diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..c3cc5e082bc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,21 @@ +# Auto detect text files and perform LF normalization +* text=auto + +*.cs text diff=csharp +*.java text diff=java +*.html text diff=html +*.py text diff=python +*.pl text diff=perl +*.pm text diff=perl +*.css text +*.js text +*.sql text + +*.sh text eol=lf + +*.bat text eol=crlf +*.cmd text eol=crlf +*.csproj text merge=union eol=crlf +*.sln text merge=union eol=crlf +*.vcxproj text merge=union eol=crlf +*.vcxproj.filters text merge=union eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..29262740e7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +.classpath +.eclipse/ +.idea/ +.project +.revision/ +.settings/ +build/ +out/ +*.iml +src/c/core.* +src/c/TEST-*.txt +src/c/*.la +src/c/*.lo +src/c/*.o +src/c/generated/ +src/java/generated/ +src/java/lib/ant-eclipse-* +src/java/lib/ivy-* diff --git a/CHANGES.txt b/CHANGES.txt new file mode 100644 index 00000000000..e5f1c25ecff --- /dev/null +++ b/CHANGES.txt @@ -0,0 +1,3116 @@ +Trunk + +NEW FEATURES: + ZOOKEEPER-2069 Netty Support for ClientCnxnSocket (Hongchao via fpj) + + ZOOKEEPER-2119 Netty client docs (Hongchao via rakeshr) + + ZOOKEEPER-2125 SSL on Netty client-server communication (Hongchao, Ian Dimayuga via rakeshr) + + ZOOKEEPER-2123 Provide implementation of X509 AuthenticationProvider + (Ian Dimayuga via rakeshr) + + ZOOKEEPER-2163: Introduce new ZNode type: container (Jordan Zimmerman via rgs) + +BUGFIXES: + ZOOKEEPER-1784 wrong check for COMMITANDACTIVATE in observer code, Learner.java (rgs via shralex). + + ZOOKEEPER-2047 testTruncationNullLog fails on windows (flavio via rakeshr) + + ZOOKEEPER-2026 Startup order in ServerCnxnFactory-ies is wrong (Stevo Slavic via rakeshr) + + ZOOKEEPER-2058 rat: exclude *.cer files (michim via rakeshr) + + ZOOKEEPER-2049 Yosemite build failure: htonll conflict (Till Toenshoff via + michim) + + ZOOKEEPER-2052 Unable to delete a node when the node has no children + (Hongchao Deng and Yip Ng via rakeshr) + + ZOOKEEPER-2064 Prevent resource leak in various classes (Ted Yu via fpj) + + ZOOKEEPER-2060 Trace bug in NettyServerCnxnFactory (Ian via fpj) + + ZOOKEEPER-2072 Netty Server Should Configure Child Channel Pipeline By Specifying + ChannelPipelineFactory (Hongchao via rakeshr) + + ZOOKEEPER-2111 Not isAlive states should be synchronized in ClientCnxn + (Hongchao via rakeshr) + + ZOOKEEPER-1366 Zookeeper should be tolerant of clock adjustments (Hongchao + Deng via michim) + + ZOOKEEPER-1949 recipes jar not included in the distribution package (Rakesh R + via michim) + + ZOOKEEPER-2114 jute generated allocate_* functions are not externally visible + (Tim Crowder via michim) + + ZOOKEEPER-2073 Memory leak on zookeeper_close (Dave Gosselin via michim) + + ZOOKEEPER-1952 Default log directory and file name can be changed + (nijel, Hari Krishna Dara via rakeshr) + + ZOOKEEPER-2134 AsyncHammerTest.testHammer fails intermittently + (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-2137 Make testPortChange() less flaky (Hongchao Deng via michim) + + ZOOKEEPER-1893. automake: use serial-tests option (michim via camille) + + ZOOKEEPER-1865 Fix retry logic in Learner.connectToLeader() (Edward Carter + via michim) + + ZOOKEEPER-2109 Typo in src/c/src/load_gen.c (surendra singh lilhore via rakeshr) + + ZOOKEEPER-2146 BinaryInputArchive readString should check length before + allocating memory (Hongchao Deng via michim) + + ZOOKEEPER-2056 Zookeeper 3.4.x and 3.5.0-alpha is not OSGi compliant + (Deiwin Sarjas via rgs) + + ZOOKEEPER-2157 Upgrade option should be removed from zkServer.sh usage + (J.Andreina via hdeng) + + ZOOKEEPER-1506 Re-try DNS hostname -> IP resolution if node connection fails + (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-2029 Leader.LearnerCnxAcceptor should handle exceptions in run() + (Rakesh R, Asad Saeed via hdeng) + + ZOOKEEPER-1626 Zookeeper C client should be tolerant of clock adjustments + (Colin Patrick McCabe via michim) + + ZOOKEEPER-2173. ZK startup failure should be handled with proper error message + (J.Andreina via camille) + + ZOOKEEPER-2174 JUnit4ZKTestRunner logs test failure for all exceptions even + if the test method is annotated with an expected exception (Chris Nauroth + via rgs) + + ZOOKEEPER-2124 Allow Zookeeper version string to have underscore '_' + (Chris Nauroth via rgs) + + ZOOKEEPER-2062 RemoveWatchesTest takes forever to run (Chris Nauroth via rakeshr) + + ZOOKEEPER-2182 Several test suites are not running during pre-commit, because their names do not end with "Test". (Chris Nauroth via hdeng) + + ZOOKEEPER-2186 QuorumCnxManager#receiveConnection may crash with random input + (rgs via michim) + + ZOOKEEPER-2190 In StandaloneDisabledTest, testReconfig() shouldn't take + leaving servers as joining servers (Hongchao Deng via rgs) + + ZOOKEEPER-1077: C client lib doesn't build on Solaris (Chris Nauroth via rgs) + + ZOOKEEPER-2156: If JAVA_HOME is not set zk startup and fetching status command execution + result misleads user (J.Andreina via rakeshr) + + ZOOKEEPER-2179: Typo in Watcher.java (Archana T via rgs) + + ZOOKEEPER-2178 Native client fails compilation on Windows. (Chris Nauroth via michim) + + ZOOKEEPER-2197 non-ascii character in FinalRequestProcessor.java + (Michi Mutsuzaki via rgs) + + ZOOKEEPER-2096: C client builds with incorrect error codes in VisualStudio 2010+ + (Vitaly Stakhovsky via rgs) + + ZOOKEEPER-2194: Let DataNode.getChildren() return an unmodifiable view of its children set + (Hitoshi Mitake via rgs) + + ZOOKEEPER-2204: LearnerSnapshotThrottlerTest.testHighContentionWithTimeout fails occasionally + (Donny Nadolny via rgs) + + ZOOKEEPER-2201: Network issues can cause cluster to hang due to near-deadlock + (Donny Nadolny via rgs) + + ZOOKEEPER-2213: Empty path in Set crashes server and prevents restart + (Hongchao Deng via rgs) + + ZOOKEEPER-706: Large numbers of watches can cause session re-establishment to fail + (Chris Thunes via rgs) + + ZOOKEEPER-2212: distributed race condition related to QV version + (Akihiro Suda via rgs) + + ZOOKEEPER-2210: clock_gettime is not available in OS X + (Michi Mutsuzaki via rgs) + + ZOOKEEPER-2193: reconfig command completes even if parameter is wrong obviously + (Yasuhito Fukuda via rgs) + + ZOOKEEPER-2221: Zookeeper JettyAdminServer server should start on configured IP + (Surendra Singh Lilhore via rgs) + + ZOOKEEPER-2224: Four letter command hangs when network is slow + (Arshad Mohammad via rakeshr) + + ZOOKEEPER-2223: support method-level JUnit testcase + (Akihiro Suda via rgs) + + ZOOKEEPER-2235 License update (fpj via michim) + + ZOOKEEPER-2239: JMX State from LocalPeerBean incorrect + (Kevin Lee via rgs) + + ZOOKEEPER-2245: SimpleSysTest test cases fails + (Arshad Mohammad via rgs) + + ZOOKEEPER-1927: zkServer.sh fails to read dataDir (and others) + from zoo.cfg on Solaris 10 (grep issue, manifests as FAILED TO WRITE PID) + (Chris Nauroth via rgs) + + ZOOKEEPER-2256: Zookeeper is not using specified JMX port in zkEnv.sh + (Arshad Mohammad via rakeshr) + + ZOOKEEPER-2264: Wrong error message when secureClientPortAddress is + configured but secureClientPort is not configured (Arshad Mohammad via rakeshr) + + ZOOKEEPER-2269: NullPointerException in RemotePeerBean + (Arshad Mohammad via rgs) + + ZOOKEEPER-2279: QuorumPeer loadDataBase() error message is incorrect + (Arshad Mohammad via rakeshr) + + ZOOKEEPER-1803: Add description for pzxid in programmer's guide + (Arshad Mohammad via rakeshr) + + ZOOKEEPER-2253: C asserts ordering of ping requests, while Java client does not + (Chris Chen via rgs) + + ZOOKEEPER-2244: On Windows zookeeper fails to restart (Arshad Mohammad via rakeshr) + + ZOOKEEPER-2268: Zookeeper doc creation fails on windows + (Arshad Mohammad via cnauroth) + + ZOOKEEPER-2281: ZK Server startup fails if there are spaces in the JAVA_HOME + path (Neha Bathra via cnauroth) + + ZOOKEEPER-1460: IPv6 literal address not supported for quorum members + (Joseph Walton via cnauroth) + + ZOOKEEPER-2302: Some test cases are not running because wrongly named + (Arshad Mohammad via fpj) + + ZOOKEEPER-2142: JMX ObjectName is incorrect for observers (Edward Ribeiro + via michim) + + ZOOKEEPER-1872: QuorumPeer is not shutdown in few cases + (Rakesh R. via rgs) + + ZOOKEEPER-2211: PurgeTxnLog does not correctly purge when snapshots and + logs are at different locations (Arshad Mohammad via rgs) + + ZOOKEEPER-2227: stmk four-letter word fails execution at server while reading + trace mask argument (Chris Nauroth via rgs) + + ZOOKEEPER-1853: zkCli.sh can't issue a CREATE command containing spaces in + the data (Ryan Lamore via rgs) + + ZOOKEEPER-2229: Several four-letter words are undocumented + (Chris Nauroth via rgs) + + ZOOKEEPER-1929: std::length_error on update children + (Charles Strahan via rgs) + + ZOOKEEPER-1371: Remove dependency on log4j in the source code + (Arshad Mohammad via rgs) + + ZOOKEEPER-2329: Clear javac and javadoc warning from zookeeper + (Arshad Mohammad via rgs) + + ZOOKEEPER-2330: ZooKeeper close API does not close Login thread + (Arshad Mohammad via rgs) + + ZOOKEEPER-2311: assert in setup_random + (Marshall McMullen via rgs) + + ZOOKEEPER-2304: JMX ClientPort from ZooKeeperServerBean incorrect + (Arshad Mohammad via rgs) + + ZOOKEEPER-2301: QuorumPeer does not listen on passed client IP in the constructor + (Arshad Mohammad via rgs) + + ZOOKEEPER-2299: NullPointerException in LocalPeerBean for ClientAddress + (Arshad Mohammad via rgs) + + ZOOKEEPER-2295: TGT refresh time logic is wrong + (Arshad Mohammad via rgs) + + ZOOKEEPER-2340: JMX is disabled even if JMXDISABLE is false + (Arshad Mohammad via rgs) + + ZOOKEEPER-2252: Random test case failure in + org.apache.zookeeper.test.StaticHostProviderTest (Timothy Ward via cnauroth) + + ZOOKEEPER-1029: C client bug in zookeeper_init (if bad hostname is given) + (fpj via cnauroth) + + ZOOKEEPER-412: checkstyle target fails trunk build (Akihiro Suda via cnauroth) + + ZOOKEEPER-2360: Update commons collections version used by tests/releaseaudit + (phunt via cnauroth) + + ZOOKEEPER-2243: Supported platforms is completely out of date (cnauroth) + +IMPROVEMENTS: + ZOOKEEPER-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex) + + ZOOKEEPER-2017 New tests for reconfig failure cases (Alexander Shraer and + Hongchao Deng via michim) + + ZOOKEEPER-2030 dynamicConfigFile should have an absolute path, not a relative + path, to the dynamic configuration file (Alexander Shraer via michim) + + ZOOKEEPER-2039 Jute compareBytes incorrect comparison index (Ian Dimayuga via fpj) + + ZOOKEEPER-1917 Apache Zookeeper logs cleartext admin passwords (fpj via michim) + + ZOOKEEPER-1948 Enable JMX remote monitoring (Biju Nair via rakeshr) + + ZOOKEEPER-2054 test-patch.sh: don't set ulimit -n (michim via rakeshr) + + ZOOKEEPER-2066 Updates to README.txt. (Wendy Smoak via camille) + + ZOOKEEPER-2079 Stop daemon with "kill" rather than "kill -9" (Guillaume ALAUX + via michim) + + ZOOKEEPER-1963 Make JDK 7 the minimum requirement for Zookeeper + (Hongchao via fpj) + + ZOOKEEPER-2110 Typo fixes in the ZK documentation. (Jeffrey Schroeder via rakeshr) + + ZOOKEEPER-1907 Improve Thread handling (Rakesh R via michim) + + ZOOKEEPER-2107 zookeeper client should support custom HostProviders + (Robert Kamphuis via rakeshr) + + ZOOKEEPER-2149 Logging of client address when socket connection established + (Hongchao Deng via michim) + + ZOOKEEPER-2176 Unclear error message should be info not error + (rgs via hdeng) + + ZOOKEEPER-2153 X509 Authentication Documentation + (Ian Dimayuga via hdeng) + + ZOOKEEPER-2171 avoid reverse lookups in QuorumCnxManager (rgs via michim) + + ZOOKEEPER-2183 Concurrent Testing Processes and Port Assignments (Chris Nauroth via hdeng) + + ZOOKEEPER-2126 Improve exit log messsage of EventThread and SendThread by + adding SessionId (surendra singh lilhore via rakeshr) + + ZOOKEEPER-2191: Continue supporting prior Ant versions that don't implement the + threads attribute for the JUnit task (Chris Nauroth via rakeshr) + + ZOOKEEPER-2187: remove duplicated code between CreateRequest{,2} + (Raul Gutierrez Segales via hdeng) + + ZOOKEEPER-2098: QuorumCnxManager: use BufferedOutputStream for initial msg + (Raul Gutierrez Segales via hdeng) + + ZOOKEEPER-2198 Set default test.junit.threads to 1 (Chris Nauroth via michim) + + ZOOKEEPER-2205: Log type of unexpected quorum packet in learner handler loop + (Hitoshi Mitake via rgs) + + ZOOKEEPER-2206: Add missing packet types to LearnerHandler.packetToString() + (Hitoshi Mitake via rgs) + + ZOOKEEPER-2207: Enhance error logs with LearnerHandler.packetToString() + (Hitoshi Mitake via rgs) + + ZOOKEEPER-2208: Log type of unexpected quorum packet in observer loop + (Akihiro Suda via rgs) + + ZOOKEEPER-2214: Findbugs warning: LearnerHandler.packetToString Dead + store to local variable (Hongchao Deng via rgs) + + ZOOKEEPER-2185: Run server with -XX:+HeapDumpOnOutOfMemoryError and + -XX:OnOutOfMemoryError='kill %p' (Chris Nauroth via rgs) + + ZOOKEEPER-2140: NettyServerCnxn and NIOServerCnxn code should be improved + (Arshad Mohammad via rgs) + + ZOOKEEPER-1423: 4lw and jmx should expose the size of the datadir/datalogdir + (Edward Ribeiro via rgs) + + ZOOKEEPER-2270: Allow MBeanRegistry to be overridden for better unit tests + (Jordan Zimmerman via rgs) + + ZOOKEEPER-2040: Server to log underlying cause of SASL connection problems. + (Steve Loughran via cnauroth) + + ZOOKEEPER-2315: Change client connect zk service timeout log level from Info + to Warn level (Lin Yiqun via rgs) + + ZOOKEEPER-2240: Make the three-node minimum more explicit in documentation + and on website (Shawn Heisey via rgs) + + ZOOKEEPER-2326: Include connected server address:port in log + (Arshad Mohammad via rgs) + + ZOOKEEPER-2335: Java Compilation Error in ClientCnxn.java + (Arshad Mohammad via rgs) + + ZOOKEEPER-2306: Remove file delete duplicate code from test code + (Arshad Mohammad via rgs) + + ZOOKEEPER-2300: Expose SecureClientPort and SecureClientAddress JMX properties + (Arshad Mohammad via rgs) + +Release 3.5.0 - 8/4/2014 + +NEW FEATURES: + ZOOKEEPER-1994. Auto-backup configuration files; config version becomes part of filename (Hongchao Deng via shralex) + + ZOOKEEPER-1355. Add zk.updateServerList(newServerList) (Alex Shraer, Marshall McMullen via fpj) + + ZOOKEEPER-1572. Add an async (Java) interface for multi request (Sijie Guo via camille) + + ZOOKEEPER-107. Allow dynamic changes to server cluster membership (Alex Shraer via breed) + + ZOOKEEPER-1400. Allow logging via callback instead of raw FILE pointer + (Marshall McMullen via michim) + + ZOOKEEPER-1147. Add support for local sessions (Jay Shrauner, thawan via thawan) + + ZOOKEEPER-1691. Add a flag to disable standalone mode (Helen Hastings via michim) + + ZOOKEEPER-442. need a way to remove watches that are no longer of + interest (Rakesh R, Daniel Gómez Ferro via phunt) + + ZOOKEEPER-1830. Support command line shell for removing watches + (Rakesh R via michim) + + ZOOKEEPER-1887. C implementation of removeWatches (Raul Gutierrez Segales via + michim) + + ZOOKEEPER-1928. add configurable throttling to the number of snapshots + concurrently sent by a leader (Edward Carter via fpj) + + ZOOKEEPER-827. enable r/o mode in C client library (rgs via fpj) + + ZOOKEEPER-1346. Add Jetty HTTP server support for four letter words. + (Skye Wanderman-Milne, Bill Havanki via phunt) + +BUGFIXES: + ZOOKEEPER-2032. Cleaning up resources in ReconfigBackupTest (Hongchao Deng via shralex) + + ZOOKEEPER-2013. Typos in programmer guide. (Tim Chambers via Alex Shraer) + + ZOOKEEPER-2006. Standalone mode won't take client port from dynamic config. (Hongchao Deng via Alex Shraer) + + ZOOKEEPER-2008. Missing leader election port in system test. (Kfir Lev-Ari via Alex Shraer). + + ZOOKEEPER-1992. Backward compatibility of the static configuration file (Hongchao Deng via Alex Shraer). + + ZOOKEEPER-1900. NullPointerException in truncate (Camille Fournier) + + ZOOKEEPER-786. Exception in ZooKeeper.toString + (Thomas Koch via phunt) + + ZOOKEEPER-1191. Synchronization issue - wait not in guarded block (Alex Shraer via breed) + + ZOOKEEPER-1192. Leader.waitForEpochAck() checks waitingForNewEpoch instead of checking electionFinished (Alex Shraer via breed) + + ZOOKEEPER-1203. Zookeeper systest is missing Junit Classes + (Prashant Gokhale via phunt) + + ZOOKEEPER-1174. FD leak when network unreachable (Ted Dunning via camille) + + ZOOKEEPER-1206. Sequential node creation does not use always use + digits in node name given certain Locales. (Mark Miller via phunt) + + ZOOKEEPER-1212. zkServer.sh stop action is not conformat with LSB + para 20.2 Init Script Actions (Roman Shaposhnik via phunt) + + ZOOKEEPER-1190. ant package is not including many of the bin scripts + in the package (zkServer.sh for example) (Eric Yang via phunt) + + ZOOKEEPER-1241. Typo in ZooKeeper Recipes and Solutions + documentation (Jingguo Yao via phunt) + + ZOOKEEPER-1220. ./zkCli.sh 'create' command is throwing + ArrayIndexOutOfBoundsException (kavita sharma via phunt) + + ZOOKEEPER-1256. ClientPortBindTest is failing on Mac OS X + (Daniel Gómez Ferro via phunt) + + ZOOKEEPER-1264. FollowerResyncConcurrencyTest failing intermittently. (phunt via camille) + + ZOOKEEPER-1246. Dead code in PrepRequestProcessor catch Exception block. (camille) + + ZOOKEEPER-1271. testEarlyLeaderAbandonment failing on solaris - + clients not retrying connection (mahadev via phunt) + + ZOOKEEPER-1264. FollowerResyncConcurrencyTest failing + intermittently. (breed, camille and Alex Shraer via camille) + + ZOOKEEPER-1282. Learner.java not following Zab 1.0 protocol - + setCurrentEpoch should be done upon receipt of NEWLEADER + (before acking it) and not upon receipt of UPTODATE (breed via camille) + + ZOOKEEPER-1291. AcceptedEpoch not updated at leader before it proposes the epoch to followers. (Alex Shraer via camille) + + ZOOKEEPER-1208. Ephemeral node not removed after the client session is long gone. (phunt via camille) + + ZOOKEEPER-1239. add logging/stats to identify fsync stalls. (phunt via camille) + + ZOOKEEPER-1311. ZooKeeper test jar is broken (Ivan Kelly via phunt) + + ZOOKEEPER-1305. zookeeper.c:prepend_string func can dereference null ptr. + (Daniel Lescohier via mahadev) + + ZOOKEEPER-1262. Documentation for Lock recipe has major flaw. + (Jordan Zimmerman via mahadev) + + ZOOKEEPER-1316. zookeeper_init leaks memory if chroot is just '/'. + (Akira Kitada via mahadev) + + ZOOKEEPER-1315. zookeeper_init always reports sessionPasswd=. + (Akira Kitada via mahadev) + + ZOOKEEPER-1317. Possible segfault in zookeeper_init. (Akira Kitada via mahadev) + + ZOOKEEPER-1319. Missing data after restarting+expanding a cluster. + (phunt and breed via mahadev) + + ZOOKEEPER-1269. Multi deserialization issues. (Camille Fournier via mahadev) + + ZOOKEEPER-1323. c client doesn't compile on freebsd + (michi mutsuzaki via phunt) + + ZOOKEEPER-1333. NPE in FileTxnSnapLog when restarting a cluster. + (Patrick Hunt via mahadev) + + ZOOKEEPER-1331. Typo in docs: acheive -> achieve (Andrew Ash via phunt) + + ZOOKEEPER-1089. zkServer.sh status does not work due to invalid + option of nc (Roman Shaposhnik via phunt) + + ZOOKEEPER-1343. getEpochToPropose should check if lastAcceptedEpoch is greater or equal than epoch (fpj via breed) + + ZOOKEEPER-1050. zooinspector shell scripts do not work + (Will Johnson via phunt) + + ZOOKEEPER-1294. One of the zookeeper server is not accepting any requests (Kavita Sharma via henryr) + + ZOOKEEPER-1358. In StaticHostProviderTest.java, testNextDoesNotSleepForZero tests that hostProvider.next(0) + doesn't sleep by checking that the latency of this call is less than 10sec (Alex Shraer via camille) + + ZOOKEEPER-1351. invalid test verification in MultiTransactionTest (phunt via camille) + + ZOOKEEPER-973. bind() could fail on Leader because it does not + setReuseAddress on its ServerSocket (Harsh J via phunt) + + ZOOKEEPER-1367. Data inconsistencies and unexpired ephemeral nodes after cluster restart. + (Benjamin Reed via mahadev) + + ZOOKEEPER-1353. C client test suite fails consistently. (Clint Byrum + via mahadev) + + ZOOKEEPER-1373. Hardcoded SASL login context name clashes with Hadoop security + configuration override. (Eugene Koontz and Thomas Weise via mahadev) + + ZOOKEEPER-1352. server.InvalidSnapshotTest is using connection timeouts + that are too short. (phunt via mahadev) + + ZOOKEEPER-1336. javadoc for multi is confusing, references functionality that doesn't seem + to exist. (phunt via mahadev) + + ZOOKEEPER-1327. there are still remnants of hadoop urls. (Harsh J via mahadev) + + ZOOKEEPER-1340. multi problem - typical user operations are generating ERROR level + messages in the server (phunt via mahadev) + + ZOOKEEPER-1374. C client multi-threaded test suite fails to compile + on ARM architectures. (James Page via mahadev) + + ZOOKEEPER-1337. multi's "Transaction" class is missing tests. (camille + and phunt via mahadev) + + ZOOKEEPER-1338. class cast exceptions may be thrown by multi ErrorResult + class (invalid equals) (phunt via mahadev) + + ZOOKEEPER-1386. avoid flaky URL redirection in "ant javadoc" : + replace "http://java.sun.com/javase/6/docs/api/" with + "http://download.oracle.com/javase/6/docs/api/" (Eugene Koontz via camille) + + ZOOKEEPER-1361. Leader.lead iterates over 'learners' set without proper synchronisation (henryr via camille) + + ZOOKEEPER-1277. servers stop serving when lower 32bits of zxid roll + over (phunt) + + ZOOKEEPER-1412. java client watches inconsistently triggered on + reconnect (phunt) + + ZOOKEEPER-1344. ZooKeeper client multi-update command is not + considering the Chroot request (Rakesh R via phunt) + + ZOOKEEPER-1307. zkCli.sh is exiting when an Invalid ACL exception is + thrown from setACL command through client (Kavita Sharma via phunt) + + ZOOKEEPER-1390. some expensive debug code not protected by a check + for debug (breed via camille) + + ZOOKEEPER-1406. dpkg init scripts don't restart - missing + check_priv_sep_dir (Chris Beauchamp via phunt) + + ZOOKEEPER-1403. zkCli.sh script quoting issue (James Page via phunt) + + ZOOKEEPER-1384. test-cppunit overrides LD_LIBRARY_PATH and fails if + gcc is in non-standard location (Jay Shrauner via phunt) + + ZOOKEEPER-1419. Leader election never settles for a 5-node cluster (flavio via camille) + + ZOOKEEPER-1433. improve ZxidRolloverTest (test seems flakey) (phunt via henryr) + + ZOOKEEPER-1395. node-watcher double-free redux (Mike Lundy via henryr) + + ZOOKEEPER-1439. c sdk: core in log_env for lack of checking the output + argument *pwp* of getpwuid_r (Yubing Yin via michim) + + ZOOKEEPER-1339. C client doesn't build with --enable-debug + (Eric Liang via michim) + + ZOOKEEPER-1048. addauth command does not work in cli_mt/cli_st + (allengao via michim) + + ZOOKEEPER-1318. In Python binding, get_children (and get and exists, and probably others) + with expired session doesn't raise exception properly (henryr via michim) + + ZOOKEEPER-642. "exceeded deadline by N ms" floods logs (Marc Celani via michim) + + ZOOKEEPER-1431. zkpython async calls leak memory (Kapil Thangavelu and Andre Cruz via henryr) + + ZOOKEEPER-1163. Memory leak in zk_hashtable.c:do_insert_watcher_object() + (Anupam Chanda via michim) + + ZOOKEEPER-1466. QuorumCnxManager.shutdown missing synchronization. (Patrick Hunt via mahadev) + + ZOOKEEPER-1490. If the configured log directory does not exist + zookeeper will not start. Better to create the directory and start + (suja s via phunt) + + ZOOKEEPER-1210. Can't build ZooKeeper RPM with RPM >= 4.6.0 (i.e. on + RHEL 6 and Fedora >= 10) (Tadeusz Andrzej Kadłubowski via phunt) + + ZOOKEEPER-1236. Security uses proprietary Sun APIs + (Adalberto Medeiros via phunt) + + ZOOKEEPER-1471. Jute generates invalid C++ code + (Michi Mutsuzaki via phunt) + + ZOOKEEPER-1465. Cluster availability following new leader election + takes a long time with large datasets - is correlated to dataset size + (fpj and Thawan Kooburat via camille) + + ZOOKEEPER-1427. Writing to local files is done non-atomically (phunt) + + ZOOKEEPER-1489. Data loss after truncate on transaction log (phunt) + + ZOOKEEPER-1521. LearnerHandler initLimit/syncLimit problems + specifying follower socket timeout limits (phunt) + + ZOOKEEPER-1493. C Client: zookeeper_process doesn't invoke + completion callback if zookeeper_close has been called + (Michi Mutsuzaki via phunt and mahadev) + + ZOOKEEPER-1522. intermittent failures in Zab test due to NPE in + recursiveDelete test function (phunt via flavio) + + ZOOKEEPER-1514. FastLeaderElection - leader ignores the round + information when joining a quorum (flavio via henryr) + + ZOOKEEPER-1533 Correct the documentation of the args for the JavaExample doc. + (Warren Turkal via michim) + + ZOOKEEPER-1536 c client : memory leak in winport.c (brooklin via michim) + + ZOOKEEPER-1481 allow the C cli to run exists with a watcher (phunt via michim) + + ZOOKEEPER-1328. Misplaced assertion for the test case 'FLELostMessageTest' + and not identifying misfunctions. (Rakesh R via mahadev) + + ZOOKEEPER-1380. zkperl: _zk_release_watch doesn't remove items properly from + the watch list. (Botond Hejj via mahadev) + + ZOOKEEPER-1538. Improve space handling in zkServer.sh and zkEnv.sh. (Andrew + Ferguson via mahadev) + + ZOOKEEPER-1501. Nagios plugin always returns OK when it cannot connect to + zookeeper. (Brian Sutherland via mahadev) + + ZOOKEEPER-1437. Client uses session before SASL authentication complete + (Eugene Koontz via mahadev) + + ZOOKEEPER-1494. C client: socket leak after receive timeout in + zookeeper_interest() (Michi Mutsuzaki via mahadev) + + ZOOKEEPER-1483. Fix leader election recipe documentation (Michi Mutsuzaki + via mahadev) + + ZOOKEEPER-1496. Ephemeral node not getting cleared even after client has + exited. (Rakesh R via mahadev) + + ZOOKEEPER-1550. ZooKeeperSaslClient does not finish anonymous login on + OpenJDK (Eugene Koontz via mahadev) + + ZOOKEEPER-1585. make dist for src/c broken in trunk (Raul Gutierrez Segales + via michim) + + ZOOKEEPER-1590. Patch to add zk.updateServerList(newServerList) + broke the build (fpj via phunt) + + ZOOKEEPER-1474. Cannot build Zookeeper with IBM Java: use of Sun + MXBean classes (Adalberto Medeiros via phunt) + + ZOOKEEPER-1591. Windows build is broken because inttypes.h doesn't exist + (Marshall McMullen via michim) + + ZOOKEEPER-1596. Zab1_0Test should ensure that the file is closed + (Enis Soztutar via phunt) + + ZOOKEEPER-1513. "Unreasonable length" exception while starting a + server (Skye W-M via phunt) + + ZOOKEEPER-1581. change copyright in notice to 2012 (breed via phunt) + + ZOOKEEPER-1553. Findbugs configuration is missing some dependencies + (Sean Busbey via phunt) + + ZOOKEEPER-1478. Small bug in QuorumTest.testFollowersStartAfterLeader( ) + (Alexander Shraer via fpj, breed, phunt) + + ZOOKEEPER-1387. Wrong epoch file created + (Benjamin Busjaeger via breed, phunt) + + ZOOKEEPER-1578. org.apache.zookeeper.server.quorum.Zab1_0Test failed due to + hard code with 33556 port (Li Ping via mahadev) + + ZOOKEEPER-1334. Zookeeper 3.4.x is not OSGi compliant - MANIFEST.MF + is flawed (Claus Ibsen via phunt) + + ZOOKEEPER-1603. StaticHostProviderTest testUpdateClientMigrateOrNot + hangs (Alexander Shraer via phunt) + + ZOOKEEPER-1597. Windows build failing (michim via phunt) + + ZOOKEEPER-1625. zkServer.sh is looking for clientPort in config file, but it + may no longer be there with ZK-1411 (Alexander Shraer via michim) + + ZOOKEEPER-1495. ZK client hangs when using a function not available + on the server. (Skye W-M via phunt) + + ZOOKEEPER-1620. NIOServerCnxnFactory (new code introduced in + ZK-1504) opens selectors but never closes them + (Thawan Kooburat via phunt) + + ZOOKEEPER-1628. Documented list of allowable characters in ZK doc + not in line with code (Gabriel Reid via phunt) + + ZOOKEEPER-1613. The documentation still points to 2008 in the + copyright notice (Edward Ribeiro via phunt) + + ZOOKEEPER-1562. Memory leaks in zoo_multi API + (Deepak Jagtap via phunt) + + ZOOKEEPER-1645. ZooKeeper OSGi package imports not complete + (Arnoud Glimmerveen via phunt) + + ZOOKEEPER-1641. Using slope=positive results in a jagged ganglia + graph of packets rcvd/sent (Ben Hartshorne via phunt) + + ZOOKEEPER-1648. Fix WatcherTest in JDK7 + (Thawan Kooburat via phunt) + + ZOOKEEPER-1606. intermittent failures in ZkDatabaseCorruptionTest on + jenkins (lixiaofeng via phunt) + + ZOOKEEPER-1647. OSGi package import/export changes not applied to + bin-jar (Arnoud Glimmerveen via phunt) + + ZOOKEEPER-1672. zookeeper client does not accept "-members" option + in reconfig command (Xiaoshuang Wang via phunt) + + ZOOKEEPER-1700. FLETest consistently failing - setLastSeenQuorumVerifier + seems to be hanging (phunt via fpj) + + ZOOKEEPER-1697. large snapshots can cause continuous quorum failure + (phunt via fpj) + + ZOOKEEPER-1706. Typo in Double Barriers example (Jingguo Yao via fpj) + + ZOOKEEPER-1324. Remove Duplicate NEWLEADER packets + from the Leader to the Follower. (Thawan, fpj via fpj) + + ZOOKEEPER-1642. Leader Loading Database Twice (fpj via camille) + + ZOOKEEPER-1663. scripts don't work when path contains spaces (Amichai Rothman via camille) + + ZOOKEEPER-1702. ZooKeeper client may write operation packets before + receiving successful response to connection request, can cause TCP + RST (Chris Nauroth via phunt) + + ZOOKEEPER-1629. testTransactionLogCorruption occasionally fails. (shralex via camille) + + ZOOKEEPER-1713. wrong time calculation in zkfuse.cc (german via fpj) + + ZOOKEEPER-1379. 'printwatches, redo, history and + connect '. client commands always print usage. This + is not necessary (edward via fpj) + + ZOOKEEPER-1670. zookeeper should set a default value + for SERVER_JVMFLAGS and CLIENT_JVMFLAGS so that memory + usage is controlled (Arpit Gupta via fpj) + + ZOOKEEPER-1448. Node+Quota creation in transaction log can crash leader startup (Botond Hejj via fpj) + + ZOOKEEPER-1664. Kerberos auth doesn't work with native platform GSS integration. (Boaz Kelmer via camille) + + ZOOKEEPER-1754. Read-only server allows to create znode (Rakesh R via fpj) + + ZOOKEEPER-1751. ClientCnxn#run could miss the second ping or connection get + dropped before a ping. (Jeffrey Zhong via mahadev) + + ZOOKEEPER-1657. Increased CPU usage by unnecessary SASL + checks (Philip K. Warren via fpj) + + ZOOKEEPER-1753. ClientCnxn is not properly releasing the resources, + which are used to ping RwServer (Rakesh R via fpj) + + ZOOKEEPER-1096. Leader communication should listen on + specified IP, not wildcard address (Jared Cantwell, + German Blanco via fpj) + + ZOOKEEPER-87. Follower does not shut itself down if its + too far behind the leader. (German Blanco via fpj) + + ZOOKEEPER-1696. Fail to run zookeeper client on Weblogic application server. + (Jeffrey Zhong via mahadev) + + ZOOKEEPER-1769. ZooInspector can't display node data/metadata/ACLs + (Benjamin Jaton via phunt) + + ZOOKEEPER-1718. Support JLine 2 (Manikumar Reddy via phunt) + + ZOOKEEPER-1655. Make jline dependency optional in maven pom + (Thomas Weise via phunt) + + ZOOKEEPER-1770. NullPointerException in SnapshotFormatter + (Germán Blanco via phunt) + + ZOOKEEPER-1733. FLETest#testLE is flaky on windows boxes + (Jeffrey Zhong via phunt) + + ZOOKEEPER-1773. incorrect reference to jline version/lib in docs + (Manikumar Reddy via phunt) + + ZOOKEEPER-732. Improper translation of error into Python exception + (Andrei Savu, Lei Zhang, fpj via fpj) + + ZOOKEEPER-1766. Consistent log severity level guards and statements + (Jackie Chang via michim) + + ZOOKEEPER-1778. Use static final Logger objects (Rakesh R via michim) + + ZOOKEEPER-1551. Observers ignore txns that come after snapshot and UPTODATE + (thawan, fpj via thawan) + + ZOOKEEPER-1781. ZooKeeper Server fails if snapCount is set to 1 + (Takashi Ohnishi via phunt, breed) + + ZOOKEEPER-1774. QuorumPeerMainTest fails consistently with + "complains about host" assertion failure (phunt) + + ZOOKEEPER-877. zkpython does not work with python3.1 + (Daniel Enman via phunt) + + ZOOKEEPER-1624. PrepRequestProcessor abort multi-operation incorrectly. (thawan via camille) + + ZOOKEEPER-1610. Some classes are using == or != to compare + Long/String objects instead of .equals() (Edward Ribeiro via phunt) + + ZOOKEEPER-1795. unable to build c client on ubuntu + (Raul Gutierrez Segales via phunt) + + ZOOKEEPER-1646. mt c client tests fail on Ubuntu Raring (phunt) + + ZOOKEEPER-1732. ZooKeeper server unable to join established + ensemble (German Blanco via fpj) + + ZOOKEEPER-1667. Watch event isn't handled correctly when + a client reestablish to a server (jacky007, fpj via fpj) + + ZOOKEEPER-1799. SaslAuthFailDesignatedClientTest.testAuth fails + frequently on SUSE (Jeffrey Zhong via phunt) + + ZOOKEEPER-1557. jenkins jdk7 test failure in + testBadSaslAuthNotifiesWatch (Eugene Koontz via phunt) + + ZOOKEEPER-1744. clientPortAddress breaks "zkServer.sh status" + (Nick Ohanian via phunt) + + ZOOKEEPER-1499. clientPort config changes not backwards-compatible + (Alexander Shraer via phunt, breed) + + ZOOKEEPER-1798. Fix race condition in testNormalObserverRun + (thawan, fpj via thawan) + + ZOOKEEPER-1783. Distinguish initial configuration from first established + configuration (shralex via breed) + + ZOOKEEPER-1812. ZooInspector reconnection always fails if first + connection fails (Benjamin Jaton via phunt) + + ZOOKEEPER-1815. Tolerate incorrectly set system hostname in tests + (some one via michim) + + ZOOKEEPER-1821. very ugly warning when compiling load_gen.c + (german blanco via fpj) + + ZOOKEEPER-1632. fix memory leaks in cli_st (fpj via michim) + + ZOOKEEPER-1459. Standalone ZooKeeperServer is not closing + the transaction log files on shutdown (Rakesh R via fpj) + + ZOOKEEPER-1019. zkfuse doesn't list dependency on boost in README + (Raul Gutierrez Segales via michim) + + ZOOKEEPER-1834. Catch IOException in FileTxnLog (fpj via michim) + + ZOOKEEPER-1382. Zookeeper server holds onto dead/expired session ids in the watch data structures + (Germán Blanco and Michael Morello via camille) + + ZOOKEEPER-1839. Deadlock in NettyServerCnxn (Rakesh R via michim) + + ZOOKEEPER-1622. session ids will be negative in the year 2022 + (Eric Newton via phunt) + + ZOOKEEPER-1756. zookeeper_interest() in C client can return a timeval of 0 + (Eric Lindvall via michim) + + ZOOKEEPER-1388. Client side 'PathValidation' is missing for the + multi-transaction api. (Rakesh R via marshallm, phunt) + + ZOOKEEPER-1849. Need to properly tear down tests in various cases + (Germán Blanco via fpj) + + ZOOKEEPER-1179. NettyServerCnxn does not properly close socket on + 4 letter word requests (Rakesh R, Germán Blanco via fpj) + + ZOOKEEPER-1852. ServerCnxnFactory instance is not properly + cleanedup (Rakesh R via fpj) + + ZOOKEEPER-1414. QuorumPeerMainTest.testQuorum, testBadPackets are failing + intermittently (Rakesh R via michim) + + ZOOKEEPER-1057. zookeeper c-client, connection to offline server fails to + successfully fallback to second zk host (Germán Blanco via michim) + + ZOOKEEPER-1857. PrepRequestProcessotTest doesn't shutdown ZooKeeper server + (Germán Blanco via michim) + + ZOOKEEPER-1860. Async versions of reconfig don't actually throw + KeeperException nor InterruptedException (Raul Gutierrez Segales via phunt) + + ZOOKEEPER-1837. Fix JMXEnv checks (potential race conditions) + (Germán Blanco via fpj) + + ZOOKEEPER-1858. JMX checks - potential race conditions while stopping + and starting server (Rakesh R via fpj) + + ZOOKEEPER-1867. Bug in ZkDatabaseCorruptionTest (fpj) + + ZOOKEEPER-1573. Unable to load database due to missing parent node + (Vinayakumar B via phunt, fpj) + + ZOOKEEPER-1811. The ZooKeeperSaslClient service name principal is + hardcoded to "zookeeper" (Harsh J via phunt) + + ZOOKEEPER-1874. Add proper teardown/cleanups in ReconfigTest to shutdown + quorumpeer (Rakesh R and Germán Blanco via michim) + + ZOOKEEPER-1873. Unnecessarily InstanceNotFoundException is coming when + unregister failed jmxbeans (Rakesh R via michim) + + ZOOKEEPER-1844. TruncateTest fails on windows (Rakesh R via fpj) + + ZOOKEEPER-1861. ConcurrentHashMap isn't used properly in QuorumCnxManager + (Ted Yu via camille) + + ZOOKEEPER-1755. Concurrent operations of four letter 'dump' ephemeral + command and killSession causing NPE (Rakesh R via camille) + + ZOOKEEPER-1779. ReconfigTest littering the source root with test files + (Abhiraj Butala via michim) + + ZOOKEEPER-1888. ZkCli.cmd commands fail with "'java' is not recognized as an + internal or external command" (Ivan Mitic via michim) + + ZOOKEEPER-1662. Fix to two small bugs in ReconfigTest.testPortChange() + (Alexander Shraer via michim) + + ZOOKEEPER-1883. C client unit test failures (Raul Gutierrez Segales via + michim) + + ZOOKEEPER-1878. Inconsistent behavior in autocreation of dataDir and + dataLogDir (Rakesh R via michim) + + ZOOKEEPER-1862. ServerCnxnTest.testServerCnxnExpiry is intermittently failing + (Rakesh R via michim) + + ZOOKEEPER-1901. [JDK8] Sort children for comparison in AsyncOps tests + (Andrew Purtell via michim) + + ZOOKEEPER-1894. ObserverTest.testObserver fails consistently. (michim via camille) + + ZOOKEEPER-1263. fix handling of min/max session timeout value initialization + (Rakesh R via michim) + + ZOOKEEPER-1904. WatcherTest#testWatchAutoResetWithPending is failing + (Rakesh R via michim) + + ZOOKEEPER-1725. Zookeeper Dynamic Conf writes out hostnames when IPs are + supplied (Alexander Shraer via michim) + + ZOOKEEPER-1906. zkpython: invalid data in GetData for empty node + (Nikita Vetoshkin via michim) + + ZOOKEEPER-1897. ZK Shell/Cli not processing commands (stack via michim) + + ZOOKEEPER-1357. Zab1_0Test uses hard-wired port numbers. Specifically, it uses + the same port for leader in two different tests. The second test periodically + fails complaining that the port is still in use. (Alexander Shraer via michim) + + ZOOKEEPER-1840. Server tries to connect to itself during dynamic reconfig + (Alexander Shraer via michim) + + ZOOKEEPER-1909. removeWatches doesn't return NOWATCHER when there is + no watch set (Raul Gutierrez Segales via rakeshr) + + ZOOKEEPER-1913. Invalid manifest files due to bogus revision property value + (Raul Gutierrez Segales via michim) + + ZOOKEEPER-1911. REST contrib module does not include all required files when + packaged (Sean Mackrory via michim) + + ZOOKEEPER-1819. DeserializationPerfTest calls method with wrong arguments + (Daniel Knightly via michim) + + ZOOKEEPER-1673. Zookeeper don't support cidr in expression in ACL with ip + scheme (Craig Condit via michim) + + ZOOKEEPER-1843. Oddity in ByteBufferInputStream skip (Bill Havanki via michim) + + ZOOKEEPER-1910. RemoveWatches wrongly removes the watcher if multiple watches + exists on a path (Rakesh R via camille) + + ZOOKEEPER-1695. Inconsistent error code and type for new errors introduced + by dynamic reconfiguration (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-1923. A typo in zookeeperStarted document (Chengwei Yang via michim) + + ZOOKEEPER-1926. Unit tests should only use build/test/data for data (Enis + Soztutar via michim) + + ZOOKEEPER-1891. StaticHostProviderTest.testUpdateLoadBalancing times out + (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-1836. addrvec_next() fails to set next parameter if + addrvec_hasnext() returns false (Dutch T. Meyer via michim) + + ZOOKEEPER-1062. Net-ZooKeeper: Net::ZooKeeper consumes 100% cpu on wait + (Botond Hejj via michim) + + ZOOKEEPER-1864. quorumVerifier is null when creating a QuorumPeerConfig + from parsing a Properties object (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-1797. PurgeTxnLog may delete data logs during roll (Rakesh R via + michim) + + ZOOKEEPER-1791. ZooKeeper package includes unnecessary jars that are part of + the package. (mahadev via michim) + + ZOOKEEPER-1214. QuorumPeer should unregister only its previsously registered + MBeans instead of use MBeanRegistry.unregisterAll() method. + (César Álvarez Núñez via michim) + + ZOOKEEPER-1699. Leader should timeout and give up leadership when losing + quorum of last proposed configuration (Alexander Shraer via michim) + + ZOOKEEPER-1870. flakey test in StandaloneDisabledTest.startSingleServerTest + (Helen Hastings via fpj) + + ZOOKEEPER-1945. deb - zkCli.sh, zkServer.sh and zkEnv.sh regression caused + by ZOOKEEPER-1663 (Mark Flickinger via fpj) + + ZOOKEEPER-1939. ReconfigRecoveryTest.testNextConfigUnreachable is + failing (Rakesh R via phunt) + + ZOOKEEPER-1835. dynamic configuration file renaming fails on Windows + (Bruno Freudensprung via rakeshr) + + ZOOKEEPER-1810. Add version to FLE notifications for trunk Germán Blanco via + michim) + + ZOOKEEPER-1222. getACL should only call DataTree.copyStat when passed in + stat is not null (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-1964. Fix Flaky Test in ReconfigTest.java (Hongchao Deng via fpj) + + ZOOKEEPER-1863. Race condition in commit processor leading to out of order + request completion, xid mismatch on client. (fpj and Dutch T Meyer via camille) + + ZOOKEEPER-1966. VS and line breaks (Orion Hodson via fpj) + + ZOOKEEPER-1683. ZooKeeper client NPE when updating server list on disconnected + client (shralex via michim) + + ZOOKEEPER-1969. Fix Port Already In Use for JettyAdminServerTest + (Hongchao Deng via phunt) + + ZOOKEEPER-1851. Follower and Observer Request Processors Do Not Forward + create2 Requests (Chris Chen via rakeshr) + + ZOOKEEPER-1807. Observers spam each other creating connections to the + election addr (Alex Shraer via fpj) + + ZOOKEEPER-1972. Fix invalid volatile long/int increment (++) + (Hongchao Deng via phunt) + + ZOOKEEPER-1973. Jetty Server changes broke ibm6 support + (Bill Havanki via phunt) + + ZOOKEEPER-1975. Turn off "internationalization warnings" in findbugs + exclude file (phunt) + + ZOOKEEPER-1979. Fix Performance Warnings found by Findbugs 2.0.3 + (Hongchao Deng via phunt) + + ZOOKEEPER-1981. Fix Dodgy Code Warnings identified by findbugs 2.0.3 + (Hongchao Deng via phunt) + + ZOOKEEPER-1984. testLeaderTimesoutOnNewQuorum is a flakey test + (Alex Shraer via phunt) + + ZOOKEEPER-1789. 3.4.x observer causes NPE on 3.5.0 (trunk) + participants (Alex Shraer via phunt) + + ZOOKEEPER-1982. Refactor (touch|add)Session in + SessionTrackerImpl.java (Hongchao Deng via phunt) + + ZOOKEEPER-1937. init script needs fixing for ZOOKEEPER-1719 + (Marshall McMullen via phunt) + + ZOOKEEPER-1877. Malformed ACL Id can crash server with skipACL=yes + (Chris Chen via phunt) + + ZOOKEEPER-1974. winvs2008 jenkins job failing with "unresolved + external symbol" (flavio via phunt) + + ZOOKEEPER-1933. Windows release build of zk client cannot connect to + zk server (Orion Hodson via fpj, phunt) + + ZOOKEEPER-1988. new test patch to verify dynamic reconfig backward + compatibility (Alexander Shraer via rakeshr) + + ZOOKEEPER-2000. Fix ReconfigTest.testPortChange (Alexander Shraer via michim) + +IMPROVEMENTS: + + ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports, + unused variables, missing generics (Thomas Koch via phunt) + + ZOOKEEPER-96. The jute parser should get generated from the jj files + instead of checking in the generated sources (Thomas Koch via phunt) + + ZOOKEEPER-1175. DataNode references parent node for no reason + (Thomas Koch via phunt) + + ZOOKEEPER-899. Update Netty version in trunk to 3.2.2 + (Thomas Koch via phunt) + + ZOOKEEPER-1182. Make findbugs usable in Eclipse (Thomas Koch via phunt) + + ZOOKEEPER-1184. jute generated files are not being cleaned up via "ant clean" + (Thomas Koch via phunt) + + ZOOKEEPER-1176. Remove dead code and basic cleanup in DataTree + (Thomas Koch via phunt) + + ZOOKEEPER-556. Startup messages should account for common error of + missing leading slash in config files (Thomas Koch via phunt) + + ZOOKEEPER-1155. Add windows automated builds (CI) for zookeeper c client bindings. (Dheeraj Agrawal via camille) + + ZOOKEEPER-1226. extract version check in separate method in PrepRequestProcessor (Thomas Koch via camille) + + ZOOKEEPER-1193. Remove upgrade code (Thomas Koch via phunt) + + ZOOKEEPER-1221. Provide accessors for Request.{hdr|txn} (Thomas Koch via phunt) + + ZOOKEEPER-1216. Fix more eclipse compiler warnings, also in Tests + (Thomas Koch via phunt) + + ZOOKEEPER-1254. test correct watch handling with multi ops + (Thomas Koch via phunt) + + ZOOKEEPER-1252. remove unused method o.a.z.test.AxyncTest.restart() + (Thomas Koch via phunt) + + ZOOKEEPER-1200. Remove obsolete DataTreeBuilder + (Thomas Koch via phunt) + + ZOOKEEPER-1247. dead code in PrepRequestProcessor.pRequest multi case + (Thomas Koch via phunt) + + ZOOKEEPER-1265. Normalize switch cases lists on request types + (Thomas Koch via phunt) + + ZOOKEEPER-1267. closeSession flag in finalRequestProcessor is superfluous + (Thomas Koch via phunt) + + ZOOKEEPER-1273. Copy'n'pasted unit test (Thomas Koch via phunt) + + ZOOKEEPER-1232. remove unused o.a.z.server.util.Profiler + (Thomas Koch via phunt) + + ZOOKEEPER-1253. return value of DataTree.createNode is never used + (Thomas Koch via phunt) + + ZOOKEEPER-756. some cleanup and improvements for zooinspector + (Colin Goodheart-Smithe & Thomas Koch via phunt) + + ZOOKEEPER-1292. FLETest is flaky (fpj via breed) + + ZOOKEEPER-1326. The CLI commands "delete" and "rmr" are confusing. + Can we have "rm" + "rmr" instead? (Harsh J via phunt) + + ZOOKEEPER-1342. quorum Listener & LearnerCnxAcceptor are missing + thread names (Rakesh R via phunt) + + ZOOKEEPER-1229. C client hashtable_remove redundantly calls hash function + (Harsh J via phunt) + + ZOOKEEPER-1345. Add a .gitignore file with general exclusions and + Eclipse project files excluded (Harsh J via phunt) + + ZOOKEEPER-1293. Remove unused readyToStart from Leader.java + (Alex Shraer via phunt) + + ZOOKEEPER-1322. Cleanup/fix logging in Quorum code. + (phunt via mahadev) + + ZOOKEEPER-1321. Add number of client connections metric in JMX and + srvr. (Neha Narkhede via camille) + + ZOOKEEPER-1389. it would be nice if start-foreground used exec $JAVA + in order to get rid of the intermediate shell process + (Roman Shaposhnik via phunt) + + ZOOKEEPER-1161. Provide an option for disabling auto-creation of the + data directory (phunt via henry) + + ZOOKEEPER-1397. Remove BookKeeper documentation links. (flavio via camille) + + ZOOKEEPER-1377. add support for dumping a snapshot file content (similar to LogFormatter). (phunt via camille) + + ZOOKEEPER-271. Better command line parsing in ZookeeperMain. + (Hartmut Lang via phunt) + + ZOOKEEPER-1435. cap space usage of default log4j rolling policy (phunt via henryr) + + ZOOKEEPER-1432. Add javadoc and debug logging for checkACL() method in + PrepRequestProcessor (Eugene Koontz via michim) + + ZOOKEEPER-1411. Consolidate membership management, distinguish between static and dynamic configuration parameters (Alex Shraer via breed) + + ZOOKEEPER-1451. C API improperly logs getaddrinfo failures on Linux when using glibc (Stephen Tyree via michim) + + ZOOKEEPER-1440. Spurious log error messages when QuorumCnxManager is shutting + down (Jordan Zimmerman via michim) + + ZOOKEEPER-1454. Document how to run autoreconf if cppunit is + installed in a non-standard directory (Michi Mutsuzaki via phunt) + + ZOOKEEPER-1503. remove redundant JAAS configuration code in SaslAuthTest and + SaslAuthFailTest (Eugene Koontz via phunt) + + ZOOKEEPER-1510. Should not log SASL errors for non-secure usage + (Todd Lipcon via phunt) + + ZOOKEEPER-1497. Allow server-side SASL login with JAAS configuration + to be programmatically set (rather than only by reading JAAS + configuration file) (Matteo Bertozzi via phunt) + + ZOOKEEPER-1238. Linger time should be -1 for Netty sockets. (Skye + W-M via henryr) + + ZOOKEEPER-1505. Multi-thread CommitProcessor (Jay Shrauner via phunt) + + ZOOKEEPER-1564. Allow JUnit test build with IBM Java + (Paulo Ricardo Paz Vital via phunt) + + ZOOKEEPER-1598. Ability to support more digits in the version string + (Raja Aluri via phunt) + + ZOOKEEPER-721. Minor cleanup related to the log4j version change + from 1.2.15 -> 1.2.16 (Sean Busbey via phunt) + + ZOOKEEPER-1583. Document maxClientCnxns in conf/zoo_sample.cfg + (Christopher Tubbs via phunt) + + ZOOKEEPER-1584. Adding mvn-install target for deploying the + zookeeper artifacts to .m2 repository (Ashish Singh via phunt) + + ZOOKEEPER-1602. a change to QuorumPeerConfig's API broke + compatibility with HBase (Alexander Shraer via phunt) + + ZOOKEEPER-1335. Add support for --config to zkEnv.sh to specify a config + directory different than what is expected (Arpit Gupta via mahadev) + + ZOOKEEPER-1504. Multi-thread NIOServerCnxn (Jay Shrauner via phunt) + + ZOOKEEPER-1297. Add stat information to create() call + (Lenni Kuff via phunt) + + ZOOKEEPER-1535. ZK Shell/Cli re-executes last command on exit (Edward Ribeiro via camille) + + ZOOKEEPER-1619. Allow spaces in URL (Edward Ribeiro via phunt) + + ZOOKEEPER-1615. minor typos in ZooKeeper Programmer's Guide web page + (Evan Zacks via phunt) + + ZOOKEEPER-1601. document changes for multi-threaded CommitProcessor + and NIOServerCnxn (Thawan Kooburat via phunt) + + ZOOKEEPER-1643. Windows: fetch_and_add not 64bit-compatible, may not be + correct (Erik Anderson via michim) + + ZOOKEEPER-1714 perl client segfaults if ZOO_READ_ACL_UNSAFE constant is used + (Botond Hejj via camille) + + ZOOKEEPER-1719. zkCli.sh, zkServer.sh and zkEnv.sh regression caused by ZOOKEEPER-1663 + (Marshall McMullen via camille) + + ZOOKEEPER-1413. Use on-disk transaction log for learner sync up (thawan) + + ZOOKEEPER-1400. Allow logging via callback instead of raw FILE pointer (michi via fpj) + + ZOOKEEPER-1679. c client: use -Wdeclaration-after-statement (michi via fpj) + + ZOOKEEPER-1750 Race condition producing NPE in NIOServerCnxn.toString + (Rakesh R via michim) + + ZOOKEEPER-1759. Adding ability to allow READ operations for authenticated users, + versus keeping ACLs wide open for READ. (Yuliya Feldman via camille) + + ZOOKEEPER-1552. Enable sync request processor in Observer (thawan, fpj) + + ZOOKEEPER-1758. Add documentation for zookeeper.observer.syncEnabled flag + (thawan, fpj via thawan) + + ZOOKEEPER-1771. ZooInspector authentication (Benjamin Jaton via phunt) + + ZOOKEEPER-1509. Please update documentation to reflect updated + FreeBSD support (George Neville-Neil via phunt) + + ZOOKEEPER-1627. Add org.apache.zookeeper.common to exported packages + in OSGi MANIFEST (Arnoud Glimmerveen via phunt) + + ZOOKEEPER-1715. Upgrade netty version (Sean Bridges via phunt) + + ZOOKEEPER-1666. Avoid Reverse DNS lookup if the hostname in + connection string is literal IP address. (George Cao via camille) + + ZOOKEEPER-1786. ZooKeeper data model documentation is incorrect + (Niraj Tolia via fpj) + + ZOOKEEPER-1430. add maven deploy support to the build + (Giridharan Kesavan via phunt) + + ZOOKEEPER-1440. Spurious log error messages when QuorumCnxManager is shutting + down (Jordan Zimmerman via michim) + + ZOOKEEPER-1638. Redundant zk.getZKDatabase().clear(); (neil bhakta via michim) + + ZOOKEEPER-1796. Move common code from {Follower, Observer}ZooKeeperServer into + LearnerZooKeeperServer (Raul Gutierrez Segales via michim) + + ZOOKEEPER-602. log all exceptions not caught by ZK threads (Rakesh R via + michim) + + ZOOKEEPER-297. centralize version numbering in the source/build (Diego de + Oliveira via michim) + + ZOOKEEPER-1408. CLI: sort output of ls command (Hartmut Lang via michim) + + ZOOKEEPER-1219. LeaderElectionSupport recipe is unnecessarily dispatching the + READY_START event even if the ELECTED node stopped/expired simultaneously. + (Rakesh R via michim) + + ZOOKEEPER-1728. Better error message when reconfig invoked in standalone mode + (Alexander Shraer via michim) + + ZOOKEEPER-1701. When new and old config have the same version, no need to + write new config to disk or create new connections (Alexander Shraer via + michim) + + ZOOKEEPER-1730. Make ZooKeeper easier to test - support simulating a session + expiration (Jordan Zimmerman via michim) + + ZOOKEEPER-1831. Document remove watches details to the guide (Rakesh R via + michim) + + ZOOKEEPER-1575. adding .gitattributes to prevent CRLF and LF mismatches for + source and text files (Raja Aluri via michim) + + ZOOKEEPER-657. Cut down the running time of ZKDatabase corruption + (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-716. dump server memory detail to the log during startup + (Michi Mutsuzaki via rakeshr) + + ZOOKEEPER-1930. A typo in zookeeper recipes.html (Chengwei Yang via michim) + + ZOOKEEPER-1659. Add JMX support for dynamic reconfiguration (Rakesh R via + michim) + + ZOOKEEPER-1928. add configurable throttling to the number of snapshots + concurrently sent by a leader (Edward Carter via fpj) + + ZOOKEEPER-1746. AsyncCallback.*Callback don't have any Javadoc + (Hongchao Deng via phunt) + + ZOOKEEPER-1938. bump version in the C library as we prepare for + 3.5.0 release (Raul Gutierrez Segales via phunt) + + ZOOKEEPER-1576. Zookeeper cluster - failed to connect to cluster if one of the + provided IPs causes java.net.UnknownHostException (Edward Ribeiro via camille) + + ZOOKEEPER-1918. Add 64 bit Windows as a supported development + platform (Michi Mutsuzaki via phunt) + + ZOOKEEPER-1946. Server logging should reflect dynamically + reconfigured address (Niko Vuokko via phunt and Alexander Shraer) + + ZOOKEEPER-1953. Add solution and project files to enable build with current + Visual Studio editions (VS 2012/2013)- 32-bit and 64-bit. + (Orion Hodson via fpj) + + ZOOKEEPER-1968. Make Jetty dependencies optional in ivy.xml + (Bill Havanki via phunt) + + ZOOKEEPER-927. there are currently 24 RAT warnings in the build -- + address directly or via exclusions (Michi Mutsuzaki via phunt) + + ZOOKEEPER-1986. refactor log trace on touchSession + (Hongchao Deng via phunt) + +headers + +Release 3.4.0 - + +Non-backward compatible changes: + +BUGFIXES: + +Backward compatible changes: + +BUGFIXES: + + ZOOKEEPER-735. cppunit test testipv6 assumes that the machine is ipv6 + enabled. (mahadev) + + ZOOKEEPER-720. Use zookeeper-{version}-sources.jar instead of + zookeeper-{version}-src.jar to publish sources in the Maven repository + (paolo via phunt) + + ZOOKEEPER-722. zkServer.sh uses sh's builtin echo on BSD, behaves + incorrectly. (Ivan Kelly via phunt) + + ZOOKEEPER-741. root level create on REST proxy fails (phunt) + + ZOOKEEPER-631. zkpython's C code could do with a style clean-up + (henry robinson via phunt) + + ZOOKEEPER-746. learner outputs session id to log in dec (phunt via + henryr) + + ZOOKEEPER-738. zookeeper.jute.h fails to compile with -pedantic + (Jozef Hatala via phunt) + + ZOOKEEPER-734. QuorumPeerTestBase.java and ZooKeeperServerMainTest.java + do not handle windows path correctly (Vishal K via phunt) + + ZOOKEEPER-754. numerous misspellings "succesfully" + (Andrei Savu via phunt) + + ZOOKEEPER-749. OSGi metadata not included in binary only jar (phunt + via henryr) + + ZOOKEEPER-750. move maven artifacts into "dist-maven" subdir of the + release (package target) (phunt via henryr) + + ZOOKEEPER-758. zkpython segfaults on invalid acl with missing key + (Kapil Thangavelu via henryr) + + ZOOKEEPER-737. some 4 letter words may fail with netcat (nc). (mahadev) + + ZOOKEEPER-764. Observer elected leader due to inconsistent voting view + (henry via mahadev) + + ZOOKEEPER-763. Deadlock on close w/ zkpython / c client + (henry via phunt) + + ZOOKEEPER-774. Recipes tests are slightly outdated: they do not compile + against JUnit 4.8 (Sergey Doroshenko via phunt) + + ZOOKEEPER-772. zkpython segfaults when watcher from async get children is + invoked. (henry via phunt) + + ZOOKEEPER-636. configure.ac has instructions which override the contents of + CFLAGS and CXXFLAGS. (Maxim P. Dementiev via phunt) + + ZOOKEEPER-796. zkServer.sh should support an external PIDFILE variable + (Alex Newman via phunt) + + ZOOKEEPER-719. Add throttling to BookKeeper client (fpj via breed) + + ZOOKEEPER-814. monitoring scripts are missing apache license headers + (andrei savu via mahadev) + + ZOOKEEPER-783. committedLog in ZKDatabase is not properly synchronized + (henry via mahadev) + + ZOOKEEPER-790. Last processed zxid set prematurely while establishing + leadership (flavio via mahadev) + + ZOOKEEPER-795. eventThread isn't shutdown after a connection + "session expired" event coming (Sergey Doroshenko and Ben via mahadev) + + ZOOKEEPER-792. zkpython memory leak (Lei Zhang via henryr) + + ZOOKEEPER-854. BookKeeper does not compile due to changes in the ZooKeeper + code (Flavio via mahadev) + + ZOOKEEPER-861. Missing the test SSL certificate used for running junit tests. + (erwin tam via mahadev) + + ZOOKEEPER-867. ClientTest is failing on hudson - fd cleanup (phunt) + + ZOOKEEPER-785. Zookeeper 3.3.1 shouldn't infinite loop if someone creates a + server.0 line (phunt and Andrei Savu via breed) + + ZOOKEEPER-785. Zookeeper 3.3.1 shouldn't infinite loop if someone creates a + server.0 line (part 2) (phunt) + + ZOOKEEPER-870. Zookeeper trunk build broken. (mahadev via phunt) + + ZOOKEEPER-831. BookKeeper: Throttling improved for reads (breed via fpj) + + ZOOKEEPER-846. zookeeper client doesn't shut down cleanly on the close call + (phunt) + + ZOOKEEPER-804. c unit tests failing due to "assertion cptr failed" (michi + mutsuzaki via mahadev) + + ZOOKEEPER-844. handle auth failure in java client + (Camille Fournier via phunt) + + ZOOKEEPER-822. Leader election taking a long time to complete + (Vishal K via phunt) + + ZOOKEEPER-866. Hedwig Server stays in "disconnected" state when + connection to ZK dies but gets reconnected (erwin tam via breed) + + ZOOKEEPER-881. ZooKeeperServer.loadData loads database twice + (jared cantwell via breed) + + ZOOKEEPER-855. clientPortBindAddress should be clientPortAddress + (Jared Cantwell via fpj) + + ZOOKEEPER-888. c-client / zkpython: Double free corruption on + node watcher (Austin Shoemaker via henryr) + + ZOOKEEPER-893. ZooKeeper high cpu usage when invalid requests + (Thijs Terlouw via phunt) + + ZOOKEEPER-804. c unit tests failing due to "assertion cptr failed" + (second try - Jared Cantwell via phunt) + + ZOOKEEPER-820. update c unit tests to ensure "zombie" java server + processes don't cause failure (Michi Mutsuzaki via phunt) + + ZOOKEEPER-794. Callbacks are not invoked when the client is closed + (Alexis Midon via phunt) + + ZOOKEEPER-800. zoo_add_auth returns ZOK if zookeeper handle is in + ZOO_CLOSED_STATE (michi mutsuzaki via mahadev konar) + + ZOOKEEPER-904. super digest is not actually acting as a full superuser + (Camille Fournier via mahadev) + + ZOOKEEPER-897. C Client seg faults during close (jared cantwell via mahadev) + + ZOOKEEPER-898. C Client might not cleanup correctly during close + (jared cantwell via mahadev) + + ZOOKEEPER-907. Spurious "KeeperErrorCode = Session moved" messages (vishal k via breed) + + ZOOKEEPER-884. Remove LedgerSequence references from BookKeeper documentation and comments in tests (fpj via breed) + + ZOOKEEPER-916. Problem receiving messages from subscribed channels in c++ client (ivan via breed) + + ZOOKEEPER-930. Hedwig c++ client uses a non thread safe logging library (ivan via breed) + + ZOOKEEPER-900. FLE implementation should be improved to use non-blocking sockets (vishal via fpj) + + ZOOKEEPER-937. test -e not available on solaris /bin/sh (Erik Hetzner via mahadev) + + ZOOKEEPER-905. enhance zkServer.sh for easier zookeeper automation-izing (Nicholas Harteau via mahadev) + + ZOOKEEPER-913. Version parser fails to parse "3.3.2-dev" from build.xml (Anthony Urso and phunt via breed) + + ZOOKEEPER-957. zkCleanup.sh doesn't do anything (Ted Dunning via mahadev) + + ZOOKEEPER-958. Flag to turn off autoconsume in hedwig c++ client (Ivan Kelly + via mahadev) + + ZOOKEEPER-882. Startup loads last transaction from snapshot (j:ared via fpj) + + ZOOKEEPER-962. leader/follower coherence issue when follower is receiving a DIFF + (camille fournier via breed) + + ZOOKEEPER-902. Fix findbug issue in trunk "Malicious code vulnerability" + (flavio and phunt via phunt) + + ZOOKEEPER-985. Test BookieRecoveryTest fails on trunk. (fpj via breed) + + ZOOKEEPER-983. running zkServer.sh start remotely using ssh hangs (phunt) + + ZOOKEEPER-976. ZooKeeper startup script doesn't use JAVA_HOME (phunt) + + ZOOKEEPER-994 "eclipse" target in the build script doesnot include + libraray required for test classes in the classpath (MIS via phunt) + + ZOOKEEPER-1013 zkServer.sh usage message should mention all startup options + (eugene koontz via mahadev) + + ZOOKEEPER-1007. iarchive leak in C client (jeremy stribling via mahadev) + + ZOOKEEPER-993. Code improvements (MIS via fpj) + + ZOOKEEPER-1012. support distinct JVMFLAGS for zookeeper server in zkServer.sh + and zookeeper client in zkCli.sh (Eugene Koontz via breed) + + ZOOKEEPER-880. QuorumCnxManager$SendWorker grows without bounds (vishal via breed) + + ZOOKEEPER-1018. The connection permutation in get_addrs uses a weak and inefficient + shuffle (Stephen Tyree via breed) + + ZOOKEEPER-1028. In python bindings, zookeeper.set2() should return a stat dict but + instead returns None. (Chris Medaglia and Ivan Kelly via mahadev) + + ZOOKEEPER-975. new peer goes in LEADING state even if ensemble is online. (vishal via fpj) + + ZOOKEEPER-1049. Session expire/close flooding renders heartbeats to delay significantly. + (chang song via mahadev) + + ZOOKEEPER-1033. c client should install includes into INCDIR/zookeeper, not INCDIR/c-client-src + (Nicholas Harteau via mahadev) + + ZOOKEEPER-1061. Zookeeper stop fails if start called twice. (Ted Dunning via mahadev) + + ZOOKEEPER-1059. stat command isses on non-existing node causes NPE. (Bhallamudi Kamesh via mahadev) + + ZOOKEEPER-1058. fix typo in opToString for getData. (camille) + + ZOOKEEPER-1046. Creating a new sequential node results in a ZNODEEXISTS error. (Vishal K via camille) + + ZOOKEEPER-1069. Calling shutdown() on a QuorumPeer too quickly can lead to a corrupt log. (Vishal K via camille) + + ZOOKEEPER-1083. Javadoc for WatchedEvent not being generated. (Ivan Kelly via michim) + + ZOOKEEPER-1086. zookeeper test jar has non mavenised dependency. (Ivan Kelly via michim) + + ZOOKEEPER-335. zookeeper servers should commit the new leader txn to their logs. (breed) + + ZOOKEEPER-1081. modify leader/follower code to correctly deal with new leader (breed) + + ZOOKEEPER-1082. modify leader election to correctly take into account current epoch (fpj via breed) + + ZOOKEEPER-1060. QuorumPeer takes a long time to shutdown (Vishal via fpj) + + ZOOKEEPER-1087. ForceSync VM arguement not working when set to "no" (Nate Putnam via breed) + + ZOOKEEPER-1068. Documentation and default config suggest incorrect + location for Zookeeper state (Roman Shaposhnik via phunt) + + ZOOKEEPER-1103. In QuorumTest, use the same "for ( .. try { break } + catch { } )" pattern in testFollowersStartAfterLeaders as in + testSessionMove. (Eugene Koontz via phunt) + ZOOKEEPER-1046. Creating a new sequential node results in a ZNODEEXISTS error. (breed via camille) + + ZOOKEEPER-1097. Quota is not correctly rehydrated on snapshot reload (camille via henryr) + + ZOOKEEPER-1046. Small fix: Creating a new sequential node results in a ZNODEEXISTS error. (Vishal K via camille) + + ZOOKEEPER-782. Incorrect C API documentation for Watches. (mahadev via breed) + + ZOOKEEPER-1063. Dubious synchronization in Zookeeper and ClientCnxnSocketNIO classes (Yanick Dufresne via breed) + + ZOOKEEPER-1124. Multiop submitted to non-leader always fails due to timeout (Marshall McMullen via breed) + + ZOOKEEPER-1111. JMXEnv uses System.err instead of logging + (Ivan Kelly via phunt) + + ZOOKEEPER-1027. chroot not transparent in zoo_create() (Thijs Terlouw via + mahadev) + + ZOOKEEPER-1109. Zookeeper service is down when SyncRequestProcessor meets + any exception. (Laxman via mahadev) + + ZOOKEEPER-1134. ClientCnxnSocket string comparison using == rather than equals. + (phunt via mahadev) + + ZOOKEEPER-1119. zkServer stop command incorrectly reading comment lines in + zoo.cfg (phunt via mahadev) + + ZOOKEEPER-1090. Race condition while taking snapshot can lead to not restoring data tree correctly (Vishal K via breed) + + ZOOKEEPER-1138. release audit failing for a number of new files. (phunt via mahadev) + + ZOOKEEPER-1139. jenkins is reporting two warnings, fix these (phunt via mahadev) + + ZOOKEEPER-1142. incorrect stat output (phunt via mahadev) + + ZOOKEEPER-1144. ZooKeeperServer not starting on leader due to a race condition (Vishal K via camille) + + ZOOKEEPER-839. deleteRecursive does not belong to the other methods. + (mahadev) + + ZOOKEEPER-1146. significant regression in client (c/python) performance. + (phunt via mahadev) + + ZOOKEEPER-1150. fix for this patch to compile on windows. (dheeraj + via mahadev) + + ZOOKEEPER-1055. check for duplicate ACLs in addACL() and create(). + (Eugene Koontz via mahadev) + + ZOOKEEPER-1141. zkpython fails tests under python 2.4. (phunt via mahadev) + + ZOOKEEPER-1025. zkCli is overly sensitive to to spaces. (Laxman via camille) + + ZOOKEEPER-1117. zookeeper 3.3.3 fails to build with gcc >= 4.6.1 on + Debian/Ubuntu (James Page via mahadev) + + ZOOKEEPER-1140. server shutdown is not stopping threads. (laxman via mahadev) + + ZOOKEEPER-1051. SIGPIPE in Zookeeper 0.3.* when send'ing after + cluster disconnection (Stephen Tyree via mahadev) + + ZOOKEEPER-1168. ZooKeeper fails to run with IKVM (Andrew Finnell via phunt) + + ZOOKEEPER-1165. better eclipse support in tests (Warren Turkal via phunt) + + ZOOKEEPER-1154. Data inconsistency when the node(s) with the highest zxid is not present at the time of leader election. (Vishal Kathuria via camille) + + ZOOKEEPER-1156. Log truncation truncating log too much - can cause data loss. (Vishal Kathuria via camille) + + ZOOKEEPER-1160. test timeouts are too small (breed via phunt) + + ZOOKEEPER-731. Zookeeper#delete , #create - async versions miss a verb in the javadoc. (Thomas Koch via camille) + + ZOOKEEPER-1108. Various bugs in zoo_add_auth in C. (Dheeraj Agrawal via mahadev) + + ZOOKEEPER-981. Hang in zookeeper_close() in the multi-threaded C client. + (Jeremy Stribling via mahadev) + + ZOOKEEPER-1125. Intermittent java core test failures. (Vishar Kher via mahadev) + + ZOOKEEPER-961. Watch recovery after disconnection when connection string contains a prefix. + (Matthias Spycher via mahadev) + + ZOOKEEPER-1136. NEW_LEADER should be queued not sent to match the Zab 1.0 protocol + on the twiki (breed via mahadev) + + ZOOKEEPER-1189. For an invalid snapshot file(less than 10bytes size) RandomAccessFile + stream is leaking. (Rakesh R via mahadev) + + ZOOKEEPER-1185. Send AuthFailed event to client if SASL authentication fails. + (Eugene Kuntz via mahadev) + + ZOOKEEPER-1181. Fix problems with Kerberos TGT renewal. + (Eugene Koontz via mahadev) + + ZOOKEEPER-1268. problems with read only mode, intermittent test failures + and ERRORs in the log (phunt via mahadev) + + ZOOKEEPER-1270. testEarlyLeaderAbandonment failing intermittently, + quorum formed, no serving. (Flavio, Camille and Alexander Shraer via mahadev) + + ZOOKEEPER-1299. Add winconfig.h file to ignore in release audit. (mahadev) + + ZOOKEEPER-1354. AuthTest.testBadAuthThenSendOtherCommands fails intermittently (phunt via camille) + + ZOOKEEPER-1417. investigate differences in client last zxid handling btw c and java clients (thawan via camille) + +IMPROVEMENTS: + ZOOKEEPER-724. Improve junit test integration - log harness information + (phunt via mahadev) + + ZOOKEEPER-766. forrest recipes docs don't mention the lock/queue recipe + implementations available in the release (phunt via mahadev) + + ZOOKEEPER-769: Leader can treat observers as quorum members + (Sergey Doroshenko via henryr) + + ZOOKEEPER-788: Add server id to message logs + (Ivan Kelly via flavio) + + ZOOKEEPER-789. Improve FLE log messages (flavio via phunt) + + ZOOKEEPER-798. Fixup loggraph for FLE changes (Ivan Kelly via phunt) + + ZOOKEEPER-797 c client source with AI_ADDRCONFIG cannot be compiled with + early glibc (Qian Ye via phunt) + + ZOOKEEPER-790. Last processed zxid set prematurely while establishing leadership + (fpj via breed) + + ZOOKEEPER-821. Add ZooKeeper version information to zkpython (Rich + Schumacher via mahadev) + + ZOOKEEPER-765. Add python example script (Travis and Andrei via mahadev) + + ZOOKEEPER-809. Improved REST Interface (Andrei Savu via phunt) + + ZOOKEEPER-733. use netty to handle client connections (breed and phunt) + + ZOOKEEPER-853. Make zookeeper.is_unrecoverable return True or False + in zkpython (Andrei Savu via henryr) + + ZOOKEEPER-864. Hedwig C++ client improvements (Ivan Kelly via breed) + + ZOOKEEPER-862. Hedwig created ledgers with hardcoded Bookkeeper ensemble and + quorum size. Make these a server config parameter instead. (Erwin T via breed) + + ZOOKEEPER-926. Fork Hadoop common's test-patch.sh and modify for Zookeeper. + (nigel) + + ZOOKEEPER-909. Extract NIO specific code from ClientCnxn + (Thomas Koch via phunt) + + ZOOKEEPER-908. Remove code duplication and inconsistent naming in + ClientCnxn.Packet creation (Thomas Koch via phunt) + + ZOOKEEPER-836. hostlist as string. (Thomas Koch via breed) + + ZOOKEEPER-921. zkPython incorrectly checks for existence of required + ACL elements (Nicholas Knight via henryr) + + ZOOKEEPER-963. Make Forrest work with JDK6 (Carl Steinbach via henryr) + + ZOOKEEPER-500. Async methods shouldnt throw exceptions (fpj via breed) + + ZOOKEEPER-977. passing null for path_buffer in zoo_create (breed via mahadev) + + ZOOKEEPER-465. Ledger size in bytes. (flavio via mahadev) + + ZOOKEEPER-980. allow configuration parameters for log4j.properties + (phunt via mahadev) + + ZOOKEEPER-1042. Generate zookeeper test jar for maven installation + (ivan kelly via breed) + + ZOOKEEPER-1030: Increase default for maxClientCnxns + (Todd Lipcon via breed/mahadev/phunt) + + ZOOKEEPER-850: Switch from log4j to slf4j (Olaf Krische via michim) + + ZOOKEEPER-874. FileTxnSnapLog.restore does not call listener (diogo via fpj) + + ZOOKEEPER-1052. Findbugs warning in QuorumPeer.ResponderThread.run() (fpj via michim) + + ZOOKEEPER-1094. Small improvements to LeaderElection and Vote classes (henryr via breed) + + ZOOKEEPER-1074. zkServer.sh is missing nohup/sleep, which are necessary + for remote invocation. (phunt via mahadev) + + ZOOKEEPER-965. Need a multi-update command to allow multiple znodes to be updated safely (Marshall McMullen and Ted Dunning via breed) + + ZOOKEEPER-1073. address a documentation issue in ZOOKEEPER-1030. (phunt via mahadev) + + ZOOKEEPER-1095. Simple leader election recipe + (Eric Sammer via henry and phunt) + + ZOOKEEPER-1076. some quorum tests are unnecessarily extending QuorumBase (phunt via mahadev) + + ZOOKEEPER-1143. quorum send & recv workers are missing thread names + (phunt via mahadev) + + ZOOKEEPER-1104. CLONE - In QuorumTest, use the same "for ( .. try { break } + catch { } )" pattern in testFollowersStartAfterLeaders as in testSessionMove. + (Eugene Koontz via mahadev) + + ZOOKEEPER-1034. perl bindings should automatically find the zookeeper + c-client headers (nicholas harteau via mahadev) + + ZOOKEEPER-1166. Please add a few svn:ignore properties (via phunt) + + ZOOKEEPER-1169. Fix compiler (eclipse) warnings in (generated) jute + code (Thomas Koch via phunt) + + ZOOKEEPER-1171. fix build for java 7 (phunt via mahadev) + + ZOOKEEPER-1201. Clean SaslServerCallbackHandler.java. (Thomas Koch + via mahadev) + +NEW FEATURES: + ZOOKEEPER-729. Java client API to recursively delete a subtree. + (Kay Kay via henry) + + ZOOKEEPER-747. Add C# generation to Jute (Eric Hauser via phunt) + + ZOOKEEPER-464. Need procedure to garbage collect ledgers + (erwin via fpj) + + ZOOKEEPER-773. Log visualisation (Ivan Kelly via phunt) + + ZOOKEEPER-744. Add monitoring four-letter word (Andrei Savu via phunt) + + ZOOKEEPER-712. Bookie recovery. (erwin tam via breed) + + ZOOKEEPER-799. Add tools and recipes for monitoring as a contrib + (Andrei Savu via phunt) + + ZOOKEEPER-808. Web-based Administrative Interface + (Andrei Savu via phunt) + + ZOOKEEPER-775. A large scale pub/sub system (Erwin, Ivan and Ben via + mahadev) + + ZOOKEEPER-1020. Implement function in C client to determine which host you're currently connected to. (stephen tyree via breed) + + ZOOKEEPER-1038. Move bookkeeper and hedwig code in subversion (breed) + + ZOOKEEPER-784. Server-side functionality for read-only mode (Sergey Doroshenko via henryr) + + ZOOKEEPER-992. MT Native Version of Windows C Client (Dheeraj Agrawal via michim) + + ZOOKEEPER-938. Support Kerberos authentication of clients. (Eugene Koontz + via mahadev) + + ZOOKEEPER-1152. Exceptions thrown from handleAuthentication can cause buffer corruption issues in NIOServer. (camille via breed) + + ZOOKEEPER-999. Create an package integration project (Eric Yang via phunt) + + ZOOKEEPER-1107. automating log and snapshot cleaning (Laxman via phunt) + +DEPRECATION: + ZOOKEEPER-1153. Deprecate AuthFLE and LE. (Flavio Junqueira via mahadev) + +Release 3.3.0 - 2010-03-24 + +Non-backward compatible changes: + +BUGFIXES: + +Backward compatible changes: + +BUGFIXES: + ZOOKEEPER-59. Synchronized block in NIOServerCnxn (fpj via breed) + + ZOOKEEPER-524. DBSizeTest is not really testing anything (breed) + + ZOOKEEPER-469. make sure CPPUNIT_CFLAGS isn't overwritten + (chris via mahadev) + + ZOOKEEPER-471. update zkperl for 3.2.x branch (chris via mahadev) + + ZOOKEEPER-470. include unistd.h for sleep() in c tests (chris via mahadev) + + ZOOKEEPR-460. bad testRetry in cppunit tests (hudson failure) + (giri via mahadev) + + ZOOKEEPER-467. Change log level in BookieHandle. (flavio via mahadev) + + ZOOKEEPER-482. ignore sigpipe in testRetry to avoid silent immediate + failure. (chris via mahadev) + + ZOOKEEPER-487. setdata on root (/) crashes the servers (mahadev via phunt) + + ZOOKEEPER-457. Make ZookeeperMain public, support for HBase (and other) + embedded clients (ryan rawson via phunt) + + ZOOKEEPER-481. Add lastMessageSent to QuorumCnxManager. (flavio via mahadev) + + ZOOKEEPER-479. QuorumHierarchical does not count groups correctly + (flavio via mahadev) + + ZOOKEEPER-466. crash on zookeeper_close() when using auth with empty cert + (Chris Darroch via phunt) + + ZOOKEEPER-480. FLE should perform leader check when node is not leading and + add vote of follower (flavio via mahadev) + + ZOOKEEPER-491. Prevent zero-weight servers from being elected. + (flavio via mahadev) + + ZOOKEEPER-447. zkServer.sh doesn't allow different config files to be + specified on the command line (henry robinson via phunt) + + ZOOKEEPER-493. patch for command line setquota (steve bendiola via phunt) + + ZOOKEEPER-311. handle small path lengths in zoo_create() + (chris barroch via breed) + + ZOOKEEPER-484. Clients get SESSION MOVED exception when switching from + follower to a leader. (mahadev) + + ZOOKEEPER-490. the java docs for session creation are misleading/incomplete + (phunt) + + ZOOKEEPER-501. CnxManagerTest failed on hudson. (flavio via mahadev) + + ZOOKEEPER-499. electionAlg should default to FLE (3) - regression + (phunt via mahadev) + + ZOOKEEPER-477. zkCleanup.sh is flaky (fernando via mahadev) + + ZOOKEEPER-498. Unending Leader Elections : WAN configuration + (flavio via mahadev) + + ZOOKEEPER-508. proposals and commits for DIFF and Truncate messages from the + leader to the followers is buggy. (mahadev and ben via mahadev) + + ZOOKEEPER-518. DEBUG message for outstanding proposals in leader should be + moved to trace. (phunt) + + ZOOKEEPER-533. ant error running clean twice (phunt via mahadev) + + ZOOKEEPER-535. ivy task does not enjoy being defined twice + (build error) (phunt via mahadev) + + ZOOKEEPER-420. build/test should not require install in zkpython + (henry robinson via phunt) + + ZOOKEEPER-538. zookeeper.async causes python to segfault + (henry robinson via phunt) + + ZOOKEEPER-542. c-client can spin when server unresponsive (Christian + Wiedmann via mahadev) + + ZOOKEEEPER-510. zkpython lumps all exceptions as IOError, needs specialized + exceptions for KeeperException types (henry & pat via mahadev) + + ZOOKEEPER-541. zkpython limited to 256 handles (henry robinson via phunt) + + ZOOKEEPER-554. zkpython can segfault when statting a deleted node + (henry robinson via phunt) + + ZOOKEEPER-512. FLE election fails to elect leader (flavio via mahadev) + + ZOOKEEPER-563. ant test for recipes is broken. (mahadev via phunt) + + ZOOKEEPER-562. c client can flood server with pings if tcp send queue + filled. (ben reed via mahadev) + + ZOOKEEPER-537. The zookeeper jar includes the java source files + (Thomas Dudziak via phunt) + + ZOOKEEPER-551. unnecessary SetWatches message on new session. + (phunt via flavio) + + ZOOKEEPER-566. "reqs" four letter word (command port) returns no information + (phunt via breed) + + ZOOKEEPER-567. javadoc for getchildren2 needs to mention "new in 3.3.0" + (phunt via breed) + + ZOOKEEPER-547. Sanity check in QuorumCnxn Manager and quorum communication + port. (mahadev via breed) + + ZOOKEEPER-532. java compiler should be target Java 1.5 + (hiram chirino and phunt via breed) + + ZOOKEEPER-519. Followerhandler should close the socket if it gets an exception + on a write. (mahadev via breed) + + ZOOKEEPER-570. AsyncHammerTest is broken, callbacks need to validate rc + parameter (phunt via breed) + + ZOOKEEPER-3. syncLimit has slightly different comments in the class header, + and > inline with the variable. (mahadev via breed) + + ZOOKEEPER-576. docs need to be updated for session moved exception and how + to handle it (breed via phunt) + + ZOOKEEPER-582. ZooKeeper can revert to old data when a snapshot is created + outside of normal processing (ben reed and mahadev via mahadev) + + ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk + (Patrick Hunt via mahadev) + + ZOOKEEPER-598. LearnerHandler is misspelt in the thread's constructor + (Henry Robinson via fpj) + + ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk (take 2) + (breed) + + ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk + (take 3) (phunt via mahadev) + + ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk + (take 4) (breed via mahadev) + + ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk + (take 5) (mahadev) + + ZOOKEEPER-611. hudson build failiure (mahadev) + + ZOOKEEPER-611. hudson build failure (take 2) (mahadev) + + ZOOKEEPER-615. wrong javadoc for create with a sequence flag + (mahadev via breed) + + ZOOKEEPER-588. remove unnecessary/annoying log of tostring error in + Request.toString() (phunt via breed) + + ZOOKEEPER-587. client should log timeout negotiated with server + (phunt via mahadev) + + ZOOKEEPER-610. cleanup final fields, esp those used for locking + (phunt via henry) + + ZOOKEEPER-614. Improper synchronisation in getClientCnxnCount + (henry via mahadev) + + ZOOKEEPER-609. ObserverTest failure "zk should not be connected expected not + same" (henry robinson via phunt) + + ZOOKEEPER-630. Trunk has duplicate ObserverTest.java files + (henry robinson via phunt) + + ZOOKEEPER-627. zkpython arbitrarily restricts the size of a 'get' to 512 + bytes (henry robinson via mahadev) + + ZOOKEEPER-534. The test target in contib/bookkeeper does not depend on jar + target. (phunt via mahadev) + + ZOOKEEPER-623. ClientBase in bookkeeper.util requires junit (fpj via breed) + + ZOOKEEPER-600. TODO pondering about allocation behavior in zkpython may be + removed (gustavo via mahadev) + + ZOOKEEPER-596. The last logged zxid calculated by zookeeper servers could + cause problems in leader election if data gets corrupted. (mahadev) + + ZOOKEEPER-637. Trunk build is failing (fpj via breed) + + ZOOKEEPER-637. Trunk build is failing - second patch (breed via fpj) + + ZOOKEEPER-644. Nightly build failed on hudson. (pat via mahadev) + + ZOOKEEPER-651: Log exception trace in QuorumCnxManager.SendWorker + (flavio via henry) + + ZOOKEEPER-608. Receipt of ACK from observer should not be logged as ERROR + (henry via mahadev) + + ZOOKEEPER-647. hudson failure in testLeaderShutdown (flavio via mahadev) + + ZOOKEEPER-574. the documentation on snapcount in the admin guide has the + wrong default (phunt via mahadev) + + ZOOKEEPER-656. SledgeHammer test - thread.run() deprecated (kay kay via mahadev) + + ZOOKEEPER-413. two flaws need addressing in the c tests that can cause false + positive failures (phunt via mahadev) + + ZOOKEEPER-495. c client logs an invalid error when zookeeper_init is called + with chroot (phunt via mahadev) + + ZOOKEEPER-589. When create a znode, a NULL ACL parameter cannot be accepted. + (breed via mahadev) + + ZOOKEEPER-673. Fix observer documentation regarding leader election (flavio + via mahadev) + + ZOOKEEPER-672. typo nits across documentation (Kay Kay via mahadev) + + ZOOKEEPER-668. Close method in LedgerInputStream doesn't do anything (flavio + via mahadev) + + ZOOKEEPER-569. Failure of elected leader can lead to never-ending leader + election (henry via flavio) + + ZOOKEEPER-669. watchedevent tostring should clearly output the + state/type/path (phunt via mahadev) + + ZOOKEEPER-683. LogFormatter fails to parse transactional log files (phunt + via mahadev) + + ZOOKEEPER-682. Event is not processed when the watcher is set to watch "/" + if chrooted (Scott Wang via mahadev) + + ZOOKEEPER-687. LENonterminatetest fails on some machines. (mahadev) + + ZOOKEEPER-681. Minor doc issue re unset maxClientCnxns (phunt via mahadev) + + ZOOKEEPER-622. Test for pending watches in send_set_watches should be moved + (ben and steven via mahadev) + + ZOOKEEPER-689. release build broken - ivysettings.xml not copied during + "package" (phunt via mahadev) + + ZOOKEEPER-59. Synchronized block in NIOServerCnxn (flavio via mahadev) + + ZOOKEEPER-691. Interface changed for NIOServer.Factory (breed via mahadev) + + ZOOKEEPER-685. Race in LENonTerminateTest (henry via breed) + + ZOOKEEPER-677. c client doesn't allow ipv6 numeric connect string + (breed & phunt & mahadev via breed) + + ZOOKEEPER-693. TestObserver stuck in tight notification loop in FLE + (flavio via phunt) + + ZOOKEEPER-696. NPE in the hudson logs, seems nioservercnxn closed twice + (phunt via mahadev) + + ZOOKEEPER-511. bad error handling in FollowerHandler.sendPackets + (mahadev via flavio) + + ZOOKEEPER-604. zk needs to prevent export of any symbol not listed in their + api (mahadev) + + ZOOKEEPER-121. SyncRequestProcessor is not closing log stream during + shutdown (mahadev) + + ZOOKEEPER-698. intermittent JMX test failures due to not verifying QuorumPeer + shutdown (phunt) + + ZOOKEEPER-121_2. SyncRequestProcessor is not closing log stream during + shutdown (breed via mahadev) + + ZOOKEEPER-121_3. SyncRequestProcessor is not closing log stream during + shutdown (mahadev via phunt) + + ZOOKEEPER-121_4. SyncRequestProcessor is not closing log stream during + shutdown (mahadev via breed) + + ZOOKEEPER-586. c client does not compile under cygwin (phunt, mahadev, breed via breed) + + ZOOKEEPER-624. The C Client cause core dump when receive error data from + Zookeeper Server (mahadev) + + ZOOKEEPER-591. The C Client cannot exit properly in some situation (mahadev) + + ZOOKEEPER-591_2. The C Client cannot exit properly in some situation + (mahadev via phunt) + + ZOOKEEPER-709. bookkeeper build failing with missing factory + (phunt) + + ZOOKEEPER-708. zkpython failing due to undefined symbol + deallocate_String_vector (mahadev via phunt) + + ZOOKEEPER-436. Bookies should auto register to ZooKeeper (erwin tam & fpj via breed) + + ZOOKEEPER-710. permanent ZSESSIONMOVED error after client app reconnects to zookeeper cluster (phunt via breed) + + ZOOKEEPER-718. the fatjar is missing libraries (ben via mahadev) + + ZOOKEEPER-717. add a preferred list to the instancemanager (breed via + mahadev) + +IMPROVEMENTS: + ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to + "socket reuse" and failure to close client (phunt via mahadev) + + ZOOKEEPER-488. Fix zkServer.sh to add clover.jar in classpath + (Giridharan Kesavan via gkesavan) + + ZOOKEEPER-516. add support for 10 minute test ie "pre-commit" test (phunt) + + ZOOKEEPER-529. Use Ivy to pull dependencies and also generate pom (phunt + via mahadev) + + ZOOKEEPER-530. Memory corruption: Zookeeper c client IPv6 implementation + does not honor struct sockaddr_in6 size (isabel drost via mahadev) + + ZOOKEEPER-549. Refactor Followers and related classes into a Peer->Follower + hierarchy in preparation for Observers (henry robinson via mahadev) + + ZOOKEEPER-472. Making DataNode not instantiate a HashMap when the node is + ephmeral (Erik Holstad via mahadev) + + ZOOKEEPER-425. Add OSGi metadata to zookeeper.jar (david bosschaert via breed) + + ZOOKEEPER-599. Changes to FLE and QuorumCnxManager to support Observers + (fpj via breed) + + ZOOKEEPER-506. QuorumBase should use default leader election (fpj via breed) + + ZOOKEEPER-633. Fetch netty using ivy for bookkeeper (giri via fpj) + + ZOOKEEPER-544. improve client testability - allow test client to access + connected server location (phunt via breed) + + ZOOKEEPER-426. Windows versions of zookeeper scripts + (David Bosschaert via breed) + + ZOOKEEPER-638. upgrade ivy to 2.1.0 final from 2.1.0 release + candidate (phunt via breed) + + ZOOKEEPER-648. Fix releaseaudit warning count to zero (phunt via henry) + + ZOOKEEPER-626. ensure the c/java cli's print xid/sessionid/etc... in hex + (pat via mahadev) + + ZOOKEEPER-655. StringBuffer -> StringBuilder - conversion of references as + necessary (Kay Kay via henry) + + ZOOKEEPER-612. Make Zookeeper C client can be compiled by gcc of early + version (qian via mahadev) + + ZOOKEEPER-456. CREATOR_ALL_ACL has unnecessary PERMS.ADMIN in the + declartion. (phunt via mahadev) + + ZOOKEEPER-593. java client api does not allow client to access negotiated + session timeout (phunt via mahadev) + + ZOOKEEPER-507. BookKeeper client re-write (Utkarsh and ben via mahadev) + + ZOOKEEPER-665. Add BookKeeper streaming documentation (flavio via mahadev) + + ZOOKEEPER-664. BookKeeper API documentation (flavio via mahadev) + + ZOOKEEPER-607. improve bookkeeper overview (flavio via mahadev) + + ZOOKEEPER-485. Need ops documentation that details supervision of ZK server + processes. (phunt via mahadev) + + ZOOKEEPER-658. update forrest docs - AuthFLE no longer supported (flavio via + mahadev) + + ZOOKEEPER-640. make build.xml more configurable to ease packaging for linux + distros (phunt via mahadev) + + ZOOKEEPER-579. zkpython needs more test coverage for ACL code paths (henry + via mahadev) + + ZOOKEEPER-688. explain session expiration better in the docs & faq (phunt + via mahadev) + + ZOOKEEPER-663. hudson failure in ZKDatabaseCorruptionTest (mahadev via henryr) + + ZOOKEEPER-543. Tests for ZooKeeper examples (steven via mahadev) + + ZOOKEEPER-692. upgrade junit to latest version (4.8.1) (phunt via mahadev) + + ZOOKEEPER-601. allow configuration of session timeout min/max bounds (phunt + via mahadev) + + ZOOKEEPER-751. Recipe heading refers to 'recoverable' but should be + 'revocable' (Michi Mutsuzaki via rakeshr) + +NEW FEATURES: + ZOOKEEPER-539. generate eclipse project via ant target. (phunt via mahadev) + + ZOOKEEPER-555. Add stat information to GetChildrenResponse. (Arni Jonson and + phunt via mahadev) + + ZOOKEEPER-550. Java Queue Recipe. (steven cheng via mahadev) + + ZOOKEEPER-368. Observers: core functionality (henry robinson via mahadev) + + ZOOKEEPER-496. zookeeper-tree utility for export, import and incremental + updates (anirban roy via breed) + + ZOOKEEPER-572. add ability for operator to examine state of watches + currently registered with a server (phunt via mahadev) + + ZOOKEEPER-678. Gui browser application to view and edit the contents of a + zookeeper instance (Colin Goodheart-Smithe via phunt) + + ZOOKEEPER-635. Server supports listening on a specified network address (phunt via breed) + +Release 3.2.0 - 2009-06-30 + +Non-backward compatible changes: + +BUGFIXES: + ZOOKEEPER-444. perms definition for PERMS_ALL differ in C and java (mahadev) + +Backward compatible changes: + +BUGFIXES: + ZOOKEEPER-303. Bin scripts dont work on a Mac. (tom white via mahadev) + + ZOOKEEPER-330. zookeeper standalone server does not startup with just a + port and datadir. (chris darroch and mahadev) + + ZOOKEEPER-319. add locking around auth info in zhandle_t. + (chris darroch via mahadev) + + ZOOKEEPER-320. call auth completion in free_completions(). + (chris darroch via mahadev) + + ZOOKEEPER-334. bookkeeper benchmark (testclient.java) has compiling errors. + (flavio and mahadev) + + ZOOKEEPER-281. autoreconf fails for /zookeeper-3.0.1/src/c/ (phunt) + + ZOOKEEPER-318. remove locking in zk_hashtable.c or add locking in + collect_keys() (chris darroch via mahadev) + + ZOOKEEPER-333. helgrind thread issues identified in mt c client code + (mahadev via phunt) + + ZOOKEEPER-309. core dump using zoo_get_acl() (mahadev via phunt) + + ZOOKEEPER-341. regression in QuorumPeerMain, + tickTime from config is lost, cannot start quorum (phunt via mahadev) + + ZOOKEEPER-360. WeakHashMap in Bookie.java causes NPE (flavio via mahadev) + + ZOOKEEPER-362. Issues with FLENewEpochTest. (fix bug in Fast leader election) + (flavio via mahadev) + + ZOOKEEPER-363. NPE when recovering ledger with no hint. (flavio via mahadev) + + ZOOKEEPER-370. Fix critical problems reported by findbugs. + (flavio via mahadev) + + ZOOKEEPER-347. zkfuse uses non-standard String. (patrick hunt via mahadev) + + ZOOKEEPER-355. make validatePath non public in Zookeeper client api. + (phunt via mahadev) + + ZOOKEEPER-374. Uninitialized struct variable in C causes warning which + is treated as an error (phunt via mahadev) + + ZOOKEEPER-337. improve logging in leader election lookForLeader method when + address resolution fails (phunt via mahadev) + + ZOOKEEPER-367. RecoveryTest failure - "unreasonable length" IOException + (mahadev via phunt) + + ZOOKEEPER-346. remove the kill command fro mthe client port. + (phunt via mahadev) + + ZOOKEEPER-377. running ant cppunit tests, a failure still results in + BUILD SUCCESSFUL (giri via mahadev) + + ZOOKEEPER-382. zookeeper cpp tests fails on 64 bit machines with gcc 4.1.2 + (mahadev via phunt) + + ZOOKEEPER-365. javadoc is wrong for setLast in LedgerHandle + (flavio via phunt) + + ZOOKEEPER-392. Change log4j properties in bookkeeper. (flavio via mahadev) + + ZOOKEEPER-400. Issues with procedure to close ledger. (flavio) + + ZOOKEEPER-405. nullpointer exception in zookeeper java shell. + (mahadev via breed) + + ZOOKEEPER-410. address all findbugs warnings in client/server classes. + (phunt via breed) + + ZOOKEEPER-403. cleanup javac compiler warnings. (flavio via breed) + + ZOOKEEPER-407. address all findbugs warnings in + org.apache.zookeeper.server.quorum.** packages. + (flavio via breed) + + ZOOKEEPER-411. Building zookeeper fails on RHEL 5 64 bit during test-cppunit + (mahadev via phunt) + + ZOOKEEPER-402. zookeeper c library segfaults on data for a node in zookeeper + being null. (mahadev via phunt) + + ZOOKEEPER-415. zookeeper c tests hang. (mahadev via phunt) + + ZOOKEEPER-385. crctest failed on hudson patch test (mahadev via phunt) + + ZOOKEEPER-192. trailing whitespace in config file can cause number format + exceptions (phunt via breed) + + ZOOKEEPER-409. address all findbugs warnings in jute related classes + (phunt via breed) + + ZOOKEEPER-416. bookkeeper jar includes unnnecessary files. + (flavio via mahadev) + + ZOOKEEPER-419. Reference counting bug in Python bindings causes abort errors + (henry robinson via phunt) + + ZOOKEEPER-421. zkpython run_tests.sh is missing #! + (henry robinson via phunt) + + ZOOKEEPER-406. address all findbugs warnings in persistence classes. + (phunt et al via breed) + + ZOOKEEPER-435. allow "super" admin digest based auth to be configurable + (phunt via breed) + + ZOOKEEPER-375. zoo_add_auth only retains most recent auth on re-sync. + (mahadev) + + ZOOKEEPER-433. getacl on root znode (/) fails. (phunt via mahadev) + + ZOOKEEPER-408. address all findbugs warnings in persistence classes. + (phunt, mahadev, flavio via mahadev) + + ZOOKEEPER-427. ZooKeeper server unexpectedly high CPU utilisation + (Sergey Zhuravlev via breed) + + ZOOKEEPER-446. some traces of the host auth scheme left (breed via mahadev) + + ZOOKEEPER-438. addauth fails to register auth on new client that's not yet + connected (breed via mahadev) + + ZOOKEEPER-448. png files do nto work with forrest. (mahadev) + + ZOOKEEPER-417. stray message problem when changing servers + (breed via mahadev) + + ZOOKEEPER-449. sesssionmoved in java code and ZCLOSING in C have the same + value. (mahadev) + + ZOOKEEPER-452. zookeeper performance graph should have percentage of reads + rather than percentage of writes - zkperfRW-3.2.jpg (mahadev) + + ZOOKEEPER-450. emphemeral cleanup not happening with session timeout. + (breed via mahadev) + + ZOOKEEPER-453. Worker is not removed in QuorumCnxManager upon crash. + (flavio via mahadev) + + ZOOKEEPER-454. allow compilation with jdk1.5 (phunt) + + ZOOKEEPER-455. zookeeper c client crashes with chroot specified in the string. + (phunt via mahadev) + + ZOOKEEPER-468. avoid compile warning in send_auth_info(). + +IMPROVEMENTS: + ZOOKEEPER-308. improve the atomic broadcast performance 3x. + (breed via mahadev) + + ZOOKEEPER-326. standalone server ignores tickTime configuration. + (chris darroch via mahadev) + + ZOOKEEPER-279. Allow specialization of quorum config parsing + (e.g. variable expansion in zoo.cfg) (Jean-Daniel Cryans via phunt) + + ZOOKEEPER-351. to run checkstyle (giridharan kesavan via mahadev) + + ZOOKEEPER-350. to run rats for releaseaudit. + (giridharan kesavan via mahadev) + + ZOOKEEPER-352. to add standard ant targets required by test-patch.sh script + (giridharan kesavan via mahadev) + + ZOOKEEPER-353. javadoc warnings needs to be fixed. + (giridharan kesavan via mahadev) + + ZOOKEEPER-354. to fix javadoc warning in the source files. (mahadev) + + ZOOKEEPER-349. to automate patch testing. (giridharan kesavan via mahadev) + + ZOOKEEPER-288. Cleanup and fixes to BookKeeper (flavio via mahadev) + + ZOOKEEPER-305. Replace timers with semaphores in FLENewEpochTest. + (flavio via mahadev) + + ZOOKEEPER-60. Get cppunit tests running as part of Hudson CI. + (girish via mahadev) + + ZOOKEEPER-343. add tests that specifically verify the zkmain and + qpmain classes. (phunt via mahadev) + + ZOOKEEPER-361. integrate cppunit testing as part of hudson patch process. + (giri via mahadev) + + ZOOKEEPER-373. One thread per bookie (flavio via mahadev) + + ZOOKEEPER-384. keeper exceptions missing path (phunt via mahadev) + + ZOOKEEPER-380. bookkeeper should have a streaming api so that its easier to + store checpoints/snapshots in bookkeeper. (mahadev via flavio) + + ZOOKEEPER-389. add help/usage to the c shell cli.c (phunt via mahadev) + + ZOOKEEPER-376. ant test target re-compiles cppunit code every time + (phunt via mahadev) + + ZOOKEEPER-391. bookeeper mainline code should not be calling + printStackTrace. (flavio via mahadev) + + ZOOKEEPER-300. zk jmx code is calling printStackTrace when creating bean + name (should not be) (phunt via mahadev) + + ZOOKEEPER-94. JMX tests are needed to verify that the JMX MBeans work + properly (phunt via mahadev) + + ZOOKEEPER-404. nightly build failed on hudson. + (henry robinson and pat via mahadev) + + ZOOKEEPER-345. the CLIs should allow addAuth to be invoked. + (henry robinson via breed) + + ZOOKEEPER-292. commit configure scripts (autotools) to svn for c projects and + include in release (phunt via breed) + + ZOOKEEPER-383. Asynchronous version of createLedger(). (flavio via mahadev) + + ZOOKEEPER-358. Throw exception when ledger does not exist. (flavio via breed) + + ZOOKEEPER-431. Expose methods to ease ZK integration. (Jean-Daniel via breed) + + ZOOKEEPER-396. race condition in zookeeper client library between + zookeeper_close and zoo_synchronous api. (mahadev) + + ZOOKEEPER-196. doxygen comment for state argument of watcher_fn typedef and + implementation differ ("...one of the *_STATE constants, otherwise -1") + (breed via mahadev) + + ZOOKEEPER-336. single bad client can cause server to stop accepting + connections (henry robinson via breed) + + ZOOKEEPER-434. the java shell should indicate connection status on command + prompt (henry robinson via breed) + + ZOOKEEPER-437. Variety of Documentation Updates (grant via mahadev) + + ZOOKEEPER-443. trace logging in watch notification not wrapped with + istraceneabled - inefficient (pat via mahadev) + + ZOOKEEPER-432. Various improvements to zkpython bindings. + (henry via mahadev) + + ZOOKEEPER-428. logging should be makred as warn rathen than error in + NIOServerCnxn. (phunt via mahadev) + + ZOOKEEPER-422. Java CLI should support ephemeral and sequential node creation + (henry via breed) + + ZOOKEEPER-315. add forrest docs for bookkeeper. (flavio via mahadev) + + ZOOKEEPER-329. document how to integrate 3rd party authentication into ZK + server ACLs. (breed via mahadev) + + ZOOKEEPER-356. Masking bookie failure during writes to a ledger + (flavio via breed) + + ZOOKEEPER-327. document effects (latency) of storing large amounts of data + in znodes. (breed via mahadev) + + ZOOKEEPER-264. docs should include a state transition diagram for client + state (breed via mahadev) + + ZOOKEEPER-440. update the performance documentation in forrest + (breed via phunt) + +NEW FEATURES: + + ZOOKEEPER-371. jdiff documentation included in build/release (giri via phunt) + + ZOOKEEPER-78. added a high level protocol/feature - for easy Leader + Election or exclusive Write Lock creation (mahadev via phunt) + + ZOOKEEPER-29. Flexible quorums (flavio via mahadev) + + ZOOKEEPER-378. perl binding for zookeeper (chris darroch via mahadev) + + ZOOKEEPER-386. improve java cli shell. (henry robinson via mahadev) + + ZOOKEEPER-36. REST access to ZooKeeper (phunt via mahadev) + + ZOOKEEPER-395. Python bindings. (henry robinson via mahadev) + + ZOOKEEPER-237. Add a Chroot request (phunt and mahadev) + + +Release 3.1.0 - 2009-02-06 + +Non-backward compatible changes: + +BUGFIXES: + + ZOOKEEPER-255. zoo_set() api does not return stat datastructure. + (avery ching via mahadev) + + ZOOKEEPER-246. review error code definition in both source and docs. + (pat via mahadev) + +Backward compatible changes: + +BUGFIXES: + ZOOKEEPER-211. Not all Mock tests are working (ben via phunt) + + ZOOKEEPER-223. change default level in root logger to INFO. + (pat via mahadev) + + ZOOKEEPER-212. fix the snapshot to be asynchronous. (mahadev and ben) + + ZOOKEEPER-213. fix programmer guide C api docs to be in sync with latest + zookeeper.h (pat via mahadev) + + ZOOKEEPER-219. fix events.poll timeout in watcher test to be longer. + (pat via mahadev) + + ZOOKEEPER-217. Fix errors in config to be thrown as Exceptions. (mahadev) + + ZOOKEEPER-228. fix apache header missing in DBTest. (mahadev) + + ZOOKEEPER-218. fix the error in the barrier example code. (pat via mahadev) + + ZOOKEEPER-206. documentation tab should contain the version number and + other small site changes. (pat via mahadev) + + ZOOKEEPER-226. fix exists calls that fail on server if node has null data. + (mahadev) + + ZOOKEEPER-204. SetWatches needs to be the first message after auth + messages to the server (ben via mahadev) + + ZOOKEEPER-208. Zookeeper C client uses API that are not thread safe, + causing crashes when multiple instances are active. + (austin shoemaker, chris daroch and ben reed via mahadev) + + ZOOKEEPER-227. gcc warning from recordio.h (chris darroch via mahadev) + + ZOOKEEPER-232. fix apache licence header in TestableZookeeper (mahadev) + + ZOOKEEPER-249. QuorumPeer.getClientPort() always returns -1. + (nitay joffe via mahadev) + + ZOOKEEPER-248. QuorumPeer should use Map interface instead of HashMap + implementation. (nitay joffe via mahadev) + + ZOOKEEPER-241. Build of a distro fails after clean target is run. + (patrick hunt via mahadev) + + ZOOKEEPER-245. update readme/quickstart to be release tar, rather than + source, based (patrick hunt via mahadev) + + ZOOKEEPER-251. NullPointerException stopping and starting Zookeeper servers + (mahadev via phunt) + + ZOOKEEPER-250. isvalidsnapshot should handle the case of 0 snapshot + files better. (mahadev via phunt) + + ZOOKEEPER-265. remove (deprecate) unused NoSyncConnected from KeeperState. + (phunt via mahadev) + + ZOOKEEPER-273. Zookeeper c client build should not depend on CPPUNIT. (pat +and runping via mahadev) + + ZOOKEEPER-268. tostring on jute generated objects can cause NPE. (pat via mahadev) + + ZOOKEEPER-267. java client incorrectly generating syncdisconnected event when in disconnected state. (pat via breed) + + ZOOKEEPER-263. document connection host:port as comma separated list in forrest docs (pat via breed) + + ZOOKEEPER-275. Bug in FastLeaderElection. (flavio via mahadev) + + ZOOKEEPER-272. getchildren can fail for large number of children. (mahadev) + + ZOOKEEPER-16. Need to do path validation. (pat, mahadev) + + ZOOKEEPER-252. PurgeTxnLog is not handling the new dataDir directory + structure (mahadev via phunt) + + ZOOKEEPER-291. regression for legacy code using KeeperException.Code + constants (due to 246). (pat via mahadev) + + ZOOKEEPER-255. zoo_set() api does not return stat datastructure. + (avery ching via mahadev) + + ZOOKEEPER-293. zoo_set needs to be abi compatible (3.1 changed the +signature), fix this by adding zoo_set2 (pat via mahadev) + + ZOOKEEPER-302. Quote values in JMX objectnames. (tom and pat via mahadev) + +IMPROVEMENTS: + + ZOOKEEPER-64. Log system env information when initializing server and + client (pat via mahadev) + + ZOOKEEPER-243. add SEQUENCE flag documentation to the programming guide. + (patrick hunt via mahadev) + + ZOOKEEPER-161. Content needed: "Designing a ZooKeeper Deployment" + (breed via phunt) + + ZOOKEEPER-247. fix formatting of C API in ACL section of programmer guide. + (patrick hunt via mahadev) + + ZOOKEEPER-230. Improvements to FLE. (Flavio via mahadev) + + ZOOKEEPER-225. c client should log an info message in zookeeper_init + detailing connection parameters. (pat via mahadev) + + ZOOKEEPER-222. print C client log message timestamp in human readable + form. (pat via mahadev) + + ZOOKEEPER-256. support use of JMX to manage log4j configuration at runtime. + (pat via mahadev) + + ZOOKEEPER-214. add new "stat reset" command to server admin port. + (pat via mahadev) + + ZOOKEEPER-258. docs incorrectly state max client timeout as 60 seconds + (it's based on server ticktime). (phunt via mahadev) + + ZOOKEEPER-135. Fat jar build target. (phunt and breed via mahadev) + + ZOOKEEPER-234. Eliminate using statics to initialize the sever. Should + allow server to be more embeddable in OSGi enviorments. (phunt) + + ZOOKEEPER-259. cleanup the logging levels used (use the correct level) + and messages generated. (phunt via breed) + + ZOOKEEPER-210. Require Java 6. (phunt via breed) + + ZOOKEEPER-177. needed: docs for JMX (phunt via mahadev) + + ZOOKEEPER-253. documentation of DataWatcher state transition is misleading +regarding auto watch reset on reconnect. (phunt via mahadev) + + ZOOKEEPER-269. connectionloss- add more documentation to detail. (phunt and +flavio via mahadev) + + ZOOKEEPER-260. document the recommended values for server id's + (mahadev via phunt) + + ZOOKEEPER-215. expand system test environment (breed via phunt) + + ZOOKEEPER-229. improve documentation regarding user's responsibility to + cleanup datadir (snaps/logs) (mahadev via phunt) + + ZOOKEEPER-69. ZooKeeper logo + + ZOOKEEPER-286. Make GenerateLoad use InstanceContainers. (breed via mahadev) + + ZOOKEEPER-220. programming guide watches section should clarify + server/clientlib role in data/child watch maint. (breed via phunt) + + ZOOKEEPER-289. add debug messages to nioserver select loop. (mahadev) + +NEW FEATURES: + + ZOOKEEPER-276. Bookkeeper contribution (Flavio and Luca Telloli via mahadev) + + ZOOKEEPER-231. Quotas in ZooKeeper. (mahadev) + +Release 3.0.0 - 2008-10-21 + +Non-backward compatible changes: + + ZOOKEEPER-43. Server side of auto reset watches. (breed via mahadev) + + ZOOKEEPER-132. Create Enum to replace CreateFlag in ZooKepper.create + method (Jakob Homan via phunt) + + ZOOKEEPER-139. Create Enums for WatcherEvent's KeeperState and EventType + (Jakob Homan via phunt) + + ZOOKEEPER-18. keeper state inconsistency (Jakob Homan via phunt) + + ZOOKEEPER-38. headers (version+) in log/snap files (Andrew Kornev and Mahadev + Konar via breed) + + ZOOKEEPER-8. Stat enchaned to include num of children and size + (phunt) + + ZOOKEEPER-6. List of problem identifiers in zookeeper.h + (phunt) + + ZOOKEEPER-7. Use enums rather than ints for types and state + (Jakob Homan via mahadev) + + ZOOKEEPER-27. Unique DB identifiers for servers and clients + (mahadev) + + ZOOKEEPER-32. CRCs for ZooKeeper data + (mahadev) + + ZOOKEEPER-33. Better ACL management + (mahadev) + +Backward compatible changes: + + BUGFIXES: + + ZOOKEEPER-203. fix datadir typo in releasenotes (phunt) + + ZOOKEEPER-145. write detailed release notes for users migrating from 2.x + to 3.0 (phunt) + + ZOOKEEPER-23. Auto reset of watches on reconnect (breed via phunt) + + ZOOKEEPER-191. forrest docs for upgrade. (mahadev via phunt) + + ZOOKEEPER-201. validate magic number when reading snapshot and transaction + logs (mahadev via phunt) + + ZOOKEEPER-200. the magic number for snapshot and log must be different + (currently same) (phunt) + + ZOOKEEPER-199. fix log messages in persistence code (mahadev via phunt) + + ZOOKEEPER-197. create checksums for snapshots (mahadev via phunt) + + ZOOKEEPER-198. apache license header missing from FollowerSyncRequest.java + (phunt) + + ZOOKEEPER-5. Upgrade Feature in Zookeeper server. (mahadev via phunt) + + ZOOKEEPER-194. Fix terminology in zookeeperAdmin.xml + (Flavio Paiva Junqueira) + + ZOOKEEPER-151. Document change to server configuration + (Flavio Paiva Junqueira) + + ZOOKEEPER-193. update java example doc to compile with latest zookeeper + (phunt) + + ZOOKEEPER-187. CreateMode api docs missing (phunt) + + ZOOKEEPER-186. add new "releasenotes.xml" to forrest documentation + (phunt) + + ZOOKEEPER-190. Reorg links to docs and navs to docs into related sections + (robbie via phunt) + + ZOOKEEPER-189. forrest build not validated xml of input documents + (robbie via phunt) + + ZOOKEEPER-188. Check that election port is present for all servers + (Flavio Paiva Junqueira via phunt) + + ZOOKEEPER-185. Improved version of FLETest (Flavio Paiva Junqueira) + + ZOOKEEPER-184. tests: An explicit include derective is needed for the usage + of memcpy(), memset(), strlen(), strdup() and free() functions + (Maxim P. Dementiev via phunt) + + ZOOKEEPER-183. Array subscript is above array bounds in od_completion(), + src/cli.c. (Maxim P. Dementiev via phunt) + + ZOOKEEPER-182. zookeeper_init accepts empty host-port string and returns + valid pointer to zhandle_t. (Maxim P. Dementiev via phunt) + + ZOOKEEPER-17. zookeeper_init doc needs clarification (phunt) + + ZOOKEEPER-181. Some Source Forge Documents did not get moved over: + javaExample, zookeeperTutorial, zookeeperInternals (robbie via phunt) + + ZOOKEEPER-180. Placeholder sections needed in document for new topics that + the umbrella jira discusses (robbie via phunt) + + ZOOKEEPER-179. Programmer's Guide "Basic Operations" section is missing + content (robbie via phunt) + + ZOOKEEPER-178. FLE test. (Flavio Paiva Junqueira) + + ZOOKEEPER-159. Cover two corner cases of leader election + (Flavio Paiva Junqueira via phunt) + + ZOOKEEPER-156. update programmer guide with acl details from old wiki page + (phunt) + + ZOOKEEPER-154. reliability graph diagram in overview doc needs context + (phunt) + + ZOOKEEPER-157. Peer can't find existing leader (Flavio Paiva Junqueira) + + ZOOKEEPER-155. improve "the zookeeper project" section of overview doc + (phunt) + + ZOOKEEPER-140. Deadlock in QuorumCnxManager (Flavio Paiva Junqueira) + + ZOOKEEPER-147. This is version of the documents with most of the [tbd...] + scrubbed out (robbie via phunt) + + ZOOKEEPER-150. zookeeper build broken (mahadev via phunt) + + ZOOKEEPER-136. sync causes hang in all followers of quorum. (breed) + + ZOOKEEPER-134. findbugs cleanup (phunt) + + ZOOKEEPER-133. hudson tests failing intermittently (phunt) + + ZOOKEEPER-144. add tostring support for watcher event, and enums for event + type/state (Jakob Homan via phunt) + + ZOOKEEPER-21. Improve zk ctor/watcher (state transition) docs (phunt) + + ZOOKEEPER-142. Provide Javadoc as to the maximum size of the data byte + array that may be stored within a znode (Jakob Homan via phunt) + + ZOOKEEPER-93. Create Documentation for Zookeeper (phunt) + + ZOOKEEPER-117. threading issues in Leader election (fpj via breed) + + ZOOKEEPER-137. client watcher objects can lose events (phunt via breed) + + ZOOKEEPER-131. Old leader election can elect a dead leader over and over + again (breed via mahadev) + + ZOOKEEPER-130. update build.xml to support apache release process + (phunt via mahadev) + + ZOOKEEPER-118. findbugs flagged switch statement in + followerrequestprocessor.run() (Flavio Paiva Junqueira via phunt) + + ZOOKEEPER-115. Potential NPE in QuorumCnxManager + (Flavio Paiva Junqueira) + + ZOOKEEPER-114. cleanup ugly event messages in zookeeper client + (Jakob Homan) + + ZOOKEEPER-112. src/java/main ZooKeeper.java has test code embedded into it. + (phunt) + + ZOOKEEPER-39. Use Watcher objects rather than boolean on read operations. + (Andrew Kornev) + + ZOOKEEPER-97. supports optional output directory in code generator. (Hiram + Chirino via phunt) + + ZOOKEEPER-101. Integrate ZooKeeper with "violations" feature on hudson + (phunt) + + ZOOKEEPER-105. Catch Zookeeper exceptions and print on the stderr. + (Anthony Urso via Mahadev) + + ZOOKEEPER-42. Change Leader Election to fast tcp. (Flavio Paiva Junqueira + via phunt) + + ZOOKEEPER-48. auth_id now handled correctly when no auth ids present + (Benjamin Reed via phunt) + + ZOOKEEPER-44. Create sequence flag children with prefixes of 0's so that + they can be lexicographically sorted. (Jakob Homan via mahadev) + + ZOOKEEPER-108. Fix sync operation reordering on a Quorum. + (Flavio Paiva Junqueira via Mahadev) + + ZOOKEEPER-25. Fuse module for Zookeeper. (Swee Lim, Bart, Patrick Hunt and + Andrew Kornev via Mahadev) + + ZOOKEEPER-58. Race condition on ClientCnxn.java (breed) + + ZOOKEEPER-56. Add clover support to build.xml. (Patrick Hunt via mahadev) + + ZOOKEEPER-75. register the ZooKeeper mailing lists with nabble.com (phunt) + + ZOOKEEPER-54. remove sleeps in the tests. (phunt) + + ZOOKEEPER-55. build.xml failes to retrieve a release number from SVN and + the ant target "dist" fails (Andrew Kornev) + + ZOOKEEPER-89. invoke WhenOwnerListener.whenNotOwner() when the ZK + connection fails (james strachan) + + ZOOKEEPER-90. invoke WhenOwnerListener.whenNotOwner() when the ZK + session expires and the znode is the leader (james strachan) + + ZOOKEEPER-82. Make the ZooKeeperServer more DI friendly. (Hiram Chirino via + mahadev) + + ZOOKEEPER-110. Build script relies on svnant, which is not compatible + with subversion 1.5 working copies (Jakob Homan) + + ZOOKEEPER-111. Significant cleanup of existing tests. (Patrick Hunt via + mahadev) + + ZOOKEEPER-122. Fix NPE in jute's Utils.toCSVString. (Anthony Urso via + mahadev) + + ZOOKEEPER-123. Fix the wrong class is specified for the logger. (Jakob Homan + via mahadev) + + ZOOKEEPER-2. Fix synchronization issues in QuorumPeer and FastLeader + election. (Flavio Paiva Junqueira via mahadev) + + ZOOKEEPER-125. Remove unwanted class declaration in FastLeaderElection. + (Flavio Paiva Junqueira via mahadev) + + ZOOKEEPER-61. Address (remove) use of sleep(#) in client/server test cases. + (phunt) + + ZOOKEEPER-75. cleanup the library directory (phunt) + + ZOOKEEPER-109. cleanup of NPE and Resource issue nits found by static + analysis (phunt) + + ZOOKEEPER-76. Commit 677109 removed the cobertura library, but not the + build targets. (phunt) + + ZOOKEEPER-63. Race condition in client close() operation. (phunt via breed) + + ZOOKEEPER-70. Add skeleton forrest doc structure for ZooKeeper (phunt) + + ZOOKEEPER-79. Document jacob's leader election on the wiki recipes page + (Flavio Junqueira) + + ZOOKEEPER-73. Move ZK wiki from SourceForge to Apache (phunt) + + ZOOKEEPER-72. Initial creation/setup of ZooKeeper ASF site. (phunt) + + ZOOKEEPER-71. Determine what to do re ZooKeeper Changelog(s) (mahadev) + + ZOOKEEPER-68. parseACLs in ZooKeeper.java fails to parse elements of ACL, + should be lastIndexOf rather than IndexOf (mahadev) + + ZOOKEEPER-130. update build.xml to support apache release process. + (phunt via mahadev) + + ZOOKEEPER-131. Fix Old leader election can elect a dead leader over and over + again. (breed via mahadev) + + ZOOKEEPER-137. client watcher objects can lose events (Patrick Hunt via breed) + + ZOOKEEPER-117. threading issues in Leader election (Flavio Junqueira and + Patrick Hunt via breed) + + ZOOKEEPER-128. test coverage on async client operations needs to be improved + (phunt) + + ZOOKEEPER-127. Use of non-standard election ports in config breaks services + (Mark Harwood and Flavio Junqueira via breed) + + ZOOKEEPER-53. tests failing on solaris. (phunt) + + ZOOKEEPER-172. FLE Test (Flavio Junqueira via breed) + + ZOOKEEPER-41. Sample startup script (mahadev) + + ZOOKEEPER-33. Better ACL management (Mahadev Konar) + + ZOOKEEPER-49. SetACL does not work (breed) + + ZOOKEEPER-20. Child watches are not triggered when the node is deleted + (phunt) + + ZOOKEEPER-15. handle failure better in build.xml:test (phunt) + + ZOOKEEPER-11. ArrayList is used instead of List (phunt) + + ZOOKEEPER-45. Restructure the SVN repository after initial import (phunt) + + ZOOKEEPER-1. Initial ZooKeeper code contribution from Yahoo! (phunt) diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 00000000000..5689ab64643 --- /dev/null +++ b/NOTICE.txt @@ -0,0 +1,5 @@ +Apache ZooKeeper +Copyright 2009-2014 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/README.txt b/README.txt new file mode 100644 index 00000000000..ab1fb710e79 --- /dev/null +++ b/README.txt @@ -0,0 +1,37 @@ +For the latest information about Apache ZooKeeper, please visit our website at: + + http://zookeeper.apache.org/ + +and our wiki, at: + + https://cwiki.apache.org/confluence/display/ZOOKEEPER + +Full documentation for this release can also be found in docs/index.html + +--------------------------- +Packaging/release artifacts + +The release artifact contains the following jar file at the top level: + +zookeeper-.jar - legacy jar file which contains all classes + and source files. Prior to version 3.3.0 this + was the only jar file available. It has the + benefit of having the source included (for + debugging purposes) however is also larger as + a result + +The release artifact contains the following jar files in "dist-maven" directory: + +zookeeper-.jar - bin (binary) jar - contains only class (*.class) files +zookeeper--sources.jar - contains only src (*.java) files +zookeeper--javadoc.jar - contains only javadoc files + +These bin/src/javadoc jars were added specifically to support Maven/Ivy which have +the ability to pull these down automatically as part of your build process. +The contents of the legacy jar and the bin + sources jars are the same. + +As of version 3.3.0, the bin, sources and javadoc jars contained in the +dist-maven directory are deployed to the central repository after the release +is voted on and approved by the Apache ZooKeeper PMC: + + https://repo1.maven.org/maven2/org/apache/zookeeper/zookeeper/ diff --git a/README_packaging.txt b/README_packaging.txt new file mode 100644 index 00000000000..2a01cf148aa --- /dev/null +++ b/README_packaging.txt @@ -0,0 +1,66 @@ +README file for Packaging Notes + +Requirement +----------- + +ant (recommended version 1.9.4 or later for concurrent JUnit test execution) +gcc, cppunit and python-setuptools are required to build +C and python bindings. + +On RHEL machine: + +yum install cppunit +yum install python-setuptools + +On Ubuntu: + +apt-get --install cppunit +apt-get --install python-setuptools + +Package build command +--------------------- + +Command to build Debian package: ant deb +Command to build RPM Package: ant rpm + +rpm and deb packages are generated and placed in: + +build/zookeeper*.[rpm|deb] +build/contrib/**.[rpm|deb] + +Default package file structure layout + + /usr/bin - User executable + /usr/sbin - System executable + /usr/libexec - Configuration boot trap script + /usr/lib - Native libraries + /usr/share/doc/zookeeper - Documents + /usr/share/zookeeper - Project files + /usr/share/zookeeper/template/conf - Configuration template files + /etc/zookeeper - Configuration files + /etc/init.d/zookeeper - OS startup script + +Source file structure layout +--------------------- + +src/packages/update-zookeeper-env.sh + - setup environment variables and symlink $PREFIX/etc/zookeeper to + /etc/zookeeper. + - This script is designed to run in post installation, and pre-remove + phase of ZooKeeper package. + - Run update-zookeeper-env.sh -h to get a list of supported parameters. + +src/packages/template + - Standard configuration template + +src/packages/deb + Meta data for creating Debian package + +src/packages/deb/init.d + Daemon start/stop script for Debian flavor of Linux + +src/packages/rpm + Meta data for creating RPM package + +src/packages/rpm/init.d + Daemon start/stop script for Redhat flavor of Linux diff --git a/bin/README.txt b/bin/README.txt new file mode 100644 index 00000000000..e70506dd711 --- /dev/null +++ b/bin/README.txt @@ -0,0 +1,6 @@ +This directory contain scripts that allow easy access (classpath in particular) +to the ZooKeeper server and command line client. + +Files ending in .sh are unix and cygwin compatible + +Files ending in .cmd are msdos/windows compatible diff --git a/bin/zkCleanup.sh b/bin/zkCleanup.sh new file mode 100755 index 00000000000..331094b3ca2 --- /dev/null +++ b/bin/zkCleanup.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This script cleans up old transaction logs and snapshots +# + +# +# If this scripted is run out of /usr/bin or some other system bin directory +# it should be linked to and not copied. Things like java jar files are found +# relative to the canonical path of this script. +# + +# use POSTIX interface, symlink is followed automatically +ZOOBIN="${BASH_SOURCE-$0}" +ZOOBIN="$(dirname "${ZOOBIN}")" +ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)" + +if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then + . "$ZOOBINDIR"/../libexec/zkEnv.sh +else + . "$ZOOBINDIR"/zkEnv.sh +fi + +ZOODATADIR="$(grep "^[[:space:]]*dataDir=" "$ZOOCFG" | sed -e 's/.*=//')" +ZOODATALOGDIR="$(grep "^[[:space:]]*dataLogDir=" "$ZOOCFG" | sed -e 's/.*=//')" + +ZOO_LOG_FILE=zookeeper-$USER-cleanup-$HOSTNAME.log + +if [ "x$ZOODATALOGDIR" = "x" ] +then +"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \ + -cp "$CLASSPATH" $JVMFLAGS \ + org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" $* +else +"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \ + -cp "$CLASSPATH" $JVMFLAGS \ + org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" $* +fi diff --git a/bin/zkCli.cmd b/bin/zkCli.cmd new file mode 100644 index 00000000000..6faf7e6dead --- /dev/null +++ b/bin/zkCli.cmd @@ -0,0 +1,26 @@ +@echo off +REM Licensed to the Apache Software Foundation (ASF) under one or more +REM contributor license agreements. See the NOTICE file distributed with +REM this work for additional information regarding copyright ownership. +REM The ASF licenses this file to You under the Apache License, Version 2.0 +REM (the "License"); you may not use this file except in compliance with +REM the License. You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +setlocal +call "%~dp0zkEnv.cmd" + +ZOO_LOG_FILE=zookeeper-%USERNAME%-cli-%COMPUTERNAME%.log + +set ZOOMAIN=org.apache.zookeeper.ZooKeeperMain +call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" "-Dzookeeper.log.file=%ZOO_LOG_FILE%" -cp "%CLASSPATH%" %ZOOMAIN% %* + +endlocal + diff --git a/bin/zkCli.sh b/bin/zkCli.sh new file mode 100755 index 00000000000..7e1b1c4ccfa --- /dev/null +++ b/bin/zkCli.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This script cleans up old transaction logs and snapshots +# + +# +# If this scripted is run out of /usr/bin or some other system bin directory +# it should be linked to and not copied. Things like java jar files are found +# relative to the canonical path of this script. +# + +# use POSTIX interface, symlink is followed automatically +ZOOBIN="${BASH_SOURCE-$0}" +ZOOBIN="$(dirname "${ZOOBIN}")" +ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)" + +if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then + . "$ZOOBINDIR"/../libexec/zkEnv.sh +else + . "$ZOOBINDIR"/zkEnv.sh +fi + +ZOO_LOG_FILE=zookeeper-$USER-cli-$HOSTNAME.log + +"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \ + -cp "$CLASSPATH" $CLIENT_JVMFLAGS $JVMFLAGS \ + org.apache.zookeeper.ZooKeeperMain "$@" diff --git a/bin/zkEnv.cmd b/bin/zkEnv.cmd new file mode 100644 index 00000000000..786c90e8e87 --- /dev/null +++ b/bin/zkEnv.cmd @@ -0,0 +1,50 @@ +@echo off +REM Licensed to the Apache Software Foundation (ASF) under one or more +REM contributor license agreements. See the NOTICE file distributed with +REM this work for additional information regarding copyright ownership. +REM The ASF licenses this file to You under the Apache License, Version 2.0 +REM (the "License"); you may not use this file except in compliance with +REM the License. You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +set ZOOCFGDIR=%~dp0%..\conf +set ZOO_LOG_DIR=%~dp0%..\logs +set ZOO_LOG4J_PROP=INFO,CONSOLE + +REM for sanity sake assume Java 1.6 +REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html + +REM add the zoocfg dir to classpath +set CLASSPATH=%ZOOCFGDIR% + +REM make it work in the release +SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH% + +REM make it work for developers +SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH% + +set ZOOCFG=%ZOOCFGDIR%\zoo.cfg + +@REM setup java environment variables + +if not defined JAVA_HOME ( + echo Error: JAVA_HOME is not set. + goto :eof +) + +set JAVA_HOME=%JAVA_HOME:"=% + +if not exist "%JAVA_HOME%"\bin\java.exe ( + echo Error: JAVA_HOME is incorrectly set. + goto :eof +) + +set JAVA="%JAVA_HOME%"\bin\java + diff --git a/bin/zkEnv.sh b/bin/zkEnv.sh new file mode 100755 index 00000000000..9806a4b5055 --- /dev/null +++ b/bin/zkEnv.sh @@ -0,0 +1,140 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script should be sourced into other zookeeper +# scripts to setup the env variables + +# We use ZOOCFGDIR if defined, +# otherwise we use /etc/zookeeper +# or the conf directory that is +# a sibling of this script's directory. +# Or you can specify the ZOOCFGDIR using the +# '--config' option in the command line. + +ZOOBINDIR="${ZOOBINDIR:-/usr/bin}" +ZOOKEEPER_PREFIX="${ZOOBINDIR}/.." + +#check to see if the conf dir is given as an optional argument +if [ $# -gt 1 ] +then + if [ "--config" = "$1" ] + then + shift + confdir=$1 + shift + ZOOCFGDIR=$confdir + fi +fi + +if [ "x$ZOOCFGDIR" = "x" ] +then + if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then + ZOOCFGDIR="$ZOOBINDIR/../conf" + else + ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper" + fi +fi + +if [ -f "${ZOOCFGDIR}/zookeeper-env.sh" ]; then + . "${ZOOCFGDIR}/zookeeper-env.sh" +fi + +if [ "x$ZOOCFG" = "x" ] +then + ZOOCFG="zoo.cfg" +fi + +ZOOCFG="$ZOOCFGDIR/$ZOOCFG" + +if [ -f "$ZOOCFGDIR/java.env" ] +then + . "$ZOOCFGDIR/java.env" +fi + +if [ "x${ZOO_LOG_DIR}" = "x" ] +then + ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs" +fi + +if [ "x${ZOO_LOG4J_PROP}" = "x" ] +then + ZOO_LOG4J_PROP="INFO,CONSOLE" +fi + +if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then + JAVA="$JAVA_HOME/bin/java" +elif type -p java; then + JAVA=java +else + echo "Error: JAVA_HOME is not set and java could not be found in PATH." 1>&2 + exit 1 +fi + +#add the zoocfg dir to classpath +CLASSPATH="$ZOOCFGDIR:$CLASSPATH" + +for i in "$ZOOBINDIR"/../src/java/lib/*.jar +do + CLASSPATH="$i:$CLASSPATH" +done + +#make it work in the binary package +#(use array for LIBPATH to account for spaces within wildcard expansion) +if ls "${ZOOKEEPER_PREFIX}"/share/zookeeper/zookeeper-*.jar > /dev/null 2>&1; then + LIBPATH=("${ZOOKEEPER_PREFIX}"/share/zookeeper/*.jar) +else + #release tarball format + for i in "$ZOOBINDIR"/../zookeeper-*.jar + do + CLASSPATH="$i:$CLASSPATH" + done + LIBPATH=("${ZOOBINDIR}"/../lib/*.jar) +fi + +for i in "${LIBPATH[@]}" +do + CLASSPATH="$i:$CLASSPATH" +done + +#make it work for developers +for d in "$ZOOBINDIR"/../build/lib/*.jar +do + CLASSPATH="$d:$CLASSPATH" +done + +#make it work for developers +CLASSPATH="$ZOOBINDIR/../build/classes:$CLASSPATH" + +case "`uname`" in + CYGWIN*) cygwin=true ;; + *) cygwin=false ;; +esac + +if $cygwin +then + CLASSPATH=`cygpath -wp "$CLASSPATH"` +fi + +#echo "CLASSPATH=$CLASSPATH" + +# default heap for zookeeper server +ZK_SERVER_HEAP="${ZK_SERVER_HEAP:-1000}" +export SERVER_JVMFLAGS="-Xmx${ZK_SERVER_HEAP}m $SERVER_JVMFLAGS" + +# default heap for zookeeper client +ZK_CLIENT_HEAP="${ZK_CLIENT_HEAP:-256}" +export CLIENT_JVMFLAGS="-Xmx${ZK_CLIENT_HEAP}m $CLIENT_JVMFLAGS" diff --git a/bin/zkServer-initialize.sh b/bin/zkServer-initialize.sh new file mode 100755 index 00000000000..d76544e7aa8 --- /dev/null +++ b/bin/zkServer-initialize.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# If this scripted is run out of /usr/bin or some other system bin directory +# it should be linked to and not copied. Things like java jar files are found +# relative to the canonical path of this script. +# + +# use POSIX interface, symlink is followed automatically +ZOOBIN="${BASH_SOURCE-$0}" +ZOOBIN="$(dirname "${ZOOBIN}")" +ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)" + +if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then + . "$ZOOBINDIR"/../libexec/zkEnv.sh +else + . "$ZOOBINDIR"/zkEnv.sh +fi + +usage() { + # the configfile will be properly formatted as long as the + # configfile path is less then 40 chars, otw the line will look a + # bit weird, but otherwise it's fine + printf "usage: $0 + Optional parameters: + -h Display this message + --help Display this message + --configfile=%-40s ZooKeeper config file + --myid=# Set the myid to be used, if any (1-255) + --force Force creation of the data/txnlog dirs +" "$ZOOCFG" + exit 1 +} + +OPTS=$(getopt \ + -n $0 \ + -o 'h' \ + -l 'help' \ + -l 'configfile:' \ + -l 'myid:' \ + -l 'force' \ + -- "$@") + +if [ $? != 0 ] ; then + usage + exit 1 +fi + +initialize() { + if [ ! -e "$ZOOCFG" ]; then + echo "Unable to find config file at $ZOOCFG" + exit 1 + fi + + ZOO_DATADIR="$(grep "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')" + ZOO_DATALOGDIR="$(grep "^[[:space:]]*dataLogDir" "$ZOOCFG" | sed -e 's/.*=//')" + + if [ -z "$ZOO_DATADIR" ]; then + echo "Unable to determine dataDir from $ZOOCFG" + exit 1 + fi + + if [ $FORCE ]; then + echo "Force enabled, data/txnlog directories will be re-initialized" + else + # we create if version-2 exists (ie real data), not the + # parent. See comments in following section for more insight + if [ -d "$ZOO_DATADIR/version-2" ]; then + echo "ZooKeeper data directory already exists at $ZOO_DATADIR (or use --force to force re-initialization)" + exit 1 + fi + + if [ -n "$ZOO_DATALOGDIR" ] && [ -d "$ZOO_DATALOGDIR/version-2" ]; then + echo "ZooKeeper txnlog directory already exists at $ZOO_DATALOGDIR (or use --force to force re-initialization)" + exit 1 + fi + fi + + # remove the child files that we're (not) interested in, not the + # parent. this allows for parent to be installed separately, and + # permissions to be set based on overarching requirements. by + # default we'll use the permissions of the user running this + # script for the files contained by the parent. note also by using + # -p the parent(s) will be created if it doesn't already exist + rm -rf "$ZOO_DATADIR/myid" 2>/dev/null >/dev/null + rm -rf "$ZOO_DATADIR/version-2" 2>/dev/null >/dev/null + mkdir -p "$ZOO_DATADIR/version-2" + + if [ -n "$ZOO_DATALOGDIR" ]; then + rm -rf "$ZOO_DATALOGDIR/myid" 2>/dev/null >/dev/null + rm -rf "$ZOO_DATALOGDIR/version-2" 2>/dev/null >/dev/null + mkdir -p "$ZOO_DATALOGDIR/version-2" + fi + + if [ $MYID ]; then + echo "Using myid of $MYID" + echo $MYID > "$ZOO_DATADIR/myid" + else + echo "No myid provided, be sure to specify it in $ZOO_DATADIR/myid if using non-standalone" + fi +} + +eval set -- "${OPTS}" +while true; do + case "$1" in + --configfile) + ZOOCFG=$2; shift 2 + ;; + --myid) + MYID=$2; shift 2 + ;; + --force) + FORCE=1; shift 1 + ;; + -h) + usage + ;; + --help) + usage + ;; + --) + initialize + break + ;; + *) + echo "Unknown option: $1" + usage + exit 1 + ;; + esac +done diff --git a/bin/zkServer.cmd b/bin/zkServer.cmd new file mode 100644 index 00000000000..b03a44386e7 --- /dev/null +++ b/bin/zkServer.cmd @@ -0,0 +1,26 @@ +@echo off +REM Licensed to the Apache Software Foundation (ASF) under one or more +REM contributor license agreements. See the NOTICE file distributed with +REM this work for additional information regarding copyright ownership. +REM The ASF licenses this file to You under the Apache License, Version 2.0 +REM (the "License"); you may not use this file except in compliance with +REM the License. You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +setlocal +call "%~dp0zkEnv.cmd" + +set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain +set ZOO_LOG_FILE=zookeeper-%USERNAME%-server-%COMPUTERNAME%.log + +echo on +call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" "-Dzookeeper.log.file=%ZOO_LOG_FILE%" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%%%p /t /f" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* + +endlocal diff --git a/bin/zkServer.sh b/bin/zkServer.sh new file mode 100755 index 00000000000..07df2f0b6d9 --- /dev/null +++ b/bin/zkServer.sh @@ -0,0 +1,276 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# If this scripted is run out of /usr/bin or some other system bin directory +# it should be linked to and not copied. Things like java jar files are found +# relative to the canonical path of this script. +# + + +# use POSTIX interface, symlink is followed automatically +ZOOBIN="${BASH_SOURCE-$0}" +ZOOBIN="$(dirname "${ZOOBIN}")" +ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)" + +if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then + . "$ZOOBINDIR"/../libexec/zkEnv.sh +else + . "$ZOOBINDIR"/zkEnv.sh +fi + +# See the following page for extensive details on setting +# up the JVM to accept JMX remote management: +# http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html +# by default we allow local JMX connections +if [ "x$JMXLOCALONLY" = "x" ] +then + JMXLOCALONLY=false +fi + +if [ "x$JMXDISABLE" = "x" ] || [ "$JMXDISABLE" = 'false' ] +then + echo "ZooKeeper JMX enabled by default" >&2 + if [ "x$JMXPORT" = "x" ] + then + # for some reason these two options are necessary on jdk6 on Ubuntu + # accord to the docs they are not necessary, but otw jconsole cannot + # do a local attach + ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY org.apache.zookeeper.server.quorum.QuorumPeerMain" + else + if [ "x$JMXAUTH" = "x" ] + then + JMXAUTH=false + fi + if [ "x$JMXSSL" = "x" ] + then + JMXSSL=false + fi + if [ "x$JMXLOG4J" = "x" ] + then + JMXLOG4J=true + fi + echo "ZooKeeper remote JMX Port set to $JMXPORT" >&2 + echo "ZooKeeper remote JMX authenticate set to $JMXAUTH" >&2 + echo "ZooKeeper remote JMX ssl set to $JMXSSL" >&2 + echo "ZooKeeper remote JMX log4j set to $JMXLOG4J" >&2 + ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMXPORT -Dcom.sun.management.jmxremote.authenticate=$JMXAUTH -Dcom.sun.management.jmxremote.ssl=$JMXSSL -Dzookeeper.jmx.log4j.disable=$JMXLOG4J org.apache.zookeeper.server.quorum.QuorumPeerMain" + fi +else + echo "JMX disabled by user request" >&2 + ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain" +fi + +if [ "x$SERVER_JVMFLAGS" != "x" ] +then + JVMFLAGS="$SERVER_JVMFLAGS $JVMFLAGS" +fi + +if [ "x$2" != "x" ] +then + ZOOCFG="$ZOOCFGDIR/$2" +fi + +# if we give a more complicated path to the config, don't screw around in $ZOOCFGDIR +if [ "x$(dirname "$ZOOCFG")" != "x$ZOOCFGDIR" ] +then + ZOOCFG="$2" +fi + +if $cygwin +then + ZOOCFG=`cygpath -wp "$ZOOCFG"` + # cygwin has a "kill" in the shell itself, gets confused + KILL=/bin/kill +else + KILL=kill +fi + +echo "Using config: $ZOOCFG" >&2 + +case "$OSTYPE" in +*solaris*) + GREP=/usr/xpg4/bin/grep + ;; +*) + GREP=grep + ;; +esac +ZOO_DATADIR="$($GREP "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')" +ZOO_DATALOGDIR="$($GREP "^[[:space:]]*dataLogDir" "$ZOOCFG" | sed -e 's/.*=//')" + +# iff autocreate is turned off and the datadirs don't exist fail +# immediately as we can't create the PID file, etc..., anyway. +if [ -n "$ZOO_DATADIR_AUTOCREATE_DISABLE" ]; then + if [ ! -d "$ZOO_DATADIR/version-2" ]; then + echo "ZooKeeper data directory is missing at $ZOO_DATADIR fix the path or run initialize" + exit 1 + fi + + if [ -n "$ZOO_DATALOGDIR" ] && [ ! -d "$ZOO_DATALOGDIR/version-2" ]; then + echo "ZooKeeper txnlog directory is missing at $ZOO_DATALOGDIR fix the path or run initialize" + exit 1 + fi + ZOO_DATADIR_AUTOCREATE="-Dzookeeper.datadir.autocreate=false" +fi + +if [ -z "$ZOOPIDFILE" ]; then + if [ ! -d "$ZOO_DATADIR" ]; then + mkdir -p "$ZOO_DATADIR" + fi + ZOOPIDFILE="$ZOO_DATADIR/zookeeper_server.pid" +else + # ensure it exists, otw stop will fail + mkdir -p "$(dirname "$ZOOPIDFILE")" +fi + +if [ ! -w "$ZOO_LOG_DIR" ] ; then +mkdir -p "$ZOO_LOG_DIR" +fi + +ZOO_LOG_FILE=zookeeper-$USER-server-$HOSTNAME.log +_ZOO_DAEMON_OUT="$ZOO_LOG_DIR/zookeeper-$USER-server-$HOSTNAME.out" + +case $1 in +start) + echo -n "Starting zookeeper ... " + if [ -f "$ZOOPIDFILE" ]; then + if kill -0 `cat "$ZOOPIDFILE"` > /dev/null 2>&1; then + echo $command already running as process `cat "$ZOOPIDFILE"`. + exit 0 + fi + fi + nohup "$JAVA" $ZOO_DATADIR_AUTOCREATE "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" \ + "-Dzookeeper.log.file=${ZOO_LOG_FILE}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ + -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \ + -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null & + if [ $? -eq 0 ] + then + case "$OSTYPE" in + *solaris*) + /bin/echo "${!}\\c" > "$ZOOPIDFILE" + ;; + *) + /bin/echo -n $! > "$ZOOPIDFILE" + ;; + esac + if [ $? -eq 0 ]; + then + sleep 1 + pid=$(cat "${ZOOPIDFILE}") + if ps -p "${pid}" > /dev/null 2>&1; then + echo STARTED + else + echo FAILED TO START + exit 1 + fi + else + echo FAILED TO WRITE PID + exit 1 + fi + else + echo SERVER DID NOT START + exit 1 + fi + ;; +start-foreground) + ZOO_CMD=(exec "$JAVA") + if [ "${ZOO_NOEXEC}" != "" ]; then + ZOO_CMD=("$JAVA") + fi + "${ZOO_CMD[@]}" $ZOO_DATADIR_AUTOCREATE "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" \ + "-Dzookeeper.log.file=${ZOO_LOG_FILE}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ + -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \ + -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" + ;; +print-cmd) + echo "\"$JAVA\" $ZOO_DATADIR_AUTOCREATE -Dzookeeper.log.dir=\"${ZOO_LOG_DIR}\" \ + -Dzookeeper.log.file=\"${ZOO_LOG_FILE}\" -Dzookeeper.root.logger=\"${ZOO_LOG4J_PROP}\" \ + -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \ + -cp \"$CLASSPATH\" $JVMFLAGS $ZOOMAIN \"$ZOOCFG\" > \"$_ZOO_DAEMON_OUT\" 2>&1 < /dev/null" + ;; +stop) + echo -n "Stopping zookeeper ... " + if [ ! -f "$ZOOPIDFILE" ] + then + echo "no zookeeper to stop (could not find file $ZOOPIDFILE)" + else + $KILL $(cat "$ZOOPIDFILE") + rm "$ZOOPIDFILE" + echo STOPPED + fi + exit 0 + ;; +restart) + shift + "$0" stop ${@} + sleep 3 + "$0" start ${@} + ;; +status) + # -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output + clientPortAddress=`$GREP "^[[:space:]]*clientPortAddress[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'` + if ! [ $clientPortAddress ] + then + clientPortAddress="localhost" + fi + clientPort=`$GREP "^[[:space:]]*clientPort[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'` + if ! [[ "$clientPort" =~ ^[0-9]+$ ]] + then + dataDir=`$GREP "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//'` + myid=`cat "$dataDir/myid"` + if ! [[ "$myid" =~ ^[0-9]+$ ]] ; then + echo "clientPort not found and myid could not be determined. Terminating." + exit 1 + fi + clientPortAndAddress=`$GREP "^[[:space:]]*server.$myid=.*;.*" "$ZOOCFG" | sed -e 's/.*=//' | sed -e 's/.*;//'` + if [ ! "$clientPortAndAddress" ] ; then + echo "Client port not found in static config file. Looking in dynamic config file." + dynamicConfigFile=`$GREP "^[[:space:]]*dynamicConfigFile" "$ZOOCFG" | sed -e 's/.*=//'` + clientPortAndAddress=`$GREP "^[[:space:]]*server.$myid=.*;.*" "$dynamicConfigFile" | sed -e 's/.*=//' | sed -e 's/.*;//'` + fi + if [ ! "$clientPortAndAddress" ] ; then + echo "Client port not found. Terminating." + exit 1 + fi + if [[ "$clientPortAndAddress" =~ ^.*:[0-9]+ ]] ; then + clientPortAddress=`echo "$clientPortAndAddress" | sed -e 's/:.*//'` + fi + clientPort=`echo "$clientPortAndAddress" | sed -e 's/.*://'` + if [ ! "$clientPort" ] ; then + echo "Client port not found. Terminating." + exit 1 + fi + fi + echo "Client port found: $clientPort. Client address: $clientPortAddress." + STAT=`"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \ + -cp "$CLASSPATH" $JVMFLAGS org.apache.zookeeper.client.FourLetterWordMain \ + $clientPortAddress $clientPort srvr 2> /dev/null \ + | $GREP Mode` + if [ "x$STAT" = "x" ] + then + echo "Error contacting service. It is probably not running." + exit 1 + else + echo $STAT + exit 0 + fi + ;; +*) + echo "Usage: $0 [--config ] {start|start-foreground|stop|restart|status|print-cmd}" >&2 + +esac diff --git a/build.xml b/build.xml new file mode 100644 index 00000000000..61a5b5a11f6 --- /dev/null +++ b/build.xml @@ -0,0 +1,1967 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ') +} + +function SwitchMenu(obj, thePath) { + var open = 'url("' + thePath + 'images/chapter_open.gif")'; + var close = 'url("' + thePath + 'images/chapter.gif")'; + if (document.getElementById) { + var el = document.getElementById(obj); + var title = document.getElementById(obj + 'Title'); + + if (el.style.display != "block") { + title.style.backgroundImage = open; + el.style.display = "block"; + } else { + title.style.backgroundImage = close; + el.style.display = "none"; + } + }// end - if(document.getElementById) +}//end - function SwitchMenu(obj) diff --git a/docs/skin/images/README.txt b/docs/skin/images/README.txt new file mode 100644 index 00000000000..e0932f4a46d --- /dev/null +++ b/docs/skin/images/README.txt @@ -0,0 +1 @@ +The images in this directory are used if the current skin lacks them. diff --git a/docs/skin/images/add.jpg b/docs/skin/images/add.jpg new file mode 100644 index 00000000000..06831eeb3dd Binary files /dev/null and b/docs/skin/images/add.jpg differ diff --git a/docs/skin/images/apache-thanks.png b/docs/skin/images/apache-thanks.png new file mode 100644 index 00000000000..c0bea09cc8b Binary files /dev/null and b/docs/skin/images/apache-thanks.png differ diff --git a/docs/skin/images/built-with-cocoon.gif b/docs/skin/images/built-with-cocoon.gif new file mode 100644 index 00000000000..0b38f7857b6 Binary files /dev/null and b/docs/skin/images/built-with-cocoon.gif differ diff --git a/docs/skin/images/built-with-forrest-button.png b/docs/skin/images/built-with-forrest-button.png new file mode 100644 index 00000000000..4a787abe4dc Binary files /dev/null and b/docs/skin/images/built-with-forrest-button.png differ diff --git a/docs/skin/images/chapter.gif b/docs/skin/images/chapter.gif new file mode 100644 index 00000000000..d3d8245d0c7 Binary files /dev/null and b/docs/skin/images/chapter.gif differ diff --git a/docs/skin/images/chapter_open.gif b/docs/skin/images/chapter_open.gif new file mode 100644 index 00000000000..eecce18b50a Binary files /dev/null and b/docs/skin/images/chapter_open.gif differ diff --git a/docs/skin/images/current.gif b/docs/skin/images/current.gif new file mode 100644 index 00000000000..fd82c082012 Binary files /dev/null and b/docs/skin/images/current.gif differ diff --git a/docs/skin/images/error.png b/docs/skin/images/error.png new file mode 100644 index 00000000000..b4fe06e3709 Binary files /dev/null and b/docs/skin/images/error.png differ diff --git a/docs/skin/images/external-link.gif b/docs/skin/images/external-link.gif new file mode 100644 index 00000000000..ff2f7b2a0ed Binary files /dev/null and b/docs/skin/images/external-link.gif differ diff --git a/docs/skin/images/fix.jpg b/docs/skin/images/fix.jpg new file mode 100644 index 00000000000..1d6820b43b7 Binary files /dev/null and b/docs/skin/images/fix.jpg differ diff --git a/docs/skin/images/forrest-credit-logo.png b/docs/skin/images/forrest-credit-logo.png new file mode 100644 index 00000000000..8a63e42038d Binary files /dev/null and b/docs/skin/images/forrest-credit-logo.png differ diff --git a/docs/skin/images/hack.jpg b/docs/skin/images/hack.jpg new file mode 100644 index 00000000000..f38d50fe4e8 Binary files /dev/null and b/docs/skin/images/hack.jpg differ diff --git a/docs/skin/images/header_white_line.gif b/docs/skin/images/header_white_line.gif new file mode 100644 index 00000000000..369cae8dcf2 Binary files /dev/null and b/docs/skin/images/header_white_line.gif differ diff --git a/docs/skin/images/info.png b/docs/skin/images/info.png new file mode 100644 index 00000000000..2e53447e8c2 Binary files /dev/null and b/docs/skin/images/info.png differ diff --git a/docs/skin/images/instruction_arrow.png b/docs/skin/images/instruction_arrow.png new file mode 100644 index 00000000000..0fbc72452bf Binary files /dev/null and b/docs/skin/images/instruction_arrow.png differ diff --git a/docs/skin/images/label.gif b/docs/skin/images/label.gif new file mode 100644 index 00000000000..c83a3893c55 Binary files /dev/null and b/docs/skin/images/label.gif differ diff --git a/docs/skin/images/page.gif b/docs/skin/images/page.gif new file mode 100644 index 00000000000..a144d3295be Binary files /dev/null and b/docs/skin/images/page.gif differ diff --git a/docs/skin/images/pdfdoc.gif b/docs/skin/images/pdfdoc.gif new file mode 100644 index 00000000000..ec13eb52fb1 Binary files /dev/null and b/docs/skin/images/pdfdoc.gif differ diff --git a/docs/skin/images/poddoc.png b/docs/skin/images/poddoc.png new file mode 100644 index 00000000000..a393df73723 Binary files /dev/null and b/docs/skin/images/poddoc.png differ diff --git a/docs/skin/images/printer.gif b/docs/skin/images/printer.gif new file mode 100644 index 00000000000..a8d0d419c90 Binary files /dev/null and b/docs/skin/images/printer.gif differ diff --git a/docs/skin/images/rc-b-l-15-1body-2menu-3menu.png b/docs/skin/images/rc-b-l-15-1body-2menu-3menu.png new file mode 100644 index 00000000000..1c6f6d9ac2f Binary files /dev/null and b/docs/skin/images/rc-b-l-15-1body-2menu-3menu.png differ diff --git a/docs/skin/images/rc-b-r-15-1body-2menu-3menu.png b/docs/skin/images/rc-b-r-15-1body-2menu-3menu.png new file mode 100644 index 00000000000..fd3ab100cba Binary files /dev/null and b/docs/skin/images/rc-b-r-15-1body-2menu-3menu.png differ diff --git a/docs/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png b/docs/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png new file mode 100644 index 00000000000..a6d887f383e Binary files /dev/null and b/docs/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png differ diff --git a/docs/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png b/docs/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png new file mode 100644 index 00000000000..b10c0cdd589 Binary files /dev/null and b/docs/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png differ diff --git a/docs/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png b/docs/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png new file mode 100644 index 00000000000..c300582e590 Binary files /dev/null and b/docs/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png differ diff --git a/docs/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png b/docs/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png new file mode 100644 index 00000000000..b10c0cdd589 Binary files /dev/null and b/docs/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png differ diff --git a/docs/skin/images/rc-t-r-15-1body-2menu-3menu.png b/docs/skin/images/rc-t-r-15-1body-2menu-3menu.png new file mode 100644 index 00000000000..1ccf4f55b4b Binary files /dev/null and b/docs/skin/images/rc-t-r-15-1body-2menu-3menu.png differ diff --git a/docs/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png b/docs/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png new file mode 100644 index 00000000000..5b30d52619b Binary files /dev/null and b/docs/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png differ diff --git a/docs/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png b/docs/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png new file mode 100644 index 00000000000..e2010d796f8 Binary files /dev/null and b/docs/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png differ diff --git a/docs/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png b/docs/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png new file mode 100644 index 00000000000..5b30d52619b Binary files /dev/null and b/docs/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png differ diff --git a/docs/skin/images/remove.jpg b/docs/skin/images/remove.jpg new file mode 100644 index 00000000000..8c9b9efa8fe Binary files /dev/null and b/docs/skin/images/remove.jpg differ diff --git a/docs/skin/images/rss.png b/docs/skin/images/rss.png new file mode 100644 index 00000000000..f0796ac8862 Binary files /dev/null and b/docs/skin/images/rss.png differ diff --git a/docs/skin/images/spacer.gif b/docs/skin/images/spacer.gif new file mode 100644 index 00000000000..35d42e808f0 Binary files /dev/null and b/docs/skin/images/spacer.gif differ diff --git a/docs/skin/images/success.png b/docs/skin/images/success.png new file mode 100644 index 00000000000..96fcfea3225 Binary files /dev/null and b/docs/skin/images/success.png differ diff --git a/docs/skin/images/txtdoc.png b/docs/skin/images/txtdoc.png new file mode 100644 index 00000000000..bf8b3744ab2 Binary files /dev/null and b/docs/skin/images/txtdoc.png differ diff --git a/docs/skin/images/update.jpg b/docs/skin/images/update.jpg new file mode 100644 index 00000000000..beb9207336f Binary files /dev/null and b/docs/skin/images/update.jpg differ diff --git a/docs/skin/images/valid-html401.png b/docs/skin/images/valid-html401.png new file mode 100644 index 00000000000..3855210c6c3 Binary files /dev/null and b/docs/skin/images/valid-html401.png differ diff --git a/docs/skin/images/vcss.png b/docs/skin/images/vcss.png new file mode 100644 index 00000000000..9b2f596e016 Binary files /dev/null and b/docs/skin/images/vcss.png differ diff --git a/docs/skin/images/warning.png b/docs/skin/images/warning.png new file mode 100644 index 00000000000..b81b2ce8a12 Binary files /dev/null and b/docs/skin/images/warning.png differ diff --git a/docs/skin/images/xmldoc.gif b/docs/skin/images/xmldoc.gif new file mode 100644 index 00000000000..c92d9b90574 Binary files /dev/null and b/docs/skin/images/xmldoc.gif differ diff --git a/docs/skin/menu.js b/docs/skin/menu.js new file mode 100644 index 00000000000..b2573496618 --- /dev/null +++ b/docs/skin/menu.js @@ -0,0 +1,47 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/** + * This script, when included in a html file, can be used to make collapsible menus + * + * Typical usage: + * + */ + +if (document.getElementById) { + document.write('') +} + +function SwitchMenu(obj) { + if (document.getElementById) { + var el = document.getElementById(obj); + var title = document.getElementById(obj + 'Title'); + + if (obj.indexOf("_selected_") == 0 && el.style.display == "") { + el.style.display = "block"; + title.className = "pagegroupselected"; + } + + if (el.style.display != "block") { + el.style.display = "block"; + title.className = "pagegroupopen"; + } + else { + el.style.display = "none"; + title.className = "pagegroup"; + } + }// end - if(document.getElementById) +}//end - function SwitchMenu(obj) diff --git a/docs/skin/note.txt b/docs/skin/note.txt new file mode 100644 index 00000000000..d34c8db5ef4 --- /dev/null +++ b/docs/skin/note.txt @@ -0,0 +1,50 @@ +Notes for developer: + +--Legend------------------- +TODO -> blocker +DONE -> blocker +ToDo -> enhancement bug +done -> enhancement bug + +--Issues------------------- +- the corner images should be rendered through svg with the header color. +-> DONE +-> ToDo: get rid of the images and use only divs! + +- the menu points should be displayed "better". +-> DONE +-- Use the krysalis-site menu approach for the overall menu display. +-> DONE +-- Use the old lenya innermenu approch to further enhance the menu . +-> DONE + +- the content area needs some attention. +-> DONE +-- introduce the heading scheme from krysalis () +-> DONE +-> ToDo: make box with round corners +-> done: make underlined with variable border height +-> ToDo: make underline with bottom round corner +-- introduce the toc for each html-page +-> DONE +-- introduce the external-link-images. +-> DONE + +- the publish note should be where now only a border is. +Like
+-> DONE +, but make it configurable. +-> DONE +- footer needs some attention +-> DONE +-- the footer do not have the color profile! Enable it! +-> DONE +-- the footer should as well contain a feedback link. +See http://issues.apache.org/eyebrowse/ReadMsg?listName=forrest-user@xml.apache.org&msgNo=71 +-> DONE + +- introduce credits alternativ location +-> DONE + +- border for published / breadtrail / menu /tab divs +-> ToDo \ No newline at end of file diff --git a/docs/skin/print.css b/docs/skin/print.css new file mode 100644 index 00000000000..87348445c74 --- /dev/null +++ b/docs/skin/print.css @@ -0,0 +1,54 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +body { + font-family: Georgia, Palatino, serif; + font-size: 12pt; + background: white; +} + +#tabs, +#menu, +#content .toc { + display: none; +} + +#content { + width: auto; + padding: 0; + float: none !important; + color: black; + background: inherit; +} + +a:link, a:visited { + color: #336699; + background: inherit; + text-decoration: underline; +} + +#top .logo { + padding: 0; + margin: 0 0 2em 0; +} + +#footer { + margin-top: 4em; +} + +acronym { + border: 0; +} \ No newline at end of file diff --git a/docs/skin/profile.css b/docs/skin/profile.css new file mode 100644 index 00000000000..a7b876a0363 --- /dev/null +++ b/docs/skin/profile.css @@ -0,0 +1,366 @@ +/* ==================== aural ============================ */ + +@media aural { + h1, h2, h3, h4, h5, h6 { + voice-family: paul, male; + stress: 20; + richness: 90 + } + + h1 { + pitch: x-low; + pitch-range: 90 + } + + h2 { + pitch: x-low; + pitch-range: 80 + } + + h3 { + pitch: low; + pitch-range: 70 + } + + h4 { + pitch: medium; + pitch-range: 60 + } + + h5 { + pitch: medium; + pitch-range: 50 + } + + h6 { + pitch: medium; + pitch-range: 40 + } + + li, dt, dd { + pitch: medium; + richness: 60 + } + + dt { + stress: 80 + } + + pre, code, tt { + pitch: medium; + pitch-range: 0; + stress: 0; + richness: 80 + } + + em { + pitch: medium; + pitch-range: 60; + stress: 60; + richness: 50 + } + + strong { + pitch: medium; + pitch-range: 60; + stress: 90; + richness: 90 + } + + dfn { + pitch: high; + pitch-range: 60; + stress: 60 + } + + s, strike { + richness: 0 + } + + i { + pitch: medium; + pitch-range: 60; + stress: 60; + richness: 50 + } + + b { + pitch: medium; + pitch-range: 60; + stress: 90; + richness: 90 + } + + u { + richness: 0 + } + + :link { + voice-family: harry, male + } + + :visited { + voice-family: betty, female + } + + :active { + voice-family: betty, female; + pitch-range: 80; + pitch: x-high + } +} + +a.external { + padding: 0 20px 0px 0px; + display: inline; + background-repeat: no-repeat; + background-position: center right; + background-image: url(images/external-link.gif); +} + +#top { + background-color: #FFFFFF; +} + +#top .header .current { + background-color: #4C6C8F; +} + +#top .header .current a:link { + color: #ffffff; +} + +#top .header .current a:visited { + color: #ffffff; +} + +#top .header .current a:hover { + color: #ffffff; +} + +#tabs li { + background-color: #E5E4D9; +} + +#tabs li a:link { + color: #000000; +} + +#tabs li a:visited { + color: #000000; +} + +#tabs li a:hover { + color: #000000; +} + +#level2tabs a.selected { + background-color: #4C6C8F; +} + +#level2tabs a:link { + color: #ffffff; +} + +#level2tabs a:visited { + color: #ffffff; +} + +#level2tabs a:hover { + color: #ffffff; +} + +#level2tabs { + background-color: #E5E4D9; +} + +#level2tabs a.unselected:link { + color: #000000; +} + +#level2tabs a.unselected:visited { + color: #000000; +} + +#level2tabs a.unselected:hover { + color: #000000; +} + +.heading { + background-color: #E5E4D9; +} + +.boxed { + background-color: #E5E4D9; +} + +.underlined_5 { + border-bottom: solid 5px #E5E4D9; +} + +.underlined_10 { + border-bottom: solid 10px #E5E4D9; +} + +table caption { + background-color: #E5E4D9; + color: #000000; +} + +#feedback { + color: #FFFFFF; + background: #4C6C8F; + text-align: center; +} + +#feedback #feedbackto { + color: #FFFFFF; +} + +#publishedStrip { + color: #FFFFFF; + background: #4C6C8F; +} + +#publishedStrip { + color: #000000; + background: #E5E4D9; +} + +#menu .menupagetitle { + background-color: #CFDCED; + color: #000000; +} + +#menu { + border-color: #999999; +} + +#menu .menupagetitle { + border-color: #999999; +} + +#menu .menupageitemgroup { + border-color: #999999; +} + +#menu { + background-color: #4C6C8F; +} + +#menu { + color: #ffffff; +} + +#menu a:link { + color: #ffffff; +} + +#menu a:visited { + color: #ffffff; +} + +#menu a:hover { + background-color: #4C6C8F; + color: #ffffff; +} + +#menu h1 { + color: #000000; + background-color: #cfdced; +} + +#top .searchbox { + background-color: #E5E4D9; + color: #000000; +} + +#menu .menupageitemgroup { + background-color: #E5E4D9; +} + +#menu .menupageitem { + color: #000000; +} + +#menu .menupageitem a:link { + color: #000000; +} + +#menu .menupageitem a:visited { + color: #000000; +} + +#menu .menupageitem a:hover { + background-color: #E5E4D9; + color: #000000; +} + +body { + background-color: #ffffff; + color: #000000; +} + +a:link { + color: #0000ff +} + +a:visited { + color: #009999 +} + +a:hover { + color: #6587ff +} + +.ForrestTable { + background-color: #ccc; +} + +.ForrestTable td { + background-color: #ffffff; +} + +.highlight { + background-color: #ffff00; +} + +.fixme { + border-color: #c60; +} + +.note { + border-color: #069; +} + +.warning { + border-color: #900; +} + +.code { + border-color: #a5b6c6; +} + +#footer { + background-color: #E5E4D9; +} + +/* extra-css */ + +p.quote { + margin-left: 2em; + padding: .5em; + background-color: #f0f0f0; + font-family: monospace; +} + +pre.code { + margin-left: 0em; + padding: 0.5em; + background-color: #f0f0f0; + font-family: monospace; +} + + + + \ No newline at end of file diff --git a/docs/skin/prototype.js b/docs/skin/prototype.js new file mode 100644 index 00000000000..82ef3e17801 --- /dev/null +++ b/docs/skin/prototype.js @@ -0,0 +1,1336 @@ +/* Prototype JavaScript framework, version 1.4.0_pre4 + * (c) 2005 Sam Stephenson + * + * THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff + * against the source tree, available from the Prototype darcs repository. + * + * Prototype is freely distributable under the terms of an MIT-style license. + * + * For details, see the Prototype web site: http://prototype.conio.net/ + * +/*--------------------------------------------------------------------------*/ + +var Prototype = { + Version: '1.4.0_pre4', + + emptyFunction: function () { + }, + K: function (x) { + return x + } +} + +var Class = { + create: function () { + return function () { + this.initialize.apply(this, arguments); + } + } +} + +var Abstract = new Object(); + +Object.extend = function (destination, source) { + for (property in source) { + destination[property] = source[property]; + } + return destination; +} + +Function.prototype.bind = function (object) { + var __method = this; + return function () { + return __method.apply(object, arguments); + } +} + +Function.prototype.bindAsEventListener = function (object) { + var __method = this; + return function (event) { + return __method.call(object, event || window.event); + } +} + +Number.prototype.toColorPart = function () { + var digits = this.toString(16); + if (this < 16) { + return '0' + digits; + } + return digits; +} + +var Try = { + these: function () { + var returnValue; + + for (var i = 0; i < arguments.length; i++) { + var lambda = arguments[i]; + try { + returnValue = lambda(); + break; + } catch (e) { + } + } + + return returnValue; + } +} + +/*--------------------------------------------------------------------------*/ + +var PeriodicalExecuter = Class.create(); +PeriodicalExecuter.prototype = { + initialize: function (callback, frequency) { + this.callback = callback; + this.frequency = frequency; + this.currentlyExecuting = false; + + this.registerCallback(); + }, + + registerCallback: function () { + setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); + }, + + onTimerEvent: function () { + if (!this.currentlyExecuting) { + try { + this.currentlyExecuting = true; + this.callback(); + } finally { + this.currentlyExecuting = false; + } + } + } +} + +/*--------------------------------------------------------------------------*/ + +function $() { + var elements = new Array(); + + for (var i = 0; i < arguments.length; i++) { + var element = arguments[i]; + if (typeof element == 'string') { + element = document.getElementById(element); + } + + if (arguments.length == 1) { + return element; + } + + elements.push(element); + } + + return elements; +} + +if (!Array.prototype.push) { + Array.prototype.push = function () { + var startLength = this.length; + for (var i = 0; i < arguments.length; i++) { + this[startLength + i] = arguments[i]; + } + return this.length; + } +} + +if (!Function.prototype.apply) { + // Based on code from http://www.youngpup.net/ + Function.prototype.apply = function (object, parameters) { + var parameterStrings = new Array(); + if (!object) { + object = window; + } + if (!parameters) { + parameters = new Array(); + } + + for (var i = 0; i < parameters.length; i++) { + parameterStrings[i] = 'parameters[' + i + ']'; + } + + object.__apply__ = this; + var result = eval('object.__apply__(' + + parameterStrings.join(', ') + ')'); + object.__apply__ = null; + + return result; + } +} + +Object.extend(String.prototype, { + stripTags: function () { + return this.replace(/<\/?[^>]+>/gi, ''); + }, + + escapeHTML: function () { + var div = document.createElement('div'); + var text = document.createTextNode(this); + div.appendChild(text); + return div.innerHTML; + }, + + unescapeHTML: function () { + var div = document.createElement('div'); + div.innerHTML = this.stripTags(); + return div.childNodes[0].nodeValue; + }, + + parseQuery: function () { + var str = this; + if (str.substring(0, 1) == '?') { + str = this.substring(1); + } + var result = {}; + var pairs = str.split('&'); + for (var i = 0; i < pairs.length; i++) { + var pair = pairs[i].split('='); + result[pair[0]] = pair[1]; + } + return result; + } +}); + +var _break = new Object(); +var _continue = new Object(); + +var Enumerable = { + each: function (iterator) { + var index = 0; + try { + this._each(function (value) { + try { + iterator(value, index++); + } catch (e) { + if (e != _continue) { + throw e; + } + } + }); + } catch (e) { + if (e != _break) { + throw e; + } + } + }, + + all: function (iterator) { + var result = true; + this.each(function (value, index) { + if (!(result &= (iterator || Prototype.K)(value, index))) { + throw _break; + } + }); + return result; + }, + + any: function (iterator) { + var result = true; + this.each(function (value, index) { + if (result &= (iterator || Prototype.K)(value, index)) { + throw _break; + } + }); + return result; + }, + + collect: function (iterator) { + var results = []; + this.each(function (value, index) { + results.push(iterator(value, index)); + }); + return results; + }, + + detect: function (iterator) { + var result; + this.each(function (value, index) { + if (iterator(value, index)) { + result = value; + throw _break; + } + }); + return result; + }, + + findAll: function (iterator) { + var results = []; + this.each(function (value, index) { + if (iterator(value, index)) { + results.push(value); + } + }); + return results; + }, + + grep: function (pattern, iterator) { + var results = []; + this.each(function (value, index) { + var stringValue = value.toString(); + if (stringValue.match(pattern)) { + results.push((iterator || Prototype.K)(value, index)); + } + }) + return results; + }, + + include: function (object) { + var found = false; + this.each(function (value) { + if (value == object) { + found = true; + throw _break; + } + }); + return found; + }, + + inject: function (memo, iterator) { + this.each(function (value, index) { + memo = iterator(memo, value, index); + }); + return memo; + }, + + invoke: function (method) { + var args = $A(arguments).slice(1); + return this.collect(function (value) { + return value[method].apply(value, args); + }); + }, + + max: function (iterator) { + var result; + this.each(function (value, index) { + value = (iterator || Prototype.K)(value, index); + if (value >= (result || value)) { + result = value; + } + }); + return result; + }, + + min: function (iterator) { + var result; + this.each(function (value, index) { + value = (iterator || Prototype.K)(value, index); + if (value <= (result || value)) { + result = value; + } + }); + return result; + }, + + partition: function (iterator) { + var trues = [], falses = []; + this.each(function (value, index) { + ((iterator || Prototype.K)(value, index) ? trues : falses).push(value); + }); + return [trues, falses]; + }, + + pluck: function (property) { + var results = []; + this.each(function (value, index) { + results.push(value[property]); + }); + return results; + }, + + reject: function (iterator) { + var results = []; + this.each(function (value, index) { + if (!iterator(value, index)) { + results.push(value); + } + }); + return results; + }, + + sortBy: function (iterator) { + return this.collect(function (value, index) { + return {value: value, criteria: iterator(value, index)}; + }).sort(function (left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + }).pluck('value'); + }, + + toArray: function () { + return this.collect(Prototype.K); + }, + + zip: function () { + var iterator = Prototype.K, args = $A(arguments); + if (typeof args.last() == 'function') { + iterator = args.pop(); + } + + var collections = [this].concat(args).map($A); + return this.map(function (value, index) { + iterator(value = collections.pluck(index)); + return value; + }); + } +} + +Object.extend(Enumerable, { + map: Enumerable.collect, + find: Enumerable.detect, + select: Enumerable.findAll, + member: Enumerable.include, + entries: Enumerable.toArray +}); + +$A = Array.from = function (iterable) { + var results = []; + for (var i = 0; i < iterable.length; i++) { + results.push(iterable[i]); + } + return results; +} + +Object.extend(Array.prototype, { + _each: function (iterator) { + for (var i = 0; i < this.length; i++) { + iterator(this[i]); + } + }, + + first: function () { + return this[0]; + }, + + last: function () { + return this[this.length - 1]; + } +}); + +Object.extend(Array.prototype, Enumerable); + +var Ajax = { + getTransport: function () { + return Try.these( + function () { + return new ActiveXObject('Msxml2.XMLHTTP') + }, + function () { + return new ActiveXObject('Microsoft.XMLHTTP') + }, + function () { + return new XMLHttpRequest() + } + ) || false; + } +} + +Ajax.Base = function () { +}; +Ajax.Base.prototype = { + setOptions: function (options) { + this.options = { + method: 'post', + asynchronous: true, + parameters: '' + } + Object.extend(this.options, options || {}); + }, + + responseIsSuccess: function () { + return this.transport.status == undefined + || this.transport.status == 0 + || (this.transport.status >= 200 && this.transport.status < 300); + }, + + responseIsFailure: function () { + return !this.responseIsSuccess(); + } +} + +Ajax.Request = Class.create(); +Ajax.Request.Events = + ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; + +Ajax.Request.prototype = Object.extend(new Ajax.Base(), { + initialize: function (url, options) { + this.transport = Ajax.getTransport(); + this.setOptions(options); + this.request(url); + }, + + request: function (url) { + var parameters = this.options.parameters || ''; + if (parameters.length > 0) { + parameters += '&_='; + } + + try { + if (this.options.method == 'get') { + url += '?' + parameters; + } + + this.transport.open(this.options.method, url, + this.options.asynchronous); + + if (this.options.asynchronous) { + this.transport.onreadystatechange = this.onStateChange.bind(this); + setTimeout((function () { + this.respondToReadyState(1) + }).bind(this), 10); + } + + this.setRequestHeaders(); + + var body = this.options.postBody ? this.options.postBody : parameters; + this.transport.send(this.options.method == 'post' ? body : null); + + } catch (e) { + } + }, + + setRequestHeaders: function () { + var requestHeaders = + ['X-Requested-With', 'XMLHttpRequest', + 'X-Prototype-Version', Prototype.Version]; + + if (this.options.method == 'post') { + requestHeaders.push('Content-type', + 'application/x-www-form-urlencoded'); + + /* Force "Connection: close" for Mozilla browsers to work around + * a bug where XMLHttpReqeuest sends an incorrect Content-length + * header. See Mozilla Bugzilla #246651. + */ + if (this.transport.overrideMimeType) { + requestHeaders.push('Connection', 'close'); + } + } + + if (this.options.requestHeaders) { + requestHeaders.push.apply(requestHeaders, this.options.requestHeaders); + } + + for (var i = 0; i < requestHeaders.length; i += 2) { + this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i + 1]); + } + }, + + onStateChange: function () { + var readyState = this.transport.readyState; + if (readyState != 1) { + this.respondToReadyState(this.transport.readyState); + } + }, + + respondToReadyState: function (readyState) { + var event = Ajax.Request.Events[readyState]; + + if (event == 'Complete') { + (this.options['on' + this.transport.status] + || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] + || Prototype.emptyFunction)(this.transport); + } + + (this.options['on' + event] || Prototype.emptyFunction)(this.transport); + + /* Avoid memory leak in MSIE: clean up the oncomplete event handler */ + if (event == 'Complete') { + this.transport.onreadystatechange = Prototype.emptyFunction; + } + } +}); + +Ajax.Updater = Class.create(); +Ajax.Updater.ScriptFragment = '(?:)((\n|.)*?)(?:<\/script>)'; + +Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { + initialize: function (container, url, options) { + this.containers = { + success: container.success ? $(container.success) : $(container), + failure: container.failure ? $(container.failure) : (container.success ? null : $(container)) + } + + this.transport = Ajax.getTransport(); + this.setOptions(options); + + var onComplete = this.options.onComplete || Prototype.emptyFunction; + this.options.onComplete = (function () { + this.updateContent(); + onComplete(this.transport); + }).bind(this); + + this.request(url); + }, + + updateContent: function () { + var receiver = this.responseIsSuccess() ? this.containers.success : this.containers.failure; + + var match = new RegExp(Ajax.Updater.ScriptFragment, 'img'); + var response = this.transport.responseText.replace(match, ''); + var scripts = this.transport.responseText.match(match); + + if (receiver) { + if (this.options.insertion) { + new this.options.insertion(receiver, response); + } else { + receiver.innerHTML = response; + } + } + + if (this.responseIsSuccess()) { + if (this.onComplete) { + setTimeout((function () { + this.onComplete( + this.transport) + }).bind(this), 10); + } + } + + if (this.options.evalScripts && scripts) { + match = new RegExp(Ajax.Updater.ScriptFragment, 'im'); + setTimeout((function () { + for (var i = 0; i < scripts.length; i++) { + eval(scripts[i].match(match)[1]); + } + }).bind(this), 10); + } + } +}); + +Ajax.PeriodicalUpdater = Class.create(); +Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), { + initialize: function (container, url, options) { + this.setOptions(options); + this.onComplete = this.options.onComplete; + + this.frequency = (this.options.frequency || 2); + this.decay = 1; + + this.updater = {}; + this.container = container; + this.url = url; + + this.start(); + }, + + start: function () { + this.options.onComplete = this.updateComplete.bind(this); + this.onTimerEvent(); + }, + + stop: function () { + this.updater.onComplete = undefined; + clearTimeout(this.timer); + (this.onComplete || Ajax.emptyFunction).apply(this, arguments); + }, + + updateComplete: function (request) { + if (this.options.decay) { + this.decay = (request.responseText == this.lastText ? this.decay * this.options.decay : 1); + + this.lastText = request.responseText; + } + this.timer = setTimeout(this.onTimerEvent.bind(this), + this.decay * this.frequency * 1000); + }, + + onTimerEvent: function () { + this.updater = new Ajax.Updater(this.container, this.url, this.options); + } +}); + +document.getElementsByClassName = function (className) { + var children = document.getElementsByTagName('*') || document.all; + var elements = new Array(); + + for (var i = 0; i < children.length; i++) { + var child = children[i]; + var classNames = child.className.split(' '); + for (var j = 0; j < classNames.length; j++) { + if (classNames[j] == className) { + elements.push(child); + break; + } + } + } + + return elements; +} + +/*--------------------------------------------------------------------------*/ + +if (!window.Element) { + var Element = new Object(); +} + +Object.extend(Element, { + toggle: function () { + for (var i = 0; i < arguments.length; i++) { + var element = $(arguments[i]); + element.style.display = + (element.style.display == 'none' ? '' : 'none'); + } + }, + + hide: function () { + for (var i = 0; i < arguments.length; i++) { + var element = $(arguments[i]); + element.style.display = 'none'; + } + }, + + show: function () { + for (var i = 0; i < arguments.length; i++) { + var element = $(arguments[i]); + element.style.display = ''; + } + }, + + remove: function (element) { + element = $(element); + element.parentNode.removeChild(element); + }, + + getHeight: function (element) { + element = $(element); + return element.offsetHeight; + }, + + hasClassName: function (element, className) { + element = $(element); + if (!element) { + return; + } + var a = element.className.split(' '); + for (var i = 0; i < a.length; i++) { + if (a[i] == className) { + return true; + } + } + return false; + }, + + addClassName: function (element, className) { + element = $(element); + Element.removeClassName(element, className); + element.className += ' ' + className; + }, + + removeClassName: function (element, className) { + element = $(element); + if (!element) { + return; + } + var newClassName = ''; + var a = element.className.split(' '); + for (var i = 0; i < a.length; i++) { + if (a[i] != className) { + if (i > 0) { + newClassName += ' '; + } + newClassName += a[i]; + } + } + element.className = newClassName; + }, + + // removes whitespace-only text node children + cleanWhitespace: function (element) { + var element = $(element); + for (var i = 0; i < element.childNodes.length; i++) { + var node = element.childNodes[i]; + if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) { + Element.remove(node); + } + } + } +}); + +var Toggle = new Object(); +Toggle.display = Element.toggle; + +/*--------------------------------------------------------------------------*/ + +Abstract.Insertion = function (adjacency) { + this.adjacency = adjacency; +} + +Abstract.Insertion.prototype = { + initialize: function (element, content) { + this.element = $(element); + this.content = content; + + if (this.adjacency && this.element.insertAdjacentHTML) { + this.element.insertAdjacentHTML(this.adjacency, this.content); + } else { + this.range = this.element.ownerDocument.createRange(); + if (this.initializeRange) { + this.initializeRange(); + } + this.fragment = this.range.createContextualFragment(this.content); + this.insertContent(); + } + } +} + +var Insertion = new Object(); + +Insertion.Before = Class.create(); +Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), { + initializeRange: function () { + this.range.setStartBefore(this.element); + }, + + insertContent: function () { + this.element.parentNode.insertBefore(this.fragment, this.element); + } +}); + +Insertion.Top = Class.create(); +Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), { + initializeRange: function () { + this.range.selectNodeContents(this.element); + this.range.collapse(true); + }, + + insertContent: function () { + this.element.insertBefore(this.fragment, this.element.firstChild); + } +}); + +Insertion.Bottom = Class.create(); +Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), { + initializeRange: function () { + this.range.selectNodeContents(this.element); + this.range.collapse(this.element); + }, + + insertContent: function () { + this.element.appendChild(this.fragment); + } +}); + +Insertion.After = Class.create(); +Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), { + initializeRange: function () { + this.range.setStartAfter(this.element); + }, + + insertContent: function () { + this.element.parentNode.insertBefore(this.fragment, + this.element.nextSibling); + } +}); + +var Field = { + clear: function () { + for (var i = 0; i < arguments.length; i++) { + $(arguments[i]).value = ''; + } + }, + + focus: function (element) { + $(element).focus(); + }, + + present: function () { + for (var i = 0; i < arguments.length; i++) { + if ($(arguments[i]).value == '') { + return false; + } + } + return true; + }, + + select: function (element) { + $(element).select(); + }, + + activate: function (element) { + $(element).focus(); + $(element).select(); + } +} + +/*--------------------------------------------------------------------------*/ + +var Form = { + serialize: function (form) { + var elements = Form.getElements($(form)); + var queryComponents = new Array(); + + for (var i = 0; i < elements.length; i++) { + var queryComponent = Form.Element.serialize(elements[i]); + if (queryComponent) { + queryComponents.push(queryComponent); + } + } + + return queryComponents.join('&'); + }, + + getElements: function (form) { + var form = $(form); + var elements = new Array(); + + for (tagName in Form.Element.Serializers) { + var tagElements = form.getElementsByTagName(tagName); + for (var j = 0; j < tagElements.length; j++) { + elements.push(tagElements[j]); + } + } + return elements; + }, + + getInputs: function (form, typeName, name) { + var form = $(form); + var inputs = form.getElementsByTagName('input'); + + if (!typeName && !name) { + return inputs; + } + + var matchingInputs = new Array(); + for (var i = 0; i < inputs.length; i++) { + var input = inputs[i]; + if ((typeName && input.type != typeName) || + (name && input.name != name)) { + continue; + } + matchingInputs.push(input); + } + + return matchingInputs; + }, + + disable: function (form) { + var elements = Form.getElements(form); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + element.blur(); + element.disabled = 'true'; + } + }, + + enable: function (form) { + var elements = Form.getElements(form); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + element.disabled = ''; + } + }, + + focusFirstElement: function (form) { + var form = $(form); + var elements = Form.getElements(form); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + if (element.type != 'hidden' && !element.disabled) { + Field.activate(element); + break; + } + } + }, + + reset: function (form) { + $(form).reset(); + } +} + +Form.Element = { + serialize: function (element) { + var element = $(element); + var method = element.tagName.toLowerCase(); + var parameter = Form.Element.Serializers[method](element); + + if (parameter) { + return encodeURIComponent(parameter[0]) + '=' + + encodeURIComponent(parameter[1]); + } + }, + + getValue: function (element) { + var element = $(element); + var method = element.tagName.toLowerCase(); + var parameter = Form.Element.Serializers[method](element); + + if (parameter) { + return parameter[1]; + } + } +} + +Form.Element.Serializers = { + input: function (element) { + switch (element.type.toLowerCase()) { + case 'submit': + case 'hidden': + case 'password': + case 'text': + return Form.Element.Serializers.textarea(element); + case 'checkbox': + case 'radio': + return Form.Element.Serializers.inputSelector(element); + } + return false; + }, + + inputSelector: function (element) { + if (element.checked) { + return [element.name, element.value]; + } + }, + + textarea: function (element) { + return [element.name, element.value]; + }, + + select: function (element) { + var value = ''; + if (element.type == 'select-one') { + var index = element.selectedIndex; + if (index >= 0) { + value = element.options[index].value || element.options[index].text; + } + } else { + value = new Array(); + for (var i = 0; i < element.length; i++) { + var opt = element.options[i]; + if (opt.selected) { + value.push(opt.value || opt.text); + } + } + } + return [element.name, value]; + } +} + +/*--------------------------------------------------------------------------*/ + +var $F = Form.Element.getValue; + +/*--------------------------------------------------------------------------*/ + +Abstract.TimedObserver = function () { +} +Abstract.TimedObserver.prototype = { + initialize: function (element, frequency, callback) { + this.frequency = frequency; + this.element = $(element); + this.callback = callback; + + this.lastValue = this.getValue(); + this.registerCallback(); + }, + + registerCallback: function () { + setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); + }, + + onTimerEvent: function () { + var value = this.getValue(); + if (this.lastValue != value) { + this.callback(this.element, value); + this.lastValue = value; + } + } +} + +Form.Element.Observer = Class.create(); +Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { + getValue: function () { + return Form.Element.getValue(this.element); + } +}); + +Form.Observer = Class.create(); +Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { + getValue: function () { + return Form.serialize(this.element); + } +}); + +/*--------------------------------------------------------------------------*/ + +Abstract.EventObserver = function () { +} +Abstract.EventObserver.prototype = { + initialize: function (element, callback) { + this.element = $(element); + this.callback = callback; + + this.lastValue = this.getValue(); + if (this.element.tagName.toLowerCase() == 'form') { + this.registerFormCallbacks(); + } else { + this.registerCallback(this.element); + } + }, + + onElementEvent: function () { + var value = this.getValue(); + if (this.lastValue != value) { + this.callback(this.element, value); + this.lastValue = value; + } + }, + + registerFormCallbacks: function () { + var elements = Form.getElements(this.element); + for (var i = 0; i < elements.length; i++) { + this.registerCallback(elements[i]); + } + }, + + registerCallback: function (element) { + if (element.type) { + switch (element.type.toLowerCase()) { + case 'checkbox': + case 'radio': + element.target = this; + element.prev_onclick = element.onclick || Prototype.emptyFunction; + element.onclick = function () { + this.prev_onclick(); + this.target.onElementEvent(); + } + break; + case 'password': + case 'text': + case 'textarea': + case 'select-one': + case 'select-multiple': + element.target = this; + element.prev_onchange = element.onchange || Prototype.emptyFunction; + element.onchange = function () { + this.prev_onchange(); + this.target.onElementEvent(); + } + break; + } + } + } +} + +Form.Element.EventObserver = Class.create(); +Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { + getValue: function () { + return Form.Element.getValue(this.element); + } +}); + +Form.EventObserver = Class.create(); +Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { + getValue: function () { + return Form.serialize(this.element); + } +}); + +if (!window.Event) { + var Event = new Object(); +} + +Object.extend(Event, { + KEY_BACKSPACE: 8, + KEY_TAB: 9, + KEY_RETURN: 13, + KEY_ESC: 27, + KEY_LEFT: 37, + KEY_UP: 38, + KEY_RIGHT: 39, + KEY_DOWN: 40, + KEY_DELETE: 46, + + element: function (event) { + return event.target || event.srcElement; + }, + + isLeftClick: function (event) { + return (((event.which) && (event.which == 1)) || + ((event.button) && (event.button == 1))); + }, + + pointerX: function (event) { + return event.pageX || (event.clientX + + (document.documentElement.scrollLeft || document.body.scrollLeft)); + }, + + pointerY: function (event) { + return event.pageY || (event.clientY + + (document.documentElement.scrollTop || document.body.scrollTop)); + }, + + stop: function (event) { + if (event.preventDefault) { + event.preventDefault(); + event.stopPropagation(); + } else { + event.returnValue = false; + } + }, + + // find the first node with the given tagName, starting from the + // node the event was triggered on; traverses the DOM upwards + findElement: function (event, tagName) { + var element = Event.element(event); + while (element.parentNode && (!element.tagName || + (element.tagName.toUpperCase() != tagName.toUpperCase()))) { + element = element.parentNode; + } + return element; + }, + + observers: false, + + _observeAndCache: function (element, name, observer, useCapture) { + if (!this.observers) { + this.observers = []; + } + if (element.addEventListener) { + this.observers.push([element, name, observer, useCapture]); + element.addEventListener(name, observer, useCapture); + } else if (element.attachEvent) { + this.observers.push([element, name, observer, useCapture]); + element.attachEvent('on' + name, observer); + } + }, + + unloadCache: function () { + if (!Event.observers) { + return; + } + for (var i = 0; i < Event.observers.length; i++) { + Event.stopObserving.apply(this, Event.observers[i]); + Event.observers[i][0] = null; + } + Event.observers = false; + }, + + observe: function (element, name, observer, useCapture) { + var element = $(element); + useCapture = useCapture || false; + + if (name == 'keypress' && + ((/Konqueror|Safari|KHTML/.test(navigator.userAgent)) + || element.attachEvent)) { + name = 'keydown'; + } + + this._observeAndCache(element, name, observer, useCapture); + }, + + stopObserving: function (element, name, observer, useCapture) { + var element = $(element); + useCapture = useCapture || false; + + if (name == 'keypress' && + ((/Konqueror|Safari|KHTML/.test(navigator.userAgent)) + || element.detachEvent)) { + name = 'keydown'; + } + + if (element.removeEventListener) { + element.removeEventListener(name, observer, useCapture); + } else if (element.detachEvent) { + element.detachEvent('on' + name, observer); + } + } +}); + +/* prevent memory leaks in IE */ +Event.observe(window, 'unload', Event.unloadCache, false); + +var Position = { + + // set to true if needed, warning: firefox performance problems + // NOT neeeded for page scrolling, only if draggable contained in + // scrollable elements + includeScrollOffsets: false, + + // must be called before calling withinIncludingScrolloffset, every time the + // page is scrolled + prepare: function () { + this.deltaX = window.pageXOffset + || document.documentElement.scrollLeft + || document.body.scrollLeft + || 0; + this.deltaY = window.pageYOffset + || document.documentElement.scrollTop + || document.body.scrollTop + || 0; + }, + + realOffset: function (element) { + var valueT = 0, valueL = 0; + do { + valueT += element.scrollTop || 0; + valueL += element.scrollLeft || 0; + element = element.parentNode; + } while (element); + return [valueL, valueT]; + }, + + cumulativeOffset: function (element) { + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + element = element.offsetParent; + } while (element); + return [valueL, valueT]; + }, + + // caches x/y coordinate pair to use with overlap + within: function (element, x, y) { + if (this.includeScrollOffsets) { + return this.withinIncludingScrolloffsets(element, x, y); + } + this.xcomp = x; + this.ycomp = y; + this.offset = this.cumulativeOffset(element); + + return (y >= this.offset[1] && + y < this.offset[1] + element.offsetHeight && + x >= this.offset[0] && + x < this.offset[0] + element.offsetWidth); + }, + + withinIncludingScrolloffsets: function (element, x, y) { + var offsetcache = this.realOffset(element); + + this.xcomp = x + offsetcache[0] - this.deltaX; + this.ycomp = y + offsetcache[1] - this.deltaY; + this.offset = this.cumulativeOffset(element); + + return (this.ycomp >= this.offset[1] && + this.ycomp < this.offset[1] + element.offsetHeight && + this.xcomp >= this.offset[0] && + this.xcomp < this.offset[0] + element.offsetWidth); + }, + + // within must be called directly before + overlap: function (mode, element) { + if (!mode) { + return 0; + } + if (mode == 'vertical') { + return ((this.offset[1] + element.offsetHeight) - this.ycomp) / + element.offsetHeight; + } + if (mode == 'horizontal') { + return ((this.offset[0] + element.offsetWidth) - this.xcomp) / + element.offsetWidth; + } + }, + + clone: function (source, target) { + source = $(source); + target = $(target); + target.style.position = 'absolute'; + var offsets = this.cumulativeOffset(source); + target.style.top = offsets[1] + 'px'; + target.style.left = offsets[0] + 'px'; + target.style.width = source.offsetWidth + 'px'; + target.style.height = source.offsetHeight + 'px'; + } +} diff --git a/docs/skin/screen.css b/docs/skin/screen.css new file mode 100644 index 00000000000..fdb20dd9a4b --- /dev/null +++ b/docs/skin/screen.css @@ -0,0 +1,721 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +body { + margin: 0px 0px 0px 0px; + font-family: Verdana, Helvetica, sans-serif; +} + +h1 { + font-size: 160%; + margin: 0px 0px 0px 0px; + padding: 0px; +} + +h2 { + font-size: 140%; + margin: 1em 0px 0.8em 0px; + padding: 0px; + font-weight: bold; +} + +h3 { + font-size: 130%; + margin: 0.8em 0px 0px 0px; + padding: 0px; + font-weight: bold; +} + +.h3 { + margin: 22px 0px 3px 0px; +} + +h4 { + font-size: 120%; + margin: 0.7em 0px 0px 0px; + padding: 0px; + font-weight: normal; + text-align: left; +} + +.h4 { + margin: 18px 0px 0px 0px; +} + +h4.faq { + font-size: 120%; + margin: 18px 0px 0px 0px; + padding: 0px; + font-weight: bold; + text-align: left; +} + +h5 { + font-size: 100%; + margin: 14px 0px 0px 0px; + padding: 0px; + font-weight: normal; + text-align: left; +} + +/** +* table +*/ +table .title { + background-color: #000000; +} + +.ForrestTable { + color: #ffffff; + background-color: #7099C5; + width: 100%; + font-size: 100%; + empty-cells: show; +} + +table caption { + padding-left: 5px; + color: white; + text-align: left; + font-weight: bold; + background-color: #000000; +} + +.ForrestTable td { + color: black; + background-color: #f0f0ff; +} + +.ForrestTable th { + text-align: center; +} + +/** + * Page Header + */ + +#top { + position: relative; + float: left; + width: 100%; + background: #294563; /* if you want a background in the header, put it here */ +} + +#top .breadtrail { + background: #CFDCED; + color: black; + border-bottom: solid 1px white; + padding: 3px 10px; + font-size: 75%; +} + +#top .breadtrail a { + color: black; +} + +#top .header { + float: left; + width: 100%; + background: url("images/header_white_line.gif") repeat-x bottom; +} + +#top .grouplogo { + padding: 7px 0 10px 10px; + float: left; + text-align: left; +} + +#top .projectlogo { + padding: 7px 0 10px 10px; + float: left; + width: 33%; + text-align: right; +} + +#top .projectlogoA1 { + padding: 7px 0 10px 10px; + float: right; +} + +html > body #top .searchbox { + bottom: 0px; +} + +#top .searchbox { + position: absolute; + right: 10px; + height: 42px; + font-size: 70%; + white-space: nowrap; + text-align: right; + color: white; + background-color: #000000; + z-index: 0; + background-image: url(images/rc-t-l-5-1header-2searchbox-3searchbox.png); + background-repeat: no-repeat; + background-position: top left; + bottom: -1px; /* compensate for IE rendering issue */ +} + +#top .searchbox form { + padding: 5px 10px; + margin: 0; +} + +#top .searchbox p { + padding: 0 0 2px 0; + margin: 0; +} + +#top .searchbox input { + font-size: 100%; +} + +#tabs { + clear: both; + padding-left: 10px; + margin: 0; + list-style: none; +} + +/* background: #CFDCED url("images/tab-right.gif") no-repeat right top;*/ +#tabs li { + float: left; + background-image: url(images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png); + background-repeat: no-repeat; + background-position: top right; + background-color: #000000; + margin: 0 3px 0 0; + padding: 0; +} + +/*background: url("images/tab-left.gif") no-repeat left top;*/ +#tabs li a { + float: left; + display: block; + font-family: verdana, arial, sans-serif; + text-decoration: none; + color: black; + white-space: nowrap; + background-image: url(images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png); + background-repeat: no-repeat; + background-position: top left; + padding: 5px 15px 4px; + width: .1em; /* IE/Win fix */ +} + +#tabs li a:hover { + + cursor: pointer; + text-decoration: underline; +} + +#tabs > li a { + width: auto; +} + +/* Rest of IE/Win fix */ + +/* Commented Backslash Hack hides rule from IE5-Mac \*/ +#tabs a { + float: none; +} + +/* End IE5-Mac hack */ + +#top .header .current { + background-color: #4C6C8F; + background-image: url(images/rc-t-r-5-1header-2tab-selected-3tab-selected.png); + background-repeat: no-repeat; + background-position: top right; +} + +#top .header .current a { + font-weight: bold; + padding-bottom: 5px; + color: white; + background-image: url(images/rc-t-l-5-1header-2tab-selected-3tab-selected.png); + background-repeat: no-repeat; + background-position: top left; +} + +#publishedStrip { + padding-right: 10px; + padding-left: 20px; + padding-top: 3px; + padding-bottom: 3px; + color: #ffffff; + font-size: 60%; + font-weight: bold; + background-color: #4C6C8F; + text-align: right; +} + +#level2tabs { + margin: 0; + float: left; + position: relative; + +} + +#level2tabs a:hover { + + cursor: pointer; + text-decoration: underline; + +} + +#level2tabs a { + + cursor: pointer; + text-decoration: none; + background-image: url('images/chapter.gif'); + background-repeat: no-repeat; + background-position: center left; + padding-left: 6px; + margin-left: 6px; +} + +/* +* border-top: solid #4C6C8F 15px; +*/ +#main { + position: relative; + background: white; + clear: both; +} + +#main .breadtrail { + clear: both; + position: relative; + background: #CFDCED; + color: black; + border-bottom: solid 1px black; + border-top: solid 1px black; + padding: 0px 180px; + font-size: 75%; + z-index: 10; +} + +/** +* Round corner +*/ +#roundtop { + background-image: url(images/rc-t-r-15-1body-2menu-3menu.png); + background-repeat: no-repeat; + background-position: top right; +} + +#roundbottom { + background-image: url(images/rc-b-r-15-1body-2menu-3menu.png); + background-repeat: no-repeat; + background-position: top right; +} + +img.corner { + width: 15px; + height: 15px; + border: none; + display: block !important; +} + +.roundtopsmall { + background-image: url(images/rc-t-r-5-1header-2searchbox-3searchbox.png); + background-repeat: no-repeat; + background-position: top right; +} + +#roundbottomsmall { + background-image: url(images/rc-b-r-5-1header-2tab-selected-3tab-selected.png); + background-repeat: no-repeat; + background-position: top right; +} + +img.cornersmall { + width: 5px; + height: 5px; + border: none; + display: block !important; +} + +/** + * Side menu + */ +#menu a { + font-weight: normal; + text-decoration: none; +} + +#menu a:visited { + font-weight: normal; +} + +#menu a:active { + font-weight: normal; +} + +#menu a:hover { + font-weight: normal; + text-decoration: underline; +} + +#menuarea { + width: 10em; +} + +#menu { + position: relative; + float: left; + width: 160px; + padding-top: 0px; + top: -18px; + left: 10px; + z-index: 20; + background-color: #f90; + font-size: 70%; + +} + +.menutitle { + cursor: pointer; + padding: 3px 12px; + margin-left: 10px; + background-image: url('images/chapter.gif'); + background-repeat: no-repeat; + background-position: center left; + font-weight: bold; + +} + +.menutitle:hover { + text-decoration: underline; + cursor: pointer; +} + +#menu .menuitemgroup { + margin: 0px 0px 6px 8px; + padding: 0px; + font-weight: bold; +} + +#menu .selectedmenuitemgroup { + margin: 0px 0px 0px 8px; + padding: 0px; + font-weight: normal; + +} + +#menu .menuitem { + padding: 2px 0px 1px 13px; + background-image: url('images/page.gif'); + background-repeat: no-repeat; + background-position: center left; + font-weight: normal; + margin-left: 10px; +} + +#menu .menupage { + margin: 2px 0px 1px 10px; + padding: 0px 3px 0px 12px; + background-image: url('images/page.gif'); + background-repeat: no-repeat; + background-position: center left; + font-style: normal; +} + +#menu .menupagetitle { + padding: 0px 0px 0px 1px; + font-style: normal; + border-style: solid; + border-width: 1px; + margin-right: 10px; + +} + +#menu .menupageitemgroup { + padding: 3px 0px 4px 6px; + font-style: normal; + border-bottom: 1px solid; + border-left: 1px solid; + border-right: 1px solid; + margin-right: 10px; +} + +#menu .menupageitem { + font-style: normal; + font-weight: normal; + border-width: 0px; + font-size: 90%; +} + +#menu #credit { + text-align: center; +} + +#menu #credit2 { + text-align: center; + padding: 3px 3px 3px 3px; + background-color: #ffffff; +} + +#menu .searchbox { + text-align: center; +} + +#menu .searchbox form { + padding: 3px 3px; + margin: 0; +} + +#menu .searchbox input { + font-size: 100%; +} + +#content { + padding: 20px 20px 20px 180px; + margin: 0; + font: small Verdana, Helvetica, sans-serif; + font-size: 80%; +} + +#content ul { + margin: 0; + padding: 0 25px; +} + +#content li { + padding: 0 5px; +} + +#feedback { + color: black; + background: #CFDCED; + text-align: center; + margin-top: 5px; +} + +#feedback #feedbackto { + font-size: 90%; + color: black; +} + +#footer { + clear: both; + position: relative; /* IE bugfix (http://www.dracos.co.uk/web/css/ie6floatbug/) */ + width: 100%; + background: #CFDCED; + border-top: solid 1px #4C6C8F; + color: black; +} + +#footer .copyright { + position: relative; /* IE bugfix cont'd */ + padding: 5px; + margin: 0; + width: 60%; +} + +#footer .lastmodified { + position: relative; /* IE bugfix cont'd */ + float: right; + width: 30%; + padding: 5px; + margin: 0; + text-align: right; +} + +#footer a { + color: white; +} + +#footer #logos { + text-align: left; +} + +/** + * Misc Styles + */ + +acronym { + cursor: help; +} + +.boxed { + background-color: #a5b6c6; +} + +.underlined_5 { + border-bottom: solid 5px #4C6C8F; +} + +.underlined_10 { + border-bottom: solid 10px #4C6C8F; +} + +/* ==================== snail trail ============================ */ + +.trail { + position: relative; /* IE bugfix cont'd */ + font-size: 70%; + text-align: right; + float: right; + margin: -10px 5px 0px 5px; + padding: 0; +} + +#motd-area { + position: relative; + float: right; + width: 35%; + background-color: #f0f0ff; + border: solid 1px #4C6C8F; + margin: 0px 0px 10px 10px; + padding: 5px; +} + +#minitoc-area { + border-top: solid 1px #4C6C8F; + border-bottom: solid 1px #4C6C8F; + margin: 15px 10% 5px 15px; + /* margin-bottom: 15px; + margin-left: 15px; + margin-right: 10%;*/ + padding-bottom: 7px; + padding-top: 5px; +} + +.minitoc { + list-style-image: url('images/current.gif'); + font-weight: normal; +} + +.abstract { + text-align: justify; +} + +li p { + margin: 0; + padding: 0; +} + +.pdflink { + position: relative; /* IE bugfix cont'd */ + float: right; + margin: 0px 5px; + padding: 0; +} + +.pdflink br { + margin-top: -10px; + padding-left: 1px; +} + +.pdflink a { + display: block; + font-size: 70%; + text-align: center; + margin: 0; + padding: 0; +} + +.pdflink img { + display: block; + height: 16px; + width: 16px; +} + +.xmllink { + position: relative; /* IE bugfix cont'd */ + float: right; + margin: 0px 5px; + padding: 0; +} + +.xmllink br { + margin-top: -10px; + padding-left: 1px; +} + +.xmllink a { + display: block; + font-size: 70%; + text-align: center; + margin: 0; + padding: 0; +} + +.xmllink img { + display: block; + height: 16px; + width: 16px; +} + +.podlink { + position: relative; /* IE bugfix cont'd */ + float: right; + margin: 0px 5px; + padding: 0; +} + +.podlink br { + margin-top: -10px; + padding-left: 1px; +} + +.podlink a { + display: block; + font-size: 70%; + text-align: center; + margin: 0; + padding: 0; +} + +.podlink img { + display: block; + height: 16px; + width: 16px; +} + +.printlink { + position: relative; /* IE bugfix cont'd */ + float: right; +} + +.printlink br { + margin-top: -10px; + padding-left: 1px; +} + +.printlink a { + display: block; + font-size: 70%; + text-align: center; + margin: 0; + padding: 0; +} + +.printlink img { + display: block; + height: 16px; + width: 16px; +} + +p.instruction { + display: list-item; + list-style-image: url('../images/instruction_arrow.png'); + list-style-position: outside; + margin-left: 2em; +} \ No newline at end of file diff --git a/docs/zookeeperAdmin.html b/docs/zookeeperAdmin.html new file mode 100644 index 00000000000..fc3886df7bb --- /dev/null +++ b/docs/zookeeperAdmin.html @@ -0,0 +1,2130 @@ + + + + + + + + ZooKeeper Administrator's Guide + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper Administrator's Guide

+

A Guide to Deployment and Administration

+ + + + +

Deployment

+
+

This section contains information about deploying Zookeeper and + covers these topics:

+ +

The first two sections assume you are interested in installing + ZooKeeper in a production environment such as a datacenter. The final + section covers situations in which you are setting up ZooKeeper on a + limited basis - for evaluation, testing, or development - but not in a + production environment.

+ +

System Requirements

+ +

Supported Platforms

+
    + +
  • + +

    GNU/Linux is supported as a development and production + platform for both server and client.

    + +
  • + +
  • + +

    Sun Solaris is supported as a development and production + platform for both server and client.

    + +
  • + +
  • + +

    FreeBSD is supported as a development and production + platform for both server and client.

    + +
  • + +
  • + +

    Win32 is supported as a development + platform only for both server and client.

    + +
  • + +
  • + +

    Win64 is supported as a development + platform only for both server and client.

    + +
  • + +
  • + +

    MacOSX is supported as a development + platform only for both server and client.

    + +
  • + +
+ +

Required Software

+

ZooKeeper runs in Java, release 1.6 or greater (JDK 6 or + greater, FreeBSD support requires openjdk7). It runs as an + ensemble of ZooKeeper servers. Three + ZooKeeper servers is the minimum recommended size for an + ensemble, and we also recommend that they run on separate + machines. At Yahoo!, ZooKeeper is usually deployed on + dedicated RHEL boxes, with dual-core processors, 2GB of RAM, + and 80GB IDE hard drives.

+ +

Clustered (Multi-Server) Setup

+

For reliable ZooKeeper service, you should deploy ZooKeeper in a + cluster known as an ensemble. As long as a majority + of the ensemble are up, the service will be available. Because Zookeeper + requires a majority, it is best to use an + odd number of machines. For example, with four machines ZooKeeper can + only handle the failure of a single machine; if two machines fail, the + remaining two machines do not constitute a majority. However, with five + machines ZooKeeper can handle the failure of two machines.

+ +
+
Note
+
+

As mentioned in the Getting Started guide, a minimum of three servers are + required for a fault tolerant clustered setup, and it is strongly + recommended that you have an odd number of servers.

+

Usually three servers is more than enough for a production install, but + for maximum reliability during maintenance, you may wish to install + five servers. With three servers, if you perform maintenance on + one of them, you are vulnerable to a failure on one of the other + two servers during that maintenance. If you have five of them + running, you can take one down for maintenance, and know that + you're still OK if one of the other four suddenly fails.

+

Your redundancy considerations should include all aspects of your + environment. If you have three zookeeper servers, but their + network cables are all plugged into the same network switch, then + the failure of that switch will take down your entire ensemble.

+
+
+ +

Here are the steps to setting a server that will be part of an + ensemble. These steps should be performed on every host in the + ensemble:

+
    + +
  1. + +

    Install the Java JDK. You can use the native packaging system + for your system, or download the JDK from:

    + + +

    + http://java.sun.com/javase/downloads/index.jsp +

    + +
  2. + + +
  3. + +

    Set the Java heap size. This is very important to avoid + swapping, which will seriously degrade ZooKeeper performance. To + determine the correct value, use load tests, and make sure you are + well below the usage limit that would cause you to swap. Be + conservative - use a maximum heap size of 3GB for a 4GB + machine.

    + +
  4. + + +
  5. + +

    Install the ZooKeeper Server Package. It can be downloaded + from: +

    + +

    + + + http://zookeeper.apache.org/releases.html + + +

    + +
  6. + + +
  7. + +

    Create a configuration file. This file can be called anything. + Use the following settings as a starting point:

    + + +
    +tickTime=2000
    +dataDir=/var/lib/zookeeper/
    +clientPort=2181
    +initLimit=5
    +syncLimit=2
    +server.1=zoo1:2888:3888
    +server.2=zoo2:2888:3888
    +server.3=zoo3:2888:3888
    + + +

    You can find the meanings of these and other configuration + settings in the section Configuration Parameters. A word + though about a few here:

    + + +

    Every machine that is part of the ZooKeeper ensemble should know + about every other machine in the ensemble. You accomplish this with + the series of lines of the form server.id=host:port:port. The parameters host and port are straightforward. You attribute the + server id to each machine by creating a file named + myid, one for each server, which resides in + that server's data directory, as specified by the configuration file + parameter dataDir.

    +
  8. + + +
  9. +

    The myid file + consists of a single line containing only the text of that machine's + id. So myid of server 1 would contain the text + "1" and nothing else. The id must be unique within the + ensemble and should have a value between 1 and 255.

    + +
  10. + + +
  11. + +

    If your configuration file is set up, you can start a + ZooKeeper server:

    + + +

    +$ java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.16.jar:conf \ + org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg + +

    + + +

    QuorumPeerMain starts a ZooKeeper server, + JMX + management beans are also registered which allows + management through a JMX management console. + The ZooKeeper JMX + document contains details on managing ZooKeeper with JMX. +

    + + +

    See the script bin/zkServer.sh, + which is included in the release, for an example + of starting server instances.

    + + +
  12. + + +
  13. + +

    Test your deployment by connecting to the hosts:

    + + +
      + +
    • + +

      In Java, you can run the following command to execute + simple operations:

      + + +

      +$ java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.16.jar:conf:src/java/lib/jline-2.11.jar \ + org.apache.zookeeper.ZooKeeperMain -server 127.0.0.1:2181 +

      + +
    • + + +
    • + +

      In C, you can compile either the single threaded client or + the multithreaded client: or n the c subdirectory in the + ZooKeeper sources. This compiles the single threaded + client:

      + + +

      + $ make cli_st +

      + + +

      And this compiles the mulithreaded client:

      + + +

      + $ make cli_mt +

      + +
    • + +
    + + +

    Running either program gives you a shell in which to execute + simple file-system-like operations. To connect to ZooKeeper with the + multithreaded client, for example, you would run:

    + + +

    + $ cli_mt 127.0.0.1:2181 +

    + +
  14. + +
+ +

Single Server and Developer Setup

+

If you want to setup ZooKeeper for development purposes, you will + probably want to setup a single server instance of ZooKeeper, and then + install either the Java or C client-side libraries and bindings on your + development machine.

+

The steps to setting up a single server instance are the similar + to the above, except the configuration file is simpler. You can find the + complete instructions in the Installing and + Running ZooKeeper in Single Server Mode section of the ZooKeeper Getting Started + Guide.

+

For information on installing the client side libraries, refer to + the Bindings + section of the ZooKeeper + Programmer's Guide.

+
+ + + +

Administration

+
+

This section contains information about running and maintaining + ZooKeeper and covers these topics:

+ + +

Designing a ZooKeeper Deployment

+

The reliablity of ZooKeeper rests on two basic assumptions.

+
    + +
  1. +

    Only a minority of servers in a deployment + will fail. Failure in this context + means a machine crash, or some error in the network that + partitions a server off from the majority.

    + +
  2. + +
  3. +

    Deployed machines operate correctly. To + operate correctly means to execute code correctly, to have + clocks that work properly, and to have storage and network + components that perform consistently.

    + +
  4. + +
+

The sections below contain considerations for ZooKeeper + administrators to maximize the probability for these assumptions + to hold true. Some of these are cross-machines considerations, + and others are things you should consider for each and every + machine in your deployment.

+ +

Cross Machine Requirements

+

For the ZooKeeper service to be active, there must be a + majority of non-failing machines that can communicate with + each other. To create a deployment that can tolerate the + failure of F machines, you should count on deploying 2xF+1 + machines. Thus, a deployment that consists of three machines + can handle one failure, and a deployment of five machines can + handle two failures. Note that a deployment of six machines + can only handle two failures since three machines is not a + majority. For this reason, ZooKeeper deployments are usually + made up of an odd number of machines.

+

To achieve the highest probability of tolerating a failure + you should try to make machine failures independent. For + example, if most of the machines share the same switch, + failure of that switch could cause a correlated failure and + bring down the service. The same holds true of shared power + circuits, cooling systems, etc.

+ +

Single Machine Requirements

+

If ZooKeeper has to contend with other applications for + access to resourses like storage media, CPU, network, or + memory, its performance will suffer markedly. ZooKeeper has + strong durability guarantees, which means it uses storage + media to log changes before the operation responsible for the + change is allowed to complete. You should be aware of this + dependency then, and take great care if you want to ensure + that ZooKeeper operations aren’t held up by your media. Here + are some things you can do to minimize that sort of + degradation: +

+
    + +
  • + +

    ZooKeeper's transaction log must be on a dedicated + device. (A dedicated partition is not enough.) ZooKeeper + writes the log sequentially, without seeking Sharing your + log device with other processes can cause seeks and + contention, which in turn can cause multi-second + delays.

    + +
  • + + +
  • + +

    Do not put ZooKeeper in a situation that can cause a + swap. In order for ZooKeeper to function with any sort of + timeliness, it simply cannot be allowed to swap. + Therefore, make certain that the maximum heap size given + to ZooKeeper is not bigger than the amount of real memory + available to ZooKeeper. For more on this, see + Things to Avoid + below.

    + +
  • + +
+ +

Provisioning

+

+ +

Things to Consider: ZooKeeper Strengths and Limitations

+

+ +

Administering

+

+ +

Maintenance

+

Little long term maintenance is required for a ZooKeeper + cluster however you must be aware of the following:

+ +

Ongoing Data Directory Cleanup

+

The ZooKeeper Data + Directory contains files which are a persistent copy + of the znodes stored by a particular serving ensemble. These + are the snapshot and transactional log files. As changes are + made to the znodes these changes are appended to a + transaction log, occasionally, when a log grows large, a + snapshot of the current state of all znodes will be written + to the filesystem. This snapshot supercedes all previous + logs. +

+

A ZooKeeper server will not remove + old snapshots and log files when using the default + configuration (see autopurge below), this is the + responsibility of the operator. Every serving environment is + different and therefore the requirements of managing these + files may differ from install to install (backup for example). +

+

The PurgeTxnLog utility implements a simple retention + policy that administrators can use. The API docs contains details on + calling conventions (arguments, etc...). +

+

In the following example the last count snapshots and + their corresponding logs are retained and the others are + deleted. The value of <count> should typically be + greater than 3 (although not required, this provides 3 backups + in the unlikely event a recent log has become corrupted). This + can be run as a cron job on the ZooKeeper server machines to + clean up the logs daily.

+
 java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.16.jar:conf org.apache.zookeeper.server.PurgeTxnLog <dataDir> <snapDir> -n <count>
+

Automatic purging of the snapshots and corresponding + transaction logs was introduced in version 3.4.0 and can be + enabled via the following configuration parameters autopurge.snapRetainCount and autopurge.purgeInterval. For more on + this, see Advanced Configuration + below.

+ +

Debug Log Cleanup (log4j)

+

See the section on logging in this document. It is + expected that you will setup a rolling file appender using the + in-built log4j feature. The sample configuration file in the + release tar's conf/log4j.properties provides an example of + this. +

+ +

Supervision

+

You will want to have a supervisory process that manages + each of your ZooKeeper server processes (JVM). The ZK server is + designed to be "fail fast" meaning that it will shutdown + (process exit) if an error occurs that it cannot recover + from. As a ZooKeeper serving cluster is highly reliable, this + means that while the server may go down the cluster as a whole + is still active and serving requests. Additionally, as the + cluster is "self healing" the failed server once restarted will + automatically rejoin the ensemble w/o any manual + interaction.

+

Having a supervisory process such as daemontools or + SMF + (other options for supervisory process are also available, it's + up to you which one you would like to use, these are just two + examples) managing your ZooKeeper server ensures that if the + process does exit abnormally it will automatically be restarted + and will quickly rejoin the cluster.

+ +

Monitoring

+

The ZooKeeper service can be monitored in one of two + primary ways; 1) the command port through the use of 4 letter words and 2) JMX. See the appropriate section for + your environment/requirements.

+ +

Logging

+

ZooKeeper uses log4j version 1.2 as + its logging infrastructure. The ZooKeeper default log4j.properties + file resides in the conf directory. Log4j requires that + log4j.properties either be in the working directory + (the directory from which ZooKeeper is run) or be accessible from the classpath.

+

For more information, see + Log4j Default Initialization Procedure + of the log4j manual.

+ +

Troubleshooting

+
+ +
+ Server not coming up because of file corruption +
+
+

A server might not be able to read its database and fail to come up because of + some file corruption in the transaction logs of the ZooKeeper server. You will + see some IOException on loading ZooKeeper database. In such a case, + make sure all the other servers in your ensemble are up and working. Use "stat" + command on the command port to see if they are in good health. After you have verified that + all the other servers of the ensemble are up, you can go ahead and clean the database + of the corrupt server. Delete all the files in datadir/version-2 and datalogdir/version-2/. + Restart the server. +

+
+ +
+ +

Configuration Parameters

+

ZooKeeper's behavior is governed by the ZooKeeper configuration + file. This file is designed so that the exact same file can be used by + all the servers that make up a ZooKeeper server assuming the disk + layouts are the same. If servers use different configuration files, care + must be taken to ensure that the list of servers in all of the different + configuration files match.

+
+
Note
+
+ +

In 3.5.0 and later, some of these parameters should be placed in + a dynamic configuration file. If they are placed in the static + configuration file, ZooKeeper will automatically move them over to the + dynamic configuration file. See + Dynamic Reconfiguration for more information.

+ +
+
+ +

Minimum Configuration

+

Here are the minimum configuration keywords that must be defined + in the configuration file:

+
+ +
+ clientPort +
+
+

the port to listen for client connections; that is, the + port that clients attempt to connect to.

+
+ + +
+ dataDir +
+
+

the location where ZooKeeper will store the in-memory + database snapshots and, unless specified otherwise, the + transaction log of updates to the database.

+
+
Note
+
+ +

Be careful where you put the transaction log. A + dedicated transaction log device is key to consistent good + performance. Putting the log on a busy device will adversely + effect performance.

+ +
+
+
+ + +
+ tickTime +
+
+

the length of a single tick, which is the basic time unit + used by ZooKeeper, as measured in milliseconds. It is used to + regulate heartbeats, and timeouts. For example, the minimum + session timeout will be two ticks.

+
+ +
+ +

Advanced Configuration

+

The configuration settings in the section are optional. You can + use them to further fine tune the behaviour of your ZooKeeper servers. + Some can also be set using Java system properties, generally of the + form zookeeper.keyword. The exact system + property, when available, is noted below.

+
+ +
+ dataLogDir +
+
+

(No Java system property)

+

This option will direct the machine to write the + transaction log to the dataLogDir rather than the dataDir. This allows a dedicated log + device to be used, and helps avoid competition between logging + and snaphots.

+
+
Note
+
+ +

Having a dedicated log device has a large impact on + throughput and stable latencies. It is highly recommened to + dedicate a log device and set dataLogDir to point to a directory on + that device, and then make sure to point dataDir to a directory + not residing on that device.

+ +
+
+
+ + +
+ globalOutstandingLimit +
+
+

(Java system property: zookeeper.globalOutstandingLimit.)

+

Clients can submit requests faster than ZooKeeper can + process them, especially if there are a lot of clients. To + prevent ZooKeeper from running out of memory due to queued + requests, ZooKeeper will throttle clients so that there is no + more than globalOutstandingLimit outstanding requests in the + system. The default limit is 1,000.

+
+ + +
+ preAllocSize +
+
+

(Java system property: zookeeper.preAllocSize)

+

To avoid seeks ZooKeeper allocates space in the + transaction log file in blocks of preAllocSize kilobytes. The + default block size is 64M. One reason for changing the size of + the blocks is to reduce the block size if snapshots are taken + more often. (Also, see snapCount).

+
+ + +
+ snapCount +
+
+

(Java system property: zookeeper.snapCount)

+

ZooKeeper logs transactions to a transaction + log. After snapCount transactions are written to a log + file a snapshot is started and a new transaction log + file is created. The default snapCount is + 100,000.

+
+ + +
+ traceFile +
+
+

(Java system property: requestTraceFile)

+

If this option is defined, requests will be will logged to + a trace file named traceFile.year.month.day. Use of this option + provides useful debugging information, but will impact + performance. (Note: The system property has no zookeeper prefix, + and the configuration variable name is different from the system + property. Yes - it's not consistent, and it's annoying.)

+
+ + +
+ maxClientCnxns +
+
+

(No Java system property)

+

Limits the number of concurrent connections (at the socket + level) that a single client, identified by IP address, may make + to a single member of the ZooKeeper ensemble. This is used to + prevent certain classes of DoS attacks, including file + descriptor exhaustion. The default is 60. Setting this to 0 + entirely removes the limit on concurrent connections.

+
+ + +
+ clientPortAddress +
+
+

+ New in 3.3.0: the + address (ipv4, ipv6 or hostname) to listen for client + connections; that is, the address that clients attempt + to connect to. This is optional, by default we bind in + such a way that any connection to the clientPort for any + address/interface/nic on the server will be + accepted.

+
+ + +
+ minSessionTimeout +
+
+

(No Java system property)

+

+ New in 3.3.0: the + minimum session timeout in milliseconds that the server + will allow the client to negotiate. Defaults to 2 times + the tickTime.

+
+ + +
+ maxSessionTimeout +
+
+

(No Java system property)

+

+ New in 3.3.0: the + maximum session timeout in milliseconds that the server + will allow the client to negotiate. Defaults to 20 times + the tickTime.

+
+ + +
+ fsync.warningthresholdms +
+
+

(Java system property: fsync.warningthresholdms)

+

+ New in 3.3.4: A + warning message will be output to the log whenever an + fsync in the Transactional Log (WAL) takes longer than + this value. The values is specified in milliseconds and + defaults to 1000. This value can only be set as a + system property.

+
+ + +
+ autopurge.snapRetainCount +
+
+

(No Java system property)

+

+ New in 3.4.0: + When enabled, ZooKeeper auto purge feature retains + the autopurge.snapRetainCount most + recent snapshots and the corresponding transaction logs in the + dataDir and dataLogDir respectively and deletes the rest. + Defaults to 3. Minimum value is 3.

+
+ + +
+ autopurge.purgeInterval +
+
+

(No Java system property)

+

+ New in 3.4.0: The + time interval in hours for which the purge task has to + be triggered. Set to a positive integer (1 and above) + to enable the auto purging. Defaults to 0.

+
+ + +
+ syncEnabled +
+
+

(Java system property: zookeeper.observer.syncEnabled)

+

+ New in 3.4.6, 3.5.0: + The observers now log transaction and write snapshot to disk + by default like the participants. This reduces the recovery time + of the observers on restart. Set to "false" to disable this + feature. Default is "true"

+
+ +
+ +

Cluster Options

+

The options in this section are designed for use with an ensemble + of servers -- that is, when deploying clusters of servers.

+
+ +
+ electionAlg +
+
+

(No Java system property)

+

Election implementation to use. A value of "0" corresponds + to the original UDP-based version, "1" corresponds to the + non-authenticated UDP-based version of fast leader election, "2" + corresponds to the authenticated UDP-based version of fast + leader election, and "3" corresponds to TCP-based version of + fast leader election. Currently, algorithm 3 is the default

+
+
Note
+
+ +

The implementations of leader election 0, 1, and 2 are now + deprecated . We have the intention + of removing them in the next release, at which point only the + FastLeaderElection will be available. +

+ +
+
+
+ + +
+ initLimit +
+
+

(No Java system property)

+

Amount of time, in ticks (see tickTime), to allow followers to + connect and sync to a leader. Increased this value as needed, if + the amount of data managed by ZooKeeper is large.

+
+ + +
+ leaderServes +
+
+

(Java system property: zookeeper.leaderServes)

+

Leader accepts client connections. Default value is "yes". + The leader machine coordinates updates. For higher update + throughput at thes slight expense of read throughput the leader + can be configured to not accept clients and focus on + coordination. The default to this option is yes, which means + that a leader will accept client connections.

+
+
Note
+
+ +

Turning on leader selection is highly recommended when + you have more than three ZooKeeper servers in an ensemble.

+ +
+
+
+ + +
+ server.x=[hostname]:nnnnn[:nnnnn], etc +
+
+

(No Java system property)

+

servers making up the ZooKeeper ensemble. When the server + starts up, it determines which server it is by looking for the + file myid in the data directory. That file + contains the server number, in ASCII, and it should match + x in server.x in the left hand side of this + setting.

+

The list of servers that make up ZooKeeper servers that is + used by the clients must match the list of ZooKeeper servers + that each ZooKeeper server has.

+

There are two port numbers nnnnn. + The first followers use to connect to the leader, and the second is for + leader election. The leader election port is only necessary if electionAlg + is 1, 2, or 3 (default). If electionAlg is 0, then the second port is not + necessary. If you want to test multiple servers on a single machine, then + different ports can be used for each server.

+
+ + +
+ syncLimit +
+
+

(No Java system property)

+

Amount of time, in ticks (see tickTime), to allow followers to sync + with ZooKeeper. If followers fall too far behind a leader, they + will be dropped.

+
+ + +
+ group.x=nnnnn[:nnnnn] +
+
+

(No Java system property)

+

Enables a hierarchical quorum construction."x" is a group identifier + and the numbers following the "=" sign correspond to server identifiers. + The left-hand side of the assignment is a colon-separated list of server + identifiers. Note that groups must be disjoint and the union of all groups + must be the ZooKeeper ensemble.

+

You will find an example here + +

+
+ + +
+ weight.x=nnnnn +
+
+

(No Java system property)

+

Used along with "group", it assigns a weight to a server when + forming quorums. Such a value corresponds to the weight of a server + when voting. There are a few parts of ZooKeeper that require voting + such as leader election and the atomic broadcast protocol. By default + the weight of server is 1. If the configuration defines groups, but not + weights, then a value of 1 will be assigned to all servers. +

+

You will find an example here + +

+
+ + +
+ cnxTimeout +
+
+

(Java system property: zookeeper.cnxTimeout)

+

Sets the timeout value for opening connections for leader election notifications. + Only applicable if you are using electionAlg 3. +

+
+
Note
+
+ +

Default value is 5 seconds.

+ +
+
+
+ + +
+ standaloneEnabled +
+
+

(No Java system property)

+

+ New in 3.5.0: + When set to false, a single server can be started in replicated + mode, a lone participant can run with observers, and a cluster + can reconfigure down to one node, and up from one node. The + default is true for backwards compatibility. It can be set + using QuorumPeerConfig's setStandaloneEnabled method or by + adding "standaloneEnabled=false" or "standaloneEnabled=true" + to a server's config file. +

+
+ +
+

+ +

Authentication & Authorization Options

+

The options in this section allow control over + authentication/authorization performed by the service.

+
+ +
+ zookeeper.DigestAuthenticationProvider.superDigest +
+
+

(Java system property only: zookeeper.DigestAuthenticationProvider.superDigest)

+

By default this feature is disabled +

+

+ New in 3.2: + Enables a ZooKeeper ensemble administrator to access the + znode hierarchy as a "super" user. In particular no ACL + checking occurs for a user authenticated as + super.

+

org.apache.zookeeper.server.auth.DigestAuthenticationProvider + can be used to generate the superDigest, call it with + one parameter of "super:<password>". Provide the + generated "super:<data>" as the system property value + when starting each server of the ensemble.

+

When authenticating to a ZooKeeper server (from a + ZooKeeper client) pass a scheme of "digest" and authdata + of "super:<password>". Note that digest auth passes + the authdata in plaintext to the server, it would be + prudent to use this authentication method only on + localhost (not over the network) or over an encrypted + connection.

+
+ +
+ +

Experimental Options/Features

+

New features that are currently considered experimental.

+
+ +
+ Read Only Mode Server +
+
+

(Java system property: readonlymode.enabled)

+

+ New in 3.4.0: + Setting this value to true enables Read Only Mode server + support (disabled by default). ROM allows clients + sessions which requested ROM support to connect to the + server even when the server might be partitioned from + the quorum. In this mode ROM clients can still read + values from the ZK service, but will be unable to write + values and see changes from other clients. See + ZOOKEEPER-784 for more details. +

+
+ + +
+ +

Unsafe Options

+

The following options can be useful, but be careful when you use + them. The risk of each is explained along with the explanation of what + the variable does.

+
+ +
+ forceSync +
+
+

(Java system property: zookeeper.forceSync)

+

Requires updates to be synced to media of the transaction + log before finishing processing the update. If this option is + set to no, ZooKeeper will not require updates to be synced to + the media.

+
+ + +
+ jute.maxbuffer: +
+
+

(Java system property: + jute.maxbuffer)

+

This option can only be set as a Java system property. + There is no zookeeper prefix on it. It specifies the maximum + size of the data that can be stored in a znode. The default is + 0xfffff, or just under 1M. If this option is changed, the system + property must be set on all servers and clients otherwise + problems will arise. This is really a sanity check. ZooKeeper is + designed to store data on the order of kilobytes in size.

+
+ + +
+ skipACL +
+
+

(Java system property: zookeeper.skipACL)

+

Skips ACL checks. This results in a boost in throughput, + but opens up full access to the data tree to everyone.

+
+ + +
+ quorumListenOnAllIPs +
+
+

When set to true the ZooKeeper server will listen + for connections from its peers on all available IP addresses, + and not only the address configured in the server list of the + configuration file. It affects the connections handling the + ZAB protocol and the Fast Leader Election protocol. Default + value is false.

+
+ + +
+ +

Disabling data directory autocreation

+

+ New in 3.5: The default + behavior of a ZooKeeper server is to automatically create the + data directory (specified in the configuration file) when + started if that directory does not already exist. This can be + inconvenient and even dangerous in some cases. Take the case + where a configuration change is made to a running server, + wherein the dataDir parameter + is accidentally changed. When the ZooKeeper server is + restarted it will create this non-existent directory and begin + serving - with an empty znode namespace. This scenario can + result in an effective "split brain" situation (i.e. data in + both the new invalid directory and the original valid data + store). As such is would be good to have an option to turn off + this autocreate behavior. In general for production + environments this should be done, unfortunately however the + default legacy behavior cannot be changed at this point and + therefore this must be done on a case by case basis. This is + left to users and to packagers of ZooKeeper distributions. +

+

When running zkServer.sh autocreate can be disabled + by setting the environment variable ZOO_DATADIR_AUTOCREATE_DISABLE to 1. + When running ZooKeeper servers directly from class files this + can be accomplished by setting zookeeper.datadir.autocreate=false on + the java command line, i.e. -Dzookeeper.datadir.autocreate=false + +

+

When this feature is disabled, and the ZooKeeper server + determines that the required directories do not exist it will + generate an error and refuse to start. +

+

A new script zkServer-initialize.sh is provided to + support this new feature. If autocreate is disabled it is + necessary for the user to first install ZooKeeper, then create + the data directory (and potentially txnlog directory), and + then start the server. Otherwise as mentioned in the previous + paragraph the server will not start. Running zkServer-initialize.sh will create the + required directories, and optionally setup the myid file + (optional command line parameter). This script can be used + even if the autocreate feature itself is not used, and will + likely be of use to users as this (setup, including creation + of the myid file) has been an issue for users in the past. + Note that this script ensures the data directories exist only, + it does not create a config file, but rather requires a config + file to be available in order to execute. +

+ +

Performance Tuning Options

+

+ New in 3.5.0: Several subsystems have been reworked + to improve read throughput. This includes multi-threading of the NIO communication subsystem and + request processing pipeline (Commit Processor). NIO is the default client/server communication + subsystem. Its threading model comprises 1 acceptor thread, 1-N selector threads and 0-M + socket I/O worker threads. In the request processing pipeline the system can be configured + to process multiple read request at once while maintaining the same consistency guarantee + (same-session read-after-write). The Commit Processor threading model comprises 1 main + thread and 0-N worker threads. +

+

+ The default values are aimed at maximizing read throughput on a dedicated ZooKeeper machine. + Both subsystems need to have sufficient amount of threads to achieve peak read throughput. +

+
+ + +
+ zookeeper.nio.numSelectorThreads +
+
+

(Java system property only: zookeeper.nio.numSelectorThreads) +

+

+ New in 3.5.0: + Number of NIO selector threads. At least 1 selector thread required. + It is recommended to use more than one selector for large numbers + of client connections. The default value is sqrt( number of cpu cores / 2 ). +

+
+ + +
+ zookeeper.nio.numWorkerThreads +
+
+

(Java system property only: zookeeper.nio.numWorkerThreads) +

+

+ New in 3.5.0: + Number of NIO worker threads. If configured with 0 worker threads, the selector threads + do the socket I/O directly. The default value is 2 times the number of cpu cores. +

+
+ + +
+ zookeeper.commitProcessor.numWorkerThreads +
+
+

(Java system property only: zookeeper.commitProcessor.numWorkerThreads) +

+

+ New in 3.5.0: + Number of Commit Processor worker threads. If configured with 0 worker threads, the main thread + will process the request directly. The default value is the number of cpu cores. +

+
+ + +
+ +

Communication using the Netty framework

+

+ New in + 3.4: Netty + is an NIO based client/server communication framework, it + simplifies (over NIO being used directly) many of the + complexities of network level communication for java + applications. Additionally the Netty framework has built + in support for encryption (SSL) and authentication + (certificates). These are optional features and can be + turned on or off individually. +

+

Prior to version 3.4 ZooKeeper has always used NIO + directly, however in versions 3.4 and later Netty is + supported as an option to NIO (replaces). NIO continues to + be the default, however Netty based communication can be + used in place of NIO by setting the environment variable + "zookeeper.serverCnxnFactory" to + "org.apache.zookeeper.server.NettyServerCnxnFactory". You + have the option of setting this on either the client(s) or + server(s), typically you would want to set this on both, + however that is at your discretion. +

+

+ TBD - tuning options for netty - currently there are none that are netty specific but we should add some. Esp around max bound on the number of reader worker threads netty creates. +

+

+ TBD - how to manage encryption +

+

+ TBD - how to manage certificates +

+ +

AdminServer configuration

+

+ New in 3.5.0: The following + options are used to configure the AdminServer.

+
+ +
+ admin.enableServer +
+
+

(Java system property: zookeeper.admin.enableServer)

+

Set to "false" to disable the AdminServer. By default the + AdminServer is enabled.

+
+ + +
+ admin.serverPort +
+
+

(Java system property: zookeeper.admin.serverPort)

+

The port the embedded Jetty server listens on. Defaults to 8080.

+
+ + +
+ admin.commandURL +
+
+

(Java system property: zookeeper.admin.commandURL)

+

The URL for listing and issuing commands relative to the + root URL. Defaults to "/commands".

+
+ +
+ +

ZooKeeper Commands

+ +

The Four Letter Words

+

ZooKeeper responds to a small set of commands. Each command is + composed of four letters. You issue the commands to ZooKeeper via telnet + or nc, at the client port.

+

Three of the more interesting commands: "stat" gives some + general information about the server and connected clients, + while "srvr" and "cons" give extended details on server and + connections respectively.

+
+ +
+ conf +
+
+

+ New in 3.3.0: Print + details about serving configuration.

+
+ + +
+ cons +
+
+

+ New in 3.3.0: List + full connection/session details for all clients connected + to this server. Includes information on numbers of packets + received/sent, session id, operation latencies, last + operation performed, etc...

+
+ + +
+ crst +
+
+

+ New in 3.3.0: Reset + connection/session statistics for all connections.

+
+ + +
+ dump +
+
+

Lists the outstanding sessions and ephemeral nodes. This + only works on the leader.

+
+ + +
+ envi +
+
+

Print details about serving environment

+
+ + +
+ ruok +
+
+

Tests if server is running in a non-error state. The server + will respond with imok if it is running. Otherwise it will not + respond at all.

+

A response of "imok" does not necessarily indicate that the + server has joined the quorum, just that the server process is active + and bound to the specified client port. Use "stat" for details on + state wrt quorum and client connection information.

+
+ + +
+ srst +
+
+

Reset server statistics.

+
+ + +
+ srvr +
+
+

+ New in 3.3.0: Lists + full details for the server.

+
+ + +
+ stat +
+
+

Lists brief details for the server and connected + clients.

+
+ + +
+ wchs +
+
+

+ New in 3.3.0: Lists + brief information on watches for the server.

+
+ + +
+ wchc +
+
+

+ New in 3.3.0: Lists + detailed information on watches for the server, by + session. This outputs a list of sessions(connections) + with associated watches (paths). Note, depending on the + number of watches this operation may be expensive (ie + impact server performance), use it carefully.

+
+ + +
+ wchp +
+
+

+ New in 3.3.0: Lists + detailed information on watches for the server, by path. + This outputs a list of paths (znodes) with associated + sessions. Note, depending on the number of watches this + operation may be expensive (ie impact server performance), + use it carefully.

+
+ + +
+ mntr +
+
+

+ New in 3.4.0: Outputs a list + of variables that could be used for monitoring the health of the cluster.

+
$ echo mntr | nc localhost 2185
+
+              zk_version  3.4.0
+              zk_avg_latency  0
+              zk_max_latency  0
+              zk_min_latency  0
+              zk_packets_received 70
+              zk_packets_sent 69
+              zk_outstanding_requests 0
+              zk_server_state leader
+              zk_znode_count   4
+              zk_watch_count  0
+              zk_ephemerals_count 0
+              zk_approximate_data_size    27
+              zk_followers    4                   - only exposed by the Leader
+              zk_synced_followers 4               - only exposed by the Leader
+              zk_pending_syncs    0               - only exposed by the Leader
+              zk_open_file_descriptor_count 23    - only available on Unix platforms
+              zk_max_file_descriptor_count 1024   - only available on Unix platforms
+              
+

The output is compatible with java properties format and the content + may change over time (new keys added). Your scripts should expect changes.

+

ATTENTION: Some of the keys are platform specific and some of the keys are only exported by the Leader.

+

The output contains multiple lines with the following format:

+
key \t value
+
+ +
+

Here's an example of the ruok + command:

+
$ echo ruok | nc 127.0.0.1 5111
+        imok
+        
+ +

The AdminServer

+

+ New in 3.5.0: The AdminServer is + an embedded Jetty server that provides an HTTP interface to the four + letter word commands. By default, the server is started on port 8080, + and commands are issued by going to the URL "/commands/[command name]", + e.g., http://localhost:8080/commands/stat. The command response is + returned as JSON. Unlike the original protocol, commands are not + restricted to four-letter names, and commands can have multiple names; + for instance, "stmk" can also be referred to as "set_trace_mask". To + view a list of all available commands, point a browser to the URL + /commands (e.g., http://localhost:8080/commands). See the AdminServer configuration options + for how to change the port and URLs.

+

The AdminServer is enabled by default, but can be disabled by either:

+
    + +
  • +

    Setting the zookeeper.admin.enableServer system + property to false.

    +
  • + +
  • +

    Removing Jetty from the classpath. (This option is + useful if you would like to override ZooKeeper's jetty + dependency.)

    +
  • + +
+

Note that the TCP four letter word interface is still available if + the AdminServer is disabled.

+ +

Data File Management

+

ZooKeeper stores its data in a data directory and its transaction + log in a transaction log directory. By default these two directories are + the same. The server can (and should) be configured to store the + transaction log files in a separate directory than the data files. + Throughput increases and latency decreases when transaction logs reside + on a dedicated log devices.

+ +

The Data Directory

+

This directory has two files in it:

+
    + +
  • + +

    + myid - contains a single integer in + human readable ASCII text that represents the server id.

    + +
  • + + +
  • + +

    + snapshot.<zxid> - holds the fuzzy + snapshot of a data tree.

    + +
  • + +
+

Each ZooKeeper server has a unique id. This id is used in two + places: the myid file and the configuration file. + The myid file identifies the server that + corresponds to the given data directory. The configuration file lists + the contact information for each server identified by its server id. + When a ZooKeeper server instance starts, it reads its id from the + myid file and then, using that id, reads from the + configuration file, looking up the port on which it should + listen.

+

The snapshot files stored in the data + directory are fuzzy snapshots in the sense that during the time the + ZooKeeper server is taking the snapshot, updates are occurring to the + data tree. The suffix of the snapshot file names + is the zxid, the ZooKeeper transaction id, of the + last committed transaction at the start of the snapshot. Thus, the + snapshot includes a subset of the updates to the data tree that + occurred while the snapshot was in process. The snapshot, then, may + not correspond to any data tree that actually existed, and for this + reason we refer to it as a fuzzy snapshot. Still, ZooKeeper can + recover using this snapshot because it takes advantage of the + idempotent nature of its updates. By replaying the transaction log + against fuzzy snapshots ZooKeeper gets the state of the system at the + end of the log.

+ +

The Log Directory

+

The Log Directory contains the ZooKeeper transaction logs. + Before any update takes place, ZooKeeper ensures that the transaction + that represents the update is written to non-volatile storage. A new + log file is started each time a snapshot is begun. The log file's + suffix is the first zxid written to that log.

+ +

File Management

+

The format of snapshot and log files does not change between + standalone ZooKeeper servers and different configurations of + replicated ZooKeeper servers. Therefore, you can pull these files from + a running replicated ZooKeeper server to a development machine with a + stand-alone ZooKeeper server for trouble shooting.

+

Using older log and snapshot files, you can look at the previous + state of ZooKeeper servers and even restore that state. The + LogFormatter class allows an administrator to look at the transactions + in a log.

+

The ZooKeeper server creates snapshot and log files, but + never deletes them. The retention policy of the data and log + files is implemented outside of the ZooKeeper server. The + server itself only needs the latest complete fuzzy snapshot + and the log files from the start of that snapshot. See the + maintenance section in + this document for more details on setting a retention policy + and maintenance of ZooKeeper storage. +

+
+
Note
+
+ +

The data stored in these files is not encrypted. In the case of + storing sensitive data in ZooKeeper, necessary measures need to be + taken to prevent unauthorized access. Such measures are external to + ZooKeeper (e.g., control access to the files) and depend on the + individual settings in which it is being deployed.

+ +
+
+ +

Things to Avoid

+

Here are some common problems you can avoid by configuring + ZooKeeper correctly:

+
+ +
+ inconsistent lists of servers +
+
+

The list of ZooKeeper servers used by the clients must match + the list of ZooKeeper servers that each ZooKeeper server has. + Things work okay if the client list is a subset of the real list, + but things will really act strange if clients have a list of + ZooKeeper servers that are in different ZooKeeper clusters. Also, + the server lists in each Zookeeper server configuration file + should be consistent with one another.

+
+ + +
+ incorrect placement of transasction log +
+
+

The most performance critical part of ZooKeeper is the + transaction log. ZooKeeper syncs transactions to media before it + returns a response. A dedicated transaction log device is key to + consistent good performance. Putting the log on a busy device will + adversely effect performance. If you only have one storage device, + put trace files on NFS and increase the snapshotCount; it doesn't + eliminate the problem, but it should mitigate it.

+
+ + +
+ incorrect Java heap size +
+
+

You should take special care to set your Java max heap size + correctly. In particular, you should not create a situation in + which ZooKeeper swaps to disk. The disk is death to ZooKeeper. + Everything is ordered, so if processing one request swaps the + disk, all other queued requests will probably do the same. the + disk. DON'T SWAP.

+

Be conservative in your estimates: if you have 4G of RAM, do + not set the Java max heap size to 6G or even 4G. For example, it + is more likely you would use a 3G heap for a 4G machine, as the + operating system and the cache also need memory. The best and only + recommend practice for estimating the heap size your system needs + is to run load tests, and then make sure you are well below the + usage limit that would cause the system to swap.

+
+ +
+ +

Best Practices

+

For best results, take note of the following list of good + Zookeeper practices:

+

For multi-tennant installations see the section + detailing ZooKeeper "chroot" support, this can be very useful + when deploying many applications/services interfacing to a + single ZooKeeper cluster.

+
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperAdmin.pdf b/docs/zookeeperAdmin.pdf new file mode 100644 index 00000000000..3f93c1c45b7 Binary files /dev/null and b/docs/zookeeperAdmin.pdf differ diff --git a/docs/zookeeperHierarchicalQuorums.html b/docs/zookeeperHierarchicalQuorums.html new file mode 100644 index 00000000000..029cd345efd --- /dev/null +++ b/docs/zookeeperHierarchicalQuorums.html @@ -0,0 +1,265 @@ + + + + + + + + Introduction to hierarchical quorums + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

Introduction to hierarchical quorums

+
+ + +

+ This document gives an example of how to use hierarchical quorums. The basic idea is + very simple. First, we split servers into groups, and add a line for each group listing + the servers that form this group. Next we have to assign a weight to each server. +

+ + +

+ The following example shows how to configure a system with three groups of three servers + each, and we assign a weight of 1 to each server: +

+ + +
+    group.1=1:2:3
+    group.2=4:5:6
+    group.3=7:8:9
+   
+    weight.1=1
+    weight.2=1
+    weight.3=1
+    weight.4=1
+    weight.5=1
+    weight.6=1
+    weight.7=1
+    weight.8=1
+    weight.9=1
+ 	
+ + +

+ When running the system, we are able to form a quorum once we have a majority of votes from + a majority of non-zero-weight groups. Groups that have zero weight are discarded and not + considered when forming quorums. Looking at the example, we are able to form a quorum once + we have votes from at least two servers from each of two different groups. +

+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperHierarchicalQuorums.pdf b/docs/zookeeperHierarchicalQuorums.pdf new file mode 100644 index 00000000000..ed71ded977e Binary files /dev/null and b/docs/zookeeperHierarchicalQuorums.pdf differ diff --git a/docs/zookeeperInternals.html b/docs/zookeeperInternals.html new file mode 100644 index 00000000000..99eef042101 --- /dev/null +++ b/docs/zookeeperInternals.html @@ -0,0 +1,795 @@ + + + + + + + + ZooKeeper Internals + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper Internals

+ + + + +

Introduction

+
+

This document contains information on the inner workings of ZooKeeper. + So far, it discusses these topics: +

+ +
+ + + +

Atomic Broadcast

+
+

+ At the heart of ZooKeeper is an atomic messaging system that keeps all of the servers in sync.

+ +

Guarantees, Properties, and Definitions

+

+ The specific guarantees provided by the messaging system used by ZooKeeper are the following:

+
+ + +
+ + Reliable delivery + +
+
+

If a message, m, is delivered + by one server, it will be eventually delivered by all servers.

+
+ + +
+ + Total order + +
+
+

If a message is + delivered before message b by one server, a will be delivered before b by all + servers. If a and b are delivered messages, either a will be delivered before b + or b will be delivered before a.

+
+ + +
+ + Causal order + +
+
+

+ If a message b is sent after a message a has been delivered by the sender of b, + a must be ordered before b. If a sender sends c after sending b, c must be ordered after b. +

+
+ + +
+

+ The ZooKeeper messaging system also needs to be efficient, reliable, and easy to + implement and maintain. We make heavy use of messaging, so we need the system to + be able to handle thousands of requests per second. Although we can require at + least k+1 correct servers to send new messages, we must be able to recover from + correlated failures such as power outages. When we implemented the system we had + little time and few engineering resources, so we needed a protocol that is + accessible to engineers and is easy to implement. We found that our protocol + satisfied all of these goals. + +

+

+ Our protocol assumes that we can construct point-to-point FIFO channels between + the servers. While similar services usually assume message delivery that can + lose or reorder messages, our assumption of FIFO channels is very practical + given that we use TCP for communication. Specifically we rely on the following property of TCP:

+
+ + +
+ + Ordered delivery + +
+
+

Data is delivered in the same order it is sent and a message m is + delivered only after all messages sent before m have been delivered. + (The corollary to this is that if message m is lost all messages after m will be lost.)

+
+ + +
+ + No message after close + +
+
+

Once a FIFO channel is closed, no messages will be received from it.

+
+ + +
+

+ FLP proved that consensus cannot be achieved in asynchronous distributed systems + if failures are possible. To ensure we achieve consensus in the presence of failures + we use timeouts. However, we rely on times for liveness not for correctness. So, + if timeouts stop working (clocks malfunction for example) the messaging system may + hang, but it will not violate its guarantees.

+

When describing the ZooKeeper messaging protocol we will talk of packets, + proposals, and messages:

+
+ +
+ + Packet + +
+
+

a sequence of bytes sent through a FIFO channel

+
+
+ + Proposal + +
+
+

a unit of agreement. Proposals are agreed upon by exchanging packets + with a quorum of ZooKeeper servers. Most proposals contain messages, however the + NEW_LEADER proposal is an example of a proposal that does not correspond to a message.

+
+
+ + Message + +
+
+

a sequence of bytes to be atomically broadcast to all ZooKeeper + servers. A message put into a proposal and agreed upon before it is delivered.

+
+ + +
+

+ As stated above, ZooKeeper guarantees a total order of messages, and it also + guarantees a total order of proposals. ZooKeeper exposes the total ordering using + a ZooKeeper transaction id (zxid). All proposals will be stamped with a zxid when + it is proposed and exactly reflects the total ordering. Proposals are sent to all + ZooKeeper servers and committed when a quorum of them acknowledge the proposal. + If a proposal contains a message, the message will be delivered when the proposal + is committed. Acknowledgement means the server has recorded the proposal to persistent storage. + Our quorums have the requirement that any pair of quorum must have at least one server + in common. We ensure this by requiring that all quorums have size (n/2+1) where + n is the number of servers that make up a ZooKeeper service. +

+

+ The zxid has two parts: the epoch and a counter. In our implementation the zxid + is a 64-bit number. We use the high order 32-bits for the epoch and the low order + 32-bits for the counter. Because it has two parts represent the zxid both as a + number and as a pair of integers, (epoch, count). The epoch number represents a + change in leadership. Each time a new leader comes into power it will have its + own epoch number. We have a simple algorithm to assign a unique zxid to a proposal: + the leader simply increments the zxid to obtain a unique zxid for each proposal. + Leadership activation will ensure that only one leader uses a given epoch, so our + simple algorithm guarantees that every proposal will have a unique id. + +

+

+ ZooKeeper messaging consists of two phases:

+
+ +
+ + Leader activation + +
+
+

In this phase a leader establishes the correct state of the system + and gets ready to start making proposals.

+
+ + +
+ + Active messaging + +
+
+

In this phase a leader accepts messages to propose and coordinates message delivery.

+
+ +
+

+ ZooKeeper is a holistic protocol. We do not focus on individual proposals, rather + look at the stream of proposals as a whole. Our strict ordering allows us to do this + efficiently and greatly simplifies our protocol. Leadership activation embodies + this holistic concept. A leader becomes active only when a quorum of followers + (The leader counts as a follower as well. You can always vote for yourself ) has synced + up with the leader, they have the same state. This state consists of all of the + proposals that the leader believes have been committed and the proposal to follow + the leader, the NEW_LEADER proposal. (Hopefully you are thinking to + yourself, Does the set of proposals that the leader believes has been committed + included all the proposals that really have been committed? The answer is yes. + Below, we make clear why.) +

+ +

Leader Activation

+

+ Leader activation includes leader election. We currently have two leader election + algorithms in ZooKeeper: LeaderElection and FastLeaderElection (AuthFastLeaderElection + is a variant of FastLeaderElection that uses UDP and allows servers to perform a simple + form of authentication to avoid IP spoofing). ZooKeeper messaging doesn't care about the + exact method of electing a leader has long as the following holds: +

+
    + + +
  • +

    The leader has seen the highest zxid of all the followers.

    +
  • + +
  • +

    A quorum of servers have committed to following the leader.

    +
  • + + +
+

+ Of these two requirements only the first, the highest zxid amoung the followers + needs to hold for correct operation. The second requirement, a quorum of followers, + just needs to hold with high probability. We are going to recheck the second requirement, + so if a failure happens during or after the leader election and quorum is lost, + we will recover by abandoning leader activation and running another election. +

+

+ After leader election a single server will be designated as a leader and start + waiting for followers to connect. The rest of the servers will try to connect to + the leader. The leader will sync up with followers by sending any proposals they + are missing, or if a follower is missing too many proposals, it will send a full + snapshot of the state to the follower. +

+

+ There is a corner case in which a follower that has proposals, U, not seen + by a leader arrives. Proposals are seen in order, so the proposals of U will have a zxids + higher than zxids seen by the leader. The follower must have arrived after the + leader election, otherwise the follower would have been elected leader given that + it has seen a higher zxid. Since committed proposals must be seen by a quorum of + servers, and a quorum of servers that elected the leader did not see U, the proposals + of you have not been committed, so they can be discarded. When the follower connects + to the leader, the leader will tell the follower to discard U. +

+

+ A new leader establishes a zxid to start using for new proposals by getting the + epoch, e, of the highest zxid it has seen and setting the next zxid to use to be + (e+1, 0), fter the leader syncs with a follower, it will propose a NEW_LEADER + proposal. Once the NEW_LEADER proposal has been committed, the leader will activate + and start receiving and issuing proposals. +

+

+ It all sounds complicated but here are the basic rules of operation during leader + activation: +

+
    + +
  • +

    A follower will ACK the NEW_LEADER proposal after it has synced with the leader.

    +
  • + +
  • +

    A follower will only ACK a NEW_LEADER proposal with a given zxid from a single server.

    +
  • + +
  • +

    A new leader will COMMIT the NEW_LEADER proposal when a quorum of followers have ACKed it.

    +
  • + +
  • +

    A follower will commit any state it received from the leader when the NEW_LEADER proposal is COMMIT.

    +
  • + +
  • +

    A new leader will not accept new proposals until the NEW_LEADER proposal has been COMMITED.

    +
  • + +
+

+ If leader election terminates erroneously, we don't have a problem since the + NEW_LEADER proposal will not be committed since the leader will not have quorum. + When this happens, the leader and any remaining followers will timeout and go back + to leader election. +

+ +

Active Messaging

+

+ Leader Activation does all the heavy lifting. Once the leader is coronated he can + start blasting out proposals. As long as he remains the leader no other leader can + emerge since no other leader will be able to get a quorum of followers. If a new + leader does emerge, + it means that the leader has lost quorum, and the new leader will clean up any + mess left over during her leadership activation. +

+

ZooKeeper messaging operates similar to a classic two-phase commit.

+ +

+ All communication channels are FIFO, so everything is done in order. Specifically + the following operating constraints are observed:

+
    + + +
  • +

    The leader sends proposals to all followers using + the same order. Moreover, this order follows the order in which requests have been + received. Because we use FIFO channels this means that followers also receive proposals in order. +

    +
  • + + +
  • +

    Followers process messages in the order they are received. This + means that messages will be ACKed in order and the leader will receive ACKs from + followers in order, due to the FIFO channels. It also means that if message $m$ + has been written to non-volatile storage, all messages that were proposed before + $m$ have been written to non-volatile storage.

    +
  • + + +
  • +

    The leader will issue a COMMIT to all followers as soon as a + quorum of followers have ACKed a message. Since messages are ACKed in order, + COMMITs will be sent by the leader as received by the followers in order.

    +
  • + + +
  • +

    COMMITs are processed in order. Followers deliver a proposals + message when that proposal is committed.

    +
  • + + +
+ +

Summary

+

So there you go. Why does it work? Specifically, why does is set of proposals + believed by a new leader always contain any proposal that has actually been committed? + First, all proposals have a unique zxid, so unlike other protocols, we never have + to worry about two different values being proposed for the same zxid; followers + (a leader is also a follower) see and record proposals in order; proposals are + committed in order; there is only one active leader at a time since followers only + follow a single leader at a time; a new leader has seen all committed proposals + from the previous epoch since it has seen the highest zxid from a quorum of servers; + any uncommited proposals from a previous epoch seen by a new leader will be committed + by that leader before it becomes active.

+ +

Comparisons

+

+ Isn't this just Multi-Paxos? No, Multi-Paxos requires some way of assuring that + there is only a single coordinator. We do not count on such assurances. Instead + we use the leader activation to recover from leadership change or old leaders + believing they are still active. +

+

+ Isn't this just Paxos? Your active messaging phase looks just like phase 2 of Paxos? + Actually, to us active messaging looks just like 2 phase commit without the need to + handle aborts. Active messaging is different from both in the sense that it has + cross proposal ordering requirements. If we do not maintain strict FIFO ordering of + all packets, it all falls apart. Also, our leader activation phase is different from + both of them. In particular, our use of epochs allows us to skip blocks of uncommitted + proposals and to not worry about duplicate proposals for a given zxid. +

+
+ + + +

Quorums

+
+

+ Atomic broadcast and leader election use the notion of quorum to guarantee a consistent + view of the system. By default, ZooKeeper uses majority quorums, which means that every + voting that happens in one of these protocols requires a majority to vote on. One example is + acknowledging a leader proposal: the leader can only commit once it receives an + acknowledgement from a quorum of servers. +

+

+ If we extract the properties that we really need from our use of majorities, we have that we only + need to guarantee that groups of processes used to validate an operation by voting (e.g., acknowledging + a leader proposal) pairwise intersect in at least one server. Using majorities guarantees such a property. + However, there are other ways of constructing quorums different from majorities. For example, we can assign + weights to the votes of servers, and say that the votes of some servers are more important. To obtain a quorum, + we get enough votes so that the sum of weights of all votes is larger than half of the total sum of all weights. +

+

+ A different construction that uses weights and is useful in wide-area deployments (co-locations) is a hierarchical + one. With this construction, we split the servers into disjoint groups and assign weights to processes. To form + a quorum, we have to get a hold of enough servers from a majority of groups G, such that for each group g in G, + the sum of votes from g is larger than half of the sum of weights in g. Interestingly, this construction enables + smaller quorums. If we have, for example, 9 servers, we split them into 3 groups, and assign a weight of 1 to each + server, then we are able to form quorums of size 4. Note that two subsets of processes composed each of a majority + of servers from each of a majority of groups necessarily have a non-empty intersection. It is reasonable to expect + that a majority of co-locations will have a majority of servers available with high probability. +

+

+ With ZooKeeper, we provide a user with the ability of configuring servers to use majority quorums, weights, or a + hierarchy of groups. +

+
+ + + +

Logging

+
+

+ Zookeeper uses + slf4j as an abstraction layer for logging. + log4j in version 1.2 is chosen as the final logging implementation for now. + For better embedding support, it is planned in the future to leave the decision of choosing the final logging implementation to the end user. + Therefore, always use the slf4j api to write log statements in the code, but configure log4j for how to log at runtime. + Note that slf4j has no FATAL level, former messages at FATAL level have been moved to ERROR level. + For information on configuring log4j for + ZooKeeper, see the Logging section + of the ZooKeeper Administrator's Guide. + + +

+ +

Developer Guidelines

+

Please follow the + slf4j manual when creating log statements within code. + Also read the + FAQ on performance + , when creating log statements. Patch reviewers will look for the following:

+ +

Logging at the Right Level

+

+ There are several levels of logging in slf4j. + It's important to pick the right one. In order of higher to lower severity:

+
    + +
  1. +

    ERROR level designates error events that might still allow the application to continue running.

    +
  2. + +
  3. +

    WARN level designates potentially harmful situations.

    +
  4. + +
  5. +

    INFO level designates informational messages that highlight the progress of the application at coarse-grained level.

    +
  6. + +
  7. +

    DEBUG Level designates fine-grained informational events that are most useful to debug an application.

    +
  8. + +
  9. +

    TRACE Level designates finer-grained informational events than the DEBUG.

    +
  10. + +
+

+ ZooKeeper is typically run in production such that log messages of INFO level + severity and higher (more severe) are output to the log.

+ +

Use of Standard slf4j Idioms

+

+ Static Message Logging +

+
+LOG.debug("process completed successfully!");
+
+

+ However when creating parameterized messages are required, use formatting anchors. +

+
+LOG.debug("got {} messages in {} minutes",new Object[]{count,time});    
+
+

+ Naming +

+

+ Loggers should be named after the class in which they are used. +

+
+public class Foo {
+    private static final Logger LOG = LoggerFactory.getLogger(Foo.class);
+    ....
+    public Foo() {
+       LOG.info("constructing Foo");
+
+

+ Exception handling +

+
+try {
+  // code
+} catch (XYZException e) {
+  // do this
+  LOG.error("Something bad happened", e);
+  // don't do this (generally)
+  // LOG.error(e);
+  // why? because "don't do" case hides the stack trace
+ 
+  // continue process here as you need... recover or (re)throw
+}
+
+
+ + +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperInternals.pdf b/docs/zookeeperInternals.pdf new file mode 100644 index 00000000000..b4b04a208dc Binary files /dev/null and b/docs/zookeeperInternals.pdf differ diff --git a/docs/zookeeperJMX.html b/docs/zookeeperJMX.html new file mode 100644 index 00000000000..f3ad76cba6b --- /dev/null +++ b/docs/zookeeperJMX.html @@ -0,0 +1,476 @@ + + + + + + + + ZooKeeper JMX + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper JMX

+ + + + +

JMX

+
+

Apache ZooKeeper has extensive support for JMX, allowing you + to view and manage a ZooKeeper serving ensemble.

+

This document assumes that you have basic knowledge of + JMX. See + Sun JMX Technology page to get started with JMX. +

+

See the + JMX Management Guide for details on setting up local and + remote management of VM instances. By default the included + zkServer.sh supports only local management - + review the linked document to enable support for remote management + (beyond the scope of this document). +

+
+ + + +

Starting ZooKeeper with JMX enabled

+
+

The class + org.apache.zookeeper.server.quorum.QuorumPeerMain + will start a JMX manageable ZooKeeper server. This class + registers the proper MBeans during initalization to support JMX + monitoring and management of the + instance. See bin/zkServer.sh for one + example of starting ZooKeeper using QuorumPeerMain.

+
+ + + +

Run a JMX console

+
+

There are a number of JMX consoles available which can connect + to the running server. For this example we will use Sun's + jconsole.

+

The Java JDK ships with a simple JMX console + named jconsole + which can be used to connect to ZooKeeper and inspect a running + server. Once you've started ZooKeeper using QuorumPeerMain + start jconsole, which typically resides in + JDK_HOME/bin/jconsole +

+

When the "new connection" window is displayed either connect + to local process (if jconsole started on same host as Server) or + use the remote process connection.

+

By default the "overview" tab for the VM is displayed (this + is a great way to get insight into the VM btw). Select + the "MBeans" tab.

+

You should now see org.apache.ZooKeeperService + on the left hand side. Expand this item and depending on how you've + started the server you will be able to monitor and manage various + service related features.

+

Also note that ZooKeeper will register log4j MBeans as + well. In the same section along the left hand side you will see + "log4j". Expand that to manage log4j through JMX. Of particular + interest is the ability to dynamically change the logging levels + used by editing the appender and root thresholds. Log4j MBean + registration can be disabled by passing + -Dzookeeper.jmx.log4j.disable=true to the JVM + when starting ZooKeeper. +

+
+ + + +

ZooKeeper MBean Reference

+
+

This table details JMX for a server participating in a + replicated ZooKeeper ensemble (ie not standalone). This is the + typical case for a production environment.

+ + + + MBeans, their names and description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MBeans, their names and description
MBeanMBean Object NameDescription
QuorumReplicatedServer_id<#>Represents the Quorum, or Ensemble - parent of all + cluster members. Note that the object name includes the + "myid" of the server (name suffix) that your JMX agent has + connected to. +
LocalPeer|RemotePeerreplica.<#>Represents a local or remote peer (ie server + participating in the ensemble). Note that the object name + includes the "myid" of the server (name suffix). +
LeaderElectionLeaderElectionRepresents a ZooKeeper cluster leader election which is + in progress. Provides information about the election, such as + when it started. +
LeaderLeaderIndicates that the parent replica is the leader and + provides attributes/operations for that server. Note that + Leader is a subclass of ZooKeeperServer, so it provides + all of the information normally associated with a + ZooKeeperServer node. +
FollowerFollowerIndicates that the parent replica is a follower and + provides attributes/operations for that server. Note that + Follower is a subclass of ZooKeeperServer, so it provides + all of the information normally associated with a + ZooKeeperServer node. +
DataTreeInMemoryDataTreeStatistics on the in memory znode database, also + operations to access finer (and more computationally + intensive) statistics on the data (such as ephemeral + count). InMemoryDataTrees are children of ZooKeeperServer + nodes. +
ServerCnxn<session_id>Statistics on each client connection, also + operations on those connections (such as + termination). Note the object name is the session id of + the connection in hex form. +
+

This table details JMX for a standalone server. Typically + standalone is only used in development situations.

+ + + + MBeans, their names and description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MBeans, their names and description
MBeanMBean Object NameDescription
ZooKeeperServerStandaloneServer_port<#>Statistics on the running server, also operations + to reset these attributes. Note that the object name + includes the client port of the server (name + suffix). +
DataTreeInMemoryDataTreeStatistics on the in memory znode database, also + operations to access finer (and more computationally + intensive) statistics on the data (such as ephemeral + count). +
ServerCnxn<session_id>Statistics on each client connection, also + operations on those connections (such as + termination). Note the object name is the session id of + the connection in hex form. +
+
+ + +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperJMX.pdf b/docs/zookeeperJMX.pdf new file mode 100644 index 00000000000..5cab92d3a60 Binary files /dev/null and b/docs/zookeeperJMX.pdf differ diff --git a/docs/zookeeperObservers.html b/docs/zookeeperObservers.html new file mode 100644 index 00000000000..e4b1e2ac486 --- /dev/null +++ b/docs/zookeeperObservers.html @@ -0,0 +1,355 @@ + + + + + + + + ZooKeeper Observers + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper Observers

+ + + + +

Observers: Scaling ZooKeeper Without Hurting Write Performance +

+
+

+ Although ZooKeeper performs very well by having clients connect directly + to voting members of the ensemble, this architecture makes it hard to + scale out to huge numbers of clients. The problem is that as we add more + voting members, the write performance drops. This is due to the fact that + a write operation requires the agreement of (in general) at least half the + nodes in an ensemble and therefore the cost of a vote can increase + significantly as more voters are added. +

+

+ We have introduced a new type of ZooKeeper node called + an Observer which helps address this problem and + further improves ZooKeeper's scalability. Observers are non-voting members + of an ensemble which only hear the results of votes, not the agreement + protocol that leads up to them. Other than this simple distinction, + Observers function exactly the same as Followers - clients may connect to + them and send read and write requests to them. Observers forward these + requests to the Leader like Followers do, but they then simply wait to + hear the result of the vote. Because of this, we can increase the number + of Observers as much as we like without harming the performance of votes. +

+

+ Observers have other advantages. Because they do not vote, they are not a + critical part of the ZooKeeper ensemble. Therefore they can fail, or be + disconnected from the cluster, without harming the availability of the + ZooKeeper service. The benefit to the user is that Observers may connect + over less reliable network links than Followers. In fact, Observers may be + used to talk to a ZooKeeper server from another data center. Clients of + the Observer will see fast reads, as all reads are served locally, and + writes result in minimal network traffic as the number of messages + required in the absence of the vote protocol is smaller. +

+
+ + +

How to use Observers

+
+

Setting up a ZooKeeper ensemble that uses Observers is very simple, + and requires just two changes to your config files. Firstly, in the config + file of every node that is to be an Observer, you must place this line: +

+
+      peerType=observer
+    
+

+ This line tells ZooKeeper that the server is to be an Observer. Secondly, + in every server config file, you must add :observer to the server + definition line of each Observer. For example: +

+
+      server.1:localhost:2181:3181:observer
+    
+

+ This tells every other server that server.1 is an Observer, and that they + should not expect it to vote. This is all the configuration you need to do + to add an Observer to your ZooKeeper cluster. Now you can connect to it as + though it were an ordinary Follower. Try it out, by running:

+
+      bin/zkCli.sh -server localhost:2181
+    
+

+ where localhost:2181 is the hostname and port number of the Observer as + specified in every config file. You should see a command line prompt + through which you can issue commands like ls to query + the ZooKeeper service. +

+
+ + + +

Example use cases

+
+

+ Two example use cases for Observers are listed below. In fact, wherever + you wish to scale the numbe of clients of your ZooKeeper ensemble, or + where you wish to insulate the critical part of an ensemble from the load + of dealing with client requests, Observers are a good architectural + choice. +

+
    + +
  • + +

    As a datacenter bridge: Forming a ZK ensemble between two + datacenters is a problematic endeavour as the high variance in latency + between the datacenters could lead to false positive failure detection + and partitioning. However if the ensemble runs entirely in one + datacenter, and the second datacenter runs only Observers, partitions + aren't problematic as the ensemble remains connected. Clients of the + Observers may still see and issue proposals.

    + +
  • + +
  • + +

    As a link to a message bus: Some companies have expressed an + interest in using ZK as a component of a persistent reliable message + bus. Observers would give a natural integration point for this work: a + plug-in mechanism could be used to attach the stream of proposals an + Observer sees to a publish-subscribe system, again without loading the + core ensemble. +

    + +
  • + +
+
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperObservers.pdf b/docs/zookeeperObservers.pdf new file mode 100644 index 00000000000..e4c442b6852 Binary files /dev/null and b/docs/zookeeperObservers.pdf differ diff --git a/docs/zookeeperOtherInfo.html b/docs/zookeeperOtherInfo.html new file mode 100644 index 00000000000..9dba4b29f27 --- /dev/null +++ b/docs/zookeeperOtherInfo.html @@ -0,0 +1,232 @@ + + + + + + + + ZooKeeper + + + + + + + + + + + +
+ +
+ Apache > Hadoop > ZooKeeper + +
+ +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper

+
+ +
+ + + +

Other Info

+
+

currently empty

+
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperOtherInfo.pdf b/docs/zookeeperOtherInfo.pdf new file mode 100644 index 00000000000..bbefa133980 Binary files /dev/null and b/docs/zookeeperOtherInfo.pdf differ diff --git a/docs/zookeeperOver.html b/docs/zookeeperOver.html new file mode 100644 index 00000000000..038671a68aa --- /dev/null +++ b/docs/zookeeperOver.html @@ -0,0 +1,693 @@ + + + + + + + + ZooKeeper + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper

+ + + + +

ZooKeeper: A Distributed Coordination Service for Distributed + Applications

+
+

ZooKeeper is a distributed, open-source coordination service for + distributed applications. It exposes a simple set of primitives that + distributed applications can build upon to implement higher level services + for synchronization, configuration maintenance, and groups and naming. It + is designed to be easy to program to, and uses a data model styled after + the familiar directory tree structure of file systems. It runs in Java and + has bindings for both Java and C.

+

Coordination services are notoriously hard to get right. They are + especially prone to errors such as race conditions and deadlock. The + motivation behind ZooKeeper is to relieve distributed applications the + responsibility of implementing coordination services from scratch.

+ +

Design Goals

+

+ ZooKeeper is simple. ZooKeeper + allows distributed processes to coordinate with each other through a + shared hierarchal namespace which is organized similarly to a standard + file system. The name space consists of data registers - called znodes, + in ZooKeeper parlance - and these are similar to files and directories. + Unlike a typical file system, which is designed for storage, ZooKeeper + data is kept in-memory, which means ZooKeeper can achieve high + throughput and low latency numbers.

+

The ZooKeeper implementation puts a premium on high performance, + highly available, strictly ordered access. The performance aspects of + ZooKeeper means it can be used in large, distributed systems. The + reliability aspects keep it from being a single point of failure. The + strict ordering means that sophisticated synchronization primitives can + be implemented at the client.

+

+ ZooKeeper is replicated. Like the + distributed processes it coordinates, ZooKeeper itself is intended to be + replicated over a sets of hosts called an ensemble.

+ + + + + + + +
ZooKeeper Service
+ + + +
+

The servers that make up the ZooKeeper service must all know about + each other. They maintain an in-memory image of state, along with a + transaction logs and snapshots in a persistent store. As long as a + majority of the servers are available, the ZooKeeper service will be + available.

+

Clients connect to a single ZooKeeper server. The client maintains + a TCP connection through which it sends requests, gets responses, gets + watch events, and sends heart beats. If the TCP connection to the server + breaks, the client will connect to a different server.

+

+ ZooKeeper is ordered. ZooKeeper + stamps each update with a number that reflects the order of all + ZooKeeper transactions. Subsequent operations can use the order to + implement higher-level abstractions, such as synchronization + primitives.

+

+ ZooKeeper is fast. It is + especially fast in "read-dominant" workloads. ZooKeeper applications run + on thousands of machines, and it performs best where reads are more + common than writes, at ratios of around 10:1.

+ +

Data model and the hierarchical namespace

+

The name space provided by ZooKeeper is much like that of a + standard file system. A name is a sequence of path elements separated by + a slash (/). Every node in ZooKeeper's name space is identified by a + path.

+ + + + + + + +
ZooKeeper's Hierarchical Namespace
+ + + +
+ +

Nodes and ephemeral nodes

+

Unlike is standard file systems, each node in a ZooKeeper + namespace can have data associated with it as well as children. It is + like having a file-system that allows a file to also be a directory. + (ZooKeeper was designed to store coordination data: status information, + configuration, location information, etc., so the data stored at each + node is usually small, in the byte to kilobyte range.) We use the term + znode to make it clear that we are talking about + ZooKeeper data nodes.

+

Znodes maintain a stat structure that includes version numbers for + data changes, ACL changes, and timestamps, to allow cache validations + and coordinated updates. Each time a znode's data changes, the version + number increases. For instance, whenever a client retrieves data it also + receives the version of the data.

+

The data stored at each znode in a namespace is read and written + atomically. Reads get all the data bytes associated with a znode and a + write replaces all the data. Each node has an Access Control List (ACL) + that restricts who can do what.

+

ZooKeeper also has the notion of ephemeral nodes. These znodes + exists as long as the session that created the znode is active. When the + session ends the znode is deleted. Ephemeral nodes are useful when you + want to implement [tbd].

+ +

Conditional updates and watches

+

ZooKeeper supports the concept of watches. + Clients can set a watch on a znodes. A watch will be triggered and + removed when the znode changes. When a watch is triggered the client + receives a packet saying that the znode has changed. And if the + connection between the client and one of the Zoo Keeper servers is + broken, the client will receive a local notification. These can be used + to [tbd].

+ +

Guarantees

+

ZooKeeper is very fast and very simple. Since its goal, though, is + to be a basis for the construction of more complicated services, such as + synchronization, it provides a set of guarantees. These are:

+
    + +
  • + +

    Sequential Consistency - Updates from a client will be applied + in the order that they were sent.

    + +
  • + + +
  • + +

    Atomicity - Updates either succeed or fail. No partial + results.

    + +
  • + + +
  • + +

    Single System Image - A client will see the same view of the + service regardless of the server that it connects to.

    + +
  • + +
+
    + +
  • + +

    Reliability - Once an update has been applied, it will persist + from that time forward until a client overwrites the update.

    + +
  • + +
+
    + +
  • + +

    Timeliness - The clients view of the system is guaranteed to + be up-to-date within a certain time bound.

    + +
  • + +
+

For more information on these, and how they can be used, see + [tbd] +

+ +

Simple API

+

One of the design goals of ZooKeeper is provide a very simple + programming interface. As a result, it supports only these + operations:

+
+ +
+ create +
+
+

creates a node at a location in the tree

+
+ + +
+ delete +
+
+

deletes a node

+
+ + +
+ exists +
+
+

tests if a node exists at a location

+
+ + +
+ get data +
+
+

reads the data from a node

+
+ + +
+ set data +
+
+

writes data to a node

+
+ + +
+ get children +
+
+

retrieves a list of children of a node

+
+ + +
+ sync +
+
+

waits for data to be propagated

+
+ +
+

For a more in-depth discussion on these, and how they can be used + to implement higher level operations, please refer to + [tbd] +

+ +

Implementation

+

+ ZooKeeper Components shows the high-level components + of the ZooKeeper service. With the exception of the request processor, + each of + the servers that make up the ZooKeeper service replicates its own copy + of each of components.

+ + + + + + + +
ZooKeeper Components
+ + + +
+

The replicated database is an in-memory database containing the + entire data tree. Updates are logged to disk for recoverability, and + writes are serialized to disk before they are applied to the in-memory + database.

+

Every ZooKeeper server services clients. Clients connect to + exactly one server to submit irequests. Read requests are serviced from + the local replica of each server database. Requests that change the + state of the service, write requests, are processed by an agreement + protocol.

+

As part of the agreement protocol all write requests from clients + are forwarded to a single server, called the + leader. The rest of the ZooKeeper servers, called + followers, receive message proposals from the + leader and agree upon message delivery. The messaging layer takes care + of replacing leaders on failures and syncing followers with + leaders.

+

ZooKeeper uses a custom atomic messaging protocol. Since the + messaging layer is atomic, ZooKeeper can guarantee that the local + replicas never diverge. When the leader receives a write request, it + calculates what the state of the system is when the write is to be + applied and transforms this into a transaction that captures this new + state.

+ +

Uses

+

The programming interface to ZooKeeper is deliberately simple. + With it, however, you can implement higher order operations, such as + synchronizations primitives, group membership, ownership, etc. Some + distributed applications have used it to: [tbd: add uses from + white paper and video presentation.] For more information, see + [tbd] +

+ +

Performance

+

ZooKeeper is designed to be highly performant. But is it? The + results of the ZooKeeper's development team at Yahoo! Research indicate + that it is. (See ZooKeeper Throughput as the Read-Write Ratio Varies.) It is especially high + performance in applications where reads outnumber writes, since writes + involve synchronizing the state of all servers. (Reads outnumbering + writes is typically the case for a coordination service.)

+ + + + + + + +
ZooKeeper Throughput as the Read-Write Ratio Varies
+ + + +
+

The figure ZooKeeper Throughput as the Read-Write Ratio Varies is a throughput + graph of ZooKeeper release 3.2 running on servers with dual 2Ghz + Xeon and two SATA 15K RPM drives. One drive was used as a + dedicated ZooKeeper log device. The snapshots were written to + the OS drive. Write requests were 1K writes and the reads were + 1K reads. "Servers" indicate the size of the ZooKeeper + ensemble, the number of servers that make up the + service. Approximately 30 other servers were used to simulate + the clients. The ZooKeeper ensemble was configured such that + leaders do not allow connections from clients.

+
+
Note
+
+

In version 3.2 r/w performance improved by ~2x + compared to the previous + 3.1 release.

+
+
+

Benchmarks also indicate that it is reliable, too. Reliability in the Presence of Errors shows how a deployment responds to + various failures. The events marked in the figure are the + following:

+
    + +
  1. + +

    Failure and recovery of a follower

    + +
  2. + + +
  3. + +

    Failure and recovery of a different follower

    + +
  4. + + +
  5. + +

    Failure of the leader

    + +
  6. + + +
  7. + +

    Failure and recovery of two followers

    + +
  8. + + +
  9. + +

    Failure of another leader

    + +
  10. + +
+ +

Reliability

+

To show the behavior of the system over time as + failures are injected we ran a ZooKeeper service made up of + 7 machines. We ran the same saturation benchmark as before, + but this time we kept the write percentage at a constant + 30%, which is a conservative ratio of our expected + workloads. +

+ + + + + + + +
Reliability in the Presence of Errors
+ + + +
+

The are a few important observations from this graph. First, if + followers fail and recover quickly, then ZooKeeper is able to sustain a + high throughput despite the failure. But maybe more importantly, the + leader election algorithm allows for the system to recover fast enough + to prevent throughput from dropping substantially. In our observations, + ZooKeeper takes less than 200ms to elect a new leader. Third, as + followers recover, ZooKeeper is able to raise throughput again once they + start processing requests.

+ +

The ZooKeeper Project

+

ZooKeeper has been + + successfully used + + in many industrial applications. It is used at Yahoo! as the + coordination and failure recovery service for Yahoo! Message + Broker, which is a highly scalable publish-subscribe system + managing thousands of topics for replication and data + delivery. It is used by the Fetching Service for Yahoo! + crawler, where it also manages failure recovery. A number of + Yahoo! advertising systems also use ZooKeeper to implement + reliable services. +

+

All users and developers are encouraged to join the + community and contribute their expertise. See the + + Zookeeper Project on Apache + + for more information. +

+
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperOver.pdf b/docs/zookeeperOver.pdf new file mode 100644 index 00000000000..7b93a4c3c1d Binary files /dev/null and b/docs/zookeeperOver.pdf differ diff --git a/docs/zookeeperProgrammers.html b/docs/zookeeperProgrammers.html new file mode 100644 index 00000000000..09500a49c17 --- /dev/null +++ b/docs/zookeeperProgrammers.html @@ -0,0 +1,2350 @@ + + + + + + + + ZooKeeper Programmer's Guide + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper Programmer's Guide

+

Developing Distributed Applications that use ZooKeeper

+ + + + +

Introduction

+
+

This document is a guide for developers wishing to create + distributed applications that take advantage of ZooKeeper's coordination + services. It contains conceptual and practical information.

+

The first four sections of this guide present higher level + discussions of various ZooKeeper concepts. These are necessary both for an + understanding of how ZooKeeper works as well how to work with it. It does + not contain source code, but it does assume a familiarity with the + problems associated with distributed computing. The sections in this first + group are:

+ +

The next four sections provide practical programming + information. These are:

+ +

The book concludes with an appendix containing links to other + useful, ZooKeeper-related information.

+

Most of information in this document is written to be accessible as + stand-alone reference material. However, before starting your first + ZooKeeper application, you should probably at least read the chaptes on + the ZooKeeper Data Model and ZooKeeper Basic Operations. Also, + the Simple Programmming + Example [tbd] is helpful for understanding the basic + structure of a ZooKeeper client application.

+
+ + + +

The ZooKeeper Data Model

+
+

ZooKeeper has a hierarchal name space, much like a distributed file + system. The only difference is that each node in the namespace can have + data associated with it as well as children. It is like having a file + system that allows a file to also be a directory. Paths to nodes are + always expressed as canonical, absolute, slash-separated paths; there are + no relative reference. Any unicode character can be used in a path subject + to the following constraints:

+
    + +
  • + +

    The null character (\u0000) cannot be part of a path name. (This + causes problems with the C binding.)

    + +
  • + + +
  • + +

    The following characters can't be used because they don't + display well, or render in confusing ways: \u0001 - \u001F and \u007F + - \u009F.

    + +
  • + + +
  • + +

    The following characters are not allowed: \ud800 - uF8FF, + \uFFF0 - uFFFF.

    + +
  • + + +
  • + +

    The "." character can be used as part of another name, but "." + and ".." cannot alone be used to indicate a node along a path, + because ZooKeeper doesn't use relative paths. The following would be + invalid: "/a/b/./c" or "/a/b/../c".

    + +
  • + + +
  • + +

    The token "zookeeper" is reserved.

    + +
  • + +
+ +

ZNodes

+

Every node in a ZooKeeper tree is referred to as a + znode. Znodes maintain a stat structure that + includes version numbers for data changes, acl changes. The stat + structure also has timestamps. The version number, together with the + timestamp, allows ZooKeeper to validate the cache and to coordinate + updates. Each time a znode's data changes, the version number increases. + For instance, whenever a client retrieves data, it also receives the + version of the data. And when a client performs an update or a delete, + it must supply the version of the data of the znode it is changing. If + the version it supplies doesn't match the actual version of the data, + the update will fail. (This behavior can be overridden. For more + information see... )[tbd...] +

+
+
Note
+
+ +

In distributed application engineering, the word + node can refer to a generic host machine, a + server, a member of an ensemble, a client process, etc. In the ZooKeeper + documentation, znodes refer to the data nodes. + Servers refer to machines that make up the + ZooKeeper service; quorum peers refer to the + servers that make up an ensemble; client refers to any host or process + which uses a ZooKeeper service.

+ +
+
+

Znodes are the main enitity that a programmer access. They have + several characteristics that are worth mentioning here.

+ +

Watches

+

Clients can set watches on znodes. Changes to that znode trigger + the watch and then clear the watch. When a watch triggers, ZooKeeper + sends the client a notification. More information about watches can be + found in the section + ZooKeeper Watches.

+ +

Data Access

+

The data stored at each znode in a namespace is read and written + atomically. Reads get all the data bytes associated with a znode and a + write replaces all the data. Each node has an Access Control List + (ACL) that restricts who can do what.

+

ZooKeeper was not designed to be a general database or large + object store. Instead, it manages coordination data. This data can + come in the form of configuration, status information, rendezvous, etc. + A common property of the various forms of coordination data is that + they are relatively small: measured in kilobytes. + The ZooKeeper client and the server implementations have sanity checks + to ensure that znodes have less than 1M of data, but the data should + be much less than that on average. Operating on relatively large data + sizes will cause some operations to take much more time than others and + will affect the latencies of some operations because of the extra time + needed to move more data over the network and onto storage media. If + large data storage is needed, the usually pattern of dealing with such + data is to store it on a bulk storage system, such as NFS or HDFS, and + store pointers to the storage locations in ZooKeeper.

+ +

Ephemeral Nodes

+

ZooKeeper also has the notion of ephemeral nodes. These znodes + exists as long as the session that created the znode is active. When + the session ends the znode is deleted. Because of this behavior + ephemeral znodes are not allowed to have children.

+ +

Sequence Nodes -- Unique Naming

+

When creating a znode you can also request that + ZooKeeper append a monotonically increasing counter to the end + of path. This counter is unique to the parent znode. The + counter has a format of %010d -- that is 10 digits with 0 + (zero) padding (the counter is formatted in this way to + simplify sorting), i.e. "<path>0000000001". See + Queue + Recipe for an example use of this feature. Note: the + counter used to store the next sequence number is a signed int + (4bytes) maintained by the parent node, the counter will + overflow when incremented beyond 2147483647 (resulting in a + name "<path>-2147483647").

+ +

Time in ZooKeeper

+

ZooKeeper tracks time multiple ways:

+
    + +
  • + +

    + Zxid +

    + + +

    Every change to the ZooKeeper state receives a stamp in the + form of a zxid (ZooKeeper Transaction Id). + This exposes the total ordering of all changes to ZooKeeper. Each + change will have a unique zxid and if zxid1 is smaller than zxid2 + then zxid1 happened before zxid2.

    + +
  • + + +
  • + +

    + Version numbers +

    + + +

    Every change to a node will cause an increase to one of the + version numbers of that node. The three version numbers are version + (number of changes to the data of a znode), cversion (number of + changes to the children of a znode), and aversion (number of changes + to the ACL of a znode).

    + +
  • + + +
  • + +

    + Ticks +

    + + +

    When using multi-server ZooKeeper, servers use ticks to define + timing of events such as status uploads, session timeouts, + connection timeouts between peers, etc. The tick time is only + indirectly exposed through the minimum session timeout (2 times the + tick time); if a client requests a session timeout less than the + minimum session timeout, the server will tell the client that the + session timeout is actually the minimum session timeout.

    + +
  • + + +
  • + +

    + Real time +

    + + +

    ZooKeeper doesn't use real time, or clock time, at all except + to put timestamps into the stat structure on znode creation and + znode modification.

    + +
  • + +
+ +

ZooKeeper Stat Structure

+

The Stat structure for each znode in ZooKeeper is made up of the + following fields:

+
    + +
  • + +

    + czxid +

    + + +

    The zxid of the change that caused this znode to be + created.

    + +
  • + + +
  • + +

    + mzxid +

    + + +

    The zxid of the change that last modified this znode.

    + +
  • + + +
  • + +

    + ctime +

    + + +

    The time in milliseconds from epoch when this znode was + created.

    + +
  • + + +
  • + +

    + mtime +

    + + +

    The time in milliseconds from epoch when this znode was last + modified.

    + +
  • + + +
  • + +

    + version +

    + + +

    The number of changes to the data of this znode.

    + +
  • + + +
  • + +

    + cversion +

    + + +

    The number of changes to the children of this znode.

    + +
  • + + +
  • + +

    + aversion +

    + + +

    The number of changes to the ACL of this znode.

    + +
  • + + +
  • + +

    + ephemeralOwner +

    + + +

    The session id of the owner of this znode if the znode is an + ephemeral node. If it is not an ephemeral node, it will be + zero.

    + +
  • + + +
  • + +

    + dataLength +

    + + +

    The length of the data field of this znode.

    + +
  • + + +
  • + +

    + numChildren +

    + + +

    The number of children of this znode.

    + +
  • + + +
+
+ + + +

ZooKeeper Sessions

+
+

A ZooKeeper client establishes a session with the ZooKeeper + service by creating a handle to the service using a language + binding. Once created, the handle starts of in the CONNECTING state + and the client library tries to connect to one of the servers that + make up the ZooKeeper service at which point it switches to the + CONNECTED state. During normal operation will be in one of these + two states. If an unrecoverable error occurs, such as session + expiration or authentication failure, or if the application explicitly + closes the handle, the handle will move to the CLOSED state. + The following figure shows the possible state transitions of a + ZooKeeper client:

+ +

To create a client session the application code must provide + a connection string containing a comma separated list of host:port pairs, + each corresponding to a ZooKeeper server (e.g. "127.0.0.1:4545" or + "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"). The ZooKeeper + client library will pick an arbitrary server and try to connect to + it. If this connection fails, or if the client becomes + disconnected from the server for any reason, the client will + automatically try the next server in the list, until a connection + is (re-)established.

+

+ Added in 3.2.0: An + optional "chroot" suffix may also be appended to the connection + string. This will run the client commands while interpreting all + paths relative to this root (similar to the unix chroot + command). If used the example would look like: + "127.0.0.1:4545/app/a" or + "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" where the + client would be rooted at "/app/a" and all paths would be relative + to this root - ie getting/setting/etc... "/foo/bar" would result + in operations being run on "/app/a/foo/bar" (from the server + perspective). This feature is particularly useful in multi-tenant + environments where each user of a particular ZooKeeper service + could be rooted differently. This makes re-use much simpler as + each user can code his/her application as if it were rooted at + "/", while actual location (say /app/a) could be determined at + deployment time.

+

When a client gets a handle to the ZooKeeper service, + ZooKeeper creates a ZooKeeper session, represented as a 64-bit + number, that it assigns to the client. If the client connects to a + different ZooKeeper server, it will send the session id as a part + of the connection handshake. As a security measure, the server + creates a password for the session id that any ZooKeeper server + can validate.The password is sent to the client with the session + id when the client establishes the session. The client sends this + password with the session id whenever it reestablishes the session + with a new server.

+

One of the parameters to the ZooKeeper client library call + to create a ZooKeeper session is the session timeout in + milliseconds. The client sends a requested timeout, the server + responds with the timeout that it can give the client. The current + implementation requires that the timeout be a minimum of 2 times + the tickTime (as set in the server configuration) and a maximum of + 20 times the tickTime. The ZooKeeper client API allows access to + the negotiated timeout.

+

When a client (session) becomes partitioned from the ZK + serving cluster it will begin searching the list of servers that + were specified during session creation. Eventually, when + connectivity between the client and at least one of the servers is + re-established, the session will either again transition to the + "connected" state (if reconnected within the session timeout + value) or it will transition to the "expired" state (if + reconnected after the session timeout). It is not advisable to + create a new session object (a new ZooKeeper.class or zookeeper + handle in the c binding) for disconnection. The ZK client library + will handle reconnect for you. In particular we have heuristics + built into the client library to handle things like "herd effect", + etc... Only create a new session when you are notified of session + expiration (mandatory).

+

Session expiration is managed by the ZooKeeper cluster + itself, not by the client. When the ZK client establishes a + session with the cluster it provides a "timeout" value detailed + above. This value is used by the cluster to determine when the + client's session expires. Expirations happens when the cluster + does not hear from the client within the specified session timeout + period (i.e. no heartbeat). At session expiration the cluster will + delete any/all ephemeral nodes owned by that session and + immediately notify any/all connected clients of the change (anyone + watching those znodes). At this point the client of the expired + session is still disconnected from the cluster, it will not be + notified of the session expiration until/unless it is able to + re-establish a connection to the cluster. The client will stay in + disconnected state until the TCP connection is re-established with + the cluster, at which point the watcher of the expired session + will receive the "session expired" notification.

+

Example state transitions for an expired session as seen by + the expired session's watcher:

+
    + +
  1. +

    'connected' : session is established and client + is communicating with cluster (client/server communication is + operating properly)

    +
  2. + +
  3. +

    .... client is partitioned from the + cluster

    +
  4. + +
  5. +

    'disconnected' : client has lost connectivity + with the cluster

    +
  6. + +
  7. +

    .... time elapses, after 'timeout' period the + cluster expires the session, nothing is seen by client as it is + disconnected from cluster

    +
  8. + +
  9. +

    .... time elapses, the client regains network + level connectivity with the cluster

    +
  10. + +
  11. +

    'expired' : eventually the client reconnects to + the cluster, it is then notified of the + expiration

    +
  12. + +
+

Another parameter to the ZooKeeper session establishment + call is the default watcher. Watchers are notified when any state + change occurs in the client. For example if the client loses + connectivity to the server the client will be notified, or if the + client's session expires, etc... This watcher should consider the + initial state to be disconnected (i.e. before any state changes + events are sent to the watcher by the client lib). In the case of + a new connection, the first event sent to the watcher is typically + the session connection event.

+

The session is kept alive by requests sent by the client. If + the session is idle for a period of time that would timeout the + session, the client will send a PING request to keep the session + alive. This PING request not only allows the ZooKeeper server to + know that the client is still active, but it also allows the + client to verify that its connection to the ZooKeeper server is + still active. The timing of the PING is conservative enough to + ensure reasonable time to detect a dead connection and reconnect + to a new server.

+

+ Once a connection to the server is successfully established + (connected) there are basically two cases where the client lib generates + connectionloss (the result code in c binding, exception in Java -- see + the API documentation for binding specific details) when either a synchronous or + asynchronous operation is performed and one of the following holds: +

+
    + +
  1. +

    The application calls an operation on a session that is no + longer alive/valid

    +
  2. + +
  3. +

    The ZooKeeper client disconnects from a server when there + are pending operations to that server, i.e., there is a pending asynchronous call. +

    +
  4. + +
+

+ Added in 3.2.0 -- SessionMovedException. There is an internal + exception that is generally not seen by clients called the SessionMovedException. + This exception occurs because a request was received on a connection for a session + which has been reestablished on a different server. The normal cause of this error is + a client that sends a request to a server, but the network packet gets delayed, so + the client times out and connects to a new server. When the delayed packet arrives at + the first server, the old server detects that the session has moved, and closes the + client connection. Clients normally do not see this error since they do not read + from those old connections. (Old connections are usually closed.) One situation in which this + condition can be seen is when two clients try to reestablish the same connection using + a saved session id and password. One of the clients will reestablish the connection + and the second client will be disconnected (causing the pair to attempt to re-establish + its connection/session indefinitely).

+

+ Updating the list of servers. We allow a client to + update the connection string by providing a new comma separated list of host:port pairs, + each corresponding to a ZooKeeper server. The function invokes a probabilistic load-balancing + algorithm which may cause the client to disconnect from its current host with the goal + to achieve expected uniform number of connections per server in the new list. + In case the current host to which the client is connected is not in the new list + this call will always cause the connection to be dropped. Otherwise, the decision + is based on whether the number of servers has increased or decreased and by how much. +

+

+ For example, if the previous connection string contained 3 hosts and now the list contains + these 3 hosts and 2 more hosts, 40% of clients connected to each of the 3 hosts will + move to one of the new hosts in order to balance the load. The algorithm will cause the client + to drop its connection to the current host to which it is connected with probability 0.4 and in this + case cause the client to connect to one of the 2 new hosts, chosen at random. +

+

+ Another example -- suppose we have 5 hosts and now update the list to remove 2 of the hosts, + the clients connected to the 3 remaining hosts will stay connected, whereas all clients connected + to the 2 removed hosts will need to move to one of the 3 hosts, chosen at random. If the connection + is dropped, the client moves to a special mode where he chooses a new server to connect to using the + probabilistic algorithm, and not just round robin. +

+

+ In the first example, each client decides to disconnect with probability 0.4 but once the decision is + made, it will try to connect to a random new server and only if it cannot connect to any of the new + servers will it try to connect to the old ones. After finding a server, or trying all servers in the + new list and failing to connect, the client moves back to the normal mode of operation where it picks + an arbitrary server from the connectString and attempt to connect to it. If that fails, is will continue + trying different random servers in round robin. (see above the algorithm used to initially choose a server) +

+
+ + + +

ZooKeeper Watches

+
+

All of the read operations in ZooKeeper - getData(), getChildren(), and exists() - have the option of setting a watch as a + side effect. Here is ZooKeeper's definition of a watch: a watch event is + one-time trigger, sent to the client that set the watch, which occurs when + the data for which the watch was set changes. There are three key points + to consider in this definition of a watch:

+
    + +
  • + +

    + One-time trigger +

    + + +

    One watch event will be sent to the client when the data has changed. + For example, if a client does a getData("/znode1", true) and later the + data for /znode1 is changed or deleted, the client will get a watch + event for /znode1. If /znode1 changes again, no watch event will be + sent unless the client has done another read that sets a new + watch.

    + +
  • + + +
  • + +

    + Sent to the client +

    + + +

    This implies that an event is on the way to the client, but may + not reach the client before the successful return code to the change + operation reaches the client that initiated the change. Watches are + sent asynchronously to watchers. ZooKeeper provides an ordering + guarantee: a client will never see a change for which it has set a + watch until it first sees the watch event. Network delays or other + factors may cause different clients to see watches and return codes + from updates at different times. The key point is that everything seen + by the different clients will have a consistent order.

    + +
  • + + +
  • + +

    + The data for which the watch was + set +

    + + +

    This refers to the different ways a node can change. It + helps to think of ZooKeeper as maintaining two lists of + watches: data watches and child watches. getData() and + exists() set data watches. getChildren() sets child + watches. Alternatively, it may help to think of watches being + set according to the kind of data returned. getData() and + exists() return information about the data of the node, + whereas getChildren() returns a list of children. Thus, + setData() will trigger data watches for the znode being set + (assuming the set is successful). A successful create() will + trigger a data watch for the znode being created and a child + watch for the parent znode. A successful delete() will trigger + both a data watch and a child watch (since there can be no + more children) for a znode being deleted as well as a child + watch for the parent znode.

    + +
  • + +
+

Watches are maintained locally at the ZooKeeper server to which the + client is connected. This allows watches to be lightweight to set, + maintain, and dispatch. When a client connects to a new server, the watch + will be triggered for any session events. Watches will not be received + while disconnected from a server. When a client reconnects, any previously + registered watches will be reregistered and triggered if needed. In + general this all occurs transparently. There is one case where a watch + may be missed: a watch for the existence of a znode not yet created will + be missed if the znode is created and deleted while disconnected.

+ +

Semantics of Watches

+

We can set watches with the three calls that read the state of + ZooKeeper: exists, getData, and getChildren. The following list details + the events that a watch can trigger and the calls that enable them: +

+
    + +
  • + +

    + Created event: +

    + +

    Enabled with a call to exists.

    + +
  • + + +
  • + +

    + Deleted event: +

    + +

    Enabled with a call to exists, getData, and getChildren.

    + +
  • + + +
  • + +

    + Changed event: +

    + +

    Enabled with a call to exists and getData.

    + +
  • + + +
  • + +

    + Child event: +

    + +

    Enabled with a call to getChildren.

    + +
  • + +
+ +

Remove Watches

+

We can remove the watches registered on a znode with a call to + removeWatches. Also, a ZooKeeper client can remove watches locally even + if there is no server connection by setting the local flag to true. The + following list details the events which will be triggered after the + successful watch removal. +

+
    + +
  • + +

    + Child Remove event: +

    + +

    Watcher which was added with a call to getChildren.

    + +
  • + + +
  • + +

    + Data Remove event: +

    + +

    Watcher which was added with a call to exists or getData.

    + +
  • + +
+ +

What ZooKeeper Guarantees about Watches

+

With regard to watches, ZooKeeper maintains these + guarantees:

+
    + +
  • + +

    Watches are ordered with respect to other events, other + watches, and asynchronous replies. The ZooKeeper client libraries + ensures that everything is dispatched in order.

    + +
  • + +
+
    + +
  • + +

    A client will see a watch event for a znode it is watching + before seeing the new data that corresponds to that znode.

    + +
  • + +
+
    + +
  • + +

    The order of watch events from ZooKeeper corresponds to the + order of the updates as seen by the ZooKeeper service.

    + +
  • + +
+ +

Things to Remember about Watches

+
    + +
  • + +

    Watches are one time triggers; if you get a watch event and + you want to get notified of future changes, you must set another + watch.

    + +
  • + +
+
    + +
  • + +

    Because watches are one time triggers and there is latency + between getting the event and sending a new request to get a watch + you cannot reliably see every change that happens to a node in + ZooKeeper. Be prepared to handle the case where the znode changes + multiple times between getting the event and setting the watch + again. (You may not care, but at least realize it may + happen.)

    + +
  • + +
+
    + +
  • + +

    A watch object, or function/context pair, will only be + triggered once for a given notification. For example, if the same + watch object is registered for an exists and a getData call for the + same file and that file is then deleted, the watch object would + only be invoked once with the deletion notification for the file. +

    + +
  • + +
+
    + +
  • + +

    When you disconnect from a server (for example, when the + server fails), you will not get any watches until the connection + is reestablished. For this reason session events are sent to all + outstanding watch handlers. Use session events to go into a safe + mode: you will not be receiving events while disconnected, so your + process should act conservatively in that mode.

    + +
  • + +
+
+ + + +

ZooKeeper access control using ACLs

+
+

ZooKeeper uses ACLs to control access to its znodes (the + data nodes of a ZooKeeper data tree). The ACL implementation is + quite similar to UNIX file access permissions: it employs + permission bits to allow/disallow various operations against a + node and the scope to which the bits apply. Unlike standard UNIX + permissions, a ZooKeeper node is not limited by the three standard + scopes for user (owner of the file), group, and world + (other). ZooKeeper does not have a notion of an owner of a + znode. Instead, an ACL specifies sets of ids and permissions that + are associated with those ids.

+

Note also that an ACL pertains only to a specific znode. In + particular it does not apply to children. For example, if + /app is only readable by ip:172.16.16.1 and + /app/status is world readable, anyone will + be able to read /app/status; ACLs are not + recursive.

+

ZooKeeper supports pluggable authentication schemes. Ids are + specified using the form scheme:id, + where scheme is a the authentication scheme + that the id corresponds to. For + example, ip:172.16.16.1 is an id for a + host with the address 172.16.16.1.

+

When a client connects to ZooKeeper and authenticates + itself, ZooKeeper associates all the ids that correspond to a + client with the clients connection. These ids are checked against + the ACLs of znodes when a clients tries to access a node. ACLs are + made up of pairs of (scheme:expression, + perms). The format of + the expression is specific to the scheme. For + example, the pair (ip:19.22.0.0/16, READ) + gives the READ permission to any clients with + an IP address that starts with 19.22.

+ +

ACL Permissions

+

ZooKeeper supports the following permissions:

+
    + +
  • +

    + CREATE: you can create a child node

    +
  • + +
  • +

    + READ: you can get data from a node and list its children.

    +
  • + +
  • +

    + WRITE: you can set data for a node

    +
  • + +
  • +

    + DELETE: you can delete a child node

    +
  • + +
  • +

    + ADMIN: you can set permissions

    +
  • + +
+

The CREATE + and DELETE permissions have been broken out + of the WRITE permission for finer grained + access controls. The cases for CREATE + and DELETE are the following:

+

You want A to be able to do a set on a ZooKeeper node, but + not be able to CREATE + or DELETE children.

+

+ CREATE + without DELETE: clients create requests by + creating ZooKeeper nodes in a parent directory. You want all + clients to be able to add, but only request processor can + delete. (This is kind of like the APPEND permission for + files.)

+

Also, the ADMIN permission is there + since ZooKeeper doesn’t have a notion of file owner. In some + sense the ADMIN permission designates the + entity as the owner. ZooKeeper doesn’t support the LOOKUP + permission (execute permission bit on directories to allow you + to LOOKUP even though you can't list the directory). Everyone + implicitly has LOOKUP permission. This allows you to stat a + node, but nothing more. (The problem is, if you want to call + zoo_exists() on a node that doesn't exist, there is no + permission to check.)

+ +

Builtin ACL Schemes

+

ZooKeeeper has the following built in schemes:

+
    + +
  • +

    + world has a + single id, anyone, that represents + anyone.

    +
  • + + +
  • +

    + auth doesn't + use any id, represents any authenticated + user.

    +
  • + + +
  • +

    + digest uses + a username:password string to generate + MD5 hash which is then used as an ACL ID + identity. Authentication is done by sending + the username:password in clear text. When + used in the ACL the expression will be + the username:base64 + encoded SHA1 + password digest.

    + +
  • + + +
  • +

    + ip uses the + client host IP as an ACL ID identity. The ACL expression is of + the form addr/bits where the most + significant bits + of addr are matched against the most + significant bits of the client host + IP.

    +
  • + + +
+ +

ZooKeeper C client API

+

The following constants are provided by the ZooKeeper C + library:

+
    + +
  • +

    + const int ZOO_PERM_READ; //can read node’s value and list its children

    +
  • + +
  • +

    + const int ZOO_PERM_WRITE;// can set the node’s value

    +
  • + +
  • +

    + const int ZOO_PERM_CREATE; //can create children

    +
  • + +
  • +

    + const int ZOO_PERM_DELETE;// can delete children

    +
  • + +
  • +

    + const int ZOO_PERM_ADMIN; //can execute set_acl()

    +
  • + +
  • +

    + const int ZOO_PERM_ALL;// all of the above flags OR’d together

    +
  • + +
+

The following are the standard ACL IDs:

+
    + +
  • +

    + struct Id ZOO_ANYONE_ID_UNSAFE; //(‘world’,’anyone’)

    +
  • + +
  • +

    + struct Id ZOO_AUTH_IDS;// (‘auth’,’’)

    +
  • + +
+

ZOO_AUTH_IDS empty identity string should be interpreted as “the identity of the creator”.

+

ZooKeeper client comes with three standard ACLs:

+
    + +
  • +

    + struct ACL_vector ZOO_OPEN_ACL_UNSAFE; //(ZOO_PERM_ALL,ZOO_ANYONE_ID_UNSAFE)

    +
  • + +
  • +

    + struct ACL_vector ZOO_READ_ACL_UNSAFE;// (ZOO_PERM_READ, ZOO_ANYONE_ID_UNSAFE)

    +
  • + +
  • +

    + struct ACL_vector ZOO_CREATOR_ALL_ACL; //(ZOO_PERM_ALL,ZOO_AUTH_IDS)

    +
  • + +
+

The ZOO_OPEN_ACL_UNSAFE is completely open free for all + ACL: any application can execute any operation on the node and + can create, list and delete its children. The + ZOO_READ_ACL_UNSAFE is read-only access for any + application. CREATE_ALL_ACL grants all permissions to the + creator of the node. The creator must have been authenticated by + the server (for example, using “digest” + scheme) before it can create nodes with this ACL.

+

The following ZooKeeper operations deal with ACLs:

+
    +
  • + +

    + int zoo_add_auth + (zhandle_t *zh,const char* + scheme,const char* + cert, int certLen, void_completion_t + completion, const void + *data);

    + +
  • +
+

The application uses the zoo_add_auth function to + authenticate itself to the server. The function can be called + multiple times if the application wants to authenticate using + different schemes and/or identities.

+
    +
  • + +

    + int zoo_create + (zhandle_t *zh, const char + *path, const char + *value,int + valuelen, const struct + ACL_vector *acl, int + flags,char + *realpath, int + max_realpath_len);

    + +
  • +
+

zoo_create(...) operation creates a new node. The acl + parameter is a list of ACLs associated with the node. The parent + node must have the CREATE permission bit set.

+
    +
  • + +

    + int zoo_get_acl + (zhandle_t *zh, const char + *path,struct ACL_vector + *acl, struct Stat *stat);

    + +
  • +
+

This operation returns a node’s ACL info.

+
    +
  • + +

    + int zoo_set_acl + (zhandle_t *zh, const char + *path, int + version,const struct + ACL_vector *acl);

    + +
  • +
+

This function replaces node’s ACL list with a new one. The + node must have the ADMIN permission set.

+

Here is a sample code that makes use of the above APIs to + authenticate itself using the “foo” scheme + and create an ephemeral node “/xyz” with create-only + permissions.

+
+
Note
+
+

This is a very simple example which is intended to show + how to interact with ZooKeeper ACLs + specifically. See .../trunk/src/c/src/cli.c + for an example of a proper C client implementation

+ +
+
+
+#include <string.h>
+#include <errno.h>
+
+#include "zookeeper.h"
+
+static zhandle_t *zh;
+
+/**
+ * In this example this method gets the cert for your
+ *   environment -- you must provide
+ */
+char *foo_get_cert_once(char* id) { return 0; }
+
+/** Watcher function -- empty for this example, not something you should
+ * do in real code */
+void watcher(zhandle_t *zzh, int type, int state, const char *path,
+             void *watcherCtx) {}
+
+int main(int argc, char argv) {
+  char buffer[512];
+  char p[2048];
+  char *cert=0;
+  char appId[64];
+
+  strcpy(appId, "example.foo_test");
+  cert = foo_get_cert_once(appId);
+  if(cert!=0) {
+    fprintf(stderr,
+            "Certificate for appid [%s] is [%s]\n",appId,cert);
+    strncpy(p,cert, sizeof(p)-1);
+    free(cert);
+  } else {
+    fprintf(stderr, "Certificate for appid [%s] not found\n",appId);
+    strcpy(p, "dummy");
+  }
+
+  zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG);
+
+  zh = zookeeper_init("localhost:3181", watcher, 10000, 0, 0, 0);
+  if (!zh) {
+    return errno;
+  }
+  if(zoo_add_auth(zh,"foo",p,strlen(p),0,0)!=ZOK)
+    return 2;
+
+  struct ACL CREATE_ONLY_ACL[] = {{ZOO_PERM_CREATE, ZOO_AUTH_IDS}};
+  struct ACL_vector CREATE_ONLY = {1, CREATE_ONLY_ACL};
+  int rc = zoo_create(zh,"/xyz","value", 5, &CREATE_ONLY, ZOO_EPHEMERAL,
+                      buffer, sizeof(buffer)-1);
+
+  /** this operation will fail with a ZNOAUTH error */
+  int buflen= sizeof(buffer);
+  struct Stat stat;
+  rc = zoo_get(zh, "/xyz", 0, buffer, &buflen, &stat);
+  if (rc) {
+    fprintf(stderr, "Error %d for %s\n", rc, __LINE__);
+  }
+
+  zookeeper_close(zh);
+  return 0;
+}
+      
+
+ + + +

Pluggable ZooKeeper authentication

+
+

ZooKeeper runs in a variety of different environments with + various different authentication schemes, so it has a completely + pluggable authentication framework. Even the builtin authentication + schemes use the pluggable authentication framework.

+

To understand how the authentication framework works, first you must + understand the two main authentication operations. The framework + first must authenticate the client. This is usually done as soon as + the client connects to a server and consists of validating information + sent from or gathered about a client and associating it with the connection. + The second operation handled by the framework is finding the entries in an + ACL that correspond to client. ACL entries are <idspec, + permissions> pairs. The idspec may be + a simple string match against the authentication information associated + with the connection or it may be a expression that is evaluated against that + information. It is up to the implementation of the authentication plugin + to do the match. Here is the interface that an authentication plugin must + implement:

+
+public interface AuthenticationProvider {
+    String getScheme();
+    KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte authData[]);
+    boolean isValid(String id);
+    boolean matches(String id, String aclExpr);
+    boolean isAuthenticated();
+}
+    
+

The first method getScheme returns the string + that identifies the plugin. Because we support multiple methods of authentication, + an authentication credential or an idspec will always be + prefixed with scheme:. The ZooKeeper server uses the scheme + returned by the authentication plugin to determine which ids the scheme + applies to.

+

+ handleAuthentication is called when a client + sends authentication information to be associated with a connection. The + client specifies the scheme to which the information corresponds. The + ZooKeeper server passes the information to the authentication plugin whose + getScheme matches the scheme passed by the client. The + implementor of handleAuthentication will usually return + an error if it determines that the information is bad, or it will associate information + with the connection using cnxn.getAuthInfo().add(new Id(getScheme(), data)). +

+

The authentication plugin is involved in both setting and using ACLs. When an + ACL is set for a znode, the ZooKeeper server will pass the id part of the entry to + the isValid(String id) method. It is up to the plugin to verify + that the id has a correct form. For example, ip:172.16.0.0/16 + is a valid id, but ip:host.com is not. If the new ACL includes + an "auth" entry, isAuthenticated is used to see if the + authentication information for this scheme that is assocatied with the connection + should be added to the ACL. Some schemes + should not be included in auth. For example, the IP address of the client is not + considered as an id that should be added to the ACL if auth is specified.

+

ZooKeeper invokes + matches(String id, String aclExpr) when checking an ACL. It + needs to match authentication information of the client against the relevant ACL + entries. To find the entries which apply to the client, the ZooKeeper server will + find the scheme of each entry and if there is authentication information + from that client for that scheme, matches(String id, String aclExpr) + will be called with id set to the authentication information + that was previously added to the connection by handleAuthentication and + aclExpr set to the id of the ACL entry. The authentication plugin + uses its own logic and matching scheme to determine if id is included + in aclExpr. +

+

There are two built in authentication plugins: ip and + digest. Additional plugins can adding using system properties. At + startup the ZooKeeper server will look for system properties that start with + "zookeeper.authProvider." and interpret the value of those properties as the class name + of an authentication plugin. These properties can be set using the + -Dzookeeeper.authProvider.X=com.f.MyAuth or adding entries such as + the following in the server configuration file:

+
+authProvider.1=com.f.MyAuth
+authProvider.2=com.f.MyAuth2
+    
+

Care should be taking to ensure that the suffix on the property is unique. If there are + duplicates such as -Dzookeeeper.authProvider.X=com.f.MyAuth -Dzookeeper.authProvider.X=com.f.MyAuth2, + only one will be used. Also all servers must have the same plugins defined, otherwise clients using + the authentication schemes provided by the plugins will have problems connecting to some servers. +

+
+ + + +

Consistency Guarantees

+
+

ZooKeeper is a high performance, scalable service. Both reads and + write operations are designed to be fast, though reads are faster than + writes. The reason for this is that in the case of reads, ZooKeeper can + serve older data, which in turn is due to ZooKeeper's consistency + guarantees:

+
+ +
+ Sequential Consistency +
+
+

Updates from a client will be applied in the order that they + were sent.

+
+ + +
+ Atomicity +
+
+

Updates either succeed or fail -- there are no partial + results.

+
+ + +
+ Single System Image +
+
+

A client will see the same view of the service regardless of + the server that it connects to.

+
+ + +
+ Reliability +
+
+

Once an update has been applied, it will persist from that + time forward until a client overwrites the update. This guarantee + has two corollaries:

+
    + +
  1. + +

    If a client gets a successful return code, the update will + have been applied. On some failures (communication errors, + timeouts, etc) the client will not know if the update has + applied or not. We take steps to minimize the failures, but the + guarantee is only present with successful return codes. + (This is called the monotonicity condition in Paxos.)

    + +
  2. + + +
  3. + +

    Any updates that are seen by the client, through a read + request or successful update, will never be rolled back when + recovering from server failures.

    + +
  4. + +
+
+ + +
+ Timeliness +
+
+

The clients view of the system is guaranteed to be up-to-date + within a certain time bound (on the order of tens of seconds). + Either system changes will be seen by a client within this bound, or + the client will detect a service outage.

+
+ +
+

Using these consistency guarantees it is easy to build higher level + functions such as leader election, barriers, queues, and read/write + revocable locks solely at the ZooKeeper client (no additions needed to + ZooKeeper). See Recipes and Solutions + for more details.

+
+
Note
+
+ +

Sometimes developers mistakenly assume one other guarantee that + ZooKeeper does not in fact make. This is:

+ + +
+ +
+ Simultaneously Consistent Cross-Client Views +
+
+

ZooKeeper does not guarantee that at every instance in + time, two different clients will have identical views of + ZooKeeper data. Due to factors like network delays, one client + may perform an update before another client gets notified of the + change. Consider the scenario of two clients, A and B. If client + A sets the value of a znode /a from 0 to 1, then tells client B + to read /a, client B may read the old value of 0, depending on + which server it is connected to. If it + is important that Client A and Client B read the same value, + Client B should should call the sync() method from the ZooKeeper API + method before it performs its read.

+

So, ZooKeeper by itself doesn't guarantee that changes occur + synchronously across all servers, but ZooKeeper + primitives can be used to construct higher level functions that + provide useful client synchronization. (For more information, + see the ZooKeeper Recipes. + [tbd:..]).

+
+ +
+ +
+
+
+ + + +

Bindings

+
+

The ZooKeeper client libraries come in two languages: Java and C. + The following sections describe these.

+ +

Java Binding

+

There are two packages that make up the ZooKeeper Java binding: + org.apache.zookeeper and org.apache.zookeeper.data. The rest of the + packages that make up ZooKeeper are used internally or are part of the + server implementation. The org.apache.zookeeper.data package is made up of + generated classes that are used simply as containers.

+

The main class used by a ZooKeeper Java client is the ZooKeeper class. Its two constructors differ only + by an optional session id and password. ZooKeeper supports session + recovery accross instances of a process. A Java program may save its + session id and password to stable storage, restart, and recover the + session that was used by the earlier instance of the program.

+

When a ZooKeeper object is created, two threads are created as + well: an IO thread and an event thread. All IO happens on the IO thread + (using Java NIO). All event callbacks happen on the event thread. + Session maintenance such as reconnecting to ZooKeeper servers and + maintaining heartbeat is done on the IO thread. Responses for + synchronous methods are also processed in the IO thread. All responses + to asynchronous methods and watch events are processed on the event + thread. There are a few things to notice that result from this + design:

+
    + +
  • + +

    All completions for asynchronous calls and watcher callbacks + will be made in order, one at a time. The caller can do any + processing they wish, but no other callbacks will be processed + during that time.

    + +
  • + + +
  • + +

    Callbacks do not block the processing of the IO thread or the + processing of the synchronous calls.

    + +
  • + + +
  • + +

    Synchronous calls may not return in the correct order. For + example, assume a client does the following processing: issues an + asynchronous read of node /a with + watch set to true, and then in the completion + callback of the read it does a synchronous read of /a. (Maybe not good practice, but not illegal + either, and it makes for a simple example.)

    + + +

    Note that if there is a change to /a between the asynchronous read and the + synchronous read, the client library will receive the watch event + saying /a changed before the + response for the synchronous read, but because the completion + callback is blocking the event queue, the synchronous read will + return with the new value of /a + before the watch event is processed.

    + +
  • + +
+

Finally, the rules associated with shutdown are straightforward: + once a ZooKeeper object is closed or receives a fatal event + (SESSION_EXPIRED and AUTH_FAILED), the ZooKeeper object becomes invalid. + On a close, the two threads shut down and any further access on zookeeper + handle is undefined behavior and should be avoided.

+ +

C Binding

+

The C binding has a single-threaded and multi-threaded library. + The multi-threaded library is easiest to use and is most similar to the + Java API. This library will create an IO thread and an event dispatch + thread for handling connection maintenance and callbacks. The + single-threaded library allows ZooKeeper to be used in event driven + applications by exposing the event loop used in the multi-threaded + library.

+

The package includes two shared libraries: zookeeper_st and + zookeeper_mt. The former only provides the asynchronous APIs and + callbacks for integrating into the application's event loop. The only + reason this library exists is to support the platforms were a + pthread library is not available or is unstable + (i.e. FreeBSD 4.x). In all other cases, application developers should + link with zookeeper_mt, as it includes support for both Sync and Async + API.

+ +

Installation

+

If you're building the client from a check-out from the Apache + repository, follow the steps outlined below. If you're building from a + project source package downloaded from apache, skip to step 3.

+
    + +
  1. + +

    Run ant compile_jute from the ZooKeeper + top level directory (.../trunk). + This will create a directory named "generated" under + .../trunk/src/c.

    + +
  2. + + +
  3. + +

    Change directory to the.../trunk/src/c + and run autoreconf -if to bootstrap autoconf, automake and libtool. Make sure you have + autoconf version 2.59 or greater installed. + Skip to step 4.

    + +
  4. + + +
  5. + +

    If you are building from a project source package, + unzip/untar the source tarball and cd to the + zookeeper-x.x.x/src/c directory.

    + +
  6. + + +
  7. + +

    Run ./configure <your-options> to + generate the makefile. Here are some of options the configure utility supports that can be + useful in this step:

    + + +
      + +
    • + +

      + --enable-debug +

      + + +

      Enables optimization and enables debug info compiler + options. (Disabled by default.)

      + +
    • + + +
    • + +

      + --without-syncapi +

      + + +

      Disables Sync API support; zookeeper_mt library won't be + built. (Enabled by default.)

      + +
    • + + +
    • + +

      + --disable-static +

      + + +

      Do not build static libraries. (Enabled by + default.)

      + +
    • + + +
    • + +

      + --disable-shared +

      + + +

      Do not build shared libraries. (Enabled by + default.)

      + +
    • + +
    + + +
    +
    Note
    +
    + +

    See INSTALL for general information about running + configure.

    + +
    +
    + +
  8. + + +
  9. + +

    Run make or make + install to build the libraries and install them.

    + +
  10. + + +
  11. + +

    To generate doxygen documentation for the ZooKeeper API, run + make doxygen-doc. All documentation will be + placed in a new subfolder named docs. By default, this command + only generates HTML. For information on other document formats, + run ./configure --help +

    + +
  12. + +
+ +

Using the C Client

+

You can test your client by running a ZooKeeper server (see + instructions on the project wiki page on how to run it) and connecting + to it using one of the cli applications that were built as part of the + installation procedure. cli_mt (multithreaded, built against + zookeeper_mt library) is shown in this example, but you could also use + cli_st (singlethreaded, built against zookeeper_st library):

+

+ $ cli_mt zookeeper_host:9876 +

+

This is a client application that gives you a shell for + executing simple ZooKeeper commands. Once successfully started + and connected to the server it displays a shell prompt. You + can now enter ZooKeeper commands. For example, to create a + node:

+

+ > create /my_new_node +

+

To verify that the node's been created:

+

+ > ls / +

+

You should see a list of node who are children of the root node + "/".

+

In order to be able to use the ZooKeeper API in your application + you have to remember to

+
    + +
  1. + +

    Include ZooKeeper header: #include + <zookeeper/zookeeper.h>

    + +
  2. + + +
  3. + +

    If you are building a multithreaded client, compile with + -DTHREADED compiler flag to enable the multi-threaded version of + the library, and then link against against the + zookeeper_mt library. If you are building a + single-threaded client, do not compile with -DTHREADED, and be + sure to link against the zookeeper_st + library.

    + +
  4. + +
+

Refer to Program Structure, with Simple Example + for examples of usage in Java and C. + [tbd] + +

+
+ + + +

Building Blocks: A Guide to ZooKeeper Operations

+
+

This section surveys all the operations a developer can perform + against a ZooKeeper server. It is lower level information than the earlier + concepts chapters in this manual, but higher level than the ZooKeeper API + Reference. It covers these topics:

+ + +

Handling Errors

+

Both the Java and C client bindings may report errors. The Java client binding does so by throwing KeeperException, calling code() on the exception will return the specific error code. + The C client binding returns an error code as defined in the enum ZOO_ERRORS. API callbacks indicate result code for both language bindings. See the API documentation (javadoc for + Java, doxygen for C) for full details on the possible errors and their meaning.

+ +

Connecting to ZooKeeper

+

+ +

Read Operations

+

+ +

Write Operations

+

+ +

Handling Watches

+

+ +

Miscelleaneous ZooKeeper Operations

+

+
+ + + +

Program Structure, with Simple Example

+
+

+ [tbd] +

+
+ + + +

Gotchas: Common Problems and Troubleshooting

+
+

So now you know ZooKeeper. It's fast, simple, your application + works, but wait ... something's wrong. Here are some pitfalls that + ZooKeeper users fall into:

+
    + +
  1. + +

    If you are using watches, you must look for the connected watch + event. When a ZooKeeper client disconnects from a server, you will + not receive notification of changes until reconnected. If you are + watching for a znode to come into existance, you will miss the event + if the znode is created and deleted while you are disconnected.

    + +
  2. + + +
  3. + +

    You must test ZooKeeper server failures. The ZooKeeper service + can survive failures as long as a majority of servers are active. The + question to ask is: can your application handle it? In the real world + a client's connection to ZooKeeper can break. (ZooKeeper server + failures and network partitions are common reasons for connection + loss.) The ZooKeeper client library takes care of recovering your + connection and letting you know what happened, but you must make sure + that you recover your state and any outstanding requests that failed. + Find out if you got it right in the test lab, not in production - test + with a ZooKeeper service made up of a several of servers and subject + them to reboots.

    + +
  4. + + +
  5. + +

    The list of ZooKeeper servers used by the client must match the + list of ZooKeeper servers that each ZooKeeper server has. Things can + work, although not optimally, if the client list is a subset of the + real list of ZooKeeper servers, but not if the client lists ZooKeeper + servers not in the ZooKeeper cluster.

    + +
  6. + + +
  7. + +

    Be careful where you put that transaction log. The most + performance-critical part of ZooKeeper is the transaction log. + ZooKeeper must sync transactions to media before it returns a + response. A dedicated transaction log device is key to consistent good + performance. Putting the log on a busy device will adversely effect + performance. If you only have one storage device, put trace files on + NFS and increase the snapshotCount; it doesn't eliminate the problem, + but it can mitigate it.

    + +
  8. + + +
  9. + +

    Set your Java max heap size correctly. It is very important to + avoid swapping. Going to disk unnecessarily will + almost certainly degrade your performance unacceptably. Remember, in + ZooKeeper, everything is ordered, so if one request hits the disk, all + other queued requests hit the disk.

    + + +

    To avoid swapping, try to set the heapsize to the amount of + physical memory you have, minus the amount needed by the OS and cache. + The best way to determine an optimal heap size for your configurations + is to run load tests. If for some reason you + can't, be conservative in your estimates and choose a number well + below the limit that would cause your machine to swap. For example, on + a 4G machine, a 3G heap is a conservative estimate to start + with.

    + +
  10. + +
+
+ + + + + + Links to Other Information + + +

Outside the formal documentation, there're several other sources of + information for ZooKeeper developers.

+ + +
+ +
+ ZooKeeper Whitepaper [tbd: find url] + +
+
+

The definitive discussion of ZooKeeper design and performance, + by Yahoo! Research

+
+ + +
+ API Reference [tbd: find url] + +
+
+

The complete reference to the ZooKeeper API

+
+ + +
+ + ZooKeeper + Talk at the Hadoup Summit 2008 + +
+
+

A video introduction to ZooKeeper, by Benjamin Reed of Yahoo! + Research

+
+ + +
+ + Barrier and + Queue Tutorial + +
+
+

The excellent Java tutorial by Flavio Junqueira, implementing + simple barriers and producer-consumer queues using ZooKeeper.

+
+ + +
+ + ZooKeeper + - A Reliable, Scalable Distributed Coordination System + +
+
+

An article by Todd Hoff (07/15/2008)

+
+ + +
+ + ZooKeeper Recipes + +
+
+

Pseudo-level discussion of the implementation of various + synchronization solutions with ZooKeeper: Event Handles, Queues, + Locks, and Two-phase Commits.

+
+ + +
+ + [tbd] + +
+
+

Any other good sources anyone can think of...

+
+ +
+ +
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperProgrammers.pdf b/docs/zookeeperProgrammers.pdf new file mode 100644 index 00000000000..2de07ff0320 Binary files /dev/null and b/docs/zookeeperProgrammers.pdf differ diff --git a/docs/zookeeperQuotas.html b/docs/zookeeperQuotas.html new file mode 100644 index 00000000000..636a6b4540e --- /dev/null +++ b/docs/zookeeperQuotas.html @@ -0,0 +1,281 @@ + + + + + + + + ZooKeeper Quota's Guide + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper Quota's Guide

+

A Guide to Deployment and Administration

+
+
+ +
+
+ + + +

Quotas

+
+

ZooKeeper has both namespace and bytes quotas. You can use the ZooKeeperMain class to setup quotas. + ZooKeeper prints WARN messages if users exceed the quota assigned to them. The messages + are printed in the log of the ZooKeeper. +

+

+$java -cp zookeeper.jar:src/java/lib/log4j-1.2.16.jar:src/java/lib/jline-2.11.jar:conf \ + org.apache.zookeeper.ZooKeeperMain -server host:port +

+

The above command gives you a command line option of using quotas.

+ +

Setting Quotas

+

You can use + setquota to set a quota on a ZooKeeper node. It has an option of setting quota with + -n (for namespace) + and -b (for bytes).

+

The ZooKeeper quota are stored in ZooKeeper itself in /zookeeper/quota. To disable other people from + changing the quota's set the ACL for /zookeeper/quota such that only admins are able to read and write to it. +

+ +

Listing Quotas

+

You can use + listquota to list a quota on a ZooKeeper node. +

+ +

Deleting Quotas

+

You can use + delquota to delete quota on a ZooKeeper node. +

+
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperQuotas.pdf b/docs/zookeeperQuotas.pdf new file mode 100644 index 00000000000..532cdee38ac Binary files /dev/null and b/docs/zookeeperQuotas.pdf differ diff --git a/docs/zookeeperReconfig.html b/docs/zookeeperReconfig.html new file mode 100644 index 00000000000..9458c38561a --- /dev/null +++ b/docs/zookeeperReconfig.html @@ -0,0 +1,1108 @@ + + + + + + + + ZooKeeper Dynamic Reconfiguration + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper Dynamic Reconfiguration

+ + + + +

Overview

+
+

Prior to the 3.5.0 release, the membership and all other configuration + parameters of Zookeeper were static - loaded during boot and immutable at + runtime. Operators resorted to ''rolling restarts'' - a manually intensive + and error-prone method of changing the configuration that has caused data + loss and inconsistency in production.

+

Starting with 3.5.0, “rolling restarts” are no longer needed! + ZooKeeper comes with full support for automated configuration changes: the + set of Zookeeper servers, their roles (participant / observer), all ports, + and even the quorum system can be changed dynamically, without service + interruption and while maintaining data consistency. Reconfigurations are + performed immediately, just like other operations in ZooKeeper. Multiple + changes can be done using a single reconfiguration command. The dynamic + reconfiguration functionality does not limit operation concurrency, does + not require client operations to be stopped during reconfigurations, has a + very simple interface for administrators and no added complexity to other + client operations.

+

New client-side features allow clients to find out about configuration + changes and to update the connection string (list of servers and their + client ports) stored in their ZooKeeper handle. A probabilistic algorithm + is used to rebalance clients across the new configuration servers while + keeping the extent of client migrations proportional to the change in + ensemble membership.

+

This document provides the administrator manual for reconfiguration. + For a detailed description of the reconfiguration algorithms, performance + measurements, and more, please see our paper:

+
+ +
+ Shraer, A., Reed, B., Malkhi, D., Junqueira, F. Dynamic + Reconfiguration of Primary/Backup Clusters. In USENIX Annual + Technical Conference (ATC) (2012), 425-437 + +
+
+

Links: paper (pdf), slides (pdf), video, hadoop summit slides +

+
+ +
+
+ + +

Changes to Configuration Format

+
+ +

Specifying the client port

+

A client port of a server is the port on which the server accepts + client connection requests. Starting with 3.5.0 the + clientPort and clientPortAddress + configuration parameters should no longer be used. Instead, + this information is now part of the server keyword specification, which + becomes as follows:

+

+ server.<positive id> = <address1>:<port1>:<port2>[:role];[<client port address>:]<client port> +

+

The client port specification is to the right of the semicolon. The + client port address is optional, and if not specified it defaults to + "0.0.0.0". As usual, role is also optional, it can be + participant or observer + (participant by default).

+

Examples of legal server statements:

+
    + +
  • + +

    + server.5 = 125.23.63.23:1234:1235;1236 +

    + +
  • + +
  • + +

    + server.5 = 125.23.63.23:1234:1235:participant;1236 +

    + +
  • + +
  • + +

    + server.5 = 125.23.63.23:1234:1235:observer;1236 +

    + +
  • + +
  • + +

    + server.5 = 125.23.63.23:1234:1235;125.23.63.24:1236 +

    + +
  • + +
  • + +

    + server.5 = 125.23.63.23:1234:1235:participant;125.23.63.23:1236 +

    + +
  • + +
+ +

The standaloneEnabled flag

+

Prior to 3.5.0, one could run ZooKeeper in Standalone mode or in a + Distributed mode. These are separate implementation stacks, and + switching between them during run time is not possible. By default (for + backward compatibility) standaloneEnabled is set to + true. The consequence of using this default is that + if started with a single server the ensemble will not be allowed to + grow, and if started with more than one server it will not be allowed to + shrink to contain fewer than two participants.

+

Setting the flag to false instructs the system + to run the Distributed software stack even if there is only a single + participant in the ensemble. To achieve this the (static) configuration + file should contain:

+

+ standaloneEnabled=false +

+

With this setting it is possible to start a ZooKeeper ensemble + containing a single participant and to dynamically grow it by adding + more servers. Similarly, it is possible to shrink an ensemble so that + just a single participant remains, by removing servers.

+

Since running the Distributed mode allows more flexibility, we + recommend setting the flag to false. We expect that + the legacy Standalone mode will be deprecated in the future.

+ +

Dynamic configuration file

+

Starting with 3.5.0 we're distinguishing between dynamic + configuration parameters, which can be changed during runtime, and + static configuration parameters, which are read from a configuration + file when a server boots and don't change during its execution. For now, + the following configuration keywords are considered part of the dynamic + configuration: server, group + and weight.

+

Dynamic configuration parameters are stored in a separate file on + the server (which we call the dynamic configuration file). This file is + linked from the static config file using the new + dynamicConfigFile keyword.

+

+ Example +

+
+
zoo_replicated1.cfg
+
+ + zoo_replicated1.cfg + +
tickTime=2000
+dataDir=/zookeeper/data/zookeeper1
+initLimit=5
+syncLimit=2
+dynamicConfigFile=/zookeeper/conf/zoo_replicated1.cfg.dynamic
+ +
+
+
+
zoo_replicated1.cfg.dynamic
+
+ + zoo_replicated1.cfg.dynamic + +
server.1=125.23.63.23:2780:2783:participant;2791
+server.2=125.23.63.24:2781:2784:participant;2792
+server.3=125.23.63.25:2782:2785:participant;2793
+ +
+
+

When the ensemble configuration changes, the static configuration + parameters remain the same. The dynamic parameters are pushed by + ZooKeeper and overwrite the dynamic configuration files on all servers. + Thus, the dynamic configuration files on the different servers are + usually identical (they can only differ momentarily when a + reconfiguration is in progress, or if a new configuration hasn't + propagated yet to some of the servers). Once created, the dynamic + configuration file should not be manually altered. Changed are only made + through the new reconfiguration commands outlined below. Note that + changing the config of an offline cluster could result in an + inconsistency with respect to configuration information stored in the + ZooKeeper log (and the special configuration znode, populated from the + log) and is therefore highly discouraged.

+

+ Example 2 +

+

Users may prefer to initially specify a single configuration file. + The following is thus also legal:

+
+
zoo_replicated1.cfg
+
+ + zoo_replicated1.cfg + +
tickTime=2000
+dataDir=/zookeeper/data/zookeeper1
+initLimit=5
+syncLimit=2
+clientPort=2791  // note that this line is now redundant and therefore not recommended
+server.1=125.23.63.23:2780:2783:participant;2791
+server.2=125.23.63.24:2781:2784:participant;2792
+server.3=125.23.63.25:2782:2785:participant;2793
+ +
+
+

The configuration files on each server will be automatically split + into dynamic and static files, if they are not already in this format. + So the configuration file above will be automatically transformed into + the two files in Example 1. Note that the clientPort and + clientPortAddress lines (if specified) will be automatically removed + during this process, if they are redundant (as in the example above). + The original static configuration file is backed up (in a .bak + file).

+ +

Backward compatibility

+

We still support the old configuration format. For example, the + following configuration file is acceptable (but not recommended):

+
+
zoo_replicated1.cfg
+
+ + zoo_replicated1.cfg + +
tickTime=2000
+dataDir=/zookeeper/data/zookeeper1
+initLimit=5
+syncLimit=2
+clientPort=2791
+server.1=125.23.63.23:2780:2783:participant
+server.2=125.23.63.24:2781:2784:participant
+server.3=125.23.63.25:2782:2785:participant
+ +
+
+

During boot, a dynamic configuration file is created and contains + the dynamic part of the configuration as explained earlier. In this + case, however, the line "clientPort=2791" will remain in the static + configuration file of server 1 since it is not redundant -- it was not + specified as part of the "server.1=..." using the format explained in + the section Changes to Configuration Format. If a reconfiguration + is invoked that sets the client port of server 1, we remove + "clientPort=2791" from the static configuration file (the dynamic file + now contain this information as part of the specification of server + 1).

+
+ + +

Upgrading to 3.5.0

+
+

Upgrading a running ZooKeeper ensemble to 3.5.0 should be done only + after upgrading your ensemble to the 3.4.6 release. Note that this is only + necessary for rolling upgrades (if you're fine with shutting down the + system completely, you don't have to go through 3.4.6). If you attempt a + rolling upgrade without going through 3.4.6 (for example from 3.4.5), you + may get the following error:

+
2013-01-30 11:32:10,663 [myid:2] - INFO [localhost/127.0.0.1:2784:QuorumCnxManager$Listener@498] - Received connection request /127.0.0.1:60876
+2013-01-30 11:32:10,663 [myid:2] - WARN [localhost/127.0.0.1:2784:QuorumCnxManager@349] - Invalid server id: -65536
+

During a rolling upgrade, each server is taken down in turn and + rebooted with the new 3.5.0 binaries. Before starting the server with + 3.5.0 binaries, we highly recommend updating the configuration file so + that all server statements "server.x=..." contain client ports (see the + section Specifying the client port). As explained earlier + you may leave the configuration in a single file, as well as leave the + clientPort/clientPortAddress statements (although if you specify client + ports in the new format, these statements are now redundant).

+
+ + +

Dynamic Reconfiguration of the ZooKeeper Ensemble

+
+

The ZooKeeper Java and C API were extended with getConfig and reconfig + commands that facilitate reconfiguration. Both commands have a synchronous + (blocking) variant and an asynchronous one. We demonstrate these commands + here using the Java CLI, but note that you can similarly use the C CLI or + invoke the commands directly from a program just like any other ZooKeeper + command.

+ +

Retrieving the current dynamic configuration

+

The dynamic configuration is stored in a special znode + ZooDefs.CONFIG_NODE = /zookeeper/config. The new + config CLI command reads this znode (currently it is + simply a wrapper to get /zookeeper/config). As with + normal reads, to retrieve the latest committed value you should do a + sync first.

+
[zk: 127.0.0.1:2791(CONNECTED) 3] config
+server.1=localhost:2780:2783:participant;localhost:2791
+server.2=localhost:2781:2784:participant;localhost:2792
+server.3=localhost:2782:2785:participant;localhost:2793
+version=400000003
+
+

Notice the last line of the output. This is the configuration + version. The version equals to the zxid of the reconfiguration command + which created this configuration. The version of the first established + configuration equals to the zxid of the NEWLEADER message sent by the + first successfully established leader. When a configuration is written + to a dynamic configuration file, the version automatically becomes part + of the filename and the static configuration file is updated with the + path to the new dynamic configuration file. Configuration files + corresponding to earlier versions are retained for backup + purposes.

+

During boot time the version (if it exists) is extracted from the + filename. The version should never be altered manually by users or the + system administrator. It is used by the system to know which + configuration is most up-to-date. Manipulating it manually can result in + data loss and inconsistency.

+

Just like a get command, the + config CLI command accepts the -w + flag for setting a watch on the znode, and -s flag for + displaying the Stats of the znode. It additionally accepts a new flag + -c which outputs only the version and the client + connection string corresponding to the current configuration. For + example, for the configuration above we would get:

+
[zk: 127.0.0.1:2791(CONNECTED) 17] config -c
+400000003 localhost:2791,localhost:2793,localhost:2792
+

Note that when using the API directly, this command is called + getConfig.

+

As any read command it returns the configuration known to the + follower to which your client is connected, which may be slightly + out-of-date. One can use the sync command for + stronger guarantees. For example using the Java API:

+
zk.sync(ZooDefs.CONFIG_NODE, void_callback, context);
+zk.getConfig(watcher, callback, context);
+

Note: in 3.5.0 it doesn't really matter which path is passed to the + sync() command as all the server's state is brought + up to date with the leader (so one could use a different path instead of + ZooDefs.CONFIG_NODE). However, this may change in the future.

+ +

Modifying the current dynamic configuration

+

Modifying the configuration is done through the + reconfig command. There are two modes of + reconfiguration: incremental and non-incremental (bulk). The + non-incremental simply specifies the new dynamic configuration of the + system. The incremental specifies changes to the current configuration. + The reconfig command returns the new + configuration.

+

A few examples are in: ReconfigTest.java, + ReconfigRecoveryTest.java and + TestReconfigServer.cc.

+ +

General

+

+ Removing servers: Any server can + be removed, including the leader (although removing the leader will + result in a short unavailability, see Figures 6 and 8 in the paper). The server will not be shut-down + automatically. + Instead, it becomes a "non-voting follower". This is somewhat similar + to an observer in that its votes don't count towards the Quorum of + votes necessary to commit operations. However, unlike a non-voting + follower, an observer doesn't actually see any operation proposals and + does not ACK them. Thus a non-voting follower has a more significant + negative effect on system throughput compared to an observer. + Non-voting follower mode should only be used as a temporary mode, + before shutting the server down, or adding it as a follower or as an + observer to the ensemble. We do not shut the server down automatically + for two main reasons. The first reason is that we do not want all the + clients connected to this server to be immediately disconnected, + causing a flood of connection requests to other servers. Instead, it + is better if each client decides when to migrate independently. The + second reason is that removing a server may sometimes (rarely) be + necessary in order to change it from "observer" to "participant" (this + is explained in the section Additional comments).

+

Note that the new configuration should have some minimal number of + participants in order to be considered legal. If the proposed change + would leave the cluster with less than 2 participants and standalone + mode is enabled (standaloneEnabled=true, see the section The standaloneEnabled flag), the reconfig will not be + processed (BadArgumentsException). If standalone mode is disabled + (standaloneEnabled=false) then its legal to remain with 1 or more + participants.

+

+ Adding servers: Before a + reconfiguration is invoked, the administrator must make sure that a + quorum (majority) of participants from the new configuration are + already connected and synced with the current leader. To achieve this + we need to connect a new joining server to the leader before it is + officially part of the ensemble. This is done by starting the joining + server using an initial list of servers which is technically not a + legal configuration of the system but (a) contains the joiner, and (b) + gives sufficient information to the joiner in order for it to find and + connect to the current leader. We list a few different options of + doing this safely.

+
    + +
  1. + +

    Initial configuration of joiners is comprised of servers in + the last committed configuration and one or more joiners, where + joiners are listed as observers. + For example, if servers D and E are added at the same time to (A, + B, C) and server C is being removed, the initial configuration of + D could be (A, B, C, D) or (A, B, C, D, E), where D and E are + listed as observers. Similarly, the configuration of E could be + (A, B, C, E) or (A, B, C, D, E), where D and E are listed as + observers. Note that listing the joiners as + observers will not actually make them observers - it will only + prevent them from accidentally forming a quorum with other + joiners. Instead, they will contact the servers in the + current configuration and adopt the last committed configuration + (A, B, C), where the joiners are absent. Configuration files of + joiners are backed up and replaced automatically as this happens. + After connecting to the current leader, joiners become non-voting + followers until the system is reconfigured and they are added to + the ensemble (as participant or observer, as appropriate).

    + +
  2. + +
  3. + +

    Initial configuration of each joiner is comprised of servers + in the last committed configuration + the + joiner itself, listed as a participant. For example, to + add a new server D to a configuration consisting of servers (A, B, + C), the administrator can start D using an initial configuration + file consisting of servers (A, B, C, D). If both D and E are added + at the same time to (A, B, C), the initial configuration of D + could be (A, B, C, D) and the configuration of E could be (A, B, + C, E). Similarly, if D is added and C is removed at the same time, + the initial configuration of D could be (A, B, C, D). Never list + more than one joiner as participant in the initial configuration + (see warning below).

    + +
  4. + +
  5. + +

    Whether listing the joiner as an observer or as participant, + it is also fine not to list all the current configuration servers, + as long as the current leader is in the list. For example, when + adding D we could start D with a configuration file consisting of + just (A, D) if A is the current leader. however this is more + fragile since if A fails before D officially joins the ensemble, D + doesn’t know anyone else and therefore the administrator will have + to intervene and restart D with another server list.

    + +
  6. + +
+
+
Warning
+
+ + Warning + +

Never specify more than one joining server in the same initial + configuration as participants. Currently, the joining servers don’t + know that they are joining an existing ensemble; if multiple joiners + are listed as participants they may form an independent quorum + creating a split-brain situation such as processing operations + independently from your main ensemble. It is OK to list multiple + joiners as observers in an initial config.

+ +
+
+

Finally, note that once connected to the leader, a joiner adopts + the last committed configuration, in which it is absent (the initial + config of the joiner is backed up before being rewritten). If the + joiner restarts in this state, it will not be able to boot since it is + absent from its configuration file. In order to start it you’ll once + again have to specify an initial configuration.

+

+ Modifying server parameters: One + can modify any of the ports of a server, or its role + (participant/observer) by adding it to the ensemble with different + parameters. This works in both the incremental and the bulk + reconfiguration modes. It is not necessary to remove the server and + then add it back; just specify the new parameters as if the server is + not yet in the system. The server will detect the configuration change + and perform the necessary adjustments. See an example in the section + Incremental mode and an exception to this + rule in the section Additional comments.

+

It is also possible to change the Quorum System used by the + ensemble (for example, change the Majority Quorum System to a + Hierarchical Quorum System on the fly). This, however, is only allowed + using the bulk (non-incremental) reconfiguration mode. In general, + incremental reconfiguration only works with the Majority Quorum + System. Bulk reconfiguration works with both Hierarchical and Majority + Quorum Systems.

+

+ Performance Impact: There is + practically no performance impact when removing a follower, since it + is not being automatically shut down (the effect of removal is that + the server's votes are no longer being counted). When adding a server, + there is no leader change and no noticeable performance disruption. + For details and graphs please see Figures 6, 7 and 8 in the paper.

+

The most significant disruption will happen when a leader change + is caused, in one of the following cases:

+
    + +
  1. + +

    Leader is removed from the ensemble.

    + +
  2. + +
  3. + +

    Leader's role is changed from participant to observer.

    + +
  4. + +
  5. + +

    The port used by the leader to send transactions to others + (quorum port) is modified.

    + +
  6. + +
+

In these cases we perform a leader hand-off where the old leader + nominates a new leader. The resulting unavailability is usually + shorter than when a leader crashes since detecting leader failure is + unnecessary and electing a new leader can usually be avoided during a + hand-off (see Figures 6 and 8 in the paper).

+

When the client port of a server is modified, it does not drop + existing client connections. New connections to the server will have + to use the new client port.

+

+ Progress guarantees: Up to the + invocation of the reconfig operation, a quorum of the old + configuration is required to be available and connected for ZooKeeper + to be able to make progress. Once reconfig is invoked, a quorum of + both the old and of the new configurations must be available. The + final transition happens once (a) the new configuration is activated, + and (b) all operations scheduled before the new configuration is + activated by the leader are committed. Once (a) and (b) happen, only a + quorum of the new configuration is required. Note, however, that + neither (a) nor (b) are visible to a client. Specifically, when a + reconfiguration operation commits, it only means that an activation + message was sent out by the leader. It does not necessarily mean that + a quorum of the new configuration got this message (which is required + in order to activate it) or that (b) has happened. If one wants to + make sure that both (a) and (b) has already occurred (for example, in + order to know that it is safe to shut down old servers that were + removed), one can simply invoke an update + (set-data, or some other quorum operation, but not + a sync) and wait for it to commit. An alternative + way to achieve this was to introduce another round to the + reconfiguration protocol (which, for simplicity and compatibility with + Zab, we decided to avoid).

+ +

Incremental mode

+

The incremental mode allows adding and removing servers to the + current configuration. Multiple changes are allowed. For + example:

+

+> reconfig -remove 3 -add + server.5=125.23.63.23:1234:1235;1236 +

+

Both the add and the remove options get a list of comma separated + arguments (no spaces):

+

+> reconfig -remove 3,4 -add + server.5=localhost:2111:2112;2113,6=localhost:2114:2115:observer;2116 +

+

The format of the server statement is exactly the same as + described in the section Specifying the client port and + includes the client port. Notice that here instead of "server.5=" you + can just say "5=". In the example above, if server 5 is already in the + system, but has different ports or is not an observer, it is updated + and once the configuration commits becomes an observer and starts + using these new ports. This is an easy way to turn participants into + observers and vise versa or change any of their ports, without + rebooting the server.

+

ZooKeeper supports two types of Quorum Systems – the simple + Majority system (where the leader commits operations after receiving + ACKs from a majority of voters) and a more complex Hierarchical + system, where votes of different servers have different weights and + servers are divided into voting groups. Currently, incremental + reconfiguration is allowed only if the last proposed configuration + known to the leader uses a Majority Quorum System + (BadArgumentsException is thrown otherwise).

+

Incremental mode - examples using the Java API:

+
List<String> leavingServers = new ArrayList<String>();
+leavingServers.add("1");
+leavingServers.add("2");
+byte[] config = zk.reconfig(null, leavingServers, null, -1, new Stat());
+
List<String> leavingServers = new ArrayList<String>();
+List<String> joiningServers = new ArrayList<String>();
+leavingServers.add("1");
+joiningServers.add("server.4=localhost:1234:1235;1236");
+byte[] config = zk.reconfig(joiningServers, leavingServers, null, -1, new Stat());
+
+String configStr = new String(config);
+System.out.println(configStr);
+

There is also an asynchronous API, and an API accepting comma + separated Strings instead of List<String>. See + src/java/main/org/apache/zookeeper/ZooKeeper.java.

+ +

Non-incremental mode

+

The second mode of reconfiguration is non-incremental, whereby a + client gives a complete specification of the new dynamic system + configuration. The new configuration can either be given in place or + read from a file:

+

+> reconfig -file newconfig.cfg + //newconfig.cfg is a dynamic config file, see Dynamic configuration file +

+

+> reconfig -members + server.1=125.23.63.23:2780:2783:participant;2791,server.2=125.23.63.24:2781:2784:participant;2792,server.3=125.23.63.25:2782:2785:participant;2793 +

+

The new configuration may use a different Quorum System. For + example, you may specify a Hierarchical Quorum System even if the + current ensemble uses a Majority Quorum System.

+

Bulk mode - example using the Java API:

+
ArrayList<String> newMembers = new ArrayList<String>();
+newMembers.add("server.1=1111:1234:1235;1236");
+newMembers.add("server.2=1112:1237:1238;1239");
+newMembers.add("server.3=1114:1240:1241:observer;1242");
+
+byte[] config = zk.reconfig(null, null, newMembers, -1, new Stat());
+
+String configStr = new String(config);
+System.out.println(configStr);
+

There is also an asynchronous API, and an API accepting comma + separated String containing the new members instead of + List<String>. See + src/java/main/org/apache/zookeeper/ZooKeeper.java.

+ +

Conditional reconfig

+

Sometimes (especially in non-incremental mode) a new proposed + configuration depends on what the client "believes" to be the current + configuration, and should be applied only to that configuration. + Specifically, the reconfig succeeds only if the + last configuration at the leader has the specified version.

+

+ > reconfig -file <filename> -v <version> +

+

In the previously listed Java examples, instead of -1 one could + specify a configuration version to condition the + reconfiguration.

+ +

Error conditions

+

In addition to normal ZooKeeper error conditions, a + reconfiguration may fail for the following reasons:

+
    + +
  1. + +

    another reconfig is currently in progress + (ReconfigInProgress)

    + +
  2. + +
  3. + +

    the proposed change would leave the cluster with less than 2 + participants, in case standalone mode is enabled, or, if + standalone mode is disabled then its legal to remain with 1 or + more participants (BadArgumentsException)

    + +
  4. + +
  5. + +

    no quorum of the new configuration was connected and + up-to-date with the leader when the reconfiguration processing + began (NewConfigNoQuorum)

    + +
  6. + +
  7. + +

    + -v x was specified, but the version + y of the latest configuration is not + x (BadVersionException)

    + +
  8. + +
  9. + +

    an incremental reconfiguration was requested but the last + configuration at the leader uses a Quorum System which is + different from the Majority system (BadArgumentsException)

    + +
  10. + +
  11. + +

    syntax error (BadArgumentsException)

    + +
  12. + +
  13. + +

    I/O exception when reading the configuration from a file + (BadArgumentsException)

    + +
  14. + +
+

Most of these are illustrated by test-cases in + ReconfigFailureCases.java.

+ +

Additional comments

+

+ Liveness: To better understand + the difference between incremental and non-incremental + reconfiguration, suppose that client C1 adds server D to the system + while a different client C2 adds server E. With the non-incremental + mode, each client would first invoke config to find + out the current configuration, and then locally create a new list of + servers by adding its own suggested server. The new configuration can + then be submitted using the non-incremental + reconfig command. After both reconfigurations + complete, only one of E or D will be added (not both), depending on + which client's request arrives second to the leader, overwriting the + previous configuration. The other client can repeat the process until + its change takes effect. This method guarantees system-wide progress + (i.e., for one of the clients), but does not ensure that every client + succeeds. To have more control C2 may request to only execute the + reconfiguration in case the version of the current configuration + hasn't changed, as explained in the section Conditional reconfig. In this way it may avoid blindly + overwriting the configuration of C1 if C1's configuration reached the + leader first.

+

With incremental reconfiguration, both changes will take effect as + they are simply applied by the leader one after the other to the + current configuration, whatever that is (assuming that the second + reconfig request reaches the leader after it sends a commit message + for the first reconfig request -- currently the leader will refuse to + propose a reconfiguration if another one is already pending). Since + both clients are guaranteed to make progress, this method guarantees + stronger liveness. In practice, multiple concurrent reconfigurations + are probably rare. Non-incremental reconfiguration is currently the + only way to dynamically change the Quorum System. Incremental + configuration is currently only allowed with the Majority Quorum + System.

+

+ Changing an observer into a + follower: Clearly, changing a server that participates in + voting into an observer may fail if error (2) occurs, i.e., if fewer + than the minimal allowed number of participants would remain. However, + converting an observer into a participant may sometimes fail for a + more subtle reason: Suppose, for example, that the current + configuration is (A, B, C, D), where A is the leader, B and C are + followers and D is an observer. In addition, suppose that B has + crashed. If a reconfiguration is submitted where D is said to become a + follower, it will fail with error (3) since in this configuration, a + majority of voters in the new configuration (any 3 voters), must be + connected and up-to-date with the leader. An observer cannot + acknowledge the history prefix sent during reconfiguration, and + therefore it does not count towards these 3 required servers and the + reconfiguration will be aborted. In case this happens, a client can + achieve the same task by two reconfig commands: first invoke a + reconfig to remove D from the configuration and then invoke a second + command to add it back as a participant (follower). During the + intermediate state D is a non-voting follower and can ACK the state + transfer performed during the second reconfig comand.

+
+ + +

Rebalancing Client Connections

+
+

When a ZooKeeper cluster is started, if each client is given the same + connection string (list of servers), the client will randomly choose a + server in the list to connect to, which makes the expected number of + client connections per server the same for each of the servers. We + implemented a method that preserves this property when the set of servers + changes through reconfiguration. See Sections 4 and 5.1 in the paper.

+

In order for the method to work, all clients must subscribe to + configuration changes (by setting a watch on /zookeeper/config either + directly or through the getConfig API command). When + the watch is triggered, the client should read the new configuration by + invoking sync and getConfig and if + the configuration is indeed new invoke the + updateServerList API command. To avoid mass client + migration at the same time, it is better to have each client sleep a + random short period of time before invoking + updateServerList.

+

A few examples can be found in: + StaticHostProviderTest.java and + TestReconfig.cc +

+

Example (this is not a recipe, but a simplified example just to + explain the general idea):

+
+public void process(WatchedEvent event) {
+    synchronized (this) {
+        if (event.getType() == EventType.None) {
+            connected = (event.getState() == KeeperState.SyncConnected);
+            notifyAll();
+        } else if (event.getPath()!=null &&  event.getPath().equals(ZooDefs.CONFIG_NODE)) {
+            // in prod code never block the event thread!
+            zk.sync(ZooDefs.CONFIG_NODE, this, null);
+            zk.getConfig(this, this, null);
+        }
+    }
+}
+public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
+    if (path!=null &&  path.equals(ZooDefs.CONFIG_NODE)) {
+        String config[] = ConfigUtils.getClientConfigStr(new String(data)).split(" ");   // similar to config -c
+        long version = Long.parseLong(config[0], 16);
+        if (this.configVersion == null){
+             this.configVersion = version;
+        } else if (version > this.configVersion) {
+            hostList = config[1];
+            try {
+                // the following command is not blocking but may cause the client to close the socket and
+                // migrate to a different server. In practice its better to wait a short period of time, chosen
+                // randomly, so that different clients migrate at different times
+                zk.updateServerList(hostList);
+            } catch (IOException e) {
+                System.err.println("Error updating server list");
+                e.printStackTrace();
+            }
+            this.configVersion = version;
+} } }
+
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperReconfig.pdf b/docs/zookeeperReconfig.pdf new file mode 100644 index 00000000000..012a8c71907 Binary files /dev/null and b/docs/zookeeperReconfig.pdf differ diff --git a/docs/zookeeperStarted.html b/docs/zookeeperStarted.html new file mode 100644 index 00000000000..9f909472d0f --- /dev/null +++ b/docs/zookeeperStarted.html @@ -0,0 +1,658 @@ + + + + + + + + ZooKeeper Getting Started Guide + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

ZooKeeper Getting Started Guide

+ + + + +

Getting Started: Coordinating Distributed Applications with + ZooKeeper

+
+

This document contains information to get you started quickly with + ZooKeeper. It is aimed primarily at developers hoping to try it out, and + contains simple installation instructions for a single ZooKeeper server, a + few commands to verify that it is running, and a simple programming + example. Finally, as a convenience, there are a few sections regarding + more complicated installations, for example running replicated + deployments, and optimizing the transaction log. However for the complete + instructions for commercial deployments, please refer to the ZooKeeper + Administrator's Guide.

+ +

Pre-requisites

+

See + System Requirements in the Admin guide.

+ +

Download

+

To get a ZooKeeper distribution, download a recent + + stable release from one of the Apache Download + Mirrors.

+ +

Standalone Operation

+

Setting up a ZooKeeper server in standalone mode is + straightforward. The server is contained in a single JAR file, + so installation consists of creating a configuration.

+

Once you've downloaded a stable ZooKeeper release unpack + it and cd to the root

+

To start ZooKeeper you need a configuration file. Here is a sample, + create it in conf/zoo.cfg:

+
+tickTime=2000
+dataDir=/var/lib/zookeeper
+clientPort=2181
+
+

This file can be called anything, but for the sake of this + discussion call + it conf/zoo.cfg. Change the + value of dataDir to specify an + existing (empty to start with) directory. Here are the meanings + for each of the fields:

+
+ +
+ + tickTime + +
+
+

the basic time unit in milliseconds used by ZooKeeper. It is + used to do heartbeats and the minimum session timeout will be + twice the tickTime.

+
+ +
+
+ +
+ + dataDir + +
+
+

the location to store the in-memory database snapshots and, + unless specified otherwise, the transaction log of updates to the + database.

+
+ + +
+ + clientPort + +
+
+

the port to listen for client connections

+
+ +
+

Now that you created the configuration file, you can start + ZooKeeper:

+
bin/zkServer.sh start
+

ZooKeeper logs messages using log4j -- more detail + available in the + Logging + section of the Programmer's Guide. You will see log messages + coming to the console (default) and/or a log file depending on + the log4j configuration.

+

The steps outlined here run ZooKeeper in standalone mode. There is + no replication, so if ZooKeeper process fails, the service will go down. + This is fine for most development situations, but to run ZooKeeper in + replicated mode, please see Running Replicated + ZooKeeper.

+ +

Managing ZooKeeper Storage

+

For long running production systems ZooKeeper storage must + be managed externally (dataDir and logs). See the section on + maintenance for + more details.

+ +

Connecting to ZooKeeper

+

Once ZooKeeper is running, you have several options for connection + to it:

+
    + +
  • + +

    + Java: Use

    + + +
    bin/zkCli.sh -server 127.0.0.1:2181
    + + +

    This lets you perform simple, file-like operations.

    + +
  • + + +
  • + +

    + C: compile cli_mt + (multi-threaded) or cli_st (single-threaded) by running + make cli_mt or make + cli_st in + the src/c subdirectory in + the ZooKeeper sources. See the README contained within + src/c for full details.

    + + +

    You can run the program + from src/c using:

    + + +
    LD_LIBRARY_PATH=. cli_mt 127.0.0.1:2181
    + + +

    or

    + + +
    LD_LIBRARY_PATH=. cli_st 127.0.0.1:2181
    + +

    This will give you a simple shell to execute file + system like operations on ZooKeeper.

    + +
  • + +
+

Once you have connected, you should see something like: +

+
+
+Connecting to localhost:2181
+log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
+log4j:WARN Please initialize the log4j system properly.
+Welcome to ZooKeeper!
+JLine support is enabled
+[zkshell: 0]
+        
+

+ From the shell, type help to get a listing of commands that can be executed from the client, as in: +

+
+
+[zkshell: 0] help
+ZooKeeper host:port cmd args
+        get path [watch]
+        ls path [watch]
+        set path data [version]
+        delquota [-n|-b] path
+        quit
+        printwatches on|off
+        create path data acl
+        stat path [watch]
+        listquota path
+        history
+        setAcl path acl
+        getAcl path
+        sync path
+        redo cmdno
+        addauth scheme auth
+        delete path [version]
+        deleteall path
+        setquota -n|-b val path
+
+        
+

From here, you can try a few simple commands to get a feel for this simple command line interface. First, start by issuing the list command, as + in ls, yielding: +

+
+
+[zkshell: 8] ls /
+[zookeeper]
+        
+

Next, create a new znode by running create /zk_test my_data. This creates a new znode and associates the string "my_data" with the node. + You should see:

+
+
+[zkshell: 9] create /zk_test my_data
+Created /zk_test
+      
+

Issue another ls / command to see what the directory looks like: +

+
+
+[zkshell: 11] ls /
+[zookeeper, zk_test]
+
+        
+

+ Notice that the zk_test directory has now been created. +

+

Next, verify that the data was associated with the znode by running the get command, as in: +

+
+
+[zkshell: 12] get /zk_test
+my_data
+cZxid = 5
+ctime = Fri Jun 05 13:57:06 PDT 2009
+mZxid = 5
+mtime = Fri Jun 05 13:57:06 PDT 2009
+pZxid = 5
+cversion = 0
+dataVersion = 0
+aclVersion = 0
+ephemeralOwner = 0
+dataLength = 7
+numChildren = 0
+        
+

We can change the data associated with zk_test by issuing the set command, as in: +

+
+
+[zkshell: 14] set /zk_test junk
+cZxid = 5
+ctime = Fri Jun 05 13:57:06 PDT 2009
+mZxid = 6
+mtime = Fri Jun 05 14:01:52 PDT 2009
+pZxid = 5
+cversion = 0
+dataVersion = 1
+aclVersion = 0
+ephemeralOwner = 0
+dataLength = 4
+numChildren = 0
+[zkshell: 15] get /zk_test
+junk
+cZxid = 5
+ctime = Fri Jun 05 13:57:06 PDT 2009
+mZxid = 6
+mtime = Fri Jun 05 14:01:52 PDT 2009
+pZxid = 5
+cversion = 0
+dataVersion = 1
+aclVersion = 0
+ephemeralOwner = 0
+dataLength = 4
+numChildren = 0
+      
+

+ (Notice we did a get after setting the data and it did, indeed, change.

+

Finally, let's delete the node by issuing: +

+
+
+[zkshell: 16] delete /zk_test
+[zkshell: 17] ls /
+[zookeeper]
+[zkshell: 18]
+
+

That's it for now. To explore more, continue with the rest of this document and see the Programmer's Guide.

+ +

Programming to ZooKeeper

+

ZooKeeper has a Java bindings and C bindings. They are + functionally equivalent. The C bindings exist in two variants: single + threaded and multi-threaded. These differ only in how the messaging loop + is done. For more information, see the Programming + Examples in the ZooKeeper Programmer's Guide for + sample code using of the different APIs.

+ +

Running Replicated ZooKeeper

+

Running ZooKeeper in standalone mode is convenient for evaluation, + some development, and testing. But in production, you should run + ZooKeeper in replicated mode. A replicated group of servers in the same + application is called a quorum, and in replicated + mode, all servers in the quorum have copies of the same configuration + file.

+ +
+
Note
+
+

For replicated mode, a minimum of three servers are required, and it is + strongly recommended that you have an odd number of servers. If you + only have two servers, then you are in a situation where if one of + them fails, there are not enough machines to form a majority quorum. + Two servers is inherently less stable than a single + server, because there are two single points of failure.

+
+
+ +

The required conf/zoo.cfg file for replicated mode is + similar to the one used in standalone mode, but with a few differences. + Here is an example:

+
+tickTime=2000
+dataDir=/var/lib/zookeeper
+clientPort=2181
+initLimit=5
+syncLimit=2
+server.1=zoo1:2888:3888
+server.2=zoo2:2888:3888
+server.3=zoo3:2888:3888
+
+

The new entry, initLimit is + timeouts ZooKeeper uses to limit the length of time the ZooKeeper + servers in quorum have to connect to a leader. The entry syncLimit limits how far out of date a server can + be from a leader.

+

With both of these timeouts, you specify the unit of time using + tickTime. In this example, the timeout + for initLimit is 5 ticks at 2000 milleseconds a tick, or 10 + seconds.

+

The entries of the form server.X list the + servers that make up the ZooKeeper service. When the server starts up, + it knows which server it is by looking for the file + myid in the data directory. That file has the + contains the server number, in ASCII.

+

Finally, note the two port numbers after each server + name: " 2888" and "3888". Peers use the former port to connect + to other peers. Such a connection is necessary so that peers + can communicate, for example, to agree upon the order of + updates. More specifically, a ZooKeeper server uses this port + to connect followers to the leader. When a new leader arises, a + follower opens a TCP connection to the leader using this + port. Because the default leader election also uses TCP, we + currently require another port for leader election. This is the + second port in the server entry. +

+
+
Note
+
+ +

If you want to test multiple servers on a single + machine, specify the servername + as localhost with unique quorum & + leader election ports (i.e. 2888:3888, 2889:3889, 2890:3890 in + the example above) for each server.X in that server's config + file. Of course separate dataDirs and + distinct clientPorts are also necessary + (in the above replicated example, running on a + single localhost, you would still have + three config files).

+ +

Please be aware that setting up multiple servers on a single machine + will not create any redundancy. If something were to happen + which caused the machine to die, all of the zookeeper servers + would be offline. Full redundancy requires that each server have + its own machine. It must be a completely separate physical server. + Multiple virtual machines on the same physical host are still + vulnerable to the complete failure of that host.

+ +
+
+ +

Other Optimizations

+

There are a couple of other configuration parameters that can + greatly increase performance:

+
    + +
  • + +

    To get low latencies on updates it is important to + have a dedicated transaction log directory. By default + transaction logs are put in the same directory as the data + snapshots and myid file. The dataLogDir + parameters indicates a different directory to use for the + transaction logs.

    + +
  • + + +
  • + +

    + [tbd: what is the other config param?] +

    + +
  • + +
+
+ +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperStarted.pdf b/docs/zookeeperStarted.pdf new file mode 100644 index 00000000000..15b73fe2aa9 Binary files /dev/null and b/docs/zookeeperStarted.pdf differ diff --git a/docs/zookeeperTutorial.html b/docs/zookeeperTutorial.html new file mode 100644 index 00000000000..8c2c4fcc3d1 --- /dev/null +++ b/docs/zookeeperTutorial.html @@ -0,0 +1,883 @@ + + + + + + + + Programming with ZooKeeper - A basic tutorial + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+ +   +
+ + + + + +
+ +

Programming with ZooKeeper - A basic tutorial

+ + + + +

Introduction

+
+

In this tutorial, we show simple implementations of barriers and + producer-consumer queues using ZooKeeper. We call the respective classes Barrier and Queue. + These examples assume that you have at least one ZooKeeper server running.

+

Both primitives use the following common excerpt of code:

+
+    static ZooKeeper zk = null;
+    static Integer mutex;
+
+    String root;
+
+    SyncPrimitive(String address) {
+        if(zk == null){
+            try {
+                System.out.println("Starting ZK:");
+                zk = new ZooKeeper(address, 3000, this);
+                mutex = new Integer(-1);
+                System.out.println("Finished starting ZK: " + zk);
+            } catch (IOException e) {
+                System.out.println(e.toString());
+                zk = null;
+            }
+        }
+    }
+
+    synchronized public void process(WatchedEvent event) {
+        synchronized (mutex) {
+            mutex.notify();
+        }
+    }
+
+

Both classes extend SyncPrimitive. In this way, we execute steps that are + common to all primitives in the constructor of SyncPrimitive. To keep the examples + simple, we create a ZooKeeper object the first time we instantiate either a barrier + object or a queue object, and we declare a static variable that is a reference + to this object. The subsequent instances of Barrier and Queue check whether a + ZooKeeper object exists. Alternatively, we could have the application creating a + ZooKeeper object and passing it to the constructor of Barrier and Queue.

+

+ We use the process() method to process notifications triggered due to watches. + In the following discussion, we present code that sets watches. A watch is internal + structure that enables ZooKeeper to notify a client of a change to a node. For example, + if a client is waiting for other clients to leave a barrier, then it can set a watch and + wait for modifications to a particular node, which can indicate that it is the end of the wait. + This point becomes clear once we go over the examples. +

+
+ + + +

Barriers

+
+

+ A barrier is a primitive that enables a group of processes to synchronize the + beginning and the end of a computation. The general idea of this implementation + is to have a barrier node that serves the purpose of being a parent for individual + process nodes. Suppose that we call the barrier node "/b1". Each process "p" then + creates a node "/b1/p". Once enough processes have created their corresponding + nodes, joined processes can start the computation. +

+

In this example, each process instantiates a Barrier object, and its constructor takes as parameters:

+
    +
  • +

    the address of a ZooKeeper server (e.g., "zoo1.foo.com:2181")

    +
  • + +
  • +

    the path of the barrier node on ZooKeeper (e.g., "/b1")

    +
  • + +
  • +

    the size of the group of processes

    +
  • + +
+

The constructor of Barrier passes the address of the Zookeeper server to the + constructor of the parent class. The parent class creates a ZooKeeper instance if + one does not exist. The constructor of Barrier then creates a + barrier node on ZooKeeper, which is the parent node of all process nodes, and + we call root (Note: This is not the ZooKeeper root "/").

+
+        /**
+         * Barrier constructor
+         *
+         * @param address
+         * @param root
+         * @param size
+         */
+        Barrier(String address, String root, int size) {
+            super(address);
+            this.root = root;
+            this.size = size;
+
+            // Create barrier node
+            if (zk != null) {
+                try {
+                    Stat s = zk.exists(root, false);
+                    if (s == null) {
+                        zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE,
+                                CreateMode.PERSISTENT);
+                    }
+                } catch (KeeperException e) {
+                    System.out
+                            .println("Keeper exception when instantiating queue: "
+                                    + e.toString());
+                } catch (InterruptedException e) {
+                    System.out.println("Interrupted exception");
+                }
+            }
+
+            // My node name
+            try {
+                name = new String(InetAddress.getLocalHost().getCanonicalHostName().toString());
+            } catch (UnknownHostException e) {
+                System.out.println(e.toString());
+            }
+
+        }
+
+

+ To enter the barrier, a process calls enter(). The process creates a node under + the root to represent it, using its host name to form the node name. It then wait + until enough processes have entered the barrier. A process does it by checking + the number of children the root node has with "getChildren()", and waiting for + notifications in the case it does not have enough. To receive a notification when + there is a change to the root node, a process has to set a watch, and does it + through the call to "getChildren()". In the code, we have that "getChildren()" + has two parameters. The first one states the node to read from, and the second is + a boolean flag that enables the process to set a watch. In the code the flag is true. +

+
+        /**
+         * Join barrier
+         *
+         * @return
+         * @throws KeeperException
+         * @throws InterruptedException
+         */
+
+        boolean enter() throws KeeperException, InterruptedException{
+            zk.create(root + "/" + name, new byte[0], Ids.OPEN_ACL_UNSAFE,
+                    CreateMode.EPHEMERAL_SEQUENTIAL);
+            while (true) {
+                synchronized (mutex) {
+                    List<String> list = zk.getChildren(root, true);
+
+                    if (list.size() < size) {
+                        mutex.wait();
+                    } else {
+                        return true;
+                    }
+                }
+            }
+        }
+
+

+ Note that enter() throws both KeeperException and InterruptedException, so it is + the reponsability of the application to catch and handle such exceptions.

+

+ Once the computation is finished, a process calls leave() to leave the barrier. + First it deletes its corresponding node, and then it gets the children of the root + node. If there is at least one child, then it waits for a notification (obs: note + that the second parameter of the call to getChildren() is true, meaning that + ZooKeeper has to set a watch on the the root node). Upon reception of a notification, + it checks once more whether the root node has any child.

+
+        /**
+         * Wait until all reach barrier
+         *
+         * @return
+         * @throws KeeperException
+         * @throws InterruptedException
+         */
+
+        boolean leave() throws KeeperException, InterruptedException{
+            zk.delete(root + "/" + name, 0);
+            while (true) {
+                synchronized (mutex) {
+                    List<String> list = zk.getChildren(root, true);
+                        if (list.size() > 0) {
+                            mutex.wait();
+                        } else {
+                            return true;
+                        }
+                    }
+                }
+        }
+    }
+
+
+ + +

Producer-Consumer Queues

+
+

+ A producer-consumer queue is a distributed data estructure thata group of processes + use to generate and consume items. Producer processes create new elements and add + them to the queue. Consumer processes remove elements from the list, and process them. + In this implementation, the elements are simple integers. The queue is represented + by a root node, and to add an element to the queue, a producer process creates a new node, + a child of the root node. +

+

+ The following excerpt of code corresponds to the constructor of the object. As + with Barrier objects, it first calls the constructor of the parent class, SyncPrimitive, + that creates a ZooKeeper object if one doesn't exist. It then verifies if the root + node of the queue exists, and creates if it doesn't. +

+
+        /**
+         * Constructor of producer-consumer queue
+         *
+         * @param address
+         * @param name
+         */
+        Queue(String address, String name) {
+            super(address);
+            this.root = name;
+            // Create ZK node name
+            if (zk != null) {
+                try {
+                    Stat s = zk.exists(root, false);
+                    if (s == null) {
+                        zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE,
+                                CreateMode.PERSISTENT);
+                    }
+                } catch (KeeperException e) {
+                    System.out
+                            .println("Keeper exception when instantiating queue: "
+                                    + e.toString());
+                } catch (InterruptedException e) {
+                    System.out.println("Interrupted exception");
+                }
+            }
+        }
+
+

+ A producer process calls "produce()" to add an element to the queue, and passes + an integer as an argument. To add an element to the queue, the method creates a + new node using "create()", and uses the SEQUENCE flag to instruct ZooKeeper to + append the value of the sequencer counter associated to the root node. In this way, + we impose a total order on the elements of the queue, thus guaranteeing that the + oldest element of the queue is the next one consumed. +

+
+        /**
+         * Add element to the queue.
+         *
+         * @param i
+         * @return
+         */
+
+        boolean produce(int i) throws KeeperException, InterruptedException{
+            ByteBuffer b = ByteBuffer.allocate(4);
+            byte[] value;
+
+            // Add child with value i
+            b.putInt(i);
+            value = b.array();
+            zk.create(root + "/element", value, Ids.OPEN_ACL_UNSAFE,
+                        CreateMode.PERSISTENT_SEQUENTIAL);
+
+            return true;
+        }
+
+

+ To consume an element, a consumer process obtains the children of the root node, + reads the node with smallest counter value, and returns the element. Note that + if there is a conflict, then one of the two contending processes won't be able to + delete the node and the delete operation will throw an exception.

+

+ A call to getChildren() returns the list of children in lexicographic order. + As lexicographic order does not necessary follow the numerical order of the counter + values, we need to decide which element is the smallest. To decide which one has + the smallest counter value, we traverse the list, and remove the prefix "element" + from each one.

+
+        /**
+         * Remove first element from the queue.
+         *
+         * @return
+         * @throws KeeperException
+         * @throws InterruptedException
+         */
+        int consume() throws KeeperException, InterruptedException{
+            int retvalue = -1;
+            Stat stat = null;
+
+            // Get the first element available
+            while (true) {
+                synchronized (mutex) {
+                    List<String> list = zk.getChildren(root, true);
+                    if (list.size() == 0) {
+                        System.out.println("Going to wait");
+                        mutex.wait();
+                    } else {
+                        Integer min = new Integer(list.get(0).substring(7));
+                        for(String s : list){
+                            Integer tempValue = new Integer(s.substring(7));
+                            //System.out.println("Temporary value: " + tempValue);
+                            if(tempValue < min) min = tempValue;
+                        }
+                        System.out.println("Temporary value: " + root + "/element" + min);
+                        byte[] b = zk.getData(root + "/element" + min,
+                                    false, stat);
+                        zk.delete(root + "/element" + min, 0);
+                        ByteBuffer buffer = ByteBuffer.wrap(b);
+                        retvalue = buffer.getInt();
+
+                        return retvalue;
+                    }
+                }
+            }
+        }
+    }
+
+
+ + +

Complete Source Listing

+
+
+
SyncPrimitive.Java
+
+ + SyncPrimitive.Java + +
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.data.Stat;
+
+public class SyncPrimitive implements Watcher {
+
+    static ZooKeeper zk = null;
+    static Integer mutex;
+
+    String root;
+
+    SyncPrimitive(String address) {
+        if(zk == null){
+            try {
+                System.out.println("Starting ZK:");
+                zk = new ZooKeeper(address, 3000, this);
+                mutex = new Integer(-1);
+                System.out.println("Finished starting ZK: " + zk);
+            } catch (IOException e) {
+                System.out.println(e.toString());
+                zk = null;
+            }
+        }
+        //else mutex = new Integer(-1);
+    }
+
+    synchronized public void process(WatchedEvent event) {
+        synchronized (mutex) {
+            //System.out.println("Process: " + event.getType());
+            mutex.notify();
+        }
+    }
+
+    /**
+     * Barrier
+     */
+    static public class Barrier extends SyncPrimitive {
+        int size;
+        String name;
+
+        /**
+         * Barrier constructor
+         *
+         * @param address
+         * @param root
+         * @param size
+         */
+        Barrier(String address, String root, int size) {
+            super(address);
+            this.root = root;
+            this.size = size;
+
+            // Create barrier node
+            if (zk != null) {
+                try {
+                    Stat s = zk.exists(root, false);
+                    if (s == null) {
+                        zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE,
+                                CreateMode.PERSISTENT);
+                    }
+                } catch (KeeperException e) {
+                    System.out
+                            .println("Keeper exception when instantiating queue: "
+                                    + e.toString());
+                } catch (InterruptedException e) {
+                    System.out.println("Interrupted exception");
+                }
+            }
+
+            // My node name
+            try {
+                name = new String(InetAddress.getLocalHost().getCanonicalHostName().toString());
+            } catch (UnknownHostException e) {
+                System.out.println(e.toString());
+            }
+
+        }
+
+        /**
+         * Join barrier
+         *
+         * @return
+         * @throws KeeperException
+         * @throws InterruptedException
+         */
+
+        boolean enter() throws KeeperException, InterruptedException{
+            zk.create(root + "/" + name, new byte[0], Ids.OPEN_ACL_UNSAFE,
+                    CreateMode.EPHEMERAL_SEQUENTIAL);
+            while (true) {
+                synchronized (mutex) {
+                    List<String> list = zk.getChildren(root, true);
+
+                    if (list.size() < size) {
+                        mutex.wait();
+                    } else {
+                        return true;
+                    }
+                }
+            }
+        }
+
+        /**
+         * Wait until all reach barrier
+         *
+         * @return
+         * @throws KeeperException
+         * @throws InterruptedException
+         */
+
+        boolean leave() throws KeeperException, InterruptedException{
+            zk.delete(root + "/" + name, 0);
+            while (true) {
+                synchronized (mutex) {
+                    List<String> list = zk.getChildren(root, true);
+                        if (list.size() > 0) {
+                            mutex.wait();
+                        } else {
+                            return true;
+                        }
+                    }
+                }
+        }
+    }
+
+    /**
+     * Producer-Consumer queue
+     */
+    static public class Queue extends SyncPrimitive {
+
+        /**
+         * Constructor of producer-consumer queue
+         *
+         * @param address
+         * @param name
+         */
+        Queue(String address, String name) {
+            super(address);
+            this.root = name;
+            // Create ZK node name
+            if (zk != null) {
+                try {
+                    Stat s = zk.exists(root, false);
+                    if (s == null) {
+                        zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE,
+                                CreateMode.PERSISTENT);
+                    }
+                } catch (KeeperException e) {
+                    System.out
+                            .println("Keeper exception when instantiating queue: "
+                                    + e.toString());
+                } catch (InterruptedException e) {
+                    System.out.println("Interrupted exception");
+                }
+            }
+        }
+
+        /**
+         * Add element to the queue.
+         *
+         * @param i
+         * @return
+         */
+
+        boolean produce(int i) throws KeeperException, InterruptedException{
+            ByteBuffer b = ByteBuffer.allocate(4);
+            byte[] value;
+
+            // Add child with value i
+            b.putInt(i);
+            value = b.array();
+            zk.create(root + "/element", value, Ids.OPEN_ACL_UNSAFE,
+                        CreateMode.PERSISTENT_SEQUENTIAL);
+
+            return true;
+        }
+
+
+        /**
+         * Remove first element from the queue.
+         *
+         * @return
+         * @throws KeeperException
+         * @throws InterruptedException
+         */
+        int consume() throws KeeperException, InterruptedException{
+            int retvalue = -1;
+            Stat stat = null;
+
+            // Get the first element available
+            while (true) {
+                synchronized (mutex) {
+                    List<String> list = zk.getChildren(root, true);
+                    if (list.size() == 0) {
+                        System.out.println("Going to wait");
+                        mutex.wait();
+                    } else {
+                        Integer min = new Integer(list.get(0).substring(7));
+                        for(String s : list){
+                            Integer tempValue = new Integer(s.substring(7));
+                            //System.out.println("Temporary value: " + tempValue);
+                            if(tempValue < min) min = tempValue;
+                        }
+                        System.out.println("Temporary value: " + root + "/element" + min);
+                        byte[] b = zk.getData(root + "/element" + min,
+                                    false, stat);
+                        zk.delete(root + "/element" + min, 0);
+                        ByteBuffer buffer = ByteBuffer.wrap(b);
+                        retvalue = buffer.getInt();
+
+                        return retvalue;
+                    }
+                }
+            }
+        }
+    }
+
+    public static void main(String args[]) {
+        if (args[0].equals("qTest"))
+            queueTest(args);
+        else
+            barrierTest(args);
+
+    }
+
+    public static void queueTest(String args[]) {
+        Queue q = new Queue(args[1], "/app1");
+
+        System.out.println("Input: " + args[1]);
+        int i;
+        Integer max = new Integer(args[2]);
+
+        if (args[3].equals("p")) {
+            System.out.println("Producer");
+            for (i = 0; i < max; i++)
+                try{
+                    q.produce(10 + i);
+                } catch (KeeperException e){
+
+                } catch (InterruptedException e){
+
+                }
+        } else {
+            System.out.println("Consumer");
+
+            for (i = 0; i < max; i++) {
+                try{
+                    int r = q.consume();
+                    System.out.println("Item: " + r);
+                } catch (KeeperException e){
+                    i--;
+                } catch (InterruptedException e){
+
+                }
+            }
+        }
+    }
+
+    public static void barrierTest(String args[]) {
+        Barrier b = new Barrier(args[1], "/b1", new Integer(args[2]));
+        try{
+            boolean flag = b.enter();
+            System.out.println("Entered barrier: " + args[2]);
+            if(!flag) System.out.println("Error when entering the barrier");
+        } catch (KeeperException e){
+
+        } catch (InterruptedException e){
+
+        }
+
+        // Generate random integer
+        Random rand = new Random();
+        int r = rand.nextInt(100);
+        // Loop for rand iterations
+        for (int i = 0; i < r; i++) {
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+
+            }
+        }
+        try{
+            b.leave();
+        } catch (KeeperException e){
+
+        } catch (InterruptedException e){
+
+        }
+        System.out.println("Left barrier");
+    }
+}
+
+
+
+
+ + +

+ +

+
+ +
 
+
+ + + diff --git a/docs/zookeeperTutorial.pdf b/docs/zookeeperTutorial.pdf new file mode 100644 index 00000000000..229b3f4cddc Binary files /dev/null and b/docs/zookeeperTutorial.pdf differ diff --git a/ivy.xml b/ivy.xml new file mode 100644 index 00000000000..5b2f29a18b4 --- /dev/null +++ b/ivy.xml @@ -0,0 +1,88 @@ + + + + + + + + ZooKeeper + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ivysettings.xml b/ivysettings.xml new file mode 100644 index 00000000000..5324ffff608 --- /dev/null +++ b/ivysettings.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/LICENSE.txt b/src/LICENSE.txt new file mode 100644 index 00000000000..7ba311f4ba8 --- /dev/null +++ b/src/LICENSE.txt @@ -0,0 +1,224 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +This distribution bundles javacc, which is available under the +3-clause BSD License. For details, see a copy of the license in +lib/javacc.LICENSE.txt + +This distribution bundles jline 2.11, which is available under the +2-clause BSD License. For details, see a copy of the license in +lib/jline-2.11.LICENSE.txt + +This distribution bundles servlet-api-2.5, which is available under the CDDL +License. For details, see a copy of the license in +lib/servlet-api-2.5.LICENSE.txt + +This distribution bundles SLF4J 1.7.5, which is available under the MIT +License. For details, see a copy of the license in +lib/slf4j-1.7.5.LICENSE.txt + +This distribution bundles a modified version of 'JZLib' as part of +Netty-3.7.0, which is available under the 3-clause BSD licence. For +details, see a copy of the licence in META-INF/license/LICENSE-jzlib.txt +as part of the Netty jar in lib/netty-3.7.0.Final.jar. diff --git a/src/NOTICE.txt b/src/NOTICE.txt new file mode 100644 index 00000000000..2c468c8b838 --- /dev/null +++ b/src/NOTICE.txt @@ -0,0 +1,9 @@ +Apache ZooKeeper +Copyright 2009-2015 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +The bundled servlet-api-2.5.jar is under the CDDL license, +the original source code for this can be found at +http://repo1.maven.org/maven2/javax/servlet/servlet-api/2.5/ diff --git a/src/c/ChangeLog b/src/c/ChangeLog new file mode 100644 index 00000000000..c85a6c0ad86 --- /dev/null +++ b/src/c/ChangeLog @@ -0,0 +1,116 @@ +Release 2.1.1 +2008-04-30 Andrew Kornev + + * changed the distributino package name to "c-client-src" + +Release 2.1.0 +2008-04-30 Andrew Kornev + + * added the client latency diagnostics; the client prints a warning when the + reponse latency exceeds 20ms + + * modified logging format to report the znode path for which the zookeeper + operation is called + + * fixed a minor bug where error messages were missing for some of the newer + zookeeper error codes (ZCLOSING and ZNOTHING). + + * improved logging by adding the XID to the message to make it easy to match + requests to responses + + * fixed the bug causing sporadic session termination and timeouts + + * added a new return code to zookeeper_process() -- ZNOTHING -- + that indicates that the socket has no more data to read + + * more unit tests added + +Release 1.1.3 +2008-02-07 Andrew Kornev + + * get_xid() is not thread-safe (xid initialization race condition + in the multi-threaded mode). + + * the I/O thread doesnt automatically terminate on AUTH_FAILURE and + SESSION_EXPIRED events. + + * all session events should be processed on the completion thread. + + * PING operation doesnt atomically enqueue the completion and + send buffers like other operations do. + + * corrected zookeeper_init() doxygen docs. + + * new unit tests added. + + +Release 1.1.2 +2008-01-24 Andrew Kornev + + * fixed a race condition caused by the code in zookeeper_process() + and free_completions() setting sc->complete to 1 without proper + synchronization; + + * fixed zoo_get() not updating buffer_len value with the actual + buffer length on return; added missing enter_critical/leave_critical + calls to the async ZK operations. + + * Replaced select() with poll() to fix the problem with the FD_SET + macro causing stack corruption for FDs higher than 1024 + + * Added zoo_set_log_stream() to the public API. The function allows + applications to specify a different log file. + + * Removed unused declarations from zookeeper.h (ACL related) + + * changed zoo_get() signature to take a pointer to buffer length. + The function sets the parameter to the actual data length upon return. + + * the watcher callback now takes the zhandle as its first parameter. This + is to avoid a race condition in the multi-threaded client when a watcher + is called before zookeeper_init() has returned. + + * fixed zookeeper_close() resource leaks and race conditions, + fixed the race condition causing xid mismatch. + + * added support for cppunit, added new targets: "check" and "run-check" + to build and run unit tests. + + * Changed the signature of zookeeper_init(): it now takes a context pointer + as a parameter. This is to avoid a race condition in the multi-threaded client. + + * Using a self-pipe rather than SIGUSR1 to wake up select() in the I/O thread + + * Added the doxygen target to the autoconf scripts + + * Pulled out the logging functionality from zookeeper.c to zk_log.c/.h. + Fixed a minor issue with PING responses being unnecessarily put on + the completion queue rather than simply dropped. Make use of DLL_EXPORT + symbol for building shared lib on cygwin. + + * Implemented new Zookeeper operation sync() to flush the leader channel + to ensure that all updates have reached the followers. + + * Synchronous methods not being handled properly on disconnect + + * breed: fixed an incorrect parameter passed to zookeeper API by + the Sync API wrapper functions + + * breed: the set and delete commands now support both Sync and Async API. + Prefix the command name with an 'a' to call the Async API: aset, adelete + + * Make sure mutexes and condition variables are properly initialized + and destroyed + + * Fixed zookeeper_close() causing core dumps with mt_adaptor + + +Release 1.0.0 +2007-11-27 Andrew Kornev + + * configure.ac and Makefile.am added support for GNU autotools + + * recordio.c/.h updated jute IO routines to use bit-explicit integer types + (int32_t vs. int, and int64_t vs. long long) + + * README rough draft \ No newline at end of file diff --git a/src/c/Cli.vcproj b/src/c/Cli.vcproj new file mode 100644 index 00000000000..39ed8a429d6 --- /dev/null +++ b/src/c/Cli.vcproj @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/c/Cli.vcxproj b/src/c/Cli.vcxproj new file mode 100644 index 00000000000..3104a4b41b0 --- /dev/null +++ b/src/c/Cli.vcxproj @@ -0,0 +1,160 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6} + Win32Proj + cli + + + + Application + true + v120 + Unicode + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + THREADED;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + include;generated + + + Console + true + ws2_32.lib + + + + + + + Level3 + Disabled + THREADED;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + include;generated + + + Console + true + ws2_32.lib + + + + + Level3 + + + MaxSpeed + true + true + THREADED;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + include;generated + + + Console + true + true + true + ws2_32.lib + + + + + Level3 + + + MaxSpeed + true + true + THREADED;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + include;generated + + + Console + true + true + true + ws2_32.lib + + + + + + + + {5754fb2b-5ea5-4988-851d-908ca533a626} + + + + + + \ No newline at end of file diff --git a/src/c/Cli.vcxproj.filters b/src/c/Cli.vcxproj.filters new file mode 100644 index 00000000000..db085edf741 --- /dev/null +++ b/src/c/Cli.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/c/INSTALL b/src/c/INSTALL new file mode 100644 index 00000000000..5458714e1e2 --- /dev/null +++ b/src/c/INSTALL @@ -0,0 +1,234 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/src/c/LICENSE b/src/c/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/src/c/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/c/Makefile.am b/src/c/Makefile.am new file mode 100644 index 00000000000..adaf0c8af4a --- /dev/null +++ b/src/c/Makefile.am @@ -0,0 +1,140 @@ +# need this for Doxygen integration +include $(top_srcdir)/aminclude.am + +AUTOMAKE_OPTIONS = serial-tests +if SOLARIS + SOLARIS_CPPFLAGS = -D_POSIX_PTHREAD_SEMANTICS + SOLARIS_LIB_LDFLAGS = -lnsl -lsocket +endif +AM_CPPFLAGS = -I${srcdir}/include -I${srcdir}/tests -I${srcdir}/generated $(SOLARIS_CPPFLAGS) +AM_CFLAGS = -Wall -Werror -Wdeclaration-after-statement +AM_CXXFLAGS = -Wall $(USEIPV6) + +LIB_LDFLAGS = -no-undefined -version-info 2 $(SOLARIS_LIB_LDFLAGS) + +pkginclude_HEADERS = include/zookeeper.h include/zookeeper_version.h include/zookeeper_log.h include/proto.h include/recordio.h generated/zookeeper.jute.h +EXTRA_DIST=LICENSE + +HASHTABLE_SRC = src/hashtable/hashtable_itr.h src/hashtable/hashtable_itr.c \ + src/hashtable/hashtable_private.h src/hashtable/hashtable.h src/hashtable/hashtable.c + +noinst_LTLIBRARIES = libhashtable.la +libhashtable_la_SOURCES = $(HASHTABLE_SRC) + +COMMON_SRC = src/zookeeper.c include/zookeeper.h include/zookeeper_version.h include/zookeeper_log.h\ + src/recordio.c include/recordio.h include/proto.h \ + src/zk_adaptor.h generated/zookeeper.jute.c \ + src/zk_log.c src/zk_hashtable.h src/zk_hashtable.c \ + src/addrvec.h src/addrvec.c + +# These are the symbols (classes, mostly) we want to export from our library. +EXPORT_SYMBOLS = '(zoo_|zookeeper_|zhandle|Z|format_log_message|log_message|logLevel|deallocate_|allocate_|zerror|is_unrecoverable)' +noinst_LTLIBRARIES += libzkst.la +libzkst_la_SOURCES =$(COMMON_SRC) src/st_adaptor.c +libzkst_la_LIBADD = -lm $(CLOCK_GETTIME_LIBS) + +lib_LTLIBRARIES = libzookeeper_st.la +libzookeeper_st_la_SOURCES = +libzookeeper_st_la_LIBADD=libzkst.la libhashtable.la +libzookeeper_st_la_DEPENDENCIES=libzkst.la libhashtable.la +libzookeeper_st_la_LDFLAGS = $(LIB_LDFLAGS) -export-symbols-regex $(EXPORT_SYMBOLS) + +if WANT_SYNCAPI +noinst_LTLIBRARIES += libzkmt.la +libzkmt_la_SOURCES =$(COMMON_SRC) src/mt_adaptor.c +libzkmt_la_CFLAGS = -DTHREADED +libzkmt_la_LIBADD = -lm $(CLOCK_GETTIME_LIBS) + +lib_LTLIBRARIES += libzookeeper_mt.la +libzookeeper_mt_la_SOURCES = +libzookeeper_mt_la_LIBADD=libzkmt.la libhashtable.la -lpthread +libzookeeper_mt_la_DEPENDENCIES=libzkmt.la libhashtable.la +libzookeeper_mt_la_LDFLAGS = $(LIB_LDFLAGS) -export-symbols-regex $(EXPORT_SYMBOLS) +endif + +bin_PROGRAMS = cli_st + +cli_st_SOURCES = src/cli.c +cli_st_LDADD = libzookeeper_st.la + +if WANT_SYNCAPI +bin_PROGRAMS += cli_mt load_gen + +cli_mt_SOURCES = src/cli.c +cli_mt_LDADD = libzookeeper_mt.la +cli_mt_CFLAGS = -DTHREADED + +load_gen_SOURCES = src/load_gen.c +load_gen_LDADD = libzookeeper_mt.la +load_gen_CFLAGS = -DTHREADED + +endif + +######################################################################### +# build and run unit tests + +EXTRA_DIST+=$(wildcard ${srcdir}/tests/*.cc) $(wildcard ${srcdir}/tests/*.h) \ + ${srcdir}/tests/wrappers.opt ${srcdir}/tests/wrappers-mt.opt + +# These tests are ordered in a logical manner such that each builds upon basic +# functionality tested in prior tests. e.g. the most basic functionality is +# tested in TestZookeeperInit and TestZookeeperClose and as such should be tested +# first as a foundation with more complex test suites to follow. +TEST_SOURCES = \ + tests/TestDriver.cc \ + tests/LibCMocks.cc \ + tests/LibCSymTable.cc \ + tests/MocksBase.cc \ + tests/ZKMocks.cc \ + tests/Util.cc \ + tests/ThreadingUtil.cc \ + tests/TestZookeeperInit.cc \ + tests/TestZookeeperClose.cc \ + tests/TestReconfig.cc \ + tests/TestReconfigServer.cc \ + tests/TestClientRetry.cc \ + tests/TestOperations.cc \ + tests/TestMulti.cc \ + tests/TestWatchers.cc \ + tests/TestClient.cc \ + tests/ZooKeeperQuorumServer.cc \ + tests/ZooKeeperQuorumServer.h \ + tests/TestReadOnlyClient.cc \ + $(NULL) + +if SOLARIS + SHELL_SYMBOL_WRAPPERS = cat ${srcdir}/tests/wrappers.opt + SYMBOL_WRAPPERS=$(SHELL_SYMBOL_WRAPPERS:sh) +else + SYMBOL_WRAPPERS=$(shell cat ${srcdir}/tests/wrappers.opt) +endif + +check_PROGRAMS = zktest-st +TESTS_ENVIRONMENT = ZKROOT=${srcdir}/../.. \ + CLASSPATH=$$CLASSPATH:$$CLOVER_HOME/lib/clover.jar +nodist_zktest_st_SOURCES = $(TEST_SOURCES) +zktest_st_LDADD = libzkst.la libhashtable.la $(CPPUNIT_LIBS) +zktest_st_CXXFLAGS = -DUSE_STATIC_LIB $(CPPUNIT_CFLAGS) $(USEIPV6) $(SOLARIS_CPPFLAGS) +zktest_st_LDFLAGS = -static-libtool-libs $(SYMBOL_WRAPPERS) $(SOLARIS_LIB_LDFLAGS) + +if WANT_SYNCAPI + check_PROGRAMS += zktest-mt + nodist_zktest_mt_SOURCES = $(TEST_SOURCES) tests/PthreadMocks.cc + zktest_mt_LDADD = libzkmt.la libhashtable.la -lpthread $(CPPUNIT_LIBS) + zktest_mt_CXXFLAGS = -DUSE_STATIC_LIB -DTHREADED $(CPPUNIT_CFLAGS) $(USEIPV6) +if SOLARIS + SHELL_SYMBOL_WRAPPERS_MT = cat ${srcdir}/tests/wrappers-mt.opt + SYMBOL_WRAPPERS_MT=$(SYMBOL_WRAPPERS) $(SHELL_SYMBOL_WRAPPERS_MT:sh) +else + SYMBOL_WRAPPERS_MT=$(SYMBOL_WRAPPERS) $(shell cat ${srcdir}/tests/wrappers-mt.opt) +endif + zktest_mt_LDFLAGS = -static-libtool-libs $(SYMBOL_WRAPPERS_MT) $(SOLARIS_LIB_LDFLAGS) +endif + +TESTS = $(check_PROGRAMS) + +clean-local: clean-check + $(RM) $(DX_CLEANFILES) + +clean-check: + $(RM) $(nodist_zktest_st_OBJECTS) $(nodist_zktest_mt_OBJECTS) diff --git a/src/c/NOTICE.txt b/src/c/NOTICE.txt new file mode 100644 index 00000000000..07ef1ad516c --- /dev/null +++ b/src/c/NOTICE.txt @@ -0,0 +1,41 @@ +Apache ZooKeeper +Copyright 2009-2011 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +---------- +include/winstdint.h is included only for Windows Client support, as follows: + +// ISO C9x compliant stdint.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006-2008 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +---------- diff --git a/src/c/README b/src/c/README new file mode 100644 index 00000000000..045ef9ac43e --- /dev/null +++ b/src/c/README @@ -0,0 +1,133 @@ + Zookeeper C client library + + +This package provides a C client interface to Zookeeper server. + +For the latest information about ZooKeeper, please visit our website at: + http://zookeeper.apache.org/ +and our wiki, at: + https://cwiki.apache.org/confluence/display/ZOOKEEPER + +Full documentation for this release can also be found in ../../docs/index.html + + +OVERVIEW + +The client supports two types of APIs -- synchronous and asynchronous. + +Asynchronous API provides non-blocking operations with completion callbacks and +relies on the application to implement event multiplexing on its behalf. + +On the other hand, Synchronous API provides a blocking flavor of +zookeeper operations and runs its own event loop in a separate thread. + +Sync and Async APIs can be mixed and matched within the same application. + +The package includes two shared libraries: zookeeper_st and +zookeeper_mt. The former only provides the Async API and is not +thread-safe. The only reason this library exists is to support the +platforms were pthread library is not available or unstable +(i.e. FreeBSD 4.x). In all other cases the application developers are +advised to link against zookeeper_mt as it includes support for both +Sync and Async API. + + +INSTALLATION + +If you're building the client from a source checkout you need to +follow the steps outlined below. If you're building from a release +tar downloaded from Apache please skip to step 2. + +1) do a "ant compile_jute" from the zookeeper top level directory (.../trunk). + This will create a directory named "generated" under src/c. Skip to step 3. +2) unzip/untar the source tarball and cd to the zookeeper-x.x.x/src/c directory +3) change directory to src/c and do a "autoreconf -if" to bootstrap + autoconf, automake and libtool. Please make sure you have autoconf + version 2.59 or greater installed. If cppunit is installed in a non-standard + directory, you need to specify where to find cppunit.m4. For example, if + cppunit is installed under /usr/local, run: + + ACLOCAL="aclocal -I /usr/local/share/aclocal" autoreconf -if + +4) do a "./configure [OPTIONS]" to generate the makefile. See INSTALL + for general information about running configure. Additionally, the + configure supports the following options: + --enable-debug enables optimization and enables debug info compiler + options, disabled by default + --without-syncapi disables Sync API support; zookeeper_mt library won't + be built, enabled by default + --disable-static do not build static libraries, enabled by default + --disable-shared do not build shared libraries, enabled by default + --without-cppunit do not build the test library, enabled by default. + +5) do a "make" or "make install" to build the libraries and install them. + Alternatively, you can also build and run a unit test suite (and + you probably should). Please make sure you have cppunit-1.10.x or + higher installed before you execute step 4. Once ./configure has + finished, do a "make check". It will build the libraries, build + the tests and run them. +6) to generate doxygen documentation do a "make doxygen-doc". All + documentations will be placed to a new subfolder named docs. By + default only HTML documentation is generated. For information on + other document formats please use "./configure --help" + + +USING THE CLIENT + +You can test your client by running a zookeeper server (see +instructions on the project wiki page on how to run it) and connecting +to it using the zookeeper shell application cli that is built as part +of the installation procedure. + +cli_mt (multithreaded, built against zookeeper_mt library) is shown in +this example, but you could also use cli_st (singlethreaded, built +against zookeeper_st library): + +$ cli_mt zookeeper_host:9876 + +To start a client with read-only mode enabled, use the -r flag: + +$ cli_mt -r zookeeper_host:9876 + +This is a client application that gives you a shell for executing +simple zookeeper commands. Once successfully started and connected to +the server it displays a shell prompt. + +You can now enter zookeeper commands. For example, to create a node: + +> create /my_new_node + +To verify that the node's been created: + +> ls / + +You should see a list of nodes who are the children of the root node "/". + +Here's a list of command supported by the cli shell: + +ls -- list children of a znode identified by . The + command set a children watch on the znode. +get -- get the value of a znode at +set -- set the value of a znode at to +create [+e|+s] -- create a znode as a child of znode ; + use +e option to create an ephemeral znode, + use +s option to create a znode with a sequence number + appended to the name. The operation will fail if + the parent znode (the one identified by ) doesn't + exist. +delete -- delete the znode at . The command will fail if the znode + has children. +sync -- make sure all pending updates have been applied to znode at +exists -- returns a result code indicating whether the znode at + exists. The command also sets a znode watch. +myid -- prints out the current zookeeper session id. +quit -- exit the shell. + +In order to be able to use the zookeeper API in your application you have to +1) remember to include the zookeeper header + #include +2) use -DTHREADED compiler option to enable Sync API; in this case you should + be linking your code against zookeeper_mt library + +Please take a look at cli.c to understand how to use the two API types. +(TODO: some kind of short tutorial would be helpful, I guess) diff --git a/src/c/acinclude.m4 b/src/c/acinclude.m4 new file mode 100644 index 00000000000..d0041d8c26a --- /dev/null +++ b/src/c/acinclude.m4 @@ -0,0 +1,312 @@ +# This file is part of Autoconf. -*- Autoconf -*- + +# Copyright (C) 2004 Oren Ben-Kiki +# This file is distributed under the same terms as the Autoconf macro files. + +# Generate automatic documentation using Doxygen. Works in concert with the +# aminclude.m4 file and a compatible doxygen configuration file. Defines the +# following public macros: +# +# DX_???_FEATURE(ON|OFF) - control the default setting fo a Doxygen feature. +# Supported features are 'DOXYGEN' itself, 'DOT' for generating graphics, +# 'HTML' for plain HTML, 'CHM' for compressed HTML help (for MS users), 'CHI' +# for generating a seperate .chi file by the .chm file, and 'MAN', 'RTF', +# 'XML', 'PDF' and 'PS' for the appropriate output formats. The environment +# variable DOXYGEN_PAPER_SIZE may be specified to override the default 'a4wide' +# paper size. +# +# By default, HTML, PDF and PS documentation is generated as this seems to be +# the most popular and portable combination. MAN pages created by Doxygen are +# usually problematic, though by picking an appropriate subset and doing some +# massaging they might be better than nothing. CHM and RTF are specific for MS +# (note that you can't generate both HTML and CHM at the same time). The XML is +# rather useless unless you apply specialized post-processing to it. +# +# The macro mainly controls the default state of the feature. The use can +# override the default by specifying --enable or --disable. The macros ensure +# that contradictory flags are not given (e.g., --enable-doxygen-html and +# --enable-doxygen-chm, --enable-doxygen-anything with --disable-doxygen, etc.) +# Finally, each feature will be automatically disabled (with a warning) if the +# required programs are missing. +# +# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN with +# the following parameters: a one-word name for the project for use as a +# filename base etc., an optional configuration file name (the default is +# 'Doxyfile', the same as Doxygen's default), and an optional output directory +# name (the default is 'doxygen-doc'). + +## ----------## +## Defaults. ## +## ----------## + +DX_ENV="" +AC_DEFUN([DX_FEATURE_doc], ON) +AC_DEFUN([DX_FEATURE_dot], ON) +AC_DEFUN([DX_FEATURE_man], OFF) +AC_DEFUN([DX_FEATURE_html], ON) +AC_DEFUN([DX_FEATURE_chm], OFF) +AC_DEFUN([DX_FEATURE_chi], OFF) +AC_DEFUN([DX_FEATURE_rtf], OFF) +AC_DEFUN([DX_FEATURE_xml], OFF) +AC_DEFUN([DX_FEATURE_pdf], ON) +AC_DEFUN([DX_FEATURE_ps], ON) + +## --------------- ## +## Private macros. ## +## --------------- ## + +# DX_ENV_APPEND(VARIABLE, VALUE) +# ------------------------------ +# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen. +AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])]) + +# DX_DIRNAME_EXPR +# --------------- +# Expand into a shell expression prints the directory part of a path. +AC_DEFUN([DX_DIRNAME_EXPR], + [[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']]) + +# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF) +# ------------------------------------- +# Expands according to the M4 (static) status of the feature. +AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])]) + +# DX_REQUIRE_PROG(VARIABLE, PROGRAM) +# ---------------------------------- +# Require the specified program to be found for the DX_CURRENT_FEATURE to work. +AC_DEFUN([DX_REQUIRE_PROG], [ +AC_PATH_TOOL([$1], [$2]) +if test "$DX_FLAG_$[DX_CURRENT_FEATURE$$1]" = 1; then + AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION]) + AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +fi +]) + +# DX_TEST_FEATURE(FEATURE) +# ------------------------ +# Expand to a shell expression testing whether the feature is active. +AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1]) + +# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE) +# ------------------------------------------------- +# Verify that a required features has the right state before trying to turn on +# the DX_CURRENT_FEATURE. +AC_DEFUN([DX_CHECK_DEPEND], [ +test "$DX_FLAG_$1" = "$2" \ +|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1, + requires, contradicts) doxygen-DX_CURRENT_FEATURE]) +]) + +# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE) +# ---------------------------------------------------------- +# Turn off the DX_CURRENT_FEATURE if the required feature is off. +AC_DEFUN([DX_CLEAR_DEPEND], [ +test "$DX_FLAG_$1" = "$2" || AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +]) + +# DX_FEATURE_ARG(FEATURE, DESCRIPTION, +# CHECK_DEPEND, CLEAR_DEPEND, +# REQUIRE, DO-IF-ON, DO-IF-OFF) +# -------------------------------------------- +# Parse the command-line option controlling a feature. CHECK_DEPEND is called +# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND), +# otherwise CLEAR_DEPEND is called to turn off the default state if a required +# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional +# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and +# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature. +AC_DEFUN([DX_ARG_ABLE], [ + AC_DEFUN([DX_CURRENT_FEATURE], [$1]) + AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2]) + AC_ARG_ENABLE(doxygen-$1, + [AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1], + [--enable-doxygen-$1]), + DX_IF_FEATURE([$1], [don't $2], [$2]))], + [ +case "$enableval" in +#( +y|Y|yes|Yes|YES) + AC_SUBST([DX_FLAG_$1], 1) + $3 +;; #( +n|N|no|No|NO) + AC_SUBST([DX_FLAG_$1], 0) +;; #( +*) + AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1]) +;; +esac +], [ +AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)]) +$4 +]) +if DX_TEST_FEATURE([$1]); then + $5 + : +fi +if DX_TEST_FEATURE([$1]); then + AM_CONDITIONAL(DX_COND_$1, :) + $6 + : +else + AM_CONDITIONAL(DX_COND_$1, false) + $7 + : +fi +]) + +## -------------- ## +## Public macros. ## +## -------------- ## + +# DX_XXX_FEATURE(DEFAULT_STATE) +# ----------------------------- +AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])]) +AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])]) +AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])]) +AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])]) +AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])]) +AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])]) +AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])]) +AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])]) + +# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR]) +# --------------------------------------------------------- +# PROJECT also serves as the base name for the documentation files. +# The default CONFIG-FILE is "Doxyfile" and OUTPUT-DOC-DIR is "doxygen-doc". +AC_DEFUN([DX_INIT_DOXYGEN], [ + +# Files: +AC_SUBST([DX_PROJECT], [$1]) +AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])]) +AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])]) + +# Environment variables used inside doxygen.cfg: +DX_ENV_APPEND(SRCDIR, $srcdir) +DX_ENV_APPEND(PROJECT, $DX_PROJECT) +DX_ENV_APPEND(DOCDIR, $DX_DOCDIR) +DX_ENV_APPEND(VERSION, $PACKAGE_VERSION) + +# Doxygen itself: +DX_ARG_ABLE(doc, [generate any doxygen documentation], + [], + [], + [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen) + DX_REQUIRE_PROG([DX_PERL], perl)], + [DX_ENV_APPEND(PERL_PATH, $DX_PERL)]) + +# Dot for graphics: +DX_ARG_ABLE(dot, [generate graphics for doxygen documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_DOT], dot)], + [DX_ENV_APPEND(HAVE_DOT, YES) + DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])], + [DX_ENV_APPEND(HAVE_DOT, NO)]) + +# Man pages generation: +DX_ARG_ABLE(man, [generate doxygen manual pages], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_MAN, YES)], + [DX_ENV_APPEND(GENERATE_MAN, NO)]) + +# RTF file generation: +DX_ARG_ABLE(rtf, [generate doxygen RTF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_RTF, YES)], + [DX_ENV_APPEND(GENERATE_RTF, NO)]) + +# XML file generation: +DX_ARG_ABLE(xml, [generate doxygen XML documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_XML, YES)], + [DX_ENV_APPEND(GENERATE_XML, NO)]) + +# (Compressed) HTML help generation: +DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_HHC], hhc)], + [DX_ENV_APPEND(HHC_PATH, $DX_HHC) + DX_ENV_APPEND(GENERATE_HTML, YES) + DX_ENV_APPEND(GENERATE_HTMLHELP, YES)], + [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)]) + +# Seperate CHI file generation. +DX_ARG_ABLE(chi, [generate doxygen seperate compressed HTML help index file], + [DX_CHECK_DEPEND(chm, 1)], + [DX_CLEAR_DEPEND(chm, 1)], + [], + [DX_ENV_APPEND(GENERATE_CHI, YES)], + [DX_ENV_APPEND(GENERATE_CHI, NO)]) + +# Plain HTML pages generation: +DX_ARG_ABLE(html, [generate doxygen plain HTML documentation], + [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)], + [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)], + [], + [DX_ENV_APPEND(GENERATE_HTML, YES)], + [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)]) + +# PostScript file generation: +DX_ARG_ABLE(ps, [generate doxygen PostScript documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_LATEX], latex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_DVIPS], dvips) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# PDF file generation: +DX_ARG_ABLE(pdf, [generate doxygen PDF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# LaTeX generation for PS and/or PDF: +if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then + AM_CONDITIONAL(DX_COND_latex, :) + DX_ENV_APPEND(GENERATE_LATEX, YES) +else + AM_CONDITIONAL(DX_COND_latex, false) + DX_ENV_APPEND(GENERATE_LATEX, NO) +fi + +# Paper size for PS and/or PDF: +AC_ARG_VAR(DOXYGEN_PAPER_SIZE, + [a4wide (default), a4, letter, legal or executive]) +case "$DOXYGEN_PAPER_SIZE" in +#( +"") + AC_SUBST(DOXYGEN_PAPER_SIZE, "") +;; #( +a4wide|a4|letter|legal|executive) + DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE) +;; #( +*) + AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE']) +;; +esac + +#For debugging: +#echo DX_FLAG_doc=$DX_FLAG_doc +#echo DX_FLAG_dot=$DX_FLAG_dot +#echo DX_FLAG_man=$DX_FLAG_man +#echo DX_FLAG_html=$DX_FLAG_html +#echo DX_FLAG_chm=$DX_FLAG_chm +#echo DX_FLAG_chi=$DX_FLAG_chi +#echo DX_FLAG_rtf=$DX_FLAG_rtf +#echo DX_FLAG_xml=$DX_FLAG_xml +#echo DX_FLAG_pdf=$DX_FLAG_pdf +#echo DX_FLAG_ps=$DX_FLAG_ps +#echo DX_ENV=$DX_ENV +]) diff --git a/src/c/aclocal.m4 b/src/c/aclocal.m4 new file mode 100644 index 00000000000..b5b4351a430 --- /dev/null +++ b/src/c/aclocal.m4 @@ -0,0 +1,10182 @@ +# generated automatically by aclocal 1.15 -*- Autoconf -*- + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. + +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, +[m4_warning([this file was generated for autoconf 2.69. +You have another version of autoconf. It may work, but is not guaranteed to. +If you have problems, you may need to regenerate the build system entirely. +To do so, use the procedure documented by the package, typically 'autoreconf'.])]) + +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +# +# Copyright (C) 1996-2001, 2003-2015 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +m4_define([_LT_COPYING], [dnl +# Copyright (C) 2014 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program or library that is built +# using GNU Libtool, you may include this file under the same +# distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +]) + +# serial 58 LT_INIT + + +# LT_PREREQ(VERSION) +# ------------------ +# Complain and exit if this libtool version is less that VERSION. +m4_defun([LT_PREREQ], +[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, + [m4_default([$3], + [m4_fatal([Libtool version $1 or higher is required], + 63)])], + [$2])]) + + +# _LT_CHECK_BUILDDIR +# ------------------ +# Complain if the absolute build directory name contains unusual characters +m4_defun([_LT_CHECK_BUILDDIR], +[case `pwd` in + *\ * | *\ *) + AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; +esac +]) + + +# LT_INIT([OPTIONS]) +# ------------------ +AC_DEFUN([LT_INIT], +[AC_PREREQ([2.62])dnl We use AC_PATH_PROGS_FEATURE_CHECK +AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +_LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}]) + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +])# LT_INIT + +# Old names: +AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) +AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PROG_LIBTOOL], []) +dnl AC_DEFUN([AM_PROG_LIBTOOL], []) + + +# _LT_PREPARE_CC_BASENAME +# ----------------------- +m4_defun([_LT_PREPARE_CC_BASENAME], [ +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in @S|@*""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} +])# _LT_PREPARE_CC_BASENAME + + +# _LT_CC_BASENAME(CC) +# ------------------- +# It would be clearer to call AC_REQUIREs from _LT_PREPARE_CC_BASENAME, +# but that macro is also expanded into generated libtool script, which +# arranges for $SED and $ECHO to be set by different means. +m4_defun([_LT_CC_BASENAME], +[m4_require([_LT_PREPARE_CC_BASENAME])dnl +AC_REQUIRE([_LT_DECL_SED])dnl +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl +func_cc_basename $1 +cc_basename=$func_cc_basename_result +]) + + +# _LT_FILEUTILS_DEFAULTS +# ---------------------- +# It is okay to use these file commands and assume they have been set +# sensibly after 'm4_require([_LT_FILEUTILS_DEFAULTS])'. +m4_defun([_LT_FILEUTILS_DEFAULTS], +[: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} +])# _LT_FILEUTILS_DEFAULTS + + +# _LT_SETUP +# --------- +m4_defun([_LT_SETUP], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl + +_LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl +dnl +_LT_DECL([], [host_alias], [0], [The host system])dnl +_LT_DECL([], [host], [0])dnl +_LT_DECL([], [host_os], [0])dnl +dnl +_LT_DECL([], [build_alias], [0], [The build system])dnl +_LT_DECL([], [build], [0])dnl +_LT_DECL([], [build_os], [0])dnl +dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +dnl +AC_REQUIRE([AC_PROG_LN_S])dnl +test -z "$LN_S" && LN_S="ln -s" +_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl +dnl +AC_REQUIRE([LT_CMD_MAX_LEN])dnl +_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl +_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl +dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl +m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_CHECK_MAGIC_METHOD])dnl +m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl +m4_require([_LT_CMD_OLD_ARCHIVE])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_WITH_SYSROOT])dnl +m4_require([_LT_CMD_TRUNCATE])dnl + +_LT_CONFIG_LIBTOOL_INIT([ +# See if we are running on zsh, and set the options that allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi +]) +if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + +_LT_CHECK_OBJDIR + +m4_require([_LT_TAG_COMPILER])dnl + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld=$lt_cv_prog_gnu_ld + +old_CC=$CC +old_CFLAGS=$CFLAGS + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + _LT_PATH_MAGIC + fi + ;; +esac + +# Use C for the default configuration in the libtool script +LT_SUPPORTED_TAG([CC]) +_LT_LANG_C_CONFIG +_LT_LANG_DEFAULT_CONFIG +_LT_CONFIG_COMMANDS +])# _LT_SETUP + + +# _LT_PREPARE_SED_QUOTE_VARS +# -------------------------- +# Define a few sed substitution that help us do robust quoting. +m4_defun([_LT_PREPARE_SED_QUOTE_VARS], +[# Backslashify metacharacters that are still active within +# double-quoted strings. +sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([["`\\]]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' +]) + +# _LT_PROG_LTMAIN +# --------------- +# Note that this code is called both from 'configure', and 'config.status' +# now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, +# 'config.status' has no value for ac_aux_dir unless we are using Automake, +# so we pass a copy along to make sure it has a sensible value anyway. +m4_defun([_LT_PROG_LTMAIN], +[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl +_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) +ltmain=$ac_aux_dir/ltmain.sh +])# _LT_PROG_LTMAIN + + + +# So that we can recreate a full libtool script including additional +# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS +# in macros and then make a single call at the end using the 'libtool' +# label. + + +# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) +# ---------------------------------------- +# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL_INIT], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_INIT], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_INIT]) + + +# _LT_CONFIG_LIBTOOL([COMMANDS]) +# ------------------------------ +# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) + + +# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) +# ----------------------------------------------------- +m4_defun([_LT_CONFIG_SAVE_COMMANDS], +[_LT_CONFIG_LIBTOOL([$1]) +_LT_CONFIG_LIBTOOL_INIT([$2]) +]) + + +# _LT_FORMAT_COMMENT([COMMENT]) +# ----------------------------- +# Add leading comment marks to the start of each line, and a trailing +# full-stop to the whole comment if one is not present already. +m4_define([_LT_FORMAT_COMMENT], +[m4_ifval([$1], [ +m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], + [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) +)]) + + + + + +# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) +# ------------------------------------------------------------------- +# CONFIGNAME is the name given to the value in the libtool script. +# VARNAME is the (base) name used in the configure script. +# VALUE may be 0, 1 or 2 for a computed quote escaped value based on +# VARNAME. Any other value will be used directly. +m4_define([_LT_DECL], +[lt_if_append_uniq([lt_decl_varnames], [$2], [, ], + [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], + [m4_ifval([$1], [$1], [$2])]) + lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) + m4_ifval([$4], + [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) + lt_dict_add_subkey([lt_decl_dict], [$2], + [tagged?], [m4_ifval([$5], [yes], [no])])]) +]) + + +# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) +# -------------------------------------------------------- +m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) + + +# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_tag_varnames], +[_lt_decl_filter([tagged?], [yes], $@)]) + + +# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) +# --------------------------------------------------------- +m4_define([_lt_decl_filter], +[m4_case([$#], + [0], [m4_fatal([$0: too few arguments: $#])], + [1], [m4_fatal([$0: too few arguments: $#: $1])], + [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], + [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], + [lt_dict_filter([lt_decl_dict], $@)])[]dnl +]) + + +# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) +# -------------------------------------------------- +m4_define([lt_decl_quote_varnames], +[_lt_decl_filter([value], [1], $@)]) + + +# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_dquote_varnames], +[_lt_decl_filter([value], [2], $@)]) + + +# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_varnames_tagged], +[m4_assert([$# <= 2])dnl +_$0(m4_quote(m4_default([$1], [[, ]])), + m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), + m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) +m4_define([_lt_decl_varnames_tagged], +[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) + + +# lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_all_varnames], +[_$0(m4_quote(m4_default([$1], [[, ]])), + m4_if([$2], [], + m4_quote(lt_decl_varnames), + m4_quote(m4_shift($@))))[]dnl +]) +m4_define([_lt_decl_all_varnames], +[lt_join($@, lt_decl_varnames_tagged([$1], + lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl +]) + + +# _LT_CONFIG_STATUS_DECLARE([VARNAME]) +# ------------------------------------ +# Quote a variable value, and forward it to 'config.status' so that its +# declaration there will have the same value as in 'configure'. VARNAME +# must have a single quote delimited value for this to work. +m4_define([_LT_CONFIG_STATUS_DECLARE], +[$1='`$ECHO "$][$1" | $SED "$delay_single_quote_subst"`']) + + +# _LT_CONFIG_STATUS_DECLARATIONS +# ------------------------------ +# We delimit libtool config variables with single quotes, so when +# we write them to config.status, we have to be sure to quote all +# embedded single quotes properly. In configure, this macro expands +# each variable declared with _LT_DECL (and _LT_TAGDECL) into: +# +# ='`$ECHO "$" | $SED "$delay_single_quote_subst"`' +m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], +[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), + [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAGS +# ---------------- +# Output comment and list of tags supported by the script +m4_defun([_LT_LIBTOOL_TAGS], +[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl +available_tags='_LT_TAGS'dnl +]) + + +# _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) +# ----------------------------------- +# Extract the dictionary values for VARNAME (optionally with TAG) and +# expand to a commented shell variable setting: +# +# # Some comment about what VAR is for. +# visible_name=$lt_internal_name +m4_define([_LT_LIBTOOL_DECLARE], +[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], + [description])))[]dnl +m4_pushdef([_libtool_name], + m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl +m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), + [0], [_libtool_name=[$]$1], + [1], [_libtool_name=$lt_[]$1], + [2], [_libtool_name=$lt_[]$1], + [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl +m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl +]) + + +# _LT_LIBTOOL_CONFIG_VARS +# ----------------------- +# Produce commented declarations of non-tagged libtool config variables +# suitable for insertion in the LIBTOOL CONFIG section of the 'libtool' +# script. Tagged libtool config variables (even for the LIBTOOL CONFIG +# section) are produced by _LT_LIBTOOL_TAG_VARS. +m4_defun([_LT_LIBTOOL_CONFIG_VARS], +[m4_foreach([_lt_var], + m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAG_VARS(TAG) +# ------------------------- +m4_define([_LT_LIBTOOL_TAG_VARS], +[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) + + +# _LT_TAGVAR(VARNAME, [TAGNAME]) +# ------------------------------ +m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) + + +# _LT_CONFIG_COMMANDS +# ------------------- +# Send accumulated output to $CONFIG_STATUS. Thanks to the lists of +# variables for single and double quote escaping we saved from calls +# to _LT_DECL, we can put quote escaped variables declarations +# into 'config.status', and then the shell code to quote escape them in +# for loops in 'config.status'. Finally, any additional code accumulated +# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. +m4_defun([_LT_CONFIG_COMMANDS], +[AC_PROVIDE_IFELSE([LT_OUTPUT], + dnl If the libtool generation code has been placed in $CONFIG_LT, + dnl instead of duplicating it all over again into config.status, + dnl then we will have config.status run $CONFIG_LT later, so it + dnl needs to know what name is stored there: + [AC_CONFIG_COMMANDS([libtool], + [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], + dnl If the libtool generation code is destined for config.status, + dnl expand the accumulated commands and init code now: + [AC_CONFIG_COMMANDS([libtool], + [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) +])#_LT_CONFIG_COMMANDS + + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], +[ + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +_LT_CONFIG_STATUS_DECLARATIONS +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$[]1 +_LTECHO_EOF' +} + +# Quote evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_quote_varnames); do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_dquote_varnames); do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +_LT_OUTPUT_LIBTOOL_INIT +]) + +# _LT_GENERATED_FILE_INIT(FILE, [COMMENT]) +# ------------------------------------ +# Generate a child script FILE with all initialization necessary to +# reuse the environment learned by the parent script, and make the +# file executable. If COMMENT is supplied, it is inserted after the +# '#!' sequence but before initialization text begins. After this +# macro, additional text can be appended to FILE to form the body of +# the child script. The macro ends with non-zero status if the +# file could not be fully written (such as if the disk is full). +m4_ifdef([AS_INIT_GENERATED], +[m4_defun([_LT_GENERATED_FILE_INIT],[AS_INIT_GENERATED($@)])], +[m4_defun([_LT_GENERATED_FILE_INIT], +[m4_require([AS_PREPARE])]dnl +[m4_pushdef([AS_MESSAGE_LOG_FD])]dnl +[lt_write_fail=0 +cat >$1 <<_ASEOF || lt_write_fail=1 +#! $SHELL +# Generated by $as_me. +$2 +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$1 <<\_ASEOF || lt_write_fail=1 +AS_SHELL_SANITIZE +_AS_PREPARE +exec AS_MESSAGE_FD>&1 +_ASEOF +test 0 = "$lt_write_fail" && chmod +x $1[]dnl +m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT + +# LT_OUTPUT +# --------- +# This macro allows early generation of the libtool script (before +# AC_OUTPUT is called), incase it is used in configure for compilation +# tests. +AC_DEFUN([LT_OUTPUT], +[: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +_LT_GENERATED_FILE_INIT(["$CONFIG_LT"], +[# Run this file to recreate a libtool stub with the current configuration.]) + +cat >>"$CONFIG_LT" <<\_LTEOF +lt_cl_silent=false +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +'$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2011 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test 0 != $[#] +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try '$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try '$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +lt_cl_success=: +test yes = "$silent" && + lt_config_lt_args="$lt_config_lt_args --quiet" +exec AS_MESSAGE_LOG_FD>/dev/null +$SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false +exec AS_MESSAGE_LOG_FD>>config.log +$lt_cl_success || AS_EXIT(1) +])# LT_OUTPUT + + +# _LT_CONFIG(TAG) +# --------------- +# If TAG is the built-in tag, create an initial libtool script with a +# default configuration from the untagged config vars. Otherwise add code +# to config.status for appending the configuration named by TAG from the +# matching tagged config vars. +m4_defun([_LT_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_CONFIG_SAVE_COMMANDS([ + m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl + m4_if(_LT_TAG, [C], [ + # See if we are running on zsh, and set the options that allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST + fi + + cfgfile=${ofile}T + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL +# Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. + +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit, 1996 + +_LT_COPYING +_LT_LIBTOOL_TAGS + +# Configured defaults for sys_lib_dlsearch_path munging. +: \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} + +# ### BEGIN LIBTOOL CONFIG +_LT_LIBTOOL_CONFIG_VARS +_LT_LIBTOOL_TAG_VARS +# ### END LIBTOOL CONFIG + +_LT_EOF + + cat <<'_LT_EOF' >> "$cfgfile" + +# ### BEGIN FUNCTIONS SHARED WITH CONFIGURE + +_LT_PREPARE_MUNGE_PATH_LIST +_LT_PREPARE_CC_BASENAME + +# ### END FUNCTIONS SHARED WITH CONFIGURE + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + _LT_PROG_LTMAIN + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +], +[cat <<_LT_EOF >> "$ofile" + +dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded +dnl in a comment (ie after a #). +# ### BEGIN LIBTOOL TAG CONFIG: $1 +_LT_LIBTOOL_TAG_VARS(_LT_TAG) +# ### END LIBTOOL TAG CONFIG: $1 +_LT_EOF +])dnl /m4_if +], +[m4_if([$1], [], [ + PACKAGE='$PACKAGE' + VERSION='$VERSION' + RM='$RM' + ofile='$ofile'], []) +])dnl /_LT_CONFIG_SAVE_COMMANDS +])# _LT_CONFIG + + +# LT_SUPPORTED_TAG(TAG) +# --------------------- +# Trace this macro to discover what tags are supported by the libtool +# --tag option, using: +# autoconf --trace 'LT_SUPPORTED_TAG:$1' +AC_DEFUN([LT_SUPPORTED_TAG], []) + + +# C support is built-in for now +m4_define([_LT_LANG_C_enabled], []) +m4_define([_LT_TAGS], []) + + +# LT_LANG(LANG) +# ------------- +# Enable libtool support for the given language if not already enabled. +AC_DEFUN([LT_LANG], +[AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Go], [_LT_LANG(GO)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +])# LT_LANG + + +# _LT_LANG(LANGNAME) +# ------------------ +m4_defun([_LT_LANG], +[m4_ifdef([_LT_LANG_]$1[_enabled], [], + [LT_SUPPORTED_TAG([$1])dnl + m4_append([_LT_TAGS], [$1 ])dnl + m4_define([_LT_LANG_]$1[_enabled], [])dnl + _LT_LANG_$1_CONFIG($1)])dnl +])# _LT_LANG + + +m4_ifndef([AC_PROG_GO], [ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_GO. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +m4_defun([AC_PROG_GO], +[AC_LANG_PUSH(Go)dnl +AC_ARG_VAR([GOC], [Go compiler command])dnl +AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl +_AC_ARG_VAR_LDFLAGS()dnl +AC_CHECK_TOOL(GOC, gccgo) +if test -z "$GOC"; then + if test -n "$ac_tool_prefix"; then + AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [${ac_tool_prefix}gccgo]) + fi +fi +if test -z "$GOC"; then + AC_CHECK_PROG(GOC, gccgo, gccgo, false) +fi +])#m4_defun +])#m4_ifndef + + +# _LT_LANG_DEFAULT_CONFIG +# ----------------------- +m4_defun([_LT_LANG_DEFAULT_CONFIG], +[AC_PROVIDE_IFELSE([AC_PROG_CXX], + [LT_LANG(CXX)], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) + +AC_PROVIDE_IFELSE([AC_PROG_F77], + [LT_LANG(F77)], + [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [LT_LANG(FC)], + [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) + +dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal +dnl pulling things in needlessly. +AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([LT_PROG_GCJ], + [LT_LANG(GCJ)], + [m4_ifdef([AC_PROG_GCJ], + [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([A][M_PROG_GCJ], + [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([LT_PROG_GCJ], + [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) + +AC_PROVIDE_IFELSE([AC_PROG_GO], + [LT_LANG(GO)], + [m4_define([AC_PROG_GO], defn([AC_PROG_GO])[LT_LANG(GO)])]) + +AC_PROVIDE_IFELSE([LT_PROG_RC], + [LT_LANG(RC)], + [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) +])# _LT_LANG_DEFAULT_CONFIG + +# Obsolete macros: +AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_CXX], []) +dnl AC_DEFUN([AC_LIBTOOL_F77], []) +dnl AC_DEFUN([AC_LIBTOOL_FC], []) +dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) +dnl AC_DEFUN([AC_LIBTOOL_RC], []) + + +# _LT_TAG_COMPILER +# ---------------- +m4_defun([_LT_TAG_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl +_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl +_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl +_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_TAG_COMPILER + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +m4_defun([_LT_COMPILER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +m4_defun([_LT_LINKER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* +])# _LT_LINKER_BOILERPLATE + +# _LT_REQUIRED_DARWIN_CHECKS +# ------------------------- +m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ + case $host_os in + rhapsody* | darwin*) + AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) + AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) + AC_CHECK_TOOL([LIPO], [lipo], [:]) + AC_CHECK_TOOL([OTOOL], [otool], [:]) + AC_CHECK_TOOL([OTOOL64], [otool64], [:]) + _LT_DECL([], [DSYMUTIL], [1], + [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) + _LT_DECL([], [NMEDIT], [1], + [Tool to change global to local symbols on Mac OS X]) + _LT_DECL([], [LIPO], [1], + [Tool to manipulate fat objects and archives on Mac OS X]) + _LT_DECL([], [OTOOL], [1], + [ldd/readelf like tool for Mach-O binaries on Mac OS X]) + _LT_DECL([], [OTOOL64], [1], + [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) + + AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], + [lt_cv_apple_cc_single_mod=no + if test -z "$LT_MULTI_MODULE"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + # If there is a non-empty error log, and "single_module" + # appears in it, assume the flag caused a linker warning + if test -s conftest.err && $GREP single_module conftest.err; then + cat conftest.err >&AS_MESSAGE_LOG_FD + # Otherwise, if the output was created with a 0 exit code from + # the compiler, it worked. + elif test -f libconftest.dylib && test 0 = "$_lt_result"; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi]) + + AC_CACHE_CHECK([for -exported_symbols_list linker flag], + [lt_cv_ld_exported_symbols_list], + [lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [lt_cv_ld_exported_symbols_list=yes], + [lt_cv_ld_exported_symbols_list=no]) + LDFLAGS=$save_LDFLAGS + ]) + + AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load], + [lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD + echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD + $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -s conftest.err && $GREP force_load conftest.err; then + cat conftest.err >&AS_MESSAGE_LOG_FD + elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -f conftest.err libconftest.a conftest conftest.c + rm -rf conftest.dSYM + ]) + case $host_os in + rhapsody* | darwin1.[[012]]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[[012]][[,.]]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test yes = "$lt_cv_apple_cc_single_mod"; then + _lt_dar_single_mod='$single_module' + fi + if test yes = "$lt_cv_ld_exported_symbols_list"; then + _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' + fi + if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac +]) + + +# _LT_DARWIN_LINKER_FEATURES([TAG]) +# --------------------------------- +# Checks for linker and compiler features on darwin +m4_defun([_LT_DARWIN_LINKER_FEATURES], +[ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + if test yes = "$lt_cv_ld_force_load"; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + m4_case([$1], [F77], [_LT_TAGVAR(compiler_needs_object, $1)=yes], + [FC], [_LT_TAGVAR(compiler_needs_object, $1)=yes]) + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + m4_if([$1], [CXX], +[ if test yes != "$lt_cv_apple_cc_single_mod"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + fi +],[]) + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi +]) + +# _LT_SYS_MODULE_PATH_AIX([TAGNAME]) +# ---------------------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +# Store the results from the different compilers for each TAGNAME. +# Allow to override them for all tags through lt_cv_aix_libpath. +m4_defun([_LT_SYS_MODULE_PATH_AIX], +[m4_require([_LT_DECL_SED])dnl +if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + AC_CACHE_VAL([_LT_TAGVAR([lt_cv_aix_libpath_], [$1])], + [AC_LINK_IFELSE([AC_LANG_PROGRAM],[ + lt_aix_libpath_sed='[ + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }]' + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi],[]) + if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=/usr/lib:/lib + fi + ]) + aix_libpath=$_LT_TAGVAR([lt_cv_aix_libpath_], [$1]) +fi +])# _LT_SYS_MODULE_PATH_AIX + + +# _LT_SHELL_INIT(ARG) +# ------------------- +m4_define([_LT_SHELL_INIT], +[m4_divert_text([M4SH-INIT], [$1 +])])# _LT_SHELL_INIT + + + +# _LT_PROG_ECHO_BACKSLASH +# ----------------------- +# Find how we can fake an echo command that does not interpret backslash. +# In particular, with Autoconf 2.60 or later we add some code to the start +# of the generated configure script that will find a shell with a builtin +# printf (that we can use as an echo command). +m4_defun([_LT_PROG_ECHO_BACKSLASH], +[ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + +AC_MSG_CHECKING([how to print strings]) +# Test print first, because it will be a builtin if present. +if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ + test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='print -r --' +elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='printf %s\n' +else + # Use this function as a fallback that always works. + func_fallback_echo () + { + eval 'cat <<_LTECHO_EOF +$[]1 +_LTECHO_EOF' + } + ECHO='func_fallback_echo' +fi + +# func_echo_all arg... +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "$*" +} + +case $ECHO in + printf*) AC_MSG_RESULT([printf]) ;; + print*) AC_MSG_RESULT([print -r]) ;; + *) AC_MSG_RESULT([cat]) ;; +esac + +m4_ifdef([_AS_DETECT_SUGGESTED], +[_AS_DETECT_SUGGESTED([ + test -n "${ZSH_VERSION+set}${BASH_VERSION+set}" || ( + ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' + ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO + ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + PATH=/empty FPATH=/empty; export PATH FPATH + test "X`printf %s $ECHO`" = "X$ECHO" \ + || test "X`print -r -- $ECHO`" = "X$ECHO" )])]) + +_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) +_LT_DECL([], [ECHO], [1], [An echo program that protects backslashes]) +])# _LT_PROG_ECHO_BACKSLASH + + +# _LT_WITH_SYSROOT +# ---------------- +AC_DEFUN([_LT_WITH_SYSROOT], +[AC_MSG_CHECKING([for sysroot]) +AC_ARG_WITH([sysroot], +[AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@], + [Search for dependent libraries within DIR (or the compiler's sysroot + if not specified).])], +[], [with_sysroot=no]) + +dnl lt_sysroot will always be passed unquoted. We quote it here +dnl in case the user passed a directory name. +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + AC_MSG_RESULT([$with_sysroot]) + AC_MSG_ERROR([The sysroot must be an absolute path.]) + ;; +esac + + AC_MSG_RESULT([${lt_sysroot:-no}]) +_LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl +[dependent libraries, and where our libraries should be installed.])]) + +# _LT_ENABLE_LOCK +# --------------- +m4_defun([_LT_ENABLE_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AS_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test no = "$enable_libtool_lock" || enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE=32 + ;; + *ELF-64*) + HPUX_IA64_MODE=64 + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test yes = "$lt_cv_prog_gnu_ld"; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +mips64*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + emul=elf + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + emul="${emul}32" + ;; + *64-bit*) + emul="${emul}64" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *MSB*) + emul="${emul}btsmip" + ;; + *LSB*) + emul="${emul}ltsmip" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *N32*) + emul="${emul}n32" + ;; + esac + LD="${LD-ld} -m $emul" + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. Note that the listed cases only cover the + # situations where additional linker options are needed (such as when + # doing 32-bit compilation for a host where ld defaults to 64-bit, or + # vice versa); the common cases where no linker options are needed do + # not appear in the list. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac + ;; + powerpc64le-*linux*) + LD="${LD-ld} -m elf32lppclinux" + ;; + powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + powerpcle-*linux*) + LD="${LD-ld} -m elf64lppc" + ;; + powerpc-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test yes != "$lt_cv_cc_needs_belf"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS=$SAVE_CFLAGS + fi + ;; +*-*solaris*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) + case $host in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; + sparc*-*-solaris*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + # GNU ld 2.21 introduced _sol2 emulations. Use them if available. + if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then + LD=${LD-ld}_sol2 + fi + ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks=$enable_libtool_lock +])# _LT_ENABLE_LOCK + + +# _LT_PROG_AR +# ----------- +m4_defun([_LT_PROG_AR], +[AC_CHECK_TOOLS(AR, [ar], false) +: ${AR=ar} +: ${AR_FLAGS=cru} +_LT_DECL([], [AR], [1], [The archiver]) +_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) + +AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file], + [lt_cv_ar_at_file=no + AC_COMPILE_IFELSE([AC_LANG_PROGRAM], + [echo conftest.$ac_objext > conftest.lst + lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&AS_MESSAGE_LOG_FD' + AC_TRY_EVAL([lt_ar_try]) + if test 0 -eq "$ac_status"; then + # Ensure the archiver fails upon bogus file names. + rm -f conftest.$ac_objext libconftest.a + AC_TRY_EVAL([lt_ar_try]) + if test 0 -ne "$ac_status"; then + lt_cv_ar_at_file=@ + fi + fi + rm -f conftest.* libconftest.a + ]) + ]) + +if test no = "$lt_cv_ar_at_file"; then + archiver_list_spec= +else + archiver_list_spec=$lt_cv_ar_at_file +fi +_LT_DECL([], [archiver_list_spec], [1], + [How to feed a file listing to the archiver]) +])# _LT_PROG_AR + + +# _LT_CMD_OLD_ARCHIVE +# ------------------- +m4_defun([_LT_CMD_OLD_ARCHIVE], +[_LT_PROG_AR + +AC_CHECK_TOOL(STRIP, strip, :) +test -z "$STRIP" && STRIP=: +_LT_DECL([], [STRIP], [1], [A symbol stripping program]) + +AC_CHECK_TOOL(RANLIB, ranlib, :) +test -z "$RANLIB" && RANLIB=: +_LT_DECL([], [RANLIB], [1], + [Commands used to install an old-style archive]) + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" +fi + +case $host_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) + lock_old_archive_extraction=no ;; +esac +_LT_DECL([], [old_postinstall_cmds], [2]) +_LT_DECL([], [old_postuninstall_cmds], [2]) +_LT_TAGDECL([], [old_archive_cmds], [2], + [Commands used to build an old-style archive]) +_LT_DECL([], [lock_old_archive_extraction], [0], + [Whether to use a lock for old archive extraction]) +])# _LT_CMD_OLD_ARCHIVE + + +# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([_LT_COMPILER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test yes = "[$]$2"; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +])# _LT_COMPILER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) + + +# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------- +# Check whether the given linker option works +AC_DEFUN([_LT_LINKER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS +]) + +if test yes = "[$]$2"; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +])# _LT_LINKER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) + + +# LT_CMD_MAX_LEN +#--------------- +AC_DEFUN([LT_CMD_MAX_LEN], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n "$lt_cv_sys_max_cmd_len"; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +])# LT_CMD_MAX_LEN + +# Old name: +AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) + + +# _LT_HEADER_DLFCN +# ---------------- +m4_defun([_LT_HEADER_DLFCN], +[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl +])# _LT_HEADER_DLFCN + + +# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ---------------------------------------------------------------- +m4_defun([_LT_TRY_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test yes = "$cross_compiling"; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +[#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_TRY_DLOPEN_SELF + + +# LT_SYS_DLOPEN_SELF +# ------------------ +AC_DEFUN([LT_SYS_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl],[ + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen=shl_load], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen=dlopen], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +])# LT_SYS_DLOPEN_SELF + +# Old name: +AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) + + +# _LT_COMPILER_C_O([TAGNAME]) +# --------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler. +# This macro does not hard code the compiler like AC_PROG_CC_C_O. +m4_defun([_LT_COMPILER_C_O], +[m4_require([_LT_DECL_SED])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* +]) +_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], + [Does compiler simultaneously support -c and -o options?]) +])# _LT_COMPILER_C_O + + +# _LT_COMPILER_FILE_LOCKS([TAGNAME]) +# ---------------------------------- +# Check to see if we can do hard links to lock some files if needed +m4_defun([_LT_COMPILER_FILE_LOCKS], +[m4_require([_LT_ENABLE_LOCK])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_COMPILER_C_O([$1]) + +hard_links=nottested +if test no = "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test no = "$hard_links"; then + AC_MSG_WARN(['$CC' does not support '-c -o', so 'make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) +])# _LT_COMPILER_FILE_LOCKS + + +# _LT_CHECK_OBJDIR +# ---------------- +m4_defun([_LT_CHECK_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +_LT_DECL([], [objdir], [0], + [The name of the directory that contains temporary libtool files])dnl +m4_pattern_allow([LT_OBJDIR])dnl +AC_DEFINE_UNQUOTED([LT_OBJDIR], "$lt_cv_objdir/", + [Define to the sub-directory where libtool stores uninstalled libraries.]) +])# _LT_CHECK_OBJDIR + + +# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) +# -------------------------------------- +# Check hardcoding attributes. +m4_defun([_LT_LINKER_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || + test -n "$_LT_TAGVAR(runpath_var, $1)" || + test yes = "$_LT_TAGVAR(hardcode_automatic, $1)"; then + + # We can hardcode non-existent directories. + if test no != "$_LT_TAGVAR(hardcode_direct, $1)" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" && + test no != "$_LT_TAGVAR(hardcode_minus_L, $1)"; then + # Linking always hardcodes the temporary library directory. + _LT_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) + +if test relink = "$_LT_TAGVAR(hardcode_action, $1)" || + test yes = "$_LT_TAGVAR(inherit_rpath, $1)"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi +_LT_TAGDECL([], [hardcode_action], [0], + [How to hardcode a shared library path into an executable]) +])# _LT_LINKER_HARDCODE_LIBPATH + + +# _LT_CMD_STRIPLIB +# ---------------- +m4_defun([_LT_CMD_STRIPLIB], +[m4_require([_LT_DECL_EGREP]) +striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +_LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) +_LT_DECL([], [striplib], [1]) +])# _LT_CMD_STRIPLIB + + +# _LT_PREPARE_MUNGE_PATH_LIST +# --------------------------- +# Make sure func_munge_path_list() is defined correctly. +m4_defun([_LT_PREPARE_MUNGE_PATH_LIST], +[[# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x@S|@2 in + x) + ;; + *:) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" + ;; + x:*) + eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" + ;; + *) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + esac +} +]])# _LT_PREPARE_PATH_LIST + + +# _LT_SYS_DYNAMIC_LINKER([TAG]) +# ----------------------------- +# PORTME Fill in your ld.so characteristics +m4_defun([_LT_SYS_DYNAMIC_LINKER], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_OBJDUMP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_PREPARE_MUNGE_PATH_LIST])dnl +AC_MSG_CHECKING([dynamic linker characteristics]) +m4_if([$1], + [], [ +if test yes = "$GCC"; then + case $host_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac + case $host_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([[A-Za-z]]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` + case $lt_search_path_spec in + *\;*) + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` + ;; + *) + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` + ;; + esac + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary... + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + # ...but if some path component already ends with the multilib dir we assume + # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). + case "$lt_multi_os_dir; $lt_search_path_spec " in + "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) + lt_multi_os_dir= + ;; + esac + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" + elif test -n "$lt_multi_os_dir"; then + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' +BEGIN {RS = " "; FS = "/|\n";} { + lt_foo = ""; + lt_count = 0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo = "/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[[lt_foo]]++; } + if (lt_freq[[lt_foo]] == 1) { print lt_foo; } +}'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. + case $host_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([[A-Za-z]]:\)|\1|g'` ;; + esac + sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +AC_ARG_VAR([LT_SYS_LIBRARY_PATH], +[User-defined run-time library search path.]) + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[[4-9]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a[(]lib.so.V[)]' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)]" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)], lib.a[(]lib.so.V[)]" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a[(]lib.so.V[)], lib.so.V[(]$shared_archive_member_spec.o[)]" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[23]].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[[3-9]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath], + [lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [lt_cv_shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + ]) + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + +_LT_DECL([], [variables_saved_for_relink], [1], + [Variables whose values should be saved in libtool wrapper scripts and + restored at link time]) +_LT_DECL([], [need_lib_prefix], [0], + [Do we need the "lib" prefix for modules?]) +_LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) +_LT_DECL([], [version_type], [0], [Library versioning type]) +_LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) +_LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) +_LT_DECL([], [shlibpath_overrides_runpath], [0], + [Is shlibpath searched before the hard-coded library search path?]) +_LT_DECL([], [libname_spec], [1], [Format of library name prefix]) +_LT_DECL([], [library_names_spec], [1], + [[List of archive names. First name is the real one, the rest are links. + The last name is the one that the linker finds with -lNAME]]) +_LT_DECL([], [soname_spec], [1], + [[The coded name of the library, if different from the real name]]) +_LT_DECL([], [install_override_mode], [1], + [Permission mode override for installation of shared libraries]) +_LT_DECL([], [postinstall_cmds], [2], + [Command to use after installation of a shared archive]) +_LT_DECL([], [postuninstall_cmds], [2], + [Command to use after uninstallation of a shared archive]) +_LT_DECL([], [finish_cmds], [2], + [Commands used to finish a libtool library installation in a directory]) +_LT_DECL([], [finish_eval], [1], + [[As "finish_cmds", except a single script fragment to be evaled but + not shown]]) +_LT_DECL([], [hardcode_into_libs], [0], + [Whether we should hardcode library paths into libraries]) +_LT_DECL([], [sys_lib_search_path_spec], [2], + [Compile-time system search path for libraries]) +_LT_DECL([sys_lib_dlsearch_path_spec], [configure_time_dlsearch_path], [2], + [Detected run-time system search path for libraries]) +_LT_DECL([], [configure_time_lt_sys_library_path], [2], + [Explicit LT_SYS_LIBRARY_PATH set during ./configure time]) +])# _LT_SYS_DYNAMIC_LINKER + + +# _LT_PATH_TOOL_PREFIX(TOOL) +# -------------------------- +# find a file program that can recognize shared library +AC_DEFUN([_LT_PATH_TOOL_PREFIX], +[m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$1"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac]) +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +])# _LT_PATH_TOOL_PREFIX + +# Old name: +AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) + + +# _LT_PATH_MAGIC +# -------------- +# find a file program that can recognize a shared library +m4_defun([_LT_PATH_MAGIC], +[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# _LT_PATH_MAGIC + + +# LT_PATH_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([LT_PATH_LD], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PROG_ECHO_BACKSLASH])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test no = "$withval" || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 conftest.i +cat conftest.i conftest.i >conftest2.i +: ${lt_DD:=$DD} +AC_PATH_PROGS_FEATURE_CHECK([lt_DD], [dd], +[if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: +fi]) +rm -f conftest.i conftest2.i conftest.out]) +])# _LT_PATH_DD + + +# _LT_CMD_TRUNCATE +# ---------------- +# find command to truncate a binary pipe +m4_defun([_LT_CMD_TRUNCATE], +[m4_require([_LT_PATH_DD]) +AC_CACHE_CHECK([how to truncate binary pipes], [lt_cv_truncate_bin], +[printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +lt_cv_truncate_bin= +if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" +fi +rm -f conftest.i conftest2.i conftest.out +test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q"]) +_LT_DECL([lt_truncate_bin], [lt_cv_truncate_bin], [1], + [Command to truncate a binary pipe]) +])# _LT_CMD_TRUNCATE + + +# _LT_CHECK_MAGIC_METHOD +# ---------------------- +# how to check for library dependencies +# -- PORTME fill in with the dynamic library characteristics +m4_defun([_LT_CHECK_MAGIC_METHOD], +[m4_require([_LT_DECL_EGREP]) +m4_require([_LT_DECL_OBJDUMP]) +AC_CACHE_CHECK([how to recognize dependent libraries], +lt_cv_deplibs_check_method, +[lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# 'unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# that responds to the $file_magic_cmd with a given extended regex. +# If you have 'file' or equivalent on your system and you're not sure +# whether 'pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[[4-9]]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[[45]]*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc*) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +haiku*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]]\.[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[[3-9]]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd* | bitrig*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +os2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) + +file_magic_glob= +want_nocaseglob=no +if test "$build" = "$host"; then + case $host_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes + else + file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[[\1]]\/[[\1]]\/g;/g"` + fi + ;; + esac +fi + +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + +_LT_DECL([], [deplibs_check_method], [1], + [Method to check whether dependent libraries are shared objects]) +_LT_DECL([], [file_magic_cmd], [1], + [Command to use when deplibs_check_method = "file_magic"]) +_LT_DECL([], [file_magic_glob], [1], + [How to find potential files when deplibs_check_method = "file_magic"]) +_LT_DECL([], [want_nocaseglob], [1], + [Find potential files using nocaseglob when deplibs_check_method = "file_magic"]) +])# _LT_CHECK_MAGIC_METHOD + + +# LT_PATH_NM +# ---------- +# find the pathname to a BSD- or MS-compatible name lister +AC_DEFUN([LT_PATH_NM], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM=$NM +else + lt_nm_to_check=${ac_tool_prefix}nm + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + tmp_nm=$ac_dir/$lt_tmp_nm + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the 'sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty + case $build_os in + mingw*) lt_bad_file=conftest.nm/nofile ;; + *) lt_bad_file=/dev/null ;; + esac + case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi]) +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :) + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + AC_SUBST([DUMPBIN]) + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +])# LT_PATH_NM + +# Old names: +AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) +AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_PROG_NM], []) +dnl AC_DEFUN([AC_PROG_NM], []) + +# _LT_CHECK_SHAREDLIB_FROM_LINKLIB +# -------------------------------- +# how to determine the name of the shared library +# associated with a specific link library. +# -- PORTME fill in with the dynamic library characteristics +m4_defun([_LT_CHECK_SHAREDLIB_FROM_LINKLIB], +[m4_require([_LT_DECL_EGREP]) +m4_require([_LT_DECL_OBJDUMP]) +m4_require([_LT_DECL_DLLTOOL]) +AC_CACHE_CHECK([how to associate runtime and link libraries], +lt_cv_sharedlib_from_linklib_cmd, +[lt_cv_sharedlib_from_linklib_cmd='unknown' + +case $host_os in +cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL + case `$DLLTOOL --help 2>&1` in + *--identify-strict*) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib + ;; + *) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback + ;; + esac + ;; +*) + # fallback: assume linklib IS sharedlib + lt_cv_sharedlib_from_linklib_cmd=$ECHO + ;; +esac +]) +sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd +test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO + +_LT_DECL([], [sharedlib_from_linklib_cmd], [1], + [Command to associate shared and link libraries]) +])# _LT_CHECK_SHAREDLIB_FROM_LINKLIB + + +# _LT_PATH_MANIFEST_TOOL +# ---------------------- +# locate the manifest tool +m4_defun([_LT_PATH_MANIFEST_TOOL], +[AC_CHECK_TOOL(MANIFEST_TOOL, mt, :) +test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt +AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_mainfest_tool], + [lt_cv_path_mainfest_tool=no + echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD + $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out + cat conftest.err >&AS_MESSAGE_LOG_FD + if $GREP 'Manifest Tool' conftest.out > /dev/null; then + lt_cv_path_mainfest_tool=yes + fi + rm -f conftest*]) +if test yes != "$lt_cv_path_mainfest_tool"; then + MANIFEST_TOOL=: +fi +_LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl +])# _LT_PATH_MANIFEST_TOOL + + +# _LT_DLL_DEF_P([FILE]) +# --------------------- +# True iff FILE is a Windows DLL '.def' file. +# Keep in sync with func_dll_def_p in the libtool script +AC_DEFUN([_LT_DLL_DEF_P], +[dnl + test DEF = "`$SED -n dnl + -e '\''s/^[[ ]]*//'\'' dnl Strip leading whitespace + -e '\''/^\(;.*\)*$/d'\'' dnl Delete empty lines and comments + -e '\''s/^\(EXPORTS\|LIBRARY\)\([[ ]].*\)*$/DEF/p'\'' dnl + -e q dnl Only consider the first "real" line + $1`" dnl +])# _LT_DLL_DEF_P + + +# LT_LIB_M +# -------- +# check for math library +AC_DEFUN([LT_LIB_M], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM=-lmw) + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM=-lm) + ;; +esac +AC_SUBST([LIBM]) +])# LT_LIB_M + +# Old name: +AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_CHECK_LIBM], []) + + +# _LT_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------- +m4_defun([_LT_COMPILER_NO_RTTI], +[m4_require([_LT_TAG_COMPILER])dnl + +_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test yes = "$GCC"; then + case $cc_basename in + nvcc*) + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -Xcompiler -fno-builtin' ;; + *) + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' ;; + esac + + _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], + [Compiler flag to turn off builtin functions]) +])# _LT_COMPILER_NO_RTTI + + +# _LT_CMD_GLOBAL_SYMBOLS +# ---------------------- +m4_defun([_LT_CMD_GLOBAL_SYMBOLS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([LT_PATH_NM])dnl +AC_REQUIRE([LT_PATH_LD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_TAG_COMPILER])dnl + +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) + if test ia64 = "$host_cpu"; then + symcode='[[ABCDEGRST]]' + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Gets list of data symbols to import. + lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + # Adjust the below global symbol transforms to fixup imported variables. + lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" + lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" + lt_c_name_lib_hook="\ + -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ + -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" +else + # Disable hooks by default. + lt_cv_sys_global_symbol_to_import= + lt_cdecl_hook= + lt_c_name_hook= + lt_c_name_lib_hook= +fi + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +$lt_cdecl_hook\ +" -e 's/^T .* \(.*\)$/extern int \1();/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +$lt_c_name_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" + +# Transform an extracted symbol line into symbol name with lib prefix and +# symbol address. +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +$lt_c_name_lib_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function, + # D for any global variable and I for any imported variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK ['"\ +" {last_section=section; section=\$ 3};"\ +" /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ +" /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ +" /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ +" {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ +" s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx]" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + nlist=conftest.nm + if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT@&t@_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT@&t@_DLSYM_CONST +#else +# define LT@&t@_DLSYM_CONST const +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +LT@&t@_DLSYM_CONST struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[[]] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_globsym_save_LIBS=$LIBS + lt_globsym_save_CFLAGS=$CFLAGS + LIBS=conftstm.$ac_objext + CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest$ac_exeext; then + pipe_works=yes + fi + LIBS=$lt_globsym_save_LIBS + CFLAGS=$lt_globsym_save_CFLAGS + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test yes = "$pipe_works"; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi + +# Response file support. +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + nm_file_list_spec='@' +elif $NM --help 2>/dev/null | grep '[[@]]FILE' >/dev/null; then + nm_file_list_spec='@' +fi + +_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], + [Take the output of nm and produce a listing of raw symbols and C names]) +_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], + [Transform the output of nm in a proper C declaration]) +_LT_DECL([global_symbol_to_import], [lt_cv_sys_global_symbol_to_import], [1], + [Transform the output of nm into a list of symbols to manually relocate]) +_LT_DECL([global_symbol_to_c_name_address], + [lt_cv_sys_global_symbol_to_c_name_address], [1], + [Transform the output of nm in a C name address pair]) +_LT_DECL([global_symbol_to_c_name_address_lib_prefix], + [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], + [Transform the output of nm in a C name address pair when lib prefix is needed]) +_LT_DECL([nm_interface], [lt_cv_nm_interface], [1], + [The name lister interface]) +_LT_DECL([], [nm_file_list_spec], [1], + [Specify filename containing input files for $NM]) +]) # _LT_CMD_GLOBAL_SYMBOLS + + +# _LT_COMPILER_PIC([TAGNAME]) +# --------------------------- +m4_defun([_LT_COMPILER_PIC], +[m4_require([_LT_TAG_COMPILER])dnl +_LT_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_TAGVAR(lt_prog_compiler_static, $1)= + +m4_if([$1], [CXX], [ + # C++ specific cases for pic, static, wl, etc. + if test yes = "$GXX"; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + _LT_TAGVAR(lt_prog_compiler_static, $1)= + ;; + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix[[4-9]]*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + if test ia64 != "$host_cpu"; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64, which still supported -KPIC. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xlc* | xlC* | bgxl[[cC]]* | mpixl[[cC]]*) + # IBM XL 8.0, 9.0 on PPC and BlueGene + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test yes = "$GCC"; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + _LT_TAGVAR(lt_prog_compiler_static, $1)= + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + + case $cc_basename in + nvcc*) # Cuda Compiler Driver 2.2 + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Xlinker ' + if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)="-Xcompiler $_LT_TAGVAR(lt_prog_compiler_pic, $1)" + fi + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + case $cc_basename in + nagfor*) + # NAG Fortran compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + + hpux9* | hpux10* | hpux11*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + # old Intel for x86_64, which still supported -KPIC. + ecc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' + _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' + ;; + nagfor*) + # NAG Fortran compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xl* | bgxl* | bgf* | mpixl*) + # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='' + ;; + *Sun\ F* | *Sun*Fortran*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + *Sun\ C*) + # Sun C 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + *Intel*\ [[CF]]*Compiler*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + *Portland\ Group*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + esac + ;; + + newsos6) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + rdos*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" + ;; +esac + +AC_CACHE_CHECK([for $compiler option to produce PIC], + [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) +_LT_TAGVAR(lt_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_cv_prog_compiler_pic, $1) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], + [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], + [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], + [Additional compiler flags for building library objects]) + +_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], + [How to pass a linker flag through the compiler]) +# +# Check to make sure the static flag actually works. +# +wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" +_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) +_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], + [Compiler flag to prevent dynamic linking]) +])# _LT_COMPILER_PIC + + +# _LT_LINKER_SHLIBS([TAGNAME]) +# ---------------------------- +# See if the linker supports building shared libraries. +m4_defun([_LT_LINKER_SHLIBS], +[AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +m4_require([_LT_PATH_MANIFEST_TOOL])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +m4_if([$1], [CXX], [ + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + case $host_os in + aix[[4-9]]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_TAGVAR(export_symbols_cmds, $1)=$ltdll_cmds + ;; + cygwin* | mingw* | cegcc*) + case $cc_basename in + cl*) + _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] + ;; + esac + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac +], [ + runpath_var= + _LT_TAGVAR(allow_undefined_flag, $1)= + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(archive_cmds, $1)= + _LT_TAGVAR(archive_expsym_cmds, $1)= + _LT_TAGVAR(compiler_needs_object, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(hardcode_automatic, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_separator, $1)= + _LT_TAGVAR(hardcode_minus_L, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(inherit_rpath, $1)=no + _LT_TAGVAR(link_all_deplibs, $1)=unknown + _LT_TAGVAR(module_cmds, $1)= + _LT_TAGVAR(module_expsym_cmds, $1)= + _LT_TAGVAR(old_archive_from_new_cmds, $1)= + _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_TAGVAR(thread_safe_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ' (' and ')$', so one must not match beginning or + # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', + # as well as any symbol that contains 'd'. + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. +dnl Note also adjust exclude_expsyms for C++ above. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test yes != "$GCC"; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd* | bitrig*) + with_gnu_ld=no + ;; + esac + + _LT_TAGVAR(ld_shlibs, $1)=yes + + # On some targets, GNU ld is compatible enough with the native linker + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then + case $host_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld + # block says, versions before 2.19.5* couldn't really create working + # shared libraries, regardless of the interface used. + case `$LD -v 2>&1` in + *\ \(GNU\ Binutils\)\ 2.19.5*) ;; + *\ \(GNU\ Binutils\)\ 2.[[2-9]]*) ;; + *\ \(GNU\ Binutils\)\ [[3-9]]*) ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + fi + + if test yes = "$lt_use_gnu_ld_interface"; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='$wl' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v | $SED -e 's/([^)]\+)\s\+//' 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[[3-9]]*) + # On AIX/PPC, the GNU linker is very broken + if test ia64 != "$host_cpu"; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.19, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to install binutils +*** 2.20 or above, or modify your PATH so that a non-GNU linker is found. +*** You will then need to restart the configuration process. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + haiku*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test linux-dietlibc = "$host_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test no = "$tmp_diet" + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group f77 and f90 compilers + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + _LT_TAGVAR(whole_archive_flag_spec, $1)= + tmp_sharedflag='--shared' ;; + nagfor*) # NAGFOR 5.3 + tmp_sharedflag='-Wl,-shared' ;; + xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + nvcc*) # Cuda Compiler Driver 2.2 + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + tcc*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-rdynamic' + ;; + xlf* | bgf* | bgxlf* | mpixlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test no = "$_LT_TAGVAR(ld_shlibs, $1)"; then + runpath_var= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix[[4-9]]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes + break + fi + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # traditional, no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + ;; + esac + + if test yes = "$GCC"; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag="$shared_flag "'$wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + bsdi[[45]]*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + case $cc_basename in + cl*) + # Native MSVC + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' + # Don't use ranlib + _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' + _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # Assume MSVC wrapper + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + esac + ;; + + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2.*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + ;; + + hpux10*) + if test yes,no = "$GCC,$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + m4_if($1, [], [ + # Older versions of the 11.00 compiler do not understand -b yet + # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) + _LT_LINKER_OPTION([if $CC understands -b], + _LT_TAGVAR(lt_cv_prog_compiler__b, $1), [-b], + [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags'], + [_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'])], + [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags']) + ;; + esac + fi + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. + AC_CACHE_CHECK([whether the $host_os linker accepts -exported_symbol], + [lt_cv_irix_exported_symbol], + [save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" + AC_LINK_IFELSE( + [AC_LANG_SOURCE( + [AC_LANG_CASE([C], [[int foo (void) { return 0; }]], + [C++], [[int foo (void) { return 0; }]], + [Fortran 77], [[ + subroutine foo + end]], + [Fortran], [[ + subroutine foo + end]])])], + [lt_cv_irix_exported_symbol=yes], + [lt_cv_irix_exported_symbol=no]) + LDFLAGS=$save_LDFLAGS]) + if test yes = "$lt_cv_irix_exported_symbol"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' + fi + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + linux*) + case $cc_basename in + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + _LT_TAGVAR(ld_shlibs, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *nto* | *qnx*) + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + fi + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + osf3*) + if test yes = "$GCC"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test yes = "$GCC"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' + if test yes = "$GCC"; then + wlarc='$wl' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + _LT_TAGVAR(archive_cmds, $1)='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='$wl' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. GCC discards it without '$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test yes = "$GCC"; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + fi + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test sequent = "$host_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + if test sni = "$host_vendor"; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Blargedynsym' + ;; + esac + fi + fi +]) +AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) +test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no + +_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld + +_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl +_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl +_LT_DECL([], [extract_expsyms_cmds], [2], + [The commands to extract the exported symbol list from a shared archive]) + +# +# Do we need to explicitly link libc? +# +case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $_LT_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_CACHE_CHECK([whether -lc should be explicitly linked in], + [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1), + [$RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + ]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1) + ;; + esac + fi + ;; +esac + +_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], + [Whether or not to add -lc for building shared libraries]) +_LT_TAGDECL([allow_libtool_libs_with_static_runtimes], + [enable_shared_with_static_runtimes], [0], + [Whether or not to disallow shared libs when runtime libs are static]) +_LT_TAGDECL([], [export_dynamic_flag_spec], [1], + [Compiler flag to allow reflexive dlopens]) +_LT_TAGDECL([], [whole_archive_flag_spec], [1], + [Compiler flag to generate shared objects directly from archives]) +_LT_TAGDECL([], [compiler_needs_object], [1], + [Whether the compiler copes with passing no objects directly]) +_LT_TAGDECL([], [old_archive_from_new_cmds], [2], + [Create an old-style archive from a shared archive]) +_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], + [Create a temporary old-style archive to link instead of a shared archive]) +_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) +_LT_TAGDECL([], [archive_expsym_cmds], [2]) +_LT_TAGDECL([], [module_cmds], [2], + [Commands used to build a loadable module if different from building + a shared archive.]) +_LT_TAGDECL([], [module_expsym_cmds], [2]) +_LT_TAGDECL([], [with_gnu_ld], [1], + [Whether we are building with GNU ld or not]) +_LT_TAGDECL([], [allow_undefined_flag], [1], + [Flag that allows shared libraries with undefined symbols to be built]) +_LT_TAGDECL([], [no_undefined_flag], [1], + [Flag that enforces no undefined symbols]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], + [Flag to hardcode $libdir into a binary during linking. + This must work even if $libdir does not exist]) +_LT_TAGDECL([], [hardcode_libdir_separator], [1], + [Whether we need a single "-rpath" flag with a separated argument]) +_LT_TAGDECL([], [hardcode_direct], [0], + [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes + DIR into the resulting binary]) +_LT_TAGDECL([], [hardcode_direct_absolute], [0], + [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes + DIR into the resulting binary and the resulting library dependency is + "absolute", i.e impossible to change by setting $shlibpath_var if the + library is relocated]) +_LT_TAGDECL([], [hardcode_minus_L], [0], + [Set to "yes" if using the -LDIR flag during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_shlibpath_var], [0], + [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_automatic], [0], + [Set to "yes" if building a shared library automatically hardcodes DIR + into the library and all subsequent libraries and executables linked + against it]) +_LT_TAGDECL([], [inherit_rpath], [0], + [Set to yes if linker adds runtime paths of dependent libraries + to runtime path list]) +_LT_TAGDECL([], [link_all_deplibs], [0], + [Whether libtool must link a program against all its dependency libraries]) +_LT_TAGDECL([], [always_export_symbols], [0], + [Set to "yes" if exported symbols are required]) +_LT_TAGDECL([], [export_symbols_cmds], [2], + [The commands to list exported symbols]) +_LT_TAGDECL([], [exclude_expsyms], [1], + [Symbols that should not be listed in the preloaded symbols]) +_LT_TAGDECL([], [include_expsyms], [1], + [Symbols that must always be exported]) +_LT_TAGDECL([], [prelink_cmds], [2], + [Commands necessary for linking programs (against libraries) with templates]) +_LT_TAGDECL([], [postlink_cmds], [2], + [Commands necessary for finishing linking programs]) +_LT_TAGDECL([], [file_list_spec], [1], + [Specify filename containing input files]) +dnl FIXME: Not yet implemented +dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], +dnl [Compiler flag to generate thread safe objects]) +])# _LT_LINKER_SHLIBS + + +# _LT_LANG_C_CONFIG([TAG]) +# ------------------------ +# Ensure that the configuration variables for a C compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_C_CONFIG], +[m4_require([_LT_DECL_EGREP])dnl +lt_save_CC=$CC +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + +_LT_TAG_COMPILER +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + LT_SYS_DLOPEN_SELF + _LT_CMD_STRIPLIB + + # Report what library types will actually be built + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_CONFIG($1) +fi +AC_LANG_POP +CC=$lt_save_CC +])# _LT_LANG_C_CONFIG + + +# _LT_LANG_CXX_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a C++ compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_CXX_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PATH_MANIFEST_TOOL])dnl +if test -n "$CXX" && ( test no != "$CXX" && + ( (test g++ = "$CXX" && `g++ -v >/dev/null 2>&1` ) || + (test g++ != "$CXX"))); then + AC_PROG_CXXCPP +else + _lt_caught_CXX_error=yes +fi + +AC_LANG_PUSH(C++) +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(compiler_needs_object, $1)=no +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_caught_CXX_error"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_CFLAGS=$CFLAGS + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + CFLAGS=$CXXFLAGS + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test yes = "$GXX"; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + else + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + fi + + if test yes = "$GXX"; then + # Set up default GNU C++ configuration + + LT_PATH_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test yes = "$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='$wl' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) + _LT_TAGVAR(ld_shlibs, $1)=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aix[[4-9]]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + ;; + esac + + if test yes = "$GXX"; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag=$shared_flag' $wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + # The "-G" linker flag allows undefined symbols. + _LT_TAGVAR(no_undefined_flag, $1)='-bernotok' + # Determine the default libpath from the value encoded in an empty + # executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared + # libraries. Need -bnortl late, we may have -brtl in LDFLAGS. + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + case $GXX,$cc_basename in + ,cl* | no,cl*) + # Native MSVC + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + # Don't use ranlib + _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' + _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + func_to_tool_file "$lt_outputfile"~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # g++ + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + freebsd2.*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + freebsd-elf*) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + haiku*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + hpux9*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` -o $lib' + fi + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib $wl-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [[1-5]].* | *pgcpp\ [[1-5]].*) + _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' + _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ + $RANLIB $oldlib' + _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 6 and above use weak symbols + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl--rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib $wl-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' + ;; + xl* | mpixl* | bgxl*) + # IBM XL 8.0 on PPC, with GNU ld + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file $wl$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file,$export_symbols -o $lib' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + fi + output_verbose_link_cmd=func_echo_all + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + case $host in + osf3*) + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $soname `test -n "$verstring" && func_echo_all "$wl-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + ;; + *) + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname $wl-input $wl$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~ + $RM $lib.exp' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes,no = "$GXX,$with_gnu_ld"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + case $host in + osf3*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag $wl-M $wl$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test yes,no = "$GXX,$with_gnu_ld"; then + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + else + # g++ 2.7 appears to require '-G' NOT '-shared' on this + # platform. + _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + fi + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Tprelink_objects $oldobjs~ + '"$_LT_TAGVAR(old_archive_cmds, $1)" + _LT_TAGVAR(reload_cmds, $1)='$CC -Tprelink_objects $reload_objs~ + '"$_LT_TAGVAR(reload_cmds, $1)" + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) + test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no + + _LT_TAGVAR(GCC, $1)=$GXX + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test yes != "$_lt_caught_CXX_error" + +AC_LANG_POP +])# _LT_LANG_CXX_CONFIG + + +# _LT_FUNC_STRIPNAME_CNF +# ---------------------- +# func_stripname_cnf prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# +# This function is identical to the (non-XSI) version of func_stripname, +# except this one can be used by m4 code that may be executed by configure, +# rather than the libtool script. +m4_defun([_LT_FUNC_STRIPNAME_CNF],[dnl +AC_REQUIRE([_LT_DECL_SED]) +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH]) +func_stripname_cnf () +{ + case @S|@2 in + .*) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%\\\\@S|@2\$%%"`;; + *) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%@S|@2\$%%"`;; + esac +} # func_stripname_cnf +])# _LT_FUNC_STRIPNAME_CNF + + +# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) +# --------------------------------- +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +m4_defun([_LT_SYS_HIDDEN_LIBDEPS], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +AC_REQUIRE([_LT_FUNC_STRIPNAME_CNF])dnl +# Dependencies to place before and after the object being linked: +_LT_TAGVAR(predep_objects, $1)= +_LT_TAGVAR(postdep_objects, $1)= +_LT_TAGVAR(predeps, $1)= +_LT_TAGVAR(postdeps, $1)= +_LT_TAGVAR(compiler_lib_search_path, $1)= + +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF +int a; +void foo (void) { a = 0; } +_LT_EOF +], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF +], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer*4 a + a=0 + return + end +_LT_EOF +], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer a + a=0 + return + end +_LT_EOF +], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF +public class foo { + private int a; + public void bar (void) { + a = 0; + } +}; +_LT_EOF +], [$1], [GO], [cat > conftest.$ac_ext <<_LT_EOF +package foo +func foo() { +} +_LT_EOF +]) + +_lt_libdeps_save_CFLAGS=$CFLAGS +case "$CC $CFLAGS " in #( +*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; +*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; +*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; +esac + +dnl Parse the compiler output and extract the necessary +dnl objects, libraries and library flags. +if AC_TRY_EVAL(ac_compile); then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $prev$p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test x-L = "$p" || + test x-R = "$p"; then + prev=$p + continue + fi + + # Expand the sysroot to ease extracting the directories later. + if test -z "$prev"; then + case $p in + -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; + -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; + -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; + esac + fi + case $p in + =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; + esac + if test no = "$pre_test_object_deps_done"; then + case $prev in + -L | -R) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then + _LT_TAGVAR(compiler_lib_search_path, $1)=$prev$p + else + _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} $prev$p" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$_LT_TAGVAR(postdeps, $1)"; then + _LT_TAGVAR(postdeps, $1)=$prev$p + else + _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} $prev$p" + fi + fi + prev= + ;; + + *.lto.$objext) ;; # Ignore GCC LTO objects + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test no = "$pre_test_object_deps_done"; then + if test -z "$_LT_TAGVAR(predep_objects, $1)"; then + _LT_TAGVAR(predep_objects, $1)=$p + else + _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" + fi + else + if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then + _LT_TAGVAR(postdep_objects, $1)=$p + else + _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling $1 test program" +fi + +$RM -f confest.$objext +CFLAGS=$_lt_libdeps_save_CFLAGS + +# PORTME: override above test on systems where it is broken +m4_if([$1], [CXX], +[case $host_os in +interix[[3-9]]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + _LT_TAGVAR(predep_objects,$1)= + _LT_TAGVAR(postdep_objects,$1)= + _LT_TAGVAR(postdeps,$1)= + ;; +esac +]) + +case " $_LT_TAGVAR(postdeps, $1) " in +*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; +esac + _LT_TAGVAR(compiler_lib_search_dirs, $1)= +if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then + _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | $SED -e 's! -L! !g' -e 's!^ !!'` +fi +_LT_TAGDECL([], [compiler_lib_search_dirs], [1], + [The directories searched by this compiler when creating a shared library]) +_LT_TAGDECL([], [predep_objects], [1], + [Dependencies to place before and after the objects being linked to + create a shared library]) +_LT_TAGDECL([], [postdep_objects], [1]) +_LT_TAGDECL([], [predeps], [1]) +_LT_TAGDECL([], [postdeps], [1]) +_LT_TAGDECL([], [compiler_lib_search_path], [1], + [The library search path used internally by the compiler when linking + a shared library]) +])# _LT_SYS_HIDDEN_LIBDEPS + + +# _LT_LANG_F77_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a Fortran 77 compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_F77_CONFIG], +[AC_LANG_PUSH(Fortran 77) +if test -z "$F77" || test no = "$F77"; then + _lt_disable_F77=yes +fi + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the F77 compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_disable_F77"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_GCC=$GCC + lt_save_CFLAGS=$CFLAGS + CC=${F77-"f77"} + CFLAGS=$FFLAGS + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + GCC=$G77 + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)=$G77 + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS +fi # test yes != "$_lt_disable_F77" + +AC_LANG_POP +])# _LT_LANG_F77_CONFIG + + +# _LT_LANG_FC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for a Fortran compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_FC_CONFIG], +[AC_LANG_PUSH(Fortran) + +if test -z "$FC" || test no = "$FC"; then + _lt_disable_FC=yes +fi + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for fc test sources. +ac_ext=${ac_fc_srcext-f} + +# Object file extension for compiled fc test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the FC compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_disable_FC"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_GCC=$GCC + lt_save_CFLAGS=$CFLAGS + CC=${FC-"f95"} + CFLAGS=$FCFLAGS + compiler=$CC + GCC=$ac_cv_fc_compiler_gnu + + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)=$ac_cv_fc_compiler_gnu + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS +fi # test yes != "$_lt_disable_FC" + +AC_LANG_POP +])# _LT_LANG_FC_CONFIG + + +# _LT_LANG_GCJ_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Java Compiler compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_GCJ_CONFIG], +[AC_REQUIRE([LT_PROG_GCJ])dnl +AC_LANG_SAVE + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC=yes +CC=${GCJ-"gcj"} +CFLAGS=$GCJFLAGS +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)=$LD +_LT_CC_BASENAME([$compiler]) + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds + +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_GCJ_CONFIG + + +# _LT_LANG_GO_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Go compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_GO_CONFIG], +[AC_REQUIRE([LT_PROG_GO])dnl +AC_LANG_SAVE + +# Source file extension for Go test sources. +ac_ext=go + +# Object file extension for compiled Go test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="package main; func main() { }" + +# Code to be used in simple link tests +lt_simple_link_test_code='package main; func main() { }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC=yes +CC=${GOC-"gccgo"} +CFLAGS=$GOFLAGS +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)=$LD +_LT_CC_BASENAME([$compiler]) + +# Go did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds + +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_GO_CONFIG + + +# _LT_LANG_RC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for the Windows resource compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_RC_CONFIG], +[AC_REQUIRE([LT_PROG_RC])dnl +AC_LANG_SAVE + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' + +# Code to be used in simple link tests +lt_simple_link_test_code=$lt_simple_compile_test_code + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC= +CC=${RC-"windres"} +CFLAGS= +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) +_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + +if test -n "$compiler"; then + : + _LT_CONFIG($1) +fi + +GCC=$lt_save_GCC +AC_LANG_RESTORE +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_RC_CONFIG + + +# LT_PROG_GCJ +# ----------- +AC_DEFUN([LT_PROG_GCJ], +[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test set = "${GCJFLAGS+set}" || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_GCJ], []) + + +# LT_PROG_GO +# ---------- +AC_DEFUN([LT_PROG_GO], +[AC_CHECK_TOOL(GOC, gccgo,) +]) + + +# LT_PROG_RC +# ---------- +AC_DEFUN([LT_PROG_RC], +[AC_CHECK_TOOL(RC, windres,) +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_RC], []) + + +# _LT_DECL_EGREP +# -------------- +# If we don't have a new enough Autoconf to choose the best grep +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_EGREP], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_REQUIRE([AC_PROG_FGREP])dnl +test -z "$GREP" && GREP=grep +_LT_DECL([], [GREP], [1], [A grep program that handles long lines]) +_LT_DECL([], [EGREP], [1], [An ERE matcher]) +_LT_DECL([], [FGREP], [1], [A literal string matcher]) +dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too +AC_SUBST([GREP]) +]) + + +# _LT_DECL_OBJDUMP +# -------------- +# If we don't have a new enough Autoconf to choose the best objdump +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_OBJDUMP], +[AC_CHECK_TOOL(OBJDUMP, objdump, false) +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) +AC_SUBST([OBJDUMP]) +]) + +# _LT_DECL_DLLTOOL +# ---------------- +# Ensure DLLTOOL variable is set. +m4_defun([_LT_DECL_DLLTOOL], +[AC_CHECK_TOOL(DLLTOOL, dlltool, false) +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [1], [DLL creation program]) +AC_SUBST([DLLTOOL]) +]) + +# _LT_DECL_SED +# ------------ +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +m4_defun([_LT_DECL_SED], +[AC_PROG_SED +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" +_LT_DECL([], [SED], [1], [A sed program that does not truncate output]) +_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], + [Sed that helps us avoid accidentally triggering echo(1) options like -n]) +])# _LT_DECL_SED + +m4_ifndef([AC_PROG_SED], [ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # + +m4_defun([AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f "$lt_ac_sed" && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test 10 -lt "$lt_ac_count" && break + lt_ac_count=`expr $lt_ac_count + 1` + if test "$lt_ac_count" -gt "$lt_ac_max"; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +])#AC_PROG_SED +])#m4_ifndef + +# Old name: +AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_SED], []) + + +# _LT_CHECK_SHELL_FEATURES +# ------------------------ +# Find out whether the shell is Bourne or XSI compatible, +# or has some other useful features. +m4_defun([_LT_CHECK_SHELL_FEATURES], +[if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi +_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac +_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl +_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl +])# _LT_CHECK_SHELL_FEATURES + + +# _LT_PATH_CONVERSION_FUNCTIONS +# ----------------------------- +# Determine what file name conversion functions should be used by +# func_to_host_file (and, implicitly, by func_to_host_path). These are needed +# for certain cross-compile configurations and native mingw. +m4_defun([_LT_PATH_CONVERSION_FUNCTIONS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +AC_MSG_CHECKING([how to convert $build file names to $host format]) +AC_CACHE_VAL(lt_cv_to_host_file_cmd, +[case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 + ;; + esac + ;; + *-*-cygwin* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin + ;; + esac + ;; + * ) # unhandled hosts (and "normal" native builds) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; +esac +]) +to_host_file_cmd=$lt_cv_to_host_file_cmd +AC_MSG_RESULT([$lt_cv_to_host_file_cmd]) +_LT_DECL([to_host_file_cmd], [lt_cv_to_host_file_cmd], + [0], [convert $build file names to $host format])dnl + +AC_MSG_CHECKING([how to convert $build file names to toolchain format]) +AC_CACHE_VAL(lt_cv_to_tool_file_cmd, +[#assume ordinary cross tools, or native build. +lt_cv_to_tool_file_cmd=func_convert_file_noop +case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 + ;; + esac + ;; +esac +]) +to_tool_file_cmd=$lt_cv_to_tool_file_cmd +AC_MSG_RESULT([$lt_cv_to_tool_file_cmd]) +_LT_DECL([to_tool_file_cmd], [lt_cv_to_tool_file_cmd], + [0], [convert $build files to toolchain format])dnl +])# _LT_PATH_CONVERSION_FUNCTIONS + +# Helper functions for option handling. -*- Autoconf -*- +# +# Copyright (C) 2004-2005, 2007-2009, 2011-2015 Free Software +# Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 8 ltoptions.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) + + +# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) +# ------------------------------------------ +m4_define([_LT_MANGLE_OPTION], +[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) + + +# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) +# --------------------------------------- +# Set option OPTION-NAME for macro MACRO-NAME, and if there is a +# matching handler defined, dispatch to it. Other OPTION-NAMEs are +# saved as a flag. +m4_define([_LT_SET_OPTION], +[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl +m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), + _LT_MANGLE_DEFUN([$1], [$2]), + [m4_warning([Unknown $1 option '$2'])])[]dnl +]) + + +# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) +# ------------------------------------------------------------ +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +m4_define([_LT_IF_OPTION], +[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) + + +# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) +# ------------------------------------------------------- +# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME +# are set. +m4_define([_LT_UNLESS_OPTIONS], +[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), + [m4_define([$0_found])])])[]dnl +m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 +])[]dnl +]) + + +# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) +# ---------------------------------------- +# OPTION-LIST is a space-separated list of Libtool options associated +# with MACRO-NAME. If any OPTION has a matching handler declared with +# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about +# the unknown option and exit. +m4_defun([_LT_SET_OPTIONS], +[# Set options +m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [_LT_SET_OPTION([$1], _LT_Option)]) + +m4_if([$1],[LT_INIT],[ + dnl + dnl Simply set some default values (i.e off) if boolean options were not + dnl specified: + _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no + ]) + _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no + ]) + dnl + dnl If no reference was made to various pairs of opposing options, then + dnl we run the default mode handler for the pair. For example, if neither + dnl 'shared' nor 'disable-shared' was passed, we enable building of shared + dnl archives by default: + _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) + _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], + [_LT_ENABLE_FAST_INSTALL]) + _LT_UNLESS_OPTIONS([LT_INIT], [aix-soname=aix aix-soname=both aix-soname=svr4], + [_LT_WITH_AIX_SONAME([aix])]) + ]) +])# _LT_SET_OPTIONS + + + +# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) +# ----------------------------------------- +m4_define([_LT_MANGLE_DEFUN], +[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) + + +# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) +# ----------------------------------------------- +m4_define([LT_OPTION_DEFINE], +[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl +])# LT_OPTION_DEFINE + + +# dlopen +# ------ +LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes +]) + +AU_DEFUN([AC_LIBTOOL_DLOPEN], +[_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'dlopen' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) + + +# win32-dll +# --------- +# Declare package support for building win32 dll's. +LT_OPTION_DEFINE([LT_INIT], [win32-dll], +[enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; +esac + +test -z "$AS" && AS=as +_LT_DECL([], [AS], [1], [Assembler program])dnl + +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl + +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl +])# win32-dll + +AU_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'win32-dll' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) + + +# _LT_ENABLE_SHARED([DEFAULT]) +# ---------------------------- +# implement the --enable-shared flag, and supports the 'shared' and +# 'disable-shared' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_SHARED], +[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) + + _LT_DECL([build_libtool_libs], [enable_shared], [0], + [Whether or not to build shared libraries]) +])# _LT_ENABLE_SHARED + +LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) + +AC_DEFUN([AC_DISABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) + +AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_SHARED], []) +dnl AC_DEFUN([AM_DISABLE_SHARED], []) + + + +# _LT_ENABLE_STATIC([DEFAULT]) +# ---------------------------- +# implement the --enable-static flag, and support the 'static' and +# 'disable-static' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_STATIC], +[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_static=]_LT_ENABLE_STATIC_DEFAULT) + + _LT_DECL([build_old_libs], [enable_static], [0], + [Whether or not to build static libraries]) +])# _LT_ENABLE_STATIC + +LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) + +AC_DEFUN([AC_DISABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], [disable-static]) +]) + +AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_STATIC], []) +dnl AC_DEFUN([AM_DISABLE_STATIC], []) + + + +# _LT_ENABLE_FAST_INSTALL([DEFAULT]) +# ---------------------------------- +# implement the --enable-fast-install flag, and support the 'fast-install' +# and 'disable-fast-install' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_FAST_INSTALL], +[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([fast-install], + [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) + +_LT_DECL([fast_install], [enable_fast_install], [0], + [Whether or not to optimize for fast installation])dnl +])# _LT_ENABLE_FAST_INSTALL + +LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) + +# Old names: +AU_DEFUN([AC_ENABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'fast-install' option into LT_INIT's first parameter.]) +]) + +AU_DEFUN([AC_DISABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'disable-fast-install' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) +dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) + + +# _LT_WITH_AIX_SONAME([DEFAULT]) +# ---------------------------------- +# implement the --with-aix-soname flag, and support the `aix-soname=aix' +# and `aix-soname=both' and `aix-soname=svr4' LT_INIT options. DEFAULT +# is either `aix', `both' or `svr4'. If omitted, it defaults to `aix'. +m4_define([_LT_WITH_AIX_SONAME], +[m4_define([_LT_WITH_AIX_SONAME_DEFAULT], [m4_if($1, svr4, svr4, m4_if($1, both, both, aix))])dnl +shared_archive_member_spec= +case $host,$enable_shared in +power*-*-aix[[5-9]]*,yes) + AC_MSG_CHECKING([which variant of shared library versioning to provide]) + AC_ARG_WITH([aix-soname], + [AS_HELP_STRING([--with-aix-soname=aix|svr4|both], + [shared library versioning (aka "SONAME") variant to provide on AIX, @<:@default=]_LT_WITH_AIX_SONAME_DEFAULT[@:>@.])], + [case $withval in + aix|svr4|both) + ;; + *) + AC_MSG_ERROR([Unknown argument to --with-aix-soname]) + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname], + [AC_CACHE_VAL([lt_cv_with_aix_soname], + [lt_cv_with_aix_soname=]_LT_WITH_AIX_SONAME_DEFAULT) + with_aix_soname=$lt_cv_with_aix_soname]) + AC_MSG_RESULT([$with_aix_soname]) + if test aix != "$with_aix_soname"; then + # For the AIX way of multilib, we name the shared archive member + # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', + # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. + # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, + # the AIX toolchain works better with OBJECT_MODE set (default 32). + if test 64 = "${OBJECT_MODE-32}"; then + shared_archive_member_spec=shr_64 + else + shared_archive_member_spec=shr + fi + fi + ;; +*) + with_aix_soname=aix + ;; +esac + +_LT_DECL([], [shared_archive_member_spec], [0], + [Shared archive member basename, for filename based shared library versioning on AIX])dnl +])# _LT_WITH_AIX_SONAME + +LT_OPTION_DEFINE([LT_INIT], [aix-soname=aix], [_LT_WITH_AIX_SONAME([aix])]) +LT_OPTION_DEFINE([LT_INIT], [aix-soname=both], [_LT_WITH_AIX_SONAME([both])]) +LT_OPTION_DEFINE([LT_INIT], [aix-soname=svr4], [_LT_WITH_AIX_SONAME([svr4])]) + + +# _LT_WITH_PIC([MODE]) +# -------------------- +# implement the --with-pic flag, and support the 'pic-only' and 'no-pic' +# LT_INIT options. +# MODE is either 'yes' or 'no'. If omitted, it defaults to 'both'. +m4_define([_LT_WITH_PIC], +[AC_ARG_WITH([pic], + [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [pic_mode=m4_default([$1], [default])]) + +_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl +])# _LT_WITH_PIC + +LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) + +# Old name: +AU_DEFUN([AC_LIBTOOL_PICMODE], +[_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'pic-only' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) + + +m4_define([_LTDL_MODE], []) +LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], + [m4_define([_LTDL_MODE], [nonrecursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [recursive], + [m4_define([_LTDL_MODE], [recursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [subproject], + [m4_define([_LTDL_MODE], [subproject])]) + +m4_define([_LTDL_TYPE], []) +LT_OPTION_DEFINE([LTDL_INIT], [installable], + [m4_define([_LTDL_TYPE], [installable])]) +LT_OPTION_DEFINE([LTDL_INIT], [convenience], + [m4_define([_LTDL_TYPE], [convenience])]) + +# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- +# +# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software +# Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltsugar.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) + + +# lt_join(SEP, ARG1, [ARG2...]) +# ----------------------------- +# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their +# associated separator. +# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier +# versions in m4sugar had bugs. +m4_define([lt_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) +m4_define([_lt_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) + + +# lt_car(LIST) +# lt_cdr(LIST) +# ------------ +# Manipulate m4 lists. +# These macros are necessary as long as will still need to support +# Autoconf-2.59, which quotes differently. +m4_define([lt_car], [[$1]]) +m4_define([lt_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) +m4_define([lt_unquote], $1) + + +# lt_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'. +# Note that neither SEPARATOR nor STRING are expanded; they are appended +# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). +# No SEPARATOR is output if MACRO-NAME was previously undefined (different +# than defined and empty). +# +# This macro is needed until we can rely on Autoconf 2.62, since earlier +# versions of m4sugar mistakenly expanded SEPARATOR but not STRING. +m4_define([lt_append], +[m4_define([$1], + m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) + + + +# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) +# ---------------------------------------------------------- +# Produce a SEP delimited list of all paired combinations of elements of +# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list +# has the form PREFIXmINFIXSUFFIXn. +# Needed until we can rely on m4_combine added in Autoconf 2.62. +m4_define([lt_combine], +[m4_if(m4_eval([$# > 3]), [1], + [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl +[[m4_foreach([_Lt_prefix], [$2], + [m4_foreach([_Lt_suffix], + ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, + [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) + + +# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) +# ----------------------------------------------------------------------- +# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited +# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. +m4_define([lt_if_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], + [lt_append([$1], [$2], [$3])$4], + [$5])], + [lt_append([$1], [$2], [$3])$4])]) + + +# lt_dict_add(DICT, KEY, VALUE) +# ----------------------------- +m4_define([lt_dict_add], +[m4_define([$1($2)], [$3])]) + + +# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) +# -------------------------------------------- +m4_define([lt_dict_add_subkey], +[m4_define([$1($2:$3)], [$4])]) + + +# lt_dict_fetch(DICT, KEY, [SUBKEY]) +# ---------------------------------- +m4_define([lt_dict_fetch], +[m4_ifval([$3], + m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), + m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) + + +# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------------------- +m4_define([lt_if_dict_fetch], +[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], + [$5], + [$6])]) + + +# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) +# -------------------------------------------------------------- +m4_define([lt_dict_filter], +[m4_if([$5], [], [], + [lt_join(m4_quote(m4_default([$4], [[, ]])), + lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), + [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl +]) + +# ltversion.m4 -- version numbers -*- Autoconf -*- +# +# Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# @configure_input@ + +# serial 4179 ltversion.m4 +# This file is part of GNU Libtool + +m4_define([LT_PACKAGE_VERSION], [2.4.6]) +m4_define([LT_PACKAGE_REVISION], [2.4.6]) + +AC_DEFUN([LTVERSION_VERSION], +[macro_version='2.4.6' +macro_revision='2.4.6' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) + +# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- +# +# Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software +# Foundation, Inc. +# Written by Scott James Remnant, 2004. +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 5 lt~obsolete.m4 + +# These exist entirely to fool aclocal when bootstrapping libtool. +# +# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN), +# which have later been changed to m4_define as they aren't part of the +# exported API, or moved to Autoconf or Automake where they belong. +# +# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN +# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us +# using a macro with the same name in our local m4/libtool.m4 it'll +# pull the old libtool.m4 in (it doesn't see our shiny new m4_define +# and doesn't know about Autoconf macros at all.) +# +# So we provide this file, which has a silly filename so it's always +# included after everything else. This provides aclocal with the +# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything +# because those macros already exist, or will be overwritten later. +# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. +# +# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. +# Yes, that means every name once taken will need to remain here until +# we give up compatibility with versions before 1.7, at which point +# we need to keep only those names which we still refer to. + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) + +m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) +m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) +m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) +m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) +m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) +m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) +m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) +m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) +m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) +m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) +m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) +m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) +m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) +m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) +m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) +m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) +m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) +m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) +m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) +m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) +m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) +m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) +m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) +m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) +m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) +m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) +m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) +m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) +m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) +m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) +m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) +m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) +m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) +m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) +m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) +m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) +m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) +m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) +m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) +m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) +m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) +m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) +m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) +m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) +m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) +m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) +m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) +m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) +m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) +m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) + +# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_AUTOMAKE_VERSION(VERSION) +# ---------------------------- +# Automake X.Y traces this macro to ensure aclocal.m4 has been +# generated from the m4 files accompanying Automake X.Y. +# (This private macro should not be called outside this file.) +AC_DEFUN([AM_AUTOMAKE_VERSION], +[am__api_version='1.15' +dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to +dnl require some minimum version. Point them to the right macro. +m4_if([$1], [1.15], [], + [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl +]) + +# _AM_AUTOCONF_VERSION(VERSION) +# ----------------------------- +# aclocal traces this macro to find the Autoconf version. +# This is a private macro too. Using m4_define simplifies +# the logic in aclocal, which can simply ignore this definition. +m4_define([_AM_AUTOCONF_VERSION], []) + +# AM_SET_CURRENT_AUTOMAKE_VERSION +# ------------------------------- +# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. +# This function is AC_REQUIREd by AM_INIT_AUTOMAKE. +AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], +[AM_AUTOMAKE_VERSION([1.15])dnl +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) + +# AM_AUX_DIR_EXPAND -*- Autoconf -*- + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets +# $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to +# '$srcdir', '$srcdir/..', or '$srcdir/../..'. +# +# Of course, Automake must honor this variable whenever it calls a +# tool from the auxiliary directory. The problem is that $srcdir (and +# therefore $ac_aux_dir as well) can be either absolute or relative, +# depending on how configure is run. This is pretty annoying, since +# it makes $ac_aux_dir quite unusable in subdirectories: in the top +# source directory, any form will work fine, but in subdirectories a +# relative path needs to be adjusted first. +# +# $ac_aux_dir/missing +# fails when called from a subdirectory if $ac_aux_dir is relative +# $top_srcdir/$ac_aux_dir/missing +# fails if $ac_aux_dir is absolute, +# fails when called from a subdirectory in a VPATH build with +# a relative $ac_aux_dir +# +# The reason of the latter failure is that $top_srcdir and $ac_aux_dir +# are both prefixed by $srcdir. In an in-source build this is usually +# harmless because $srcdir is '.', but things will broke when you +# start a VPATH build or use an absolute $srcdir. +# +# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, +# iff we strip the leading $srcdir from $ac_aux_dir. That would be: +# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` +# and then we would define $MISSING as +# MISSING="\${SHELL} $am_aux_dir/missing" +# This will work as long as MISSING is not called from configure, because +# unfortunately $(top_srcdir) has no meaning in configure. +# However there are other variables, like CC, which are often used in +# configure, and could therefore not use this "fixed" $ac_aux_dir. +# +# Another solution, used here, is to always expand $ac_aux_dir to an +# absolute PATH. The drawback is that using absolute paths prevent a +# configured tree to be moved without reconfiguration. + +AC_DEFUN([AM_AUX_DIR_EXPAND], +[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` +]) + +# AM_CONDITIONAL -*- Autoconf -*- + +# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_CONDITIONAL(NAME, SHELL-CONDITION) +# ------------------------------------- +# Define a conditional. +AC_DEFUN([AM_CONDITIONAL], +[AC_PREREQ([2.52])dnl + m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE])dnl +AC_SUBST([$1_FALSE])dnl +_AM_SUBST_NOTMAKE([$1_TRUE])dnl +_AM_SUBST_NOTMAKE([$1_FALSE])dnl +m4_define([_AM_COND_VALUE_$1], [$2])dnl +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + + +# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be +# written in clear, in which case automake, when reading aclocal.m4, +# will think it sees a *use*, and therefore will trigger all it's +# C support machinery. Also note that it means that autoscan, seeing +# CC etc. in the Makefile, will ask for an AC_PROG_CC use... + + +# _AM_DEPENDENCIES(NAME) +# ---------------------- +# See how the compiler implements dependency checking. +# NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC". +# We try a few techniques and use that to set a single cache variable. +# +# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was +# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular +# dependency, and given that the user is not expected to run this macro, +# just rely on AC_PROG_CC. +AC_DEFUN([_AM_DEPENDENCIES], +[AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], + [$1], [CXX], [depcc="$CXX" am_compiler_list=], + [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], + [$1], [UPC], [depcc="$UPC" am_compiler_list=], + [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + am__universal=false + m4_case([$1], [CC], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac], + [CXX], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac]) + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) + + +# AM_SET_DEPDIR +# ------------- +# Choose a directory name for dependency files. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES. +AC_DEFUN([AM_SET_DEPDIR], +[AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) + + +# AM_DEP_TRACK +# ------------ +AC_DEFUN([AM_DEP_TRACK], +[AC_ARG_ENABLE([dependency-tracking], [dnl +AS_HELP_STRING( + [--enable-dependency-tracking], + [do not reject slow dependency extractors]) +AS_HELP_STRING( + [--disable-dependency-tracking], + [speeds up one-time build])]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' + am__nodep='_no' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH])dnl +_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl +AC_SUBST([am__nodep])dnl +_AM_SUBST_NOTMAKE([am__nodep])dnl +]) + +# Generate code to set up dependency tracking. -*- Autoconf -*- + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + + +# _AM_OUTPUT_DEPENDENCY_COMMANDS +# ------------------------------ +AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], +[{ + # Older Autoconf quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named 'Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running 'make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "$am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} +])# _AM_OUTPUT_DEPENDENCY_COMMANDS + + +# AM_OUTPUT_DEPENDENCY_COMMANDS +# ----------------------------- +# This macro should only be invoked once -- use via AC_REQUIRE. +# +# This code is only required when automatic dependency tracking +# is enabled. FIXME. This creates each '.P' file that we will +# need in order to bootstrap the dependency handling code. +AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], +[AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) + +# Do all the work for Automake. -*- Autoconf -*- + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This macro actually does too much. Some checks are only needed if +# your package does certain things. But this isn't really a big deal. + +dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O. +m4_define([AC_PROG_CC], +m4_defn([AC_PROG_CC]) +[_AM_PROG_CC_C_O +]) + +# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) +# AM_INIT_AUTOMAKE([OPTIONS]) +# ----------------------------------------------- +# The call with PACKAGE and VERSION arguments is the old style +# call (pre autoconf-2.50), which is being phased out. PACKAGE +# and VERSION should now be passed to AC_INIT and removed from +# the call to AM_INIT_AUTOMAKE. +# We support both call styles for the transition. After +# the next Automake release, Autoconf can make the AC_INIT +# arguments mandatory, and then we can depend on a new Autoconf +# release and drop the old call support. +AC_DEFUN([AM_INIT_AUTOMAKE], +[AC_PREREQ([2.65])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[AC_DIAGNOSE([obsolete], + [$0: two- and three-arguments forms are deprecated.]) +m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl +dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. +m4_if( + m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), + [ok:ok],, + [m4_fatal([AC_INIT should be called with package and version arguments])])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) + AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) +AM_MISSING_PROG([AUTOCONF], [autoconf]) +AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) +AM_MISSING_PROG([AUTOHEADER], [autoheader]) +AM_MISSING_PROG([MAKEINFO], [makeinfo]) +AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +AC_SUBST([mkdir_p], ['$(MKDIR_P)']) +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES([CC])], + [m4_define([AC_PROG_CC], + m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES([CXX])], + [m4_define([AC_PROG_CXX], + m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJC], + [_AM_DEPENDENCIES([OBJC])], + [m4_define([AC_PROG_OBJC], + m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], + [_AM_DEPENDENCIES([OBJCXX])], + [m4_define([AC_PROG_OBJCXX], + m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl +]) +AC_REQUIRE([AM_SILENT_RULES])dnl +dnl The testsuite driver may need to know about EXEEXT, so add the +dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This +dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below. +AC_CONFIG_COMMANDS_PRE(dnl +[m4_provide_if([_AM_COMPILER_EXEEXT], + [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) + fi +fi +dnl The trailing newline in this macro's definition is deliberate, for +dnl backward compatibility and to allow trailing 'dnl'-style comments +dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. +]) + +dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not +dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further +dnl mangled by Autoconf and run in a shell conditional statement. +m4_define([_AC_COMPILER_EXEEXT], +m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) + +# When config.status generates a header, we must update the stamp-h file. +# This file resides in the same directory as the config header +# that is generated. The stamp files are numbered to have different names. + +# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the +# loop where config.status creates the headers, so we can generate +# our stamp files there. +AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], +[# Compute $1's index in $config_headers. +_am_arg=$1 +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_SH +# ------------------ +# Define $install_sh. +AC_DEFUN([AM_PROG_INSTALL_SH], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +if test x"${install_sh+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi +AC_SUBST([install_sh])]) + +# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Check whether the underlying file-system supports filenames +# with a leading dot. For instance MS-DOS doesn't. +AC_DEFUN([AM_SET_LEADING_DOT], +[rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) + +# Check to see how 'make' treats includes. -*- Autoconf -*- + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_MAKE_INCLUDE() +# ----------------- +# Check to see how make treats includes. +AC_DEFUN([AM_MAKE_INCLUDE], +[am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from 'make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) + +# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- + +# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_MISSING_PROG(NAME, PROGRAM) +# ------------------------------ +AC_DEFUN([AM_MISSING_PROG], +[AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) + +# AM_MISSING_HAS_RUN +# ------------------ +# Define MISSING if not defined so far and test if it is modern enough. +# If it is, set am_missing_run to use it, otherwise, to nothing. +AC_DEFUN([AM_MISSING_HAS_RUN], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([missing])dnl +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --is-lightweight"; then + am_missing_run="$MISSING " +else + am_missing_run= + AC_MSG_WARN(['missing' script is too old or missing]) +fi +]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_MANGLE_OPTION(NAME) +# ----------------------- +AC_DEFUN([_AM_MANGLE_OPTION], +[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) + +# _AM_SET_OPTION(NAME) +# -------------------- +# Set option NAME. Presently that only means defining a flag for this option. +AC_DEFUN([_AM_SET_OPTION], +[m4_define(_AM_MANGLE_OPTION([$1]), [1])]) + +# _AM_SET_OPTIONS(OPTIONS) +# ------------------------ +# OPTIONS is a space-separated list of Automake options. +AC_DEFUN([_AM_SET_OPTIONS], +[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) + +# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) +# ------------------------------------------- +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +AC_DEFUN([_AM_IF_OPTION], +[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_PROG_CC_C_O +# --------------- +# Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC +# to automatically call this. +AC_DEFUN([_AM_PROG_CC_C_O], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([compile])dnl +AC_LANG_PUSH([C])dnl +AC_CACHE_CHECK( + [whether $CC understands -c and -o together], + [am_cv_prog_cc_c_o], + [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])]) + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i]) +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +AC_LANG_POP([C])]) + +# For backward compatibility. +AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_RUN_LOG(COMMAND) +# ------------------- +# Run COMMAND, save the exit status in ac_status, and log it. +# (This has been adapted from Autoconf's _AC_RUN_LOG macro.) +AC_DEFUN([AM_RUN_LOG], +[{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD + ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + (exit $ac_status); }]) + +# Check to make sure that the build environment is sane. -*- Autoconf -*- + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_SANITY_CHECK +# --------------- +AC_DEFUN([AM_SANITY_CHECK], +[AC_MSG_CHECKING([whether build environment is sane]) +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[[\\\"\#\$\&\'\`$am_lf]]*) + AC_MSG_ERROR([unsafe absolute working directory name]);; +esac +case $srcdir in + *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) + AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; +esac + +# Do 'set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken + alias in your environment]) + fi + if test "$[2]" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT([yes]) +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi +AC_CONFIG_COMMANDS_PRE( + [AC_MSG_CHECKING([that generated files are newer than configure]) + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + AC_MSG_RESULT([done])]) +rm -f conftest.file +]) + +# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_SILENT_RULES([DEFAULT]) +# -------------------------- +# Enable less verbose build rules; with the default set to DEFAULT +# ("yes" being less verbose, "no" or empty being verbose). +AC_DEFUN([AM_SILENT_RULES], +[AC_ARG_ENABLE([silent-rules], [dnl +AS_HELP_STRING( + [--enable-silent-rules], + [less verbose build output (undo: "make V=1")]) +AS_HELP_STRING( + [--disable-silent-rules], + [verbose build output (undo: "make V=0")])dnl +]) +case $enable_silent_rules in @%:@ ((( + yes) AM_DEFAULT_VERBOSITY=0;; + no) AM_DEFAULT_VERBOSITY=1;; + *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);; +esac +dnl +dnl A few 'make' implementations (e.g., NonStop OS and NextStep) +dnl do not support nested variable expansions. +dnl See automake bug#9928 and bug#10237. +am_make=${MAKE-make} +AC_CACHE_CHECK([whether $am_make supports nested variables], + [am_cv_make_support_nested_variables], + [if AS_ECHO([['TRUE=$(BAR$(V)) +BAR0=false +BAR1=true +V=1 +am__doit: + @$(TRUE) +.PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then + am_cv_make_support_nested_variables=yes +else + am_cv_make_support_nested_variables=no +fi]) +if test $am_cv_make_support_nested_variables = yes; then + dnl Using '$V' instead of '$(V)' breaks IRIX make. + AM_V='$(V)' + AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' +else + AM_V=$AM_DEFAULT_VERBOSITY + AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY +fi +AC_SUBST([AM_V])dnl +AM_SUBST_NOTMAKE([AM_V])dnl +AC_SUBST([AM_DEFAULT_V])dnl +AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl +AC_SUBST([AM_DEFAULT_VERBOSITY])dnl +AM_BACKSLASH='\' +AC_SUBST([AM_BACKSLASH])dnl +_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl +]) + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_STRIP +# --------------------- +# One issue with vendor 'install' (even GNU) is that you can't +# specify the program used to strip binaries. This is especially +# annoying in cross-compiling environments, where the build's strip +# is unlikely to handle the host's binaries. +# Fortunately install-sh will honor a STRIPPROG variable, so we +# always use install-sh in "make install-strip", and initialize +# STRIPPROG with the value of the STRIP variable (set by the user). +AC_DEFUN([AM_PROG_INSTALL_STRIP], +[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the 'STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) + +# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_SUBST_NOTMAKE(VARIABLE) +# --------------------------- +# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. +# This macro is traced by Automake. +AC_DEFUN([_AM_SUBST_NOTMAKE]) + +# AM_SUBST_NOTMAKE(VARIABLE) +# -------------------------- +# Public sister of _AM_SUBST_NOTMAKE. +AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) + +# Check how to create a tarball. -*- Autoconf -*- + +# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_PROG_TAR(FORMAT) +# -------------------- +# Check how to create a tarball in format FORMAT. +# FORMAT should be one of 'v7', 'ustar', or 'pax'. +# +# Substitute a variable $(am__tar) that is a command +# writing to stdout a FORMAT-tarball containing the directory +# $tardir. +# tardir=directory && $(am__tar) > result.tar +# +# Substitute a variable $(am__untar) that extract such +# a tarball read from stdin. +# $(am__untar) < result.tar +# +AC_DEFUN([_AM_PROG_TAR], +[# Always define AMTAR for backward compatibility. Yes, it's still used +# in the wild :-( We should find a proper way to deprecate it ... +AC_SUBST([AMTAR], ['$${TAR-tar}']) + +# We'll loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' + +m4_if([$1], [v7], + [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], + + [m4_case([$1], + [ustar], + [# The POSIX 1988 'ustar' format is defined with fixed-size fields. + # There is notably a 21 bits limit for the UID and the GID. In fact, + # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343 + # and bug#13588). + am_max_uid=2097151 # 2^21 - 1 + am_max_gid=$am_max_uid + # The $UID and $GID variables are not portable, so we need to resort + # to the POSIX-mandated id(1) utility. Errors in the 'id' calls + # below are definitely unexpected, so allow the users to see them + # (that is, avoid stderr redirection). + am_uid=`id -u || echo unknown` + am_gid=`id -g || echo unknown` + AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format]) + if test $am_uid -le $am_max_uid; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + _am_tools=none + fi + AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format]) + if test $am_gid -le $am_max_gid; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + _am_tools=none + fi], + + [pax], + [], + + [m4_fatal([Unknown tar format])]) + + AC_MSG_CHECKING([how to create a $1 tar archive]) + + # Go ahead even if we have the value already cached. We do so because we + # need to set the values for the 'am__tar' and 'am__untar' variables. + _am_tools=${am_cv_prog_tar_$1-$_am_tools} + + for _am_tool in $_am_tools; do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works. + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi + done + rm -rf conftest.dir + + AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) + AC_MSG_RESULT([$am_cv_prog_tar_$1])]) + +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) # _AM_PROG_TAR + +m4_include([acinclude.m4]) diff --git a/src/c/aminclude.am b/src/c/aminclude.am new file mode 100644 index 00000000000..420049eca35 --- /dev/null +++ b/src/c/aminclude.am @@ -0,0 +1,186 @@ +# Copyright (C) 2004 Oren Ben-Kiki +# This file is distributed under the same terms as the Automake macro files. + +# Generate automatic documentation using Doxygen. Goals and variables values +# are controlled by the various DX_COND_??? conditionals set by autoconf. +# +# The provided goals are: +# doxygen-doc: Generate all doxygen documentation. +# doxygen-run: Run doxygen, which will generate some of the documentation +# (HTML, CHM, CHI, MAN, RTF, XML) but will not do the post +# processing required for the rest of it (PS, PDF, and some MAN). +# doxygen-man: Rename some doxygen generated man pages. +# doxygen-ps: Generate doxygen PostScript documentation. +# doxygen-pdf: Generate doxygen PDF documentation. +# +# Note that by default these are not integrated into the automake goals. If +# doxygen is used to generate man pages, you can achieve this integration by +# setting man3_MANS to the list of man pages generated and then adding the +# dependency: +# +# $(man3_MANS): doxygen-doc +# +# This will cause make to run doxygen and generate all the documentation. +# +# The following variable is intended for use in Makefile.am: +# +# DX_CLEANFILES = everything to clean. +# +# This is usually added to MOSTLYCLEANFILES. + +## --------------------------------- ## +## Format-independent Doxygen rules. ## +## --------------------------------- ## + +if DX_COND_doc + +## ------------------------------- ## +## Rules specific for HTML output. ## +## ------------------------------- ## + +if DX_COND_html + +DX_CLEAN_HTML = @DX_DOCDIR@/html + +endif DX_COND_html + +## ------------------------------ ## +## Rules specific for CHM output. ## +## ------------------------------ ## + +if DX_COND_chm + +DX_CLEAN_CHM = @DX_DOCDIR@/chm + +if DX_COND_chi + +DX_CLEAN_CHI = @DX_DOCDIR@/@PACKAGE@.chi + +endif DX_COND_chi + +endif DX_COND_chm + +## ------------------------------ ## +## Rules specific for MAN output. ## +## ------------------------------ ## + +if DX_COND_man + +DX_CLEAN_MAN = @DX_DOCDIR@/man + +endif DX_COND_man + +## ------------------------------ ## +## Rules specific for RTF output. ## +## ------------------------------ ## + +if DX_COND_rtf + +DX_CLEAN_RTF = @DX_DOCDIR@/rtf + +endif DX_COND_rtf + +## ------------------------------ ## +## Rules specific for XML output. ## +## ------------------------------ ## + +if DX_COND_xml + +DX_CLEAN_XML = @DX_DOCDIR@/xml + +endif DX_COND_xml + +## ----------------------------- ## +## Rules specific for PS output. ## +## ----------------------------- ## + +if DX_COND_ps + +DX_CLEAN_PS = @DX_DOCDIR@/@PACKAGE@.ps + +DX_PS_GOAL = doxygen-ps + +doxygen-ps: @DX_DOCDIR@/@PACKAGE@.ps + +@DX_DOCDIR@/@PACKAGE@.ps: @DX_DOCDIR@/@PACKAGE@.tag + cd @DX_DOCDIR@/latex; \ + rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ + $(DX_LATEX) refman.tex; \ + $(MAKEINDEX_PATH) refman.idx; \ + $(DX_LATEX) refman.tex; \ + countdown=5; \ + while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ + refman.log > /dev/null 2>&1 \ + && test $$countdown -gt 0; do \ + $(DX_LATEX) refman.tex; \ + countdown=`expr $$countdown - 1`; \ + done; \ + $(DX_DVIPS) -o ../@PACKAGE@.ps refman.dvi + +endif DX_COND_ps + +## ------------------------------ ## +## Rules specific for PDF output. ## +## ------------------------------ ## + +if DX_COND_pdf + +DX_CLEAN_PDF = @DX_DOCDIR@/@PACKAGE@.pdf + +DX_PDF_GOAL = doxygen-pdf + +doxygen-pdf: @DX_DOCDIR@/@PACKAGE@.pdf + +@DX_DOCDIR@/@PACKAGE@.pdf: @DX_DOCDIR@/@PACKAGE@.tag + cd @DX_DOCDIR@/latex; \ + rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ + $(DX_PDFLATEX) refman.tex; \ + $(DX_MAKEINDEX) refman.idx; \ + $(DX_PDFLATEX) refman.tex; \ + countdown=5; \ + while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ + refman.log > /dev/null 2>&1 \ + && test $$countdown -gt 0; do \ + $(DX_PDFLATEX) refman.tex; \ + countdown=`expr $$countdown - 1`; \ + done; \ + mv refman.pdf ../@PACKAGE@.pdf + +endif DX_COND_pdf + +## ------------------------------------------------- ## +## Rules specific for LaTeX (shared for PS and PDF). ## +## ------------------------------------------------- ## + +if DX_COND_latex + +DX_CLEAN_LATEX = @DX_DOCDIR@/latex + +endif DX_COND_latex + +.PHONY: doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL) + +.INTERMEDIATE: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) + +doxygen-run: @DX_DOCDIR@/@PACKAGE@.tag + +doxygen-doc: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) + +@DX_DOCDIR@/@PACKAGE@.tag: $(DX_CONFIG) $(pkginclude_HEADERS) + rm -rf @DX_DOCDIR@ + $(DX_ENV) $(DX_DOXYGEN) $(srcdir)/$(DX_CONFIG) + +DX_CLEANFILES = \ + @DX_DOCDIR@/@PACKAGE@.tag \ + -r \ + $(DX_CLEAN_HTML) \ + $(DX_CLEAN_CHM) \ + $(DX_CLEAN_CHI) \ + $(DX_CLEAN_MAN) \ + $(DX_CLEAN_RTF) \ + $(DX_CLEAN_XML) \ + $(DX_CLEAN_PS) \ + $(DX_CLEAN_PDF) \ + $(DX_CLEAN_LATEX) + +endif DX_COND_doc diff --git a/src/c/autom4te.cache/output.0 b/src/c/autom4te.cache/output.0 new file mode 100644 index 00000000000..f7c8f6230fb --- /dev/null +++ b/src/c/autom4te.cache/output.0 @@ -0,0 +1,21096 @@ +@%:@! /bin/sh +@%:@ Guess values for system-dependent variables and create Makefiles. +@%:@ Generated by GNU Autoconf 2.69 for zookeeper C client 3.6.0. +@%:@ +@%:@ Report bugs to . +@%:@ +@%:@ +@%:@ Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +@%:@ +@%:@ +@%:@ This configure script is free software; the Free Software Foundation +@%:@ gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in @%:@( + *posix*) : + set -o posix ;; @%:@( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in @%:@( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in @%:@(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in @%:@ (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in @%:@( + *posix*) : + set -o posix ;; @%:@( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 + + test -n \"\${ZSH_VERSION+set}\${BASH_VERSION+set}\" || ( + ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + PATH=/empty FPATH=/empty; export PATH FPATH + test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ + || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in @%:@( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in @%:@ (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org and +$0: user@zookeeper.apache.org about your system, including +$0: any error possibly output before this message. Then +$0: install a modern shell, or manually run the script +$0: under such a shell if you do have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +@%:@ as_fn_unset VAR +@%:@ --------------- +@%:@ Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +@%:@ as_fn_set_status STATUS +@%:@ ----------------------- +@%:@ Set @S|@? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} @%:@ as_fn_set_status + +@%:@ as_fn_exit STATUS +@%:@ ----------------- +@%:@ Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} @%:@ as_fn_exit + +@%:@ as_fn_mkdir_p +@%:@ ------------- +@%:@ Create "@S|@as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} @%:@ as_fn_mkdir_p + +@%:@ as_fn_executable_p FILE +@%:@ ----------------------- +@%:@ Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} @%:@ as_fn_executable_p +@%:@ as_fn_append VAR VALUE +@%:@ ---------------------- +@%:@ Append the text in VALUE to the end of the definition contained in VAR. Take +@%:@ advantage of any shell optimizations that allow amortized linear growth over +@%:@ repeated appends, instead of the typical quadratic growth present in naive +@%:@ implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +@%:@ as_fn_arith ARG... +@%:@ ------------------ +@%:@ Perform arithmetic evaluation on the ARGs, and store the result in the +@%:@ global @S|@as_val. Take advantage of shells that can avoid forks. The arguments +@%:@ must be portable across @S|@(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +@%:@ as_fn_error STATUS ERROR [LINENO LOG_FD] +@%:@ ---------------------------------------- +@%:@ Output "`basename @S|@0`: error: ERROR" to stderr. If LINENO and LOG_FD are +@%:@ provided, also output the error to LOG_FD, referencing LINENO. Then exit the +@%:@ script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} @%:@ as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in @%:@((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + +SHELL=${CONFIG_SHELL-/bin/sh} + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIB@&t@OBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='zookeeper C client' +PACKAGE_TARNAME='zookeeper' +PACKAGE_VERSION='3.6.0' +PACKAGE_STRING='zookeeper C client 3.6.0' +PACKAGE_BUGREPORT='user@zookeeper.apache.org' +PACKAGE_URL='' + +ac_unique_file="src/zookeeper.c" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='am__EXEEXT_FALSE +am__EXEEXT_TRUE +LTLIBOBJS +LIB@&t@OBJS +SOLARIS_FALSE +SOLARIS_TRUE +CLOCK_GETTIME_LIBS +USEIPV6 +WANT_SYNCAPI_FALSE +WANT_SYNCAPI_TRUE +CXXCPP +CPP +LT_SYS_LIBRARY_PATH +OTOOL64 +OTOOL +LIPO +NMEDIT +DSYMUTIL +MANIFEST_TOOL +RANLIB +ac_ct_AR +AR +DLLTOOL +OBJDUMP +NM +ac_ct_DUMPBIN +DUMPBIN +LD +FGREP +EGREP +GREP +SED +host_os +host_vendor +host_cpu +host +build_os +build_vendor +build_cpu +build +LIBTOOL +LN_S +am__fastdepCXX_FALSE +am__fastdepCXX_TRUE +CXXDEPMODE +ac_ct_CXX +CXXFLAGS +CXX +am__fastdepCC_FALSE +am__fastdepCC_TRUE +CCDEPMODE +am__nodep +AMDEPBACKSLASH +AMDEP_FALSE +AMDEP_TRUE +am__quote +am__include +DEPDIR +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +CPPUNIT_CFLAGS +AM_BACKSLASH +AM_DEFAULT_VERBOSITY +AM_DEFAULT_V +AM_V +am__untar +am__tar +AMTAR +am__leading_dot +SET_MAKE +AWK +mkdir_p +MKDIR_P +INSTALL_STRIP_PROGRAM +STRIP +install_sh +MAKEINFO +AUTOHEADER +AUTOMAKE +AUTOCONF +ACLOCAL +VERSION +PACKAGE +CYGPATH_W +am__isrc +INSTALL_DATA +INSTALL_SCRIPT +INSTALL_PROGRAM +DOXYGEN_PAPER_SIZE +DX_COND_latex_FALSE +DX_COND_latex_TRUE +DX_COND_pdf_FALSE +DX_COND_pdf_TRUE +DX_PDFLATEX +DX_FLAG_pdf +DX_COND_ps_FALSE +DX_COND_ps_TRUE +DX_EGREP +DX_DVIPS +DX_MAKEINDEX +DX_LATEX +DX_FLAG_ps +DX_COND_html_FALSE +DX_COND_html_TRUE +DX_FLAG_html +DX_COND_chi_FALSE +DX_COND_chi_TRUE +DX_FLAG_chi +DX_COND_chm_FALSE +DX_COND_chm_TRUE +DX_HHC +DX_FLAG_chm +DX_COND_xml_FALSE +DX_COND_xml_TRUE +DX_FLAG_xml +DX_COND_rtf_FALSE +DX_COND_rtf_TRUE +DX_FLAG_rtf +DX_COND_man_FALSE +DX_COND_man_TRUE +DX_FLAG_man +DX_COND_dot_FALSE +DX_COND_dot_TRUE +DX_DOT +DX_FLAG_dot +DX_COND_doc_FALSE +DX_COND_doc_TRUE +DX_PERL +DX_DOXYGEN +DX_FLAG_doc +DX_ENV +DX_DOCDIR +DX_CONFIG +DX_PROJECT +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +enable_doxygen_doc +enable_doxygen_dot +enable_doxygen_man +enable_doxygen_rtf +enable_doxygen_xml +enable_doxygen_chm +enable_doxygen_chi +enable_doxygen_html +enable_doxygen_ps +enable_doxygen_pdf +enable_silent_rules +with_cppunit +enable_dependency_tracking +enable_shared +enable_static +with_pic +enable_fast_install +with_aix_soname +with_gnu_ld +with_sysroot +enable_libtool_lock +enable_debug +with_syncapi +' + ac_precious_vars='build_alias +host_alias +target_alias +DOXYGEN_PAPER_SIZE +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CXX +CXXFLAGS +CCC +LT_SYS_LIBRARY_PATH +CPP +CXXCPP' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *=) ac_optarg= ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error $? "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error $? "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error $? "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures zookeeper C client 3.6.0 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking ...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + @<:@@S|@ac_default_prefix@:>@ + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + @<:@PREFIX@:>@ + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root @<:@DATAROOTDIR/doc/zookeeper@:>@ + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +Program names: + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM run sed PROGRAM on installed program names + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of zookeeper C client 3.6.0:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-doxygen-doc don't generate any doxygen documentation + --disable-doxygen-dot don't generate graphics for doxygen documentation + --enable-doxygen-man generate doxygen manual pages + --enable-doxygen-rtf generate doxygen RTF documentation + --enable-doxygen-xml generate doxygen XML documentation + --enable-doxygen-chm generate doxygen compressed HTML help documentation + --enable-doxygen-chi generate doxygen seperate compressed HTML help index + file + --disable-doxygen-html don't generate doxygen plain HTML documentation + --enable-doxygen-ps generate doxygen PostScript documentation + --enable-doxygen-pdf generate doxygen PDF documentation + --enable-silent-rules less verbose build output (undo: "make V=1") + --disable-silent-rules verbose build output (undo: "make V=0") + --enable-dependency-tracking + do not reject slow dependency extractors + --disable-dependency-tracking + speeds up one-time build + --enable-shared@<:@=PKGS@:>@ build shared libraries @<:@default=yes@:>@ + --enable-static@<:@=PKGS@:>@ build static libraries @<:@default=yes@:>@ + --enable-fast-install@<:@=PKGS@:>@ + optimize for fast installation @<:@default=yes@:>@ + --disable-libtool-lock avoid locking (might break parallel builds) + --enable-debug enable debug build @<:@default=no@:>@ + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --without-cppunit do not use CPPUNIT + --with-pic@<:@=PKGS@:>@ try to use only PIC/non-PIC objects @<:@default=use + both@:>@ + --with-aix-soname=aix|svr4|both + shared library versioning (aka "SONAME") variant to + provide on AIX, @<:@default=aix@:>@. + --with-gnu-ld assume the C compiler uses GNU ld @<:@default=no@:>@ + --with-sysroot@<:@=DIR@:>@ Search for dependent libraries within DIR (or the + compiler's sysroot if not specified). + --with-syncapi build with support for SyncAPI @<:@default=yes@:>@ + +Some influential environment variables: + DOXYGEN_PAPER_SIZE + a4wide (default), a4, letter, legal or executive + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CXX C++ compiler command + CXXFLAGS C++ compiler flags + LT_SYS_LIBRARY_PATH + User-defined run-time library search path. + CPP C preprocessor + CXXCPP C++ preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +zookeeper C client configure 3.6.0 +generated by GNU Autoconf 2.69 + +Copyright (C) 2012 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +@%:@ ac_fn_c_try_compile LINENO +@%:@ -------------------------- +@%:@ Try to compile conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_compile + +@%:@ ac_fn_cxx_try_compile LINENO +@%:@ ---------------------------- +@%:@ Try to compile conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_cxx_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_cxx_try_compile + +@%:@ ac_fn_c_try_link LINENO +@%:@ ----------------------- +@%:@ Try to link conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_link + +@%:@ ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +@%:@ ------------------------------------------------------- +@%:@ Tests whether HEADER exists and can be compiled using the include files in +@%:@ INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +@%:@include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_header_compile + +@%:@ ac_fn_c_try_cpp LINENO +@%:@ ---------------------- +@%:@ Try to preprocess conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_cpp + +@%:@ ac_fn_c_try_run LINENO +@%:@ ---------------------- +@%:@ Try to link conftest.@S|@ac_ext, and return whether this succeeded. Assumes +@%:@ that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_run + +@%:@ ac_fn_c_check_func LINENO FUNC VAR +@%:@ ---------------------------------- +@%:@ Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_func + +@%:@ ac_fn_cxx_try_cpp LINENO +@%:@ ------------------------ +@%:@ Try to preprocess conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_cxx_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_cxx_try_cpp + +@%:@ ac_fn_cxx_try_link LINENO +@%:@ ------------------------- +@%:@ Try to link conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_cxx_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_cxx_try_link + +@%:@ ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +@%:@ ------------------------------------------------------- +@%:@ Tests whether HEADER exists, giving a warning if it cannot be compiled using +@%:@ the include files in INCLUDES and setting the cache variable VAR +@%:@ accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if eval \${$3+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +@%:@include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.i conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( $as_echo "## ---------------------------------------- ## +## Report this to user@zookeeper.apache.org ## +## ---------------------------------------- ##" + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_header_mongrel + +@%:@ ac_fn_c_check_type LINENO TYPE VAR INCLUDES +@%:@ ------------------------------------------- +@%:@ Tests whether TYPE exists after having included INCLUDES, setting cache +@%:@ variable VAR accordingly. +ac_fn_c_check_type () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=no" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof ($2)) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof (($2))) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + eval "$3=yes" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_type +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by zookeeper C client $as_me 3.6.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + $as_echo "## ---------------- ## +## Cache variables. ## +## ---------------- ##" + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + $as_echo "## ----------------- ## +## Output variables. ## +## ----------------- ##" + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + $as_echo "## ------------------- ## +## File substitutions. ## +## ------------------- ##" + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + $as_echo "## ----------- ## +## confdefs.h. ## +## ----------- ##" + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + # We do not want a PATH search for config.site. + case $CONFIG_SITE in @%:@(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" \ + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + +# Save initial CFLAGS and CXXFLAGS values before AC_PROG_CC and AC_PROG_CXX +init_cflags="$CFLAGS" +init_cxxflags="$CXXFLAGS" + +# initialize Doxygen support + + + + + + + + + + +# Files: +DX_PROJECT=zookeeper + +DX_CONFIG=c-doc.Doxyfile + +DX_DOCDIR=docs + + +# Environment variables used inside doxygen.cfg: +DX_ENV="$DX_ENV SRCDIR='$srcdir'" + +DX_ENV="$DX_ENV PROJECT='$DX_PROJECT'" + +DX_ENV="$DX_ENV DOCDIR='$DX_DOCDIR'" + +DX_ENV="$DX_ENV VERSION='$PACKAGE_VERSION'" + + +# Doxygen itself: + + + + @%:@ Check whether --enable-doxygen-doc was given. +if test "${enable_doxygen_doc+set}" = set; then : + enableval=$enable_doxygen_doc; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_doc=1 + + +;; #( +n|N|no|No|NO) + DX_FLAG_doc=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-doc" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_doc=1 + + + +fi + +if test "$DX_FLAG_doc" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}doxygen", so it can be a program name with args. +set dummy ${ac_tool_prefix}doxygen; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DOXYGEN+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DOXYGEN in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DOXYGEN="$DX_DOXYGEN" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DOXYGEN=$ac_cv_path_DX_DOXYGEN +if test -n "$DX_DOXYGEN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOXYGEN" >&5 +$as_echo "$DX_DOXYGEN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DOXYGEN"; then + ac_pt_DX_DOXYGEN=$DX_DOXYGEN + # Extract the first word of "doxygen", so it can be a program name with args. +set dummy doxygen; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DOXYGEN+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DOXYGEN in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DOXYGEN="$ac_pt_DX_DOXYGEN" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DOXYGEN=$ac_cv_path_ac_pt_DX_DOXYGEN +if test -n "$ac_pt_DX_DOXYGEN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOXYGEN" >&5 +$as_echo "$ac_pt_DX_DOXYGEN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DOXYGEN" = x; then + DX_DOXYGEN="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DOXYGEN=$ac_pt_DX_DOXYGEN + fi +else + DX_DOXYGEN="$ac_cv_path_DX_DOXYGEN" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DOXYGEN" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: doxygen not found - will not generate any doxygen documentation" >&5 +$as_echo "$as_me: WARNING: doxygen not found - will not generate any doxygen documentation" >&2;} + DX_FLAG_doc=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}perl", so it can be a program name with args. +set dummy ${ac_tool_prefix}perl; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_PERL+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_PERL in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_PERL="$DX_PERL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_PERL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_PERL=$ac_cv_path_DX_PERL +if test -n "$DX_PERL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PERL" >&5 +$as_echo "$DX_PERL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_PERL"; then + ac_pt_DX_PERL=$DX_PERL + # Extract the first word of "perl", so it can be a program name with args. +set dummy perl; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_PERL+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_PERL in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_PERL="$ac_pt_DX_PERL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_PERL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_PERL=$ac_cv_path_ac_pt_DX_PERL +if test -n "$ac_pt_DX_PERL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PERL" >&5 +$as_echo "$ac_pt_DX_PERL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_PERL" = x; then + DX_PERL="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_PERL=$ac_pt_DX_PERL + fi +else + DX_PERL="$ac_cv_path_DX_PERL" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_PERL" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: perl not found - will not generate any doxygen documentation" >&5 +$as_echo "$as_me: WARNING: perl not found - will not generate any doxygen documentation" >&2;} + DX_FLAG_doc=0 + +fi + + : +fi +if test "$DX_FLAG_doc" = 1; then + if :; then + DX_COND_doc_TRUE= + DX_COND_doc_FALSE='#' +else + DX_COND_doc_TRUE='#' + DX_COND_doc_FALSE= +fi + + DX_ENV="$DX_ENV PERL_PATH='$DX_PERL'" + + : +else + if false; then + DX_COND_doc_TRUE= + DX_COND_doc_FALSE='#' +else + DX_COND_doc_TRUE='#' + DX_COND_doc_FALSE= +fi + + + : +fi + + +# Dot for graphics: + + + + @%:@ Check whether --enable-doxygen-dot was given. +if test "${enable_doxygen_dot+set}" = set; then : + enableval=$enable_doxygen_dot; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_dot=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-dot requires doxygen-dot" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_dot=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-dot" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_dot=1 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_dot=0 + + + +fi + +if test "$DX_FLAG_dot" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dot", so it can be a program name with args. +set dummy ${ac_tool_prefix}dot; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DOT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DOT in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DOT="$DX_DOT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DOT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DOT=$ac_cv_path_DX_DOT +if test -n "$DX_DOT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOT" >&5 +$as_echo "$DX_DOT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DOT"; then + ac_pt_DX_DOT=$DX_DOT + # Extract the first word of "dot", so it can be a program name with args. +set dummy dot; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DOT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DOT in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DOT="$ac_pt_DX_DOT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DOT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DOT=$ac_cv_path_ac_pt_DX_DOT +if test -n "$ac_pt_DX_DOT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOT" >&5 +$as_echo "$ac_pt_DX_DOT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DOT" = x; then + DX_DOT="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DOT=$ac_pt_DX_DOT + fi +else + DX_DOT="$ac_cv_path_DX_DOT" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DOT" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dot not found - will not generate graphics for doxygen documentation" >&5 +$as_echo "$as_me: WARNING: dot not found - will not generate graphics for doxygen documentation" >&2;} + DX_FLAG_dot=0 + +fi + + : +fi +if test "$DX_FLAG_dot" = 1; then + if :; then + DX_COND_dot_TRUE= + DX_COND_dot_FALSE='#' +else + DX_COND_dot_TRUE='#' + DX_COND_dot_FALSE= +fi + + DX_ENV="$DX_ENV HAVE_DOT='YES'" + + DX_ENV="$DX_ENV DOT_PATH='`expr ".$DX_DOT" : '\(\.\)[^/]*$' \| "x$DX_DOT" : 'x\(.*\)/[^/]*$'`'" + + : +else + if false; then + DX_COND_dot_TRUE= + DX_COND_dot_FALSE='#' +else + DX_COND_dot_TRUE='#' + DX_COND_dot_FALSE= +fi + + DX_ENV="$DX_ENV HAVE_DOT='NO'" + + : +fi + + +# Man pages generation: + + + + @%:@ Check whether --enable-doxygen-man was given. +if test "${enable_doxygen_man+set}" = set; then : + enableval=$enable_doxygen_man; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_man=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-man requires doxygen-man" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_man=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-man" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_man=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_man=0 + + + +fi + +if test "$DX_FLAG_man" = 1; then + + : +fi +if test "$DX_FLAG_man" = 1; then + if :; then + DX_COND_man_TRUE= + DX_COND_man_FALSE='#' +else + DX_COND_man_TRUE='#' + DX_COND_man_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_MAN='YES'" + + : +else + if false; then + DX_COND_man_TRUE= + DX_COND_man_FALSE='#' +else + DX_COND_man_TRUE='#' + DX_COND_man_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_MAN='NO'" + + : +fi + + +# RTF file generation: + + + + @%:@ Check whether --enable-doxygen-rtf was given. +if test "${enable_doxygen_rtf+set}" = set; then : + enableval=$enable_doxygen_rtf; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_rtf=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-rtf requires doxygen-rtf" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_rtf=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-rtf" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_rtf=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_rtf=0 + + + +fi + +if test "$DX_FLAG_rtf" = 1; then + + : +fi +if test "$DX_FLAG_rtf" = 1; then + if :; then + DX_COND_rtf_TRUE= + DX_COND_rtf_FALSE='#' +else + DX_COND_rtf_TRUE='#' + DX_COND_rtf_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_RTF='YES'" + + : +else + if false; then + DX_COND_rtf_TRUE= + DX_COND_rtf_FALSE='#' +else + DX_COND_rtf_TRUE='#' + DX_COND_rtf_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_RTF='NO'" + + : +fi + + +# XML file generation: + + + + @%:@ Check whether --enable-doxygen-xml was given. +if test "${enable_doxygen_xml+set}" = set; then : + enableval=$enable_doxygen_xml; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_xml=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-xml requires doxygen-xml" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_xml=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-xml" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_xml=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_xml=0 + + + +fi + +if test "$DX_FLAG_xml" = 1; then + + : +fi +if test "$DX_FLAG_xml" = 1; then + if :; then + DX_COND_xml_TRUE= + DX_COND_xml_FALSE='#' +else + DX_COND_xml_TRUE='#' + DX_COND_xml_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_XML='YES'" + + : +else + if false; then + DX_COND_xml_TRUE= + DX_COND_xml_FALSE='#' +else + DX_COND_xml_TRUE='#' + DX_COND_xml_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_XML='NO'" + + : +fi + + +# (Compressed) HTML help generation: + + + + @%:@ Check whether --enable-doxygen-chm was given. +if test "${enable_doxygen_chm+set}" = set; then : + enableval=$enable_doxygen_chm; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_chm=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-chm requires doxygen-chm" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_chm=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-chm" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_chm=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_chm=0 + + + +fi + +if test "$DX_FLAG_chm" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}hhc", so it can be a program name with args. +set dummy ${ac_tool_prefix}hhc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_HHC+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_HHC in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_HHC="$DX_HHC" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_HHC="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_HHC=$ac_cv_path_DX_HHC +if test -n "$DX_HHC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_HHC" >&5 +$as_echo "$DX_HHC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_HHC"; then + ac_pt_DX_HHC=$DX_HHC + # Extract the first word of "hhc", so it can be a program name with args. +set dummy hhc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_HHC+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_HHC in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_HHC="$ac_pt_DX_HHC" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_HHC="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_HHC=$ac_cv_path_ac_pt_DX_HHC +if test -n "$ac_pt_DX_HHC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_HHC" >&5 +$as_echo "$ac_pt_DX_HHC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_HHC" = x; then + DX_HHC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_HHC=$ac_pt_DX_HHC + fi +else + DX_HHC="$ac_cv_path_DX_HHC" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_HHC" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&5 +$as_echo "$as_me: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&2;} + DX_FLAG_chm=0 + +fi + + : +fi +if test "$DX_FLAG_chm" = 1; then + if :; then + DX_COND_chm_TRUE= + DX_COND_chm_FALSE='#' +else + DX_COND_chm_TRUE='#' + DX_COND_chm_FALSE= +fi + + DX_ENV="$DX_ENV HHC_PATH='$DX_HHC'" + + DX_ENV="$DX_ENV GENERATE_HTML='YES'" + + DX_ENV="$DX_ENV GENERATE_HTMLHELP='YES'" + + : +else + if false; then + DX_COND_chm_TRUE= + DX_COND_chm_FALSE='#' +else + DX_COND_chm_TRUE='#' + DX_COND_chm_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_HTMLHELP='NO'" + + : +fi + + +# Seperate CHI file generation. + + + + @%:@ Check whether --enable-doxygen-chi was given. +if test "${enable_doxygen_chi+set}" = set; then : + enableval=$enable_doxygen_chi; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_chi=1 + + +test "$DX_FLAG_chm" = "1" \ +|| as_fn_error $? "doxygen-chi requires doxygen-chi" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_chi=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-chi" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_chi=0 + + +test "$DX_FLAG_chm" = "1" || DX_FLAG_chi=0 + + + +fi + +if test "$DX_FLAG_chi" = 1; then + + : +fi +if test "$DX_FLAG_chi" = 1; then + if :; then + DX_COND_chi_TRUE= + DX_COND_chi_FALSE='#' +else + DX_COND_chi_TRUE='#' + DX_COND_chi_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_CHI='YES'" + + : +else + if false; then + DX_COND_chi_TRUE= + DX_COND_chi_FALSE='#' +else + DX_COND_chi_TRUE='#' + DX_COND_chi_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_CHI='NO'" + + : +fi + + +# Plain HTML pages generation: + + + + @%:@ Check whether --enable-doxygen-html was given. +if test "${enable_doxygen_html+set}" = set; then : + enableval=$enable_doxygen_html; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_html=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-html requires doxygen-html" "$LINENO" 5 + +test "$DX_FLAG_chm" = "0" \ +|| as_fn_error $? "doxygen-html contradicts doxygen-html" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_html=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-html" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_html=1 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_html=0 + + +test "$DX_FLAG_chm" = "0" || DX_FLAG_html=0 + + + +fi + +if test "$DX_FLAG_html" = 1; then + + : +fi +if test "$DX_FLAG_html" = 1; then + if :; then + DX_COND_html_TRUE= + DX_COND_html_FALSE='#' +else + DX_COND_html_TRUE='#' + DX_COND_html_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_HTML='YES'" + + : +else + if false; then + DX_COND_html_TRUE= + DX_COND_html_FALSE='#' +else + DX_COND_html_TRUE='#' + DX_COND_html_FALSE= +fi + + test "$DX_FLAG_chm" = 1 || DX_ENV="$DX_ENV GENERATE_HTML='NO'" + + : +fi + + +# PostScript file generation: + + + + @%:@ Check whether --enable-doxygen-ps was given. +if test "${enable_doxygen_ps+set}" = set; then : + enableval=$enable_doxygen_ps; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_ps=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-ps requires doxygen-ps" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_ps=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-ps" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_ps=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_ps=0 + + + +fi + +if test "$DX_FLAG_ps" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}latex", so it can be a program name with args. +set dummy ${ac_tool_prefix}latex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_LATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_LATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_LATEX="$DX_LATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_LATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_LATEX=$ac_cv_path_DX_LATEX +if test -n "$DX_LATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_LATEX" >&5 +$as_echo "$DX_LATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_LATEX"; then + ac_pt_DX_LATEX=$DX_LATEX + # Extract the first word of "latex", so it can be a program name with args. +set dummy latex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_LATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_LATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_LATEX="$ac_pt_DX_LATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_LATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_LATEX=$ac_cv_path_ac_pt_DX_LATEX +if test -n "$ac_pt_DX_LATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_LATEX" >&5 +$as_echo "$ac_pt_DX_LATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_LATEX" = x; then + DX_LATEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_LATEX=$ac_pt_DX_LATEX + fi +else + DX_LATEX="$ac_cv_path_DX_LATEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_LATEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: latex not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: latex not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args. +set dummy ${ac_tool_prefix}makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX +if test -n "$DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5 +$as_echo "$DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_MAKEINDEX"; then + ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX + # Extract the first word of "makeindex", so it can be a program name with args. +set dummy makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX +if test -n "$ac_pt_DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5 +$as_echo "$ac_pt_DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_MAKEINDEX" = x; then + DX_MAKEINDEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX + fi +else + DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_MAKEINDEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dvips", so it can be a program name with args. +set dummy ${ac_tool_prefix}dvips; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DVIPS+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DVIPS in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DVIPS="$DX_DVIPS" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DVIPS=$ac_cv_path_DX_DVIPS +if test -n "$DX_DVIPS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DVIPS" >&5 +$as_echo "$DX_DVIPS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DVIPS"; then + ac_pt_DX_DVIPS=$DX_DVIPS + # Extract the first word of "dvips", so it can be a program name with args. +set dummy dvips; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DVIPS+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DVIPS in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DVIPS="$ac_pt_DX_DVIPS" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DVIPS=$ac_cv_path_ac_pt_DX_DVIPS +if test -n "$ac_pt_DX_DVIPS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DVIPS" >&5 +$as_echo "$ac_pt_DX_DVIPS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DVIPS" = x; then + DX_DVIPS="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DVIPS=$ac_pt_DX_DVIPS + fi +else + DX_DVIPS="$ac_cv_path_DX_DVIPS" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DVIPS" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args. +set dummy ${ac_tool_prefix}egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_EGREP=$ac_cv_path_DX_EGREP +if test -n "$DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5 +$as_echo "$DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_EGREP"; then + ac_pt_DX_EGREP=$DX_EGREP + # Extract the first word of "egrep", so it can be a program name with args. +set dummy egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP +if test -n "$ac_pt_DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5 +$as_echo "$ac_pt_DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_EGREP" = x; then + DX_EGREP="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_EGREP=$ac_pt_DX_EGREP + fi +else + DX_EGREP="$ac_cv_path_DX_EGREP" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_EGREP" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + : +fi +if test "$DX_FLAG_ps" = 1; then + if :; then + DX_COND_ps_TRUE= + DX_COND_ps_FALSE='#' +else + DX_COND_ps_TRUE='#' + DX_COND_ps_FALSE= +fi + + + : +else + if false; then + DX_COND_ps_TRUE= + DX_COND_ps_FALSE='#' +else + DX_COND_ps_TRUE='#' + DX_COND_ps_FALSE= +fi + + + : +fi + + +# PDF file generation: + + + + @%:@ Check whether --enable-doxygen-pdf was given. +if test "${enable_doxygen_pdf+set}" = set; then : + enableval=$enable_doxygen_pdf; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_pdf=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-pdf requires doxygen-pdf" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_pdf=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-pdf" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_pdf=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_pdf=0 + + + +fi + +if test "$DX_FLAG_pdf" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pdflatex", so it can be a program name with args. +set dummy ${ac_tool_prefix}pdflatex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_PDFLATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_PDFLATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_PDFLATEX="$DX_PDFLATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_PDFLATEX=$ac_cv_path_DX_PDFLATEX +if test -n "$DX_PDFLATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PDFLATEX" >&5 +$as_echo "$DX_PDFLATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_PDFLATEX"; then + ac_pt_DX_PDFLATEX=$DX_PDFLATEX + # Extract the first word of "pdflatex", so it can be a program name with args. +set dummy pdflatex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_PDFLATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_PDFLATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_PDFLATEX="$ac_pt_DX_PDFLATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_PDFLATEX=$ac_cv_path_ac_pt_DX_PDFLATEX +if test -n "$ac_pt_DX_PDFLATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PDFLATEX" >&5 +$as_echo "$ac_pt_DX_PDFLATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_PDFLATEX" = x; then + DX_PDFLATEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_PDFLATEX=$ac_pt_DX_PDFLATEX + fi +else + DX_PDFLATEX="$ac_cv_path_DX_PDFLATEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_PDFLATEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args. +set dummy ${ac_tool_prefix}makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX +if test -n "$DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5 +$as_echo "$DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_MAKEINDEX"; then + ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX + # Extract the first word of "makeindex", so it can be a program name with args. +set dummy makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX +if test -n "$ac_pt_DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5 +$as_echo "$ac_pt_DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_MAKEINDEX" = x; then + DX_MAKEINDEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX + fi +else + DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_MAKEINDEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args. +set dummy ${ac_tool_prefix}egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_EGREP=$ac_cv_path_DX_EGREP +if test -n "$DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5 +$as_echo "$DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_EGREP"; then + ac_pt_DX_EGREP=$DX_EGREP + # Extract the first word of "egrep", so it can be a program name with args. +set dummy egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP +if test -n "$ac_pt_DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5 +$as_echo "$ac_pt_DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_EGREP" = x; then + DX_EGREP="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_EGREP=$ac_pt_DX_EGREP + fi +else + DX_EGREP="$ac_cv_path_DX_EGREP" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_EGREP" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + : +fi +if test "$DX_FLAG_pdf" = 1; then + if :; then + DX_COND_pdf_TRUE= + DX_COND_pdf_FALSE='#' +else + DX_COND_pdf_TRUE='#' + DX_COND_pdf_FALSE= +fi + + + : +else + if false; then + DX_COND_pdf_TRUE= + DX_COND_pdf_FALSE='#' +else + DX_COND_pdf_TRUE='#' + DX_COND_pdf_FALSE= +fi + + + : +fi + + +# LaTeX generation for PS and/or PDF: +if test "$DX_FLAG_ps" = 1 || test "$DX_FLAG_pdf" = 1; then + if :; then + DX_COND_latex_TRUE= + DX_COND_latex_FALSE='#' +else + DX_COND_latex_TRUE='#' + DX_COND_latex_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_LATEX='YES'" + +else + if false; then + DX_COND_latex_TRUE= + DX_COND_latex_FALSE='#' +else + DX_COND_latex_TRUE='#' + DX_COND_latex_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_LATEX='NO'" + +fi + +# Paper size for PS and/or PDF: + +case "$DOXYGEN_PAPER_SIZE" in +#( +"") + DOXYGEN_PAPER_SIZE="" + +;; #( +a4wide|a4|letter|legal|executive) + DX_ENV="$DX_ENV PAPER_SIZE='$DOXYGEN_PAPER_SIZE'" + +;; #( +*) + as_fn_error $? "unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'" "$LINENO" 5 +;; +esac + +#For debugging: +#echo DX_FLAG_doc=$DX_FLAG_doc +#echo DX_FLAG_dot=$DX_FLAG_dot +#echo DX_FLAG_man=$DX_FLAG_man +#echo DX_FLAG_html=$DX_FLAG_html +#echo DX_FLAG_chm=$DX_FLAG_chm +#echo DX_FLAG_chi=$DX_FLAG_chi +#echo DX_FLAG_rtf=$DX_FLAG_rtf +#echo DX_FLAG_xml=$DX_FLAG_xml +#echo DX_FLAG_pdf=$DX_FLAG_pdf +#echo DX_FLAG_ps=$DX_FLAG_ps +#echo DX_ENV=$DX_ENV + + +# initialize automake +am__api_version='1.15' + +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if ${ac_cv_path_install+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in @%:@(( + ./ | .// | /[cC]/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + + done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +$as_echo_n "checking whether build environment is sane... " >&6; } +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[\\\"\#\$\&\'\`$am_lf]*) + as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; +esac +case $srcdir in + *[\\\"\#\$\&\'\`$am_lf\ \ ]*) + as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; +esac + +# Do 'set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + as_fn_error $? "ls -t appears to fail. Make sure there is not a broken + alias in your environment" "$LINENO" 5 + fi + if test "$2" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done + test "$2" = conftest.file + ) +then + # Ok. + : +else + as_fn_error $? "newly created file is older than distributed files! +Check your system clock" "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi + +rm -f conftest.file + +test "$program_prefix" != NONE && + program_transform_name="s&^&$program_prefix&;$program_transform_name" +# Use a double $ so make ignores it. +test "$program_suffix" != NONE && + program_transform_name="s&\$&$program_suffix&;$program_transform_name" +# Double any \ or $. +# By default was `s,x,x', remove it if useless. +ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' +program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` + +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` + +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --is-lightweight"; then + am_missing_run="$MISSING " +else + am_missing_run= + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} +fi + +if test x"${install_sh+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi + +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the 'STRIP' environment variable to overrule this program. +if test "$cross_compiling" != no; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } +if test -z "$MKDIR_P"; then + if ${ac_cv_path_mkdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done + done +IFS=$as_save_IFS + +fi + + test -d ./--version && rmdir ./--version + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + MKDIR_P="$ac_install_sh -d" + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } + +for ac_prog in gawk mawk nawk awk +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AWK+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AWK"; then + ac_cv_prog_AWK="$AWK" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AWK="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AWK=$ac_cv_prog_AWK +if test -n "$AWK"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +$as_echo "$AWK" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AWK" && break +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +set x ${MAKE-make} +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering ...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null + +@%:@ Check whether --enable-silent-rules was given. +if test "${enable_silent_rules+set}" = set; then : + enableval=$enable_silent_rules; +fi + +case $enable_silent_rules in @%:@ ((( + yes) AM_DEFAULT_VERBOSITY=0;; + no) AM_DEFAULT_VERBOSITY=1;; + *) AM_DEFAULT_VERBOSITY=1;; +esac +am_make=${MAKE-make} +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +$as_echo_n "checking whether $am_make supports nested variables... " >&6; } +if ${am_cv_make_support_nested_variables+:} false; then : + $as_echo_n "(cached) " >&6 +else + if $as_echo 'TRUE=$(BAR$(V)) +BAR0=false +BAR1=true +V=1 +am__doit: + @$(TRUE) +.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then + am_cv_make_support_nested_variables=yes +else + am_cv_make_support_nested_variables=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +$as_echo "$am_cv_make_support_nested_variables" >&6; } +if test $am_cv_make_support_nested_variables = yes; then + AM_V='$(V)' + AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' +else + AM_V=$AM_DEFAULT_VERBOSITY + AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY +fi +AM_BACKSLASH='\' + +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + am__isrc=' -I$(srcdir)' + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi + + +# Define the identity of the package. + PACKAGE='zookeeper' + VERSION='3.6.0' + + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE "$PACKAGE" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +@%:@define VERSION "$VERSION" +_ACEOF + +# Some tools Automake needs. + +ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} + + +AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} + + +AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} + + +AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} + + +MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} + +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +mkdir_p='$(MKDIR_P)' + +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. +# Always define AMTAR for backward compatibility. Yes, it's still used +# in the wild :-( We should find a proper way to deprecate it ... +AMTAR='$${TAR-tar}' + + +# We'll loop over all known methods to create a tar archive until one works. +_am_tools='gnutar pax cpio none' + +am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' + + + + + + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 + fi +fi + +ac_config_headers="$ac_config_headers config.h" + + +# Checks for programs. + +@%:@ Check whether --with-cppunit was given. +if test "${with_cppunit+set}" = set; then : + withval=$with_cppunit; +fi + + +if test "$with_cppunit" = "no" ; then + CPPUNIT_PATH="No_CPPUNIT" + CPPUNIT_INCLUDE= + CPPUNIT_LIBS= +else + AM_PATH_CPPUNIT(1.10.2) +fi + +if test "$CALLER" = "ANT" ; then +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"${base_dir}/src/c/tests/zkServer.sh\\\"\"" +else +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"./tests/zkServer.sh\\\"\"" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for generated/zookeeper.jute.c" >&5 +$as_echo_n "checking for generated/zookeeper.jute.c... " >&6; } +if ${ac_cv_file_generated_zookeeper_jute_c+:} false; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "generated/zookeeper.jute.c"; then + ac_cv_file_generated_zookeeper_jute_c=yes +else + ac_cv_file_generated_zookeeper_jute_c=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file_generated_zookeeper_jute_c" >&5 +$as_echo "$ac_cv_file_generated_zookeeper_jute_c" >&6; } +if test "x$ac_cv_file_generated_zookeeper_jute_c" = xyes; then : + +cat >>confdefs.h <<_ACEOF +@%:@define HAVE_GENERATED_ZOOKEEPER_JUTE_C 1 +_ACEOF + +else + as_fn_error $? "jute files are missing! Please run \"ant compile_jute\" while in the zookeeper top level directory." "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for generated/zookeeper.jute.h" >&5 +$as_echo_n "checking for generated/zookeeper.jute.h... " >&6; } +if ${ac_cv_file_generated_zookeeper_jute_h+:} false; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "generated/zookeeper.jute.h"; then + ac_cv_file_generated_zookeeper_jute_h=yes +else + ac_cv_file_generated_zookeeper_jute_h=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file_generated_zookeeper_jute_h" >&5 +$as_echo "$ac_cv_file_generated_zookeeper_jute_h" >&6; } +if test "x$ac_cv_file_generated_zookeeper_jute_h" = xyes; then : + +cat >>confdefs.h <<_ACEOF +@%:@define HAVE_GENERATED_ZOOKEEPER_JUTE_H 1 +_ACEOF + +else + as_fn_error $? "jute files are missing! Please run \"ant compile_jute\" while in the zookeeper top level directory." "$LINENO" 5 + +fi + +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $@%:@ != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "C compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if ${ac_cv_objext+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of object files: cannot compile +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +$as_echo_n "checking whether $CC understands -c and -o together... " >&6; } +if ${am_cv_prog_cc_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 + ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +$as_echo "$am_cv_prog_cc_c_o" >&6; } +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +DEPDIR="${am__leading_dot}deps" + +ac_config_commands="$ac_config_commands depfiles" + + +am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 +$as_echo_n "checking for style of include used by $am_make... " >&6; } +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from 'make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 +$as_echo "$_am_result" >&6; } +rm -f confinc confmf + +@%:@ Check whether --enable-dependency-tracking was given. +if test "${enable_dependency_tracking+set}" = set; then : + enableval=$enable_dependency_tracking; +fi + +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' + am__nodep='_no' +fi + if test "x$enable_dependency_tracking" != xno; then + AMDEP_TRUE= + AMDEP_FALSE='#' +else + AMDEP_TRUE='#' + AMDEP_FALSE= +fi + + + +depcc="$CC" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CC_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CC_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CC_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CC_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } +CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then + am__fastdepCC_TRUE= + am__fastdepCC_FALSE='#' +else + am__fastdepCC_TRUE='#' + am__fastdepCC_FALSE= +fi + + + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CXX"; then + ac_cv_prog_CXX="$CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 +$as_echo "$CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 +$as_echo "$ac_ct_CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 +$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } +if ${ac_cv_cxx_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 +$as_echo "$ac_cv_cxx_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GXX=yes +else + GXX= +fi +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 +$as_echo_n "checking whether $CXX accepts -g... " >&6; } +if ${ac_cv_prog_cxx_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +else + CXXFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + +else + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 +$as_echo "$ac_cv_prog_cxx_g" >&6; } +if test "$ac_test_CXXFLAGS" = set; then + CXXFLAGS=$ac_save_CXXFLAGS +elif test $ac_cv_prog_cxx_g = yes; then + if test "$GXX" = yes; then + CXXFLAGS="-g -O2" + else + CXXFLAGS="-g" + fi +else + if test "$GXX" = yes; then + CXXFLAGS="-O2" + else + CXXFLAGS= + fi +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +depcc="$CXX" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CXX_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CXX_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CXX_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CXX_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CXX_dependencies_compiler_type" >&6; } +CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then + am__fastdepCXX_TRUE= + am__fastdepCXX_FALSE='#' +else + am__fastdepCXX_TRUE='#' + am__fastdepCXX_FALSE= +fi + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +$as_echo_n "checking whether ln -s works... " >&6; } +LN_S=$as_ln_s +if test "$LN_S" = "ln -s"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +$as_echo "no, using $LN_S" >&6; } +fi + + +# AC_DISABLE_SHARED +case `pwd` in + *\ * | *\ *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; +esac + + + +macro_version='2.4.6' +macro_revision='2.4.6' + + + + + + + + + + + + + +ltmain=$ac_aux_dir/ltmain.sh + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if ${ac_cv_build+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if ${ac_cv_host+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + +# Backslashify metacharacters that are still active within +# double-quoted strings. +sed_quote_subst='s/\(["`$\\]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +$as_echo_n "checking how to print strings... " >&6; } +# Test print first, because it will be a builtin if present. +if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ + test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='print -r --' +elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='printf %s\n' +else + # Use this function as a fallback that always works. + func_fallback_echo () + { + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' + } + ECHO='func_fallback_echo' +fi + +# func_echo_all arg... +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "" +} + +case $ECHO in + printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +$as_echo "printf" >&6; } ;; + print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +$as_echo "print -r" >&6; } ;; + *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +$as_echo "cat" >&6; } ;; +esac + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +$as_echo_n "checking for a sed that does not truncate output... " >&6; } +if ${ac_cv_path_SED+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for ac_i in 1 2 3 4 5 6 7; do + ac_script="$ac_script$as_nl$ac_script" + done + echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed + { ac_script=; unset ac_script;} + if test -z "$SED"; then + ac_path_SED_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_SED" || continue +# Check for GNU ac_path_SED and select it if it is found. + # Check for GNU $ac_path_SED +case `"$ac_path_SED" --version 2>&1` in +*GNU*) + ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo '' >> "conftest.nl" + "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_SED_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_SED="$ac_path_SED" + ac_path_SED_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_SED_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_SED"; then + as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 + fi +else + ac_cv_path_SED=$SED +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +$as_echo "$ac_cv_path_SED" >&6; } + SED="$ac_cv_path_SED" + rm -f conftest.sed + +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_GREP" || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if ${ac_cv_path_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_EGREP" || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +$as_echo_n "checking for fgrep... " >&6; } +if ${ac_cv_path_FGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 + then ac_cv_path_FGREP="$GREP -F" + else + if test -z "$FGREP"; then + ac_path_FGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in fgrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_FGREP" || continue +# Check for GNU ac_path_FGREP and select it if it is found. + # Check for GNU $ac_path_FGREP +case `"$ac_path_FGREP" --version 2>&1` in +*GNU*) + ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'FGREP' >> "conftest.nl" + "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_FGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_FGREP="$ac_path_FGREP" + ac_path_FGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_FGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_FGREP"; then + as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_FGREP=$FGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +$as_echo "$ac_cv_path_FGREP" >&6; } + FGREP="$ac_cv_path_FGREP" + + +test -z "$GREP" && GREP=grep + + + + + + + + + + + + + + + + + + + +@%:@ Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if ${lt_cv_path_NM+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM=$NM +else + lt_nm_to_check=${ac_tool_prefix}nm + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + tmp_nm=$ac_dir/$lt_tmp_nm + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the 'sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty + case $build_os in + mingw*) lt_bad_file=conftest.nm/nofile ;; + *) lt_bad_file=/dev/null ;; + esac + case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +$as_echo "$lt_cv_path_NM" >&6; } +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + if test -n "$ac_tool_prefix"; then + for ac_prog in dumpbin "link -dump" + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DUMPBIN"; then + ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DUMPBIN=$ac_cv_prog_DUMPBIN +if test -n "$DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +$as_echo "$DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$DUMPBIN" && break + done +fi +if test -z "$DUMPBIN"; then + ac_ct_DUMPBIN=$DUMPBIN + for ac_prog in dumpbin "link -dump" +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DUMPBIN"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN +if test -n "$ac_ct_DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +$as_echo "$ac_ct_DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_DUMPBIN" && break +done + + if test "x$ac_ct_DUMPBIN" = x; then + DUMPBIN=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DUMPBIN=$ac_ct_DUMPBIN + fi +fi + + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +$as_echo_n "checking the name lister ($NM) interface... " >&6; } +if ${lt_cv_nm_interface+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: output\"" >&5) + cat conftest.out >&5 + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +$as_echo "$lt_cv_nm_interface" >&6; } + +# find the maximum length of command line arguments +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +$as_echo_n "checking the maximum length of command line arguments... " >&6; } +if ${lt_cv_sys_max_cmd_len+:} false; then : + $as_echo_n "(cached) " >&6 +else + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac + +fi + +if test -n "$lt_cv_sys_max_cmd_len"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +$as_echo "$lt_cv_sys_max_cmd_len" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 +$as_echo "none" >&6; } +fi +max_cmd_len=$lt_cv_sys_max_cmd_len + + + + + + +: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi + + + + + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +$as_echo_n "checking how to convert $build file names to $host format... " >&6; } +if ${lt_cv_to_host_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 + ;; + esac + ;; + *-*-cygwin* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin + ;; + esac + ;; + * ) # unhandled hosts (and "normal" native builds) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; +esac + +fi + +to_host_file_cmd=$lt_cv_to_host_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +$as_echo "$lt_cv_to_host_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; } +if ${lt_cv_to_tool_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + #assume ordinary cross tools, or native build. +lt_cv_to_tool_file_cmd=func_convert_file_noop +case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 + ;; + esac + ;; +esac + +fi + +to_tool_file_cmd=$lt_cv_to_tool_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +$as_echo "$lt_cv_to_tool_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +$as_echo_n "checking for $LD option to reload object files... " >&6; } +if ${lt_cv_ld_reload_flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_reload_flag='-r' +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +$as_echo "$lt_cv_ld_reload_flag" >&6; } +reload_flag=$lt_cv_ld_reload_flag +case $reload_flag in +"" | " "*) ;; +*) reload_flag=" $reload_flag" ;; +esac +reload_cmds='$LD$reload_flag -o $output$reload_objs' +case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + if test yes != "$GCC"; then + reload_cmds=false + fi + ;; + darwin*) + if test yes = "$GCC"; then + reload_cmds='$LTCC $LTCFLAGS -nostdlib $wl-r -o $output$reload_objs' + else + reload_cmds='$LD$reload_flag -o $output$reload_objs' + fi + ;; +esac + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. +set dummy ${ac_tool_prefix}objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OBJDUMP"; then + ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OBJDUMP=$ac_cv_prog_OBJDUMP +if test -n "$OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OBJDUMP"; then + ac_ct_OBJDUMP=$OBJDUMP + # Extract the first word of "objdump", so it can be a program name with args. +set dummy objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OBJDUMP"; then + ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OBJDUMP="objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP +if test -n "$ac_ct_OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OBJDUMP" = x; then + OBJDUMP="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OBJDUMP=$ac_ct_OBJDUMP + fi +else + OBJDUMP="$ac_cv_prog_OBJDUMP" +fi + +test -z "$OBJDUMP" && OBJDUMP=objdump + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +$as_echo_n "checking how to recognize dependent libraries... " >&6; } +if ${lt_cv_deplibs_check_method+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# 'unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# that responds to the $file_magic_cmd with a given extended regex. +# If you have 'file' or equivalent on your system and you're not sure +# whether 'pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[4-9]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[45]*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc*) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +haiku*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]' + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9]\.[0-9]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[3-9]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd* | bitrig*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +os2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +$as_echo "$lt_cv_deplibs_check_method" >&6; } + +file_magic_glob= +want_nocaseglob=no +if test "$build" = "$host"; then + case $host_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes + else + file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[\1]\/[\1]\/g;/g"` + fi + ;; + esac +fi + +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + + + + + + + + + + + + + + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. +set dummy ${ac_tool_prefix}dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DLLTOOL"; then + ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DLLTOOL=$ac_cv_prog_DLLTOOL +if test -n "$DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +$as_echo "$DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DLLTOOL"; then + ac_ct_DLLTOOL=$DLLTOOL + # Extract the first word of "dlltool", so it can be a program name with args. +set dummy dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DLLTOOL"; then + ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DLLTOOL="dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL +if test -n "$ac_ct_DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +$as_echo "$ac_ct_DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DLLTOOL" = x; then + DLLTOOL="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DLLTOOL=$ac_ct_DLLTOOL + fi +else + DLLTOOL="$ac_cv_prog_DLLTOOL" +fi + +test -z "$DLLTOOL" && DLLTOOL=dlltool + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +$as_echo_n "checking how to associate runtime and link libraries... " >&6; } +if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_sharedlib_from_linklib_cmd='unknown' + +case $host_os in +cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL + case `$DLLTOOL --help 2>&1` in + *--identify-strict*) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib + ;; + *) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback + ;; + esac + ;; +*) + # fallback: assume linklib IS sharedlib + lt_cv_sharedlib_from_linklib_cmd=$ECHO + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; } +sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd +test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO + + + + + + + + +if test -n "$ac_tool_prefix"; then + for ac_prog in ar + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AR="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AR" && break + done +fi +if test -z "$AR"; then + ac_ct_AR=$AR + for ac_prog in ar +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_AR="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_AR" && break +done + + if test "x$ac_ct_AR" = x; then + AR="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +fi + +: ${AR=ar} +: ${AR_FLAGS=cru} + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +$as_echo_n "checking for archiver @FILE support... " >&6; } +if ${lt_cv_ar_at_file+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ar_at_file=no + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + echo conftest.$ac_objext > conftest.lst + lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -eq "$ac_status"; then + # Ensure the archiver fails upon bogus file names. + rm -f conftest.$ac_objext libconftest.a + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -ne "$ac_status"; then + lt_cv_ar_at_file=@ + fi + fi + rm -f conftest.* libconftest.a + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +$as_echo "$lt_cv_ar_at_file" >&6; } + +if test no = "$lt_cv_ar_at_file"; then + archiver_list_spec= +else + archiver_list_spec=$lt_cv_ar_at_file +fi + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +test -z "$STRIP" && STRIP=: + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +test -z "$RANLIB" && RANLIB=: + + + + + + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" +fi + +case $host_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) + lock_old_archive_extraction=no ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# Check for command to grab the raw symbol name followed by C symbol from nm. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } +if ${lt_cv_sys_global_symbol_pipe+:} false; then : + $as_echo_n "(cached) " >&6 +else + +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[BCDEGRST]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([_A-Za-z][_A-Za-z0-9]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[BCDT]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[ABCDGISTW]' + ;; +hpux*) + if test ia64 = "$host_cpu"; then + symcode='[ABCDEGRST]' + fi + ;; +irix* | nonstopux*) + symcode='[BCDEGRST]' + ;; +osf*) + symcode='[BCDEGQRST]' + ;; +solaris*) + symcode='[BDRT]' + ;; +sco3.2v5*) + symcode='[DT]' + ;; +sysv4.2uw2*) + symcode='[DT]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[ABDT]' + ;; +sysv4) + symcode='[DFNSTU]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[ABCDGIRSTW]' ;; +esac + +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Gets list of data symbols to import. + lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + # Adjust the below global symbol transforms to fixup imported variables. + lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" + lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" + lt_c_name_lib_hook="\ + -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ + -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" +else + # Disable hooks by default. + lt_cv_sys_global_symbol_to_import= + lt_cdecl_hook= + lt_c_name_hook= + lt_c_name_lib_hook= +fi + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +$lt_cdecl_hook\ +" -e 's/^T .* \(.*\)$/extern int \1();/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +$lt_c_name_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" + +# Transform an extracted symbol line into symbol name with lib prefix and +# symbol address. +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +$lt_c_name_lib_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function, + # D for any global variable and I for any imported variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK '"\ +" {last_section=section; section=\$ 3};"\ +" /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ +" /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ +" /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ +" {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ +" s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Now try to grab the symbols. + nlist=conftest.nm + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 + (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT@&t@_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT@&t@_DLSYM_CONST +#else +# define LT@&t@_DLSYM_CONST const +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +LT@&t@_DLSYM_CONST struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_globsym_save_LIBS=$LIBS + lt_globsym_save_CFLAGS=$CFLAGS + LIBS=conftstm.$ac_objext + CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s conftest$ac_exeext; then + pipe_works=yes + fi + LIBS=$lt_globsym_save_LIBS + CFLAGS=$lt_globsym_save_CFLAGS + else + echo "cannot find nm_test_func in $nlist" >&5 + fi + else + echo "cannot find nm_test_var in $nlist" >&5 + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 + fi + else + echo "$progname: failed program was:" >&5 + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test yes = "$pipe_works"; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done + +fi + +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +$as_echo "failed" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } +fi + +# Response file support. +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + nm_file_list_spec='@' +elif $NM --help 2>/dev/null | grep '[@]FILE' >/dev/null; then + nm_file_list_spec='@' +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +$as_echo_n "checking for sysroot... " >&6; } + +@%:@ Check whether --with-sysroot was given. +if test "${with_sysroot+set}" = set; then : + withval=$with_sysroot; +else + with_sysroot=no +fi + + +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +$as_echo "$with_sysroot" >&6; } + as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5 + ;; +esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +$as_echo "${lt_sysroot:-no}" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +$as_echo_n "checking for a working dd... " >&6; } +if ${ac_cv_path_lt_DD+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +: ${lt_DD:=$DD} +if test -z "$lt_DD"; then + ac_path_lt_DD_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in dd; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_lt_DD="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_lt_DD" || continue +if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: +fi + $ac_path_lt_DD_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_lt_DD"; then + : + fi +else + ac_cv_path_lt_DD=$lt_DD +fi + +rm -f conftest.i conftest2.i conftest.out +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +$as_echo "$ac_cv_path_lt_DD" >&6; } + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +$as_echo_n "checking how to truncate binary pipes... " >&6; } +if ${lt_cv_truncate_bin+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +lt_cv_truncate_bin= +if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" +fi +rm -f conftest.i conftest2.i conftest.out +test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +$as_echo "$lt_cv_truncate_bin" >&6; } + + + + + + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in @S|@*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + +@%:@ Check whether --enable-libtool-lock was given. +if test "${enable_libtool_lock+set}" = set; then : + enableval=$enable_libtool_lock; +fi + +test no = "$enable_libtool_lock" || enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE=32 + ;; + *ELF-64*) + HPUX_IA64_MODE=64 + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + if test yes = "$lt_cv_prog_gnu_ld"; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +mips64*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + emul=elf + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + emul="${emul}32" + ;; + *64-bit*) + emul="${emul}64" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *MSB*) + emul="${emul}btsmip" + ;; + *LSB*) + emul="${emul}ltsmip" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *N32*) + emul="${emul}n32" + ;; + esac + LD="${LD-ld} -m $emul" + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. Note that the listed cases only cover the + # situations where additional linker options are needed (such as when + # doing 32-bit compilation for a host where ld defaults to 64-bit, or + # vice versa); the common cases where no linker options are needed do + # not appear in the list. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac + ;; + powerpc64le-*linux*) + LD="${LD-ld} -m elf32lppclinux" + ;; + powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + powerpcle-*linux*) + LD="${LD-ld} -m elf64lppc" + ;; + powerpc-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -belf" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +$as_echo_n "checking whether the C compiler needs -belf... " >&6; } +if ${lt_cv_cc_needs_belf+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_cc_needs_belf=yes +else + lt_cv_cc_needs_belf=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +$as_echo "$lt_cv_cc_needs_belf" >&6; } + if test yes != "$lt_cv_cc_needs_belf"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS=$SAVE_CFLAGS + fi + ;; +*-*solaris*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) + case $host in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; + sparc*-*-solaris*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + # GNU ld 2.21 introduced _sol2 emulations. Use them if available. + if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then + LD=${LD-ld}_sol2 + fi + ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks=$enable_libtool_lock + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args. +set dummy ${ac_tool_prefix}mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$MANIFEST_TOOL"; then + ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL +if test -n "$MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +$as_echo "$MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_MANIFEST_TOOL"; then + ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL + # Extract the first word of "mt", so it can be a program name with args. +set dummy mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_MANIFEST_TOOL"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL +if test -n "$ac_ct_MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +$as_echo "$ac_ct_MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_MANIFEST_TOOL" = x; then + MANIFEST_TOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL + fi +else + MANIFEST_TOOL="$ac_cv_prog_MANIFEST_TOOL" +fi + +test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if ${lt_cv_path_mainfest_tool+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_path_mainfest_tool=no + echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 + $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out + cat conftest.err >&5 + if $GREP 'Manifest Tool' conftest.out > /dev/null; then + lt_cv_path_mainfest_tool=yes + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 +$as_echo "$lt_cv_path_mainfest_tool" >&6; } +if test yes != "$lt_cv_path_mainfest_tool"; then + MANIFEST_TOOL=: +fi + + + + + + + case $host_os in + rhapsody* | darwin*) + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. +set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DSYMUTIL"; then + ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DSYMUTIL=$ac_cv_prog_DSYMUTIL +if test -n "$DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +$as_echo "$DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DSYMUTIL"; then + ac_ct_DSYMUTIL=$DSYMUTIL + # Extract the first word of "dsymutil", so it can be a program name with args. +set dummy dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DSYMUTIL"; then + ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL +if test -n "$ac_ct_DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +$as_echo "$ac_ct_DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DSYMUTIL" = x; then + DSYMUTIL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DSYMUTIL=$ac_ct_DSYMUTIL + fi +else + DSYMUTIL="$ac_cv_prog_DSYMUTIL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. +set dummy ${ac_tool_prefix}nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NMEDIT"; then + ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +NMEDIT=$ac_cv_prog_NMEDIT +if test -n "$NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +$as_echo "$NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_NMEDIT"; then + ac_ct_NMEDIT=$NMEDIT + # Extract the first word of "nmedit", so it can be a program name with args. +set dummy nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_NMEDIT"; then + ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_NMEDIT="nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT +if test -n "$ac_ct_NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +$as_echo "$ac_ct_NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_NMEDIT" = x; then + NMEDIT=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + NMEDIT=$ac_ct_NMEDIT + fi +else + NMEDIT="$ac_cv_prog_NMEDIT" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. +set dummy ${ac_tool_prefix}lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$LIPO"; then + ac_cv_prog_LIPO="$LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_LIPO="${ac_tool_prefix}lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +LIPO=$ac_cv_prog_LIPO +if test -n "$LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +$as_echo "$LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_LIPO"; then + ac_ct_LIPO=$LIPO + # Extract the first word of "lipo", so it can be a program name with args. +set dummy lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_LIPO"; then + ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_LIPO="lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO +if test -n "$ac_ct_LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +$as_echo "$ac_ct_LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_LIPO" = x; then + LIPO=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + LIPO=$ac_ct_LIPO + fi +else + LIPO="$ac_cv_prog_LIPO" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL"; then + ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL="${ac_tool_prefix}otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL=$ac_cv_prog_OTOOL +if test -n "$OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +$as_echo "$OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL"; then + ac_ct_OTOOL=$OTOOL + # Extract the first word of "otool", so it can be a program name with args. +set dummy otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL"; then + ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL="otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL +if test -n "$ac_ct_OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +$as_echo "$ac_ct_OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL" = x; then + OTOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL=$ac_ct_OTOOL + fi +else + OTOOL="$ac_cv_prog_OTOOL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL64"; then + ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL64=$ac_cv_prog_OTOOL64 +if test -n "$OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +$as_echo "$OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL64"; then + ac_ct_OTOOL64=$OTOOL64 + # Extract the first word of "otool64", so it can be a program name with args. +set dummy otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL64"; then + ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL64="otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 +if test -n "$ac_ct_OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +$as_echo "$ac_ct_OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL64" = x; then + OTOOL64=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL64=$ac_ct_OTOOL64 + fi +else + OTOOL64="$ac_cv_prog_OTOOL64" +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +$as_echo_n "checking for -single_module linker flag... " >&6; } +if ${lt_cv_apple_cc_single_mod+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_apple_cc_single_mod=no + if test -z "$LT_MULTI_MODULE"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + # If there is a non-empty error log, and "single_module" + # appears in it, assume the flag caused a linker warning + if test -s conftest.err && $GREP single_module conftest.err; then + cat conftest.err >&5 + # Otherwise, if the output was created with a 0 exit code from + # the compiler, it worked. + elif test -f libconftest.dylib && test 0 = "$_lt_result"; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&5 + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +$as_echo "$lt_cv_apple_cc_single_mod" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } +if ${lt_cv_ld_exported_symbols_list+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_ld_exported_symbols_list=yes +else + lt_cv_ld_exported_symbols_list=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +$as_echo "$lt_cv_ld_exported_symbols_list" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +$as_echo_n "checking for -force_load linker flag... " >&6; } +if ${lt_cv_ld_force_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 + echo "$AR cru libconftest.a conftest.o" >&5 + $AR cru libconftest.a conftest.o 2>&5 + echo "$RANLIB libconftest.a" >&5 + $RANLIB libconftest.a 2>&5 + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -s conftest.err && $GREP force_load conftest.err; then + cat conftest.err >&5 + elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&5 + fi + rm -f conftest.err libconftest.a conftest conftest.c + rm -rf conftest.dSYM + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +$as_echo "$lt_cv_ld_force_load" >&6; } + case $host_os in + rhapsody* | darwin1.[012]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[91]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test yes = "$lt_cv_apple_cc_single_mod"; then + _lt_dar_single_mod='$single_module' + fi + if test yes = "$lt_cv_ld_exported_symbols_list"; then + _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' + fi + if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x@S|@2 in + x) + ;; + *:) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" + ;; + x:*) + eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" + ;; + *) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + esac +} + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "@%:@define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +@%:@define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +for ac_header in dlfcn.h +do : + ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default +" +if test "x$ac_cv_header_dlfcn_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +@%:@define HAVE_DLFCN_H 1 +_ACEOF + +fi + +done + + + + +func_stripname_cnf () +{ + case @S|@2 in + .*) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%\\\\@S|@2\$%%"`;; + *) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%@S|@2\$%%"`;; + esac +} # func_stripname_cnf + + + + + +# Set options + + + + enable_dlopen=no + + + enable_win32_dll=no + + + @%:@ Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then : + enableval=$enable_shared; p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_shared=yes +fi + + + + + + + + + + @%:@ Check whether --enable-static was given. +if test "${enable_static+set}" = set; then : + enableval=$enable_static; p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_static=yes +fi + + + + + + + + + + +@%:@ Check whether --with-pic was given. +if test "${with_pic+set}" = set; then : + withval=$with_pic; lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + pic_mode=default +fi + + + + + + + + + @%:@ Check whether --enable-fast-install was given. +if test "${enable_fast_install+set}" = set; then : + enableval=$enable_fast_install; p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_fast_install=yes +fi + + + + + + + + + shared_archive_member_spec= +case $host,$enable_shared in +power*-*-aix[5-9]*,yes) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +$as_echo_n "checking which variant of shared library versioning to provide... " >&6; } + +@%:@ Check whether --with-aix-soname was given. +if test "${with_aix_soname+set}" = set; then : + withval=$with_aix_soname; case $withval in + aix|svr4|both) + ;; + *) + as_fn_error $? "Unknown argument to --with-aix-soname" "$LINENO" 5 + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname +else + if ${lt_cv_with_aix_soname+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_with_aix_soname=aix +fi + + with_aix_soname=$lt_cv_with_aix_soname +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +$as_echo "$with_aix_soname" >&6; } + if test aix != "$with_aix_soname"; then + # For the AIX way of multilib, we name the shared archive member + # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', + # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. + # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, + # the AIX toolchain works better with OBJECT_MODE set (default 32). + if test 64 = "${OBJECT_MODE-32}"; then + shared_archive_member_spec=shr_64 + else + shared_archive_member_spec=shr + fi + fi + ;; +*) + with_aix_soname=aix + ;; +esac + + + + + + + + + + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +test -z "$LN_S" && LN_S="ln -s" + + + + + + + + + + + + + + +if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +$as_echo_n "checking for objdir... " >&6; } +if ${lt_cv_objdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +$as_echo "$lt_cv_objdir" >&6; } +objdir=$lt_cv_objdir + + + + + +cat >>confdefs.h <<_ACEOF +@%:@define LT_OBJDIR "$lt_cv_objdir/" +_ACEOF + + + + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld=$lt_cv_prog_gnu_ld + +old_CC=$CC +old_CFLAGS=$CFLAGS + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +func_cc_basename $compiler +cc_basename=$func_cc_basename_result + + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/${ac_tool_prefix}file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"${ac_tool_prefix}file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + + + +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +$as_echo_n "checking for file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + else + MAGIC_CMD=: + fi +fi + + fi + ;; +esac + +# Use C for the default configuration in the libtool script + +lt_save_CC=$CC +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +objext=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + +lt_prog_compiler_no_builtin_flag= + +if test yes = "$GCC"; then + case $cc_basename in + nvcc*) + lt_prog_compiler_no_builtin_flag=' -Xcompiler -fno-builtin' ;; + *) + lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_rtti_exceptions=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="-fno-rtti -fno-exceptions" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_rtti_exceptions=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } + +if test yes = "$lt_cv_prog_compiler_rtti_exceptions"; then + lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" +else + : +fi + +fi + + + + + + + lt_prog_compiler_wl= +lt_prog_compiler_pic= +lt_prog_compiler_static= + + + if test yes = "$GCC"; then + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_static='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + fi + lt_prog_compiler_pic='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + ;; + + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + lt_prog_compiler_static= + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + ;; + + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic=-Kconform_pic + fi + ;; + + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + + case $cc_basename in + nvcc*) # Cuda Compiler Driver 2.2 + lt_prog_compiler_wl='-Xlinker ' + if test -n "$lt_prog_compiler_pic"; then + lt_prog_compiler_pic="-Xcompiler $lt_prog_compiler_pic" + fi + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl='-Wl,' + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + else + lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + case $cc_basename in + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static='$wl-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + # old Intel for x86_64, which still supported -KPIC. + ecc*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='--shared' + lt_prog_compiler_static='--static' + ;; + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + xl* | bgxl* | bgf* | mpixl*) + # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-qpic' + lt_prog_compiler_static='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='' + ;; + *Sun\ F* | *Sun*Fortran*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Qoption ld ' + ;; + *Sun\ C*) + # Sun C 5.9 + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Wl,' + ;; + *Intel*\ [CF]*Compiler*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + *Portland\ Group*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + esac + ;; + + newsos6) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + + rdos*) + lt_prog_compiler_static='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + lt_prog_compiler_wl='-Qoption ld ';; + *) + lt_prog_compiler_wl='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl='-Qoption ld ' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic='-Kconform_pic' + lt_prog_compiler_static='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_can_build_shared=no + ;; + + uts4*) + lt_prog_compiler_pic='-pic' + lt_prog_compiler_static='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared=no + ;; + esac + fi + +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic= + ;; + *) + lt_prog_compiler_pic="$lt_prog_compiler_pic@&t@ -DPIC" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic=$lt_prog_compiler_pic +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +$as_echo "$lt_cv_prog_compiler_pic" >&6; } +lt_prog_compiler_pic=$lt_cv_prog_compiler_pic + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if ${lt_cv_prog_compiler_pic_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic@&t@ -DPIC" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_pic_works"; then + case $lt_prog_compiler_pic in + "" | " "*) ;; + *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; + esac +else + lt_prog_compiler_pic= + lt_prog_compiler_can_build_shared=no +fi + +fi + + + + + + + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works=yes + fi + else + lt_cv_prog_compiler_static_works=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +$as_echo "$lt_cv_prog_compiler_static_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_static_works"; then + : +else + lt_prog_compiler_static= +fi + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + +hard_links=nottested +if test no = "$lt_cv_prog_compiler_c_o" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test no = "$hard_links"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + runpath_var= + allow_undefined_flag= + always_export_symbols=no + archive_cmds= + archive_expsym_cmds= + compiler_needs_object=no + enable_shared_with_static_runtimes=no + export_dynamic_flag_spec= + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + hardcode_automatic=no + hardcode_direct=no + hardcode_direct_absolute=no + hardcode_libdir_flag_spec= + hardcode_libdir_separator= + hardcode_minus_L=no + hardcode_shlibpath_var=unsupported + inherit_rpath=no + link_all_deplibs=unknown + module_cmds= + module_expsym_cmds= + old_archive_from_new_cmds= + old_archive_from_expsyms_cmds= + thread_safe_flag_spec= + whole_archive_flag_spec= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ' (' and ')$', so one must not match beginning or + # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', + # as well as any symbol that contains 'd'. + exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test yes != "$GCC"; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd* | bitrig*) + with_gnu_ld=no + ;; + esac + + ld_shlibs=yes + + # On some targets, GNU ld is compatible enough with the native linker + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then + case $host_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld + # block says, versions before 2.19.5* couldn't really create working + # shared libraries, regardless of the interface used. + case `$LD -v 2>&1` in + *\ \(GNU\ Binutils\)\ 2.19.5*) ;; + *\ \(GNU\ Binutils\)\ 2.[2-9]*) ;; + *\ \(GNU\ Binutils\)\ [3-9]*) ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + fi + + if test yes = "$lt_use_gnu_ld_interface"; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='$wl' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + export_dynamic_flag_spec='$wl--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + whole_archive_flag_spec= + fi + supports_anon_versioning=no + case `$LD -v | $SED -e 's/(^)\+)\s\+//' 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[3-9]*) + # On AIX/PPC, the GNU linker is very broken + if test ia64 != "$host_cpu"; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.19, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to install binutils +*** 2.20 or above, or modify your PATH so that a non-GNU linker is found. +*** You will then need to restart the configuration process. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + ld_shlibs=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + export_dynamic_flag_spec='$wl--export-all-symbols' + allow_undefined_flag=unsupported + always_export_symbols=no + enable_shared_with_static_runtimes=yes + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs=no + fi + ;; + + haiku*) + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + link_all_deplibs=yes + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + interix[3-9]*) + hardcode_direct=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test linux-dietlibc = "$host_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test no = "$tmp_diet" + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group f77 and f90 compilers + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + whole_archive_flag_spec= + tmp_sharedflag='--shared' ;; + nagfor*) # NAGFOR 5.3 + tmp_sharedflag='-Wl,-shared' ;; + xl[cC]* | bgxl[cC]* | mpixl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + nvcc*) # Cuda Compiler Driver 2.2 + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + whole_archive_flag_spec='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + tcc*) + export_dynamic_flag_spec='-rdynamic' + ;; + xlf* | bgf* | bgxlf* | mpixlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + ld_shlibs=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + + if test no = "$ld_shlibs"; then + runpath_var= + hardcode_libdir_flag_spec= + export_dynamic_flag_spec= + whole_archive_flag_spec= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag=unsupported + always_export_symbols=yes + archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + + aix[4-9]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes + break + fi + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds='' + hardcode_direct=yes + hardcode_direct_absolute=yes + hardcode_libdir_separator=':' + link_all_deplibs=yes + file_list_spec='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # traditional, no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + hardcode_direct=no + hardcode_direct_absolute=no + ;; + esac + + if test yes = "$GCC"; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag="$shared_flag "'$wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + export_dynamic_flag_spec='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + hardcode_libdir_flag_spec='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag="-z nodefs" + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag=' $wl-bernotok' + allow_undefined_flag=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + whole_archive_flag_spec='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec='$convenience' + fi + archive_cmds_need_lc=yes + archive_expsym_cmds='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([, ]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + archive_expsym_cmds="$archive_expsym_cmds"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + archive_expsym_cmds="$archive_expsym_cmds"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + bsdi[45]*) + export_dynamic_flag_spec=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + case $cc_basename in + cl*) + # Native MSVC + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + always_export_symbols=yes + file_list_spec='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, )='true' + enable_shared_with_static_runtimes=yes + exclude_expsyms='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1,DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols' + # Don't use ranlib + old_postinstall_cmds='chmod 644 $oldlib' + postlink_cmds='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # Assume MSVC wrapper + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_from_new_cmds='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs' + enable_shared_with_static_runtimes=yes + ;; + esac + ;; + + darwin* | rhapsody*) + + + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes + hardcode_shlibpath_var=unsupported + if test yes = "$lt_cv_ld_force_load"; then + whole_archive_flag_spec='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + + else + whole_archive_flag_spec='' + fi + link_all_deplibs=yes + allow_undefined_flag=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + archive_expsym_cmds="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + + else + ld_shlibs=no + fi + + ;; + + dgux*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2.*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + hpux9*) + if test yes = "$GCC"; then + archive_cmds='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + export_dynamic_flag_spec='$wl-E' + ;; + + hpux10*) + if test yes,no = "$GCC,$with_gnu_ld"; then + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + archive_cmds='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + + # Older versions of the 11.00 compiler do not understand -b yet + # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +$as_echo_n "checking if $CC understands -b... " >&6; } +if ${lt_cv_prog_compiler__b+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler__b=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -b" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler__b=yes + fi + else + lt_cv_prog_compiler__b=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +$as_echo "$lt_cv_prog_compiler__b" >&6; } + +if test yes = "$lt_cv_prog_compiler__b"; then + archive_cmds='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' +else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' +fi + + ;; + esac + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct=no + hardcode_shlibpath_var=no + ;; + *) + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test yes = "$GCC"; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if ${lt_cv_irix_exported_symbol+:} false; then : + $as_echo_n "(cached) " >&6 +else + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int foo (void) { return 0; } +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_irix_exported_symbol=yes +else + lt_cv_irix_exported_symbol=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +$as_echo "$lt_cv_irix_exported_symbol" >&6; } + if test yes = "$lt_cv_irix_exported_symbol"; then + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' + fi + else + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + inherit_rpath=yes + link_all_deplibs=yes + ;; + + linux*) + case $cc_basename in + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + ld_shlibs=yes + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + newsos6) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + hardcode_shlibpath_var=no + ;; + + *nto* | *qnx*) + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + hardcode_direct=yes + hardcode_shlibpath_var=no + hardcode_direct_absolute=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + else + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + fi + else + ld_shlibs=no + fi + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + osf3*) + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + archive_cmds_need_lc='no' + hardcode_libdir_separator=: + ;; + + solaris*) + no_undefined_flag=' -z defs' + if test yes = "$GCC"; then + wlarc='$wl' + archive_cmds='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + archive_cmds='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='$wl' + archive_cmds='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_shlibpath_var=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. GCC discards it without '$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test yes = "$GCC"; then + whole_archive_flag_spec='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + else + whole_archive_flag_spec='-z allextract$convenience -z defaultextract' + fi + ;; + esac + link_all_deplibs=yes + ;; + + sunos4*) + if test sequent = "$host_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds='$CC -r -o $output$reload_objs' + hardcode_direct=no + ;; + motorola) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var=no + ;; + + sysv4.3*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + export_dynamic_flag_spec='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag='$wl-z,text' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag='$wl-z,text' + allow_undefined_flag='$wl-z,nodefs' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-R,$libdir' + hardcode_libdir_separator=':' + link_all_deplibs=yes + export_dynamic_flag_spec='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + *) + ld_shlibs=no + ;; + esac + + if test sni = "$host_vendor"; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + export_dynamic_flag_spec='$wl-Blargedynsym' + ;; + esac + fi + fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +$as_echo "$ld_shlibs" >&6; } +test no = "$ld_shlibs" && can_build_shared=no + +with_gnu_ld=$with_gnu_ld + + + + + + + + + + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $archive_cmds in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc+:} false; then : + $as_echo_n "(cached) " >&6 +else + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl + pic_flag=$lt_prog_compiler_pic + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag + allow_undefined_flag= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + lt_cv_archive_cmds_need_lc=no + else + lt_cv_archive_cmds_need_lc=yes + fi + allow_undefined_flag=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc" >&6; } + archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +if test yes = "$GCC"; then + case $host_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac + case $host_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([A-Za-z]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` + case $lt_search_path_spec in + *\;*) + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` + ;; + *) + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` + ;; + esac + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary... + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + # ...but if some path component already ends with the multilib dir we assume + # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). + case "$lt_multi_os_dir; $lt_search_path_spec " in + "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) + lt_multi_os_dir= + ;; + esac + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" + elif test -n "$lt_multi_os_dir"; then + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' +BEGIN {RS = " "; FS = "/|\n";} { + lt_foo = ""; + lt_count = 0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo = "/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[lt_foo]++; } + if (lt_freq[lt_foo] == 1) { print lt_foo; } +}'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. + case $host_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([A-Za-z]:\)|\1|g'` ;; + esac + sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + + + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[4-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a(lib.so.V)' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o), lib.a(lib.so.V)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a(lib.so.V), lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib" + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[3-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + hardcode_libdir_flag_spec='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + lt_cv_shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + +fi + + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action= +if test -n "$hardcode_libdir_flag_spec" || + test -n "$runpath_var" || + test yes = "$hardcode_automatic"; then + + # We can hardcode non-existent directories. + if test no != "$hardcode_direct" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, )" && + test no != "$hardcode_minus_L"; then + # Linking always hardcodes the temporary library directory. + hardcode_action=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +$as_echo "$hardcode_action" >&6; } + +if test relink = "$hardcode_action" || + test yes = "$inherit_rpath"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + +fi + + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" +if test "x$ac_cv_func_shl_load" = xyes; then : + lt_cv_dlopen=shl_load +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : + lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld +else + ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" +if test "x$ac_cv_func_dlopen" = xyes; then : + lt_cv_dlopen=dlopen +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +$as_echo_n "checking for dlopen in -lsvld... " >&6; } +if ${ac_cv_lib_svld_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsvld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_svld_dlopen=yes +else + ac_cv_lib_svld_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +$as_echo "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +$as_echo_n "checking for dld_link in -ldld... " >&6; } +if ${ac_cv_lib_dld_dld_link+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dld_link (); +int +main () +{ +return dld_link (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_dld_link=yes +else + ac_cv_lib_dld_dld_link=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +$as_echo "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = xyes; then : + lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld +fi + + +fi + + +fi + + +fi + + +fi + + +fi + + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +$as_echo_n "checking whether a program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +$as_echo "$lt_cv_dlopen_self" >&6; } + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self_static+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self_static=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self_static=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +$as_echo "$lt_cv_dlopen_self_static" >&6; } + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi + + + + + + + + + + + + + + + + + +striplib= +old_striplib= +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +$as_echo_n "checking whether stripping libraries is possible... " >&6; } +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ;; + esac +fi + + + + + + + + + + + + + # Report what library types will actually be built + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +$as_echo_n "checking if libtool supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +$as_echo "$can_build_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +$as_echo_n "checking whether to build shared libraries... " >&6; } + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[4-9]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +$as_echo "$enable_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +$as_echo_n "checking whether to build static libraries... " >&6; } + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +$as_echo "$enable_static" >&6; } + + + + +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC=$lt_save_CC + + if test -n "$CXX" && ( test no != "$CXX" && + ( (test g++ = "$CXX" && `g++ -v >/dev/null 2>&1` ) || + (test g++ != "$CXX"))); then + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5 +$as_echo_n "checking how to run the C++ preprocessor... " >&6; } +if test -z "$CXXCPP"; then + if ${ac_cv_prog_CXXCPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CXXCPP needs to be expanded + for CXXCPP in "$CXX -E" "/lib/cpp" + do + ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CXXCPP=$CXXCPP + +fi + CXXCPP=$ac_cv_prog_CXXCPP +else + ac_cv_prog_CXXCPP=$CXXCPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5 +$as_echo "$CXXCPP" >&6; } +ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +else + _lt_caught_CXX_error=yes +fi + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +archive_cmds_need_lc_CXX=no +allow_undefined_flag_CXX= +always_export_symbols_CXX=no +archive_expsym_cmds_CXX= +compiler_needs_object_CXX=no +export_dynamic_flag_spec_CXX= +hardcode_direct_CXX=no +hardcode_direct_absolute_CXX=no +hardcode_libdir_flag_spec_CXX= +hardcode_libdir_separator_CXX= +hardcode_minus_L_CXX=no +hardcode_shlibpath_var_CXX=unsupported +hardcode_automatic_CXX=no +inherit_rpath_CXX=no +module_cmds_CXX= +module_expsym_cmds_CXX= +link_all_deplibs_CXX=unknown +old_archive_cmds_CXX=$old_archive_cmds +reload_flag_CXX=$reload_flag +reload_cmds_CXX=$reload_cmds +no_undefined_flag_CXX= +whole_archive_flag_spec_CXX= +enable_shared_with_static_runtimes_CXX=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +objext_CXX=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_caught_CXX_error"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + + # save warnings/boilerplate of simple test code + ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + + ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_CFLAGS=$CFLAGS + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + CFLAGS=$CXXFLAGS + compiler=$CC + compiler_CXX=$CC + func_cc_basename $compiler +cc_basename=$func_cc_basename_result + + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test yes = "$GXX"; then + lt_prog_compiler_no_builtin_flag_CXX=' -fno-builtin' + else + lt_prog_compiler_no_builtin_flag_CXX= + fi + + if test yes = "$GXX"; then + # Set up default GNU C++ configuration + + + +@%:@ Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test yes = "$with_gnu_ld"; then + archive_cmds_CXX='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='$wl' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec_CXX=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + whole_archive_flag_spec_CXX= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + ld_shlibs_CXX=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aix[4-9]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds_CXX='' + hardcode_direct_CXX=yes + hardcode_direct_absolute_CXX=yes + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + file_list_spec_CXX='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + hardcode_direct_CXX=no + hardcode_direct_absolute_CXX=no + ;; + esac + + if test yes = "$GXX"; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct_CXX=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L_CXX=yes + hardcode_libdir_flag_spec_CXX='-L$libdir' + hardcode_libdir_separator_CXX= + fi + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag=$shared_flag' $wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + export_dynamic_flag_spec_CXX='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + always_export_symbols_CXX=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + # The "-G" linker flag allows undefined symbols. + no_undefined_flag_CXX='-bernotok' + # Determine the default libpath from the value encoded in an empty + # executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath__CXX=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath__CXX +fi + + hardcode_libdir_flag_spec_CXX='$wl-blibpath:$libdir:'"$aix_libpath" + + archive_expsym_cmds_CXX='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + hardcode_libdir_flag_spec_CXX='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag_CXX="-z nodefs" + archive_expsym_cmds_CXX="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath__CXX=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath__CXX +fi + + hardcode_libdir_flag_spec_CXX='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag_CXX=' $wl-bernotok' + allow_undefined_flag_CXX=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + whole_archive_flag_spec_CXX='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec_CXX='$convenience' + fi + archive_cmds_need_lc_CXX=yes + archive_expsym_cmds_CXX='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([, ]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared + # libraries. Need -bnortl late, we may have -brtl in LDFLAGS. + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag_CXX=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds_CXX='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + ld_shlibs_CXX=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + case $GXX,$cc_basename in + ,cl* | no,cl*) + # Native MSVC + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec_CXX=' ' + allow_undefined_flag_CXX=unsupported + always_export_symbols_CXX=yes + file_list_spec_CXX='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds_CXX='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_expsym_cmds_CXX='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, CXX)='true' + enable_shared_with_static_runtimes_CXX=yes + # Don't use ranlib + old_postinstall_cmds_CXX='chmod 644 $oldlib' + postlink_cmds_CXX='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + func_to_tool_file "$lt_outputfile"~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # g++ + # _LT_TAGVAR(hardcode_libdir_flag_spec, CXX) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec_CXX='-L$libdir' + export_dynamic_flag_spec_CXX='$wl--export-all-symbols' + allow_undefined_flag_CXX=unsupported + always_export_symbols_CXX=no + enable_shared_with_static_runtimes_CXX=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + archive_expsym_cmds_CXX='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs_CXX=no + fi + ;; + esac + ;; + darwin* | rhapsody*) + + + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes + hardcode_shlibpath_var_CXX=unsupported + if test yes = "$lt_cv_ld_force_load"; then + whole_archive_flag_spec_CXX='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + + else + whole_archive_flag_spec_CXX='' + fi + link_all_deplibs_CXX=yes + allow_undefined_flag_CXX=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds_CXX="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + if test yes != "$lt_cv_apple_cc_single_mod"; then + archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" + archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + fi + + else + ld_shlibs_CXX=no + fi + + ;; + + os2*) + hardcode_libdir_flag_spec_CXX='-L$libdir' + hardcode_minus_L_CXX=yes + allow_undefined_flag_CXX=unsupported + shrext_cmds=.dll + archive_cmds_CXX='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds_CXX='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds_CXX='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes_CXX=yes + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + freebsd2.*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + ld_shlibs_CXX=no + ;; + + freebsd-elf*) + archive_cmds_need_lc_CXX=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + ld_shlibs_CXX=yes + ;; + + haiku*) + archive_cmds_CXX='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + link_all_deplibs_CXX=yes + ;; + + hpux9*) + hardcode_libdir_flag_spec_CXX='$wl+b $wl$libdir' + hardcode_libdir_separator_CXX=: + export_dynamic_flag_spec_CXX='$wl-E' + hardcode_direct_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + archive_cmds_CXX='$RM $output_objdir/$soname~$CC -b $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + archive_cmds_CXX='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec_CXX='$wl+b $wl$libdir' + hardcode_libdir_separator_CXX=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + export_dynamic_flag_spec_CXX='$wl-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + ;; + *) + hardcode_direct_CXX=yes + hardcode_direct_absolute_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -b $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -shared -nostdlib -fPIC $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + interix[3-9]*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds_CXX='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds_CXX='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + archive_cmds_CXX='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` -o $lib' + fi + fi + link_all_deplibs_CXX=yes + ;; + esac + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + hardcode_libdir_separator_CXX=: + inherit_rpath_CXX=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + archive_expsym_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib $wl-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + archive_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + archive_cmds_need_lc_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + whole_archive_flag_spec_CXX='$wl--whole-archive$convenience $wl--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [1-5].* | *pgcpp\ [1-5].*) + prelink_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' + old_archive_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ + $RANLIB $oldlib' + archive_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 6 and above use weak symbols + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + + hardcode_libdir_flag_spec_CXX='$wl--rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + whole_archive_flag_spec_CXX='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + ;; + cxx*) + # Compaq C++ + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib $wl-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' + ;; + xl* | mpixl* | bgxl*) + # IBM XL 8.0 on PPC, with GNU ld + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + archive_cmds_CXX='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds_CXX='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + no_undefined_flag_CXX=' -zdefs' + archive_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + archive_expsym_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file $wl$export_symbols' + hardcode_libdir_flag_spec_CXX='-R$libdir' + whole_archive_flag_spec_CXX='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object_CXX=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds_CXX='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + ld_shlibs_CXX=yes + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + hardcode_direct_absolute_CXX=yes + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`"; then + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file,$export_symbols -o $lib' + export_dynamic_flag_spec_CXX='$wl-E' + whole_archive_flag_spec_CXX=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + fi + output_verbose_link_cmd=func_echo_all + else + ld_shlibs_CXX=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + hardcode_libdir_separator_CXX=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) old_archive_cmds_CXX='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + cxx*) + case $host in + osf3*) + allow_undefined_flag_CXX=' $wl-expect_unresolved $wl\*' + archive_cmds_CXX='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $soname `test -n "$verstring" && func_echo_all "$wl-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + ;; + *) + allow_undefined_flag_CXX=' -expect_unresolved \*' + archive_cmds_CXX='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds_CXX='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname $wl-input $wl$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~ + $RM $lib.exp' + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + ;; + esac + + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes,no = "$GXX,$with_gnu_ld"; then + allow_undefined_flag_CXX=' $wl-expect_unresolved $wl\*' + case $host in + osf3*) + archive_cmds_CXX='$CC -shared -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + *) + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + esac + + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + archive_cmds_need_lc_CXX=yes + no_undefined_flag_CXX=' -zdefs' + archive_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag $wl-M $wl$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_shlibpath_var_CXX=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + whole_archive_flag_spec_CXX='-z allextract$convenience -z defaultextract' + ;; + esac + link_all_deplibs_CXX=yes + + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + old_archive_cmds_CXX='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test yes,no = "$GXX,$with_gnu_ld"; then + no_undefined_flag_CXX=' $wl-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + else + # g++ 2.7 appears to require '-G' NOT '-shared' on this + # platform. + archive_cmds_CXX='$CC -G -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + fi + + hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir' + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + whole_archive_flag_spec_CXX='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag_CXX='$wl-z,text' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag_CXX='$wl-z,text' + allow_undefined_flag_CXX='$wl-z,nodefs' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-R,$libdir' + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + export_dynamic_flag_spec_CXX='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + old_archive_cmds_CXX='$CC -Tprelink_objects $oldobjs~ + '"$old_archive_cmds_CXX" + reload_cmds_CXX='$CC -Tprelink_objects $reload_objs~ + '"$reload_cmds_CXX" + ;; + *) + archive_cmds_CXX='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } + test no = "$ld_shlibs_CXX" && can_build_shared=no + + GCC_CXX=$GXX + LD_CXX=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + # Dependencies to place before and after the object being linked: +predep_objects_CXX= +postdep_objects_CXX= +predeps_CXX= +postdeps_CXX= +compiler_lib_search_path_CXX= + +cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF + + +_lt_libdeps_save_CFLAGS=$CFLAGS +case "$CC $CFLAGS " in #( +*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; +*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; +*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; +esac + +if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $prev$p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test x-L = "$p" || + test x-R = "$p"; then + prev=$p + continue + fi + + # Expand the sysroot to ease extracting the directories later. + if test -z "$prev"; then + case $p in + -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; + -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; + -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; + esac + fi + case $p in + =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; + esac + if test no = "$pre_test_object_deps_done"; then + case $prev in + -L | -R) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$compiler_lib_search_path_CXX"; then + compiler_lib_search_path_CXX=$prev$p + else + compiler_lib_search_path_CXX="${compiler_lib_search_path_CXX} $prev$p" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$postdeps_CXX"; then + postdeps_CXX=$prev$p + else + postdeps_CXX="${postdeps_CXX} $prev$p" + fi + fi + prev= + ;; + + *.lto.$objext) ;; # Ignore GCC LTO objects + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test no = "$pre_test_object_deps_done"; then + if test -z "$predep_objects_CXX"; then + predep_objects_CXX=$p + else + predep_objects_CXX="$predep_objects_CXX $p" + fi + else + if test -z "$postdep_objects_CXX"; then + postdep_objects_CXX=$p + else + postdep_objects_CXX="$postdep_objects_CXX $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling CXX test program" +fi + +$RM -f confest.$objext +CFLAGS=$_lt_libdeps_save_CFLAGS + +# PORTME: override above test on systems where it is broken +case $host_os in +interix[3-9]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + predep_objects_CXX= + postdep_objects_CXX= + postdeps_CXX= + ;; +esac + + +case " $postdeps_CXX " in +*" -lc "*) archive_cmds_need_lc_CXX=no ;; +esac + compiler_lib_search_dirs_CXX= +if test -n "${compiler_lib_search_path_CXX}"; then + compiler_lib_search_dirs_CXX=`echo " ${compiler_lib_search_path_CXX}" | $SED -e 's! -L! !g' -e 's!^ !!'` +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lt_prog_compiler_wl_CXX= +lt_prog_compiler_pic_CXX= +lt_prog_compiler_static_CXX= + + + # C++ specific cases for pic, static, wl, etc. + if test yes = "$GXX"; then + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + fi + lt_prog_compiler_pic_CXX='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic_CXX='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + lt_prog_compiler_pic_CXX='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic_CXX='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static_CXX='$wl-static' + ;; + esac + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic_CXX='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + lt_prog_compiler_pic_CXX= + ;; + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + lt_prog_compiler_static_CXX= + ;; + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic_CXX=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic_CXX='-fPIC -shared' + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + else + case $host_os in + aix[4-9]*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + else + lt_prog_compiler_static_CXX='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, CXX)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_CXX='-DDLL_EXPORT' + ;; + dgux*) + case $cc_basename in + ec++*) + lt_prog_compiler_pic_CXX='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='$wl-a ${wl}archive' + if test ia64 != "$host_cpu"; then + lt_prog_compiler_pic_CXX='+Z' + fi + ;; + aCC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='$wl-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_CXX='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + lt_prog_compiler_wl_CXX='--backend -Wl,' + lt_prog_compiler_pic_CXX='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64, which still supported -KPIC. + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-fPIC' + lt_prog_compiler_static_CXX='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-fpic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + xlc* | xlC* | bgxl[cC]* | mpixl[cC]*) + # IBM XL 8.0, 9.0 on PPC and BlueGene + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-qpic' + lt_prog_compiler_static_CXX='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + lt_prog_compiler_wl_CXX='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + lt_prog_compiler_pic_CXX='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic_CXX='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + lt_prog_compiler_wl_CXX='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + lt_prog_compiler_pic_CXX='-pic' + ;; + cxx*) + # Digital/Compaq C++ + lt_prog_compiler_wl_CXX='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + lt_prog_compiler_wl_CXX='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + lt_prog_compiler_pic_CXX='-pic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + lcc*) + # Lucid + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + lt_prog_compiler_pic_CXX='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + lt_prog_compiler_can_build_shared_CXX=no + ;; + esac + fi + +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic_CXX= + ;; + *) + lt_prog_compiler_pic_CXX="$lt_prog_compiler_pic_CXX@&t@ -DPIC" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_CXX=$lt_prog_compiler_pic_CXX +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_CXX" >&6; } +lt_prog_compiler_pic_CXX=$lt_cv_prog_compiler_pic_CXX + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... " >&6; } +if ${lt_cv_prog_compiler_pic_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works_CXX=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic_CXX@&t@ -DPIC" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works_CXX=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works_CXX" >&6; } + +if test yes = "$lt_cv_prog_compiler_pic_works_CXX"; then + case $lt_prog_compiler_pic_CXX in + "" | " "*) ;; + *) lt_prog_compiler_pic_CXX=" $lt_prog_compiler_pic_CXX" ;; + esac +else + lt_prog_compiler_pic_CXX= + lt_prog_compiler_can_build_shared_CXX=no +fi + +fi + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl_CXX eval lt_tmp_static_flag=\"$lt_prog_compiler_static_CXX\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works_CXX=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works_CXX=yes + fi + else + lt_cv_prog_compiler_static_works_CXX=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_static_works_CXX" >&6; } + +if test yes = "$lt_cv_prog_compiler_static_works_CXX"; then + : +else + lt_prog_compiler_static_CXX= +fi + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o_CXX=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_CXX=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o_CXX=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_CXX=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } + + + + +hard_links=nottested +if test no = "$lt_cv_prog_compiler_c_o_CXX" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test no = "$hard_links"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms_CXX='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + case $host_os in + aix[4-9]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds_CXX='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + export_symbols_cmds_CXX=$ltdll_cmds + ;; + cygwin* | mingw* | cegcc*) + case $cc_basename in + cl*) + exclude_expsyms_CXX='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + ;; + *) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms_CXX='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' + ;; + esac + ;; + *) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } +test no = "$ld_shlibs_CXX" && can_build_shared=no + +with_gnu_ld_CXX=$with_gnu_ld + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc_CXX" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc_CXX=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $archive_cmds_CXX in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl_CXX + pic_flag=$lt_prog_compiler_pic_CXX + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag_CXX + allow_undefined_flag_CXX= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + lt_cv_archive_cmds_need_lc_CXX=no + else + lt_cv_archive_cmds_need_lc_CXX=yes + fi + allow_undefined_flag_CXX=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_CXX" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc_CXX" >&6; } + archive_cmds_need_lc_CXX=$lt_cv_archive_cmds_need_lc_CXX + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + + + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[4-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a(lib.so.V)' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o), lib.a(lib.so.V)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a(lib.so.V), lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[3-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + hardcode_libdir_flag_spec_CXX='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl_CXX\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec_CXX\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + lt_cv_shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + +fi + + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action_CXX= +if test -n "$hardcode_libdir_flag_spec_CXX" || + test -n "$runpath_var_CXX" || + test yes = "$hardcode_automatic_CXX"; then + + # We can hardcode non-existent directories. + if test no != "$hardcode_direct_CXX" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, CXX)" && + test no != "$hardcode_minus_L_CXX"; then + # Linking always hardcodes the temporary library directory. + hardcode_action_CXX=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action_CXX=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action_CXX=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_CXX" >&5 +$as_echo "$hardcode_action_CXX" >&6; } + +if test relink = "$hardcode_action_CXX" || + test yes = "$inherit_rpath_CXX"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + + fi # test -n "$compiler" + + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test yes != "$_lt_caught_CXX_error" + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + + + + + + + + + + + + + ac_config_commands="$ac_config_commands libtool" + + + + +# Only expand once: + + + +#enable -D_GNU_SOURCE since the return code value of getaddrinfo +#ifdefed with __USE_GNU +#features.h header undef's __USE_GNU and defines it only if _GNU_SOURCE is defined +#hence this define for gcc +@%:@ Check whether --enable-debug was given. +if test "${enable_debug+set}" = set; then : + enableval=$enable_debug; +else + enable_debug=no +fi + + +if test "x$enable_debug" = xyes; then + if test "x$init_cflags" = x; then + CFLAGS="" + fi + CFLAGS="$CFLAGS -g -O0 -D_GNU_SOURCE" +else + if test "x$init_cflags" = x; then + CFLAGS="-g -O2 -D_GNU_SOURCE" + fi +fi + +if test "x$enable_debug" = xyes; then + if test "x$init_cxxflags" = x; then + CXXFLAGS="" + fi + CXXFLAGS="$CXXFLAGS -g -O0" +else + if test "x$init_cxxflags" = x; then + CXXFLAGS="-g -O2" + fi +fi + + +@%:@ Check whether --with-syncapi was given. +if test "${with_syncapi+set}" = set; then : + withval=$with_syncapi; +else + with_syncapi=yes +fi + + +# Checks for libraries. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_lock in -lpthread" >&5 +$as_echo_n "checking for pthread_mutex_lock in -lpthread... " >&6; } +if ${ac_cv_lib_pthread_pthread_mutex_lock+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_mutex_lock (); +int +main () +{ +return pthread_mutex_lock (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_pthread_pthread_mutex_lock=yes +else + ac_cv_lib_pthread_pthread_mutex_lock=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_lock" >&5 +$as_echo "$ac_cv_lib_pthread_pthread_mutex_lock" >&6; } +if test "x$ac_cv_lib_pthread_pthread_mutex_lock" = xyes; then : + have_pthread=yes +else + have_pthread=no +fi + + +if test "x$with_syncapi" != xno && test "x$have_pthread" = xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot build SyncAPI -- pthread not found" >&5 +$as_echo "$as_me: WARNING: cannot build SyncAPI -- pthread not found" >&2;} + with_syncapi=no +fi +if test "x$with_syncapi" != xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: building with SyncAPI support" >&5 +$as_echo "$as_me: building with SyncAPI support" >&6;} +else + { $as_echo "$as_me:${as_lineno-$LINENO}: building without SyncAPI support" >&5 +$as_echo "$as_me: building without SyncAPI support" >&6;} +fi + + if test "x$with_syncapi" != xno; then + WANT_SYNCAPI_TRUE= + WANT_SYNCAPI_FALSE='#' +else + WANT_SYNCAPI_TRUE='#' + WANT_SYNCAPI_FALSE= +fi + + +# Checks for header files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "@%:@define STDC_HEADERS 1" >>confdefs.h + +fi + +for ac_header in arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h sys/utsname.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +@%:@define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +# Checks for typedefs, structures, and compiler characteristics. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +$as_echo_n "checking for an ANSI C-conforming const... " >&6; } +if ${ac_cv_c_const+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#ifndef __cplusplus + /* Ultrix mips cc rejects this sort of thing. */ + typedef int charset[2]; + const charset cs = { 0, 0 }; + /* SunOS 4.1.1 cc rejects this. */ + char const *const *pcpcc; + char **ppc; + /* NEC SVR4.0.2 mips cc rejects this. */ + struct point {int x, y;}; + static struct point const zero = {0,0}; + /* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in + an arm of an if-expression whose if-part is not a constant + expression */ + const char *g = "string"; + pcpcc = &g + (g ? g-g : 0); + /* HPUX 7.0 cc rejects these. */ + ++pcpcc; + ppc = (char**) pcpcc; + pcpcc = (char const *const *) ppc; + { /* SCO 3.2v4 cc rejects this sort of thing. */ + char tx; + char *t = &tx; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; + if (s) return 0; + } + { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; + } + { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; + } + { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; } bx; + struct s *b = &bx; b->j = 5; + } + { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; + if (!foo) return 0; + } + return !cs[0] && !zero.x; +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_const=yes +else + ac_cv_c_const=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +$as_echo "$ac_cv_c_const" >&6; } +if test $ac_cv_c_const = no; then + +$as_echo "@%:@define const /**/" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 +$as_echo_n "checking for inline... " >&6; } +if ${ac_cv_c_inline+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_c_inline=no +for ac_kw in inline __inline__ __inline; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifndef __cplusplus +typedef int foo_t; +static $ac_kw foo_t static_foo () {return 0; } +$ac_kw foo_t foo () {return 0; } +#endif + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_inline=$ac_kw +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test "$ac_cv_c_inline" != no && break +done + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 +$as_echo "$ac_cv_c_inline" >&6; } + +case $ac_cv_c_inline in + inline | yes) ;; + *) + case $ac_cv_c_inline in + no) ac_val=;; + *) ac_val=$ac_cv_c_inline;; + esac + cat >>confdefs.h <<_ACEOF +#ifndef __cplusplus +#define inline $ac_val +#endif +_ACEOF + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5 +$as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; } +if ${ac_cv_header_time+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include + +int +main () +{ +if ((struct tm *) 0) +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_time=yes +else + ac_cv_header_time=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5 +$as_echo "$ac_cv_header_time" >&6; } +if test $ac_cv_header_time = yes; then + +$as_echo "@%:@define TIME_WITH_SYS_TIME 1" >>confdefs.h + +fi + +ac_fn_c_check_type "$LINENO" "nfds_t" "ac_cv_type_nfds_t" "#include +" +if test "x$ac_cv_type_nfds_t" = xyes; then : + +$as_echo "@%:@define POLL_NFDS_TYPE nfds_t" >>confdefs.h + +else + +$as_echo "@%:@define POLL_NFDS_TYPE unsigned int" >>confdefs.h + +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable ipv6" >&5 +$as_echo_n "checking whether to enable ipv6... " >&6; } + +if test "$cross_compiling" = yes; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ipv6=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + /* is AF_INET6 available? */ +#include +#include +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + ipv6=yes +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ipv6=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +if test x"$ipv6" = xyes; then + USEIPV6="-DZOO_IPV6_ENABLED" + +fi + +# Determine which libraries we need to use clock_gettime +saved_LIBS="$LIBS" +LIBS="" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5 +$as_echo_n "checking for clock_gettime in -lrt... " >&6; } +if ${ac_cv_lib_rt_clock_gettime+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrt $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char clock_gettime (); +int +main () +{ +return clock_gettime (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_rt_clock_gettime=yes +else + ac_cv_lib_rt_clock_gettime=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5 +$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; } +if test "x$ac_cv_lib_rt_clock_gettime" = xyes; then : + cat >>confdefs.h <<_ACEOF +@%:@define HAVE_LIBRT 1 +_ACEOF + + LIBS="-lrt $LIBS" + +fi + +CLOCK_GETTIME_LIBS=$LIBS + +LIBS="$saved_LIBS" + +# Checks for library functions. +for ac_func in getcwd gethostbyname gethostname getlogin getpwuid_r gettimeofday getuid memmove memset poll socket strchr strdup strerror strtol +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +@%:@define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +ac_config_files="$ac_config_files Makefile" + + + if + case "$host_os" in + *solaris*) + true + ;; + *) + false + ;; + esac ; then + SOLARIS_TRUE= + SOLARIS_FALSE='#' +else + SOLARIS_TRUE='#' + SOLARIS_FALSE= +fi + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + if test "x$cache_file" != "x/dev/null"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +U= +for ac_i in : $LIB@&t@OBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIB@&t@OBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + +if test -z "${DX_COND_doc_TRUE}" && test -z "${DX_COND_doc_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_doc\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_doc_TRUE}" && test -z "${DX_COND_doc_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_doc\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_dot_TRUE}" && test -z "${DX_COND_dot_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_dot\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_dot_TRUE}" && test -z "${DX_COND_dot_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_dot\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_man_TRUE}" && test -z "${DX_COND_man_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_man\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_man_TRUE}" && test -z "${DX_COND_man_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_man\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_rtf_TRUE}" && test -z "${DX_COND_rtf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_rtf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_rtf_TRUE}" && test -z "${DX_COND_rtf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_rtf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_xml_TRUE}" && test -z "${DX_COND_xml_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_xml\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_xml_TRUE}" && test -z "${DX_COND_xml_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_xml\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chm_TRUE}" && test -z "${DX_COND_chm_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chm\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chm_TRUE}" && test -z "${DX_COND_chm_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chm\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chi_TRUE}" && test -z "${DX_COND_chi_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chi\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chi_TRUE}" && test -z "${DX_COND_chi_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chi\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_html_TRUE}" && test -z "${DX_COND_html_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_html\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_html_TRUE}" && test -z "${DX_COND_html_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_html\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_ps_TRUE}" && test -z "${DX_COND_ps_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_ps\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_ps_TRUE}" && test -z "${DX_COND_ps_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_ps\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_pdf_TRUE}" && test -z "${DX_COND_pdf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_pdf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_pdf_TRUE}" && test -z "${DX_COND_pdf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_pdf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_latex_TRUE}" && test -z "${DX_COND_latex_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_latex\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_latex_TRUE}" && test -z "${DX_COND_latex_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_latex\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +$as_echo_n "checking that generated files are newer than configure... " >&6; } + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 +$as_echo "done" >&6; } + if test -n "$EXEEXT"; then + am__EXEEXT_TRUE= + am__EXEEXT_FALSE='#' +else + am__EXEEXT_TRUE='#' + am__EXEEXT_FALSE= +fi + +if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then + as_fn_error $? "conditional \"AMDEP\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCC\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WANT_SYNCAPI_TRUE}" && test -z "${WANT_SYNCAPI_FALSE}"; then + as_fn_error $? "conditional \"WANT_SYNCAPI\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${SOLARIS_TRUE}" && test -z "${SOLARIS_FALSE}"; then + as_fn_error $? "conditional \"SOLARIS\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi + +: "${CONFIG_STATUS=./config.status}" +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in @%:@( + *posix*) : + set -o posix ;; @%:@( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in @%:@( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in @%:@(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +@%:@ as_fn_error STATUS ERROR [LINENO LOG_FD] +@%:@ ---------------------------------------- +@%:@ Output "`basename @S|@0`: error: ERROR" to stderr. If LINENO and LOG_FD are +@%:@ provided, also output the error to LOG_FD, referencing LINENO. Then exit the +@%:@ script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} @%:@ as_fn_error + + +@%:@ as_fn_set_status STATUS +@%:@ ----------------------- +@%:@ Set @S|@? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} @%:@ as_fn_set_status + +@%:@ as_fn_exit STATUS +@%:@ ----------------- +@%:@ Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} @%:@ as_fn_exit + +@%:@ as_fn_unset VAR +@%:@ --------------- +@%:@ Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +@%:@ as_fn_append VAR VALUE +@%:@ ---------------------- +@%:@ Append the text in VALUE to the end of the definition contained in VAR. Take +@%:@ advantage of any shell optimizations that allow amortized linear growth over +@%:@ repeated appends, instead of the typical quadratic growth present in naive +@%:@ implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +@%:@ as_fn_arith ARG... +@%:@ ------------------ +@%:@ Perform arithmetic evaluation on the ARGs, and store the result in the +@%:@ global @S|@as_val. Take advantage of shells that can avoid forks. The arguments +@%:@ must be portable across @S|@(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in @%:@((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +@%:@ as_fn_mkdir_p +@%:@ ------------- +@%:@ Create "@S|@as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} @%:@ as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + + +@%:@ as_fn_executable_p FILE +@%:@ ----------------------- +@%:@ Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} @%:@ as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by zookeeper C client $as_me 3.6.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + +case $ac_config_headers in *" +"*) set x $ac_config_headers; shift; ac_config_headers=$*;; +esac + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" +config_commands="$ac_config_commands" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Configuration commands: +$config_commands + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_version="\\ +zookeeper C client config.status 3.6.0 +configured by $0, generated by GNU Autoconf 2.69, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2012 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' +AWK='$AWK' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=?*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + --*=) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg= + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + $as_echo "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + '') as_fn_error $? "missing file argument" ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_HEADERS " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + as_fn_error $? "ambiguous option: \`$1' +Try \`$0 --help' for more information.";; + --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error $? "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../@%:@@%:@ /;s/...$/ @%:@@%:@/;p;x;p;x' <<_ASBOX +@%:@@%:@ Running $as_me. @%:@@%:@ +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# +# INIT-COMMANDS +# +AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" + + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +macro_version='`$ECHO "$macro_version" | $SED "$delay_single_quote_subst"`' +macro_revision='`$ECHO "$macro_revision" | $SED "$delay_single_quote_subst"`' +enable_shared='`$ECHO "$enable_shared" | $SED "$delay_single_quote_subst"`' +enable_static='`$ECHO "$enable_static" | $SED "$delay_single_quote_subst"`' +pic_mode='`$ECHO "$pic_mode" | $SED "$delay_single_quote_subst"`' +enable_fast_install='`$ECHO "$enable_fast_install" | $SED "$delay_single_quote_subst"`' +shared_archive_member_spec='`$ECHO "$shared_archive_member_spec" | $SED "$delay_single_quote_subst"`' +SHELL='`$ECHO "$SHELL" | $SED "$delay_single_quote_subst"`' +ECHO='`$ECHO "$ECHO" | $SED "$delay_single_quote_subst"`' +PATH_SEPARATOR='`$ECHO "$PATH_SEPARATOR" | $SED "$delay_single_quote_subst"`' +host_alias='`$ECHO "$host_alias" | $SED "$delay_single_quote_subst"`' +host='`$ECHO "$host" | $SED "$delay_single_quote_subst"`' +host_os='`$ECHO "$host_os" | $SED "$delay_single_quote_subst"`' +build_alias='`$ECHO "$build_alias" | $SED "$delay_single_quote_subst"`' +build='`$ECHO "$build" | $SED "$delay_single_quote_subst"`' +build_os='`$ECHO "$build_os" | $SED "$delay_single_quote_subst"`' +SED='`$ECHO "$SED" | $SED "$delay_single_quote_subst"`' +Xsed='`$ECHO "$Xsed" | $SED "$delay_single_quote_subst"`' +GREP='`$ECHO "$GREP" | $SED "$delay_single_quote_subst"`' +EGREP='`$ECHO "$EGREP" | $SED "$delay_single_quote_subst"`' +FGREP='`$ECHO "$FGREP" | $SED "$delay_single_quote_subst"`' +LD='`$ECHO "$LD" | $SED "$delay_single_quote_subst"`' +NM='`$ECHO "$NM" | $SED "$delay_single_quote_subst"`' +LN_S='`$ECHO "$LN_S" | $SED "$delay_single_quote_subst"`' +max_cmd_len='`$ECHO "$max_cmd_len" | $SED "$delay_single_quote_subst"`' +ac_objext='`$ECHO "$ac_objext" | $SED "$delay_single_quote_subst"`' +exeext='`$ECHO "$exeext" | $SED "$delay_single_quote_subst"`' +lt_unset='`$ECHO "$lt_unset" | $SED "$delay_single_quote_subst"`' +lt_SP2NL='`$ECHO "$lt_SP2NL" | $SED "$delay_single_quote_subst"`' +lt_NL2SP='`$ECHO "$lt_NL2SP" | $SED "$delay_single_quote_subst"`' +lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_quote_subst"`' +lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`' +reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`' +reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`' +OBJDUMP='`$ECHO "$OBJDUMP" | $SED "$delay_single_quote_subst"`' +deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`' +file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`' +file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`' +want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`' +DLLTOOL='`$ECHO "$DLLTOOL" | $SED "$delay_single_quote_subst"`' +sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`' +AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`' +AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`' +archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`' +STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`' +RANLIB='`$ECHO "$RANLIB" | $SED "$delay_single_quote_subst"`' +old_postinstall_cmds='`$ECHO "$old_postinstall_cmds" | $SED "$delay_single_quote_subst"`' +old_postuninstall_cmds='`$ECHO "$old_postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_cmds='`$ECHO "$old_archive_cmds" | $SED "$delay_single_quote_subst"`' +lock_old_archive_extraction='`$ECHO "$lock_old_archive_extraction" | $SED "$delay_single_quote_subst"`' +CC='`$ECHO "$CC" | $SED "$delay_single_quote_subst"`' +CFLAGS='`$ECHO "$CFLAGS" | $SED "$delay_single_quote_subst"`' +compiler='`$ECHO "$compiler" | $SED "$delay_single_quote_subst"`' +GCC='`$ECHO "$GCC" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_pipe='`$ECHO "$lt_cv_sys_global_symbol_pipe" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_cdecl='`$ECHO "$lt_cv_sys_global_symbol_to_cdecl" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_import='`$ECHO "$lt_cv_sys_global_symbol_to_import" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $SED "$delay_single_quote_subst"`' +lt_cv_nm_interface='`$ECHO "$lt_cv_nm_interface" | $SED "$delay_single_quote_subst"`' +nm_file_list_spec='`$ECHO "$nm_file_list_spec" | $SED "$delay_single_quote_subst"`' +lt_sysroot='`$ECHO "$lt_sysroot" | $SED "$delay_single_quote_subst"`' +lt_cv_truncate_bin='`$ECHO "$lt_cv_truncate_bin" | $SED "$delay_single_quote_subst"`' +objdir='`$ECHO "$objdir" | $SED "$delay_single_quote_subst"`' +MAGIC_CMD='`$ECHO "$MAGIC_CMD" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag='`$ECHO "$lt_prog_compiler_no_builtin_flag" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_pic='`$ECHO "$lt_prog_compiler_pic" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_wl='`$ECHO "$lt_prog_compiler_wl" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_static='`$ECHO "$lt_prog_compiler_static" | $SED "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o='`$ECHO "$lt_cv_prog_compiler_c_o" | $SED "$delay_single_quote_subst"`' +need_locks='`$ECHO "$need_locks" | $SED "$delay_single_quote_subst"`' +MANIFEST_TOOL='`$ECHO "$MANIFEST_TOOL" | $SED "$delay_single_quote_subst"`' +DSYMUTIL='`$ECHO "$DSYMUTIL" | $SED "$delay_single_quote_subst"`' +NMEDIT='`$ECHO "$NMEDIT" | $SED "$delay_single_quote_subst"`' +LIPO='`$ECHO "$LIPO" | $SED "$delay_single_quote_subst"`' +OTOOL='`$ECHO "$OTOOL" | $SED "$delay_single_quote_subst"`' +OTOOL64='`$ECHO "$OTOOL64" | $SED "$delay_single_quote_subst"`' +libext='`$ECHO "$libext" | $SED "$delay_single_quote_subst"`' +shrext_cmds='`$ECHO "$shrext_cmds" | $SED "$delay_single_quote_subst"`' +extract_expsyms_cmds='`$ECHO "$extract_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds_need_lc='`$ECHO "$archive_cmds_need_lc" | $SED "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes='`$ECHO "$enable_shared_with_static_runtimes" | $SED "$delay_single_quote_subst"`' +export_dynamic_flag_spec='`$ECHO "$export_dynamic_flag_spec" | $SED "$delay_single_quote_subst"`' +whole_archive_flag_spec='`$ECHO "$whole_archive_flag_spec" | $SED "$delay_single_quote_subst"`' +compiler_needs_object='`$ECHO "$compiler_needs_object" | $SED "$delay_single_quote_subst"`' +old_archive_from_new_cmds='`$ECHO "$old_archive_from_new_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds='`$ECHO "$old_archive_from_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds='`$ECHO "$archive_cmds" | $SED "$delay_single_quote_subst"`' +archive_expsym_cmds='`$ECHO "$archive_expsym_cmds" | $SED "$delay_single_quote_subst"`' +module_cmds='`$ECHO "$module_cmds" | $SED "$delay_single_quote_subst"`' +module_expsym_cmds='`$ECHO "$module_expsym_cmds" | $SED "$delay_single_quote_subst"`' +with_gnu_ld='`$ECHO "$with_gnu_ld" | $SED "$delay_single_quote_subst"`' +allow_undefined_flag='`$ECHO "$allow_undefined_flag" | $SED "$delay_single_quote_subst"`' +no_undefined_flag='`$ECHO "$no_undefined_flag" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec='`$ECHO "$hardcode_libdir_flag_spec" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_separator='`$ECHO "$hardcode_libdir_separator" | $SED "$delay_single_quote_subst"`' +hardcode_direct='`$ECHO "$hardcode_direct" | $SED "$delay_single_quote_subst"`' +hardcode_direct_absolute='`$ECHO "$hardcode_direct_absolute" | $SED "$delay_single_quote_subst"`' +hardcode_minus_L='`$ECHO "$hardcode_minus_L" | $SED "$delay_single_quote_subst"`' +hardcode_shlibpath_var='`$ECHO "$hardcode_shlibpath_var" | $SED "$delay_single_quote_subst"`' +hardcode_automatic='`$ECHO "$hardcode_automatic" | $SED "$delay_single_quote_subst"`' +inherit_rpath='`$ECHO "$inherit_rpath" | $SED "$delay_single_quote_subst"`' +link_all_deplibs='`$ECHO "$link_all_deplibs" | $SED "$delay_single_quote_subst"`' +always_export_symbols='`$ECHO "$always_export_symbols" | $SED "$delay_single_quote_subst"`' +export_symbols_cmds='`$ECHO "$export_symbols_cmds" | $SED "$delay_single_quote_subst"`' +exclude_expsyms='`$ECHO "$exclude_expsyms" | $SED "$delay_single_quote_subst"`' +include_expsyms='`$ECHO "$include_expsyms" | $SED "$delay_single_quote_subst"`' +prelink_cmds='`$ECHO "$prelink_cmds" | $SED "$delay_single_quote_subst"`' +postlink_cmds='`$ECHO "$postlink_cmds" | $SED "$delay_single_quote_subst"`' +file_list_spec='`$ECHO "$file_list_spec" | $SED "$delay_single_quote_subst"`' +variables_saved_for_relink='`$ECHO "$variables_saved_for_relink" | $SED "$delay_single_quote_subst"`' +need_lib_prefix='`$ECHO "$need_lib_prefix" | $SED "$delay_single_quote_subst"`' +need_version='`$ECHO "$need_version" | $SED "$delay_single_quote_subst"`' +version_type='`$ECHO "$version_type" | $SED "$delay_single_quote_subst"`' +runpath_var='`$ECHO "$runpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_var='`$ECHO "$shlibpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_overrides_runpath='`$ECHO "$shlibpath_overrides_runpath" | $SED "$delay_single_quote_subst"`' +libname_spec='`$ECHO "$libname_spec" | $SED "$delay_single_quote_subst"`' +library_names_spec='`$ECHO "$library_names_spec" | $SED "$delay_single_quote_subst"`' +soname_spec='`$ECHO "$soname_spec" | $SED "$delay_single_quote_subst"`' +install_override_mode='`$ECHO "$install_override_mode" | $SED "$delay_single_quote_subst"`' +postinstall_cmds='`$ECHO "$postinstall_cmds" | $SED "$delay_single_quote_subst"`' +postuninstall_cmds='`$ECHO "$postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +finish_cmds='`$ECHO "$finish_cmds" | $SED "$delay_single_quote_subst"`' +finish_eval='`$ECHO "$finish_eval" | $SED "$delay_single_quote_subst"`' +hardcode_into_libs='`$ECHO "$hardcode_into_libs" | $SED "$delay_single_quote_subst"`' +sys_lib_search_path_spec='`$ECHO "$sys_lib_search_path_spec" | $SED "$delay_single_quote_subst"`' +configure_time_dlsearch_path='`$ECHO "$configure_time_dlsearch_path" | $SED "$delay_single_quote_subst"`' +configure_time_lt_sys_library_path='`$ECHO "$configure_time_lt_sys_library_path" | $SED "$delay_single_quote_subst"`' +hardcode_action='`$ECHO "$hardcode_action" | $SED "$delay_single_quote_subst"`' +enable_dlopen='`$ECHO "$enable_dlopen" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self='`$ECHO "$enable_dlopen_self" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self_static='`$ECHO "$enable_dlopen_self_static" | $SED "$delay_single_quote_subst"`' +old_striplib='`$ECHO "$old_striplib" | $SED "$delay_single_quote_subst"`' +striplib='`$ECHO "$striplib" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_dirs='`$ECHO "$compiler_lib_search_dirs" | $SED "$delay_single_quote_subst"`' +predep_objects='`$ECHO "$predep_objects" | $SED "$delay_single_quote_subst"`' +postdep_objects='`$ECHO "$postdep_objects" | $SED "$delay_single_quote_subst"`' +predeps='`$ECHO "$predeps" | $SED "$delay_single_quote_subst"`' +postdeps='`$ECHO "$postdeps" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_path='`$ECHO "$compiler_lib_search_path" | $SED "$delay_single_quote_subst"`' +LD_CXX='`$ECHO "$LD_CXX" | $SED "$delay_single_quote_subst"`' +reload_flag_CXX='`$ECHO "$reload_flag_CXX" | $SED "$delay_single_quote_subst"`' +reload_cmds_CXX='`$ECHO "$reload_cmds_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_cmds_CXX='`$ECHO "$old_archive_cmds_CXX" | $SED "$delay_single_quote_subst"`' +compiler_CXX='`$ECHO "$compiler_CXX" | $SED "$delay_single_quote_subst"`' +GCC_CXX='`$ECHO "$GCC_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag_CXX='`$ECHO "$lt_prog_compiler_no_builtin_flag_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_pic_CXX='`$ECHO "$lt_prog_compiler_pic_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_wl_CXX='`$ECHO "$lt_prog_compiler_wl_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_static_CXX='`$ECHO "$lt_prog_compiler_static_CXX" | $SED "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o_CXX='`$ECHO "$lt_cv_prog_compiler_c_o_CXX" | $SED "$delay_single_quote_subst"`' +archive_cmds_need_lc_CXX='`$ECHO "$archive_cmds_need_lc_CXX" | $SED "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes_CXX='`$ECHO "$enable_shared_with_static_runtimes_CXX" | $SED "$delay_single_quote_subst"`' +export_dynamic_flag_spec_CXX='`$ECHO "$export_dynamic_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +whole_archive_flag_spec_CXX='`$ECHO "$whole_archive_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +compiler_needs_object_CXX='`$ECHO "$compiler_needs_object_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_from_new_cmds_CXX='`$ECHO "$old_archive_from_new_cmds_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds_CXX='`$ECHO "$old_archive_from_expsyms_cmds_CXX" | $SED "$delay_single_quote_subst"`' +archive_cmds_CXX='`$ECHO "$archive_cmds_CXX" | $SED "$delay_single_quote_subst"`' +archive_expsym_cmds_CXX='`$ECHO "$archive_expsym_cmds_CXX" | $SED "$delay_single_quote_subst"`' +module_cmds_CXX='`$ECHO "$module_cmds_CXX" | $SED "$delay_single_quote_subst"`' +module_expsym_cmds_CXX='`$ECHO "$module_expsym_cmds_CXX" | $SED "$delay_single_quote_subst"`' +with_gnu_ld_CXX='`$ECHO "$with_gnu_ld_CXX" | $SED "$delay_single_quote_subst"`' +allow_undefined_flag_CXX='`$ECHO "$allow_undefined_flag_CXX" | $SED "$delay_single_quote_subst"`' +no_undefined_flag_CXX='`$ECHO "$no_undefined_flag_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec_CXX='`$ECHO "$hardcode_libdir_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_separator_CXX='`$ECHO "$hardcode_libdir_separator_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_direct_CXX='`$ECHO "$hardcode_direct_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_direct_absolute_CXX='`$ECHO "$hardcode_direct_absolute_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_minus_L_CXX='`$ECHO "$hardcode_minus_L_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_shlibpath_var_CXX='`$ECHO "$hardcode_shlibpath_var_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_automatic_CXX='`$ECHO "$hardcode_automatic_CXX" | $SED "$delay_single_quote_subst"`' +inherit_rpath_CXX='`$ECHO "$inherit_rpath_CXX" | $SED "$delay_single_quote_subst"`' +link_all_deplibs_CXX='`$ECHO "$link_all_deplibs_CXX" | $SED "$delay_single_quote_subst"`' +always_export_symbols_CXX='`$ECHO "$always_export_symbols_CXX" | $SED "$delay_single_quote_subst"`' +export_symbols_cmds_CXX='`$ECHO "$export_symbols_cmds_CXX" | $SED "$delay_single_quote_subst"`' +exclude_expsyms_CXX='`$ECHO "$exclude_expsyms_CXX" | $SED "$delay_single_quote_subst"`' +include_expsyms_CXX='`$ECHO "$include_expsyms_CXX" | $SED "$delay_single_quote_subst"`' +prelink_cmds_CXX='`$ECHO "$prelink_cmds_CXX" | $SED "$delay_single_quote_subst"`' +postlink_cmds_CXX='`$ECHO "$postlink_cmds_CXX" | $SED "$delay_single_quote_subst"`' +file_list_spec_CXX='`$ECHO "$file_list_spec_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_action_CXX='`$ECHO "$hardcode_action_CXX" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_dirs_CXX='`$ECHO "$compiler_lib_search_dirs_CXX" | $SED "$delay_single_quote_subst"`' +predep_objects_CXX='`$ECHO "$predep_objects_CXX" | $SED "$delay_single_quote_subst"`' +postdep_objects_CXX='`$ECHO "$postdep_objects_CXX" | $SED "$delay_single_quote_subst"`' +predeps_CXX='`$ECHO "$predeps_CXX" | $SED "$delay_single_quote_subst"`' +postdeps_CXX='`$ECHO "$postdeps_CXX" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_path_CXX='`$ECHO "$compiler_lib_search_path_CXX" | $SED "$delay_single_quote_subst"`' + +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$1 +_LTECHO_EOF' +} + +# Quote evaled strings. +for var in SHELL \ +ECHO \ +PATH_SEPARATOR \ +SED \ +GREP \ +EGREP \ +FGREP \ +LD \ +NM \ +LN_S \ +lt_SP2NL \ +lt_NL2SP \ +reload_flag \ +OBJDUMP \ +deplibs_check_method \ +file_magic_cmd \ +file_magic_glob \ +want_nocaseglob \ +DLLTOOL \ +sharedlib_from_linklib_cmd \ +AR \ +AR_FLAGS \ +archiver_list_spec \ +STRIP \ +RANLIB \ +CC \ +CFLAGS \ +compiler \ +lt_cv_sys_global_symbol_pipe \ +lt_cv_sys_global_symbol_to_cdecl \ +lt_cv_sys_global_symbol_to_import \ +lt_cv_sys_global_symbol_to_c_name_address \ +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \ +lt_cv_nm_interface \ +nm_file_list_spec \ +lt_cv_truncate_bin \ +lt_prog_compiler_no_builtin_flag \ +lt_prog_compiler_pic \ +lt_prog_compiler_wl \ +lt_prog_compiler_static \ +lt_cv_prog_compiler_c_o \ +need_locks \ +MANIFEST_TOOL \ +DSYMUTIL \ +NMEDIT \ +LIPO \ +OTOOL \ +OTOOL64 \ +shrext_cmds \ +export_dynamic_flag_spec \ +whole_archive_flag_spec \ +compiler_needs_object \ +with_gnu_ld \ +allow_undefined_flag \ +no_undefined_flag \ +hardcode_libdir_flag_spec \ +hardcode_libdir_separator \ +exclude_expsyms \ +include_expsyms \ +file_list_spec \ +variables_saved_for_relink \ +libname_spec \ +library_names_spec \ +soname_spec \ +install_override_mode \ +finish_eval \ +old_striplib \ +striplib \ +compiler_lib_search_dirs \ +predep_objects \ +postdep_objects \ +predeps \ +postdeps \ +compiler_lib_search_path \ +LD_CXX \ +reload_flag_CXX \ +compiler_CXX \ +lt_prog_compiler_no_builtin_flag_CXX \ +lt_prog_compiler_pic_CXX \ +lt_prog_compiler_wl_CXX \ +lt_prog_compiler_static_CXX \ +lt_cv_prog_compiler_c_o_CXX \ +export_dynamic_flag_spec_CXX \ +whole_archive_flag_spec_CXX \ +compiler_needs_object_CXX \ +with_gnu_ld_CXX \ +allow_undefined_flag_CXX \ +no_undefined_flag_CXX \ +hardcode_libdir_flag_spec_CXX \ +hardcode_libdir_separator_CXX \ +exclude_expsyms_CXX \ +include_expsyms_CXX \ +file_list_spec_CXX \ +compiler_lib_search_dirs_CXX \ +predep_objects_CXX \ +postdep_objects_CXX \ +predeps_CXX \ +postdeps_CXX \ +compiler_lib_search_path_CXX; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in reload_cmds \ +old_postinstall_cmds \ +old_postuninstall_cmds \ +old_archive_cmds \ +extract_expsyms_cmds \ +old_archive_from_new_cmds \ +old_archive_from_expsyms_cmds \ +archive_cmds \ +archive_expsym_cmds \ +module_cmds \ +module_expsym_cmds \ +export_symbols_cmds \ +prelink_cmds \ +postlink_cmds \ +postinstall_cmds \ +postuninstall_cmds \ +finish_cmds \ +sys_lib_search_path_spec \ +configure_time_dlsearch_path \ +configure_time_lt_sys_library_path \ +reload_cmds_CXX \ +old_archive_cmds_CXX \ +old_archive_from_new_cmds_CXX \ +old_archive_from_expsyms_cmds_CXX \ +archive_cmds_CXX \ +archive_expsym_cmds_CXX \ +module_cmds_CXX \ +module_expsym_cmds_CXX \ +export_symbols_cmds_CXX \ +prelink_cmds_CXX \ +postlink_cmds_CXX; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +ac_aux_dir='$ac_aux_dir' + +# See if we are running on zsh, and set the options that allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + + + PACKAGE='$PACKAGE' + VERSION='$VERSION' + RM='$RM' + ofile='$ofile' + + + + + + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; + "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= ac_tmp= + trap 'exit_status=$? + : "${ac_tmp:=$tmp}" + { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 +ac_tmp=$tmp + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$ac_tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ + || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove sole $(srcdir), +# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ +h +s/// +s/^/:/ +s/[ ]*$/:/ +s/:\$(srcdir):/:/g +s/:\${srcdir}:/:/g +s/:@srcdir@:/:/g +s/^:*// +s/:*$// +x +s/\(=[ ]*\).*/\1/ +G +s/\n// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + +# Set up the scripts for CONFIG_HEADERS section. +# No need to generate them if there are no CONFIG_HEADERS. +# This happens for instance with `./config.status Makefile'. +if test -n "$CONFIG_HEADERS"; then +cat >"$ac_tmp/defines.awk" <<\_ACAWK || +BEGIN { +_ACEOF + +# Transform confdefs.h into an awk script `defines.awk', embedded as +# here-document in config.status, that substitutes the proper values into +# config.h.in to produce config.h. + +# Create a delimiter string that does not exist in confdefs.h, to ease +# handling of long lines. +ac_delim='%!_!# ' +for ac_last_try in false false :; do + ac_tt=`sed -n "/$ac_delim/p" confdefs.h` + if test -z "$ac_tt"; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +# For the awk script, D is an array of macro values keyed by name, +# likewise P contains macro parameters if any. Preserve backslash +# newline sequences. + +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +sed -n ' +s/.\{148\}/&'"$ac_delim"'/g +t rset +:rset +s/^[ ]*#[ ]*define[ ][ ]*/ / +t def +d +:def +s/\\$// +t bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3"/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p +d +:bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3\\\\\\n"\\/p +t cont +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p +t cont +d +:cont +n +s/.\{148\}/&'"$ac_delim"'/g +t clear +:clear +s/\\$// +t bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/"/p +d +:bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p +b cont +' >$CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + for (key in D) D_is_set[key] = 1 + FS = "" +} +/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { + line = \$ 0 + split(line, arg, " ") + if (arg[1] == "#") { + defundef = arg[2] + mac1 = arg[3] + } else { + defundef = substr(arg[1], 2) + mac1 = arg[2] + } + split(mac1, mac2, "(") #) + macro = mac2[1] + prefix = substr(line, 1, index(line, defundef) - 1) + if (D_is_set[macro]) { + # Preserve the white space surrounding the "#". + print prefix "define", macro P[macro] D[macro] + next + } else { + # Replace #undef with comments. This is necessary, for example, + # in the case of _POSIX_SOURCE, which is predefined and required + # on some systems where configure will not decide to define it. + if (defundef == "undef") { + print "/*", prefix defundef, macro, "*/" + next + } + } +} +{ print } +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 +fi # test -n "$CONFIG_HEADERS" + + +eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$ac_tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$ac_tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ + >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + "$ac_tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&2;} + + rm -f "$ac_tmp/stdin" + case $ac_file in + -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; + *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; + esac \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + ;; + :H) + # + # CONFIG_HEADER + # + if test x"$ac_file" != x-; then + { + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" + } >"$ac_tmp/config.h" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +$as_echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f "$ac_file" + mv "$ac_tmp/config.h" "$ac_file" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + fi + else + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ + || as_fn_error $? "could not create -" "$LINENO" 5 + fi +# Compute "$ac_file"'s index in $config_headers. +_am_arg="$ac_file" +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || +$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$_am_arg" : 'X\(//\)[^/]' \| \ + X"$_am_arg" : 'X\(//\)$' \| \ + X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$_am_arg" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'`/stamp-h$_am_stamp_count + ;; + + :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +$as_echo "$as_me: executing $ac_file commands" >&6;} + ;; + esac + + + case $ac_file$ac_mode in + "depfiles":C) test x"$AMDEP_TRUE" != x"" || { + # Older Autoconf quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named 'Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`$as_dirname -- "$mf" || +$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$mf" : 'X\(//\)[^/]' \| \ + X"$mf" : 'X\(//\)$' \| \ + X"$mf" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$mf" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running 'make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "$am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`$as_dirname -- "$file" || +$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$file" : 'X\(//\)[^/]' \| \ + X"$file" : 'X\(//\)$' \| \ + X"$file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir=$dirpart/$fdir; as_fn_mkdir_p + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} + ;; + "libtool":C) + + # See if we are running on zsh, and set the options that allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST + fi + + cfgfile=${ofile}T + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL +# Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. + +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit, 1996 + +# Copyright (C) 2014 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program or library that is built +# using GNU Libtool, you may include this file under the same +# distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# The names of the tagged configurations supported by this script. +available_tags='CXX ' + +# Configured defaults for sys_lib_dlsearch_path munging. +: \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} + +# ### BEGIN LIBTOOL CONFIG + +# Which release of libtool.m4 was used? +macro_version=$macro_version +macro_revision=$macro_revision + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# What type of objects to build. +pic_mode=$pic_mode + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# Shared archive member basename,for filename based shared library versioning on AIX. +shared_archive_member_spec=$shared_archive_member_spec + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# An echo program that protects backslashes. +ECHO=$lt_ECHO + +# The PATH separator for the build system. +PATH_SEPARATOR=$lt_PATH_SEPARATOR + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="\$SED -e 1s/^X//" + +# A grep program that handles long lines. +GREP=$lt_GREP + +# An ERE matcher. +EGREP=$lt_EGREP + +# A literal string matcher. +FGREP=$lt_FGREP + +# A BSD- or MS-compatible name lister. +NM=$lt_NM + +# Whether we need soft or hard links. +LN_S=$lt_LN_S + +# What is the maximum length of a command? +max_cmd_len=$max_cmd_len + +# Object file suffix (normally "o"). +objext=$ac_objext + +# Executable file suffix (normally ""). +exeext=$exeext + +# whether the shell understands "unset". +lt_unset=$lt_unset + +# turn spaces into newlines. +SP2NL=$lt_lt_SP2NL + +# turn newlines into spaces. +NL2SP=$lt_lt_NL2SP + +# convert \$build file names to \$host format. +to_host_file_cmd=$lt_cv_to_host_file_cmd + +# convert \$build files to toolchain format. +to_tool_file_cmd=$lt_cv_to_tool_file_cmd + +# An object symbol dumper. +OBJDUMP=$lt_OBJDUMP + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method = "file_magic". +file_magic_cmd=$lt_file_magic_cmd + +# How to find potential files when deplibs_check_method = "file_magic". +file_magic_glob=$lt_file_magic_glob + +# Find potential files using nocaseglob when deplibs_check_method = "file_magic". +want_nocaseglob=$lt_want_nocaseglob + +# DLL creation program. +DLLTOOL=$lt_DLLTOOL + +# Command to associate shared and link libraries. +sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd + +# The archiver. +AR=$lt_AR + +# Flags to create an archive. +AR_FLAGS=$lt_AR_FLAGS + +# How to feed a file listing to the archiver. +archiver_list_spec=$lt_archiver_list_spec + +# A symbol stripping program. +STRIP=$lt_STRIP + +# Commands used to install an old-style archive. +RANLIB=$lt_RANLIB +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Whether to use a lock for old archive extraction. +lock_old_archive_extraction=$lock_old_archive_extraction + +# A C compiler. +LTCC=$lt_CC + +# LTCC compiler flags. +LTCFLAGS=$lt_CFLAGS + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration. +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm into a list of symbols to manually relocate. +global_symbol_to_import=$lt_lt_cv_sys_global_symbol_to_import + +# Transform the output of nm in a C name address pair. +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# Transform the output of nm in a C name address pair when lib prefix is needed. +global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix + +# The name lister interface. +nm_interface=$lt_lt_cv_nm_interface + +# Specify filename containing input files for \$NM. +nm_file_list_spec=$lt_nm_file_list_spec + +# The root where to search for dependent libraries,and where our libraries should be installed. +lt_sysroot=$lt_sysroot + +# Command to truncate a binary pipe. +lt_truncate_bin=$lt_lt_cv_truncate_bin + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# Used to examine libraries when file_magic_cmd begins with "file". +MAGIC_CMD=$MAGIC_CMD + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Manifest tool. +MANIFEST_TOOL=$lt_MANIFEST_TOOL + +# Tool to manipulate archived DWARF debug symbol files on Mac OS X. +DSYMUTIL=$lt_DSYMUTIL + +# Tool to change global to local symbols on Mac OS X. +NMEDIT=$lt_NMEDIT + +# Tool to manipulate fat objects and archives on Mac OS X. +LIPO=$lt_LIPO + +# ldd/readelf like tool for Mach-O binaries on Mac OS X. +OTOOL=$lt_OTOOL + +# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4. +OTOOL64=$lt_OTOOL64 + +# Old archive suffix (normally "a"). +libext=$libext + +# Shared library suffix (normally ".so"). +shrext_cmds=$lt_shrext_cmds + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at link time. +variables_saved_for_relink=$lt_variables_saved_for_relink + +# Do we need the "lib" prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Library versioning type. +version_type=$version_type + +# Shared library runtime path variable. +runpath_var=$runpath_var + +# Shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Permission mode override for installation of shared libraries. +install_override_mode=$lt_install_override_mode + +# Command to use after installation of a shared archive. +postinstall_cmds=$lt_postinstall_cmds + +# Command to use after uninstallation of a shared archive. +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# As "finish_cmds", except a single script fragment to be evaled but +# not shown. +finish_eval=$lt_finish_eval + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Compile-time system search path for libraries. +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Detected run-time system search path for libraries. +sys_lib_dlsearch_path_spec=$lt_configure_time_dlsearch_path + +# Explicit LT_SYS_LIBRARY_PATH set during ./configure time. +configure_time_lt_sys_library_path=$lt_configure_time_lt_sys_library_path + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + + +# The linker used to build libraries. +LD=$lt_LD + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds + +# A language specific compiler. +CC=$lt_compiler + +# Is the compiler the GNU compiler? +with_gcc=$GCC + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds +archive_expsym_cmds=$lt_archive_expsym_cmds + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds +module_expsym_cmds=$lt_module_expsym_cmds + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds + +# Commands necessary for finishing linking programs. +postlink_cmds=$lt_postlink_cmds + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action + +# The directories searched by this compiler when creating a shared library. +compiler_lib_search_dirs=$lt_compiler_lib_search_dirs + +# Dependencies to place before and after the objects being linked to +# create a shared library. +predep_objects=$lt_predep_objects +postdep_objects=$lt_postdep_objects +predeps=$lt_predeps +postdeps=$lt_postdeps + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path + +# ### END LIBTOOL CONFIG + +_LT_EOF + + cat <<'_LT_EOF' >> "$cfgfile" + +# ### BEGIN FUNCTIONS SHARED WITH CONFIGURE + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x@S|@2 in + x) + ;; + *:) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" + ;; + x:*) + eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" + ;; + *) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + esac +} + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in @S|@*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + + +# ### END FUNCTIONS SHARED WITH CONFIGURE + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + +ltmain=$ac_aux_dir/ltmain.sh + + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" + + + cat <<_LT_EOF >> "$ofile" + +# ### BEGIN LIBTOOL TAG CONFIG: CXX + +# The linker used to build libraries. +LD=$lt_LD_CXX + +# How to create reloadable object files. +reload_flag=$lt_reload_flag_CXX +reload_cmds=$lt_reload_cmds_CXX + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds_CXX + +# A language specific compiler. +CC=$lt_compiler_CXX + +# Is the compiler the GNU compiler? +with_gcc=$GCC_CXX + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_CXX + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic_CXX + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl_CXX + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static_CXX + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o_CXX + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc_CXX + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_CXX + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_CXX + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec_CXX + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object_CXX + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_CXX + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_CXX + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds_CXX +archive_expsym_cmds=$lt_archive_expsym_cmds_CXX + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds_CXX +module_expsym_cmds=$lt_module_expsym_cmds_CXX + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld_CXX + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag_CXX + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag_CXX + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_CXX + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator_CXX + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct_CXX + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute_CXX + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L_CXX + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var_CXX + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic_CXX + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath_CXX + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs_CXX + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols_CXX + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds_CXX + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms_CXX + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms_CXX + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds_CXX + +# Commands necessary for finishing linking programs. +postlink_cmds=$lt_postlink_cmds_CXX + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec_CXX + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action_CXX + +# The directories searched by this compiler when creating a shared library. +compiler_lib_search_dirs=$lt_compiler_lib_search_dirs_CXX + +# Dependencies to place before and after the objects being linked to +# create a shared library. +predep_objects=$lt_predep_objects_CXX +postdep_objects=$lt_postdep_objects_CXX +predeps=$lt_predeps_CXX +postdeps=$lt_postdeps_CXX + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path_CXX + +# ### END LIBTOOL TAG CONFIG: CXX +_LT_EOF + + ;; + + esac +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit 1 +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + diff --git a/src/c/autom4te.cache/output.1 b/src/c/autom4te.cache/output.1 new file mode 100644 index 00000000000..8700b4e0268 --- /dev/null +++ b/src/c/autom4te.cache/output.1 @@ -0,0 +1,21092 @@ +@%:@! /bin/sh +@%:@ Guess values for system-dependent variables and create Makefiles. +@%:@ Generated by GNU Autoconf 2.69 for zookeeper C client 3.6.0. +@%:@ +@%:@ Report bugs to . +@%:@ +@%:@ +@%:@ Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +@%:@ +@%:@ +@%:@ This configure script is free software; the Free Software Foundation +@%:@ gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in @%:@( + *posix*) : + set -o posix ;; @%:@( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in @%:@( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in @%:@(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in @%:@ (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in @%:@( + *posix*) : + set -o posix ;; @%:@( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 + + test -n \"\${ZSH_VERSION+set}\${BASH_VERSION+set}\" || ( + ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + PATH=/empty FPATH=/empty; export PATH FPATH + test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ + || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in @%:@( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in @%:@ (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org and +$0: user@zookeeper.apache.org about your system, including +$0: any error possibly output before this message. Then +$0: install a modern shell, or manually run the script +$0: under such a shell if you do have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +@%:@ as_fn_unset VAR +@%:@ --------------- +@%:@ Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +@%:@ as_fn_set_status STATUS +@%:@ ----------------------- +@%:@ Set @S|@? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} @%:@ as_fn_set_status + +@%:@ as_fn_exit STATUS +@%:@ ----------------- +@%:@ Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} @%:@ as_fn_exit + +@%:@ as_fn_mkdir_p +@%:@ ------------- +@%:@ Create "@S|@as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} @%:@ as_fn_mkdir_p + +@%:@ as_fn_executable_p FILE +@%:@ ----------------------- +@%:@ Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} @%:@ as_fn_executable_p +@%:@ as_fn_append VAR VALUE +@%:@ ---------------------- +@%:@ Append the text in VALUE to the end of the definition contained in VAR. Take +@%:@ advantage of any shell optimizations that allow amortized linear growth over +@%:@ repeated appends, instead of the typical quadratic growth present in naive +@%:@ implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +@%:@ as_fn_arith ARG... +@%:@ ------------------ +@%:@ Perform arithmetic evaluation on the ARGs, and store the result in the +@%:@ global @S|@as_val. Take advantage of shells that can avoid forks. The arguments +@%:@ must be portable across @S|@(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +@%:@ as_fn_error STATUS ERROR [LINENO LOG_FD] +@%:@ ---------------------------------------- +@%:@ Output "`basename @S|@0`: error: ERROR" to stderr. If LINENO and LOG_FD are +@%:@ provided, also output the error to LOG_FD, referencing LINENO. Then exit the +@%:@ script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} @%:@ as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in @%:@((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + +SHELL=${CONFIG_SHELL-/bin/sh} + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIB@&t@OBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='zookeeper C client' +PACKAGE_TARNAME='zookeeper' +PACKAGE_VERSION='3.6.0' +PACKAGE_STRING='zookeeper C client 3.6.0' +PACKAGE_BUGREPORT='user@zookeeper.apache.org' +PACKAGE_URL='' + +ac_unique_file="src/zookeeper.c" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='am__EXEEXT_FALSE +am__EXEEXT_TRUE +LTLIBOBJS +LIB@&t@OBJS +SOLARIS_FALSE +SOLARIS_TRUE +CLOCK_GETTIME_LIBS +USEIPV6 +WANT_SYNCAPI_FALSE +WANT_SYNCAPI_TRUE +CXXCPP +CPP +LT_SYS_LIBRARY_PATH +OTOOL64 +OTOOL +LIPO +NMEDIT +DSYMUTIL +MANIFEST_TOOL +RANLIB +ac_ct_AR +AR +DLLTOOL +OBJDUMP +NM +ac_ct_DUMPBIN +DUMPBIN +LD +FGREP +EGREP +GREP +SED +host_os +host_vendor +host_cpu +host +build_os +build_vendor +build_cpu +build +LIBTOOL +LN_S +am__fastdepCXX_FALSE +am__fastdepCXX_TRUE +CXXDEPMODE +ac_ct_CXX +CXXFLAGS +CXX +am__fastdepCC_FALSE +am__fastdepCC_TRUE +CCDEPMODE +am__nodep +AMDEPBACKSLASH +AMDEP_FALSE +AMDEP_TRUE +am__quote +am__include +DEPDIR +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +CPPUNIT_CFLAGS +AM_BACKSLASH +AM_DEFAULT_VERBOSITY +AM_DEFAULT_V +AM_V +am__untar +am__tar +AMTAR +am__leading_dot +SET_MAKE +AWK +mkdir_p +MKDIR_P +INSTALL_STRIP_PROGRAM +STRIP +install_sh +MAKEINFO +AUTOHEADER +AUTOMAKE +AUTOCONF +ACLOCAL +VERSION +PACKAGE +CYGPATH_W +am__isrc +INSTALL_DATA +INSTALL_SCRIPT +INSTALL_PROGRAM +DOXYGEN_PAPER_SIZE +DX_COND_latex_FALSE +DX_COND_latex_TRUE +DX_COND_pdf_FALSE +DX_COND_pdf_TRUE +DX_PDFLATEX +DX_FLAG_pdf +DX_COND_ps_FALSE +DX_COND_ps_TRUE +DX_EGREP +DX_DVIPS +DX_MAKEINDEX +DX_LATEX +DX_FLAG_ps +DX_COND_html_FALSE +DX_COND_html_TRUE +DX_FLAG_html +DX_COND_chi_FALSE +DX_COND_chi_TRUE +DX_FLAG_chi +DX_COND_chm_FALSE +DX_COND_chm_TRUE +DX_HHC +DX_FLAG_chm +DX_COND_xml_FALSE +DX_COND_xml_TRUE +DX_FLAG_xml +DX_COND_rtf_FALSE +DX_COND_rtf_TRUE +DX_FLAG_rtf +DX_COND_man_FALSE +DX_COND_man_TRUE +DX_FLAG_man +DX_COND_dot_FALSE +DX_COND_dot_TRUE +DX_DOT +DX_FLAG_dot +DX_COND_doc_FALSE +DX_COND_doc_TRUE +DX_PERL +DX_DOXYGEN +DX_FLAG_doc +DX_ENV +DX_DOCDIR +DX_CONFIG +DX_PROJECT +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +enable_doxygen_doc +enable_doxygen_dot +enable_doxygen_man +enable_doxygen_rtf +enable_doxygen_xml +enable_doxygen_chm +enable_doxygen_chi +enable_doxygen_html +enable_doxygen_ps +enable_doxygen_pdf +enable_silent_rules +with_cppunit +enable_dependency_tracking +enable_shared +enable_static +with_pic +enable_fast_install +with_aix_soname +with_gnu_ld +with_sysroot +enable_libtool_lock +enable_debug +with_syncapi +' + ac_precious_vars='build_alias +host_alias +target_alias +DOXYGEN_PAPER_SIZE +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CXX +CXXFLAGS +CCC +LT_SYS_LIBRARY_PATH +CPP +CXXCPP' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *=) ac_optarg= ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error $? "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error $? "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error $? "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures zookeeper C client 3.6.0 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking ...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + @<:@@S|@ac_default_prefix@:>@ + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + @<:@PREFIX@:>@ + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root @<:@DATAROOTDIR/doc/zookeeper@:>@ + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +Program names: + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM run sed PROGRAM on installed program names + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of zookeeper C client 3.6.0:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-doxygen-doc don't generate any doxygen documentation + --disable-doxygen-dot don't generate graphics for doxygen documentation + --enable-doxygen-man generate doxygen manual pages + --enable-doxygen-rtf generate doxygen RTF documentation + --enable-doxygen-xml generate doxygen XML documentation + --enable-doxygen-chm generate doxygen compressed HTML help documentation + --enable-doxygen-chi generate doxygen seperate compressed HTML help index + file + --disable-doxygen-html don't generate doxygen plain HTML documentation + --enable-doxygen-ps generate doxygen PostScript documentation + --enable-doxygen-pdf generate doxygen PDF documentation + --enable-silent-rules less verbose build output (undo: "make V=1") + --disable-silent-rules verbose build output (undo: "make V=0") + --enable-dependency-tracking + do not reject slow dependency extractors + --disable-dependency-tracking + speeds up one-time build + --enable-shared@<:@=PKGS@:>@ build shared libraries @<:@default=yes@:>@ + --enable-static@<:@=PKGS@:>@ build static libraries @<:@default=yes@:>@ + --enable-fast-install@<:@=PKGS@:>@ + optimize for fast installation @<:@default=yes@:>@ + --disable-libtool-lock avoid locking (might break parallel builds) + --enable-debug enable debug build @<:@default=no@:>@ + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --without-cppunit do not use CPPUNIT + --with-pic@<:@=PKGS@:>@ try to use only PIC/non-PIC objects @<:@default=use + both@:>@ + --with-aix-soname=aix|svr4|both + shared library versioning (aka "SONAME") variant to + provide on AIX, @<:@default=aix@:>@. + --with-gnu-ld assume the C compiler uses GNU ld @<:@default=no@:>@ + --with-sysroot@<:@=DIR@:>@ Search for dependent libraries within DIR (or the + compiler's sysroot if not specified). + --with-syncapi build with support for SyncAPI @<:@default=yes@:>@ + +Some influential environment variables: + DOXYGEN_PAPER_SIZE + a4wide (default), a4, letter, legal or executive + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CXX C++ compiler command + CXXFLAGS C++ compiler flags + LT_SYS_LIBRARY_PATH + User-defined run-time library search path. + CPP C preprocessor + CXXCPP C++ preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +zookeeper C client configure 3.6.0 +generated by GNU Autoconf 2.69 + +Copyright (C) 2012 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +@%:@ ac_fn_c_try_compile LINENO +@%:@ -------------------------- +@%:@ Try to compile conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_compile + +@%:@ ac_fn_cxx_try_compile LINENO +@%:@ ---------------------------- +@%:@ Try to compile conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_cxx_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_cxx_try_compile + +@%:@ ac_fn_c_try_link LINENO +@%:@ ----------------------- +@%:@ Try to link conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_link + +@%:@ ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +@%:@ ------------------------------------------------------- +@%:@ Tests whether HEADER exists and can be compiled using the include files in +@%:@ INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +@%:@include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_header_compile + +@%:@ ac_fn_c_try_cpp LINENO +@%:@ ---------------------- +@%:@ Try to preprocess conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_cpp + +@%:@ ac_fn_c_try_run LINENO +@%:@ ---------------------- +@%:@ Try to link conftest.@S|@ac_ext, and return whether this succeeded. Assumes +@%:@ that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_c_try_run + +@%:@ ac_fn_c_check_func LINENO FUNC VAR +@%:@ ---------------------------------- +@%:@ Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_func + +@%:@ ac_fn_cxx_try_cpp LINENO +@%:@ ------------------------ +@%:@ Try to preprocess conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_cxx_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_cxx_try_cpp + +@%:@ ac_fn_cxx_try_link LINENO +@%:@ ------------------------- +@%:@ Try to link conftest.@S|@ac_ext, and return whether this succeeded. +ac_fn_cxx_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} @%:@ ac_fn_cxx_try_link + +@%:@ ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +@%:@ ------------------------------------------------------- +@%:@ Tests whether HEADER exists, giving a warning if it cannot be compiled using +@%:@ the include files in INCLUDES and setting the cache variable VAR +@%:@ accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if eval \${$3+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +@%:@include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.i conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( $as_echo "## ---------------------------------------- ## +## Report this to user@zookeeper.apache.org ## +## ---------------------------------------- ##" + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_header_mongrel + +@%:@ ac_fn_c_check_type LINENO TYPE VAR INCLUDES +@%:@ ------------------------------------------- +@%:@ Tests whether TYPE exists after having included INCLUDES, setting cache +@%:@ variable VAR accordingly. +ac_fn_c_check_type () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=no" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof ($2)) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof (($2))) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + eval "$3=yes" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} @%:@ ac_fn_c_check_type +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by zookeeper C client $as_me 3.6.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + $as_echo "## ---------------- ## +## Cache variables. ## +## ---------------- ##" + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + $as_echo "## ----------------- ## +## Output variables. ## +## ----------------- ##" + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + $as_echo "## ------------------- ## +## File substitutions. ## +## ------------------- ##" + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + $as_echo "## ----------- ## +## confdefs.h. ## +## ----------- ##" + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + # We do not want a PATH search for config.site. + case $CONFIG_SITE in @%:@(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" \ + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + +# Save initial CFLAGS and CXXFLAGS values before AC_PROG_CC and AC_PROG_CXX +init_cflags="$CFLAGS" +init_cxxflags="$CXXFLAGS" + +# initialize Doxygen support + + + + + + + + + + +# Files: +DX_PROJECT=zookeeper + +DX_CONFIG=c-doc.Doxyfile + +DX_DOCDIR=docs + + +# Environment variables used inside doxygen.cfg: +DX_ENV="$DX_ENV SRCDIR='$srcdir'" + +DX_ENV="$DX_ENV PROJECT='$DX_PROJECT'" + +DX_ENV="$DX_ENV DOCDIR='$DX_DOCDIR'" + +DX_ENV="$DX_ENV VERSION='$PACKAGE_VERSION'" + + +# Doxygen itself: + + + + @%:@ Check whether --enable-doxygen-doc was given. +if test "${enable_doxygen_doc+set}" = set; then : + enableval=$enable_doxygen_doc; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_doc=1 + + +;; #( +n|N|no|No|NO) + DX_FLAG_doc=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-doc" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_doc=1 + + + +fi + +if test "$DX_FLAG_doc" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}doxygen", so it can be a program name with args. +set dummy ${ac_tool_prefix}doxygen; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DOXYGEN+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DOXYGEN in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DOXYGEN="$DX_DOXYGEN" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DOXYGEN=$ac_cv_path_DX_DOXYGEN +if test -n "$DX_DOXYGEN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOXYGEN" >&5 +$as_echo "$DX_DOXYGEN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DOXYGEN"; then + ac_pt_DX_DOXYGEN=$DX_DOXYGEN + # Extract the first word of "doxygen", so it can be a program name with args. +set dummy doxygen; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DOXYGEN+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DOXYGEN in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DOXYGEN="$ac_pt_DX_DOXYGEN" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DOXYGEN=$ac_cv_path_ac_pt_DX_DOXYGEN +if test -n "$ac_pt_DX_DOXYGEN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOXYGEN" >&5 +$as_echo "$ac_pt_DX_DOXYGEN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DOXYGEN" = x; then + DX_DOXYGEN="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DOXYGEN=$ac_pt_DX_DOXYGEN + fi +else + DX_DOXYGEN="$ac_cv_path_DX_DOXYGEN" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DOXYGEN" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: doxygen not found - will not generate any doxygen documentation" >&5 +$as_echo "$as_me: WARNING: doxygen not found - will not generate any doxygen documentation" >&2;} + DX_FLAG_doc=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}perl", so it can be a program name with args. +set dummy ${ac_tool_prefix}perl; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_PERL+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_PERL in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_PERL="$DX_PERL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_PERL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_PERL=$ac_cv_path_DX_PERL +if test -n "$DX_PERL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PERL" >&5 +$as_echo "$DX_PERL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_PERL"; then + ac_pt_DX_PERL=$DX_PERL + # Extract the first word of "perl", so it can be a program name with args. +set dummy perl; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_PERL+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_PERL in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_PERL="$ac_pt_DX_PERL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_PERL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_PERL=$ac_cv_path_ac_pt_DX_PERL +if test -n "$ac_pt_DX_PERL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PERL" >&5 +$as_echo "$ac_pt_DX_PERL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_PERL" = x; then + DX_PERL="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_PERL=$ac_pt_DX_PERL + fi +else + DX_PERL="$ac_cv_path_DX_PERL" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_PERL" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: perl not found - will not generate any doxygen documentation" >&5 +$as_echo "$as_me: WARNING: perl not found - will not generate any doxygen documentation" >&2;} + DX_FLAG_doc=0 + +fi + + : +fi +if test "$DX_FLAG_doc" = 1; then + if :; then + DX_COND_doc_TRUE= + DX_COND_doc_FALSE='#' +else + DX_COND_doc_TRUE='#' + DX_COND_doc_FALSE= +fi + + DX_ENV="$DX_ENV PERL_PATH='$DX_PERL'" + + : +else + if false; then + DX_COND_doc_TRUE= + DX_COND_doc_FALSE='#' +else + DX_COND_doc_TRUE='#' + DX_COND_doc_FALSE= +fi + + + : +fi + + +# Dot for graphics: + + + + @%:@ Check whether --enable-doxygen-dot was given. +if test "${enable_doxygen_dot+set}" = set; then : + enableval=$enable_doxygen_dot; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_dot=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-dot requires doxygen-dot" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_dot=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-dot" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_dot=1 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_dot=0 + + + +fi + +if test "$DX_FLAG_dot" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dot", so it can be a program name with args. +set dummy ${ac_tool_prefix}dot; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DOT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DOT in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DOT="$DX_DOT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DOT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DOT=$ac_cv_path_DX_DOT +if test -n "$DX_DOT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOT" >&5 +$as_echo "$DX_DOT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DOT"; then + ac_pt_DX_DOT=$DX_DOT + # Extract the first word of "dot", so it can be a program name with args. +set dummy dot; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DOT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DOT in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DOT="$ac_pt_DX_DOT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DOT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DOT=$ac_cv_path_ac_pt_DX_DOT +if test -n "$ac_pt_DX_DOT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOT" >&5 +$as_echo "$ac_pt_DX_DOT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DOT" = x; then + DX_DOT="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DOT=$ac_pt_DX_DOT + fi +else + DX_DOT="$ac_cv_path_DX_DOT" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DOT" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dot not found - will not generate graphics for doxygen documentation" >&5 +$as_echo "$as_me: WARNING: dot not found - will not generate graphics for doxygen documentation" >&2;} + DX_FLAG_dot=0 + +fi + + : +fi +if test "$DX_FLAG_dot" = 1; then + if :; then + DX_COND_dot_TRUE= + DX_COND_dot_FALSE='#' +else + DX_COND_dot_TRUE='#' + DX_COND_dot_FALSE= +fi + + DX_ENV="$DX_ENV HAVE_DOT='YES'" + + DX_ENV="$DX_ENV DOT_PATH='`expr ".$DX_DOT" : '\(\.\)[^/]*$' \| "x$DX_DOT" : 'x\(.*\)/[^/]*$'`'" + + : +else + if false; then + DX_COND_dot_TRUE= + DX_COND_dot_FALSE='#' +else + DX_COND_dot_TRUE='#' + DX_COND_dot_FALSE= +fi + + DX_ENV="$DX_ENV HAVE_DOT='NO'" + + : +fi + + +# Man pages generation: + + + + @%:@ Check whether --enable-doxygen-man was given. +if test "${enable_doxygen_man+set}" = set; then : + enableval=$enable_doxygen_man; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_man=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-man requires doxygen-man" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_man=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-man" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_man=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_man=0 + + + +fi + +if test "$DX_FLAG_man" = 1; then + + : +fi +if test "$DX_FLAG_man" = 1; then + if :; then + DX_COND_man_TRUE= + DX_COND_man_FALSE='#' +else + DX_COND_man_TRUE='#' + DX_COND_man_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_MAN='YES'" + + : +else + if false; then + DX_COND_man_TRUE= + DX_COND_man_FALSE='#' +else + DX_COND_man_TRUE='#' + DX_COND_man_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_MAN='NO'" + + : +fi + + +# RTF file generation: + + + + @%:@ Check whether --enable-doxygen-rtf was given. +if test "${enable_doxygen_rtf+set}" = set; then : + enableval=$enable_doxygen_rtf; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_rtf=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-rtf requires doxygen-rtf" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_rtf=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-rtf" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_rtf=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_rtf=0 + + + +fi + +if test "$DX_FLAG_rtf" = 1; then + + : +fi +if test "$DX_FLAG_rtf" = 1; then + if :; then + DX_COND_rtf_TRUE= + DX_COND_rtf_FALSE='#' +else + DX_COND_rtf_TRUE='#' + DX_COND_rtf_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_RTF='YES'" + + : +else + if false; then + DX_COND_rtf_TRUE= + DX_COND_rtf_FALSE='#' +else + DX_COND_rtf_TRUE='#' + DX_COND_rtf_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_RTF='NO'" + + : +fi + + +# XML file generation: + + + + @%:@ Check whether --enable-doxygen-xml was given. +if test "${enable_doxygen_xml+set}" = set; then : + enableval=$enable_doxygen_xml; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_xml=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-xml requires doxygen-xml" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_xml=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-xml" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_xml=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_xml=0 + + + +fi + +if test "$DX_FLAG_xml" = 1; then + + : +fi +if test "$DX_FLAG_xml" = 1; then + if :; then + DX_COND_xml_TRUE= + DX_COND_xml_FALSE='#' +else + DX_COND_xml_TRUE='#' + DX_COND_xml_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_XML='YES'" + + : +else + if false; then + DX_COND_xml_TRUE= + DX_COND_xml_FALSE='#' +else + DX_COND_xml_TRUE='#' + DX_COND_xml_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_XML='NO'" + + : +fi + + +# (Compressed) HTML help generation: + + + + @%:@ Check whether --enable-doxygen-chm was given. +if test "${enable_doxygen_chm+set}" = set; then : + enableval=$enable_doxygen_chm; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_chm=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-chm requires doxygen-chm" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_chm=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-chm" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_chm=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_chm=0 + + + +fi + +if test "$DX_FLAG_chm" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}hhc", so it can be a program name with args. +set dummy ${ac_tool_prefix}hhc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_HHC+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_HHC in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_HHC="$DX_HHC" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_HHC="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_HHC=$ac_cv_path_DX_HHC +if test -n "$DX_HHC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_HHC" >&5 +$as_echo "$DX_HHC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_HHC"; then + ac_pt_DX_HHC=$DX_HHC + # Extract the first word of "hhc", so it can be a program name with args. +set dummy hhc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_HHC+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_HHC in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_HHC="$ac_pt_DX_HHC" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_HHC="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_HHC=$ac_cv_path_ac_pt_DX_HHC +if test -n "$ac_pt_DX_HHC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_HHC" >&5 +$as_echo "$ac_pt_DX_HHC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_HHC" = x; then + DX_HHC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_HHC=$ac_pt_DX_HHC + fi +else + DX_HHC="$ac_cv_path_DX_HHC" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_HHC" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&5 +$as_echo "$as_me: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&2;} + DX_FLAG_chm=0 + +fi + + : +fi +if test "$DX_FLAG_chm" = 1; then + if :; then + DX_COND_chm_TRUE= + DX_COND_chm_FALSE='#' +else + DX_COND_chm_TRUE='#' + DX_COND_chm_FALSE= +fi + + DX_ENV="$DX_ENV HHC_PATH='$DX_HHC'" + + DX_ENV="$DX_ENV GENERATE_HTML='YES'" + + DX_ENV="$DX_ENV GENERATE_HTMLHELP='YES'" + + : +else + if false; then + DX_COND_chm_TRUE= + DX_COND_chm_FALSE='#' +else + DX_COND_chm_TRUE='#' + DX_COND_chm_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_HTMLHELP='NO'" + + : +fi + + +# Seperate CHI file generation. + + + + @%:@ Check whether --enable-doxygen-chi was given. +if test "${enable_doxygen_chi+set}" = set; then : + enableval=$enable_doxygen_chi; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_chi=1 + + +test "$DX_FLAG_chm" = "1" \ +|| as_fn_error $? "doxygen-chi requires doxygen-chi" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_chi=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-chi" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_chi=0 + + +test "$DX_FLAG_chm" = "1" || DX_FLAG_chi=0 + + + +fi + +if test "$DX_FLAG_chi" = 1; then + + : +fi +if test "$DX_FLAG_chi" = 1; then + if :; then + DX_COND_chi_TRUE= + DX_COND_chi_FALSE='#' +else + DX_COND_chi_TRUE='#' + DX_COND_chi_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_CHI='YES'" + + : +else + if false; then + DX_COND_chi_TRUE= + DX_COND_chi_FALSE='#' +else + DX_COND_chi_TRUE='#' + DX_COND_chi_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_CHI='NO'" + + : +fi + + +# Plain HTML pages generation: + + + + @%:@ Check whether --enable-doxygen-html was given. +if test "${enable_doxygen_html+set}" = set; then : + enableval=$enable_doxygen_html; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_html=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-html requires doxygen-html" "$LINENO" 5 + +test "$DX_FLAG_chm" = "0" \ +|| as_fn_error $? "doxygen-html contradicts doxygen-html" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_html=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-html" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_html=1 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_html=0 + + +test "$DX_FLAG_chm" = "0" || DX_FLAG_html=0 + + + +fi + +if test "$DX_FLAG_html" = 1; then + + : +fi +if test "$DX_FLAG_html" = 1; then + if :; then + DX_COND_html_TRUE= + DX_COND_html_FALSE='#' +else + DX_COND_html_TRUE='#' + DX_COND_html_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_HTML='YES'" + + : +else + if false; then + DX_COND_html_TRUE= + DX_COND_html_FALSE='#' +else + DX_COND_html_TRUE='#' + DX_COND_html_FALSE= +fi + + test "$DX_FLAG_chm" = 1 || DX_ENV="$DX_ENV GENERATE_HTML='NO'" + + : +fi + + +# PostScript file generation: + + + + @%:@ Check whether --enable-doxygen-ps was given. +if test "${enable_doxygen_ps+set}" = set; then : + enableval=$enable_doxygen_ps; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_ps=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-ps requires doxygen-ps" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_ps=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-ps" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_ps=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_ps=0 + + + +fi + +if test "$DX_FLAG_ps" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}latex", so it can be a program name with args. +set dummy ${ac_tool_prefix}latex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_LATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_LATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_LATEX="$DX_LATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_LATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_LATEX=$ac_cv_path_DX_LATEX +if test -n "$DX_LATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_LATEX" >&5 +$as_echo "$DX_LATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_LATEX"; then + ac_pt_DX_LATEX=$DX_LATEX + # Extract the first word of "latex", so it can be a program name with args. +set dummy latex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_LATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_LATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_LATEX="$ac_pt_DX_LATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_LATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_LATEX=$ac_cv_path_ac_pt_DX_LATEX +if test -n "$ac_pt_DX_LATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_LATEX" >&5 +$as_echo "$ac_pt_DX_LATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_LATEX" = x; then + DX_LATEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_LATEX=$ac_pt_DX_LATEX + fi +else + DX_LATEX="$ac_cv_path_DX_LATEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_LATEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: latex not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: latex not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args. +set dummy ${ac_tool_prefix}makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX +if test -n "$DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5 +$as_echo "$DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_MAKEINDEX"; then + ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX + # Extract the first word of "makeindex", so it can be a program name with args. +set dummy makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX +if test -n "$ac_pt_DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5 +$as_echo "$ac_pt_DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_MAKEINDEX" = x; then + DX_MAKEINDEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX + fi +else + DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_MAKEINDEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dvips", so it can be a program name with args. +set dummy ${ac_tool_prefix}dvips; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DVIPS+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DVIPS in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DVIPS="$DX_DVIPS" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DVIPS=$ac_cv_path_DX_DVIPS +if test -n "$DX_DVIPS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DVIPS" >&5 +$as_echo "$DX_DVIPS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DVIPS"; then + ac_pt_DX_DVIPS=$DX_DVIPS + # Extract the first word of "dvips", so it can be a program name with args. +set dummy dvips; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DVIPS+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DVIPS in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DVIPS="$ac_pt_DX_DVIPS" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DVIPS=$ac_cv_path_ac_pt_DX_DVIPS +if test -n "$ac_pt_DX_DVIPS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DVIPS" >&5 +$as_echo "$ac_pt_DX_DVIPS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DVIPS" = x; then + DX_DVIPS="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DVIPS=$ac_pt_DX_DVIPS + fi +else + DX_DVIPS="$ac_cv_path_DX_DVIPS" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DVIPS" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args. +set dummy ${ac_tool_prefix}egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_EGREP=$ac_cv_path_DX_EGREP +if test -n "$DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5 +$as_echo "$DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_EGREP"; then + ac_pt_DX_EGREP=$DX_EGREP + # Extract the first word of "egrep", so it can be a program name with args. +set dummy egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP +if test -n "$ac_pt_DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5 +$as_echo "$ac_pt_DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_EGREP" = x; then + DX_EGREP="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_EGREP=$ac_pt_DX_EGREP + fi +else + DX_EGREP="$ac_cv_path_DX_EGREP" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_EGREP" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + : +fi +if test "$DX_FLAG_ps" = 1; then + if :; then + DX_COND_ps_TRUE= + DX_COND_ps_FALSE='#' +else + DX_COND_ps_TRUE='#' + DX_COND_ps_FALSE= +fi + + + : +else + if false; then + DX_COND_ps_TRUE= + DX_COND_ps_FALSE='#' +else + DX_COND_ps_TRUE='#' + DX_COND_ps_FALSE= +fi + + + : +fi + + +# PDF file generation: + + + + @%:@ Check whether --enable-doxygen-pdf was given. +if test "${enable_doxygen_pdf+set}" = set; then : + enableval=$enable_doxygen_pdf; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_pdf=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-pdf requires doxygen-pdf" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_pdf=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-pdf" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_pdf=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_pdf=0 + + + +fi + +if test "$DX_FLAG_pdf" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pdflatex", so it can be a program name with args. +set dummy ${ac_tool_prefix}pdflatex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_PDFLATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_PDFLATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_PDFLATEX="$DX_PDFLATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_PDFLATEX=$ac_cv_path_DX_PDFLATEX +if test -n "$DX_PDFLATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PDFLATEX" >&5 +$as_echo "$DX_PDFLATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_PDFLATEX"; then + ac_pt_DX_PDFLATEX=$DX_PDFLATEX + # Extract the first word of "pdflatex", so it can be a program name with args. +set dummy pdflatex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_PDFLATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_PDFLATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_PDFLATEX="$ac_pt_DX_PDFLATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_PDFLATEX=$ac_cv_path_ac_pt_DX_PDFLATEX +if test -n "$ac_pt_DX_PDFLATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PDFLATEX" >&5 +$as_echo "$ac_pt_DX_PDFLATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_PDFLATEX" = x; then + DX_PDFLATEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_PDFLATEX=$ac_pt_DX_PDFLATEX + fi +else + DX_PDFLATEX="$ac_cv_path_DX_PDFLATEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_PDFLATEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args. +set dummy ${ac_tool_prefix}makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX +if test -n "$DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5 +$as_echo "$DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_MAKEINDEX"; then + ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX + # Extract the first word of "makeindex", so it can be a program name with args. +set dummy makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX +if test -n "$ac_pt_DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5 +$as_echo "$ac_pt_DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_MAKEINDEX" = x; then + DX_MAKEINDEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX + fi +else + DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_MAKEINDEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args. +set dummy ${ac_tool_prefix}egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_EGREP=$ac_cv_path_DX_EGREP +if test -n "$DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5 +$as_echo "$DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_EGREP"; then + ac_pt_DX_EGREP=$DX_EGREP + # Extract the first word of "egrep", so it can be a program name with args. +set dummy egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP +if test -n "$ac_pt_DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5 +$as_echo "$ac_pt_DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_EGREP" = x; then + DX_EGREP="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_EGREP=$ac_pt_DX_EGREP + fi +else + DX_EGREP="$ac_cv_path_DX_EGREP" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_EGREP" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + : +fi +if test "$DX_FLAG_pdf" = 1; then + if :; then + DX_COND_pdf_TRUE= + DX_COND_pdf_FALSE='#' +else + DX_COND_pdf_TRUE='#' + DX_COND_pdf_FALSE= +fi + + + : +else + if false; then + DX_COND_pdf_TRUE= + DX_COND_pdf_FALSE='#' +else + DX_COND_pdf_TRUE='#' + DX_COND_pdf_FALSE= +fi + + + : +fi + + +# LaTeX generation for PS and/or PDF: +if test "$DX_FLAG_ps" = 1 || test "$DX_FLAG_pdf" = 1; then + if :; then + DX_COND_latex_TRUE= + DX_COND_latex_FALSE='#' +else + DX_COND_latex_TRUE='#' + DX_COND_latex_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_LATEX='YES'" + +else + if false; then + DX_COND_latex_TRUE= + DX_COND_latex_FALSE='#' +else + DX_COND_latex_TRUE='#' + DX_COND_latex_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_LATEX='NO'" + +fi + +# Paper size for PS and/or PDF: + +case "$DOXYGEN_PAPER_SIZE" in +#( +"") + DOXYGEN_PAPER_SIZE="" + +;; #( +a4wide|a4|letter|legal|executive) + DX_ENV="$DX_ENV PAPER_SIZE='$DOXYGEN_PAPER_SIZE'" + +;; #( +*) + as_fn_error $? "unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'" "$LINENO" 5 +;; +esac + +#For debugging: +#echo DX_FLAG_doc=$DX_FLAG_doc +#echo DX_FLAG_dot=$DX_FLAG_dot +#echo DX_FLAG_man=$DX_FLAG_man +#echo DX_FLAG_html=$DX_FLAG_html +#echo DX_FLAG_chm=$DX_FLAG_chm +#echo DX_FLAG_chi=$DX_FLAG_chi +#echo DX_FLAG_rtf=$DX_FLAG_rtf +#echo DX_FLAG_xml=$DX_FLAG_xml +#echo DX_FLAG_pdf=$DX_FLAG_pdf +#echo DX_FLAG_ps=$DX_FLAG_ps +#echo DX_ENV=$DX_ENV + + +# initialize automake +am__api_version='1.15' + +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if ${ac_cv_path_install+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in @%:@(( + ./ | .// | /[cC]/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + + done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +$as_echo_n "checking whether build environment is sane... " >&6; } +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[\\\"\#\$\&\'\`$am_lf]*) + as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; +esac +case $srcdir in + *[\\\"\#\$\&\'\`$am_lf\ \ ]*) + as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; +esac + +# Do 'set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + as_fn_error $? "ls -t appears to fail. Make sure there is not a broken + alias in your environment" "$LINENO" 5 + fi + if test "$2" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done + test "$2" = conftest.file + ) +then + # Ok. + : +else + as_fn_error $? "newly created file is older than distributed files! +Check your system clock" "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi + +rm -f conftest.file + +test "$program_prefix" != NONE && + program_transform_name="s&^&$program_prefix&;$program_transform_name" +# Use a double $ so make ignores it. +test "$program_suffix" != NONE && + program_transform_name="s&\$&$program_suffix&;$program_transform_name" +# Double any \ or $. +# By default was `s,x,x', remove it if useless. +ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' +program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` + +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` + +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --is-lightweight"; then + am_missing_run="$MISSING " +else + am_missing_run= + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} +fi + +if test x"${install_sh+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi + +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the 'STRIP' environment variable to overrule this program. +if test "$cross_compiling" != no; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } +if test -z "$MKDIR_P"; then + if ${ac_cv_path_mkdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done + done +IFS=$as_save_IFS + +fi + + test -d ./--version && rmdir ./--version + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + MKDIR_P="$ac_install_sh -d" + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } + +for ac_prog in gawk mawk nawk awk +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AWK+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AWK"; then + ac_cv_prog_AWK="$AWK" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AWK="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AWK=$ac_cv_prog_AWK +if test -n "$AWK"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +$as_echo "$AWK" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AWK" && break +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +set x ${MAKE-make} +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering ...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null + +@%:@ Check whether --enable-silent-rules was given. +if test "${enable_silent_rules+set}" = set; then : + enableval=$enable_silent_rules; +fi + +case $enable_silent_rules in @%:@ ((( + yes) AM_DEFAULT_VERBOSITY=0;; + no) AM_DEFAULT_VERBOSITY=1;; + *) AM_DEFAULT_VERBOSITY=1;; +esac +am_make=${MAKE-make} +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +$as_echo_n "checking whether $am_make supports nested variables... " >&6; } +if ${am_cv_make_support_nested_variables+:} false; then : + $as_echo_n "(cached) " >&6 +else + if $as_echo 'TRUE=$(BAR$(V)) +BAR0=false +BAR1=true +V=1 +am__doit: + @$(TRUE) +.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then + am_cv_make_support_nested_variables=yes +else + am_cv_make_support_nested_variables=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +$as_echo "$am_cv_make_support_nested_variables" >&6; } +if test $am_cv_make_support_nested_variables = yes; then + AM_V='$(V)' + AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' +else + AM_V=$AM_DEFAULT_VERBOSITY + AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY +fi +AM_BACKSLASH='\' + +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + am__isrc=' -I$(srcdir)' + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi + + +# Define the identity of the package. + PACKAGE='zookeeper' + VERSION='3.6.0' + + +cat >>confdefs.h <<_ACEOF +@%:@define PACKAGE "$PACKAGE" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +@%:@define VERSION "$VERSION" +_ACEOF + +# Some tools Automake needs. + +ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} + + +AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} + + +AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} + + +AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} + + +MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} + +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +mkdir_p='$(MKDIR_P)' + +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. +# Always define AMTAR for backward compatibility. Yes, it's still used +# in the wild :-( We should find a proper way to deprecate it ... +AMTAR='$${TAR-tar}' + + +# We'll loop over all known methods to create a tar archive until one works. +_am_tools='gnutar pax cpio none' + +am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' + + + + + + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 + fi +fi + +ac_config_headers="$ac_config_headers config.h" + + +# Checks for programs. + +@%:@ Check whether --with-cppunit was given. +if test "${with_cppunit+set}" = set; then : + withval=$with_cppunit; +fi + + +if test "$with_cppunit" = "no" ; then + CPPUNIT_PATH="No_CPPUNIT" + CPPUNIT_INCLUDE= + CPPUNIT_LIBS= +else + AM_PATH_CPPUNIT(1.10.2) +fi + +if test "$CALLER" = "ANT" ; then +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"${base_dir}/src/c/tests/zkServer.sh\\\"\"" +else +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"./tests/zkServer.sh\\\"\"" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for generated/zookeeper.jute.c" >&5 +$as_echo_n "checking for generated/zookeeper.jute.c... " >&6; } +if ${ac_cv_file_generated_zookeeper_jute_c+:} false; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "generated/zookeeper.jute.c"; then + ac_cv_file_generated_zookeeper_jute_c=yes +else + ac_cv_file_generated_zookeeper_jute_c=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file_generated_zookeeper_jute_c" >&5 +$as_echo "$ac_cv_file_generated_zookeeper_jute_c" >&6; } +if test "x$ac_cv_file_generated_zookeeper_jute_c" = xyes; then : + +cat >>confdefs.h <<_ACEOF +@%:@define HAVE_GENERATED_ZOOKEEPER_JUTE_C 1 +_ACEOF + +else + as_fn_error $? "jute files are missing! Please run \"ant compile_jute\" while in the zookeeper top level directory." "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for generated/zookeeper.jute.h" >&5 +$as_echo_n "checking for generated/zookeeper.jute.h... " >&6; } +if ${ac_cv_file_generated_zookeeper_jute_h+:} false; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "generated/zookeeper.jute.h"; then + ac_cv_file_generated_zookeeper_jute_h=yes +else + ac_cv_file_generated_zookeeper_jute_h=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file_generated_zookeeper_jute_h" >&5 +$as_echo "$ac_cv_file_generated_zookeeper_jute_h" >&6; } +if test "x$ac_cv_file_generated_zookeeper_jute_h" = xyes; then : + +cat >>confdefs.h <<_ACEOF +@%:@define HAVE_GENERATED_ZOOKEEPER_JUTE_H 1 +_ACEOF + +else + as_fn_error $? "jute files are missing! Please run \"ant compile_jute\" while in the zookeeper top level directory." "$LINENO" 5 + +fi + +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $@%:@ != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "C compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if ${ac_cv_objext+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of object files: cannot compile +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +$as_echo_n "checking whether $CC understands -c and -o together... " >&6; } +if ${am_cv_prog_cc_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 + ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +$as_echo "$am_cv_prog_cc_c_o" >&6; } +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +DEPDIR="${am__leading_dot}deps" + +ac_config_commands="$ac_config_commands depfiles" + + +am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 +$as_echo_n "checking for style of include used by $am_make... " >&6; } +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from 'make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 +$as_echo "$_am_result" >&6; } +rm -f confinc confmf + +@%:@ Check whether --enable-dependency-tracking was given. +if test "${enable_dependency_tracking+set}" = set; then : + enableval=$enable_dependency_tracking; +fi + +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' + am__nodep='_no' +fi + if test "x$enable_dependency_tracking" != xno; then + AMDEP_TRUE= + AMDEP_FALSE='#' +else + AMDEP_TRUE='#' + AMDEP_FALSE= +fi + + + +depcc="$CC" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CC_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CC_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CC_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CC_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } +CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then + am__fastdepCC_TRUE= + am__fastdepCC_FALSE='#' +else + am__fastdepCC_TRUE='#' + am__fastdepCC_FALSE= +fi + + + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CXX"; then + ac_cv_prog_CXX="$CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 +$as_echo "$CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 +$as_echo "$ac_ct_CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 +$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } +if ${ac_cv_cxx_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 +$as_echo "$ac_cv_cxx_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GXX=yes +else + GXX= +fi +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 +$as_echo_n "checking whether $CXX accepts -g... " >&6; } +if ${ac_cv_prog_cxx_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +else + CXXFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + +else + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 +$as_echo "$ac_cv_prog_cxx_g" >&6; } +if test "$ac_test_CXXFLAGS" = set; then + CXXFLAGS=$ac_save_CXXFLAGS +elif test $ac_cv_prog_cxx_g = yes; then + if test "$GXX" = yes; then + CXXFLAGS="-g -O2" + else + CXXFLAGS="-g" + fi +else + if test "$GXX" = yes; then + CXXFLAGS="-O2" + else + CXXFLAGS= + fi +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +depcc="$CXX" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CXX_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CXX_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CXX_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CXX_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CXX_dependencies_compiler_type" >&6; } +CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then + am__fastdepCXX_TRUE= + am__fastdepCXX_FALSE='#' +else + am__fastdepCXX_TRUE='#' + am__fastdepCXX_FALSE= +fi + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +$as_echo_n "checking whether ln -s works... " >&6; } +LN_S=$as_ln_s +if test "$LN_S" = "ln -s"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +$as_echo "no, using $LN_S" >&6; } +fi + + +# AC_DISABLE_SHARED +case `pwd` in + *\ * | *\ *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; +esac + + + +macro_version='2.4.6' +macro_revision='2.4.6' + + + + + + + + + + + + + +ltmain=$ac_aux_dir/ltmain.sh + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if ${ac_cv_build+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if ${ac_cv_host+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + +# Backslashify metacharacters that are still active within +# double-quoted strings. +sed_quote_subst='s/\(["`$\\]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +$as_echo_n "checking how to print strings... " >&6; } +# Test print first, because it will be a builtin if present. +if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ + test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='print -r --' +elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='printf %s\n' +else + # Use this function as a fallback that always works. + func_fallback_echo () + { + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' + } + ECHO='func_fallback_echo' +fi + +# func_echo_all arg... +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "" +} + +case $ECHO in + printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +$as_echo "printf" >&6; } ;; + print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +$as_echo "print -r" >&6; } ;; + *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +$as_echo "cat" >&6; } ;; +esac + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +$as_echo_n "checking for a sed that does not truncate output... " >&6; } +if ${ac_cv_path_SED+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for ac_i in 1 2 3 4 5 6 7; do + ac_script="$ac_script$as_nl$ac_script" + done + echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed + { ac_script=; unset ac_script;} + if test -z "$SED"; then + ac_path_SED_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_SED" || continue +# Check for GNU ac_path_SED and select it if it is found. + # Check for GNU $ac_path_SED +case `"$ac_path_SED" --version 2>&1` in +*GNU*) + ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo '' >> "conftest.nl" + "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_SED_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_SED="$ac_path_SED" + ac_path_SED_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_SED_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_SED"; then + as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 + fi +else + ac_cv_path_SED=$SED +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +$as_echo "$ac_cv_path_SED" >&6; } + SED="$ac_cv_path_SED" + rm -f conftest.sed + +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_GREP" || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if ${ac_cv_path_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_EGREP" || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +$as_echo_n "checking for fgrep... " >&6; } +if ${ac_cv_path_FGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 + then ac_cv_path_FGREP="$GREP -F" + else + if test -z "$FGREP"; then + ac_path_FGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in fgrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_FGREP" || continue +# Check for GNU ac_path_FGREP and select it if it is found. + # Check for GNU $ac_path_FGREP +case `"$ac_path_FGREP" --version 2>&1` in +*GNU*) + ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'FGREP' >> "conftest.nl" + "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_FGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_FGREP="$ac_path_FGREP" + ac_path_FGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_FGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_FGREP"; then + as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_FGREP=$FGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +$as_echo "$ac_cv_path_FGREP" >&6; } + FGREP="$ac_cv_path_FGREP" + + +test -z "$GREP" && GREP=grep + + + + + + + + + + + + + + + + + + + +@%:@ Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if ${lt_cv_path_NM+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM=$NM +else + lt_nm_to_check=${ac_tool_prefix}nm + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + tmp_nm=$ac_dir/$lt_tmp_nm + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the 'sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty + case $build_os in + mingw*) lt_bad_file=conftest.nm/nofile ;; + *) lt_bad_file=/dev/null ;; + esac + case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +$as_echo "$lt_cv_path_NM" >&6; } +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + if test -n "$ac_tool_prefix"; then + for ac_prog in dumpbin "link -dump" + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DUMPBIN"; then + ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DUMPBIN=$ac_cv_prog_DUMPBIN +if test -n "$DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +$as_echo "$DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$DUMPBIN" && break + done +fi +if test -z "$DUMPBIN"; then + ac_ct_DUMPBIN=$DUMPBIN + for ac_prog in dumpbin "link -dump" +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DUMPBIN"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN +if test -n "$ac_ct_DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +$as_echo "$ac_ct_DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_DUMPBIN" && break +done + + if test "x$ac_ct_DUMPBIN" = x; then + DUMPBIN=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DUMPBIN=$ac_ct_DUMPBIN + fi +fi + + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +$as_echo_n "checking the name lister ($NM) interface... " >&6; } +if ${lt_cv_nm_interface+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: output\"" >&5) + cat conftest.out >&5 + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +$as_echo "$lt_cv_nm_interface" >&6; } + +# find the maximum length of command line arguments +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +$as_echo_n "checking the maximum length of command line arguments... " >&6; } +if ${lt_cv_sys_max_cmd_len+:} false; then : + $as_echo_n "(cached) " >&6 +else + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac + +fi + +if test -n "$lt_cv_sys_max_cmd_len"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +$as_echo "$lt_cv_sys_max_cmd_len" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 +$as_echo "none" >&6; } +fi +max_cmd_len=$lt_cv_sys_max_cmd_len + + + + + + +: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi + + + + + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +$as_echo_n "checking how to convert $build file names to $host format... " >&6; } +if ${lt_cv_to_host_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 + ;; + esac + ;; + *-*-cygwin* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin + ;; + esac + ;; + * ) # unhandled hosts (and "normal" native builds) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; +esac + +fi + +to_host_file_cmd=$lt_cv_to_host_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +$as_echo "$lt_cv_to_host_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; } +if ${lt_cv_to_tool_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + #assume ordinary cross tools, or native build. +lt_cv_to_tool_file_cmd=func_convert_file_noop +case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 + ;; + esac + ;; +esac + +fi + +to_tool_file_cmd=$lt_cv_to_tool_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +$as_echo "$lt_cv_to_tool_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +$as_echo_n "checking for $LD option to reload object files... " >&6; } +if ${lt_cv_ld_reload_flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_reload_flag='-r' +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +$as_echo "$lt_cv_ld_reload_flag" >&6; } +reload_flag=$lt_cv_ld_reload_flag +case $reload_flag in +"" | " "*) ;; +*) reload_flag=" $reload_flag" ;; +esac +reload_cmds='$LD$reload_flag -o $output$reload_objs' +case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + if test yes != "$GCC"; then + reload_cmds=false + fi + ;; + darwin*) + if test yes = "$GCC"; then + reload_cmds='$LTCC $LTCFLAGS -nostdlib $wl-r -o $output$reload_objs' + else + reload_cmds='$LD$reload_flag -o $output$reload_objs' + fi + ;; +esac + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. +set dummy ${ac_tool_prefix}objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OBJDUMP"; then + ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OBJDUMP=$ac_cv_prog_OBJDUMP +if test -n "$OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OBJDUMP"; then + ac_ct_OBJDUMP=$OBJDUMP + # Extract the first word of "objdump", so it can be a program name with args. +set dummy objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OBJDUMP"; then + ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OBJDUMP="objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP +if test -n "$ac_ct_OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OBJDUMP" = x; then + OBJDUMP="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OBJDUMP=$ac_ct_OBJDUMP + fi +else + OBJDUMP="$ac_cv_prog_OBJDUMP" +fi + +test -z "$OBJDUMP" && OBJDUMP=objdump + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +$as_echo_n "checking how to recognize dependent libraries... " >&6; } +if ${lt_cv_deplibs_check_method+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# 'unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# that responds to the $file_magic_cmd with a given extended regex. +# If you have 'file' or equivalent on your system and you're not sure +# whether 'pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[4-9]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[45]*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc*) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +haiku*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]' + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9]\.[0-9]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[3-9]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd* | bitrig*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +os2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +$as_echo "$lt_cv_deplibs_check_method" >&6; } + +file_magic_glob= +want_nocaseglob=no +if test "$build" = "$host"; then + case $host_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes + else + file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[\1]\/[\1]\/g;/g"` + fi + ;; + esac +fi + +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + + + + + + + + + + + + + + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. +set dummy ${ac_tool_prefix}dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DLLTOOL"; then + ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DLLTOOL=$ac_cv_prog_DLLTOOL +if test -n "$DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +$as_echo "$DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DLLTOOL"; then + ac_ct_DLLTOOL=$DLLTOOL + # Extract the first word of "dlltool", so it can be a program name with args. +set dummy dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DLLTOOL"; then + ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DLLTOOL="dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL +if test -n "$ac_ct_DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +$as_echo "$ac_ct_DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DLLTOOL" = x; then + DLLTOOL="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DLLTOOL=$ac_ct_DLLTOOL + fi +else + DLLTOOL="$ac_cv_prog_DLLTOOL" +fi + +test -z "$DLLTOOL" && DLLTOOL=dlltool + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +$as_echo_n "checking how to associate runtime and link libraries... " >&6; } +if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_sharedlib_from_linklib_cmd='unknown' + +case $host_os in +cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL + case `$DLLTOOL --help 2>&1` in + *--identify-strict*) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib + ;; + *) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback + ;; + esac + ;; +*) + # fallback: assume linklib IS sharedlib + lt_cv_sharedlib_from_linklib_cmd=$ECHO + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; } +sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd +test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO + + + + + + + + +if test -n "$ac_tool_prefix"; then + for ac_prog in ar + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AR="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AR" && break + done +fi +if test -z "$AR"; then + ac_ct_AR=$AR + for ac_prog in ar +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_AR="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_AR" && break +done + + if test "x$ac_ct_AR" = x; then + AR="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +fi + +: ${AR=ar} +: ${AR_FLAGS=cru} + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +$as_echo_n "checking for archiver @FILE support... " >&6; } +if ${lt_cv_ar_at_file+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ar_at_file=no + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + echo conftest.$ac_objext > conftest.lst + lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -eq "$ac_status"; then + # Ensure the archiver fails upon bogus file names. + rm -f conftest.$ac_objext libconftest.a + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -ne "$ac_status"; then + lt_cv_ar_at_file=@ + fi + fi + rm -f conftest.* libconftest.a + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +$as_echo "$lt_cv_ar_at_file" >&6; } + +if test no = "$lt_cv_ar_at_file"; then + archiver_list_spec= +else + archiver_list_spec=$lt_cv_ar_at_file +fi + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +test -z "$STRIP" && STRIP=: + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +test -z "$RANLIB" && RANLIB=: + + + + + + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" +fi + +case $host_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) + lock_old_archive_extraction=no ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# Check for command to grab the raw symbol name followed by C symbol from nm. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } +if ${lt_cv_sys_global_symbol_pipe+:} false; then : + $as_echo_n "(cached) " >&6 +else + +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[BCDEGRST]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([_A-Za-z][_A-Za-z0-9]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[BCDT]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[ABCDGISTW]' + ;; +hpux*) + if test ia64 = "$host_cpu"; then + symcode='[ABCDEGRST]' + fi + ;; +irix* | nonstopux*) + symcode='[BCDEGRST]' + ;; +osf*) + symcode='[BCDEGQRST]' + ;; +solaris*) + symcode='[BDRT]' + ;; +sco3.2v5*) + symcode='[DT]' + ;; +sysv4.2uw2*) + symcode='[DT]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[ABDT]' + ;; +sysv4) + symcode='[DFNSTU]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[ABCDGIRSTW]' ;; +esac + +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Gets list of data symbols to import. + lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + # Adjust the below global symbol transforms to fixup imported variables. + lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" + lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" + lt_c_name_lib_hook="\ + -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ + -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" +else + # Disable hooks by default. + lt_cv_sys_global_symbol_to_import= + lt_cdecl_hook= + lt_c_name_hook= + lt_c_name_lib_hook= +fi + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +$lt_cdecl_hook\ +" -e 's/^T .* \(.*\)$/extern int \1();/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +$lt_c_name_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" + +# Transform an extracted symbol line into symbol name with lib prefix and +# symbol address. +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +$lt_c_name_lib_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function, + # D for any global variable and I for any imported variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK '"\ +" {last_section=section; section=\$ 3};"\ +" /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ +" /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ +" /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ +" {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ +" s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Now try to grab the symbols. + nlist=conftest.nm + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 + (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT@&t@_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT@&t@_DLSYM_CONST +#else +# define LT@&t@_DLSYM_CONST const +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +LT@&t@_DLSYM_CONST struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_globsym_save_LIBS=$LIBS + lt_globsym_save_CFLAGS=$CFLAGS + LIBS=conftstm.$ac_objext + CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s conftest$ac_exeext; then + pipe_works=yes + fi + LIBS=$lt_globsym_save_LIBS + CFLAGS=$lt_globsym_save_CFLAGS + else + echo "cannot find nm_test_func in $nlist" >&5 + fi + else + echo "cannot find nm_test_var in $nlist" >&5 + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 + fi + else + echo "$progname: failed program was:" >&5 + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test yes = "$pipe_works"; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done + +fi + +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +$as_echo "failed" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } +fi + +# Response file support. +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + nm_file_list_spec='@' +elif $NM --help 2>/dev/null | grep '[@]FILE' >/dev/null; then + nm_file_list_spec='@' +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +$as_echo_n "checking for sysroot... " >&6; } + +@%:@ Check whether --with-sysroot was given. +if test "${with_sysroot+set}" = set; then : + withval=$with_sysroot; +else + with_sysroot=no +fi + + +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +$as_echo "$with_sysroot" >&6; } + as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5 + ;; +esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +$as_echo "${lt_sysroot:-no}" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +$as_echo_n "checking for a working dd... " >&6; } +if ${ac_cv_path_lt_DD+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +: ${lt_DD:=$DD} +if test -z "$lt_DD"; then + ac_path_lt_DD_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in dd; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_lt_DD="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_lt_DD" || continue +if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: +fi + $ac_path_lt_DD_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_lt_DD"; then + : + fi +else + ac_cv_path_lt_DD=$lt_DD +fi + +rm -f conftest.i conftest2.i conftest.out +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +$as_echo "$ac_cv_path_lt_DD" >&6; } + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +$as_echo_n "checking how to truncate binary pipes... " >&6; } +if ${lt_cv_truncate_bin+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +lt_cv_truncate_bin= +if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" +fi +rm -f conftest.i conftest2.i conftest.out +test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +$as_echo "$lt_cv_truncate_bin" >&6; } + + + + + + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in @S|@*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + +@%:@ Check whether --enable-libtool-lock was given. +if test "${enable_libtool_lock+set}" = set; then : + enableval=$enable_libtool_lock; +fi + +test no = "$enable_libtool_lock" || enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE=32 + ;; + *ELF-64*) + HPUX_IA64_MODE=64 + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + if test yes = "$lt_cv_prog_gnu_ld"; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +mips64*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + emul=elf + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + emul="${emul}32" + ;; + *64-bit*) + emul="${emul}64" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *MSB*) + emul="${emul}btsmip" + ;; + *LSB*) + emul="${emul}ltsmip" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *N32*) + emul="${emul}n32" + ;; + esac + LD="${LD-ld} -m $emul" + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. Note that the listed cases only cover the + # situations where additional linker options are needed (such as when + # doing 32-bit compilation for a host where ld defaults to 64-bit, or + # vice versa); the common cases where no linker options are needed do + # not appear in the list. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac + ;; + powerpc64le-*linux*) + LD="${LD-ld} -m elf32lppclinux" + ;; + powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + powerpcle-*linux*) + LD="${LD-ld} -m elf64lppc" + ;; + powerpc-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -belf" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +$as_echo_n "checking whether the C compiler needs -belf... " >&6; } +if ${lt_cv_cc_needs_belf+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_cc_needs_belf=yes +else + lt_cv_cc_needs_belf=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +$as_echo "$lt_cv_cc_needs_belf" >&6; } + if test yes != "$lt_cv_cc_needs_belf"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS=$SAVE_CFLAGS + fi + ;; +*-*solaris*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) + case $host in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; + sparc*-*-solaris*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + # GNU ld 2.21 introduced _sol2 emulations. Use them if available. + if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then + LD=${LD-ld}_sol2 + fi + ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks=$enable_libtool_lock + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args. +set dummy ${ac_tool_prefix}mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$MANIFEST_TOOL"; then + ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL +if test -n "$MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +$as_echo "$MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_MANIFEST_TOOL"; then + ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL + # Extract the first word of "mt", so it can be a program name with args. +set dummy mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_MANIFEST_TOOL"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL +if test -n "$ac_ct_MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +$as_echo "$ac_ct_MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_MANIFEST_TOOL" = x; then + MANIFEST_TOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL + fi +else + MANIFEST_TOOL="$ac_cv_prog_MANIFEST_TOOL" +fi + +test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if ${lt_cv_path_mainfest_tool+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_path_mainfest_tool=no + echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 + $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out + cat conftest.err >&5 + if $GREP 'Manifest Tool' conftest.out > /dev/null; then + lt_cv_path_mainfest_tool=yes + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 +$as_echo "$lt_cv_path_mainfest_tool" >&6; } +if test yes != "$lt_cv_path_mainfest_tool"; then + MANIFEST_TOOL=: +fi + + + + + + + case $host_os in + rhapsody* | darwin*) + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. +set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DSYMUTIL"; then + ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DSYMUTIL=$ac_cv_prog_DSYMUTIL +if test -n "$DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +$as_echo "$DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DSYMUTIL"; then + ac_ct_DSYMUTIL=$DSYMUTIL + # Extract the first word of "dsymutil", so it can be a program name with args. +set dummy dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DSYMUTIL"; then + ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL +if test -n "$ac_ct_DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +$as_echo "$ac_ct_DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DSYMUTIL" = x; then + DSYMUTIL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DSYMUTIL=$ac_ct_DSYMUTIL + fi +else + DSYMUTIL="$ac_cv_prog_DSYMUTIL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. +set dummy ${ac_tool_prefix}nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NMEDIT"; then + ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +NMEDIT=$ac_cv_prog_NMEDIT +if test -n "$NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +$as_echo "$NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_NMEDIT"; then + ac_ct_NMEDIT=$NMEDIT + # Extract the first word of "nmedit", so it can be a program name with args. +set dummy nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_NMEDIT"; then + ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_NMEDIT="nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT +if test -n "$ac_ct_NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +$as_echo "$ac_ct_NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_NMEDIT" = x; then + NMEDIT=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + NMEDIT=$ac_ct_NMEDIT + fi +else + NMEDIT="$ac_cv_prog_NMEDIT" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. +set dummy ${ac_tool_prefix}lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$LIPO"; then + ac_cv_prog_LIPO="$LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_LIPO="${ac_tool_prefix}lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +LIPO=$ac_cv_prog_LIPO +if test -n "$LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +$as_echo "$LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_LIPO"; then + ac_ct_LIPO=$LIPO + # Extract the first word of "lipo", so it can be a program name with args. +set dummy lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_LIPO"; then + ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_LIPO="lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO +if test -n "$ac_ct_LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +$as_echo "$ac_ct_LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_LIPO" = x; then + LIPO=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + LIPO=$ac_ct_LIPO + fi +else + LIPO="$ac_cv_prog_LIPO" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL"; then + ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL="${ac_tool_prefix}otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL=$ac_cv_prog_OTOOL +if test -n "$OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +$as_echo "$OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL"; then + ac_ct_OTOOL=$OTOOL + # Extract the first word of "otool", so it can be a program name with args. +set dummy otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL"; then + ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL="otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL +if test -n "$ac_ct_OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +$as_echo "$ac_ct_OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL" = x; then + OTOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL=$ac_ct_OTOOL + fi +else + OTOOL="$ac_cv_prog_OTOOL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL64"; then + ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL64=$ac_cv_prog_OTOOL64 +if test -n "$OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +$as_echo "$OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL64"; then + ac_ct_OTOOL64=$OTOOL64 + # Extract the first word of "otool64", so it can be a program name with args. +set dummy otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL64"; then + ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL64="otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 +if test -n "$ac_ct_OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +$as_echo "$ac_ct_OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL64" = x; then + OTOOL64=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL64=$ac_ct_OTOOL64 + fi +else + OTOOL64="$ac_cv_prog_OTOOL64" +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +$as_echo_n "checking for -single_module linker flag... " >&6; } +if ${lt_cv_apple_cc_single_mod+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_apple_cc_single_mod=no + if test -z "$LT_MULTI_MODULE"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + # If there is a non-empty error log, and "single_module" + # appears in it, assume the flag caused a linker warning + if test -s conftest.err && $GREP single_module conftest.err; then + cat conftest.err >&5 + # Otherwise, if the output was created with a 0 exit code from + # the compiler, it worked. + elif test -f libconftest.dylib && test 0 = "$_lt_result"; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&5 + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +$as_echo "$lt_cv_apple_cc_single_mod" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } +if ${lt_cv_ld_exported_symbols_list+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_ld_exported_symbols_list=yes +else + lt_cv_ld_exported_symbols_list=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +$as_echo "$lt_cv_ld_exported_symbols_list" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +$as_echo_n "checking for -force_load linker flag... " >&6; } +if ${lt_cv_ld_force_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 + echo "$AR cru libconftest.a conftest.o" >&5 + $AR cru libconftest.a conftest.o 2>&5 + echo "$RANLIB libconftest.a" >&5 + $RANLIB libconftest.a 2>&5 + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -s conftest.err && $GREP force_load conftest.err; then + cat conftest.err >&5 + elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&5 + fi + rm -f conftest.err libconftest.a conftest conftest.c + rm -rf conftest.dSYM + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +$as_echo "$lt_cv_ld_force_load" >&6; } + case $host_os in + rhapsody* | darwin1.[012]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[91]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test yes = "$lt_cv_apple_cc_single_mod"; then + _lt_dar_single_mod='$single_module' + fi + if test yes = "$lt_cv_ld_exported_symbols_list"; then + _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' + fi + if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x@S|@2 in + x) + ;; + *:) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" + ;; + x:*) + eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" + ;; + *) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + esac +} + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "@%:@define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +@%:@define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +for ac_header in dlfcn.h +do : + ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default +" +if test "x$ac_cv_header_dlfcn_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +@%:@define HAVE_DLFCN_H 1 +_ACEOF + +fi + +done + + + + +func_stripname_cnf () +{ + case @S|@2 in + .*) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%\\\\@S|@2\$%%"`;; + *) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%@S|@2\$%%"`;; + esac +} # func_stripname_cnf + + + + + +# Set options + + + + enable_dlopen=no + + + enable_win32_dll=no + + + @%:@ Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then : + enableval=$enable_shared; p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_shared=yes +fi + + + + + + + + + + @%:@ Check whether --enable-static was given. +if test "${enable_static+set}" = set; then : + enableval=$enable_static; p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_static=yes +fi + + + + + + + + + + +@%:@ Check whether --with-pic was given. +if test "${with_pic+set}" = set; then : + withval=$with_pic; lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + pic_mode=default +fi + + + + + + + + + @%:@ Check whether --enable-fast-install was given. +if test "${enable_fast_install+set}" = set; then : + enableval=$enable_fast_install; p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_fast_install=yes +fi + + + + + + + + + shared_archive_member_spec= +case $host,$enable_shared in +power*-*-aix[5-9]*,yes) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +$as_echo_n "checking which variant of shared library versioning to provide... " >&6; } + +@%:@ Check whether --with-aix-soname was given. +if test "${with_aix_soname+set}" = set; then : + withval=$with_aix_soname; case $withval in + aix|svr4|both) + ;; + *) + as_fn_error $? "Unknown argument to --with-aix-soname" "$LINENO" 5 + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname +else + if ${lt_cv_with_aix_soname+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_with_aix_soname=aix +fi + + with_aix_soname=$lt_cv_with_aix_soname +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +$as_echo "$with_aix_soname" >&6; } + if test aix != "$with_aix_soname"; then + # For the AIX way of multilib, we name the shared archive member + # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', + # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. + # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, + # the AIX toolchain works better with OBJECT_MODE set (default 32). + if test 64 = "${OBJECT_MODE-32}"; then + shared_archive_member_spec=shr_64 + else + shared_archive_member_spec=shr + fi + fi + ;; +*) + with_aix_soname=aix + ;; +esac + + + + + + + + + + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +test -z "$LN_S" && LN_S="ln -s" + + + + + + + + + + + + + + +if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +$as_echo_n "checking for objdir... " >&6; } +if ${lt_cv_objdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +$as_echo "$lt_cv_objdir" >&6; } +objdir=$lt_cv_objdir + + + + + +cat >>confdefs.h <<_ACEOF +@%:@define LT_OBJDIR "$lt_cv_objdir/" +_ACEOF + + + + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld=$lt_cv_prog_gnu_ld + +old_CC=$CC +old_CFLAGS=$CFLAGS + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +func_cc_basename $compiler +cc_basename=$func_cc_basename_result + + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/${ac_tool_prefix}file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"${ac_tool_prefix}file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + + + +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +$as_echo_n "checking for file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + else + MAGIC_CMD=: + fi +fi + + fi + ;; +esac + +# Use C for the default configuration in the libtool script + +lt_save_CC=$CC +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +objext=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + +if test -n "$compiler"; then + +lt_prog_compiler_no_builtin_flag= + +if test yes = "$GCC"; then + case $cc_basename in + nvcc*) + lt_prog_compiler_no_builtin_flag=' -Xcompiler -fno-builtin' ;; + *) + lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_rtti_exceptions=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="-fno-rtti -fno-exceptions" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_rtti_exceptions=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } + +if test yes = "$lt_cv_prog_compiler_rtti_exceptions"; then + lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" +else + : +fi + +fi + + + + + + + lt_prog_compiler_wl= +lt_prog_compiler_pic= +lt_prog_compiler_static= + + + if test yes = "$GCC"; then + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_static='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + fi + lt_prog_compiler_pic='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + ;; + + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + lt_prog_compiler_static= + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + ;; + + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic=-Kconform_pic + fi + ;; + + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + + case $cc_basename in + nvcc*) # Cuda Compiler Driver 2.2 + lt_prog_compiler_wl='-Xlinker ' + if test -n "$lt_prog_compiler_pic"; then + lt_prog_compiler_pic="-Xcompiler $lt_prog_compiler_pic" + fi + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl='-Wl,' + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + else + lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + case $cc_basename in + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static='$wl-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + # old Intel for x86_64, which still supported -KPIC. + ecc*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='--shared' + lt_prog_compiler_static='--static' + ;; + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + xl* | bgxl* | bgf* | mpixl*) + # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-qpic' + lt_prog_compiler_static='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='' + ;; + *Sun\ F* | *Sun*Fortran*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Qoption ld ' + ;; + *Sun\ C*) + # Sun C 5.9 + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Wl,' + ;; + *Intel*\ [CF]*Compiler*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + *Portland\ Group*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + esac + ;; + + newsos6) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + + rdos*) + lt_prog_compiler_static='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + lt_prog_compiler_wl='-Qoption ld ';; + *) + lt_prog_compiler_wl='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl='-Qoption ld ' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic='-Kconform_pic' + lt_prog_compiler_static='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_can_build_shared=no + ;; + + uts4*) + lt_prog_compiler_pic='-pic' + lt_prog_compiler_static='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared=no + ;; + esac + fi + +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic= + ;; + *) + lt_prog_compiler_pic="$lt_prog_compiler_pic@&t@ -DPIC" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic=$lt_prog_compiler_pic +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +$as_echo "$lt_cv_prog_compiler_pic" >&6; } +lt_prog_compiler_pic=$lt_cv_prog_compiler_pic + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if ${lt_cv_prog_compiler_pic_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic@&t@ -DPIC" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_pic_works"; then + case $lt_prog_compiler_pic in + "" | " "*) ;; + *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; + esac +else + lt_prog_compiler_pic= + lt_prog_compiler_can_build_shared=no +fi + +fi + + + + + + + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works=yes + fi + else + lt_cv_prog_compiler_static_works=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +$as_echo "$lt_cv_prog_compiler_static_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_static_works"; then + : +else + lt_prog_compiler_static= +fi + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + +hard_links=nottested +if test no = "$lt_cv_prog_compiler_c_o" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test no = "$hard_links"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + runpath_var= + allow_undefined_flag= + always_export_symbols=no + archive_cmds= + archive_expsym_cmds= + compiler_needs_object=no + enable_shared_with_static_runtimes=no + export_dynamic_flag_spec= + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + hardcode_automatic=no + hardcode_direct=no + hardcode_direct_absolute=no + hardcode_libdir_flag_spec= + hardcode_libdir_separator= + hardcode_minus_L=no + hardcode_shlibpath_var=unsupported + inherit_rpath=no + link_all_deplibs=unknown + module_cmds= + module_expsym_cmds= + old_archive_from_new_cmds= + old_archive_from_expsyms_cmds= + thread_safe_flag_spec= + whole_archive_flag_spec= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ' (' and ')$', so one must not match beginning or + # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', + # as well as any symbol that contains 'd'. + exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test yes != "$GCC"; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd* | bitrig*) + with_gnu_ld=no + ;; + esac + + ld_shlibs=yes + + # On some targets, GNU ld is compatible enough with the native linker + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then + case $host_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld + # block says, versions before 2.19.5* couldn't really create working + # shared libraries, regardless of the interface used. + case `$LD -v 2>&1` in + *\ \(GNU\ Binutils\)\ 2.19.5*) ;; + *\ \(GNU\ Binutils\)\ 2.[2-9]*) ;; + *\ \(GNU\ Binutils\)\ [3-9]*) ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + fi + + if test yes = "$lt_use_gnu_ld_interface"; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='$wl' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + export_dynamic_flag_spec='$wl--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + whole_archive_flag_spec= + fi + supports_anon_versioning=no + case `$LD -v | $SED -e 's/(^)\+)\s\+//' 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[3-9]*) + # On AIX/PPC, the GNU linker is very broken + if test ia64 != "$host_cpu"; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.19, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to install binutils +*** 2.20 or above, or modify your PATH so that a non-GNU linker is found. +*** You will then need to restart the configuration process. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + ld_shlibs=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + export_dynamic_flag_spec='$wl--export-all-symbols' + allow_undefined_flag=unsupported + always_export_symbols=no + enable_shared_with_static_runtimes=yes + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs=no + fi + ;; + + haiku*) + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + link_all_deplibs=yes + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + interix[3-9]*) + hardcode_direct=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test linux-dietlibc = "$host_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test no = "$tmp_diet" + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group f77 and f90 compilers + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + whole_archive_flag_spec= + tmp_sharedflag='--shared' ;; + nagfor*) # NAGFOR 5.3 + tmp_sharedflag='-Wl,-shared' ;; + xl[cC]* | bgxl[cC]* | mpixl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + nvcc*) # Cuda Compiler Driver 2.2 + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + whole_archive_flag_spec='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + tcc*) + export_dynamic_flag_spec='-rdynamic' + ;; + xlf* | bgf* | bgxlf* | mpixlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + ld_shlibs=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + + if test no = "$ld_shlibs"; then + runpath_var= + hardcode_libdir_flag_spec= + export_dynamic_flag_spec= + whole_archive_flag_spec= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag=unsupported + always_export_symbols=yes + archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + + aix[4-9]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes + break + fi + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds='' + hardcode_direct=yes + hardcode_direct_absolute=yes + hardcode_libdir_separator=':' + link_all_deplibs=yes + file_list_spec='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # traditional, no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + hardcode_direct=no + hardcode_direct_absolute=no + ;; + esac + + if test yes = "$GCC"; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag="$shared_flag "'$wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + export_dynamic_flag_spec='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + hardcode_libdir_flag_spec='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag="-z nodefs" + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag=' $wl-bernotok' + allow_undefined_flag=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + whole_archive_flag_spec='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec='$convenience' + fi + archive_cmds_need_lc=yes + archive_expsym_cmds='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([, ]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + archive_expsym_cmds="$archive_expsym_cmds"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + archive_expsym_cmds="$archive_expsym_cmds"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + bsdi[45]*) + export_dynamic_flag_spec=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + case $cc_basename in + cl*) + # Native MSVC + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + always_export_symbols=yes + file_list_spec='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, )='true' + enable_shared_with_static_runtimes=yes + exclude_expsyms='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1,DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols' + # Don't use ranlib + old_postinstall_cmds='chmod 644 $oldlib' + postlink_cmds='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # Assume MSVC wrapper + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_from_new_cmds='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs' + enable_shared_with_static_runtimes=yes + ;; + esac + ;; + + darwin* | rhapsody*) + + + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes + hardcode_shlibpath_var=unsupported + if test yes = "$lt_cv_ld_force_load"; then + whole_archive_flag_spec='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + + else + whole_archive_flag_spec='' + fi + link_all_deplibs=yes + allow_undefined_flag=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + archive_expsym_cmds="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + + else + ld_shlibs=no + fi + + ;; + + dgux*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2.*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + hpux9*) + if test yes = "$GCC"; then + archive_cmds='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + export_dynamic_flag_spec='$wl-E' + ;; + + hpux10*) + if test yes,no = "$GCC,$with_gnu_ld"; then + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + archive_cmds='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + + # Older versions of the 11.00 compiler do not understand -b yet + # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +$as_echo_n "checking if $CC understands -b... " >&6; } +if ${lt_cv_prog_compiler__b+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler__b=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -b" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler__b=yes + fi + else + lt_cv_prog_compiler__b=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +$as_echo "$lt_cv_prog_compiler__b" >&6; } + +if test yes = "$lt_cv_prog_compiler__b"; then + archive_cmds='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' +else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' +fi + + ;; + esac + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct=no + hardcode_shlibpath_var=no + ;; + *) + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test yes = "$GCC"; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if ${lt_cv_irix_exported_symbol+:} false; then : + $as_echo_n "(cached) " >&6 +else + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int foo (void) { return 0; } +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_irix_exported_symbol=yes +else + lt_cv_irix_exported_symbol=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +$as_echo "$lt_cv_irix_exported_symbol" >&6; } + if test yes = "$lt_cv_irix_exported_symbol"; then + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' + fi + else + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + inherit_rpath=yes + link_all_deplibs=yes + ;; + + linux*) + case $cc_basename in + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + ld_shlibs=yes + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + newsos6) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + hardcode_shlibpath_var=no + ;; + + *nto* | *qnx*) + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + hardcode_direct=yes + hardcode_shlibpath_var=no + hardcode_direct_absolute=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + else + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + fi + else + ld_shlibs=no + fi + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + osf3*) + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + archive_cmds_need_lc='no' + hardcode_libdir_separator=: + ;; + + solaris*) + no_undefined_flag=' -z defs' + if test yes = "$GCC"; then + wlarc='$wl' + archive_cmds='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + archive_cmds='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='$wl' + archive_cmds='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_shlibpath_var=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. GCC discards it without '$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test yes = "$GCC"; then + whole_archive_flag_spec='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + else + whole_archive_flag_spec='-z allextract$convenience -z defaultextract' + fi + ;; + esac + link_all_deplibs=yes + ;; + + sunos4*) + if test sequent = "$host_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds='$CC -r -o $output$reload_objs' + hardcode_direct=no + ;; + motorola) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var=no + ;; + + sysv4.3*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + export_dynamic_flag_spec='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag='$wl-z,text' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag='$wl-z,text' + allow_undefined_flag='$wl-z,nodefs' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-R,$libdir' + hardcode_libdir_separator=':' + link_all_deplibs=yes + export_dynamic_flag_spec='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + *) + ld_shlibs=no + ;; + esac + + if test sni = "$host_vendor"; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + export_dynamic_flag_spec='$wl-Blargedynsym' + ;; + esac + fi + fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +$as_echo "$ld_shlibs" >&6; } +test no = "$ld_shlibs" && can_build_shared=no + +with_gnu_ld=$with_gnu_ld + + + + + + + + + + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $archive_cmds in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc+:} false; then : + $as_echo_n "(cached) " >&6 +else + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl + pic_flag=$lt_prog_compiler_pic + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag + allow_undefined_flag= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + lt_cv_archive_cmds_need_lc=no + else + lt_cv_archive_cmds_need_lc=yes + fi + allow_undefined_flag=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc" >&6; } + archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +if test yes = "$GCC"; then + case $host_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac + case $host_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([A-Za-z]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` + case $lt_search_path_spec in + *\;*) + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` + ;; + *) + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` + ;; + esac + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary... + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + # ...but if some path component already ends with the multilib dir we assume + # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). + case "$lt_multi_os_dir; $lt_search_path_spec " in + "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) + lt_multi_os_dir= + ;; + esac + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" + elif test -n "$lt_multi_os_dir"; then + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' +BEGIN {RS = " "; FS = "/|\n";} { + lt_foo = ""; + lt_count = 0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo = "/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[lt_foo]++; } + if (lt_freq[lt_foo] == 1) { print lt_foo; } +}'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. + case $host_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([A-Za-z]:\)|\1|g'` ;; + esac + sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + + + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[4-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a(lib.so.V)' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o), lib.a(lib.so.V)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a(lib.so.V), lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib" + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[3-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + hardcode_libdir_flag_spec='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + lt_cv_shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + +fi + + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action= +if test -n "$hardcode_libdir_flag_spec" || + test -n "$runpath_var" || + test yes = "$hardcode_automatic"; then + + # We can hardcode non-existent directories. + if test no != "$hardcode_direct" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, )" && + test no != "$hardcode_minus_L"; then + # Linking always hardcodes the temporary library directory. + hardcode_action=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +$as_echo "$hardcode_action" >&6; } + +if test relink = "$hardcode_action" || + test yes = "$inherit_rpath"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + +fi + + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" +if test "x$ac_cv_func_shl_load" = xyes; then : + lt_cv_dlopen=shl_load +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : + lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld +else + ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" +if test "x$ac_cv_func_dlopen" = xyes; then : + lt_cv_dlopen=dlopen +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +$as_echo_n "checking for dlopen in -lsvld... " >&6; } +if ${ac_cv_lib_svld_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsvld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_svld_dlopen=yes +else + ac_cv_lib_svld_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +$as_echo "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +$as_echo_n "checking for dld_link in -ldld... " >&6; } +if ${ac_cv_lib_dld_dld_link+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dld_link (); +int +main () +{ +return dld_link (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_dld_link=yes +else + ac_cv_lib_dld_dld_link=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +$as_echo "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = xyes; then : + lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld +fi + + +fi + + +fi + + +fi + + +fi + + +fi + + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +$as_echo_n "checking whether a program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +$as_echo "$lt_cv_dlopen_self" >&6; } + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self_static+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self_static=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self_static=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +$as_echo "$lt_cv_dlopen_self_static" >&6; } + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi + + + + + + + + + + + + + + + + + +striplib= +old_striplib= +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +$as_echo_n "checking whether stripping libraries is possible... " >&6; } +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ;; + esac +fi + + + + + + + + + + + + + # Report what library types will actually be built + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +$as_echo_n "checking if libtool supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +$as_echo "$can_build_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +$as_echo_n "checking whether to build shared libraries... " >&6; } + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[4-9]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +$as_echo "$enable_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +$as_echo_n "checking whether to build static libraries... " >&6; } + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +$as_echo "$enable_static" >&6; } + + + + +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC=$lt_save_CC + + if test -n "$CXX" && ( test no != "$CXX" && + ( (test g++ = "$CXX" && `g++ -v >/dev/null 2>&1` ) || + (test g++ != "$CXX"))); then + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5 +$as_echo_n "checking how to run the C++ preprocessor... " >&6; } +if test -z "$CXXCPP"; then + if ${ac_cv_prog_CXXCPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CXXCPP needs to be expanded + for CXXCPP in "$CXX -E" "/lib/cpp" + do + ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CXXCPP=$CXXCPP + +fi + CXXCPP=$ac_cv_prog_CXXCPP +else + ac_cv_prog_CXXCPP=$CXXCPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5 +$as_echo "$CXXCPP" >&6; } +ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@ifdef __STDC__ +@%:@ include +@%:@else +@%:@ include +@%:@endif + Syntax error +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +@%:@include +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +else + _lt_caught_CXX_error=yes +fi + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +archive_cmds_need_lc_CXX=no +allow_undefined_flag_CXX= +always_export_symbols_CXX=no +archive_expsym_cmds_CXX= +compiler_needs_object_CXX=no +export_dynamic_flag_spec_CXX= +hardcode_direct_CXX=no +hardcode_direct_absolute_CXX=no +hardcode_libdir_flag_spec_CXX= +hardcode_libdir_separator_CXX= +hardcode_minus_L_CXX=no +hardcode_shlibpath_var_CXX=unsupported +hardcode_automatic_CXX=no +inherit_rpath_CXX=no +module_cmds_CXX= +module_expsym_cmds_CXX= +link_all_deplibs_CXX=unknown +old_archive_cmds_CXX=$old_archive_cmds +reload_flag_CXX=$reload_flag +reload_cmds_CXX=$reload_cmds +no_undefined_flag_CXX= +whole_archive_flag_spec_CXX= +enable_shared_with_static_runtimes_CXX=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +objext_CXX=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_caught_CXX_error"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + + # save warnings/boilerplate of simple test code + ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + + ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_CFLAGS=$CFLAGS + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + CFLAGS=$CXXFLAGS + compiler=$CC + compiler_CXX=$CC + func_cc_basename $compiler +cc_basename=$func_cc_basename_result + + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test yes = "$GXX"; then + lt_prog_compiler_no_builtin_flag_CXX=' -fno-builtin' + else + lt_prog_compiler_no_builtin_flag_CXX= + fi + + if test yes = "$GXX"; then + # Set up default GNU C++ configuration + + + +@%:@ Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test yes = "$with_gnu_ld"; then + archive_cmds_CXX='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='$wl' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec_CXX=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + whole_archive_flag_spec_CXX= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + ld_shlibs_CXX=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aix[4-9]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds_CXX='' + hardcode_direct_CXX=yes + hardcode_direct_absolute_CXX=yes + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + file_list_spec_CXX='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + hardcode_direct_CXX=no + hardcode_direct_absolute_CXX=no + ;; + esac + + if test yes = "$GXX"; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct_CXX=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L_CXX=yes + hardcode_libdir_flag_spec_CXX='-L$libdir' + hardcode_libdir_separator_CXX= + fi + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag=$shared_flag' $wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + export_dynamic_flag_spec_CXX='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + always_export_symbols_CXX=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + # The "-G" linker flag allows undefined symbols. + no_undefined_flag_CXX='-bernotok' + # Determine the default libpath from the value encoded in an empty + # executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath__CXX=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath__CXX +fi + + hardcode_libdir_flag_spec_CXX='$wl-blibpath:$libdir:'"$aix_libpath" + + archive_expsym_cmds_CXX='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + hardcode_libdir_flag_spec_CXX='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag_CXX="-z nodefs" + archive_expsym_cmds_CXX="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath__CXX=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath__CXX +fi + + hardcode_libdir_flag_spec_CXX='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag_CXX=' $wl-bernotok' + allow_undefined_flag_CXX=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + whole_archive_flag_spec_CXX='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec_CXX='$convenience' + fi + archive_cmds_need_lc_CXX=yes + archive_expsym_cmds_CXX='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([, ]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared + # libraries. Need -bnortl late, we may have -brtl in LDFLAGS. + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag_CXX=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds_CXX='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + ld_shlibs_CXX=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + case $GXX,$cc_basename in + ,cl* | no,cl*) + # Native MSVC + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec_CXX=' ' + allow_undefined_flag_CXX=unsupported + always_export_symbols_CXX=yes + file_list_spec_CXX='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds_CXX='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_expsym_cmds_CXX='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, CXX)='true' + enable_shared_with_static_runtimes_CXX=yes + # Don't use ranlib + old_postinstall_cmds_CXX='chmod 644 $oldlib' + postlink_cmds_CXX='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + func_to_tool_file "$lt_outputfile"~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # g++ + # _LT_TAGVAR(hardcode_libdir_flag_spec, CXX) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec_CXX='-L$libdir' + export_dynamic_flag_spec_CXX='$wl--export-all-symbols' + allow_undefined_flag_CXX=unsupported + always_export_symbols_CXX=no + enable_shared_with_static_runtimes_CXX=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + archive_expsym_cmds_CXX='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs_CXX=no + fi + ;; + esac + ;; + darwin* | rhapsody*) + + + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes + hardcode_shlibpath_var_CXX=unsupported + if test yes = "$lt_cv_ld_force_load"; then + whole_archive_flag_spec_CXX='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + + else + whole_archive_flag_spec_CXX='' + fi + link_all_deplibs_CXX=yes + allow_undefined_flag_CXX=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds_CXX="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + if test yes != "$lt_cv_apple_cc_single_mod"; then + archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" + archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + fi + + else + ld_shlibs_CXX=no + fi + + ;; + + os2*) + hardcode_libdir_flag_spec_CXX='-L$libdir' + hardcode_minus_L_CXX=yes + allow_undefined_flag_CXX=unsupported + shrext_cmds=.dll + archive_cmds_CXX='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds_CXX='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds_CXX='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes_CXX=yes + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + freebsd2.*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + ld_shlibs_CXX=no + ;; + + freebsd-elf*) + archive_cmds_need_lc_CXX=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + ld_shlibs_CXX=yes + ;; + + haiku*) + archive_cmds_CXX='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + link_all_deplibs_CXX=yes + ;; + + hpux9*) + hardcode_libdir_flag_spec_CXX='$wl+b $wl$libdir' + hardcode_libdir_separator_CXX=: + export_dynamic_flag_spec_CXX='$wl-E' + hardcode_direct_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + archive_cmds_CXX='$RM $output_objdir/$soname~$CC -b $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + archive_cmds_CXX='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec_CXX='$wl+b $wl$libdir' + hardcode_libdir_separator_CXX=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + export_dynamic_flag_spec_CXX='$wl-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + ;; + *) + hardcode_direct_CXX=yes + hardcode_direct_absolute_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -b $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -shared -nostdlib -fPIC $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + interix[3-9]*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds_CXX='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds_CXX='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + archive_cmds_CXX='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` -o $lib' + fi + fi + link_all_deplibs_CXX=yes + ;; + esac + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + hardcode_libdir_separator_CXX=: + inherit_rpath_CXX=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + archive_expsym_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib $wl-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + archive_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + archive_cmds_need_lc_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + whole_archive_flag_spec_CXX='$wl--whole-archive$convenience $wl--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [1-5].* | *pgcpp\ [1-5].*) + prelink_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' + old_archive_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ + $RANLIB $oldlib' + archive_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 6 and above use weak symbols + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + + hardcode_libdir_flag_spec_CXX='$wl--rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + whole_archive_flag_spec_CXX='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + ;; + cxx*) + # Compaq C++ + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib $wl-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' + ;; + xl* | mpixl* | bgxl*) + # IBM XL 8.0 on PPC, with GNU ld + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + archive_cmds_CXX='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds_CXX='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + no_undefined_flag_CXX=' -zdefs' + archive_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + archive_expsym_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file $wl$export_symbols' + hardcode_libdir_flag_spec_CXX='-R$libdir' + whole_archive_flag_spec_CXX='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object_CXX=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds_CXX='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + ld_shlibs_CXX=yes + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + hardcode_direct_absolute_CXX=yes + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`"; then + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file,$export_symbols -o $lib' + export_dynamic_flag_spec_CXX='$wl-E' + whole_archive_flag_spec_CXX=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + fi + output_verbose_link_cmd=func_echo_all + else + ld_shlibs_CXX=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + hardcode_libdir_separator_CXX=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) old_archive_cmds_CXX='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + cxx*) + case $host in + osf3*) + allow_undefined_flag_CXX=' $wl-expect_unresolved $wl\*' + archive_cmds_CXX='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $soname `test -n "$verstring" && func_echo_all "$wl-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + ;; + *) + allow_undefined_flag_CXX=' -expect_unresolved \*' + archive_cmds_CXX='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds_CXX='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname $wl-input $wl$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~ + $RM $lib.exp' + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + ;; + esac + + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes,no = "$GXX,$with_gnu_ld"; then + allow_undefined_flag_CXX=' $wl-expect_unresolved $wl\*' + case $host in + osf3*) + archive_cmds_CXX='$CC -shared -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + *) + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + esac + + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + archive_cmds_need_lc_CXX=yes + no_undefined_flag_CXX=' -zdefs' + archive_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag $wl-M $wl$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_shlibpath_var_CXX=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + whole_archive_flag_spec_CXX='-z allextract$convenience -z defaultextract' + ;; + esac + link_all_deplibs_CXX=yes + + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + old_archive_cmds_CXX='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test yes,no = "$GXX,$with_gnu_ld"; then + no_undefined_flag_CXX=' $wl-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + else + # g++ 2.7 appears to require '-G' NOT '-shared' on this + # platform. + archive_cmds_CXX='$CC -G -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + fi + + hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir' + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + whole_archive_flag_spec_CXX='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag_CXX='$wl-z,text' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag_CXX='$wl-z,text' + allow_undefined_flag_CXX='$wl-z,nodefs' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-R,$libdir' + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + export_dynamic_flag_spec_CXX='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + old_archive_cmds_CXX='$CC -Tprelink_objects $oldobjs~ + '"$old_archive_cmds_CXX" + reload_cmds_CXX='$CC -Tprelink_objects $reload_objs~ + '"$reload_cmds_CXX" + ;; + *) + archive_cmds_CXX='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } + test no = "$ld_shlibs_CXX" && can_build_shared=no + + GCC_CXX=$GXX + LD_CXX=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + # Dependencies to place before and after the object being linked: +predep_objects_CXX= +postdep_objects_CXX= +predeps_CXX= +postdeps_CXX= +compiler_lib_search_path_CXX= + +cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF + + +_lt_libdeps_save_CFLAGS=$CFLAGS +case "$CC $CFLAGS " in #( +*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; +*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; +*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; +esac + +if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $prev$p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test x-L = "$p" || + test x-R = "$p"; then + prev=$p + continue + fi + + # Expand the sysroot to ease extracting the directories later. + if test -z "$prev"; then + case $p in + -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; + -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; + -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; + esac + fi + case $p in + =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; + esac + if test no = "$pre_test_object_deps_done"; then + case $prev in + -L | -R) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$compiler_lib_search_path_CXX"; then + compiler_lib_search_path_CXX=$prev$p + else + compiler_lib_search_path_CXX="${compiler_lib_search_path_CXX} $prev$p" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$postdeps_CXX"; then + postdeps_CXX=$prev$p + else + postdeps_CXX="${postdeps_CXX} $prev$p" + fi + fi + prev= + ;; + + *.lto.$objext) ;; # Ignore GCC LTO objects + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test no = "$pre_test_object_deps_done"; then + if test -z "$predep_objects_CXX"; then + predep_objects_CXX=$p + else + predep_objects_CXX="$predep_objects_CXX $p" + fi + else + if test -z "$postdep_objects_CXX"; then + postdep_objects_CXX=$p + else + postdep_objects_CXX="$postdep_objects_CXX $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling CXX test program" +fi + +$RM -f confest.$objext +CFLAGS=$_lt_libdeps_save_CFLAGS + +# PORTME: override above test on systems where it is broken +case $host_os in +interix[3-9]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + predep_objects_CXX= + postdep_objects_CXX= + postdeps_CXX= + ;; +esac + + +case " $postdeps_CXX " in +*" -lc "*) archive_cmds_need_lc_CXX=no ;; +esac + compiler_lib_search_dirs_CXX= +if test -n "${compiler_lib_search_path_CXX}"; then + compiler_lib_search_dirs_CXX=`echo " ${compiler_lib_search_path_CXX}" | $SED -e 's! -L! !g' -e 's!^ !!'` +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lt_prog_compiler_wl_CXX= +lt_prog_compiler_pic_CXX= +lt_prog_compiler_static_CXX= + + + # C++ specific cases for pic, static, wl, etc. + if test yes = "$GXX"; then + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + fi + lt_prog_compiler_pic_CXX='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic_CXX='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + lt_prog_compiler_pic_CXX='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic_CXX='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static_CXX='$wl-static' + ;; + esac + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic_CXX='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + lt_prog_compiler_pic_CXX= + ;; + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + lt_prog_compiler_static_CXX= + ;; + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic_CXX=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic_CXX='-fPIC -shared' + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + else + case $host_os in + aix[4-9]*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + else + lt_prog_compiler_static_CXX='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, CXX)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_CXX='-DDLL_EXPORT' + ;; + dgux*) + case $cc_basename in + ec++*) + lt_prog_compiler_pic_CXX='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='$wl-a ${wl}archive' + if test ia64 != "$host_cpu"; then + lt_prog_compiler_pic_CXX='+Z' + fi + ;; + aCC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='$wl-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_CXX='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + lt_prog_compiler_wl_CXX='--backend -Wl,' + lt_prog_compiler_pic_CXX='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64, which still supported -KPIC. + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-fPIC' + lt_prog_compiler_static_CXX='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-fpic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + xlc* | xlC* | bgxl[cC]* | mpixl[cC]*) + # IBM XL 8.0, 9.0 on PPC and BlueGene + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-qpic' + lt_prog_compiler_static_CXX='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + lt_prog_compiler_wl_CXX='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + lt_prog_compiler_pic_CXX='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic_CXX='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + lt_prog_compiler_wl_CXX='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + lt_prog_compiler_pic_CXX='-pic' + ;; + cxx*) + # Digital/Compaq C++ + lt_prog_compiler_wl_CXX='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + lt_prog_compiler_wl_CXX='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + lt_prog_compiler_pic_CXX='-pic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + lcc*) + # Lucid + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + lt_prog_compiler_pic_CXX='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + lt_prog_compiler_can_build_shared_CXX=no + ;; + esac + fi + +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic_CXX= + ;; + *) + lt_prog_compiler_pic_CXX="$lt_prog_compiler_pic_CXX@&t@ -DPIC" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_CXX=$lt_prog_compiler_pic_CXX +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_CXX" >&6; } +lt_prog_compiler_pic_CXX=$lt_cv_prog_compiler_pic_CXX + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... " >&6; } +if ${lt_cv_prog_compiler_pic_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works_CXX=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic_CXX@&t@ -DPIC" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works_CXX=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works_CXX" >&6; } + +if test yes = "$lt_cv_prog_compiler_pic_works_CXX"; then + case $lt_prog_compiler_pic_CXX in + "" | " "*) ;; + *) lt_prog_compiler_pic_CXX=" $lt_prog_compiler_pic_CXX" ;; + esac +else + lt_prog_compiler_pic_CXX= + lt_prog_compiler_can_build_shared_CXX=no +fi + +fi + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl_CXX eval lt_tmp_static_flag=\"$lt_prog_compiler_static_CXX\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works_CXX=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works_CXX=yes + fi + else + lt_cv_prog_compiler_static_works_CXX=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_static_works_CXX" >&6; } + +if test yes = "$lt_cv_prog_compiler_static_works_CXX"; then + : +else + lt_prog_compiler_static_CXX= +fi + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o_CXX=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_CXX=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o_CXX=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_CXX=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } + + + + +hard_links=nottested +if test no = "$lt_cv_prog_compiler_c_o_CXX" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test no = "$hard_links"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms_CXX='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + case $host_os in + aix[4-9]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds_CXX='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + export_symbols_cmds_CXX=$ltdll_cmds + ;; + cygwin* | mingw* | cegcc*) + case $cc_basename in + cl*) + exclude_expsyms_CXX='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + ;; + *) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms_CXX='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' + ;; + esac + ;; + *) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } +test no = "$ld_shlibs_CXX" && can_build_shared=no + +with_gnu_ld_CXX=$with_gnu_ld + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc_CXX" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc_CXX=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $archive_cmds_CXX in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl_CXX + pic_flag=$lt_prog_compiler_pic_CXX + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag_CXX + allow_undefined_flag_CXX= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + lt_cv_archive_cmds_need_lc_CXX=no + else + lt_cv_archive_cmds_need_lc_CXX=yes + fi + allow_undefined_flag_CXX=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_CXX" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc_CXX" >&6; } + archive_cmds_need_lc_CXX=$lt_cv_archive_cmds_need_lc_CXX + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + + + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[4-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a(lib.so.V)' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o), lib.a(lib.so.V)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a(lib.so.V), lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[3-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + hardcode_libdir_flag_spec_CXX='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl_CXX\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec_CXX\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + lt_cv_shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + +fi + + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action_CXX= +if test -n "$hardcode_libdir_flag_spec_CXX" || + test -n "$runpath_var_CXX" || + test yes = "$hardcode_automatic_CXX"; then + + # We can hardcode non-existent directories. + if test no != "$hardcode_direct_CXX" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, CXX)" && + test no != "$hardcode_minus_L_CXX"; then + # Linking always hardcodes the temporary library directory. + hardcode_action_CXX=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action_CXX=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action_CXX=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_CXX" >&5 +$as_echo "$hardcode_action_CXX" >&6; } + +if test relink = "$hardcode_action_CXX" || + test yes = "$inherit_rpath_CXX"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + + fi # test -n "$compiler" + + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test yes != "$_lt_caught_CXX_error" + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + + + + + + + + + + + + + ac_config_commands="$ac_config_commands libtool" + + + + +# Only expand once: + + + +#enable -D_GNU_SOURCE since the return code value of getaddrinfo +#ifdefed with __USE_GNU +#features.h header undef's __USE_GNU and defines it only if _GNU_SOURCE is defined +#hence this define for gcc +@%:@ Check whether --enable-debug was given. +if test "${enable_debug+set}" = set; then : + enableval=$enable_debug; +else + enable_debug=no +fi + + +if test "x$enable_debug" = xyes; then + if test "x$init_cflags" = x; then + CFLAGS="" + fi + CFLAGS="$CFLAGS -g -O0 -D_GNU_SOURCE" +else + if test "x$init_cflags" = x; then + CFLAGS="-g -O2 -D_GNU_SOURCE" + fi +fi + +if test "x$enable_debug" = xyes; then + if test "x$init_cxxflags" = x; then + CXXFLAGS="" + fi + CXXFLAGS="$CXXFLAGS -g -O0" +else + if test "x$init_cxxflags" = x; then + CXXFLAGS="-g -O2" + fi +fi + + +@%:@ Check whether --with-syncapi was given. +if test "${with_syncapi+set}" = set; then : + withval=$with_syncapi; +else + with_syncapi=yes +fi + + +# Checks for libraries. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_lock in -lpthread" >&5 +$as_echo_n "checking for pthread_mutex_lock in -lpthread... " >&6; } +if ${ac_cv_lib_pthread_pthread_mutex_lock+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_mutex_lock (); +int +main () +{ +return pthread_mutex_lock (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_pthread_pthread_mutex_lock=yes +else + ac_cv_lib_pthread_pthread_mutex_lock=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_lock" >&5 +$as_echo "$ac_cv_lib_pthread_pthread_mutex_lock" >&6; } +if test "x$ac_cv_lib_pthread_pthread_mutex_lock" = xyes; then : + have_pthread=yes +else + have_pthread=no +fi + + +if test "x$with_syncapi" != xno && test "x$have_pthread" = xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot build SyncAPI -- pthread not found" >&5 +$as_echo "$as_me: WARNING: cannot build SyncAPI -- pthread not found" >&2;} + with_syncapi=no +fi +if test "x$with_syncapi" != xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: building with SyncAPI support" >&5 +$as_echo "$as_me: building with SyncAPI support" >&6;} +else + { $as_echo "$as_me:${as_lineno-$LINENO}: building without SyncAPI support" >&5 +$as_echo "$as_me: building without SyncAPI support" >&6;} +fi + + if test "x$with_syncapi" != xno; then + WANT_SYNCAPI_TRUE= + WANT_SYNCAPI_FALSE='#' +else + WANT_SYNCAPI_TRUE='#' + WANT_SYNCAPI_FALSE= +fi + + +# Checks for header files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "@%:@define STDC_HEADERS 1" >>confdefs.h + +fi + +for ac_header in arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h sys/utsname.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +@%:@define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +# Checks for typedefs, structures, and compiler characteristics. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +$as_echo_n "checking for an ANSI C-conforming const... " >&6; } +if ${ac_cv_c_const+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#ifndef __cplusplus + /* Ultrix mips cc rejects this sort of thing. */ + typedef int charset[2]; + const charset cs = { 0, 0 }; + /* SunOS 4.1.1 cc rejects this. */ + char const *const *pcpcc; + char **ppc; + /* NEC SVR4.0.2 mips cc rejects this. */ + struct point {int x, y;}; + static struct point const zero = {0,0}; + /* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in + an arm of an if-expression whose if-part is not a constant + expression */ + const char *g = "string"; + pcpcc = &g + (g ? g-g : 0); + /* HPUX 7.0 cc rejects these. */ + ++pcpcc; + ppc = (char**) pcpcc; + pcpcc = (char const *const *) ppc; + { /* SCO 3.2v4 cc rejects this sort of thing. */ + char tx; + char *t = &tx; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; + if (s) return 0; + } + { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; + } + { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; + } + { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; } bx; + struct s *b = &bx; b->j = 5; + } + { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; + if (!foo) return 0; + } + return !cs[0] && !zero.x; +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_const=yes +else + ac_cv_c_const=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +$as_echo "$ac_cv_c_const" >&6; } +if test $ac_cv_c_const = no; then + +$as_echo "@%:@define const /**/" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 +$as_echo_n "checking for inline... " >&6; } +if ${ac_cv_c_inline+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_c_inline=no +for ac_kw in inline __inline__ __inline; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifndef __cplusplus +typedef int foo_t; +static $ac_kw foo_t static_foo () {return 0; } +$ac_kw foo_t foo () {return 0; } +#endif + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_inline=$ac_kw +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test "$ac_cv_c_inline" != no && break +done + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 +$as_echo "$ac_cv_c_inline" >&6; } + +case $ac_cv_c_inline in + inline | yes) ;; + *) + case $ac_cv_c_inline in + no) ac_val=;; + *) ac_val=$ac_cv_c_inline;; + esac + cat >>confdefs.h <<_ACEOF +#ifndef __cplusplus +#define inline $ac_val +#endif +_ACEOF + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5 +$as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; } +if ${ac_cv_header_time+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include + +int +main () +{ +if ((struct tm *) 0) +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_time=yes +else + ac_cv_header_time=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5 +$as_echo "$ac_cv_header_time" >&6; } +if test $ac_cv_header_time = yes; then + +$as_echo "@%:@define TIME_WITH_SYS_TIME 1" >>confdefs.h + +fi + +ac_fn_c_check_type "$LINENO" "nfds_t" "ac_cv_type_nfds_t" "#include +" +if test "x$ac_cv_type_nfds_t" = xyes; then : + +$as_echo "@%:@define POLL_NFDS_TYPE nfds_t" >>confdefs.h + +else + +$as_echo "@%:@define POLL_NFDS_TYPE unsigned int" >>confdefs.h + +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable ipv6" >&5 +$as_echo_n "checking whether to enable ipv6... " >&6; } + +if test "$cross_compiling" = yes; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ipv6=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + /* is AF_INET6 available? */ +#include +#include +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + ipv6=yes +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ipv6=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +if test x"$ipv6" = xyes; then + USEIPV6="-DZOO_IPV6_ENABLED" + +fi + +# Determine which libraries we need to use clock_gettime +saved_LIBS="$LIBS" +LIBS="" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5 +$as_echo_n "checking for clock_gettime in -lrt... " >&6; } +if ${ac_cv_lib_rt_clock_gettime+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrt $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char clock_gettime (); +int +main () +{ +return clock_gettime (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_rt_clock_gettime=yes +else + ac_cv_lib_rt_clock_gettime=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5 +$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; } +if test "x$ac_cv_lib_rt_clock_gettime" = xyes; then : + cat >>confdefs.h <<_ACEOF +@%:@define HAVE_LIBRT 1 +_ACEOF + + LIBS="-lrt $LIBS" + +fi + +CLOCK_GETTIME_LIBS=$LIBS + +LIBS="$saved_LIBS" + +# Checks for library functions. +for ac_func in getcwd gethostbyname gethostname getlogin getpwuid_r gettimeofday getuid memmove memset poll socket strchr strdup strerror strtol +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +@%:@define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +ac_config_files="$ac_config_files Makefile" + + + if + case "$host_os" in + *solaris*) + true + ;; + *) + false + ;; + esac ; then + SOLARIS_TRUE= + SOLARIS_FALSE='#' +else + SOLARIS_TRUE='#' + SOLARIS_FALSE= +fi + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + if test "x$cache_file" != "x/dev/null"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +U= +for ac_i in : $LIB@&t@OBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIB@&t@OBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + +if test -z "${DX_COND_doc_TRUE}" && test -z "${DX_COND_doc_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_doc\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_doc_TRUE}" && test -z "${DX_COND_doc_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_doc\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_dot_TRUE}" && test -z "${DX_COND_dot_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_dot\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_dot_TRUE}" && test -z "${DX_COND_dot_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_dot\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_man_TRUE}" && test -z "${DX_COND_man_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_man\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_man_TRUE}" && test -z "${DX_COND_man_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_man\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_rtf_TRUE}" && test -z "${DX_COND_rtf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_rtf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_rtf_TRUE}" && test -z "${DX_COND_rtf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_rtf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_xml_TRUE}" && test -z "${DX_COND_xml_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_xml\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_xml_TRUE}" && test -z "${DX_COND_xml_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_xml\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chm_TRUE}" && test -z "${DX_COND_chm_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chm\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chm_TRUE}" && test -z "${DX_COND_chm_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chm\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chi_TRUE}" && test -z "${DX_COND_chi_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chi\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chi_TRUE}" && test -z "${DX_COND_chi_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chi\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_html_TRUE}" && test -z "${DX_COND_html_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_html\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_html_TRUE}" && test -z "${DX_COND_html_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_html\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_ps_TRUE}" && test -z "${DX_COND_ps_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_ps\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_ps_TRUE}" && test -z "${DX_COND_ps_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_ps\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_pdf_TRUE}" && test -z "${DX_COND_pdf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_pdf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_pdf_TRUE}" && test -z "${DX_COND_pdf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_pdf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_latex_TRUE}" && test -z "${DX_COND_latex_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_latex\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_latex_TRUE}" && test -z "${DX_COND_latex_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_latex\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +$as_echo_n "checking that generated files are newer than configure... " >&6; } + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 +$as_echo "done" >&6; } + if test -n "$EXEEXT"; then + am__EXEEXT_TRUE= + am__EXEEXT_FALSE='#' +else + am__EXEEXT_TRUE='#' + am__EXEEXT_FALSE= +fi + +if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then + as_fn_error $? "conditional \"AMDEP\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCC\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WANT_SYNCAPI_TRUE}" && test -z "${WANT_SYNCAPI_FALSE}"; then + as_fn_error $? "conditional \"WANT_SYNCAPI\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${SOLARIS_TRUE}" && test -z "${SOLARIS_FALSE}"; then + as_fn_error $? "conditional \"SOLARIS\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi + +: "${CONFIG_STATUS=./config.status}" +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in @%:@( + *posix*) : + set -o posix ;; @%:@( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in @%:@( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in @%:@(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +@%:@ as_fn_error STATUS ERROR [LINENO LOG_FD] +@%:@ ---------------------------------------- +@%:@ Output "`basename @S|@0`: error: ERROR" to stderr. If LINENO and LOG_FD are +@%:@ provided, also output the error to LOG_FD, referencing LINENO. Then exit the +@%:@ script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} @%:@ as_fn_error + + +@%:@ as_fn_set_status STATUS +@%:@ ----------------------- +@%:@ Set @S|@? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} @%:@ as_fn_set_status + +@%:@ as_fn_exit STATUS +@%:@ ----------------- +@%:@ Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} @%:@ as_fn_exit + +@%:@ as_fn_unset VAR +@%:@ --------------- +@%:@ Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +@%:@ as_fn_append VAR VALUE +@%:@ ---------------------- +@%:@ Append the text in VALUE to the end of the definition contained in VAR. Take +@%:@ advantage of any shell optimizations that allow amortized linear growth over +@%:@ repeated appends, instead of the typical quadratic growth present in naive +@%:@ implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +@%:@ as_fn_arith ARG... +@%:@ ------------------ +@%:@ Perform arithmetic evaluation on the ARGs, and store the result in the +@%:@ global @S|@as_val. Take advantage of shells that can avoid forks. The arguments +@%:@ must be portable across @S|@(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in @%:@((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +@%:@ as_fn_mkdir_p +@%:@ ------------- +@%:@ Create "@S|@as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} @%:@ as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + + +@%:@ as_fn_executable_p FILE +@%:@ ----------------------- +@%:@ Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} @%:@ as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by zookeeper C client $as_me 3.6.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + +case $ac_config_headers in *" +"*) set x $ac_config_headers; shift; ac_config_headers=$*;; +esac + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" +config_commands="$ac_config_commands" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Configuration commands: +$config_commands + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_version="\\ +zookeeper C client config.status 3.6.0 +configured by $0, generated by GNU Autoconf 2.69, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2012 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' +AWK='$AWK' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=?*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + --*=) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg= + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + $as_echo "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + '') as_fn_error $? "missing file argument" ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_HEADERS " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + as_fn_error $? "ambiguous option: \`$1' +Try \`$0 --help' for more information.";; + --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error $? "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../@%:@@%:@ /;s/...$/ @%:@@%:@/;p;x;p;x' <<_ASBOX +@%:@@%:@ Running $as_me. @%:@@%:@ +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# +# INIT-COMMANDS +# +AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" + + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +macro_version='`$ECHO "$macro_version" | $SED "$delay_single_quote_subst"`' +macro_revision='`$ECHO "$macro_revision" | $SED "$delay_single_quote_subst"`' +enable_shared='`$ECHO "$enable_shared" | $SED "$delay_single_quote_subst"`' +enable_static='`$ECHO "$enable_static" | $SED "$delay_single_quote_subst"`' +pic_mode='`$ECHO "$pic_mode" | $SED "$delay_single_quote_subst"`' +enable_fast_install='`$ECHO "$enable_fast_install" | $SED "$delay_single_quote_subst"`' +shared_archive_member_spec='`$ECHO "$shared_archive_member_spec" | $SED "$delay_single_quote_subst"`' +SHELL='`$ECHO "$SHELL" | $SED "$delay_single_quote_subst"`' +ECHO='`$ECHO "$ECHO" | $SED "$delay_single_quote_subst"`' +PATH_SEPARATOR='`$ECHO "$PATH_SEPARATOR" | $SED "$delay_single_quote_subst"`' +host_alias='`$ECHO "$host_alias" | $SED "$delay_single_quote_subst"`' +host='`$ECHO "$host" | $SED "$delay_single_quote_subst"`' +host_os='`$ECHO "$host_os" | $SED "$delay_single_quote_subst"`' +build_alias='`$ECHO "$build_alias" | $SED "$delay_single_quote_subst"`' +build='`$ECHO "$build" | $SED "$delay_single_quote_subst"`' +build_os='`$ECHO "$build_os" | $SED "$delay_single_quote_subst"`' +SED='`$ECHO "$SED" | $SED "$delay_single_quote_subst"`' +Xsed='`$ECHO "$Xsed" | $SED "$delay_single_quote_subst"`' +GREP='`$ECHO "$GREP" | $SED "$delay_single_quote_subst"`' +EGREP='`$ECHO "$EGREP" | $SED "$delay_single_quote_subst"`' +FGREP='`$ECHO "$FGREP" | $SED "$delay_single_quote_subst"`' +LD='`$ECHO "$LD" | $SED "$delay_single_quote_subst"`' +NM='`$ECHO "$NM" | $SED "$delay_single_quote_subst"`' +LN_S='`$ECHO "$LN_S" | $SED "$delay_single_quote_subst"`' +max_cmd_len='`$ECHO "$max_cmd_len" | $SED "$delay_single_quote_subst"`' +ac_objext='`$ECHO "$ac_objext" | $SED "$delay_single_quote_subst"`' +exeext='`$ECHO "$exeext" | $SED "$delay_single_quote_subst"`' +lt_unset='`$ECHO "$lt_unset" | $SED "$delay_single_quote_subst"`' +lt_SP2NL='`$ECHO "$lt_SP2NL" | $SED "$delay_single_quote_subst"`' +lt_NL2SP='`$ECHO "$lt_NL2SP" | $SED "$delay_single_quote_subst"`' +lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_quote_subst"`' +lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`' +reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`' +reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`' +OBJDUMP='`$ECHO "$OBJDUMP" | $SED "$delay_single_quote_subst"`' +deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`' +file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`' +file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`' +want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`' +DLLTOOL='`$ECHO "$DLLTOOL" | $SED "$delay_single_quote_subst"`' +sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`' +AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`' +AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`' +archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`' +STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`' +RANLIB='`$ECHO "$RANLIB" | $SED "$delay_single_quote_subst"`' +old_postinstall_cmds='`$ECHO "$old_postinstall_cmds" | $SED "$delay_single_quote_subst"`' +old_postuninstall_cmds='`$ECHO "$old_postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_cmds='`$ECHO "$old_archive_cmds" | $SED "$delay_single_quote_subst"`' +lock_old_archive_extraction='`$ECHO "$lock_old_archive_extraction" | $SED "$delay_single_quote_subst"`' +CC='`$ECHO "$CC" | $SED "$delay_single_quote_subst"`' +CFLAGS='`$ECHO "$CFLAGS" | $SED "$delay_single_quote_subst"`' +compiler='`$ECHO "$compiler" | $SED "$delay_single_quote_subst"`' +GCC='`$ECHO "$GCC" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_pipe='`$ECHO "$lt_cv_sys_global_symbol_pipe" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_cdecl='`$ECHO "$lt_cv_sys_global_symbol_to_cdecl" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_import='`$ECHO "$lt_cv_sys_global_symbol_to_import" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $SED "$delay_single_quote_subst"`' +lt_cv_nm_interface='`$ECHO "$lt_cv_nm_interface" | $SED "$delay_single_quote_subst"`' +nm_file_list_spec='`$ECHO "$nm_file_list_spec" | $SED "$delay_single_quote_subst"`' +lt_sysroot='`$ECHO "$lt_sysroot" | $SED "$delay_single_quote_subst"`' +lt_cv_truncate_bin='`$ECHO "$lt_cv_truncate_bin" | $SED "$delay_single_quote_subst"`' +objdir='`$ECHO "$objdir" | $SED "$delay_single_quote_subst"`' +MAGIC_CMD='`$ECHO "$MAGIC_CMD" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag='`$ECHO "$lt_prog_compiler_no_builtin_flag" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_pic='`$ECHO "$lt_prog_compiler_pic" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_wl='`$ECHO "$lt_prog_compiler_wl" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_static='`$ECHO "$lt_prog_compiler_static" | $SED "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o='`$ECHO "$lt_cv_prog_compiler_c_o" | $SED "$delay_single_quote_subst"`' +need_locks='`$ECHO "$need_locks" | $SED "$delay_single_quote_subst"`' +MANIFEST_TOOL='`$ECHO "$MANIFEST_TOOL" | $SED "$delay_single_quote_subst"`' +DSYMUTIL='`$ECHO "$DSYMUTIL" | $SED "$delay_single_quote_subst"`' +NMEDIT='`$ECHO "$NMEDIT" | $SED "$delay_single_quote_subst"`' +LIPO='`$ECHO "$LIPO" | $SED "$delay_single_quote_subst"`' +OTOOL='`$ECHO "$OTOOL" | $SED "$delay_single_quote_subst"`' +OTOOL64='`$ECHO "$OTOOL64" | $SED "$delay_single_quote_subst"`' +libext='`$ECHO "$libext" | $SED "$delay_single_quote_subst"`' +shrext_cmds='`$ECHO "$shrext_cmds" | $SED "$delay_single_quote_subst"`' +extract_expsyms_cmds='`$ECHO "$extract_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds_need_lc='`$ECHO "$archive_cmds_need_lc" | $SED "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes='`$ECHO "$enable_shared_with_static_runtimes" | $SED "$delay_single_quote_subst"`' +export_dynamic_flag_spec='`$ECHO "$export_dynamic_flag_spec" | $SED "$delay_single_quote_subst"`' +whole_archive_flag_spec='`$ECHO "$whole_archive_flag_spec" | $SED "$delay_single_quote_subst"`' +compiler_needs_object='`$ECHO "$compiler_needs_object" | $SED "$delay_single_quote_subst"`' +old_archive_from_new_cmds='`$ECHO "$old_archive_from_new_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds='`$ECHO "$old_archive_from_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds='`$ECHO "$archive_cmds" | $SED "$delay_single_quote_subst"`' +archive_expsym_cmds='`$ECHO "$archive_expsym_cmds" | $SED "$delay_single_quote_subst"`' +module_cmds='`$ECHO "$module_cmds" | $SED "$delay_single_quote_subst"`' +module_expsym_cmds='`$ECHO "$module_expsym_cmds" | $SED "$delay_single_quote_subst"`' +with_gnu_ld='`$ECHO "$with_gnu_ld" | $SED "$delay_single_quote_subst"`' +allow_undefined_flag='`$ECHO "$allow_undefined_flag" | $SED "$delay_single_quote_subst"`' +no_undefined_flag='`$ECHO "$no_undefined_flag" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec='`$ECHO "$hardcode_libdir_flag_spec" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_separator='`$ECHO "$hardcode_libdir_separator" | $SED "$delay_single_quote_subst"`' +hardcode_direct='`$ECHO "$hardcode_direct" | $SED "$delay_single_quote_subst"`' +hardcode_direct_absolute='`$ECHO "$hardcode_direct_absolute" | $SED "$delay_single_quote_subst"`' +hardcode_minus_L='`$ECHO "$hardcode_minus_L" | $SED "$delay_single_quote_subst"`' +hardcode_shlibpath_var='`$ECHO "$hardcode_shlibpath_var" | $SED "$delay_single_quote_subst"`' +hardcode_automatic='`$ECHO "$hardcode_automatic" | $SED "$delay_single_quote_subst"`' +inherit_rpath='`$ECHO "$inherit_rpath" | $SED "$delay_single_quote_subst"`' +link_all_deplibs='`$ECHO "$link_all_deplibs" | $SED "$delay_single_quote_subst"`' +always_export_symbols='`$ECHO "$always_export_symbols" | $SED "$delay_single_quote_subst"`' +export_symbols_cmds='`$ECHO "$export_symbols_cmds" | $SED "$delay_single_quote_subst"`' +exclude_expsyms='`$ECHO "$exclude_expsyms" | $SED "$delay_single_quote_subst"`' +include_expsyms='`$ECHO "$include_expsyms" | $SED "$delay_single_quote_subst"`' +prelink_cmds='`$ECHO "$prelink_cmds" | $SED "$delay_single_quote_subst"`' +postlink_cmds='`$ECHO "$postlink_cmds" | $SED "$delay_single_quote_subst"`' +file_list_spec='`$ECHO "$file_list_spec" | $SED "$delay_single_quote_subst"`' +variables_saved_for_relink='`$ECHO "$variables_saved_for_relink" | $SED "$delay_single_quote_subst"`' +need_lib_prefix='`$ECHO "$need_lib_prefix" | $SED "$delay_single_quote_subst"`' +need_version='`$ECHO "$need_version" | $SED "$delay_single_quote_subst"`' +version_type='`$ECHO "$version_type" | $SED "$delay_single_quote_subst"`' +runpath_var='`$ECHO "$runpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_var='`$ECHO "$shlibpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_overrides_runpath='`$ECHO "$shlibpath_overrides_runpath" | $SED "$delay_single_quote_subst"`' +libname_spec='`$ECHO "$libname_spec" | $SED "$delay_single_quote_subst"`' +library_names_spec='`$ECHO "$library_names_spec" | $SED "$delay_single_quote_subst"`' +soname_spec='`$ECHO "$soname_spec" | $SED "$delay_single_quote_subst"`' +install_override_mode='`$ECHO "$install_override_mode" | $SED "$delay_single_quote_subst"`' +postinstall_cmds='`$ECHO "$postinstall_cmds" | $SED "$delay_single_quote_subst"`' +postuninstall_cmds='`$ECHO "$postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +finish_cmds='`$ECHO "$finish_cmds" | $SED "$delay_single_quote_subst"`' +finish_eval='`$ECHO "$finish_eval" | $SED "$delay_single_quote_subst"`' +hardcode_into_libs='`$ECHO "$hardcode_into_libs" | $SED "$delay_single_quote_subst"`' +sys_lib_search_path_spec='`$ECHO "$sys_lib_search_path_spec" | $SED "$delay_single_quote_subst"`' +configure_time_dlsearch_path='`$ECHO "$configure_time_dlsearch_path" | $SED "$delay_single_quote_subst"`' +configure_time_lt_sys_library_path='`$ECHO "$configure_time_lt_sys_library_path" | $SED "$delay_single_quote_subst"`' +hardcode_action='`$ECHO "$hardcode_action" | $SED "$delay_single_quote_subst"`' +enable_dlopen='`$ECHO "$enable_dlopen" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self='`$ECHO "$enable_dlopen_self" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self_static='`$ECHO "$enable_dlopen_self_static" | $SED "$delay_single_quote_subst"`' +old_striplib='`$ECHO "$old_striplib" | $SED "$delay_single_quote_subst"`' +striplib='`$ECHO "$striplib" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_dirs='`$ECHO "$compiler_lib_search_dirs" | $SED "$delay_single_quote_subst"`' +predep_objects='`$ECHO "$predep_objects" | $SED "$delay_single_quote_subst"`' +postdep_objects='`$ECHO "$postdep_objects" | $SED "$delay_single_quote_subst"`' +predeps='`$ECHO "$predeps" | $SED "$delay_single_quote_subst"`' +postdeps='`$ECHO "$postdeps" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_path='`$ECHO "$compiler_lib_search_path" | $SED "$delay_single_quote_subst"`' +LD_CXX='`$ECHO "$LD_CXX" | $SED "$delay_single_quote_subst"`' +reload_flag_CXX='`$ECHO "$reload_flag_CXX" | $SED "$delay_single_quote_subst"`' +reload_cmds_CXX='`$ECHO "$reload_cmds_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_cmds_CXX='`$ECHO "$old_archive_cmds_CXX" | $SED "$delay_single_quote_subst"`' +compiler_CXX='`$ECHO "$compiler_CXX" | $SED "$delay_single_quote_subst"`' +GCC_CXX='`$ECHO "$GCC_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag_CXX='`$ECHO "$lt_prog_compiler_no_builtin_flag_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_pic_CXX='`$ECHO "$lt_prog_compiler_pic_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_wl_CXX='`$ECHO "$lt_prog_compiler_wl_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_static_CXX='`$ECHO "$lt_prog_compiler_static_CXX" | $SED "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o_CXX='`$ECHO "$lt_cv_prog_compiler_c_o_CXX" | $SED "$delay_single_quote_subst"`' +archive_cmds_need_lc_CXX='`$ECHO "$archive_cmds_need_lc_CXX" | $SED "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes_CXX='`$ECHO "$enable_shared_with_static_runtimes_CXX" | $SED "$delay_single_quote_subst"`' +export_dynamic_flag_spec_CXX='`$ECHO "$export_dynamic_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +whole_archive_flag_spec_CXX='`$ECHO "$whole_archive_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +compiler_needs_object_CXX='`$ECHO "$compiler_needs_object_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_from_new_cmds_CXX='`$ECHO "$old_archive_from_new_cmds_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds_CXX='`$ECHO "$old_archive_from_expsyms_cmds_CXX" | $SED "$delay_single_quote_subst"`' +archive_cmds_CXX='`$ECHO "$archive_cmds_CXX" | $SED "$delay_single_quote_subst"`' +archive_expsym_cmds_CXX='`$ECHO "$archive_expsym_cmds_CXX" | $SED "$delay_single_quote_subst"`' +module_cmds_CXX='`$ECHO "$module_cmds_CXX" | $SED "$delay_single_quote_subst"`' +module_expsym_cmds_CXX='`$ECHO "$module_expsym_cmds_CXX" | $SED "$delay_single_quote_subst"`' +with_gnu_ld_CXX='`$ECHO "$with_gnu_ld_CXX" | $SED "$delay_single_quote_subst"`' +allow_undefined_flag_CXX='`$ECHO "$allow_undefined_flag_CXX" | $SED "$delay_single_quote_subst"`' +no_undefined_flag_CXX='`$ECHO "$no_undefined_flag_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec_CXX='`$ECHO "$hardcode_libdir_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_separator_CXX='`$ECHO "$hardcode_libdir_separator_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_direct_CXX='`$ECHO "$hardcode_direct_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_direct_absolute_CXX='`$ECHO "$hardcode_direct_absolute_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_minus_L_CXX='`$ECHO "$hardcode_minus_L_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_shlibpath_var_CXX='`$ECHO "$hardcode_shlibpath_var_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_automatic_CXX='`$ECHO "$hardcode_automatic_CXX" | $SED "$delay_single_quote_subst"`' +inherit_rpath_CXX='`$ECHO "$inherit_rpath_CXX" | $SED "$delay_single_quote_subst"`' +link_all_deplibs_CXX='`$ECHO "$link_all_deplibs_CXX" | $SED "$delay_single_quote_subst"`' +always_export_symbols_CXX='`$ECHO "$always_export_symbols_CXX" | $SED "$delay_single_quote_subst"`' +export_symbols_cmds_CXX='`$ECHO "$export_symbols_cmds_CXX" | $SED "$delay_single_quote_subst"`' +exclude_expsyms_CXX='`$ECHO "$exclude_expsyms_CXX" | $SED "$delay_single_quote_subst"`' +include_expsyms_CXX='`$ECHO "$include_expsyms_CXX" | $SED "$delay_single_quote_subst"`' +prelink_cmds_CXX='`$ECHO "$prelink_cmds_CXX" | $SED "$delay_single_quote_subst"`' +postlink_cmds_CXX='`$ECHO "$postlink_cmds_CXX" | $SED "$delay_single_quote_subst"`' +file_list_spec_CXX='`$ECHO "$file_list_spec_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_action_CXX='`$ECHO "$hardcode_action_CXX" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_dirs_CXX='`$ECHO "$compiler_lib_search_dirs_CXX" | $SED "$delay_single_quote_subst"`' +predep_objects_CXX='`$ECHO "$predep_objects_CXX" | $SED "$delay_single_quote_subst"`' +postdep_objects_CXX='`$ECHO "$postdep_objects_CXX" | $SED "$delay_single_quote_subst"`' +predeps_CXX='`$ECHO "$predeps_CXX" | $SED "$delay_single_quote_subst"`' +postdeps_CXX='`$ECHO "$postdeps_CXX" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_path_CXX='`$ECHO "$compiler_lib_search_path_CXX" | $SED "$delay_single_quote_subst"`' + +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$1 +_LTECHO_EOF' +} + +# Quote evaled strings. +for var in SHELL \ +ECHO \ +PATH_SEPARATOR \ +SED \ +GREP \ +EGREP \ +FGREP \ +LD \ +NM \ +LN_S \ +lt_SP2NL \ +lt_NL2SP \ +reload_flag \ +OBJDUMP \ +deplibs_check_method \ +file_magic_cmd \ +file_magic_glob \ +want_nocaseglob \ +DLLTOOL \ +sharedlib_from_linklib_cmd \ +AR \ +AR_FLAGS \ +archiver_list_spec \ +STRIP \ +RANLIB \ +CC \ +CFLAGS \ +compiler \ +lt_cv_sys_global_symbol_pipe \ +lt_cv_sys_global_symbol_to_cdecl \ +lt_cv_sys_global_symbol_to_import \ +lt_cv_sys_global_symbol_to_c_name_address \ +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \ +lt_cv_nm_interface \ +nm_file_list_spec \ +lt_cv_truncate_bin \ +lt_prog_compiler_no_builtin_flag \ +lt_prog_compiler_pic \ +lt_prog_compiler_wl \ +lt_prog_compiler_static \ +lt_cv_prog_compiler_c_o \ +need_locks \ +MANIFEST_TOOL \ +DSYMUTIL \ +NMEDIT \ +LIPO \ +OTOOL \ +OTOOL64 \ +shrext_cmds \ +export_dynamic_flag_spec \ +whole_archive_flag_spec \ +compiler_needs_object \ +with_gnu_ld \ +allow_undefined_flag \ +no_undefined_flag \ +hardcode_libdir_flag_spec \ +hardcode_libdir_separator \ +exclude_expsyms \ +include_expsyms \ +file_list_spec \ +variables_saved_for_relink \ +libname_spec \ +library_names_spec \ +soname_spec \ +install_override_mode \ +finish_eval \ +old_striplib \ +striplib \ +compiler_lib_search_dirs \ +predep_objects \ +postdep_objects \ +predeps \ +postdeps \ +compiler_lib_search_path \ +LD_CXX \ +reload_flag_CXX \ +compiler_CXX \ +lt_prog_compiler_no_builtin_flag_CXX \ +lt_prog_compiler_pic_CXX \ +lt_prog_compiler_wl_CXX \ +lt_prog_compiler_static_CXX \ +lt_cv_prog_compiler_c_o_CXX \ +export_dynamic_flag_spec_CXX \ +whole_archive_flag_spec_CXX \ +compiler_needs_object_CXX \ +with_gnu_ld_CXX \ +allow_undefined_flag_CXX \ +no_undefined_flag_CXX \ +hardcode_libdir_flag_spec_CXX \ +hardcode_libdir_separator_CXX \ +exclude_expsyms_CXX \ +include_expsyms_CXX \ +file_list_spec_CXX \ +compiler_lib_search_dirs_CXX \ +predep_objects_CXX \ +postdep_objects_CXX \ +predeps_CXX \ +postdeps_CXX \ +compiler_lib_search_path_CXX; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in reload_cmds \ +old_postinstall_cmds \ +old_postuninstall_cmds \ +old_archive_cmds \ +extract_expsyms_cmds \ +old_archive_from_new_cmds \ +old_archive_from_expsyms_cmds \ +archive_cmds \ +archive_expsym_cmds \ +module_cmds \ +module_expsym_cmds \ +export_symbols_cmds \ +prelink_cmds \ +postlink_cmds \ +postinstall_cmds \ +postuninstall_cmds \ +finish_cmds \ +sys_lib_search_path_spec \ +configure_time_dlsearch_path \ +configure_time_lt_sys_library_path \ +reload_cmds_CXX \ +old_archive_cmds_CXX \ +old_archive_from_new_cmds_CXX \ +old_archive_from_expsyms_cmds_CXX \ +archive_cmds_CXX \ +archive_expsym_cmds_CXX \ +module_cmds_CXX \ +module_expsym_cmds_CXX \ +export_symbols_cmds_CXX \ +prelink_cmds_CXX \ +postlink_cmds_CXX; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +ac_aux_dir='$ac_aux_dir' + +# See if we are running on zsh, and set the options that allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + + + PACKAGE='$PACKAGE' + VERSION='$VERSION' + RM='$RM' + ofile='$ofile' + + + + + + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; + "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= ac_tmp= + trap 'exit_status=$? + : "${ac_tmp:=$tmp}" + { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 +ac_tmp=$tmp + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$ac_tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ + || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove sole $(srcdir), +# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ +h +s/// +s/^/:/ +s/[ ]*$/:/ +s/:\$(srcdir):/:/g +s/:\${srcdir}:/:/g +s/:@srcdir@:/:/g +s/^:*// +s/:*$// +x +s/\(=[ ]*\).*/\1/ +G +s/\n// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + +# Set up the scripts for CONFIG_HEADERS section. +# No need to generate them if there are no CONFIG_HEADERS. +# This happens for instance with `./config.status Makefile'. +if test -n "$CONFIG_HEADERS"; then +cat >"$ac_tmp/defines.awk" <<\_ACAWK || +BEGIN { +_ACEOF + +# Transform confdefs.h into an awk script `defines.awk', embedded as +# here-document in config.status, that substitutes the proper values into +# config.h.in to produce config.h. + +# Create a delimiter string that does not exist in confdefs.h, to ease +# handling of long lines. +ac_delim='%!_!# ' +for ac_last_try in false false :; do + ac_tt=`sed -n "/$ac_delim/p" confdefs.h` + if test -z "$ac_tt"; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +# For the awk script, D is an array of macro values keyed by name, +# likewise P contains macro parameters if any. Preserve backslash +# newline sequences. + +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +sed -n ' +s/.\{148\}/&'"$ac_delim"'/g +t rset +:rset +s/^[ ]*#[ ]*define[ ][ ]*/ / +t def +d +:def +s/\\$// +t bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3"/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p +d +:bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3\\\\\\n"\\/p +t cont +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p +t cont +d +:cont +n +s/.\{148\}/&'"$ac_delim"'/g +t clear +:clear +s/\\$// +t bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/"/p +d +:bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p +b cont +' >$CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + for (key in D) D_is_set[key] = 1 + FS = "" +} +/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { + line = \$ 0 + split(line, arg, " ") + if (arg[1] == "#") { + defundef = arg[2] + mac1 = arg[3] + } else { + defundef = substr(arg[1], 2) + mac1 = arg[2] + } + split(mac1, mac2, "(") #) + macro = mac2[1] + prefix = substr(line, 1, index(line, defundef) - 1) + if (D_is_set[macro]) { + # Preserve the white space surrounding the "#". + print prefix "define", macro P[macro] D[macro] + next + } else { + # Replace #undef with comments. This is necessary, for example, + # in the case of _POSIX_SOURCE, which is predefined and required + # on some systems where configure will not decide to define it. + if (defundef == "undef") { + print "/*", prefix defundef, macro, "*/" + next + } + } +} +{ print } +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 +fi # test -n "$CONFIG_HEADERS" + + +eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$ac_tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$ac_tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ + >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + "$ac_tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&2;} + + rm -f "$ac_tmp/stdin" + case $ac_file in + -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; + *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; + esac \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + ;; + :H) + # + # CONFIG_HEADER + # + if test x"$ac_file" != x-; then + { + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" + } >"$ac_tmp/config.h" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +$as_echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f "$ac_file" + mv "$ac_tmp/config.h" "$ac_file" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + fi + else + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ + || as_fn_error $? "could not create -" "$LINENO" 5 + fi +# Compute "$ac_file"'s index in $config_headers. +_am_arg="$ac_file" +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || +$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$_am_arg" : 'X\(//\)[^/]' \| \ + X"$_am_arg" : 'X\(//\)$' \| \ + X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$_am_arg" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'`/stamp-h$_am_stamp_count + ;; + + :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +$as_echo "$as_me: executing $ac_file commands" >&6;} + ;; + esac + + + case $ac_file$ac_mode in + "depfiles":C) test x"$AMDEP_TRUE" != x"" || { + # Older Autoconf quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named 'Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`$as_dirname -- "$mf" || +$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$mf" : 'X\(//\)[^/]' \| \ + X"$mf" : 'X\(//\)$' \| \ + X"$mf" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$mf" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running 'make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "$am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`$as_dirname -- "$file" || +$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$file" : 'X\(//\)[^/]' \| \ + X"$file" : 'X\(//\)$' \| \ + X"$file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir=$dirpart/$fdir; as_fn_mkdir_p + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} + ;; + "libtool":C) + + # See if we are running on zsh, and set the options that allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST + fi + + cfgfile=${ofile}T + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL +# Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. + +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit, 1996 + +# Copyright (C) 2014 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program or library that is built +# using GNU Libtool, you may include this file under the same +# distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# The names of the tagged configurations supported by this script. +available_tags='CXX ' + +# Configured defaults for sys_lib_dlsearch_path munging. +: \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} + +# ### BEGIN LIBTOOL CONFIG + +# Which release of libtool.m4 was used? +macro_version=$macro_version +macro_revision=$macro_revision + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# What type of objects to build. +pic_mode=$pic_mode + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# Shared archive member basename,for filename based shared library versioning on AIX. +shared_archive_member_spec=$shared_archive_member_spec + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# An echo program that protects backslashes. +ECHO=$lt_ECHO + +# The PATH separator for the build system. +PATH_SEPARATOR=$lt_PATH_SEPARATOR + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="\$SED -e 1s/^X//" + +# A grep program that handles long lines. +GREP=$lt_GREP + +# An ERE matcher. +EGREP=$lt_EGREP + +# A literal string matcher. +FGREP=$lt_FGREP + +# A BSD- or MS-compatible name lister. +NM=$lt_NM + +# Whether we need soft or hard links. +LN_S=$lt_LN_S + +# What is the maximum length of a command? +max_cmd_len=$max_cmd_len + +# Object file suffix (normally "o"). +objext=$ac_objext + +# Executable file suffix (normally ""). +exeext=$exeext + +# whether the shell understands "unset". +lt_unset=$lt_unset + +# turn spaces into newlines. +SP2NL=$lt_lt_SP2NL + +# turn newlines into spaces. +NL2SP=$lt_lt_NL2SP + +# convert \$build file names to \$host format. +to_host_file_cmd=$lt_cv_to_host_file_cmd + +# convert \$build files to toolchain format. +to_tool_file_cmd=$lt_cv_to_tool_file_cmd + +# An object symbol dumper. +OBJDUMP=$lt_OBJDUMP + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method = "file_magic". +file_magic_cmd=$lt_file_magic_cmd + +# How to find potential files when deplibs_check_method = "file_magic". +file_magic_glob=$lt_file_magic_glob + +# Find potential files using nocaseglob when deplibs_check_method = "file_magic". +want_nocaseglob=$lt_want_nocaseglob + +# DLL creation program. +DLLTOOL=$lt_DLLTOOL + +# Command to associate shared and link libraries. +sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd + +# The archiver. +AR=$lt_AR + +# Flags to create an archive. +AR_FLAGS=$lt_AR_FLAGS + +# How to feed a file listing to the archiver. +archiver_list_spec=$lt_archiver_list_spec + +# A symbol stripping program. +STRIP=$lt_STRIP + +# Commands used to install an old-style archive. +RANLIB=$lt_RANLIB +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Whether to use a lock for old archive extraction. +lock_old_archive_extraction=$lock_old_archive_extraction + +# A C compiler. +LTCC=$lt_CC + +# LTCC compiler flags. +LTCFLAGS=$lt_CFLAGS + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration. +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm into a list of symbols to manually relocate. +global_symbol_to_import=$lt_lt_cv_sys_global_symbol_to_import + +# Transform the output of nm in a C name address pair. +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# Transform the output of nm in a C name address pair when lib prefix is needed. +global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix + +# The name lister interface. +nm_interface=$lt_lt_cv_nm_interface + +# Specify filename containing input files for \$NM. +nm_file_list_spec=$lt_nm_file_list_spec + +# The root where to search for dependent libraries,and where our libraries should be installed. +lt_sysroot=$lt_sysroot + +# Command to truncate a binary pipe. +lt_truncate_bin=$lt_lt_cv_truncate_bin + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# Used to examine libraries when file_magic_cmd begins with "file". +MAGIC_CMD=$MAGIC_CMD + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Manifest tool. +MANIFEST_TOOL=$lt_MANIFEST_TOOL + +# Tool to manipulate archived DWARF debug symbol files on Mac OS X. +DSYMUTIL=$lt_DSYMUTIL + +# Tool to change global to local symbols on Mac OS X. +NMEDIT=$lt_NMEDIT + +# Tool to manipulate fat objects and archives on Mac OS X. +LIPO=$lt_LIPO + +# ldd/readelf like tool for Mach-O binaries on Mac OS X. +OTOOL=$lt_OTOOL + +# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4. +OTOOL64=$lt_OTOOL64 + +# Old archive suffix (normally "a"). +libext=$libext + +# Shared library suffix (normally ".so"). +shrext_cmds=$lt_shrext_cmds + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at link time. +variables_saved_for_relink=$lt_variables_saved_for_relink + +# Do we need the "lib" prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Library versioning type. +version_type=$version_type + +# Shared library runtime path variable. +runpath_var=$runpath_var + +# Shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Permission mode override for installation of shared libraries. +install_override_mode=$lt_install_override_mode + +# Command to use after installation of a shared archive. +postinstall_cmds=$lt_postinstall_cmds + +# Command to use after uninstallation of a shared archive. +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# As "finish_cmds", except a single script fragment to be evaled but +# not shown. +finish_eval=$lt_finish_eval + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Compile-time system search path for libraries. +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Detected run-time system search path for libraries. +sys_lib_dlsearch_path_spec=$lt_configure_time_dlsearch_path + +# Explicit LT_SYS_LIBRARY_PATH set during ./configure time. +configure_time_lt_sys_library_path=$lt_configure_time_lt_sys_library_path + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + + +# The linker used to build libraries. +LD=$lt_LD + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds + +# A language specific compiler. +CC=$lt_compiler + +# Is the compiler the GNU compiler? +with_gcc=$GCC + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds +archive_expsym_cmds=$lt_archive_expsym_cmds + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds +module_expsym_cmds=$lt_module_expsym_cmds + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds + +# Commands necessary for finishing linking programs. +postlink_cmds=$lt_postlink_cmds + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action + +# The directories searched by this compiler when creating a shared library. +compiler_lib_search_dirs=$lt_compiler_lib_search_dirs + +# Dependencies to place before and after the objects being linked to +# create a shared library. +predep_objects=$lt_predep_objects +postdep_objects=$lt_postdep_objects +predeps=$lt_predeps +postdeps=$lt_postdeps + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path + +# ### END LIBTOOL CONFIG + +_LT_EOF + + cat <<'_LT_EOF' >> "$cfgfile" + +# ### BEGIN FUNCTIONS SHARED WITH CONFIGURE + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x@S|@2 in + x) + ;; + *:) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" + ;; + x:*) + eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" + ;; + *) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + esac +} + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in @S|@*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + + +# ### END FUNCTIONS SHARED WITH CONFIGURE + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + +ltmain=$ac_aux_dir/ltmain.sh + + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" + + + cat <<_LT_EOF >> "$ofile" + +# ### BEGIN LIBTOOL TAG CONFIG: CXX + +# The linker used to build libraries. +LD=$lt_LD_CXX + +# How to create reloadable object files. +reload_flag=$lt_reload_flag_CXX +reload_cmds=$lt_reload_cmds_CXX + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds_CXX + +# A language specific compiler. +CC=$lt_compiler_CXX + +# Is the compiler the GNU compiler? +with_gcc=$GCC_CXX + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_CXX + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic_CXX + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl_CXX + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static_CXX + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o_CXX + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc_CXX + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_CXX + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_CXX + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec_CXX + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object_CXX + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_CXX + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_CXX + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds_CXX +archive_expsym_cmds=$lt_archive_expsym_cmds_CXX + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds_CXX +module_expsym_cmds=$lt_module_expsym_cmds_CXX + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld_CXX + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag_CXX + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag_CXX + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_CXX + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator_CXX + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct_CXX + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute_CXX + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L_CXX + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var_CXX + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic_CXX + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath_CXX + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs_CXX + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols_CXX + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds_CXX + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms_CXX + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms_CXX + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds_CXX + +# Commands necessary for finishing linking programs. +postlink_cmds=$lt_postlink_cmds_CXX + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec_CXX + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action_CXX + +# The directories searched by this compiler when creating a shared library. +compiler_lib_search_dirs=$lt_compiler_lib_search_dirs_CXX + +# Dependencies to place before and after the objects being linked to +# create a shared library. +predep_objects=$lt_predep_objects_CXX +postdep_objects=$lt_postdep_objects_CXX +predeps=$lt_predeps_CXX +postdeps=$lt_postdeps_CXX + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path_CXX + +# ### END LIBTOOL TAG CONFIG: CXX +_LT_EOF + + ;; + + esac +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit 1 +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + diff --git a/src/c/autom4te.cache/requests b/src/c/autom4te.cache/requests new file mode 100644 index 00000000000..1811dd177dd --- /dev/null +++ b/src/c/autom4te.cache/requests @@ -0,0 +1,328 @@ +# This file was generated. +# It contains the lists of macros which have been traced. +# It can be safely removed. + +@request = ( + bless( [ + '0', + 1, + [ + '/usr/local/Cellar/autoconf/2.69/share/autoconf' + ], + [ + '/usr/local/Cellar/autoconf/2.69/share/autoconf/autoconf/autoconf.m4f', + '-', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/internal/ac-config-macro-dirs.m4', + '/usr/local/share/aclocal/libtool.m4', + '/usr/local/share/aclocal/ltargz.m4', + '/usr/local/share/aclocal/ltdl.m4', + '/usr/local/share/aclocal/ltoptions.m4', + '/usr/local/share/aclocal/ltsugar.m4', + '/usr/local/share/aclocal/ltversion.m4', + '/usr/local/share/aclocal/lt~obsolete.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/amversion.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/auxdir.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/cond.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/depend.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/depout.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/init.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/install-sh.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/lead-dot.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/make.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/missing.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/options.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/prog-cc-c-o.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/runlog.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/sanity.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/silent.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/strip.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/substnot.m4', + '/usr/local/Cellar/automake/1.15/share/aclocal-1.15/tar.m4', + 'acinclude.m4', + 'configure.ac' + ], + { + 'LTSUGAR_VERSION' => 1, + 'AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, + 'AC_LIBTOOL_CONFIG' => 1, + '_AM_SUBST_NOTMAKE' => 1, + '_LT_PROG_CXX' => 1, + 'AC_LTDL_SYMBOL_USCORE' => 1, + 'AC_LIBTOOL_SYS_HARD_LINK_LOCKS' => 1, + 'AC_LTDL_SYS_DLOPEN_DEPLIBS' => 1, + 'LT_PROG_GO' => 1, + 'm4_pattern_forbid' => 1, + 'AC_PROG_LD_GNU' => 1, + 'AC_LTDL_PREOPEN' => 1, + 'DX_MAN_FEATURE' => 1, + '_LT_AC_LANG_F77' => 1, + 'AC_ENABLE_STATIC' => 1, + 'AU_DEFUN' => 1, + 'DX_CHI_FEATURE' => 1, + 'AC_PROG_NM' => 1, + 'AC_LIBTOOL_SETUP' => 1, + 'AM_DEP_TRACK' => 1, + 'DX_FEATURE_dot' => 1, + 'LT_INIT' => 1, + '_AM_PROG_CC_C_O' => 1, + '_LT_PROG_FC' => 1, + 'AC_LIBTOOL_PROG_CC_C_O' => 1, + '_LT_AC_TRY_DLOPEN_SELF' => 1, + '_LT_AC_CHECK_DLFCN' => 1, + '_LT_CC_BASENAME' => 1, + 'DX_FEATURE_rtf' => 1, + '_LT_PATH_TOOL_PREFIX' => 1, + 'DX_FEATURE_doc' => 1, + 'LT_AC_PROG_EGREP' => 1, + '_LT_WITH_SYSROOT' => 1, + 'AC_LIBTOOL_WIN32_DLL' => 1, + 'DX_PS_FEATURE' => 1, + 'DX_IF_FEATURE' => 1, + 'LT_CONFIG_LTDL_DIR' => 1, + 'AC_LTDL_SHLIBPATH' => 1, + 'AM_RUN_LOG' => 1, + '_LT_AC_LANG_F77_CONFIG' => 1, + 'AM_PROG_CC_C_O' => 1, + '_LT_AC_PROG_ECHO_BACKSLASH' => 1, + 'AM_SET_DEPDIR' => 1, + 'DX_CHECK_DEPEND' => 1, + 'DX_REQUIRE_PROG' => 1, + 'LTOPTIONS_VERSION' => 1, + '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, + 'AM_SANITY_CHECK' => 1, + 'LTVERSION_VERSION' => 1, + 'AC_LIBTOOL_POSTDEP_PREDEP' => 1, + '_LT_AC_LOCK' => 1, + 'm4_include' => 1, + 'LT_SYS_DLOPEN_SELF' => 1, + '_LT_AC_LANG_GCJ' => 1, + 'AC_LIBTOOL_LANG_GCJ_CONFIG' => 1, + '_LT_LIBOBJ' => 1, + 'AC_LIBTOOL_PROG_LD_SHLIBS' => 1, + 'AC_CONFIG_MACRO_DIR_TRACE' => 1, + '_LT_AC_LANG_GCJ_CONFIG' => 1, + '_AC_PROG_LIBTOOL' => 1, + 'AC_LTDL_SYSSEARCHPATH' => 1, + 'AM_PROG_INSTALL_SH' => 1, + 'AC_PROG_EGREP' => 1, + '_LT_AC_LANG_RC_CONFIG' => 1, + 'AM_PROG_LIBTOOL' => 1, + '_AM_AUTOCONF_VERSION' => 1, + 'LT_SYS_DLSEARCH_PATH' => 1, + 'LTDL_CONVENIENCE' => 1, + '_AC_AM_CONFIG_HEADER_HOOK' => 1, + 'AM_SUBST_NOTMAKE' => 1, + 'AC_LIBTOOL_PICMODE' => 1, + 'AC_LIBTOOL_LINKER_OPTION' => 1, + 'AC_LIBTOOL_COMPILER_OPTION' => 1, + 'AC_LIBTOOL_GCJ' => 1, + 'DX_FEATURE_html' => 1, + 'DX_ARG_ABLE' => 1, + '_LT_AC_SYS_COMPILER' => 1, + 'AM_SET_LEADING_DOT' => 1, + 'AC_LIBTOOL_OBJDIR' => 1, + 'DX_INIT_DOXYGEN' => 1, + 'LT_PATH_NM' => 1, + 'LT_SYS_MODULE_PATH' => 1, + 'AC_LIBLTDL_CONVENIENCE' => 1, + 'DX_DIRNAME_EXPR' => 1, + 'AC_LIBTOOL_SYS_OLD_ARCHIVE' => 1, + '_LT_AC_LANG_CXX_CONFIG' => 1, + 'AM_MISSING_HAS_RUN' => 1, + 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1, + '_LT_LINKER_BOILERPLATE' => 1, + 'AC_DEFUN_ONCE' => 1, + 'AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH' => 1, + 'LT_CMD_MAX_LEN' => 1, + '_AM_CONFIG_MACRO_DIRS' => 1, + 'LT_WITH_LTDL' => 1, + 'LT_FUNC_DLSYM_USCORE' => 1, + '_m4_warn' => 1, + 'AM_AUTOMAKE_VERSION' => 1, + 'AC_LIBTOOL_SYS_DYNAMIC_LINKER' => 1, + '_LT_PROG_LTMAIN' => 1, + 'DX_FEATURE_pdf' => 1, + 'LT_AC_PROG_RC' => 1, + 'AC_ENABLE_SHARED' => 1, + 'AC_LIB_LTDL' => 1, + 'LTDL_INIT' => 1, + '_LT_COMPILER_OPTION' => 1, + 'AC_LIBTOOL_LANG_C_CONFIG' => 1, + 'DX_DOXYGEN_FEATURE' => 1, + 'DX_CURRENT_DESCRIPTION' => 1, + 'AC_LIBTOOL_DLOPEN' => 1, + 'include' => 1, + '_LT_AC_TAGCONFIG' => 1, + 'AC_PATH_TOOL_PREFIX' => 1, + 'AC_LIBTOOL_LANG_RC_CONFIG' => 1, + '_LT_PROG_ECHO_BACKSLASH' => 1, + 'AC_LIBTOOL_FC' => 1, + 'AC_DISABLE_SHARED' => 1, + 'LT_LIB_DLLOAD' => 1, + 'AC_LIBTOOL_CXX' => 1, + 'DX_RTF_FEATURE' => 1, + 'AM_AUX_DIR_EXPAND' => 1, + 'AC_LIBTOOL_F77' => 1, + 'LTOBSOLETE_VERSION' => 1, + 'AM_PROG_NM' => 1, + '_AM_DEPENDENCIES' => 1, + 'AC_PROG_LIBTOOL' => 1, + '_LT_AC_SYS_LIBPATH_AIX' => 1, + 'AC_LIBTOOL_SYS_MAX_CMD_LEN' => 1, + 'AM_SILENT_RULES' => 1, + 'AC_PROG_LD_RELOAD_FLAG' => 1, + '_LT_PREPARE_SED_QUOTE_VARS' => 1, + 'DX_FEATURE_ps' => 1, + 'LT_FUNC_ARGZ' => 1, + 'AC_LTDL_ENABLE_INSTALL' => 1, + 'AC_LTDL_DLSYM_USCORE' => 1, + 'LT_SYS_DLOPEN_DEPLIBS' => 1, + 'AC_DISABLE_STATIC' => 1, + 'LT_AC_PROG_SED' => 1, + 'DX_FEATURE_man' => 1, + 'AC_WITH_LTDL' => 1, + 'AC_DEFUN' => 1, + 'AM_ENABLE_STATIC' => 1, + '_LTDL_SETUP' => 1, + 'LT_PATH_LD' => 1, + 'AC_CHECK_LIBM' => 1, + 'AM_CONDITIONAL' => 1, + 'AC_CONFIG_MACRO_DIR' => 1, + 'LT_LANG' => 1, + 'LT_SYS_MODULE_EXT' => 1, + 'AC_LTDL_SHLIBEXT' => 1, + 'AC_DISABLE_FAST_INSTALL' => 1, + '_AM_IF_OPTION' => 1, + '_LT_AC_PROG_CXXCPP' => 1, + '_AM_SET_OPTIONS' => 1, + 'AC_LTDL_DLLIB' => 1, + '_LT_AC_TAGVAR' => 1, + 'AC_LIBTOOL_PROG_COMPILER_PIC' => 1, + 'AC_LIBTOOL_DLOPEN_SELF' => 1, + 'AM_DISABLE_STATIC' => 1, + 'LT_AC_PROG_GCJ' => 1, + 'AC_LIBTOOL_LANG_CXX_CONFIG' => 1, + 'DX_HTML_FEATURE' => 1, + 'AC_LIBLTDL_INSTALLABLE' => 1, + '_AM_MANGLE_OPTION' => 1, + 'AC_ENABLE_FAST_INSTALL' => 1, + '_LT_AC_FILE_LTDLL_C' => 1, + 'LT_SYS_SYMBOL_USCORE' => 1, + 'LT_PROG_GCJ' => 1, + '_AM_PROG_TAR' => 1, + '_LT_AC_LANG_CXX' => 1, + 'AC_LIBTOOL_PROG_COMPILER_NO_RTTI' => 1, + 'm4_pattern_allow' => 1, + 'LT_SUPPORTED_TAG' => 1, + 'AC_LIBTOOL_LANG_F77_CONFIG' => 1, + '_LT_REQUIRED_DARWIN_CHECKS' => 1, + 'AC_PROG_LD' => 1, + 'LT_OUTPUT' => 1, + 'DX_CURRENT_FEATURE' => 1, + '_LT_AC_LANG_C_CONFIG' => 1, + 'AM_PROG_LD' => 1, + 'AC_PATH_MAGIC' => 1, + 'AM_INIT_AUTOMAKE' => 1, + 'DX_CHM_FEATURE' => 1, + 'AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE' => 1, + 'AM_DISABLE_SHARED' => 1, + '_LT_LINKER_OPTION' => 1, + '_LT_PROG_F77' => 1, + 'DX_FEATURE_chi' => 1, + 'DX_CLEAR_DEPEND' => 1, + '_LT_DLL_DEF_P' => 1, + 'AC_LIBTOOL_SYS_LIB_STRIP' => 1, + 'DX_FEATURE_chm' => 1, + 'LT_LIB_M' => 1, + 'DX_PDF_FEATURE' => 1, + 'DX_XML_FEATURE' => 1, + '_LT_COMPILER_BOILERPLATE' => 1, + '_AM_SET_OPTION' => 1, + 'AM_PROG_INSTALL_STRIP' => 1, + 'LT_PROG_RC' => 1, + '_LT_AC_SHELL_INIT' => 1, + 'AC_LIBTOOL_RC' => 1, + 'AC_LTDL_OBJDIR' => 1, + 'AM_MAKE_INCLUDE' => 1, + 'AM_ENABLE_SHARED' => 1, + 'AC_DEPLIBS_CHECK_METHOD' => 1, + 'AM_MISSING_PROG' => 1, + 'DX_TEST_FEATURE' => 1, + 'LTDL_INSTALLABLE' => 1, + 'DX_FEATURE_xml' => 1, + 'DX_ENV_APPEND' => 1 + } + ], 'Autom4te::Request' ), + bless( [ + '1', + 1, + [ + '/usr/local/Cellar/autoconf/2.69/share/autoconf' + ], + [ + '/usr/local/Cellar/autoconf/2.69/share/autoconf/autoconf/autoconf.m4f', + 'aclocal.m4', + 'configure.ac' + ], + { + 'AM_MAINTAINER_MODE' => 1, + 'AM_POT_TOOLS' => 1, + 'AH_OUTPUT' => 1, + 'AM_ENABLE_MULTILIB' => 1, + '_AM_MAKEFILE_INCLUDE' => 1, + '_AM_COND_ELSE' => 1, + 'AM_GNU_GETTEXT' => 1, + 'AM_XGETTEXT_OPTION' => 1, + 'LT_CONFIG_LTDL_DIR' => 1, + 'AC_CANONICAL_SYSTEM' => 1, + 'AM_CONDITIONAL' => 1, + 'm4_sinclude' => 1, + 'AC_LIBSOURCE' => 1, + '_AM_COND_IF' => 1, + 'AC_CONFIG_HEADERS' => 1, + 'AC_FC_FREEFORM' => 1, + 'AC_INIT' => 1, + 'AM_PROG_FC_C_O' => 1, + 'AM_PROG_CC_C_O' => 1, + 'AC_FC_PP_DEFINE' => 1, + 'AM_PROG_F77_C_O' => 1, + 'AC_CONFIG_FILES' => 1, + 'AM_PROG_AR' => 1, + 'AC_CONFIG_LINKS' => 1, + '_AM_COND_ENDIF' => 1, + 'AM_NLS' => 1, + 'AM_AUTOMAKE_VERSION' => 1, + 'AC_CANONICAL_HOST' => 1, + 'AC_CONFIG_LIBOBJ_DIR' => 1, + '_m4_warn' => 1, + 'AC_SUBST' => 1, + 'AC_CANONICAL_BUILD' => 1, + 'AC_CANONICAL_TARGET' => 1, + '_AM_SUBST_NOTMAKE' => 1, + 'm4_include' => 1, + 'AM_PROG_CXX_C_O' => 1, + 'AM_MAKEFILE_INCLUDE' => 1, + 'include' => 1, + 'm4_pattern_forbid' => 1, + 'AC_REQUIRE_AUX_FILE' => 1, + 'AC_FC_SRCEXT' => 1, + '_LT_AC_TAGCONFIG' => 1, + 'LT_SUPPORTED_TAG' => 1, + 'AC_SUBST_TRACE' => 1, + 'm4_pattern_allow' => 1, + 'AM_GNU_GETTEXT_INTL_SUBDIR' => 1, + 'AM_PROG_MOC' => 1, + 'sinclude' => 1, + 'LT_INIT' => 1, + 'AC_CONFIG_AUX_DIR' => 1, + 'AC_CONFIG_SUBDIRS' => 1, + 'AC_DEFINE_TRACE_LITERAL' => 1, + 'AC_PROG_LIBTOOL' => 1, + 'AM_SILENT_RULES' => 1, + 'AM_INIT_AUTOMAKE' => 1, + 'AC_FC_PP_SRCEXT' => 1, + 'AM_PATH_GUILE' => 1 + } + ], 'Autom4te::Request' ) + ); + diff --git a/src/c/autom4te.cache/traces.0 b/src/c/autom4te.cache/traces.0 new file mode 100644 index 00000000000..ad216f5a6c4 --- /dev/null +++ b/src/c/autom4te.cache/traces.0 @@ -0,0 +1,3449 @@ +m4trace:/usr/local/share/aclocal/libtool.m4:96: -1- AC_DEFUN([LT_INIT], [AC_PREREQ([2.62])dnl We use AC_PATH_PROGS_FEATURE_CHECK +AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +_LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}]) + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:99: -1- AU_DEFUN([AC_PROG_LIBTOOL], [m4_if($#, 0, [LT_INIT], [LT_INIT($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:99: -1- AC_DEFUN([AC_PROG_LIBTOOL], [AC_DIAGNOSE([obsolete], [The macro `AC_PROG_LIBTOOL' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_INIT], [LT_INIT($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:100: -1- AU_DEFUN([AM_PROG_LIBTOOL], [m4_if($#, 0, [LT_INIT], [LT_INIT($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:100: -1- AC_DEFUN([AM_PROG_LIBTOOL], [AC_DIAGNOSE([obsolete], [The macro `AM_PROG_LIBTOOL' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_INIT], [LT_INIT($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:704: -1- AC_DEFUN([LT_OUTPUT], [: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +_LT_GENERATED_FILE_INIT(["$CONFIG_LT"], +[# Run this file to recreate a libtool stub with the current configuration.]) + +cat >>"$CONFIG_LT" <<\_LTEOF +lt_cl_silent=false +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +'$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2011 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test 0 != $[#] +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try '$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try '$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +lt_cl_success=: +test yes = "$silent" && + lt_config_lt_args="$lt_config_lt_args --quiet" +exec AS_MESSAGE_LOG_FD>/dev/null +$SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false +exec AS_MESSAGE_LOG_FD>>config.log +$lt_cl_success || AS_EXIT(1) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:812: -1- AC_DEFUN([LT_SUPPORTED_TAG], []) +m4trace:/usr/local/share/aclocal/libtool.m4:836: -1- AC_DEFUN([LT_LANG], [AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Go], [_LT_LANG(GO)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +]) +m4trace:/usr/local/share/aclocal/libtool.m4:915: -1- AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +m4trace:/usr/local/share/aclocal/libtool.m4:915: -1- AC_DEFUN([AC_LIBTOOL_CXX], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_CXX' is obsolete. +You should run autoupdate.])dnl +LT_LANG(C++)]) +m4trace:/usr/local/share/aclocal/libtool.m4:916: -1- AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +m4trace:/usr/local/share/aclocal/libtool.m4:916: -1- AC_DEFUN([AC_LIBTOOL_F77], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_F77' is obsolete. +You should run autoupdate.])dnl +LT_LANG(Fortran 77)]) +m4trace:/usr/local/share/aclocal/libtool.m4:917: -1- AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +m4trace:/usr/local/share/aclocal/libtool.m4:917: -1- AC_DEFUN([AC_LIBTOOL_FC], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_FC' is obsolete. +You should run autoupdate.])dnl +LT_LANG(Fortran)]) +m4trace:/usr/local/share/aclocal/libtool.m4:918: -1- AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +m4trace:/usr/local/share/aclocal/libtool.m4:918: -1- AC_DEFUN([AC_LIBTOOL_GCJ], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_GCJ' is obsolete. +You should run autoupdate.])dnl +LT_LANG(Java)]) +m4trace:/usr/local/share/aclocal/libtool.m4:919: -1- AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)]) +m4trace:/usr/local/share/aclocal/libtool.m4:919: -1- AC_DEFUN([AC_LIBTOOL_RC], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_RC' is obsolete. +You should run autoupdate.])dnl +LT_LANG(Windows Resource)]) +m4trace:/usr/local/share/aclocal/libtool.m4:1277: -1- AC_DEFUN([_LT_WITH_SYSROOT], [AC_MSG_CHECKING([for sysroot]) +AC_ARG_WITH([sysroot], +[AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@], + [Search for dependent libraries within DIR (or the compiler's sysroot + if not specified).])], +[], [with_sysroot=no]) + +dnl lt_sysroot will always be passed unquoted. We quote it here +dnl in case the user passed a directory name. +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + AC_MSG_RESULT([$with_sysroot]) + AC_MSG_ERROR([The sysroot must be an absolute path.]) + ;; +esac + + AC_MSG_RESULT([${lt_sysroot:-no}]) +_LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl +[dependent libraries, and where our libraries should be installed.])]) +m4trace:/usr/local/share/aclocal/libtool.m4:1617: -1- AC_DEFUN([_LT_COMPILER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test yes = "[$]$2"; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +]) +m4trace:/usr/local/share/aclocal/libtool.m4:1620: -1- AU_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [m4_if($#, 0, [_LT_COMPILER_OPTION], [_LT_COMPILER_OPTION($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:1620: -1- AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_COMPILER_OPTION' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [_LT_COMPILER_OPTION], [_LT_COMPILER_OPTION($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:1661: -1- AC_DEFUN([_LT_LINKER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS +]) + +if test yes = "[$]$2"; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +]) +m4trace:/usr/local/share/aclocal/libtool.m4:1664: -1- AU_DEFUN([AC_LIBTOOL_LINKER_OPTION], [m4_if($#, 0, [_LT_LINKER_OPTION], [_LT_LINKER_OPTION($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:1664: -1- AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_LINKER_OPTION' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [_LT_LINKER_OPTION], [_LT_LINKER_OPTION($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:1807: -1- AC_DEFUN([LT_CMD_MAX_LEN], [AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n "$lt_cv_sys_max_cmd_len"; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:1810: -1- AU_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [m4_if($#, 0, [LT_CMD_MAX_LEN], [LT_CMD_MAX_LEN($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:1810: -1- AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_SYS_MAX_CMD_LEN' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_CMD_MAX_LEN], [LT_CMD_MAX_LEN($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:2043: -1- AC_DEFUN([LT_SYS_DLOPEN_SELF], [m4_require([_LT_HEADER_DLFCN])dnl +if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl],[ + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen=shl_load], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen=dlopen], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:2046: -1- AU_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [m4_if($#, 0, [LT_SYS_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:2046: -1- AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_DLOPEN_SELF' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_SYS_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3214: -1- AC_DEFUN([_LT_PATH_TOOL_PREFIX], [m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$1"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac]) +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +]) +m4trace:/usr/local/share/aclocal/libtool.m4:3217: -1- AU_DEFUN([AC_PATH_TOOL_PREFIX], [m4_if($#, 0, [_LT_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3217: -1- AC_DEFUN([AC_PATH_TOOL_PREFIX], [AC_DIAGNOSE([obsolete], [The macro `AC_PATH_TOOL_PREFIX' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [_LT_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3326: -1- AC_DEFUN([LT_PATH_LD], [AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PROG_ECHO_BACKSLASH])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test no = "$withval" || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi]) +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :) + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + AC_SUBST([DUMPBIN]) + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:3754: -1- AU_DEFUN([AM_PROG_NM], [m4_if($#, 0, [LT_PATH_NM], [LT_PATH_NM($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3754: -1- AC_DEFUN([AM_PROG_NM], [AC_DIAGNOSE([obsolete], [The macro `AM_PROG_NM' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_PATH_NM], [LT_PATH_NM($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3755: -1- AU_DEFUN([AC_PROG_NM], [m4_if($#, 0, [LT_PATH_NM], [LT_PATH_NM($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3755: -1- AC_DEFUN([AC_PROG_NM], [AC_DIAGNOSE([obsolete], [The macro `AC_PROG_NM' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_PATH_NM], [LT_PATH_NM($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3834: -1- AC_DEFUN([_LT_DLL_DEF_P], [dnl + test DEF = "`$SED -n dnl + -e '\''s/^[[ ]]*//'\'' dnl Strip leading whitespace + -e '\''/^\(;.*\)*$/d'\'' dnl Delete empty lines and comments + -e '\''s/^\(EXPORTS\|LIBRARY\)\([[ ]].*\)*$/DEF/p'\'' dnl + -e q dnl Only consider the first "real" line + $1`" dnl +]) +m4trace:/usr/local/share/aclocal/libtool.m4:3856: -1- AC_DEFUN([LT_LIB_M], [AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM=-lmw) + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM=-lm) + ;; +esac +AC_SUBST([LIBM]) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:3859: -1- AU_DEFUN([AC_CHECK_LIBM], [m4_if($#, 0, [LT_LIB_M], [LT_LIB_M($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:3859: -1- AC_DEFUN([AC_CHECK_LIBM], [AC_DIAGNOSE([obsolete], [The macro `AC_CHECK_LIBM' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_LIB_M], [LT_LIB_M($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:8128: -1- AC_DEFUN([LT_PROG_GCJ], [m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test set = "${GCJFLAGS+set}" || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) +m4trace:/usr/local/share/aclocal/libtool.m4:8131: -1- AU_DEFUN([LT_AC_PROG_GCJ], [m4_if($#, 0, [LT_PROG_GCJ], [LT_PROG_GCJ($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:8131: -1- AC_DEFUN([LT_AC_PROG_GCJ], [AC_DIAGNOSE([obsolete], [The macro `LT_AC_PROG_GCJ' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_PROG_GCJ], [LT_PROG_GCJ($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:8140: -1- AC_DEFUN([LT_PROG_GO], [AC_CHECK_TOOL(GOC, gccgo,) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:8147: -1- AC_DEFUN([LT_PROG_RC], [AC_CHECK_TOOL(RC, windres,) +]) +m4trace:/usr/local/share/aclocal/libtool.m4:8150: -1- AU_DEFUN([LT_AC_PROG_RC], [m4_if($#, 0, [LT_PROG_RC], [LT_PROG_RC($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:8150: -1- AC_DEFUN([LT_AC_PROG_RC], [AC_DIAGNOSE([obsolete], [The macro `LT_AC_PROG_RC' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_PROG_RC], [LT_PROG_RC($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:8270: -1- AU_DEFUN([LT_AC_PROG_SED], [m4_if($#, 0, [AC_PROG_SED], [AC_PROG_SED($@)])]) +m4trace:/usr/local/share/aclocal/libtool.m4:8270: -1- AC_DEFUN([LT_AC_PROG_SED], [AC_DIAGNOSE([obsolete], [The macro `LT_AC_PROG_SED' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [AC_PROG_SED], [AC_PROG_SED($@)])]) +m4trace:/usr/local/share/aclocal/ltargz.m4:74: -1- AC_DEFUN([LT_FUNC_ARGZ], [ +AC_CHECK_HEADERS([argz.h], [], [], [AC_INCLUDES_DEFAULT]) + +AC_CHECK_TYPES([error_t], + [], + [AC_DEFINE([error_t], [int], + [Define to a type to use for 'error_t' if it is not otherwise available.]) + AC_DEFINE([__error_t_defined], [1], [Define so that glibc/gnulib argp.h + does not typedef error_t.])], + [#if defined(HAVE_ARGZ_H) +# include +#endif]) + +LT_ARGZ_H= +AC_CHECK_FUNCS([argz_add argz_append argz_count argz_create_sep argz_insert \ + argz_next argz_stringify], [], [LT_ARGZ_H=lt__argz.h; AC_LIBOBJ([lt__argz])]) + +dnl if have system argz functions, allow forced use of +dnl libltdl-supplied implementation (and default to do so +dnl on "known bad" systems). Could use a runtime check, but +dnl (a) detecting malloc issues is notoriously unreliable +dnl (b) only known system that declares argz functions, +dnl provides them, yet they are broken, is cygwin +dnl releases prior to 16-Mar-2007 (1.5.24 and earlier) +dnl So, it's more straightforward simply to special case +dnl this for known bad systems. +AS_IF([test -z "$LT_ARGZ_H"], + [AC_CACHE_CHECK( + [if argz actually works], + [lt_cv_sys_argz_works], + [[case $host_os in #( + *cygwin*) + lt_cv_sys_argz_works=no + if test no != "$cross_compiling"; then + lt_cv_sys_argz_works="guessing no" + else + lt_sed_extract_leading_digits='s/^\([0-9\.]*\).*/\1/' + save_IFS=$IFS + IFS=-. + set x `uname -r | sed -e "$lt_sed_extract_leading_digits"` + IFS=$save_IFS + lt_os_major=${2-0} + lt_os_minor=${3-0} + lt_os_micro=${4-0} + if test 1 -lt "$lt_os_major" \ + || { test 1 -eq "$lt_os_major" \ + && { test 5 -lt "$lt_os_minor" \ + || { test 5 -eq "$lt_os_minor" \ + && test 24 -lt "$lt_os_micro"; }; }; }; then + lt_cv_sys_argz_works=yes + fi + fi + ;; #( + *) lt_cv_sys_argz_works=yes ;; + esac]]) + AS_IF([test yes = "$lt_cv_sys_argz_works"], + [AC_DEFINE([HAVE_WORKING_ARGZ], 1, + [This value is set to 1 to indicate that the system argz facility works])], + [LT_ARGZ_H=lt__argz.h + AC_LIBOBJ([lt__argz])])]) + +AC_SUBST([LT_ARGZ_H]) +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:19: -1- AC_DEFUN([LT_CONFIG_LTDL_DIR], [AC_BEFORE([$0], [LTDL_INIT]) +_$0($*) +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:77: -1- AC_DEFUN([LTDL_CONVENIENCE], [AC_BEFORE([$0], [LTDL_INIT])dnl +dnl Although the argument is deprecated and no longer documented, +dnl LTDL_CONVENIENCE used to take a DIRECTORY orgument, if we have one +dnl here make sure it is the same as any other declaration of libltdl's +dnl location! This also ensures lt_ltdl_dir is set when configure.ac is +dnl not yet using an explicit LT_CONFIG_LTDL_DIR. +m4_ifval([$1], [_LT_CONFIG_LTDL_DIR([$1])])dnl +_$0() +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:83: -1- AU_DEFUN([AC_LIBLTDL_CONVENIENCE], [_LT_CONFIG_LTDL_DIR([m4_default([$1], [libltdl])]) +_LTDL_CONVENIENCE]) +m4trace:/usr/local/share/aclocal/ltdl.m4:83: -1- AC_DEFUN([AC_LIBLTDL_CONVENIENCE], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBLTDL_CONVENIENCE' is obsolete. +You should run autoupdate.])dnl +_LT_CONFIG_LTDL_DIR([m4_default([$1], [libltdl])]) +_LTDL_CONVENIENCE]) +m4trace:/usr/local/share/aclocal/ltdl.m4:133: -1- AC_DEFUN([LTDL_INSTALLABLE], [AC_BEFORE([$0], [LTDL_INIT])dnl +dnl Although the argument is deprecated and no longer documented, +dnl LTDL_INSTALLABLE used to take a DIRECTORY orgument, if we have one +dnl here make sure it is the same as any other declaration of libltdl's +dnl location! This also ensures lt_ltdl_dir is set when configure.ac is +dnl not yet using an explicit LT_CONFIG_LTDL_DIR. +m4_ifval([$1], [_LT_CONFIG_LTDL_DIR([$1])])dnl +_$0() +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:139: -1- AU_DEFUN([AC_LIBLTDL_INSTALLABLE], [_LT_CONFIG_LTDL_DIR([m4_default([$1], [libltdl])]) +_LTDL_INSTALLABLE]) +m4trace:/usr/local/share/aclocal/ltdl.m4:139: -1- AC_DEFUN([AC_LIBLTDL_INSTALLABLE], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBLTDL_INSTALLABLE' is obsolete. +You should run autoupdate.])dnl +_LT_CONFIG_LTDL_DIR([m4_default([$1], [libltdl])]) +_LTDL_INSTALLABLE]) +m4trace:/usr/local/share/aclocal/ltdl.m4:216: -1- AC_DEFUN([_LT_LIBOBJ], [ + m4_pattern_allow([^_LT_LIBOBJS$]) + _LT_LIBOBJS="$_LT_LIBOBJS $1.$ac_objext" +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:349: -1- AC_DEFUN([LTDL_INIT], [dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +dnl We need to keep our own list of libobjs separate from our parent project, +dnl and the easiest way to do that is redefine the AC_LIBOBJs macro while +dnl we look for our own LIBOBJs. +m4_pushdef([AC_LIBOBJ], m4_defn([_LT_LIBOBJ])) +m4_pushdef([AC_LIBSOURCES]) + +dnl If not otherwise defined, default to the 1.5.x compatible subproject mode: +m4_if(_LTDL_MODE, [], + [m4_define([_LTDL_MODE], m4_default([$2], [subproject])) + m4_if([-1], [m4_bregexp(_LTDL_MODE, [\(subproject\|\(non\)?recursive\)])], + [m4_fatal([unknown libltdl mode: ]_LTDL_MODE)])]) + +AC_ARG_WITH([included_ltdl], + [AS_HELP_STRING([--with-included-ltdl], + [use the GNU ltdl sources included here])]) + +if test yes != "$with_included_ltdl"; then + # We are not being forced to use the included libltdl sources, so + # decide whether there is a useful installed version we can use. + AC_CHECK_HEADER([ltdl.h], + [AC_CHECK_DECL([lt_dlinterface_register], + [AC_CHECK_LIB([ltdl], [lt_dladvise_preload], + [with_included_ltdl=no], + [with_included_ltdl=yes])], + [with_included_ltdl=yes], + [AC_INCLUDES_DEFAULT + #include ])], + [with_included_ltdl=yes], + [AC_INCLUDES_DEFAULT] + ) +fi + +dnl If neither LT_CONFIG_LTDL_DIR, LTDL_CONVENIENCE nor LTDL_INSTALLABLE +dnl was called yet, then for old times' sake, we assume libltdl is in an +dnl eponymous directory: +AC_PROVIDE_IFELSE([LT_CONFIG_LTDL_DIR], [], [_LT_CONFIG_LTDL_DIR([libltdl])]) + +AC_ARG_WITH([ltdl_include], + [AS_HELP_STRING([--with-ltdl-include=DIR], + [use the ltdl headers installed in DIR])]) + +if test -n "$with_ltdl_include"; then + if test -f "$with_ltdl_include/ltdl.h"; then : + else + AC_MSG_ERROR([invalid ltdl include directory: '$with_ltdl_include']) + fi +else + with_ltdl_include=no +fi + +AC_ARG_WITH([ltdl_lib], + [AS_HELP_STRING([--with-ltdl-lib=DIR], + [use the libltdl.la installed in DIR])]) + +if test -n "$with_ltdl_lib"; then + if test -f "$with_ltdl_lib/libltdl.la"; then : + else + AC_MSG_ERROR([invalid ltdl library directory: '$with_ltdl_lib']) + fi +else + with_ltdl_lib=no +fi + +case ,$with_included_ltdl,$with_ltdl_include,$with_ltdl_lib, in + ,yes,no,no,) + m4_case(m4_default(_LTDL_TYPE, [convenience]), + [convenience], [_LTDL_CONVENIENCE], + [installable], [_LTDL_INSTALLABLE], + [m4_fatal([unknown libltdl build type: ]_LTDL_TYPE)]) + ;; + ,no,no,no,) + # If the included ltdl is not to be used, then use the + # preinstalled libltdl we found. + AC_DEFINE([HAVE_LTDL], [1], + [Define this if a modern libltdl is already installed]) + LIBLTDL=-lltdl + LTDLDEPS= + LTDLINCL= + ;; + ,no*,no,*) + AC_MSG_ERROR(['--with-ltdl-include' and '--with-ltdl-lib' options must be used together]) + ;; + *) with_included_ltdl=no + LIBLTDL="-L$with_ltdl_lib -lltdl" + LTDLDEPS= + LTDLINCL=-I$with_ltdl_include + ;; +esac +INCLTDL=$LTDLINCL + +# Report our decision... +AC_MSG_CHECKING([where to find libltdl headers]) +AC_MSG_RESULT([$LTDLINCL]) +AC_MSG_CHECKING([where to find libltdl library]) +AC_MSG_RESULT([$LIBLTDL]) + +_LTDL_SETUP + +dnl restore autoconf definition. +m4_popdef([AC_LIBOBJ]) +m4_popdef([AC_LIBSOURCES]) + +AC_CONFIG_COMMANDS_PRE([ + _ltdl_libobjs= + _ltdl_ltlibobjs= + if test -n "$_LT_LIBOBJS"; then + # Remove the extension. + _lt_sed_drop_objext='s/\.o$//;s/\.obj$//' + for i in `for i in $_LT_LIBOBJS; do echo "$i"; done | sed "$_lt_sed_drop_objext" | sort -u`; do + _ltdl_libobjs="$_ltdl_libobjs $lt_libobj_prefix$i.$ac_objext" + _ltdl_ltlibobjs="$_ltdl_ltlibobjs $lt_libobj_prefix$i.lo" + done + fi + AC_SUBST([ltdl_LIBOBJS], [$_ltdl_libobjs]) + AC_SUBST([ltdl_LTLIBOBJS], [$_ltdl_ltlibobjs]) +]) + +# Only expand once: +m4_define([LTDL_INIT]) +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:352: -1- AU_DEFUN([AC_LIB_LTDL], [LTDL_INIT($@)]) +m4trace:/usr/local/share/aclocal/ltdl.m4:352: -1- AC_DEFUN([AC_LIB_LTDL], [AC_DIAGNOSE([obsolete], [The macro `AC_LIB_LTDL' is obsolete. +You should run autoupdate.])dnl +LTDL_INIT($@)]) +m4trace:/usr/local/share/aclocal/ltdl.m4:353: -1- AU_DEFUN([AC_WITH_LTDL], [LTDL_INIT($@)]) +m4trace:/usr/local/share/aclocal/ltdl.m4:353: -1- AC_DEFUN([AC_WITH_LTDL], [AC_DIAGNOSE([obsolete], [The macro `AC_WITH_LTDL' is obsolete. +You should run autoupdate.])dnl +LTDL_INIT($@)]) +m4trace:/usr/local/share/aclocal/ltdl.m4:354: -1- AU_DEFUN([LT_WITH_LTDL], [LTDL_INIT($@)]) +m4trace:/usr/local/share/aclocal/ltdl.m4:354: -1- AC_DEFUN([LT_WITH_LTDL], [AC_DIAGNOSE([obsolete], [The macro `LT_WITH_LTDL' is obsolete. +You should run autoupdate.])dnl +LTDL_INIT($@)]) +m4trace:/usr/local/share/aclocal/ltdl.m4:421: -1- AC_DEFUN([_LTDL_SETUP], [AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_SYS_MODULE_EXT])dnl +AC_REQUIRE([LT_SYS_MODULE_PATH])dnl +AC_REQUIRE([LT_SYS_DLSEARCH_PATH])dnl +AC_REQUIRE([LT_LIB_DLLOAD])dnl +AC_REQUIRE([LT_SYS_SYMBOL_USCORE])dnl +AC_REQUIRE([LT_FUNC_DLSYM_USCORE])dnl +AC_REQUIRE([LT_SYS_DLOPEN_DEPLIBS])dnl +AC_REQUIRE([LT_FUNC_ARGZ])dnl + +m4_require([_LT_CHECK_OBJDIR])dnl +m4_require([_LT_HEADER_DLFCN])dnl +m4_require([_LT_CHECK_DLPREOPEN])dnl +m4_require([_LT_DECL_SED])dnl + +dnl Don't require this, or it will be expanded earlier than the code +dnl that sets the variables it relies on: +_LT_ENABLE_INSTALL + +dnl _LTDL_MODE specific code must be called at least once: +_LTDL_MODE_DISPATCH + +# In order that ltdl.c can compile, find out the first AC_CONFIG_HEADERS +# the user used. This is so that ltdl.h can pick up the parent projects +# config.h file, The first file in AC_CONFIG_HEADERS must contain the +# definitions required by ltdl.c. +# FIXME: Remove use of undocumented AC_LIST_HEADERS (2.59 compatibility). +AC_CONFIG_COMMANDS_PRE([dnl +m4_pattern_allow([^LT_CONFIG_H$])dnl +m4_ifset([AH_HEADER], + [LT_CONFIG_H=AH_HEADER], + [m4_ifset([AC_LIST_HEADERS], + [LT_CONFIG_H=`echo "AC_LIST_HEADERS" | $SED 's|^[[ ]]*||;s|[[ :]].*$||'`], + [])])]) +AC_SUBST([LT_CONFIG_H]) + +AC_CHECK_HEADERS([unistd.h dl.h sys/dl.h dld.h mach-o/dyld.h dirent.h], + [], [], [AC_INCLUDES_DEFAULT]) + +AC_CHECK_FUNCS([closedir opendir readdir], [], [AC_LIBOBJ([lt__dirent])]) +AC_CHECK_FUNCS([strlcat strlcpy], [], [AC_LIBOBJ([lt__strl])]) + +m4_pattern_allow([LT_LIBEXT])dnl +AC_DEFINE_UNQUOTED([LT_LIBEXT],["$libext"],[The archive extension]) + +name= +eval "lt_libprefix=\"$libname_spec\"" +m4_pattern_allow([LT_LIBPREFIX])dnl +AC_DEFINE_UNQUOTED([LT_LIBPREFIX],["$lt_libprefix"],[The archive prefix]) + +name=ltdl +eval "LTDLOPEN=\"$libname_spec\"" +AC_SUBST([LTDLOPEN]) +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:542: -1- AC_DEFUN([LT_SYS_DLOPEN_DEPLIBS], [AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_CACHE_CHECK([whether deplibs are loaded by dlopen], + [lt_cv_sys_dlopen_deplibs], + [# PORTME does your system automatically load deplibs for dlopen? + # or its logical equivalent (e.g. shl_load for HP-UX < 11) + # For now, we just catch OSes we know something about -- in the + # future, we'll try test this programmatically. + lt_cv_sys_dlopen_deplibs=unknown + case $host_os in + aix3*|aix4.1.*|aix4.2.*) + # Unknown whether this is true for these versions of AIX, but + # we want this 'case' here to explicitly catch those versions. + lt_cv_sys_dlopen_deplibs=unknown + ;; + aix[[4-9]]*) + lt_cv_sys_dlopen_deplibs=yes + ;; + amigaos*) + case $host_cpu in + powerpc) + lt_cv_sys_dlopen_deplibs=no + ;; + esac + ;; + bitrig*) + lt_cv_sys_dlopen_deplibs=yes + ;; + darwin*) + # Assuming the user has installed a libdl from somewhere, this is true + # If you are looking for one http://www.opendarwin.org/projects/dlcompat + lt_cv_sys_dlopen_deplibs=yes + ;; + freebsd* | dragonfly*) + lt_cv_sys_dlopen_deplibs=yes + ;; + gnu* | linux* | k*bsd*-gnu | kopensolaris*-gnu) + # GNU and its variants, using gnu ld.so (Glibc) + lt_cv_sys_dlopen_deplibs=yes + ;; + hpux10*|hpux11*) + lt_cv_sys_dlopen_deplibs=yes + ;; + interix*) + lt_cv_sys_dlopen_deplibs=yes + ;; + irix[[12345]]*|irix6.[[01]]*) + # Catch all versions of IRIX before 6.2, and indicate that we don't + # know how it worked for any of those versions. + lt_cv_sys_dlopen_deplibs=unknown + ;; + irix*) + # The case above catches anything before 6.2, and it's known that + # at 6.2 and later dlopen does load deplibs. + lt_cv_sys_dlopen_deplibs=yes + ;; + netbsd*) + lt_cv_sys_dlopen_deplibs=yes + ;; + openbsd*) + lt_cv_sys_dlopen_deplibs=yes + ;; + osf[[1234]]*) + # dlopen did load deplibs (at least at 4.x), but until the 5.x series, + # it did *not* use an RPATH in a shared library to find objects the + # library depends on, so we explicitly say 'no'. + lt_cv_sys_dlopen_deplibs=no + ;; + osf5.0|osf5.0a|osf5.1) + # dlopen *does* load deplibs and with the right loader patch applied + # it even uses RPATH in a shared library to search for shared objects + # that the library depends on, but there's no easy way to know if that + # patch is installed. Since this is the case, all we can really + # say is unknown -- it depends on the patch being installed. If + # it is, this changes to 'yes'. Without it, it would be 'no'. + lt_cv_sys_dlopen_deplibs=unknown + ;; + osf*) + # the two cases above should catch all versions of osf <= 5.1. Read + # the comments above for what we know about them. + # At > 5.1, deplibs are loaded *and* any RPATH in a shared library + # is used to find them so we can finally say 'yes'. + lt_cv_sys_dlopen_deplibs=yes + ;; + qnx*) + lt_cv_sys_dlopen_deplibs=yes + ;; + solaris*) + lt_cv_sys_dlopen_deplibs=yes + ;; + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + libltdl_cv_sys_dlopen_deplibs=yes + ;; + esac + ]) +if test yes != "$lt_cv_sys_dlopen_deplibs"; then + AC_DEFINE([LTDL_DLOPEN_DEPLIBS], [1], + [Define if the OS needs help to load dependent libraries for dlopen().]) +fi +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:545: -1- AU_DEFUN([AC_LTDL_SYS_DLOPEN_DEPLIBS], [m4_if($#, 0, [LT_SYS_DLOPEN_DEPLIBS], [LT_SYS_DLOPEN_DEPLIBS($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:545: -1- AC_DEFUN([AC_LTDL_SYS_DLOPEN_DEPLIBS], [AC_DIAGNOSE([obsolete], [The macro `AC_LTDL_SYS_DLOPEN_DEPLIBS' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_SYS_DLOPEN_DEPLIBS], [LT_SYS_DLOPEN_DEPLIBS($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:577: -1- AC_DEFUN([LT_SYS_MODULE_EXT], [m4_require([_LT_SYS_DYNAMIC_LINKER])dnl +AC_CACHE_CHECK([what extension is used for runtime loadable modules], + [libltdl_cv_shlibext], +[ +module=yes +eval libltdl_cv_shlibext=$shrext_cmds +module=no +eval libltdl_cv_shrext=$shrext_cmds + ]) +if test -n "$libltdl_cv_shlibext"; then + m4_pattern_allow([LT_MODULE_EXT])dnl + AC_DEFINE_UNQUOTED([LT_MODULE_EXT], ["$libltdl_cv_shlibext"], + [Define to the extension used for runtime loadable modules, say, ".so".]) +fi +if test "$libltdl_cv_shrext" != "$libltdl_cv_shlibext"; then + m4_pattern_allow([LT_SHARED_EXT])dnl + AC_DEFINE_UNQUOTED([LT_SHARED_EXT], ["$libltdl_cv_shrext"], + [Define to the shared library suffix, say, ".dylib".]) +fi +if test -n "$shared_archive_member_spec"; then + m4_pattern_allow([LT_SHARED_LIB_MEMBER])dnl + AC_DEFINE_UNQUOTED([LT_SHARED_LIB_MEMBER], ["($shared_archive_member_spec.o)"], + [Define to the shared archive member specification, say "(shr.o)".]) +fi +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:580: -1- AU_DEFUN([AC_LTDL_SHLIBEXT], [m4_if($#, 0, [LT_SYS_MODULE_EXT], [LT_SYS_MODULE_EXT($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:580: -1- AC_DEFUN([AC_LTDL_SHLIBEXT], [AC_DIAGNOSE([obsolete], [The macro `AC_LTDL_SHLIBEXT' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_SYS_MODULE_EXT], [LT_SYS_MODULE_EXT($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:596: -1- AC_DEFUN([LT_SYS_MODULE_PATH], [m4_require([_LT_SYS_DYNAMIC_LINKER])dnl +AC_CACHE_CHECK([what variable specifies run-time module search path], + [lt_cv_module_path_var], [lt_cv_module_path_var=$shlibpath_var]) +if test -n "$lt_cv_module_path_var"; then + m4_pattern_allow([LT_MODULE_PATH_VAR])dnl + AC_DEFINE_UNQUOTED([LT_MODULE_PATH_VAR], ["$lt_cv_module_path_var"], + [Define to the name of the environment variable that determines the run-time module search path.]) +fi +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:599: -1- AU_DEFUN([AC_LTDL_SHLIBPATH], [m4_if($#, 0, [LT_SYS_MODULE_PATH], [LT_SYS_MODULE_PATH($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:599: -1- AC_DEFUN([AC_LTDL_SHLIBPATH], [AC_DIAGNOSE([obsolete], [The macro `AC_LTDL_SHLIBPATH' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_SYS_MODULE_PATH], [LT_SYS_MODULE_PATH($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:624: -1- AC_DEFUN([LT_SYS_DLSEARCH_PATH], [m4_require([_LT_SYS_DYNAMIC_LINKER])dnl +AC_CACHE_CHECK([for the default library search path], + [lt_cv_sys_dlsearch_path], + [lt_cv_sys_dlsearch_path=$sys_lib_dlsearch_path_spec]) +if test -n "$lt_cv_sys_dlsearch_path"; then + sys_dlsearch_path= + for dir in $lt_cv_sys_dlsearch_path; do + if test -z "$sys_dlsearch_path"; then + sys_dlsearch_path=$dir + else + sys_dlsearch_path=$sys_dlsearch_path$PATH_SEPARATOR$dir + fi + done + m4_pattern_allow([LT_DLSEARCH_PATH])dnl + AC_DEFINE_UNQUOTED([LT_DLSEARCH_PATH], ["$sys_dlsearch_path"], + [Define to the system default library search path.]) +fi +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:627: -1- AU_DEFUN([AC_LTDL_SYSSEARCHPATH], [m4_if($#, 0, [LT_SYS_DLSEARCH_PATH], [LT_SYS_DLSEARCH_PATH($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:627: -1- AC_DEFUN([AC_LTDL_SYSSEARCHPATH], [AC_DIAGNOSE([obsolete], [The macro `AC_LTDL_SYSSEARCHPATH' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_SYS_DLSEARCH_PATH], [LT_SYS_DLSEARCH_PATH($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:745: -1- AC_DEFUN([LT_LIB_DLLOAD], [m4_pattern_allow([^LT_DLLOADERS$]) +LT_DLLOADERS= +AC_SUBST([LT_DLLOADERS]) + +AC_LANG_PUSH([C]) +lt_dlload_save_LIBS=$LIBS + +LIBADD_DLOPEN= +AC_SEARCH_LIBS([dlopen], [dl], + [AC_DEFINE([HAVE_LIBDL], [1], + [Define if you have the libdl library or equivalent.]) + if test "$ac_cv_search_dlopen" != "none required"; then + LIBADD_DLOPEN=-ldl + fi + libltdl_cv_lib_dl_dlopen=yes + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dlopen.la"], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#if HAVE_DLFCN_H +# include +#endif + ]], [[dlopen(0, 0);]])], + [AC_DEFINE([HAVE_LIBDL], [1], + [Define if you have the libdl library or equivalent.]) + libltdl_cv_func_dlopen=yes + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dlopen.la"], + [AC_CHECK_LIB([svld], [dlopen], + [AC_DEFINE([HAVE_LIBDL], [1], + [Define if you have the libdl library or equivalent.]) + LIBADD_DLOPEN=-lsvld libltdl_cv_func_dlopen=yes + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dlopen.la"])])]) +if test yes = "$libltdl_cv_func_dlopen" || test yes = "$libltdl_cv_lib_dl_dlopen" +then + lt_save_LIBS=$LIBS + LIBS="$LIBS $LIBADD_DLOPEN" + AC_CHECK_FUNCS([dlerror]) + LIBS=$lt_save_LIBS +fi +AC_SUBST([LIBADD_DLOPEN]) + +LIBADD_SHL_LOAD= +AC_CHECK_FUNC([shl_load], + [AC_DEFINE([HAVE_SHL_LOAD], [1], + [Define if you have the shl_load function.]) + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}shl_load.la"], + [AC_CHECK_LIB([dld], [shl_load], + [AC_DEFINE([HAVE_SHL_LOAD], [1], + [Define if you have the shl_load function.]) + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}shl_load.la" + LIBADD_SHL_LOAD=-ldld])]) +AC_SUBST([LIBADD_SHL_LOAD]) + +case $host_os in +darwin[[1567]].*) +# We only want this for pre-Mac OS X 10.4. + AC_CHECK_FUNC([_dyld_func_lookup], + [AC_DEFINE([HAVE_DYLD], [1], + [Define if you have the _dyld_func_lookup function.]) + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dyld.la"]) + ;; +beos*) + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}load_add_on.la" + ;; +cygwin* | mingw* | pw32*) + AC_CHECK_DECLS([cygwin_conv_path], [], [], [[#include ]]) + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}loadlibrary.la" + ;; +esac + +AC_CHECK_LIB([dld], [dld_link], + [AC_DEFINE([HAVE_DLD], [1], + [Define if you have the GNU dld library.]) + LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dld_link.la"]) +AC_SUBST([LIBADD_DLD_LINK]) + +m4_pattern_allow([^LT_DLPREOPEN$]) +LT_DLPREOPEN= +if test -n "$LT_DLLOADERS" +then + for lt_loader in $LT_DLLOADERS; do + LT_DLPREOPEN="$LT_DLPREOPEN-dlpreopen $lt_loader " + done + AC_DEFINE([HAVE_LIBDLLOADER], [1], + [Define if libdlloader will be built on this platform]) +fi +AC_SUBST([LT_DLPREOPEN]) + +dnl This isn't used anymore, but set it for backwards compatibility +LIBADD_DL="$LIBADD_DLOPEN $LIBADD_SHL_LOAD" +AC_SUBST([LIBADD_DL]) + +LIBS=$lt_dlload_save_LIBS +AC_LANG_POP +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:748: -1- AU_DEFUN([AC_LTDL_DLLIB], [m4_if($#, 0, [LT_LIB_DLLOAD], [LT_LIB_DLLOAD($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:748: -1- AC_DEFUN([AC_LTDL_DLLIB], [AC_DIAGNOSE([obsolete], [The macro `AC_LTDL_DLLIB' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_LIB_DLLOAD], [LT_LIB_DLLOAD($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:790: -1- AC_DEFUN([LT_SYS_SYMBOL_USCORE], [m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +AC_CACHE_CHECK([for _ prefix in compiled symbols], + [lt_cv_sys_symbol_underscore], + [lt_cv_sys_symbol_underscore=no + cat > conftest.$ac_ext <<_LT_EOF +void nm_test_func(){} +int main(){nm_test_func;return 0;} +_LT_EOF + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + ac_nlist=conftest.nm + if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then + # See whether the symbols have a leading underscore. + if grep '^. _nm_test_func' "$ac_nlist" >/dev/null; then + lt_cv_sys_symbol_underscore=yes + else + if grep '^. nm_test_func ' "$ac_nlist" >/dev/null; then + : + else + echo "configure: cannot find nm_test_func in $ac_nlist" >&AS_MESSAGE_LOG_FD + fi + fi + else + echo "configure: cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.c >&AS_MESSAGE_LOG_FD + fi + rm -rf conftest* + ]) + sys_symbol_underscore=$lt_cv_sys_symbol_underscore + AC_SUBST([sys_symbol_underscore]) +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:793: -1- AU_DEFUN([AC_LTDL_SYMBOL_USCORE], [m4_if($#, 0, [LT_SYS_SYMBOL_USCORE], [LT_SYS_SYMBOL_USCORE($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:793: -1- AC_DEFUN([AC_LTDL_SYMBOL_USCORE], [AC_DIAGNOSE([obsolete], [The macro `AC_LTDL_SYMBOL_USCORE' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_SYS_SYMBOL_USCORE], [LT_SYS_SYMBOL_USCORE($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:904: -1- AC_DEFUN([LT_FUNC_DLSYM_USCORE], [AC_REQUIRE([_LT_COMPILER_PIC])dnl for lt_prog_compiler_wl +AC_REQUIRE([LT_SYS_SYMBOL_USCORE])dnl for lt_cv_sys_symbol_underscore +AC_REQUIRE([LT_SYS_MODULE_EXT])dnl for libltdl_cv_shlibext +if test yes = "$lt_cv_sys_symbol_underscore"; then + if test yes = "$libltdl_cv_func_dlopen" || test yes = "$libltdl_cv_lib_dl_dlopen"; then + AC_CACHE_CHECK([whether we have to add an underscore for dlsym], + [libltdl_cv_need_uscore], + [libltdl_cv_need_uscore=unknown + dlsym_uscore_save_LIBS=$LIBS + LIBS="$LIBS $LIBADD_DLOPEN" + libname=conftmod # stay within 8.3 filename limits! + cat >$libname.$ac_ext <<_LT_EOF +[#line $LINENO "configure" +#include "confdefs.h" +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif +int fnord () { return 42; }] +_LT_EOF + + # ltfn_module_cmds module_cmds + # Execute tilde-delimited MODULE_CMDS with environment primed for + # $module_cmds or $archive_cmds type content. + ltfn_module_cmds () + {( # subshell avoids polluting parent global environment + module_cmds_save_ifs=$IFS; IFS='~' + for cmd in @S|@1; do + IFS=$module_cmds_save_ifs + libobjs=$libname.$ac_objext; lib=$libname$libltdl_cv_shlibext + rpath=/not-exists; soname=$libname$libltdl_cv_shlibext; output_objdir=. + major=; versuffix=; verstring=; deplibs= + ECHO=echo; wl=$lt_prog_compiler_wl; allow_undefined_flag= + eval $cmd + done + IFS=$module_cmds_save_ifs + )} + + # Compile a loadable module using libtool macro expansion results. + $CC $pic_flag -c $libname.$ac_ext + ltfn_module_cmds "${module_cmds:-$archive_cmds}" + + # Try to fetch fnord with dlsym(). + libltdl_dlunknown=0; libltdl_dlnouscore=1; libltdl_dluscore=2 + cat >conftest.$ac_ext <<_LT_EOF +[#line $LINENO "configure" +#include "confdefs.h" +#if HAVE_DLFCN_H +#include +#endif +#include +#ifndef RTLD_GLOBAL +# ifdef DL_GLOBAL +# define RTLD_GLOBAL DL_GLOBAL +# else +# define RTLD_GLOBAL 0 +# endif +#endif +#ifndef RTLD_NOW +# ifdef DL_NOW +# define RTLD_NOW DL_NOW +# else +# define RTLD_NOW 0 +# endif +#endif +int main () { + void *handle = dlopen ("`pwd`/$libname$libltdl_cv_shlibext", RTLD_GLOBAL|RTLD_NOW); + int status = $libltdl_dlunknown; + if (handle) { + if (dlsym (handle, "fnord")) + status = $libltdl_dlnouscore; + else { + if (dlsym (handle, "_fnord")) + status = $libltdl_dluscore; + else + puts (dlerror ()); + } + dlclose (handle); + } else + puts (dlerror ()); + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + libltdl_status=$? + case x$libltdl_status in + x$libltdl_dlnouscore) libltdl_cv_need_uscore=no ;; + x$libltdl_dluscore) libltdl_cv_need_uscore=yes ;; + x*) libltdl_cv_need_uscore=unknown ;; + esac + fi + rm -rf conftest* $libname* + LIBS=$dlsym_uscore_save_LIBS + ]) + fi +fi + +if test yes = "$libltdl_cv_need_uscore"; then + AC_DEFINE([NEED_USCORE], [1], + [Define if dlsym() requires a leading underscore in symbol names.]) +fi +]) +m4trace:/usr/local/share/aclocal/ltdl.m4:907: -1- AU_DEFUN([AC_LTDL_DLSYM_USCORE], [m4_if($#, 0, [LT_FUNC_DLSYM_USCORE], [LT_FUNC_DLSYM_USCORE($@)])]) +m4trace:/usr/local/share/aclocal/ltdl.m4:907: -1- AC_DEFUN([AC_LTDL_DLSYM_USCORE], [AC_DIAGNOSE([obsolete], [The macro `AC_LTDL_DLSYM_USCORE' is obsolete. +You should run autoupdate.])dnl +m4_if($#, 0, [LT_FUNC_DLSYM_USCORE], [LT_FUNC_DLSYM_USCORE($@)])]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:14: -1- AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:118: -1- AU_DEFUN([AC_LIBTOOL_DLOPEN], [_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'dlopen' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:118: -1- AC_DEFUN([AC_LIBTOOL_DLOPEN], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_DLOPEN' is obsolete. +You should run autoupdate.])dnl +_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'dlopen' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:154: -1- AU_DEFUN([AC_LIBTOOL_WIN32_DLL], [AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'win32-dll' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:154: -1- AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_WIN32_DLL' is obsolete. +You should run autoupdate.])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'win32-dll' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:199: -1- AC_DEFUN([AC_ENABLE_SHARED], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:203: -1- AC_DEFUN([AC_DISABLE_SHARED], [_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:205: -1- AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:205: -1- AC_DEFUN([AM_ENABLE_SHARED], [AC_DIAGNOSE([obsolete], [The macro `AM_ENABLE_SHARED' is obsolete. +You should run autoupdate.])dnl +AC_ENABLE_SHARED($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:206: -1- AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:206: -1- AC_DEFUN([AM_DISABLE_SHARED], [AC_DIAGNOSE([obsolete], [The macro `AM_DISABLE_SHARED' is obsolete. +You should run autoupdate.])dnl +AC_DISABLE_SHARED($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:253: -1- AC_DEFUN([AC_ENABLE_STATIC], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:257: -1- AC_DEFUN([AC_DISABLE_STATIC], [_LT_SET_OPTION([LT_INIT], [disable-static]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:259: -1- AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:259: -1- AC_DEFUN([AM_ENABLE_STATIC], [AC_DIAGNOSE([obsolete], [The macro `AM_ENABLE_STATIC' is obsolete. +You should run autoupdate.])dnl +AC_ENABLE_STATIC($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:260: -1- AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:260: -1- AC_DEFUN([AM_DISABLE_STATIC], [AC_DIAGNOSE([obsolete], [The macro `AM_DISABLE_STATIC' is obsolete. +You should run autoupdate.])dnl +AC_DISABLE_STATIC($@)]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:310: -1- AU_DEFUN([AC_ENABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'fast-install' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:310: -1- AC_DEFUN([AC_ENABLE_FAST_INSTALL], [AC_DIAGNOSE([obsolete], [The macro `AC_ENABLE_FAST_INSTALL' is obsolete. +You should run autoupdate.])dnl +_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'fast-install' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:317: -1- AU_DEFUN([AC_DISABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'disable-fast-install' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:317: -1- AC_DEFUN([AC_DISABLE_FAST_INSTALL], [AC_DIAGNOSE([obsolete], [The macro `AC_DISABLE_FAST_INSTALL' is obsolete. +You should run autoupdate.])dnl +_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'disable-fast-install' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:416: -1- AU_DEFUN([AC_LIBTOOL_PICMODE], [_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'pic-only' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltoptions.m4:416: -1- AC_DEFUN([AC_LIBTOOL_PICMODE], [AC_DIAGNOSE([obsolete], [The macro `AC_LIBTOOL_PICMODE' is obsolete. +You should run autoupdate.])dnl +_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'pic-only' option into LT_INIT's first parameter.]) +]) +m4trace:/usr/local/share/aclocal/ltsugar.m4:14: -1- AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) +m4trace:/usr/local/share/aclocal/ltversion.m4:23: -1- AC_DEFUN([LTVERSION_VERSION], [macro_version='2.4.6' +macro_revision='2.4.6' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:37: -1- AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:41: -1- AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:42: -1- AC_DEFUN([_LT_AC_SHELL_INIT]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:43: -1- AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:45: -1- AC_DEFUN([_LT_AC_TAGVAR]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:46: -1- AC_DEFUN([AC_LTDL_ENABLE_INSTALL]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:47: -1- AC_DEFUN([AC_LTDL_PREOPEN]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:48: -1- AC_DEFUN([_LT_AC_SYS_COMPILER]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:49: -1- AC_DEFUN([_LT_AC_LOCK]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:50: -1- AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:51: -1- AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:52: -1- AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:53: -1- AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:54: -1- AC_DEFUN([AC_LIBTOOL_OBJDIR]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:55: -1- AC_DEFUN([AC_LTDL_OBJDIR]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:56: -1- AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:57: -1- AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:58: -1- AC_DEFUN([AC_PATH_MAGIC]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:59: -1- AC_DEFUN([AC_PROG_LD_GNU]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:60: -1- AC_DEFUN([AC_PROG_LD_RELOAD_FLAG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:61: -1- AC_DEFUN([AC_DEPLIBS_CHECK_METHOD]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:62: -1- AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:63: -1- AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:64: -1- AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:65: -1- AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:66: -1- AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:67: -1- AC_DEFUN([LT_AC_PROG_EGREP]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:72: -1- AC_DEFUN([_AC_PROG_LIBTOOL]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:73: -1- AC_DEFUN([AC_LIBTOOL_SETUP]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:74: -1- AC_DEFUN([_LT_AC_CHECK_DLFCN]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:75: -1- AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:76: -1- AC_DEFUN([_LT_AC_TAGCONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:78: -1- AC_DEFUN([_LT_AC_LANG_CXX]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:79: -1- AC_DEFUN([_LT_AC_LANG_F77]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:80: -1- AC_DEFUN([_LT_AC_LANG_GCJ]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:81: -1- AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:82: -1- AC_DEFUN([_LT_AC_LANG_C_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:83: -1- AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:84: -1- AC_DEFUN([_LT_AC_LANG_CXX_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:85: -1- AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:86: -1- AC_DEFUN([_LT_AC_LANG_F77_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:87: -1- AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:88: -1- AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:89: -1- AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:90: -1- AC_DEFUN([_LT_AC_LANG_RC_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:91: -1- AC_DEFUN([AC_LIBTOOL_CONFIG]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:92: -1- AC_DEFUN([_LT_AC_FILE_LTDLL_C]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:94: -1- AC_DEFUN([_LT_AC_PROG_CXXCPP]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:97: -1- AC_DEFUN([_LT_PROG_F77]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:98: -1- AC_DEFUN([_LT_PROG_FC]) +m4trace:/usr/local/share/aclocal/lt~obsolete.m4:99: -1- AC_DEFUN([_LT_PROG_CXX]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/amversion.m4:20: -1- AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.15' +dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to +dnl require some minimum version. Point them to the right macro. +m4_if([$1], [1.15], [], + [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/amversion.m4:37: -1- AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.15])dnl +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/auxdir.m4:51: -1- AC_DEFUN([AM_AUX_DIR_EXPAND], [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/cond.m4:32: -1- AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ([2.52])dnl + m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE])dnl +AC_SUBST([$1_FALSE])dnl +_AM_SUBST_NOTMAKE([$1_TRUE])dnl +_AM_SUBST_NOTMAKE([$1_FALSE])dnl +m4_define([_AM_COND_VALUE_$1], [$2])dnl +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/depend.m4:156: -1- AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], + [$1], [CXX], [depcc="$CXX" am_compiler_list=], + [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], + [$1], [UPC], [depcc="$UPC" am_compiler_list=], + [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + am__universal=false + m4_case([$1], [CC], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac], + [CXX], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac]) + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/depend.m4:166: -1- AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/depend.m4:189: -1- AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE([dependency-tracking], [dnl +AS_HELP_STRING( + [--enable-dependency-tracking], + [do not reject slow dependency extractors]) +AS_HELP_STRING( + [--disable-dependency-tracking], + [speeds up one-time build])]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' + am__nodep='_no' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH])dnl +_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl +AC_SUBST([am__nodep])dnl +_AM_SUBST_NOTMAKE([am__nodep])dnl +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/depout.m4:61: -1- AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [{ + # Older Autoconf quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named 'Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running 'make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "$am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/depout.m4:75: -1- AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/init.m4:171: -1- AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.65])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[AC_DIAGNOSE([obsolete], + [$0: two- and three-arguments forms are deprecated.]) +m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl +dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. +m4_if( + m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), + [ok:ok],, + [m4_fatal([AC_INIT should be called with package and version arguments])])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) + AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) +AM_MISSING_PROG([AUTOCONF], [autoconf]) +AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) +AM_MISSING_PROG([AUTOHEADER], [autoheader]) +AM_MISSING_PROG([MAKEINFO], [makeinfo]) +AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +AC_SUBST([mkdir_p], ['$(MKDIR_P)']) +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES([CC])], + [m4_define([AC_PROG_CC], + m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES([CXX])], + [m4_define([AC_PROG_CXX], + m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJC], + [_AM_DEPENDENCIES([OBJC])], + [m4_define([AC_PROG_OBJC], + m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], + [_AM_DEPENDENCIES([OBJCXX])], + [m4_define([AC_PROG_OBJCXX], + m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl +]) +AC_REQUIRE([AM_SILENT_RULES])dnl +dnl The testsuite driver may need to know about EXEEXT, so add the +dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This +dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below. +AC_CONFIG_COMMANDS_PRE(dnl +[m4_provide_if([_AM_COMPILER_EXEEXT], + [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) + fi +fi +dnl The trailing newline in this macro's definition is deliberate, for +dnl backward compatibility and to allow trailing 'dnl'-style comments +dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/init.m4:198: -1- AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers. +_am_arg=$1 +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/install-sh.m4:21: -1- AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +if test x"${install_sh+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi +AC_SUBST([install_sh])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/lead-dot.m4:19: -1- AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/make.m4:49: -1- AC_DEFUN([AM_MAKE_INCLUDE], [am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from 'make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/missing.m4:14: -1- AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/missing.m4:38: -1- AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([missing])dnl +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --is-lightweight"; then + am_missing_run="$MISSING " +else + am_missing_run= + AC_MSG_WARN(['missing' script is too old or missing]) +fi +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/options.m4:12: -1- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/options.m4:18: -1- AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), [1])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/options.m4:24: -1- AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/options.m4:30: -1- AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/prog-cc-c-o.m4:44: -1- AC_DEFUN([_AM_PROG_CC_C_O], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([compile])dnl +AC_LANG_PUSH([C])dnl +AC_CACHE_CHECK( + [whether $CC understands -c and -o together], + [am_cv_prog_cc_c_o], + [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])]) + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i]) +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +AC_LANG_POP([C])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/prog-cc-c-o.m4:47: -1- AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/runlog.m4:17: -1- AC_DEFUN([AM_RUN_LOG], [{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD + ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + (exit $ac_status); }]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/sanity.m4:82: -1- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[[\\\"\#\$\&\'\`$am_lf]]*) + AC_MSG_ERROR([unsafe absolute working directory name]);; +esac +case $srcdir in + *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) + AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; +esac + +# Do 'set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken + alias in your environment]) + fi + if test "$[2]" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT([yes]) +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi +AC_CONFIG_COMMANDS_PRE( + [AC_MSG_CHECKING([that generated files are newer than configure]) + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + AC_MSG_RESULT([done])]) +rm -f conftest.file +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/silent.m4:60: -1- AC_DEFUN([AM_SILENT_RULES], [AC_ARG_ENABLE([silent-rules], [dnl +AS_HELP_STRING( + [--enable-silent-rules], + [less verbose build output (undo: "make V=1")]) +AS_HELP_STRING( + [--disable-silent-rules], + [verbose build output (undo: "make V=0")])dnl +]) +case $enable_silent_rules in @%:@ ((( + yes) AM_DEFAULT_VERBOSITY=0;; + no) AM_DEFAULT_VERBOSITY=1;; + *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);; +esac +dnl +dnl A few 'make' implementations (e.g., NonStop OS and NextStep) +dnl do not support nested variable expansions. +dnl See automake bug#9928 and bug#10237. +am_make=${MAKE-make} +AC_CACHE_CHECK([whether $am_make supports nested variables], + [am_cv_make_support_nested_variables], + [if AS_ECHO([['TRUE=$(BAR$(V)) +BAR0=false +BAR1=true +V=1 +am__doit: + @$(TRUE) +.PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then + am_cv_make_support_nested_variables=yes +else + am_cv_make_support_nested_variables=no +fi]) +if test $am_cv_make_support_nested_variables = yes; then + dnl Using '$V' instead of '$(V)' breaks IRIX make. + AM_V='$(V)' + AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' +else + AM_V=$AM_DEFAULT_VERBOSITY + AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY +fi +AC_SUBST([AM_V])dnl +AM_SUBST_NOTMAKE([AM_V])dnl +AC_SUBST([AM_DEFAULT_V])dnl +AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl +AC_SUBST([AM_DEFAULT_VERBOSITY])dnl +AM_BACKSLASH='\' +AC_SUBST([AM_BACKSLASH])dnl +_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl +]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/strip.m4:28: -1- AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the 'STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/substnot.m4:12: -1- AC_DEFUN([_AM_SUBST_NOTMAKE]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/substnot.m4:17: -1- AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) +m4trace:/usr/local/Cellar/automake/1.15/share/aclocal-1.15/tar.m4:132: -1- AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility. Yes, it's still used +# in the wild :-( We should find a proper way to deprecate it ... +AC_SUBST([AMTAR], ['$${TAR-tar}']) + +# We'll loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' + +m4_if([$1], [v7], + [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], + + [m4_case([$1], + [ustar], + [# The POSIX 1988 'ustar' format is defined with fixed-size fields. + # There is notably a 21 bits limit for the UID and the GID. In fact, + # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343 + # and bug#13588). + am_max_uid=2097151 # 2^21 - 1 + am_max_gid=$am_max_uid + # The $UID and $GID variables are not portable, so we need to resort + # to the POSIX-mandated id(1) utility. Errors in the 'id' calls + # below are definitely unexpected, so allow the users to see them + # (that is, avoid stderr redirection). + am_uid=`id -u || echo unknown` + am_gid=`id -g || echo unknown` + AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format]) + if test $am_uid -le $am_max_uid; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + _am_tools=none + fi + AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format]) + if test $am_gid -le $am_max_gid; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + _am_tools=none + fi], + + [pax], + [], + + [m4_fatal([Unknown tar format])]) + + AC_MSG_CHECKING([how to create a $1 tar archive]) + + # Go ahead even if we have the value already cached. We do so because we + # need to set the values for the 'am__tar' and 'am__untar' variables. + _am_tools=${am_cv_prog_tar_$1-$_am_tools} + + for _am_tool in $_am_tools; do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works. + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi + done + rm -rf conftest.dir + + AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) + AC_MSG_RESULT([$am_cv_prog_tar_$1])]) + +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) +m4trace:acinclude.m4:43: -1- AC_DEFUN([DX_FEATURE_doc], [ON]) +m4trace:acinclude.m4:44: -1- AC_DEFUN([DX_FEATURE_dot], [ON]) +m4trace:acinclude.m4:45: -1- AC_DEFUN([DX_FEATURE_man], [OFF]) +m4trace:acinclude.m4:46: -1- AC_DEFUN([DX_FEATURE_html], [ON]) +m4trace:acinclude.m4:47: -1- AC_DEFUN([DX_FEATURE_chm], [OFF]) +m4trace:acinclude.m4:48: -1- AC_DEFUN([DX_FEATURE_chi], [OFF]) +m4trace:acinclude.m4:49: -1- AC_DEFUN([DX_FEATURE_rtf], [OFF]) +m4trace:acinclude.m4:50: -1- AC_DEFUN([DX_FEATURE_xml], [OFF]) +m4trace:acinclude.m4:51: -1- AC_DEFUN([DX_FEATURE_pdf], [ON]) +m4trace:acinclude.m4:52: -1- AC_DEFUN([DX_FEATURE_ps], [ON]) +m4trace:acinclude.m4:61: -1- AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])]) +m4trace:acinclude.m4:67: -1- AC_DEFUN([DX_DIRNAME_EXPR], [[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']]) +m4trace:acinclude.m4:72: -1- AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])]) +m4trace:acinclude.m4:83: -1- AC_DEFUN([DX_REQUIRE_PROG], [ +AC_PATH_TOOL([$1], [$2]) +if test "$DX_FLAG_$[DX_CURRENT_FEATURE$$1]" = 1; then + AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION]) + AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +fi +]) +m4trace:acinclude.m4:88: -1- AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1]) +m4trace:acinclude.m4:98: -1- AC_DEFUN([DX_CHECK_DEPEND], [ +test "$DX_FLAG_$1" = "$2" \ +|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1, + requires, contradicts) doxygen-DX_CURRENT_FEATURE]) +]) +m4trace:acinclude.m4:105: -1- AC_DEFUN([DX_CLEAR_DEPEND], [ +test "$DX_FLAG_$1" = "$2" || AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +]) +m4trace:acinclude.m4:155: -1- AC_DEFUN([DX_ARG_ABLE], [ + AC_DEFUN([DX_CURRENT_FEATURE], [$1]) + AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2]) + AC_ARG_ENABLE(doxygen-$1, + [AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1], + [--enable-doxygen-$1]), + DX_IF_FEATURE([$1], [don't $2], [$2]))], + [ +case "$enableval" in +#( +y|Y|yes|Yes|YES) + AC_SUBST([DX_FLAG_$1], 1) + $3 +;; #( +n|N|no|No|NO) + AC_SUBST([DX_FLAG_$1], 0) +;; #( +*) + AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1]) +;; +esac +], [ +AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)]) +$4 +]) +if DX_TEST_FEATURE([$1]); then + $5 + : +fi +if DX_TEST_FEATURE([$1]); then + AM_CONDITIONAL(DX_COND_$1, :) + $6 + : +else + AM_CONDITIONAL(DX_COND_$1, false) + $7 + : +fi +]) +m4trace:acinclude.m4:163: -1- AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])]) +m4trace:acinclude.m4:164: -1- AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])]) +m4trace:acinclude.m4:165: -1- AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])]) +m4trace:acinclude.m4:166: -1- AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])]) +m4trace:acinclude.m4:167: -1- AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])]) +m4trace:acinclude.m4:168: -1- AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])]) +m4trace:acinclude.m4:169: -1- AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +m4trace:acinclude.m4:170: -1- AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +m4trace:acinclude.m4:171: -1- AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])]) +m4trace:acinclude.m4:172: -1- AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])]) +m4trace:acinclude.m4:312: -1- AC_DEFUN([DX_INIT_DOXYGEN], [ + +# Files: +AC_SUBST([DX_PROJECT], [$1]) +AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])]) +AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])]) + +# Environment variables used inside doxygen.cfg: +DX_ENV_APPEND(SRCDIR, $srcdir) +DX_ENV_APPEND(PROJECT, $DX_PROJECT) +DX_ENV_APPEND(DOCDIR, $DX_DOCDIR) +DX_ENV_APPEND(VERSION, $PACKAGE_VERSION) + +# Doxygen itself: +DX_ARG_ABLE(doc, [generate any doxygen documentation], + [], + [], + [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen) + DX_REQUIRE_PROG([DX_PERL], perl)], + [DX_ENV_APPEND(PERL_PATH, $DX_PERL)]) + +# Dot for graphics: +DX_ARG_ABLE(dot, [generate graphics for doxygen documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_DOT], dot)], + [DX_ENV_APPEND(HAVE_DOT, YES) + DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])], + [DX_ENV_APPEND(HAVE_DOT, NO)]) + +# Man pages generation: +DX_ARG_ABLE(man, [generate doxygen manual pages], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_MAN, YES)], + [DX_ENV_APPEND(GENERATE_MAN, NO)]) + +# RTF file generation: +DX_ARG_ABLE(rtf, [generate doxygen RTF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_RTF, YES)], + [DX_ENV_APPEND(GENERATE_RTF, NO)]) + +# XML file generation: +DX_ARG_ABLE(xml, [generate doxygen XML documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_XML, YES)], + [DX_ENV_APPEND(GENERATE_XML, NO)]) + +# (Compressed) HTML help generation: +DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_HHC], hhc)], + [DX_ENV_APPEND(HHC_PATH, $DX_HHC) + DX_ENV_APPEND(GENERATE_HTML, YES) + DX_ENV_APPEND(GENERATE_HTMLHELP, YES)], + [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)]) + +# Seperate CHI file generation. +DX_ARG_ABLE(chi, [generate doxygen seperate compressed HTML help index file], + [DX_CHECK_DEPEND(chm, 1)], + [DX_CLEAR_DEPEND(chm, 1)], + [], + [DX_ENV_APPEND(GENERATE_CHI, YES)], + [DX_ENV_APPEND(GENERATE_CHI, NO)]) + +# Plain HTML pages generation: +DX_ARG_ABLE(html, [generate doxygen plain HTML documentation], + [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)], + [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)], + [], + [DX_ENV_APPEND(GENERATE_HTML, YES)], + [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)]) + +# PostScript file generation: +DX_ARG_ABLE(ps, [generate doxygen PostScript documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_LATEX], latex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_DVIPS], dvips) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# PDF file generation: +DX_ARG_ABLE(pdf, [generate doxygen PDF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# LaTeX generation for PS and/or PDF: +if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then + AM_CONDITIONAL(DX_COND_latex, :) + DX_ENV_APPEND(GENERATE_LATEX, YES) +else + AM_CONDITIONAL(DX_COND_latex, false) + DX_ENV_APPEND(GENERATE_LATEX, NO) +fi + +# Paper size for PS and/or PDF: +AC_ARG_VAR(DOXYGEN_PAPER_SIZE, + [a4wide (default), a4, letter, legal or executive]) +case "$DOXYGEN_PAPER_SIZE" in +#( +"") + AC_SUBST(DOXYGEN_PAPER_SIZE, "") +;; #( +a4wide|a4|letter|legal|executive) + DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE) +;; #( +*) + AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE']) +;; +esac + +#For debugging: +#echo DX_FLAG_doc=$DX_FLAG_doc +#echo DX_FLAG_dot=$DX_FLAG_dot +#echo DX_FLAG_man=$DX_FLAG_man +#echo DX_FLAG_html=$DX_FLAG_html +#echo DX_FLAG_chm=$DX_FLAG_chm +#echo DX_FLAG_chi=$DX_FLAG_chi +#echo DX_FLAG_rtf=$DX_FLAG_rtf +#echo DX_FLAG_xml=$DX_FLAG_xml +#echo DX_FLAG_pdf=$DX_FLAG_pdf +#echo DX_FLAG_ps=$DX_FLAG_ps +#echo DX_ENV=$DX_ENV +]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^_?A[CHUM]_]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([_AC_]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^LIBOBJS$], [do not use LIBOBJS directly, use AC_LIBOBJ (see section `AC_LIBOBJ vs LIBOBJS']) +m4trace:configure.ac:6: -1- m4_pattern_allow([^AS_FLAGS$]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^_?m4_]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^dnl$]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^_?AS_]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^SHELL$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PATH_SEPARATOR$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_NAME$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_VERSION$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_STRING$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_URL$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^exec_prefix$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^prefix$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^program_transform_name$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^bindir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^sbindir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^libexecdir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^datarootdir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^datadir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^sysconfdir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^sharedstatedir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^localstatedir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^includedir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^oldincludedir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^docdir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^infodir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^htmldir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^dvidir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^pdfdir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^psdir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^libdir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^localedir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^mandir$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_NAME$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_VERSION$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_STRING$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_URL$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^DEFS$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^ECHO_C$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^ECHO_N$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^ECHO_T$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^LIBS$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^build_alias$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^host_alias$]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^target_alias$]) +m4trace:configure.ac:14: -1- DX_HTML_FEATURE([ON]) +m4trace:configure.ac:14: -1- AC_DEFUN([DX_FEATURE_html], [ON]) +m4trace:configure.ac:15: -1- DX_CHM_FEATURE([OFF]) +m4trace:configure.ac:15: -1- AC_DEFUN([DX_FEATURE_chm], [OFF]) +m4trace:configure.ac:16: -1- DX_CHI_FEATURE([OFF]) +m4trace:configure.ac:16: -1- AC_DEFUN([DX_FEATURE_chi], [OFF]) +m4trace:configure.ac:17: -1- DX_MAN_FEATURE([OFF]) +m4trace:configure.ac:17: -1- AC_DEFUN([DX_FEATURE_man], [OFF]) +m4trace:configure.ac:18: -1- DX_RTF_FEATURE([OFF]) +m4trace:configure.ac:18: -1- AC_DEFUN([DX_FEATURE_rtf], [OFF]) +m4trace:configure.ac:19: -1- DX_XML_FEATURE([OFF]) +m4trace:configure.ac:19: -1- AC_DEFUN([DX_FEATURE_xml], [OFF]) +m4trace:configure.ac:20: -1- DX_PDF_FEATURE([OFF]) +m4trace:configure.ac:20: -1- AC_DEFUN([DX_FEATURE_pdf], [OFF]) +m4trace:configure.ac:21: -1- DX_PS_FEATURE([OFF]) +m4trace:configure.ac:21: -1- AC_DEFUN([DX_FEATURE_ps], [OFF]) +m4trace:configure.ac:22: -1- DX_INIT_DOXYGEN([zookeeper], [c-doc.Doxyfile], [docs]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_PROJECT$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_CONFIG$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DOCDIR$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([SRCDIR], [$srcdir]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([PROJECT], [$DX_PROJECT]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([DOCDIR], [$DX_DOCDIR]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([VERSION], [$PACKAGE_VERSION]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([doc], [generate any doxygen documentation], [], [], [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen) + DX_REQUIRE_PROG([DX_PERL], perl)], [DX_ENV_APPEND(PERL_PATH, $DX_PERL)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [doc]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate any doxygen documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([doc], [--disable-doxygen-doc], [--enable-doxygen-doc]) +m4trace:configure.ac:22: -3- DX_FEATURE_doc +m4trace:configure.ac:22: -2- DX_IF_FEATURE([doc], [don't generate any doxygen documentation], [generate any doxygen documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_doc +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([doc], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_doc +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([doc]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_DOXYGEN], [doxygen]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DOXYGEN$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_PERL], [perl]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_PERL$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([doc]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_doc], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([PERL_PATH], [$DX_PERL]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_doc], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([dot], [generate graphics for doxygen documentation], [DX_CHECK_DEPEND(doc, 1)], [DX_CLEAR_DEPEND(doc, 1)], [DX_REQUIRE_PROG([DX_DOT], dot)], [DX_ENV_APPEND(HAVE_DOT, YES) + DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])], [DX_ENV_APPEND(HAVE_DOT, NO)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [dot]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate graphics for doxygen documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([dot], [--disable-doxygen-dot], [--enable-doxygen-dot]) +m4trace:configure.ac:22: -3- DX_FEATURE_dot +m4trace:configure.ac:22: -2- DX_IF_FEATURE([dot], [don't generate graphics for doxygen documentation], [generate graphics for doxygen documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_dot +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([dot], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_dot +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([dot]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_DOT], [dot]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DOT$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([dot]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_dot], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([HAVE_DOT], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([DOT_PATH], [`DX_DIRNAME_EXPR($DX_DOT)`]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_DIRNAME_EXPR([$DX_DOT]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_dot], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([HAVE_DOT], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([man], [generate doxygen manual pages], [DX_CHECK_DEPEND(doc, 1)], [DX_CLEAR_DEPEND(doc, 1)], [], [DX_ENV_APPEND(GENERATE_MAN, YES)], [DX_ENV_APPEND(GENERATE_MAN, NO)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [man]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen manual pages]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([man], [--disable-doxygen-man], [--enable-doxygen-man]) +m4trace:configure.ac:22: -3- DX_FEATURE_man +m4trace:configure.ac:22: -2- DX_IF_FEATURE([man], [don't generate doxygen manual pages], [generate doxygen manual pages]) +m4trace:configure.ac:22: -3- DX_FEATURE_man +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([man], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_man +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([man]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([man]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_man], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_MAN], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_man], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_MAN], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([rtf], [generate doxygen RTF documentation], [DX_CHECK_DEPEND(doc, 1)], [DX_CLEAR_DEPEND(doc, 1)], [], [DX_ENV_APPEND(GENERATE_RTF, YES)], [DX_ENV_APPEND(GENERATE_RTF, NO)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [rtf]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen RTF documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([rtf], [--disable-doxygen-rtf], [--enable-doxygen-rtf]) +m4trace:configure.ac:22: -3- DX_FEATURE_rtf +m4trace:configure.ac:22: -2- DX_IF_FEATURE([rtf], [don't generate doxygen RTF documentation], [generate doxygen RTF documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_rtf +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([rtf], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_rtf +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([rtf]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([rtf]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_rtf], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_RTF], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_rtf], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_RTF], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([xml], [generate doxygen XML documentation], [DX_CHECK_DEPEND(doc, 1)], [DX_CLEAR_DEPEND(doc, 1)], [], [DX_ENV_APPEND(GENERATE_XML, YES)], [DX_ENV_APPEND(GENERATE_XML, NO)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [xml]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen XML documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([xml], [--disable-doxygen-xml], [--enable-doxygen-xml]) +m4trace:configure.ac:22: -3- DX_FEATURE_xml +m4trace:configure.ac:22: -2- DX_IF_FEATURE([xml], [don't generate doxygen XML documentation], [generate doxygen XML documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_xml +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([xml], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_xml +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([xml]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([xml]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_xml], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_XML], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_xml], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_XML], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([chm], [generate doxygen compressed HTML help documentation], [DX_CHECK_DEPEND(doc, 1)], [DX_CLEAR_DEPEND(doc, 1)], [DX_REQUIRE_PROG([DX_HHC], hhc)], [DX_ENV_APPEND(HHC_PATH, $DX_HHC) + DX_ENV_APPEND(GENERATE_HTML, YES) + DX_ENV_APPEND(GENERATE_HTMLHELP, YES)], [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [chm]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen compressed HTML help documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([chm], [--disable-doxygen-chm], [--enable-doxygen-chm]) +m4trace:configure.ac:22: -3- DX_FEATURE_chm +m4trace:configure.ac:22: -2- DX_IF_FEATURE([chm], [don't generate doxygen compressed HTML help documentation], [generate doxygen compressed HTML help documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_chm +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([chm], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_chm +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([chm]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_HHC], [hhc]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_HHC$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([chm]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chm], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([HHC_PATH], [$DX_HHC]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_HTML], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_HTMLHELP], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chm], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_HTMLHELP], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([chi], [generate doxygen seperate compressed HTML help index file], [DX_CHECK_DEPEND(chm, 1)], [DX_CLEAR_DEPEND(chm, 1)], [], [DX_ENV_APPEND(GENERATE_CHI, YES)], [DX_ENV_APPEND(GENERATE_CHI, NO)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [chi]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen seperate compressed HTML help index file]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([chi], [--disable-doxygen-chi], [--enable-doxygen-chi]) +m4trace:configure.ac:22: -3- DX_FEATURE_chi +m4trace:configure.ac:22: -2- DX_IF_FEATURE([chi], [don't generate doxygen seperate compressed HTML help index file], [generate doxygen seperate compressed HTML help index file]) +m4trace:configure.ac:22: -3- DX_FEATURE_chi +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([chm], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([chi], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_chi +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([chm], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([chi]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([chi]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chi], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_CHI], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chi], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_CHI], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([html], [generate doxygen plain HTML documentation], [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)], [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)], [], [DX_ENV_APPEND(GENERATE_HTML, YES)], [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [html]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen plain HTML documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([html], [--disable-doxygen-html], [--enable-doxygen-html]) +m4trace:configure.ac:22: -3- DX_FEATURE_html +m4trace:configure.ac:22: -2- DX_IF_FEATURE([html], [don't generate doxygen plain HTML documentation], [generate doxygen plain HTML documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_html +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([chm], [0]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([html], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_html +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([chm], [0]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([html]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([html]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_html], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_HTML], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_html], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([chm]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_HTML], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([ps], [generate doxygen PostScript documentation], [DX_CHECK_DEPEND(doc, 1)], [DX_CLEAR_DEPEND(doc, 1)], [DX_REQUIRE_PROG([DX_LATEX], latex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_DVIPS], dvips) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [ps]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen PostScript documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([ps], [--disable-doxygen-ps], [--enable-doxygen-ps]) +m4trace:configure.ac:22: -3- DX_FEATURE_ps +m4trace:configure.ac:22: -2- DX_IF_FEATURE([ps], [don't generate doxygen PostScript documentation], [generate doxygen PostScript documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_ps +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([ps], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_ps +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([ps]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_LATEX], [latex]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_LATEX$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_MAKEINDEX], [makeindex]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_MAKEINDEX$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_DVIPS], [dvips]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DVIPS$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_EGREP], [egrep]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_EGREP$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([ps]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_ps], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_ps], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- DX_ARG_ABLE([pdf], [generate doxygen PDF documentation], [DX_CHECK_DEPEND(doc, 1)], [DX_CLEAR_DEPEND(doc, 1)], [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_FEATURE], [pdf]) +m4trace:configure.ac:22: -1- AC_DEFUN([DX_CURRENT_DESCRIPTION], [generate doxygen PDF documentation]) +m4trace:configure.ac:22: -2- DX_IF_FEATURE([pdf], [--disable-doxygen-pdf], [--enable-doxygen-pdf]) +m4trace:configure.ac:22: -3- DX_FEATURE_pdf +m4trace:configure.ac:22: -2- DX_IF_FEATURE([pdf], [don't generate doxygen PDF documentation], [generate doxygen PDF documentation]) +m4trace:configure.ac:22: -3- DX_FEATURE_pdf +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- DX_CHECK_DEPEND([doc], [1]) +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- DX_IF_FEATURE([pdf], [1], [0]) +m4trace:configure.ac:22: -2- DX_FEATURE_pdf +m4trace:configure.ac:22: -1- DX_CLEAR_DEPEND([doc], [1]) +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([pdf]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_PDFLATEX], [pdflatex]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_PDFLATEX$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_MAKEINDEX], [makeindex]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_MAKEINDEX$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- DX_REQUIRE_PROG([DX_EGREP], [egrep]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_EGREP$]) +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -1- DX_CURRENT_DESCRIPTION +m4trace:configure.ac:22: -2- DX_CURRENT_FEATURE +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([pdf]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_pdf], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_pdf], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([ps]) +m4trace:configure.ac:22: -1- DX_TEST_FEATURE([pdf]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_latex], [:]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_LATEX], [YES]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_latex], [false]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_TRUE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([GENERATE_LATEX], [NO]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DOXYGEN_PAPER_SIZE$]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DOXYGEN_PAPER_SIZE$]) +m4trace:configure.ac:22: -1- DX_ENV_APPEND([PAPER_SIZE], [$DOXYGEN_PAPER_SIZE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:25: -1- AM_INIT_AUTOMAKE([-Wall foreign]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_[A-Z]+FLAGS$]) +m4trace:configure.ac:25: -1- AM_SET_CURRENT_AUTOMAKE_VERSION +m4trace:configure.ac:25: -1- AM_AUTOMAKE_VERSION([1.15]) +m4trace:configure.ac:25: -1- _AM_AUTOCONF_VERSION([2.69]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_PROGRAM$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_SCRIPT$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_DATA$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__isrc$]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([am__isrc]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^CYGPATH_W$]) +m4trace:configure.ac:25: -1- _AM_SET_OPTIONS([-Wall foreign]) +m4trace:configure.ac:25: -1- _AM_SET_OPTION([-Wall]) +m4trace:configure.ac:25: -2- _AM_MANGLE_OPTION([-Wall]) +m4trace:configure.ac:25: -1- _AM_SET_OPTION([foreign]) +m4trace:configure.ac:25: -2- _AM_MANGLE_OPTION([foreign]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^PACKAGE$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^VERSION$]) +m4trace:configure.ac:25: -1- _AM_IF_OPTION([no-define], [], [AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) + AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])]) +m4trace:configure.ac:25: -2- _AM_MANGLE_OPTION([no-define]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^PACKAGE$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^VERSION$]) +m4trace:configure.ac:25: -1- AM_SANITY_CHECK +m4trace:configure.ac:25: -1- AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) +m4trace:configure.ac:25: -1- AM_MISSING_HAS_RUN +m4trace:configure.ac:25: -1- AM_AUX_DIR_EXPAND +m4trace:configure.ac:25: -1- m4_pattern_allow([^ACLOCAL$]) +m4trace:configure.ac:25: -1- AM_MISSING_PROG([AUTOCONF], [autoconf]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AUTOCONF$]) +m4trace:configure.ac:25: -1- AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AUTOMAKE$]) +m4trace:configure.ac:25: -1- AM_MISSING_PROG([AUTOHEADER], [autoheader]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AUTOHEADER$]) +m4trace:configure.ac:25: -1- AM_MISSING_PROG([MAKEINFO], [makeinfo]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^MAKEINFO$]) +m4trace:configure.ac:25: -1- AM_PROG_INSTALL_SH +m4trace:configure.ac:25: -1- m4_pattern_allow([^install_sh$]) +m4trace:configure.ac:25: -1- AM_PROG_INSTALL_STRIP +m4trace:configure.ac:25: -1- m4_pattern_allow([^STRIP$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_STRIP_PROGRAM$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^MKDIR_P$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^mkdir_p$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AWK$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^SET_MAKE$]) +m4trace:configure.ac:25: -1- AM_SET_LEADING_DOT +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__leading_dot$]) +m4trace:configure.ac:25: -1- _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +m4trace:configure.ac:25: -2- _AM_MANGLE_OPTION([tar-ustar]) +m4trace:configure.ac:25: -1- _AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_PROG_TAR([v7])]) +m4trace:configure.ac:25: -2- _AM_MANGLE_OPTION([tar-pax]) +m4trace:configure.ac:25: -1- _AM_PROG_TAR([v7]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AMTAR$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__tar$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__untar$]) +m4trace:configure.ac:25: -1- _AM_IF_OPTION([no-dependencies], [], [AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES([CC])], + [m4_define([AC_PROG_CC], + m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES([CXX])], + [m4_define([AC_PROG_CXX], + m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJC], + [_AM_DEPENDENCIES([OBJC])], + [m4_define([AC_PROG_OBJC], + m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], + [_AM_DEPENDENCIES([OBJCXX])], + [m4_define([AC_PROG_OBJCXX], + m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl +]) +m4trace:configure.ac:25: -2- _AM_MANGLE_OPTION([no-dependencies]) +m4trace:configure.ac:25: -1- AM_SILENT_RULES +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_V$]) +m4trace:configure.ac:25: -1- AM_SUBST_NOTMAKE([AM_V]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([AM_V]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_DEFAULT_V$]) +m4trace:configure.ac:25: -1- AM_SUBST_NOTMAKE([AM_DEFAULT_V]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([AM_DEFAULT_V]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_DEFAULT_VERBOSITY$]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_BACKSLASH$]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([AM_BACKSLASH]) +m4trace:configure.ac:46: -1- _m4_warn([cross], [cannot check for file existence when cross compiling], [../../lib/autoconf/general.m4:2791: AC_CHECK_FILE is expanded from... +../../lib/autoconf/general.m4:2809: AC_CHECK_FILES is expanded from... +configure.ac:46: the top level]) +m4trace:configure.ac:46: -1- m4_pattern_allow([^HAVE_GENERATED_ZOOKEEPER_JUTE_C$]) +m4trace:configure.ac:46: -1- _m4_warn([cross], [cannot check for file existence when cross compiling], [../../lib/autoconf/general.m4:2791: AC_CHECK_FILE is expanded from... +../../lib/autoconf/general.m4:2809: AC_CHECK_FILES is expanded from... +configure.ac:46: the top level]) +m4trace:configure.ac:46: -1- m4_pattern_allow([^HAVE_GENERATED_ZOOKEEPER_JUTE_H$]) +m4trace:configure.ac:48: -1- m4_pattern_allow([^CPPUNIT_CFLAGS$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CFLAGS$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^LDFLAGS$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^LIBS$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^ac_ct_CC$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^EXEEXT$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^OBJEXT$]) +m4trace:configure.ac:50: -1- _AM_PROG_CC_C_O +m4trace:configure.ac:50: -1- AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) +m4trace:configure.ac:50: -1- _AM_DEPENDENCIES([CC]) +m4trace:configure.ac:50: -1- AM_SET_DEPDIR +m4trace:configure.ac:50: -1- m4_pattern_allow([^DEPDIR$]) +m4trace:configure.ac:50: -1- AM_OUTPUT_DEPENDENCY_COMMANDS +m4trace:configure.ac:50: -1- AM_MAKE_INCLUDE +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__include$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__quote$]) +m4trace:configure.ac:50: -1- AM_DEP_TRACK +m4trace:configure.ac:50: -1- AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^AMDEP_TRUE$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^AMDEP_FALSE$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([AMDEP_TRUE]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([AMDEP_FALSE]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^AMDEPBACKSLASH$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([AMDEPBACKSLASH]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__nodep$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([am__nodep]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CCDEPMODE$]) +m4trace:configure.ac:50: -1- AM_CONDITIONAL([am__fastdepCC], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__fastdepCC_TRUE$]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__fastdepCC_FALSE$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([am__fastdepCC_TRUE]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([am__fastdepCC_FALSE]) +m4trace:configure.ac:51: -1- AM_PROG_CC_C_O +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXX$]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXXFLAGS$]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^LDFLAGS$]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^LIBS$]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXX$]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^ac_ct_CXX$]) +m4trace:configure.ac:52: -1- _AM_DEPENDENCIES([CXX]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXXDEPMODE$]) +m4trace:configure.ac:52: -1- AM_CONDITIONAL([am__fastdepCXX], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CXX_dependencies_compiler_type" = gcc3]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^am__fastdepCXX_TRUE$]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^am__fastdepCXX_FALSE$]) +m4trace:configure.ac:52: -1- _AM_SUBST_NOTMAKE([am__fastdepCXX_TRUE]) +m4trace:configure.ac:52: -1- _AM_SUBST_NOTMAKE([am__fastdepCXX_FALSE]) +m4trace:configure.ac:54: -1- m4_pattern_allow([^LN_S$]) +m4trace:configure.ac:57: -1- AC_PROG_LIBTOOL +m4trace:configure.ac:57: -1- _m4_warn([obsolete], [The macro `AC_PROG_LIBTOOL' is obsolete. +You should run autoupdate.], [/usr/local/share/aclocal/libtool.m4:99: AC_PROG_LIBTOOL is expanded from... +configure.ac:57: the top level]) +m4trace:configure.ac:57: -1- LT_INIT +m4trace:configure.ac:57: -1- m4_pattern_forbid([^_?LT_[A-Z_]+$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$]) +m4trace:configure.ac:57: -1- LTOPTIONS_VERSION +m4trace:configure.ac:57: -1- LTSUGAR_VERSION +m4trace:configure.ac:57: -1- LTVERSION_VERSION +m4trace:configure.ac:57: -1- LTOBSOLETE_VERSION +m4trace:configure.ac:57: -1- _LT_PROG_LTMAIN +m4trace:configure.ac:57: -1- m4_pattern_allow([^LIBTOOL$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build_cpu$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build_vendor$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build_os$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host_cpu$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host_vendor$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host_os$]) +m4trace:configure.ac:57: -1- _LT_PREPARE_SED_QUOTE_VARS +m4trace:configure.ac:57: -1- _LT_PROG_ECHO_BACKSLASH +m4trace:configure.ac:57: -1- LT_PATH_LD +m4trace:configure.ac:57: -1- m4_pattern_allow([^SED$]) +m4trace:configure.ac:57: -1- AC_PROG_EGREP +m4trace:configure.ac:57: -1- m4_pattern_allow([^GREP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^EGREP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^FGREP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^GREP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LD$]) +m4trace:configure.ac:57: -1- LT_PATH_NM +m4trace:configure.ac:57: -1- m4_pattern_allow([^DUMPBIN$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^ac_ct_DUMPBIN$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DUMPBIN$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^NM$]) +m4trace:configure.ac:57: -1- LT_CMD_MAX_LEN +m4trace:configure.ac:57: -1- m4_pattern_allow([^OBJDUMP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^OBJDUMP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DLLTOOL$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DLLTOOL$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^AR$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^ac_ct_AR$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^STRIP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^RANLIB$]) +m4trace:configure.ac:57: -1- _LT_WITH_SYSROOT +m4trace:configure.ac:57: -1- m4_pattern_allow([LT_OBJDIR]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LT_OBJDIR$]) +m4trace:configure.ac:57: -1- _LT_CC_BASENAME([$compiler]) +m4trace:configure.ac:57: -1- _LT_PATH_TOOL_PREFIX([${ac_tool_prefix}file], [/usr/bin$PATH_SEPARATOR$PATH]) +m4trace:configure.ac:57: -1- _LT_PATH_TOOL_PREFIX([file], [/usr/bin$PATH_SEPARATOR$PATH]) +m4trace:configure.ac:57: -1- LT_SUPPORTED_TAG([CC]) +m4trace:configure.ac:57: -1- _LT_COMPILER_BOILERPLATE +m4trace:configure.ac:57: -1- _LT_LINKER_BOILERPLATE +m4trace:configure.ac:57: -1- _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], [lt_cv_prog_compiler_rtti_exceptions], [-fno-rtti -fno-exceptions], [], [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, )="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, ) -fno-rtti -fno-exceptions"]) +m4trace:configure.ac:57: -1- _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, ) works], [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, )], [$_LT_TAGVAR(lt_prog_compiler_pic, )@&t@m4_if([],[],[ -DPIC],[m4_if([],[CXX],[ -DPIC],[])])], [], [case $_LT_TAGVAR(lt_prog_compiler_pic, ) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, )=" $_LT_TAGVAR(lt_prog_compiler_pic, )" ;; + esac], [_LT_TAGVAR(lt_prog_compiler_pic, )= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, )=no]) +m4trace:configure.ac:57: -1- _LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], [lt_cv_prog_compiler_static_works], [$lt_tmp_static_flag], [], [_LT_TAGVAR(lt_prog_compiler_static, )=]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^MANIFEST_TOOL$]) +m4trace:configure.ac:57: -1- _LT_DLL_DEF_P([$export_symbols]) +m4trace:configure.ac:57: -1- _LT_DLL_DEF_P([$export_symbols]) +m4trace:configure.ac:57: -1- _LT_REQUIRED_DARWIN_CHECKS +m4trace:configure.ac:57: -1- m4_pattern_allow([^DSYMUTIL$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^NMEDIT$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LIPO$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^OTOOL$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^OTOOL64$]) +m4trace:configure.ac:57: -1- _LT_LINKER_OPTION([if $CC understands -b], [lt_cv_prog_compiler__b], [-b], [_LT_TAGVAR(archive_cmds, )='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags'], [_LT_TAGVAR(archive_cmds, )='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags']) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LT_SYS_LIBRARY_PATH$]) +m4trace:configure.ac:57: -1- LT_SYS_DLOPEN_SELF +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^STDC_HEADERS$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^HAVE_DLFCN_H$]) +m4trace:configure.ac:57: -1- LT_LANG([CXX]) +m4trace:configure.ac:57: -1- LT_SUPPORTED_TAG([CXX]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CXXCPP$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CXXCPP$]) +m4trace:configure.ac:57: -1- _LT_COMPILER_BOILERPLATE +m4trace:configure.ac:57: -1- _LT_LINKER_BOILERPLATE +m4trace:configure.ac:57: -1- _LT_CC_BASENAME([$compiler]) +m4trace:configure.ac:57: -1- LT_PATH_LD +m4trace:configure.ac:57: -1- m4_pattern_allow([^LD$]) +m4trace:configure.ac:57: -1- _LT_DLL_DEF_P([$export_symbols]) +m4trace:configure.ac:57: -1- _LT_DLL_DEF_P([$export_symbols]) +m4trace:configure.ac:57: -1- _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, CXX) works], [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, CXX)], [$_LT_TAGVAR(lt_prog_compiler_pic, CXX)@&t@m4_if([CXX],[],[ -DPIC],[m4_if([CXX],[CXX],[ -DPIC],[])])], [], [case $_LT_TAGVAR(lt_prog_compiler_pic, CXX) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, CXX)=" $_LT_TAGVAR(lt_prog_compiler_pic, CXX)" ;; + esac], [_LT_TAGVAR(lt_prog_compiler_pic, CXX)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, CXX)=no]) +m4trace:configure.ac:57: -1- _LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], [lt_cv_prog_compiler_static_works_CXX], [$lt_tmp_static_flag], [], [_LT_TAGVAR(lt_prog_compiler_static, CXX)=]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LT_SYS_LIBRARY_PATH$]) +m4trace:configure.ac:106: -1- AM_CONDITIONAL([WANT_SYNCAPI], [test "x$with_syncapi" != xno]) +m4trace:configure.ac:106: -1- m4_pattern_allow([^WANT_SYNCAPI_TRUE$]) +m4trace:configure.ac:106: -1- m4_pattern_allow([^WANT_SYNCAPI_FALSE$]) +m4trace:configure.ac:106: -1- _AM_SUBST_NOTMAKE([WANT_SYNCAPI_TRUE]) +m4trace:configure.ac:106: -1- _AM_SUBST_NOTMAKE([WANT_SYNCAPI_FALSE]) +m4trace:configure.ac:109: -1- m4_pattern_allow([^STDC_HEADERS$]) +m4trace:configure.ac:113: -1- m4_pattern_allow([^const$]) +m4trace:configure.ac:115: -1- m4_pattern_allow([^TIME_WITH_SYS_TIME$]) +m4trace:configure.ac:119: -1- m4_pattern_allow([^POLL_NFDS_TYPE$]) +m4trace:configure.ac:119: -1- m4_pattern_allow([^POLL_NFDS_TYPE$]) +m4trace:configure.ac:138: -1- _m4_warn([obsolete], [The macro `AC_TRY_RUN' is obsolete. +You should run autoupdate.], [../../lib/autoconf/general.m4:2765: AC_TRY_RUN is expanded from... +configure.ac:138: the top level]) +m4trace:configure.ac:142: -1- m4_pattern_allow([^USEIPV6$]) +m4trace:configure.ac:148: -1- m4_pattern_allow([^HAVE_LIBRT$]) +m4trace:configure.ac:150: -1- m4_pattern_allow([^CLOCK_GETTIME_LIBS$]) +m4trace:configure.ac:166: -1- AM_CONDITIONAL([SOLARIS], [ + case "$host_os" in + *solaris*) + true + ;; + *) + false + ;; + esac ]) +m4trace:configure.ac:166: -1- m4_pattern_allow([^SOLARIS_TRUE$]) +m4trace:configure.ac:166: -1- m4_pattern_allow([^SOLARIS_FALSE$]) +m4trace:configure.ac:166: -1- _AM_SUBST_NOTMAKE([SOLARIS_TRUE]) +m4trace:configure.ac:166: -1- _AM_SUBST_NOTMAKE([SOLARIS_FALSE]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^LIB@&t@OBJS$]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^LTLIBOBJS$]) +m4trace:configure.ac:167: -1- AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^am__EXEEXT_TRUE$]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^am__EXEEXT_FALSE$]) +m4trace:configure.ac:167: -1- _AM_SUBST_NOTMAKE([am__EXEEXT_TRUE]) +m4trace:configure.ac:167: -1- _AM_SUBST_NOTMAKE([am__EXEEXT_FALSE]) +m4trace:configure.ac:167: -1- _AC_AM_CONFIG_HEADER_HOOK(["$ac_file"]) +m4trace:configure.ac:167: -1- _AM_OUTPUT_DEPENDENCY_COMMANDS +m4trace:configure.ac:167: -1- _LT_PROG_LTMAIN diff --git a/src/c/autom4te.cache/traces.1 b/src/c/autom4te.cache/traces.1 new file mode 100644 index 00000000000..6b54d57c8d0 --- /dev/null +++ b/src/c/autom4te.cache/traces.1 @@ -0,0 +1,1171 @@ +m4trace:aclocal.m4:10182: -1- m4_include([acinclude.m4]) +m4trace:configure.ac:6: -1- AC_INIT([zookeeper C client], [3.6.0], [user@zookeeper.apache.org], [zookeeper]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^_?A[CHUM]_]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([_AC_]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^LIBOBJS$], [do not use LIBOBJS directly, use AC_LIBOBJ (see section `AC_LIBOBJ vs LIBOBJS']) +m4trace:configure.ac:6: -1- m4_pattern_allow([^AS_FLAGS$]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^_?m4_]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^dnl$]) +m4trace:configure.ac:6: -1- m4_pattern_forbid([^_?AS_]) +m4trace:configure.ac:6: -1- AC_SUBST([SHELL]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([SHELL]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^SHELL$]) +m4trace:configure.ac:6: -1- AC_SUBST([PATH_SEPARATOR]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([PATH_SEPARATOR]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PATH_SEPARATOR$]) +m4trace:configure.ac:6: -1- AC_SUBST([PACKAGE_NAME], [m4_ifdef([AC_PACKAGE_NAME], ['AC_PACKAGE_NAME'])]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([PACKAGE_NAME]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_NAME$]) +m4trace:configure.ac:6: -1- AC_SUBST([PACKAGE_TARNAME], [m4_ifdef([AC_PACKAGE_TARNAME], ['AC_PACKAGE_TARNAME'])]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([PACKAGE_TARNAME]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) +m4trace:configure.ac:6: -1- AC_SUBST([PACKAGE_VERSION], [m4_ifdef([AC_PACKAGE_VERSION], ['AC_PACKAGE_VERSION'])]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([PACKAGE_VERSION]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_VERSION$]) +m4trace:configure.ac:6: -1- AC_SUBST([PACKAGE_STRING], [m4_ifdef([AC_PACKAGE_STRING], ['AC_PACKAGE_STRING'])]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([PACKAGE_STRING]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_STRING$]) +m4trace:configure.ac:6: -1- AC_SUBST([PACKAGE_BUGREPORT], [m4_ifdef([AC_PACKAGE_BUGREPORT], ['AC_PACKAGE_BUGREPORT'])]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([PACKAGE_BUGREPORT]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) +m4trace:configure.ac:6: -1- AC_SUBST([PACKAGE_URL], [m4_ifdef([AC_PACKAGE_URL], ['AC_PACKAGE_URL'])]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([PACKAGE_URL]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_URL$]) +m4trace:configure.ac:6: -1- AC_SUBST([exec_prefix], [NONE]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([exec_prefix]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^exec_prefix$]) +m4trace:configure.ac:6: -1- AC_SUBST([prefix], [NONE]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([prefix]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^prefix$]) +m4trace:configure.ac:6: -1- AC_SUBST([program_transform_name], [s,x,x,]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([program_transform_name]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^program_transform_name$]) +m4trace:configure.ac:6: -1- AC_SUBST([bindir], ['${exec_prefix}/bin']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([bindir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^bindir$]) +m4trace:configure.ac:6: -1- AC_SUBST([sbindir], ['${exec_prefix}/sbin']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([sbindir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^sbindir$]) +m4trace:configure.ac:6: -1- AC_SUBST([libexecdir], ['${exec_prefix}/libexec']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([libexecdir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^libexecdir$]) +m4trace:configure.ac:6: -1- AC_SUBST([datarootdir], ['${prefix}/share']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([datarootdir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^datarootdir$]) +m4trace:configure.ac:6: -1- AC_SUBST([datadir], ['${datarootdir}']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([datadir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^datadir$]) +m4trace:configure.ac:6: -1- AC_SUBST([sysconfdir], ['${prefix}/etc']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([sysconfdir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^sysconfdir$]) +m4trace:configure.ac:6: -1- AC_SUBST([sharedstatedir], ['${prefix}/com']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([sharedstatedir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^sharedstatedir$]) +m4trace:configure.ac:6: -1- AC_SUBST([localstatedir], ['${prefix}/var']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([localstatedir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^localstatedir$]) +m4trace:configure.ac:6: -1- AC_SUBST([includedir], ['${prefix}/include']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([includedir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^includedir$]) +m4trace:configure.ac:6: -1- AC_SUBST([oldincludedir], ['/usr/include']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([oldincludedir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^oldincludedir$]) +m4trace:configure.ac:6: -1- AC_SUBST([docdir], [m4_ifset([AC_PACKAGE_TARNAME], + ['${datarootdir}/doc/${PACKAGE_TARNAME}'], + ['${datarootdir}/doc/${PACKAGE}'])]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([docdir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^docdir$]) +m4trace:configure.ac:6: -1- AC_SUBST([infodir], ['${datarootdir}/info']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([infodir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^infodir$]) +m4trace:configure.ac:6: -1- AC_SUBST([htmldir], ['${docdir}']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([htmldir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^htmldir$]) +m4trace:configure.ac:6: -1- AC_SUBST([dvidir], ['${docdir}']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([dvidir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^dvidir$]) +m4trace:configure.ac:6: -1- AC_SUBST([pdfdir], ['${docdir}']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([pdfdir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^pdfdir$]) +m4trace:configure.ac:6: -1- AC_SUBST([psdir], ['${docdir}']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([psdir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^psdir$]) +m4trace:configure.ac:6: -1- AC_SUBST([libdir], ['${exec_prefix}/lib']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([libdir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^libdir$]) +m4trace:configure.ac:6: -1- AC_SUBST([localedir], ['${datarootdir}/locale']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([localedir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^localedir$]) +m4trace:configure.ac:6: -1- AC_SUBST([mandir], ['${datarootdir}/man']) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([mandir]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^mandir$]) +m4trace:configure.ac:6: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_NAME]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_NAME$]) +m4trace:configure.ac:6: -1- AH_OUTPUT([PACKAGE_NAME], [/* Define to the full name of this package. */ +@%:@undef PACKAGE_NAME]) +m4trace:configure.ac:6: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_TARNAME]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_TARNAME$]) +m4trace:configure.ac:6: -1- AH_OUTPUT([PACKAGE_TARNAME], [/* Define to the one symbol short name of this package. */ +@%:@undef PACKAGE_TARNAME]) +m4trace:configure.ac:6: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_VERSION]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_VERSION$]) +m4trace:configure.ac:6: -1- AH_OUTPUT([PACKAGE_VERSION], [/* Define to the version of this package. */ +@%:@undef PACKAGE_VERSION]) +m4trace:configure.ac:6: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_STRING]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_STRING$]) +m4trace:configure.ac:6: -1- AH_OUTPUT([PACKAGE_STRING], [/* Define to the full name and version of this package. */ +@%:@undef PACKAGE_STRING]) +m4trace:configure.ac:6: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_BUGREPORT]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_BUGREPORT$]) +m4trace:configure.ac:6: -1- AH_OUTPUT([PACKAGE_BUGREPORT], [/* Define to the address where bug reports for this package should be sent. */ +@%:@undef PACKAGE_BUGREPORT]) +m4trace:configure.ac:6: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE_URL]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^PACKAGE_URL$]) +m4trace:configure.ac:6: -1- AH_OUTPUT([PACKAGE_URL], [/* Define to the home page for this package. */ +@%:@undef PACKAGE_URL]) +m4trace:configure.ac:6: -1- AC_SUBST([DEFS]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([DEFS]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^DEFS$]) +m4trace:configure.ac:6: -1- AC_SUBST([ECHO_C]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([ECHO_C]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^ECHO_C$]) +m4trace:configure.ac:6: -1- AC_SUBST([ECHO_N]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([ECHO_N]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^ECHO_N$]) +m4trace:configure.ac:6: -1- AC_SUBST([ECHO_T]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([ECHO_T]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^ECHO_T$]) +m4trace:configure.ac:6: -1- AC_SUBST([LIBS]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([LIBS]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^LIBS$]) +m4trace:configure.ac:6: -1- AC_SUBST([build_alias]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([build_alias]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^build_alias$]) +m4trace:configure.ac:6: -1- AC_SUBST([host_alias]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([host_alias]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^host_alias$]) +m4trace:configure.ac:6: -1- AC_SUBST([target_alias]) +m4trace:configure.ac:6: -1- AC_SUBST_TRACE([target_alias]) +m4trace:configure.ac:6: -1- m4_pattern_allow([^target_alias$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_PROJECT], [zookeeper]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_PROJECT]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_PROJECT$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_CONFIG], [ifelse([c-doc.Doxyfile], [], Doxyfile, [c-doc.Doxyfile])]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_CONFIG]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_CONFIG$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_DOCDIR], [ifelse([docs], [], doxygen-doc, [docs])]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_DOCDIR]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DOCDIR$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV SRCDIR='$srcdir'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV PROJECT='$DX_PROJECT'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV DOCDIR='$DX_DOCDIR'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV VERSION='$PACKAGE_VERSION'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_doc], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_doc]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_doc], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_doc]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_doc], [DX_IF_FEATURE([doc], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_doc]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_DOXYGEN]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_DOXYGEN]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DOXYGEN$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_doc], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_doc]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_PERL]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_PERL]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_PERL$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_doc], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_doc]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_doc$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_doc], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV PERL_PATH='$DX_PERL'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_doc], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_doc_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_doc_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_dot], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_dot]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_dot], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_dot]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_dot], [DX_IF_FEATURE([dot], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_dot]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_dot], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_dot]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_DOT]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_DOT]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DOT$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_dot], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_dot]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_dot$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_dot], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV HAVE_DOT='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV DOT_PATH='`DX_DIRNAME_EXPR($DX_DOT)`'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_dot], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_dot_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_dot_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV HAVE_DOT='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_man], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_man]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_man], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_man]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_man], [DX_IF_FEATURE([man], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_man]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_man], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_man]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_man$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_man], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_MAN='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_man], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_man_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_man_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_MAN='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_rtf], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_rtf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_rtf], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_rtf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_rtf], [DX_IF_FEATURE([rtf], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_rtf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_rtf], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_rtf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_rtf$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_rtf], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_RTF='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_rtf], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_rtf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_rtf_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_RTF='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_xml], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_xml]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_xml], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_xml]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_xml], [DX_IF_FEATURE([xml], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_xml]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_xml], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_xml]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_xml$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_xml], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_XML='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_xml], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_xml_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_xml_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_XML='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chm], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chm]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chm], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chm]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chm], [DX_IF_FEATURE([chm], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chm]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chm], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chm]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_HHC]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_HHC]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_HHC$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chm], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chm]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chm$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chm], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV HHC_PATH='$DX_HHC'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_HTML='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_HTMLHELP='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chm], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chm_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chm_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_HTMLHELP='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chi], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chi]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chi], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chi]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chi], [DX_IF_FEATURE([chi], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chi]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_chi], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_chi]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_chi$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chi], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_CHI='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_chi], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_chi_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_chi_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_CHI='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_html], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_html]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_html], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_html]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_html], [DX_IF_FEATURE([html], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_html]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_html], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_html]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_html], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_html]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_html$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_html], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_HTML='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_html], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_html_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_html_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_HTML='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [DX_IF_FEATURE([ps], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_LATEX]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_LATEX]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_LATEX$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_MAKEINDEX]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_MAKEINDEX]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_MAKEINDEX$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_DVIPS]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_DVIPS]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_DVIPS$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_EGREP]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_EGREP]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_EGREP$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_ps], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_ps]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_ps$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_ps], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_ps], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_ps_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_ps_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_pdf], [1]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_pdf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_pdf], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_pdf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_pdf], [DX_IF_FEATURE([pdf], 1, 0)]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_pdf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_pdf], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_pdf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_PDFLATEX]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_PDFLATEX]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_PDFLATEX$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_pdf], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_pdf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_MAKEINDEX]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_MAKEINDEX]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_MAKEINDEX$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_pdf], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_pdf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_EGREP]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_EGREP]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_EGREP$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_FLAG_pdf], [0]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_FLAG_pdf]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_FLAG_pdf$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_pdf], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_pdf], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_pdf_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_pdf_FALSE]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_latex], [:]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_LATEX='YES'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AM_CONDITIONAL([DX_COND_latex], [false]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_TRUE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_COND_latex_FALSE$]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_TRUE]) +m4trace:configure.ac:22: -1- _AM_SUBST_NOTMAKE([DX_COND_latex_FALSE]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV GENERATE_LATEX='NO'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:22: -1- AC_SUBST([DOXYGEN_PAPER_SIZE]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DOXYGEN_PAPER_SIZE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DOXYGEN_PAPER_SIZE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DOXYGEN_PAPER_SIZE], [""]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DOXYGEN_PAPER_SIZE]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DOXYGEN_PAPER_SIZE$]) +m4trace:configure.ac:22: -1- AC_SUBST([DX_ENV], ["$DX_ENV PAPER_SIZE='$DOXYGEN_PAPER_SIZE'"]) +m4trace:configure.ac:22: -1- AC_SUBST_TRACE([DX_ENV]) +m4trace:configure.ac:22: -1- m4_pattern_allow([^DX_ENV$]) +m4trace:configure.ac:25: -1- AM_INIT_AUTOMAKE([-Wall foreign]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_[A-Z]+FLAGS$]) +m4trace:configure.ac:25: -1- AM_AUTOMAKE_VERSION([1.15]) +m4trace:configure.ac:25: -1- AC_REQUIRE_AUX_FILE([install-sh]) +m4trace:configure.ac:25: -1- AC_SUBST([INSTALL_PROGRAM]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([INSTALL_PROGRAM]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_PROGRAM$]) +m4trace:configure.ac:25: -1- AC_SUBST([INSTALL_SCRIPT]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([INSTALL_SCRIPT]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_SCRIPT$]) +m4trace:configure.ac:25: -1- AC_SUBST([INSTALL_DATA]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([INSTALL_DATA]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_DATA$]) +m4trace:configure.ac:25: -1- AC_SUBST([am__isrc], [' -I$(srcdir)']) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([am__isrc]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__isrc$]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([am__isrc]) +m4trace:configure.ac:25: -1- AC_SUBST([CYGPATH_W]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([CYGPATH_W]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^CYGPATH_W$]) +m4trace:configure.ac:25: -1- AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME']) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([PACKAGE]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^PACKAGE$]) +m4trace:configure.ac:25: -1- AC_SUBST([VERSION], ['AC_PACKAGE_VERSION']) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([VERSION]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^VERSION$]) +m4trace:configure.ac:25: -1- AC_DEFINE_TRACE_LITERAL([PACKAGE]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^PACKAGE$]) +m4trace:configure.ac:25: -1- AH_OUTPUT([PACKAGE], [/* Name of package */ +@%:@undef PACKAGE]) +m4trace:configure.ac:25: -1- AC_DEFINE_TRACE_LITERAL([VERSION]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^VERSION$]) +m4trace:configure.ac:25: -1- AH_OUTPUT([VERSION], [/* Version number of package */ +@%:@undef VERSION]) +m4trace:configure.ac:25: -1- AC_REQUIRE_AUX_FILE([missing]) +m4trace:configure.ac:25: -1- AC_SUBST([ACLOCAL]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([ACLOCAL]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^ACLOCAL$]) +m4trace:configure.ac:25: -1- AC_SUBST([AUTOCONF]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AUTOCONF]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AUTOCONF$]) +m4trace:configure.ac:25: -1- AC_SUBST([AUTOMAKE]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AUTOMAKE]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AUTOMAKE$]) +m4trace:configure.ac:25: -1- AC_SUBST([AUTOHEADER]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AUTOHEADER]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AUTOHEADER$]) +m4trace:configure.ac:25: -1- AC_SUBST([MAKEINFO]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([MAKEINFO]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^MAKEINFO$]) +m4trace:configure.ac:25: -1- AC_SUBST([install_sh]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([install_sh]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^install_sh$]) +m4trace:configure.ac:25: -1- AC_SUBST([STRIP]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([STRIP]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^STRIP$]) +m4trace:configure.ac:25: -1- AC_SUBST([INSTALL_STRIP_PROGRAM]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([INSTALL_STRIP_PROGRAM]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^INSTALL_STRIP_PROGRAM$]) +m4trace:configure.ac:25: -1- AC_REQUIRE_AUX_FILE([install-sh]) +m4trace:configure.ac:25: -1- AC_SUBST([MKDIR_P]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([MKDIR_P]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^MKDIR_P$]) +m4trace:configure.ac:25: -1- AC_SUBST([mkdir_p], ['$(MKDIR_P)']) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([mkdir_p]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^mkdir_p$]) +m4trace:configure.ac:25: -1- AC_SUBST([AWK]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AWK]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AWK$]) +m4trace:configure.ac:25: -1- AC_SUBST([SET_MAKE]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([SET_MAKE]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^SET_MAKE$]) +m4trace:configure.ac:25: -1- AC_SUBST([am__leading_dot]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([am__leading_dot]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__leading_dot$]) +m4trace:configure.ac:25: -1- AC_SUBST([AMTAR], ['$${TAR-tar}']) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AMTAR]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AMTAR$]) +m4trace:configure.ac:25: -1- AC_SUBST([am__tar]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([am__tar]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__tar$]) +m4trace:configure.ac:25: -1- AC_SUBST([am__untar]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([am__untar]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^am__untar$]) +m4trace:configure.ac:25: -1- AM_SILENT_RULES +m4trace:configure.ac:25: -1- AC_SUBST([AM_V]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AM_V]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_V$]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([AM_V]) +m4trace:configure.ac:25: -1- AC_SUBST([AM_DEFAULT_V]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AM_DEFAULT_V]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_DEFAULT_V$]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([AM_DEFAULT_V]) +m4trace:configure.ac:25: -1- AC_SUBST([AM_DEFAULT_VERBOSITY]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AM_DEFAULT_VERBOSITY]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_DEFAULT_VERBOSITY$]) +m4trace:configure.ac:25: -1- AC_SUBST([AM_BACKSLASH]) +m4trace:configure.ac:25: -1- AC_SUBST_TRACE([AM_BACKSLASH]) +m4trace:configure.ac:25: -1- m4_pattern_allow([^AM_BACKSLASH$]) +m4trace:configure.ac:25: -1- _AM_SUBST_NOTMAKE([AM_BACKSLASH]) +m4trace:configure.ac:26: -1- AC_CONFIG_HEADERS([config.h]) +m4trace:configure.ac:46: -1- _m4_warn([cross], [cannot check for file existence when cross compiling], [../../lib/autoconf/general.m4:2791: AC_CHECK_FILE is expanded from... +../../lib/autoconf/general.m4:2809: AC_CHECK_FILES is expanded from... +configure.ac:46: the top level]) +m4trace:configure.ac:46: -1- AC_DEFINE_TRACE_LITERAL([HAVE_GENERATED_ZOOKEEPER_JUTE_C]) +m4trace:configure.ac:46: -1- m4_pattern_allow([^HAVE_GENERATED_ZOOKEEPER_JUTE_C$]) +m4trace:configure.ac:46: -1- AH_OUTPUT([HAVE_GENERATED_ZOOKEEPER_JUTE_C], [/* Define to 1 if you have the file `generated/zookeeper.jute.c\'. */ +@%:@undef HAVE_GENERATED_ZOOKEEPER_JUTE_C]) +m4trace:configure.ac:46: -1- _m4_warn([cross], [cannot check for file existence when cross compiling], [../../lib/autoconf/general.m4:2791: AC_CHECK_FILE is expanded from... +../../lib/autoconf/general.m4:2809: AC_CHECK_FILES is expanded from... +configure.ac:46: the top level]) +m4trace:configure.ac:46: -1- AC_DEFINE_TRACE_LITERAL([HAVE_GENERATED_ZOOKEEPER_JUTE_H]) +m4trace:configure.ac:46: -1- m4_pattern_allow([^HAVE_GENERATED_ZOOKEEPER_JUTE_H$]) +m4trace:configure.ac:46: -1- AH_OUTPUT([HAVE_GENERATED_ZOOKEEPER_JUTE_H], [/* Define to 1 if you have the file `generated/zookeeper.jute.h\'. */ +@%:@undef HAVE_GENERATED_ZOOKEEPER_JUTE_H]) +m4trace:configure.ac:48: -1- AC_SUBST([CPPUNIT_CFLAGS]) +m4trace:configure.ac:48: -1- AC_SUBST_TRACE([CPPUNIT_CFLAGS]) +m4trace:configure.ac:48: -1- m4_pattern_allow([^CPPUNIT_CFLAGS$]) +m4trace:configure.ac:50: -1- AC_SUBST([CC]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CC]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- AC_SUBST([CFLAGS]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CFLAGS]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CFLAGS$]) +m4trace:configure.ac:50: -1- AC_SUBST([LDFLAGS]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([LDFLAGS]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^LDFLAGS$]) +m4trace:configure.ac:50: -1- AC_SUBST([LIBS]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([LIBS]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^LIBS$]) +m4trace:configure.ac:50: -1- AC_SUBST([CPPFLAGS]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CPPFLAGS]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:50: -1- AC_SUBST([CC]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CC]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- AC_SUBST([CC]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CC]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- AC_SUBST([CC]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CC]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- AC_SUBST([CC]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CC]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CC$]) +m4trace:configure.ac:50: -1- AC_SUBST([ac_ct_CC]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([ac_ct_CC]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^ac_ct_CC$]) +m4trace:configure.ac:50: -1- AC_SUBST([EXEEXT], [$ac_cv_exeext]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([EXEEXT]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^EXEEXT$]) +m4trace:configure.ac:50: -1- AC_SUBST([OBJEXT], [$ac_cv_objext]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([OBJEXT]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^OBJEXT$]) +m4trace:configure.ac:50: -1- AC_REQUIRE_AUX_FILE([compile]) +m4trace:configure.ac:50: -1- AC_SUBST([DEPDIR], ["${am__leading_dot}deps"]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([DEPDIR]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^DEPDIR$]) +m4trace:configure.ac:50: -1- AC_SUBST([am__include]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([am__include]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__include$]) +m4trace:configure.ac:50: -1- AC_SUBST([am__quote]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([am__quote]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__quote$]) +m4trace:configure.ac:50: -1- AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +m4trace:configure.ac:50: -1- AC_SUBST([AMDEP_TRUE]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([AMDEP_TRUE]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^AMDEP_TRUE$]) +m4trace:configure.ac:50: -1- AC_SUBST([AMDEP_FALSE]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([AMDEP_FALSE]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^AMDEP_FALSE$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([AMDEP_TRUE]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([AMDEP_FALSE]) +m4trace:configure.ac:50: -1- AC_SUBST([AMDEPBACKSLASH]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([AMDEPBACKSLASH]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^AMDEPBACKSLASH$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([AMDEPBACKSLASH]) +m4trace:configure.ac:50: -1- AC_SUBST([am__nodep]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([am__nodep]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__nodep$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([am__nodep]) +m4trace:configure.ac:50: -1- AC_SUBST([CCDEPMODE], [depmode=$am_cv_CC_dependencies_compiler_type]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([CCDEPMODE]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^CCDEPMODE$]) +m4trace:configure.ac:50: -1- AM_CONDITIONAL([am__fastdepCC], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3]) +m4trace:configure.ac:50: -1- AC_SUBST([am__fastdepCC_TRUE]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([am__fastdepCC_TRUE]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__fastdepCC_TRUE$]) +m4trace:configure.ac:50: -1- AC_SUBST([am__fastdepCC_FALSE]) +m4trace:configure.ac:50: -1- AC_SUBST_TRACE([am__fastdepCC_FALSE]) +m4trace:configure.ac:50: -1- m4_pattern_allow([^am__fastdepCC_FALSE$]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([am__fastdepCC_TRUE]) +m4trace:configure.ac:50: -1- _AM_SUBST_NOTMAKE([am__fastdepCC_FALSE]) +m4trace:configure.ac:51: -1- AM_PROG_CC_C_O +m4trace:configure.ac:52: -1- AC_SUBST([CXX]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([CXX]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXX$]) +m4trace:configure.ac:52: -1- AC_SUBST([CXXFLAGS]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([CXXFLAGS]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXXFLAGS$]) +m4trace:configure.ac:52: -1- AC_SUBST([LDFLAGS]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([LDFLAGS]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^LDFLAGS$]) +m4trace:configure.ac:52: -1- AC_SUBST([LIBS]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([LIBS]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^LIBS$]) +m4trace:configure.ac:52: -1- AC_SUBST([CPPFLAGS]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([CPPFLAGS]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:52: -1- AC_SUBST([CXX]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([CXX]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXX$]) +m4trace:configure.ac:52: -1- AC_SUBST([ac_ct_CXX]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([ac_ct_CXX]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^ac_ct_CXX$]) +m4trace:configure.ac:52: -1- AC_SUBST([CXXDEPMODE], [depmode=$am_cv_CXX_dependencies_compiler_type]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([CXXDEPMODE]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^CXXDEPMODE$]) +m4trace:configure.ac:52: -1- AM_CONDITIONAL([am__fastdepCXX], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CXX_dependencies_compiler_type" = gcc3]) +m4trace:configure.ac:52: -1- AC_SUBST([am__fastdepCXX_TRUE]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([am__fastdepCXX_TRUE]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^am__fastdepCXX_TRUE$]) +m4trace:configure.ac:52: -1- AC_SUBST([am__fastdepCXX_FALSE]) +m4trace:configure.ac:52: -1- AC_SUBST_TRACE([am__fastdepCXX_FALSE]) +m4trace:configure.ac:52: -1- m4_pattern_allow([^am__fastdepCXX_FALSE$]) +m4trace:configure.ac:52: -1- _AM_SUBST_NOTMAKE([am__fastdepCXX_TRUE]) +m4trace:configure.ac:52: -1- _AM_SUBST_NOTMAKE([am__fastdepCXX_FALSE]) +m4trace:configure.ac:54: -1- AC_SUBST([LN_S], [$as_ln_s]) +m4trace:configure.ac:54: -1- AC_SUBST_TRACE([LN_S]) +m4trace:configure.ac:54: -1- m4_pattern_allow([^LN_S$]) +m4trace:configure.ac:57: -1- AC_PROG_LIBTOOL +m4trace:configure.ac:57: -1- _m4_warn([obsolete], [The macro `AC_PROG_LIBTOOL' is obsolete. +You should run autoupdate.], [aclocal.m4:121: AC_PROG_LIBTOOL is expanded from... +configure.ac:57: the top level]) +m4trace:configure.ac:57: -1- LT_INIT +m4trace:configure.ac:57: -1- m4_pattern_forbid([^_?LT_[A-Z_]+$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$]) +m4trace:configure.ac:57: -1- AC_REQUIRE_AUX_FILE([ltmain.sh]) +m4trace:configure.ac:57: -1- AC_SUBST([LIBTOOL]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([LIBTOOL]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LIBTOOL$]) +m4trace:configure.ac:57: -1- AC_CANONICAL_HOST +m4trace:configure.ac:57: -1- AC_CANONICAL_BUILD +m4trace:configure.ac:57: -1- AC_REQUIRE_AUX_FILE([config.sub]) +m4trace:configure.ac:57: -1- AC_REQUIRE_AUX_FILE([config.guess]) +m4trace:configure.ac:57: -1- AC_SUBST([build], [$ac_cv_build]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([build]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build$]) +m4trace:configure.ac:57: -1- AC_SUBST([build_cpu], [$[1]]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([build_cpu]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build_cpu$]) +m4trace:configure.ac:57: -1- AC_SUBST([build_vendor], [$[2]]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([build_vendor]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build_vendor$]) +m4trace:configure.ac:57: -1- AC_SUBST([build_os]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([build_os]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^build_os$]) +m4trace:configure.ac:57: -1- AC_SUBST([host], [$ac_cv_host]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([host]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host$]) +m4trace:configure.ac:57: -1- AC_SUBST([host_cpu], [$[1]]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([host_cpu]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host_cpu$]) +m4trace:configure.ac:57: -1- AC_SUBST([host_vendor], [$[2]]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([host_vendor]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host_vendor$]) +m4trace:configure.ac:57: -1- AC_SUBST([host_os]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([host_os]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^host_os$]) +m4trace:configure.ac:57: -1- AC_SUBST([SED]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([SED]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^SED$]) +m4trace:configure.ac:57: -1- AC_SUBST([GREP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([GREP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^GREP$]) +m4trace:configure.ac:57: -1- AC_SUBST([EGREP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([EGREP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^EGREP$]) +m4trace:configure.ac:57: -1- AC_SUBST([FGREP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([FGREP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^FGREP$]) +m4trace:configure.ac:57: -1- AC_SUBST([GREP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([GREP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^GREP$]) +m4trace:configure.ac:57: -1- AC_SUBST([LD]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([LD]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LD$]) +m4trace:configure.ac:57: -1- AC_SUBST([DUMPBIN]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([DUMPBIN]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DUMPBIN$]) +m4trace:configure.ac:57: -1- AC_SUBST([ac_ct_DUMPBIN]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([ac_ct_DUMPBIN]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^ac_ct_DUMPBIN$]) +m4trace:configure.ac:57: -1- AC_SUBST([DUMPBIN]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([DUMPBIN]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DUMPBIN$]) +m4trace:configure.ac:57: -1- AC_SUBST([NM]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([NM]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^NM$]) +m4trace:configure.ac:57: -1- AC_SUBST([OBJDUMP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([OBJDUMP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^OBJDUMP$]) +m4trace:configure.ac:57: -1- AC_SUBST([OBJDUMP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([OBJDUMP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^OBJDUMP$]) +m4trace:configure.ac:57: -1- AC_SUBST([DLLTOOL]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([DLLTOOL]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DLLTOOL$]) +m4trace:configure.ac:57: -1- AC_SUBST([DLLTOOL]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([DLLTOOL]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DLLTOOL$]) +m4trace:configure.ac:57: -1- AC_SUBST([AR]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([AR]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^AR$]) +m4trace:configure.ac:57: -1- AC_SUBST([ac_ct_AR]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([ac_ct_AR]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^ac_ct_AR$]) +m4trace:configure.ac:57: -1- AC_SUBST([STRIP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([STRIP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^STRIP$]) +m4trace:configure.ac:57: -1- AC_SUBST([RANLIB]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([RANLIB]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^RANLIB$]) +m4trace:configure.ac:57: -1- m4_pattern_allow([LT_OBJDIR]) +m4trace:configure.ac:57: -1- AC_DEFINE_TRACE_LITERAL([LT_OBJDIR]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LT_OBJDIR$]) +m4trace:configure.ac:57: -1- AH_OUTPUT([LT_OBJDIR], [/* Define to the sub-directory where libtool stores uninstalled libraries. */ +@%:@undef LT_OBJDIR]) +m4trace:configure.ac:57: -1- LT_SUPPORTED_TAG([CC]) +m4trace:configure.ac:57: -1- AC_SUBST([MANIFEST_TOOL]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([MANIFEST_TOOL]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^MANIFEST_TOOL$]) +m4trace:configure.ac:57: -1- AC_SUBST([DSYMUTIL]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([DSYMUTIL]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^DSYMUTIL$]) +m4trace:configure.ac:57: -1- AC_SUBST([NMEDIT]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([NMEDIT]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^NMEDIT$]) +m4trace:configure.ac:57: -1- AC_SUBST([LIPO]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([LIPO]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LIPO$]) +m4trace:configure.ac:57: -1- AC_SUBST([OTOOL]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([OTOOL]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^OTOOL$]) +m4trace:configure.ac:57: -1- AC_SUBST([OTOOL64]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([OTOOL64]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^OTOOL64$]) +m4trace:configure.ac:57: -1- AC_SUBST([LT_SYS_LIBRARY_PATH]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([LT_SYS_LIBRARY_PATH]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LT_SYS_LIBRARY_PATH$]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_DLFCN_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_DLFCN_H]) +m4trace:configure.ac:57: -1- AC_SUBST([CPP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([CPP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPP$]) +m4trace:configure.ac:57: -1- AC_SUBST([CPPFLAGS]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([CPPFLAGS]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:57: -1- AC_SUBST([CPP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([CPP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPP$]) +m4trace:configure.ac:57: -1- AC_DEFINE_TRACE_LITERAL([STDC_HEADERS]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^STDC_HEADERS$]) +m4trace:configure.ac:57: -1- AH_OUTPUT([STDC_HEADERS], [/* Define to 1 if you have the ANSI C header files. */ +@%:@undef STDC_HEADERS]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_SYS_TYPES_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_SYS_TYPES_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_SYS_STAT_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_SYS_STAT_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_STDLIB_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_STDLIB_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_STRING_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_STRING_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_MEMORY_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_MEMORY_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_STRINGS_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_STRINGS_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_INTTYPES_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_INTTYPES_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_STDINT_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_STDINT_H]) +m4trace:configure.ac:57: -1- AH_OUTPUT([HAVE_UNISTD_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_UNISTD_H]) +m4trace:configure.ac:57: -1- AC_DEFINE_TRACE_LITERAL([HAVE_DLFCN_H]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^HAVE_DLFCN_H$]) +m4trace:configure.ac:57: -1- LT_SUPPORTED_TAG([CXX]) +m4trace:configure.ac:57: -1- AC_SUBST([CXXCPP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([CXXCPP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CXXCPP$]) +m4trace:configure.ac:57: -1- AC_SUBST([CPPFLAGS]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([CPPFLAGS]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CPPFLAGS$]) +m4trace:configure.ac:57: -1- AC_SUBST([CXXCPP]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([CXXCPP]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^CXXCPP$]) +m4trace:configure.ac:57: -1- AC_SUBST([LD]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([LD]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LD$]) +m4trace:configure.ac:57: -1- AC_SUBST([LT_SYS_LIBRARY_PATH]) +m4trace:configure.ac:57: -1- AC_SUBST_TRACE([LT_SYS_LIBRARY_PATH]) +m4trace:configure.ac:57: -1- m4_pattern_allow([^LT_SYS_LIBRARY_PATH$]) +m4trace:configure.ac:106: -1- AM_CONDITIONAL([WANT_SYNCAPI], [test "x$with_syncapi" != xno]) +m4trace:configure.ac:106: -1- AC_SUBST([WANT_SYNCAPI_TRUE]) +m4trace:configure.ac:106: -1- AC_SUBST_TRACE([WANT_SYNCAPI_TRUE]) +m4trace:configure.ac:106: -1- m4_pattern_allow([^WANT_SYNCAPI_TRUE$]) +m4trace:configure.ac:106: -1- AC_SUBST([WANT_SYNCAPI_FALSE]) +m4trace:configure.ac:106: -1- AC_SUBST_TRACE([WANT_SYNCAPI_FALSE]) +m4trace:configure.ac:106: -1- m4_pattern_allow([^WANT_SYNCAPI_FALSE$]) +m4trace:configure.ac:106: -1- _AM_SUBST_NOTMAKE([WANT_SYNCAPI_TRUE]) +m4trace:configure.ac:106: -1- _AM_SUBST_NOTMAKE([WANT_SYNCAPI_FALSE]) +m4trace:configure.ac:109: -1- AC_DEFINE_TRACE_LITERAL([STDC_HEADERS]) +m4trace:configure.ac:109: -1- m4_pattern_allow([^STDC_HEADERS$]) +m4trace:configure.ac:109: -1- AH_OUTPUT([STDC_HEADERS], [/* Define to 1 if you have the ANSI C header files. */ +@%:@undef STDC_HEADERS]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_ARPA_INET_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_ARPA_INET_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_FCNTL_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_FCNTL_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_NETDB_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_NETDB_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_NETINET_IN_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_NETINET_IN_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_STDLIB_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_STDLIB_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_STRING_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_STRING_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_SYS_SOCKET_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_SYS_SOCKET_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_SYS_TIME_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_SYS_TIME_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_UNISTD_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_UNISTD_H]) +m4trace:configure.ac:110: -1- AH_OUTPUT([HAVE_SYS_UTSNAME_H], [/* Define to 1 if you have the header file. */ +@%:@undef HAVE_SYS_UTSNAME_H]) +m4trace:configure.ac:113: -1- AC_DEFINE_TRACE_LITERAL([const]) +m4trace:configure.ac:113: -1- m4_pattern_allow([^const$]) +m4trace:configure.ac:113: -1- AH_OUTPUT([const], [/* Define to empty if `const\' does not conform to ANSI C. */ +@%:@undef const]) +m4trace:configure.ac:114: -1- AH_OUTPUT([inline], [/* Define to `__inline__\' or `__inline\' if that\'s what the C compiler + calls it, or to nothing if \'inline\' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif]) +m4trace:configure.ac:115: -1- AC_DEFINE_TRACE_LITERAL([TIME_WITH_SYS_TIME]) +m4trace:configure.ac:115: -1- m4_pattern_allow([^TIME_WITH_SYS_TIME$]) +m4trace:configure.ac:115: -1- AH_OUTPUT([TIME_WITH_SYS_TIME], [/* Define to 1 if you can safely include both and . */ +@%:@undef TIME_WITH_SYS_TIME]) +m4trace:configure.ac:119: -1- AC_DEFINE_TRACE_LITERAL([POLL_NFDS_TYPE]) +m4trace:configure.ac:119: -1- m4_pattern_allow([^POLL_NFDS_TYPE$]) +m4trace:configure.ac:119: -1- AH_OUTPUT([POLL_NFDS_TYPE], [/* poll() second argument type */ +@%:@undef POLL_NFDS_TYPE]) +m4trace:configure.ac:119: -1- AC_DEFINE_TRACE_LITERAL([POLL_NFDS_TYPE]) +m4trace:configure.ac:119: -1- m4_pattern_allow([^POLL_NFDS_TYPE$]) +m4trace:configure.ac:119: -1- AH_OUTPUT([POLL_NFDS_TYPE], [/* poll() second argument type */ +@%:@undef POLL_NFDS_TYPE]) +m4trace:configure.ac:138: -1- _m4_warn([obsolete], [The macro `AC_TRY_RUN' is obsolete. +You should run autoupdate.], [../../lib/autoconf/general.m4:2765: AC_TRY_RUN is expanded from... +configure.ac:138: the top level]) +m4trace:configure.ac:142: -1- AC_SUBST([USEIPV6]) +m4trace:configure.ac:142: -1- AC_SUBST_TRACE([USEIPV6]) +m4trace:configure.ac:142: -1- m4_pattern_allow([^USEIPV6$]) +m4trace:configure.ac:148: -1- AH_OUTPUT([HAVE_LIBRT], [/* Define to 1 if you have the `rt\' library (-lrt). */ +@%:@undef HAVE_LIBRT]) +m4trace:configure.ac:148: -1- AC_DEFINE_TRACE_LITERAL([HAVE_LIBRT]) +m4trace:configure.ac:148: -1- m4_pattern_allow([^HAVE_LIBRT$]) +m4trace:configure.ac:150: -1- AC_SUBST([CLOCK_GETTIME_LIBS]) +m4trace:configure.ac:150: -1- AC_SUBST_TRACE([CLOCK_GETTIME_LIBS]) +m4trace:configure.ac:150: -1- m4_pattern_allow([^CLOCK_GETTIME_LIBS$]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_GETCWD], [/* Define to 1 if you have the `getcwd\' function. */ +@%:@undef HAVE_GETCWD]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_GETHOSTBYNAME], [/* Define to 1 if you have the `gethostbyname\' function. */ +@%:@undef HAVE_GETHOSTBYNAME]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_GETHOSTNAME], [/* Define to 1 if you have the `gethostname\' function. */ +@%:@undef HAVE_GETHOSTNAME]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_GETLOGIN], [/* Define to 1 if you have the `getlogin\' function. */ +@%:@undef HAVE_GETLOGIN]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_GETPWUID_R], [/* Define to 1 if you have the `getpwuid_r\' function. */ +@%:@undef HAVE_GETPWUID_R]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_GETTIMEOFDAY], [/* Define to 1 if you have the `gettimeofday\' function. */ +@%:@undef HAVE_GETTIMEOFDAY]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_GETUID], [/* Define to 1 if you have the `getuid\' function. */ +@%:@undef HAVE_GETUID]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_MEMMOVE], [/* Define to 1 if you have the `memmove\' function. */ +@%:@undef HAVE_MEMMOVE]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_MEMSET], [/* Define to 1 if you have the `memset\' function. */ +@%:@undef HAVE_MEMSET]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_POLL], [/* Define to 1 if you have the `poll\' function. */ +@%:@undef HAVE_POLL]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_SOCKET], [/* Define to 1 if you have the `socket\' function. */ +@%:@undef HAVE_SOCKET]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_STRCHR], [/* Define to 1 if you have the `strchr\' function. */ +@%:@undef HAVE_STRCHR]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_STRDUP], [/* Define to 1 if you have the `strdup\' function. */ +@%:@undef HAVE_STRDUP]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_STRERROR], [/* Define to 1 if you have the `strerror\' function. */ +@%:@undef HAVE_STRERROR]) +m4trace:configure.ac:154: -1- AH_OUTPUT([HAVE_STRTOL], [/* Define to 1 if you have the `strtol\' function. */ +@%:@undef HAVE_STRTOL]) +m4trace:configure.ac:156: -1- AC_CONFIG_FILES([Makefile]) +m4trace:configure.ac:157: -1- AC_CANONICAL_HOST +m4trace:configure.ac:166: -1- AM_CONDITIONAL([SOLARIS], [ + case "$host_os" in + *solaris*) + true + ;; + *) + false + ;; + esac ]) +m4trace:configure.ac:166: -1- AC_SUBST([SOLARIS_TRUE]) +m4trace:configure.ac:166: -1- AC_SUBST_TRACE([SOLARIS_TRUE]) +m4trace:configure.ac:166: -1- m4_pattern_allow([^SOLARIS_TRUE$]) +m4trace:configure.ac:166: -1- AC_SUBST([SOLARIS_FALSE]) +m4trace:configure.ac:166: -1- AC_SUBST_TRACE([SOLARIS_FALSE]) +m4trace:configure.ac:166: -1- m4_pattern_allow([^SOLARIS_FALSE$]) +m4trace:configure.ac:166: -1- _AM_SUBST_NOTMAKE([SOLARIS_TRUE]) +m4trace:configure.ac:166: -1- _AM_SUBST_NOTMAKE([SOLARIS_FALSE]) +m4trace:configure.ac:167: -1- AC_SUBST([LIB@&t@OBJS], [$ac_libobjs]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([LIB@&t@OBJS]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^LIB@&t@OBJS$]) +m4trace:configure.ac:167: -1- AC_SUBST([LTLIBOBJS], [$ac_ltlibobjs]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([LTLIBOBJS]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^LTLIBOBJS$]) +m4trace:configure.ac:167: -1- AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"]) +m4trace:configure.ac:167: -1- AC_SUBST([am__EXEEXT_TRUE]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([am__EXEEXT_TRUE]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^am__EXEEXT_TRUE$]) +m4trace:configure.ac:167: -1- AC_SUBST([am__EXEEXT_FALSE]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([am__EXEEXT_FALSE]) +m4trace:configure.ac:167: -1- m4_pattern_allow([^am__EXEEXT_FALSE$]) +m4trace:configure.ac:167: -1- _AM_SUBST_NOTMAKE([am__EXEEXT_TRUE]) +m4trace:configure.ac:167: -1- _AM_SUBST_NOTMAKE([am__EXEEXT_FALSE]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([top_builddir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([top_build_prefix]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([srcdir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([abs_srcdir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([top_srcdir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([abs_top_srcdir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([builddir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([abs_builddir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([abs_top_builddir]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([INSTALL]) +m4trace:configure.ac:167: -1- AC_SUBST_TRACE([MKDIR_P]) +m4trace:configure.ac:167: -1- AC_REQUIRE_AUX_FILE([ltmain.sh]) diff --git a/src/c/c-doc.Doxyfile b/src/c/c-doc.Doxyfile new file mode 100644 index 00000000000..e9029cb1745 --- /dev/null +++ b/src/c/c-doc.Doxyfile @@ -0,0 +1,1252 @@ +# Doxyfile 1.4.7 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = $(PROJECT)-$(VERSION) + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = $(DOCDIR) + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST = YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = include/zookeeper.h + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = $(GENERATE_HTML) + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = $(GENERATE_HTMLHELP) + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = ../$(PROJECT).chm + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = $(HHC_PATH) + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = $(GENERATE_CHI) + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = $(GENERATE_LATEX) + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = $(PAPER_SIZE) + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = $(GENERATE_PDF) + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = $(GENERATE_RTF) + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = $(GENERATE_MAN) + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = $(GENERATE_XML) + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = $(DOCDIR)/$(PROJECT).tag + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = $(HAVE_DOT) + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = $(DOT_PATH) + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/src/c/configure b/src/c/configure new file mode 100755 index 00000000000..bbec2057e4b --- /dev/null +++ b/src/c/configure @@ -0,0 +1,21092 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.69 for zookeeper C client 3.6.0. +# +# Report bugs to . +# +# +# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 + + test -n \"\${ZSH_VERSION+set}\${BASH_VERSION+set}\" || ( + ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + PATH=/empty FPATH=/empty; export PATH FPATH + test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ + || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in #( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org and +$0: user@zookeeper.apache.org about your system, including +$0: any error possibly output before this message. Then +$0: install a modern shell, or manually run the script +$0: under such a shell if you do have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + +SHELL=${CONFIG_SHELL-/bin/sh} + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='zookeeper C client' +PACKAGE_TARNAME='zookeeper' +PACKAGE_VERSION='3.6.0' +PACKAGE_STRING='zookeeper C client 3.6.0' +PACKAGE_BUGREPORT='user@zookeeper.apache.org' +PACKAGE_URL='' + +ac_unique_file="src/zookeeper.c" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='am__EXEEXT_FALSE +am__EXEEXT_TRUE +LTLIBOBJS +LIBOBJS +SOLARIS_FALSE +SOLARIS_TRUE +CLOCK_GETTIME_LIBS +USEIPV6 +WANT_SYNCAPI_FALSE +WANT_SYNCAPI_TRUE +CXXCPP +CPP +LT_SYS_LIBRARY_PATH +OTOOL64 +OTOOL +LIPO +NMEDIT +DSYMUTIL +MANIFEST_TOOL +RANLIB +ac_ct_AR +AR +DLLTOOL +OBJDUMP +NM +ac_ct_DUMPBIN +DUMPBIN +LD +FGREP +EGREP +GREP +SED +host_os +host_vendor +host_cpu +host +build_os +build_vendor +build_cpu +build +LIBTOOL +LN_S +am__fastdepCXX_FALSE +am__fastdepCXX_TRUE +CXXDEPMODE +ac_ct_CXX +CXXFLAGS +CXX +am__fastdepCC_FALSE +am__fastdepCC_TRUE +CCDEPMODE +am__nodep +AMDEPBACKSLASH +AMDEP_FALSE +AMDEP_TRUE +am__quote +am__include +DEPDIR +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +CPPUNIT_CFLAGS +AM_BACKSLASH +AM_DEFAULT_VERBOSITY +AM_DEFAULT_V +AM_V +am__untar +am__tar +AMTAR +am__leading_dot +SET_MAKE +AWK +mkdir_p +MKDIR_P +INSTALL_STRIP_PROGRAM +STRIP +install_sh +MAKEINFO +AUTOHEADER +AUTOMAKE +AUTOCONF +ACLOCAL +VERSION +PACKAGE +CYGPATH_W +am__isrc +INSTALL_DATA +INSTALL_SCRIPT +INSTALL_PROGRAM +DOXYGEN_PAPER_SIZE +DX_COND_latex_FALSE +DX_COND_latex_TRUE +DX_COND_pdf_FALSE +DX_COND_pdf_TRUE +DX_PDFLATEX +DX_FLAG_pdf +DX_COND_ps_FALSE +DX_COND_ps_TRUE +DX_EGREP +DX_DVIPS +DX_MAKEINDEX +DX_LATEX +DX_FLAG_ps +DX_COND_html_FALSE +DX_COND_html_TRUE +DX_FLAG_html +DX_COND_chi_FALSE +DX_COND_chi_TRUE +DX_FLAG_chi +DX_COND_chm_FALSE +DX_COND_chm_TRUE +DX_HHC +DX_FLAG_chm +DX_COND_xml_FALSE +DX_COND_xml_TRUE +DX_FLAG_xml +DX_COND_rtf_FALSE +DX_COND_rtf_TRUE +DX_FLAG_rtf +DX_COND_man_FALSE +DX_COND_man_TRUE +DX_FLAG_man +DX_COND_dot_FALSE +DX_COND_dot_TRUE +DX_DOT +DX_FLAG_dot +DX_COND_doc_FALSE +DX_COND_doc_TRUE +DX_PERL +DX_DOXYGEN +DX_FLAG_doc +DX_ENV +DX_DOCDIR +DX_CONFIG +DX_PROJECT +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +enable_doxygen_doc +enable_doxygen_dot +enable_doxygen_man +enable_doxygen_rtf +enable_doxygen_xml +enable_doxygen_chm +enable_doxygen_chi +enable_doxygen_html +enable_doxygen_ps +enable_doxygen_pdf +enable_silent_rules +with_cppunit +enable_dependency_tracking +enable_shared +enable_static +with_pic +enable_fast_install +with_aix_soname +with_gnu_ld +with_sysroot +enable_libtool_lock +enable_debug +with_syncapi +' + ac_precious_vars='build_alias +host_alias +target_alias +DOXYGEN_PAPER_SIZE +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CXX +CXXFLAGS +CCC +LT_SYS_LIBRARY_PATH +CPP +CXXCPP' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *=) ac_optarg= ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error $? "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error $? "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error $? "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures zookeeper C client 3.6.0 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking ...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/zookeeper] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +Program names: + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM run sed PROGRAM on installed program names + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of zookeeper C client 3.6.0:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-doxygen-doc don't generate any doxygen documentation + --disable-doxygen-dot don't generate graphics for doxygen documentation + --enable-doxygen-man generate doxygen manual pages + --enable-doxygen-rtf generate doxygen RTF documentation + --enable-doxygen-xml generate doxygen XML documentation + --enable-doxygen-chm generate doxygen compressed HTML help documentation + --enable-doxygen-chi generate doxygen seperate compressed HTML help index + file + --disable-doxygen-html don't generate doxygen plain HTML documentation + --enable-doxygen-ps generate doxygen PostScript documentation + --enable-doxygen-pdf generate doxygen PDF documentation + --enable-silent-rules less verbose build output (undo: "make V=1") + --disable-silent-rules verbose build output (undo: "make V=0") + --enable-dependency-tracking + do not reject slow dependency extractors + --disable-dependency-tracking + speeds up one-time build + --enable-shared[=PKGS] build shared libraries [default=yes] + --enable-static[=PKGS] build static libraries [default=yes] + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) + --enable-debug enable debug build [default=no] + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --without-cppunit do not use CPPUNIT + --with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use + both] + --with-aix-soname=aix|svr4|both + shared library versioning (aka "SONAME") variant to + provide on AIX, [default=aix]. + --with-gnu-ld assume the C compiler uses GNU ld [default=no] + --with-sysroot[=DIR] Search for dependent libraries within DIR (or the + compiler's sysroot if not specified). + --with-syncapi build with support for SyncAPI [default=yes] + +Some influential environment variables: + DOXYGEN_PAPER_SIZE + a4wide (default), a4, letter, legal or executive + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CXX C++ compiler command + CXXFLAGS C++ compiler flags + LT_SYS_LIBRARY_PATH + User-defined run-time library search path. + CPP C preprocessor + CXXCPP C++ preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +zookeeper C client configure 3.6.0 +generated by GNU Autoconf 2.69 + +Copyright (C) 2012 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +# ac_fn_c_try_compile LINENO +# -------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_compile + +# ac_fn_cxx_try_compile LINENO +# ---------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_cxx_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_cxx_try_compile + +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + +# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists and can be compiled using the include files in +# INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_compile + +# ac_fn_c_try_cpp LINENO +# ---------------------- +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_cpp + +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_func + +# ac_fn_cxx_try_cpp LINENO +# ------------------------ +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_cxx_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_cxx_try_cpp + +# ac_fn_cxx_try_link LINENO +# ------------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_cxx_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_cxx_try_link + +# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists, giving a warning if it cannot be compiled using +# the include files in INCLUDES and setting the cache variable VAR +# accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if eval \${$3+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.i conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( $as_echo "## ---------------------------------------- ## +## Report this to user@zookeeper.apache.org ## +## ---------------------------------------- ##" + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_mongrel + +# ac_fn_c_check_type LINENO TYPE VAR INCLUDES +# ------------------------------------------- +# Tests whether TYPE exists after having included INCLUDES, setting cache +# variable VAR accordingly. +ac_fn_c_check_type () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=no" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof ($2)) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof (($2))) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + eval "$3=yes" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_type +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by zookeeper C client $as_me 3.6.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + $as_echo "## ---------------- ## +## Cache variables. ## +## ---------------- ##" + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + $as_echo "## ----------------- ## +## Output variables. ## +## ----------------- ##" + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + $as_echo "## ------------------- ## +## File substitutions. ## +## ------------------- ##" + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + $as_echo "## ----------- ## +## confdefs.h. ## +## ----------- ##" + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + # We do not want a PATH search for config.site. + case $CONFIG_SITE in #(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" \ + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + +# Save initial CFLAGS and CXXFLAGS values before AC_PROG_CC and AC_PROG_CXX +init_cflags="$CFLAGS" +init_cxxflags="$CXXFLAGS" + +# initialize Doxygen support + + + + + + + + + + +# Files: +DX_PROJECT=zookeeper + +DX_CONFIG=c-doc.Doxyfile + +DX_DOCDIR=docs + + +# Environment variables used inside doxygen.cfg: +DX_ENV="$DX_ENV SRCDIR='$srcdir'" + +DX_ENV="$DX_ENV PROJECT='$DX_PROJECT'" + +DX_ENV="$DX_ENV DOCDIR='$DX_DOCDIR'" + +DX_ENV="$DX_ENV VERSION='$PACKAGE_VERSION'" + + +# Doxygen itself: + + + + # Check whether --enable-doxygen-doc was given. +if test "${enable_doxygen_doc+set}" = set; then : + enableval=$enable_doxygen_doc; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_doc=1 + + +;; #( +n|N|no|No|NO) + DX_FLAG_doc=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-doc" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_doc=1 + + + +fi + +if test "$DX_FLAG_doc" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}doxygen", so it can be a program name with args. +set dummy ${ac_tool_prefix}doxygen; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DOXYGEN+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DOXYGEN in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DOXYGEN="$DX_DOXYGEN" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DOXYGEN=$ac_cv_path_DX_DOXYGEN +if test -n "$DX_DOXYGEN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOXYGEN" >&5 +$as_echo "$DX_DOXYGEN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DOXYGEN"; then + ac_pt_DX_DOXYGEN=$DX_DOXYGEN + # Extract the first word of "doxygen", so it can be a program name with args. +set dummy doxygen; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DOXYGEN+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DOXYGEN in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DOXYGEN="$ac_pt_DX_DOXYGEN" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DOXYGEN="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DOXYGEN=$ac_cv_path_ac_pt_DX_DOXYGEN +if test -n "$ac_pt_DX_DOXYGEN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOXYGEN" >&5 +$as_echo "$ac_pt_DX_DOXYGEN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DOXYGEN" = x; then + DX_DOXYGEN="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DOXYGEN=$ac_pt_DX_DOXYGEN + fi +else + DX_DOXYGEN="$ac_cv_path_DX_DOXYGEN" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DOXYGEN" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: doxygen not found - will not generate any doxygen documentation" >&5 +$as_echo "$as_me: WARNING: doxygen not found - will not generate any doxygen documentation" >&2;} + DX_FLAG_doc=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}perl", so it can be a program name with args. +set dummy ${ac_tool_prefix}perl; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_PERL+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_PERL in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_PERL="$DX_PERL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_PERL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_PERL=$ac_cv_path_DX_PERL +if test -n "$DX_PERL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PERL" >&5 +$as_echo "$DX_PERL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_PERL"; then + ac_pt_DX_PERL=$DX_PERL + # Extract the first word of "perl", so it can be a program name with args. +set dummy perl; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_PERL+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_PERL in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_PERL="$ac_pt_DX_PERL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_PERL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_PERL=$ac_cv_path_ac_pt_DX_PERL +if test -n "$ac_pt_DX_PERL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PERL" >&5 +$as_echo "$ac_pt_DX_PERL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_PERL" = x; then + DX_PERL="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_PERL=$ac_pt_DX_PERL + fi +else + DX_PERL="$ac_cv_path_DX_PERL" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_PERL" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: perl not found - will not generate any doxygen documentation" >&5 +$as_echo "$as_me: WARNING: perl not found - will not generate any doxygen documentation" >&2;} + DX_FLAG_doc=0 + +fi + + : +fi +if test "$DX_FLAG_doc" = 1; then + if :; then + DX_COND_doc_TRUE= + DX_COND_doc_FALSE='#' +else + DX_COND_doc_TRUE='#' + DX_COND_doc_FALSE= +fi + + DX_ENV="$DX_ENV PERL_PATH='$DX_PERL'" + + : +else + if false; then + DX_COND_doc_TRUE= + DX_COND_doc_FALSE='#' +else + DX_COND_doc_TRUE='#' + DX_COND_doc_FALSE= +fi + + + : +fi + + +# Dot for graphics: + + + + # Check whether --enable-doxygen-dot was given. +if test "${enable_doxygen_dot+set}" = set; then : + enableval=$enable_doxygen_dot; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_dot=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-dot requires doxygen-dot" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_dot=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-dot" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_dot=1 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_dot=0 + + + +fi + +if test "$DX_FLAG_dot" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dot", so it can be a program name with args. +set dummy ${ac_tool_prefix}dot; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DOT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DOT in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DOT="$DX_DOT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DOT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DOT=$ac_cv_path_DX_DOT +if test -n "$DX_DOT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DOT" >&5 +$as_echo "$DX_DOT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DOT"; then + ac_pt_DX_DOT=$DX_DOT + # Extract the first word of "dot", so it can be a program name with args. +set dummy dot; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DOT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DOT in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DOT="$ac_pt_DX_DOT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DOT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DOT=$ac_cv_path_ac_pt_DX_DOT +if test -n "$ac_pt_DX_DOT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DOT" >&5 +$as_echo "$ac_pt_DX_DOT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DOT" = x; then + DX_DOT="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DOT=$ac_pt_DX_DOT + fi +else + DX_DOT="$ac_cv_path_DX_DOT" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DOT" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dot not found - will not generate graphics for doxygen documentation" >&5 +$as_echo "$as_me: WARNING: dot not found - will not generate graphics for doxygen documentation" >&2;} + DX_FLAG_dot=0 + +fi + + : +fi +if test "$DX_FLAG_dot" = 1; then + if :; then + DX_COND_dot_TRUE= + DX_COND_dot_FALSE='#' +else + DX_COND_dot_TRUE='#' + DX_COND_dot_FALSE= +fi + + DX_ENV="$DX_ENV HAVE_DOT='YES'" + + DX_ENV="$DX_ENV DOT_PATH='`expr ".$DX_DOT" : '\(\.\)[^/]*$' \| "x$DX_DOT" : 'x\(.*\)/[^/]*$'`'" + + : +else + if false; then + DX_COND_dot_TRUE= + DX_COND_dot_FALSE='#' +else + DX_COND_dot_TRUE='#' + DX_COND_dot_FALSE= +fi + + DX_ENV="$DX_ENV HAVE_DOT='NO'" + + : +fi + + +# Man pages generation: + + + + # Check whether --enable-doxygen-man was given. +if test "${enable_doxygen_man+set}" = set; then : + enableval=$enable_doxygen_man; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_man=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-man requires doxygen-man" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_man=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-man" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_man=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_man=0 + + + +fi + +if test "$DX_FLAG_man" = 1; then + + : +fi +if test "$DX_FLAG_man" = 1; then + if :; then + DX_COND_man_TRUE= + DX_COND_man_FALSE='#' +else + DX_COND_man_TRUE='#' + DX_COND_man_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_MAN='YES'" + + : +else + if false; then + DX_COND_man_TRUE= + DX_COND_man_FALSE='#' +else + DX_COND_man_TRUE='#' + DX_COND_man_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_MAN='NO'" + + : +fi + + +# RTF file generation: + + + + # Check whether --enable-doxygen-rtf was given. +if test "${enable_doxygen_rtf+set}" = set; then : + enableval=$enable_doxygen_rtf; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_rtf=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-rtf requires doxygen-rtf" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_rtf=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-rtf" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_rtf=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_rtf=0 + + + +fi + +if test "$DX_FLAG_rtf" = 1; then + + : +fi +if test "$DX_FLAG_rtf" = 1; then + if :; then + DX_COND_rtf_TRUE= + DX_COND_rtf_FALSE='#' +else + DX_COND_rtf_TRUE='#' + DX_COND_rtf_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_RTF='YES'" + + : +else + if false; then + DX_COND_rtf_TRUE= + DX_COND_rtf_FALSE='#' +else + DX_COND_rtf_TRUE='#' + DX_COND_rtf_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_RTF='NO'" + + : +fi + + +# XML file generation: + + + + # Check whether --enable-doxygen-xml was given. +if test "${enable_doxygen_xml+set}" = set; then : + enableval=$enable_doxygen_xml; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_xml=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-xml requires doxygen-xml" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_xml=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-xml" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_xml=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_xml=0 + + + +fi + +if test "$DX_FLAG_xml" = 1; then + + : +fi +if test "$DX_FLAG_xml" = 1; then + if :; then + DX_COND_xml_TRUE= + DX_COND_xml_FALSE='#' +else + DX_COND_xml_TRUE='#' + DX_COND_xml_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_XML='YES'" + + : +else + if false; then + DX_COND_xml_TRUE= + DX_COND_xml_FALSE='#' +else + DX_COND_xml_TRUE='#' + DX_COND_xml_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_XML='NO'" + + : +fi + + +# (Compressed) HTML help generation: + + + + # Check whether --enable-doxygen-chm was given. +if test "${enable_doxygen_chm+set}" = set; then : + enableval=$enable_doxygen_chm; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_chm=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-chm requires doxygen-chm" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_chm=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-chm" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_chm=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_chm=0 + + + +fi + +if test "$DX_FLAG_chm" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}hhc", so it can be a program name with args. +set dummy ${ac_tool_prefix}hhc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_HHC+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_HHC in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_HHC="$DX_HHC" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_HHC="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_HHC=$ac_cv_path_DX_HHC +if test -n "$DX_HHC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_HHC" >&5 +$as_echo "$DX_HHC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_HHC"; then + ac_pt_DX_HHC=$DX_HHC + # Extract the first word of "hhc", so it can be a program name with args. +set dummy hhc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_HHC+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_HHC in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_HHC="$ac_pt_DX_HHC" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_HHC="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_HHC=$ac_cv_path_ac_pt_DX_HHC +if test -n "$ac_pt_DX_HHC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_HHC" >&5 +$as_echo "$ac_pt_DX_HHC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_HHC" = x; then + DX_HHC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_HHC=$ac_pt_DX_HHC + fi +else + DX_HHC="$ac_cv_path_DX_HHC" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_HHC" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&5 +$as_echo "$as_me: WARNING: hhc not found - will not generate doxygen compressed HTML help documentation" >&2;} + DX_FLAG_chm=0 + +fi + + : +fi +if test "$DX_FLAG_chm" = 1; then + if :; then + DX_COND_chm_TRUE= + DX_COND_chm_FALSE='#' +else + DX_COND_chm_TRUE='#' + DX_COND_chm_FALSE= +fi + + DX_ENV="$DX_ENV HHC_PATH='$DX_HHC'" + + DX_ENV="$DX_ENV GENERATE_HTML='YES'" + + DX_ENV="$DX_ENV GENERATE_HTMLHELP='YES'" + + : +else + if false; then + DX_COND_chm_TRUE= + DX_COND_chm_FALSE='#' +else + DX_COND_chm_TRUE='#' + DX_COND_chm_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_HTMLHELP='NO'" + + : +fi + + +# Seperate CHI file generation. + + + + # Check whether --enable-doxygen-chi was given. +if test "${enable_doxygen_chi+set}" = set; then : + enableval=$enable_doxygen_chi; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_chi=1 + + +test "$DX_FLAG_chm" = "1" \ +|| as_fn_error $? "doxygen-chi requires doxygen-chi" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_chi=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-chi" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_chi=0 + + +test "$DX_FLAG_chm" = "1" || DX_FLAG_chi=0 + + + +fi + +if test "$DX_FLAG_chi" = 1; then + + : +fi +if test "$DX_FLAG_chi" = 1; then + if :; then + DX_COND_chi_TRUE= + DX_COND_chi_FALSE='#' +else + DX_COND_chi_TRUE='#' + DX_COND_chi_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_CHI='YES'" + + : +else + if false; then + DX_COND_chi_TRUE= + DX_COND_chi_FALSE='#' +else + DX_COND_chi_TRUE='#' + DX_COND_chi_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_CHI='NO'" + + : +fi + + +# Plain HTML pages generation: + + + + # Check whether --enable-doxygen-html was given. +if test "${enable_doxygen_html+set}" = set; then : + enableval=$enable_doxygen_html; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_html=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-html requires doxygen-html" "$LINENO" 5 + +test "$DX_FLAG_chm" = "0" \ +|| as_fn_error $? "doxygen-html contradicts doxygen-html" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_html=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-html" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_html=1 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_html=0 + + +test "$DX_FLAG_chm" = "0" || DX_FLAG_html=0 + + + +fi + +if test "$DX_FLAG_html" = 1; then + + : +fi +if test "$DX_FLAG_html" = 1; then + if :; then + DX_COND_html_TRUE= + DX_COND_html_FALSE='#' +else + DX_COND_html_TRUE='#' + DX_COND_html_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_HTML='YES'" + + : +else + if false; then + DX_COND_html_TRUE= + DX_COND_html_FALSE='#' +else + DX_COND_html_TRUE='#' + DX_COND_html_FALSE= +fi + + test "$DX_FLAG_chm" = 1 || DX_ENV="$DX_ENV GENERATE_HTML='NO'" + + : +fi + + +# PostScript file generation: + + + + # Check whether --enable-doxygen-ps was given. +if test "${enable_doxygen_ps+set}" = set; then : + enableval=$enable_doxygen_ps; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_ps=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-ps requires doxygen-ps" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_ps=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-ps" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_ps=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_ps=0 + + + +fi + +if test "$DX_FLAG_ps" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}latex", so it can be a program name with args. +set dummy ${ac_tool_prefix}latex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_LATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_LATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_LATEX="$DX_LATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_LATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_LATEX=$ac_cv_path_DX_LATEX +if test -n "$DX_LATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_LATEX" >&5 +$as_echo "$DX_LATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_LATEX"; then + ac_pt_DX_LATEX=$DX_LATEX + # Extract the first word of "latex", so it can be a program name with args. +set dummy latex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_LATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_LATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_LATEX="$ac_pt_DX_LATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_LATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_LATEX=$ac_cv_path_ac_pt_DX_LATEX +if test -n "$ac_pt_DX_LATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_LATEX" >&5 +$as_echo "$ac_pt_DX_LATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_LATEX" = x; then + DX_LATEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_LATEX=$ac_pt_DX_LATEX + fi +else + DX_LATEX="$ac_cv_path_DX_LATEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_LATEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: latex not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: latex not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args. +set dummy ${ac_tool_prefix}makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX +if test -n "$DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5 +$as_echo "$DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_MAKEINDEX"; then + ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX + # Extract the first word of "makeindex", so it can be a program name with args. +set dummy makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX +if test -n "$ac_pt_DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5 +$as_echo "$ac_pt_DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_MAKEINDEX" = x; then + DX_MAKEINDEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX + fi +else + DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_MAKEINDEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dvips", so it can be a program name with args. +set dummy ${ac_tool_prefix}dvips; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_DVIPS+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_DVIPS in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_DVIPS="$DX_DVIPS" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_DVIPS=$ac_cv_path_DX_DVIPS +if test -n "$DX_DVIPS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_DVIPS" >&5 +$as_echo "$DX_DVIPS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_DVIPS"; then + ac_pt_DX_DVIPS=$DX_DVIPS + # Extract the first word of "dvips", so it can be a program name with args. +set dummy dvips; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_DVIPS+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_DVIPS in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_DVIPS="$ac_pt_DX_DVIPS" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_DVIPS="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_DVIPS=$ac_cv_path_ac_pt_DX_DVIPS +if test -n "$ac_pt_DX_DVIPS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_DVIPS" >&5 +$as_echo "$ac_pt_DX_DVIPS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_DVIPS" = x; then + DX_DVIPS="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_DVIPS=$ac_pt_DX_DVIPS + fi +else + DX_DVIPS="$ac_cv_path_DX_DVIPS" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_DVIPS" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: dvips not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args. +set dummy ${ac_tool_prefix}egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_EGREP=$ac_cv_path_DX_EGREP +if test -n "$DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5 +$as_echo "$DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_EGREP"; then + ac_pt_DX_EGREP=$DX_EGREP + # Extract the first word of "egrep", so it can be a program name with args. +set dummy egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP +if test -n "$ac_pt_DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5 +$as_echo "$ac_pt_DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_EGREP" = x; then + DX_EGREP="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_EGREP=$ac_pt_DX_EGREP + fi +else + DX_EGREP="$ac_cv_path_DX_EGREP" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_EGREP" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&5 +$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PostScript documentation" >&2;} + DX_FLAG_ps=0 + +fi + + : +fi +if test "$DX_FLAG_ps" = 1; then + if :; then + DX_COND_ps_TRUE= + DX_COND_ps_FALSE='#' +else + DX_COND_ps_TRUE='#' + DX_COND_ps_FALSE= +fi + + + : +else + if false; then + DX_COND_ps_TRUE= + DX_COND_ps_FALSE='#' +else + DX_COND_ps_TRUE='#' + DX_COND_ps_FALSE= +fi + + + : +fi + + +# PDF file generation: + + + + # Check whether --enable-doxygen-pdf was given. +if test "${enable_doxygen_pdf+set}" = set; then : + enableval=$enable_doxygen_pdf; +case "$enableval" in +#( +y|Y|yes|Yes|YES) + DX_FLAG_pdf=1 + + +test "$DX_FLAG_doc" = "1" \ +|| as_fn_error $? "doxygen-pdf requires doxygen-pdf" "$LINENO" 5 + +;; #( +n|N|no|No|NO) + DX_FLAG_pdf=0 + +;; #( +*) + as_fn_error $? "invalid value '$enableval' given to doxygen-pdf" "$LINENO" 5 +;; +esac + +else + +DX_FLAG_pdf=0 + + +test "$DX_FLAG_doc" = "1" || DX_FLAG_pdf=0 + + + +fi + +if test "$DX_FLAG_pdf" = 1; then + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pdflatex", so it can be a program name with args. +set dummy ${ac_tool_prefix}pdflatex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_PDFLATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_PDFLATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_PDFLATEX="$DX_PDFLATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_PDFLATEX=$ac_cv_path_DX_PDFLATEX +if test -n "$DX_PDFLATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_PDFLATEX" >&5 +$as_echo "$DX_PDFLATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_PDFLATEX"; then + ac_pt_DX_PDFLATEX=$DX_PDFLATEX + # Extract the first word of "pdflatex", so it can be a program name with args. +set dummy pdflatex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_PDFLATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_PDFLATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_PDFLATEX="$ac_pt_DX_PDFLATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_PDFLATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_PDFLATEX=$ac_cv_path_ac_pt_DX_PDFLATEX +if test -n "$ac_pt_DX_PDFLATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_PDFLATEX" >&5 +$as_echo "$ac_pt_DX_PDFLATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_PDFLATEX" = x; then + DX_PDFLATEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_PDFLATEX=$ac_pt_DX_PDFLATEX + fi +else + DX_PDFLATEX="$ac_cv_path_DX_PDFLATEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_PDFLATEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: pdflatex not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}makeindex", so it can be a program name with args. +set dummy ${ac_tool_prefix}makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_MAKEINDEX="$DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_MAKEINDEX=$ac_cv_path_DX_MAKEINDEX +if test -n "$DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_MAKEINDEX" >&5 +$as_echo "$DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_MAKEINDEX"; then + ac_pt_DX_MAKEINDEX=$DX_MAKEINDEX + # Extract the first word of "makeindex", so it can be a program name with args. +set dummy makeindex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_MAKEINDEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_MAKEINDEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_MAKEINDEX="$ac_pt_DX_MAKEINDEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_MAKEINDEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_MAKEINDEX=$ac_cv_path_ac_pt_DX_MAKEINDEX +if test -n "$ac_pt_DX_MAKEINDEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_MAKEINDEX" >&5 +$as_echo "$ac_pt_DX_MAKEINDEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_MAKEINDEX" = x; then + DX_MAKEINDEX="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_MAKEINDEX=$ac_pt_DX_MAKEINDEX + fi +else + DX_MAKEINDEX="$ac_cv_path_DX_MAKEINDEX" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_MAKEINDEX" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: makeindex not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}egrep", so it can be a program name with args. +set dummy ${ac_tool_prefix}egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_DX_EGREP="$DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DX_EGREP=$ac_cv_path_DX_EGREP +if test -n "$DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DX_EGREP" >&5 +$as_echo "$DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_DX_EGREP"; then + ac_pt_DX_EGREP=$DX_EGREP + # Extract the first word of "egrep", so it can be a program name with args. +set dummy egrep; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_DX_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_DX_EGREP in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_DX_EGREP="$ac_pt_DX_EGREP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_DX_EGREP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_DX_EGREP=$ac_cv_path_ac_pt_DX_EGREP +if test -n "$ac_pt_DX_EGREP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_DX_EGREP" >&5 +$as_echo "$ac_pt_DX_EGREP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_DX_EGREP" = x; then + DX_EGREP="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DX_EGREP=$ac_pt_DX_EGREP + fi +else + DX_EGREP="$ac_cv_path_DX_EGREP" +fi + +if test "$DX_FLAG_$DX_CURRENT_FEATURE$DX_EGREP" = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: egrep not found - will not generate doxygen PDF documentation" >&5 +$as_echo "$as_me: WARNING: egrep not found - will not generate doxygen PDF documentation" >&2;} + DX_FLAG_pdf=0 + +fi + + : +fi +if test "$DX_FLAG_pdf" = 1; then + if :; then + DX_COND_pdf_TRUE= + DX_COND_pdf_FALSE='#' +else + DX_COND_pdf_TRUE='#' + DX_COND_pdf_FALSE= +fi + + + : +else + if false; then + DX_COND_pdf_TRUE= + DX_COND_pdf_FALSE='#' +else + DX_COND_pdf_TRUE='#' + DX_COND_pdf_FALSE= +fi + + + : +fi + + +# LaTeX generation for PS and/or PDF: +if test "$DX_FLAG_ps" = 1 || test "$DX_FLAG_pdf" = 1; then + if :; then + DX_COND_latex_TRUE= + DX_COND_latex_FALSE='#' +else + DX_COND_latex_TRUE='#' + DX_COND_latex_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_LATEX='YES'" + +else + if false; then + DX_COND_latex_TRUE= + DX_COND_latex_FALSE='#' +else + DX_COND_latex_TRUE='#' + DX_COND_latex_FALSE= +fi + + DX_ENV="$DX_ENV GENERATE_LATEX='NO'" + +fi + +# Paper size for PS and/or PDF: + +case "$DOXYGEN_PAPER_SIZE" in +#( +"") + DOXYGEN_PAPER_SIZE="" + +;; #( +a4wide|a4|letter|legal|executive) + DX_ENV="$DX_ENV PAPER_SIZE='$DOXYGEN_PAPER_SIZE'" + +;; #( +*) + as_fn_error $? "unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'" "$LINENO" 5 +;; +esac + +#For debugging: +#echo DX_FLAG_doc=$DX_FLAG_doc +#echo DX_FLAG_dot=$DX_FLAG_dot +#echo DX_FLAG_man=$DX_FLAG_man +#echo DX_FLAG_html=$DX_FLAG_html +#echo DX_FLAG_chm=$DX_FLAG_chm +#echo DX_FLAG_chi=$DX_FLAG_chi +#echo DX_FLAG_rtf=$DX_FLAG_rtf +#echo DX_FLAG_xml=$DX_FLAG_xml +#echo DX_FLAG_pdf=$DX_FLAG_pdf +#echo DX_FLAG_ps=$DX_FLAG_ps +#echo DX_ENV=$DX_ENV + + +# initialize automake +am__api_version='1.15' + +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if ${ac_cv_path_install+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in #(( + ./ | .// | /[cC]/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + + done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +$as_echo_n "checking whether build environment is sane... " >&6; } +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[\\\"\#\$\&\'\`$am_lf]*) + as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; +esac +case $srcdir in + *[\\\"\#\$\&\'\`$am_lf\ \ ]*) + as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; +esac + +# Do 'set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + as_fn_error $? "ls -t appears to fail. Make sure there is not a broken + alias in your environment" "$LINENO" 5 + fi + if test "$2" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done + test "$2" = conftest.file + ) +then + # Ok. + : +else + as_fn_error $? "newly created file is older than distributed files! +Check your system clock" "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi + +rm -f conftest.file + +test "$program_prefix" != NONE && + program_transform_name="s&^&$program_prefix&;$program_transform_name" +# Use a double $ so make ignores it. +test "$program_suffix" != NONE && + program_transform_name="s&\$&$program_suffix&;$program_transform_name" +# Double any \ or $. +# By default was `s,x,x', remove it if useless. +ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' +program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` + +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` + +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --is-lightweight"; then + am_missing_run="$MISSING " +else + am_missing_run= + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} +fi + +if test x"${install_sh+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi + +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the 'STRIP' environment variable to overrule this program. +if test "$cross_compiling" != no; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } +if test -z "$MKDIR_P"; then + if ${ac_cv_path_mkdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done + done +IFS=$as_save_IFS + +fi + + test -d ./--version && rmdir ./--version + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + MKDIR_P="$ac_install_sh -d" + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } + +for ac_prog in gawk mawk nawk awk +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AWK+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AWK"; then + ac_cv_prog_AWK="$AWK" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AWK="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AWK=$ac_cv_prog_AWK +if test -n "$AWK"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +$as_echo "$AWK" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AWK" && break +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +set x ${MAKE-make} +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering ...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null + +# Check whether --enable-silent-rules was given. +if test "${enable_silent_rules+set}" = set; then : + enableval=$enable_silent_rules; +fi + +case $enable_silent_rules in # ((( + yes) AM_DEFAULT_VERBOSITY=0;; + no) AM_DEFAULT_VERBOSITY=1;; + *) AM_DEFAULT_VERBOSITY=1;; +esac +am_make=${MAKE-make} +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +$as_echo_n "checking whether $am_make supports nested variables... " >&6; } +if ${am_cv_make_support_nested_variables+:} false; then : + $as_echo_n "(cached) " >&6 +else + if $as_echo 'TRUE=$(BAR$(V)) +BAR0=false +BAR1=true +V=1 +am__doit: + @$(TRUE) +.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then + am_cv_make_support_nested_variables=yes +else + am_cv_make_support_nested_variables=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +$as_echo "$am_cv_make_support_nested_variables" >&6; } +if test $am_cv_make_support_nested_variables = yes; then + AM_V='$(V)' + AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' +else + AM_V=$AM_DEFAULT_VERBOSITY + AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY +fi +AM_BACKSLASH='\' + +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + am__isrc=' -I$(srcdir)' + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi + + +# Define the identity of the package. + PACKAGE='zookeeper' + VERSION='3.6.0' + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE "$PACKAGE" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define VERSION "$VERSION" +_ACEOF + +# Some tools Automake needs. + +ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} + + +AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} + + +AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} + + +AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} + + +MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} + +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +mkdir_p='$(MKDIR_P)' + +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. +# Always define AMTAR for backward compatibility. Yes, it's still used +# in the wild :-( We should find a proper way to deprecate it ... +AMTAR='$${TAR-tar}' + + +# We'll loop over all known methods to create a tar archive until one works. +_am_tools='gnutar pax cpio none' + +am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' + + + + + + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 + fi +fi + +ac_config_headers="$ac_config_headers config.h" + + +# Checks for programs. + +# Check whether --with-cppunit was given. +if test "${with_cppunit+set}" = set; then : + withval=$with_cppunit; +fi + + +if test "$with_cppunit" = "no" ; then + CPPUNIT_PATH="No_CPPUNIT" + CPPUNIT_INCLUDE= + CPPUNIT_LIBS= +else + AM_PATH_CPPUNIT(1.10.2) +fi + +if test "$CALLER" = "ANT" ; then +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"${base_dir}/src/c/tests/zkServer.sh\\\"\"" +else +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"./tests/zkServer.sh\\\"\"" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for generated/zookeeper.jute.c" >&5 +$as_echo_n "checking for generated/zookeeper.jute.c... " >&6; } +if ${ac_cv_file_generated_zookeeper_jute_c+:} false; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "generated/zookeeper.jute.c"; then + ac_cv_file_generated_zookeeper_jute_c=yes +else + ac_cv_file_generated_zookeeper_jute_c=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file_generated_zookeeper_jute_c" >&5 +$as_echo "$ac_cv_file_generated_zookeeper_jute_c" >&6; } +if test "x$ac_cv_file_generated_zookeeper_jute_c" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_GENERATED_ZOOKEEPER_JUTE_C 1 +_ACEOF + +else + as_fn_error $? "jute files are missing! Please run \"ant compile_jute\" while in the zookeeper top level directory." "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for generated/zookeeper.jute.h" >&5 +$as_echo_n "checking for generated/zookeeper.jute.h... " >&6; } +if ${ac_cv_file_generated_zookeeper_jute_h+:} false; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "generated/zookeeper.jute.h"; then + ac_cv_file_generated_zookeeper_jute_h=yes +else + ac_cv_file_generated_zookeeper_jute_h=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file_generated_zookeeper_jute_h" >&5 +$as_echo "$ac_cv_file_generated_zookeeper_jute_h" >&6; } +if test "x$ac_cv_file_generated_zookeeper_jute_h" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_GENERATED_ZOOKEEPER_JUTE_H 1 +_ACEOF + +else + as_fn_error $? "jute files are missing! Please run \"ant compile_jute\" while in the zookeeper top level directory." "$LINENO" 5 + +fi + +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "C compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if ${ac_cv_objext+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of object files: cannot compile +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +$as_echo_n "checking whether $CC understands -c and -o together... " >&6; } +if ${am_cv_prog_cc_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 + ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +$as_echo "$am_cv_prog_cc_c_o" >&6; } +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +DEPDIR="${am__leading_dot}deps" + +ac_config_commands="$ac_config_commands depfiles" + + +am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 +$as_echo_n "checking for style of include used by $am_make... " >&6; } +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from 'make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 +$as_echo "$_am_result" >&6; } +rm -f confinc confmf + +# Check whether --enable-dependency-tracking was given. +if test "${enable_dependency_tracking+set}" = set; then : + enableval=$enable_dependency_tracking; +fi + +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' + am__nodep='_no' +fi + if test "x$enable_dependency_tracking" != xno; then + AMDEP_TRUE= + AMDEP_FALSE='#' +else + AMDEP_TRUE='#' + AMDEP_FALSE= +fi + + + +depcc="$CC" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CC_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CC_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CC_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CC_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } +CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then + am__fastdepCC_TRUE= + am__fastdepCC_FALSE='#' +else + am__fastdepCC_TRUE='#' + am__fastdepCC_FALSE= +fi + + + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CXX"; then + ac_cv_prog_CXX="$CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 +$as_echo "$CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 +$as_echo "$ac_ct_CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 +$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } +if ${ac_cv_cxx_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 +$as_echo "$ac_cv_cxx_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GXX=yes +else + GXX= +fi +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 +$as_echo_n "checking whether $CXX accepts -g... " >&6; } +if ${ac_cv_prog_cxx_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +else + CXXFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + +else + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 +$as_echo "$ac_cv_prog_cxx_g" >&6; } +if test "$ac_test_CXXFLAGS" = set; then + CXXFLAGS=$ac_save_CXXFLAGS +elif test $ac_cv_prog_cxx_g = yes; then + if test "$GXX" = yes; then + CXXFLAGS="-g -O2" + else + CXXFLAGS="-g" + fi +else + if test "$GXX" = yes; then + CXXFLAGS="-O2" + else + CXXFLAGS= + fi +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +depcc="$CXX" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CXX_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CXX_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CXX_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CXX_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CXX_dependencies_compiler_type" >&6; } +CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CXX_dependencies_compiler_type" = gcc3; then + am__fastdepCXX_TRUE= + am__fastdepCXX_FALSE='#' +else + am__fastdepCXX_TRUE='#' + am__fastdepCXX_FALSE= +fi + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +$as_echo_n "checking whether ln -s works... " >&6; } +LN_S=$as_ln_s +if test "$LN_S" = "ln -s"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +$as_echo "no, using $LN_S" >&6; } +fi + + +# AC_DISABLE_SHARED +case `pwd` in + *\ * | *\ *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; +esac + + + +macro_version='2.4.6' +macro_revision='2.4.6' + + + + + + + + + + + + + +ltmain=$ac_aux_dir/ltmain.sh + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if ${ac_cv_build+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if ${ac_cv_host+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + +# Backslashify metacharacters that are still active within +# double-quoted strings. +sed_quote_subst='s/\(["`$\\]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +$as_echo_n "checking how to print strings... " >&6; } +# Test print first, because it will be a builtin if present. +if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ + test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='print -r --' +elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='printf %s\n' +else + # Use this function as a fallback that always works. + func_fallback_echo () + { + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' + } + ECHO='func_fallback_echo' +fi + +# func_echo_all arg... +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "" +} + +case $ECHO in + printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +$as_echo "printf" >&6; } ;; + print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +$as_echo "print -r" >&6; } ;; + *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +$as_echo "cat" >&6; } ;; +esac + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +$as_echo_n "checking for a sed that does not truncate output... " >&6; } +if ${ac_cv_path_SED+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for ac_i in 1 2 3 4 5 6 7; do + ac_script="$ac_script$as_nl$ac_script" + done + echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed + { ac_script=; unset ac_script;} + if test -z "$SED"; then + ac_path_SED_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_SED" || continue +# Check for GNU ac_path_SED and select it if it is found. + # Check for GNU $ac_path_SED +case `"$ac_path_SED" --version 2>&1` in +*GNU*) + ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo '' >> "conftest.nl" + "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_SED_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_SED="$ac_path_SED" + ac_path_SED_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_SED_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_SED"; then + as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 + fi +else + ac_cv_path_SED=$SED +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +$as_echo "$ac_cv_path_SED" >&6; } + SED="$ac_cv_path_SED" + rm -f conftest.sed + +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_GREP" || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if ${ac_cv_path_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_EGREP" || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +$as_echo_n "checking for fgrep... " >&6; } +if ${ac_cv_path_FGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 + then ac_cv_path_FGREP="$GREP -F" + else + if test -z "$FGREP"; then + ac_path_FGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in fgrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_FGREP" || continue +# Check for GNU ac_path_FGREP and select it if it is found. + # Check for GNU $ac_path_FGREP +case `"$ac_path_FGREP" --version 2>&1` in +*GNU*) + ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'FGREP' >> "conftest.nl" + "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_FGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_FGREP="$ac_path_FGREP" + ac_path_FGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_FGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_FGREP"; then + as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_FGREP=$FGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +$as_echo "$ac_cv_path_FGREP" >&6; } + FGREP="$ac_cv_path_FGREP" + + +test -z "$GREP" && GREP=grep + + + + + + + + + + + + + + + + + + + +# Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if ${lt_cv_path_NM+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM=$NM +else + lt_nm_to_check=${ac_tool_prefix}nm + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + tmp_nm=$ac_dir/$lt_tmp_nm + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the 'sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty + case $build_os in + mingw*) lt_bad_file=conftest.nm/nofile ;; + *) lt_bad_file=/dev/null ;; + esac + case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +$as_echo "$lt_cv_path_NM" >&6; } +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + if test -n "$ac_tool_prefix"; then + for ac_prog in dumpbin "link -dump" + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DUMPBIN"; then + ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DUMPBIN=$ac_cv_prog_DUMPBIN +if test -n "$DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +$as_echo "$DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$DUMPBIN" && break + done +fi +if test -z "$DUMPBIN"; then + ac_ct_DUMPBIN=$DUMPBIN + for ac_prog in dumpbin "link -dump" +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DUMPBIN"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN +if test -n "$ac_ct_DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +$as_echo "$ac_ct_DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_DUMPBIN" && break +done + + if test "x$ac_ct_DUMPBIN" = x; then + DUMPBIN=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DUMPBIN=$ac_ct_DUMPBIN + fi +fi + + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +$as_echo_n "checking the name lister ($NM) interface... " >&6; } +if ${lt_cv_nm_interface+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: output\"" >&5) + cat conftest.out >&5 + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +$as_echo "$lt_cv_nm_interface" >&6; } + +# find the maximum length of command line arguments +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +$as_echo_n "checking the maximum length of command line arguments... " >&6; } +if ${lt_cv_sys_max_cmd_len+:} false; then : + $as_echo_n "(cached) " >&6 +else + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac + +fi + +if test -n "$lt_cv_sys_max_cmd_len"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +$as_echo "$lt_cv_sys_max_cmd_len" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 +$as_echo "none" >&6; } +fi +max_cmd_len=$lt_cv_sys_max_cmd_len + + + + + + +: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi + + + + + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +$as_echo_n "checking how to convert $build file names to $host format... " >&6; } +if ${lt_cv_to_host_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 + ;; + esac + ;; + *-*-cygwin* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin + ;; + esac + ;; + * ) # unhandled hosts (and "normal" native builds) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; +esac + +fi + +to_host_file_cmd=$lt_cv_to_host_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +$as_echo "$lt_cv_to_host_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; } +if ${lt_cv_to_tool_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + #assume ordinary cross tools, or native build. +lt_cv_to_tool_file_cmd=func_convert_file_noop +case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 + ;; + esac + ;; +esac + +fi + +to_tool_file_cmd=$lt_cv_to_tool_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +$as_echo "$lt_cv_to_tool_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +$as_echo_n "checking for $LD option to reload object files... " >&6; } +if ${lt_cv_ld_reload_flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_reload_flag='-r' +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +$as_echo "$lt_cv_ld_reload_flag" >&6; } +reload_flag=$lt_cv_ld_reload_flag +case $reload_flag in +"" | " "*) ;; +*) reload_flag=" $reload_flag" ;; +esac +reload_cmds='$LD$reload_flag -o $output$reload_objs' +case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + if test yes != "$GCC"; then + reload_cmds=false + fi + ;; + darwin*) + if test yes = "$GCC"; then + reload_cmds='$LTCC $LTCFLAGS -nostdlib $wl-r -o $output$reload_objs' + else + reload_cmds='$LD$reload_flag -o $output$reload_objs' + fi + ;; +esac + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. +set dummy ${ac_tool_prefix}objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OBJDUMP"; then + ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OBJDUMP=$ac_cv_prog_OBJDUMP +if test -n "$OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OBJDUMP"; then + ac_ct_OBJDUMP=$OBJDUMP + # Extract the first word of "objdump", so it can be a program name with args. +set dummy objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OBJDUMP"; then + ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OBJDUMP="objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP +if test -n "$ac_ct_OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OBJDUMP" = x; then + OBJDUMP="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OBJDUMP=$ac_ct_OBJDUMP + fi +else + OBJDUMP="$ac_cv_prog_OBJDUMP" +fi + +test -z "$OBJDUMP" && OBJDUMP=objdump + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +$as_echo_n "checking how to recognize dependent libraries... " >&6; } +if ${lt_cv_deplibs_check_method+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# 'unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# that responds to the $file_magic_cmd with a given extended regex. +# If you have 'file' or equivalent on your system and you're not sure +# whether 'pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[4-9]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[45]*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc*) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +haiku*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]' + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9]\.[0-9]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[3-9]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd* | bitrig*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +os2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +$as_echo "$lt_cv_deplibs_check_method" >&6; } + +file_magic_glob= +want_nocaseglob=no +if test "$build" = "$host"; then + case $host_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes + else + file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[\1]\/[\1]\/g;/g"` + fi + ;; + esac +fi + +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + + + + + + + + + + + + + + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. +set dummy ${ac_tool_prefix}dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DLLTOOL"; then + ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DLLTOOL=$ac_cv_prog_DLLTOOL +if test -n "$DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +$as_echo "$DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DLLTOOL"; then + ac_ct_DLLTOOL=$DLLTOOL + # Extract the first word of "dlltool", so it can be a program name with args. +set dummy dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DLLTOOL"; then + ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DLLTOOL="dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL +if test -n "$ac_ct_DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +$as_echo "$ac_ct_DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DLLTOOL" = x; then + DLLTOOL="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DLLTOOL=$ac_ct_DLLTOOL + fi +else + DLLTOOL="$ac_cv_prog_DLLTOOL" +fi + +test -z "$DLLTOOL" && DLLTOOL=dlltool + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +$as_echo_n "checking how to associate runtime and link libraries... " >&6; } +if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_sharedlib_from_linklib_cmd='unknown' + +case $host_os in +cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL + case `$DLLTOOL --help 2>&1` in + *--identify-strict*) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib + ;; + *) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback + ;; + esac + ;; +*) + # fallback: assume linklib IS sharedlib + lt_cv_sharedlib_from_linklib_cmd=$ECHO + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; } +sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd +test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO + + + + + + + + +if test -n "$ac_tool_prefix"; then + for ac_prog in ar + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AR="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AR" && break + done +fi +if test -z "$AR"; then + ac_ct_AR=$AR + for ac_prog in ar +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_AR="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_AR" && break +done + + if test "x$ac_ct_AR" = x; then + AR="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +fi + +: ${AR=ar} +: ${AR_FLAGS=cru} + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +$as_echo_n "checking for archiver @FILE support... " >&6; } +if ${lt_cv_ar_at_file+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ar_at_file=no + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + echo conftest.$ac_objext > conftest.lst + lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -eq "$ac_status"; then + # Ensure the archiver fails upon bogus file names. + rm -f conftest.$ac_objext libconftest.a + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -ne "$ac_status"; then + lt_cv_ar_at_file=@ + fi + fi + rm -f conftest.* libconftest.a + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +$as_echo "$lt_cv_ar_at_file" >&6; } + +if test no = "$lt_cv_ar_at_file"; then + archiver_list_spec= +else + archiver_list_spec=$lt_cv_ar_at_file +fi + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +test -z "$STRIP" && STRIP=: + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +test -z "$RANLIB" && RANLIB=: + + + + + + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" +fi + +case $host_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) + lock_old_archive_extraction=no ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# Check for command to grab the raw symbol name followed by C symbol from nm. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } +if ${lt_cv_sys_global_symbol_pipe+:} false; then : + $as_echo_n "(cached) " >&6 +else + +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[BCDEGRST]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([_A-Za-z][_A-Za-z0-9]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[BCDT]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[ABCDGISTW]' + ;; +hpux*) + if test ia64 = "$host_cpu"; then + symcode='[ABCDEGRST]' + fi + ;; +irix* | nonstopux*) + symcode='[BCDEGRST]' + ;; +osf*) + symcode='[BCDEGQRST]' + ;; +solaris*) + symcode='[BDRT]' + ;; +sco3.2v5*) + symcode='[DT]' + ;; +sysv4.2uw2*) + symcode='[DT]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[ABDT]' + ;; +sysv4) + symcode='[DFNSTU]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[ABCDGIRSTW]' ;; +esac + +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Gets list of data symbols to import. + lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + # Adjust the below global symbol transforms to fixup imported variables. + lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" + lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" + lt_c_name_lib_hook="\ + -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ + -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" +else + # Disable hooks by default. + lt_cv_sys_global_symbol_to_import= + lt_cdecl_hook= + lt_c_name_hook= + lt_c_name_lib_hook= +fi + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +$lt_cdecl_hook\ +" -e 's/^T .* \(.*\)$/extern int \1();/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +$lt_c_name_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" + +# Transform an extracted symbol line into symbol name with lib prefix and +# symbol address. +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +$lt_c_name_lib_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function, + # D for any global variable and I for any imported variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK '"\ +" {last_section=section; section=\$ 3};"\ +" /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ +" /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ +" /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ +" {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ +" s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Now try to grab the symbols. + nlist=conftest.nm + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 + (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +LT_DLSYM_CONST struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_globsym_save_LIBS=$LIBS + lt_globsym_save_CFLAGS=$CFLAGS + LIBS=conftstm.$ac_objext + CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s conftest$ac_exeext; then + pipe_works=yes + fi + LIBS=$lt_globsym_save_LIBS + CFLAGS=$lt_globsym_save_CFLAGS + else + echo "cannot find nm_test_func in $nlist" >&5 + fi + else + echo "cannot find nm_test_var in $nlist" >&5 + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 + fi + else + echo "$progname: failed program was:" >&5 + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test yes = "$pipe_works"; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done + +fi + +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +$as_echo "failed" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } +fi + +# Response file support. +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + nm_file_list_spec='@' +elif $NM --help 2>/dev/null | grep '[@]FILE' >/dev/null; then + nm_file_list_spec='@' +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +$as_echo_n "checking for sysroot... " >&6; } + +# Check whether --with-sysroot was given. +if test "${with_sysroot+set}" = set; then : + withval=$with_sysroot; +else + with_sysroot=no +fi + + +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +$as_echo "$with_sysroot" >&6; } + as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5 + ;; +esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +$as_echo "${lt_sysroot:-no}" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +$as_echo_n "checking for a working dd... " >&6; } +if ${ac_cv_path_lt_DD+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +: ${lt_DD:=$DD} +if test -z "$lt_DD"; then + ac_path_lt_DD_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in dd; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_lt_DD="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_lt_DD" || continue +if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: +fi + $ac_path_lt_DD_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_lt_DD"; then + : + fi +else + ac_cv_path_lt_DD=$lt_DD +fi + +rm -f conftest.i conftest2.i conftest.out +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +$as_echo "$ac_cv_path_lt_DD" >&6; } + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +$as_echo_n "checking how to truncate binary pipes... " >&6; } +if ${lt_cv_truncate_bin+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +lt_cv_truncate_bin= +if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" +fi +rm -f conftest.i conftest2.i conftest.out +test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +$as_echo "$lt_cv_truncate_bin" >&6; } + + + + + + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in $*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + +# Check whether --enable-libtool-lock was given. +if test "${enable_libtool_lock+set}" = set; then : + enableval=$enable_libtool_lock; +fi + +test no = "$enable_libtool_lock" || enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE=32 + ;; + *ELF-64*) + HPUX_IA64_MODE=64 + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + if test yes = "$lt_cv_prog_gnu_ld"; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +mips64*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + emul=elf + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + emul="${emul}32" + ;; + *64-bit*) + emul="${emul}64" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *MSB*) + emul="${emul}btsmip" + ;; + *LSB*) + emul="${emul}ltsmip" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *N32*) + emul="${emul}n32" + ;; + esac + LD="${LD-ld} -m $emul" + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. Note that the listed cases only cover the + # situations where additional linker options are needed (such as when + # doing 32-bit compilation for a host where ld defaults to 64-bit, or + # vice versa); the common cases where no linker options are needed do + # not appear in the list. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac + ;; + powerpc64le-*linux*) + LD="${LD-ld} -m elf32lppclinux" + ;; + powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + powerpcle-*linux*) + LD="${LD-ld} -m elf64lppc" + ;; + powerpc-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -belf" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +$as_echo_n "checking whether the C compiler needs -belf... " >&6; } +if ${lt_cv_cc_needs_belf+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_cc_needs_belf=yes +else + lt_cv_cc_needs_belf=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +$as_echo "$lt_cv_cc_needs_belf" >&6; } + if test yes != "$lt_cv_cc_needs_belf"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS=$SAVE_CFLAGS + fi + ;; +*-*solaris*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) + case $host in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; + sparc*-*-solaris*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + # GNU ld 2.21 introduced _sol2 emulations. Use them if available. + if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then + LD=${LD-ld}_sol2 + fi + ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks=$enable_libtool_lock + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args. +set dummy ${ac_tool_prefix}mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$MANIFEST_TOOL"; then + ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL +if test -n "$MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +$as_echo "$MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_MANIFEST_TOOL"; then + ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL + # Extract the first word of "mt", so it can be a program name with args. +set dummy mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_MANIFEST_TOOL"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL +if test -n "$ac_ct_MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +$as_echo "$ac_ct_MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_MANIFEST_TOOL" = x; then + MANIFEST_TOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL + fi +else + MANIFEST_TOOL="$ac_cv_prog_MANIFEST_TOOL" +fi + +test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if ${lt_cv_path_mainfest_tool+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_path_mainfest_tool=no + echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 + $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out + cat conftest.err >&5 + if $GREP 'Manifest Tool' conftest.out > /dev/null; then + lt_cv_path_mainfest_tool=yes + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 +$as_echo "$lt_cv_path_mainfest_tool" >&6; } +if test yes != "$lt_cv_path_mainfest_tool"; then + MANIFEST_TOOL=: +fi + + + + + + + case $host_os in + rhapsody* | darwin*) + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. +set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DSYMUTIL"; then + ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DSYMUTIL=$ac_cv_prog_DSYMUTIL +if test -n "$DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +$as_echo "$DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DSYMUTIL"; then + ac_ct_DSYMUTIL=$DSYMUTIL + # Extract the first word of "dsymutil", so it can be a program name with args. +set dummy dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DSYMUTIL"; then + ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL +if test -n "$ac_ct_DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +$as_echo "$ac_ct_DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DSYMUTIL" = x; then + DSYMUTIL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DSYMUTIL=$ac_ct_DSYMUTIL + fi +else + DSYMUTIL="$ac_cv_prog_DSYMUTIL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. +set dummy ${ac_tool_prefix}nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NMEDIT"; then + ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +NMEDIT=$ac_cv_prog_NMEDIT +if test -n "$NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +$as_echo "$NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_NMEDIT"; then + ac_ct_NMEDIT=$NMEDIT + # Extract the first word of "nmedit", so it can be a program name with args. +set dummy nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_NMEDIT"; then + ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_NMEDIT="nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT +if test -n "$ac_ct_NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +$as_echo "$ac_ct_NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_NMEDIT" = x; then + NMEDIT=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + NMEDIT=$ac_ct_NMEDIT + fi +else + NMEDIT="$ac_cv_prog_NMEDIT" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. +set dummy ${ac_tool_prefix}lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$LIPO"; then + ac_cv_prog_LIPO="$LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_LIPO="${ac_tool_prefix}lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +LIPO=$ac_cv_prog_LIPO +if test -n "$LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +$as_echo "$LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_LIPO"; then + ac_ct_LIPO=$LIPO + # Extract the first word of "lipo", so it can be a program name with args. +set dummy lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_LIPO"; then + ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_LIPO="lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO +if test -n "$ac_ct_LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +$as_echo "$ac_ct_LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_LIPO" = x; then + LIPO=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + LIPO=$ac_ct_LIPO + fi +else + LIPO="$ac_cv_prog_LIPO" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL"; then + ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL="${ac_tool_prefix}otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL=$ac_cv_prog_OTOOL +if test -n "$OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +$as_echo "$OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL"; then + ac_ct_OTOOL=$OTOOL + # Extract the first word of "otool", so it can be a program name with args. +set dummy otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL"; then + ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL="otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL +if test -n "$ac_ct_OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +$as_echo "$ac_ct_OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL" = x; then + OTOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL=$ac_ct_OTOOL + fi +else + OTOOL="$ac_cv_prog_OTOOL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL64"; then + ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL64=$ac_cv_prog_OTOOL64 +if test -n "$OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +$as_echo "$OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL64"; then + ac_ct_OTOOL64=$OTOOL64 + # Extract the first word of "otool64", so it can be a program name with args. +set dummy otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL64"; then + ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL64="otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 +if test -n "$ac_ct_OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +$as_echo "$ac_ct_OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL64" = x; then + OTOOL64=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL64=$ac_ct_OTOOL64 + fi +else + OTOOL64="$ac_cv_prog_OTOOL64" +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +$as_echo_n "checking for -single_module linker flag... " >&6; } +if ${lt_cv_apple_cc_single_mod+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_apple_cc_single_mod=no + if test -z "$LT_MULTI_MODULE"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + # If there is a non-empty error log, and "single_module" + # appears in it, assume the flag caused a linker warning + if test -s conftest.err && $GREP single_module conftest.err; then + cat conftest.err >&5 + # Otherwise, if the output was created with a 0 exit code from + # the compiler, it worked. + elif test -f libconftest.dylib && test 0 = "$_lt_result"; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&5 + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +$as_echo "$lt_cv_apple_cc_single_mod" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } +if ${lt_cv_ld_exported_symbols_list+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_ld_exported_symbols_list=yes +else + lt_cv_ld_exported_symbols_list=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +$as_echo "$lt_cv_ld_exported_symbols_list" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +$as_echo_n "checking for -force_load linker flag... " >&6; } +if ${lt_cv_ld_force_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 + echo "$AR cru libconftest.a conftest.o" >&5 + $AR cru libconftest.a conftest.o 2>&5 + echo "$RANLIB libconftest.a" >&5 + $RANLIB libconftest.a 2>&5 + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -s conftest.err && $GREP force_load conftest.err; then + cat conftest.err >&5 + elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&5 + fi + rm -f conftest.err libconftest.a conftest conftest.c + rm -rf conftest.dSYM + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +$as_echo "$lt_cv_ld_force_load" >&6; } + case $host_os in + rhapsody* | darwin1.[012]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[91]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test yes = "$lt_cv_apple_cc_single_mod"; then + _lt_dar_single_mod='$single_module' + fi + if test yes = "$lt_cv_ld_exported_symbols_list"; then + _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' + fi + if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x$2 in + x) + ;; + *:) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'` \$$1\" + ;; + x:*) + eval $1=\"\$$1 `$ECHO $2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval $1=\"\$$1\ `$ECHO $2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval $1=\"`$ECHO $2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \$$1\" + ;; + *) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'`\" + ;; + esac +} + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +for ac_header in dlfcn.h +do : + ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default +" +if test "x$ac_cv_header_dlfcn_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_DLFCN_H 1 +_ACEOF + +fi + +done + + + + +func_stripname_cnf () +{ + case $2 in + .*) func_stripname_result=`$ECHO "$3" | $SED "s%^$1%%; s%\\\\$2\$%%"`;; + *) func_stripname_result=`$ECHO "$3" | $SED "s%^$1%%; s%$2\$%%"`;; + esac +} # func_stripname_cnf + + + + + +# Set options + + + + enable_dlopen=no + + + enable_win32_dll=no + + + # Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then : + enableval=$enable_shared; p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_shared=yes +fi + + + + + + + + + + # Check whether --enable-static was given. +if test "${enable_static+set}" = set; then : + enableval=$enable_static; p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_static=yes +fi + + + + + + + + + + +# Check whether --with-pic was given. +if test "${with_pic+set}" = set; then : + withval=$with_pic; lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + pic_mode=default +fi + + + + + + + + + # Check whether --enable-fast-install was given. +if test "${enable_fast_install+set}" = set; then : + enableval=$enable_fast_install; p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_fast_install=yes +fi + + + + + + + + + shared_archive_member_spec= +case $host,$enable_shared in +power*-*-aix[5-9]*,yes) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +$as_echo_n "checking which variant of shared library versioning to provide... " >&6; } + +# Check whether --with-aix-soname was given. +if test "${with_aix_soname+set}" = set; then : + withval=$with_aix_soname; case $withval in + aix|svr4|both) + ;; + *) + as_fn_error $? "Unknown argument to --with-aix-soname" "$LINENO" 5 + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname +else + if ${lt_cv_with_aix_soname+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_with_aix_soname=aix +fi + + with_aix_soname=$lt_cv_with_aix_soname +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +$as_echo "$with_aix_soname" >&6; } + if test aix != "$with_aix_soname"; then + # For the AIX way of multilib, we name the shared archive member + # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', + # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. + # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, + # the AIX toolchain works better with OBJECT_MODE set (default 32). + if test 64 = "${OBJECT_MODE-32}"; then + shared_archive_member_spec=shr_64 + else + shared_archive_member_spec=shr + fi + fi + ;; +*) + with_aix_soname=aix + ;; +esac + + + + + + + + + + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +test -z "$LN_S" && LN_S="ln -s" + + + + + + + + + + + + + + +if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +$as_echo_n "checking for objdir... " >&6; } +if ${lt_cv_objdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +$as_echo "$lt_cv_objdir" >&6; } +objdir=$lt_cv_objdir + + + + + +cat >>confdefs.h <<_ACEOF +#define LT_OBJDIR "$lt_cv_objdir/" +_ACEOF + + + + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld=$lt_cv_prog_gnu_ld + +old_CC=$CC +old_CFLAGS=$CFLAGS + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +func_cc_basename $compiler +cc_basename=$func_cc_basename_result + + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/${ac_tool_prefix}file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"${ac_tool_prefix}file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + + + +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +$as_echo_n "checking for file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + else + MAGIC_CMD=: + fi +fi + + fi + ;; +esac + +# Use C for the default configuration in the libtool script + +lt_save_CC=$CC +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +objext=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + +if test -n "$compiler"; then + +lt_prog_compiler_no_builtin_flag= + +if test yes = "$GCC"; then + case $cc_basename in + nvcc*) + lt_prog_compiler_no_builtin_flag=' -Xcompiler -fno-builtin' ;; + *) + lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_rtti_exceptions=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="-fno-rtti -fno-exceptions" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_rtti_exceptions=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } + +if test yes = "$lt_cv_prog_compiler_rtti_exceptions"; then + lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" +else + : +fi + +fi + + + + + + + lt_prog_compiler_wl= +lt_prog_compiler_pic= +lt_prog_compiler_static= + + + if test yes = "$GCC"; then + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_static='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + fi + lt_prog_compiler_pic='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + ;; + + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + lt_prog_compiler_static= + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + ;; + + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic=-Kconform_pic + fi + ;; + + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + + case $cc_basename in + nvcc*) # Cuda Compiler Driver 2.2 + lt_prog_compiler_wl='-Xlinker ' + if test -n "$lt_prog_compiler_pic"; then + lt_prog_compiler_pic="-Xcompiler $lt_prog_compiler_pic" + fi + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl='-Wl,' + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + else + lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + case $cc_basename in + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static='$wl-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + # old Intel for x86_64, which still supported -KPIC. + ecc*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='--shared' + lt_prog_compiler_static='--static' + ;; + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + xl* | bgxl* | bgf* | mpixl*) + # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-qpic' + lt_prog_compiler_static='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='' + ;; + *Sun\ F* | *Sun*Fortran*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Qoption ld ' + ;; + *Sun\ C*) + # Sun C 5.9 + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Wl,' + ;; + *Intel*\ [CF]*Compiler*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + *Portland\ Group*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + esac + ;; + + newsos6) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + + rdos*) + lt_prog_compiler_static='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + lt_prog_compiler_wl='-Qoption ld ';; + *) + lt_prog_compiler_wl='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl='-Qoption ld ' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic='-Kconform_pic' + lt_prog_compiler_static='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_can_build_shared=no + ;; + + uts4*) + lt_prog_compiler_pic='-pic' + lt_prog_compiler_static='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared=no + ;; + esac + fi + +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic= + ;; + *) + lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic=$lt_prog_compiler_pic +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +$as_echo "$lt_cv_prog_compiler_pic" >&6; } +lt_prog_compiler_pic=$lt_cv_prog_compiler_pic + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if ${lt_cv_prog_compiler_pic_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic -DPIC" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_pic_works"; then + case $lt_prog_compiler_pic in + "" | " "*) ;; + *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; + esac +else + lt_prog_compiler_pic= + lt_prog_compiler_can_build_shared=no +fi + +fi + + + + + + + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works=yes + fi + else + lt_cv_prog_compiler_static_works=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +$as_echo "$lt_cv_prog_compiler_static_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_static_works"; then + : +else + lt_prog_compiler_static= +fi + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + +hard_links=nottested +if test no = "$lt_cv_prog_compiler_c_o" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test no = "$hard_links"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + runpath_var= + allow_undefined_flag= + always_export_symbols=no + archive_cmds= + archive_expsym_cmds= + compiler_needs_object=no + enable_shared_with_static_runtimes=no + export_dynamic_flag_spec= + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + hardcode_automatic=no + hardcode_direct=no + hardcode_direct_absolute=no + hardcode_libdir_flag_spec= + hardcode_libdir_separator= + hardcode_minus_L=no + hardcode_shlibpath_var=unsupported + inherit_rpath=no + link_all_deplibs=unknown + module_cmds= + module_expsym_cmds= + old_archive_from_new_cmds= + old_archive_from_expsyms_cmds= + thread_safe_flag_spec= + whole_archive_flag_spec= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ' (' and ')$', so one must not match beginning or + # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', + # as well as any symbol that contains 'd'. + exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test yes != "$GCC"; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd* | bitrig*) + with_gnu_ld=no + ;; + esac + + ld_shlibs=yes + + # On some targets, GNU ld is compatible enough with the native linker + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then + case $host_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld + # block says, versions before 2.19.5* couldn't really create working + # shared libraries, regardless of the interface used. + case `$LD -v 2>&1` in + *\ \(GNU\ Binutils\)\ 2.19.5*) ;; + *\ \(GNU\ Binutils\)\ 2.[2-9]*) ;; + *\ \(GNU\ Binutils\)\ [3-9]*) ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + fi + + if test yes = "$lt_use_gnu_ld_interface"; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='$wl' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + export_dynamic_flag_spec='$wl--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + whole_archive_flag_spec= + fi + supports_anon_versioning=no + case `$LD -v | $SED -e 's/(^)\+)\s\+//' 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[3-9]*) + # On AIX/PPC, the GNU linker is very broken + if test ia64 != "$host_cpu"; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.19, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to install binutils +*** 2.20 or above, or modify your PATH so that a non-GNU linker is found. +*** You will then need to restart the configuration process. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + ld_shlibs=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + export_dynamic_flag_spec='$wl--export-all-symbols' + allow_undefined_flag=unsupported + always_export_symbols=no + enable_shared_with_static_runtimes=yes + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs=no + fi + ;; + + haiku*) + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + link_all_deplibs=yes + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + interix[3-9]*) + hardcode_direct=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test linux-dietlibc = "$host_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test no = "$tmp_diet" + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group f77 and f90 compilers + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + whole_archive_flag_spec= + tmp_sharedflag='--shared' ;; + nagfor*) # NAGFOR 5.3 + tmp_sharedflag='-Wl,-shared' ;; + xl[cC]* | bgxl[cC]* | mpixl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + nvcc*) # Cuda Compiler Driver 2.2 + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + whole_archive_flag_spec='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + tcc*) + export_dynamic_flag_spec='-rdynamic' + ;; + xlf* | bgf* | bgxlf* | mpixlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + ld_shlibs=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + + if test no = "$ld_shlibs"; then + runpath_var= + hardcode_libdir_flag_spec= + export_dynamic_flag_spec= + whole_archive_flag_spec= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag=unsupported + always_export_symbols=yes + archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + + aix[4-9]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes + break + fi + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds='' + hardcode_direct=yes + hardcode_direct_absolute=yes + hardcode_libdir_separator=':' + link_all_deplibs=yes + file_list_spec='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # traditional, no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + hardcode_direct=no + hardcode_direct_absolute=no + ;; + esac + + if test yes = "$GCC"; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag="$shared_flag "'$wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + export_dynamic_flag_spec='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + hardcode_libdir_flag_spec='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag="-z nodefs" + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag=' $wl-bernotok' + allow_undefined_flag=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + whole_archive_flag_spec='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec='$convenience' + fi + archive_cmds_need_lc=yes + archive_expsym_cmds='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([, ]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + archive_expsym_cmds="$archive_expsym_cmds"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + archive_expsym_cmds="$archive_expsym_cmds"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + bsdi[45]*) + export_dynamic_flag_spec=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + case $cc_basename in + cl*) + # Native MSVC + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + always_export_symbols=yes + file_list_spec='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, )='true' + enable_shared_with_static_runtimes=yes + exclude_expsyms='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1,DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols' + # Don't use ranlib + old_postinstall_cmds='chmod 644 $oldlib' + postlink_cmds='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # Assume MSVC wrapper + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_from_new_cmds='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs' + enable_shared_with_static_runtimes=yes + ;; + esac + ;; + + darwin* | rhapsody*) + + + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes + hardcode_shlibpath_var=unsupported + if test yes = "$lt_cv_ld_force_load"; then + whole_archive_flag_spec='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + + else + whole_archive_flag_spec='' + fi + link_all_deplibs=yes + allow_undefined_flag=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + archive_expsym_cmds="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + + else + ld_shlibs=no + fi + + ;; + + dgux*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2.*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + hpux9*) + if test yes = "$GCC"; then + archive_cmds='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + export_dynamic_flag_spec='$wl-E' + ;; + + hpux10*) + if test yes,no = "$GCC,$with_gnu_ld"; then + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + archive_cmds='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + + # Older versions of the 11.00 compiler do not understand -b yet + # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +$as_echo_n "checking if $CC understands -b... " >&6; } +if ${lt_cv_prog_compiler__b+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler__b=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -b" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler__b=yes + fi + else + lt_cv_prog_compiler__b=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +$as_echo "$lt_cv_prog_compiler__b" >&6; } + +if test yes = "$lt_cv_prog_compiler__b"; then + archive_cmds='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' +else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' +fi + + ;; + esac + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct=no + hardcode_shlibpath_var=no + ;; + *) + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test yes = "$GCC"; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if ${lt_cv_irix_exported_symbol+:} false; then : + $as_echo_n "(cached) " >&6 +else + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int foo (void) { return 0; } +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_irix_exported_symbol=yes +else + lt_cv_irix_exported_symbol=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +$as_echo "$lt_cv_irix_exported_symbol" >&6; } + if test yes = "$lt_cv_irix_exported_symbol"; then + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' + fi + else + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + inherit_rpath=yes + link_all_deplibs=yes + ;; + + linux*) + case $cc_basename in + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + ld_shlibs=yes + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + newsos6) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + hardcode_shlibpath_var=no + ;; + + *nto* | *qnx*) + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + hardcode_direct=yes + hardcode_shlibpath_var=no + hardcode_direct_absolute=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + else + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + fi + else + ld_shlibs=no + fi + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + osf3*) + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + archive_cmds_need_lc='no' + hardcode_libdir_separator=: + ;; + + solaris*) + no_undefined_flag=' -z defs' + if test yes = "$GCC"; then + wlarc='$wl' + archive_cmds='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + archive_cmds='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='$wl' + archive_cmds='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_shlibpath_var=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. GCC discards it without '$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test yes = "$GCC"; then + whole_archive_flag_spec='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + else + whole_archive_flag_spec='-z allextract$convenience -z defaultextract' + fi + ;; + esac + link_all_deplibs=yes + ;; + + sunos4*) + if test sequent = "$host_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds='$CC -r -o $output$reload_objs' + hardcode_direct=no + ;; + motorola) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var=no + ;; + + sysv4.3*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + export_dynamic_flag_spec='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag='$wl-z,text' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag='$wl-z,text' + allow_undefined_flag='$wl-z,nodefs' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-R,$libdir' + hardcode_libdir_separator=':' + link_all_deplibs=yes + export_dynamic_flag_spec='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + *) + ld_shlibs=no + ;; + esac + + if test sni = "$host_vendor"; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + export_dynamic_flag_spec='$wl-Blargedynsym' + ;; + esac + fi + fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +$as_echo "$ld_shlibs" >&6; } +test no = "$ld_shlibs" && can_build_shared=no + +with_gnu_ld=$with_gnu_ld + + + + + + + + + + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $archive_cmds in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc+:} false; then : + $as_echo_n "(cached) " >&6 +else + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl + pic_flag=$lt_prog_compiler_pic + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag + allow_undefined_flag= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + lt_cv_archive_cmds_need_lc=no + else + lt_cv_archive_cmds_need_lc=yes + fi + allow_undefined_flag=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc" >&6; } + archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +if test yes = "$GCC"; then + case $host_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac + case $host_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([A-Za-z]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` + case $lt_search_path_spec in + *\;*) + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` + ;; + *) + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` + ;; + esac + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary... + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + # ...but if some path component already ends with the multilib dir we assume + # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). + case "$lt_multi_os_dir; $lt_search_path_spec " in + "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) + lt_multi_os_dir= + ;; + esac + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" + elif test -n "$lt_multi_os_dir"; then + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' +BEGIN {RS = " "; FS = "/|\n";} { + lt_foo = ""; + lt_count = 0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo = "/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[lt_foo]++; } + if (lt_freq[lt_foo] == 1) { print lt_foo; } +}'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. + case $host_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([A-Za-z]:\)|\1|g'` ;; + esac + sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + + + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[4-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a(lib.so.V)' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o), lib.a(lib.so.V)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a(lib.so.V), lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib" + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[3-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + hardcode_libdir_flag_spec='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + lt_cv_shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + +fi + + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action= +if test -n "$hardcode_libdir_flag_spec" || + test -n "$runpath_var" || + test yes = "$hardcode_automatic"; then + + # We can hardcode non-existent directories. + if test no != "$hardcode_direct" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, )" && + test no != "$hardcode_minus_L"; then + # Linking always hardcodes the temporary library directory. + hardcode_action=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +$as_echo "$hardcode_action" >&6; } + +if test relink = "$hardcode_action" || + test yes = "$inherit_rpath"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + +fi + + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" +if test "x$ac_cv_func_shl_load" = xyes; then : + lt_cv_dlopen=shl_load +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : + lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld +else + ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" +if test "x$ac_cv_func_dlopen" = xyes; then : + lt_cv_dlopen=dlopen +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +$as_echo_n "checking for dlopen in -lsvld... " >&6; } +if ${ac_cv_lib_svld_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsvld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_svld_dlopen=yes +else + ac_cv_lib_svld_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +$as_echo "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +$as_echo_n "checking for dld_link in -ldld... " >&6; } +if ${ac_cv_lib_dld_dld_link+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dld_link (); +int +main () +{ +return dld_link (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_dld_link=yes +else + ac_cv_lib_dld_dld_link=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +$as_echo "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = xyes; then : + lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld +fi + + +fi + + +fi + + +fi + + +fi + + +fi + + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +$as_echo_n "checking whether a program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +$as_echo "$lt_cv_dlopen_self" >&6; } + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self_static+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self_static=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self_static=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +$as_echo "$lt_cv_dlopen_self_static" >&6; } + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi + + + + + + + + + + + + + + + + + +striplib= +old_striplib= +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +$as_echo_n "checking whether stripping libraries is possible... " >&6; } +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ;; + esac +fi + + + + + + + + + + + + + # Report what library types will actually be built + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +$as_echo_n "checking if libtool supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +$as_echo "$can_build_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +$as_echo_n "checking whether to build shared libraries... " >&6; } + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[4-9]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +$as_echo "$enable_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +$as_echo_n "checking whether to build static libraries... " >&6; } + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +$as_echo "$enable_static" >&6; } + + + + +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC=$lt_save_CC + + if test -n "$CXX" && ( test no != "$CXX" && + ( (test g++ = "$CXX" && `g++ -v >/dev/null 2>&1` ) || + (test g++ != "$CXX"))); then + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5 +$as_echo_n "checking how to run the C++ preprocessor... " >&6; } +if test -z "$CXXCPP"; then + if ${ac_cv_prog_CXXCPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CXXCPP needs to be expanded + for CXXCPP in "$CXX -E" "/lib/cpp" + do + ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CXXCPP=$CXXCPP + +fi + CXXCPP=$ac_cv_prog_CXXCPP +else + ac_cv_prog_CXXCPP=$CXXCPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5 +$as_echo "$CXXCPP" >&6; } +ac_preproc_ok=false +for ac_cxx_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_cxx_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C++ preprocessor \"$CXXCPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +else + _lt_caught_CXX_error=yes +fi + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +archive_cmds_need_lc_CXX=no +allow_undefined_flag_CXX= +always_export_symbols_CXX=no +archive_expsym_cmds_CXX= +compiler_needs_object_CXX=no +export_dynamic_flag_spec_CXX= +hardcode_direct_CXX=no +hardcode_direct_absolute_CXX=no +hardcode_libdir_flag_spec_CXX= +hardcode_libdir_separator_CXX= +hardcode_minus_L_CXX=no +hardcode_shlibpath_var_CXX=unsupported +hardcode_automatic_CXX=no +inherit_rpath_CXX=no +module_cmds_CXX= +module_expsym_cmds_CXX= +link_all_deplibs_CXX=unknown +old_archive_cmds_CXX=$old_archive_cmds +reload_flag_CXX=$reload_flag +reload_cmds_CXX=$reload_cmds +no_undefined_flag_CXX= +whole_archive_flag_spec_CXX= +enable_shared_with_static_runtimes_CXX=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +objext_CXX=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_caught_CXX_error"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + + # save warnings/boilerplate of simple test code + ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + + ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_CFLAGS=$CFLAGS + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + CFLAGS=$CXXFLAGS + compiler=$CC + compiler_CXX=$CC + func_cc_basename $compiler +cc_basename=$func_cc_basename_result + + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test yes = "$GXX"; then + lt_prog_compiler_no_builtin_flag_CXX=' -fno-builtin' + else + lt_prog_compiler_no_builtin_flag_CXX= + fi + + if test yes = "$GXX"; then + # Set up default GNU C++ configuration + + + +# Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test yes = "$with_gnu_ld"; then + archive_cmds_CXX='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='$wl' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec_CXX=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + whole_archive_flag_spec_CXX= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + ld_shlibs_CXX=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aix[4-9]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds_CXX='' + hardcode_direct_CXX=yes + hardcode_direct_absolute_CXX=yes + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + file_list_spec_CXX='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + hardcode_direct_CXX=no + hardcode_direct_absolute_CXX=no + ;; + esac + + if test yes = "$GXX"; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct_CXX=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L_CXX=yes + hardcode_libdir_flag_spec_CXX='-L$libdir' + hardcode_libdir_separator_CXX= + fi + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag=$shared_flag' $wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + export_dynamic_flag_spec_CXX='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + always_export_symbols_CXX=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + # The "-G" linker flag allows undefined symbols. + no_undefined_flag_CXX='-bernotok' + # Determine the default libpath from the value encoded in an empty + # executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath__CXX=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath__CXX +fi + + hardcode_libdir_flag_spec_CXX='$wl-blibpath:$libdir:'"$aix_libpath" + + archive_expsym_cmds_CXX='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + hardcode_libdir_flag_spec_CXX='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag_CXX="-z nodefs" + archive_expsym_cmds_CXX="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath__CXX=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath__CXX"; then + lt_cv_aix_libpath__CXX=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath__CXX +fi + + hardcode_libdir_flag_spec_CXX='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag_CXX=' $wl-bernotok' + allow_undefined_flag_CXX=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + whole_archive_flag_spec_CXX='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec_CXX='$convenience' + fi + archive_cmds_need_lc_CXX=yes + archive_expsym_cmds_CXX='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([, ]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared + # libraries. Need -bnortl late, we may have -brtl in LDFLAGS. + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + archive_expsym_cmds_CXX="$archive_expsym_cmds_CXX"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag_CXX=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds_CXX='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + ld_shlibs_CXX=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + case $GXX,$cc_basename in + ,cl* | no,cl*) + # Native MSVC + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec_CXX=' ' + allow_undefined_flag_CXX=unsupported + always_export_symbols_CXX=yes + file_list_spec_CXX='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds_CXX='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_expsym_cmds_CXX='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, CXX)='true' + enable_shared_with_static_runtimes_CXX=yes + # Don't use ranlib + old_postinstall_cmds_CXX='chmod 644 $oldlib' + postlink_cmds_CXX='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + func_to_tool_file "$lt_outputfile"~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # g++ + # _LT_TAGVAR(hardcode_libdir_flag_spec, CXX) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec_CXX='-L$libdir' + export_dynamic_flag_spec_CXX='$wl--export-all-symbols' + allow_undefined_flag_CXX=unsupported + always_export_symbols_CXX=no + enable_shared_with_static_runtimes_CXX=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + archive_expsym_cmds_CXX='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs_CXX=no + fi + ;; + esac + ;; + darwin* | rhapsody*) + + + archive_cmds_need_lc_CXX=no + hardcode_direct_CXX=no + hardcode_automatic_CXX=yes + hardcode_shlibpath_var_CXX=unsupported + if test yes = "$lt_cv_ld_force_load"; then + whole_archive_flag_spec_CXX='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + + else + whole_archive_flag_spec_CXX='' + fi + link_all_deplibs_CXX=yes + allow_undefined_flag_CXX=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds_CXX="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + if test yes != "$lt_cv_apple_cc_single_mod"; then + archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" + archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + fi + + else + ld_shlibs_CXX=no + fi + + ;; + + os2*) + hardcode_libdir_flag_spec_CXX='-L$libdir' + hardcode_minus_L_CXX=yes + allow_undefined_flag_CXX=unsupported + shrext_cmds=.dll + archive_cmds_CXX='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds_CXX='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds_CXX='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes_CXX=yes + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + freebsd2.*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + ld_shlibs_CXX=no + ;; + + freebsd-elf*) + archive_cmds_need_lc_CXX=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + ld_shlibs_CXX=yes + ;; + + haiku*) + archive_cmds_CXX='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + link_all_deplibs_CXX=yes + ;; + + hpux9*) + hardcode_libdir_flag_spec_CXX='$wl+b $wl$libdir' + hardcode_libdir_separator_CXX=: + export_dynamic_flag_spec_CXX='$wl-E' + hardcode_direct_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + archive_cmds_CXX='$RM $output_objdir/$soname~$CC -b $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + archive_cmds_CXX='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec_CXX='$wl+b $wl$libdir' + hardcode_libdir_separator_CXX=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + export_dynamic_flag_spec_CXX='$wl-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + ;; + *) + hardcode_direct_CXX=yes + hardcode_direct_absolute_CXX=yes + hardcode_minus_L_CXX=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -b $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + archive_cmds_CXX='$CC -shared -nostdlib -fPIC $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + archive_cmds_CXX='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + interix[3-9]*) + hardcode_direct_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds_CXX='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds_CXX='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + archive_cmds_CXX='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` -o $lib' + fi + fi + link_all_deplibs_CXX=yes + ;; + esac + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + hardcode_libdir_separator_CXX=: + inherit_rpath_CXX=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + archive_expsym_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib $wl-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + archive_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + archive_cmds_need_lc_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + whole_archive_flag_spec_CXX='$wl--whole-archive$convenience $wl--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [1-5].* | *pgcpp\ [1-5].*) + prelink_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' + old_archive_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ + $RANLIB $oldlib' + archive_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 6 and above use weak symbols + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + + hardcode_libdir_flag_spec_CXX='$wl--rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + whole_archive_flag_spec_CXX='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + ;; + cxx*) + # Compaq C++ + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib $wl-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' + ;; + xl* | mpixl* | bgxl*) + # IBM XL 8.0 on PPC, with GNU ld + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + export_dynamic_flag_spec_CXX='$wl--export-dynamic' + archive_cmds_CXX='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds_CXX='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + no_undefined_flag_CXX=' -zdefs' + archive_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + archive_expsym_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file $wl$export_symbols' + hardcode_libdir_flag_spec_CXX='-R$libdir' + whole_archive_flag_spec_CXX='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object_CXX=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds_CXX='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + ld_shlibs_CXX=yes + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + hardcode_direct_CXX=yes + hardcode_shlibpath_var_CXX=no + hardcode_direct_absolute_CXX=yes + archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`"; then + archive_expsym_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file,$export_symbols -o $lib' + export_dynamic_flag_spec_CXX='$wl-E' + whole_archive_flag_spec_CXX=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + fi + output_verbose_link_cmd=func_echo_all + else + ld_shlibs_CXX=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + archive_cmds_CXX='tempext=`echo $shared_ext | $SED -e '\''s/\([^()0-9A-Za-z{}]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + hardcode_libdir_flag_spec_CXX='$wl-rpath,$libdir' + hardcode_libdir_separator_CXX=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) old_archive_cmds_CXX='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) old_archive_cmds_CXX='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + cxx*) + case $host in + osf3*) + allow_undefined_flag_CXX=' $wl-expect_unresolved $wl\*' + archive_cmds_CXX='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $soname `test -n "$verstring" && func_echo_all "$wl-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + ;; + *) + allow_undefined_flag_CXX=' -expect_unresolved \*' + archive_cmds_CXX='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds_CXX='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname $wl-input $wl$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~ + $RM $lib.exp' + hardcode_libdir_flag_spec_CXX='-rpath $libdir' + ;; + esac + + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes,no = "$GXX,$with_gnu_ld"; then + allow_undefined_flag_CXX=' $wl-expect_unresolved $wl\*' + case $host in + osf3*) + archive_cmds_CXX='$CC -shared -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + *) + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + esac + + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' + hardcode_libdir_separator_CXX=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + archive_cmds_need_lc_CXX=yes + no_undefined_flag_CXX=' -zdefs' + archive_cmds_CXX='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag $wl-M $wl$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + hardcode_libdir_flag_spec_CXX='-R$libdir' + hardcode_shlibpath_var_CXX=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + whole_archive_flag_spec_CXX='-z allextract$convenience -z defaultextract' + ;; + esac + link_all_deplibs_CXX=yes + + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + old_archive_cmds_CXX='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + archive_cmds_CXX='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + old_archive_cmds_CXX='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test yes,no = "$GXX,$with_gnu_ld"; then + no_undefined_flag_CXX=' $wl-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + archive_cmds_CXX='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + else + # g++ 2.7 appears to require '-G' NOT '-shared' on this + # platform. + archive_cmds_CXX='$CC -G -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + archive_expsym_cmds_CXX='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + fi + + hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir' + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + whole_archive_flag_spec_CXX='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag_CXX='$wl-z,text' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds_CXX='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag_CXX='$wl-z,text' + allow_undefined_flag_CXX='$wl-z,nodefs' + archive_cmds_need_lc_CXX=no + hardcode_shlibpath_var_CXX=no + hardcode_libdir_flag_spec_CXX='$wl-R,$libdir' + hardcode_libdir_separator_CXX=':' + link_all_deplibs_CXX=yes + export_dynamic_flag_spec_CXX='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + archive_cmds_CXX='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + old_archive_cmds_CXX='$CC -Tprelink_objects $oldobjs~ + '"$old_archive_cmds_CXX" + reload_cmds_CXX='$CC -Tprelink_objects $reload_objs~ + '"$reload_cmds_CXX" + ;; + *) + archive_cmds_CXX='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds_CXX='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + + *) + # FIXME: insert proper C++ library support + ld_shlibs_CXX=no + ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } + test no = "$ld_shlibs_CXX" && can_build_shared=no + + GCC_CXX=$GXX + LD_CXX=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + # Dependencies to place before and after the object being linked: +predep_objects_CXX= +postdep_objects_CXX= +predeps_CXX= +postdeps_CXX= +compiler_lib_search_path_CXX= + +cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF + + +_lt_libdeps_save_CFLAGS=$CFLAGS +case "$CC $CFLAGS " in #( +*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; +*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; +*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; +esac + +if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $prev$p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test x-L = "$p" || + test x-R = "$p"; then + prev=$p + continue + fi + + # Expand the sysroot to ease extracting the directories later. + if test -z "$prev"; then + case $p in + -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; + -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; + -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; + esac + fi + case $p in + =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; + esac + if test no = "$pre_test_object_deps_done"; then + case $prev in + -L | -R) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$compiler_lib_search_path_CXX"; then + compiler_lib_search_path_CXX=$prev$p + else + compiler_lib_search_path_CXX="${compiler_lib_search_path_CXX} $prev$p" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$postdeps_CXX"; then + postdeps_CXX=$prev$p + else + postdeps_CXX="${postdeps_CXX} $prev$p" + fi + fi + prev= + ;; + + *.lto.$objext) ;; # Ignore GCC LTO objects + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test no = "$pre_test_object_deps_done"; then + if test -z "$predep_objects_CXX"; then + predep_objects_CXX=$p + else + predep_objects_CXX="$predep_objects_CXX $p" + fi + else + if test -z "$postdep_objects_CXX"; then + postdep_objects_CXX=$p + else + postdep_objects_CXX="$postdep_objects_CXX $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling CXX test program" +fi + +$RM -f confest.$objext +CFLAGS=$_lt_libdeps_save_CFLAGS + +# PORTME: override above test on systems where it is broken +case $host_os in +interix[3-9]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + predep_objects_CXX= + postdep_objects_CXX= + postdeps_CXX= + ;; +esac + + +case " $postdeps_CXX " in +*" -lc "*) archive_cmds_need_lc_CXX=no ;; +esac + compiler_lib_search_dirs_CXX= +if test -n "${compiler_lib_search_path_CXX}"; then + compiler_lib_search_dirs_CXX=`echo " ${compiler_lib_search_path_CXX}" | $SED -e 's! -L! !g' -e 's!^ !!'` +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lt_prog_compiler_wl_CXX= +lt_prog_compiler_pic_CXX= +lt_prog_compiler_static_CXX= + + + # C++ specific cases for pic, static, wl, etc. + if test yes = "$GXX"; then + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + fi + lt_prog_compiler_pic_CXX='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic_CXX='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + lt_prog_compiler_pic_CXX='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic_CXX='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static_CXX='$wl-static' + ;; + esac + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic_CXX='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + lt_prog_compiler_pic_CXX= + ;; + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + lt_prog_compiler_static_CXX= + ;; + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic_CXX=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic_CXX='-fPIC -shared' + ;; + *) + lt_prog_compiler_pic_CXX='-fPIC' + ;; + esac + else + case $host_os in + aix[4-9]*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static_CXX='-Bstatic' + else + lt_prog_compiler_static_CXX='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, CXX)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic_CXX='-DDLL_EXPORT' + ;; + dgux*) + case $cc_basename in + ec++*) + lt_prog_compiler_pic_CXX='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='$wl-a ${wl}archive' + if test ia64 != "$host_cpu"; then + lt_prog_compiler_pic_CXX='+Z' + fi + ;; + aCC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='$wl-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic_CXX='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_static_CXX='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + lt_prog_compiler_wl_CXX='--backend -Wl,' + lt_prog_compiler_pic_CXX='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64, which still supported -KPIC. + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-fPIC' + lt_prog_compiler_static_CXX='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-fpic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + xlc* | xlC* | bgxl[cC]* | mpixl[cC]*) + # IBM XL 8.0, 9.0 on PPC and BlueGene + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-qpic' + lt_prog_compiler_static_CXX='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + lt_prog_compiler_wl_CXX='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + lt_prog_compiler_pic_CXX='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic_CXX='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + lt_prog_compiler_wl_CXX='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + lt_prog_compiler_pic_CXX='-pic' + ;; + cxx*) + # Digital/Compaq C++ + lt_prog_compiler_wl_CXX='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + lt_prog_compiler_pic_CXX= + lt_prog_compiler_static_CXX='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + lt_prog_compiler_wl_CXX='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + lt_prog_compiler_pic_CXX='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + lt_prog_compiler_pic_CXX='-pic' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + lcc*) + # Lucid + lt_prog_compiler_pic_CXX='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + lt_prog_compiler_wl_CXX='-Wl,' + lt_prog_compiler_pic_CXX='-KPIC' + lt_prog_compiler_static_CXX='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + lt_prog_compiler_pic_CXX='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + lt_prog_compiler_can_build_shared_CXX=no + ;; + esac + fi + +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic_CXX= + ;; + *) + lt_prog_compiler_pic_CXX="$lt_prog_compiler_pic_CXX -DPIC" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_CXX=$lt_prog_compiler_pic_CXX +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_CXX" >&6; } +lt_prog_compiler_pic_CXX=$lt_cv_prog_compiler_pic_CXX + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... " >&6; } +if ${lt_cv_prog_compiler_pic_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works_CXX=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic_CXX -DPIC" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works_CXX=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works_CXX" >&6; } + +if test yes = "$lt_cv_prog_compiler_pic_works_CXX"; then + case $lt_prog_compiler_pic_CXX in + "" | " "*) ;; + *) lt_prog_compiler_pic_CXX=" $lt_prog_compiler_pic_CXX" ;; + esac +else + lt_prog_compiler_pic_CXX= + lt_prog_compiler_can_build_shared_CXX=no +fi + +fi + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl_CXX eval lt_tmp_static_flag=\"$lt_prog_compiler_static_CXX\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works_CXX=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works_CXX=yes + fi + else + lt_cv_prog_compiler_static_works_CXX=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_static_works_CXX" >&6; } + +if test yes = "$lt_cv_prog_compiler_static_works_CXX"; then + : +else + lt_prog_compiler_static_CXX= +fi + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o_CXX=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_CXX=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o_CXX=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o_CXX=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } + + + + +hard_links=nottested +if test no = "$lt_cv_prog_compiler_c_o_CXX" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test no = "$hard_links"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms_CXX='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + case $host_os in + aix[4-9]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds_CXX='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + export_symbols_cmds_CXX=$ltdll_cmds + ;; + cygwin* | mingw* | cegcc*) + case $cc_basename in + cl*) + exclude_expsyms_CXX='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + ;; + *) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms_CXX='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' + ;; + esac + ;; + *) + export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } +test no = "$ld_shlibs_CXX" && can_build_shared=no + +with_gnu_ld_CXX=$with_gnu_ld + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc_CXX" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc_CXX=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $archive_cmds_CXX in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl_CXX + pic_flag=$lt_prog_compiler_pic_CXX + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag_CXX + allow_undefined_flag_CXX= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + lt_cv_archive_cmds_need_lc_CXX=no + else + lt_cv_archive_cmds_need_lc_CXX=yes + fi + allow_undefined_flag_CXX=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_CXX" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc_CXX" >&6; } + archive_cmds_need_lc_CXX=$lt_cv_archive_cmds_need_lc_CXX + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + + + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[4-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a(lib.so.V)' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o), lib.a(lib.so.V)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a(lib.so.V), lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[3-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + hardcode_libdir_flag_spec_CXX='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl_CXX\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec_CXX\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + lt_cv_shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + +fi + + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action_CXX= +if test -n "$hardcode_libdir_flag_spec_CXX" || + test -n "$runpath_var_CXX" || + test yes = "$hardcode_automatic_CXX"; then + + # We can hardcode non-existent directories. + if test no != "$hardcode_direct_CXX" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, CXX)" && + test no != "$hardcode_minus_L_CXX"; then + # Linking always hardcodes the temporary library directory. + hardcode_action_CXX=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action_CXX=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action_CXX=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_CXX" >&5 +$as_echo "$hardcode_action_CXX" >&6; } + +if test relink = "$hardcode_action_CXX" || + test yes = "$inherit_rpath_CXX"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + + fi # test -n "$compiler" + + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test yes != "$_lt_caught_CXX_error" + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + + + + + + + + + + + + + ac_config_commands="$ac_config_commands libtool" + + + + +# Only expand once: + + + +#enable -D_GNU_SOURCE since the return code value of getaddrinfo +#ifdefed with __USE_GNU +#features.h header undef's __USE_GNU and defines it only if _GNU_SOURCE is defined +#hence this define for gcc +# Check whether --enable-debug was given. +if test "${enable_debug+set}" = set; then : + enableval=$enable_debug; +else + enable_debug=no +fi + + +if test "x$enable_debug" = xyes; then + if test "x$init_cflags" = x; then + CFLAGS="" + fi + CFLAGS="$CFLAGS -g -O0 -D_GNU_SOURCE" +else + if test "x$init_cflags" = x; then + CFLAGS="-g -O2 -D_GNU_SOURCE" + fi +fi + +if test "x$enable_debug" = xyes; then + if test "x$init_cxxflags" = x; then + CXXFLAGS="" + fi + CXXFLAGS="$CXXFLAGS -g -O0" +else + if test "x$init_cxxflags" = x; then + CXXFLAGS="-g -O2" + fi +fi + + +# Check whether --with-syncapi was given. +if test "${with_syncapi+set}" = set; then : + withval=$with_syncapi; +else + with_syncapi=yes +fi + + +# Checks for libraries. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_lock in -lpthread" >&5 +$as_echo_n "checking for pthread_mutex_lock in -lpthread... " >&6; } +if ${ac_cv_lib_pthread_pthread_mutex_lock+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_mutex_lock (); +int +main () +{ +return pthread_mutex_lock (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_pthread_pthread_mutex_lock=yes +else + ac_cv_lib_pthread_pthread_mutex_lock=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_lock" >&5 +$as_echo "$ac_cv_lib_pthread_pthread_mutex_lock" >&6; } +if test "x$ac_cv_lib_pthread_pthread_mutex_lock" = xyes; then : + have_pthread=yes +else + have_pthread=no +fi + + +if test "x$with_syncapi" != xno && test "x$have_pthread" = xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot build SyncAPI -- pthread not found" >&5 +$as_echo "$as_me: WARNING: cannot build SyncAPI -- pthread not found" >&2;} + with_syncapi=no +fi +if test "x$with_syncapi" != xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: building with SyncAPI support" >&5 +$as_echo "$as_me: building with SyncAPI support" >&6;} +else + { $as_echo "$as_me:${as_lineno-$LINENO}: building without SyncAPI support" >&5 +$as_echo "$as_me: building without SyncAPI support" >&6;} +fi + + if test "x$with_syncapi" != xno; then + WANT_SYNCAPI_TRUE= + WANT_SYNCAPI_FALSE='#' +else + WANT_SYNCAPI_TRUE='#' + WANT_SYNCAPI_FALSE= +fi + + +# Checks for header files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +for ac_header in arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h sys/utsname.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +# Checks for typedefs, structures, and compiler characteristics. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +$as_echo_n "checking for an ANSI C-conforming const... " >&6; } +if ${ac_cv_c_const+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#ifndef __cplusplus + /* Ultrix mips cc rejects this sort of thing. */ + typedef int charset[2]; + const charset cs = { 0, 0 }; + /* SunOS 4.1.1 cc rejects this. */ + char const *const *pcpcc; + char **ppc; + /* NEC SVR4.0.2 mips cc rejects this. */ + struct point {int x, y;}; + static struct point const zero = {0,0}; + /* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in + an arm of an if-expression whose if-part is not a constant + expression */ + const char *g = "string"; + pcpcc = &g + (g ? g-g : 0); + /* HPUX 7.0 cc rejects these. */ + ++pcpcc; + ppc = (char**) pcpcc; + pcpcc = (char const *const *) ppc; + { /* SCO 3.2v4 cc rejects this sort of thing. */ + char tx; + char *t = &tx; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; + if (s) return 0; + } + { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; + } + { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; + } + { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; } bx; + struct s *b = &bx; b->j = 5; + } + { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; + if (!foo) return 0; + } + return !cs[0] && !zero.x; +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_const=yes +else + ac_cv_c_const=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +$as_echo "$ac_cv_c_const" >&6; } +if test $ac_cv_c_const = no; then + +$as_echo "#define const /**/" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 +$as_echo_n "checking for inline... " >&6; } +if ${ac_cv_c_inline+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_c_inline=no +for ac_kw in inline __inline__ __inline; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifndef __cplusplus +typedef int foo_t; +static $ac_kw foo_t static_foo () {return 0; } +$ac_kw foo_t foo () {return 0; } +#endif + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_inline=$ac_kw +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test "$ac_cv_c_inline" != no && break +done + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 +$as_echo "$ac_cv_c_inline" >&6; } + +case $ac_cv_c_inline in + inline | yes) ;; + *) + case $ac_cv_c_inline in + no) ac_val=;; + *) ac_val=$ac_cv_c_inline;; + esac + cat >>confdefs.h <<_ACEOF +#ifndef __cplusplus +#define inline $ac_val +#endif +_ACEOF + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5 +$as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; } +if ${ac_cv_header_time+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include + +int +main () +{ +if ((struct tm *) 0) +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_time=yes +else + ac_cv_header_time=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5 +$as_echo "$ac_cv_header_time" >&6; } +if test $ac_cv_header_time = yes; then + +$as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h + +fi + +ac_fn_c_check_type "$LINENO" "nfds_t" "ac_cv_type_nfds_t" "#include +" +if test "x$ac_cv_type_nfds_t" = xyes; then : + +$as_echo "#define POLL_NFDS_TYPE nfds_t" >>confdefs.h + +else + +$as_echo "#define POLL_NFDS_TYPE unsigned int" >>confdefs.h + +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable ipv6" >&5 +$as_echo_n "checking whether to enable ipv6... " >&6; } + +if test "$cross_compiling" = yes; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ipv6=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + /* is AF_INET6 available? */ +#include +#include +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + ipv6=yes +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ipv6=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +if test x"$ipv6" = xyes; then + USEIPV6="-DZOO_IPV6_ENABLED" + +fi + +# Determine which libraries we need to use clock_gettime +saved_LIBS="$LIBS" +LIBS="" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5 +$as_echo_n "checking for clock_gettime in -lrt... " >&6; } +if ${ac_cv_lib_rt_clock_gettime+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrt $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char clock_gettime (); +int +main () +{ +return clock_gettime (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_rt_clock_gettime=yes +else + ac_cv_lib_rt_clock_gettime=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5 +$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; } +if test "x$ac_cv_lib_rt_clock_gettime" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBRT 1 +_ACEOF + + LIBS="-lrt $LIBS" + +fi + +CLOCK_GETTIME_LIBS=$LIBS + +LIBS="$saved_LIBS" + +# Checks for library functions. +for ac_func in getcwd gethostbyname gethostname getlogin getpwuid_r gettimeofday getuid memmove memset poll socket strchr strdup strerror strtol +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +ac_config_files="$ac_config_files Makefile" + + + if + case "$host_os" in + *solaris*) + true + ;; + *) + false + ;; + esac ; then + SOLARIS_TRUE= + SOLARIS_FALSE='#' +else + SOLARIS_TRUE='#' + SOLARIS_FALSE= +fi + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + if test "x$cache_file" != "x/dev/null"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +U= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + +if test -z "${DX_COND_doc_TRUE}" && test -z "${DX_COND_doc_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_doc\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_doc_TRUE}" && test -z "${DX_COND_doc_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_doc\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_dot_TRUE}" && test -z "${DX_COND_dot_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_dot\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_dot_TRUE}" && test -z "${DX_COND_dot_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_dot\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_man_TRUE}" && test -z "${DX_COND_man_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_man\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_man_TRUE}" && test -z "${DX_COND_man_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_man\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_rtf_TRUE}" && test -z "${DX_COND_rtf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_rtf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_rtf_TRUE}" && test -z "${DX_COND_rtf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_rtf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_xml_TRUE}" && test -z "${DX_COND_xml_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_xml\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_xml_TRUE}" && test -z "${DX_COND_xml_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_xml\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chm_TRUE}" && test -z "${DX_COND_chm_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chm\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chm_TRUE}" && test -z "${DX_COND_chm_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chm\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chi_TRUE}" && test -z "${DX_COND_chi_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chi\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_chi_TRUE}" && test -z "${DX_COND_chi_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_chi\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_html_TRUE}" && test -z "${DX_COND_html_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_html\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_html_TRUE}" && test -z "${DX_COND_html_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_html\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_ps_TRUE}" && test -z "${DX_COND_ps_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_ps\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_ps_TRUE}" && test -z "${DX_COND_ps_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_ps\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_pdf_TRUE}" && test -z "${DX_COND_pdf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_pdf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_pdf_TRUE}" && test -z "${DX_COND_pdf_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_pdf\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_latex_TRUE}" && test -z "${DX_COND_latex_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_latex\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${DX_COND_latex_TRUE}" && test -z "${DX_COND_latex_FALSE}"; then + as_fn_error $? "conditional \"DX_COND_latex\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +$as_echo_n "checking that generated files are newer than configure... " >&6; } + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 +$as_echo "done" >&6; } + if test -n "$EXEEXT"; then + am__EXEEXT_TRUE= + am__EXEEXT_FALSE='#' +else + am__EXEEXT_TRUE='#' + am__EXEEXT_FALSE= +fi + +if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then + as_fn_error $? "conditional \"AMDEP\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCC\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCXX\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WANT_SYNCAPI_TRUE}" && test -z "${WANT_SYNCAPI_FALSE}"; then + as_fn_error $? "conditional \"WANT_SYNCAPI\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${SOLARIS_TRUE}" && test -z "${SOLARIS_FALSE}"; then + as_fn_error $? "conditional \"SOLARIS\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi + +: "${CONFIG_STATUS=./config.status}" +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by zookeeper C client $as_me 3.6.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + +case $ac_config_headers in *" +"*) set x $ac_config_headers; shift; ac_config_headers=$*;; +esac + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" +config_commands="$ac_config_commands" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Configuration commands: +$config_commands + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_version="\\ +zookeeper C client config.status 3.6.0 +configured by $0, generated by GNU Autoconf 2.69, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2012 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' +AWK='$AWK' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=?*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + --*=) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg= + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + $as_echo "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + '') as_fn_error $? "missing file argument" ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_HEADERS " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + as_fn_error $? "ambiguous option: \`$1' +Try \`$0 --help' for more information.";; + --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error $? "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# +# INIT-COMMANDS +# +AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" + + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +macro_version='`$ECHO "$macro_version" | $SED "$delay_single_quote_subst"`' +macro_revision='`$ECHO "$macro_revision" | $SED "$delay_single_quote_subst"`' +enable_shared='`$ECHO "$enable_shared" | $SED "$delay_single_quote_subst"`' +enable_static='`$ECHO "$enable_static" | $SED "$delay_single_quote_subst"`' +pic_mode='`$ECHO "$pic_mode" | $SED "$delay_single_quote_subst"`' +enable_fast_install='`$ECHO "$enable_fast_install" | $SED "$delay_single_quote_subst"`' +shared_archive_member_spec='`$ECHO "$shared_archive_member_spec" | $SED "$delay_single_quote_subst"`' +SHELL='`$ECHO "$SHELL" | $SED "$delay_single_quote_subst"`' +ECHO='`$ECHO "$ECHO" | $SED "$delay_single_quote_subst"`' +PATH_SEPARATOR='`$ECHO "$PATH_SEPARATOR" | $SED "$delay_single_quote_subst"`' +host_alias='`$ECHO "$host_alias" | $SED "$delay_single_quote_subst"`' +host='`$ECHO "$host" | $SED "$delay_single_quote_subst"`' +host_os='`$ECHO "$host_os" | $SED "$delay_single_quote_subst"`' +build_alias='`$ECHO "$build_alias" | $SED "$delay_single_quote_subst"`' +build='`$ECHO "$build" | $SED "$delay_single_quote_subst"`' +build_os='`$ECHO "$build_os" | $SED "$delay_single_quote_subst"`' +SED='`$ECHO "$SED" | $SED "$delay_single_quote_subst"`' +Xsed='`$ECHO "$Xsed" | $SED "$delay_single_quote_subst"`' +GREP='`$ECHO "$GREP" | $SED "$delay_single_quote_subst"`' +EGREP='`$ECHO "$EGREP" | $SED "$delay_single_quote_subst"`' +FGREP='`$ECHO "$FGREP" | $SED "$delay_single_quote_subst"`' +LD='`$ECHO "$LD" | $SED "$delay_single_quote_subst"`' +NM='`$ECHO "$NM" | $SED "$delay_single_quote_subst"`' +LN_S='`$ECHO "$LN_S" | $SED "$delay_single_quote_subst"`' +max_cmd_len='`$ECHO "$max_cmd_len" | $SED "$delay_single_quote_subst"`' +ac_objext='`$ECHO "$ac_objext" | $SED "$delay_single_quote_subst"`' +exeext='`$ECHO "$exeext" | $SED "$delay_single_quote_subst"`' +lt_unset='`$ECHO "$lt_unset" | $SED "$delay_single_quote_subst"`' +lt_SP2NL='`$ECHO "$lt_SP2NL" | $SED "$delay_single_quote_subst"`' +lt_NL2SP='`$ECHO "$lt_NL2SP" | $SED "$delay_single_quote_subst"`' +lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_quote_subst"`' +lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`' +reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`' +reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`' +OBJDUMP='`$ECHO "$OBJDUMP" | $SED "$delay_single_quote_subst"`' +deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`' +file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`' +file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`' +want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`' +DLLTOOL='`$ECHO "$DLLTOOL" | $SED "$delay_single_quote_subst"`' +sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`' +AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`' +AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`' +archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`' +STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`' +RANLIB='`$ECHO "$RANLIB" | $SED "$delay_single_quote_subst"`' +old_postinstall_cmds='`$ECHO "$old_postinstall_cmds" | $SED "$delay_single_quote_subst"`' +old_postuninstall_cmds='`$ECHO "$old_postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_cmds='`$ECHO "$old_archive_cmds" | $SED "$delay_single_quote_subst"`' +lock_old_archive_extraction='`$ECHO "$lock_old_archive_extraction" | $SED "$delay_single_quote_subst"`' +CC='`$ECHO "$CC" | $SED "$delay_single_quote_subst"`' +CFLAGS='`$ECHO "$CFLAGS" | $SED "$delay_single_quote_subst"`' +compiler='`$ECHO "$compiler" | $SED "$delay_single_quote_subst"`' +GCC='`$ECHO "$GCC" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_pipe='`$ECHO "$lt_cv_sys_global_symbol_pipe" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_cdecl='`$ECHO "$lt_cv_sys_global_symbol_to_cdecl" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_import='`$ECHO "$lt_cv_sys_global_symbol_to_import" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $SED "$delay_single_quote_subst"`' +lt_cv_nm_interface='`$ECHO "$lt_cv_nm_interface" | $SED "$delay_single_quote_subst"`' +nm_file_list_spec='`$ECHO "$nm_file_list_spec" | $SED "$delay_single_quote_subst"`' +lt_sysroot='`$ECHO "$lt_sysroot" | $SED "$delay_single_quote_subst"`' +lt_cv_truncate_bin='`$ECHO "$lt_cv_truncate_bin" | $SED "$delay_single_quote_subst"`' +objdir='`$ECHO "$objdir" | $SED "$delay_single_quote_subst"`' +MAGIC_CMD='`$ECHO "$MAGIC_CMD" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag='`$ECHO "$lt_prog_compiler_no_builtin_flag" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_pic='`$ECHO "$lt_prog_compiler_pic" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_wl='`$ECHO "$lt_prog_compiler_wl" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_static='`$ECHO "$lt_prog_compiler_static" | $SED "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o='`$ECHO "$lt_cv_prog_compiler_c_o" | $SED "$delay_single_quote_subst"`' +need_locks='`$ECHO "$need_locks" | $SED "$delay_single_quote_subst"`' +MANIFEST_TOOL='`$ECHO "$MANIFEST_TOOL" | $SED "$delay_single_quote_subst"`' +DSYMUTIL='`$ECHO "$DSYMUTIL" | $SED "$delay_single_quote_subst"`' +NMEDIT='`$ECHO "$NMEDIT" | $SED "$delay_single_quote_subst"`' +LIPO='`$ECHO "$LIPO" | $SED "$delay_single_quote_subst"`' +OTOOL='`$ECHO "$OTOOL" | $SED "$delay_single_quote_subst"`' +OTOOL64='`$ECHO "$OTOOL64" | $SED "$delay_single_quote_subst"`' +libext='`$ECHO "$libext" | $SED "$delay_single_quote_subst"`' +shrext_cmds='`$ECHO "$shrext_cmds" | $SED "$delay_single_quote_subst"`' +extract_expsyms_cmds='`$ECHO "$extract_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds_need_lc='`$ECHO "$archive_cmds_need_lc" | $SED "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes='`$ECHO "$enable_shared_with_static_runtimes" | $SED "$delay_single_quote_subst"`' +export_dynamic_flag_spec='`$ECHO "$export_dynamic_flag_spec" | $SED "$delay_single_quote_subst"`' +whole_archive_flag_spec='`$ECHO "$whole_archive_flag_spec" | $SED "$delay_single_quote_subst"`' +compiler_needs_object='`$ECHO "$compiler_needs_object" | $SED "$delay_single_quote_subst"`' +old_archive_from_new_cmds='`$ECHO "$old_archive_from_new_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds='`$ECHO "$old_archive_from_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds='`$ECHO "$archive_cmds" | $SED "$delay_single_quote_subst"`' +archive_expsym_cmds='`$ECHO "$archive_expsym_cmds" | $SED "$delay_single_quote_subst"`' +module_cmds='`$ECHO "$module_cmds" | $SED "$delay_single_quote_subst"`' +module_expsym_cmds='`$ECHO "$module_expsym_cmds" | $SED "$delay_single_quote_subst"`' +with_gnu_ld='`$ECHO "$with_gnu_ld" | $SED "$delay_single_quote_subst"`' +allow_undefined_flag='`$ECHO "$allow_undefined_flag" | $SED "$delay_single_quote_subst"`' +no_undefined_flag='`$ECHO "$no_undefined_flag" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec='`$ECHO "$hardcode_libdir_flag_spec" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_separator='`$ECHO "$hardcode_libdir_separator" | $SED "$delay_single_quote_subst"`' +hardcode_direct='`$ECHO "$hardcode_direct" | $SED "$delay_single_quote_subst"`' +hardcode_direct_absolute='`$ECHO "$hardcode_direct_absolute" | $SED "$delay_single_quote_subst"`' +hardcode_minus_L='`$ECHO "$hardcode_minus_L" | $SED "$delay_single_quote_subst"`' +hardcode_shlibpath_var='`$ECHO "$hardcode_shlibpath_var" | $SED "$delay_single_quote_subst"`' +hardcode_automatic='`$ECHO "$hardcode_automatic" | $SED "$delay_single_quote_subst"`' +inherit_rpath='`$ECHO "$inherit_rpath" | $SED "$delay_single_quote_subst"`' +link_all_deplibs='`$ECHO "$link_all_deplibs" | $SED "$delay_single_quote_subst"`' +always_export_symbols='`$ECHO "$always_export_symbols" | $SED "$delay_single_quote_subst"`' +export_symbols_cmds='`$ECHO "$export_symbols_cmds" | $SED "$delay_single_quote_subst"`' +exclude_expsyms='`$ECHO "$exclude_expsyms" | $SED "$delay_single_quote_subst"`' +include_expsyms='`$ECHO "$include_expsyms" | $SED "$delay_single_quote_subst"`' +prelink_cmds='`$ECHO "$prelink_cmds" | $SED "$delay_single_quote_subst"`' +postlink_cmds='`$ECHO "$postlink_cmds" | $SED "$delay_single_quote_subst"`' +file_list_spec='`$ECHO "$file_list_spec" | $SED "$delay_single_quote_subst"`' +variables_saved_for_relink='`$ECHO "$variables_saved_for_relink" | $SED "$delay_single_quote_subst"`' +need_lib_prefix='`$ECHO "$need_lib_prefix" | $SED "$delay_single_quote_subst"`' +need_version='`$ECHO "$need_version" | $SED "$delay_single_quote_subst"`' +version_type='`$ECHO "$version_type" | $SED "$delay_single_quote_subst"`' +runpath_var='`$ECHO "$runpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_var='`$ECHO "$shlibpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_overrides_runpath='`$ECHO "$shlibpath_overrides_runpath" | $SED "$delay_single_quote_subst"`' +libname_spec='`$ECHO "$libname_spec" | $SED "$delay_single_quote_subst"`' +library_names_spec='`$ECHO "$library_names_spec" | $SED "$delay_single_quote_subst"`' +soname_spec='`$ECHO "$soname_spec" | $SED "$delay_single_quote_subst"`' +install_override_mode='`$ECHO "$install_override_mode" | $SED "$delay_single_quote_subst"`' +postinstall_cmds='`$ECHO "$postinstall_cmds" | $SED "$delay_single_quote_subst"`' +postuninstall_cmds='`$ECHO "$postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +finish_cmds='`$ECHO "$finish_cmds" | $SED "$delay_single_quote_subst"`' +finish_eval='`$ECHO "$finish_eval" | $SED "$delay_single_quote_subst"`' +hardcode_into_libs='`$ECHO "$hardcode_into_libs" | $SED "$delay_single_quote_subst"`' +sys_lib_search_path_spec='`$ECHO "$sys_lib_search_path_spec" | $SED "$delay_single_quote_subst"`' +configure_time_dlsearch_path='`$ECHO "$configure_time_dlsearch_path" | $SED "$delay_single_quote_subst"`' +configure_time_lt_sys_library_path='`$ECHO "$configure_time_lt_sys_library_path" | $SED "$delay_single_quote_subst"`' +hardcode_action='`$ECHO "$hardcode_action" | $SED "$delay_single_quote_subst"`' +enable_dlopen='`$ECHO "$enable_dlopen" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self='`$ECHO "$enable_dlopen_self" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self_static='`$ECHO "$enable_dlopen_self_static" | $SED "$delay_single_quote_subst"`' +old_striplib='`$ECHO "$old_striplib" | $SED "$delay_single_quote_subst"`' +striplib='`$ECHO "$striplib" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_dirs='`$ECHO "$compiler_lib_search_dirs" | $SED "$delay_single_quote_subst"`' +predep_objects='`$ECHO "$predep_objects" | $SED "$delay_single_quote_subst"`' +postdep_objects='`$ECHO "$postdep_objects" | $SED "$delay_single_quote_subst"`' +predeps='`$ECHO "$predeps" | $SED "$delay_single_quote_subst"`' +postdeps='`$ECHO "$postdeps" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_path='`$ECHO "$compiler_lib_search_path" | $SED "$delay_single_quote_subst"`' +LD_CXX='`$ECHO "$LD_CXX" | $SED "$delay_single_quote_subst"`' +reload_flag_CXX='`$ECHO "$reload_flag_CXX" | $SED "$delay_single_quote_subst"`' +reload_cmds_CXX='`$ECHO "$reload_cmds_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_cmds_CXX='`$ECHO "$old_archive_cmds_CXX" | $SED "$delay_single_quote_subst"`' +compiler_CXX='`$ECHO "$compiler_CXX" | $SED "$delay_single_quote_subst"`' +GCC_CXX='`$ECHO "$GCC_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag_CXX='`$ECHO "$lt_prog_compiler_no_builtin_flag_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_pic_CXX='`$ECHO "$lt_prog_compiler_pic_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_wl_CXX='`$ECHO "$lt_prog_compiler_wl_CXX" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_static_CXX='`$ECHO "$lt_prog_compiler_static_CXX" | $SED "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o_CXX='`$ECHO "$lt_cv_prog_compiler_c_o_CXX" | $SED "$delay_single_quote_subst"`' +archive_cmds_need_lc_CXX='`$ECHO "$archive_cmds_need_lc_CXX" | $SED "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes_CXX='`$ECHO "$enable_shared_with_static_runtimes_CXX" | $SED "$delay_single_quote_subst"`' +export_dynamic_flag_spec_CXX='`$ECHO "$export_dynamic_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +whole_archive_flag_spec_CXX='`$ECHO "$whole_archive_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +compiler_needs_object_CXX='`$ECHO "$compiler_needs_object_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_from_new_cmds_CXX='`$ECHO "$old_archive_from_new_cmds_CXX" | $SED "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds_CXX='`$ECHO "$old_archive_from_expsyms_cmds_CXX" | $SED "$delay_single_quote_subst"`' +archive_cmds_CXX='`$ECHO "$archive_cmds_CXX" | $SED "$delay_single_quote_subst"`' +archive_expsym_cmds_CXX='`$ECHO "$archive_expsym_cmds_CXX" | $SED "$delay_single_quote_subst"`' +module_cmds_CXX='`$ECHO "$module_cmds_CXX" | $SED "$delay_single_quote_subst"`' +module_expsym_cmds_CXX='`$ECHO "$module_expsym_cmds_CXX" | $SED "$delay_single_quote_subst"`' +with_gnu_ld_CXX='`$ECHO "$with_gnu_ld_CXX" | $SED "$delay_single_quote_subst"`' +allow_undefined_flag_CXX='`$ECHO "$allow_undefined_flag_CXX" | $SED "$delay_single_quote_subst"`' +no_undefined_flag_CXX='`$ECHO "$no_undefined_flag_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec_CXX='`$ECHO "$hardcode_libdir_flag_spec_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_separator_CXX='`$ECHO "$hardcode_libdir_separator_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_direct_CXX='`$ECHO "$hardcode_direct_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_direct_absolute_CXX='`$ECHO "$hardcode_direct_absolute_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_minus_L_CXX='`$ECHO "$hardcode_minus_L_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_shlibpath_var_CXX='`$ECHO "$hardcode_shlibpath_var_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_automatic_CXX='`$ECHO "$hardcode_automatic_CXX" | $SED "$delay_single_quote_subst"`' +inherit_rpath_CXX='`$ECHO "$inherit_rpath_CXX" | $SED "$delay_single_quote_subst"`' +link_all_deplibs_CXX='`$ECHO "$link_all_deplibs_CXX" | $SED "$delay_single_quote_subst"`' +always_export_symbols_CXX='`$ECHO "$always_export_symbols_CXX" | $SED "$delay_single_quote_subst"`' +export_symbols_cmds_CXX='`$ECHO "$export_symbols_cmds_CXX" | $SED "$delay_single_quote_subst"`' +exclude_expsyms_CXX='`$ECHO "$exclude_expsyms_CXX" | $SED "$delay_single_quote_subst"`' +include_expsyms_CXX='`$ECHO "$include_expsyms_CXX" | $SED "$delay_single_quote_subst"`' +prelink_cmds_CXX='`$ECHO "$prelink_cmds_CXX" | $SED "$delay_single_quote_subst"`' +postlink_cmds_CXX='`$ECHO "$postlink_cmds_CXX" | $SED "$delay_single_quote_subst"`' +file_list_spec_CXX='`$ECHO "$file_list_spec_CXX" | $SED "$delay_single_quote_subst"`' +hardcode_action_CXX='`$ECHO "$hardcode_action_CXX" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_dirs_CXX='`$ECHO "$compiler_lib_search_dirs_CXX" | $SED "$delay_single_quote_subst"`' +predep_objects_CXX='`$ECHO "$predep_objects_CXX" | $SED "$delay_single_quote_subst"`' +postdep_objects_CXX='`$ECHO "$postdep_objects_CXX" | $SED "$delay_single_quote_subst"`' +predeps_CXX='`$ECHO "$predeps_CXX" | $SED "$delay_single_quote_subst"`' +postdeps_CXX='`$ECHO "$postdeps_CXX" | $SED "$delay_single_quote_subst"`' +compiler_lib_search_path_CXX='`$ECHO "$compiler_lib_search_path_CXX" | $SED "$delay_single_quote_subst"`' + +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$1 +_LTECHO_EOF' +} + +# Quote evaled strings. +for var in SHELL \ +ECHO \ +PATH_SEPARATOR \ +SED \ +GREP \ +EGREP \ +FGREP \ +LD \ +NM \ +LN_S \ +lt_SP2NL \ +lt_NL2SP \ +reload_flag \ +OBJDUMP \ +deplibs_check_method \ +file_magic_cmd \ +file_magic_glob \ +want_nocaseglob \ +DLLTOOL \ +sharedlib_from_linklib_cmd \ +AR \ +AR_FLAGS \ +archiver_list_spec \ +STRIP \ +RANLIB \ +CC \ +CFLAGS \ +compiler \ +lt_cv_sys_global_symbol_pipe \ +lt_cv_sys_global_symbol_to_cdecl \ +lt_cv_sys_global_symbol_to_import \ +lt_cv_sys_global_symbol_to_c_name_address \ +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \ +lt_cv_nm_interface \ +nm_file_list_spec \ +lt_cv_truncate_bin \ +lt_prog_compiler_no_builtin_flag \ +lt_prog_compiler_pic \ +lt_prog_compiler_wl \ +lt_prog_compiler_static \ +lt_cv_prog_compiler_c_o \ +need_locks \ +MANIFEST_TOOL \ +DSYMUTIL \ +NMEDIT \ +LIPO \ +OTOOL \ +OTOOL64 \ +shrext_cmds \ +export_dynamic_flag_spec \ +whole_archive_flag_spec \ +compiler_needs_object \ +with_gnu_ld \ +allow_undefined_flag \ +no_undefined_flag \ +hardcode_libdir_flag_spec \ +hardcode_libdir_separator \ +exclude_expsyms \ +include_expsyms \ +file_list_spec \ +variables_saved_for_relink \ +libname_spec \ +library_names_spec \ +soname_spec \ +install_override_mode \ +finish_eval \ +old_striplib \ +striplib \ +compiler_lib_search_dirs \ +predep_objects \ +postdep_objects \ +predeps \ +postdeps \ +compiler_lib_search_path \ +LD_CXX \ +reload_flag_CXX \ +compiler_CXX \ +lt_prog_compiler_no_builtin_flag_CXX \ +lt_prog_compiler_pic_CXX \ +lt_prog_compiler_wl_CXX \ +lt_prog_compiler_static_CXX \ +lt_cv_prog_compiler_c_o_CXX \ +export_dynamic_flag_spec_CXX \ +whole_archive_flag_spec_CXX \ +compiler_needs_object_CXX \ +with_gnu_ld_CXX \ +allow_undefined_flag_CXX \ +no_undefined_flag_CXX \ +hardcode_libdir_flag_spec_CXX \ +hardcode_libdir_separator_CXX \ +exclude_expsyms_CXX \ +include_expsyms_CXX \ +file_list_spec_CXX \ +compiler_lib_search_dirs_CXX \ +predep_objects_CXX \ +postdep_objects_CXX \ +predeps_CXX \ +postdeps_CXX \ +compiler_lib_search_path_CXX; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in reload_cmds \ +old_postinstall_cmds \ +old_postuninstall_cmds \ +old_archive_cmds \ +extract_expsyms_cmds \ +old_archive_from_new_cmds \ +old_archive_from_expsyms_cmds \ +archive_cmds \ +archive_expsym_cmds \ +module_cmds \ +module_expsym_cmds \ +export_symbols_cmds \ +prelink_cmds \ +postlink_cmds \ +postinstall_cmds \ +postuninstall_cmds \ +finish_cmds \ +sys_lib_search_path_spec \ +configure_time_dlsearch_path \ +configure_time_lt_sys_library_path \ +reload_cmds_CXX \ +old_archive_cmds_CXX \ +old_archive_from_new_cmds_CXX \ +old_archive_from_expsyms_cmds_CXX \ +archive_cmds_CXX \ +archive_expsym_cmds_CXX \ +module_cmds_CXX \ +module_expsym_cmds_CXX \ +export_symbols_cmds_CXX \ +prelink_cmds_CXX \ +postlink_cmds_CXX; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +ac_aux_dir='$ac_aux_dir' + +# See if we are running on zsh, and set the options that allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + + + PACKAGE='$PACKAGE' + VERSION='$VERSION' + RM='$RM' + ofile='$ofile' + + + + + + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; + "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= ac_tmp= + trap 'exit_status=$? + : "${ac_tmp:=$tmp}" + { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 +ac_tmp=$tmp + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$ac_tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ + || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove sole $(srcdir), +# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ +h +s/// +s/^/:/ +s/[ ]*$/:/ +s/:\$(srcdir):/:/g +s/:\${srcdir}:/:/g +s/:@srcdir@:/:/g +s/^:*// +s/:*$// +x +s/\(=[ ]*\).*/\1/ +G +s/\n// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + +# Set up the scripts for CONFIG_HEADERS section. +# No need to generate them if there are no CONFIG_HEADERS. +# This happens for instance with `./config.status Makefile'. +if test -n "$CONFIG_HEADERS"; then +cat >"$ac_tmp/defines.awk" <<\_ACAWK || +BEGIN { +_ACEOF + +# Transform confdefs.h into an awk script `defines.awk', embedded as +# here-document in config.status, that substitutes the proper values into +# config.h.in to produce config.h. + +# Create a delimiter string that does not exist in confdefs.h, to ease +# handling of long lines. +ac_delim='%!_!# ' +for ac_last_try in false false :; do + ac_tt=`sed -n "/$ac_delim/p" confdefs.h` + if test -z "$ac_tt"; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +# For the awk script, D is an array of macro values keyed by name, +# likewise P contains macro parameters if any. Preserve backslash +# newline sequences. + +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +sed -n ' +s/.\{148\}/&'"$ac_delim"'/g +t rset +:rset +s/^[ ]*#[ ]*define[ ][ ]*/ / +t def +d +:def +s/\\$// +t bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3"/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p +d +:bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3\\\\\\n"\\/p +t cont +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p +t cont +d +:cont +n +s/.\{148\}/&'"$ac_delim"'/g +t clear +:clear +s/\\$// +t bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/"/p +d +:bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p +b cont +' >$CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + for (key in D) D_is_set[key] = 1 + FS = "" +} +/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { + line = \$ 0 + split(line, arg, " ") + if (arg[1] == "#") { + defundef = arg[2] + mac1 = arg[3] + } else { + defundef = substr(arg[1], 2) + mac1 = arg[2] + } + split(mac1, mac2, "(") #) + macro = mac2[1] + prefix = substr(line, 1, index(line, defundef) - 1) + if (D_is_set[macro]) { + # Preserve the white space surrounding the "#". + print prefix "define", macro P[macro] D[macro] + next + } else { + # Replace #undef with comments. This is necessary, for example, + # in the case of _POSIX_SOURCE, which is predefined and required + # on some systems where configure will not decide to define it. + if (defundef == "undef") { + print "/*", prefix defundef, macro, "*/" + next + } + } +} +{ print } +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 +fi # test -n "$CONFIG_HEADERS" + + +eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$ac_tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$ac_tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ + >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + "$ac_tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&2;} + + rm -f "$ac_tmp/stdin" + case $ac_file in + -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; + *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; + esac \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + ;; + :H) + # + # CONFIG_HEADER + # + if test x"$ac_file" != x-; then + { + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" + } >"$ac_tmp/config.h" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +$as_echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f "$ac_file" + mv "$ac_tmp/config.h" "$ac_file" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + fi + else + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ + || as_fn_error $? "could not create -" "$LINENO" 5 + fi +# Compute "$ac_file"'s index in $config_headers. +_am_arg="$ac_file" +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || +$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$_am_arg" : 'X\(//\)[^/]' \| \ + X"$_am_arg" : 'X\(//\)$' \| \ + X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$_am_arg" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'`/stamp-h$_am_stamp_count + ;; + + :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +$as_echo "$as_me: executing $ac_file commands" >&6;} + ;; + esac + + + case $ac_file$ac_mode in + "depfiles":C) test x"$AMDEP_TRUE" != x"" || { + # Older Autoconf quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named 'Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`$as_dirname -- "$mf" || +$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$mf" : 'X\(//\)[^/]' \| \ + X"$mf" : 'X\(//\)$' \| \ + X"$mf" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$mf" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running 'make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "$am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`$as_dirname -- "$file" || +$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$file" : 'X\(//\)[^/]' \| \ + X"$file" : 'X\(//\)$' \| \ + X"$file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir=$dirpart/$fdir; as_fn_mkdir_p + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} + ;; + "libtool":C) + + # See if we are running on zsh, and set the options that allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST + fi + + cfgfile=${ofile}T + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL +# Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. + +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit, 1996 + +# Copyright (C) 2014 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program or library that is built +# using GNU Libtool, you may include this file under the same +# distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# The names of the tagged configurations supported by this script. +available_tags='CXX ' + +# Configured defaults for sys_lib_dlsearch_path munging. +: \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} + +# ### BEGIN LIBTOOL CONFIG + +# Which release of libtool.m4 was used? +macro_version=$macro_version +macro_revision=$macro_revision + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# What type of objects to build. +pic_mode=$pic_mode + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# Shared archive member basename,for filename based shared library versioning on AIX. +shared_archive_member_spec=$shared_archive_member_spec + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# An echo program that protects backslashes. +ECHO=$lt_ECHO + +# The PATH separator for the build system. +PATH_SEPARATOR=$lt_PATH_SEPARATOR + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="\$SED -e 1s/^X//" + +# A grep program that handles long lines. +GREP=$lt_GREP + +# An ERE matcher. +EGREP=$lt_EGREP + +# A literal string matcher. +FGREP=$lt_FGREP + +# A BSD- or MS-compatible name lister. +NM=$lt_NM + +# Whether we need soft or hard links. +LN_S=$lt_LN_S + +# What is the maximum length of a command? +max_cmd_len=$max_cmd_len + +# Object file suffix (normally "o"). +objext=$ac_objext + +# Executable file suffix (normally ""). +exeext=$exeext + +# whether the shell understands "unset". +lt_unset=$lt_unset + +# turn spaces into newlines. +SP2NL=$lt_lt_SP2NL + +# turn newlines into spaces. +NL2SP=$lt_lt_NL2SP + +# convert \$build file names to \$host format. +to_host_file_cmd=$lt_cv_to_host_file_cmd + +# convert \$build files to toolchain format. +to_tool_file_cmd=$lt_cv_to_tool_file_cmd + +# An object symbol dumper. +OBJDUMP=$lt_OBJDUMP + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method = "file_magic". +file_magic_cmd=$lt_file_magic_cmd + +# How to find potential files when deplibs_check_method = "file_magic". +file_magic_glob=$lt_file_magic_glob + +# Find potential files using nocaseglob when deplibs_check_method = "file_magic". +want_nocaseglob=$lt_want_nocaseglob + +# DLL creation program. +DLLTOOL=$lt_DLLTOOL + +# Command to associate shared and link libraries. +sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd + +# The archiver. +AR=$lt_AR + +# Flags to create an archive. +AR_FLAGS=$lt_AR_FLAGS + +# How to feed a file listing to the archiver. +archiver_list_spec=$lt_archiver_list_spec + +# A symbol stripping program. +STRIP=$lt_STRIP + +# Commands used to install an old-style archive. +RANLIB=$lt_RANLIB +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Whether to use a lock for old archive extraction. +lock_old_archive_extraction=$lock_old_archive_extraction + +# A C compiler. +LTCC=$lt_CC + +# LTCC compiler flags. +LTCFLAGS=$lt_CFLAGS + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration. +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm into a list of symbols to manually relocate. +global_symbol_to_import=$lt_lt_cv_sys_global_symbol_to_import + +# Transform the output of nm in a C name address pair. +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# Transform the output of nm in a C name address pair when lib prefix is needed. +global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix + +# The name lister interface. +nm_interface=$lt_lt_cv_nm_interface + +# Specify filename containing input files for \$NM. +nm_file_list_spec=$lt_nm_file_list_spec + +# The root where to search for dependent libraries,and where our libraries should be installed. +lt_sysroot=$lt_sysroot + +# Command to truncate a binary pipe. +lt_truncate_bin=$lt_lt_cv_truncate_bin + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# Used to examine libraries when file_magic_cmd begins with "file". +MAGIC_CMD=$MAGIC_CMD + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Manifest tool. +MANIFEST_TOOL=$lt_MANIFEST_TOOL + +# Tool to manipulate archived DWARF debug symbol files on Mac OS X. +DSYMUTIL=$lt_DSYMUTIL + +# Tool to change global to local symbols on Mac OS X. +NMEDIT=$lt_NMEDIT + +# Tool to manipulate fat objects and archives on Mac OS X. +LIPO=$lt_LIPO + +# ldd/readelf like tool for Mach-O binaries on Mac OS X. +OTOOL=$lt_OTOOL + +# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4. +OTOOL64=$lt_OTOOL64 + +# Old archive suffix (normally "a"). +libext=$libext + +# Shared library suffix (normally ".so"). +shrext_cmds=$lt_shrext_cmds + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at link time. +variables_saved_for_relink=$lt_variables_saved_for_relink + +# Do we need the "lib" prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Library versioning type. +version_type=$version_type + +# Shared library runtime path variable. +runpath_var=$runpath_var + +# Shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Permission mode override for installation of shared libraries. +install_override_mode=$lt_install_override_mode + +# Command to use after installation of a shared archive. +postinstall_cmds=$lt_postinstall_cmds + +# Command to use after uninstallation of a shared archive. +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# As "finish_cmds", except a single script fragment to be evaled but +# not shown. +finish_eval=$lt_finish_eval + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Compile-time system search path for libraries. +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Detected run-time system search path for libraries. +sys_lib_dlsearch_path_spec=$lt_configure_time_dlsearch_path + +# Explicit LT_SYS_LIBRARY_PATH set during ./configure time. +configure_time_lt_sys_library_path=$lt_configure_time_lt_sys_library_path + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + + +# The linker used to build libraries. +LD=$lt_LD + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds + +# A language specific compiler. +CC=$lt_compiler + +# Is the compiler the GNU compiler? +with_gcc=$GCC + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds +archive_expsym_cmds=$lt_archive_expsym_cmds + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds +module_expsym_cmds=$lt_module_expsym_cmds + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds + +# Commands necessary for finishing linking programs. +postlink_cmds=$lt_postlink_cmds + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action + +# The directories searched by this compiler when creating a shared library. +compiler_lib_search_dirs=$lt_compiler_lib_search_dirs + +# Dependencies to place before and after the objects being linked to +# create a shared library. +predep_objects=$lt_predep_objects +postdep_objects=$lt_postdep_objects +predeps=$lt_predeps +postdeps=$lt_postdeps + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path + +# ### END LIBTOOL CONFIG + +_LT_EOF + + cat <<'_LT_EOF' >> "$cfgfile" + +# ### BEGIN FUNCTIONS SHARED WITH CONFIGURE + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x$2 in + x) + ;; + *:) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'` \$$1\" + ;; + x:*) + eval $1=\"\$$1 `$ECHO $2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval $1=\"\$$1\ `$ECHO $2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval $1=\"`$ECHO $2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \$$1\" + ;; + *) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'`\" + ;; + esac +} + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in $*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + + +# ### END FUNCTIONS SHARED WITH CONFIGURE + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + +ltmain=$ac_aux_dir/ltmain.sh + + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" + + + cat <<_LT_EOF >> "$ofile" + +# ### BEGIN LIBTOOL TAG CONFIG: CXX + +# The linker used to build libraries. +LD=$lt_LD_CXX + +# How to create reloadable object files. +reload_flag=$lt_reload_flag_CXX +reload_cmds=$lt_reload_cmds_CXX + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds_CXX + +# A language specific compiler. +CC=$lt_compiler_CXX + +# Is the compiler the GNU compiler? +with_gcc=$GCC_CXX + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag_CXX + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic_CXX + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl_CXX + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static_CXX + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o_CXX + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc_CXX + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes_CXX + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec_CXX + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec_CXX + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object_CXX + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds_CXX + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds_CXX + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds_CXX +archive_expsym_cmds=$lt_archive_expsym_cmds_CXX + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds_CXX +module_expsym_cmds=$lt_module_expsym_cmds_CXX + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld_CXX + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag_CXX + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag_CXX + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec_CXX + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator_CXX + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct_CXX + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute_CXX + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L_CXX + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var_CXX + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic_CXX + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath_CXX + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs_CXX + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols_CXX + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds_CXX + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms_CXX + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms_CXX + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds_CXX + +# Commands necessary for finishing linking programs. +postlink_cmds=$lt_postlink_cmds_CXX + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec_CXX + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action_CXX + +# The directories searched by this compiler when creating a shared library. +compiler_lib_search_dirs=$lt_compiler_lib_search_dirs_CXX + +# Dependencies to place before and after the objects being linked to +# create a shared library. +predep_objects=$lt_predep_objects_CXX +postdep_objects=$lt_postdep_objects_CXX +predeps=$lt_predeps_CXX +postdeps=$lt_postdeps_CXX + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_compiler_lib_search_path_CXX + +# ### END LIBTOOL TAG CONFIG: CXX +_LT_EOF + + ;; + + esac +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit 1 +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + diff --git a/src/c/configure.ac b/src/c/configure.ac new file mode 100644 index 00000000000..b4a1752a49c --- /dev/null +++ b/src/c/configure.ac @@ -0,0 +1,167 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) + +AC_INIT([zookeeper C client],3.6.0,[user@zookeeper.apache.org],[zookeeper]) +AC_CONFIG_SRCDIR([src/zookeeper.c]) + +# Save initial CFLAGS and CXXFLAGS values before AC_PROG_CC and AC_PROG_CXX +init_cflags="$CFLAGS" +init_cxxflags="$CXXFLAGS" + +# initialize Doxygen support +DX_HTML_FEATURE(ON) +DX_CHM_FEATURE(OFF) +DX_CHI_FEATURE(OFF) +DX_MAN_FEATURE(OFF) +DX_RTF_FEATURE(OFF) +DX_XML_FEATURE(OFF) +DX_PDF_FEATURE(OFF) +DX_PS_FEATURE(OFF) +DX_INIT_DOXYGEN([zookeeper],[c-doc.Doxyfile],[docs]) + +# initialize automake +AM_INIT_AUTOMAKE([-Wall foreign]) +AC_CONFIG_HEADER([config.h]) + +# Checks for programs. +AC_ARG_WITH(cppunit, + [ --without-cppunit do not use CPPUNIT]) + +if test "$with_cppunit" = "no" ; then + CPPUNIT_PATH="No_CPPUNIT" + CPPUNIT_INCLUDE= + CPPUNIT_LIBS= +else + AM_PATH_CPPUNIT(1.10.2) +fi + +if test "$CALLER" = "ANT" ; then +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"${base_dir}/src/c/tests/zkServer.sh\\\"\"" +else +CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS -DZKSERVER_CMD=\"\\\"./tests/zkServer.sh\\\"\"" +AC_CHECK_FILES([generated/zookeeper.jute.c generated/zookeeper.jute.h],[], + [AC_MSG_ERROR([jute files are missing! Please run "ant compile_jute" while in the zookeeper top level directory.]) +]) +fi +AC_SUBST(CPPUNIT_CFLAGS) + +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_CXX +AC_PROG_INSTALL +AC_PROG_LN_S + +# AC_DISABLE_SHARED +AC_PROG_LIBTOOL + +#enable -D_GNU_SOURCE since the return code value of getaddrinfo +#ifdefed with __USE_GNU +#features.h header undef's __USE_GNU and defines it only if _GNU_SOURCE is defined +#hence this define for gcc +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug],[enable debug build [default=no]])], + [],[enable_debug=no]) + +if test "x$enable_debug" = xyes; then + if test "x$init_cflags" = x; then + CFLAGS="" + fi + CFLAGS="$CFLAGS -g -O0 -D_GNU_SOURCE" +else + if test "x$init_cflags" = x; then + CFLAGS="-g -O2 -D_GNU_SOURCE" + fi +fi + +if test "x$enable_debug" = xyes; then + if test "x$init_cxxflags" = x; then + CXXFLAGS="" + fi + CXXFLAGS="$CXXFLAGS -g -O0" +else + if test "x$init_cxxflags" = x; then + CXXFLAGS="-g -O2" + fi +fi + +AC_ARG_WITH([syncapi], + [AS_HELP_STRING([--with-syncapi],[build with support for SyncAPI [default=yes]])], + [],[with_syncapi=yes]) + +# Checks for libraries. +AC_CHECK_LIB([pthread], [pthread_mutex_lock],[have_pthread=yes],[have_pthread=no]) + +if test "x$with_syncapi" != xno && test "x$have_pthread" = xno; then + AC_MSG_WARN([cannot build SyncAPI -- pthread not found]) + with_syncapi=no +fi +if test "x$with_syncapi" != xno; then + AC_MSG_NOTICE([building with SyncAPI support]) +else + AC_MSG_NOTICE([building without SyncAPI support]) +fi + +AM_CONDITIONAL([WANT_SYNCAPI],[test "x$with_syncapi" != xno]) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h sys/utsname.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_C_INLINE +AC_HEADER_TIME +AC_CHECK_TYPE([nfds_t], + [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[poll() second argument type])], + [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[poll() second argument type])], + [#include ]) + +AC_MSG_CHECKING([whether to enable ipv6]) + +AC_TRY_RUN([ /* is AF_INET6 available? */ +#include +#include +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} +], AC_MSG_RESULT(yes) + ipv6=yes, + AC_MSG_RESULT(no) + ipv6=no, + AC_MSG_RESULT(no) + ipv6=no) + +if test x"$ipv6" = xyes; then + USEIPV6="-DZOO_IPV6_ENABLED" + AC_SUBST(USEIPV6) +fi + +# Determine which libraries we need to use clock_gettime +saved_LIBS="$LIBS" +LIBS="" +AC_CHECK_LIB(rt, clock_gettime) +CLOCK_GETTIME_LIBS=$LIBS +AC_SUBST(CLOCK_GETTIME_LIBS) +LIBS="$saved_LIBS" + +# Checks for library functions. +AC_CHECK_FUNCS([getcwd gethostbyname gethostname getlogin getpwuid_r gettimeofday getuid memmove memset poll socket strchr strdup strerror strtol]) + +AC_CONFIG_FILES([Makefile]) +AC_CANONICAL_HOST +AM_CONDITIONAL([SOLARIS],[ + case "$host_os" in + *solaris*) + true + ;; + *) + false + ;; + esac ]) +AC_OUTPUT diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JBoolean.java b/src/c/include/proto.h old mode 100755 new mode 100644 similarity index 56% rename from zookeeper/java/src/com/yahoo/jute/compiler/JBoolean.java rename to src/c/include/proto.h index b956c191f2b..933d7c28bbb --- a/zookeeper/java/src/com/yahoo/jute/compiler/JBoolean.java +++ b/src/c/include/proto.h @@ -15,29 +15,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef PROTO_H_ +#define PROTO_H_ -package com.yahoo.jute.compiler; +#ifdef __cplusplus +extern "C" { +#endif -/** - * - * @author Milind Bhandarkar - */ -public class JBoolean extends JType { - - /** Creates a new instance of JBoolean */ - public JBoolean() { - super("int", "bool", "boolean", "Bool", "Boolean", "toBoolean"); - } - - public String getSignature() { - return "z"; - } - - public String genJavaCompareTo(String fname) { - return " ret = ("+fname+" == peer."+fname+")? 0 : ("+fname+"?1:-1);\n"; - } - - public String genJavaHashCode(String fname) { - return " ret = ("+fname+")?0:1;\n"; - } +#define ZOO_NOTIFY_OP 0 +#define ZOO_CREATE_OP 1 +#define ZOO_DELETE_OP 2 +#define ZOO_EXISTS_OP 3 +#define ZOO_GETDATA_OP 4 +#define ZOO_SETDATA_OP 5 +#define ZOO_GETACL_OP 6 +#define ZOO_SETACL_OP 7 +#define ZOO_GETCHILDREN_OP 8 +#define ZOO_SYNC_OP 9 +#define ZOO_PING_OP 11 +#define ZOO_GETCHILDREN2_OP 12 +#define ZOO_CHECK_OP 13 +#define ZOO_MULTI_OP 14 +#define ZOO_CREATE2_OP 15 +#define ZOO_RECONFIG_OP 16 +#define ZOO_REMOVE_WATCHES 17 +#define ZOO_CLOSE_OP -11 +#define ZOO_SETAUTH_OP 100 +#define ZOO_SETWATCHES_OP 101 + +#ifdef __cplusplus } +#endif + +#endif /*PROTO_H_*/ diff --git a/src/c/include/recordio.h b/src/c/include/recordio.h new file mode 100644 index 00000000000..65af23978b1 --- /dev/null +++ b/src/c/include/recordio.h @@ -0,0 +1,79 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __RECORDIO_H__ +#define __RECORDIO_H__ + +#include +#ifdef WIN32 +#include "winconfig.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +struct buffer { + int32_t len; + char *buff; +}; + +void deallocate_String(char **s); +void deallocate_Buffer(struct buffer *b); +void deallocate_vector(void *d); +struct iarchive { + int (*start_record)(struct iarchive *ia, const char *tag); + int (*end_record)(struct iarchive *ia, const char *tag); + int (*start_vector)(struct iarchive *ia, const char *tag, int32_t *count); + int (*end_vector)(struct iarchive *ia, const char *tag); + int (*deserialize_Bool)(struct iarchive *ia, const char *name, int32_t *); + int (*deserialize_Int)(struct iarchive *ia, const char *name, int32_t *); + int (*deserialize_Long)(struct iarchive *ia, const char *name, int64_t *); + int (*deserialize_Buffer)(struct iarchive *ia, const char *name, + struct buffer *); + int (*deserialize_String)(struct iarchive *ia, const char *name, char **); + void *priv; +}; +struct oarchive { + int (*start_record)(struct oarchive *oa, const char *tag); + int (*end_record)(struct oarchive *oa, const char *tag); + int (*start_vector)(struct oarchive *oa, const char *tag, const int32_t *count); + int (*end_vector)(struct oarchive *oa, const char *tag); + int (*serialize_Bool)(struct oarchive *oa, const char *name, const int32_t *); + int (*serialize_Int)(struct oarchive *oa, const char *name, const int32_t *); + int (*serialize_Long)(struct oarchive *oa, const char *name, + const int64_t *); + int (*serialize_Buffer)(struct oarchive *oa, const char *name, + const struct buffer *); + int (*serialize_String)(struct oarchive *oa, const char *name, char **); + void *priv; +}; + +struct oarchive *create_buffer_oarchive(void); +void close_buffer_oarchive(struct oarchive **oa, int free_buffer); +struct iarchive *create_buffer_iarchive(char *buffer, int len); +void close_buffer_iarchive(struct iarchive **ia); +char *get_buffer(struct oarchive *); +int get_buffer_len(struct oarchive *); + +int64_t zoo_htonll(int64_t v); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/c/include/winconfig.h b/src/c/include/winconfig.h new file mode 100644 index 00000000000..ccc3c189952 --- /dev/null +++ b/src/c/include/winconfig.h @@ -0,0 +1,196 @@ +/* Define to 1 if you have the header file. */ +#undef HAVE_ARPA_INET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the file `generated/zookeeper.jute.c'. */ +#define HAVE_GENERATED_ZOOKEEPER_JUTE_C 1 + +/* Define to 1 if you have the file `generated/zookeeper.jute.h'. */ +#define HAVE_GENERATED_ZOOKEEPER_JUTE_H 1 + +/* Define to 1 if you have the `getcwd' function. */ +#undef HAVE_GETCWD + +/* Define to 1 if you have the `gethostbyname' function. */ +#undef HAVE_GETHOSTBYNAME + +/* Define to 1 if you have the `gethostname' function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the `getlogin' function. */ +#undef HAVE_GETLOGIN + +/* Define to 1 if you have the `getpwuid_r' function. */ +#undef HAVE_GETPWUID_R + +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the `getuid' function. */ +#undef HAVE_GETUID + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETDB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H + +/* Define to 1 if you have the `poll' function. */ +#undef HAVE_POLL + +/* Define to 1 if you have the `socket' function. */ +#undef HAVE_SOCKET + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strchr' function. */ +#define HAVE_STRCHR 1 + +/* Define to 1 if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strtol' function. */ +#undef HAVE_STRTOL + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UTSNAME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* Name of package */ +#define PACKAGE "c-client-src" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "user@zookeeper.apache.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "zookeeper C client" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "zookeeper C client 3.5.0 win32" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "c-client-src" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "3.5.0" + +/* poll() second argument type */ +#define POLL_NFDS_TYPE + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME + +/* Version number of package */ +#define VERSION "3.5.0" + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#define inline __inline +#endif +#ifdef WIN32 +#define __attribute__(x) +#define __func__ __FUNCTION__ + +#ifndef _WIN32_WINNT_NT4 +#define _WIN32_WINNT_NT4 0x0400 +#endif + +#define NTDDI_VERSION _WIN32_WINNT_NT4 +#define _WIN32_WINNT _WIN32_WINNT_NT4 + +#define _CRT_SECURE_NO_WARNINGS +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#undef AF_INET6 +#undef min +#undef max + +#include + +#define strtok_r strtok_s +#define localtime_r(a,b) localtime_s(b,a) +#define get_errno() errno=GetLastError() +#define random rand +#define snprintf _snprintf + +#define ACL ZKACL // Conflict with windows API + +#define EAI_ADDRFAMILY WSAEINVAL +#define EHOSTDOWN EPIPE +#define ESTALE ENODEV + +#ifndef EWOULDBLOCK +#define EWOULDBLOCK WSAEWOULDBLOCK +#endif + +#ifndef EINPROGRESS +#define EINPROGRESS WSAEINPROGRESS +#endif + +typedef int pid_t; +#endif diff --git a/src/c/include/winstdint.h b/src/c/include/winstdint.h new file mode 100644 index 00000000000..d02608a5972 --- /dev/null +++ b/src/c/include/winstdint.h @@ -0,0 +1,247 @@ +// ISO C9x compliant stdint.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006-2008 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_STDINT_H_ // [ +#define _MSC_STDINT_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include + +// For Visual Studio 6 in C++ mode and for many Visual Studio versions when +// compiling for ARM we should wrap include with 'extern "C++" {}' +// or compiler give many errors like this: +// error C2733: second C linkage of overloaded function 'wmemchr' not allowed +#ifdef __cplusplus +extern "C" { +#endif +# include +#ifdef __cplusplus +} +#endif + +// Define _W64 macros to mark types changing their size, like intptr_t. +#ifndef _W64 +# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 +# define _W64 __w64 +# else +# define _W64 +# endif +#endif + + +// 7.18.1 Integer types + +// 7.18.1.1 Exact-width integer types + +// Visual Studio 6 and Embedded Visual C++ 4 doesn't +// realize that, e.g. char has the same size as __int8 +// so we give up on __intX for them. +#if (_MSC_VER < 1300) + typedef signed char int8_t; + typedef signed short int16_t; + typedef signed int int32_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; +#else + typedef signed __int8 int8_t; + typedef signed __int16 int16_t; + typedef signed __int32 int32_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; +#endif +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; + + +// 7.18.1.2 Minimum-width integer types +typedef int8_t int_least8_t; +typedef int16_t int_least16_t; +typedef int32_t int_least32_t; +typedef int64_t int_least64_t; +typedef uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; + +// 7.18.1.3 Fastest minimum-width integer types +typedef int8_t int_fast8_t; +typedef int16_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef int64_t int_fast64_t; +typedef uint8_t uint_fast8_t; +typedef uint16_t uint_fast16_t; +typedef uint32_t uint_fast32_t; +typedef uint64_t uint_fast64_t; + +// 7.18.1.4 Integer types capable of holding object pointers +#ifdef _WIN64 // [ + typedef signed __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +#else // _WIN64 ][ + typedef _W64 signed int intptr_t; + typedef _W64 unsigned int uintptr_t; +#endif // _WIN64 ] + +// 7.18.1.5 Greatest-width integer types +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; + + +// 7.18.2 Limits of specified-width integer types + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 + +// 7.18.2.1 Limits of exact-width integer types +#define INT8_MIN ((int8_t)_I8_MIN) +#define INT8_MAX _I8_MAX +#define INT16_MIN ((int16_t)_I16_MIN) +#define INT16_MAX _I16_MAX +#define INT32_MIN ((int32_t)_I32_MIN) +#define INT32_MAX _I32_MAX +#define INT64_MIN ((int64_t)_I64_MIN) +#define INT64_MAX _I64_MAX +#define UINT8_MAX _UI8_MAX +#define UINT16_MAX _UI16_MAX +#define UINT32_MAX _UI32_MAX +#define UINT64_MAX _UI64_MAX + +// 7.18.2.2 Limits of minimum-width integer types +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +// 7.18.2.3 Limits of fastest minimum-width integer types +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +// 7.18.2.4 Limits of integer types capable of holding object pointers +#ifdef _WIN64 // [ +# define INTPTR_MIN INT64_MIN +# define INTPTR_MAX INT64_MAX +# define UINTPTR_MAX UINT64_MAX +#else // _WIN64 ][ +# define INTPTR_MIN INT32_MIN +# define INTPTR_MAX INT32_MAX +# define UINTPTR_MAX UINT32_MAX +#endif // _WIN64 ] + +// 7.18.2.5 Limits of greatest-width integer types +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +// 7.18.3 Limits of other integer types + +#ifdef _WIN64 // [ +# define PTRDIFF_MIN _I64_MIN +# define PTRDIFF_MAX _I64_MAX +#else // _WIN64 ][ +# define PTRDIFF_MIN _I32_MIN +# define PTRDIFF_MAX _I32_MAX +#endif // _WIN64 ] + +#define SIG_ATOMIC_MIN INT_MIN +#define SIG_ATOMIC_MAX INT_MAX + +#ifndef SIZE_MAX // [ +# ifdef _WIN64 // [ +# define SIZE_MAX _UI64_MAX +# else // _WIN64 ][ +# define SIZE_MAX _UI32_MAX +# endif // _WIN64 ] +#endif // SIZE_MAX ] + +// WCHAR_MIN and WCHAR_MAX are also defined in +#ifndef WCHAR_MIN // [ +# define WCHAR_MIN 0 +#endif // WCHAR_MIN ] +#ifndef WCHAR_MAX // [ +# define WCHAR_MAX _UI16_MAX +#endif // WCHAR_MAX ] + +#define WINT_MIN 0 +#define WINT_MAX _UI16_MAX + +#endif // __STDC_LIMIT_MACROS ] + + +// 7.18.4 Limits of other integer types + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 + +// 7.18.4.1 Macros for minimum-width integer constants + +#define INT8_C(val) val##i8 +#define INT16_C(val) val##i16 +#define INT32_C(val) val##i32 +#define INT64_C(val) val##i64 + +#define UINT8_C(val) val##ui8 +#define UINT16_C(val) val##ui16 +#define UINT32_C(val) val##ui32 +#define UINT64_C(val) val##ui64 + +// 7.18.4.2 Macros for greatest-width integer constants +#define INTMAX_C INT64_C +#define UINTMAX_C UINT64_C + +#endif // __STDC_CONSTANT_MACROS ] + + +#endif // _MSC_STDINT_H_ ] diff --git a/src/c/include/zookeeper.h b/src/c/include/zookeeper.h new file mode 100644 index 00000000000..18a203d75eb --- /dev/null +++ b/src/c/include/zookeeper.h @@ -0,0 +1,2064 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZOOKEEPER_H_ +#define ZOOKEEPER_H_ + +#include +#ifndef WIN32 +#include +#include +#else +#include "winconfig.h" +#endif +#include +#include + +#include "proto.h" +#include "zookeeper_version.h" +#include "recordio.h" +#include "zookeeper.jute.h" + +/** + * \file zookeeper.h + * \brief ZooKeeper functions and definitions. + * + * ZooKeeper is a network service that may be backed by a cluster of + * synchronized servers. The data in the service is represented as a tree + * of data nodes. Each node has data, children, an ACL, and status information. + * The data for a node is read and write in its entirety. + * + * ZooKeeper clients can leave watches when they queries the data or children + * of a node. If a watch is left, that client will be notified of the change. + * The notification is a one time trigger. Subsequent chances to the node will + * not trigger a notification unless the client issues a query with the watch + * flag set. If the client is ever disconnected from the service, the watches do + * not need to be reset. The client automatically resets the watches. + * + * When a node is created, it may be flagged as an ephemeral node. Ephemeral + * nodes are automatically removed when a client session is closed or when + * a session times out due to inactivity (the ZooKeeper runtime fills in + * periods of inactivity with pings). Ephemeral nodes cannot have children. + * + * ZooKeeper clients are identified by a server assigned session id. For + * security reasons The server + * also generates a corresponding password for a session. A client may save its + * id and corresponding password to persistent storage in order to use the + * session across program invocation boundaries. + */ + +/* Support for building on various platforms */ + +// on cygwin we should take care of exporting/importing symbols properly +#ifdef DLL_EXPORT +# define ZOOAPI __declspec(dllexport) +#else +# if (defined(__CYGWIN__) || defined(WIN32)) && !defined(USE_STATIC_LIB) +# define ZOOAPI __declspec(dllimport) +# else +# define ZOOAPI +# endif +#endif + +/** zookeeper return constants **/ + +enum ZOO_ERRORS { + ZOK = 0, /*!< Everything is OK */ + + /** System and server-side errors. + * This is never thrown by the server, it shouldn't be used other than + * to indicate a range. Specifically error codes greater than this + * value, but lesser than {@link #ZAPIERROR}, are system errors. */ + ZSYSTEMERROR = -1, + ZRUNTIMEINCONSISTENCY = -2, /*!< A runtime inconsistency was found */ + ZDATAINCONSISTENCY = -3, /*!< A data inconsistency was found */ + ZCONNECTIONLOSS = -4, /*!< Connection to the server has been lost */ + ZMARSHALLINGERROR = -5, /*!< Error while marshalling or unmarshalling data */ + ZUNIMPLEMENTED = -6, /*!< Operation is unimplemented */ + ZOPERATIONTIMEOUT = -7, /*!< Operation timeout */ + ZBADARGUMENTS = -8, /*!< Invalid arguments */ + ZINVALIDSTATE = -9, /*!< Invliad zhandle state */ + ZNEWCONFIGNOQUORUM = -13, /*!< No quorum of new config is connected and + up-to-date with the leader of last commmitted + config - try invoking reconfiguration after new + servers are connected and synced */ + ZRECONFIGINPROGRESS = -14, /*!< Reconfiguration requested while another + reconfiguration is currently in progress. This + is currently not supported. Please retry. */ + + /** API errors. + * This is never thrown by the server, it shouldn't be used other than + * to indicate a range. Specifically error codes greater than this + * value are API errors (while values less than this indicate a + * {@link #ZSYSTEMERROR}). + */ + ZAPIERROR = -100, + ZNONODE = -101, /*!< Node does not exist */ + ZNOAUTH = -102, /*!< Not authenticated */ + ZBADVERSION = -103, /*!< Version conflict */ + ZNOCHILDRENFOREPHEMERALS = -108, /*!< Ephemeral nodes may not have children */ + ZNODEEXISTS = -110, /*!< The node already exists */ + ZNOTEMPTY = -111, /*!< The node has children */ + ZSESSIONEXPIRED = -112, /*!< The session has been expired by the server */ + ZINVALIDCALLBACK = -113, /*!< Invalid callback specified */ + ZINVALIDACL = -114, /*!< Invalid ACL specified */ + ZAUTHFAILED = -115, /*!< Client authentication failed */ + ZCLOSING = -116, /*!< ZooKeeper is closing */ + ZNOTHING = -117, /*!< (not error) no server responses to process */ + ZSESSIONMOVED = -118, /*! + * The legacy style, an application wishing to receive events from ZooKeeper must + * first implement a function with this signature and pass a pointer to the function + * to \ref zookeeper_init. Next, the application sets a watch by calling one of + * the getter API that accept the watch integer flag (for example, \ref zoo_aexists, + * \ref zoo_get, etc). + *

+ * The watcher object style uses an instance of a "watcher object" which in + * the C world is represented by a pair: a pointer to a function implementing this + * signature and a pointer to watcher context -- handback user-specific data. + * When a watch is triggered this function will be called along with + * the watcher context. An application wishing to use this style must use + * the getter API functions with the "w" prefix in their names (for example, \ref + * zoo_awexists, \ref zoo_wget, etc). + * + * \param zh zookeeper handle + * \param type event type. This is one of the *_EVENT constants. + * \param state connection state. The state value will be one of the *_STATE constants. + * \param path znode path for which the watcher is triggered. NULL if the event + * type is ZOO_SESSION_EVENT + * \param watcherCtx watcher context. + */ +typedef void (*watcher_fn)(zhandle_t *zh, int type, + int state, const char *path,void *watcherCtx); + +/** + * \brief typedef for setting the log callback. It's a function pointer which + * returns void and accepts a const char* as its only argument. + * + * \param message message to be passed to the callback function. + */ +typedef void (*log_callback_fn)(const char *message); + +/** + * \brief create a handle to used communicate with zookeeper. + * + * This method creates a new handle and a zookeeper session that corresponds + * to that handle. Session establishment is asynchronous, meaning that the + * session should not be considered established until (and unless) an + * event of state ZOO_CONNECTED_STATE is received. + * \param host comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + * \param fn the global watcher callback function. When notifications are + * triggered this function will be invoked. + * \param clientid the id of a previously established session that this + * client will be reconnecting to. Pass 0 if not reconnecting to a previous + * session. Clients can access the session id of an established, valid, + * connection by calling \ref zoo_client_id. If the session corresponding to + * the specified clientid has expired, or if the clientid is invalid for + * any reason, the returned zhandle_t will be invalid -- the zhandle_t + * state will indicate the reason for failure (typically + * ZOO_EXPIRED_SESSION_STATE). + * \param context the handback object that will be associated with this instance + * of zhandle_t. Application can access it (for example, in the watcher + * callback) using \ref zoo_get_context. The object is not used by zookeeper + * internally and can be null. + * \param flags reserved for future use. Should be set to zero. + * \return a pointer to the opaque zhandle structure. If it fails to create + * a new zhandle the function returns NULL and the errno variable + * indicates the reason. + */ +ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn, + int recv_timeout, const clientid_t *clientid, void *context, int flags); + +/** + * \brief create a handle to communicate with zookeeper. + * + * This function is identical to \ref zookeeper_init except it allows one + * to specify an additional callback to be used for all logging for that + * specific connection. For more details on the logging callback see + * \ref zoo_get_log_callback and \ref zoo_set_log_callback. + * + * This method creates a new handle and a zookeeper session that corresponds + * to that handle. Session establishment is asynchronous, meaning that the + * session should not be considered established until (and unless) an + * event of state ZOO_CONNECTED_STATE is received. + * \param host comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + * \param fn the global watcher callback function. When notifications are + * triggered this function will be invoked. + * \param clientid the id of a previously established session that this + * client will be reconnecting to. Pass 0 if not reconnecting to a previous + * session. Clients can access the session id of an established, valid, + * connection by calling \ref zoo_client_id. If the session corresponding to + * the specified clientid has expired, or if the clientid is invalid for + * any reason, the returned zhandle_t will be invalid -- the zhandle_t + * state will indicate the reason for failure (typically + * ZOO_EXPIRED_SESSION_STATE). + * \param context the handback object that will be associated with this instance + * of zhandle_t. Application can access it (for example, in the watcher + * callback) using \ref zoo_get_context. The object is not used by zookeeper + * internally and can be null. + * \param flags reserved for future use. Should be set to zero. + * \param log_callback All log messages will be passed to this callback function. + * For more details see \ref zoo_get_log_callback and \ref zoo_set_log_callback. + * \return a pointer to the opaque zhandle structure. If it fails to create + * a new zhandle the function returns NULL and the errno variable + * indicates the reason. + */ +ZOOAPI zhandle_t *zookeeper_init2(const char *host, watcher_fn fn, + int recv_timeout, const clientid_t *clientid, void *context, int flags, + log_callback_fn log_callback); + +/** + * \brief update the list of servers this client will connect to. + * + * This method allows a client to update the connection string by providing + * a new comma separated list of host:port pairs, each corresponding to a + * ZooKeeper server. + * + * This function invokes a probabilistic load-balancing algorithm which may cause + * the client to disconnect from its current host to achieve expected uniform + * connections per server in the new list. In case the current host to which the + * client is connected is not in the new list this call will always cause the + * connection to be dropped. Otherwise, the decision is based on whether the + * number of servers has increased or decreased and by how much. + * + * If the connection is dropped, the client moves to a special "reconfig" mode + * where he chooses a new server to connect to using the probabilistic algorithm. + * After finding a server or exhaustively trying all the servers in the new list, + * the client moves back to the normal mode of operation where it will pick an + * arbitrary server from the 'host' string. + * + * See {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1355} for the + * protocol and its evaluation, + * + * \param host comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details + */ +ZOOAPI int zoo_set_servers(zhandle_t *zh, const char *hosts); + +/** + * \brief cycle to the next server on the next connection attempt. + * + * Note: typically this method should NOT be used outside of testing. + * + * This method allows a client to cycle through the list of servers in it's + * connection pool to be used on the next connection attempt. This function does + * not actually trigger a connection or state change in any way. Its purpose is + * to allow testing changing servers on the fly and the probabilistic load + * balancing algorithm. + */ +ZOOAPI void zoo_cycle_next_server(zhandle_t *zh); + +/** + * \brief get current host:port this client is connecting/connected to. + * + * Note: typically this method should NOT be used outside of testing. + * + * This method allows a client to get the current host:port that this client + * is either in the process of connecting to or is currently connected to. This + * is mainly used for testing purposes but might also come in handy as a general + * purpose tool to be used by other clients. + */ +ZOOAPI const char* zoo_get_current_server(zhandle_t* zh); + +/** + * \brief close the zookeeper handle and free up any resources. + * + * After this call, the client session will no longer be valid. The function + * will flush any outstanding send requests before return. As a result it may + * block. + * + * This method should only be called only once on a zookeeper handle. Calling + * twice will cause undefined (and probably undesirable behavior). Calling any other + * zookeeper method after calling close is undefined behaviour and should be avoided. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \return a result code. Regardless of the error code returned, the zhandle + * will be destroyed and all resources freed. + * + * ZOK - success + * ZBADARGUMENTS - invalid input parameters + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + * ZOPERATIONTIMEOUT - failed to flush the buffers within the specified timeout. + * ZCONNECTIONLOSS - a network error occured while attempting to send request to server + * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details + */ +ZOOAPI int zookeeper_close(zhandle_t *zh); + +/** + * \brief return the client session id, only valid if the connections + * is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE) + */ +ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh); + +/** + * \brief return the timeout for this session, only valid if the connections + * is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE). This + * value may change after a server re-connect. + */ +ZOOAPI int zoo_recv_timeout(zhandle_t *zh); + +/** + * \brief return the context for this handle. + */ +ZOOAPI const void *zoo_get_context(zhandle_t *zh); + +/** + * \brief set the context for this handle. + */ +ZOOAPI void zoo_set_context(zhandle_t *zh, void *context); + +/** + * \brief set a watcher function + * \return previous watcher function + */ +ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn); + +/** + * \brief returns the socket address for the current connection + * \return socket address of the connected host or NULL on failure, only valid if the + * connection is current connected + */ +ZOOAPI struct sockaddr* zookeeper_get_connected_host(zhandle_t *zh, + struct sockaddr *addr, socklen_t *addr_len); + +#ifndef THREADED +/** + * \brief Returns the events that zookeeper is interested in. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param fd is the file descriptor of interest + * \param interest is an or of the ZOOKEEPER_WRITE and ZOOKEEPER_READ flags to + * indicate the I/O of interest on fd. + * \param tv a timeout value to be used with select/poll system call + * \return a result code. + * ZOK - success + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZCONNECTIONLOSS - a network error occured while attempting to establish + * a connection to the server + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + * ZOPERATIONTIMEOUT - hasn't received anything from the server for 2/3 of the + * timeout value specified in zookeeper_init() + * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details + */ +#ifdef WIN32 +ZOOAPI int zookeeper_interest(zhandle_t *zh, SOCKET *fd, int *interest, + struct timeval *tv); +#else +ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest, + struct timeval *tv); +#endif + +/** + * \brief Notifies zookeeper that an event of interest has happened. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param events will be an OR of the ZOOKEEPER_WRITE and ZOOKEEPER_READ flags. + * \return a result code. + * ZOK - success + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZCONNECTIONLOSS - a network error occured while attempting to send request to server + * ZSESSIONEXPIRED - connection attempt failed -- the session's expired + * ZAUTHFAILED - authentication request failed, e.i. invalid credentials + * ZRUNTIMEINCONSISTENCY - a server response came out of order + * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details + * ZNOTHING -- not an error; simply indicates that there no more data from the server + * to be processed (when called with ZOOKEEPER_READ flag). + */ +ZOOAPI int zookeeper_process(zhandle_t *zh, int events); +#endif + +/** + * \brief signature of a completion function for a call that returns void. + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void (*void_completion_t)(int rc, const void *data); + +/** + * \brief signature of a completion function that returns a Stat structure. + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param stat a pointer to the stat information for the node involved in + * this function. If a non zero error code is returned, the content of + * stat is undefined. The programmer is NOT responsible for freeing stat. + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void (*stat_completion_t)(int rc, const struct Stat *stat, + const void *data); + +/** + * \brief signature of a completion function that returns data. + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param value the value of the information returned by the asynchronous call. + * If a non zero error code is returned, the content of value is undefined. + * The programmer is NOT responsible for freeing value. + * \param value_len the number of bytes in value. + * \param stat a pointer to the stat information for the node involved in + * this function. If a non zero error code is returned, the content of + * stat is undefined. The programmer is NOT responsible for freeing stat. + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void (*data_completion_t)(int rc, const char *value, int value_len, + const struct Stat *stat, const void *data); + +/** + * \brief signature of a completion function that returns a list of strings. + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param strings a pointer to the structure containng the list of strings of the + * names of the children of a node. If a non zero error code is returned, + * the content of strings is undefined. The programmer is NOT responsible + * for freeing strings. + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void (*strings_completion_t)(int rc, + const struct String_vector *strings, const void *data); + +/** + * \brief signature of a completion function that returns a string and stat. + * . + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param value the value of the string returned. + * \param stat a pointer to the stat information for the node involved in + * this function. If a non zero error code is returned, the content of + * stat is undefined. The programmer is NOT responsible for freeing stat. + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void (*string_stat_completion_t)(int rc, + const char *string, const struct Stat *stat, const void *data); + +/** + * \brief signature of a completion function that returns a list of strings and stat. + * . + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param strings a pointer to the structure containng the list of strings of the + * names of the children of a node. If a non zero error code is returned, + * the content of strings is undefined. The programmer is NOT responsible + * for freeing strings. + * \param stat a pointer to the stat information for the node involved in + * this function. If a non zero error code is returned, the content of + * stat is undefined. The programmer is NOT responsible for freeing stat. + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void (*strings_stat_completion_t)(int rc, + const struct String_vector *strings, const struct Stat *stat, + const void *data); + +/** + * \brief signature of a completion function that returns a list of strings. + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param value the value of the string returned. + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void + (*string_completion_t)(int rc, const char *value, const void *data); + +/** + * \brief signature of a completion function that returns an ACL. + * + * This method will be invoked at the end of a asynchronous call and also as + * a result of connection loss or timeout. + * \param rc the error code of the call. Connection loss/timeout triggers + * the completion with one of the following error codes: + * ZCONNECTIONLOSS -- lost connection to the server + * ZOPERATIONTIMEOUT -- connection timed out + * Data related events trigger the completion with error codes listed the + * Exceptions section of the documentation of the function that initiated the + * call. (Zero indicates call was successful.) + * \param acl a pointer to the structure containng the ACL of a node. If a non + * zero error code is returned, the content of strings is undefined. The + * programmer is NOT responsible for freeing acl. + * \param stat a pointer to the stat information for the node involved in + * this function. If a non zero error code is returned, the content of + * stat is undefined. The programmer is NOT responsible for freeing stat. + * \param data the pointer that was passed by the caller when the function + * that this completion corresponds to was invoked. The programmer + * is responsible for any memory freeing associated with the data + * pointer. + */ +typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl, + struct Stat *stat, const void *data); + +/** + * \brief get the state of the zookeeper connection. + * + * The return value will be one of the \ref State Consts. + */ +ZOOAPI int zoo_state(zhandle_t *zh); + +/** + * \brief create a node. + * + * This method will create a node in ZooKeeper. A node can only be created if + * it does not already exists. The Create Flags affect the creation of nodes. + * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the + * client session goes away. If the ZOO_SEQUENCE flag is set, a unique + * monotonically increasing sequence number is appended to the path name. The + * sequence number is always fixed length of 10 digits, 0 padded. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path The name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param value The data to be stored in the node. + * \param valuelen The number of bytes in data. + * \param acl The initial ACL of the node. The ACL must not be null or empty. + * \param flags this parameter can be set to 0 for normal create or an OR + * of the Create Flags + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the parent node does not exist. + * ZNODEEXISTS the node already exists + * ZNOAUTH the client does not have permission. + * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes. + * \param data The data that will be passed to the completion routine when the + * function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + string_completion_t completion, const void *data); + +/** + * \brief create a node asynchronously and returns stat details. + * + * This method will create a node in ZooKeeper. A node can only be created if + * it does not already exists. The Create Flags affect the creation of nodes. + * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the + * client session goes away. If the ZOO_SEQUENCE flag is set, a unique + * monotonically increasing sequence number is appended to the path name. The + * sequence number is always fixed length of 10 digits, 0 padded. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path The name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param value The data to be stored in the node. + * \param valuelen The number of bytes in data. + * \param acl The initial ACL of the node. The ACL must not be null or empty. + * \param flags this parameter can be set to 0 for normal create or an OR + * of the Create Flags + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the parent node does not exist. + * ZNODEEXISTS the node already exists + * ZNOAUTH the client does not have permission. + * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes. + * \param data The data that will be passed to the completion routine when the + * function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_acreate2(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + string_stat_completion_t completion, const void *data); + +/** + * \brief delete a node in zookeeper. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param version the expected version of the node. The function will fail if the + * actual version of the node does not match the expected version. + * If -1 is used the version check will not take place. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADVERSION expected version does not match actual version. + * ZNOTEMPTY children are present; node cannot be deleted. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version, + void_completion_t completion, const void *data); + +/** + * \brief checks the existence of a node in zookeeper. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify the + * client if the node changes. The watch will be set even if the node does not + * exist. This allows clients to watch for nodes to appear. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when the + * function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch, + stat_completion_t completion, const void *data); + +/** + * \brief checks the existence of a node in zookeeper. + * + * This function is similar to \ref zoo_axists except it allows one specify + * a watcher object - a function pointer and associated context. The function + * will be called once the watch has fired. The associated context data will be + * passed to the function as the watcher context parameter. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null a watch will set on the specified znode on the server. + * The watch will be set even if the node does not exist. This allows clients + * to watch for nodes to appear. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when the + * function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + stat_completion_t completion, const void *data); + +/** + * \brief gets the data associated with a node. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the node changes. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch, + data_completion_t completion, const void *data); + +/** + * \brief gets the data associated with a node. + * + * This function is similar to \ref zoo_aget except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_awget(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + data_completion_t completion, const void *data); + +/** + * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to + * the server to which the client is connected. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the configuration changes. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the configuration node (/zookeeper/config) does not exist. + * ZNOAUTH the client does not have permission to access the configuration node. + * \param data the configuration data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_agetconfig(zhandle_t *zh, int watch, + data_completion_t completion, const void *data); + +/** + * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to + * the server to which the client is connected. + * + * This function is similar to \ref zoo_agetconfig except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the configuration node (/zookeeper/config) does not exist. + * ZNOAUTH the client does not have permission to access the configuration node. + * \param data the configuration data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_awgetconfig(zhandle_t *zh, watcher_fn watcher, void* watcherCtx, + data_completion_t completion, const void *data); + +/** + * \brief asynchronous reconfiguration interface - allows changing ZK cluster + * ensemble membership and roles of ensemble peers. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param joining - comma separated list of servers to be added to the ensemble. + * Each has a configuration line for a server to be added (as would appear in a + * configuration file), only for maj. quorums. NULL for non-incremental reconfiguration. + * \param leaving - comma separated list of server IDs to be removed from the ensemble. + * Each has an id of a server to be removed, only for maj. quorums. NULL for + * non-incremental reconfiguration. + * \param members - comma separated list of new membership (e.g., contents of a + * membership configuration file) - for use only with a non-incremental + * reconfiguration. NULL for incremental reconfiguration. + * \param version - version of config from which we want to reconfigure - if + * current config is different reconfiguration will fail. Should be -1 to disable + * this option. + * \param completion - the routine to invoke when the request completes. The + * completion will be triggered with one of the following codes passed in as the + * rc argument: + * ZOK operation completed successfully + * \param data the configuration data that will be passed to the completion routine + * when the function completes. + * \return return value of the function call. + * ZOK operation completed successfully + * ZBADARGUMENTS - invalid input parameters (one case when this is returned is + * when the new config has less than 2 servers) + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + * ZNEWCONFIGNOQUORUM - no quorum of new config is connected and up-to-date with + * the leader of last committed config - try invoking reconfiguration after new servers are connected and synced + * ZRECONFIGINPROGRESS - another reconfig is currently in progress + */ +ZOOAPI int zoo_areconfig(zhandle_t *zh, const char *joining, const char *leaving, + const char *members, int64_t version, data_completion_t dc, const void *data); + +/** + * \brief sets the data associated with a node. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param buffer the buffer holding data to be written to the node. + * \param buflen the number of bytes from buffer to write. + * \param version the expected version of the node. The function will fail if + * the actual version of the node does not match the expected version. If -1 is + * used the version check will not take place. * completion: If null, + * the function will execute synchronously. Otherwise, the function will return + * immediately and invoke the completion routine when the request completes. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADVERSION expected version does not match actual version. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen, + int version, stat_completion_t completion, const void *data); + +/** + * \brief lists the children of a node. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the node changes. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch, + strings_completion_t completion, const void *data); + +/** + * \brief lists the children of a node. + * + * This function is similar to \ref zoo_aget_children except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + strings_completion_t completion, const void *data); + +/** + * \brief lists the children of a node, and get the parent stat. + * + * This function is new in version 3.3.0 + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the node changes. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch, + strings_stat_completion_t completion, const void *data); + +/** + * \brief lists the children of a node, and get the parent stat. + * + * This function is similar to \ref zoo_aget_children2 except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * This function is new in version 3.3.0 + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_awget_children2(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + strings_stat_completion_t completion, const void *data); + +/** + * \brief Flush leader channel. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ + +ZOOAPI int zoo_async(zhandle_t *zh, const char *path, + string_completion_t completion, const void *data); + + +/** + * \brief gets the acl associated with a node. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion, + const void *data); + +/** + * \brief sets the acl associated with a node. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param buffer the buffer holding the acls to be written to the node. + * \param buflen the number of bytes from buffer to write. + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with one of the following codes passed in as the rc argument: + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZINVALIDACL invalid ACL specified + * ZBADVERSION expected version does not match actual version. + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version, + struct ACL_vector *acl, void_completion_t, const void *data); + +/** + * \brief atomically commits multiple zookeeper operations. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param count the number of operations + * \param ops an array of operations to commit + * \param results an array to hold the results of the operations + * \param completion the routine to invoke when the request completes. The completion + * will be triggered with any of the error codes that can that can be returned by the + * ops supported by a multi op (see \ref zoo_acreate, \ref zoo_adelete, \ref zoo_aset). + * \param data the data that will be passed to the completion routine when + * the function completes. + * \return the return code for the function call. This can be any of the + * values that can be returned by the ops supported by a multi op (see + * \ref zoo_acreate, \ref zoo_adelete, \ref zoo_aset). + */ +ZOOAPI int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops, + zoo_op_result_t *results, void_completion_t, const void *data); + +/** + * \brief return an error string. + * + * \param return code + * \return string corresponding to the return code + */ +ZOOAPI const char* zerror(int c); + +/** + * \brief specify application credentials. + * + * The application calls this function to specify its credentials for purposes + * of authentication. The server will use the security provider specified by + * the scheme parameter to authenticate the client connection. If the + * authentication request has failed: + * - the server connection is dropped + * - the watcher is called with the ZOO_AUTH_FAILED_STATE value as the state + * parameter. + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param scheme the id of authentication scheme. Natively supported: + * "digest" password-based authentication + * \param cert application credentials. The actual value depends on the scheme. + * \param certLen the length of the data parameter + * \param completion the routine to invoke when the request completes. One of + * the following result codes may be passed into the completion callback: + * ZOK operation completed successfully + * ZAUTHFAILED authentication failed + * \param data the data that will be passed to the completion routine when the + * function completes. + * \return ZOK on success or one of the following errcodes on failure: + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + * ZSYSTEMERROR - a system error occured + */ +ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert, + int certLen, void_completion_t completion, const void *data); + +/** + * \brief checks if the current zookeeper connection state can't be recovered. + * + * The application must close the zhandle and try to reconnect. + * + * \param zh the zookeeper handle (see \ref zookeeper_init) + * \return ZINVALIDSTATE if connection is unrecoverable + */ +ZOOAPI int is_unrecoverable(zhandle_t *zh); + +/** + * \brief sets the debugging level for the library + */ +ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel); + +/** + * \brief sets the stream to be used by the library for logging + * + * The zookeeper library uses stderr as its default log stream. Application + * must make sure the stream is writable. Passing in NULL resets the stream + * to its default value (stderr). + */ +ZOOAPI void zoo_set_log_stream(FILE* logStream); + +/** + * \brief gets the callback to be used by this connection for logging. + * + * This is a per-connection logging mechanism that will take priority over + * the library-wide default log stream. That is, zookeeper library will first + * try to use a per-connection callback if available and if not, will fallback + * to using the logging stream. Passing in NULL resets the callback and will + * cause it to then fallback to using the logging stream as described in \ref + * zoo_set_log_stream. + */ +ZOOAPI log_callback_fn zoo_get_log_callback(const zhandle_t *zh); + +/** + * \brief sets the callback to be used by the library for logging + * + * Setting this callback has the effect of overriding the default log stream. + * Zookeeper will first try to use a per-connection callback if available + * and if not, will fallback to using the logging stream. Passing in NULL + * resets the callback and will cause it to then fallback to using the logging + * stream as described in \ref zoo_set_log_stream. + * + * Note: The provided callback will be invoked by multiple threads and therefore + * it needs to be thread-safe. + */ +ZOOAPI void zoo_set_log_callback(zhandle_t *zh, log_callback_fn callback); + +/** + * \brief enable/disable quorum endpoint order randomization + * + * Note: typically this method should NOT be used outside of testing. + * + * If passed a non-zero value, will make the client connect to quorum peers + * in the order as specified in the zookeeper_init() call. + * A zero value causes zookeeper_init() to permute the peer endpoints + * which is good for more even client connection distribution among the + * quorum peers. + */ +ZOOAPI void zoo_deterministic_conn_order(int yesOrNo); + +/** + * \brief create a node synchronously. + * + * This method will create a node in ZooKeeper. A node can only be created if + * it does not already exists. The Create Flags affect the creation of nodes. + * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the + * client session goes away. If the ZOO_SEQUENCE flag is set, a unique + * monotonically increasing sequence number is appended to the path name. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path The name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param value The data to be stored in the node. + * \param valuelen The number of bytes in data. To set the data to be NULL use + * value as NULL and valuelen as -1. + * \param acl The initial ACL of the node. The ACL must not be null or empty. + * \param flags this parameter can be set to 0 for normal create or an OR + * of the Create Flags + * \param path_buffer Buffer which will be filled with the path of the + * new node (this might be different than the supplied path + * because of the ZOO_SEQUENCE flag). The path string will always be + * null-terminated. This parameter may be NULL if path_buffer_len = 0. + * \param path_buffer_len Size of path buffer; if the path of the new + * node (including space for the null terminator) exceeds the buffer size, + * the path string will be truncated to fit. The actual path of the + * new node in the server will not be affected by the truncation. + * The path string will always be null-terminated. + * \return one of the following codes are returned: + * ZOK operation completed successfully + * ZNONODE the parent node does not exist. + * ZNODEEXISTS the node already exists + * ZNOAUTH the client does not have permission. + * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + char *path_buffer, int path_buffer_len); + +/** + * \brief create a node synchronously and collect stat details. + * + * This method will create a node in ZooKeeper. A node can only be created if + * it does not already exists. The Create Flags affect the creation of nodes. + * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the + * client session goes away. If the ZOO_SEQUENCE flag is set, a unique + * monotonically increasing sequence number is appended to the path name. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path The name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param value The data to be stored in the node. + * \param valuelen The number of bytes in data. To set the data to be NULL use + * value as NULL and valuelen as -1. + * \param acl The initial ACL of the node. The ACL must not be null or empty. + * \param flags this parameter can be set to 0 for normal create or an OR + * of the Create Flags + * \param path_buffer Buffer which will be filled with the path of the + * new node (this might be different than the supplied path + * because of the ZOO_SEQUENCE flag). The path string will always be + * null-terminated. This parameter may be NULL if path_buffer_len = 0. + * \param path_buffer_len Size of path buffer; if the path of the new + * node (including space for the null terminator) exceeds the buffer size, + * the path string will be truncated to fit. The actual path of the + * new node in the server will not be affected by the truncation. + * The path string will always be null-terminated. + * \param stat The Stat struct to store Stat info into. + * \return one of the following codes are returned: + * ZOK operation completed successfully + * ZNONODE the parent node does not exist. + * ZNODEEXISTS the node already exists + * ZNOAUTH the client does not have permission. + * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_create2(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + char *path_buffer, int path_buffer_len, struct Stat *stat); + +/** + * \brief delete a node in zookeeper synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param version the expected version of the node. The function will fail if the + * actual version of the node does not match the expected version. + * If -1 is used the version check will not take place. + * \return one of the following values is returned. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADVERSION expected version does not match actual version. + * ZNOTEMPTY children are present; node cannot be deleted. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version); + + +/** + * \brief checks the existence of a node in zookeeper synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify the + * client if the node changes. The watch will be set even if the node does not + * exist. This allows clients to watch for nodes to appear. + * \param the return stat value of the node. + * \return return code of the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat); + +/** + * \brief checks the existence of a node in zookeeper synchronously. + * + * This function is similar to \ref zoo_exists except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null a watch will set on the specified znode on the server. + * The watch will be set even if the node does not exist. This allows clients + * to watch for nodes to appear. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param the return stat value of the node. + * \return return code of the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, struct Stat *stat); + +/** + * \brief gets the data associated with a node synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the node changes. + * \param buffer the buffer holding the node data returned by the server + * \param buffer_len is the size of the buffer pointed to by the buffer parameter. + * It'll be set to the actual data length upon return. If the data is NULL, length is -1. + * \param stat if not NULL, will hold the value of stat for the path on return. + * \return return value of the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, + int* buffer_len, struct Stat *stat); +/** + * \brief gets the data associated with a node synchronously. + * + * This function is similar to \ref zoo_get except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param buffer the buffer holding the node data returned by the server + * \param buffer_len is the size of the buffer pointed to by the buffer parameter. + * It'll be set to the actual data length upon return. If the data is NULL, length is -1. + * \param stat if not NULL, will hold the value of stat for the path on return. + * \return return value of the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_wget(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + char *buffer, int* buffer_len, struct Stat *stat); + +/** + * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to + * the server to which the client is connected, synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the node changes. + * \param buffer the buffer holding the configuration data returned by the server + * \param buffer_len is the size of the buffer pointed to by the buffer parameter. + * It'll be set to the actual data length upon return. If the data is NULL, length is -1. + * \param stat if not NULL, will hold the value of stat for the path on return. + * \return return value of the function call. + * ZOK operation completed successfully + * ZNONODE the configuration node (/zookeeper/config) does not exist. + * ZNOAUTH the client does not have permission to access the configuration node. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_getconfig(zhandle_t *zh, int watch, char *buffer, + int* buffer_len, struct Stat *stat); + +/** + * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to + * the server to which the client is connected, synchronously. + * + * This function is similar to \ref zoo_getconfig except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param buffer the buffer holding the configuration data returned by the server + * \param buffer_len is the size of the buffer pointed to by the buffer parameter. + * It'll be set to the actual data length upon return. If the data is NULL, length is -1. + * \param stat if not NULL, will hold the value of stat for the path on return. + * \return return value of the function call. + * ZOK operation completed successfully + * ZNONODE the configuration node (/zookeeper/config) does not exist. + * ZNOAUTH the client does not have permission to access the configuration node. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_wgetconfig(zhandle_t *zh, watcher_fn watcher, void* watcherCtx, + char *buffer, int* buffer_len, struct Stat *stat); + +/** + * \brief synchronous reconfiguration interface - allows changing ZK cluster + * ensemble membership and roles of ensemble peers. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param joining - comma separated list of servers to be added to the ensemble. + * Each has a configuration line for a server to be added (as would appear in a + * configuration file), only for maj. quorums. NULL for non-incremental reconfiguration. + * \param leaving - comma separated list of server IDs to be removed from the ensemble. + * Each has an id of a server to be removed, only for maj. quorums. NULL for + * non-incremental reconfiguration. + * \param members - comma separated list of new membership (e.g., contents of a + * membership configuration file) - for use only with a non-incremental + * reconfiguration. NULL for incremental reconfiguration. + * \param version - zxid of config from which we want to reconfigure - if + * current config is different reconfiguration will fail. Should be -1 to + * disable this option. + * \param buffer the buffer holding the configuration data returned by the server + * \param buffer_len is the size of the buffer pointed to by the buffer parameter. + * It'll be set to the actual data length upon return. If the data is NULL, length + * is -1. + * \param stat if not NULL, will hold the value of stat for the path on return. + * \return return value of the function call. + * ZOK operation completed successfully + * ZBADARGUMENTS - invalid input parameters (one case when this is returned is + * when the new config has less than 2 servers) + * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or + * ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + * ZNEWCONFIGNOQUORUM - no quorum of new config is connected and up-to-date with + * the leader of last committed config - try invoking reconfiguration after new + * servers are connected and synced + * ZRECONFIGINPROGRESS - another reconfig is currently in progress + */ +ZOOAPI int zoo_reconfig(zhandle_t *zh, const char *joining, const char *leaving, + const char *members, int64_t version, char *buffer, int* buffer_len, + struct Stat *stat); + +/** + * \brief sets the data associated with a node. See zoo_set2 function if + * you require access to the stat information associated with the znode. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param buffer the buffer holding data to be written to the node. + * \param buflen the number of bytes from buffer to write. To set NULL as data + * use buffer as NULL and buflen as -1. + * \param version the expected version of the node. The function will fail if + * the actual version of the node does not match the expected version. If -1 is + * used the version check will not take place. + * \return the return code for the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADVERSION expected version does not match actual version. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer, + int buflen, int version); + +/** + * \brief sets the data associated with a node. This function is the same + * as zoo_set except that it also provides access to stat information + * associated with the znode. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param buffer the buffer holding data to be written to the node. + * \param buflen the number of bytes from buffer to write. To set NULL as data + * use buffer as NULL and buflen as -1. + * \param version the expected version of the node. The function will fail if + * the actual version of the node does not match the expected version. If -1 is + * used the version check will not take place. + * \param stat if not NULL, will hold the value of stat for the path on return. + * \return the return code for the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADVERSION expected version does not match actual version. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer, + int buflen, int version, struct Stat *stat); + +/** + * \brief lists the children of a node synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the node changes. + * \param strings return value of children paths. + * \return the return code of the function. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch, + struct String_vector *strings); + +/** + * \brief lists the children of a node synchronously. + * + * This function is similar to \ref zoo_get_children except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param strings return value of children paths. + * \return the return code of the function. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + struct String_vector *strings); + +/** + * \brief lists the children of a node and get its stat synchronously. + * + * This function is new in version 3.3.0 + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watch if nonzero, a watch will be set at the server to notify + * the client if the node changes. + * \param strings return value of children paths. + * \param stat return value of node stat. + * \return the return code of the function. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch, + struct String_vector *strings, struct Stat *stat); + +/** + * \brief lists the children of a node and get its stat synchronously. + * + * This function is similar to \ref zoo_get_children except it allows one specify + * a watcher object rather than a boolean watch flag. + * + * This function is new in version 3.3.0 + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param watcher if non-null, a watch will be set at the server to notify + * the client if the node changes. + * \param watcherCtx user specific data, will be passed to the watcher callback. + * Unlike the global context set by \ref zookeeper_init, this watcher context + * is associated with the given instance of the watcher only. + * \param strings return value of children paths. + * \param stat return value of node stat. + * \return the return code of the function. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_wget_children2(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + struct String_vector *strings, struct Stat *stat); + +/** + * \brief gets the acl associated with a node synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param acl the return value of acls on the path. + * \param stat returns the stat of the path specified. + * \return the return code for the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, + struct Stat *stat); + +/** + * \brief sets the acl associated with a node synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the name of the node. Expressed as a file name with slashes + * separating ancestors of the node. + * \param version the expected version of the path. + * \param acl the acl to be set on the path. + * \return the return code for the function call. + * ZOK operation completed successfully + * ZNONODE the node does not exist. + * ZNOAUTH the client does not have permission. + * ZINVALIDACL invalid ACL specified + * ZBADVERSION expected version does not match actual version. + * ZBADARGUMENTS - invalid input parameters + * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + */ +ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version, + const struct ACL_vector *acl); + +/** + * \brief atomically commits multiple zookeeper operations synchronously. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param count the number of operations + * \param ops an array of operations to commit + * \param results an array to hold the results of the operations + * \return the return code for the function call. This can be any of the + * values that can be returned by the ops supported by a multi op (see + * \ref zoo_acreate, \ref zoo_adelete, \ref zoo_aset). + */ +ZOOAPI int zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results); + +/** + * Type of watchers: used to select which type of watchers should be removed + */ +typedef enum { + ZWATCHERTYPE_CHILDREN = 1, + ZWATCHERTYPE_DATA = 2, + ZWATCHERTYPE_ANY = 3 +} ZooWatcherType; + +/** + * \brief removes the watchers for the given path and watcher type. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the path for which watchers will be removed + * \param wtype the watcher type to be removed + * \param watcher the watcher to be removed, if null all watchers for that + * path (and watcher type) will be removed + * \param watcherCtx the contex associated with the watcher to be removed + * \param local whether the watchers will be removed locally even if there is + * no server connection + * \return the return code for the function call. + * ZOK - operation completed successfully + * ZNOWATCHER - the watcher couldn't be found. + * ZINVALIDSTATE - if !local, zhandle state is either ZOO_SESSION_EXPIRED_STATE + * or ZOO_AUTH_FAILED_STATE + * ZBADARGUMENTS - invalid input parameters + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + * ZSYSTEMERROR - a system error occured + */ +ZOOAPI int zoo_remove_watchers(zhandle_t *zh, const char *path, + ZooWatcherType wtype, watcher_fn watcher, void *watcherCtx, int local); + +/** + * \brief removes the watchers for the given path and watcher type. + * + * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init + * \param path the path for which watchers will be removed + * \param wtype the watcher type to be removed + * \param watcher the watcher to be removed, if null all watchers for that + * path (and watcher type) will be removed + * \param watcherCtx the contex associated with the watcher to be removed + * \param local whether the watchers will be removed locally even if there is + * no server connection + * \return the return code for the function call. + * ZOK - operation completed successfully + * ZNOWATCHER - the watcher couldn't be found. + * ZINVALIDSTATE - if !local, zhandle state is either ZOO_SESSION_EXPIRED_STATE + * or ZOO_AUTH_FAILED_STATE + * ZBADARGUMENTS - invalid input parameters + * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory + * ZSYSTEMERROR - a system error occured + */ +ZOOAPI int zoo_aremove_watchers(zhandle_t *zh, const char *path, + ZooWatcherType wtype, watcher_fn watcher, void *watcherCtx, int local, + void_completion_t *completion, const void *data); + +#ifdef __cplusplus +} +#endif + +#endif /*ZOOKEEPER_H_*/ diff --git a/src/c/include/zookeeper_log.h b/src/c/include/zookeeper_log.h new file mode 100644 index 00000000000..56a9b73abdf --- /dev/null +++ b/src/c/include/zookeeper_log.h @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZK_LOG_H_ +#define ZK_LOG_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern ZOOAPI ZooLogLevel logLevel; +#define LOGCALLBACK(_zh) zoo_get_log_callback(_zh) +#define LOGSTREAM NULL + +#define LOG_ERROR(_cb, ...) if(logLevel>=ZOO_LOG_LEVEL_ERROR) \ + log_message(_cb, ZOO_LOG_LEVEL_ERROR, __LINE__, __func__, __VA_ARGS__) +#define LOG_WARN(_cb, ...) if(logLevel>=ZOO_LOG_LEVEL_WARN) \ + log_message(_cb, ZOO_LOG_LEVEL_WARN, __LINE__, __func__, __VA_ARGS__) +#define LOG_INFO(_cb, ...) if(logLevel>=ZOO_LOG_LEVEL_INFO) \ + log_message(_cb, ZOO_LOG_LEVEL_INFO, __LINE__, __func__, __VA_ARGS__) +#define LOG_DEBUG(_cb, ...) if(logLevel==ZOO_LOG_LEVEL_DEBUG) \ + log_message(_cb, ZOO_LOG_LEVEL_DEBUG, __LINE__, __func__, __VA_ARGS__) + +ZOOAPI void log_message(log_callback_fn callback, ZooLogLevel curLevel, + int line, const char* funcName, const char* format, ...); + +FILE* zoo_get_log_stream(); + +#ifdef __cplusplus +} +#endif + +#endif /*ZK_LOG_H_*/ diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JByte.java b/src/c/include/zookeeper_version.h old mode 100755 new mode 100644 similarity index 71% rename from zookeeper/java/src/com/yahoo/jute/compiler/JByte.java rename to src/c/include/zookeeper_version.h index 92e31c00b80..1633cab2a80 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JByte.java +++ b/src/c/include/zookeeper_version.h @@ -15,21 +15,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef ZOOKEEPER_VERSION_H_ +#define ZOOKEEPER_VERSION_H_ -package com.yahoo.jute.compiler; +#ifdef __cplusplus +extern "C" { +#endif -/** - * - * @author Milind Bhandarkar - */ -public class JByte extends JType { - - /** Creates a new instance of JByte */ - public JByte() { - super("char", "int8_t", "byte", "Byte", "Byte", "toByte"); - } - - public String getSignature() { - return "b"; - } +#define ZOO_MAJOR_VERSION 3 +#define ZOO_MINOR_VERSION 6 +#define ZOO_PATCH_VERSION 0 + +#ifdef __cplusplus } +#endif + +#endif /* ZOOKEEPER_VERSION_H_ */ diff --git a/src/c/ltmain.sh b/src/c/ltmain.sh new file mode 100644 index 00000000000..0f0a2da3f9d --- /dev/null +++ b/src/c/ltmain.sh @@ -0,0 +1,11147 @@ +#! /bin/sh +## DO NOT EDIT - This file generated from ./build-aux/ltmain.in +## by inline-source v2014-01-03.01 + +# libtool (GNU libtool) 2.4.6 +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit , 1996 + +# Copyright (C) 1996-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +PROGRAM=libtool +PACKAGE=libtool +VERSION=2.4.6 +package_revision=2.4.6 + + +## ------ ## +## Usage. ## +## ------ ## + +# Run './libtool --help' for help with using this script from the +# command line. + + +## ------------------------------- ## +## User overridable command paths. ## +## ------------------------------- ## + +# After configure completes, it has a better idea of some of the +# shell tools we need than the defaults used by the functions shared +# with bootstrap, so set those here where they can still be over- +# ridden by the user, but otherwise take precedence. + +: ${AUTOCONF="autoconf"} +: ${AUTOMAKE="automake"} + + +## -------------------------- ## +## Source external libraries. ## +## -------------------------- ## + +# Much of our low-level functionality needs to be sourced from external +# libraries, which are installed to $pkgauxdir. + +# Set a version string for this script. +scriptversion=2015-01-20.17; # UTC + +# General shell script boiler plate, and helper functions. +# Written by Gary V. Vaughan, 2004 + +# Copyright (C) 2004-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# As a special exception to the GNU General Public License, if you distribute +# this file as part of a program or library that is built using GNU Libtool, +# you may include this file under the same distribution terms that you use +# for the rest of that program. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Please report bugs or propose patches to gary@gnu.org. + + +## ------ ## +## Usage. ## +## ------ ## + +# Evaluate this file near the top of your script to gain access to +# the functions and variables defined here: +# +# . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh +# +# If you need to override any of the default environment variable +# settings, do that before evaluating this file. + + +## -------------------- ## +## Shell normalisation. ## +## -------------------- ## + +# Some shells need a little help to be as Bourne compatible as possible. +# Before doing anything else, make sure all that help has been provided! + +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac +fi + +# NLS nuisances: We save the old values in case they are required later. +_G_user_locale= +_G_safe_locale= +for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES +do + eval "if test set = \"\${$_G_var+set}\"; then + save_$_G_var=\$$_G_var + $_G_var=C + export $_G_var + _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\" + _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\" + fi" +done + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Make sure IFS has a sensible default +sp=' ' +nl=' +' +IFS="$sp $nl" + +# There are apparently some retarded systems that use ';' as a PATH separator! +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + + +## ------------------------- ## +## Locate command utilities. ## +## ------------------------- ## + + +# func_executable_p FILE +# ---------------------- +# Check that FILE is an executable regular file. +func_executable_p () +{ + test -f "$1" && test -x "$1" +} + + +# func_path_progs PROGS_LIST CHECK_FUNC [PATH] +# -------------------------------------------- +# Search for either a program that responds to --version with output +# containing "GNU", or else returned by CHECK_FUNC otherwise, by +# trying all the directories in PATH with each of the elements of +# PROGS_LIST. +# +# CHECK_FUNC should accept the path to a candidate program, and +# set $func_check_prog_result if it truncates its output less than +# $_G_path_prog_max characters. +func_path_progs () +{ + _G_progs_list=$1 + _G_check_func=$2 + _G_PATH=${3-"$PATH"} + + _G_path_prog_max=0 + _G_path_prog_found=false + _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:} + for _G_dir in $_G_PATH; do + IFS=$_G_save_IFS + test -z "$_G_dir" && _G_dir=. + for _G_prog_name in $_G_progs_list; do + for _exeext in '' .EXE; do + _G_path_prog=$_G_dir/$_G_prog_name$_exeext + func_executable_p "$_G_path_prog" || continue + case `"$_G_path_prog" --version 2>&1` in + *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;; + *) $_G_check_func $_G_path_prog + func_path_progs_result=$func_check_prog_result + ;; + esac + $_G_path_prog_found && break 3 + done + done + done + IFS=$_G_save_IFS + test -z "$func_path_progs_result" && { + echo "no acceptable sed could be found in \$PATH" >&2 + exit 1 + } +} + + +# We want to be able to use the functions in this file before configure +# has figured out where the best binaries are kept, which means we have +# to search for them ourselves - except when the results are already set +# where we skip the searches. + +# Unless the user overrides by setting SED, search the path for either GNU +# sed, or the sed that truncates its output the least. +test -z "$SED" && { + _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for _G_i in 1 2 3 4 5 6 7; do + _G_sed_script=$_G_sed_script$nl$_G_sed_script + done + echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed + _G_sed_script= + + func_check_prog_sed () + { + _G_path_prog=$1 + + _G_count=0 + printf 0123456789 >conftest.in + while : + do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo '' >> conftest.nl + "$_G_path_prog" -f conftest.sed conftest.out 2>/dev/null || break + diff conftest.out conftest.nl >/dev/null 2>&1 || break + _G_count=`expr $_G_count + 1` + if test "$_G_count" -gt "$_G_path_prog_max"; then + # Best one so far, save it but keep looking for a better one + func_check_prog_result=$_G_path_prog + _G_path_prog_max=$_G_count + fi + # 10*(2^10) chars as input seems more than enough + test 10 -lt "$_G_count" && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out + } + + func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin + rm -f conftest.sed + SED=$func_path_progs_result +} + + +# Unless the user overrides by setting GREP, search the path for either GNU +# grep, or the grep that truncates its output the least. +test -z "$GREP" && { + func_check_prog_grep () + { + _G_path_prog=$1 + + _G_count=0 + _G_path_prog_max=0 + printf 0123456789 >conftest.in + while : + do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo 'GREP' >> conftest.nl + "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' conftest.out 2>/dev/null || break + diff conftest.out conftest.nl >/dev/null 2>&1 || break + _G_count=`expr $_G_count + 1` + if test "$_G_count" -gt "$_G_path_prog_max"; then + # Best one so far, save it but keep looking for a better one + func_check_prog_result=$_G_path_prog + _G_path_prog_max=$_G_count + fi + # 10*(2^10) chars as input seems more than enough + test 10 -lt "$_G_count" && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out + } + + func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin + GREP=$func_path_progs_result +} + + +## ------------------------------- ## +## User overridable command paths. ## +## ------------------------------- ## + +# All uppercase variable names are used for environment variables. These +# variables can be overridden by the user before calling a script that +# uses them if a suitable command of that name is not already available +# in the command search PATH. + +: ${CP="cp -f"} +: ${ECHO="printf %s\n"} +: ${EGREP="$GREP -E"} +: ${FGREP="$GREP -F"} +: ${LN_S="ln -s"} +: ${MAKE="make"} +: ${MKDIR="mkdir"} +: ${MV="mv -f"} +: ${RM="rm -f"} +: ${SHELL="${CONFIG_SHELL-/bin/sh}"} + + +## -------------------- ## +## Useful sed snippets. ## +## -------------------- ## + +sed_dirname='s|/[^/]*$||' +sed_basename='s|^.*/||' + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s|\([`"$\\]\)|\\\1|g' + +# Same as above, but do not quote variable references. +sed_double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution that turns a string into a regex matching for the +# string literally. +sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g' + +# Sed substitution that converts a w32 file name or path +# that contains forward slashes, into one that contains +# (escaped) backslashes. A very naive implementation. +sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' + +# Re-'\' parameter expansions in output of sed_double_quote_subst that +# were '\'-ed in input to the same. If an odd number of '\' preceded a +# '$' in input to sed_double_quote_subst, that '$' was protected from +# expansion. Since each input '\' is now two '\'s, look for any number +# of runs of four '\'s followed by two '\'s and then a '$'. '\' that '$'. +_G_bs='\\' +_G_bs2='\\\\' +_G_bs4='\\\\\\\\' +_G_dollar='\$' +sed_double_backslash="\ + s/$_G_bs4/&\\ +/g + s/^$_G_bs2$_G_dollar/$_G_bs&/ + s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g + s/\n//g" + + +## ----------------- ## +## Global variables. ## +## ----------------- ## + +# Except for the global variables explicitly listed below, the following +# functions in the '^func_' namespace, and the '^require_' namespace +# variables initialised in the 'Resource management' section, sourcing +# this file will not pollute your global namespace with anything +# else. There's no portable way to scope variables in Bourne shell +# though, so actually running these functions will sometimes place +# results into a variable named after the function, and often use +# temporary variables in the '^_G_' namespace. If you are careful to +# avoid using those namespaces casually in your sourcing script, things +# should continue to work as you expect. And, of course, you can freely +# overwrite any of the functions or variables defined here before +# calling anything to customize them. + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 +EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. +EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. + +# Allow overriding, eg assuming that you follow the convention of +# putting '$debug_cmd' at the start of all your functions, you can get +# bash to show function call trace with: +# +# debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name +debug_cmd=${debug_cmd-":"} +exit_cmd=: + +# By convention, finish your script with: +# +# exit $exit_status +# +# so that you can set exit_status to non-zero if you want to indicate +# something went wrong during execution without actually bailing out at +# the point of failure. +exit_status=$EXIT_SUCCESS + +# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh +# is ksh but when the shell is invoked as "sh" and the current value of +# the _XPG environment variable is not equal to 1 (one), the special +# positional parameter $0, within a function call, is the name of the +# function. +progpath=$0 + +# The name of this program. +progname=`$ECHO "$progpath" |$SED "$sed_basename"` + +# Make sure we have an absolute progpath for reexecution: +case $progpath in + [\\/]*|[A-Za-z]:\\*) ;; + *[\\/]*) + progdir=`$ECHO "$progpath" |$SED "$sed_dirname"` + progdir=`cd "$progdir" && pwd` + progpath=$progdir/$progname + ;; + *) + _G_IFS=$IFS + IFS=${PATH_SEPARATOR-:} + for progdir in $PATH; do + IFS=$_G_IFS + test -x "$progdir/$progname" && break + done + IFS=$_G_IFS + test -n "$progdir" || progdir=`pwd` + progpath=$progdir/$progname + ;; +esac + + +## ----------------- ## +## Standard options. ## +## ----------------- ## + +# The following options affect the operation of the functions defined +# below, and should be set appropriately depending on run-time para- +# meters passed on the command line. + +opt_dry_run=false +opt_quiet=false +opt_verbose=false + +# Categories 'all' and 'none' are always available. Append any others +# you will pass as the first argument to func_warning from your own +# code. +warning_categories= + +# By default, display warnings according to 'opt_warning_types'. Set +# 'warning_func' to ':' to elide all warnings, or func_fatal_error to +# treat the next displayed warning as a fatal error. +warning_func=func_warn_and_continue + +# Set to 'all' to display all warnings, 'none' to suppress all +# warnings, or a space delimited list of some subset of +# 'warning_categories' to display only the listed warnings. +opt_warning_types=all + + +## -------------------- ## +## Resource management. ## +## -------------------- ## + +# This section contains definitions for functions that each ensure a +# particular resource (a file, or a non-empty configuration variable for +# example) is available, and if appropriate to extract default values +# from pertinent package files. Call them using their associated +# 'require_*' variable to ensure that they are executed, at most, once. +# +# It's entirely deliberate that calling these functions can set +# variables that don't obey the namespace limitations obeyed by the rest +# of this file, in order that that they be as useful as possible to +# callers. + + +# require_term_colors +# ------------------- +# Allow display of bold text on terminals that support it. +require_term_colors=func_require_term_colors +func_require_term_colors () +{ + $debug_cmd + + test -t 1 && { + # COLORTERM and USE_ANSI_COLORS environment variables take + # precedence, because most terminfo databases neglect to describe + # whether color sequences are supported. + test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"} + + if test 1 = "$USE_ANSI_COLORS"; then + # Standard ANSI escape sequences + tc_reset='' + tc_bold=''; tc_standout='' + tc_red=''; tc_green='' + tc_blue=''; tc_cyan='' + else + # Otherwise trust the terminfo database after all. + test -n "`tput sgr0 2>/dev/null`" && { + tc_reset=`tput sgr0` + test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold` + tc_standout=$tc_bold + test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso` + test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1` + test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2` + test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4` + test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5` + } + fi + } + + require_term_colors=: +} + + +## ----------------- ## +## Function library. ## +## ----------------- ## + +# This section contains a variety of useful functions to call in your +# scripts. Take note of the portable wrappers for features provided by +# some modern shells, which will fall back to slower equivalents on +# less featureful shells. + + +# func_append VAR VALUE +# --------------------- +# Append VALUE onto the existing contents of VAR. + + # We should try to minimise forks, especially on Windows where they are + # unreasonably slow, so skip the feature probes when bash or zsh are + # being used: + if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then + : ${_G_HAVE_ARITH_OP="yes"} + : ${_G_HAVE_XSI_OPS="yes"} + # The += operator was introduced in bash 3.1 + case $BASH_VERSION in + [12].* | 3.0 | 3.0*) ;; + *) + : ${_G_HAVE_PLUSEQ_OP="yes"} + ;; + esac + fi + + # _G_HAVE_PLUSEQ_OP + # Can be empty, in which case the shell is probed, "yes" if += is + # useable or anything else if it does not work. + test -z "$_G_HAVE_PLUSEQ_OP" \ + && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \ + && _G_HAVE_PLUSEQ_OP=yes + +if test yes = "$_G_HAVE_PLUSEQ_OP" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_append () + { + $debug_cmd + + eval "$1+=\$2" + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_append () + { + $debug_cmd + + eval "$1=\$$1\$2" + } +fi + + +# func_append_quoted VAR VALUE +# ---------------------------- +# Quote VALUE and append to the end of shell variable VAR, separated +# by a space. +if test yes = "$_G_HAVE_PLUSEQ_OP"; then + eval 'func_append_quoted () + { + $debug_cmd + + func_quote_for_eval "$2" + eval "$1+=\\ \$func_quote_for_eval_result" + }' +else + func_append_quoted () + { + $debug_cmd + + func_quote_for_eval "$2" + eval "$1=\$$1\\ \$func_quote_for_eval_result" + } +fi + + +# func_append_uniq VAR VALUE +# -------------------------- +# Append unique VALUE onto the existing contents of VAR, assuming +# entries are delimited by the first character of VALUE. For example: +# +# func_append_uniq options " --another-option option-argument" +# +# will only append to $options if " --another-option option-argument " +# is not already present somewhere in $options already (note spaces at +# each end implied by leading space in second argument). +func_append_uniq () +{ + $debug_cmd + + eval _G_current_value='`$ECHO $'$1'`' + _G_delim=`expr "$2" : '\(.\)'` + + case $_G_delim$_G_current_value$_G_delim in + *"$2$_G_delim"*) ;; + *) func_append "$@" ;; + esac +} + + +# func_arith TERM... +# ------------------ +# Set func_arith_result to the result of evaluating TERMs. + test -z "$_G_HAVE_ARITH_OP" \ + && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \ + && _G_HAVE_ARITH_OP=yes + +if test yes = "$_G_HAVE_ARITH_OP"; then + eval 'func_arith () + { + $debug_cmd + + func_arith_result=$(( $* )) + }' +else + func_arith () + { + $debug_cmd + + func_arith_result=`expr "$@"` + } +fi + + +# func_basename FILE +# ------------------ +# Set func_basename_result to FILE with everything up to and including +# the last / stripped. +if test yes = "$_G_HAVE_XSI_OPS"; then + # If this shell supports suffix pattern removal, then use it to avoid + # forking. Hide the definitions single quotes in case the shell chokes + # on unsupported syntax... + _b='func_basename_result=${1##*/}' + _d='case $1 in + */*) func_dirname_result=${1%/*}$2 ;; + * ) func_dirname_result=$3 ;; + esac' + +else + # ...otherwise fall back to using sed. + _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`' + _d='func_dirname_result=`$ECHO "$1" |$SED "$sed_dirname"` + if test "X$func_dirname_result" = "X$1"; then + func_dirname_result=$3 + else + func_append func_dirname_result "$2" + fi' +fi + +eval 'func_basename () +{ + $debug_cmd + + '"$_b"' +}' + + +# func_dirname FILE APPEND NONDIR_REPLACEMENT +# ------------------------------------------- +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +eval 'func_dirname () +{ + $debug_cmd + + '"$_d"' +}' + + +# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT +# -------------------------------------------------------- +# Perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# For efficiency, we do not delegate to the functions above but instead +# duplicate the functionality here. +eval 'func_dirname_and_basename () +{ + $debug_cmd + + '"$_b"' + '"$_d"' +}' + + +# func_echo ARG... +# ---------------- +# Echo program name prefixed message. +func_echo () +{ + $debug_cmd + + _G_message=$* + + func_echo_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_IFS + $ECHO "$progname: $_G_line" + done + IFS=$func_echo_IFS +} + + +# func_echo_all ARG... +# -------------------- +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "$*" +} + + +# func_echo_infix_1 INFIX ARG... +# ------------------------------ +# Echo program name, followed by INFIX on the first line, with any +# additional lines not showing INFIX. +func_echo_infix_1 () +{ + $debug_cmd + + $require_term_colors + + _G_infix=$1; shift + _G_indent=$_G_infix + _G_prefix="$progname: $_G_infix: " + _G_message=$* + + # Strip color escape sequences before counting printable length + for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan" + do + test -n "$_G_tc" && { + _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"` + _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"` + } + done + _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`" " ## exclude from sc_prohibit_nested_quotes + + func_echo_infix_1_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_infix_1_IFS + $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2 + _G_prefix=$_G_indent + done + IFS=$func_echo_infix_1_IFS +} + + +# func_error ARG... +# ----------------- +# Echo program name prefixed message to standard error. +func_error () +{ + $debug_cmd + + $require_term_colors + + func_echo_infix_1 " $tc_standout${tc_red}error$tc_reset" "$*" >&2 +} + + +# func_fatal_error ARG... +# ----------------------- +# Echo program name prefixed message to standard error, and exit. +func_fatal_error () +{ + $debug_cmd + + func_error "$*" + exit $EXIT_FAILURE +} + + +# func_grep EXPRESSION FILENAME +# ----------------------------- +# Check whether EXPRESSION matches any line of FILENAME, without output. +func_grep () +{ + $debug_cmd + + $GREP "$1" "$2" >/dev/null 2>&1 +} + + +# func_len STRING +# --------------- +# Set func_len_result to the length of STRING. STRING may not +# start with a hyphen. + test -z "$_G_HAVE_XSI_OPS" \ + && (eval 'x=a/b/c; + test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ + && _G_HAVE_XSI_OPS=yes + +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_len () + { + $debug_cmd + + func_len_result=${#1} + }' +else + func_len () + { + $debug_cmd + + func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len` + } +fi + + +# func_mkdir_p DIRECTORY-PATH +# --------------------------- +# Make sure the entire path to DIRECTORY-PATH is available. +func_mkdir_p () +{ + $debug_cmd + + _G_directory_path=$1 + _G_dir_list= + + if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then + + # Protect directory names starting with '-' + case $_G_directory_path in + -*) _G_directory_path=./$_G_directory_path ;; + esac + + # While some portion of DIR does not yet exist... + while test ! -d "$_G_directory_path"; do + # ...make a list in topmost first order. Use a colon delimited + # list incase some portion of path contains whitespace. + _G_dir_list=$_G_directory_path:$_G_dir_list + + # If the last portion added has no slash in it, the list is done + case $_G_directory_path in */*) ;; *) break ;; esac + + # ...otherwise throw away the child directory and loop + _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"` + done + _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'` + + func_mkdir_p_IFS=$IFS; IFS=: + for _G_dir in $_G_dir_list; do + IFS=$func_mkdir_p_IFS + # mkdir can fail with a 'File exist' error if two processes + # try to create one of the directories concurrently. Don't + # stop in that case! + $MKDIR "$_G_dir" 2>/dev/null || : + done + IFS=$func_mkdir_p_IFS + + # Bail out if we (or some other process) failed to create a directory. + test -d "$_G_directory_path" || \ + func_fatal_error "Failed to create '$1'" + fi +} + + +# func_mktempdir [BASENAME] +# ------------------------- +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible. If +# given, BASENAME is the basename for that directory. +func_mktempdir () +{ + $debug_cmd + + _G_template=${TMPDIR-/tmp}/${1-$progname} + + if test : = "$opt_dry_run"; then + # Return a directory name, but don't create it in dry-run mode + _G_tmpdir=$_G_template-$$ + else + + # If mktemp works, use that first and foremost + _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null` + + if test ! -d "$_G_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + _G_tmpdir=$_G_template-${RANDOM-0}$$ + + func_mktempdir_umask=`umask` + umask 0077 + $MKDIR "$_G_tmpdir" + umask $func_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$_G_tmpdir" || \ + func_fatal_error "cannot create temporary directory '$_G_tmpdir'" + fi + + $ECHO "$_G_tmpdir" +} + + +# func_normal_abspath PATH +# ------------------------ +# Remove doubled-up and trailing slashes, "." path components, +# and cancel out any ".." path components in PATH after making +# it an absolute path. +func_normal_abspath () +{ + $debug_cmd + + # These SED scripts presuppose an absolute path with a trailing slash. + _G_pathcar='s|^/\([^/]*\).*$|\1|' + _G_pathcdr='s|^/[^/]*||' + _G_removedotparts=':dotsl + s|/\./|/|g + t dotsl + s|/\.$|/|' + _G_collapseslashes='s|/\{1,\}|/|g' + _G_finalslash='s|/*$|/|' + + # Start from root dir and reassemble the path. + func_normal_abspath_result= + func_normal_abspath_tpath=$1 + func_normal_abspath_altnamespace= + case $func_normal_abspath_tpath in + "") + # Empty path, that just means $cwd. + func_stripname '' '/' "`pwd`" + func_normal_abspath_result=$func_stripname_result + return + ;; + # The next three entries are used to spot a run of precisely + # two leading slashes without using negated character classes; + # we take advantage of case's first-match behaviour. + ///*) + # Unusual form of absolute path, do nothing. + ;; + //*) + # Not necessarily an ordinary path; POSIX reserves leading '//' + # and for example Cygwin uses it to access remote file shares + # over CIFS/SMB, so we conserve a leading double slash if found. + func_normal_abspath_altnamespace=/ + ;; + /*) + # Absolute path, do nothing. + ;; + *) + # Relative path, prepend $cwd. + func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath + ;; + esac + + # Cancel out all the simple stuff to save iterations. We also want + # the path to end with a slash for ease of parsing, so make sure + # there is one (and only one) here. + func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"` + while :; do + # Processed it all yet? + if test / = "$func_normal_abspath_tpath"; then + # If we ascended to the root using ".." the result may be empty now. + if test -z "$func_normal_abspath_result"; then + func_normal_abspath_result=/ + fi + break + fi + func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_pathcar"` + func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_pathcdr"` + # Figure out what to do with it + case $func_normal_abspath_tcomponent in + "") + # Trailing empty path component, ignore it. + ;; + ..) + # Parent dir; strip last assembled component from result. + func_dirname "$func_normal_abspath_result" + func_normal_abspath_result=$func_dirname_result + ;; + *) + # Actual path component, append it. + func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent" + ;; + esac + done + # Restore leading double-slash if one was found on entry. + func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result +} + + +# func_notquiet ARG... +# -------------------- +# Echo program name prefixed message only when not in quiet mode. +func_notquiet () +{ + $debug_cmd + + $opt_quiet || func_echo ${1+"$@"} + + # A bug in bash halts the script if the last line of a function + # fails when set -e is in force, so we need another command to + # work around that: + : +} + + +# func_relative_path SRCDIR DSTDIR +# -------------------------------- +# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR. +func_relative_path () +{ + $debug_cmd + + func_relative_path_result= + func_normal_abspath "$1" + func_relative_path_tlibdir=$func_normal_abspath_result + func_normal_abspath "$2" + func_relative_path_tbindir=$func_normal_abspath_result + + # Ascend the tree starting from libdir + while :; do + # check if we have found a prefix of bindir + case $func_relative_path_tbindir in + $func_relative_path_tlibdir) + # found an exact match + func_relative_path_tcancelled= + break + ;; + $func_relative_path_tlibdir*) + # found a matching prefix + func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir" + func_relative_path_tcancelled=$func_stripname_result + if test -z "$func_relative_path_result"; then + func_relative_path_result=. + fi + break + ;; + *) + func_dirname $func_relative_path_tlibdir + func_relative_path_tlibdir=$func_dirname_result + if test -z "$func_relative_path_tlibdir"; then + # Have to descend all the way to the root! + func_relative_path_result=../$func_relative_path_result + func_relative_path_tcancelled=$func_relative_path_tbindir + break + fi + func_relative_path_result=../$func_relative_path_result + ;; + esac + done + + # Now calculate path; take care to avoid doubling-up slashes. + func_stripname '' '/' "$func_relative_path_result" + func_relative_path_result=$func_stripname_result + func_stripname '/' '/' "$func_relative_path_tcancelled" + if test -n "$func_stripname_result"; then + func_append func_relative_path_result "/$func_stripname_result" + fi + + # Normalisation. If bindir is libdir, return '.' else relative path. + if test -n "$func_relative_path_result"; then + func_stripname './' '' "$func_relative_path_result" + func_relative_path_result=$func_stripname_result + fi + + test -n "$func_relative_path_result" || func_relative_path_result=. + + : +} + + +# func_quote_for_eval ARG... +# -------------------------- +# Aesthetically quote ARGs to be evaled later. +# This function returns two values: +# i) func_quote_for_eval_result +# double-quoted, suitable for a subsequent eval +# ii) func_quote_for_eval_unquoted_result +# has all characters that are still active within double +# quotes backslashified. +func_quote_for_eval () +{ + $debug_cmd + + func_quote_for_eval_unquoted_result= + func_quote_for_eval_result= + while test 0 -lt $#; do + case $1 in + *[\\\`\"\$]*) + _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;; + *) + _G_unquoted_arg=$1 ;; + esac + if test -n "$func_quote_for_eval_unquoted_result"; then + func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg" + else + func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg" + fi + + case $_G_unquoted_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting, command substitution and variable expansion + # for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + _G_quoted_arg=\"$_G_unquoted_arg\" + ;; + *) + _G_quoted_arg=$_G_unquoted_arg + ;; + esac + + if test -n "$func_quote_for_eval_result"; then + func_append func_quote_for_eval_result " $_G_quoted_arg" + else + func_append func_quote_for_eval_result "$_G_quoted_arg" + fi + shift + done +} + + +# func_quote_for_expand ARG +# ------------------------- +# Aesthetically quote ARG to be evaled later; same as above, +# but do not quote variable references. +func_quote_for_expand () +{ + $debug_cmd + + case $1 in + *[\\\`\"]*) + _G_arg=`$ECHO "$1" | $SED \ + -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;; + *) + _G_arg=$1 ;; + esac + + case $_G_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting and command substitution for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + _G_arg=\"$_G_arg\" + ;; + esac + + func_quote_for_expand_result=$_G_arg +} + + +# func_stripname PREFIX SUFFIX NAME +# --------------------------------- +# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_stripname () + { + $debug_cmd + + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary variable first. + func_stripname_result=$3 + func_stripname_result=${func_stripname_result#"$1"} + func_stripname_result=${func_stripname_result%"$2"} + }' +else + func_stripname () + { + $debug_cmd + + case $2 in + .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;; + *) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;; + esac + } +fi + + +# func_show_eval CMD [FAIL_EXP] +# ----------------------------- +# Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. +func_show_eval () +{ + $debug_cmd + + _G_cmd=$1 + _G_fail_exp=${2-':'} + + func_quote_for_expand "$_G_cmd" + eval "func_notquiet $func_quote_for_expand_result" + + $opt_dry_run || { + eval "$_G_cmd" + _G_status=$? + if test 0 -ne "$_G_status"; then + eval "(exit $_G_status); $_G_fail_exp" + fi + } +} + + +# func_show_eval_locale CMD [FAIL_EXP] +# ------------------------------------ +# Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. Use the saved locale for evaluation. +func_show_eval_locale () +{ + $debug_cmd + + _G_cmd=$1 + _G_fail_exp=${2-':'} + + $opt_quiet || { + func_quote_for_expand "$_G_cmd" + eval "func_echo $func_quote_for_expand_result" + } + + $opt_dry_run || { + eval "$_G_user_locale + $_G_cmd" + _G_status=$? + eval "$_G_safe_locale" + if test 0 -ne "$_G_status"; then + eval "(exit $_G_status); $_G_fail_exp" + fi + } +} + + +# func_tr_sh +# ---------- +# Turn $1 into a string suitable for a shell variable name. +# Result is stored in $func_tr_sh_result. All characters +# not in the set a-zA-Z0-9_ are replaced with '_'. Further, +# if $1 begins with a digit, a '_' is prepended as well. +func_tr_sh () +{ + $debug_cmd + + case $1 in + [0-9]* | *[!a-zA-Z0-9_]*) + func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'` + ;; + * ) + func_tr_sh_result=$1 + ;; + esac +} + + +# func_verbose ARG... +# ------------------- +# Echo program name prefixed message in verbose mode only. +func_verbose () +{ + $debug_cmd + + $opt_verbose && func_echo "$*" + + : +} + + +# func_warn_and_continue ARG... +# ----------------------------- +# Echo program name prefixed warning message to standard error. +func_warn_and_continue () +{ + $debug_cmd + + $require_term_colors + + func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2 +} + + +# func_warning CATEGORY ARG... +# ---------------------------- +# Echo program name prefixed warning message to standard error. Warning +# messages can be filtered according to CATEGORY, where this function +# elides messages where CATEGORY is not listed in the global variable +# 'opt_warning_types'. +func_warning () +{ + $debug_cmd + + # CATEGORY must be in the warning_categories list! + case " $warning_categories " in + *" $1 "*) ;; + *) func_internal_error "invalid warning category '$1'" ;; + esac + + _G_category=$1 + shift + + case " $opt_warning_types " in + *" $_G_category "*) $warning_func ${1+"$@"} ;; + esac +} + + +# func_sort_ver VER1 VER2 +# ----------------------- +# 'sort -V' is not generally available. +# Note this deviates from the version comparison in automake +# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a +# but this should suffice as we won't be specifying old +# version formats or redundant trailing .0 in bootstrap.conf. +# If we did want full compatibility then we should probably +# use m4_version_compare from autoconf. +func_sort_ver () +{ + $debug_cmd + + printf '%s\n%s\n' "$1" "$2" \ + | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n +} + +# func_lt_ver PREV CURR +# --------------------- +# Return true if PREV and CURR are in the correct order according to +# func_sort_ver, otherwise false. Use it like this: +# +# func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..." +func_lt_ver () +{ + $debug_cmd + + test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q` +} + + +# Local variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" +# time-stamp-time-zone: "UTC" +# End: +#! /bin/sh + +# Set a version string for this script. +scriptversion=2014-01-07.03; # UTC + +# A portable, pluggable option parser for Bourne shell. +# Written by Gary V. Vaughan, 2010 + +# Copyright (C) 2010-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Please report bugs or propose patches to gary@gnu.org. + + +## ------ ## +## Usage. ## +## ------ ## + +# This file is a library for parsing options in your shell scripts along +# with assorted other useful supporting features that you can make use +# of too. +# +# For the simplest scripts you might need only: +# +# #!/bin/sh +# . relative/path/to/funclib.sh +# . relative/path/to/options-parser +# scriptversion=1.0 +# func_options ${1+"$@"} +# eval set dummy "$func_options_result"; shift +# ...rest of your script... +# +# In order for the '--version' option to work, you will need to have a +# suitably formatted comment like the one at the top of this file +# starting with '# Written by ' and ending with '# warranty; '. +# +# For '-h' and '--help' to work, you will also need a one line +# description of your script's purpose in a comment directly above the +# '# Written by ' line, like the one at the top of this file. +# +# The default options also support '--debug', which will turn on shell +# execution tracing (see the comment above debug_cmd below for another +# use), and '--verbose' and the func_verbose function to allow your script +# to display verbose messages only when your user has specified +# '--verbose'. +# +# After sourcing this file, you can plug processing for additional +# options by amending the variables from the 'Configuration' section +# below, and following the instructions in the 'Option parsing' +# section further down. + +## -------------- ## +## Configuration. ## +## -------------- ## + +# You should override these variables in your script after sourcing this +# file so that they reflect the customisations you have added to the +# option parser. + +# The usage line for option parsing errors and the start of '-h' and +# '--help' output messages. You can embed shell variables for delayed +# expansion at the time the message is displayed, but you will need to +# quote other shell meta-characters carefully to prevent them being +# expanded when the contents are evaled. +usage='$progpath [OPTION]...' + +# Short help message in response to '-h' and '--help'. Add to this or +# override it after sourcing this library to reflect the full set of +# options your script accepts. +usage_message="\ + --debug enable verbose shell tracing + -W, --warnings=CATEGORY + report the warnings falling in CATEGORY [all] + -v, --verbose verbosely report processing + --version print version information and exit + -h, --help print short or long help message and exit +" + +# Additional text appended to 'usage_message' in response to '--help'. +long_help_message=" +Warning categories include: + 'all' show all warnings + 'none' turn off all the warnings + 'error' warnings are treated as fatal errors" + +# Help message printed before fatal option parsing errors. +fatal_help="Try '\$progname --help' for more information." + + + +## ------------------------- ## +## Hook function management. ## +## ------------------------- ## + +# This section contains functions for adding, removing, and running hooks +# to the main code. A hook is just a named list of of function, that can +# be run in order later on. + +# func_hookable FUNC_NAME +# ----------------------- +# Declare that FUNC_NAME will run hooks added with +# 'func_add_hook FUNC_NAME ...'. +func_hookable () +{ + $debug_cmd + + func_append hookable_fns " $1" +} + + +# func_add_hook FUNC_NAME HOOK_FUNC +# --------------------------------- +# Request that FUNC_NAME call HOOK_FUNC before it returns. FUNC_NAME must +# first have been declared "hookable" by a call to 'func_hookable'. +func_add_hook () +{ + $debug_cmd + + case " $hookable_fns " in + *" $1 "*) ;; + *) func_fatal_error "'$1' does not accept hook functions." ;; + esac + + eval func_append ${1}_hooks '" $2"' +} + + +# func_remove_hook FUNC_NAME HOOK_FUNC +# ------------------------------------ +# Remove HOOK_FUNC from the list of functions called by FUNC_NAME. +func_remove_hook () +{ + $debug_cmd + + eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`' +} + + +# func_run_hooks FUNC_NAME [ARG]... +# --------------------------------- +# Run all hook functions registered to FUNC_NAME. +# It is assumed that the list of hook functions contains nothing more +# than a whitespace-delimited list of legal shell function names, and +# no effort is wasted trying to catch shell meta-characters or preserve +# whitespace. +func_run_hooks () +{ + $debug_cmd + + case " $hookable_fns " in + *" $1 "*) ;; + *) func_fatal_error "'$1' does not support hook funcions.n" ;; + esac + + eval _G_hook_fns=\$$1_hooks; shift + + for _G_hook in $_G_hook_fns; do + eval $_G_hook '"$@"' + + # store returned options list back into positional + # parameters for next 'cmd' execution. + eval _G_hook_result=\$${_G_hook}_result + eval set dummy "$_G_hook_result"; shift + done + + func_quote_for_eval ${1+"$@"} + func_run_hooks_result=$func_quote_for_eval_result +} + + + +## --------------- ## +## Option parsing. ## +## --------------- ## + +# In order to add your own option parsing hooks, you must accept the +# full positional parameter list in your hook function, remove any +# options that you action, and then pass back the remaining unprocessed +# options in '_result', escaped suitably for +# 'eval'. Like this: +# +# my_options_prep () +# { +# $debug_cmd +# +# # Extend the existing usage message. +# usage_message=$usage_message' +# -s, --silent don'\''t print informational messages +# ' +# +# func_quote_for_eval ${1+"$@"} +# my_options_prep_result=$func_quote_for_eval_result +# } +# func_add_hook func_options_prep my_options_prep +# +# +# my_silent_option () +# { +# $debug_cmd +# +# # Note that for efficiency, we parse as many options as we can +# # recognise in a loop before passing the remainder back to the +# # caller on the first unrecognised argument we encounter. +# while test $# -gt 0; do +# opt=$1; shift +# case $opt in +# --silent|-s) opt_silent=: ;; +# # Separate non-argument short options: +# -s*) func_split_short_opt "$_G_opt" +# set dummy "$func_split_short_opt_name" \ +# "-$func_split_short_opt_arg" ${1+"$@"} +# shift +# ;; +# *) set dummy "$_G_opt" "$*"; shift; break ;; +# esac +# done +# +# func_quote_for_eval ${1+"$@"} +# my_silent_option_result=$func_quote_for_eval_result +# } +# func_add_hook func_parse_options my_silent_option +# +# +# my_option_validation () +# { +# $debug_cmd +# +# $opt_silent && $opt_verbose && func_fatal_help "\ +# '--silent' and '--verbose' options are mutually exclusive." +# +# func_quote_for_eval ${1+"$@"} +# my_option_validation_result=$func_quote_for_eval_result +# } +# func_add_hook func_validate_options my_option_validation +# +# You'll alse need to manually amend $usage_message to reflect the extra +# options you parse. It's preferable to append if you can, so that +# multiple option parsing hooks can be added safely. + + +# func_options [ARG]... +# --------------------- +# All the functions called inside func_options are hookable. See the +# individual implementations for details. +func_hookable func_options +func_options () +{ + $debug_cmd + + func_options_prep ${1+"$@"} + eval func_parse_options \ + ${func_options_prep_result+"$func_options_prep_result"} + eval func_validate_options \ + ${func_parse_options_result+"$func_parse_options_result"} + + eval func_run_hooks func_options \ + ${func_validate_options_result+"$func_validate_options_result"} + + # save modified positional parameters for caller + func_options_result=$func_run_hooks_result +} + + +# func_options_prep [ARG]... +# -------------------------- +# All initialisations required before starting the option parse loop. +# Note that when calling hook functions, we pass through the list of +# positional parameters. If a hook function modifies that list, and +# needs to propogate that back to rest of this script, then the complete +# modified list must be put in 'func_run_hooks_result' before +# returning. +func_hookable func_options_prep +func_options_prep () +{ + $debug_cmd + + # Option defaults: + opt_verbose=false + opt_warning_types= + + func_run_hooks func_options_prep ${1+"$@"} + + # save modified positional parameters for caller + func_options_prep_result=$func_run_hooks_result +} + + +# func_parse_options [ARG]... +# --------------------------- +# The main option parsing loop. +func_hookable func_parse_options +func_parse_options () +{ + $debug_cmd + + func_parse_options_result= + + # this just eases exit handling + while test $# -gt 0; do + # Defer to hook functions for initial option parsing, so they + # get priority in the event of reusing an option name. + func_run_hooks func_parse_options ${1+"$@"} + + # Adjust func_parse_options positional parameters to match + eval set dummy "$func_run_hooks_result"; shift + + # Break out of the loop if we already parsed every option. + test $# -gt 0 || break + + _G_opt=$1 + shift + case $_G_opt in + --debug|-x) debug_cmd='set -x' + func_echo "enabling shell trace mode" + $debug_cmd + ;; + + --no-warnings|--no-warning|--no-warn) + set dummy --warnings none ${1+"$@"} + shift + ;; + + --warnings|--warning|-W) + test $# = 0 && func_missing_arg $_G_opt && break + case " $warning_categories $1" in + *" $1 "*) + # trailing space prevents matching last $1 above + func_append_uniq opt_warning_types " $1" + ;; + *all) + opt_warning_types=$warning_categories + ;; + *none) + opt_warning_types=none + warning_func=: + ;; + *error) + opt_warning_types=$warning_categories + warning_func=func_fatal_error + ;; + *) + func_fatal_error \ + "unsupported warning category: '$1'" + ;; + esac + shift + ;; + + --verbose|-v) opt_verbose=: ;; + --version) func_version ;; + -\?|-h) func_usage ;; + --help) func_help ;; + + # Separate optargs to long options (plugins may need this): + --*=*) func_split_equals "$_G_opt" + set dummy "$func_split_equals_lhs" \ + "$func_split_equals_rhs" ${1+"$@"} + shift + ;; + + # Separate optargs to short options: + -W*) + func_split_short_opt "$_G_opt" + set dummy "$func_split_short_opt_name" \ + "$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + # Separate non-argument short options: + -\?*|-h*|-v*|-x*) + func_split_short_opt "$_G_opt" + set dummy "$func_split_short_opt_name" \ + "-$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + --) break ;; + -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; + *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + esac + done + + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + func_parse_options_result=$func_quote_for_eval_result +} + + +# func_validate_options [ARG]... +# ------------------------------ +# Perform any sanity checks on option settings and/or unconsumed +# arguments. +func_hookable func_validate_options +func_validate_options () +{ + $debug_cmd + + # Display all warnings if -W was not given. + test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" + + func_run_hooks func_validate_options ${1+"$@"} + + # Bail if the options were screwed! + $exit_cmd $EXIT_FAILURE + + # save modified positional parameters for caller + func_validate_options_result=$func_run_hooks_result +} + + + +## ----------------- ## +## Helper functions. ## +## ----------------- ## + +# This section contains the helper functions used by the rest of the +# hookable option parser framework in ascii-betical order. + + +# func_fatal_help ARG... +# ---------------------- +# Echo program name prefixed message to standard error, followed by +# a help hint, and exit. +func_fatal_help () +{ + $debug_cmd + + eval \$ECHO \""Usage: $usage"\" + eval \$ECHO \""$fatal_help"\" + func_error ${1+"$@"} + exit $EXIT_FAILURE +} + + +# func_help +# --------- +# Echo long help message to standard output and exit. +func_help () +{ + $debug_cmd + + func_usage_message + $ECHO "$long_help_message" + exit 0 +} + + +# func_missing_arg ARGNAME +# ------------------------ +# Echo program name prefixed message to standard error and set global +# exit_cmd. +func_missing_arg () +{ + $debug_cmd + + func_error "Missing argument for '$1'." + exit_cmd=exit +} + + +# func_split_equals STRING +# ------------------------ +# Set func_split_equals_lhs and func_split_equals_rhs shell variables after +# splitting STRING at the '=' sign. +test -z "$_G_HAVE_XSI_OPS" \ + && (eval 'x=a/b/c; + test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ + && _G_HAVE_XSI_OPS=yes + +if test yes = "$_G_HAVE_XSI_OPS" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_split_equals () + { + $debug_cmd + + func_split_equals_lhs=${1%%=*} + func_split_equals_rhs=${1#*=} + test "x$func_split_equals_lhs" = "x$1" \ + && func_split_equals_rhs= + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_split_equals () + { + $debug_cmd + + func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'` + func_split_equals_rhs= + test "x$func_split_equals_lhs" = "x$1" \ + || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'` + } +fi #func_split_equals + + +# func_split_short_opt SHORTOPT +# ----------------------------- +# Set func_split_short_opt_name and func_split_short_opt_arg shell +# variables after splitting SHORTOPT after the 2nd character. +if test yes = "$_G_HAVE_XSI_OPS" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_split_short_opt () + { + $debug_cmd + + func_split_short_opt_arg=${1#??} + func_split_short_opt_name=${1%"$func_split_short_opt_arg"} + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_split_short_opt () + { + $debug_cmd + + func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'` + func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'` + } +fi #func_split_short_opt + + +# func_usage +# ---------- +# Echo short help message to standard output and exit. +func_usage () +{ + $debug_cmd + + func_usage_message + $ECHO "Run '$progname --help |${PAGER-more}' for full usage" + exit 0 +} + + +# func_usage_message +# ------------------ +# Echo short help message to standard output. +func_usage_message () +{ + $debug_cmd + + eval \$ECHO \""Usage: $usage"\" + echo + $SED -n 's|^# || + /^Written by/{ + x;p;x + } + h + /^Written by/q' < "$progpath" + echo + eval \$ECHO \""$usage_message"\" +} + + +# func_version +# ------------ +# Echo version message to standard output and exit. +func_version () +{ + $debug_cmd + + printf '%s\n' "$progname $scriptversion" + $SED -n ' + /(C)/!b go + :more + /\./!{ + N + s|\n# | | + b more + } + :go + /^# Written by /,/# warranty; / { + s|^# || + s|^# *$|| + s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| + p + } + /^# Written by / { + s|^# || + p + } + /^warranty; /q' < "$progpath" + + exit $? +} + + +# Local variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" +# time-stamp-time-zone: "UTC" +# End: + +# Set a version string. +scriptversion='(GNU libtool) 2.4.6' + + +# func_echo ARG... +# ---------------- +# Libtool also displays the current mode in messages, so override +# funclib.sh func_echo with this custom definition. +func_echo () +{ + $debug_cmd + + _G_message=$* + + func_echo_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_IFS + $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line" + done + IFS=$func_echo_IFS +} + + +# func_warning ARG... +# ------------------- +# Libtool warnings are not categorized, so override funclib.sh +# func_warning with this simpler definition. +func_warning () +{ + $debug_cmd + + $warning_func ${1+"$@"} +} + + +## ---------------- ## +## Options parsing. ## +## ---------------- ## + +# Hook in the functions to make sure our own options are parsed during +# the option parsing loop. + +usage='$progpath [OPTION]... [MODE-ARG]...' + +# Short help message in response to '-h'. +usage_message="Options: + --config show all configuration variables + --debug enable verbose shell tracing + -n, --dry-run display commands without modifying any files + --features display basic configuration information and exit + --mode=MODE use operation mode MODE + --no-warnings equivalent to '-Wnone' + --preserve-dup-deps don't remove duplicate dependency libraries + --quiet, --silent don't print informational messages + --tag=TAG use configuration variables from tag TAG + -v, --verbose print more informational messages than default + --version print version information + -W, --warnings=CATEGORY report the warnings falling in CATEGORY [all] + -h, --help, --help-all print short, long, or detailed help message +" + +# Additional text appended to 'usage_message' in response to '--help'. +func_help () +{ + $debug_cmd + + func_usage_message + $ECHO "$long_help_message + +MODE must be one of the following: + + clean remove files from the build directory + compile compile a source file into a libtool object + execute automatically set library path, then run a program + finish complete the installation of libtool libraries + install install libraries or executables + link create a library or an executable + uninstall remove libraries from an installed directory + +MODE-ARGS vary depending on the MODE. When passed as first option, +'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that. +Try '$progname --help --mode=MODE' for a more detailed description of MODE. + +When reporting a bug, please describe a test case to reproduce it and +include the following information: + + host-triplet: $host + shell: $SHELL + compiler: $LTCC + compiler flags: $LTCFLAGS + linker: $LD (gnu? $with_gnu_ld) + version: $progname (GNU libtool) 2.4.6 + automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` + autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` + +Report bugs to . +GNU libtool home page: . +General help using GNU software: ." + exit 0 +} + + +# func_lo2o OBJECT-NAME +# --------------------- +# Transform OBJECT-NAME from a '.lo' suffix to the platform specific +# object suffix. + +lo2o=s/\\.lo\$/.$objext/ +o2lo=s/\\.$objext\$/.lo/ + +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_lo2o () + { + case $1 in + *.lo) func_lo2o_result=${1%.lo}.$objext ;; + * ) func_lo2o_result=$1 ;; + esac + }' + + # func_xform LIBOBJ-OR-SOURCE + # --------------------------- + # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise) + # suffix to a '.lo' libtool-object suffix. + eval 'func_xform () + { + func_xform_result=${1%.*}.lo + }' +else + # ...otherwise fall back to using sed. + func_lo2o () + { + func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"` + } + + func_xform () + { + func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'` + } +fi + + +# func_fatal_configuration ARG... +# ------------------------------- +# Echo program name prefixed message to standard error, followed by +# a configuration failure hint, and exit. +func_fatal_configuration () +{ + func__fatal_error ${1+"$@"} \ + "See the $PACKAGE documentation for more information." \ + "Fatal configuration error." +} + + +# func_config +# ----------- +# Display the configuration for all the tags in this script. +func_config () +{ + re_begincf='^# ### BEGIN LIBTOOL' + re_endcf='^# ### END LIBTOOL' + + # Default configuration. + $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath" + + # Now print the configurations for the tags. + for tagname in $taglist; do + $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath" + done + + exit $? +} + + +# func_features +# ------------- +# Display the features supported by this script. +func_features () +{ + echo "host: $host" + if test yes = "$build_libtool_libs"; then + echo "enable shared libraries" + else + echo "disable shared libraries" + fi + if test yes = "$build_old_libs"; then + echo "enable static libraries" + else + echo "disable static libraries" + fi + + exit $? +} + + +# func_enable_tag TAGNAME +# ----------------------- +# Verify that TAGNAME is valid, and either flag an error and exit, or +# enable the TAGNAME tag. We also add TAGNAME to the global $taglist +# variable here. +func_enable_tag () +{ + # Global variable: + tagname=$1 + + re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$" + re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$" + sed_extractcf=/$re_begincf/,/$re_endcf/p + + # Validate tagname. + case $tagname in + *[!-_A-Za-z0-9,/]*) + func_fatal_error "invalid tag name: $tagname" + ;; + esac + + # Don't test for the "default" C tag, as we know it's + # there but not specially marked. + case $tagname in + CC) ;; + *) + if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then + taglist="$taglist $tagname" + + # Evaluate the configuration. Be careful to quote the path + # and the sed script, to avoid splitting on whitespace, but + # also don't use non-portable quotes within backquotes within + # quotes we have to do it in 2 steps: + extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"` + eval "$extractedcf" + else + func_error "ignoring unknown tag $tagname" + fi + ;; + esac +} + + +# func_check_version_match +# ------------------------ +# Ensure that we are using m4 macros, and libtool script from the same +# release of libtool. +func_check_version_match () +{ + if test "$package_revision" != "$macro_revision"; then + if test "$VERSION" != "$macro_version"; then + if test -z "$macro_version"; then + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from an older release. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from $PACKAGE $macro_version. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + fi + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, revision $package_revision, +$progname: but the definition of this LT_INIT comes from revision $macro_revision. +$progname: You should recreate aclocal.m4 with macros from revision $package_revision +$progname: of $PACKAGE $VERSION and run autoconf again. +_LT_EOF + fi + + exit $EXIT_MISMATCH + fi +} + + +# libtool_options_prep [ARG]... +# ----------------------------- +# Preparation for options parsed by libtool. +libtool_options_prep () +{ + $debug_mode + + # Option defaults: + opt_config=false + opt_dlopen= + opt_dry_run=false + opt_help=false + opt_mode= + opt_preserve_dup_deps=false + opt_quiet=false + + nonopt= + preserve_args= + + # Shorthand for --mode=foo, only valid as the first argument + case $1 in + clean|clea|cle|cl) + shift; set dummy --mode clean ${1+"$@"}; shift + ;; + compile|compil|compi|comp|com|co|c) + shift; set dummy --mode compile ${1+"$@"}; shift + ;; + execute|execut|execu|exec|exe|ex|e) + shift; set dummy --mode execute ${1+"$@"}; shift + ;; + finish|finis|fini|fin|fi|f) + shift; set dummy --mode finish ${1+"$@"}; shift + ;; + install|instal|insta|inst|ins|in|i) + shift; set dummy --mode install ${1+"$@"}; shift + ;; + link|lin|li|l) + shift; set dummy --mode link ${1+"$@"}; shift + ;; + uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) + shift; set dummy --mode uninstall ${1+"$@"}; shift + ;; + esac + + # Pass back the list of options. + func_quote_for_eval ${1+"$@"} + libtool_options_prep_result=$func_quote_for_eval_result +} +func_add_hook func_options_prep libtool_options_prep + + +# libtool_parse_options [ARG]... +# --------------------------------- +# Provide handling for libtool specific options. +libtool_parse_options () +{ + $debug_cmd + + # Perform our own loop to consume as many options as possible in + # each iteration. + while test $# -gt 0; do + _G_opt=$1 + shift + case $_G_opt in + --dry-run|--dryrun|-n) + opt_dry_run=: + ;; + + --config) func_config ;; + + --dlopen|-dlopen) + opt_dlopen="${opt_dlopen+$opt_dlopen +}$1" + shift + ;; + + --preserve-dup-deps) + opt_preserve_dup_deps=: ;; + + --features) func_features ;; + + --finish) set dummy --mode finish ${1+"$@"}; shift ;; + + --help) opt_help=: ;; + + --help-all) opt_help=': help-all' ;; + + --mode) test $# = 0 && func_missing_arg $_G_opt && break + opt_mode=$1 + case $1 in + # Valid mode arguments: + clean|compile|execute|finish|install|link|relink|uninstall) ;; + + # Catch anything else as an error + *) func_error "invalid argument for $_G_opt" + exit_cmd=exit + break + ;; + esac + shift + ;; + + --no-silent|--no-quiet) + opt_quiet=false + func_append preserve_args " $_G_opt" + ;; + + --no-warnings|--no-warning|--no-warn) + opt_warning=false + func_append preserve_args " $_G_opt" + ;; + + --no-verbose) + opt_verbose=false + func_append preserve_args " $_G_opt" + ;; + + --silent|--quiet) + opt_quiet=: + opt_verbose=false + func_append preserve_args " $_G_opt" + ;; + + --tag) test $# = 0 && func_missing_arg $_G_opt && break + opt_tag=$1 + func_append preserve_args " $_G_opt $1" + func_enable_tag "$1" + shift + ;; + + --verbose|-v) opt_quiet=false + opt_verbose=: + func_append preserve_args " $_G_opt" + ;; + + # An option not handled by this hook function: + *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + esac + done + + + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + libtool_parse_options_result=$func_quote_for_eval_result +} +func_add_hook func_parse_options libtool_parse_options + + + +# libtool_validate_options [ARG]... +# --------------------------------- +# Perform any sanity checks on option settings and/or unconsumed +# arguments. +libtool_validate_options () +{ + # save first non-option argument + if test 0 -lt $#; then + nonopt=$1 + shift + fi + + # preserve --debug + test : = "$debug_cmd" || func_append preserve_args " --debug" + + case $host in + # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452 + # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788 + *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*) + # don't eliminate duplications in $postdeps and $predeps + opt_duplicate_compiler_generated_deps=: + ;; + *) + opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps + ;; + esac + + $opt_help || { + # Sanity checks first: + func_check_version_match + + test yes != "$build_libtool_libs" \ + && test yes != "$build_old_libs" \ + && func_fatal_configuration "not configured to build any kind of library" + + # Darwin sucks + eval std_shrext=\"$shrext_cmds\" + + # Only execute mode is allowed to have -dlopen flags. + if test -n "$opt_dlopen" && test execute != "$opt_mode"; then + func_error "unrecognized option '-dlopen'" + $ECHO "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Change the help message to a mode-specific one. + generic_help=$help + help="Try '$progname --help --mode=$opt_mode' for more information." + } + + # Pass back the unparsed argument list + func_quote_for_eval ${1+"$@"} + libtool_validate_options_result=$func_quote_for_eval_result +} +func_add_hook func_validate_options libtool_validate_options + + +# Process options as early as possible so that --help and --version +# can return quickly. +func_options ${1+"$@"} +eval set dummy "$func_options_result"; shift + + + +## ----------- ## +## Main. ## +## ----------- ## + +magic='%%%MAGIC variable%%%' +magic_exe='%%%MAGIC EXE variable%%%' + +# Global variables. +extracted_archives= +extracted_serial=0 + +# If this variable is set in any of the actions, the command in it +# will be execed at the end. This prevents here-documents from being +# left over by shells. +exec_cmd= + + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + +# func_generated_by_libtool +# True iff stdin has been generated by Libtool. This function is only +# a basic sanity check; it will hardly flush out determined imposters. +func_generated_by_libtool_p () +{ + $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1 +} + +# func_lalib_p file +# True iff FILE is a libtool '.la' library or '.lo' object file. +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_lalib_p () +{ + test -f "$1" && + $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p +} + +# func_lalib_unsafe_p file +# True iff FILE is a libtool '.la' library or '.lo' object file. +# This function implements the same check as func_lalib_p without +# resorting to external programs. To this end, it redirects stdin and +# closes it afterwards, without saving the original file descriptor. +# As a safety measure, use it only where a negative result would be +# fatal anyway. Works if 'file' does not exist. +func_lalib_unsafe_p () +{ + lalib_p=no + if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then + for lalib_p_l in 1 2 3 4 + do + read lalib_p_line + case $lalib_p_line in + \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;; + esac + done + exec 0<&5 5<&- + fi + test yes = "$lalib_p" +} + +# func_ltwrapper_script_p file +# True iff FILE is a libtool wrapper script +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_script_p () +{ + test -f "$1" && + $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p +} + +# func_ltwrapper_executable_p file +# True iff FILE is a libtool wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_executable_p () +{ + func_ltwrapper_exec_suffix= + case $1 in + *.exe) ;; + *) func_ltwrapper_exec_suffix=.exe ;; + esac + $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1 +} + +# func_ltwrapper_scriptname file +# Assumes file is an ltwrapper_executable +# uses $file to determine the appropriate filename for a +# temporary ltwrapper_script. +func_ltwrapper_scriptname () +{ + func_dirname_and_basename "$1" "" "." + func_stripname '' '.exe' "$func_basename_result" + func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper +} + +# func_ltwrapper_p file +# True iff FILE is a libtool wrapper script or wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_p () +{ + func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1" +} + + +# func_execute_cmds commands fail_cmd +# Execute tilde-delimited COMMANDS. +# If FAIL_CMD is given, eval that upon failure. +# FAIL_CMD may read-access the current command in variable CMD! +func_execute_cmds () +{ + $debug_cmd + + save_ifs=$IFS; IFS='~' + for cmd in $1; do + IFS=$sp$nl + eval cmd=\"$cmd\" + IFS=$save_ifs + func_show_eval "$cmd" "${2-:}" + done + IFS=$save_ifs +} + + +# func_source file +# Source FILE, adding directory component if necessary. +# Note that it is not necessary on cygwin/mingw to append a dot to +# FILE even if both FILE and FILE.exe exist: automatic-append-.exe +# behavior happens only for exec(3), not for open(2)! Also, sourcing +# 'FILE.' does not work on cygwin managed mounts. +func_source () +{ + $debug_cmd + + case $1 in + */* | *\\*) . "$1" ;; + *) . "./$1" ;; + esac +} + + +# func_resolve_sysroot PATH +# Replace a leading = in PATH with a sysroot. Store the result into +# func_resolve_sysroot_result +func_resolve_sysroot () +{ + func_resolve_sysroot_result=$1 + case $func_resolve_sysroot_result in + =*) + func_stripname '=' '' "$func_resolve_sysroot_result" + func_resolve_sysroot_result=$lt_sysroot$func_stripname_result + ;; + esac +} + +# func_replace_sysroot PATH +# If PATH begins with the sysroot, replace it with = and +# store the result into func_replace_sysroot_result. +func_replace_sysroot () +{ + case $lt_sysroot:$1 in + ?*:"$lt_sysroot"*) + func_stripname "$lt_sysroot" '' "$1" + func_replace_sysroot_result='='$func_stripname_result + ;; + *) + # Including no sysroot. + func_replace_sysroot_result=$1 + ;; + esac +} + +# func_infer_tag arg +# Infer tagged configuration to use if any are available and +# if one wasn't chosen via the "--tag" command line option. +# Only attempt this if the compiler in the base compile +# command doesn't match the default compiler. +# arg is usually of the form 'gcc ...' +func_infer_tag () +{ + $debug_cmd + + if test -n "$available_tags" && test -z "$tagname"; then + CC_quoted= + for arg in $CC; do + func_append_quoted CC_quoted "$arg" + done + CC_expanded=`func_echo_all $CC` + CC_quoted_expanded=`func_echo_all $CC_quoted` + case $@ in + # Blanks in the command may have been stripped by the calling shell, + # but not from the CC environment variable when configure was run. + " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ + " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;; + # Blanks at the start of $base_compile will cause this to fail + # if we don't check for them as well. + *) + for z in $available_tags; do + if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then + # Evaluate the configuration. + eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" + CC_quoted= + for arg in $CC; do + # Double-quote args containing other shell metacharacters. + func_append_quoted CC_quoted "$arg" + done + CC_expanded=`func_echo_all $CC` + CC_quoted_expanded=`func_echo_all $CC_quoted` + case "$@ " in + " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ + " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) + # The compiler in the base compile command matches + # the one in the tagged configuration. + # Assume this is the tagged configuration we want. + tagname=$z + break + ;; + esac + fi + done + # If $tagname still isn't set, then no tagged configuration + # was found and let the user know that the "--tag" command + # line option must be used. + if test -z "$tagname"; then + func_echo "unable to infer tagged configuration" + func_fatal_error "specify a tag with '--tag'" +# else +# func_verbose "using $tagname tagged configuration" + fi + ;; + esac + fi +} + + + +# func_write_libtool_object output_name pic_name nonpic_name +# Create a libtool object file (analogous to a ".la" file), +# but don't create it if we're doing a dry run. +func_write_libtool_object () +{ + write_libobj=$1 + if test yes = "$build_libtool_libs"; then + write_lobj=\'$2\' + else + write_lobj=none + fi + + if test yes = "$build_old_libs"; then + write_oldobj=\'$3\' + else + write_oldobj=none + fi + + $opt_dry_run || { + cat >${write_libobj}T </dev/null` + if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then + func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" | + $SED -e "$sed_naive_backslashify"` + else + func_convert_core_file_wine_to_w32_result= + fi + fi +} +# end: func_convert_core_file_wine_to_w32 + + +# func_convert_core_path_wine_to_w32 ARG +# Helper function used by path conversion functions when $build is *nix, and +# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly +# configured wine environment available, with the winepath program in $build's +# $PATH. Assumes ARG has no leading or trailing path separator characters. +# +# ARG is path to be converted from $build format to win32. +# Result is available in $func_convert_core_path_wine_to_w32_result. +# Unconvertible file (directory) names in ARG are skipped; if no directory names +# are convertible, then the result may be empty. +func_convert_core_path_wine_to_w32 () +{ + $debug_cmd + + # unfortunately, winepath doesn't convert paths, only file names + func_convert_core_path_wine_to_w32_result= + if test -n "$1"; then + oldIFS=$IFS + IFS=: + for func_convert_core_path_wine_to_w32_f in $1; do + IFS=$oldIFS + func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f" + if test -n "$func_convert_core_file_wine_to_w32_result"; then + if test -z "$func_convert_core_path_wine_to_w32_result"; then + func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result + else + func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result" + fi + fi + done + IFS=$oldIFS + fi +} +# end: func_convert_core_path_wine_to_w32 + + +# func_cygpath ARGS... +# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when +# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2) +# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or +# (2), returns the Cygwin file name or path in func_cygpath_result (input +# file name or path is assumed to be in w32 format, as previously converted +# from $build's *nix or MSYS format). In case (3), returns the w32 file name +# or path in func_cygpath_result (input file name or path is assumed to be in +# Cygwin format). Returns an empty string on error. +# +# ARGS are passed to cygpath, with the last one being the file name or path to +# be converted. +# +# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH +# environment variable; do not put it in $PATH. +func_cygpath () +{ + $debug_cmd + + if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then + func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null` + if test "$?" -ne 0; then + # on failure, ensure result is empty + func_cygpath_result= + fi + else + func_cygpath_result= + func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'" + fi +} +#end: func_cygpath + + +# func_convert_core_msys_to_w32 ARG +# Convert file name or path ARG from MSYS format to w32 format. Return +# result in func_convert_core_msys_to_w32_result. +func_convert_core_msys_to_w32 () +{ + $debug_cmd + + # awkward: cmd appends spaces to result + func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null | + $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"` +} +#end: func_convert_core_msys_to_w32 + + +# func_convert_file_check ARG1 ARG2 +# Verify that ARG1 (a file name in $build format) was converted to $host +# format in ARG2. Otherwise, emit an error message, but continue (resetting +# func_to_host_file_result to ARG1). +func_convert_file_check () +{ + $debug_cmd + + if test -z "$2" && test -n "$1"; then + func_error "Could not determine host file name corresponding to" + func_error " '$1'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback: + func_to_host_file_result=$1 + fi +} +# end func_convert_file_check + + +# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH +# Verify that FROM_PATH (a path in $build format) was converted to $host +# format in TO_PATH. Otherwise, emit an error message, but continue, resetting +# func_to_host_file_result to a simplistic fallback value (see below). +func_convert_path_check () +{ + $debug_cmd + + if test -z "$4" && test -n "$3"; then + func_error "Could not determine the host path corresponding to" + func_error " '$3'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback. This is a deliberately simplistic "conversion" and + # should not be "improved". See libtool.info. + if test "x$1" != "x$2"; then + lt_replace_pathsep_chars="s|$1|$2|g" + func_to_host_path_result=`echo "$3" | + $SED -e "$lt_replace_pathsep_chars"` + else + func_to_host_path_result=$3 + fi + fi +} +# end func_convert_path_check + + +# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG +# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT +# and appending REPL if ORIG matches BACKPAT. +func_convert_path_front_back_pathsep () +{ + $debug_cmd + + case $4 in + $1 ) func_to_host_path_result=$3$func_to_host_path_result + ;; + esac + case $4 in + $2 ) func_append func_to_host_path_result "$3" + ;; + esac +} +# end func_convert_path_front_back_pathsep + + +################################################## +# $build to $host FILE NAME CONVERSION FUNCTIONS # +################################################## +# invoked via '$to_host_file_cmd ARG' +# +# In each case, ARG is the path to be converted from $build to $host format. +# Result will be available in $func_to_host_file_result. + + +# func_to_host_file ARG +# Converts the file name ARG from $build format to $host format. Return result +# in func_to_host_file_result. +func_to_host_file () +{ + $debug_cmd + + $to_host_file_cmd "$1" +} +# end func_to_host_file + + +# func_to_tool_file ARG LAZY +# converts the file name ARG from $build format to toolchain format. Return +# result in func_to_tool_file_result. If the conversion in use is listed +# in (the comma separated) LAZY, no conversion takes place. +func_to_tool_file () +{ + $debug_cmd + + case ,$2, in + *,"$to_tool_file_cmd",*) + func_to_tool_file_result=$1 + ;; + *) + $to_tool_file_cmd "$1" + func_to_tool_file_result=$func_to_host_file_result + ;; + esac +} +# end func_to_tool_file + + +# func_convert_file_noop ARG +# Copy ARG to func_to_host_file_result. +func_convert_file_noop () +{ + func_to_host_file_result=$1 +} +# end func_convert_file_noop + + +# func_convert_file_msys_to_w32 ARG +# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic +# conversion to w32 is not available inside the cwrapper. Returns result in +# func_to_host_file_result. +func_convert_file_msys_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_msys_to_w32 "$1" + func_to_host_file_result=$func_convert_core_msys_to_w32_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_msys_to_w32 + + +# func_convert_file_cygwin_to_w32 ARG +# Convert file name ARG from Cygwin to w32 format. Returns result in +# func_to_host_file_result. +func_convert_file_cygwin_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + # because $build is cygwin, we call "the" cygpath in $PATH; no need to use + # LT_CYGPATH in this case. + func_to_host_file_result=`cygpath -m "$1"` + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_cygwin_to_w32 + + +# func_convert_file_nix_to_w32 ARG +# Convert file name ARG from *nix to w32 format. Requires a wine environment +# and a working winepath. Returns result in func_to_host_file_result. +func_convert_file_nix_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_file_wine_to_w32 "$1" + func_to_host_file_result=$func_convert_core_file_wine_to_w32_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_nix_to_w32 + + +# func_convert_file_msys_to_cygwin ARG +# Convert file name ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. +# Returns result in func_to_host_file_result. +func_convert_file_msys_to_cygwin () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_msys_to_w32 "$1" + func_cygpath -u "$func_convert_core_msys_to_w32_result" + func_to_host_file_result=$func_cygpath_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_msys_to_cygwin + + +# func_convert_file_nix_to_cygwin ARG +# Convert file name ARG from *nix to Cygwin format. Requires Cygwin installed +# in a wine environment, working winepath, and LT_CYGPATH set. Returns result +# in func_to_host_file_result. +func_convert_file_nix_to_cygwin () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + # convert from *nix to w32, then use cygpath to convert from w32 to cygwin. + func_convert_core_file_wine_to_w32 "$1" + func_cygpath -u "$func_convert_core_file_wine_to_w32_result" + func_to_host_file_result=$func_cygpath_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_nix_to_cygwin + + +############################################# +# $build to $host PATH CONVERSION FUNCTIONS # +############################################# +# invoked via '$to_host_path_cmd ARG' +# +# In each case, ARG is the path to be converted from $build to $host format. +# The result will be available in $func_to_host_path_result. +# +# Path separators are also converted from $build format to $host format. If +# ARG begins or ends with a path separator character, it is preserved (but +# converted to $host format) on output. +# +# All path conversion functions are named using the following convention: +# file name conversion function : func_convert_file_X_to_Y () +# path conversion function : func_convert_path_X_to_Y () +# where, for any given $build/$host combination the 'X_to_Y' value is the +# same. If conversion functions are added for new $build/$host combinations, +# the two new functions must follow this pattern, or func_init_to_host_path_cmd +# will break. + + +# func_init_to_host_path_cmd +# Ensures that function "pointer" variable $to_host_path_cmd is set to the +# appropriate value, based on the value of $to_host_file_cmd. +to_host_path_cmd= +func_init_to_host_path_cmd () +{ + $debug_cmd + + if test -z "$to_host_path_cmd"; then + func_stripname 'func_convert_file_' '' "$to_host_file_cmd" + to_host_path_cmd=func_convert_path_$func_stripname_result + fi +} + + +# func_to_host_path ARG +# Converts the path ARG from $build format to $host format. Return result +# in func_to_host_path_result. +func_to_host_path () +{ + $debug_cmd + + func_init_to_host_path_cmd + $to_host_path_cmd "$1" +} +# end func_to_host_path + + +# func_convert_path_noop ARG +# Copy ARG to func_to_host_path_result. +func_convert_path_noop () +{ + func_to_host_path_result=$1 +} +# end func_convert_path_noop + + +# func_convert_path_msys_to_w32 ARG +# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic +# conversion to w32 is not available inside the cwrapper. Returns result in +# func_to_host_path_result. +func_convert_path_msys_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # Remove leading and trailing path separator characters from ARG. MSYS + # behavior is inconsistent here; cygpath turns them into '.;' and ';.'; + # and winepath ignores them completely. + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" + func_to_host_path_result=$func_convert_core_msys_to_w32_result + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_msys_to_w32 + + +# func_convert_path_cygwin_to_w32 ARG +# Convert path ARG from Cygwin to w32 format. Returns result in +# func_to_host_file_result. +func_convert_path_cygwin_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"` + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_cygwin_to_w32 + + +# func_convert_path_nix_to_w32 ARG +# Convert path ARG from *nix to w32 format. Requires a wine environment and +# a working winepath. Returns result in func_to_host_file_result. +func_convert_path_nix_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" + func_to_host_path_result=$func_convert_core_path_wine_to_w32_result + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_nix_to_w32 + + +# func_convert_path_msys_to_cygwin ARG +# Convert path ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. +# Returns result in func_to_host_file_result. +func_convert_path_msys_to_cygwin () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" + func_cygpath -u -p "$func_convert_core_msys_to_w32_result" + func_to_host_path_result=$func_cygpath_result + func_convert_path_check : : \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" : "$1" + fi +} +# end func_convert_path_msys_to_cygwin + + +# func_convert_path_nix_to_cygwin ARG +# Convert path ARG from *nix to Cygwin format. Requires Cygwin installed in a +# a wine environment, working winepath, and LT_CYGPATH set. Returns result in +# func_to_host_file_result. +func_convert_path_nix_to_cygwin () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # Remove leading and trailing path separator characters from + # ARG. msys behavior is inconsistent here, cygpath turns them + # into '.;' and ';.', and winepath ignores them completely. + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" + func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result" + func_to_host_path_result=$func_cygpath_result + func_convert_path_check : : \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" : "$1" + fi +} +# end func_convert_path_nix_to_cygwin + + +# func_dll_def_p FILE +# True iff FILE is a Windows DLL '.def' file. +# Keep in sync with _LT_DLL_DEF_P in libtool.m4 +func_dll_def_p () +{ + $debug_cmd + + func_dll_def_p_tmp=`$SED -n \ + -e 's/^[ ]*//' \ + -e '/^\(;.*\)*$/d' \ + -e 's/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p' \ + -e q \ + "$1"` + test DEF = "$func_dll_def_p_tmp" +} + + +# func_mode_compile arg... +func_mode_compile () +{ + $debug_cmd + + # Get the compilation command and the source file. + base_compile= + srcfile=$nonopt # always keep a non-empty value in "srcfile" + suppress_opt=yes + suppress_output= + arg_mode=normal + libobj= + later= + pie_flag= + + for arg + do + case $arg_mode in + arg ) + # do not "continue". Instead, add this to base_compile + lastarg=$arg + arg_mode=normal + ;; + + target ) + libobj=$arg + arg_mode=normal + continue + ;; + + normal ) + # Accept any command-line options. + case $arg in + -o) + test -n "$libobj" && \ + func_fatal_error "you cannot specify '-o' more than once" + arg_mode=target + continue + ;; + + -pie | -fpie | -fPIE) + func_append pie_flag " $arg" + continue + ;; + + -shared | -static | -prefer-pic | -prefer-non-pic) + func_append later " $arg" + continue + ;; + + -no-suppress) + suppress_opt=no + continue + ;; + + -Xcompiler) + arg_mode=arg # the next one goes into the "base_compile" arg list + continue # The current "srcfile" will either be retained or + ;; # replaced later. I would guess that would be a bug. + + -Wc,*) + func_stripname '-Wc,' '' "$arg" + args=$func_stripname_result + lastarg= + save_ifs=$IFS; IFS=, + for arg in $args; do + IFS=$save_ifs + func_append_quoted lastarg "$arg" + done + IFS=$save_ifs + func_stripname ' ' '' "$lastarg" + lastarg=$func_stripname_result + + # Add the arguments to base_compile. + func_append base_compile " $lastarg" + continue + ;; + + *) + # Accept the current argument as the source file. + # The previous "srcfile" becomes the current argument. + # + lastarg=$srcfile + srcfile=$arg + ;; + esac # case $arg + ;; + esac # case $arg_mode + + # Aesthetically quote the previous argument. + func_append_quoted base_compile "$lastarg" + done # for arg + + case $arg_mode in + arg) + func_fatal_error "you must specify an argument for -Xcompile" + ;; + target) + func_fatal_error "you must specify a target with '-o'" + ;; + *) + # Get the name of the library object. + test -z "$libobj" && { + func_basename "$srcfile" + libobj=$func_basename_result + } + ;; + esac + + # Recognize several different file suffixes. + # If the user specifies -o file.o, it is replaced with file.lo + case $libobj in + *.[cCFSifmso] | \ + *.ada | *.adb | *.ads | *.asm | \ + *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \ + *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup) + func_xform "$libobj" + libobj=$func_xform_result + ;; + esac + + case $libobj in + *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;; + *) + func_fatal_error "cannot determine name of library object from '$libobj'" + ;; + esac + + func_infer_tag $base_compile + + for arg in $later; do + case $arg in + -shared) + test yes = "$build_libtool_libs" \ + || func_fatal_configuration "cannot build a shared library" + build_old_libs=no + continue + ;; + + -static) + build_libtool_libs=no + build_old_libs=yes + continue + ;; + + -prefer-pic) + pic_mode=yes + continue + ;; + + -prefer-non-pic) + pic_mode=no + continue + ;; + esac + done + + func_quote_for_eval "$libobj" + test "X$libobj" != "X$func_quote_for_eval_result" \ + && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"' &()|`$[]' \ + && func_warning "libobj name '$libobj' may not contain shell special characters." + func_dirname_and_basename "$obj" "/" "" + objname=$func_basename_result + xdir=$func_dirname_result + lobj=$xdir$objdir/$objname + + test -z "$base_compile" && \ + func_fatal_help "you must specify a compilation command" + + # Delete any leftover library objects. + if test yes = "$build_old_libs"; then + removelist="$obj $lobj $libobj ${libobj}T" + else + removelist="$lobj $libobj ${libobj}T" + fi + + # On Cygwin there's no "real" PIC flag so we must build both object types + case $host_os in + cygwin* | mingw* | pw32* | os2* | cegcc*) + pic_mode=default + ;; + esac + if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then + # non-PIC code in shared libraries is not supported + pic_mode=default + fi + + # Calculate the filename of the output object if compiler does + # not support -o with -c + if test no = "$compiler_c_o"; then + output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext + lockfile=$output_obj.lock + else + output_obj= + need_locks=no + lockfile= + fi + + # Lock this critical section if it is needed + # We use this script file to make the link, it avoids creating a new file + if test yes = "$need_locks"; then + until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do + func_echo "Waiting for $lockfile to be removed" + sleep 2 + done + elif test warn = "$need_locks"; then + if test -f "$lockfile"; then + $ECHO "\ +*** ERROR, $lockfile exists and contains: +`cat $lockfile 2>/dev/null` + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + func_append removelist " $output_obj" + $ECHO "$srcfile" > "$lockfile" + fi + + $opt_dry_run || $RM $removelist + func_append removelist " $lockfile" + trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15 + + func_to_tool_file "$srcfile" func_convert_file_msys_to_w32 + srcfile=$func_to_tool_file_result + func_quote_for_eval "$srcfile" + qsrcfile=$func_quote_for_eval_result + + # Only build a PIC object if we are building libtool libraries. + if test yes = "$build_libtool_libs"; then + # Without this assignment, base_compile gets emptied. + fbsd_hideous_sh_bug=$base_compile + + if test no != "$pic_mode"; then + command="$base_compile $qsrcfile $pic_flag" + else + # Don't build PIC code + command="$base_compile $qsrcfile" + fi + + func_mkdir_p "$xdir$objdir" + + if test -z "$output_obj"; then + # Place PIC objects in $objdir + func_append command " -o $lobj" + fi + + func_show_eval_locale "$command" \ + 'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE' + + if test warn = "$need_locks" && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed, then go on to compile the next one + if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then + func_show_eval '$MV "$output_obj" "$lobj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + + # Allow error messages only from the first compilation. + if test yes = "$suppress_opt"; then + suppress_output=' >/dev/null 2>&1' + fi + fi + + # Only build a position-dependent object if we build old libraries. + if test yes = "$build_old_libs"; then + if test yes != "$pic_mode"; then + # Don't build PIC code + command="$base_compile $qsrcfile$pie_flag" + else + command="$base_compile $qsrcfile $pic_flag" + fi + if test yes = "$compiler_c_o"; then + func_append command " -o $obj" + fi + + # Suppress compiler output if we already did a PIC compilation. + func_append command "$suppress_output" + func_show_eval_locale "$command" \ + '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' + + if test warn = "$need_locks" && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed + if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then + func_show_eval '$MV "$output_obj" "$obj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + fi + + $opt_dry_run || { + func_write_libtool_object "$libobj" "$objdir/$objname" "$objname" + + # Unlock the critical section if it was locked + if test no != "$need_locks"; then + removelist=$lockfile + $RM "$lockfile" + fi + } + + exit $EXIT_SUCCESS +} + +$opt_help || { + test compile = "$opt_mode" && func_mode_compile ${1+"$@"} +} + +func_mode_help () +{ + # We need to display help for each of the modes. + case $opt_mode in + "") + # Generic help is extracted from the usage comments + # at the start of this file. + func_help + ;; + + clean) + $ECHO \ +"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE... + +Remove files from the build directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed +to RM. + +If FILE is a libtool library, object or program, all the files associated +with it are deleted. Otherwise, only FILE itself is deleted using RM." + ;; + + compile) + $ECHO \ +"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE + +Compile a source file into a libtool library object. + +This mode accepts the following additional options: + + -o OUTPUT-FILE set the output file name to OUTPUT-FILE + -no-suppress do not suppress compiler output for multiple passes + -prefer-pic try to build PIC objects only + -prefer-non-pic try to build non-PIC objects only + -shared do not build a '.o' file suitable for static linking + -static only build a '.o' file suitable for static linking + -Wc,FLAG pass FLAG directly to the compiler + +COMPILE-COMMAND is a command to be used in creating a 'standard' object file +from the given SOURCEFILE. + +The output file name is determined by removing the directory component from +SOURCEFILE, then substituting the C source code suffix '.c' with the +library object suffix, '.lo'." + ;; + + execute) + $ECHO \ +"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]... + +Automatically set library path, then run a program. + +This mode accepts the following additional options: + + -dlopen FILE add the directory containing FILE to the library path + +This mode sets the library path environment variable according to '-dlopen' +flags. + +If any of the ARGS are libtool executable wrappers, then they are translated +into their corresponding uninstalled binary, and any of their required library +directories are added to the library path. + +Then, COMMAND is executed, with ARGS as arguments." + ;; + + finish) + $ECHO \ +"Usage: $progname [OPTION]... --mode=finish [LIBDIR]... + +Complete the installation of libtool libraries. + +Each LIBDIR is a directory that contains libtool libraries. + +The commands that this mode executes may require superuser privileges. Use +the '--dry-run' option if you just want to see what would be executed." + ;; + + install) + $ECHO \ +"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND... + +Install executables or libraries. + +INSTALL-COMMAND is the installation command. The first component should be +either the 'install' or 'cp' program. + +The following components of INSTALL-COMMAND are treated specially: + + -inst-prefix-dir PREFIX-DIR Use PREFIX-DIR as a staging area for installation + +The rest of the components are interpreted as arguments to that command (only +BSD-compatible install options are recognized)." + ;; + + link) + $ECHO \ +"Usage: $progname [OPTION]... --mode=link LINK-COMMAND... + +Link object files or libraries together to form another library, or to +create an executable program. + +LINK-COMMAND is a command using the C compiler that you would use to create +a program from several object files. + +The following components of LINK-COMMAND are treated specially: + + -all-static do not do any dynamic linking at all + -avoid-version do not add a version suffix if possible + -bindir BINDIR specify path to binaries directory (for systems where + libraries must be found in the PATH setting at runtime) + -dlopen FILE '-dlpreopen' FILE if it cannot be dlopened at runtime + -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols + -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) + -export-symbols SYMFILE + try to export only the symbols listed in SYMFILE + -export-symbols-regex REGEX + try to export only the symbols matching REGEX + -LLIBDIR search LIBDIR for required installed libraries + -lNAME OUTPUT-FILE requires the installed library libNAME + -module build a library that can dlopened + -no-fast-install disable the fast-install mode + -no-install link a not-installable executable + -no-undefined declare that a library does not refer to external symbols + -o OUTPUT-FILE create OUTPUT-FILE from the specified objects + -objectlist FILE use a list of object files found in FILE to specify objects + -os2dllname NAME force a short DLL name on OS/2 (no effect on other OSes) + -precious-files-regex REGEX + don't remove output files matching REGEX + -release RELEASE specify package release information + -rpath LIBDIR the created library will eventually be installed in LIBDIR + -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries + -shared only do dynamic linking of libtool libraries + -shrext SUFFIX override the standard shared library file extension + -static do not do any dynamic linking of uninstalled libtool libraries + -static-libtool-libs + do not do any dynamic linking of libtool libraries + -version-info CURRENT[:REVISION[:AGE]] + specify library version info [each variable defaults to 0] + -weak LIBNAME declare that the target provides the LIBNAME interface + -Wc,FLAG + -Xcompiler FLAG pass linker-specific FLAG directly to the compiler + -Wl,FLAG + -Xlinker FLAG pass linker-specific FLAG directly to the linker + -XCClinker FLAG pass link-specific FLAG to the compiler driver (CC) + +All other options (arguments beginning with '-') are ignored. + +Every other argument is treated as a filename. Files ending in '.la' are +treated as uninstalled libtool libraries, other files are standard or library +object files. + +If the OUTPUT-FILE ends in '.la', then a libtool library is created, +only library objects ('.lo' files) may be specified, and '-rpath' is +required, except when creating a convenience library. + +If OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created +using 'ar' and 'ranlib', or on Windows using 'lib'. + +If OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file +is created, otherwise an executable program is created." + ;; + + uninstall) + $ECHO \ +"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... + +Remove libraries from an installation directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed +to RM. + +If FILE is a libtool library, all the files associated with it are deleted. +Otherwise, only FILE itself is deleted using RM." + ;; + + *) + func_fatal_help "invalid operation mode '$opt_mode'" + ;; + esac + + echo + $ECHO "Try '$progname --help' for more information about other modes." +} + +# Now that we've collected a possible --mode arg, show help if necessary +if $opt_help; then + if test : = "$opt_help"; then + func_mode_help + else + { + func_help noexit + for opt_mode in compile link execute install finish uninstall clean; do + func_mode_help + done + } | $SED -n '1p; 2,$s/^Usage:/ or: /p' + { + func_help noexit + for opt_mode in compile link execute install finish uninstall clean; do + echo + func_mode_help + done + } | + $SED '1d + /^When reporting/,/^Report/{ + H + d + } + $x + /information about other modes/d + /more detailed .*MODE/d + s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/' + fi + exit $? +fi + + +# func_mode_execute arg... +func_mode_execute () +{ + $debug_cmd + + # The first argument is the command name. + cmd=$nonopt + test -z "$cmd" && \ + func_fatal_help "you must specify a COMMAND" + + # Handle -dlopen flags immediately. + for file in $opt_dlopen; do + test -f "$file" \ + || func_fatal_help "'$file' is not a file" + + dir= + case $file in + *.la) + func_resolve_sysroot "$file" + file=$func_resolve_sysroot_result + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "'$lib' is not a valid libtool archive" + + # Read the libtool library. + dlname= + library_names= + func_source "$file" + + # Skip this library if it cannot be dlopened. + if test -z "$dlname"; then + # Warn if it was a shared library. + test -n "$library_names" && \ + func_warning "'$file' was not linked with '-export-dynamic'" + continue + fi + + func_dirname "$file" "" "." + dir=$func_dirname_result + + if test -f "$dir/$objdir/$dlname"; then + func_append dir "/$objdir" + else + if test ! -f "$dir/$dlname"; then + func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'" + fi + fi + ;; + + *.lo) + # Just add the directory containing the .lo file. + func_dirname "$file" "" "." + dir=$func_dirname_result + ;; + + *) + func_warning "'-dlopen' is ignored for non-libtool libraries and objects" + continue + ;; + esac + + # Get the absolute pathname. + absdir=`cd "$dir" && pwd` + test -n "$absdir" && dir=$absdir + + # Now add the directory to shlibpath_var. + if eval "test -z \"\$$shlibpath_var\""; then + eval "$shlibpath_var=\"\$dir\"" + else + eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" + fi + done + + # This variable tells wrapper scripts just to set shlibpath_var + # rather than running their programs. + libtool_execute_magic=$magic + + # Check if any of the arguments is a wrapper script. + args= + for file + do + case $file in + -* | *.la | *.lo ) ;; + *) + # Do a test to see if this is really a libtool program. + if func_ltwrapper_script_p "$file"; then + func_source "$file" + # Transform arg to wrapped name. + file=$progdir/$program + elif func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + func_source "$func_ltwrapper_scriptname_result" + # Transform arg to wrapped name. + file=$progdir/$program + fi + ;; + esac + # Quote arguments (to preserve shell metacharacters). + func_append_quoted args "$file" + done + + if $opt_dry_run; then + # Display what would be done. + if test -n "$shlibpath_var"; then + eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\"" + echo "export $shlibpath_var" + fi + $ECHO "$cmd$args" + exit $EXIT_SUCCESS + else + if test -n "$shlibpath_var"; then + # Export the shlibpath_var. + eval "export $shlibpath_var" + fi + + # Restore saved environment variables + for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + do + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + else + $lt_unset $lt_var + fi" + done + + # Now prepare to actually exec the command. + exec_cmd=\$cmd$args + fi +} + +test execute = "$opt_mode" && func_mode_execute ${1+"$@"} + + +# func_mode_finish arg... +func_mode_finish () +{ + $debug_cmd + + libs= + libdirs= + admincmds= + + for opt in "$nonopt" ${1+"$@"} + do + if test -d "$opt"; then + func_append libdirs " $opt" + + elif test -f "$opt"; then + if func_lalib_unsafe_p "$opt"; then + func_append libs " $opt" + else + func_warning "'$opt' is not a valid libtool archive" + fi + + else + func_fatal_error "invalid argument '$opt'" + fi + done + + if test -n "$libs"; then + if test -n "$lt_sysroot"; then + sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"` + sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;" + else + sysroot_cmd= + fi + + # Remove sysroot references + if $opt_dry_run; then + for lib in $libs; do + echo "removing references to $lt_sysroot and '=' prefixes from $lib" + done + else + tmpdir=`func_mktempdir` + for lib in $libs; do + $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \ + > $tmpdir/tmp-la + mv -f $tmpdir/tmp-la $lib + done + ${RM}r "$tmpdir" + fi + fi + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + for libdir in $libdirs; do + if test -n "$finish_cmds"; then + # Do each command in the finish commands. + func_execute_cmds "$finish_cmds" 'admincmds="$admincmds +'"$cmd"'"' + fi + if test -n "$finish_eval"; then + # Do the single finish_eval. + eval cmds=\"$finish_eval\" + $opt_dry_run || eval "$cmds" || func_append admincmds " + $cmds" + fi + done + fi + + # Exit here if they wanted silent mode. + $opt_quiet && exit $EXIT_SUCCESS + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + echo "----------------------------------------------------------------------" + echo "Libraries have been installed in:" + for libdir in $libdirs; do + $ECHO " $libdir" + done + echo + echo "If you ever happen to want to link against installed libraries" + echo "in a given directory, LIBDIR, you must either use libtool, and" + echo "specify the full pathname of the library, or use the '-LLIBDIR'" + echo "flag during linking and do at least one of the following:" + if test -n "$shlibpath_var"; then + echo " - add LIBDIR to the '$shlibpath_var' environment variable" + echo " during execution" + fi + if test -n "$runpath_var"; then + echo " - add LIBDIR to the '$runpath_var' environment variable" + echo " during linking" + fi + if test -n "$hardcode_libdir_flag_spec"; then + libdir=LIBDIR + eval flag=\"$hardcode_libdir_flag_spec\" + + $ECHO " - use the '$flag' linker flag" + fi + if test -n "$admincmds"; then + $ECHO " - have your system administrator run these commands:$admincmds" + fi + if test -f /etc/ld.so.conf; then + echo " - have your system administrator add LIBDIR to '/etc/ld.so.conf'" + fi + echo + + echo "See any operating system documentation about shared libraries for" + case $host in + solaris2.[6789]|solaris2.1[0-9]) + echo "more information, such as the ld(1), crle(1) and ld.so(8) manual" + echo "pages." + ;; + *) + echo "more information, such as the ld(1) and ld.so(8) manual pages." + ;; + esac + echo "----------------------------------------------------------------------" + fi + exit $EXIT_SUCCESS +} + +test finish = "$opt_mode" && func_mode_finish ${1+"$@"} + + +# func_mode_install arg... +func_mode_install () +{ + $debug_cmd + + # There may be an optional sh(1) argument at the beginning of + # install_prog (especially on Windows NT). + if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" || + # Allow the use of GNU shtool's install command. + case $nonopt in *shtool*) :;; *) false;; esac + then + # Aesthetically quote it. + func_quote_for_eval "$nonopt" + install_prog="$func_quote_for_eval_result " + arg=$1 + shift + else + install_prog= + arg=$nonopt + fi + + # The real first argument should be the name of the installation program. + # Aesthetically quote it. + func_quote_for_eval "$arg" + func_append install_prog "$func_quote_for_eval_result" + install_shared_prog=$install_prog + case " $install_prog " in + *[\\\ /]cp\ *) install_cp=: ;; + *) install_cp=false ;; + esac + + # We need to accept at least all the BSD install flags. + dest= + files= + opts= + prev= + install_type= + isdir=false + stripme= + no_mode=: + for arg + do + arg2= + if test -n "$dest"; then + func_append files " $dest" + dest=$arg + continue + fi + + case $arg in + -d) isdir=: ;; + -f) + if $install_cp; then :; else + prev=$arg + fi + ;; + -g | -m | -o) + prev=$arg + ;; + -s) + stripme=" -s" + continue + ;; + -*) + ;; + *) + # If the previous option needed an argument, then skip it. + if test -n "$prev"; then + if test X-m = "X$prev" && test -n "$install_override_mode"; then + arg2=$install_override_mode + no_mode=false + fi + prev= + else + dest=$arg + continue + fi + ;; + esac + + # Aesthetically quote the argument. + func_quote_for_eval "$arg" + func_append install_prog " $func_quote_for_eval_result" + if test -n "$arg2"; then + func_quote_for_eval "$arg2" + fi + func_append install_shared_prog " $func_quote_for_eval_result" + done + + test -z "$install_prog" && \ + func_fatal_help "you must specify an install program" + + test -n "$prev" && \ + func_fatal_help "the '$prev' option requires an argument" + + if test -n "$install_override_mode" && $no_mode; then + if $install_cp; then :; else + func_quote_for_eval "$install_override_mode" + func_append install_shared_prog " -m $func_quote_for_eval_result" + fi + fi + + if test -z "$files"; then + if test -z "$dest"; then + func_fatal_help "no file or destination specified" + else + func_fatal_help "you must specify a destination" + fi + fi + + # Strip any trailing slash from the destination. + func_stripname '' '/' "$dest" + dest=$func_stripname_result + + # Check to see that the destination is a directory. + test -d "$dest" && isdir=: + if $isdir; then + destdir=$dest + destname= + else + func_dirname_and_basename "$dest" "" "." + destdir=$func_dirname_result + destname=$func_basename_result + + # Not a directory, so check to see that there is only one file specified. + set dummy $files; shift + test "$#" -gt 1 && \ + func_fatal_help "'$dest' is not a directory" + fi + case $destdir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + for file in $files; do + case $file in + *.lo) ;; + *) + func_fatal_help "'$destdir' must be an absolute directory name" + ;; + esac + done + ;; + esac + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic=$magic + + staticlibs= + future_libdirs= + current_libdirs= + for file in $files; do + + # Do each installation. + case $file in + *.$libext) + # Do the static libraries later. + func_append staticlibs " $file" + ;; + + *.la) + func_resolve_sysroot "$file" + file=$func_resolve_sysroot_result + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "'$file' is not a valid libtool archive" + + library_names= + old_library= + relink_command= + func_source "$file" + + # Add the libdir to current_libdirs if it is the destination. + if test "X$destdir" = "X$libdir"; then + case "$current_libdirs " in + *" $libdir "*) ;; + *) func_append current_libdirs " $libdir" ;; + esac + else + # Note the libdir as a future libdir. + case "$future_libdirs " in + *" $libdir "*) ;; + *) func_append future_libdirs " $libdir" ;; + esac + fi + + func_dirname "$file" "/" "" + dir=$func_dirname_result + func_append dir "$objdir" + + if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + # At present, this check doesn't affect windows .dll's that + # are installed into $libdir/../bin (currently, that works fine) + # but it's something to keep an eye on. + test "$inst_prefix_dir" = "$destdir" && \ + func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir" + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` + else + relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"` + fi + + func_warning "relinking '$file'" + func_show_eval "$relink_command" \ + 'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"' + fi + + # See the names of the shared library. + set dummy $library_names; shift + if test -n "$1"; then + realname=$1 + shift + + srcname=$realname + test -n "$relink_command" && srcname=${realname}T + + # Install the shared library and build the symlinks. + func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \ + 'exit $?' + tstripme=$stripme + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + case $realname in + *.dll.a) + tstripme= + ;; + esac + ;; + os2*) + case $realname in + *_dll.a) + tstripme= + ;; + esac + ;; + esac + if test -n "$tstripme" && test -n "$striplib"; then + func_show_eval "$striplib $destdir/$realname" 'exit $?' + fi + + if test "$#" -gt 0; then + # Delete the old symlinks, and create new ones. + # Try 'ln -sf' first, because the 'ln' binary might depend on + # the symlink we replace! Solaris /bin/ln does not understand -f, + # so we also need to try rm && ln -s. + for linkname + do + test "$linkname" != "$realname" \ + && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })" + done + fi + + # Do each command in the postinstall commands. + lib=$destdir/$realname + func_execute_cmds "$postinstall_cmds" 'exit $?' + fi + + # Install the pseudo-library for information purposes. + func_basename "$file" + name=$func_basename_result + instname=$dir/${name}i + func_show_eval "$install_prog $instname $destdir/$name" 'exit $?' + + # Maybe install the static library, too. + test -n "$old_library" && func_append staticlibs " $dir/$old_library" + ;; + + *.lo) + # Install (i.e. copy) a libtool object. + + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile=$destdir/$destname + else + func_basename "$file" + destfile=$func_basename_result + destfile=$destdir/$destfile + fi + + # Deduce the name of the destination old-style object file. + case $destfile in + *.lo) + func_lo2o "$destfile" + staticdest=$func_lo2o_result + ;; + *.$objext) + staticdest=$destfile + destfile= + ;; + *) + func_fatal_help "cannot copy a libtool object to '$destfile'" + ;; + esac + + # Install the libtool object if requested. + test -n "$destfile" && \ + func_show_eval "$install_prog $file $destfile" 'exit $?' + + # Install the old object if enabled. + if test yes = "$build_old_libs"; then + # Deduce the name of the old-style object file. + func_lo2o "$file" + staticobj=$func_lo2o_result + func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?' + fi + exit $EXIT_SUCCESS + ;; + + *) + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile=$destdir/$destname + else + func_basename "$file" + destfile=$func_basename_result + destfile=$destdir/$destfile + fi + + # If the file is missing, and there is a .exe on the end, strip it + # because it is most likely a libtool script we actually want to + # install + stripped_ext= + case $file in + *.exe) + if test ! -f "$file"; then + func_stripname '' '.exe' "$file" + file=$func_stripname_result + stripped_ext=.exe + fi + ;; + esac + + # Do a test to see if this is really a libtool program. + case $host in + *cygwin* | *mingw*) + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + wrapper=$func_ltwrapper_scriptname_result + else + func_stripname '' '.exe' "$file" + wrapper=$func_stripname_result + fi + ;; + *) + wrapper=$file + ;; + esac + if func_ltwrapper_script_p "$wrapper"; then + notinst_deplibs= + relink_command= + + func_source "$wrapper" + + # Check the variables that should have been set. + test -z "$generated_by_libtool_version" && \ + func_fatal_error "invalid libtool wrapper script '$wrapper'" + + finalize=: + for lib in $notinst_deplibs; do + # Check to see that each library is installed. + libdir= + if test -f "$lib"; then + func_source "$lib" + fi + libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'` + if test -n "$libdir" && test ! -f "$libfile"; then + func_warning "'$lib' has not been installed in '$libdir'" + finalize=false + fi + done + + relink_command= + func_source "$wrapper" + + outputname= + if test no = "$fast_install" && test -n "$relink_command"; then + $opt_dry_run || { + if $finalize; then + tmpdir=`func_mktempdir` + func_basename "$file$stripped_ext" + file=$func_basename_result + outputname=$tmpdir/$file + # Replace the output file specification. + relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'` + + $opt_quiet || { + func_quote_for_expand "$relink_command" + eval "func_echo $func_quote_for_expand_result" + } + if eval "$relink_command"; then : + else + func_error "error: relink '$file' with the above command before installing it" + $opt_dry_run || ${RM}r "$tmpdir" + continue + fi + file=$outputname + else + func_warning "cannot relink '$file'" + fi + } + else + # Install the binary that we compiled earlier. + file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"` + fi + fi + + # remove .exe since cygwin /usr/bin/install will append another + # one anyway + case $install_prog,$host in + */usr/bin/install*,*cygwin*) + case $file:$destfile in + *.exe:*.exe) + # this is ok + ;; + *.exe:*) + destfile=$destfile.exe + ;; + *:*.exe) + func_stripname '' '.exe' "$destfile" + destfile=$func_stripname_result + ;; + esac + ;; + esac + func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?' + $opt_dry_run || if test -n "$outputname"; then + ${RM}r "$tmpdir" + fi + ;; + esac + done + + for file in $staticlibs; do + func_basename "$file" + name=$func_basename_result + + # Set up the ranlib parameters. + oldlib=$destdir/$name + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result + + func_show_eval "$install_prog \$file \$oldlib" 'exit $?' + + if test -n "$stripme" && test -n "$old_striplib"; then + func_show_eval "$old_striplib $tool_oldlib" 'exit $?' + fi + + # Do each command in the postinstall commands. + func_execute_cmds "$old_postinstall_cmds" 'exit $?' + done + + test -n "$future_libdirs" && \ + func_warning "remember to run '$progname --finish$future_libdirs'" + + if test -n "$current_libdirs"; then + # Maybe just do a dry run. + $opt_dry_run && current_libdirs=" -n$current_libdirs" + exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs' + else + exit $EXIT_SUCCESS + fi +} + +test install = "$opt_mode" && func_mode_install ${1+"$@"} + + +# func_generate_dlsyms outputname originator pic_p +# Extract symbols from dlprefiles and create ${outputname}S.o with +# a dlpreopen symbol table. +func_generate_dlsyms () +{ + $debug_cmd + + my_outputname=$1 + my_originator=$2 + my_pic_p=${3-false} + my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'` + my_dlsyms= + + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + my_dlsyms=${my_outputname}S.c + else + func_error "not configured to extract global symbols from dlpreopened files" + fi + fi + + if test -n "$my_dlsyms"; then + case $my_dlsyms in + "") ;; + *.c) + # Discover the nlist of each of the dlfiles. + nlist=$output_objdir/$my_outputname.nm + + func_show_eval "$RM $nlist ${nlist}S ${nlist}T" + + # Parse the name list into a source file. + func_verbose "creating $output_objdir/$my_dlsyms" + + $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\ +/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */ +/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */ + +#ifdef __cplusplus +extern \"C\" { +#endif + +#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4)) +#pragma GCC diagnostic ignored \"-Wstrict-prototypes\" +#endif + +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + +#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) + +/* External symbol declarations for the compiler. */\ +" + + if test yes = "$dlself"; then + func_verbose "generating symbol list for '$output'" + + $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist" + + # Add our own program objects to the symbol list. + progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP` + for progfile in $progfiles; do + func_to_tool_file "$progfile" func_convert_file_msys_to_w32 + func_verbose "extracting global C symbols from '$func_to_tool_file_result'" + $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'" + done + + if test -n "$exclude_expsyms"; then + $opt_dry_run || { + eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + if test -n "$export_symbols_regex"; then + $opt_dry_run || { + eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + export_symbols=$output_objdir/$outputname.exp + $opt_dry_run || { + $RM $export_symbols + eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' + case $host in + *cygwin* | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' + ;; + esac + } + else + $opt_dry_run || { + eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' + eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + case $host in + *cygwin* | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' + ;; + esac + } + fi + fi + + for dlprefile in $dlprefiles; do + func_verbose "extracting global C symbols from '$dlprefile'" + func_basename "$dlprefile" + name=$func_basename_result + case $host in + *cygwin* | *mingw* | *cegcc* ) + # if an import library, we need to obtain dlname + if func_win32_import_lib_p "$dlprefile"; then + func_tr_sh "$dlprefile" + eval "curr_lafile=\$libfile_$func_tr_sh_result" + dlprefile_dlbasename= + if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then + # Use subshell, to avoid clobbering current variable values + dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"` + if test -n "$dlprefile_dlname"; then + func_basename "$dlprefile_dlname" + dlprefile_dlbasename=$func_basename_result + else + # no lafile. user explicitly requested -dlpreopen . + $sharedlib_from_linklib_cmd "$dlprefile" + dlprefile_dlbasename=$sharedlib_from_linklib_result + fi + fi + $opt_dry_run || { + if test -n "$dlprefile_dlbasename"; then + eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"' + else + func_warning "Could not compute DLL name from $name" + eval '$ECHO ": $name " >> "$nlist"' + fi + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | + $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" + } + else # not an import lib + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + fi + ;; + *) + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + ;; + esac + done + + $opt_dry_run || { + # Make sure we have at least an empty file. + test -f "$nlist" || : > "$nlist" + + if test -n "$exclude_expsyms"; then + $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T + $MV "$nlist"T "$nlist" + fi + + # Try sorting and uniquifying the output. + if $GREP -v "^: " < "$nlist" | + if sort -k 3 /dev/null 2>&1; then + sort -k 3 + else + sort +2 + fi | + uniq > "$nlist"S; then + : + else + $GREP -v "^: " < "$nlist" > "$nlist"S + fi + + if test -f "$nlist"S; then + eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"' + else + echo '/* NONE */' >> "$output_objdir/$my_dlsyms" + fi + + func_show_eval '$RM "${nlist}I"' + if test -n "$global_symbol_to_import"; then + eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I' + fi + + echo >> "$output_objdir/$my_dlsyms" "\ + +/* The mapping between symbol names and symbols. */ +typedef struct { + const char *name; + void *address; +} lt_dlsymlist; +extern LT_DLSYM_CONST lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[];\ +" + + if test -s "$nlist"I; then + echo >> "$output_objdir/$my_dlsyms" "\ +static void lt_syminit(void) +{ + LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols; + for (; symbol->name; ++symbol) + {" + $SED 's/.*/ if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms" + echo >> "$output_objdir/$my_dlsyms" "\ + } +}" + fi + echo >> "$output_objdir/$my_dlsyms" "\ +LT_DLSYM_CONST lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[] = +{ {\"$my_originator\", (void *) 0}," + + if test -s "$nlist"I; then + echo >> "$output_objdir/$my_dlsyms" "\ + {\"@INIT@\", (void *) <_syminit}," + fi + + case $need_lib_prefix in + no) + eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + *) + eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + esac + echo >> "$output_objdir/$my_dlsyms" "\ + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt_${my_prefix}_LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif\ +" + } # !$opt_dry_run + + pic_flag_for_symtable= + case "$compile_command " in + *" -static "*) ;; + *) + case $host in + # compiling the symbol table file with pic_flag works around + # a FreeBSD bug that causes programs to crash when -lm is + # linked before any other PIC object. But we must not use + # pic_flag when linking with -static. The problem exists in + # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. + *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; + *-*-hpux*) + pic_flag_for_symtable=" $pic_flag" ;; + *) + $my_pic_p && pic_flag_for_symtable=" $pic_flag" + ;; + esac + ;; + esac + symtab_cflags= + for arg in $LTCFLAGS; do + case $arg in + -pie | -fpie | -fPIE) ;; + *) func_append symtab_cflags " $arg" ;; + esac + done + + # Now compile the dynamic symbol file. + func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?' + + # Clean up the generated files. + func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"' + + # Transform the symbol file into the correct name. + symfileobj=$output_objdir/${my_outputname}S.$objext + case $host in + *cygwin* | *mingw* | *cegcc* ) + if test -f "$output_objdir/$my_outputname.def"; then + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + else + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` + fi + ;; + *) + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` + ;; + esac + ;; + *) + func_fatal_error "unknown suffix for '$my_dlsyms'" + ;; + esac + else + # We keep going just in case the user didn't refer to + # lt_preloaded_symbols. The linker will fail if global_symbol_pipe + # really was required. + + # Nullify the symbol file. + compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"` + fi +} + +# func_cygming_gnu_implib_p ARG +# This predicate returns with zero status (TRUE) if +# ARG is a GNU/binutils-style import library. Returns +# with nonzero status (FALSE) otherwise. +func_cygming_gnu_implib_p () +{ + $debug_cmd + + func_to_tool_file "$1" func_convert_file_msys_to_w32 + func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'` + test -n "$func_cygming_gnu_implib_tmp" +} + +# func_cygming_ms_implib_p ARG +# This predicate returns with zero status (TRUE) if +# ARG is an MS-style import library. Returns +# with nonzero status (FALSE) otherwise. +func_cygming_ms_implib_p () +{ + $debug_cmd + + func_to_tool_file "$1" func_convert_file_msys_to_w32 + func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'` + test -n "$func_cygming_ms_implib_tmp" +} + +# func_win32_libid arg +# return the library type of file 'arg' +# +# Need a lot of goo to handle *both* DLLs and import libs +# Has to be a shell function in order to 'eat' the argument +# that is supplied when $file_magic_command is called. +# Despite the name, also deal with 64 bit binaries. +func_win32_libid () +{ + $debug_cmd + + win32_libid_type=unknown + win32_fileres=`file -L $1 2>/dev/null` + case $win32_fileres in + *ar\ archive\ import\ library*) # definitely import + win32_libid_type="x86 archive import" + ;; + *ar\ archive*) # could be an import, or static + # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD. + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | + $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then + case $nm_interface in + "MS dumpbin") + if func_cygming_ms_implib_p "$1" || + func_cygming_gnu_implib_p "$1" + then + win32_nmres=import + else + win32_nmres= + fi + ;; + *) + func_to_tool_file "$1" func_convert_file_msys_to_w32 + win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" | + $SED -n -e ' + 1,100{ + / I /{ + s|.*|import| + p + q + } + }'` + ;; + esac + case $win32_nmres in + import*) win32_libid_type="x86 archive import";; + *) win32_libid_type="x86 archive static";; + esac + fi + ;; + *DLL*) + win32_libid_type="x86 DLL" + ;; + *executable*) # but shell scripts are "executable" too... + case $win32_fileres in + *MS\ Windows\ PE\ Intel*) + win32_libid_type="x86 DLL" + ;; + esac + ;; + esac + $ECHO "$win32_libid_type" +} + +# func_cygming_dll_for_implib ARG +# +# Platform-specific function to extract the +# name of the DLL associated with the specified +# import library ARG. +# Invoked by eval'ing the libtool variable +# $sharedlib_from_linklib_cmd +# Result is available in the variable +# $sharedlib_from_linklib_result +func_cygming_dll_for_implib () +{ + $debug_cmd + + sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"` +} + +# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs +# +# The is the core of a fallback implementation of a +# platform-specific function to extract the name of the +# DLL associated with the specified import library LIBNAME. +# +# SECTION_NAME is either .idata$6 or .idata$7, depending +# on the platform and compiler that created the implib. +# +# Echos the name of the DLL associated with the +# specified import library. +func_cygming_dll_for_implib_fallback_core () +{ + $debug_cmd + + match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"` + $OBJDUMP -s --section "$1" "$2" 2>/dev/null | + $SED '/^Contents of section '"$match_literal"':/{ + # Place marker at beginning of archive member dllname section + s/.*/====MARK====/ + p + d + } + # These lines can sometimes be longer than 43 characters, but + # are always uninteresting + /:[ ]*file format pe[i]\{,1\}-/d + /^In archive [^:]*:/d + # Ensure marker is printed + /^====MARK====/p + # Remove all lines with less than 43 characters + /^.\{43\}/!d + # From remaining lines, remove first 43 characters + s/^.\{43\}//' | + $SED -n ' + # Join marker and all lines until next marker into a single line + /^====MARK====/ b para + H + $ b para + b + :para + x + s/\n//g + # Remove the marker + s/^====MARK====// + # Remove trailing dots and whitespace + s/[\. \t]*$// + # Print + /./p' | + # we now have a list, one entry per line, of the stringified + # contents of the appropriate section of all members of the + # archive that possess that section. Heuristic: eliminate + # all those that have a first or second character that is + # a '.' (that is, objdump's representation of an unprintable + # character.) This should work for all archives with less than + # 0x302f exports -- but will fail for DLLs whose name actually + # begins with a literal '.' or a single character followed by + # a '.'. + # + # Of those that remain, print the first one. + $SED -e '/^\./d;/^.\./d;q' +} + +# func_cygming_dll_for_implib_fallback ARG +# Platform-specific function to extract the +# name of the DLL associated with the specified +# import library ARG. +# +# This fallback implementation is for use when $DLLTOOL +# does not support the --identify-strict option. +# Invoked by eval'ing the libtool variable +# $sharedlib_from_linklib_cmd +# Result is available in the variable +# $sharedlib_from_linklib_result +func_cygming_dll_for_implib_fallback () +{ + $debug_cmd + + if func_cygming_gnu_implib_p "$1"; then + # binutils import library + sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"` + elif func_cygming_ms_implib_p "$1"; then + # ms-generated import library + sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"` + else + # unknown + sharedlib_from_linklib_result= + fi +} + + +# func_extract_an_archive dir oldlib +func_extract_an_archive () +{ + $debug_cmd + + f_ex_an_ar_dir=$1; shift + f_ex_an_ar_oldlib=$1 + if test yes = "$lock_old_archive_extraction"; then + lockfile=$f_ex_an_ar_oldlib.lock + until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do + func_echo "Waiting for $lockfile to be removed" + sleep 2 + done + fi + func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \ + 'stat=$?; rm -f "$lockfile"; exit $stat' + if test yes = "$lock_old_archive_extraction"; then + $opt_dry_run || rm -f "$lockfile" + fi + if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then + : + else + func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" + fi +} + + +# func_extract_archives gentop oldlib ... +func_extract_archives () +{ + $debug_cmd + + my_gentop=$1; shift + my_oldlibs=${1+"$@"} + my_oldobjs= + my_xlib= + my_xabs= + my_xdir= + + for my_xlib in $my_oldlibs; do + # Extract the objects. + case $my_xlib in + [\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;; + *) my_xabs=`pwd`"/$my_xlib" ;; + esac + func_basename "$my_xlib" + my_xlib=$func_basename_result + my_xlib_u=$my_xlib + while :; do + case " $extracted_archives " in + *" $my_xlib_u "*) + func_arith $extracted_serial + 1 + extracted_serial=$func_arith_result + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac + done + extracted_archives="$extracted_archives $my_xlib_u" + my_xdir=$my_gentop/$my_xlib_u + + func_mkdir_p "$my_xdir" + + case $host in + *-darwin*) + func_verbose "Extracting $my_xabs" + # Do not bother doing anything if just a dry run + $opt_dry_run || { + darwin_orig_dir=`pwd` + cd $my_xdir || exit $? + darwin_archive=$my_xabs + darwin_curdir=`pwd` + func_basename "$darwin_archive" + darwin_base_archive=$func_basename_result + darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true` + if test -n "$darwin_arches"; then + darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'` + darwin_arch= + func_verbose "$darwin_base_archive has multiple architectures $darwin_arches" + for darwin_arch in $darwin_arches; do + func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch" + $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive" + cd "unfat-$$/$darwin_base_archive-$darwin_arch" + func_extract_an_archive "`pwd`" "$darwin_base_archive" + cd "$darwin_curdir" + $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" + done # $darwin_arches + ## Okay now we've a bunch of thin objects, gotta fatten them up :) + darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u` + darwin_file= + darwin_files= + for darwin_file in $darwin_filelist; do + darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP` + $LIPO -create -output "$darwin_file" $darwin_files + done # $darwin_filelist + $RM -rf unfat-$$ + cd "$darwin_orig_dir" + else + cd $darwin_orig_dir + func_extract_an_archive "$my_xdir" "$my_xabs" + fi # $darwin_arches + } # !$opt_dry_run + ;; + *) + func_extract_an_archive "$my_xdir" "$my_xabs" + ;; + esac + my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP` + done + + func_extract_archives_result=$my_oldobjs +} + + +# func_emit_wrapper [arg=no] +# +# Emit a libtool wrapper script on stdout. +# Don't directly open a file because we may want to +# incorporate the script contents within a cygwin/mingw +# wrapper executable. Must ONLY be called from within +# func_mode_link because it depends on a number of variables +# set therein. +# +# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR +# variable will take. If 'yes', then the emitted script +# will assume that the directory where it is stored is +# the $objdir directory. This is a cygwin/mingw-specific +# behavior. +func_emit_wrapper () +{ + func_emit_wrapper_arg1=${1-no} + + $ECHO "\ +#! $SHELL + +# $output - temporary wrapper script for $objdir/$outputname +# Generated by $PROGRAM (GNU $PACKAGE) $VERSION +# +# The $output program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='$sed_quote_subst' + +# Be Bourne compatible +if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command=\"$relink_command\" + +# This environment variable determines our operation mode. +if test \"\$libtool_install_magic\" = \"$magic\"; then + # install mode needs the following variables: + generated_by_libtool_version='$macro_version' + notinst_deplibs='$notinst_deplibs' +else + # When we are sourced in execute mode, \$file and \$ECHO are already set. + if test \"\$libtool_execute_magic\" != \"$magic\"; then + file=\"\$0\"" + + qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"` + $ECHO "\ + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$1 +_LTECHO_EOF' +} + ECHO=\"$qECHO\" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ that is used only on +# windows platforms, and (c) all begin with the string "--lt-" +# (application programs are unlikely to have options that match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's $0 value, followed by "$@". +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=\$0 + shift + for lt_opt + do + case \"\$lt_opt\" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\` + test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=. + lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\` + cat \"\$lt_dump_D/\$lt_dump_F\" + exit 0 + ;; + --lt-*) + \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n \"\$lt_option_debug\"; then + echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\" + lt_dump_args_N=\`expr \$lt_dump_args_N + 1\` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ +" + case $host in + # Backslashes separate directories on plain windows + *-*-mingw | *-*-os2* | *-cegcc*) + $ECHO "\ + if test -n \"\$lt_option_debug\"; then + \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2 + func_lt_dump_args \${1+\"\$@\"} 1>&2 + fi + exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} +" + ;; + + *) + $ECHO "\ + if test -n \"\$lt_option_debug\"; then + \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2 + func_lt_dump_args \${1+\"\$@\"} 1>&2 + fi + exec \"\$progdir/\$program\" \${1+\"\$@\"} +" + ;; + esac + $ECHO "\ + \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from \$@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + case \" \$* \" in + *\\ --lt-*) + for lt_wr_arg + do + case \$lt_wr_arg in + --lt-*) ;; + *) set x \"\$@\" \"\$lt_wr_arg\"; shift;; + esac + shift + done ;; + esac + func_exec_program_core \${1+\"\$@\"} +} + + # Parse options + func_parse_lt_options \"\$0\" \${1+\"\$@\"} + + # Find the directory that this script lives in. + thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\` + test \"x\$thisdir\" = \"x\$file\" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\` + while test -n \"\$file\"; do + destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\` + + # If there was a directory component, then change thisdir. + if test \"x\$destdir\" != \"x\$file\"; then + case \"\$destdir\" in + [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; + *) thisdir=\"\$thisdir/\$destdir\" ;; + esac + fi + + file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\` + file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1 + if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then + # special case for '.' + if test \"\$thisdir\" = \".\"; then + thisdir=\`pwd\` + fi + # remove .libs from thisdir + case \"\$thisdir\" in + *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;; + $objdir ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=\`cd \"\$thisdir\" && pwd\` + test -n \"\$absdir\" && thisdir=\"\$absdir\" +" + + if test yes = "$fast_install"; then + $ECHO "\ + program=lt-'$outputname'$exeext + progdir=\"\$thisdir/$objdir\" + + if test ! -f \"\$progdir/\$program\" || + { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\ + test \"X\$file\" != \"X\$progdir/\$program\"; }; then + + file=\"\$\$-\$program\" + + if test ! -d \"\$progdir\"; then + $MKDIR \"\$progdir\" + else + $RM \"\$progdir/\$file\" + fi" + + $ECHO "\ + + # relink executable if necessary + if test -n \"\$relink_command\"; then + if relink_command_output=\`eval \$relink_command 2>&1\`; then : + else + \$ECHO \"\$relink_command_output\" >&2 + $RM \"\$progdir/\$file\" + exit 1 + fi + fi + + $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || + { $RM \"\$progdir/\$program\"; + $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; } + $RM \"\$progdir/\$file\" + fi" + else + $ECHO "\ + program='$outputname' + progdir=\"\$thisdir/$objdir\" +" + fi + + $ECHO "\ + + if test -f \"\$progdir/\$program\"; then" + + # fixup the dll searchpath if we need to. + # + # Fix the DLL searchpath if we need to. Do this before prepending + # to shlibpath, because on Windows, both are PATH and uninstalled + # libraries must come first. + if test -n "$dllsearchpath"; then + $ECHO "\ + # Add the dll search path components to the executable PATH + PATH=$dllsearchpath:\$PATH +" + fi + + # Export our shlibpath_var if we have one. + if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then + $ECHO "\ + # Add our own library path to $shlibpath_var + $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" + + # Some systems cannot cope with colon-terminated $shlibpath_var + # The second colon is a workaround for a bug in BeOS R4 sed + $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\` + + export $shlibpath_var +" + fi + + $ECHO "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then + # Run the actual program with our arguments. + func_exec_program \${1+\"\$@\"} + fi + else + # The program doesn't exist. + \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2 + \$ECHO \"This script is just a wrapper for \$program.\" 1>&2 + \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2 + exit 1 + fi +fi\ +" +} + + +# func_emit_cwrapperexe_src +# emit the source code for a wrapper executable on stdout +# Must ONLY be called from within func_mode_link because +# it depends on a number of variable set therein. +func_emit_cwrapperexe_src () +{ + cat < +#include +#ifdef _MSC_VER +# include +# include +# include +#else +# include +# include +# ifdef __CYGWIN__ +# include +# endif +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) + +/* declarations of non-ANSI functions */ +#if defined __MINGW32__ +# ifdef __STRICT_ANSI__ +int _putenv (const char *); +# endif +#elif defined __CYGWIN__ +# ifdef __STRICT_ANSI__ +char *realpath (const char *, char *); +int putenv (char *); +int setenv (const char *, const char *, int); +# endif +/* #elif defined other_platform || defined ... */ +#endif + +/* portability defines, excluding path handling macros */ +#if defined _MSC_VER +# define setmode _setmode +# define stat _stat +# define chmod _chmod +# define getcwd _getcwd +# define putenv _putenv +# define S_IXUSR _S_IEXEC +#elif defined __MINGW32__ +# define setmode _setmode +# define stat _stat +# define chmod _chmod +# define getcwd _getcwd +# define putenv _putenv +#elif defined __CYGWIN__ +# define HAVE_SETENV +# define FOPEN_WB "wb" +/* #elif defined other platforms ... */ +#endif + +#if defined PATH_MAX +# define LT_PATHMAX PATH_MAX +#elif defined MAXPATHLEN +# define LT_PATHMAX MAXPATHLEN +#else +# define LT_PATHMAX 1024 +#endif + +#ifndef S_IXOTH +# define S_IXOTH 0 +#endif +#ifndef S_IXGRP +# define S_IXGRP 0 +#endif + +/* path handling portability macros */ +#ifndef DIR_SEPARATOR +# define DIR_SEPARATOR '/' +# define PATH_SEPARATOR ':' +#endif + +#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \ + defined __OS2__ +# define HAVE_DOS_BASED_FILE_SYSTEM +# define FOPEN_WB "wb" +# ifndef DIR_SEPARATOR_2 +# define DIR_SEPARATOR_2 '\\' +# endif +# ifndef PATH_SEPARATOR_2 +# define PATH_SEPARATOR_2 ';' +# endif +#endif + +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + +#ifndef PATH_SEPARATOR_2 +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) +#else /* PATH_SEPARATOR_2 */ +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) +#endif /* PATH_SEPARATOR_2 */ + +#ifndef FOPEN_WB +# define FOPEN_WB "w" +#endif +#ifndef _O_BINARY +# define _O_BINARY 0 +#endif + +#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) +#define XFREE(stale) do { \ + if (stale) { free (stale); stale = 0; } \ +} while (0) + +#if defined LT_DEBUGWRAPPER +static int lt_debug = 1; +#else +static int lt_debug = 0; +#endif + +const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */ + +void *xmalloc (size_t num); +char *xstrdup (const char *string); +const char *base_name (const char *name); +char *find_executable (const char *wrapper); +char *chase_symlinks (const char *pathspec); +int make_executable (const char *path); +int check_executable (const char *path); +char *strendzap (char *str, const char *pat); +void lt_debugprintf (const char *file, int line, const char *fmt, ...); +void lt_fatal (const char *file, int line, const char *message, ...); +static const char *nonnull (const char *s); +static const char *nonempty (const char *s); +void lt_setenv (const char *name, const char *value); +char *lt_extend_str (const char *orig_value, const char *add, int to_end); +void lt_update_exe_path (const char *name, const char *value); +void lt_update_lib_path (const char *name, const char *value); +char **prepare_spawn (char **argv); +void lt_dump_script (FILE *f); +EOF + + cat <= 0) + && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) + return 1; + else + return 0; +} + +int +make_executable (const char *path) +{ + int rval = 0; + struct stat st; + + lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n", + nonempty (path)); + if ((!path) || (!*path)) + return 0; + + if (stat (path, &st) >= 0) + { + rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR); + } + return rval; +} + +/* Searches for the full path of the wrapper. Returns + newly allocated full path name if found, NULL otherwise + Does not chase symlinks, even on platforms that support them. +*/ +char * +find_executable (const char *wrapper) +{ + int has_slash = 0; + const char *p; + const char *p_next; + /* static buffer for getcwd */ + char tmp[LT_PATHMAX + 1]; + size_t tmp_len; + char *concat_name; + + lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n", + nonempty (wrapper)); + + if ((wrapper == NULL) || (*wrapper == '\0')) + return NULL; + + /* Absolute path? */ +#if defined HAVE_DOS_BASED_FILE_SYSTEM + if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':') + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + else + { +#endif + if (IS_DIR_SEPARATOR (wrapper[0])) + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } +#if defined HAVE_DOS_BASED_FILE_SYSTEM + } +#endif + + for (p = wrapper; *p; p++) + if (*p == '/') + { + has_slash = 1; + break; + } + if (!has_slash) + { + /* no slashes; search PATH */ + const char *path = getenv ("PATH"); + if (path != NULL) + { + for (p = path; *p; p = p_next) + { + const char *q; + size_t p_len; + for (q = p; *q; q++) + if (IS_PATH_SEPARATOR (*q)) + break; + p_len = (size_t) (q - p); + p_next = (*q == '\0' ? q : q + 1); + if (p_len == 0) + { + /* empty path: current directory */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", + nonnull (strerror (errno))); + tmp_len = strlen (tmp); + concat_name = + XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + } + else + { + concat_name = + XMALLOC (char, p_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, wrapper); + } + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + } + /* not found in PATH; assume curdir */ + } + /* Relative path | not found in path: prepend cwd */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", + nonnull (strerror (errno))); + tmp_len = strlen (tmp); + concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + return NULL; +} + +char * +chase_symlinks (const char *pathspec) +{ +#ifndef S_ISLNK + return xstrdup (pathspec); +#else + char buf[LT_PATHMAX]; + struct stat s; + char *tmp_pathspec = xstrdup (pathspec); + char *p; + int has_symlinks = 0; + while (strlen (tmp_pathspec) && !has_symlinks) + { + lt_debugprintf (__FILE__, __LINE__, + "checking path component for symlinks: %s\n", + tmp_pathspec); + if (lstat (tmp_pathspec, &s) == 0) + { + if (S_ISLNK (s.st_mode) != 0) + { + has_symlinks = 1; + break; + } + + /* search backwards for last DIR_SEPARATOR */ + p = tmp_pathspec + strlen (tmp_pathspec) - 1; + while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + p--; + if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + { + /* no more DIR_SEPARATORS left */ + break; + } + *p = '\0'; + } + else + { + lt_fatal (__FILE__, __LINE__, + "error accessing file \"%s\": %s", + tmp_pathspec, nonnull (strerror (errno))); + } + } + XFREE (tmp_pathspec); + + if (!has_symlinks) + { + return xstrdup (pathspec); + } + + tmp_pathspec = realpath (pathspec, buf); + if (tmp_pathspec == 0) + { + lt_fatal (__FILE__, __LINE__, + "could not follow symlinks for %s", pathspec); + } + return xstrdup (tmp_pathspec); +#endif +} + +char * +strendzap (char *str, const char *pat) +{ + size_t len, patlen; + + assert (str != NULL); + assert (pat != NULL); + + len = strlen (str); + patlen = strlen (pat); + + if (patlen <= len) + { + str += len - patlen; + if (STREQ (str, pat)) + *str = '\0'; + } + return str; +} + +void +lt_debugprintf (const char *file, int line, const char *fmt, ...) +{ + va_list args; + if (lt_debug) + { + (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line); + va_start (args, fmt); + (void) vfprintf (stderr, fmt, args); + va_end (args); + } +} + +static void +lt_error_core (int exit_status, const char *file, + int line, const char *mode, + const char *message, va_list ap) +{ + fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode); + vfprintf (stderr, message, ap); + fprintf (stderr, ".\n"); + + if (exit_status >= 0) + exit (exit_status); +} + +void +lt_fatal (const char *file, int line, const char *message, ...) +{ + va_list ap; + va_start (ap, message); + lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap); + va_end (ap); +} + +static const char * +nonnull (const char *s) +{ + return s ? s : "(null)"; +} + +static const char * +nonempty (const char *s) +{ + return (s && !*s) ? "(empty)" : nonnull (s); +} + +void +lt_setenv (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_setenv) setting '%s' to '%s'\n", + nonnull (name), nonnull (value)); + { +#ifdef HAVE_SETENV + /* always make a copy, for consistency with !HAVE_SETENV */ + char *str = xstrdup (value); + setenv (name, str, 1); +#else + size_t len = strlen (name) + 1 + strlen (value) + 1; + char *str = XMALLOC (char, len); + sprintf (str, "%s=%s", name, value); + if (putenv (str) != EXIT_SUCCESS) + { + XFREE (str); + } +#endif + } +} + +char * +lt_extend_str (const char *orig_value, const char *add, int to_end) +{ + char *new_value; + if (orig_value && *orig_value) + { + size_t orig_value_len = strlen (orig_value); + size_t add_len = strlen (add); + new_value = XMALLOC (char, add_len + orig_value_len + 1); + if (to_end) + { + strcpy (new_value, orig_value); + strcpy (new_value + orig_value_len, add); + } + else + { + strcpy (new_value, add); + strcpy (new_value + add_len, orig_value); + } + } + else + { + new_value = xstrdup (add); + } + return new_value; +} + +void +lt_update_exe_path (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_update_exe_path) modifying '%s' by prepending '%s'\n", + nonnull (name), nonnull (value)); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + /* some systems can't cope with a ':'-terminated path #' */ + size_t len = strlen (new_value); + while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1])) + { + new_value[--len] = '\0'; + } + lt_setenv (name, new_value); + XFREE (new_value); + } +} + +void +lt_update_lib_path (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_update_lib_path) modifying '%s' by prepending '%s'\n", + nonnull (name), nonnull (value)); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + lt_setenv (name, new_value); + XFREE (new_value); + } +} + +EOF + case $host_os in + mingw*) + cat <<"EOF" + +/* Prepares an argument vector before calling spawn(). + Note that spawn() does not by itself call the command interpreter + (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") : + ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&v); + v.dwPlatformId == VER_PLATFORM_WIN32_NT; + }) ? "cmd.exe" : "command.com"). + Instead it simply concatenates the arguments, separated by ' ', and calls + CreateProcess(). We must quote the arguments since Win32 CreateProcess() + interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a + special way: + - Space and tab are interpreted as delimiters. They are not treated as + delimiters if they are surrounded by double quotes: "...". + - Unescaped double quotes are removed from the input. Their only effect is + that within double quotes, space and tab are treated like normal + characters. + - Backslashes not followed by double quotes are not special. + - But 2*n+1 backslashes followed by a double quote become + n backslashes followed by a double quote (n >= 0): + \" -> " + \\\" -> \" + \\\\\" -> \\" + */ +#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" +#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" +char ** +prepare_spawn (char **argv) +{ + size_t argc; + char **new_argv; + size_t i; + + /* Count number of arguments. */ + for (argc = 0; argv[argc] != NULL; argc++) + ; + + /* Allocate new argument vector. */ + new_argv = XMALLOC (char *, argc + 1); + + /* Put quoted arguments into the new argument vector. */ + for (i = 0; i < argc; i++) + { + const char *string = argv[i]; + + if (string[0] == '\0') + new_argv[i] = xstrdup ("\"\""); + else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL) + { + int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL); + size_t length; + unsigned int backslashes; + const char *s; + char *quoted_string; + char *p; + + length = 0; + backslashes = 0; + if (quote_around) + length++; + for (s = string; *s != '\0'; s++) + { + char c = *s; + if (c == '"') + length += backslashes + 1; + length++; + if (c == '\\') + backslashes++; + else + backslashes = 0; + } + if (quote_around) + length += backslashes + 1; + + quoted_string = XMALLOC (char, length + 1); + + p = quoted_string; + backslashes = 0; + if (quote_around) + *p++ = '"'; + for (s = string; *s != '\0'; s++) + { + char c = *s; + if (c == '"') + { + unsigned int j; + for (j = backslashes + 1; j > 0; j--) + *p++ = '\\'; + } + *p++ = c; + if (c == '\\') + backslashes++; + else + backslashes = 0; + } + if (quote_around) + { + unsigned int j; + for (j = backslashes; j > 0; j--) + *p++ = '\\'; + *p++ = '"'; + } + *p = '\0'; + + new_argv[i] = quoted_string; + } + else + new_argv[i] = (char *) string; + } + new_argv[argc] = NULL; + + return new_argv; +} +EOF + ;; + esac + + cat <<"EOF" +void lt_dump_script (FILE* f) +{ +EOF + func_emit_wrapper yes | + $SED -n -e ' +s/^\(.\{79\}\)\(..*\)/\1\ +\2/ +h +s/\([\\"]\)/\\\1/g +s/$/\\n/ +s/\([^\n]*\).*/ fputs ("\1", f);/p +g +D' + cat <<"EOF" +} +EOF +} +# end: func_emit_cwrapperexe_src + +# func_win32_import_lib_p ARG +# True if ARG is an import lib, as indicated by $file_magic_cmd +func_win32_import_lib_p () +{ + $debug_cmd + + case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in + *import*) : ;; + *) false ;; + esac +} + +# func_suncc_cstd_abi +# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!! +# Several compiler flags select an ABI that is incompatible with the +# Cstd library. Avoid specifying it if any are in CXXFLAGS. +func_suncc_cstd_abi () +{ + $debug_cmd + + case " $compile_command " in + *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*) + suncc_use_cstd_abi=no + ;; + *) + suncc_use_cstd_abi=yes + ;; + esac +} + +# func_mode_link arg... +func_mode_link () +{ + $debug_cmd + + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + # It is impossible to link a dll without this setting, and + # we shouldn't force the makefile maintainer to figure out + # what system we are compiling for in order to pass an extra + # flag for every libtool invocation. + # allow_undefined=no + + # FIXME: Unfortunately, there are problems with the above when trying + # to make a dll that has undefined symbols, in which case not + # even a static library is built. For now, we need to specify + # -no-undefined on the libtool link line when we can be certain + # that all symbols are satisfied, otherwise we get a static library. + allow_undefined=yes + ;; + *) + allow_undefined=yes + ;; + esac + libtool_args=$nonopt + base_compile="$nonopt $@" + compile_command=$nonopt + finalize_command=$nonopt + + compile_rpath= + finalize_rpath= + compile_shlibpath= + finalize_shlibpath= + convenience= + old_convenience= + deplibs= + old_deplibs= + compiler_flags= + linker_flags= + dllsearchpath= + lib_search_path=`pwd` + inst_prefix_dir= + new_inherited_linker_flags= + + avoid_version=no + bindir= + dlfiles= + dlprefiles= + dlself=no + export_dynamic=no + export_symbols= + export_symbols_regex= + generated= + libobjs= + ltlibs= + module=no + no_install=no + objs= + os2dllname= + non_pic_objects= + precious_files_regex= + prefer_static_libs=no + preload=false + prev= + prevarg= + release= + rpath= + xrpath= + perm_rpath= + temp_rpath= + thread_safe=no + vinfo= + vinfo_number=no + weak_libs= + single_module=$wl-single_module + func_infer_tag $base_compile + + # We need to know -static, to get the right output filenames. + for arg + do + case $arg in + -shared) + test yes != "$build_libtool_libs" \ + && func_fatal_configuration "cannot build a shared library" + build_old_libs=no + break + ;; + -all-static | -static | -static-libtool-libs) + case $arg in + -all-static) + if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then + func_warning "complete static linking is impossible in this configuration" + fi + if test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + -static) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=built + ;; + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac + build_libtool_libs=no + build_old_libs=yes + break + ;; + esac + done + + # See if our shared archives depend on static archives. + test -n "$old_archive_from_new_cmds" && build_old_libs=yes + + # Go through the arguments, transforming them on the way. + while test "$#" -gt 0; do + arg=$1 + shift + func_quote_for_eval "$arg" + qarg=$func_quote_for_eval_unquoted_result + func_append libtool_args " $func_quote_for_eval_result" + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + output) + func_append compile_command " @OUTPUT@" + func_append finalize_command " @OUTPUT@" + ;; + esac + + case $prev in + bindir) + bindir=$arg + prev= + continue + ;; + dlfiles|dlprefiles) + $preload || { + # Add the symbol object into the linking commands. + func_append compile_command " @SYMFILE@" + func_append finalize_command " @SYMFILE@" + preload=: + } + case $arg in + *.la | *.lo) ;; # We handle these cases below. + force) + if test no = "$dlself"; then + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + self) + if test dlprefiles = "$prev"; then + dlself=yes + elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then + dlself=yes + else + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + *) + if test dlfiles = "$prev"; then + func_append dlfiles " $arg" + else + func_append dlprefiles " $arg" + fi + prev= + continue + ;; + esac + ;; + expsyms) + export_symbols=$arg + test -f "$arg" \ + || func_fatal_error "symbol file '$arg' does not exist" + prev= + continue + ;; + expsyms_regex) + export_symbols_regex=$arg + prev= + continue + ;; + framework) + case $host in + *-*-darwin*) + case "$deplibs " in + *" $qarg.ltframework "*) ;; + *) func_append deplibs " $qarg.ltframework" # this is fixed later + ;; + esac + ;; + esac + prev= + continue + ;; + inst_prefix) + inst_prefix_dir=$arg + prev= + continue + ;; + mllvm) + # Clang does not use LLVM to link, so we can simply discard any + # '-mllvm $arg' options when doing the link step. + prev= + continue + ;; + objectlist) + if test -f "$arg"; then + save_arg=$arg + moreargs= + for fil in `cat "$save_arg"` + do +# func_append moreargs " $fil" + arg=$fil + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test none = "$pic_object" && + test none = "$non_pic_object"; then + func_fatal_error "cannot find name of object for '$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + if test none != "$pic_object"; then + # Prepend the subdirectory the object is found in. + pic_object=$xdir$pic_object + + if test dlfiles = "$prev"; then + if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then + func_append dlfiles " $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test dlprefiles = "$prev"; then + # Preload the old-style object. + func_append dlprefiles " $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg=$pic_object + fi + + # Non-PIC object. + if test none != "$non_pic_object"; then + # Prepend the subdirectory the object is found in. + non_pic_object=$xdir$non_pic_object + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test none = "$pic_object"; then + arg=$non_pic_object + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object=$pic_object + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "'$arg' is not a valid libtool object" + fi + fi + done + else + func_fatal_error "link input file '$arg' does not exist" + fi + arg=$save_arg + prev= + continue + ;; + os2dllname) + os2dllname=$arg + prev= + continue + ;; + precious_regex) + precious_files_regex=$arg + prev= + continue + ;; + release) + release=-$arg + prev= + continue + ;; + rpath | xrpath) + # We need an absolute path. + case $arg in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + if test rpath = "$prev"; then + case "$rpath " in + *" $arg "*) ;; + *) func_append rpath " $arg" ;; + esac + else + case "$xrpath " in + *" $arg "*) ;; + *) func_append xrpath " $arg" ;; + esac + fi + prev= + continue + ;; + shrext) + shrext_cmds=$arg + prev= + continue + ;; + weak) + func_append weak_libs " $arg" + prev= + continue + ;; + xcclinker) + func_append linker_flags " $qarg" + func_append compiler_flags " $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xcompiler) + func_append compiler_flags " $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xlinker) + func_append linker_flags " $qarg" + func_append compiler_flags " $wl$qarg" + prev= + func_append compile_command " $wl$qarg" + func_append finalize_command " $wl$qarg" + continue + ;; + *) + eval "$prev=\"\$arg\"" + prev= + continue + ;; + esac + fi # test -n "$prev" + + prevarg=$arg + + case $arg in + -all-static) + if test -n "$link_static_flag"; then + # See comment for -static flag below, for more details. + func_append compile_command " $link_static_flag" + func_append finalize_command " $link_static_flag" + fi + continue + ;; + + -allow-undefined) + # FIXME: remove this flag sometime in the future. + func_fatal_error "'-allow-undefined' must not be used because it is the default" + ;; + + -avoid-version) + avoid_version=yes + continue + ;; + + -bindir) + prev=bindir + continue + ;; + + -dlopen) + prev=dlfiles + continue + ;; + + -dlpreopen) + prev=dlprefiles + continue + ;; + + -export-dynamic) + export_dynamic=yes + continue + ;; + + -export-symbols | -export-symbols-regex) + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + func_fatal_error "more than one -exported-symbols argument is not allowed" + fi + if test X-export-symbols = "X$arg"; then + prev=expsyms + else + prev=expsyms_regex + fi + continue + ;; + + -framework) + prev=framework + continue + ;; + + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* + # so, if we see these flags be careful not to treat them like -L + -L[A-Z][A-Z]*:*) + case $with_gcc/$host in + no/*-*-irix* | /*-*-irix*) + func_append compile_command " $arg" + func_append finalize_command " $arg" + ;; + esac + continue + ;; + + -L*) + func_stripname "-L" '' "$arg" + if test -z "$func_stripname_result"; then + if test "$#" -gt 0; then + func_fatal_error "require no space between '-L' and '$1'" + else + func_fatal_error "need path for '-L' option" + fi + fi + func_resolve_sysroot "$func_stripname_result" + dir=$func_resolve_sysroot_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + absdir=`cd "$dir" && pwd` + test -z "$absdir" && \ + func_fatal_error "cannot determine absolute directory name of '$dir'" + dir=$absdir + ;; + esac + case "$deplibs " in + *" -L$dir "* | *" $arg "*) + # Will only happen for absolute or sysroot arguments + ;; + *) + # Preserve sysroot, but never include relative directories + case $dir in + [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;; + *) func_append deplibs " -L$dir" ;; + esac + func_append lib_search_path " $dir" + ;; + esac + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$dir:"*) ;; + ::) dllsearchpath=$dir;; + *) func_append dllsearchpath ":$dir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) func_append dllsearchpath ":$testbindir";; + esac + ;; + esac + continue + ;; + + -l*) + if test X-lc = "X$arg" || test X-lm = "X$arg"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) + # These systems don't actually have a C or math library (as such) + continue + ;; + *-*-os2*) + # These systems don't actually have a C library (as such) + test X-lc = "X$arg" && continue + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + # Do not include libc due to us having libc/libc_r. + test X-lc = "X$arg" && continue + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C and math libraries are in the System framework + func_append deplibs " System.ltframework" + continue + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + test X-lc = "X$arg" && continue + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + test X-lc = "X$arg" && continue + ;; + esac + elif test X-lc_r = "X$arg"; then + case $host in + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + # Do not include libc_r directly, use -pthread flag. + continue + ;; + esac + fi + func_append deplibs " $arg" + continue + ;; + + -mllvm) + prev=mllvm + continue + ;; + + -module) + module=yes + continue + ;; + + # Tru64 UNIX uses -model [arg] to determine the layout of C++ + # classes, name mangling, and exception handling. + # Darwin uses the -arch flag to determine output architecture. + -model|-arch|-isysroot|--sysroot) + func_append compiler_flags " $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + prev=xcompiler + continue + ;; + + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + func_append compiler_flags " $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + case "$new_inherited_linker_flags " in + *" $arg "*) ;; + * ) func_append new_inherited_linker_flags " $arg" ;; + esac + continue + ;; + + -multi_module) + single_module=$wl-multi_module + continue + ;; + + -no-fast-install) + fast_install=no + continue + ;; + + -no-install) + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) + # The PATH hackery in wrapper scripts is required on Windows + # and Darwin in order for the loader to find any dlls it needs. + func_warning "'-no-install' is ignored for $host" + func_warning "assuming '-no-fast-install' instead" + fast_install=no + ;; + *) no_install=yes ;; + esac + continue + ;; + + -no-undefined) + allow_undefined=no + continue + ;; + + -objectlist) + prev=objectlist + continue + ;; + + -os2dllname) + prev=os2dllname + continue + ;; + + -o) prev=output ;; + + -precious-files-regex) + prev=precious_regex + continue + ;; + + -release) + prev=release + continue + ;; + + -rpath) + prev=rpath + continue + ;; + + -R) + prev=xrpath + continue + ;; + + -R*) + func_stripname '-R' '' "$arg" + dir=$func_stripname_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + =*) + func_stripname '=' '' "$dir" + dir=$lt_sysroot$func_stripname_result + ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + case "$xrpath " in + *" $dir "*) ;; + *) func_append xrpath " $dir" ;; + esac + continue + ;; + + -shared) + # The effects of -shared are defined in a previous loop. + continue + ;; + + -shrext) + prev=shrext + continue + ;; + + -static | -static-libtool-libs) + # The effects of -static are defined in a previous loop. + # We used to do the same as -all-static on platforms that + # didn't have a PIC flag, but the assumption that the effects + # would be equivalent was wrong. It would break on at least + # Digital Unix and AIX. + continue + ;; + + -thread-safe) + thread_safe=yes + continue + ;; + + -version-info) + prev=vinfo + continue + ;; + + -version-number) + prev=vinfo + vinfo_number=yes + continue + ;; + + -weak) + prev=weak + continue + ;; + + -Wc,*) + func_stripname '-Wc,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs=$IFS; IFS=, + for flag in $args; do + IFS=$save_ifs + func_quote_for_eval "$flag" + func_append arg " $func_quote_for_eval_result" + func_append compiler_flags " $func_quote_for_eval_result" + done + IFS=$save_ifs + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Wl,*) + func_stripname '-Wl,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs=$IFS; IFS=, + for flag in $args; do + IFS=$save_ifs + func_quote_for_eval "$flag" + func_append arg " $wl$func_quote_for_eval_result" + func_append compiler_flags " $wl$func_quote_for_eval_result" + func_append linker_flags " $func_quote_for_eval_result" + done + IFS=$save_ifs + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Xcompiler) + prev=xcompiler + continue + ;; + + -Xlinker) + prev=xlinker + continue + ;; + + -XCClinker) + prev=xcclinker + continue + ;; + + # -msg_* for osf cc + -msg_*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + + # Flags to be passed through unchanged, with rationale: + # -64, -mips[0-9] enable 64-bit mode for the SGI compiler + # -r[0-9][0-9]* specify processor for the SGI compiler + # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler + # +DA*, +DD* enable 64-bit mode for the HP compiler + # -q* compiler args for the IBM compiler + # -m*, -t[45]*, -txscale* architecture-specific flags for GCC + # -F/path path to uninstalled frameworks, gcc on darwin + # -p, -pg, --coverage, -fprofile-* profiling flags for GCC + # -fstack-protector* stack protector flags for GCC + # @file GCC response files + # -tp=* Portland pgcc target processor selection + # --sysroot=* for sysroot support + # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -stdlib=* select c++ std lib with clang + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + func_append compile_command " $arg" + func_append finalize_command " $arg" + func_append compiler_flags " $arg" + continue + ;; + + -Z*) + if test os2 = "`expr $host : '.*\(os2\)'`"; then + # OS/2 uses -Zxxx to specify OS/2-specific options + compiler_flags="$compiler_flags $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + case $arg in + -Zlinker | -Zstack) + prev=xcompiler + ;; + esac + continue + else + # Otherwise treat like 'Some other compiler flag' below + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + fi + ;; + + # Some other compiler flag. + -* | +*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + + *.$objext) + # A standard object. + func_append objs " $arg" + ;; + + *.lo) + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test none = "$pic_object" && + test none = "$non_pic_object"; then + func_fatal_error "cannot find name of object for '$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + test none = "$pic_object" || { + # Prepend the subdirectory the object is found in. + pic_object=$xdir$pic_object + + if test dlfiles = "$prev"; then + if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then + func_append dlfiles " $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test dlprefiles = "$prev"; then + # Preload the old-style object. + func_append dlprefiles " $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg=$pic_object + } + + # Non-PIC object. + if test none != "$non_pic_object"; then + # Prepend the subdirectory the object is found in. + non_pic_object=$xdir$non_pic_object + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test none = "$pic_object"; then + arg=$non_pic_object + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object=$pic_object + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "'$arg' is not a valid libtool object" + fi + fi + ;; + + *.$libext) + # An archive. + func_append deplibs " $arg" + func_append old_deplibs " $arg" + continue + ;; + + *.la) + # A libtool-controlled library. + + func_resolve_sysroot "$arg" + if test dlfiles = "$prev"; then + # This library was specified with -dlopen. + func_append dlfiles " $func_resolve_sysroot_result" + prev= + elif test dlprefiles = "$prev"; then + # The library was specified with -dlpreopen. + func_append dlprefiles " $func_resolve_sysroot_result" + prev= + else + func_append deplibs " $func_resolve_sysroot_result" + fi + continue + ;; + + # Some other compiler argument. + *) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + esac # arg + + # Now actually substitute the argument into the commands. + if test -n "$arg"; then + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + done # argument parsing loop + + test -n "$prev" && \ + func_fatal_help "the '$prevarg' option requires an argument" + + if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then + eval arg=\"$export_dynamic_flag_spec\" + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + + oldlibs= + # calculate the name of the file, without its directory + func_basename "$output" + outputname=$func_basename_result + libobjs_save=$libobjs + + if test -n "$shlibpath_var"; then + # get the directories listed in $shlibpath_var + eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\` + else + shlib_search_path= + fi + eval sys_lib_search_path=\"$sys_lib_search_path_spec\" + eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" + + # Definition is injected by LT_CONFIG during libtool generation. + func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH" + + func_dirname "$output" "/" "" + output_objdir=$func_dirname_result$objdir + func_to_tool_file "$output_objdir/" + tool_output_objdir=$func_to_tool_file_result + # Create the object directory. + func_mkdir_p "$output_objdir" + + # Determine the type of output + case $output in + "") + func_fatal_help "you must specify an output file" + ;; + *.$libext) linkmode=oldlib ;; + *.lo | *.$objext) linkmode=obj ;; + *.la) linkmode=lib ;; + *) linkmode=prog ;; # Anything else should be a program. + esac + + specialdeplibs= + + libs= + # Find all interdependent deplibs by searching for libraries + # that are linked more than once (e.g. -la -lb -la) + for deplib in $deplibs; do + if $opt_preserve_dup_deps; then + case "$libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append libs " $deplib" + done + + if test lib = "$linkmode"; then + libs="$predeps $libs $compiler_lib_search_path $postdeps" + + # Compute libraries that are listed more than once in $predeps + # $postdeps and mark them as special (i.e., whose duplicates are + # not to be eliminated). + pre_post_deps= + if $opt_duplicate_compiler_generated_deps; then + for pre_post_dep in $predeps $postdeps; do + case "$pre_post_deps " in + *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;; + esac + func_append pre_post_deps " $pre_post_dep" + done + fi + pre_post_deps= + fi + + deplibs= + newdependency_libs= + newlib_search_path= + need_relink=no # whether we're linking any uninstalled libtool libraries + notinst_deplibs= # not-installed libtool libraries + notinst_path= # paths that contain not-installed libtool libraries + + case $linkmode in + lib) + passes="conv dlpreopen link" + for file in $dlfiles $dlprefiles; do + case $file in + *.la) ;; + *) + func_fatal_help "libraries can '-dlopen' only libtool libraries: $file" + ;; + esac + done + ;; + prog) + compile_deplibs= + finalize_deplibs= + alldeplibs=false + newdlfiles= + newdlprefiles= + passes="conv scan dlopen dlpreopen link" + ;; + *) passes="conv" + ;; + esac + + for pass in $passes; do + # The preopen pass in lib mode reverses $deplibs; put it back here + # so that -L comes before libs that need it for instance... + if test lib,link = "$linkmode,$pass"; then + ## FIXME: Find the place where the list is rebuilt in the wrong + ## order, and fix it there properly + tmp_deplibs= + for deplib in $deplibs; do + tmp_deplibs="$deplib $tmp_deplibs" + done + deplibs=$tmp_deplibs + fi + + if test lib,link = "$linkmode,$pass" || + test prog,scan = "$linkmode,$pass"; then + libs=$deplibs + deplibs= + fi + if test prog = "$linkmode"; then + case $pass in + dlopen) libs=$dlfiles ;; + dlpreopen) libs=$dlprefiles ;; + link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + esac + fi + if test lib,dlpreopen = "$linkmode,$pass"; then + # Collect and forward deplibs of preopened libtool libs + for lib in $dlprefiles; do + # Ignore non-libtool-libs + dependency_libs= + func_resolve_sysroot "$lib" + case $lib in + *.la) func_source "$func_resolve_sysroot_result" ;; + esac + + # Collect preopened libtool deplibs, except any this library + # has declared as weak libs + for deplib in $dependency_libs; do + func_basename "$deplib" + deplib_base=$func_basename_result + case " $weak_libs " in + *" $deplib_base "*) ;; + *) func_append deplibs " $deplib" ;; + esac + done + done + libs=$dlprefiles + fi + if test dlopen = "$pass"; then + # Collect dlpreopened libraries + save_deplibs=$deplibs + deplibs= + fi + + for deplib in $libs; do + lib= + found=false + case $deplib in + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + func_append compiler_flags " $deplib" + if test lib = "$linkmode"; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) func_append new_inherited_linker_flags " $deplib" ;; + esac + fi + fi + continue + ;; + -l*) + if test lib != "$linkmode" && test prog != "$linkmode"; then + func_warning "'-l' is ignored for archives/objects" + continue + fi + func_stripname '-l' '' "$deplib" + name=$func_stripname_result + if test lib = "$linkmode"; then + searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" + else + searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" + fi + for searchdir in $searchdirs; do + for search_ext in .la $std_shrext .so .a; do + # Search the libtool library + lib=$searchdir/lib$name$search_ext + if test -f "$lib"; then + if test .la = "$search_ext"; then + found=: + else + found=false + fi + break 2 + fi + done + done + if $found; then + # deplib is a libtool library + # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, + # We need to do some special things here, and not later. + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + case " $predeps $postdeps " in + *" $deplib "*) + if func_lalib_p "$lib"; then + library_names= + old_library= + func_source "$lib" + for l in $old_library $library_names; do + ll=$l + done + if test "X$ll" = "X$old_library"; then # only static version available + found=false + func_dirname "$lib" "" "." + ladir=$func_dirname_result + lib=$ladir/$old_library + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + fi + ;; + *) ;; + esac + fi + else + # deplib doesn't seem to be a libtool library + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + ;; # -l + *.ltframework) + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + if test lib = "$linkmode"; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) func_append new_inherited_linker_flags " $deplib" ;; + esac + fi + fi + continue + ;; + -L*) + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test conv = "$pass" && continue + newdependency_libs="$deplib $newdependency_libs" + func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + prog) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + continue + fi + if test scan = "$pass"; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + *) + func_warning "'-L' is ignored for archives/objects" + ;; + esac # linkmode + continue + ;; # -L + -R*) + if test link = "$pass"; then + func_stripname '-R' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + dir=$func_resolve_sysroot_result + # Make sure the xrpath contains only unique directories. + case "$xrpath " in + *" $dir "*) ;; + *) func_append xrpath " $dir" ;; + esac + fi + deplibs="$deplib $deplibs" + continue + ;; + *.la) + func_resolve_sysroot "$deplib" + lib=$func_resolve_sysroot_result + ;; + *.$libext) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + continue + fi + case $linkmode in + lib) + # Linking convenience modules into shared libraries is allowed, + # but linking other static libraries is non-portable. + case " $dlpreconveniencelibs " in + *" $deplib "*) ;; + *) + valid_a_lib=false + case $deplibs_check_method in + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + valid_a_lib=: + fi + ;; + pass_all) + valid_a_lib=: + ;; + esac + if $valid_a_lib; then + echo + $ECHO "*** Warning: Linking the shared library $output against the" + $ECHO "*** static library $deplib is not portable!" + deplibs="$deplib $deplibs" + else + echo + $ECHO "*** Warning: Trying to link with static lib archive $deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because the file extensions .$libext of this argument makes me believe" + echo "*** that it is just a static archive that I should not use here." + fi + ;; + esac + continue + ;; + prog) + if test link != "$pass"; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + continue + ;; + esac # linkmode + ;; # *.$libext + *.lo | *.$objext) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + elif test prog = "$linkmode"; then + if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then + # If there is no dlopen support or we're linking statically, + # we need to preload. + func_append newdlprefiles " $deplib" + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + func_append newdlfiles " $deplib" + fi + fi + continue + ;; + %DEPLIBS%) + alldeplibs=: + continue + ;; + esac # case $deplib + + $found || test -f "$lib" \ + || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'" + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$lib" \ + || func_fatal_error "'$lib' is not a valid libtool archive" + + func_dirname "$lib" "" "." + ladir=$func_dirname_result + + dlname= + dlopen= + dlpreopen= + libdir= + library_names= + old_library= + inherited_linker_flags= + # If the library was installed with an old release of libtool, + # it will not redefine variables installed, or shouldnotlink + installed=yes + shouldnotlink=no + avoidtemprpath= + + + # Read the .la file + func_source "$lib" + + # Convert "-framework foo" to "foo.ltframework" + if test -n "$inherited_linker_flags"; then + tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'` + for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do + case " $new_inherited_linker_flags " in + *" $tmp_inherited_linker_flag "*) ;; + *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";; + esac + done + fi + dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + if test lib,link = "$linkmode,$pass" || + test prog,scan = "$linkmode,$pass" || + { test prog != "$linkmode" && test lib != "$linkmode"; }; then + test -n "$dlopen" && func_append dlfiles " $dlopen" + test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen" + fi + + if test conv = "$pass"; then + # Only check for convenience libraries + deplibs="$lib $deplibs" + if test -z "$libdir"; then + if test -z "$old_library"; then + func_fatal_error "cannot find name of link library for '$lib'" + fi + # It is a libtool convenience library, so add in its objects. + func_append convenience " $ladir/$objdir/$old_library" + func_append old_convenience " $ladir/$objdir/$old_library" + elif test prog != "$linkmode" && test lib != "$linkmode"; then + func_fatal_error "'$lib' is not a convenience library" + fi + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done + continue + fi # $pass = conv + + + # Get the name of the library we link against. + linklib= + if test -n "$old_library" && + { test yes = "$prefer_static_libs" || + test built,no = "$prefer_static_libs,$installed"; }; then + linklib=$old_library + else + for l in $old_library $library_names; do + linklib=$l + done + fi + if test -z "$linklib"; then + func_fatal_error "cannot find name of link library for '$lib'" + fi + + # This library was specified with -dlopen. + if test dlopen = "$pass"; then + test -z "$libdir" \ + && func_fatal_error "cannot -dlopen a convenience library: '$lib'" + if test -z "$dlname" || + test yes != "$dlopen_support" || + test no = "$build_libtool_libs" + then + # If there is no dlname, no dlopen support or we're linking + # statically, we need to preload. We also need to preload any + # dependent libraries so libltdl's deplib preloader doesn't + # bomb out in the load deplibs phase. + func_append dlprefiles " $lib $dependency_libs" + else + func_append newdlfiles " $lib" + fi + continue + fi # $pass = dlopen + + # We need an absolute path. + case $ladir in + [\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;; + *) + abs_ladir=`cd "$ladir" && pwd` + if test -z "$abs_ladir"; then + func_warning "cannot determine absolute directory name of '$ladir'" + func_warning "passing it literally to the linker, although it might fail" + abs_ladir=$ladir + fi + ;; + esac + func_basename "$lib" + laname=$func_basename_result + + # Find the relevant object directory and library name. + if test yes = "$installed"; then + if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then + func_warning "library '$lib' was moved." + dir=$ladir + absdir=$abs_ladir + libdir=$abs_ladir + else + dir=$lt_sysroot$libdir + absdir=$lt_sysroot$libdir + fi + test yes = "$hardcode_automatic" && avoidtemprpath=yes + else + if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then + dir=$ladir + absdir=$abs_ladir + # Remove this search path later + func_append notinst_path " $abs_ladir" + else + dir=$ladir/$objdir + absdir=$abs_ladir/$objdir + # Remove this search path later + func_append notinst_path " $abs_ladir" + fi + fi # $installed = yes + func_stripname 'lib' '.la' "$laname" + name=$func_stripname_result + + # This library was specified with -dlpreopen. + if test dlpreopen = "$pass"; then + if test -z "$libdir" && test prog = "$linkmode"; then + func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'" + fi + case $host in + # special handling for platforms with PE-DLLs. + *cygwin* | *mingw* | *cegcc* ) + # Linker will automatically link against shared library if both + # static and shared are present. Therefore, ensure we extract + # symbols from the import library if a shared library is present + # (otherwise, the dlopen module name will be incorrect). We do + # this by putting the import library name into $newdlprefiles. + # We recover the dlopen module name by 'saving' the la file + # name in a special purpose variable, and (later) extracting the + # dlname from the la file. + if test -n "$dlname"; then + func_tr_sh "$dir/$linklib" + eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname" + func_append newdlprefiles " $dir/$linklib" + else + func_append newdlprefiles " $dir/$old_library" + # Keep a list of preopened convenience libraries to check + # that they are being used correctly in the link pass. + test -z "$libdir" && \ + func_append dlpreconveniencelibs " $dir/$old_library" + fi + ;; + * ) + # Prefer using a static library (so that no silly _DYNAMIC symbols + # are required to link). + if test -n "$old_library"; then + func_append newdlprefiles " $dir/$old_library" + # Keep a list of preopened convenience libraries to check + # that they are being used correctly in the link pass. + test -z "$libdir" && \ + func_append dlpreconveniencelibs " $dir/$old_library" + # Otherwise, use the dlname, so that lt_dlopen finds it. + elif test -n "$dlname"; then + func_append newdlprefiles " $dir/$dlname" + else + func_append newdlprefiles " $dir/$linklib" + fi + ;; + esac + fi # $pass = dlpreopen + + if test -z "$libdir"; then + # Link the convenience library + if test lib = "$linkmode"; then + deplibs="$dir/$old_library $deplibs" + elif test prog,link = "$linkmode,$pass"; then + compile_deplibs="$dir/$old_library $compile_deplibs" + finalize_deplibs="$dir/$old_library $finalize_deplibs" + else + deplibs="$lib $deplibs" # used for prog,scan pass + fi + continue + fi + + + if test prog = "$linkmode" && test link != "$pass"; then + func_append newlib_search_path " $ladir" + deplibs="$lib $deplibs" + + linkalldeplibs=false + if test no != "$link_all_deplibs" || test -z "$library_names" || + test no = "$build_libtool_libs"; then + linkalldeplibs=: + fi + + tmp_libs= + for deplib in $dependency_libs; do + case $deplib in + -L*) func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + esac + # Need to link against all dependency_libs? + if $linkalldeplibs; then + deplibs="$deplib $deplibs" + else + # Need to hardcode shared library paths + # or/and link against static libraries + newdependency_libs="$deplib $newdependency_libs" + fi + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done # for deplib + continue + fi # $linkmode = prog... + + if test prog,link = "$linkmode,$pass"; then + if test -n "$library_names" && + { { test no = "$prefer_static_libs" || + test built,yes = "$prefer_static_libs,$installed"; } || + test -z "$old_library"; }; then + # We need to hardcode the library path + if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then + # Make sure the rpath contains only unique directories. + case $temp_rpath: in + *"$absdir:"*) ;; + *) func_append temp_rpath "$absdir:" ;; + esac + fi + + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) func_append compile_rpath " $absdir" ;; + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + ;; + esac + fi # $linkmode,$pass = prog,link... + + if $alldeplibs && + { test pass_all = "$deplibs_check_method" || + { test yes = "$build_libtool_libs" && + test -n "$library_names"; }; }; then + # We only need to search for static libraries + continue + fi + fi + + link_static=no # Whether the deplib will be linked statically + use_static_libs=$prefer_static_libs + if test built = "$use_static_libs" && test yes = "$installed"; then + use_static_libs=no + fi + if test -n "$library_names" && + { test no = "$use_static_libs" || test -z "$old_library"; }; then + case $host in + *cygwin* | *mingw* | *cegcc* | *os2*) + # No point in relinking DLLs because paths are not encoded + func_append notinst_deplibs " $lib" + need_relink=no + ;; + *) + if test no = "$installed"; then + func_append notinst_deplibs " $lib" + need_relink=yes + fi + ;; + esac + # This is a shared library + + # Warn about portability, can't link against -module's on some + # systems (darwin). Don't bleat about dlopened modules though! + dlopenmodule= + for dlpremoduletest in $dlprefiles; do + if test "X$dlpremoduletest" = "X$lib"; then + dlopenmodule=$dlpremoduletest + break + fi + done + if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then + echo + if test prog = "$linkmode"; then + $ECHO "*** Warning: Linking the executable $output against the loadable module" + else + $ECHO "*** Warning: Linking the shared library $output against the loadable module" + fi + $ECHO "*** $linklib is not portable!" + fi + if test lib = "$linkmode" && + test yes = "$hardcode_into_libs"; then + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) func_append compile_rpath " $absdir" ;; + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + ;; + esac + fi + + if test -n "$old_archive_from_expsyms_cmds"; then + # figure out the soname + set dummy $library_names + shift + realname=$1 + shift + libname=`eval "\\$ECHO \"$libname_spec\""` + # use dlname if we got it. it's perfectly good, no? + if test -n "$dlname"; then + soname=$dlname + elif test -n "$soname_spec"; then + # bleh windows + case $host in + *cygwin* | mingw* | *cegcc* | *os2*) + func_arith $current - $age + major=$func_arith_result + versuffix=-$major + ;; + esac + eval soname=\"$soname_spec\" + else + soname=$realname + fi + + # Make a new name for the extract_expsyms_cmds to use + soroot=$soname + func_basename "$soroot" + soname=$func_basename_result + func_stripname 'lib' '.dll' "$soname" + newlib=libimp-$func_stripname_result.a + + # If the library has no export list, then create one now + if test -f "$output_objdir/$soname-def"; then : + else + func_verbose "extracting exported symbol list from '$soname'" + func_execute_cmds "$extract_expsyms_cmds" 'exit $?' + fi + + # Create $newlib + if test -f "$output_objdir/$newlib"; then :; else + func_verbose "generating import library for '$soname'" + func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?' + fi + # make sure the library variables are pointing to the new library + dir=$output_objdir + linklib=$newlib + fi # test -n "$old_archive_from_expsyms_cmds" + + if test prog = "$linkmode" || test relink != "$opt_mode"; then + add_shlibpath= + add_dir= + add= + lib_linked=yes + case $hardcode_action in + immediate | unsupported) + if test no = "$hardcode_direct"; then + add=$dir/$linklib + case $host in + *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;; + *-*-sysv4*uw2*) add_dir=-L$dir ;; + *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ + *-*-unixware7*) add_dir=-L$dir ;; + *-*-darwin* ) + # if the lib is a (non-dlopened) module then we cannot + # link against it, someone is ignoring the earlier warnings + if /usr/bin/file -L $add 2> /dev/null | + $GREP ": [^:]* bundle" >/dev/null; then + if test "X$dlopenmodule" != "X$lib"; then + $ECHO "*** Warning: lib $linklib is a module, not a shared library" + if test -z "$old_library"; then + echo + echo "*** And there doesn't seem to be a static archive available" + echo "*** The link will probably fail, sorry" + else + add=$dir/$old_library + fi + elif test -n "$old_library"; then + add=$dir/$old_library + fi + fi + esac + elif test no = "$hardcode_minus_L"; then + case $host in + *-*-sunos*) add_shlibpath=$dir ;; + esac + add_dir=-L$dir + add=-l$name + elif test no = "$hardcode_shlibpath_var"; then + add_shlibpath=$dir + add=-l$name + else + lib_linked=no + fi + ;; + relink) + if test yes = "$hardcode_direct" && + test no = "$hardcode_direct_absolute"; then + add=$dir/$linklib + elif test yes = "$hardcode_minus_L"; then + add_dir=-L$absdir + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + func_append add_dir " -L$inst_prefix_dir$libdir" + ;; + esac + fi + add=-l$name + elif test yes = "$hardcode_shlibpath_var"; then + add_shlibpath=$dir + add=-l$name + else + lib_linked=no + fi + ;; + *) lib_linked=no ;; + esac + + if test yes != "$lib_linked"; then + func_fatal_configuration "unsupported hardcode properties" + fi + + if test -n "$add_shlibpath"; then + case :$compile_shlibpath: in + *":$add_shlibpath:"*) ;; + *) func_append compile_shlibpath "$add_shlibpath:" ;; + esac + fi + if test prog = "$linkmode"; then + test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" + test -n "$add" && compile_deplibs="$add $compile_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + if test yes != "$hardcode_direct" && + test yes != "$hardcode_minus_L" && + test yes = "$hardcode_shlibpath_var"; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) func_append finalize_shlibpath "$libdir:" ;; + esac + fi + fi + fi + + if test prog = "$linkmode" || test relink = "$opt_mode"; then + add_shlibpath= + add_dir= + add= + # Finalize command for both is simple: just hardcode it. + if test yes = "$hardcode_direct" && + test no = "$hardcode_direct_absolute"; then + add=$libdir/$linklib + elif test yes = "$hardcode_minus_L"; then + add_dir=-L$libdir + add=-l$name + elif test yes = "$hardcode_shlibpath_var"; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) func_append finalize_shlibpath "$libdir:" ;; + esac + add=-l$name + elif test yes = "$hardcode_automatic"; then + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib"; then + add=$inst_prefix_dir$libdir/$linklib + else + add=$libdir/$linklib + fi + else + # We cannot seem to hardcode it, guess we'll fake it. + add_dir=-L$libdir + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + func_append add_dir " -L$inst_prefix_dir$libdir" + ;; + esac + fi + add=-l$name + fi + + if test prog = "$linkmode"; then + test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" + test -n "$add" && finalize_deplibs="$add $finalize_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + fi + fi + elif test prog = "$linkmode"; then + # Here we assume that one of hardcode_direct or hardcode_minus_L + # is not unsupported. This is valid on all known static and + # shared platforms. + if test unsupported != "$hardcode_direct"; then + test -n "$old_library" && linklib=$old_library + compile_deplibs="$dir/$linklib $compile_deplibs" + finalize_deplibs="$dir/$linklib $finalize_deplibs" + else + compile_deplibs="-l$name -L$dir $compile_deplibs" + finalize_deplibs="-l$name -L$dir $finalize_deplibs" + fi + elif test yes = "$build_libtool_libs"; then + # Not a shared library + if test pass_all != "$deplibs_check_method"; then + # We're trying link a shared library against a static one + # but the system doesn't support it. + + # Just print a warning and add the library to dependency_libs so + # that the program can be linked against the static library. + echo + $ECHO "*** Warning: This system cannot link to static lib archive $lib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have." + if test yes = "$module"; then + echo "*** But as you try to build a module library, libtool will still create " + echo "*** a static module, that should work as long as the dlopening application" + echo "*** is linked with the -dlopen flag to resolve symbols at runtime." + if test -z "$global_symbol_pipe"; then + echo + echo "*** However, this would only work if libtool was able to extract symbol" + echo "*** lists from a program, using 'nm' or equivalent, but libtool could" + echo "*** not find such a program. So, this module is probably useless." + echo "*** 'nm' from GNU binutils and a full rebuild may help." + fi + if test no = "$build_old_libs"; then + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + else + deplibs="$dir/$old_library $deplibs" + link_static=yes + fi + fi # link shared/static library? + + if test lib = "$linkmode"; then + if test -n "$dependency_libs" && + { test yes != "$hardcode_into_libs" || + test yes = "$build_old_libs" || + test yes = "$link_static"; }; then + # Extract -R from dependency_libs + temp_deplibs= + for libdir in $dependency_libs; do + case $libdir in + -R*) func_stripname '-R' '' "$libdir" + temp_xrpath=$func_stripname_result + case " $xrpath " in + *" $temp_xrpath "*) ;; + *) func_append xrpath " $temp_xrpath";; + esac;; + *) func_append temp_deplibs " $libdir";; + esac + done + dependency_libs=$temp_deplibs + fi + + func_append newlib_search_path " $absdir" + # Link against this library + test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs" + # ... and its dependency_libs + tmp_libs= + for deplib in $dependency_libs; do + newdependency_libs="$deplib $newdependency_libs" + case $deplib in + -L*) func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result";; + *) func_resolve_sysroot "$deplib" ;; + esac + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $func_resolve_sysroot_result "*) + func_append specialdeplibs " $func_resolve_sysroot_result" ;; + esac + fi + func_append tmp_libs " $func_resolve_sysroot_result" + done + + if test no != "$link_all_deplibs"; then + # Add the search paths of all dependency libraries + for deplib in $dependency_libs; do + path= + case $deplib in + -L*) path=$deplib ;; + *.la) + func_resolve_sysroot "$deplib" + deplib=$func_resolve_sysroot_result + func_dirname "$deplib" "" "." + dir=$func_dirname_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + func_warning "cannot determine absolute directory name of '$dir'" + absdir=$dir + fi + ;; + esac + if $GREP "^installed=no" $deplib > /dev/null; then + case $host in + *-*-darwin*) + depdepl= + eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + if test -n "$deplibrary_names"; then + for tmp in $deplibrary_names; do + depdepl=$tmp + done + if test -f "$absdir/$objdir/$depdepl"; then + depdepl=$absdir/$objdir/$depdepl + darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + if test -z "$darwin_install_name"; then + darwin_install_name=`$OTOOL64 -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + fi + func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl" + func_append linker_flags " -dylib_file $darwin_install_name:$depdepl" + path= + fi + fi + ;; + *) + path=-L$absdir/$objdir + ;; + esac + else + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + test -z "$libdir" && \ + func_fatal_error "'$deplib' is not a valid libtool archive" + test "$absdir" != "$libdir" && \ + func_warning "'$deplib' seems to be moved" + + path=-L$absdir + fi + ;; + esac + case " $deplibs " in + *" $path "*) ;; + *) deplibs="$path $deplibs" ;; + esac + done + fi # link_all_deplibs != no + fi # linkmode = lib + done # for deplib in $libs + if test link = "$pass"; then + if test prog = "$linkmode"; then + compile_deplibs="$new_inherited_linker_flags $compile_deplibs" + finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs" + else + compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + fi + fi + dependency_libs=$newdependency_libs + if test dlpreopen = "$pass"; then + # Link the dlpreopened libraries before other libraries + for deplib in $save_deplibs; do + deplibs="$deplib $deplibs" + done + fi + if test dlopen != "$pass"; then + test conv = "$pass" || { + # Make sure lib_search_path contains only unique directories. + lib_search_path= + for dir in $newlib_search_path; do + case "$lib_search_path " in + *" $dir "*) ;; + *) func_append lib_search_path " $dir" ;; + esac + done + newlib_search_path= + } + + if test prog,link = "$linkmode,$pass"; then + vars="compile_deplibs finalize_deplibs" + else + vars=deplibs + fi + for var in $vars dependency_libs; do + # Add libraries to $var in reverse order + eval tmp_libs=\"\$$var\" + new_libs= + for deplib in $tmp_libs; do + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: + #new_libs="$deplib $new_libs" + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; + *) + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; + esac + done + tmp_libs= + for deplib in $new_libs; do + case $deplib in + -L*) + case " $tmp_libs " in + *" $deplib "*) ;; + *) func_append tmp_libs " $deplib" ;; + esac + ;; + *) func_append tmp_libs " $deplib" ;; + esac + done + eval $var=\"$tmp_libs\" + done # for var + fi + + # Add Sun CC postdeps if required: + test CXX = "$tagname" && { + case $host_os in + linux*) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C++ 5.9 + func_suncc_cstd_abi + + if test no != "$suncc_use_cstd_abi"; then + func_append postdeps ' -library=Cstd -library=Crun' + fi + ;; + esac + ;; + + solaris*) + func_cc_basename "$CC" + case $func_cc_basename_result in + CC* | sunCC*) + func_suncc_cstd_abi + + if test no != "$suncc_use_cstd_abi"; then + func_append postdeps ' -library=Cstd -library=Crun' + fi + ;; + esac + ;; + esac + } + + # Last step: remove runtime libs from dependency_libs + # (they stay in deplibs) + tmp_libs= + for i in $dependency_libs; do + case " $predeps $postdeps $compiler_lib_search_path " in + *" $i "*) + i= + ;; + esac + if test -n "$i"; then + func_append tmp_libs " $i" + fi + done + dependency_libs=$tmp_libs + done # for pass + if test prog = "$linkmode"; then + dlfiles=$newdlfiles + fi + if test prog = "$linkmode" || test lib = "$linkmode"; then + dlprefiles=$newdlprefiles + fi + + case $linkmode in + oldlib) + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + func_warning "'-dlopen' is ignored for archives" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "'-l' and '-L' are ignored for archives" ;; + esac + + test -n "$rpath" && \ + func_warning "'-rpath' is ignored for archives" + + test -n "$xrpath" && \ + func_warning "'-R' is ignored for archives" + + test -n "$vinfo" && \ + func_warning "'-version-info/-version-number' is ignored for archives" + + test -n "$release" && \ + func_warning "'-release' is ignored for archives" + + test -n "$export_symbols$export_symbols_regex" && \ + func_warning "'-export-symbols' is ignored for archives" + + # Now set the variables for building old libraries. + build_libtool_libs=no + oldlibs=$output + func_append objs "$old_deplibs" + ;; + + lib) + # Make sure we only generate libraries of the form 'libNAME.la'. + case $outputname in + lib*) + func_stripname 'lib' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + ;; + *) + test no = "$module" \ + && func_fatal_help "libtool library '$output' must begin with 'lib'" + + if test no != "$need_lib_prefix"; then + # Add the "lib" prefix for modules if required + func_stripname '' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + else + func_stripname '' '.la' "$outputname" + libname=$func_stripname_result + fi + ;; + esac + + if test -n "$objs"; then + if test pass_all != "$deplibs_check_method"; then + func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs" + else + echo + $ECHO "*** Warning: Linking the shared library $output against the non-libtool" + $ECHO "*** objects $objs is not portable!" + func_append libobjs " $objs" + fi + fi + + test no = "$dlself" \ + || func_warning "'-dlopen self' is ignored for libtool libraries" + + set dummy $rpath + shift + test 1 -lt "$#" \ + && func_warning "ignoring multiple '-rpath's for a libtool library" + + install_libdir=$1 + + oldlibs= + if test -z "$rpath"; then + if test yes = "$build_libtool_libs"; then + # Building a libtool convenience library. + # Some compilers have problems with a '.al' extension so + # convenience libraries should have the same extension an + # archive normally would. + oldlibs="$output_objdir/$libname.$libext $oldlibs" + build_libtool_libs=convenience + build_old_libs=yes + fi + + test -n "$vinfo" && \ + func_warning "'-version-info/-version-number' is ignored for convenience libraries" + + test -n "$release" && \ + func_warning "'-release' is ignored for convenience libraries" + else + + # Parse the version information argument. + save_ifs=$IFS; IFS=: + set dummy $vinfo 0 0 0 + shift + IFS=$save_ifs + + test -n "$7" && \ + func_fatal_help "too many parameters to '-version-info'" + + # convert absolute version numbers to libtool ages + # this retains compatibility with .la files and attempts + # to make the code below a bit more comprehensible + + case $vinfo_number in + yes) + number_major=$1 + number_minor=$2 + number_revision=$3 + # + # There are really only two kinds -- those that + # use the current revision as the major version + # and those that subtract age and use age as + # a minor version. But, then there is irix + # that has an extra 1 added just for fun + # + case $version_type in + # correct linux to gnu/linux during the next big refactor + darwin|freebsd-elf|linux|osf|windows|none) + func_arith $number_major + $number_minor + current=$func_arith_result + age=$number_minor + revision=$number_revision + ;; + freebsd-aout|qnx|sunos) + current=$number_major + revision=$number_minor + age=0 + ;; + irix|nonstopux) + func_arith $number_major + $number_minor + current=$func_arith_result + age=$number_minor + revision=$number_minor + lt_irix_increment=no + ;; + esac + ;; + no) + current=$1 + revision=$2 + age=$3 + ;; + esac + + # Check that each of the things are valid numbers. + case $current in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "CURRENT '$current' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + case $revision in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "REVISION '$revision' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + case $age in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "AGE '$age' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + if test "$age" -gt "$current"; then + func_error "AGE '$age' is greater than the current interface number '$current'" + func_fatal_error "'$vinfo' is not valid version information" + fi + + # Calculate the version variables. + major= + versuffix= + verstring= + case $version_type in + none) ;; + + darwin) + # Like Linux, but with the current version available in + # verstring for coding it into the library header + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + # Darwin ld doesn't like 0 for these options... + func_arith $current + 1 + minor_current=$func_arith_result + xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + # On Darwin other compilers + case $CC in + nagfor*) + verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision" + ;; + *) + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + ;; + esac + ;; + + freebsd-aout) + major=.$current + versuffix=.$current.$revision + ;; + + freebsd-elf) + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + ;; + + irix | nonstopux) + if test no = "$lt_irix_increment"; then + func_arith $current - $age + else + func_arith $current - $age + 1 + fi + major=$func_arith_result + + case $version_type in + nonstopux) verstring_prefix=nonstopux ;; + *) verstring_prefix=sgi ;; + esac + verstring=$verstring_prefix$major.$revision + + # Add in all the interfaces that we are compatible with. + loop=$revision + while test 0 -ne "$loop"; do + func_arith $revision - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring=$verstring_prefix$major.$iface:$verstring + done + + # Before this point, $major must not contain '.'. + major=.$major + versuffix=$major.$revision + ;; + + linux) # correct to gnu/linux during the next big refactor + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + ;; + + osf) + func_arith $current - $age + major=.$func_arith_result + versuffix=.$current.$age.$revision + verstring=$current.$age.$revision + + # Add in all the interfaces that we are compatible with. + loop=$age + while test 0 -ne "$loop"; do + func_arith $current - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring=$verstring:$iface.0 + done + + # Make executables depend on our current version. + func_append verstring ":$current.0" + ;; + + qnx) + major=.$current + versuffix=.$current + ;; + + sco) + major=.$current + versuffix=.$current + ;; + + sunos) + major=.$current + versuffix=.$current.$revision + ;; + + windows) + # Use '-' rather than '.', since we only want one + # extension on DOS 8.3 file systems. + func_arith $current - $age + major=$func_arith_result + versuffix=-$major + ;; + + *) + func_fatal_configuration "unknown library version type '$version_type'" + ;; + esac + + # Clear the version info if we defaulted, and they specified a release. + if test -z "$vinfo" && test -n "$release"; then + major= + case $version_type in + darwin) + # we can't check for "0.0" in archive_cmds due to quoting + # problems, so we reset it completely + verstring= + ;; + *) + verstring=0.0 + ;; + esac + if test no = "$need_version"; then + versuffix= + else + versuffix=.0.0 + fi + fi + + # Remove version info from name if versioning should be avoided + if test yes,no = "$avoid_version,$need_version"; then + major= + versuffix= + verstring= + fi + + # Check to see if the archive will have undefined symbols. + if test yes = "$allow_undefined"; then + if test unsupported = "$allow_undefined_flag"; then + if test yes = "$build_old_libs"; then + func_warning "undefined symbols not allowed in $host shared libraries; building static only" + build_libtool_libs=no + else + func_fatal_error "can't build $host shared library unless -no-undefined is specified" + fi + fi + else + # Don't allow undefined symbols. + allow_undefined_flag=$no_undefined_flag + fi + + fi + + func_generate_dlsyms "$libname" "$libname" : + func_append libobjs " $symfileobj" + test " " = "$libobjs" && libobjs= + + if test relink != "$opt_mode"; then + # Remove our outputs, but don't remove object files since they + # may have been created when compiling PIC objects. + removelist= + tempremovelist=`$ECHO "$output_objdir/*"` + for p in $tempremovelist; do + case $p in + *.$objext | *.gcno) + ;; + $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*) + if test -n "$precious_files_regex"; then + if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 + then + continue + fi + fi + func_append removelist " $p" + ;; + *) ;; + esac + done + test -n "$removelist" && \ + func_show_eval "${RM}r \$removelist" + fi + + # Now set the variables for building old libraries. + if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then + func_append oldlibs " $output_objdir/$libname.$libext" + + # Transform .lo files to .o files. + oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP` + fi + + # Eliminate all temporary directories. + #for path in $notinst_path; do + # lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"` + # deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"` + # dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"` + #done + + if test -n "$xrpath"; then + # If the user specified any rpath flags, then add them. + temp_xrpath= + for libdir in $xrpath; do + func_replace_sysroot "$libdir" + func_append temp_xrpath " -R$func_replace_sysroot_result" + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + done + if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then + dependency_libs="$temp_xrpath $dependency_libs" + fi + fi + + # Make sure dlfiles contains only unique files that won't be dlpreopened + old_dlfiles=$dlfiles + dlfiles= + for lib in $old_dlfiles; do + case " $dlprefiles $dlfiles " in + *" $lib "*) ;; + *) func_append dlfiles " $lib" ;; + esac + done + + # Make sure dlprefiles contains only unique files + old_dlprefiles=$dlprefiles + dlprefiles= + for lib in $old_dlprefiles; do + case "$dlprefiles " in + *" $lib "*) ;; + *) func_append dlprefiles " $lib" ;; + esac + done + + if test yes = "$build_libtool_libs"; then + if test -n "$rpath"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) + # these systems don't actually have a c library (as such)! + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C library is in the System framework + func_append deplibs " System.ltframework" + ;; + *-*-netbsd*) + # Don't link with libc until the a.out ld.so is fixed. + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + ;; + *) + # Add libc to deplibs on all other systems if necessary. + if test yes = "$build_libtool_need_lc"; then + func_append deplibs " -lc" + fi + ;; + esac + fi + + # Transform deplibs into only deplibs that can be linked in shared. + name_save=$name + libname_save=$libname + release_save=$release + versuffix_save=$versuffix + major_save=$major + # I'm not sure if I'm treating the release correctly. I think + # release should show up in the -l (ie -lgmp5) so we don't want to + # add it in twice. Is that correct? + release= + versuffix= + major= + newdeplibs= + droppeddeps=no + case $deplibs_check_method in + pass_all) + # Don't check for shared/static. Everything works. + # This might be a little naive. We might want to check + # whether the library exists or not. But this is on + # osf3 & osf4 and I'm not really sure... Just + # implementing what was already the behavior. + newdeplibs=$deplibs + ;; + test_compile) + # This code stresses the "libraries are programs" paradigm to its + # limits. Maybe even breaks it. We compile a program, linking it + # against the deplibs as a proxy for the library. Then we can check + # whether they linked in statically or dynamically with ldd. + $opt_dry_run || $RM conftest.c + cat > conftest.c </dev/null` + $nocaseglob + else + potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null` + fi + for potent_lib in $potential_libs; do + # Follow soft links. + if ls -lLd "$potent_lib" 2>/dev/null | + $GREP " -> " >/dev/null; then + continue + fi + # The statement above tries to avoid entering an + # endless loop below, in case of cyclic links. + # We might still enter an endless loop, since a link + # loop can be closed while we follow links, + # but so what? + potlib=$potent_lib + while test -h "$potlib" 2>/dev/null; do + potliblink=`ls -ld $potlib | $SED 's/.* -> //'` + case $potliblink in + [\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;; + *) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";; + esac + done + if eval $file_magic_cmd \"\$potlib\" 2>/dev/null | + $SED -e 10q | + $EGREP "$file_magic_regex" > /dev/null; then + func_append newdeplibs " $a_deplib" + a_deplib= + break 2 + fi + done + done + fi + if test -n "$a_deplib"; then + droppeddeps=yes + echo + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib"; then + $ECHO "*** with $libname but no candidates were found. (...for file magic test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a file magic. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + func_append newdeplibs " $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + for a_deplib in $deplibs; do + case $a_deplib in + -l*) + func_stripname -l '' "$a_deplib" + name=$func_stripname_result + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + case " $predeps $postdeps " in + *" $a_deplib "*) + func_append newdeplibs " $a_deplib" + a_deplib= + ;; + esac + fi + if test -n "$a_deplib"; then + libname=`eval "\\$ECHO \"$libname_spec\""` + for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do + potential_libs=`ls $i/$libname[.-]* 2>/dev/null` + for potent_lib in $potential_libs; do + potlib=$potent_lib # see symlink-check above in file_magic test + if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \ + $EGREP "$match_pattern_regex" > /dev/null; then + func_append newdeplibs " $a_deplib" + a_deplib= + break 2 + fi + done + done + fi + if test -n "$a_deplib"; then + droppeddeps=yes + echo + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib"; then + $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a regex pattern. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + func_append newdeplibs " $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + none | unknown | *) + newdeplibs= + tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'` + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + for i in $predeps $postdeps; do + # can't use Xsed below, because $i might contain '/' + tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"` + done + fi + case $tmp_deplibs in + *[!\ \ ]*) + echo + if test none = "$deplibs_check_method"; then + echo "*** Warning: inter-library dependencies are not supported in this platform." + else + echo "*** Warning: inter-library dependencies are not known to be supported." + fi + echo "*** All declared inter-library dependencies are being dropped." + droppeddeps=yes + ;; + esac + ;; + esac + versuffix=$versuffix_save + major=$major_save + release=$release_save + libname=$libname_save + name=$name_save + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library with the System framework + newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'` + ;; + esac + + if test yes = "$droppeddeps"; then + if test yes = "$module"; then + echo + echo "*** Warning: libtool could not satisfy all declared inter-library" + $ECHO "*** dependencies of module $libname. Therefore, libtool will create" + echo "*** a static module, that should work as long as the dlopening" + echo "*** application is linked with the -dlopen flag." + if test -z "$global_symbol_pipe"; then + echo + echo "*** However, this would only work if libtool was able to extract symbol" + echo "*** lists from a program, using 'nm' or equivalent, but libtool could" + echo "*** not find such a program. So, this module is probably useless." + echo "*** 'nm' from GNU binutils and a full rebuild may help." + fi + if test no = "$build_old_libs"; then + oldlibs=$output_objdir/$libname.$libext + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + else + echo "*** The inter-library dependencies that have been dropped here will be" + echo "*** automatically added whenever a program is linked with this library" + echo "*** or is declared to -dlopen it." + + if test no = "$allow_undefined"; then + echo + echo "*** Since this library must not contain undefined symbols," + echo "*** because either the platform does not support them or" + echo "*** it was explicitly requested with -no-undefined," + echo "*** libtool will only create a static version of it." + if test no = "$build_old_libs"; then + oldlibs=$output_objdir/$libname.$libext + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + fi + fi + # Done checking deplibs! + deplibs=$newdeplibs + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + case $host in + *-*-darwin*) + newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $deplibs " in + *" -L$path/$objdir "*) + func_append new_libs " -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) func_append new_libs " $deplib" ;; + esac + ;; + *) func_append new_libs " $deplib" ;; + esac + done + deplibs=$new_libs + + # All the library-specific variables (install_libdir is set above). + library_names= + old_library= + dlname= + + # Test again, we may have decided not to build it any more + if test yes = "$build_libtool_libs"; then + # Remove $wl instances when linking with ld. + # FIXME: should test the right _cmds variable. + case $archive_cmds in + *\$LD\ *) wl= ;; + esac + if test yes = "$hardcode_into_libs"; then + # Hardcode the library paths + hardcode_libdirs= + dep_rpath= + rpath=$finalize_rpath + test relink = "$opt_mode" || rpath=$compile_rpath$rpath + for libdir in $rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + func_replace_sysroot "$libdir" + libdir=$func_replace_sysroot_result + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append dep_rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) func_append perm_rpath " $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval "dep_rpath=\"$hardcode_libdir_flag_spec\"" + fi + if test -n "$runpath_var" && test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + func_append rpath "$dir:" + done + eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" + fi + test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" + fi + + shlibpath=$finalize_shlibpath + test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath + if test -n "$shlibpath"; then + eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" + fi + + # Get the real and link names of the library. + eval shared_ext=\"$shrext_cmds\" + eval library_names=\"$library_names_spec\" + set dummy $library_names + shift + realname=$1 + shift + + if test -n "$soname_spec"; then + eval soname=\"$soname_spec\" + else + soname=$realname + fi + if test -z "$dlname"; then + dlname=$soname + fi + + lib=$output_objdir/$realname + linknames= + for link + do + func_append linknames " $link" + done + + # Use standard objects if they are pic + test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP` + test "X$libobjs" = "X " && libobjs= + + delfiles= + if test -n "$export_symbols" && test -n "$include_expsyms"; then + $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp" + export_symbols=$output_objdir/$libname.uexp + func_append delfiles " $export_symbols" + fi + + orig_export_symbols= + case $host_os in + cygwin* | mingw* | cegcc*) + if test -n "$export_symbols" && test -z "$export_symbols_regex"; then + # exporting using user supplied symfile + func_dll_def_p "$export_symbols" || { + # and it's NOT already a .def file. Must figure out + # which of the given symbols are data symbols and tag + # them as such. So, trigger use of export_symbols_cmds. + # export_symbols gets reassigned inside the "prepare + # the list of exported symbols" if statement, so the + # include_expsyms logic still works. + orig_export_symbols=$export_symbols + export_symbols= + always_export_symbols=yes + } + fi + ;; + esac + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then + func_verbose "generating symbol list for '$libname.la'" + export_symbols=$output_objdir/$libname.exp + $opt_dry_run || $RM $export_symbols + cmds=$export_symbols_cmds + save_ifs=$IFS; IFS='~' + for cmd1 in $cmds; do + IFS=$save_ifs + # Take the normal branch if the nm_file_list_spec branch + # doesn't work or if tool conversion is not needed. + case $nm_file_list_spec~$to_tool_file_cmd in + *~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*) + try_normal_branch=yes + eval cmd=\"$cmd1\" + func_len " $cmd" + len=$func_len_result + ;; + *) + try_normal_branch=no + ;; + esac + if test yes = "$try_normal_branch" \ + && { test "$len" -lt "$max_cmd_len" \ + || test "$max_cmd_len" -le -1; } + then + func_show_eval "$cmd" 'exit $?' + skipped_export=false + elif test -n "$nm_file_list_spec"; then + func_basename "$output" + output_la=$func_basename_result + save_libobjs=$libobjs + save_output=$output + output=$output_objdir/$output_la.nm + func_to_tool_file "$output" + libobjs=$nm_file_list_spec$func_to_tool_file_result + func_append delfiles " $output" + func_verbose "creating $NM input file list: $output" + for obj in $save_libobjs; do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" + done > "$output" + eval cmd=\"$cmd1\" + func_show_eval "$cmd" 'exit $?' + output=$save_output + libobjs=$save_libobjs + skipped_export=false + else + # The command line is too long to execute in one step. + func_verbose "using reloadable object file for export list..." + skipped_export=: + # Break out early, otherwise skipped_export may be + # set to false by a later but shorter cmd. + break + fi + done + IFS=$save_ifs + if test -n "$export_symbols_regex" && test : != "$skipped_export"; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + fi + + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols=$export_symbols + test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols + $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' + fi + + if test : != "$skipped_export" && test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for '$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands, which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + func_append delfiles " $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + + tmp_deplibs= + for test_deplib in $deplibs; do + case " $convenience " in + *" $test_deplib "*) ;; + *) + func_append tmp_deplibs " $test_deplib" + ;; + esac + done + deplibs=$tmp_deplibs + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec" && + test yes = "$compiler_needs_object" && + test -z "$libobjs"; then + # extract the archives, so we have objects to list. + # TODO: could optimize this to just extract one archive. + whole_archive_flag_spec= + fi + if test -n "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + else + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $convenience + func_append libobjs " $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + fi + + if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then + eval flag=\"$thread_safe_flag_spec\" + func_append linker_flags " $flag" + fi + + # Make a backup of the uninstalled library when relinking + if test relink = "$opt_mode"; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $? + fi + + # Do each of the archive commands. + if test yes = "$module" && test -n "$module_cmds"; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + eval test_cmds=\"$module_expsym_cmds\" + cmds=$module_expsym_cmds + else + eval test_cmds=\"$module_cmds\" + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + eval test_cmds=\"$archive_expsym_cmds\" + cmds=$archive_expsym_cmds + else + eval test_cmds=\"$archive_cmds\" + cmds=$archive_cmds + fi + fi + + if test : != "$skipped_export" && + func_len " $test_cmds" && + len=$func_len_result && + test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + : + else + # The command line is too long to link in one step, link piecewise + # or, if using GNU ld and skipped_export is not :, use a linker + # script. + + # Save the value of $output and $libobjs because we want to + # use them later. If we have whole_archive_flag_spec, we + # want to use save_libobjs as it was before + # whole_archive_flag_spec was expanded, because we can't + # assume the linker understands whole_archive_flag_spec. + # This may have to be revisited, in case too many + # convenience libraries get linked in and end up exceeding + # the spec. + if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + fi + save_output=$output + func_basename "$output" + output_la=$func_basename_result + + # Clear the reloadable object creation command queue and + # initialize k to one. + test_cmds= + concat_cmds= + objlist= + last_robj= + k=1 + + if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then + output=$output_objdir/$output_la.lnkscript + func_verbose "creating GNU ld script: $output" + echo 'INPUT (' > $output + for obj in $save_libobjs + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" >> $output + done + echo ')' >> $output + func_append delfiles " $output" + func_to_tool_file "$output" + output=$func_to_tool_file_result + elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then + output=$output_objdir/$output_la.lnk + func_verbose "creating linker input file list: $output" + : > $output + set x $save_libobjs + shift + firstobj= + if test yes = "$compiler_needs_object"; then + firstobj="$1 " + shift + fi + for obj + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" >> $output + done + func_append delfiles " $output" + func_to_tool_file "$output" + output=$firstobj\"$file_list_spec$func_to_tool_file_result\" + else + if test -n "$save_libobjs"; then + func_verbose "creating reloadable object files..." + output=$output_objdir/$output_la-$k.$objext + eval test_cmds=\"$reload_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + + # Loop over the list of objects to be linked. + for obj in $save_libobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + if test -z "$objlist" || + test "$len" -lt "$max_cmd_len"; then + func_append objlist " $obj" + else + # The command $test_cmds is almost too long, add a + # command to the queue. + if test 1 -eq "$k"; then + # The first file doesn't have a previous command to add. + reload_objs=$objlist + eval concat_cmds=\"$reload_cmds\" + else + # All subsequent reloadable object files will link in + # the last one created. + reload_objs="$objlist $last_robj" + eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\" + fi + last_robj=$output_objdir/$output_la-$k.$objext + func_arith $k + 1 + k=$func_arith_result + output=$output_objdir/$output_la-$k.$objext + objlist=" $obj" + func_len " $last_robj" + func_arith $len0 + $func_len_result + len=$func_arith_result + fi + done + # Handle the remaining objects by creating one last + # reloadable object file. All subsequent reloadable object + # files will link in the last one created. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + reload_objs="$objlist $last_robj" + eval concat_cmds=\"\$concat_cmds$reload_cmds\" + if test -n "$last_robj"; then + eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" + fi + func_append delfiles " $output" + + else + output= + fi + + ${skipped_export-false} && { + func_verbose "generating symbol list for '$libname.la'" + export_symbols=$output_objdir/$libname.exp + $opt_dry_run || $RM $export_symbols + libobjs=$output + # Append the command to create the export file. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\" + if test -n "$last_robj"; then + eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" + fi + } + + test -n "$save_libobjs" && + func_verbose "creating a temporary reloadable object file: $output" + + # Loop through the commands generated above and execute them. + save_ifs=$IFS; IFS='~' + for cmd in $concat_cmds; do + IFS=$save_ifs + $opt_quiet || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS=$save_ifs + + if test -n "$export_symbols_regex" && ${skipped_export-false}; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + + ${skipped_export-false} && { + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols=$export_symbols + test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols + $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' + fi + + if test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for '$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands, which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + func_append delfiles " $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + } + + libobjs=$output + # Restore the value of output. + output=$save_output + + if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + fi + # Expand the library linking commands again to reset the + # value of $libobjs for piecewise linking. + + # Do each of the archive commands. + if test yes = "$module" && test -n "$module_cmds"; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + cmds=$module_expsym_cmds + else + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + cmds=$archive_expsym_cmds + else + cmds=$archive_cmds + fi + fi + fi + + if test -n "$delfiles"; then + # Append the command to remove temporary files to $cmds. + eval cmds=\"\$cmds~\$RM $delfiles\" + fi + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $dlprefiles + func_append libobjs " $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + + save_ifs=$IFS; IFS='~' + for cmd in $cmds; do + IFS=$sp$nl + eval cmd=\"$cmd\" + IFS=$save_ifs + $opt_quiet || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS=$save_ifs + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $? + + if test -n "$convenience"; then + if test -z "$whole_archive_flag_spec"; then + func_show_eval '${RM}r "$gentop"' + fi + fi + + exit $EXIT_SUCCESS + fi + + # Create links to the real library. + for linkname in $linknames; do + if test "$realname" != "$linkname"; then + func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?' + fi + done + + # If -module or -export-dynamic was specified, set the dlname. + if test yes = "$module" || test yes = "$export_dynamic"; then + # On all known operating systems, these are identical. + dlname=$soname + fi + fi + ;; + + obj) + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + func_warning "'-dlopen' is ignored for objects" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "'-l' and '-L' are ignored for objects" ;; + esac + + test -n "$rpath" && \ + func_warning "'-rpath' is ignored for objects" + + test -n "$xrpath" && \ + func_warning "'-R' is ignored for objects" + + test -n "$vinfo" && \ + func_warning "'-version-info' is ignored for objects" + + test -n "$release" && \ + func_warning "'-release' is ignored for objects" + + case $output in + *.lo) + test -n "$objs$old_deplibs" && \ + func_fatal_error "cannot build library object '$output' from non-libtool objects" + + libobj=$output + func_lo2o "$libobj" + obj=$func_lo2o_result + ;; + *) + libobj= + obj=$output + ;; + esac + + # Delete the old objects. + $opt_dry_run || $RM $obj $libobj + + # Objects from convenience libraries. This assumes + # single-version convenience libraries. Whenever we create + # different ones for PIC/non-PIC, this we'll have to duplicate + # the extraction. + reload_conv_objs= + gentop= + # if reload_cmds runs $LD directly, get rid of -Wl from + # whole_archive_flag_spec and hope we can get by with turning comma + # into space. + case $reload_cmds in + *\$LD[\ \$]*) wl= ;; + esac + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" + test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'` + reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags + else + gentop=$output_objdir/${obj}x + func_append generated " $gentop" + + func_extract_archives $gentop $convenience + reload_conv_objs="$reload_objs $func_extract_archives_result" + fi + fi + + # If we're not building shared, we need to use non_pic_objs + test yes = "$build_libtool_libs" || libobjs=$non_pic_objects + + # Create the old-style object. + reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs + + output=$obj + func_execute_cmds "$reload_cmds" 'exit $?' + + # Exit if we aren't doing a library object file. + if test -z "$libobj"; then + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + fi + + test yes = "$build_libtool_libs" || { + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + # Create an invalid libtool object if no PIC, so that we don't + # accidentally link it into a program. + # $show "echo timestamp > $libobj" + # $opt_dry_run || eval "echo timestamp > $libobj" || exit $? + exit $EXIT_SUCCESS + } + + if test -n "$pic_flag" || test default != "$pic_mode"; then + # Only do commands if we really have different PIC objects. + reload_objs="$libobjs $reload_conv_objs" + output=$libobj + func_execute_cmds "$reload_cmds" 'exit $?' + fi + + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + ;; + + prog) + case $host in + *cygwin*) func_stripname '' '.exe' "$output" + output=$func_stripname_result.exe;; + esac + test -n "$vinfo" && \ + func_warning "'-version-info' is ignored for programs" + + test -n "$release" && \ + func_warning "'-release' is ignored for programs" + + $preload \ + && test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \ + && func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support." + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'` + finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'` + ;; + esac + + case $host in + *-*-darwin*) + # Don't allow lazy linking, it breaks C++ global constructors + # But is supposedly fixed on 10.4 or later (yay!). + if test CXX = "$tagname"; then + case ${MACOSX_DEPLOYMENT_TARGET-10.0} in + 10.[0123]) + func_append compile_command " $wl-bind_at_load" + func_append finalize_command " $wl-bind_at_load" + ;; + esac + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $compile_deplibs " in + *" -L$path/$objdir "*) + func_append new_libs " -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $compile_deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) func_append new_libs " $deplib" ;; + esac + ;; + *) func_append new_libs " $deplib" ;; + esac + done + compile_deplibs=$new_libs + + + func_append compile_command " $compile_deplibs" + func_append finalize_command " $finalize_deplibs" + + if test -n "$rpath$xrpath"; then + # If the user specified any rpath flags, then add them. + for libdir in $rpath $xrpath; do + # This is the magic to use -rpath. + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + done + fi + + # Now hardcode the library paths + rpath= + hardcode_libdirs= + for libdir in $compile_rpath $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) func_append perm_rpath " $libdir" ;; + esac + fi + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$libdir:"*) ;; + ::) dllsearchpath=$libdir;; + *) func_append dllsearchpath ":$libdir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) func_append dllsearchpath ":$testbindir";; + esac + ;; + esac + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + compile_rpath=$rpath + + rpath= + hardcode_libdirs= + for libdir in $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$finalize_perm_rpath " in + *" $libdir "*) ;; + *) func_append finalize_perm_rpath " $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + finalize_rpath=$rpath + + if test -n "$libobjs" && test yes = "$build_old_libs"; then + # Transform all the library objects into standard objects. + compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP` + finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP` + fi + + func_generate_dlsyms "$outputname" "@PROGRAM@" false + + # template prelinking step + if test -n "$prelink_cmds"; then + func_execute_cmds "$prelink_cmds" 'exit $?' + fi + + wrappers_required=: + case $host in + *cegcc* | *mingw32ce*) + # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway. + wrappers_required=false + ;; + *cygwin* | *mingw* ) + test yes = "$build_libtool_libs" || wrappers_required=false + ;; + *) + if test no = "$need_relink" || test yes != "$build_libtool_libs"; then + wrappers_required=false + fi + ;; + esac + $wrappers_required || { + # Replace the output file specification. + compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'` + link_command=$compile_command$compile_rpath + + # We have no uninstalled library dependencies, so finalize right now. + exit_status=0 + func_show_eval "$link_command" 'exit_status=$?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + # Delete the generated files. + if test -f "$output_objdir/${outputname}S.$objext"; then + func_show_eval '$RM "$output_objdir/${outputname}S.$objext"' + fi + + exit $exit_status + } + + if test -n "$compile_shlibpath$finalize_shlibpath"; then + compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" + fi + if test -n "$finalize_shlibpath"; then + finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" + fi + + compile_var= + finalize_var= + if test -n "$runpath_var"; then + if test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + func_append rpath "$dir:" + done + compile_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + if test -n "$finalize_perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $finalize_perm_rpath; do + func_append rpath "$dir:" + done + finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + fi + + if test yes = "$no_install"; then + # We don't need to create a wrapper script. + link_command=$compile_var$compile_command$compile_rpath + # Replace the output file specification. + link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'` + # Delete the old output file. + $opt_dry_run || $RM $output + # Link the executable and exit + func_show_eval "$link_command" 'exit $?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + exit $EXIT_SUCCESS + fi + + case $hardcode_action,$fast_install in + relink,*) + # Fast installation is not supported + link_command=$compile_var$compile_command$compile_rpath + relink_command=$finalize_var$finalize_command$finalize_rpath + + func_warning "this platform does not like uninstalled shared libraries" + func_warning "'$output' will be relinked during installation" + ;; + *,yes) + link_command=$finalize_var$compile_command$finalize_rpath + relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'` + ;; + *,no) + link_command=$compile_var$compile_command$compile_rpath + relink_command=$finalize_var$finalize_command$finalize_rpath + ;; + *,needless) + link_command=$finalize_var$compile_command$finalize_rpath + relink_command= + ;; + esac + + # Replace the output file specification. + link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` + + # Delete the old output files. + $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname + + func_show_eval "$link_command" 'exit $?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output_objdir/$outputname" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + # Now create the wrapper script. + func_verbose "creating $output" + + # Quote the relink command for shipping. + if test -n "$relink_command"; then + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + relink_command="(cd `pwd`; $relink_command)" + relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + fi + + # Only actually do things if not in dry run mode. + $opt_dry_run || { + # win32 will think the script is a binary if it has + # a .exe suffix, so we strip it off here. + case $output in + *.exe) func_stripname '' '.exe' "$output" + output=$func_stripname_result ;; + esac + # test for cygwin because mv fails w/o .exe extensions + case $host in + *cygwin*) + exeext=.exe + func_stripname '' '.exe' "$outputname" + outputname=$func_stripname_result ;; + *) exeext= ;; + esac + case $host in + *cygwin* | *mingw* ) + func_dirname_and_basename "$output" "" "." + output_name=$func_basename_result + output_path=$func_dirname_result + cwrappersource=$output_path/$objdir/lt-$output_name.c + cwrapper=$output_path/$output_name.exe + $RM $cwrappersource $cwrapper + trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 + + func_emit_cwrapperexe_src > $cwrappersource + + # The wrapper executable is built using the $host compiler, + # because it contains $host paths and files. If cross- + # compiling, it, like the target executable, must be + # executed on the $host or under an emulation environment. + $opt_dry_run || { + $LTCC $LTCFLAGS -o $cwrapper $cwrappersource + $STRIP $cwrapper + } + + # Now, create the wrapper script for func_source use: + func_ltwrapper_scriptname $cwrapper + $RM $func_ltwrapper_scriptname_result + trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15 + $opt_dry_run || { + # note: this script will not be executed, so do not chmod. + if test "x$build" = "x$host"; then + $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result + else + func_emit_wrapper no > $func_ltwrapper_scriptname_result + fi + } + ;; + * ) + $RM $output + trap "$RM $output; exit $EXIT_FAILURE" 1 2 15 + + func_emit_wrapper no > $output + chmod +x $output + ;; + esac + } + exit $EXIT_SUCCESS + ;; + esac + + # See if we need to build an old-fashioned archive. + for oldlib in $oldlibs; do + + case $build_libtool_libs in + convenience) + oldobjs="$libobjs_save $symfileobj" + addlibs=$convenience + build_libtool_libs=no + ;; + module) + oldobjs=$libobjs_save + addlibs=$old_convenience + build_libtool_libs=no + ;; + *) + oldobjs="$old_deplibs $non_pic_objects" + $preload && test -f "$symfileobj" \ + && func_append oldobjs " $symfileobj" + addlibs=$old_convenience + ;; + esac + + if test -n "$addlibs"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $addlibs + func_append oldobjs " $func_extract_archives_result" + fi + + # Do each command in the archive commands. + if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then + cmds=$old_archive_from_new_cmds + else + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $dlprefiles + func_append oldobjs " $func_extract_archives_result" + fi + + # POSIX demands no paths to be encoded in archives. We have + # to avoid creating archives with duplicate basenames if we + # might have to extract them afterwards, e.g., when creating a + # static archive out of a convenience library, or when linking + # the entirety of a libtool archive into another (currently + # not supported by libtool). + if (for obj in $oldobjs + do + func_basename "$obj" + $ECHO "$func_basename_result" + done | sort | sort -uc >/dev/null 2>&1); then + : + else + echo "copying selected object files to avoid basename conflicts..." + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + func_mkdir_p "$gentop" + save_oldobjs=$oldobjs + oldobjs= + counter=1 + for obj in $save_oldobjs + do + func_basename "$obj" + objbase=$func_basename_result + case " $oldobjs " in + " ") oldobjs=$obj ;; + *[\ /]"$objbase "*) + while :; do + # Make sure we don't pick an alternate name that also + # overlaps. + newobj=lt$counter-$objbase + func_arith $counter + 1 + counter=$func_arith_result + case " $oldobjs " in + *[\ /]"$newobj "*) ;; + *) if test ! -f "$gentop/$newobj"; then break; fi ;; + esac + done + func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" + func_append oldobjs " $gentop/$newobj" + ;; + *) func_append oldobjs " $obj" ;; + esac + done + fi + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result + eval cmds=\"$old_archive_cmds\" + + func_len " $cmds" + len=$func_len_result + if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + cmds=$old_archive_cmds + elif test -n "$archiver_list_spec"; then + func_verbose "using command file archive linking..." + for obj in $oldobjs + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" + done > $output_objdir/$libname.libcmd + func_to_tool_file "$output_objdir/$libname.libcmd" + oldobjs=" $archiver_list_spec$func_to_tool_file_result" + cmds=$old_archive_cmds + else + # the command line is too long to link in one step, link in parts + func_verbose "using piecewise archive linking..." + save_RANLIB=$RANLIB + RANLIB=: + objlist= + concat_cmds= + save_oldobjs=$oldobjs + oldobjs= + # Is there a better way of finding the last object in the list? + for obj in $save_oldobjs + do + last_oldobj=$obj + done + eval test_cmds=\"$old_archive_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + for obj in $save_oldobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + func_append objlist " $obj" + if test "$len" -lt "$max_cmd_len"; then + : + else + # the above command should be used before it gets too long + oldobjs=$objlist + if test "$obj" = "$last_oldobj"; then + RANLIB=$save_RANLIB + fi + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\$concat_cmds$old_archive_cmds\" + objlist= + len=$len0 + fi + done + RANLIB=$save_RANLIB + oldobjs=$objlist + if test -z "$oldobjs"; then + eval cmds=\"\$concat_cmds\" + else + eval cmds=\"\$concat_cmds~\$old_archive_cmds\" + fi + fi + fi + func_execute_cmds "$cmds" 'exit $?' + done + + test -n "$generated" && \ + func_show_eval "${RM}r$generated" + + # Now create the libtool archive. + case $output in + *.la) + old_library= + test yes = "$build_old_libs" && old_library=$libname.$libext + func_verbose "creating $output" + + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + # Quote the link command for shipping. + relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + if test yes = "$hardcode_automatic"; then + relink_command= + fi + + # Only create the output if not a dry run. + $opt_dry_run || { + for installed in no yes; do + if test yes = "$installed"; then + if test -z "$install_libdir"; then + break + fi + output=$output_objdir/${outputname}i + # Replace all uninstalled libtool libraries with the installed ones + newdependency_libs= + for deplib in $dependency_libs; do + case $deplib in + *.la) + func_basename "$deplib" + name=$func_basename_result + func_resolve_sysroot "$deplib" + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result` + test -z "$libdir" && \ + func_fatal_error "'$deplib' is not a valid libtool archive" + func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name" + ;; + -L*) + func_stripname -L '' "$deplib" + func_replace_sysroot "$func_stripname_result" + func_append newdependency_libs " -L$func_replace_sysroot_result" + ;; + -R*) + func_stripname -R '' "$deplib" + func_replace_sysroot "$func_stripname_result" + func_append newdependency_libs " -R$func_replace_sysroot_result" + ;; + *) func_append newdependency_libs " $deplib" ;; + esac + done + dependency_libs=$newdependency_libs + newdlfiles= + + for lib in $dlfiles; do + case $lib in + *.la) + func_basename "$lib" + name=$func_basename_result + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "'$lib' is not a valid libtool archive" + func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name" + ;; + *) func_append newdlfiles " $lib" ;; + esac + done + dlfiles=$newdlfiles + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + *.la) + # Only pass preopened files to the pseudo-archive (for + # eventual linking with the app. that links it) if we + # didn't already link the preopened objects directly into + # the library: + func_basename "$lib" + name=$func_basename_result + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "'$lib' is not a valid libtool archive" + func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name" + ;; + esac + done + dlprefiles=$newdlprefiles + else + newdlfiles= + for lib in $dlfiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;; + *) abs=`pwd`"/$lib" ;; + esac + func_append newdlfiles " $abs" + done + dlfiles=$newdlfiles + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;; + *) abs=`pwd`"/$lib" ;; + esac + func_append newdlprefiles " $abs" + done + dlprefiles=$newdlprefiles + fi + $RM $output + # place dlname in correct position for cygwin + # In fact, it would be nice if we could use this code for all target + # systems that can't hard-code library paths into their executables + # and that have no shared library path variable independent of PATH, + # but it turns out we can't easily determine that from inspecting + # libtool variables, so we have to hard-code the OSs to which it + # applies here; at the moment, that means platforms that use the PE + # object format with DLL files. See the long comment at the top of + # tests/bindir.at for full details. + tdlname=$dlname + case $host,$output,$installed,$module,$dlname in + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) + # If a -bindir argument was supplied, place the dll there. + if test -n "$bindir"; then + func_relative_path "$install_libdir" "$bindir" + tdlname=$func_relative_path_result/$dlname + else + # Otherwise fall back on heuristic. + tdlname=../bin/$dlname + fi + ;; + esac + $ECHO > $output "\ +# $outputname - a libtool library file +# Generated by $PROGRAM (GNU $PACKAGE) $VERSION +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='$tdlname' + +# Names of this library. +library_names='$library_names' + +# The name of the static archive. +old_library='$old_library' + +# Linker flags that cannot go in dependency_libs. +inherited_linker_flags='$new_inherited_linker_flags' + +# Libraries that this one depends upon. +dependency_libs='$dependency_libs' + +# Names of additional weak libraries provided by this library +weak_library_names='$weak_libs' + +# Version information for $libname. +current=$current +age=$age +revision=$revision + +# Is this an already installed library? +installed=$installed + +# Should we warn about portability when linking against -modules? +shouldnotlink=$module + +# Files to dlopen/dlpreopen +dlopen='$dlfiles' +dlpreopen='$dlprefiles' + +# Directory that this library needs to be installed in: +libdir='$install_libdir'" + if test no,yes = "$installed,$need_relink"; then + $ECHO >> $output "\ +relink_command=\"$relink_command\"" + fi + done + } + + # Do a symbolic link so that the libtool archive can be found in + # LD_LIBRARY_PATH before the program is installed. + func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?' + ;; + esac + exit $EXIT_SUCCESS +} + +if test link = "$opt_mode" || test relink = "$opt_mode"; then + func_mode_link ${1+"$@"} +fi + + +# func_mode_uninstall arg... +func_mode_uninstall () +{ + $debug_cmd + + RM=$nonopt + files= + rmforce=false + exit_status=0 + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic=$magic + + for arg + do + case $arg in + -f) func_append RM " $arg"; rmforce=: ;; + -*) func_append RM " $arg" ;; + *) func_append files " $arg" ;; + esac + done + + test -z "$RM" && \ + func_fatal_help "you must specify an RM program" + + rmdirs= + + for file in $files; do + func_dirname "$file" "" "." + dir=$func_dirname_result + if test . = "$dir"; then + odir=$objdir + else + odir=$dir/$objdir + fi + func_basename "$file" + name=$func_basename_result + test uninstall = "$opt_mode" && odir=$dir + + # Remember odir for removal later, being careful to avoid duplicates + if test clean = "$opt_mode"; then + case " $rmdirs " in + *" $odir "*) ;; + *) func_append rmdirs " $odir" ;; + esac + fi + + # Don't error if the file doesn't exist and rm -f was used. + if { test -L "$file"; } >/dev/null 2>&1 || + { test -h "$file"; } >/dev/null 2>&1 || + test -f "$file"; then + : + elif test -d "$file"; then + exit_status=1 + continue + elif $rmforce; then + continue + fi + + rmfiles=$file + + case $name in + *.la) + # Possibly a libtool archive, so verify it. + if func_lalib_p "$file"; then + func_source $dir/$name + + # Delete the libtool libraries and symlinks. + for n in $library_names; do + func_append rmfiles " $odir/$n" + done + test -n "$old_library" && func_append rmfiles " $odir/$old_library" + + case $opt_mode in + clean) + case " $library_names " in + *" $dlname "*) ;; + *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;; + esac + test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i" + ;; + uninstall) + if test -n "$library_names"; then + # Do each command in the postuninstall commands. + func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1' + fi + + if test -n "$old_library"; then + # Do each command in the old_postuninstall commands. + func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1' + fi + # FIXME: should reinstall the best remaining shared library. + ;; + esac + fi + ;; + + *.lo) + # Possibly a libtool object, so verify it. + if func_lalib_p "$file"; then + + # Read the .lo file + func_source $dir/$name + + # Add PIC object to the list of files to remove. + if test -n "$pic_object" && test none != "$pic_object"; then + func_append rmfiles " $dir/$pic_object" + fi + + # Add non-PIC object to the list of files to remove. + if test -n "$non_pic_object" && test none != "$non_pic_object"; then + func_append rmfiles " $dir/$non_pic_object" + fi + fi + ;; + + *) + if test clean = "$opt_mode"; then + noexename=$name + case $file in + *.exe) + func_stripname '' '.exe' "$file" + file=$func_stripname_result + func_stripname '' '.exe' "$name" + noexename=$func_stripname_result + # $file with .exe has already been added to rmfiles, + # add $file without .exe + func_append rmfiles " $file" + ;; + esac + # Do a test to see if this is a libtool program. + if func_ltwrapper_p "$file"; then + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + relink_command= + func_source $func_ltwrapper_scriptname_result + func_append rmfiles " $func_ltwrapper_scriptname_result" + else + relink_command= + func_source $dir/$noexename + fi + + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + func_append rmfiles " $odir/$name $odir/${name}S.$objext" + if test yes = "$fast_install" && test -n "$relink_command"; then + func_append rmfiles " $odir/lt-$name" + fi + if test "X$noexename" != "X$name"; then + func_append rmfiles " $odir/lt-$noexename.c" + fi + fi + fi + ;; + esac + func_show_eval "$RM $rmfiles" 'exit_status=1' + done + + # Try to remove the $objdir's in the directories where we deleted files + for dir in $rmdirs; do + if test -d "$dir"; then + func_show_eval "rmdir $dir >/dev/null 2>&1" + fi + done + + exit $exit_status +} + +if test uninstall = "$opt_mode" || test clean = "$opt_mode"; then + func_mode_uninstall ${1+"$@"} +fi + +test -z "$opt_mode" && { + help=$generic_help + func_fatal_help "you must specify a MODE" +} + +test -z "$exec_cmd" && \ + func_fatal_help "invalid operation mode '$opt_mode'" + +if test -n "$exec_cmd"; then + eval exec "$exec_cmd" + exit $EXIT_FAILURE +fi + +exit $exit_status + + +# The TAGs below are defined such that we never get into a situation +# where we disable both kinds of libraries. Given conflicting +# choices, we go for a static library, that is the most portable, +# since we can't tell whether shared libraries were disabled because +# the user asked for that or because the platform doesn't support +# them. This is particularly important on AIX, because we don't +# support having both static and shared libraries enabled at the same +# time on that platform, so we default to a shared-only configuration. +# If a disable-shared tag is given, we'll fallback to a static-only +# configuration. But we'll never go from static-only to shared-only. + +# ### BEGIN LIBTOOL TAG CONFIG: disable-shared +build_libtool_libs=no +build_old_libs=yes +# ### END LIBTOOL TAG CONFIG: disable-shared + +# ### BEGIN LIBTOOL TAG CONFIG: disable-static +build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` +# ### END LIBTOOL TAG CONFIG: disable-static + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: diff --git a/src/c/src/addrvec.c b/src/c/src/addrvec.c new file mode 100644 index 00000000000..e641a46f226 --- /dev/null +++ b/src/c/src/addrvec.c @@ -0,0 +1,251 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#ifdef WIN32 +#include +#include "winport.h" +#endif + +#include "addrvec.h" + +#define ADDRVEC_DEFAULT_GROW_AMOUNT 16 + +void addrvec_init(addrvec_t *avec) +{ + assert(avec); + avec->next = 0; + avec->count = 0; + avec->capacity = 0; + avec->data = NULL; +} + +void addrvec_free(addrvec_t *avec) +{ + if (avec == NULL) + { + return; + } + + avec->next = 0; + avec->count = 0; + avec->capacity = 0; + if (avec->data) { + free(avec->data); + avec->data = NULL; + } +} + +int addrvec_alloc(addrvec_t *avec) +{ + addrvec_init(avec); + return addrvec_grow_default(avec); +} + +int addrvec_alloc_capacity(addrvec_t* avec, uint32_t capacity) +{ + addrvec_init(avec); + return addrvec_grow(avec, capacity); +} + +int addrvec_grow(addrvec_t *avec, uint32_t grow_amount) +{ + unsigned int old_capacity = 0; + struct sockaddr_storage *old_data = NULL; + assert(avec); + + if (grow_amount == 0) + { + return 0; + } + + // Save off old data and capacity in case there is a realloc failure + old_capacity = avec->capacity; + old_data = avec->data; + + avec->capacity += grow_amount; + avec->data = realloc(avec->data, sizeof(*avec->data) * avec->capacity); + if (avec->data == NULL) + { + avec->capacity = old_capacity; + avec->data = old_data; + errno = ENOMEM; + return 1; + } + + return 0; +} + +int addrvec_grow_default(addrvec_t *avec) +{ + return addrvec_grow(avec, ADDRVEC_DEFAULT_GROW_AMOUNT); +} + +static int addrvec_grow_if_full(addrvec_t *avec) +{ + assert(avec); + if (avec->count == avec->capacity) + { + int rc = addrvec_grow_default(avec); + if (rc != 0) + { + return rc; + } + } + + return 0; +} + +int addrvec_contains(const addrvec_t *avec, const struct sockaddr_storage *addr) +{ + uint32_t i = 0; + if (!avec || !addr) + { + return 0; + } + + for (i = 0; i < avec->count; i++) + { + if(memcmp(&avec->data[i], addr, INET_ADDRSTRLEN) == 0) + return 1; + } + + return 0; +} + +int addrvec_append(addrvec_t *avec, const struct sockaddr_storage *addr) +{ + int rc = 0; + assert(avec); + assert(addr); + + rc = addrvec_grow_if_full(avec); + if (rc != 0) + { + return rc; + } + + // Copy addrinfo into address list + memcpy(avec->data + avec->count, addr, sizeof(*addr)); + ++avec->count; + + return 0; +} + +int addrvec_append_addrinfo(addrvec_t *avec, const struct addrinfo *addrinfo) +{ + int rc = 0; + assert(avec); + assert(addrinfo); + + rc = addrvec_grow_if_full(avec); + if (rc != 0) + { + return rc; + } + + // Copy addrinfo into address list + memcpy(avec->data + avec->count, addrinfo->ai_addr, addrinfo->ai_addrlen); + ++avec->count; + + return 0; +} + +void addrvec_shuffle(addrvec_t *avec) +{ + int i = 0; + for (i = avec->count - 1; i > 0; --i) { + long int j = random()%(i+1); + if (i != j) { + struct sockaddr_storage t = avec->data[i]; + avec->data[i] = avec->data[j]; + avec->data[j] = t; + } + } +} + +int addrvec_hasnext(const addrvec_t *avec) +{ + return avec->count > 0 && (avec->next < avec->count); +} + +int addrvec_atend(const addrvec_t *avec) +{ + return avec->count > 0 && avec->next >= avec->count; +} + +void addrvec_next(addrvec_t *avec, struct sockaddr_storage *next) +{ + int index; + + // If we're at the end of the list, then reset index to start + if (addrvec_atend(avec)) { + avec->next = 0; + } + + if (!addrvec_hasnext(avec)) { + if (next) { + memset(next, 0, sizeof(*next)); + } + + return; + } + + index = avec->next++; + + if (next) { + *next = avec->data[index]; + } +} + +void addrvec_peek(addrvec_t *avec, struct sockaddr_storage *next) +{ + int index = avec->next; + + if (avec->count == 0) { + memset(next, 0, sizeof(*next)); + return; + } + + if (addrvec_atend(avec)) { + index = 0; + } + + *next = avec->data[index]; +} + + +int addrvec_eq(const addrvec_t *a1, const addrvec_t *a2) +{ + uint32_t i = 0; + if (a1->count != a2->count) + { + return 0; + } + + for (i = 0; i < a1->count; ++i) + { + if (!addrvec_contains(a2, &a1->data[i])) + return 0; + } + + return 1; +} diff --git a/src/c/src/addrvec.h b/src/c/src/addrvec.h new file mode 100644 index 00000000000..3897095373b --- /dev/null +++ b/src/c/src/addrvec.h @@ -0,0 +1,138 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ADDRVEC_H_ +#define ADDRVEC_H_ + +#ifndef WIN32 +#include +#include +#include +#include +#else +#include +#include "winstdint.h" +#endif + +/** + * This structure represents a list of addresses. It stores the count of the + * number of elements that have been inserted via calls to addrvec_append and + * addrvec_append_addrinfo. It also has a capacity field for the number of + * addresses it has the ability to hold without needing to be enlarged. + */ +typedef struct _addrvec { + unsigned int next; // next index to use + unsigned int count; // number of addresses in this list + unsigned int capacity; // number of address this list can hold + struct sockaddr_storage *data; // list of addresses +} addrvec_t; + +/** + * Initialize an addrvec by clearing out all its state. + */ +void addrvec_init(addrvec_t *avec); + +/** + * Free any memory used internally by an addrvec + */ +void addrvec_free(addrvec_t *avec); + +/** + * Allocate an addrvec with a default capacity (16) + */ +int addrvec_alloc(addrvec_t *avec); + +/** + * Allocates an addrvec with a specified capacity + */ +int addrvec_alloc_capacity(addrvec_t *avec, uint32_t capacity); + +/** + * Grow an addrvec by the specified amount. This will increase the capacity + * of the vector and not the contents. + */ +int addrvec_grow(addrvec_t *avec, uint32_t grow_amount); + +/** + * Similar to addrvec_grow but uses a default growth amount of 16. + */ +int addrvec_grow_default(addrvec_t *avec); + +/** + * Check if an addrvec contains the specificed sockaddr_storage value. + * \returns 1 if it contains the value and 0 otherwise. + */ +int addrvec_contains(const addrvec_t *avec, const struct sockaddr_storage *addr); + +/** + * Append the given sockaddr_storage pointer into the addrvec. The contents of + * the given 'addr' are copied into the addrvec via memcpy. + */ +int addrvec_append(addrvec_t *avec, const struct sockaddr_storage *addr); + +/** + * Append the given addrinfo pointer into the addrvec. The contents of the given + * 'addrinfo' are copied into the addrvec via memcpy. + */ +int addrvec_append_addrinfo(addrvec_t *avec, const struct addrinfo *addrinfo); + +/** + * Shuffle the addrvec so that it's internal list of addresses are randomized. + * Uses random() and assumes it has been properly seeded. + */ +void addrvec_shuffle(addrvec_t *avec); + +/** + * Determine if the addrvec has a next element (e.g. it's safe to call addrvec_next) + * + * \returns 1 if it has a next element and 0 otherwise + */ +int addrvec_hasnext(const addrvec_t *avec); + +/** + * Determine if the addrvec is at the end or not. Specifically, this means a + * subsequent call to addrvec_next will loop around to the start again. + */ +int addrvec_atend(const addrvec_t *avec); + +/** + * Get the next entry from the addrvec and update the associated index. + * + * If next is NULL, the index will still be updated. + * + * If the current index points at (or after) the last element in the vector then + * it will loop back around and start at the beginning of the list. + */ +void addrvec_next(addrvec_t *avec, struct sockaddr_storage *next); + +/** + * Retrieves the next entry from the addrvec but doesn't update the index. + */ +void addrvec_peek(addrvec_t *avec, struct sockaddr_storage *next); + +/** + * Compare two addrvecs for equality. + * + * \returns 1 if the contents of the two lists are identical and and 0 otherwise. + */ +int addrvec_eq(const addrvec_t *a1, const addrvec_t *a2); + +#endif // ADDRVEC_H + + + diff --git a/src/c/src/cli.c b/src/c/src/cli.c new file mode 100644 index 00000000000..a9d11e173f6 --- /dev/null +++ b/src/c/src/cli.c @@ -0,0 +1,829 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#include +#include +#else +#include "winport.h" +//#include <-- can't include, conflicting definitions of close() +int read(int _FileHandle, void * _DstBuf, unsigned int _MaxCharCount); +int write(int _Filehandle, const void * _Buf, unsigned int _MaxCharCount); +#define ctime_r(tctime, buffer) ctime_s (buffer, 40, tctime) +#endif + +#include +#include +#include + +#ifdef YCA +#include +#endif + +#define _LL_CAST_ (long long) + +static zhandle_t *zh; +static clientid_t myid; +static const char *clientIdFile = 0; +struct timeval startTime; +static char cmd[1024]; +static int batchMode=0; + +static int to_send=0; +static int sent=0; +static int recvd=0; + +static int shutdownThisThing=0; + +static __attribute__ ((unused)) void +printProfileInfo(struct timeval start, struct timeval end, int thres, + const char* msg) +{ + int delay=(end.tv_sec*1000+end.tv_usec/1000)- + (start.tv_sec*1000+start.tv_usec/1000); + if(delay>thres) + fprintf(stderr,"%s: execution time=%dms\n",msg,delay); +} + +static const char* state2String(int state){ + if (state == 0) + return "CLOSED_STATE"; + if (state == ZOO_CONNECTING_STATE) + return "CONNECTING_STATE"; + if (state == ZOO_ASSOCIATING_STATE) + return "ASSOCIATING_STATE"; + if (state == ZOO_CONNECTED_STATE) + return "CONNECTED_STATE"; + if (state == ZOO_READONLY_STATE) + return "READONLY_STATE"; + if (state == ZOO_EXPIRED_SESSION_STATE) + return "EXPIRED_SESSION_STATE"; + if (state == ZOO_AUTH_FAILED_STATE) + return "AUTH_FAILED_STATE"; + + return "INVALID_STATE"; +} + +static const char* type2String(int state){ + if (state == ZOO_CREATED_EVENT) + return "CREATED_EVENT"; + if (state == ZOO_DELETED_EVENT) + return "DELETED_EVENT"; + if (state == ZOO_CHANGED_EVENT) + return "CHANGED_EVENT"; + if (state == ZOO_CHILD_EVENT) + return "CHILD_EVENT"; + if (state == ZOO_SESSION_EVENT) + return "SESSION_EVENT"; + if (state == ZOO_NOTWATCHING_EVENT) + return "NOTWATCHING_EVENT"; + + return "UNKNOWN_EVENT_TYPE"; +} + +void watcher(zhandle_t *zzh, int type, int state, const char *path, + void* context) +{ + /* Be careful using zh here rather than zzh - as this may be mt code + * the client lib may call the watcher before zookeeper_init returns */ + + fprintf(stderr, "Watcher %s state = %s", type2String(type), state2String(state)); + if (path && strlen(path) > 0) { + fprintf(stderr, " for path %s", path); + } + fprintf(stderr, "\n"); + + if (type == ZOO_SESSION_EVENT) { + if (state == ZOO_CONNECTED_STATE) { + const clientid_t *id = zoo_client_id(zzh); + if (myid.client_id == 0 || myid.client_id != id->client_id) { + myid = *id; + fprintf(stderr, "Got a new session id: 0x%llx\n", + _LL_CAST_ myid.client_id); + if (clientIdFile) { + FILE *fh = fopen(clientIdFile, "w"); + if (!fh) { + perror(clientIdFile); + } else { + int rc = fwrite(&myid, sizeof(myid), 1, fh); + if (rc != sizeof(myid)) { + perror("writing client id"); + } + fclose(fh); + } + } + } + } else if (state == ZOO_AUTH_FAILED_STATE) { + fprintf(stderr, "Authentication failure. Shutting down...\n"); + zookeeper_close(zzh); + shutdownThisThing=1; + zh=0; + } else if (state == ZOO_EXPIRED_SESSION_STATE) { + fprintf(stderr, "Session expired. Shutting down...\n"); + zookeeper_close(zzh); + shutdownThisThing=1; + zh=0; + } + } +} + +void dumpStat(const struct Stat *stat) { + char tctimes[40]; + char tmtimes[40]; + time_t tctime; + time_t tmtime; + + if (!stat) { + fprintf(stderr,"null\n"); + return; + } + tctime = stat->ctime/1000; + tmtime = stat->mtime/1000; + + ctime_r(&tmtime, tmtimes); + ctime_r(&tctime, tctimes); + + fprintf(stderr, "\tctime = %s\tczxid=%llx\n" + "\tmtime=%s\tmzxid=%llx\n" + "\tversion=%x\taversion=%x\n" + "\tephemeralOwner = %llx\n", + tctimes, _LL_CAST_ stat->czxid, tmtimes, + _LL_CAST_ stat->mzxid, + (unsigned int)stat->version, (unsigned int)stat->aversion, + _LL_CAST_ stat->ephemeralOwner); +} + +void my_string_completion(int rc, const char *name, const void *data) { + fprintf(stderr, "[%s]: rc = %d\n", (char*)(data==0?"null":data), rc); + if (!rc) { + fprintf(stderr, "\tname = %s\n", name); + } + if(batchMode) + shutdownThisThing=1; +} + +void my_string_completion_free_data(int rc, const char *name, const void *data) { + my_string_completion(rc, name, data); + free((void*)data); +} + +void my_string_stat_completion(int rc, const char *name, const struct Stat *stat, + const void *data) { + my_string_completion(rc, name, data); + dumpStat(stat); +} + +void my_string_stat_completion_free_data(int rc, const char *name, + const struct Stat *stat, const void *data) { + my_string_stat_completion(rc, name, stat, data); + free((void*)data); +} + +void my_data_completion(int rc, const char *value, int value_len, + const struct Stat *stat, const void *data) { + struct timeval tv; + int sec; + int usec; + gettimeofday(&tv, 0); + sec = tv.tv_sec - startTime.tv_sec; + usec = tv.tv_usec - startTime.tv_usec; + fprintf(stderr, "time = %d msec\n", sec*1000 + usec/1000); + fprintf(stderr, "%s: rc = %d\n", (char*)data, rc); + if (value) { + fprintf(stderr, " value_len = %d\n", value_len); + assert(write(2, value, value_len) == value_len); + } + fprintf(stderr, "\nStat:\n"); + dumpStat(stat); + free((void*)data); + if(batchMode) + shutdownThisThing=1; +} + +void my_silent_data_completion(int rc, const char *value, int value_len, + const struct Stat *stat, const void *data) { + recvd++; + fprintf(stderr, "Data completion %s rc = %d\n",(char*)data,rc); + free((void*)data); + if (recvd==to_send) { + fprintf(stderr,"Recvd %d responses for %d requests sent\n",recvd,to_send); + if(batchMode) + shutdownThisThing=1; + } +} + +void my_strings_completion(int rc, const struct String_vector *strings, + const void *data) { + struct timeval tv; + int sec; + int usec; + int i; + + gettimeofday(&tv, 0); + sec = tv.tv_sec - startTime.tv_sec; + usec = tv.tv_usec - startTime.tv_usec; + fprintf(stderr, "time = %d msec\n", sec*1000 + usec/1000); + fprintf(stderr, "%s: rc = %d\n", (char*)data, rc); + if (strings) + for (i=0; i < strings->count; i++) { + fprintf(stderr, "\t%s\n", strings->data[i]); + } + free((void*)data); + gettimeofday(&tv, 0); + sec = tv.tv_sec - startTime.tv_sec; + usec = tv.tv_usec - startTime.tv_usec; + fprintf(stderr, "time = %d msec\n", sec*1000 + usec/1000); + if(batchMode) + shutdownThisThing=1; +} + +void my_strings_stat_completion(int rc, const struct String_vector *strings, + const struct Stat *stat, const void *data) { + my_strings_completion(rc, strings, data); + dumpStat(stat); + if(batchMode) + shutdownThisThing=1; +} + +void my_void_completion(int rc, const void *data) { + fprintf(stderr, "%s: rc = %d\n", (char*)data, rc); + free((void*)data); + if(batchMode) + shutdownThisThing=1; +} + +void my_stat_completion(int rc, const struct Stat *stat, const void *data) { + fprintf(stderr, "%s: rc = %d Stat:\n", (char*)data, rc); + dumpStat(stat); + free((void*)data); + if(batchMode) + shutdownThisThing=1; +} + +void my_silent_stat_completion(int rc, const struct Stat *stat, + const void *data) { + // fprintf(stderr, "State completion: [%s] rc = %d\n", (char*)data, rc); + sent++; + free((void*)data); +} + +static void sendRequest(const char* data) { + zoo_aset(zh, "/od", data, strlen(data), -1, my_silent_stat_completion, + strdup("/od")); + zoo_aget(zh, "/od", 1, my_silent_data_completion, strdup("/od")); +} + +void od_completion(int rc, const struct Stat *stat, const void *data) { + int i; + fprintf(stderr, "od command response: rc = %d Stat:\n", rc); + dumpStat(stat); + // send a whole bunch of requests + recvd=0; + sent=0; + to_send=200; + for (i=0; i\n"); + fprintf(stderr, " create2 [+[e|s]] \n"); + fprintf(stderr, " delete \n"); + fprintf(stderr, " set \n"); + fprintf(stderr, " get \n"); + fprintf(stderr, " ls \n"); + fprintf(stderr, " ls2 \n"); + fprintf(stderr, " sync \n"); + fprintf(stderr, " exists \n"); + fprintf(stderr, " wexists \n"); + fprintf(stderr, " myid\n"); + fprintf(stderr, " verbose\n"); + fprintf(stderr, " addauth \n"); + fprintf(stderr, " config\n"); + fprintf(stderr, " reconfig [-file | -members ,... | " + " -add ,... | -remove ,...] [-version ]\n"); + fprintf(stderr, " quit\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " prefix the command with the character 'a' to run the command asynchronously.\n"); + fprintf(stderr, " run the 'verbose' command to toggle verbose logging.\n"); + fprintf(stderr, " i.e. 'aget /foo' to get /foo asynchronously\n"); + } else if (startsWith(line, "verbose")) { + if (verbose) { + verbose = 0; + zoo_set_debug_level(ZOO_LOG_LEVEL_WARN); + fprintf(stderr, "logging level set to WARN\n"); + } else { + verbose = 1; + zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG); + fprintf(stderr, "logging level set to DEBUG\n"); + } + } else if (startsWith(line, "get ")) { + line += 4; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } + + rc = zoo_aget(zh, line, 1, my_data_completion, strdup(line)); + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (strcmp(line, "config") == 0) { + gettimeofday(&startTime, 0); + rc = zoo_agetconfig(zh, 1, my_data_completion, strdup(ZOO_CONFIG_NODE)); + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "reconfig ")) { + int syntaxError = 0; + char* p = NULL; + char* joining = NULL; + char* leaving = NULL; + char* members = NULL; + size_t members_size = 0; + + int mode = 0; // 0 = not set, 1 = incremental, 2 = non-incremental + int64_t version = -1; + + line += 9; + p = strtok (strdup(line)," "); + while (p != NULL) { + if (strcmp(p, "-add")==0) { + p = strtok (NULL," "); + if (mode == 2 || p == NULL) { + syntaxError = 1; + break; + } + mode = 1; + joining = strdup(p); + } else if (strcmp(p, "-remove")==0){ + p = strtok (NULL," "); + if (mode == 2 || p == NULL) { + syntaxError = 1; + break; + } + mode = 1; + leaving = strdup(p); + } else if (strcmp(p, "-members")==0) { + p = strtok (NULL," "); + if (mode == 1 || p == NULL) { + syntaxError = 1; + break; + } + mode = 2; + members = strdup(p); + } else if (strcmp(p, "-file")==0){ + FILE *fp = NULL; + p = strtok (NULL," "); + if (mode == 1 || p == NULL) { + syntaxError = 1; + break; + } + mode = 2; + fp = fopen(p, "r"); + if (fp == NULL) { + fprintf(stderr, "Error reading file: %s\n", p); + syntaxError = 1; + break; + } + fseek(fp, 0L, SEEK_END); /* Position to end of file */ + members_size = ftell(fp); /* Get file length */ + rewind(fp); /* Back to start of file */ + members = calloc(members_size + 1, sizeof(char)); + if(members == NULL ) + { + fprintf(stderr, "\nInsufficient memory to read file: %s\n", p); + syntaxError = 1; + fclose(fp); + break; + } + + /* Read the entire file into members + * NOTE: -- fread returns number of items successfully read + * not the number of bytes. We're requesting one item of + * members_size bytes. So we expect the return value here + * to be 1. + */ + if (fread(members, members_size, 1, fp) != 1){ + fprintf(stderr, "Error reading file: %s\n", p); + syntaxError = 1; + fclose(fp); + break; + } + fclose(fp); + } else if (strcmp(p, "-version")==0){ + p = strtok (NULL," "); + if (version != -1 || p == NULL){ + syntaxError = 1; + break; + } +#ifdef WIN32 + version = _strtoui64(p, NULL, 16); +#else + version = strtoull(p, NULL, 16); +#endif + if (version < 0) { + syntaxError = 1; + break; + } + } else { + syntaxError = 1; + break; + } + p = strtok (NULL," "); + } + if (syntaxError) return; + + rc = zoo_areconfig(zh, joining, leaving, members, version, my_data_completion, strdup(line)); + free(joining); + free(leaving); + free(members); + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + + } else if (startsWith(line, "set ")) { + char *ptr; + line += 4; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } + ptr = strchr(line, ' '); + if (!ptr) { + fprintf(stderr, "No data found after path\n"); + return; + } + *ptr = '\0'; + ptr++; + if (async) { + rc = zoo_aset(zh, line, ptr, strlen(ptr), -1, my_stat_completion, + strdup(line)); + } else { + struct Stat stat; + rc = zoo_set2(zh, line, ptr, strlen(ptr), -1, &stat); + } + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "ls ")) { + line += 3; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } + gettimeofday(&startTime, 0); + rc= zoo_aget_children(zh, line, 1, my_strings_completion, strdup(line)); + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "ls2 ")) { + line += 4; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } + gettimeofday(&startTime, 0); + rc= zoo_aget_children2(zh, line, 1, my_strings_stat_completion, strdup(line)); + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "create ") || startsWith(line, "create2 ")) { + int flags = 0; + int is_create2 = startsWith(line, "create2 "); + line += is_create2 ? 8 : 7; + if (line[0] == '+') { + line++; + if (line[0] == 'e') { + flags |= ZOO_EPHEMERAL; + line++; + } + if (line[0] == 's') { + flags |= ZOO_SEQUENCE; + line++; + } + line++; + } + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } + fprintf(stderr, "Creating [%s] node\n", line); +// { +// struct ACL _CREATE_ONLY_ACL_ACL[] = {{ZOO_PERM_CREATE, ZOO_ANYONE_ID_UNSAFE}}; +// struct ACL_vector CREATE_ONLY_ACL = {1,_CREATE_ONLY_ACL_ACL}; +// rc = zoo_acreate(zh, line, "new", 3, &CREATE_ONLY_ACL, flags, +// my_string_completion, strdup(line)); +// } + if (is_create2) { + rc = zoo_acreate2(zh, line, "new", 3, &ZOO_OPEN_ACL_UNSAFE, flags, + my_string_stat_completion_free_data, strdup(line)); + } else { + rc = zoo_acreate(zh, line, "new", 3, &ZOO_OPEN_ACL_UNSAFE, flags, + my_string_completion_free_data, strdup(line)); + } + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "delete ")) { + line += 7; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } + if (async) { + rc = zoo_adelete(zh, line, -1, my_void_completion, strdup(line)); + } else { + rc = zoo_delete(zh, line, -1); + } + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "sync ")) { + line += 5; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } + rc = zoo_async(zh, line, my_string_completion_free_data, strdup(line)); + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "wexists ")) { +#ifdef THREADED + struct Stat stat; +#endif + line += 8; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } +#ifndef THREADED + rc = zoo_awexists(zh, line, watcher, (void*) 0, my_stat_completion, strdup(line)); +#else + rc = zoo_wexists(zh, line, watcher, (void*) 0, &stat); +#endif + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (startsWith(line, "exists ")) { +#ifdef THREADED + struct Stat stat; +#endif + line += 7; + if (line[0] != '/') { + fprintf(stderr, "Path must start with /, found: %s\n", line); + return; + } +#ifndef THREADED + rc = zoo_aexists(zh, line, 1, my_stat_completion, strdup(line)); +#else + rc = zoo_exists(zh, line, 1, &stat); +#endif + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, line); + } + } else if (strcmp(line, "myid") == 0) { + printf("session Id = %llx\n", _LL_CAST_ zoo_client_id(zh)->client_id); + } else if (strcmp(line, "reinit") == 0) { + zookeeper_close(zh); + // we can't send myid to the server here -- zookeeper_close() removes + // the session on the server. We must start anew. + zh = zookeeper_init(hostPort, watcher, 30000, 0, 0, 0); + } else if (startsWith(line, "quit")) { + fprintf(stderr, "Quitting...\n"); + shutdownThisThing=1; + } else if (startsWith(line, "od")) { + const char val[]="fire off"; + fprintf(stderr, "Overdosing...\n"); + rc = zoo_aset(zh, "/od", val, sizeof(val)-1, -1, od_completion, 0); + if (rc) + fprintf(stderr, "od command failed: %d\n", rc); + } else if (startsWith(line, "addauth ")) { + char *ptr; + line += 8; + ptr = strchr(line, ' '); + if (ptr) { + *ptr = '\0'; + ptr++; + } + zoo_add_auth(zh, line, ptr, ptr ? strlen(ptr) : 0, NULL, NULL); + } +} + +int main(int argc, char **argv) { +#ifndef THREADED + fd_set rfds, wfds, efds; + int processed=0; +#endif + char buffer[4096]; + char p[2048]; +#ifdef YCA + char *cert=0; + char appId[64]; +#endif + int bufoff = 0; + int flags, i; + FILE *fh; + + if (argc < 2) { + fprintf(stderr, + "USAGE %s zookeeper_host_list [clientid_file|cmd:(ls|ls2|create|create2|od|...)]\n", + argv[0]); + fprintf(stderr, + "Version: ZooKeeper cli (c client) version %d.%d.%d\n", + ZOO_MAJOR_VERSION, + ZOO_MINOR_VERSION, + ZOO_PATCH_VERSION); + return 2; + } + if (argc > 2) { + if(strncmp("cmd:",argv[2],4)==0){ + strcpy(cmd,argv[2]+4); + batchMode=1; + fprintf(stderr,"Batch mode: %s\n",cmd); + }else{ + clientIdFile = argv[2]; + fh = fopen(clientIdFile, "r"); + if (fh) { + if (fread(&myid, sizeof(myid), 1, fh) != sizeof(myid)) { + memset(&myid, 0, sizeof(myid)); + } + fclose(fh); + } + } + } + + flags = 0; + for (i = 1; i < argc; ++i) { + if (strcmp("-r", argv[i]) == 0) { + flags = ZOO_READONLY; + break; + } + } + +#ifdef YCA + strcpy(appId,"yahoo.example.yca_test"); + cert = yca_get_cert_once(appId); + if(cert!=0) { + fprintf(stderr,"Certificate for appid [%s] is [%s]\n",appId,cert); + strncpy(p,cert,sizeof(p)-1); + free(cert); + } else { + fprintf(stderr,"Certificate for appid [%s] not found\n",appId); + strcpy(p,"dummy"); + } +#else + strcpy(p, "dummy"); +#endif + verbose = 0; + zoo_set_debug_level(ZOO_LOG_LEVEL_WARN); + zoo_deterministic_conn_order(1); // enable deterministic order + hostPort = argv[1]; + zh = zookeeper_init(hostPort, watcher, 30000, &myid, NULL, flags); + if (!zh) { + return errno; + } + +#ifdef YCA + if(zoo_add_auth(zh,"yca",p,strlen(p),0,0)!=ZOK) + return 2; +#endif + +#ifdef THREADED + while(!shutdownThisThing) { + int rc; + int len = sizeof(buffer) - bufoff -1; + if (len <= 0) { + fprintf(stderr, "Can't handle lines that long!\n"); + exit(2); + } + rc = read(0, buffer+bufoff, len); + if (rc <= 0) { + fprintf(stderr, "bye\n"); + shutdownThisThing=1; + break; + } + bufoff += rc; + buffer[bufoff] = '\0'; + while (strchr(buffer, '\n')) { + char *ptr = strchr(buffer, '\n'); + *ptr = '\0'; + processline(buffer); + ptr++; + memmove(buffer, ptr, strlen(ptr)+1); + bufoff = 0; + } + } +#else + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + while (!shutdownThisThing) { + int fd; + int interest; + int events; + struct timeval tv; + int rc; + zookeeper_interest(zh, &fd, &interest, &tv); + if (fd != -1) { + if (interest&ZOOKEEPER_READ) { + FD_SET(fd, &rfds); + } else { + FD_CLR(fd, &rfds); + } + if (interest&ZOOKEEPER_WRITE) { + FD_SET(fd, &wfds); + } else { + FD_CLR(fd, &wfds); + } + } else { + fd = 0; + } + FD_SET(0, &rfds); + rc = select(fd+1, &rfds, &wfds, &efds, &tv); + events = 0; + if (rc > 0) { + if (FD_ISSET(fd, &rfds)) { + events |= ZOOKEEPER_READ; + } + if (FD_ISSET(fd, &wfds)) { + events |= ZOOKEEPER_WRITE; + } + } + if(batchMode && processed==0){ + //batch mode + processline(cmd); + processed=1; + } + if (!processed && FD_ISSET(0, &rfds)) { + int rc; + int len = sizeof(buffer) - bufoff -1; + if (len <= 0) { + fprintf(stderr, "Can't handle lines that long!\n"); + exit(2); + } + rc = read(0, buffer+bufoff, len); + if (rc <= 0) { + fprintf(stderr, "bye\n"); + break; + } + bufoff += rc; + buffer[bufoff] = '\0'; + while (strchr(buffer, '\n')) { + char *ptr = strchr(buffer, '\n'); + *ptr = '\0'; + processline(buffer); + ptr++; + memmove(buffer, ptr, strlen(ptr)+1); + bufoff = 0; + } + } + zookeeper_process(zh, events); + } +#endif + if (to_send!=0) + fprintf(stderr,"Recvd %d responses for %d requests sent\n",recvd,sent); + zookeeper_close(zh); + return 0; +} diff --git a/src/c/src/hashtable/LICENSE.txt b/src/c/src/hashtable/LICENSE.txt new file mode 100644 index 00000000000..674a6245648 --- /dev/null +++ b/src/c/src/hashtable/LICENSE.txt @@ -0,0 +1,30 @@ +Copyright (c) 2002, 2004, Christopher Clark +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + + * Neither the name of the original author; nor the names of any contributors +may be used to endorse or promote products derived from this software +without specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/c/src/hashtable/hashtable.c b/src/c/src/hashtable/hashtable.c new file mode 100644 index 00000000000..caa5f6ccc03 --- /dev/null +++ b/src/c/src/hashtable/hashtable.c @@ -0,0 +1,274 @@ +/* Copyright (C) 2004 Christopher Clark */ + +#include "hashtable.h" +#include "hashtable_private.h" +#include +#include +#include +#include + +/* +Credit for primes table: Aaron Krowne + http://br.endernet.org/~akrowne/ + http://planetmath.org/encyclopedia/GoodHashTablePrimes.html +*/ +static const unsigned int primes[] = { +53, 97, 193, 389, +769, 1543, 3079, 6151, +12289, 24593, 49157, 98317, +196613, 393241, 786433, 1572869, +3145739, 6291469, 12582917, 25165843, +50331653, 100663319, 201326611, 402653189, +805306457, 1610612741 +}; +const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); +const float max_load_factor = 0.65; + +/*****************************************************************************/ +struct hashtable * +create_hashtable(unsigned int minsize, + unsigned int (*hashf) (void*), + int (*eqf) (void*,void*)) +{ + struct hashtable *h; + unsigned int pindex, size = primes[0]; + /* Check requested hashtable isn't too large */ + if (minsize > (1u << 30)) return NULL; + /* Enforce size as prime */ + for (pindex=0; pindex < prime_table_length; pindex++) { + if (primes[pindex] > minsize) { size = primes[pindex]; break; } + } + h = (struct hashtable *)malloc(sizeof(struct hashtable)); + if (NULL == h) return NULL; /*oom*/ + h->table = (struct entry **)malloc(sizeof(struct entry*) * size); + if (NULL == h->table) { free(h); return NULL; } /*oom*/ + memset(h->table, 0, size * sizeof(struct entry *)); + h->tablelength = size; + h->primeindex = pindex; + h->entrycount = 0; + h->hashfn = hashf; + h->eqfn = eqf; + h->loadlimit = (unsigned int) ceil(size * max_load_factor); + return h; +} + +/*****************************************************************************/ +unsigned int +hash(struct hashtable *h, void *k) +{ + /* Aim to protect against poor hash functions by adding logic here + * - logic taken from java 1.4 hashtable source */ + unsigned int i = h->hashfn(k); + i += ~(i << 9); + i ^= ((i >> 14) | (i << 18)); /* >>> */ + i += (i << 4); + i ^= ((i >> 10) | (i << 22)); /* >>> */ + return i; +} + +/*****************************************************************************/ +static int +hashtable_expand(struct hashtable *h) +{ + /* Double the size of the table to accomodate more entries */ + struct entry **newtable; + struct entry *e; + struct entry **pE; + unsigned int newsize, i, index; + /* Check we're not hitting max capacity */ + if (h->primeindex == (prime_table_length - 1)) return 0; + newsize = primes[++(h->primeindex)]; + + newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); + if (NULL != newtable) + { + memset(newtable, 0, newsize * sizeof(struct entry *)); + /* This algorithm is not 'stable'. ie. it reverses the list + * when it transfers entries between the tables */ + for (i = 0; i < h->tablelength; i++) { + while (NULL != (e = h->table[i])) { + h->table[i] = e->next; + index = indexFor(newsize,e->h); + e->next = newtable[index]; + newtable[index] = e; + } + } + free(h->table); + h->table = newtable; + } + /* Plan B: realloc instead */ + else + { + newtable = (struct entry **) + realloc(h->table, newsize * sizeof(struct entry *)); + if (NULL == newtable) { (h->primeindex)--; return 0; } + h->table = newtable; + memset(newtable[h->tablelength], 0, newsize - h->tablelength); + for (i = 0; i < h->tablelength; i++) { + for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { + index = indexFor(newsize,e->h); + if (index == i) + { + pE = &(e->next); + } + else + { + *pE = e->next; + e->next = newtable[index]; + newtable[index] = e; + } + } + } + } + h->tablelength = newsize; + h->loadlimit = (unsigned int) ceil(newsize * max_load_factor); + return -1; +} + +/*****************************************************************************/ +unsigned int +hashtable_count(struct hashtable *h) +{ + return h->entrycount; +} + +/*****************************************************************************/ +int +hashtable_insert(struct hashtable *h, void *k, void *v) +{ + /* This method allows duplicate keys - but they shouldn't be used */ + unsigned int index; + struct entry *e; + if (++(h->entrycount) > h->loadlimit) + { + /* Ignore the return value. If expand fails, we should + * still try cramming just this value into the existing table + * -- we may not have memory for a larger table, but one more + * element may be ok. Next time we insert, we'll try expanding again.*/ + hashtable_expand(h); + } + e = (struct entry *)malloc(sizeof(struct entry)); + if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ + e->h = hash(h,k); + index = indexFor(h->tablelength,e->h); + e->k = k; + e->v = v; + e->next = h->table[index]; + h->table[index] = e; + return -1; +} + +/*****************************************************************************/ +void * /* returns value associated with key */ +hashtable_search(struct hashtable *h, void *k) +{ + struct entry *e; + unsigned int hashvalue, index; + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hashvalue); + e = h->table[index]; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; + e = e->next; + } + return NULL; +} + +/*****************************************************************************/ +void * /* returns value associated with key */ +hashtable_remove(struct hashtable *h, void *k) +{ + /* TODO: consider compacting the table when the load factor drops enough, + * or provide a 'compact' method. */ + + struct entry *e; + struct entry **pE; + void *v; + unsigned int hashvalue, index; + + hashvalue = hash(h,k); + index = indexFor(h->tablelength, hashvalue); + pE = &(h->table[index]); + e = *pE; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + *pE = e->next; + h->entrycount--; + v = e->v; + freekey(e->k); + free(e); + return v; + } + pE = &(e->next); + e = e->next; + } + return NULL; +} + +/*****************************************************************************/ +/* destroy */ +void +hashtable_destroy(struct hashtable *h, int free_values) +{ + unsigned int i; + struct entry *e, *f; + struct entry **table = h->table; + if (free_values) + { + for (i = 0; i < h->tablelength; i++) + { + e = table[i]; + while (NULL != e) + { f = e; e = e->next; freekey(f->k); free(f->v); free(f); } + } + } + else + { + for (i = 0; i < h->tablelength; i++) + { + e = table[i]; + while (NULL != e) + { f = e; e = e->next; freekey(f->k); free(f); } + } + } + free(h->table); + free(h); +} + +/* + * Copyright (c) 2002, Christopher Clark + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ diff --git a/src/c/src/hashtable/hashtable.h b/src/c/src/hashtable/hashtable.h new file mode 100644 index 00000000000..cbead182987 --- /dev/null +++ b/src/c/src/hashtable/hashtable.h @@ -0,0 +1,209 @@ +/* Copyright (C) 2002 Christopher Clark */ + +#ifndef __HASHTABLE_CWC22_H__ +#define __HASHTABLE_CWC22_H__ +#ifdef WIN32 +#include "winconfig.h" +#endif +#ifdef __cplusplus +extern "C" { +#endif + +struct hashtable; + +/* Example of use: + * + * struct hashtable *h; + * struct some_key *k; + * struct some_value *v; + * + * static unsigned int hash_from_key_fn( void *k ); + * static int keys_equal_fn ( void *key1, void *key2 ); + * + * h = create_hashtable(16, hash_from_key_fn, keys_equal_fn); + * k = (struct some_key *) malloc(sizeof(struct some_key)); + * v = (struct some_value *) malloc(sizeof(struct some_value)); + * + * (initialise k and v to suitable values) + * + * if (! hashtable_insert(h,k,v) ) + * { exit(-1); } + * + * if (NULL == (found = hashtable_search(h,k) )) + * { printf("not found!"); } + * + * if (NULL == (found = hashtable_remove(h,k) )) + * { printf("Not found\n"); } + * + */ + +/* Macros may be used to define type-safe(r) hashtable access functions, with + * methods specialized to take known key and value types as parameters. + * + * Example: + * + * Insert this at the start of your file: + * + * DEFINE_HASHTABLE_INSERT(insert_some, struct some_key, struct some_value); + * DEFINE_HASHTABLE_SEARCH(search_some, struct some_key, struct some_value); + * DEFINE_HASHTABLE_REMOVE(remove_some, struct some_key, struct some_value); + * + * This defines the functions 'insert_some', 'search_some' and 'remove_some'. + * These operate just like hashtable_insert etc., with the same parameters, + * but their function signatures have 'struct some_key *' rather than + * 'void *', and hence can generate compile time errors if your program is + * supplying incorrect data as a key (and similarly for value). + * + * Note that the hash and key equality functions passed to create_hashtable + * still take 'void *' parameters instead of 'some key *'. This shouldn't be + * a difficult issue as they're only defined and passed once, and the other + * functions will ensure that only valid keys are supplied to them. + * + * The cost for this checking is increased code size and runtime overhead + * - if performance is important, it may be worth switching back to the + * unsafe methods once your program has been debugged with the safe methods. + * This just requires switching to some simple alternative defines - eg: + * #define insert_some hashtable_insert + * + */ + +/***************************************************************************** + * create_hashtable + + * @name create_hashtable + * @param minsize minimum initial size of hashtable + * @param hashfunction function for hashing keys + * @param key_eq_fn function for determining key equality + * @return newly created hashtable or NULL on failure + */ + +struct hashtable * +create_hashtable(unsigned int minsize, + unsigned int (*hashfunction) (void*), + int (*key_eq_fn) (void*,void*)); + +/***************************************************************************** + * hashtable_insert + + * @name hashtable_insert + * @param h the hashtable to insert into + * @param k the key - hashtable claims ownership and will free on removal + * @param v the value - does not claim ownership + * @return non-zero for successful insertion + * + * This function will cause the table to expand if the insertion would take + * the ratio of entries to table size over the maximum load factor. + * + * This function does not check for repeated insertions with a duplicate key. + * The value returned when using a duplicate key is undefined -- when + * the hashtable changes size, the order of retrieval of duplicate key + * entries is reversed. + * If in doubt, remove before insert. + */ + +int +hashtable_insert(struct hashtable *h, void *k, void *v); + +#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ +int fnname (struct hashtable *h, keytype *k, valuetype *v) \ +{ \ + return hashtable_insert(h,k,v); \ +} + +/***************************************************************************** + * hashtable_search + + * @name hashtable_search + * @param h the hashtable to search + * @param k the key to search for - does not claim ownership + * @return the value associated with the key, or NULL if none found + */ + +void * +hashtable_search(struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ +valuetype * fnname (struct hashtable *h, keytype *k) \ +{ \ + return (valuetype *) (hashtable_search(h,k)); \ +} + +/***************************************************************************** + * hashtable_remove + + * @name hashtable_remove + * @param h the hashtable to remove the item from + * @param k the key to search for - does not claim ownership + * @return the value associated with the key, or NULL if none found + */ + +void * /* returns value */ +hashtable_remove(struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ +valuetype * fnname (struct hashtable *h, keytype *k) \ +{ \ + return (valuetype *) (hashtable_remove(h,k)); \ +} + + +/***************************************************************************** + * hashtable_count + + * @name hashtable_count + * @param h the hashtable + * @return the number of items stored in the hashtable + */ +unsigned int +hashtable_count(struct hashtable *h); + + +/***************************************************************************** + * hashtable_destroy + + * @name hashtable_destroy + * @param h the hashtable + * @param free_values whether to call 'free' on the remaining values + */ + +void +hashtable_destroy(struct hashtable *h, int free_values); + +#ifdef __cplusplus +} +#endif + +#endif /* __HASHTABLE_CWC22_H__ */ + +/* + * Copyright (c) 2002, Christopher Clark + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ diff --git a/src/c/src/hashtable/hashtable_itr.c b/src/c/src/hashtable/hashtable_itr.c new file mode 100644 index 00000000000..defac691f03 --- /dev/null +++ b/src/c/src/hashtable/hashtable_itr.c @@ -0,0 +1,176 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#include "hashtable.h" +#include "hashtable_private.h" +#include "hashtable_itr.h" +#include /* defines NULL */ + +/*****************************************************************************/ +/* hashtable_iterator - iterator constructor */ + +struct hashtable_itr * +hashtable_iterator(struct hashtable *h) +{ + unsigned int i, tablelength; + struct hashtable_itr *itr = (struct hashtable_itr *) + malloc(sizeof(struct hashtable_itr)); + if (NULL == itr) return NULL; + itr->h = h; + itr->e = NULL; + itr->parent = NULL; + tablelength = h->tablelength; + itr->index = tablelength; + if (0 == h->entrycount) return itr; + + for (i = 0; i < tablelength; i++) + { + if (NULL != h->table[i]) + { + itr->e = h->table[i]; + itr->index = i; + break; + } + } + return itr; +} + +/*****************************************************************************/ +/* advance - advance the iterator to the next element + * returns zero if advanced to end of table */ + +int +hashtable_iterator_advance(struct hashtable_itr *itr) +{ + unsigned int j,tablelength; + struct entry **table; + struct entry *next; + if (NULL == itr->e) return 0; /* stupidity check */ + + next = itr->e->next; + if (NULL != next) + { + itr->parent = itr->e; + itr->e = next; + return -1; + } + tablelength = itr->h->tablelength; + itr->parent = NULL; + if (tablelength <= (j = ++(itr->index))) + { + itr->e = NULL; + return 0; + } + table = itr->h->table; + while (NULL == (next = table[j])) + { + if (++j >= tablelength) + { + itr->index = tablelength; + itr->e = NULL; + return 0; + } + } + itr->index = j; + itr->e = next; + return -1; +} + +/*****************************************************************************/ +/* remove - remove the entry at the current iterator position + * and advance the iterator, if there is a successive + * element. + * If you want the value, read it before you remove: + * beware memory leaks if you don't. + * Returns zero if end of iteration. */ + +int +hashtable_iterator_remove(struct hashtable_itr *itr) +{ + struct entry *remember_e, *remember_parent; + int ret; + + /* Do the removal */ + if (NULL == (itr->parent)) + { + /* element is head of a chain */ + itr->h->table[itr->index] = itr->e->next; + } else { + /* element is mid-chain */ + itr->parent->next = itr->e->next; + } + /* itr->e is now outside the hashtable */ + remember_e = itr->e; + itr->h->entrycount--; + freekey(remember_e->k); + + /* Advance the iterator, correcting the parent */ + remember_parent = itr->parent; + ret = hashtable_iterator_advance(itr); + if (itr->parent == remember_e) { itr->parent = remember_parent; } + free(remember_e); + return ret; +} + +/*****************************************************************************/ +int /* returns zero if not found */ +hashtable_iterator_search(struct hashtable_itr *itr, + struct hashtable *h, void *k) +{ + struct entry *e, *parent; + unsigned int hashvalue, index; + + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hashvalue); + + e = h->table[index]; + parent = NULL; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + itr->index = index; + itr->e = e; + itr->parent = parent; + itr->h = h; + return -1; + } + parent = e; + e = e->next; + } + return 0; +} + + +/* + * Copyright (c) 2002, 2004, Christopher Clark + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ diff --git a/src/c/src/hashtable/hashtable_itr.h b/src/c/src/hashtable/hashtable_itr.h new file mode 100644 index 00000000000..30379c7ee1e --- /dev/null +++ b/src/c/src/hashtable/hashtable_itr.h @@ -0,0 +1,119 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#ifndef __HASHTABLE_ITR_CWC22__ +#define __HASHTABLE_ITR_CWC22__ +#include "hashtable.h" +#include "hashtable_private.h" /* needed to enable inlining */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*****************************************************************************/ +/* This struct is only concrete here to allow the inlining of two of the + * accessor functions. */ +struct hashtable_itr +{ + struct hashtable *h; + struct entry *e; + struct entry *parent; + unsigned int index; +}; + + +/*****************************************************************************/ +/* hashtable_iterator + */ + +struct hashtable_itr * +hashtable_iterator(struct hashtable *h); + +/*****************************************************************************/ +/* hashtable_iterator_key + * - return the value of the (key,value) pair at the current position */ + +static inline void * +hashtable_iterator_key(struct hashtable_itr *i) +{ + return i->e->k; +} + +/*****************************************************************************/ +/* value - return the value of the (key,value) pair at the current position */ + +static inline void * +hashtable_iterator_value(struct hashtable_itr *i) +{ + return i->e->v; +} + +/*****************************************************************************/ +/* advance - advance the iterator to the next element + * returns zero if advanced to end of table */ + +int +hashtable_iterator_advance(struct hashtable_itr *itr); + +/*****************************************************************************/ +/* remove - remove current element and advance the iterator to the next element + * NB: if you need the value to free it, read it before + * removing. ie: beware memory leaks! + * returns zero if advanced to end of table */ + +int +hashtable_iterator_remove(struct hashtable_itr *itr); + +/*****************************************************************************/ +/* search - overwrite the supplied iterator, to point to the entry + * matching the supplied key. + h points to the hashtable to be searched. + * returns zero if not found. */ +int +hashtable_iterator_search(struct hashtable_itr *itr, + struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ +int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ +{ \ + return (hashtable_iterator_search(i,h,k)); \ +} + + +#ifdef __cplusplus +} +#endif + +#endif /* __HASHTABLE_ITR_CWC22__*/ + +/* + * Copyright (c) 2002, 2004, Christopher Clark + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ diff --git a/src/c/src/hashtable/hashtable_private.h b/src/c/src/hashtable/hashtable_private.h new file mode 100644 index 00000000000..3e95f600577 --- /dev/null +++ b/src/c/src/hashtable/hashtable_private.h @@ -0,0 +1,85 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#ifndef __HASHTABLE_PRIVATE_CWC22_H__ +#define __HASHTABLE_PRIVATE_CWC22_H__ + +#include "hashtable.h" + +/*****************************************************************************/ +struct entry +{ + void *k, *v; + unsigned int h; + struct entry *next; +}; + +struct hashtable { + unsigned int tablelength; + struct entry **table; + unsigned int entrycount; + unsigned int loadlimit; + unsigned int primeindex; + unsigned int (*hashfn) (void *k); + int (*eqfn) (void *k1, void *k2); +}; + +/*****************************************************************************/ +unsigned int +hash(struct hashtable *h, void *k); + +/*****************************************************************************/ +/* indexFor */ +static inline unsigned int +indexFor(unsigned int tablelength, unsigned int hashvalue) { + return (hashvalue % tablelength); +}; + +/* Only works if tablelength == 2^N */ +/*static inline unsigned int +indexFor(unsigned int tablelength, unsigned int hashvalue) +{ + return (hashvalue & (tablelength - 1u)); +} +*/ + +/*****************************************************************************/ +#define freekey(X) free(X) +/*define freekey(X) ; */ + + +/*****************************************************************************/ + +#endif /* __HASHTABLE_PRIVATE_CWC22_H__*/ + +/* + * Copyright (c) 2002, Christopher Clark + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ diff --git a/src/c/src/load_gen.c b/src/c/src/load_gen.c new file mode 100644 index 00000000000..b062af6dd6e --- /dev/null +++ b/src/c/src/load_gen.c @@ -0,0 +1,286 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "zookeeper_log.h" +#include +#ifndef WIN32 +#ifdef THREADED +#include +#endif +#else +#include "win32port.h" +#endif +#include +#include + +static zhandle_t *zh; + +static int shutdownThisThing=0; + +// ***************************************************************************** +// +static pthread_cond_t cond=PTHREAD_COND_INITIALIZER; +static pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER; + +static pthread_cond_t counterCond=PTHREAD_COND_INITIALIZER; +static pthread_mutex_t counterLock=PTHREAD_MUTEX_INITIALIZER; +static int counter; + + + +void ensureConnected(){ + pthread_mutex_lock(&lock); + while (zoo_state(zh)!=ZOO_CONNECTED_STATE) { + pthread_cond_wait(&cond,&lock); + } + pthread_mutex_unlock(&lock); +} + +void incCounter(int delta){ + pthread_mutex_lock(&counterLock); + counter+=delta; + pthread_cond_broadcast(&counterCond); + pthread_mutex_unlock(&counterLock); + +} +void setCounter(int cnt){ + pthread_mutex_lock(&counterLock); + counter=cnt; + pthread_cond_broadcast(&counterCond); + pthread_mutex_unlock(&counterLock); + +} +void waitCounter(){ + pthread_mutex_lock(&counterLock); + while (counter>0) { + pthread_cond_wait(&counterCond,&counterLock); + } + pthread_mutex_unlock(&counterLock); +} + +void listener(zhandle_t *zzh, int type, int state, const char *path,void* ctx) { + if (type == ZOO_SESSION_EVENT) { + if (state == ZOO_CONNECTED_STATE || state == ZOO_READONLY_STATE) { + pthread_mutex_lock(&lock); + pthread_cond_broadcast(&cond); + pthread_mutex_unlock(&lock); + } + setCounter(0); + } +} + +void create_completion(int rc, const char *name, const void *data) { + incCounter(-1); + if(rc!=ZOK){ + LOG_ERROR(LOGSTREAM, "Failed to create a node rc=%d",rc); + } +} + +int doCreateNodes(const char* root, int count){ + char nodeName[1024]; + int i; + for(i=0; idata) { + int32_t i; + for(i=0;icount; i++) { + free(v->data[i]); + } + free(v->data); + v->data = 0; + } + return 0; +} + +static int deletedCounter; + +int recursiveDelete(const char* root){ + struct String_vector children; + int i; + int rc=zoo_get_children(zh,root,0,&children); + if(rc!=ZNONODE){ + if(rc!=ZOK){ + LOG_ERROR(LOGSTREAM, "Failed to get children of %s, rc=%d",root,rc); + return rc; + } + for(i=0;i +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#include +#include +#include +#endif + +int zoo_lock_auth(zhandle_t *zh) +{ + return pthread_mutex_lock(&zh->auth_h.lock); +} +int zoo_unlock_auth(zhandle_t *zh) +{ + return pthread_mutex_unlock(&zh->auth_h.lock); +} +int lock_buffer_list(buffer_head_t *l) +{ + return pthread_mutex_lock(&l->lock); +} +int unlock_buffer_list(buffer_head_t *l) +{ + return pthread_mutex_unlock(&l->lock); +} +int lock_completion_list(completion_head_t *l) +{ + return pthread_mutex_lock(&l->lock); +} +int unlock_completion_list(completion_head_t *l) +{ + pthread_cond_broadcast(&l->cond); + return pthread_mutex_unlock(&l->lock); +} +struct sync_completion *alloc_sync_completion(void) +{ + struct sync_completion *sc = (struct sync_completion*)calloc(1, sizeof(struct sync_completion)); + if (sc) { + pthread_cond_init(&sc->cond, 0); + pthread_mutex_init(&sc->lock, 0); + } + return sc; +} +int wait_sync_completion(struct sync_completion *sc) +{ + pthread_mutex_lock(&sc->lock); + while (!sc->complete) { + pthread_cond_wait(&sc->cond, &sc->lock); + } + pthread_mutex_unlock(&sc->lock); + return 0; +} + +void free_sync_completion(struct sync_completion *sc) +{ + if (sc) { + pthread_mutex_destroy(&sc->lock); + pthread_cond_destroy(&sc->cond); + free(sc); + } +} + +void notify_sync_completion(struct sync_completion *sc) +{ + pthread_mutex_lock(&sc->lock); + sc->complete = 1; + pthread_cond_broadcast(&sc->cond); + pthread_mutex_unlock(&sc->lock); +} + +int process_async(int outstanding_sync) +{ + return 0; +} + +#ifdef WIN32 +unsigned __stdcall do_io( void * ); +unsigned __stdcall do_completion( void * ); + +int handle_error(zhandle_t* zh, SOCKET sock, char* message) +{ + LOG_ERROR(LOGCALLBACK(zh), "%s. %d",message, WSAGetLastError()); + closesocket (sock); + return -1; +} + +//--create socket pair for interupting selects. +int create_socket_pair(zhandle_t* zh, SOCKET fds[2]) +{ + struct sockaddr_in inaddr; + struct sockaddr addr; + int yes=1; + int len=0; + + SOCKET lst=socket(AF_INET, SOCK_STREAM,IPPROTO_TCP); + if (lst == INVALID_SOCKET ){ + LOG_ERROR(LOGCALLBACK(zh), "Error creating socket. %d",WSAGetLastError()); + return -1; + } + memset(&inaddr, 0, sizeof(inaddr)); + memset(&addr, 0, sizeof(addr)); + inaddr.sin_family = AF_INET; + inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + inaddr.sin_port = 0; //--system assigns the port + + if ( setsockopt(lst,SOL_SOCKET,SO_REUSEADDR,(char*)&yes,sizeof(yes)) == SOCKET_ERROR ) { + return handle_error(zh, lst,"Error trying to set socket option."); + } + if (bind(lst,(struct sockaddr *)&inaddr,sizeof(inaddr)) == SOCKET_ERROR){ + return handle_error(zh, lst,"Error trying to bind socket."); + } + if (listen(lst,1) == SOCKET_ERROR){ + return handle_error(zh, lst,"Error trying to listen on socket."); + } + len=sizeof(inaddr); + getsockname(lst, &addr,&len); + fds[0]=socket(AF_INET, SOCK_STREAM,0); + if (connect(fds[0],&addr,len) == SOCKET_ERROR){ + return handle_error(zh, lst, "Error while connecting to socket."); + } + if ((fds[1]=accept(lst,0,0)) == INVALID_SOCKET){ + closesocket(fds[0]); + return handle_error(zh, lst, "Error while accepting socket connection."); + } + closesocket(lst); + return 0; +} +#else +void *do_io(void *); +void *do_completion(void *); +#endif + + +int wakeup_io_thread(zhandle_t *zh); + +#ifdef WIN32 +static int set_nonblock(SOCKET fd){ + ULONG nonblocking_flag = 1; + if (ioctlsocket(fd, FIONBIO, &nonblocking_flag) == 0) + return 1; + else + return -1; +} +#else +static int set_nonblock(int fd){ + long l = fcntl(fd, F_GETFL); + if(l & O_NONBLOCK) return 0; + return fcntl(fd, F_SETFL, l | O_NONBLOCK); +} +#endif + +void wait_for_others(zhandle_t* zh) +{ + struct adaptor_threads* adaptor=zh->adaptor_priv; + pthread_mutex_lock(&adaptor->lock); + while(adaptor->threadsToWait>0) + pthread_cond_wait(&adaptor->cond,&adaptor->lock); + pthread_mutex_unlock(&adaptor->lock); +} + +void notify_thread_ready(zhandle_t* zh) +{ + struct adaptor_threads* adaptor=zh->adaptor_priv; + pthread_mutex_lock(&adaptor->lock); + adaptor->threadsToWait--; + pthread_cond_broadcast(&adaptor->cond); + while(adaptor->threadsToWait>0) + pthread_cond_wait(&adaptor->cond,&adaptor->lock); + pthread_mutex_unlock(&adaptor->lock); +} + + +void start_threads(zhandle_t* zh) +{ + int rc = 0; + struct adaptor_threads* adaptor=zh->adaptor_priv; + pthread_cond_init(&adaptor->cond,0); + pthread_mutex_init(&adaptor->lock,0); + adaptor->threadsToWait=2; // wait for 2 threads before opening the barrier + + // use api_prolog() to make sure zhandle doesn't get destroyed + // while initialization is in progress + api_prolog(zh); + LOG_DEBUG(LOGCALLBACK(zh), "starting threads..."); + rc=pthread_create(&adaptor->io, 0, do_io, zh); + assert("pthread_create() failed for the IO thread"&&!rc); + rc=pthread_create(&adaptor->completion, 0, do_completion, zh); + assert("pthread_create() failed for the completion thread"&&!rc); + wait_for_others(zh); + api_epilog(zh, 0); +} + +int adaptor_init(zhandle_t *zh) +{ + pthread_mutexattr_t recursive_mx_attr; + struct adaptor_threads *adaptor_threads = calloc(1, sizeof(*adaptor_threads)); + if (!adaptor_threads) { + LOG_ERROR(LOGCALLBACK(zh), "Out of memory"); + return -1; + } + + /* We use a pipe for interrupting select() in unix/sol and socketpair in windows. */ +#ifdef WIN32 + if (create_socket_pair(zh, adaptor_threads->self_pipe) == -1){ + LOG_ERROR(LOGCALLBACK(zh), "Can't make a socket."); +#else + if(pipe(adaptor_threads->self_pipe)==-1) { + LOG_ERROR(LOGCALLBACK(zh), "Can't make a pipe %d",errno); +#endif + free(adaptor_threads); + return -1; + } + set_nonblock(adaptor_threads->self_pipe[1]); + set_nonblock(adaptor_threads->self_pipe[0]); + + pthread_mutex_init(&zh->auth_h.lock,0); + + zh->adaptor_priv = adaptor_threads; + pthread_mutex_init(&zh->to_process.lock,0); + pthread_mutex_init(&adaptor_threads->zh_lock,0); + pthread_mutex_init(&adaptor_threads->reconfig_lock,0); + // to_send must be recursive mutex + pthread_mutexattr_init(&recursive_mx_attr); + pthread_mutexattr_settype(&recursive_mx_attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&zh->to_send.lock,&recursive_mx_attr); + pthread_mutexattr_destroy(&recursive_mx_attr); + + pthread_mutex_init(&zh->sent_requests.lock,0); + pthread_cond_init(&zh->sent_requests.cond,0); + pthread_mutex_init(&zh->completions_to_process.lock,0); + pthread_cond_init(&zh->completions_to_process.cond,0); + start_threads(zh); + return 0; +} + +void adaptor_finish(zhandle_t *zh) +{ + struct adaptor_threads *adaptor_threads; + // make sure zh doesn't get destroyed until after we're done here + api_prolog(zh); + adaptor_threads = zh->adaptor_priv; + if(adaptor_threads==0) { + api_epilog(zh,0); + return; + } + + if(!pthread_equal(adaptor_threads->io,pthread_self())){ + wakeup_io_thread(zh); + pthread_join(adaptor_threads->io, 0); + }else + pthread_detach(adaptor_threads->io); + + if(!pthread_equal(adaptor_threads->completion,pthread_self())){ + pthread_mutex_lock(&zh->completions_to_process.lock); + pthread_cond_broadcast(&zh->completions_to_process.cond); + pthread_mutex_unlock(&zh->completions_to_process.lock); + pthread_join(adaptor_threads->completion, 0); + }else + pthread_detach(adaptor_threads->completion); + + api_epilog(zh,0); +} + +void adaptor_destroy(zhandle_t *zh) +{ + struct adaptor_threads *adaptor = zh->adaptor_priv; + if(adaptor==0) return; + + pthread_cond_destroy(&adaptor->cond); + pthread_mutex_destroy(&adaptor->lock); + pthread_mutex_destroy(&zh->to_process.lock); + pthread_mutex_destroy(&zh->to_send.lock); + pthread_mutex_destroy(&zh->sent_requests.lock); + pthread_cond_destroy(&zh->sent_requests.cond); + pthread_mutex_destroy(&zh->completions_to_process.lock); + pthread_cond_destroy(&zh->completions_to_process.cond); + pthread_mutex_destroy(&adaptor->zh_lock); + + pthread_mutex_destroy(&zh->auth_h.lock); + + close(adaptor->self_pipe[0]); + close(adaptor->self_pipe[1]); + free(adaptor); + zh->adaptor_priv=0; +} + +int wakeup_io_thread(zhandle_t *zh) +{ + struct adaptor_threads *adaptor_threads = zh->adaptor_priv; + char c=0; +#ifndef WIN32 + return write(adaptor_threads->self_pipe[1],&c,1)==1? ZOK: ZSYSTEMERROR; +#else + return send(adaptor_threads->self_pipe[1], &c, 1, 0)==1? ZOK: ZSYSTEMERROR; +#endif +} + +int adaptor_send_queue(zhandle_t *zh, int timeout) +{ + if(!zh->close_requested) + return wakeup_io_thread(zh); + // don't rely on the IO thread to send the messages if the app has + // requested to close + return flush_send_queue(zh, timeout); +} + +/* These two are declared here because we will run the event loop + * and not the client */ +#ifdef WIN32 +int zookeeper_interest(zhandle_t *zh, SOCKET *fd, int *interest, + struct timeval *tv); +#else +int zookeeper_interest(zhandle_t *zh, int *fd, int *interest, + struct timeval *tv); +#endif +int zookeeper_process(zhandle_t *zh, int events); + +#ifdef WIN32 +unsigned __stdcall do_io( void * v) +#else +void *do_io(void *v) +#endif +{ + zhandle_t *zh = (zhandle_t*)v; +#ifndef WIN32 + struct pollfd fds[2]; + struct adaptor_threads *adaptor_threads = zh->adaptor_priv; + + api_prolog(zh); + notify_thread_ready(zh); + LOG_DEBUG(LOGCALLBACK(zh), "started IO thread"); + fds[0].fd=adaptor_threads->self_pipe[0]; + fds[0].events=POLLIN; + while(!zh->close_requested) { + zh->io_count++; + struct timeval tv; + int fd; + int interest; + int timeout; + int maxfd=1; + int rc; + + zookeeper_interest(zh, &fd, &interest, &tv); + if (fd != -1) { + fds[1].fd=fd; + fds[1].events=(interest&ZOOKEEPER_READ)?POLLIN:0; + fds[1].events|=(interest&ZOOKEEPER_WRITE)?POLLOUT:0; + maxfd=2; + } + timeout=tv.tv_sec * 1000 + (tv.tv_usec/1000); + + poll(fds,maxfd,timeout); + if (fd != -1) { + interest=(fds[1].revents&POLLIN)?ZOOKEEPER_READ:0; + interest|=((fds[1].revents&POLLOUT)||(fds[1].revents&POLLHUP))?ZOOKEEPER_WRITE:0; + } + if(fds[0].revents&POLLIN){ + // flush the pipe + char b[128]; + while(read(adaptor_threads->self_pipe[0],b,sizeof(b))==sizeof(b)){} + } +#else + fd_set rfds, wfds; + struct adaptor_threads *adaptor_threads = zh->adaptor_priv; + api_prolog(zh); + notify_thread_ready(zh); + LOG_DEBUG(LOGCALLBACK(zh), "started IO thread"); + + while(!zh->close_requested) { + struct timeval tv; + SOCKET fd; + int interest; + int rc; + + zookeeper_interest(zh, &fd, &interest, &tv); + + // FD_ZERO is cheap on Win32, it just sets count of elements to zero. + // It needs to be done to ensure no stale entries. + FD_ZERO(&rfds); + FD_ZERO(&wfds); + + if (fd != -1) { + if (interest&ZOOKEEPER_READ) { + FD_SET(fd, &rfds); + } + + if (interest&ZOOKEEPER_WRITE) { + FD_SET(fd, &wfds); + } + } + + // Always interested in self_pipe. + FD_SET(adaptor_threads->self_pipe[0], &rfds); + + rc = select(/* unused */0, &rfds, &wfds, NULL, &tv); + if (rc > 0) { + interest=(FD_ISSET(fd, &rfds))? ZOOKEEPER_READ: 0; + interest|=(FD_ISSET(fd, &wfds))? ZOOKEEPER_WRITE: 0; + + if (FD_ISSET(adaptor_threads->self_pipe[0], &rfds)){ + // flush the pipe/socket + char b[128]; + while(recv(adaptor_threads->self_pipe[0],b,sizeof(b), 0)==sizeof(b)){} + } + } + else if (rc < 0) { + LOG_ERROR(LOGCALLBACK(zh), ("select() failed %d [%d].", rc, WSAGetLastError())); + + // Clear interest events for zookeeper_process if select() fails. + interest = 0; + } + +#endif + // dispatch zookeeper events + rc = zookeeper_process(zh, interest); + // check the current state of the zhandle and terminate + // if it is_unrecoverable() + if(is_unrecoverable(zh)) + break; + } + api_epilog(zh, 0); + LOG_DEBUG(LOGCALLBACK(zh), "IO thread terminated"); + return 0; +} + +#ifdef WIN32 +unsigned __stdcall do_completion( void * v) +#else +void *do_completion(void *v) +#endif +{ + zhandle_t *zh = v; + api_prolog(zh); + notify_thread_ready(zh); + LOG_DEBUG(LOGCALLBACK(zh), "started completion thread"); + while(!zh->close_requested) { + pthread_mutex_lock(&zh->completions_to_process.lock); + while(!zh->completions_to_process.head && !zh->close_requested) { + pthread_cond_wait(&zh->completions_to_process.cond, &zh->completions_to_process.lock); + } + pthread_mutex_unlock(&zh->completions_to_process.lock); + process_completions(zh); + } + api_epilog(zh, 0); + LOG_DEBUG(LOGCALLBACK(zh), "completion thread terminated"); + return 0; +} + +int32_t inc_ref_counter(zhandle_t* zh,int i) +{ + int incr=(i<0?-1:(i>0?1:0)); + // fetch_and_add implements atomic post-increment + int v=fetch_and_add(&zh->ref_counter,incr); + // inc_ref_counter wants pre-increment + v+=incr; // simulate pre-increment + return v; +} + +int32_t fetch_and_add(volatile int32_t* operand, int incr) +{ +#ifndef WIN32 + return __sync_fetch_and_add(operand, incr); +#else + return InterlockedExchangeAdd(operand, incr); +#endif +} + +// make sure the static xid is initialized before any threads started +__attribute__((constructor)) int32_t get_xid() +{ + static int32_t xid = -1; + if (xid == -1) { + xid = time(0); + } + return fetch_and_add(&xid,1); +} + +int lock_reconfig(struct _zhandle *zh) +{ + struct adaptor_threads *adaptor = zh->adaptor_priv; + if (adaptor) { + return pthread_mutex_lock(&adaptor->reconfig_lock); + } else { + return 0; + } +} +int unlock_reconfig(struct _zhandle *zh) +{ + struct adaptor_threads *adaptor = zh->adaptor_priv; + if (adaptor) { + return pthread_mutex_unlock(&adaptor->reconfig_lock); + } else { + return 0; + } +} + +int enter_critical(zhandle_t* zh) +{ + struct adaptor_threads *adaptor = zh->adaptor_priv; + if (adaptor) { + return pthread_mutex_lock(&adaptor->zh_lock); + } else { + return 0; + } +} + +int leave_critical(zhandle_t* zh) +{ + struct adaptor_threads *adaptor = zh->adaptor_priv; + if (adaptor) { + return pthread_mutex_unlock(&adaptor->zh_lock); + } else { + return 0; + } +} diff --git a/src/c/src/recordio.c b/src/c/src/recordio.c new file mode 100644 index 00000000000..07217c1e884 --- /dev/null +++ b/src/c/src/recordio.c @@ -0,0 +1,366 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#ifndef WIN32 +#include +#endif + +void deallocate_String(char **s) +{ + if (*s) + free(*s); + *s = 0; +} + +void deallocate_Buffer(struct buffer *b) +{ + if (b->buff) + free(b->buff); + b->buff = 0; +} + +struct buff_struct { + int32_t len; + int32_t off; + char *buffer; +}; + +static int resize_buffer(struct buff_struct *s, int newlen) +{ + char *buffer= NULL; + while (s->len < newlen) { + s->len *= 2; + } + buffer = (char*)realloc(s->buffer, s->len); + if (!buffer) { + s->buffer = 0; + return -ENOMEM; + } + s->buffer = buffer; + return 0; +} + +int oa_start_record(struct oarchive *oa, const char *tag) +{ + return 0; +} +int oa_end_record(struct oarchive *oa, const char *tag) +{ + return 0; +} +int oa_serialize_int(struct oarchive *oa, const char *tag, const int32_t *d) +{ + struct buff_struct *priv = oa->priv; + int32_t i = htonl(*d); + if ((priv->len - priv->off) < sizeof(i)) { + int rc = resize_buffer(priv, priv->len + sizeof(i)); + if (rc < 0) return rc; + } + memcpy(priv->buffer+priv->off, &i, sizeof(i)); + priv->off+=sizeof(i); + return 0; +} +int64_t zoo_htonll(int64_t v) +{ + int i = 0; + char *s = (char *)&v; + if (htonl(1) == 1) { + return v; + } + for (i = 0; i < 4; i++) { + int tmp = s[i]; + s[i] = s[8-i-1]; + s[8-i-1] = tmp; + } + + return v; +} + +int oa_serialize_long(struct oarchive *oa, const char *tag, const int64_t *d) +{ + const int64_t i = zoo_htonll(*d); + struct buff_struct *priv = oa->priv; + if ((priv->len - priv->off) < sizeof(i)) { + int rc = resize_buffer(priv, priv->len + sizeof(i)); + if (rc < 0) return rc; + } + memcpy(priv->buffer+priv->off, &i, sizeof(i)); + priv->off+=sizeof(i); + return 0; +} +int oa_start_vector(struct oarchive *oa, const char *tag, const int32_t *count) +{ + return oa_serialize_int(oa, tag, count); +} +int oa_end_vector(struct oarchive *oa, const char *tag) +{ + return 0; +} +int oa_serialize_bool(struct oarchive *oa, const char *name, const int32_t *i) +{ + //return oa_serialize_int(oa, name, i); + struct buff_struct *priv = oa->priv; + if ((priv->len - priv->off) < 1) { + int rc = resize_buffer(priv, priv->len + 1); + if (rc < 0) + return rc; + } + priv->buffer[priv->off] = (*i == 0 ? '\0' : '\1'); + priv->off++; + return 0; +} +static const int32_t negone = -1; +int oa_serialize_buffer(struct oarchive *oa, const char *name, + const struct buffer *b) +{ + struct buff_struct *priv = oa->priv; + int rc; + if (!b) { + return oa_serialize_int(oa, "len", &negone); + } + rc = oa_serialize_int(oa, "len", &b->len); + if (rc < 0) + return rc; + // this means a buffer of NUll + // with size of -1. This is + // waht we use in java serialization for NULL + if (b->len == -1) { + return rc; + } + if ((priv->len - priv->off) < b->len) { + rc = resize_buffer(priv, priv->len + b->len); + if (rc < 0) + return rc; + } + memcpy(priv->buffer+priv->off, b->buff, b->len); + priv->off += b->len; + return 0; +} +int oa_serialize_string(struct oarchive *oa, const char *name, char **s) +{ + struct buff_struct *priv = oa->priv; + int32_t len; + int rc; + if (!*s) { + oa_serialize_int(oa, "len", &negone); + return 0; + } + len = strlen(*s); + rc = oa_serialize_int(oa, "len", &len); + if (rc < 0) + return rc; + if ((priv->len - priv->off) < len) { + rc = resize_buffer(priv, priv->len + len); + if (rc < 0) + return rc; + } + memcpy(priv->buffer+priv->off, *s, len); + priv->off += len; + return 0; +} +int ia_start_record(struct iarchive *ia, const char *tag) +{ + return 0; +} +int ia_end_record(struct iarchive *ia, const char *tag) +{ + return 0; +} +int ia_deserialize_int(struct iarchive *ia, const char *tag, int32_t *count) +{ + struct buff_struct *priv = ia->priv; + if ((priv->len - priv->off) < sizeof(*count)) { + return -E2BIG; + } + memcpy(count, priv->buffer+priv->off, sizeof(*count)); + priv->off+=sizeof(*count); + *count = ntohl(*count); + return 0; +} + +int ia_deserialize_long(struct iarchive *ia, const char *tag, int64_t *count) +{ + struct buff_struct *priv = ia->priv; + int64_t v = 0; + if ((priv->len - priv->off) < sizeof(*count)) { + return -E2BIG; + } + memcpy(count, priv->buffer+priv->off, sizeof(*count)); + priv->off+=sizeof(*count); + v = zoo_htonll(*count); // htonll and ntohll do the same + *count = v; + return 0; +} +int ia_start_vector(struct iarchive *ia, const char *tag, int32_t *count) +{ + return ia_deserialize_int(ia, tag, count); +} +int ia_end_vector(struct iarchive *ia, const char *tag) +{ + return 0; +} +int ia_deserialize_bool(struct iarchive *ia, const char *name, int32_t *v) +{ + struct buff_struct *priv = ia->priv; + //fprintf(stderr, "Deserializing bool %d\n", priv->off); + //return ia_deserialize_int(ia, name, v); + if ((priv->len - priv->off) < 1) { + return -E2BIG; + } + *v = priv->buffer[priv->off]; + priv->off+=1; + //fprintf(stderr, "Deserializing bool end %d\n", priv->off); + return 0; +} +int ia_deserialize_buffer(struct iarchive *ia, const char *name, + struct buffer *b) +{ + struct buff_struct *priv = ia->priv; + int rc = ia_deserialize_int(ia, "len", &b->len); + if (rc < 0) + return rc; + if ((priv->len - priv->off) < b->len) { + return -E2BIG; + } + // set the buffer to null + if (b->len == -1) { + b->buff = NULL; + return rc; + } + b->buff = malloc(b->len); + if (!b->buff) { + return -ENOMEM; + } + memcpy(b->buff, priv->buffer+priv->off, b->len); + priv->off += b->len; + return 0; +} +int ia_deserialize_string(struct iarchive *ia, const char *name, char **s) +{ + struct buff_struct *priv = ia->priv; + int32_t len; + int rc = ia_deserialize_int(ia, "len", &len); + if (rc < 0) + return rc; + if ((priv->len - priv->off) < len) { + return -E2BIG; + } + if (len < 0) { + return -EINVAL; + } + *s = malloc(len+1); + if (!*s) { + return -ENOMEM; + } + memcpy(*s, priv->buffer+priv->off, len); + (*s)[len] = '\0'; + priv->off += len; + return 0; +} + +static struct iarchive ia_default = { + ia_start_record, + ia_end_record, + ia_start_vector, + ia_end_vector, + ia_deserialize_bool, + ia_deserialize_int, + ia_deserialize_long , + ia_deserialize_buffer, + ia_deserialize_string}; + +static struct oarchive oa_default = { + oa_start_record, + oa_end_record, + oa_start_vector, + oa_end_vector, + oa_serialize_bool, + oa_serialize_int, + oa_serialize_long , + oa_serialize_buffer, + oa_serialize_string}; + +struct iarchive *create_buffer_iarchive(char *buffer, int len) +{ + struct iarchive *ia = malloc(sizeof(*ia)); + struct buff_struct *buff = malloc(sizeof(struct buff_struct)); + if (!ia) return 0; + if (!buff) { + free(ia); + return 0; + } + *ia = ia_default; + buff->off = 0; + buff->buffer = buffer; + buff->len = len; + ia->priv = buff; + return ia; +} + +struct oarchive *create_buffer_oarchive() +{ + struct oarchive *oa = malloc(sizeof(*oa)); + struct buff_struct *buff = malloc(sizeof(struct buff_struct)); + if (!oa) return 0; + if (!buff) { + free(oa); + return 0; + } + *oa = oa_default; + buff->off = 0; + buff->buffer = malloc(128); + buff->len = 128; + oa->priv = buff; + return oa; +} + +void close_buffer_iarchive(struct iarchive **ia) +{ + free((*ia)->priv); + free(*ia); + *ia = 0; +} + +void close_buffer_oarchive(struct oarchive **oa, int free_buffer) +{ + if (free_buffer) { + struct buff_struct *buff = (struct buff_struct *)(*oa)->priv; + if (buff->buffer) { + free(buff->buffer); + } + } + free((*oa)->priv); + free(*oa); + *oa = 0; +} + +char *get_buffer(struct oarchive *oa) +{ + struct buff_struct *buff = oa->priv; + return buff->buffer; +} +int get_buffer_len(struct oarchive *oa) +{ + struct buff_struct *buff = oa->priv; + return buff->off; +} diff --git a/src/c/src/st_adaptor.c b/src/c/src/st_adaptor.c new file mode 100644 index 00000000000..0f62966bd2a --- /dev/null +++ b/src/c/src/st_adaptor.c @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DLL_EXPORT +# define USE_STATIC_LIB +#endif + +#include "zk_adaptor.h" +#include +#include + +int zoo_lock_auth(zhandle_t *zh) +{ + return 0; +} +int zoo_unlock_auth(zhandle_t *zh) +{ + return 0; +} +int lock_buffer_list(buffer_head_t *l) +{ + return 0; +} +int unlock_buffer_list(buffer_head_t *l) +{ + return 0; +} +int lock_completion_list(completion_head_t *l) +{ + return 0; +} +int unlock_completion_list(completion_head_t *l) +{ + return 0; +} +struct sync_completion *alloc_sync_completion(void) +{ + return (struct sync_completion*)calloc(1, sizeof(struct sync_completion)); +} +int wait_sync_completion(struct sync_completion *sc) +{ + return 0; +} + +void free_sync_completion(struct sync_completion *sc) +{ + free(sc); +} + +void notify_sync_completion(struct sync_completion *sc) +{ +} + +int process_async(int outstanding_sync) +{ + return outstanding_sync == 0; +} + +int adaptor_init(zhandle_t *zh) +{ + return 0; +} + +void adaptor_finish(zhandle_t *zh){} + +void adaptor_destroy(zhandle_t *zh){} + +int flush_send_queue(zhandle_t *, int); + +int adaptor_send_queue(zhandle_t *zh, int timeout) +{ + return flush_send_queue(zh, timeout); +} + +int32_t inc_ref_counter(zhandle_t* zh,int i) +{ + zh->ref_counter+=(i<0?-1:(i>0?1:0)); + return zh->ref_counter; +} + +int32_t get_xid() +{ + static int32_t xid = -1; + if (xid == -1) { + xid = time(0); + } + return xid++; +} + +int lock_reconfig(struct _zhandle *zh) +{ + return 0; +} + +int unlock_reconfig(struct _zhandle *zh) +{ + return 0; +} + +int enter_critical(zhandle_t* zh) +{ + return 0; +} + +int leave_critical(zhandle_t* zh) +{ + return 0; +} diff --git a/src/c/src/winport.c b/src/c/src/winport.c new file mode 100644 index 00000000000..46a5a2b73e1 --- /dev/null +++ b/src/c/src/winport.c @@ -0,0 +1,298 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef WIN32 +#include "winport.h" +#include +#include +#include + +int pthread_mutex_lock(pthread_mutex_t* _mutex ){ + int rc = WaitForSingleObject( *_mutex, // handle to mutex + INFINITE); // no time-out interval + return ((rc == WAIT_OBJECT_0) ? 0: rc); +} + +int pthread_mutex_unlock( pthread_mutex_t* _mutex ){ + int rc = ReleaseMutex(*_mutex); + return ((rc != 0)? 0: GetLastError()); +} + +int pthread_mutex_init(pthread_mutex_t* _mutex, void* ignoredAttr){ + //use CreateMutex as we are using the HANDLES in pthread_cond + *_mutex = CreateMutex( + NULL, // default security attributes + FALSE, // initially not owned + NULL); // unnamed mutex + return ((*_mutex == NULL) ? GetLastError() : 0); +} + +int pthread_mutex_destroy(pthread_mutex_t* _mutex) +{ + int rc = CloseHandle(*_mutex); + return ((rc != 0)? 0: GetLastError()); +} + +int pthread_create(pthread_t *thread, const pthread_attr_t *attr, unsigned (__stdcall* start_routine)(void* a), void *arg) +{ + int _intThreadId; + (*thread).thread_handle = (HANDLE)_beginthreadex( NULL, 0, start_routine , arg, 0, (unsigned int*)&_intThreadId ); + (*thread).thread_id = _intThreadId; + return (((*thread).thread_handle == 0 ) ? errno : 0 ); +} + + +int pthread_equal(pthread_t t1, pthread_t t2){ +//Is there a better way to do this? GetThreadId(handle) is only supported Windows 2003 n above. + return ((t1.thread_id == t2.thread_id) ? 1:0); +} + +pthread_t pthread_self(){ + pthread_t thread_self; + thread_self.thread_handle = GetCurrentThread(); + thread_self.thread_id = GetCurrentThreadId(); + return thread_self; +} + +int pthread_join(pthread_t _thread, void** ignore) +{ + int rc = WaitForSingleObject( _thread.thread_handle, INFINITE ); + return ((rc == WAIT_OBJECT_0) ? 0: rc); +} + +int pthread_detach(pthread_t _thread) +{ + int rc = CloseHandle(_thread.thread_handle) ; + return (rc != 0) ? 0: GetLastError(); +} + +void pthread_mutexattr_init(pthread_mutexattr_t* ignore){} +void pthread_mutexattr_settype(pthread_mutexattr_t* ingore_attr, int ignore){} +void pthread_mutexattr_destroy(pthread_mutexattr_t* ignore_attr){} + +int +pthread_cond_init (pthread_cond_t *cv, + const pthread_condattr_t * ignore) +{ + cv->waiters_count_ = 0; + cv->was_broadcast_ = 0; + cv->sema_ = CreateSemaphore (NULL, // no security + 0, // initially 0 + 0x7fffffff, // max count + NULL); // unnamed + if (cv->sema_ == NULL ) + return GetLastError(); + InitializeCriticalSection (&cv->waiters_count_lock_); + cv->waiters_done_ = CreateEvent (NULL, // no security + FALSE, // auto-reset + FALSE, // non-signaled initially + NULL); // unnamed + return (cv->waiters_done_ == NULL) ? GetLastError() : 0; + +} + + +int pthread_cond_destroy(pthread_cond_t *cond) +{ + CloseHandle( cond->sema_); + DeleteCriticalSection(&cond->waiters_count_lock_); + return (CloseHandle( cond->waiters_done_ ) == 0)? GetLastError(): 0 ; +} + + +int +pthread_cond_signal (pthread_cond_t *cv) +{ + int have_waiters; + EnterCriticalSection (& (cv->waiters_count_lock_)); + have_waiters = cv->waiters_count_ > 0; + LeaveCriticalSection (&cv->waiters_count_lock_); + + // If there aren't any waiters, then this is a no-op. + if (have_waiters){ + return (ReleaseSemaphore (cv->sema_, 1, 0) == 0 ) ? GetLastError() : 0 ; + }else + return 0; +} + + +int +pthread_cond_broadcast (pthread_cond_t *cv) +{ + // This is needed to ensure that and are + // consistent relative to each other. + int have_waiters = 0; + EnterCriticalSection (&cv->waiters_count_lock_); + + if (cv->waiters_count_ > 0) { + // We are broadcasting, even if there is just one waiter... + // Record that we are broadcasting, which helps optimize + // for the non-broadcast case. + cv->was_broadcast_ = 1; + have_waiters = 1; + } + + if (have_waiters) { + // Wake up all the waiters atomically. + ReleaseSemaphore (cv->sema_, cv->waiters_count_, 0); + + LeaveCriticalSection (&cv->waiters_count_lock_); + + // Wait for all the awakened threads to acquire the counting + // semaphore. + WaitForSingleObject (cv->waiters_done_, INFINITE); + // This assignment is okay, even without the held + // because no other waiter threads can wake up to access it. + cv->was_broadcast_ = 0; + } + else + LeaveCriticalSection (&cv->waiters_count_lock_); +} + + +int +pthread_cond_wait (pthread_cond_t *cv, + pthread_mutex_t *external_mutex) +{ + int last_waiter; + // Avoid race conditions. + EnterCriticalSection (&cv->waiters_count_lock_); + cv->waiters_count_++; + LeaveCriticalSection (&cv->waiters_count_lock_); + + // This call atomically releases the mutex and waits on the + // semaphore until or + // are called by another thread. + SignalObjectAndWait (*external_mutex, cv->sema_, INFINITE, FALSE); + + // Reacquire lock to avoid race conditions. + EnterCriticalSection (&cv->waiters_count_lock_); + + // We're no longer waiting... + cv->waiters_count_--; + + // Check to see if we're the last waiter after . + last_waiter = cv->was_broadcast_ && cv->waiters_count_ == 0; + + LeaveCriticalSection (&cv->waiters_count_lock_); + + // If we're the last waiter thread during this particular broadcast + // then let all the other threads proceed. + if (last_waiter) + // This call atomically signals the event and waits until + // it can acquire the . This is required to ensure fairness. + SignalObjectAndWait (cv->waiters_done_, *external_mutex, INFINITE, FALSE); + else + // Always regain the external mutex since that's the guarantee we + // give to our callers. + WaitForSingleObject (*external_mutex, INFINITE); +} + +int pthread_key_create(pthread_key_t *key, void (*destructor)(void *) ) +{ + int result = 0; + pthread_key_t* newkey; + + if ((newkey = (pthread_key_t*) calloc (1, sizeof (pthread_key_t))) == NULL) + { + result = ENOMEM; + } + else if ((newkey->key = TlsAlloc ()) == TLS_OUT_OF_INDEXES) + { + result = EAGAIN; + free (newkey); + newkey = NULL; + } + else if (destructor != NULL) + { + //--we have to store the function pointer for destructor, so that we can call it + //--to free up the user allocated storage-- + newkey->destructor = destructor; + } + key = newkey; + return (result); +} + +int pthread_key_delete(pthread_key_t key) +{ + int rc = 0; + LPVOID lpvData = TlsGetValue(key.key); + rc = TlsFree (key.key); + rc = (rc != 0 ) ? 0 : GetLastError(); + if (key.destructor != NULL && lpvData != 0){ + key.destructor(lpvData); //we take control of calling destructor, instead of calling it on thread exit. + } + free (&key); + return (rc); +} + +void *pthread_getspecific(pthread_key_t key) +{ + LPVOID lpvData = TlsGetValue(key.key); + if ((lpvData == 0) && (GetLastError() != ERROR_SUCCESS)) + return NULL; + else + return lpvData; +} + +int pthread_setspecific(pthread_key_t key, const void *value) +{ + int rc = TlsSetValue (key.key, value); + return ((rc != 0 ) ? 0 : GetLastError()); +} + + +int close(SOCKET fd) { + return closesocket(fd); +} + +int Win32WSAStartup() +{ + WORD wVersionRq; + WSADATA wsaData; + int err; + + wVersionRq = MAKEWORD(2,0); + err = WSAStartup(wVersionRq, &wsaData); + if (err != 0) + return 1; + + // confirm the version information + if ((LOBYTE(wsaData.wVersion) != 2) || + (HIBYTE(wsaData.wVersion) != 0)) + { + Win32WSACleanup(); + return 1; + } + return 0; +} + +void Win32WSACleanup() +{ + WSACleanup(); +} + +double drand48(void) +{ + return (double)(rand()) / RAND_MAX; +} + +#endif //WIN32 + + + diff --git a/src/c/src/winport.h b/src/c/src/winport.h new file mode 100644 index 00000000000..2cfda47cbd7 --- /dev/null +++ b/src/c/src/winport.h @@ -0,0 +1,124 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This header file is to port pthread lib , sockets and other utility methods on windows. + * Specifically the threads function, mutexes, keys, and socket initialization. + */ + +#ifndef WINPORT_H_ +#define WINPORT_H_ + +#ifdef WIN32 +#include +#include +#include +#include +#include + + +typedef int ssize_t; +typedef HANDLE pthread_mutex_t; + +struct pthread_t_ +{ + HANDLE thread_handle; + DWORD thread_id; +}; + +typedef struct pthread_t_ pthread_t; +typedef int pthread_mutexattr_t; +typedef int pthread_condattr_t; +typedef int pthread_attr_t; +#define PTHREAD_MUTEX_RECURSIVE 0 + +int pthread_mutex_lock(pthread_mutex_t* _mutex ); +int pthread_mutex_unlock( pthread_mutex_t* _mutex ); +int pthread_mutex_init(pthread_mutex_t* _mutex, void* ignoredAttr); +int pthread_mutex_destroy(pthread_mutex_t* _mutex); +int pthread_create(pthread_t *thread, const pthread_attr_t *attr, unsigned (__stdcall* start_routine)(void* a), void *arg); +int pthread_equal(pthread_t t1, pthread_t t2); +pthread_t pthread_self(); +int pthread_join(pthread_t _thread, void** ignore); +int pthread_detach(pthread_t _thread); + +void pthread_mutexattr_init(pthread_mutexattr_t* ignore); +void pthread_mutexattr_settype(pthread_mutexattr_t* ingore_attr, int ignore); +void pthread_mutexattr_destroy(pthread_mutexattr_t* ignore_attr); + + +// http://www.cs.wustl.edu/~schmidt/win32-cv-1.html + +typedef struct +{ + int waiters_count_; + // Number of waiting threads. + + CRITICAL_SECTION waiters_count_lock_; + // Serialize access to . + + HANDLE sema_; + // Semaphore used to queue up threads waiting for the condition to + // become signaled. + + HANDLE waiters_done_; + // An auto-reset event used by the broadcast/signal thread to wait + // for all the waiting thread(s) to wake up and be released from the + // semaphore. + + size_t was_broadcast_; + // Keeps track of whether we were broadcasting or signaling. This + // allows us to optimize the code if we're just signaling. +}pthread_cond_t; + +int pthread_cond_init (pthread_cond_t *cv,const pthread_condattr_t * ignore); +int pthread_cond_destroy(pthread_cond_t *cond); +int pthread_cond_signal (pthread_cond_t *cv); +int pthread_cond_broadcast (pthread_cond_t *cv); +int pthread_cond_wait (pthread_cond_t *cv, pthread_mutex_t *external_mutex); + + +struct pthread_key_t_ +{ + DWORD key; + void (*destructor) (void *); +}; + +typedef struct pthread_key_t_ pthread_key_t; +int pthread_key_create(pthread_key_t *key, void (*destructor)(void *) ); +int pthread_key_delete(pthread_key_t key); +void *pthread_getspecific(pthread_key_t key); +int pthread_setspecific(pthread_key_t key, const void *value); + +inline int gettimeofday(struct timeval *tp, void *tzp) { + int64_t now = 0; + if (tzp != 0) { errno = EINVAL; return -1; } + GetSystemTimeAsFileTime( (LPFILETIME)&now ); + tp->tv_sec = (long)(now / 10000000 - 11644473600LL); + tp->tv_usec = (now / 10) % 1000000; + return 0; +} +int close(SOCKET fd); +int Win32WSAStartup(); +void Win32WSACleanup(); +double drand48(void); +#endif //WIN32 + + + +#endif //WINPORT_H_ diff --git a/src/c/src/zk_adaptor.h b/src/c/src/zk_adaptor.h new file mode 100644 index 00000000000..2039fb32a02 --- /dev/null +++ b/src/c/src/zk_adaptor.h @@ -0,0 +1,317 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZK_ADAPTOR_H_ +#define ZK_ADAPTOR_H_ +#include +#ifdef THREADED +#ifndef WIN32 +#include +#else +#include "winport.h" +#endif +#endif +#include "zookeeper.h" +#include "zk_hashtable.h" +#include "addrvec.h" + +/* predefined xid's values recognized as special by the server */ +#define WATCHER_EVENT_XID -1 +#define PING_XID -2 +#define AUTH_XID -4 +#define SET_WATCHES_XID -8 + +/* zookeeper state constants */ +#define EXPIRED_SESSION_STATE_DEF -112 +#define AUTH_FAILED_STATE_DEF -113 +#define CONNECTING_STATE_DEF 1 +#define ASSOCIATING_STATE_DEF 2 +#define CONNECTED_STATE_DEF 3 +#define READONLY_STATE_DEF 5 +#define NOTCONNECTED_STATE_DEF 999 + +/* zookeeper event type constants */ +#define CREATED_EVENT_DEF 1 +#define DELETED_EVENT_DEF 2 +#define CHANGED_EVENT_DEF 3 +#define CHILD_EVENT_DEF 4 +#define SESSION_EVENT_DEF -1 +#define NOTWATCHING_EVENT_DEF -2 + +#ifdef __cplusplus +extern "C" { +#endif + +struct _buffer_list; +struct _completion_list; + +typedef struct _buffer_head { + struct _buffer_list *volatile head; + struct _buffer_list *last; +#ifdef THREADED + pthread_mutex_t lock; +#endif +} buffer_head_t; + +typedef struct _completion_head { + struct _completion_list *volatile head; + struct _completion_list *last; +#ifdef THREADED + pthread_cond_t cond; + pthread_mutex_t lock; +#endif +} completion_head_t; + +int lock_buffer_list(buffer_head_t *l); +int unlock_buffer_list(buffer_head_t *l); +int lock_completion_list(completion_head_t *l); +int unlock_completion_list(completion_head_t *l); + +struct sync_completion { + int rc; + union { + struct { + char *str; + int str_len; + } str; + struct Stat stat; + struct { + char *buffer; + int buff_len; + struct Stat stat; + } data; + struct { + struct ACL_vector acl; + struct Stat stat; + } acl; + struct String_vector strs2; + struct { + struct String_vector strs2; + struct Stat stat2; + } strs_stat; + } u; + int complete; +#ifdef THREADED + pthread_cond_t cond; + pthread_mutex_t lock; +#endif +}; + +typedef struct _auth_info { + int state; /* 0=>inactive, >0 => active */ + char* scheme; + struct buffer auth; + void_completion_t completion; + const char* data; + struct _auth_info *next; +} auth_info; + +/** + * This structure represents a packet being read or written. + */ +typedef struct _buffer_list { + char *buffer; + int len; /* This represents the length of sizeof(header) + length of buffer */ + int curr_offset; /* This is the offset into the header followed by offset into the buffer */ + struct _buffer_list *next; +} buffer_list_t; + +/* the size of connect request */ +#define HANDSHAKE_REQ_SIZE 45 +/* connect request */ +struct connect_req { + int32_t protocolVersion; + int64_t lastZxidSeen; + int32_t timeOut; + int64_t sessionId; + int32_t passwd_len; + char passwd[16]; + char readOnly; +}; + +/* the connect response */ +struct prime_struct { + int32_t len; + int32_t protocolVersion; + int32_t timeOut; + int64_t sessionId; + int32_t passwd_len; + char passwd[16]; + char readOnly; +}; + +#ifdef THREADED +/* this is used by mt_adaptor internally for thread management */ +struct adaptor_threads { + pthread_t io; + pthread_t completion; + int threadsToWait; // barrier + pthread_cond_t cond; // barrier's conditional + pthread_mutex_t lock; // ... and a lock + pthread_mutex_t zh_lock; // critical section lock + pthread_mutex_t reconfig_lock; // lock for reconfiguring cluster's ensemble +#ifdef WIN32 + SOCKET self_pipe[2]; +#else + int self_pipe[2]; +#endif +}; +#endif + +/** the auth list for adding auth */ +typedef struct _auth_list_head { + auth_info *auth; +#ifdef THREADED + pthread_mutex_t lock; +#endif +} auth_list_head_t; + +/** + * This structure represents the connection to zookeeper. + */ +struct _zhandle { +#ifdef WIN32 + SOCKET fd; // the descriptor used to talk to zookeeper +#else + int fd; // the descriptor used to talk to zookeeper +#endif + + // Hostlist and list of addresses + char *hostname; // hostname contains list of zookeeper servers to connect to + struct sockaddr_storage addr_cur; // address of server we're currently connecting/connected to + + addrvec_t addrs; // current list of addresses we're connected to + addrvec_t addrs_old; // old list of addresses that we are no longer connected to + addrvec_t addrs_new; // new list of addresses to connect to if we're reconfiguring + + int reconfig; // Are we in the process of reconfiguring cluster's ensemble + double pOld, pNew; // Probability for selecting between 'addrs_old' and 'addrs_new' + int delay; + + watcher_fn watcher; // the registered watcher + + // Message timings + struct timeval last_recv; // time last message was received + struct timeval last_send; // time last message was sent + struct timeval last_ping; // time last PING was sent + struct timeval next_deadline; // time of the next deadline + int recv_timeout; // max receive timeout for messages from server + + // Buffers + buffer_list_t *input_buffer; // current buffer being read in + buffer_head_t to_process; // buffers that have been read and ready to be processed + buffer_head_t to_send; // packets queued to send + completion_head_t sent_requests; // outstanding requests + completion_head_t completions_to_process; // completions that are ready to run + int outstanding_sync; // number of outstanding synchronous requests + + /* read-only mode specific fields */ + struct timeval last_ping_rw; /* The last time we checked server for being r/w */ + int ping_rw_timeout; /* The time that can go by before checking next server */ + + // State info + volatile int state; // Current zookeeper state + void *context; // client-side provided context + clientid_t client_id; // client-id + long long last_zxid; // last zookeeper ID + auth_list_head_t auth_h; // authentication data list + log_callback_fn log_callback; // Callback for logging (falls back to logging to stderr) + int io_count; // counts the number of iterations of do_io + + // Primer storage + struct _buffer_list primer_buffer; // The buffer used for the handshake at the start of a connection + struct prime_struct primer_storage; // the connect response + char primer_storage_buffer[41]; // the true size of primer_storage + + /* zookeeper_close is not reentrant because it de-allocates the zhandler. + * This guard variable is used to defer the destruction of zhandle till + * right before top-level API call returns to the caller */ + int32_t ref_counter; + volatile int close_requested; + void *adaptor_priv; + + /* Used for debugging only: non-zero value indicates the time when the zookeeper_process + * call returned while there was at least one unprocessed server response + * available in the socket recv buffer */ + struct timeval socket_readable; + + // Watchers + zk_hashtable* active_node_watchers; + zk_hashtable* active_exist_watchers; + zk_hashtable* active_child_watchers; + + /** used for chroot path at the client side **/ + char *chroot; + + /** Indicates if this client is allowed to go to r/o mode */ + char allow_read_only; + /** Indicates if we connected to a majority server before */ + char seen_rw_server_before; +}; + + +int adaptor_init(zhandle_t *zh); +void adaptor_finish(zhandle_t *zh); +void adaptor_destroy(zhandle_t *zh); +struct sync_completion *alloc_sync_completion(void); +int wait_sync_completion(struct sync_completion *sc); +void free_sync_completion(struct sync_completion *sc); +void notify_sync_completion(struct sync_completion *sc); +int adaptor_send_queue(zhandle_t *zh, int timeout); +int process_async(int outstanding_sync); +void process_completions(zhandle_t *zh); +int flush_send_queue(zhandle_t*zh, int timeout); +char* sub_string(zhandle_t *zh, const char* server_path); +void free_duplicate_path(const char* free_path, const char* path); +int zoo_lock_auth(zhandle_t *zh); +int zoo_unlock_auth(zhandle_t *zh); + +// ensemble reconfigure access guards +int lock_reconfig(struct _zhandle *zh); +int unlock_reconfig(struct _zhandle *zh); + +// critical section guards +int enter_critical(zhandle_t* zh); +int leave_critical(zhandle_t* zh); + +// zhandle object reference counting +void api_prolog(zhandle_t* zh); +int api_epilog(zhandle_t *zh, int rc); +int32_t get_xid(); + +// returns the new value of the ref counter +int32_t inc_ref_counter(zhandle_t* zh,int i); + +#ifdef THREADED +// atomic post-increment +int32_t fetch_and_add(volatile int32_t* operand, int incr); +// in mt mode process session event asynchronously by the completion thread +#define PROCESS_SESSION_EVENT(zh,newstate) queue_session_event(zh,newstate) +#else +// in single-threaded mode process session event immediately +//#define PROCESS_SESSION_EVENT(zh,newstate) deliverWatchers(zh,ZOO_SESSION_EVENT,newstate,0) +#define PROCESS_SESSION_EVENT(zh,newstate) queue_session_event(zh,newstate) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*ZK_ADAPTOR_H_*/ + + diff --git a/src/c/src/zk_hashtable.c b/src/c/src/zk_hashtable.c new file mode 100644 index 00000000000..8f87a96f7f0 --- /dev/null +++ b/src/c/src/zk_hashtable.c @@ -0,0 +1,476 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "zk_hashtable.h" +#include "zk_adaptor.h" +#include "hashtable/hashtable.h" +#include "hashtable/hashtable_itr.h" +#include +#include +#include + +typedef struct _watcher_object { + watcher_fn watcher; + void* context; + struct _watcher_object* next; +} watcher_object_t; + + +struct _zk_hashtable { + struct hashtable* ht; +}; + +struct watcher_object_list { + watcher_object_t* head; +}; + +/* the following functions are for testing only */ +typedef struct hashtable hashtable_impl; + +hashtable_impl* getImpl(zk_hashtable* ht){ + return ht->ht; +} + +watcher_object_t* getFirstWatcher(zk_hashtable* ht,const char* path) +{ + watcher_object_list_t* wl=hashtable_search(ht->ht,(void*)path); + if(wl!=0) + return wl->head; + return 0; +} +/* end of testing functions */ + +watcher_object_t* clone_watcher_object(watcher_object_t* wo) +{ + watcher_object_t* res=calloc(1,sizeof(watcher_object_t)); + assert(res); + res->watcher=wo->watcher; + res->context=wo->context; + return res; +} + +static unsigned int string_hash_djb2(void *str) +{ + unsigned int hash = 5381; + int c; + const char* cstr = (const char*)str; + while ((c = *cstr++)) + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + + return hash; +} + +static int string_equal(void *key1,void *key2) +{ + return strcmp((const char*)key1,(const char*)key2)==0; +} + +static watcher_object_t* create_watcher_object(watcher_fn watcher,void* ctx) +{ + watcher_object_t* wo=calloc(1,sizeof(watcher_object_t)); + assert(wo); + wo->watcher=watcher; + wo->context=ctx; + return wo; +} + +static watcher_object_list_t* create_watcher_object_list(watcher_object_t* head) +{ + watcher_object_list_t* wl=calloc(1,sizeof(watcher_object_list_t)); + assert(wl); + wl->head=head; + return wl; +} + +static void destroy_watcher_object_list(watcher_object_list_t* list) +{ + watcher_object_t* e = NULL; + + if(list==0) + return; + e=list->head; + while(e!=0){ + watcher_object_t* this=e; + e=e->next; + free(this); + } + free(list); +} + +zk_hashtable* create_zk_hashtable() +{ + struct _zk_hashtable *ht=calloc(1,sizeof(struct _zk_hashtable)); + assert(ht); + ht->ht=create_hashtable(32,string_hash_djb2,string_equal); + return ht; +} + +static void do_clean_hashtable(zk_hashtable* ht) +{ + struct hashtable_itr *it; + int hasMore; + if(hashtable_count(ht->ht)==0) + return; + it=hashtable_iterator(ht->ht); + do { + watcher_object_list_t* w=hashtable_iterator_value(it); + destroy_watcher_object_list(w); + hasMore=hashtable_iterator_remove(it); + } while(hasMore); + free(it); +} + +void destroy_zk_hashtable(zk_hashtable* ht) +{ + if(ht!=0){ + do_clean_hashtable(ht); + hashtable_destroy(ht->ht,0); + free(ht); + } +} + +// searches for a watcher object instance in a watcher object list; +// two watcher objects are equal if their watcher function and context pointers +// are equal +static watcher_object_t* search_watcher(watcher_object_list_t** wl,watcher_object_t* wo) +{ + watcher_object_t* wobj=(*wl)->head; + while(wobj!=0){ + if(wobj->watcher==wo->watcher && wobj->context==wo->context) + return wobj; + wobj=wobj->next; + } + return 0; +} + +static int add_to_list(watcher_object_list_t **wl, watcher_object_t *wo, + int clone) +{ + if (search_watcher(wl, wo)==0) { + watcher_object_t* cloned=wo; + if (clone) { + cloned = clone_watcher_object(wo); + assert(cloned); + } + cloned->next = (*wl)->head; + (*wl)->head = cloned; + return 1; + } else if (!clone) { + // If it's here and we aren't supposed to clone, we must destroy + free(wo); + } + return 0; +} + +static int do_insert_watcher_object(zk_hashtable *ht, const char *path, watcher_object_t* wo) +{ + int res=1; + watcher_object_list_t* wl; + + wl=hashtable_search(ht->ht,(void*)path); + if(wl==0){ + int res; + /* inserting a new path element */ + res=hashtable_insert(ht->ht,strdup(path),create_watcher_object_list(wo)); + assert(res); + }else{ + /* + * Path already exists; check if the watcher already exists. + * Don't clone the watcher since it's allocated on the heap --- avoids + * a memory leak and saves a clone operation (calloc + copy). + */ + res = add_to_list(&wl, wo, 0); + } + return res; +} + + +char **collect_keys(zk_hashtable *ht, int *count) +{ + char **list; + struct hashtable_itr *it; + int i; + + *count = hashtable_count(ht->ht); + list = calloc(*count, sizeof(char*)); + it=hashtable_iterator(ht->ht); + for(i = 0; i < *count; i++) { + list[i] = strdup(hashtable_iterator_key(it)); + hashtable_iterator_advance(it); + } + free(it); + return list; +} + +static int insert_watcher_object(zk_hashtable *ht, const char *path, + watcher_object_t* wo) +{ + int res; + res=do_insert_watcher_object(ht,path,wo); + return res; +} + +static void copy_watchers(watcher_object_list_t *from, watcher_object_list_t *to, int clone) +{ + watcher_object_t* wo=from->head; + while(wo){ + watcher_object_t *next = wo->next; + add_to_list(&to, wo, clone); + wo=next; + } +} + +static void copy_table(zk_hashtable *from, watcher_object_list_t *to) { + struct hashtable_itr *it; + int hasMore; + if(hashtable_count(from->ht)==0) + return; + it=hashtable_iterator(from->ht); + do { + watcher_object_list_t *w = hashtable_iterator_value(it); + copy_watchers(w, to, 1); + hasMore=hashtable_iterator_advance(it); + } while(hasMore); + free(it); +} + +static void collect_session_watchers(zhandle_t *zh, + watcher_object_list_t **list) +{ + copy_table(zh->active_node_watchers, *list); + copy_table(zh->active_exist_watchers, *list); + copy_table(zh->active_child_watchers, *list); +} + +static void add_for_event(zk_hashtable *ht, char *path, watcher_object_list_t **list) +{ + watcher_object_list_t* wl; + wl = (watcher_object_list_t*)hashtable_remove(ht->ht, path); + if (wl) { + copy_watchers(wl, *list, 0); + // Since we move, not clone the watch_objects, we just need to free the + // head pointer + free(wl); + } +} + +static void do_foreach_watcher(watcher_object_t* wo,zhandle_t* zh, + const char* path,int type,int state) +{ + // session event's don't have paths + const char *client_path = + (type != ZOO_SESSION_EVENT ? sub_string(zh, path) : path); + while(wo!=0){ + wo->watcher(zh,type,state,client_path,wo->context); + wo=wo->next; + } + free_duplicate_path(client_path, path); +} + +watcher_object_list_t *collectWatchers(zhandle_t *zh,int type, char *path) +{ + struct watcher_object_list *list = create_watcher_object_list(0); + + if(type==ZOO_SESSION_EVENT){ + watcher_object_t defWatcher; + defWatcher.watcher=zh->watcher; + defWatcher.context=zh->context; + add_to_list(&list, &defWatcher, 1); + collect_session_watchers(zh, &list); + return list; + } + switch(type){ + case CREATED_EVENT_DEF: + case CHANGED_EVENT_DEF: + // look up the watchers for the path and move them to a delivery list + add_for_event(zh->active_node_watchers,path,&list); + add_for_event(zh->active_exist_watchers,path,&list); + break; + case CHILD_EVENT_DEF: + // look up the watchers for the path and move them to a delivery list + add_for_event(zh->active_child_watchers,path,&list); + break; + case DELETED_EVENT_DEF: + // look up the watchers for the path and move them to a delivery list + add_for_event(zh->active_node_watchers,path,&list); + add_for_event(zh->active_exist_watchers,path,&list); + add_for_event(zh->active_child_watchers,path,&list); + break; + } + return list; +} + +void deliverWatchers(zhandle_t *zh, int type,int state, char *path, watcher_object_list_t **list) +{ + if (!list || !(*list)) return; + do_foreach_watcher((*list)->head, zh, path, type, state); + destroy_watcher_object_list(*list); + *list = 0; +} + +void activateWatcher(zhandle_t *zh, watcher_registration_t* reg, int rc) +{ + if(reg){ + /* in multithreaded lib, this code is executed + * by the IO thread */ + zk_hashtable *ht = reg->checker(zh, rc); + if(ht){ + insert_watcher_object(ht,reg->path, + create_watcher_object(reg->watcher, reg->context)); + } + } +} + +/* If watcher is NULL, we return TRUE since we consider it a match */ +static int containsWatcher(zk_hashtable *watchers, const char *path, + watcher_fn watcher, void *watcherCtx) +{ + watcher_object_list_t *wl; + watcher_object_t e; + + if (!watcher) + return 1; + + wl = hashtable_search(watchers->ht, (void *)path); + if (!wl) + return 0; + + e.watcher = watcher; + e.context = watcherCtx; + + return search_watcher(&wl, &e) ? 1 : 0; +} + +/** + * remove any watcher_object that has a matching (watcher, watcherCtx) + */ +static void removeWatcherFromList(watcher_object_list_t *wl, watcher_fn watcher, + void *watcherCtx) +{ + watcher_object_t *e = NULL; + + if (!wl || (wl && !wl->head)) + return; + + e = wl->head; + while (e){ + if (e->next && + e->next->watcher == watcher && + e->context == watcherCtx) { + watcher_object_t *this = e->next; + e->next = e->next->next; + free(this); + break; + } + e = e->next; + } + + if (wl->head && + wl->head->watcher == watcher && wl->head->context == watcherCtx) { + watcher_object_t *this = wl->head; + wl->head = wl->head->next; + free(this); + } +} + +static void removeWatcher(zk_hashtable *watchers, const char *path, + watcher_fn watcher, void *watcherCtx) +{ + watcher_object_list_t *wl = hashtable_search(watchers->ht, (void *)path); + + if (!wl) + return; + + if (!watcher) { + wl = (watcher_object_list_t *) hashtable_remove(watchers->ht, + (void *)path); + destroy_watcher_object_list(wl); + return; + } + + removeWatcherFromList(wl, watcher, watcherCtx); + + if (!wl->head) { + wl = (watcher_object_list_t *) hashtable_remove(watchers->ht, + (void *)path); + destroy_watcher_object_list(wl); + } +} + +void deactivateWatcher(zhandle_t *zh, watcher_deregistration_t *dereg, int rc) +{ + if (rc != ZOK || !dereg) + return; + + removeWatchers(zh, dereg->path, dereg->type, dereg->watcher, + dereg->context); +} + +void removeWatchers(zhandle_t *zh, const char* path, ZooWatcherType type, + watcher_fn watcher, void *watcherCtx) +{ + switch (type) { + case ZWATCHERTYPE_CHILDREN: + removeWatcher(zh->active_child_watchers, path, watcher, watcherCtx); + break; + case ZWATCHERTYPE_DATA: + removeWatcher(zh->active_node_watchers, path, watcher, watcherCtx); + removeWatcher(zh->active_exist_watchers, path, watcher, watcherCtx); + break; + case ZWATCHERTYPE_ANY: + removeWatcher(zh->active_child_watchers, path, watcher, watcherCtx); + removeWatcher(zh->active_node_watchers, path, watcher, watcherCtx); + removeWatcher(zh->active_exist_watchers, path, watcher, watcherCtx); + break; + } +} + +int pathHasWatcher(zhandle_t *zh, const char *path, int wtype, + watcher_fn watcher, void *watcherCtx) +{ + int watcher_found = 0; + + switch (wtype) { + case ZWATCHERTYPE_CHILDREN: + watcher_found = containsWatcher(zh->active_child_watchers, + path, watcher, watcherCtx); + break; + case ZWATCHERTYPE_DATA: + watcher_found = containsWatcher(zh->active_node_watchers, path, + watcher, watcherCtx); + if (!watcher_found) { + watcher_found = containsWatcher(zh->active_exist_watchers, path, + watcher, watcherCtx); + } + break; + case ZWATCHERTYPE_ANY: + watcher_found = containsWatcher(zh->active_child_watchers, path, + watcher, watcherCtx); + if (!watcher_found) { + watcher_found = containsWatcher(zh->active_node_watchers, path, + watcher, watcherCtx); + } + if (!watcher_found) { + watcher_found = containsWatcher(zh->active_exist_watchers, path, + watcher, watcherCtx); + } + break; + } + + return watcher_found; +} diff --git a/src/c/src/zk_hashtable.h b/src/c/src/zk_hashtable.h new file mode 100644 index 00000000000..5227e07764c --- /dev/null +++ b/src/c/src/zk_hashtable.h @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZK_HASHTABLE_H_ +#define ZK_HASHTABLE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct watcher_object_list watcher_object_list_t; +typedef struct _zk_hashtable zk_hashtable; + +/** + * The function must return a non-zero value if the watcher object can be activated + * as a result of the server response. Normally, a watch can only be activated + * if the server returns a success code (ZOK). However in the case when zoo_exists() + * returns a ZNONODE code the watcher should be activated nevertheless. + */ +typedef zk_hashtable *(*result_checker_fn)(zhandle_t *, int rc); + +/** + * A watcher object gets temporarily stored with the completion entry until + * the server response comes back at which moment the watcher object is moved + * to the active watchers map. + */ +typedef struct _watcher_registration { + watcher_fn watcher; + void* context; + result_checker_fn checker; + const char* path; +} watcher_registration_t; + +/** + * A watcher deregistration gets temporarily stored with the completion entry until + * the server response comes back at which moment we can remove the watchers from + * the active watchers map. + */ +typedef struct _watcher_deregistration { + watcher_fn watcher; + void* context; + ZooWatcherType type; + const char* path; +} watcher_deregistration_t; + +zk_hashtable* create_zk_hashtable(); +void destroy_zk_hashtable(zk_hashtable* ht); + +char **collect_keys(zk_hashtable *ht, int *count); + +/** + * check if the completion has a watcher object associated + * with it. If it does, move the watcher object to the map of + * active watchers (only if the checker allows to do so) + */ + void activateWatcher(zhandle_t *zh, watcher_registration_t* reg, int rc); + void deactivateWatcher(zhandle_t *zh, watcher_deregistration_t *dereg, int rc); + watcher_object_list_t *collectWatchers(zhandle_t *zh,int type, char *path); + void deliverWatchers(zhandle_t *zh, int type, int state, char *path, struct watcher_object_list **list); + void removeWatchers(zhandle_t *zh, const char* path, ZooWatcherType type, + watcher_fn watcher, void *watcherCtx); + int pathHasWatcher(zhandle_t *zh, const char *path, int wtype, + watcher_fn watcher, void *watcherCtx); + +#ifdef __cplusplus +} +#endif + +#endif /*ZK_HASHTABLE_H_*/ diff --git a/src/c/src/zk_log.c b/src/c/src/zk_log.c new file mode 100644 index 00000000000..afe03009770 --- /dev/null +++ b/src/c/src/zk_log.c @@ -0,0 +1,200 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DLL_EXPORT +# define USE_STATIC_LIB +#endif + +#include "zookeeper_log.h" +#ifndef WIN32 +#include +#endif + +#include +#include + +#define TIME_NOW_BUF_SIZE 1024 +#define FORMAT_LOG_BUF_SIZE 4096 + +#ifdef THREADED +#ifndef WIN32 +#include +#else +#include "winport.h" +#endif + +static pthread_key_t time_now_buffer; +static pthread_key_t format_log_msg_buffer; + +void freeBuffer(void* p){ + if(p) free(p); +} + +__attribute__((constructor)) void prepareTSDKeys() { + pthread_key_create (&time_now_buffer, freeBuffer); + pthread_key_create (&format_log_msg_buffer, freeBuffer); +} + +char* getTSData(pthread_key_t key,int size){ + char* p=pthread_getspecific(key); + if(p==0){ + int res; + p=calloc(1,size); + res=pthread_setspecific(key,p); + if(res!=0){ + fprintf(stderr,"Failed to set TSD key: %d",res); + } + } + return p; +} + +char* get_time_buffer(){ + return getTSData(time_now_buffer,TIME_NOW_BUF_SIZE); +} + +char* get_format_log_buffer(){ + return getTSData(format_log_msg_buffer,FORMAT_LOG_BUF_SIZE); +} +#else +char* get_time_buffer(){ + static char buf[TIME_NOW_BUF_SIZE]; + return buf; +} + +char* get_format_log_buffer(){ + static char buf[FORMAT_LOG_BUF_SIZE]; + return buf; +} + +#endif + +ZooLogLevel logLevel=ZOO_LOG_LEVEL_INFO; + +static FILE* logStream=0; +FILE* zoo_get_log_stream(){ + if(logStream==0) + logStream=stderr; + return logStream; +} + +void zoo_set_log_stream(FILE* stream){ + logStream=stream; +} + +static const char* time_now(char* now_str){ + struct timeval tv; + struct tm lt; + time_t now = 0; + size_t len = 0; + + gettimeofday(&tv,0); + + now = tv.tv_sec; + localtime_r(&now, <); + + // clone the format used by log4j ISO8601DateFormat + // specifically: "yyyy-MM-dd HH:mm:ss,SSS" + + len = strftime(now_str, TIME_NOW_BUF_SIZE, + "%Y-%m-%d %H:%M:%S", + <); + + len += snprintf(now_str + len, + TIME_NOW_BUF_SIZE - len, + ",%03d", + (int)(tv.tv_usec/1000)); + + return now_str; +} + +void log_message(log_callback_fn callback, ZooLogLevel curLevel, + int line, const char* funcName, const char* format, ...) +{ + static const char* dbgLevelStr[]={"ZOO_INVALID","ZOO_ERROR","ZOO_WARN", + "ZOO_INFO","ZOO_DEBUG"}; + static pid_t pid=0; + va_list va; + int ofs = 0; +#ifdef THREADED + unsigned long int tid = 0; +#endif +#ifdef WIN32 + char timebuf [TIME_NOW_BUF_SIZE]; + const char* time = time_now(timebuf); +#else + const char* time = time_now(get_time_buffer()); +#endif + + char* buf = get_format_log_buffer(); + if(!buf) + { + fprintf(stderr, "log_message: Unable to allocate memory buffer"); + return; + } + + if(pid==0) + { + pid=getpid(); + } + + +#ifndef THREADED + + // pid_t is long on Solaris + ofs = snprintf(buf, FORMAT_LOG_BUF_SIZE, + "%s:%ld:%s@%s@%d: ", time, (long)pid, + dbgLevelStr[curLevel], funcName, line); +#else + + #ifdef WIN32 + tid = (unsigned long int)(pthread_self().thread_id); + #else + tid = (unsigned long int)(pthread_self()); + #endif + + ofs = snprintf(buf, FORMAT_LOG_BUF_SIZE-1, + "%s:%ld(0x%lx):%s@%s@%d: ", time, (long)pid, tid, + dbgLevelStr[curLevel], funcName, line); +#endif + + // Now grab the actual message out of the variadic arg list + va_start(va, format); + vsnprintf(buf+ofs, FORMAT_LOG_BUF_SIZE-1-ofs, format, va); + va_end(va); + + if (callback) + { + callback(buf); + } else { + fprintf(zoo_get_log_stream(), "%s\n", buf); + fflush(zoo_get_log_stream()); + } +} + +void zoo_set_debug_level(ZooLogLevel level) +{ + if(level==0){ + // disable logging (unit tests do this) + logLevel=(ZooLogLevel)0; + return; + } + if(levelZOO_LOG_LEVEL_DEBUG)level=ZOO_LOG_LEVEL_DEBUG; + logLevel=level; +} + diff --git a/src/c/src/zookeeper.c b/src/c/src/zookeeper.c new file mode 100644 index 00000000000..7549d48970f --- /dev/null +++ b/src/c/src/zookeeper.c @@ -0,0 +1,4767 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DLL_EXPORT +# define USE_STATIC_LIB +#endif + +#if defined(__CYGWIN__) +#define USE_IPV6 +#endif + +#include +#include +#include +#include "zk_adaptor.h" +#include "zookeeper_log.h" +#include "zk_hashtable.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef _WIN32 +#include +#include +#include +#include +#include +#include +#include +#include // needed for _POSIX_MONOTONIC_CLOCK +#include "config.h" +#else +#include "winstdint.h" +#endif + +#ifdef HAVE_SYS_UTSNAME_H +#include +#endif + +#ifdef HAVE_GETPWUID_R +#include +#endif + +#ifdef __MACH__ // OS X +#include +#include +#endif + +#define IF_DEBUG(x) if(logLevel==ZOO_LOG_LEVEL_DEBUG) {x;} + +const int ZOOKEEPER_WRITE = 1 << 0; +const int ZOOKEEPER_READ = 1 << 1; + +const int ZOO_EPHEMERAL = 1 << 0; +const int ZOO_SEQUENCE = 1 << 1; + +const int ZOO_EXPIRED_SESSION_STATE = EXPIRED_SESSION_STATE_DEF; +const int ZOO_AUTH_FAILED_STATE = AUTH_FAILED_STATE_DEF; +const int ZOO_CONNECTING_STATE = CONNECTING_STATE_DEF; +const int ZOO_ASSOCIATING_STATE = ASSOCIATING_STATE_DEF; +const int ZOO_CONNECTED_STATE = CONNECTED_STATE_DEF; +const int ZOO_READONLY_STATE = READONLY_STATE_DEF; +const int ZOO_NOTCONNECTED_STATE = NOTCONNECTED_STATE_DEF; + +static __attribute__ ((unused)) const char* state2String(int state){ + switch(state){ + case 0: + return "ZOO_CLOSED_STATE"; + case CONNECTING_STATE_DEF: + return "ZOO_CONNECTING_STATE"; + case ASSOCIATING_STATE_DEF: + return "ZOO_ASSOCIATING_STATE"; + case CONNECTED_STATE_DEF: + return "ZOO_CONNECTED_STATE"; + case READONLY_STATE_DEF: + return "ZOO_READONLY_STATE"; + case EXPIRED_SESSION_STATE_DEF: + return "ZOO_EXPIRED_SESSION_STATE"; + case AUTH_FAILED_STATE_DEF: + return "ZOO_AUTH_FAILED_STATE"; + } + return "INVALID_STATE"; +} + +const int ZOO_CREATED_EVENT = CREATED_EVENT_DEF; +const int ZOO_DELETED_EVENT = DELETED_EVENT_DEF; +const int ZOO_CHANGED_EVENT = CHANGED_EVENT_DEF; +const int ZOO_CHILD_EVENT = CHILD_EVENT_DEF; +const int ZOO_SESSION_EVENT = SESSION_EVENT_DEF; +const int ZOO_NOTWATCHING_EVENT = NOTWATCHING_EVENT_DEF; +static __attribute__ ((unused)) const char* watcherEvent2String(int ev){ + switch(ev){ + case 0: + return "ZOO_ERROR_EVENT"; + case CREATED_EVENT_DEF: + return "ZOO_CREATED_EVENT"; + case DELETED_EVENT_DEF: + return "ZOO_DELETED_EVENT"; + case CHANGED_EVENT_DEF: + return "ZOO_CHANGED_EVENT"; + case CHILD_EVENT_DEF: + return "ZOO_CHILD_EVENT"; + case SESSION_EVENT_DEF: + return "ZOO_SESSION_EVENT"; + case NOTWATCHING_EVENT_DEF: + return "ZOO_NOTWATCHING_EVENT"; + } + return "INVALID_EVENT"; +} + +const int ZOO_PERM_READ = 1 << 0; +const int ZOO_PERM_WRITE = 1 << 1; +const int ZOO_PERM_CREATE = 1 << 2; +const int ZOO_PERM_DELETE = 1 << 3; +const int ZOO_PERM_ADMIN = 1 << 4; +const int ZOO_PERM_ALL = 0x1f; +struct Id ZOO_ANYONE_ID_UNSAFE = {"world", "anyone"}; +struct Id ZOO_AUTH_IDS = {"auth", ""}; +static struct ACL _OPEN_ACL_UNSAFE_ACL[] = {{0x1f, {"world", "anyone"}}}; +static struct ACL _READ_ACL_UNSAFE_ACL[] = {{0x01, {"world", "anyone"}}}; +static struct ACL _CREATOR_ALL_ACL_ACL[] = {{0x1f, {"auth", ""}}}; +struct ACL_vector ZOO_OPEN_ACL_UNSAFE = { 1, _OPEN_ACL_UNSAFE_ACL}; +struct ACL_vector ZOO_READ_ACL_UNSAFE = { 1, _READ_ACL_UNSAFE_ACL}; +struct ACL_vector ZOO_CREATOR_ALL_ACL = { 1, _CREATOR_ALL_ACL_ACL}; + +#define COMPLETION_WATCH -1 +#define COMPLETION_VOID 0 +#define COMPLETION_STAT 1 +#define COMPLETION_DATA 2 +#define COMPLETION_STRINGLIST 3 +#define COMPLETION_STRINGLIST_STAT 4 +#define COMPLETION_ACLLIST 5 +#define COMPLETION_STRING 6 +#define COMPLETION_MULTI 7 +#define COMPLETION_STRING_STAT 8 + +typedef struct _auth_completion_list { + void_completion_t completion; + const char *auth_data; + struct _auth_completion_list *next; +} auth_completion_list_t; + +typedef struct completion { + int type; /* one of COMPLETION_* values above */ + union { + void_completion_t void_result; + stat_completion_t stat_result; + data_completion_t data_result; + strings_completion_t strings_result; + strings_stat_completion_t strings_stat_result; + acl_completion_t acl_result; + string_completion_t string_result; + string_stat_completion_t string_stat_result; + struct watcher_object_list *watcher_result; + }; + completion_head_t clist; /* For multi-op */ +} completion_t; + +typedef struct _completion_list { + int xid; + completion_t c; + const void *data; + buffer_list_t *buffer; + struct _completion_list *next; + watcher_registration_t* watcher; + watcher_deregistration_t* watcher_deregistration; +} completion_list_t; + +const char*err2string(int err); +static int queue_session_event(zhandle_t *zh, int state); +static const char* format_endpoint_info(const struct sockaddr_storage* ep); + +/* deserialize forward declarations */ +static void deserialize_response(zhandle_t *zh, int type, int xid, int failed, int rc, completion_list_t *cptr, struct iarchive *ia); +static int deserialize_multi(zhandle_t *zh, int xid, completion_list_t *cptr, struct iarchive *ia); + +/* completion routine forward declarations */ +static int add_completion(zhandle_t *zh, int xid, int completion_type, + const void *dc, const void *data, int add_to_front, + watcher_registration_t* wo, completion_head_t *clist); +static int add_completion_deregistration(zhandle_t *zh, int xid, + int completion_type, const void *dc, const void *data, + int add_to_front, watcher_deregistration_t* wo, + completion_head_t *clist); +static int do_add_completion(zhandle_t *zh, const void *dc, completion_list_t *c, + int add_to_front); + +static completion_list_t* create_completion_entry(zhandle_t *zh, int xid, int completion_type, + const void *dc, const void *data, watcher_registration_t* wo, + completion_head_t *clist); +static completion_list_t* create_completion_entry_deregistration(zhandle_t *zh, + int xid, int completion_type, const void *dc, const void *data, + watcher_deregistration_t* wo, completion_head_t *clist); +static completion_list_t* do_create_completion_entry(zhandle_t *zh, + int xid, int completion_type, const void *dc, const void *data, + watcher_registration_t* wo, completion_head_t *clist, + watcher_deregistration_t* wdo); +static void destroy_completion_entry(completion_list_t* c); +static void queue_completion_nolock(completion_head_t *list, completion_list_t *c, + int add_to_front); +static void queue_completion(completion_head_t *list, completion_list_t *c, + int add_to_front); +static int handle_socket_error_msg(zhandle_t *zh, int line, int rc, + const char* format,...); +static void cleanup_bufs(zhandle_t *zh,int callCompletion,int rc); + +static int disable_conn_permute=0; // permute enabled by default + +static __attribute__((unused)) void print_completion_queue(zhandle_t *zh); + +static void *SYNCHRONOUS_MARKER = (void*)&SYNCHRONOUS_MARKER; +static int isValidPath(const char* path, const int flags); + +#ifdef _WIN32 +typedef SOCKET socket_t; +typedef int sendsize_t; +#define SEND_FLAGS 0 +#else +#ifdef __APPLE__ +#define SEND_FLAGS SO_NOSIGPIPE +#endif +#ifdef __linux__ +#define SEND_FLAGS MSG_NOSIGNAL +#endif +#ifndef SEND_FLAGS +#define SEND_FLAGS 0 +#endif +typedef int socket_t; +typedef ssize_t sendsize_t; +#endif + +static void zookeeper_set_sock_nodelay(zhandle_t *, socket_t); +static void zookeeper_set_sock_noblock(zhandle_t *, socket_t); +static void zookeeper_set_sock_timeout(zhandle_t *, socket_t, int); +static socket_t zookeeper_connect(zhandle_t *, struct sockaddr_storage *, socket_t); + + +static sendsize_t zookeeper_send(socket_t s, const void* buf, size_t len) +{ + return send(s, buf, len, SEND_FLAGS); +} + +/** + * Get the system time. + * + * If the monotonic clock is available, we use that. The monotonic clock does + * not change when the wall-clock time is adjusted by NTP or the system + * administrator. The monotonic clock returns a value which is monotonically + * increasing. + * + * If POSIX monotonic clocks are not available, we fall back on the wall-clock. + * + * @param tv (out param) The time. + */ +void get_system_time(struct timeval *tv) +{ + int ret; + +#ifdef __MACH__ // OS X + clock_serv_t cclock; + mach_timespec_t mts; + ret = host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); + if (!ret) { + ret += clock_get_time(cclock, &mts); + ret += mach_port_deallocate(mach_task_self(), cclock); + if (!ret) { + tv->tv_sec = mts.tv_sec; + tv->tv_usec = mts.tv_nsec / 1000; + } + } + if (ret) { + // Default to gettimeofday in case of failure. + ret = gettimeofday(tv, NULL); + } +#elif CLOCK_MONOTONIC_RAW + // On Linux, CLOCK_MONOTONIC is affected by ntp slew but CLOCK_MONOTONIC_RAW + // is not. We want the non-slewed (constant rate) CLOCK_MONOTONIC_RAW if it + // is available. + struct timespec ts = { 0 }; + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts); + tv->tv_sec = ts.tv_sec; + tv->tv_usec = ts.tv_nsec / 1000; +#elif _POSIX_MONOTONIC_CLOCK + struct timespec ts = { 0 }; + ret = clock_gettime(CLOCK_MONOTONIC, &ts); + tv->tv_sec = ts.tv_sec; + tv->tv_usec = ts.tv_nsec / 1000; +#elif _WIN32 + LARGE_INTEGER counts, countsPerSecond, countsPerMicrosecond; + if (QueryPerformanceFrequency(&countsPerSecond) && + QueryPerformanceCounter(&counts)) { + countsPerMicrosecond.QuadPart = countsPerSecond.QuadPart / 1000000; + tv->tv_sec = (long)(counts.QuadPart / countsPerSecond.QuadPart); + tv->tv_usec = (long)((counts.QuadPart % countsPerSecond.QuadPart) / + countsPerMicrosecond.QuadPart); + ret = 0; + } else { + ret = gettimeofday(tv, NULL); + } +#else + ret = gettimeofday(tv, NULL); +#endif + if (ret) { + abort(); + } +} + +const void *zoo_get_context(zhandle_t *zh) +{ + return zh->context; +} + +void zoo_set_context(zhandle_t *zh, void *context) +{ + if (zh != NULL) { + zh->context = context; + } +} + +int zoo_recv_timeout(zhandle_t *zh) +{ + return zh->recv_timeout; +} + +/** these functions are thread unsafe, so make sure that + zoo_lock_auth is called before you access them **/ +static auth_info* get_last_auth(auth_list_head_t *auth_list) { + auth_info *element; + element = auth_list->auth; + if (element == NULL) { + return NULL; + } + while (element->next != NULL) { + element = element->next; + } + return element; +} + +static void free_auth_completion(auth_completion_list_t *a_list) { + auth_completion_list_t *tmp, *ftmp; + if (a_list == NULL) { + return; + } + tmp = a_list->next; + while (tmp != NULL) { + ftmp = tmp; + tmp = tmp->next; + ftmp->completion = NULL; + ftmp->auth_data = NULL; + free(ftmp); + } + a_list->completion = NULL; + a_list->auth_data = NULL; + a_list->next = NULL; + return; +} + +static void add_auth_completion(auth_completion_list_t* a_list, void_completion_t* completion, + const char *data) { + auth_completion_list_t *element; + auth_completion_list_t *n_element; + element = a_list; + if (a_list->completion == NULL) { + //this is the first element + a_list->completion = *completion; + a_list->next = NULL; + a_list->auth_data = data; + return; + } + while (element->next != NULL) { + element = element->next; + } + n_element = (auth_completion_list_t*) malloc(sizeof(auth_completion_list_t)); + n_element->next = NULL; + n_element->completion = *completion; + n_element->auth_data = data; + element->next = n_element; + return; +} + +static void get_auth_completions(auth_list_head_t *auth_list, auth_completion_list_t *a_list) { + auth_info *element; + element = auth_list->auth; + if (element == NULL) { + return; + } + while (element) { + if (element->completion) { + add_auth_completion(a_list, &element->completion, element->data); + } + element->completion = NULL; + element = element->next; + } + return; +} + +static void add_last_auth(auth_list_head_t *auth_list, auth_info *add_el) { + auth_info *element; + element = auth_list->auth; + if (element == NULL) { + //first element in the list + auth_list->auth = add_el; + return; + } + while (element->next != NULL) { + element = element->next; + } + element->next = add_el; + return; +} + +static void init_auth_info(auth_list_head_t *auth_list) +{ + auth_list->auth = NULL; +} + +static void mark_active_auth(zhandle_t *zh) { + auth_list_head_t auth_h = zh->auth_h; + auth_info *element; + if (auth_h.auth == NULL) { + return; + } + element = auth_h.auth; + while (element != NULL) { + element->state = 1; + element = element->next; + } +} + +static void free_auth_info(auth_list_head_t *auth_list) +{ + auth_info *auth = auth_list->auth; + while (auth != NULL) { + auth_info* old_auth = NULL; + if(auth->scheme!=NULL) + free(auth->scheme); + deallocate_Buffer(&auth->auth); + old_auth = auth; + auth = auth->next; + free(old_auth); + } + init_auth_info(auth_list); +} + +int is_unrecoverable(zhandle_t *zh) +{ + return (zh->state<0)? ZINVALIDSTATE: ZOK; +} + +zk_hashtable *exists_result_checker(zhandle_t *zh, int rc) +{ + if (rc == ZOK) { + return zh->active_node_watchers; + } else if (rc == ZNONODE) { + return zh->active_exist_watchers; + } + return 0; +} + +zk_hashtable *data_result_checker(zhandle_t *zh, int rc) +{ + return rc==ZOK ? zh->active_node_watchers : 0; +} + +zk_hashtable *child_result_checker(zhandle_t *zh, int rc) +{ + return rc==ZOK ? zh->active_child_watchers : 0; +} + +/** + * Frees and closes everything associated with a handle, + * including the handle itself. + */ +static void destroy(zhandle_t *zh) +{ + if (zh == NULL) { + return; + } + /* call any outstanding completions with a special error code */ + cleanup_bufs(zh,1,ZCLOSING); + if (zh->hostname != 0) { + free(zh->hostname); + zh->hostname = NULL; + } + if (zh->fd != -1) { + close(zh->fd); + zh->fd = -1; + memset(&zh->addr_cur, 0, sizeof(zh->addr_cur)); + zh->state = 0; + } + addrvec_free(&zh->addrs); + + if (zh->chroot != NULL) { + free(zh->chroot); + zh->chroot = NULL; + } + + free_auth_info(&zh->auth_h); + destroy_zk_hashtable(zh->active_node_watchers); + destroy_zk_hashtable(zh->active_exist_watchers); + destroy_zk_hashtable(zh->active_child_watchers); + addrvec_free(&zh->addrs_old); + addrvec_free(&zh->addrs_new); +} + +static void setup_random() +{ +#ifndef _WIN32 // TODO: better seed + int seed; + int fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + seed = getpid(); + } else { + int seed_len = 0; + + /* Enter a loop to fill in seed with random data from /dev/urandom. + * This is done in a loop so that we can safely handle short reads + * which can happen due to signal interruptions. + */ + while (seed_len < sizeof(seed)) { + /* Assert we either read something or we were interrupted due to a + * signal (errno == EINTR) in which case we need to retry. + */ + int rc = read(fd, &seed + seed_len, sizeof(seed) - seed_len); + assert(rc > 0 || errno == EINTR); + if (rc > 0) { + seed_len += rc; + } + } + close(fd); + } + srandom(seed); + srand48(seed); +#endif +} + +#ifndef __CYGWIN__ +/** + * get the errno from the return code + * of get addrinfo. Errno is not set + * with the call to getaddrinfo, so thats + * why we have to do this. + */ +static int getaddrinfo_errno(int rc) { + switch(rc) { + case EAI_NONAME: +// ZOOKEEPER-1323 EAI_NODATA and EAI_ADDRFAMILY are deprecated in FreeBSD. +#if defined EAI_NODATA && EAI_NODATA != EAI_NONAME + case EAI_NODATA: +#endif + return ENOENT; + case EAI_MEMORY: + return ENOMEM; + default: + return EINVAL; + } +} +#endif + +/** + * Count the number of hosts in the connection host string. This assumes it's + * a well-formed connection string whereby each host is separated by a comma. + */ +static int count_hosts(char *hosts) +{ + uint32_t count = 0; + char *loc = hosts; + if (!hosts || strlen(hosts) == 0) { + return 0; + } + + while ((loc = strchr(loc, ','))) { + count++; + loc+=1; + } + + return count+1; +} + +/** + * Resolve hosts and populate provided address vector with shuffled results. + * The contents of the provided address vector will be initialized to an + * empty state. + */ +static int resolve_hosts(const zhandle_t *zh, const char *hosts_in, addrvec_t *avec) +{ + int rc = ZOK; + char *host = NULL; + char *hosts = NULL; + int num_hosts = 0; + char *strtok_last = NULL; + + if (zh == NULL || hosts_in == NULL || avec == NULL) { + return ZBADARGUMENTS; + } + + // initialize address vector + addrvec_init(avec); + + hosts = strdup(hosts_in); + if (hosts == NULL) { + LOG_ERROR(LOGCALLBACK(zh), "out of memory"); + errno=ENOMEM; + rc=ZSYSTEMERROR; + goto fail; + } + + num_hosts = count_hosts(hosts); + if (num_hosts == 0) { + free(hosts); + return ZOK; + } + + // Allocate list inside avec + rc = addrvec_alloc_capacity(avec, num_hosts); + if (rc != 0) { + LOG_ERROR(LOGCALLBACK(zh), "out of memory"); + errno=ENOMEM; + rc=ZSYSTEMERROR; + goto fail; + } + + host = strtok_r(hosts, ",", &strtok_last); + while(host) { + char *port_spec = strrchr(host, ':'); + char *end_port_spec; + int port; + if (!port_spec) { + LOG_ERROR(LOGCALLBACK(zh), "no port in %s", host); + errno=EINVAL; + rc=ZBADARGUMENTS; + goto fail; + } + *port_spec = '\0'; + port_spec++; + port = strtol(port_spec, &end_port_spec, 0); + if (!*port_spec || *end_port_spec || port == 0) { + LOG_ERROR(LOGCALLBACK(zh), "invalid port in %s", host); + errno=EINVAL; + rc=ZBADARGUMENTS; + goto fail; + } +#if defined(__CYGWIN__) + // sadly CYGWIN doesn't have getaddrinfo + // but happily gethostbyname is threadsafe in windows + { + struct hostent *he; + char **ptr; + struct sockaddr_in *addr4; + + he = gethostbyname(host); + if (!he) { + LOG_ERROR(LOGCALLBACK(zh), "could not resolve %s", host); + errno=ENOENT; + rc=ZBADARGUMENTS; + goto fail; + } + + // Setup the address array + for(ptr = he->h_addr_list;*ptr != 0; ptr++) { + if (addrs->count == addrs->capacity) { + rc = addrvec_grow_default(addrs); + if (rc != 0) { + LOG_ERROR(LOGCALLBACK(zh), "out of memory"); + errno=ENOMEM; + rc=ZSYSTEMERROR; + goto fail; + } + } + addr = &addrs->list[addrs->count]; + addr4 = (struct sockaddr_in*)addr; + addr->ss_family = he->h_addrtype; + if (addr->ss_family == AF_INET) { + addr4->sin_port = htons(port); + memset(&addr4->sin_zero, 0, sizeof(addr4->sin_zero)); + memcpy(&addr4->sin_addr, *ptr, he->h_length); + zh->addrs.count++; + } +#if defined(AF_INET6) + else if (addr->ss_family == AF_INET6) { + struct sockaddr_in6 *addr6; + + addr6 = (struct sockaddr_in6*)addr; + addr6->sin6_port = htons(port); + addr6->sin6_scope_id = 0; + addr6->sin6_flowinfo = 0; + memcpy(&addr6->sin6_addr, *ptr, he->h_length); + zh->addrs.count++; + } +#endif + else { + LOG_WARN(LOGCALLBACK(zh), "skipping unknown address family %x for %s", + addr->ss_family, hosts_in); + } + } + host = strtok_r(0, ",", &strtok_last); + } +#else + { + struct addrinfo hints, *res, *res0; + + memset(&hints, 0, sizeof(hints)); +#ifdef AI_ADDRCONFIG + hints.ai_flags = AI_ADDRCONFIG; +#else + hints.ai_flags = 0; +#endif + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + while(isspace(*host) && host != strtok_last) + host++; + + if ((rc = getaddrinfo(host, port_spec, &hints, &res0)) != 0) { + //bug in getaddrinfo implementation when it returns + //EAI_BADFLAGS or EAI_ADDRFAMILY with AF_UNSPEC and + // ai_flags as AI_ADDRCONFIG +#ifdef AI_ADDRCONFIG + if ((hints.ai_flags == AI_ADDRCONFIG) && +// ZOOKEEPER-1323 EAI_NODATA and EAI_ADDRFAMILY are deprecated in FreeBSD. +#ifdef EAI_ADDRFAMILY + ((rc ==EAI_BADFLAGS) || (rc == EAI_ADDRFAMILY))) { +#else + (rc == EAI_BADFLAGS)) { +#endif + //reset ai_flags to null + hints.ai_flags = 0; + //retry getaddrinfo + rc = getaddrinfo(host, port_spec, &hints, &res0); + } +#endif + if (rc != 0) { + errno = getaddrinfo_errno(rc); +#ifdef _WIN32 + LOG_ERROR(LOGCALLBACK(zh), "Win32 message: %s\n", gai_strerror(rc)); +#elif __linux__ && __GNUC__ + LOG_ERROR(LOGCALLBACK(zh), "getaddrinfo: %s\n", gai_strerror(rc)); +#else + LOG_ERROR(LOGCALLBACK(zh), "getaddrinfo: %s\n", strerror(errno)); +#endif + rc=ZSYSTEMERROR; + goto fail; + } + } + + for (res = res0; res; res = res->ai_next) { + // Expand address list if needed + if (avec->count == avec->capacity) { + rc = addrvec_grow_default(avec); + if (rc != 0) { + LOG_ERROR(LOGCALLBACK(zh), "out of memory"); + errno=ENOMEM; + rc=ZSYSTEMERROR; + goto fail; + } + } + + // Copy addrinfo into address list + switch (res->ai_family) { + case AF_INET: +#if defined(AF_INET6) + case AF_INET6: +#endif + addrvec_append_addrinfo(avec, res); + break; + default: + LOG_WARN(LOGCALLBACK(zh), "skipping unknown address family %x for %s", + res->ai_family, hosts_in); + break; + } + } + + freeaddrinfo(res0); + + host = strtok_r(0, ",", &strtok_last); + } +#endif + } + free(hosts); + + if(!disable_conn_permute){ + setup_random(); + addrvec_shuffle(avec); + } + + return ZOK; + +fail: + addrvec_free(avec); + + if (hosts) { + free(hosts); + hosts = NULL; + } + + return rc; +} + +/** + * Updates the list of servers and determine if changing connections is necessary. + * Permutes server list for proper load balancing. + * + * Changing connections is necessary if one of the following holds: + * a) the server this client is currently connected is not in new address list. + * Otherwise (if currentHost is in the new list): + * b) the number of servers in the cluster is increasing - in this case the load + * on currentHost should decrease, which means that SOME of the clients + * connected to it will migrate to the new servers. The decision whether this + * client migrates or not is probabilistic so that the expected number of + * clients connected to each server is the same. + * + * If reconfig is set to true, the function sets pOld and pNew that correspond + * to the probability to migrate to ones of the new servers or one of the old + * servers (migrating to one of the old servers is done only if our client's + * currentHost is not in new list). + * + * See zoo_cycle_next_server for the selection logic. + * + * See {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1355} for the + * protocol and its evaluation, + */ +int update_addrs(zhandle_t *zh) +{ + int rc = ZOK; + char *hosts = NULL; + uint32_t num_old = 0; + uint32_t num_new = 0; + uint32_t i = 0; + int found_current = 0; + addrvec_t resolved = { 0 }; + + // Verify we have a valid handle + if (zh == NULL) { + return ZBADARGUMENTS; + } + + // zh->hostname should always be set + if (zh->hostname == NULL) + { + return ZSYSTEMERROR; + } + + // NOTE: guard access to {hostname, addr_cur, addrs, addrs_old, addrs_new} + lock_reconfig(zh); + + // Copy zh->hostname for local use + hosts = strdup(zh->hostname); + if (hosts == NULL) { + rc = ZSYSTEMERROR; + goto fail; + } + + rc = resolve_hosts(zh, hosts, &resolved); + if (rc != ZOK) + { + goto fail; + } + + // If the addrvec list is identical to last time we ran don't do anything + if (addrvec_eq(&zh->addrs, &resolved)) + { + goto fail; + } + + // Is the server we're connected to in the new resolved list? + found_current = addrvec_contains(&resolved, &zh->addr_cur); + + // Clear out old and new address lists + zh->reconfig = 1; + addrvec_free(&zh->addrs_old); + addrvec_free(&zh->addrs_new); + + // Divide server list into addrs_old if in previous list and addrs_new if not + for (i = 0; i < resolved.count; i++) + { + struct sockaddr_storage *resolved_address = &resolved.data[i]; + if (addrvec_contains(&zh->addrs, resolved_address)) + { + rc = addrvec_append(&zh->addrs_old, resolved_address); + if (rc != ZOK) + { + goto fail; + } + } + else { + rc = addrvec_append(&zh->addrs_new, resolved_address); + if (rc != ZOK) + { + goto fail; + } + } + } + + num_old = zh->addrs_old.count; + num_new = zh->addrs_new.count; + + // Number of servers increased + if (num_old + num_new > zh->addrs.count) + { + if (found_current) { + // my server is in the new config, but load should be decreased. + // Need to decide if the client is moving to one of the new servers + if (drand48() <= (1 - ((double)zh->addrs.count) / (num_old + num_new))) { + zh->pNew = 1; + zh->pOld = 0; + } else { + // do nothing special -- stay with the current server + zh->reconfig = 0; + } + } else { + // my server is not in the new config, and load on old servers must + // be decreased, so connect to one of the new servers + zh->pNew = 1; + zh->pOld = 0; + } + } + + // Number of servers stayed the same or decreased + else { + if (found_current) { + // my server is in the new config, and load should be increased, so + // stay with this server and do nothing special + zh->reconfig = 0; + } else { + zh->pOld = ((double) (num_old * (zh->addrs.count - (num_old + num_new)))) / ((num_old + num_new) * (zh->addrs.count - num_old)); + zh->pNew = 1 - zh->pOld; + } + } + + addrvec_free(&zh->addrs); + zh->addrs = resolved; + + // If we need to do a reconfig and we're currently connected to a server, + // then force close that connection so on next interest() call we'll make a + // new connection + if (zh->reconfig == 1 && zh->fd != -1) + { + close(zh->fd); + zh->fd = -1; + zh->state = ZOO_NOTCONNECTED_STATE; + } + +fail: + + unlock_reconfig(zh); + + // If we short-circuited out and never assigned resolved to zh->addrs then we + // need to free resolved to avoid a memleak. + if (zh->addrs.data != resolved.data) + { + addrvec_free(&resolved); + } + + if (hosts) { + free(hosts); + hosts = NULL; + } + + return rc; +} + +const clientid_t *zoo_client_id(zhandle_t *zh) +{ + return &zh->client_id; +} + +static void null_watcher_fn(zhandle_t* p1, int p2, int p3,const char* p4,void*p5){} + +watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn) +{ + watcher_fn oldWatcher=zh->watcher; + if (newFn) { + zh->watcher = newFn; + } else { + zh->watcher = null_watcher_fn; + } + return oldWatcher; +} + +struct sockaddr* zookeeper_get_connected_host(zhandle_t *zh, + struct sockaddr *addr, socklen_t *addr_len) +{ + if (zh->state!=ZOO_CONNECTED_STATE) { + return NULL; + } + if (getpeername(zh->fd, addr, addr_len)==-1) { + return NULL; + } + return addr; +} + +static void log_env(zhandle_t *zh) { + char buf[2048]; +#ifdef HAVE_SYS_UTSNAME_H + struct utsname utsname; +#endif + +#if defined(HAVE_GETUID) && defined(HAVE_GETPWUID_R) + struct passwd pw; + struct passwd *pwp = NULL; + uid_t uid = 0; +#endif + + LOG_INFO(LOGCALLBACK(zh), "Client environment:zookeeper.version=%s", PACKAGE_STRING); + +#ifdef HAVE_GETHOSTNAME + gethostname(buf, sizeof(buf)); + LOG_INFO(LOGCALLBACK(zh), "Client environment:host.name=%s", buf); +#else + LOG_INFO(LOGCALLBACK(zh), "Client environment:host.name="); +#endif + +#ifdef HAVE_SYS_UTSNAME_H + uname(&utsname); + LOG_INFO(LOGCALLBACK(zh), "Client environment:os.name=%s", utsname.sysname); + LOG_INFO(LOGCALLBACK(zh), "Client environment:os.arch=%s", utsname.release); + LOG_INFO(LOGCALLBACK(zh), "Client environment:os.version=%s", utsname.version); +#else + LOG_INFO(LOGCALLBACK(zh), "Client environment:os.name="); + LOG_INFO(LOGCALLBACK(zh), "Client environment:os.arch="); + LOG_INFO(LOGCALLBACK(zh), "Client environment:os.version="); +#endif + +#ifdef HAVE_GETLOGIN + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.name=%s", getlogin()); +#else + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.name="); +#endif + +#if defined(HAVE_GETUID) && defined(HAVE_GETPWUID_R) + uid = getuid(); + if (!getpwuid_r(uid, &pw, buf, sizeof(buf), &pwp) && pwp) { + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.home=%s", pw.pw_dir); + } else { + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.home="); + } +#else + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.home="); +#endif + +#ifdef HAVE_GETCWD + if (!getcwd(buf, sizeof(buf))) { + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.dir="); + } else { + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.dir=%s", buf); + } +#else + LOG_INFO(LOGCALLBACK(zh), "Client environment:user.dir="); +#endif +} + +/** + * Create a zookeeper handle associated with the given host and port. + */ +static zhandle_t *zookeeper_init_internal(const char *host, watcher_fn watcher, + int recv_timeout, const clientid_t *clientid, void *context, int flags, + log_callback_fn log_callback) +{ + int errnosave = 0; + zhandle_t *zh = NULL; + char *index_chroot = NULL; + + // Create our handle + zh = calloc(1, sizeof(*zh)); + if (!zh) { + return 0; + } + + // Set log callback before calling into log_env + zh->log_callback = log_callback; + log_env(zh); + +#ifdef _WIN32 + if (Win32WSAStartup()){ + LOG_ERROR(LOGCALLBACK(zh), "Error initializing ws2_32.dll"); + return 0; + } +#endif + LOG_INFO(LOGCALLBACK(zh), "Initiating client connection, host=%s sessionTimeout=%d watcher=%p" + " sessionId=%#llx sessionPasswd=%s context=%p flags=%d", + host, + recv_timeout, + watcher, + (clientid == 0 ? 0 : clientid->client_id), + ((clientid == 0) || (clientid->passwd[0] == 0) ? + "" : ""), + context, + flags); + + zh->hostname = NULL; + zh->fd = -1; + zh->state = ZOO_NOTCONNECTED_STATE; + zh->context = context; + zh->recv_timeout = recv_timeout; + zh->allow_read_only = flags & ZOO_READONLY; + // non-zero clientid implies we've seen r/w server already + zh->seen_rw_server_before = (clientid != 0 && clientid->client_id != 0); + init_auth_info(&zh->auth_h); + if (watcher) { + zh->watcher = watcher; + } else { + zh->watcher = null_watcher_fn; + } + if (host == 0 || *host == 0) { // what we shouldn't dup + errno=EINVAL; + goto abort; + } + //parse the host to get the chroot if available + index_chroot = strchr(host, '/'); + if (index_chroot) { + zh->chroot = strdup(index_chroot); + if (zh->chroot == NULL) { + goto abort; + } + // if chroot is just / set it to null + if (strlen(zh->chroot) == 1) { + free(zh->chroot); + zh->chroot = NULL; + } + // cannot use strndup so allocate and strcpy + zh->hostname = (char *) malloc(index_chroot - host + 1); + zh->hostname = strncpy(zh->hostname, host, (index_chroot - host)); + //strncpy does not null terminate + *(zh->hostname + (index_chroot - host)) = '\0'; + + } else { + zh->chroot = NULL; + zh->hostname = strdup(host); + } + if (zh->chroot && !isValidPath(zh->chroot, 0)) { + errno = EINVAL; + goto abort; + } + if (zh->hostname == 0) { + goto abort; + } + if(update_addrs(zh) != 0) { + goto abort; + } + + if (clientid) { + memcpy(&zh->client_id, clientid, sizeof(zh->client_id)); + } else { + memset(&zh->client_id, 0, sizeof(zh->client_id)); + } + zh->io_count = 0; + zh->primer_buffer.buffer = zh->primer_storage_buffer; + zh->primer_buffer.curr_offset = 0; + zh->primer_buffer.len = sizeof(zh->primer_storage_buffer); + zh->primer_buffer.next = 0; + zh->last_zxid = 0; + zh->next_deadline.tv_sec=zh->next_deadline.tv_usec=0; + zh->socket_readable.tv_sec=zh->socket_readable.tv_usec=0; + zh->active_node_watchers=create_zk_hashtable(); + zh->active_exist_watchers=create_zk_hashtable(); + zh->active_child_watchers=create_zk_hashtable(); + + if (adaptor_init(zh) == -1) { + goto abort; + } + + return zh; +abort: + errnosave=errno; + destroy(zh); + free(zh); + errno=errnosave; + return 0; +} + +zhandle_t *zookeeper_init(const char *host, watcher_fn watcher, + int recv_timeout, const clientid_t *clientid, void *context, int flags) +{ + return zookeeper_init_internal(host, watcher, recv_timeout, clientid, context, flags, NULL); +} + +zhandle_t *zookeeper_init2(const char *host, watcher_fn watcher, + int recv_timeout, const clientid_t *clientid, void *context, int flags, + log_callback_fn log_callback) +{ + return zookeeper_init_internal(host, watcher, recv_timeout, clientid, context, flags, log_callback); +} + +/** + * Set a new list of zk servers to connect to. Disconnect will occur if + * current connection endpoint is not in the list. + */ +int zoo_set_servers(zhandle_t *zh, const char *hosts) +{ + if (hosts == NULL) + { + LOG_ERROR(LOGCALLBACK(zh), "New server list cannot be empty"); + return ZBADARGUMENTS; + } + + // NOTE: guard access to {hostname, addr_cur, addrs, addrs_old, addrs_new} + lock_reconfig(zh); + + // Reset hostname to new set of hosts to connect to + if (zh->hostname) { + free(zh->hostname); + } + + zh->hostname = strdup(hosts); + + unlock_reconfig(zh); + + return update_addrs(zh); +} + +/** + * Get the next server to connect to, when in 'reconfig' mode, which means that + * we've updated the server list to connect to, and are now trying to find some + * server to connect to. Once we get successfully connected, 'reconfig' mode is + * set to false. Similarly, if we tried to connect to all servers in new config + * and failed, 'reconfig' mode is set to false. + * + * While in 'reconfig' mode, we should connect to a server in the new set of + * servers (addrs_new) with probability pNew and to servers in the old set of + * servers (addrs_old) with probability pOld (which is just 1-pNew). If we tried + * out all servers in either, we continue to try servers from the other set, + * regardless of pNew or pOld. If we tried all servers we give up and go back to + * the normal round robin mode + * + * When called, must be protected by lock_reconfig(zh). + */ +static int get_next_server_in_reconfig(zhandle_t *zh) +{ + int take_new = drand48() <= zh->pNew; + + LOG_DEBUG(LOGCALLBACK(zh), "[OLD] count=%d capacity=%d next=%d hasnext=%d", + zh->addrs_old.count, zh->addrs_old.capacity, zh->addrs_old.next, + addrvec_hasnext(&zh->addrs_old)); + LOG_DEBUG(LOGCALLBACK(zh), "[NEW] count=%d capacity=%d next=%d hasnext=%d", + zh->addrs_new.count, zh->addrs_new.capacity, zh->addrs_new.next, + addrvec_hasnext(&zh->addrs_new)); + + // Take one of the new servers if we haven't tried them all yet + // and either the probability tells us to connect to one of the new servers + // or if we already tried them all then use one of the old servers + if (addrvec_hasnext(&zh->addrs_new) + && (take_new || !addrvec_hasnext(&zh->addrs_old))) + { + addrvec_next(&zh->addrs_new, &zh->addr_cur); + LOG_DEBUG(LOGCALLBACK(zh), "Using next from NEW=%s", format_endpoint_info(&zh->addr_cur)); + return 0; + } + + // start taking old servers + if (addrvec_hasnext(&zh->addrs_old)) { + addrvec_next(&zh->addrs_old, &zh->addr_cur); + LOG_DEBUG(LOGCALLBACK(zh), "Using next from OLD=%s", format_endpoint_info(&zh->addr_cur)); + return 0; + } + + LOG_DEBUG(LOGCALLBACK(zh), "Failed to find either new or old"); + memset(&zh->addr_cur, 0, sizeof(zh->addr_cur)); + return 1; +} + +/** + * Cycle through our server list to the correct 'next' server. The 'next' server + * to connect to depends upon whether we're in a 'reconfig' mode or not. Reconfig + * mode means we've upated the server list and are now trying to find a server + * to connect to. Once we get connected, we are no longer in the reconfig mode. + * Similarly, if we try to connect to all the servers in the new configuration + * and failed, reconfig mode is set to false. + * + * For more algorithm details, see get_next_server_in_reconfig. + */ +void zoo_cycle_next_server(zhandle_t *zh) +{ + // NOTE: guard access to {hostname, addr_cur, addrs, addrs_old, addrs_new} + lock_reconfig(zh); + + memset(&zh->addr_cur, 0, sizeof(zh->addr_cur)); + + if (zh->reconfig) + { + if (get_next_server_in_reconfig(zh) == 0) { + unlock_reconfig(zh); + return; + } + + // tried all new and old servers and couldn't connect + zh->reconfig = 0; + } + + addrvec_next(&zh->addrs, &zh->addr_cur); + + unlock_reconfig(zh); + + return; +} + +/** + * Get the host:port for the server we are currently connecting to or connected + * to. This is largely for testing purposes but is also generally useful for + * other client software built on top of this client. + */ +const char* zoo_get_current_server(zhandle_t* zh) +{ + const char *endpoint_info = NULL; + + // NOTE: guard access to {hostname, addr_cur, addrs, addrs_old, addrs_new} + // Need the lock here as it is changed in update_addrs() + lock_reconfig(zh); + + endpoint_info = format_endpoint_info(&zh->addr_cur); + unlock_reconfig(zh); + return endpoint_info; +} + +/** + * deallocated the free_path only its beeen allocated + * and not equal to path + */ +void free_duplicate_path(const char *free_path, const char* path) { + if (free_path != path) { + free((void*)free_path); + } +} + +/** + prepend the chroot path if available else return the path +*/ +static char* prepend_string(zhandle_t *zh, const char* client_path) { + char *ret_str; + if (zh == NULL || zh->chroot == NULL) + return (char *) client_path; + // handle the chroot itself, client_path = "/" + if (strlen(client_path) == 1) { + return strdup(zh->chroot); + } + ret_str = (char *) malloc(strlen(zh->chroot) + strlen(client_path) + 1); + strcpy(ret_str, zh->chroot); + return strcat(ret_str, client_path); +} + +/** + strip off the chroot string from the server path + if there is one else return the exact path + */ +char* sub_string(zhandle_t *zh, const char* server_path) { + char *ret_str; + if (zh->chroot == NULL) + return (char *) server_path; + //ZOOKEEPER-1027 + if (strncmp(server_path, zh->chroot, strlen(zh->chroot)) != 0) { + LOG_ERROR(LOGCALLBACK(zh), "server path %s does not include chroot path %s", + server_path, zh->chroot); + return (char *) server_path; + } + if (strlen(server_path) == strlen(zh->chroot)) { + //return "/" + ret_str = strdup("/"); + return ret_str; + } + ret_str = strdup(server_path + strlen(zh->chroot)); + return ret_str; +} + +static buffer_list_t *allocate_buffer(char *buff, int len) +{ + buffer_list_t *buffer = calloc(1, sizeof(*buffer)); + if (buffer == 0) + return 0; + + buffer->len = len==0?sizeof(*buffer):len; + buffer->curr_offset = 0; + buffer->buffer = buff; + buffer->next = 0; + return buffer; +} + +static void free_buffer(buffer_list_t *b) +{ + if (!b) { + return; + } + if (b->buffer) { + free(b->buffer); + } + free(b); +} + +static buffer_list_t *dequeue_buffer(buffer_head_t *list) +{ + buffer_list_t *b; + lock_buffer_list(list); + b = list->head; + if (b) { + list->head = b->next; + if (!list->head) { + assert(b == list->last); + list->last = 0; + } + } + unlock_buffer_list(list); + return b; +} + +static int remove_buffer(buffer_head_t *list) +{ + buffer_list_t *b = dequeue_buffer(list); + if (!b) { + return 0; + } + free_buffer(b); + return 1; +} + +static void queue_buffer(buffer_head_t *list, buffer_list_t *b, int add_to_front) +{ + b->next = 0; + lock_buffer_list(list); + if (list->head) { + assert(list->last); + // The list is not empty + if (add_to_front) { + b->next = list->head; + list->head = b; + } else { + list->last->next = b; + list->last = b; + } + }else{ + // The list is empty + assert(!list->head); + list->head = b; + list->last = b; + } + unlock_buffer_list(list); +} + +static int queue_buffer_bytes(buffer_head_t *list, char *buff, int len) +{ + buffer_list_t *b = allocate_buffer(buff,len); + if (!b) + return ZSYSTEMERROR; + queue_buffer(list, b, 0); + return ZOK; +} + +static int queue_front_buffer_bytes(buffer_head_t *list, char *buff, int len) +{ + buffer_list_t *b = allocate_buffer(buff,len); + if (!b) + return ZSYSTEMERROR; + queue_buffer(list, b, 1); + return ZOK; +} + +static __attribute__ ((unused)) int get_queue_len(buffer_head_t *list) +{ + int i; + buffer_list_t *ptr; + lock_buffer_list(list); + ptr = list->head; + for (i=0; ptr!=0; ptr=ptr->next, i++) + ; + unlock_buffer_list(list); + return i; +} +/* returns: + * -1 if send failed, + * 0 if send would block while sending the buffer (or a send was incomplete), + * 1 if success + */ +static int send_buffer(socket_t fd, buffer_list_t *buff) +{ + int len = buff->len; + int off = buff->curr_offset; + int rc = -1; + + if (off < 4) { + /* we need to send the length at the beginning */ + int nlen = htonl(len); + char *b = (char*)&nlen; + rc = zookeeper_send(fd, b + off, sizeof(nlen) - off); + if (rc == -1) { +#ifdef _WIN32 + if (WSAGetLastError() != WSAEWOULDBLOCK) { +#else + if (errno != EAGAIN) { +#endif + return -1; + } else { + return 0; + } + } else { + buff->curr_offset += rc; + } + off = buff->curr_offset; + } + if (off >= 4) { + /* want off to now represent the offset into the buffer */ + off -= sizeof(buff->len); + rc = zookeeper_send(fd, buff->buffer + off, len - off); + if (rc == -1) { +#ifdef _WIN32 + if (WSAGetLastError() != WSAEWOULDBLOCK) { +#else + if (errno != EAGAIN) { +#endif + return -1; + } + } else { + buff->curr_offset += rc; + } + } + return buff->curr_offset == len + sizeof(buff->len); +} + +/* returns: + * -1 if recv call failed, + * 0 if recv would block, + * 1 if success + */ +static int recv_buffer(zhandle_t *zh, buffer_list_t *buff) +{ + int off = buff->curr_offset; + int rc = 0; + + /* if buffer is less than 4, we are reading in the length */ + if (off < 4) { + char *buffer = (char*)&(buff->len); + rc = recv(zh->fd, buffer+off, sizeof(int)-off, 0); + switch (rc) { + case 0: + errno = EHOSTDOWN; + case -1: +#ifdef _WIN32 + if (WSAGetLastError() == WSAEWOULDBLOCK) { +#else + if (errno == EAGAIN) { +#endif + return 0; + } + return -1; + default: + buff->curr_offset += rc; + } + off = buff->curr_offset; + if (buff->curr_offset == sizeof(buff->len)) { + buff->len = ntohl(buff->len); + buff->buffer = calloc(1, buff->len); + } + } + if (buff->buffer) { + /* want off to now represent the offset into the buffer */ + off -= sizeof(buff->len); + + rc = recv(zh->fd, buff->buffer+off, buff->len-off, 0); + + /* dirty hack to make new client work against old server + * old server sends 40 bytes to finish connection handshake, + * while we're expecting 41 (1 byte for read-only mode data) */ + if (buff == &zh->primer_buffer && rc == buff->len - 1) ++rc; + + switch(rc) { + case 0: + errno = EHOSTDOWN; + case -1: +#ifdef _WIN32 + if (WSAGetLastError() == WSAEWOULDBLOCK) { +#else + if (errno == EAGAIN) { +#endif + break; + } + return -1; + default: + buff->curr_offset += rc; + } + } + return buff->curr_offset == buff->len + sizeof(buff->len); +} + +void free_buffers(buffer_head_t *list) +{ + while (remove_buffer(list)) + ; +} + +void free_completions(zhandle_t *zh,int callCompletion,int reason) +{ + completion_head_t tmp_list; + struct oarchive *oa; + struct ReplyHeader h; + void_completion_t auth_completion = NULL; + auth_completion_list_t a_list, *a_tmp; + + if (lock_completion_list(&zh->sent_requests) == 0) { + tmp_list = zh->sent_requests; + zh->sent_requests.head = 0; + zh->sent_requests.last = 0; + unlock_completion_list(&zh->sent_requests); + while (tmp_list.head) { + completion_list_t *cptr = tmp_list.head; + + tmp_list.head = cptr->next; + if (cptr->c.data_result == SYNCHRONOUS_MARKER) { + struct sync_completion + *sc = (struct sync_completion*)cptr->data; + sc->rc = reason; + notify_sync_completion(sc); + zh->outstanding_sync--; + destroy_completion_entry(cptr); + } else if (callCompletion) { + // Fake the response + buffer_list_t *bptr; + h.xid = cptr->xid; + h.zxid = -1; + h.err = reason; + oa = create_buffer_oarchive(); + serialize_ReplyHeader(oa, "header", &h); + bptr = calloc(sizeof(*bptr), 1); + assert(bptr); + bptr->len = get_buffer_len(oa); + bptr->buffer = get_buffer(oa); + close_buffer_oarchive(&oa, 0); + cptr->buffer = bptr; + queue_completion(&zh->completions_to_process, cptr, 0); + } + } + } + if (zoo_lock_auth(zh) == 0) { + a_list.completion = NULL; + a_list.next = NULL; + + get_auth_completions(&zh->auth_h, &a_list); + zoo_unlock_auth(zh); + + a_tmp = &a_list; + // chain call user's completion function + while (a_tmp->completion != NULL) { + auth_completion = a_tmp->completion; + auth_completion(reason, a_tmp->auth_data); + a_tmp = a_tmp->next; + if (a_tmp == NULL) + break; + } + } + free_auth_completion(&a_list); +} + +static void cleanup_bufs(zhandle_t *zh,int callCompletion,int rc) +{ + enter_critical(zh); + free_buffers(&zh->to_send); + free_buffers(&zh->to_process); + free_completions(zh,callCompletion,rc); + leave_critical(zh); + if (zh->input_buffer && zh->input_buffer != &zh->primer_buffer) { + free_buffer(zh->input_buffer); + zh->input_buffer = 0; + } +} + +/* return 1 if zh's state is ZOO_CONNECTED_STATE or ZOO_READONLY_STATE, + * 0 otherwise */ +static int is_connected(zhandle_t* zh) +{ + return (zh->state==ZOO_CONNECTED_STATE || zh->state==ZOO_READONLY_STATE); +} + +static void handle_error(zhandle_t *zh,int rc) +{ + close(zh->fd); + if (is_unrecoverable(zh)) { + LOG_DEBUG(LOGCALLBACK(zh), "Calling a watcher for a ZOO_SESSION_EVENT and the state=%s", + state2String(zh->state)); + PROCESS_SESSION_EVENT(zh, zh->state); + } else if (is_connected(zh)) { + LOG_DEBUG(LOGCALLBACK(zh), "Calling a watcher for a ZOO_SESSION_EVENT and the state=CONNECTING_STATE"); + PROCESS_SESSION_EVENT(zh, ZOO_CONNECTING_STATE); + } + cleanup_bufs(zh,1,rc); + zh->fd = -1; + + LOG_DEBUG(LOGCALLBACK(zh), "Previous connection=[%s] delay=%d", zoo_get_current_server(zh), zh->delay); + + // NOTE: If we're at the end of the list of addresses to connect to, then + // we want to delay the next connection attempt to avoid spinning. + // Then increment what host we'll connect to since we failed to connect to current + zh->delay = addrvec_atend(&zh->addrs); + addrvec_next(&zh->addrs, &zh->addr_cur); + + if (!is_unrecoverable(zh)) { + zh->state = 0; + } + if (process_async(zh->outstanding_sync)) { + process_completions(zh); + } +} + +static int handle_socket_error_msg(zhandle_t *zh, int line, int rc, + const char* format, ...) +{ + if(logLevel>=ZOO_LOG_LEVEL_ERROR){ + va_list va; + char buf[1024]; + va_start(va,format); + vsnprintf(buf, sizeof(buf)-1,format,va); + log_message(LOGCALLBACK(zh), ZOO_LOG_LEVEL_ERROR,line,__func__, + "Socket [%s] zk retcode=%d, errno=%d(%s): %s", + zoo_get_current_server(zh),rc,errno,strerror(errno),buf); + va_end(va); + } + handle_error(zh,rc); + return rc; +} + +static void auth_completion_func(int rc, zhandle_t* zh) +{ + void_completion_t auth_completion = NULL; + auth_completion_list_t a_list; + auth_completion_list_t *a_tmp; + + if(zh==NULL) + return; + + zoo_lock_auth(zh); + + if(rc!=0){ + zh->state=ZOO_AUTH_FAILED_STATE; + }else{ + //change state for all auths + mark_active_auth(zh); + } + a_list.completion = NULL; + a_list.next = NULL; + get_auth_completions(&zh->auth_h, &a_list); + zoo_unlock_auth(zh); + if (rc) { + LOG_ERROR(LOGCALLBACK(zh), "Authentication scheme %s failed. Connection closed.", + zh->auth_h.auth->scheme); + } + else { + LOG_INFO(LOGCALLBACK(zh), "Authentication scheme %s succeeded", zh->auth_h.auth->scheme); + } + a_tmp = &a_list; + // chain call user's completion function + while (a_tmp->completion != NULL) { + auth_completion = a_tmp->completion; + auth_completion(rc, a_tmp->auth_data); + a_tmp = a_tmp->next; + if (a_tmp == NULL) + break; + } + free_auth_completion(&a_list); +} + +static int send_info_packet(zhandle_t *zh, auth_info* auth) { + struct oarchive *oa; + struct RequestHeader h = {AUTH_XID, ZOO_SETAUTH_OP}; + struct AuthPacket req; + int rc; + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + req.type=0; // ignored by the server + req.scheme = auth->scheme; + req.auth = auth->auth; + rc = rc < 0 ? rc : serialize_AuthPacket(oa, "req", &req); + /* add this buffer to the head of the send queue */ + rc = rc < 0 ? rc : queue_front_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + return rc; +} + +/** send all auths, not just the last one **/ +static int send_auth_info(zhandle_t *zh) { + int rc = 0; + auth_info *auth = NULL; + + zoo_lock_auth(zh); + auth = zh->auth_h.auth; + if (auth == NULL) { + zoo_unlock_auth(zh); + return ZOK; + } + while (auth != NULL) { + rc = send_info_packet(zh, auth); + auth = auth->next; + } + zoo_unlock_auth(zh); + LOG_DEBUG(LOGCALLBACK(zh), "Sending all auth info request to %s", zoo_get_current_server(zh)); + return (rc <0) ? ZMARSHALLINGERROR:ZOK; +} + +static int send_last_auth_info(zhandle_t *zh) +{ + int rc = 0; + auth_info *auth = NULL; + + zoo_lock_auth(zh); + auth = get_last_auth(&zh->auth_h); + if(auth==NULL) { + zoo_unlock_auth(zh); + return ZOK; // there is nothing to send + } + rc = send_info_packet(zh, auth); + zoo_unlock_auth(zh); + LOG_DEBUG(LOGCALLBACK(zh), "Sending auth info request to %s",zoo_get_current_server(zh)); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +static void free_key_list(char **list, int count) +{ + int i; + + for(i = 0; i < count; i++) { + free(list[i]); + } + free(list); +} + +static int send_set_watches(zhandle_t *zh) +{ + struct oarchive *oa; + struct RequestHeader h = {SET_WATCHES_XID, ZOO_SETWATCHES_OP}; + struct SetWatches req; + int rc; + + req.relativeZxid = zh->last_zxid; + req.dataWatches.data = collect_keys(zh->active_node_watchers, (int*)&req.dataWatches.count); + req.existWatches.data = collect_keys(zh->active_exist_watchers, (int*)&req.existWatches.count); + req.childWatches.data = collect_keys(zh->active_child_watchers, (int*)&req.childWatches.count); + + // return if there are no pending watches + if (!req.dataWatches.count && !req.existWatches.count && + !req.childWatches.count) { + free_key_list(req.dataWatches.data, req.dataWatches.count); + free_key_list(req.existWatches.data, req.existWatches.count); + free_key_list(req.childWatches.data, req.childWatches.count); + return ZOK; + } + + + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_SetWatches(oa, "req", &req); + /* add this buffer to the head of the send queue */ + rc = rc < 0 ? rc : queue_front_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + free_key_list(req.dataWatches.data, req.dataWatches.count); + free_key_list(req.existWatches.data, req.existWatches.count); + free_key_list(req.childWatches.data, req.childWatches.count); + LOG_DEBUG(LOGCALLBACK(zh), "Sending set watches request to %s",zoo_get_current_server(zh)); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +static int serialize_prime_connect(struct connect_req *req, char* buffer){ + //this should be the order of serialization + int offset = 0; + req->protocolVersion = htonl(req->protocolVersion); + memcpy(buffer + offset, &req->protocolVersion, sizeof(req->protocolVersion)); + offset = offset + sizeof(req->protocolVersion); + + req->lastZxidSeen = zoo_htonll(req->lastZxidSeen); + memcpy(buffer + offset, &req->lastZxidSeen, sizeof(req->lastZxidSeen)); + offset = offset + sizeof(req->lastZxidSeen); + + req->timeOut = htonl(req->timeOut); + memcpy(buffer + offset, &req->timeOut, sizeof(req->timeOut)); + offset = offset + sizeof(req->timeOut); + + req->sessionId = zoo_htonll(req->sessionId); + memcpy(buffer + offset, &req->sessionId, sizeof(req->sessionId)); + offset = offset + sizeof(req->sessionId); + + req->passwd_len = htonl(req->passwd_len); + memcpy(buffer + offset, &req->passwd_len, sizeof(req->passwd_len)); + offset = offset + sizeof(req->passwd_len); + + memcpy(buffer + offset, req->passwd, sizeof(req->passwd)); + offset = offset + sizeof(req->passwd); + + memcpy(buffer + offset, &req->readOnly, sizeof(req->readOnly)); + + return 0; +} + +static int deserialize_prime_response(struct prime_struct *resp, char* buffer) +{ + //this should be the order of deserialization + int offset = 0; + memcpy(&resp->len, buffer + offset, sizeof(resp->len)); + offset = offset + sizeof(resp->len); + + resp->len = ntohl(resp->len); + memcpy(&resp->protocolVersion, + buffer + offset, + sizeof(resp->protocolVersion)); + offset = offset + sizeof(resp->protocolVersion); + + resp->protocolVersion = ntohl(resp->protocolVersion); + memcpy(&resp->timeOut, buffer + offset, sizeof(resp->timeOut)); + offset = offset + sizeof(resp->timeOut); + + resp->timeOut = ntohl(resp->timeOut); + memcpy(&resp->sessionId, buffer + offset, sizeof(resp->sessionId)); + offset = offset + sizeof(resp->sessionId); + + resp->sessionId = zoo_htonll(resp->sessionId); + memcpy(&resp->passwd_len, buffer + offset, sizeof(resp->passwd_len)); + offset = offset + sizeof(resp->passwd_len); + + resp->passwd_len = ntohl(resp->passwd_len); + memcpy(resp->passwd, buffer + offset, sizeof(resp->passwd)); + offset = offset + sizeof(resp->passwd); + + memcpy(&resp->readOnly, buffer + offset, sizeof(resp->readOnly)); + + return 0; +} + +static int prime_connection(zhandle_t *zh) +{ + int rc; + /*this is the size of buffer to serialize req into*/ + char buffer_req[HANDSHAKE_REQ_SIZE]; + int len = sizeof(buffer_req); + int hlen = 0; + struct connect_req req; + req.protocolVersion = 0; + req.sessionId = zh->seen_rw_server_before ? zh->client_id.client_id : 0; + req.passwd_len = sizeof(req.passwd); + memcpy(req.passwd, zh->client_id.passwd, sizeof(zh->client_id.passwd)); + req.timeOut = zh->recv_timeout; + req.lastZxidSeen = zh->last_zxid; + req.readOnly = zh->allow_read_only; + hlen = htonl(len); + /* We are running fast and loose here, but this string should fit in the initial buffer! */ + rc=zookeeper_send(zh->fd, &hlen, sizeof(len)); + serialize_prime_connect(&req, buffer_req); + rc=rc<0 ? rc : zookeeper_send(zh->fd, buffer_req, len); + if (rc<0) { + return handle_socket_error_msg(zh, __LINE__, ZCONNECTIONLOSS, + "failed to send a handshake packet: %s", strerror(errno)); + } + zh->state = ZOO_ASSOCIATING_STATE; + + zh->input_buffer = &zh->primer_buffer; + memset(zh->input_buffer->buffer, 0, zh->input_buffer->len); + + /* This seems a bit weird to to set the offset to 4, but we already have a + * length, so we skip reading the length (and allocating the buffer) by + * saying that we are already at offset 4 */ + zh->input_buffer->curr_offset = 4; + + return ZOK; +} + +static inline int calculate_interval(const struct timeval *start, + const struct timeval *end) +{ + int interval; + struct timeval i = *end; + i.tv_sec -= start->tv_sec; + i.tv_usec -= start->tv_usec; + interval = i.tv_sec * 1000 + (i.tv_usec/1000); + return interval; +} + +static struct timeval get_timeval(int interval) +{ + struct timeval tv; + if (interval < 0) { + interval = 0; + } + tv.tv_sec = interval/1000; + tv.tv_usec = (interval%1000)*1000; + return tv; +} + + static int add_void_completion(zhandle_t *zh, int xid, void_completion_t dc, + const void *data); + static int add_string_completion(zhandle_t *zh, int xid, + string_completion_t dc, const void *data); + static int add_string_stat_completion(zhandle_t *zh, int xid, + string_stat_completion_t dc, const void *data); + + + int send_ping(zhandle_t* zh) + { + int rc; + struct oarchive *oa = create_buffer_oarchive(); + struct RequestHeader h = {PING_XID, ZOO_PING_OP}; + + rc = serialize_RequestHeader(oa, "header", &h); + enter_critical(zh); + get_system_time(&zh->last_ping); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + close_buffer_oarchive(&oa, 0); + return rc<0 ? rc : adaptor_send_queue(zh, 0); +} + +/* upper bound of a timeout for seeking for r/w server when in read-only mode */ +const int MAX_RW_TIMEOUT = 60000; +const int MIN_RW_TIMEOUT = 200; + +static int ping_rw_server(zhandle_t* zh) +{ + char buf[10]; + socket_t sock; + int rc; + sendsize_t ssize; + struct sockaddr_storage addr; + + addrvec_peek(&zh->addrs, &addr); + + sock = socket(addr.ss_family, SOCK_STREAM, 0); + if (sock < 0) { + return 0; + } + + zookeeper_set_sock_nodelay(zh, sock); + zookeeper_set_sock_timeout(zh, sock, 1); + + rc = zookeeper_connect(zh, &addr, sock); + if (rc < 0) { + return 0; + } + + ssize = zookeeper_send(sock, "isro", 4); + if (ssize < 0) { + rc = 0; + goto out; + } + + memset(buf, 0, sizeof(buf)); + rc = recv(sock, buf, sizeof(buf), 0); + if (rc < 0) { + rc = 0; + goto out; + } + + rc = strcmp("rw", buf) == 0; + +out: + close(sock); + return rc; +} + +static inline int min(int a, int b) +{ + return a < b ? a : b; +} + +static void zookeeper_set_sock_noblock(zhandle_t *zh, socket_t sock) +{ +#ifdef _WIN32 + ULONG nonblocking_flag = 1; + + ioctlsocket(sock, FIONBIO, &nonblocking_flag); +#else + fcntl(sock, F_SETFL, O_NONBLOCK|fcntl(sock, F_GETFL, 0)); +#endif +} + +static void zookeeper_set_sock_timeout(zhandle_t *zh, socket_t s, int timeout) +{ + struct timeval tv; + + tv.tv_sec = timeout; + setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)); + setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); +} + +static void zookeeper_set_sock_nodelay(zhandle_t *zh, socket_t sock) +{ +#ifdef _WIN32 + char enable_tcp_nodelay = 1; +#else + int enable_tcp_nodelay = 1; +#endif + int rc; + + rc = setsockopt(sock, + IPPROTO_TCP, + TCP_NODELAY, + &enable_tcp_nodelay, + sizeof(enable_tcp_nodelay)); + + if (rc) { + LOG_WARN(LOGCALLBACK(zh), + "Unable to set TCP_NODELAY, latency may be effected"); + } +} + +static socket_t zookeeper_connect(zhandle_t *zh, + struct sockaddr_storage *addr, + socket_t fd) +{ + int rc; + int addr_len; + +#if defined(AF_INET6) + if (addr->ss_family == AF_INET6) { + addr_len = sizeof(struct sockaddr_in6); + } else { + addr_len = sizeof(struct sockaddr_in); + } +#else + addr_len = sizeof(struct sockaddr_in); +#endif + + LOG_DEBUG(LOGCALLBACK(zh), "[zk] connect()\n"); + rc = connect(fd, (struct sockaddr *)addr, addr_len); + +#ifdef _WIN32 + get_errno(); +#if _MSC_VER >= 1600 + switch(errno) { + case WSAEWOULDBLOCK: + errno = EWOULDBLOCK; + break; + case WSAEINPROGRESS: + errno = EINPROGRESS; + break; + } +#endif +#endif + + return rc; +} + +int zookeeper_interest(zhandle_t *zh, socket_t *fd, int *interest, + struct timeval *tv) +{ + int rc = 0; + struct timeval now; + if(zh==0 || fd==0 ||interest==0 || tv==0) + return ZBADARGUMENTS; + if (is_unrecoverable(zh)) + return ZINVALIDSTATE; + get_system_time(&now); + if(zh->next_deadline.tv_sec!=0 || zh->next_deadline.tv_usec!=0){ + int time_left = calculate_interval(&zh->next_deadline, &now); + int max_exceed = zh->recv_timeout / 10 > 200 ? 200 : + (zh->recv_timeout / 10); + if (time_left > max_exceed) + LOG_WARN(LOGCALLBACK(zh), "Exceeded deadline by %dms", time_left); + } + api_prolog(zh); + + rc = update_addrs(zh); + if (rc != ZOK) { + return api_epilog(zh, rc); + } + + *fd = zh->fd; + *interest = 0; + tv->tv_sec = 0; + tv->tv_usec = 0; + + if (*fd == -1) { + /* + * If we previously failed to connect to server pool (zh->delay == 1) + * then we need delay our connection on this iteration 1/60 of the + * recv timeout before trying again so we don't spin. + * + * We always clear the delay setting. If we fail again, we'll set delay + * again and on the next iteration we'll do the same. + */ + if (zh->delay == 1) { + *tv = get_timeval(zh->recv_timeout/60); + zh->delay = 0; + + LOG_WARN(LOGCALLBACK(zh), "Delaying connection after exhaustively trying all servers [%s]", + zh->hostname); + } else { + // No need to delay -- grab the next server and attempt connection + zoo_cycle_next_server(zh); + zh->fd = socket(zh->addr_cur.ss_family, SOCK_STREAM, 0); + if (zh->fd < 0) { + rc = handle_socket_error_msg(zh, + __LINE__, + ZSYSTEMERROR, + "socket() call failed"); + return api_epilog(zh, rc); + } + + zookeeper_set_sock_nodelay(zh, zh->fd); + zookeeper_set_sock_noblock(zh, zh->fd); + + rc = zookeeper_connect(zh, &zh->addr_cur, zh->fd); + + if (rc == -1) { + /* we are handling the non-blocking connect according to + * the description in section 16.3 "Non-blocking connect" + * in UNIX Network Programming vol 1, 3rd edition */ + if (errno == EWOULDBLOCK || errno == EINPROGRESS) { + zh->state = ZOO_CONNECTING_STATE; + } else { + rc = handle_socket_error_msg(zh, + __LINE__, + ZCONNECTIONLOSS, + "connect() call failed"); + return api_epilog(zh, rc); + } + } else { + rc = prime_connection(zh); + if (rc != 0) { + return api_epilog(zh,rc); + } + + LOG_INFO(LOGCALLBACK(zh), + "Initiated connection to server [%s]", + format_endpoint_info(&zh->addr_cur)); + } + *tv = get_timeval(zh->recv_timeout/3); + } + *fd = zh->fd; + zh->last_recv = now; + zh->last_send = now; + zh->last_ping = now; + zh->last_ping_rw = now; + zh->ping_rw_timeout = MIN_RW_TIMEOUT; + } + + if (zh->fd != -1) { + int idle_recv = calculate_interval(&zh->last_recv, &now); + int idle_send = calculate_interval(&zh->last_send, &now); + int recv_to = zh->recv_timeout*2/3 - idle_recv; + int send_to = zh->recv_timeout/3; + // have we exceeded the receive timeout threshold? + if (recv_to <= 0) { + // We gotta cut our losses and connect to someone else +#ifdef _WIN32 + errno = WSAETIMEDOUT; +#else + errno = ETIMEDOUT; +#endif + *interest=0; + *tv = get_timeval(0); + return api_epilog(zh,handle_socket_error_msg(zh, + __LINE__,ZOPERATIONTIMEOUT, + "connection to %s timed out (exceeded timeout by %dms)", + format_endpoint_info(&zh->addr_cur), + -recv_to)); + + } + + // We only allow 1/3 of our timeout time to expire before sending + // a PING + if (is_connected(zh)) { + send_to = zh->recv_timeout/3 - idle_send; + if (send_to <= 0) { + if (zh->sent_requests.head == 0) { + rc = send_ping(zh); + if (rc < 0) { + LOG_ERROR(LOGCALLBACK(zh), "failed to send PING request (zk retcode=%d)",rc); + return api_epilog(zh,rc); + } + } + send_to = zh->recv_timeout/3; + } + } + + // If we are in read-only mode, seek for read/write server + if (zh->state == ZOO_READONLY_STATE) { + int idle_ping_rw = calculate_interval(&zh->last_ping_rw, &now); + if (idle_ping_rw >= zh->ping_rw_timeout) { + zh->last_ping_rw = now; + idle_ping_rw = 0; + zh->ping_rw_timeout = min(zh->ping_rw_timeout * 2, + MAX_RW_TIMEOUT); + if (ping_rw_server(zh)) { + struct sockaddr_storage addr; + addrvec_peek(&zh->addrs, &addr); + zh->ping_rw_timeout = MIN_RW_TIMEOUT; + LOG_INFO(LOGCALLBACK(zh), + "r/w server found at %s", + format_endpoint_info(&addr)); + handle_error(zh, ZRWSERVERFOUND); + } else { + addrvec_next(&zh->addrs, NULL); + } + } + send_to = min(send_to, zh->ping_rw_timeout - idle_ping_rw); + } + + // choose the lesser value as the timeout + *tv = get_timeval(min(recv_to, send_to)); + + zh->next_deadline.tv_sec = now.tv_sec + tv->tv_sec; + zh->next_deadline.tv_usec = now.tv_usec + tv->tv_usec; + if (zh->next_deadline.tv_usec > 1000000) { + zh->next_deadline.tv_sec += zh->next_deadline.tv_usec / 1000000; + zh->next_deadline.tv_usec = zh->next_deadline.tv_usec % 1000000; + } + *interest = ZOOKEEPER_READ; + /* we are interested in a write if we are connected and have something + * to send, or we are waiting for a connect to finish. */ + if ((zh->to_send.head && is_connected(zh)) + || zh->state == ZOO_CONNECTING_STATE) { + *interest |= ZOOKEEPER_WRITE; + } + } + return api_epilog(zh,ZOK); +} + +static int check_events(zhandle_t *zh, int events) +{ + if (zh->fd == -1) + return ZINVALIDSTATE; + if ((events&ZOOKEEPER_WRITE)&&(zh->state == ZOO_CONNECTING_STATE)) { + int rc, error; + socklen_t len = sizeof(error); + rc = getsockopt(zh->fd, SOL_SOCKET, SO_ERROR, &error, &len); + /* the description in section 16.4 "Non-blocking connect" + * in UNIX Network Programming vol 1, 3rd edition, points out + * that sometimes the error is in errno and sometimes in error */ + if (rc < 0 || error) { + if (rc == 0) + errno = error; + return handle_socket_error_msg(zh, __LINE__,ZCONNECTIONLOSS, + "server refused to accept the client"); + } + + if((rc=prime_connection(zh))!=0) + return rc; + + LOG_INFO(LOGCALLBACK(zh), "initiated connection to server [%s]", format_endpoint_info(&zh->addr_cur)); + return ZOK; + } + if (zh->to_send.head && (events&ZOOKEEPER_WRITE)) { + /* make the flush call non-blocking by specifying a 0 timeout */ + int rc=flush_send_queue(zh,0); + if (rc < 0) + return handle_socket_error_msg(zh,__LINE__,ZCONNECTIONLOSS, + "failed while flushing send queue"); + } + if (events&ZOOKEEPER_READ) { + int rc; + if (zh->input_buffer == 0) { + zh->input_buffer = allocate_buffer(0,0); + } + + rc = recv_buffer(zh, zh->input_buffer); + if (rc < 0) { + return handle_socket_error_msg(zh, __LINE__,ZCONNECTIONLOSS, + "failed while receiving a server response"); + } + if (rc > 0) { + get_system_time(&zh->last_recv); + if (zh->input_buffer != &zh->primer_buffer) { + queue_buffer(&zh->to_process, zh->input_buffer, 0); + } else { + int64_t oldid, newid; + //deserialize + deserialize_prime_response(&zh->primer_storage, zh->primer_buffer.buffer); + /* We are processing the primer_buffer, so we need to finish + * the connection handshake */ + oldid = zh->seen_rw_server_before ? zh->client_id.client_id : 0; + zh->seen_rw_server_before |= !zh->primer_storage.readOnly; + newid = zh->primer_storage.sessionId; + if (oldid != 0 && oldid != newid) { + zh->state = ZOO_EXPIRED_SESSION_STATE; + errno = ESTALE; + return handle_socket_error_msg(zh,__LINE__,ZSESSIONEXPIRED, + "sessionId=%#llx has expired.",oldid); + } else { + zh->recv_timeout = zh->primer_storage.timeOut; + zh->client_id.client_id = newid; + + memcpy(zh->client_id.passwd, &zh->primer_storage.passwd, + sizeof(zh->client_id.passwd)); + zh->state = zh->primer_storage.readOnly ? + ZOO_READONLY_STATE : ZOO_CONNECTED_STATE; + zh->reconfig = 0; + LOG_INFO(LOGCALLBACK(zh), + "session establishment complete on server [%s], sessionId=%#llx, negotiated timeout=%d %s", + format_endpoint_info(&zh->addr_cur), + newid, zh->recv_timeout, + zh->primer_storage.readOnly ? "(READ-ONLY mode)" : ""); + /* we want the auth to be sent for, but since both call push to front + we need to call send_watch_set first */ + send_set_watches(zh); + /* send the authentication packet now */ + send_auth_info(zh); + LOG_DEBUG(LOGCALLBACK(zh), "Calling a watcher for a ZOO_SESSION_EVENT and the state=ZOO_CONNECTED_STATE"); + zh->input_buffer = 0; // just in case the watcher calls zookeeper_process() again + PROCESS_SESSION_EVENT(zh, zh->state); + } + } + zh->input_buffer = 0; + } else { + // zookeeper_process was called but there was nothing to read + // from the socket + return ZNOTHING; + } + } + return ZOK; +} + +void api_prolog(zhandle_t* zh) +{ + inc_ref_counter(zh,1); +} + +int api_epilog(zhandle_t *zh,int rc) +{ + if(inc_ref_counter(zh,-1)==0 && zh->close_requested!=0) + zookeeper_close(zh); + return rc; +} + +static __attribute__((unused)) void print_completion_queue(zhandle_t *zh) +{ + completion_list_t* cptr; + + if(logLevelsent_requests.head==0) { + fprintf(LOGSTREAM,"empty\n"); + return; + } + + cptr=zh->sent_requests.head; + while(cptr){ + fprintf(LOGSTREAM,"%d,",cptr->xid); + cptr=cptr->next; + } + fprintf(LOGSTREAM,"end\n"); +} + +//#ifdef THREADED +// IO thread queues session events to be processed by the completion thread +static int queue_session_event(zhandle_t *zh, int state) +{ + int rc; + struct WatcherEvent evt = { ZOO_SESSION_EVENT, state, "" }; + struct ReplyHeader hdr = { WATCHER_EVENT_XID, 0, 0 }; + struct oarchive *oa; + completion_list_t *cptr; + + if ((oa=create_buffer_oarchive())==NULL) { + LOG_ERROR(LOGCALLBACK(zh), "out of memory"); + goto error; + } + rc = serialize_ReplyHeader(oa, "hdr", &hdr); + rc = rc<0?rc: serialize_WatcherEvent(oa, "event", &evt); + if(rc<0){ + close_buffer_oarchive(&oa, 1); + goto error; + } + cptr = create_completion_entry(zh, WATCHER_EVENT_XID,-1,0,0,0,0); + cptr->buffer = allocate_buffer(get_buffer(oa), get_buffer_len(oa)); + cptr->buffer->curr_offset = get_buffer_len(oa); + if (!cptr->buffer) { + free(cptr); + close_buffer_oarchive(&oa, 1); + goto error; + } + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + cptr->c.watcher_result = collectWatchers(zh, ZOO_SESSION_EVENT, ""); + queue_completion(&zh->completions_to_process, cptr, 0); + if (process_async(zh->outstanding_sync)) { + process_completions(zh); + } + return ZOK; +error: + errno=ENOMEM; + return ZSYSTEMERROR; +} +//#endif + +completion_list_t *dequeue_completion(completion_head_t *list) +{ + completion_list_t *cptr; + lock_completion_list(list); + cptr = list->head; + if (cptr) { + list->head = cptr->next; + if (!list->head) { + assert(list->last == cptr); + list->last = 0; + } + } + unlock_completion_list(list); + return cptr; +} + +static void process_sync_completion(zhandle_t *zh, + completion_list_t *cptr, + struct sync_completion *sc, + struct iarchive *ia) +{ + LOG_DEBUG(LOGCALLBACK(zh), "Processing sync_completion with type=%d xid=%#x rc=%d", + cptr->c.type, cptr->xid, sc->rc); + + switch(cptr->c.type) { + case COMPLETION_DATA: + if (sc->rc==0) { + struct GetDataResponse res; + int len; + deserialize_GetDataResponse(ia, "reply", &res); + if (res.data.len <= sc->u.data.buff_len) { + len = res.data.len; + } else { + len = sc->u.data.buff_len; + } + sc->u.data.buff_len = len; + // check if len is negative + // just of NULL which is -1 int + if (len == -1) { + sc->u.data.buffer = NULL; + } else { + memcpy(sc->u.data.buffer, res.data.buff, len); + } + sc->u.data.stat = res.stat; + deallocate_GetDataResponse(&res); + } + break; + case COMPLETION_STAT: + if (sc->rc==0) { + struct SetDataResponse res; + deserialize_SetDataResponse(ia, "reply", &res); + sc->u.stat = res.stat; + deallocate_SetDataResponse(&res); + } + break; + case COMPLETION_STRINGLIST: + if (sc->rc==0) { + struct GetChildrenResponse res; + deserialize_GetChildrenResponse(ia, "reply", &res); + sc->u.strs2 = res.children; + /* We don't deallocate since we are passing it back */ + // deallocate_GetChildrenResponse(&res); + } + break; + case COMPLETION_STRINGLIST_STAT: + if (sc->rc==0) { + struct GetChildren2Response res; + deserialize_GetChildren2Response(ia, "reply", &res); + sc->u.strs_stat.strs2 = res.children; + sc->u.strs_stat.stat2 = res.stat; + /* We don't deallocate since we are passing it back */ + // deallocate_GetChildren2Response(&res); + } + break; + case COMPLETION_STRING: + if (sc->rc==0) { + struct CreateResponse res; + int len; + const char * client_path; + deserialize_CreateResponse(ia, "reply", &res); + //ZOOKEEPER-1027 + client_path = sub_string(zh, res.path); + len = strlen(client_path) + 1;if (len > sc->u.str.str_len) { + len = sc->u.str.str_len; + } + if (len > 0) { + memcpy(sc->u.str.str, client_path, len - 1); + sc->u.str.str[len - 1] = '\0'; + } + free_duplicate_path(client_path, res.path); + deallocate_CreateResponse(&res); + } + break; + case COMPLETION_STRING_STAT: + if (sc->rc==0) { + struct Create2Response res; + int len; + const char * client_path; + deserialize_Create2Response(ia, "reply", &res); + client_path = sub_string(zh, res.path); + len = strlen(client_path) + 1; + if (len > sc->u.str.str_len) { + len = sc->u.str.str_len; + } + if (len > 0) { + memcpy(sc->u.str.str, client_path, len - 1); + sc->u.str.str[len - 1] = '\0'; + } + free_duplicate_path(client_path, res.path); + sc->u.stat = res.stat; + deallocate_Create2Response(&res); + } + break; + case COMPLETION_ACLLIST: + if (sc->rc==0) { + struct GetACLResponse res; + deserialize_GetACLResponse(ia, "reply", &res); + sc->u.acl.acl = res.acl; + sc->u.acl.stat = res.stat; + /* We don't deallocate since we are passing it back */ + //deallocate_GetACLResponse(&res); + } + break; + case COMPLETION_VOID: + break; + case COMPLETION_MULTI: + sc->rc = deserialize_multi(zh, cptr->xid, cptr, ia); + break; + default: + LOG_DEBUG(LOGCALLBACK(zh), "Unsupported completion type=%d", cptr->c.type); + break; + } +} + +static int deserialize_multi(zhandle_t *zh, int xid, completion_list_t *cptr, struct iarchive *ia) +{ + int rc = 0; + completion_head_t *clist = &cptr->c.clist; + struct MultiHeader mhdr = {0, 0, 0}; + assert(clist); + deserialize_MultiHeader(ia, "multiheader", &mhdr); + while (!mhdr.done) { + completion_list_t *entry = dequeue_completion(clist); + assert(entry); + + if (mhdr.type == -1) { + struct ErrorResponse er; + deserialize_ErrorResponse(ia, "error", &er); + mhdr.err = er.err ; + if (rc == 0 && er.err != 0 && er.err != ZRUNTIMEINCONSISTENCY) { + rc = er.err; + } + } + + deserialize_response(zh, entry->c.type, xid, mhdr.type == -1, mhdr.err, entry, ia); + deserialize_MultiHeader(ia, "multiheader", &mhdr); + //While deserializing the response we must destroy completion entry for each operation in + //the zoo_multi transaction. Otherwise this results in memory leak when client invokes zoo_multi + //operation. + destroy_completion_entry(entry); + } + + return rc; +} + +static void deserialize_response(zhandle_t *zh, int type, int xid, int failed, int rc, completion_list_t *cptr, struct iarchive *ia) +{ + switch (type) { + case COMPLETION_DATA: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_DATA for xid=%#x failed=%d rc=%d", + cptr->xid, failed, rc); + if (failed) { + cptr->c.data_result(rc, 0, 0, 0, cptr->data); + } else { + struct GetDataResponse res; + deserialize_GetDataResponse(ia, "reply", &res); + cptr->c.data_result(rc, res.data.buff, res.data.len, + &res.stat, cptr->data); + deallocate_GetDataResponse(&res); + } + break; + case COMPLETION_STAT: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_STAT for xid=%#x failed=%d rc=%d", + cptr->xid, failed, rc); + if (failed) { + cptr->c.stat_result(rc, 0, cptr->data); + } else { + struct SetDataResponse res; + deserialize_SetDataResponse(ia, "reply", &res); + cptr->c.stat_result(rc, &res.stat, cptr->data); + deallocate_SetDataResponse(&res); + } + break; + case COMPLETION_STRINGLIST: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_STRINGLIST for xid=%#x failed=%d rc=%d", + cptr->xid, failed, rc); + if (failed) { + cptr->c.strings_result(rc, 0, cptr->data); + } else { + struct GetChildrenResponse res; + deserialize_GetChildrenResponse(ia, "reply", &res); + cptr->c.strings_result(rc, &res.children, cptr->data); + deallocate_GetChildrenResponse(&res); + } + break; + case COMPLETION_STRINGLIST_STAT: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_STRINGLIST_STAT for xid=%#x failed=%d rc=%d", + cptr->xid, failed, rc); + if (failed) { + cptr->c.strings_stat_result(rc, 0, 0, cptr->data); + } else { + struct GetChildren2Response res; + deserialize_GetChildren2Response(ia, "reply", &res); + cptr->c.strings_stat_result(rc, &res.children, &res.stat, cptr->data); + deallocate_GetChildren2Response(&res); + } + break; + case COMPLETION_STRING: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_STRING for xid=%#x failed=%d, rc=%d", + cptr->xid, failed, rc); + if (failed) { + cptr->c.string_result(rc, 0, cptr->data); + } else { + struct CreateResponse res; + deserialize_CreateResponse(ia, "reply", &res); + cptr->c.string_result(rc, res.path, cptr->data); + deallocate_CreateResponse(&res); + } + break; + case COMPLETION_STRING_STAT: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_STRING_STAT for xid=%#x failed=%d, rc=%d", + cptr->xid, failed, rc); + if (failed) { + cptr->c.string_stat_result(rc, 0, 0, cptr->data); + } else { + struct Create2Response res; + deserialize_Create2Response(ia, "reply", &res); + cptr->c.string_stat_result(rc, res.path, &res.stat, cptr->data); + deallocate_Create2Response(&res); + } + break; + case COMPLETION_ACLLIST: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_ACLLIST for xid=%#x failed=%d rc=%d", + cptr->xid, failed, rc); + if (failed) { + cptr->c.acl_result(rc, 0, 0, cptr->data); + } else { + struct GetACLResponse res; + deserialize_GetACLResponse(ia, "reply", &res); + cptr->c.acl_result(rc, &res.acl, &res.stat, cptr->data); + deallocate_GetACLResponse(&res); + } + break; + case COMPLETION_VOID: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_VOID for xid=%#x failed=%d rc=%d", + cptr->xid, failed, rc); + assert(cptr->c.void_result); + cptr->c.void_result(rc, cptr->data); + break; + case COMPLETION_MULTI: + LOG_DEBUG(LOGCALLBACK(zh), "Calling COMPLETION_MULTI for xid=%#x failed=%d rc=%d", + cptr->xid, failed, rc); + rc = deserialize_multi(zh, xid, cptr, ia); + assert(cptr->c.void_result); + cptr->c.void_result(rc, cptr->data); + break; + default: + LOG_DEBUG(LOGCALLBACK(zh), "Unsupported completion type=%d", cptr->c.type); + } +} + + +/* handles async completion (both single- and multithreaded) */ +void process_completions(zhandle_t *zh) +{ + completion_list_t *cptr; + while ((cptr = dequeue_completion(&zh->completions_to_process)) != 0) { + struct ReplyHeader hdr; + buffer_list_t *bptr = cptr->buffer; + struct iarchive *ia = create_buffer_iarchive(bptr->buffer, + bptr->len); + deserialize_ReplyHeader(ia, "hdr", &hdr); + + if (hdr.xid == WATCHER_EVENT_XID) { + int type, state; + struct WatcherEvent evt; + deserialize_WatcherEvent(ia, "event", &evt); + /* We are doing a notification, so there is no pending request */ + type = evt.type; + state = evt.state; + /* This is a notification so there aren't any pending requests */ + LOG_DEBUG(LOGCALLBACK(zh), "Calling a watcher for node [%s], type = %d event=%s", + (evt.path==NULL?"NULL":evt.path), cptr->c.type, + watcherEvent2String(type)); + deliverWatchers(zh,type,state,evt.path, &cptr->c.watcher_result); + deallocate_WatcherEvent(&evt); + } else { + deserialize_response(zh, cptr->c.type, hdr.xid, hdr.err != 0, hdr.err, cptr, ia); + } + destroy_completion_entry(cptr); + close_buffer_iarchive(&ia); + } +} + +static void isSocketReadable(zhandle_t* zh) +{ +#ifndef _WIN32 + struct pollfd fds; + fds.fd = zh->fd; + fds.events = POLLIN; + if (poll(&fds,1,0)<=0) { + // socket not readable -- no more responses to process + zh->socket_readable.tv_sec=zh->socket_readable.tv_usec=0; + } +#else + fd_set rfds; + struct timeval waittime = {0, 0}; + FD_ZERO(&rfds); + FD_SET( zh->fd , &rfds); + if (select(0, &rfds, NULL, NULL, &waittime) <= 0){ + // socket not readable -- no more responses to process + zh->socket_readable.tv_sec=zh->socket_readable.tv_usec=0; + } +#endif + else{ + get_system_time(&zh->socket_readable); + } +} + +static void checkResponseLatency(zhandle_t* zh) +{ + int delay; + struct timeval now; + + if(zh->socket_readable.tv_sec==0) + return; + + get_system_time(&now); + delay=calculate_interval(&zh->socket_readable, &now); + if(delay>20) + LOG_DEBUG(LOGCALLBACK(zh), "The following server response has spent at least %dms sitting in the client socket recv buffer",delay); + + zh->socket_readable.tv_sec=zh->socket_readable.tv_usec=0; +} + +int zookeeper_process(zhandle_t *zh, int events) +{ + buffer_list_t *bptr; + int rc; + + if (zh==NULL) + return ZBADARGUMENTS; + if (is_unrecoverable(zh)) + return ZINVALIDSTATE; + api_prolog(zh); + IF_DEBUG(checkResponseLatency(zh)); + rc = check_events(zh, events); + if (rc!=ZOK) + return api_epilog(zh, rc); + + IF_DEBUG(isSocketReadable(zh)); + + while (rc >= 0 && (bptr=dequeue_buffer(&zh->to_process))) { + struct ReplyHeader hdr; + struct iarchive *ia = create_buffer_iarchive( + bptr->buffer, bptr->curr_offset); + deserialize_ReplyHeader(ia, "hdr", &hdr); + + if (hdr.xid == PING_XID) { + // Ping replies can arrive out-of-order + int elapsed = 0; + struct timeval now; + gettimeofday(&now, 0); + elapsed = calculate_interval(&zh->last_ping, &now); + LOG_DEBUG(LOGCALLBACK(zh), "Got ping response in %d ms", elapsed); + free_buffer(bptr); + } else if (hdr.xid == WATCHER_EVENT_XID) { + struct WatcherEvent evt; + int type = 0; + char *path = NULL; + completion_list_t *c = NULL; + + LOG_DEBUG(LOGCALLBACK(zh), "Processing WATCHER_EVENT"); + + deserialize_WatcherEvent(ia, "event", &evt); + type = evt.type; + path = evt.path; + /* We are doing a notification, so there is no pending request */ + c = create_completion_entry(zh, WATCHER_EVENT_XID,-1,0,0,0,0); + c->buffer = bptr; + c->c.watcher_result = collectWatchers(zh, type, path); + + // We cannot free until now, otherwise path will become invalid + deallocate_WatcherEvent(&evt); + queue_completion(&zh->completions_to_process, c, 0); + } else if (hdr.xid == SET_WATCHES_XID) { + LOG_DEBUG(LOGCALLBACK(zh), "Processing SET_WATCHES"); + free_buffer(bptr); + } else if (hdr.xid == AUTH_XID){ + LOG_DEBUG(LOGCALLBACK(zh), "Processing AUTH_XID"); + + /* special handling for the AUTH response as it may come back + * out-of-band */ + auth_completion_func(hdr.err,zh); + free_buffer(bptr); + /* authentication completion may change the connection state to + * unrecoverable */ + if(is_unrecoverable(zh)){ + handle_error(zh, ZAUTHFAILED); + close_buffer_iarchive(&ia); + return api_epilog(zh, ZAUTHFAILED); + } + } else { + int rc = hdr.err; + /* Find the request corresponding to the response */ + completion_list_t *cptr = dequeue_completion(&zh->sent_requests); + + /* [ZOOKEEPER-804] Don't assert if zookeeper_close has been called. */ + if (zh->close_requested == 1 && cptr == NULL) { + LOG_DEBUG(LOGCALLBACK(zh), "Completion queue has been cleared by zookeeper_close()"); + close_buffer_iarchive(&ia); + free_buffer(bptr); + return api_epilog(zh,ZINVALIDSTATE); + } + assert(cptr); + /* The requests are going to come back in order */ + if (cptr->xid != hdr.xid) { + LOG_DEBUG(LOGCALLBACK(zh), "Processing unexpected or out-of-order response!"); + + // received unexpected (or out-of-order) response + close_buffer_iarchive(&ia); + free_buffer(bptr); + // put the completion back on the queue (so it gets properly + // signaled and deallocated) and disconnect from the server + queue_completion(&zh->sent_requests,cptr,1); + return handle_socket_error_msg(zh, __LINE__,ZRUNTIMEINCONSISTENCY, + "unexpected server response: expected %#x, but received %#x", + hdr.xid,cptr->xid); + } + + if (hdr.zxid > 0) { + // Update last_zxid only when it is a request response + zh->last_zxid = hdr.zxid; + } + activateWatcher(zh, cptr->watcher, rc); + deactivateWatcher(zh, cptr->watcher_deregistration, rc); + + if (cptr->c.void_result != SYNCHRONOUS_MARKER) { + LOG_DEBUG(LOGCALLBACK(zh), "Queueing asynchronous response"); + cptr->buffer = bptr; + queue_completion(&zh->completions_to_process, cptr, 0); + } else { + struct sync_completion + *sc = (struct sync_completion*)cptr->data; + sc->rc = rc; + + process_sync_completion(zh, cptr, sc, ia); + + notify_sync_completion(sc); + free_buffer(bptr); + zh->outstanding_sync--; + destroy_completion_entry(cptr); + } + } + + close_buffer_iarchive(&ia); + + } + if (process_async(zh->outstanding_sync)) { + process_completions(zh); + } + + return api_epilog(zh, ZOK); +} + +int zoo_state(zhandle_t *zh) +{ + if(zh!=0) + return zh->state; + return 0; +} + +static watcher_registration_t* create_watcher_registration(const char* path, + result_checker_fn checker,watcher_fn watcher,void* ctx){ + watcher_registration_t* wo; + if(watcher==0) + return 0; + wo=calloc(1,sizeof(watcher_registration_t)); + wo->path=strdup(path); + wo->watcher=watcher; + wo->context=ctx; + wo->checker=checker; + return wo; +} + +static watcher_deregistration_t* create_watcher_deregistration(const char* path, + watcher_fn watcher, void *watcherCtx, ZooWatcherType wtype) { + watcher_deregistration_t *wdo; + + wdo = calloc(1, sizeof(watcher_deregistration_t)); + if (!wdo) { + return NULL; + } + wdo->path = strdup(path); + wdo->watcher = watcher; + wdo->context = watcherCtx; + wdo->type = wtype; + return wdo; +} + +static void destroy_watcher_registration(watcher_registration_t* wo){ + if(wo!=0){ + free((void*)wo->path); + free(wo); + } +} + +static void destroy_watcher_deregistration(watcher_deregistration_t *wdo) { + if (wdo) { + free((void *)wdo->path); + free(wdo); + } +} + +static completion_list_t* create_completion_entry(zhandle_t *zh, int xid, int completion_type, + const void *dc, const void *data,watcher_registration_t* wo, completion_head_t *clist) +{ + return do_create_completion_entry(zh, xid, completion_type, dc, data, wo, + clist, NULL); +} + +static completion_list_t* create_completion_entry_deregistration(zhandle_t *zh, + int xid, int completion_type, const void *dc, const void *data, + watcher_deregistration_t* wdo, completion_head_t *clist) +{ + return do_create_completion_entry(zh, xid, completion_type, dc, data, NULL, + clist, wdo); +} + +static completion_list_t* do_create_completion_entry(zhandle_t *zh, int xid, + int completion_type, const void *dc, const void *data, + watcher_registration_t* wo, completion_head_t *clist, + watcher_deregistration_t* wdo) +{ + completion_list_t *c = calloc(1, sizeof(completion_list_t)); + if (!c) { + LOG_ERROR(LOGCALLBACK(zh), "out of memory"); + return 0; + } + c->c.type = completion_type; + c->data = data; + switch(c->c.type) { + case COMPLETION_VOID: + c->c.void_result = (void_completion_t)dc; + break; + case COMPLETION_STRING: + c->c.string_result = (string_completion_t)dc; + break; + case COMPLETION_DATA: + c->c.data_result = (data_completion_t)dc; + break; + case COMPLETION_STAT: + c->c.stat_result = (stat_completion_t)dc; + break; + case COMPLETION_STRINGLIST: + c->c.strings_result = (strings_completion_t)dc; + break; + case COMPLETION_STRINGLIST_STAT: + c->c.strings_stat_result = (strings_stat_completion_t)dc; + break; + case COMPLETION_STRING_STAT: + c->c.string_stat_result = (string_stat_completion_t)dc; + case COMPLETION_ACLLIST: + c->c.acl_result = (acl_completion_t)dc; + break; + case COMPLETION_MULTI: + assert(clist); + c->c.void_result = (void_completion_t)dc; + c->c.clist = *clist; + break; + } + c->xid = xid; + c->watcher = wo; + c->watcher_deregistration = wdo; + + return c; +} + +static void destroy_completion_entry(completion_list_t* c){ + if(c!=0){ + destroy_watcher_registration(c->watcher); + destroy_watcher_deregistration(c->watcher_deregistration); + if(c->buffer!=0) + free_buffer(c->buffer); + free(c); + } +} + +static void queue_completion_nolock(completion_head_t *list, + completion_list_t *c, + int add_to_front) +{ + c->next = 0; + /* appending a new entry to the back of the list */ + if (list->last) { + assert(list->head); + // List is not empty + if (!add_to_front) { + list->last->next = c; + list->last = c; + } else { + c->next = list->head; + list->head = c; + } + } else { + // List is empty + assert(!list->head); + list->head = c; + list->last = c; + } +} + +static void queue_completion(completion_head_t *list, completion_list_t *c, + int add_to_front) +{ + + lock_completion_list(list); + queue_completion_nolock(list, c, add_to_front); + unlock_completion_list(list); +} + +static int add_completion(zhandle_t *zh, int xid, int completion_type, + const void *dc, const void *data, int add_to_front, + watcher_registration_t* wo, completion_head_t *clist) +{ + completion_list_t *c =create_completion_entry(zh, xid, completion_type, dc, + data, wo, clist); + return do_add_completion(zh, dc, c, add_to_front); +} + +static int add_completion_deregistration(zhandle_t *zh, int xid, + int completion_type, const void *dc, const void *data, int add_to_front, + watcher_deregistration_t* wdo, completion_head_t *clist) +{ + completion_list_t *c = create_completion_entry_deregistration(zh, xid, + completion_type, dc, data, wdo, clist); + return do_add_completion(zh, dc, c, add_to_front); +} + +static int do_add_completion(zhandle_t *zh, const void *dc, + completion_list_t *c, int add_to_front) +{ + int rc = 0; + if (!c) + return ZSYSTEMERROR; + lock_completion_list(&zh->sent_requests); + if (zh->close_requested != 1) { + queue_completion_nolock(&zh->sent_requests, c, add_to_front); + if (dc == SYNCHRONOUS_MARKER) { + zh->outstanding_sync++; + } + rc = ZOK; + } else { + free(c); + rc = ZINVALIDSTATE; + } + unlock_completion_list(&zh->sent_requests); + return rc; +} + +static int add_data_completion(zhandle_t *zh, int xid, data_completion_t dc, + const void *data,watcher_registration_t* wo) +{ + return add_completion(zh, xid, COMPLETION_DATA, dc, data, 0, wo, 0); +} + +static int add_stat_completion(zhandle_t *zh, int xid, stat_completion_t dc, + const void *data,watcher_registration_t* wo) +{ + return add_completion(zh, xid, COMPLETION_STAT, dc, data, 0, wo, 0); +} + +static int add_strings_completion(zhandle_t *zh, int xid, + strings_completion_t dc, const void *data,watcher_registration_t* wo) +{ + return add_completion(zh, xid, COMPLETION_STRINGLIST, dc, data, 0, wo, 0); +} + +static int add_strings_stat_completion(zhandle_t *zh, int xid, + strings_stat_completion_t dc, const void *data,watcher_registration_t* wo) +{ + return add_completion(zh, xid, COMPLETION_STRINGLIST_STAT, dc, data, 0, wo, 0); +} + +static int add_acl_completion(zhandle_t *zh, int xid, acl_completion_t dc, + const void *data) +{ + return add_completion(zh, xid, COMPLETION_ACLLIST, dc, data, 0, 0, 0); +} + +static int add_void_completion(zhandle_t *zh, int xid, void_completion_t dc, + const void *data) +{ + return add_completion(zh, xid, COMPLETION_VOID, dc, data, 0, 0, 0); +} + +static int add_string_completion(zhandle_t *zh, int xid, + string_completion_t dc, const void *data) +{ + return add_completion(zh, xid, COMPLETION_STRING, dc, data, 0, 0, 0); +} + +static int add_string_stat_completion(zhandle_t *zh, int xid, + string_stat_completion_t dc, const void *data) +{ + return add_completion(zh, xid, COMPLETION_STRING_STAT, dc, data, 0, 0, 0); +} + +static int add_multi_completion(zhandle_t *zh, int xid, void_completion_t dc, + const void *data, completion_head_t *clist) +{ + return add_completion(zh, xid, COMPLETION_MULTI, dc, data, 0,0, clist); +} + +int zookeeper_close(zhandle_t *zh) +{ + int rc=ZOK; + if (zh==0) + return ZBADARGUMENTS; + + zh->close_requested=1; + if (inc_ref_counter(zh,1)>1) { + /* We have incremented the ref counter to prevent the + * completions from calling zookeeper_close before we have + * completed the adaptor_finish call below. */ + + /* Signal any syncronous completions before joining the threads */ + enter_critical(zh); + free_completions(zh,1,ZCLOSING); + leave_critical(zh); + + adaptor_finish(zh); + /* Now we can allow the handle to be cleaned up, if the completion + * threads finished during the adaptor_finish call. */ + api_epilog(zh, 0); + return ZOK; + } + /* No need to decrement the counter since we're just going to + * destroy the handle later. */ + if (is_connected(zh)){ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_CLOSE_OP}; + LOG_INFO(LOGCALLBACK(zh), "Closing zookeeper sessionId=%#llx to [%s]\n", + zh->client_id.client_id,zoo_get_current_server(zh)); + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + if (rc < 0) { + rc = ZMARSHALLINGERROR; + goto finish; + } + + /* make sure the close request is sent; we set timeout to an arbitrary + * (but reasonable) number of milliseconds since we want the call to block*/ + rc=adaptor_send_queue(zh, 3000); + }else{ + LOG_INFO(LOGCALLBACK(zh), "Freeing zookeeper resources for sessionId=%#llx\n", + zh->client_id.client_id); + rc = ZOK; + } + +finish: + destroy(zh); + adaptor_destroy(zh); + free(zh); +#ifdef _WIN32 + Win32WSACleanup(); +#endif + return rc; +} + +static int isValidPath(const char* path, const int flags) { + int len = 0; + char lastc = '/'; + char c; + int i = 0; + + if (path == 0) + return 0; + len = strlen(path); + if (len == 0) + return 0; + if (path[0] != '/') + return 0; + if (len == 1) // done checking - it's the root + return 1; + if (path[len - 1] == '/' && !(flags & ZOO_SEQUENCE)) + return 0; + + i = 1; + for (; i < len; lastc = path[i], i++) { + c = path[i]; + + if (c == 0) { + return 0; + } else if (c == '/' && lastc == '/') { + return 0; + } else if (c == '.' && lastc == '.') { + if (path[i-2] == '/' && (((i + 1 == len) && !(flags & ZOO_SEQUENCE)) + || path[i+1] == '/')) { + return 0; + } + } else if (c == '.') { + if ((path[i-1] == '/') && (((i + 1 == len) && !(flags & ZOO_SEQUENCE)) + || path[i+1] == '/')) { + return 0; + } + } else if (c > 0x00 && c < 0x1f) { + return 0; + } + } + + return 1; +} + +/*---------------------------------------------------------------------------* + * REQUEST INIT HELPERS + *---------------------------------------------------------------------------*/ +/* Common Request init helper functions to reduce code duplication */ +static int Request_path_init(zhandle_t *zh, int flags, + char **path_out, const char *path) +{ + assert(path_out); + + *path_out = prepend_string(zh, path); + if (zh == NULL || !isValidPath(*path_out, flags)) { + free_duplicate_path(*path_out, path); + return ZBADARGUMENTS; + } + if (is_unrecoverable(zh)) { + free_duplicate_path(*path_out, path); + return ZINVALIDSTATE; + } + + return ZOK; +} + +static int Request_path_watch_init(zhandle_t *zh, int flags, + char **path_out, const char *path, + int32_t *watch_out, uint32_t watch) +{ + int rc = Request_path_init(zh, flags, path_out, path); + if (rc != ZOK) { + return rc; + } + *watch_out = watch; + return ZOK; +} + +/*---------------------------------------------------------------------------* + * ASYNC API + *---------------------------------------------------------------------------*/ +int zoo_aget(zhandle_t *zh, const char *path, int watch, data_completion_t dc, + const void *data) +{ + return zoo_awget(zh,path,watch?zh->watcher:0,zh->context,dc,data); +} + +int zoo_awget(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + data_completion_t dc, const void *data) +{ + struct oarchive *oa; + char *server_path = prepend_string(zh, path); + struct RequestHeader h = {get_xid(), ZOO_GETDATA_OP}; + struct GetDataRequest req = { (char*)server_path, watcher!=0 }; + int rc; + + if (zh==0 || !isValidPath(server_path, 0)) { + free_duplicate_path(server_path, path); + return ZBADARGUMENTS; + } + if (is_unrecoverable(zh)) { + free_duplicate_path(server_path, path); + return ZINVALIDSTATE; + } + oa=create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_GetDataRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_data_completion(zh, h.xid, dc, data, + create_watcher_registration(server_path,data_result_checker,watcher,watcherCtx)); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(server_path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int zoo_agetconfig(zhandle_t *zh, int watch, data_completion_t dc, + const void *data) +{ + return zoo_awgetconfig(zh,watch?zh->watcher:0,zh->context,dc,data); +} + +int zoo_awgetconfig(zhandle_t *zh, watcher_fn watcher, void* watcherCtx, + data_completion_t dc, const void *data) +{ + struct oarchive *oa; + char *path = ZOO_CONFIG_NODE; + char *server_path = ZOO_CONFIG_NODE; + struct RequestHeader h = { get_xid(), ZOO_GETDATA_OP }; + struct GetDataRequest req = { (char*)server_path, watcher!=0 }; + int rc; + + if (zh==0 || !isValidPath(server_path, 0)) { + free_duplicate_path(server_path, path); + return ZBADARGUMENTS; + } + if (is_unrecoverable(zh)) { + free_duplicate_path(server_path, path); + return ZINVALIDSTATE; + } + oa=create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_GetDataRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_data_completion(zh, h.xid, dc, data, + create_watcher_registration(server_path,data_result_checker,watcher,watcherCtx)); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(server_path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int zoo_areconfig(zhandle_t *zh, const char *joining, const char *leaving, + const char *members, int64_t version, data_completion_t dc, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = { get_xid(), ZOO_RECONFIG_OP }; + struct ReconfigRequest req; + int rc = 0; + + if (zh==0) { + return ZBADARGUMENTS; + } + if (is_unrecoverable(zh)) { + return ZINVALIDSTATE; + } + + oa=create_buffer_oarchive(); + req.joiningServers = (char *)joining; + req.leavingServers = (char *)leaving; + req.newMembers = (char *)members; + req.curConfigId = version; + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_ReconfigRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_data_completion(zh, h.xid, dc, data, NULL); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending Reconfig request xid=%#x to %s",h.xid, zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +static int SetDataRequest_init(zhandle_t *zh, struct SetDataRequest *req, + const char *path, const char *buffer, int buflen, int version) +{ + int rc; + assert(req); + rc = Request_path_init(zh, 0, &req->path, path); + if (rc != ZOK) { + return rc; + } + req->data.buff = (char*)buffer; + req->data.len = buflen; + req->version = version; + + return ZOK; +} + +int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen, + int version, stat_completion_t dc, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_SETDATA_OP}; + struct SetDataRequest req; + int rc = SetDataRequest_init(zh, &req, path, buffer, buflen, version); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_SetDataRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_stat_completion(zh, h.xid, dc, data,0); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +static int CreateRequest_init(zhandle_t *zh, struct CreateRequest *req, + const char *path, const char *value, + int valuelen, const struct ACL_vector *acl_entries, int flags) +{ + int rc; + assert(req); + rc = Request_path_init(zh, flags, &req->path, path); + assert(req); + if (rc != ZOK) { + return rc; + } + req->flags = flags; + req->data.buff = (char*)value; + req->data.len = valuelen; + if (acl_entries == 0) { + req->acl.count = 0; + req->acl.data = 0; + } else { + req->acl = *acl_entries; + } + + return ZOK; +} + +int zoo_acreate(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl_entries, int flags, + string_completion_t completion, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_CREATE_OP}; + struct CreateRequest req; + + int rc = CreateRequest_init(zh, &req, + path, value, valuelen, acl_entries, flags); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_CreateRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_string_completion(zh, h.xid, completion, data); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int zoo_acreate2(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl_entries, int flags, + string_stat_completion_t completion, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = { get_xid(), ZOO_CREATE2_OP }; + struct CreateRequest req; + + int rc = CreateRequest_init(zh, &req, path, value, valuelen, acl_entries, flags); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_CreateRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_string_stat_completion(zh, h.xid, completion, data); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int DeleteRequest_init(zhandle_t *zh, struct DeleteRequest *req, + const char *path, int version) +{ + int rc = Request_path_init(zh, 0, &req->path, path); + if (rc != ZOK) { + return rc; + } + req->version = version; + return ZOK; +} + +int zoo_adelete(zhandle_t *zh, const char *path, int version, + void_completion_t completion, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_DELETE_OP}; + struct DeleteRequest req; + int rc = DeleteRequest_init(zh, &req, path, version); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_DeleteRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_void_completion(zh, h.xid, completion, data); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int zoo_aexists(zhandle_t *zh, const char *path, int watch, + stat_completion_t sc, const void *data) +{ + return zoo_awexists(zh,path,watch?zh->watcher:0,zh->context,sc,data); +} + +int zoo_awexists(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + stat_completion_t completion, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_EXISTS_OP}; + struct ExistsRequest req; + int rc = Request_path_watch_init(zh, 0, &req.path, path, + &req.watch, watcher != NULL); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_ExistsRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_stat_completion(zh, h.xid, completion, data, + create_watcher_registration(req.path,exists_result_checker, + watcher,watcherCtx)); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +static int zoo_awget_children_(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + strings_completion_t sc, + const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_GETCHILDREN_OP}; + struct GetChildrenRequest req ; + int rc = Request_path_watch_init(zh, 0, &req.path, path, + &req.watch, watcher != NULL); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_GetChildrenRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_strings_completion(zh, h.xid, sc, data, + create_watcher_registration(req.path,child_result_checker,watcher,watcherCtx)); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int zoo_aget_children(zhandle_t *zh, const char *path, int watch, + strings_completion_t dc, const void *data) +{ + return zoo_awget_children_(zh,path,watch?zh->watcher:0,zh->context,dc,data); +} + +int zoo_awget_children(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + strings_completion_t dc, + const void *data) +{ + return zoo_awget_children_(zh,path,watcher,watcherCtx,dc,data); +} + +static int zoo_awget_children2_(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + strings_stat_completion_t ssc, + const void *data) +{ + /* invariant: (sc == NULL) != (sc == NULL) */ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_GETCHILDREN2_OP}; + struct GetChildren2Request req ; + int rc = Request_path_watch_init(zh, 0, &req.path, path, + &req.watch, watcher != NULL); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_GetChildren2Request(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_strings_stat_completion(zh, h.xid, ssc, data, + create_watcher_registration(req.path,child_result_checker,watcher,watcherCtx)); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int zoo_aget_children2(zhandle_t *zh, const char *path, int watch, + strings_stat_completion_t dc, const void *data) +{ + return zoo_awget_children2_(zh,path,watch?zh->watcher:0,zh->context,dc,data); +} + +int zoo_awget_children2(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + strings_stat_completion_t dc, + const void *data) +{ + return zoo_awget_children2_(zh,path,watcher,watcherCtx,dc,data); +} + +int zoo_async(zhandle_t *zh, const char *path, + string_completion_t completion, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_SYNC_OP}; + struct SyncRequest req; + int rc = Request_path_init(zh, 0, &req.path, path); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_SyncRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_string_completion(zh, h.xid, completion, data); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + + +int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion, + const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_GETACL_OP}; + struct GetACLRequest req; + int rc = Request_path_init(zh, 0, &req.path, path) ; + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_GetACLRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_acl_completion(zh, h.xid, completion, data); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +int zoo_aset_acl(zhandle_t *zh, const char *path, int version, + struct ACL_vector *acl, void_completion_t completion, const void *data) +{ + struct oarchive *oa; + struct RequestHeader h = {get_xid(), ZOO_SETACL_OP}; + struct SetACLRequest req; + int rc = Request_path_init(zh, 0, &req.path, path); + if (rc != ZOK) { + return rc; + } + oa = create_buffer_oarchive(); + req.acl = *acl; + req.version = version; + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_SetACLRequest(oa, "req", &req); + enter_critical(zh); + rc = rc < 0 ? rc : add_void_completion(zh, h.xid, completion, data); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + free_duplicate_path(req.path, path); + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s",h.xid,path, + zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + return (rc < 0)?ZMARSHALLINGERROR:ZOK; +} + +/* Completions for multi-op results */ +static void op_result_string_completion(int err, const char *value, const void *data) +{ + struct zoo_op_result *result = (struct zoo_op_result *)data; + assert(result); + result->err = err; + + if (result->value && value) { + int len = strlen(value) + 1; + if (len > result->valuelen) { + len = result->valuelen; + } + if (len > 0) { + memcpy(result->value, value, len - 1); + result->value[len - 1] = '\0'; + } + } else { + result->value = NULL; + } +} + +static void op_result_void_completion(int err, const void *data) +{ + struct zoo_op_result *result = (struct zoo_op_result *)data; + assert(result); + result->err = err; +} + +static void op_result_stat_completion(int err, const struct Stat *stat, const void *data) +{ + struct zoo_op_result *result = (struct zoo_op_result *)data; + assert(result); + result->err = err; + + if (result->stat && err == 0 && stat) { + *result->stat = *stat; + } else { + result->stat = NULL ; + } +} + +static int CheckVersionRequest_init(zhandle_t *zh, struct CheckVersionRequest *req, + const char *path, int version) +{ + int rc ; + assert(req); + rc = Request_path_init(zh, 0, &req->path, path); + if (rc != ZOK) { + return rc; + } + req->version = version; + + return ZOK; +} + +int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops, + zoo_op_result_t *results, void_completion_t completion, const void *data) +{ + struct RequestHeader h = {get_xid(), ZOO_MULTI_OP}; + struct MultiHeader mh = {-1, 1, -1}; + struct oarchive *oa = create_buffer_oarchive(); + completion_head_t clist = { 0 }; + + int rc = serialize_RequestHeader(oa, "header", &h); + + int index = 0; + for (index=0; index < count; index++) { + const zoo_op_t *op = ops+index; + zoo_op_result_t *result = results+index; + completion_list_t *entry = NULL; + + struct MultiHeader mh = {op->type, 0, -1}; + rc = rc < 0 ? rc : serialize_MultiHeader(oa, "multiheader", &mh); + + switch(op->type) { + case ZOO_CREATE_OP: { + struct CreateRequest req; + + rc = rc < 0 ? rc : CreateRequest_init(zh, &req, + op->create_op.path, op->create_op.data, + op->create_op.datalen, op->create_op.acl, + op->create_op.flags); + rc = rc < 0 ? rc : serialize_CreateRequest(oa, "req", &req); + result->value = op->create_op.buf; + result->valuelen = op->create_op.buflen; + + enter_critical(zh); + entry = create_completion_entry(zh, h.xid, COMPLETION_STRING, op_result_string_completion, result, 0, 0); + leave_critical(zh); + free_duplicate_path(req.path, op->create_op.path); + break; + } + + case ZOO_DELETE_OP: { + struct DeleteRequest req; + rc = rc < 0 ? rc : DeleteRequest_init(zh, &req, op->delete_op.path, op->delete_op.version); + rc = rc < 0 ? rc : serialize_DeleteRequest(oa, "req", &req); + + enter_critical(zh); + entry = create_completion_entry(zh, h.xid, COMPLETION_VOID, op_result_void_completion, result, 0, 0); + leave_critical(zh); + free_duplicate_path(req.path, op->delete_op.path); + break; + } + + case ZOO_SETDATA_OP: { + struct SetDataRequest req; + rc = rc < 0 ? rc : SetDataRequest_init(zh, &req, + op->set_op.path, op->set_op.data, + op->set_op.datalen, op->set_op.version); + rc = rc < 0 ? rc : serialize_SetDataRequest(oa, "req", &req); + result->stat = op->set_op.stat; + + enter_critical(zh); + entry = create_completion_entry(zh, h.xid, COMPLETION_STAT, op_result_stat_completion, result, 0, 0); + leave_critical(zh); + free_duplicate_path(req.path, op->set_op.path); + break; + } + + case ZOO_CHECK_OP: { + struct CheckVersionRequest req; + rc = rc < 0 ? rc : CheckVersionRequest_init(zh, &req, + op->check_op.path, op->check_op.version); + rc = rc < 0 ? rc : serialize_CheckVersionRequest(oa, "req", &req); + + enter_critical(zh); + entry = create_completion_entry(zh, h.xid, COMPLETION_VOID, op_result_void_completion, result, 0, 0); + leave_critical(zh); + free_duplicate_path(req.path, op->check_op.path); + break; + } + + default: + LOG_ERROR(LOGCALLBACK(zh), "Unimplemented sub-op type=%d in multi-op", op->type); + return ZUNIMPLEMENTED; + } + + queue_completion(&clist, entry, 0); + } + + rc = rc < 0 ? rc : serialize_MultiHeader(oa, "multiheader", &mh); + + /* BEGIN: CRTICIAL SECTION */ + enter_critical(zh); + rc = rc < 0 ? rc : add_multi_completion(zh, h.xid, completion, data, &clist); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + leave_critical(zh); + + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending multi request xid=%#x with %d subrequests to %s", + h.xid, index, zoo_get_current_server(zh)); + /* make a best (non-blocking) effort to send the requests asap */ + adaptor_send_queue(zh, 0); + + return (rc < 0) ? ZMARSHALLINGERROR : ZOK; +} + +void zoo_create_op_init(zoo_op_t *op, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + char *path_buffer, int path_buffer_len) +{ + assert(op); + op->type = ZOO_CREATE_OP; + op->create_op.path = path; + op->create_op.data = value; + op->create_op.datalen = valuelen; + op->create_op.acl = acl; + op->create_op.flags = flags; + op->create_op.buf = path_buffer; + op->create_op.buflen = path_buffer_len; +} + +void zoo_create2_op_init(zoo_op_t *op, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + char *path_buffer, int path_buffer_len) +{ + assert(op); + op->type = ZOO_CREATE2_OP; + op->create_op.path = path; + op->create_op.data = value; + op->create_op.datalen = valuelen; + op->create_op.acl = acl; + op->create_op.flags = flags; + op->create_op.buf = path_buffer; + op->create_op.buflen = path_buffer_len; +} + +void zoo_delete_op_init(zoo_op_t *op, const char *path, int version) +{ + assert(op); + op->type = ZOO_DELETE_OP; + op->delete_op.path = path; + op->delete_op.version = version; +} + +void zoo_set_op_init(zoo_op_t *op, const char *path, const char *buffer, + int buflen, int version, struct Stat *stat) +{ + assert(op); + op->type = ZOO_SETDATA_OP; + op->set_op.path = path; + op->set_op.data = buffer; + op->set_op.datalen = buflen; + op->set_op.version = version; + op->set_op.stat = stat; +} + +void zoo_check_op_init(zoo_op_t *op, const char *path, int version) +{ + assert(op); + op->type = ZOO_CHECK_OP; + op->check_op.path = path; + op->check_op.version = version; +} + +int zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results) +{ + int rc; + + struct sync_completion *sc = alloc_sync_completion(); + if (!sc) { + return ZSYSTEMERROR; + } + + rc = zoo_amulti(zh, count, ops, results, SYNCHRONOUS_MARKER, sc); + if (rc == ZOK) { + wait_sync_completion(sc); + rc = sc->rc; + } + free_sync_completion(sc); + + return rc; +} + +/* specify timeout of 0 to make the function non-blocking */ +/* timeout is in milliseconds */ +int flush_send_queue(zhandle_t*zh, int timeout) +{ + int rc= ZOK; + struct timeval started; +#ifdef _WIN32 + fd_set pollSet; + struct timeval wait; +#endif + get_system_time(&started); + // we can't use dequeue_buffer() here because if (non-blocking) send_buffer() + // returns EWOULDBLOCK we'd have to put the buffer back on the queue. + // we use a recursive lock instead and only dequeue the buffer if a send was + // successful + lock_buffer_list(&zh->to_send); + while (zh->to_send.head != 0 && is_connected(zh)) { + if(timeout!=0){ +#ifndef _WIN32 + struct pollfd fds; +#endif + int elapsed; + struct timeval now; + get_system_time(&now); + elapsed=calculate_interval(&started,&now); + if (elapsed>timeout) { + rc = ZOPERATIONTIMEOUT; + break; + } + +#ifdef _WIN32 + wait = get_timeval(timeout-elapsed); + FD_ZERO(&pollSet); + FD_SET(zh->fd, &pollSet); + // Poll the socket + rc = select((int)(zh->fd)+1, NULL, &pollSet, NULL, &wait); +#else + fds.fd = zh->fd; + fds.events = POLLOUT; + fds.revents = 0; + rc = poll(&fds, 1, timeout-elapsed); +#endif + if (rc<=0) { + /* timed out or an error or POLLERR */ + rc = rc==0 ? ZOPERATIONTIMEOUT : ZSYSTEMERROR; + break; + } + } + + rc = send_buffer(zh->fd, zh->to_send.head); + if(rc==0 && timeout==0){ + /* send_buffer would block while sending this buffer */ + rc = ZOK; + break; + } + if (rc < 0) { + rc = ZCONNECTIONLOSS; + break; + } + // if the buffer has been sent successfully, remove it from the queue + if (rc > 0) + remove_buffer(&zh->to_send); + get_system_time(&zh->last_send); + rc = ZOK; + } + unlock_buffer_list(&zh->to_send); + return rc; +} + +const char* zerror(int c) +{ + switch (c){ + case ZOK: + return "ok"; + case ZSYSTEMERROR: + return "system error"; + case ZRUNTIMEINCONSISTENCY: + return "run time inconsistency"; + case ZDATAINCONSISTENCY: + return "data inconsistency"; + case ZCONNECTIONLOSS: + return "connection loss"; + case ZMARSHALLINGERROR: + return "marshalling error"; + case ZUNIMPLEMENTED: + return "unimplemented"; + case ZOPERATIONTIMEOUT: + return "operation timeout"; + case ZBADARGUMENTS: + return "bad arguments"; + case ZINVALIDSTATE: + return "invalid zhandle state"; + case ZAPIERROR: + return "api error"; + case ZNONODE: + return "no node"; + case ZNOAUTH: + return "not authenticated"; + case ZBADVERSION: + return "bad version"; + case ZNOCHILDRENFOREPHEMERALS: + return "no children for ephemerals"; + case ZNODEEXISTS: + return "node exists"; + case ZNOTEMPTY: + return "not empty"; + case ZSESSIONEXPIRED: + return "session expired"; + case ZINVALIDCALLBACK: + return "invalid callback"; + case ZINVALIDACL: + return "invalid acl"; + case ZAUTHFAILED: + return "authentication failed"; + case ZCLOSING: + return "zookeeper is closing"; + case ZNOTHING: + return "(not error) no server responses to process"; + case ZSESSIONMOVED: + return "session moved to another server, so operation is ignored"; + case ZNOTREADONLY: + return "state-changing request is passed to read-only server"; + case ZNEWCONFIGNOQUORUM: + return "no quorum of new config is connected and up-to-date with the leader of last commmitted config - try invoking reconfiguration after new servers are connected and synced"; + case ZRECONFIGINPROGRESS: + return "Another reconfiguration is in progress -- concurrent reconfigs not supported (yet)"; + } + if (c > 0) { + return strerror(c); + } + return "unknown error"; +} + +int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert, + int certLen,void_completion_t completion, const void *data) +{ + struct buffer auth; + auth_info *authinfo; + if(scheme==NULL || zh==NULL) + return ZBADARGUMENTS; + + if (is_unrecoverable(zh)) + return ZINVALIDSTATE; + + // [ZOOKEEPER-800] zoo_add_auth should return ZINVALIDSTATE if + // the connection is closed. + if (zoo_state(zh) == 0) { + return ZINVALIDSTATE; + } + + if(cert!=NULL && certLen!=0){ + auth.buff=calloc(1,certLen); + if(auth.buff==0) { + return ZSYSTEMERROR; + } + memcpy(auth.buff,cert,certLen); + auth.len=certLen; + } else { + auth.buff = 0; + auth.len = 0; + } + + zoo_lock_auth(zh); + authinfo = (auth_info*) malloc(sizeof(auth_info)); + authinfo->scheme=strdup(scheme); + authinfo->auth=auth; + authinfo->completion=completion; + authinfo->data=data; + authinfo->next = NULL; + add_last_auth(&zh->auth_h, authinfo); + zoo_unlock_auth(zh); + + if (is_connected(zh) || zh->state == ZOO_ASSOCIATING_STATE) + return send_last_auth_info(zh); + + return ZOK; +} + +static const char* format_endpoint_info(const struct sockaddr_storage* ep) +{ + static char buf[128] = { 0 }; + char addrstr[128] = { 0 }; + void *inaddr; +#ifdef _WIN32 + char * addrstring; +#endif + int port; + if(ep==0) + return "null"; + +#if defined(AF_INET6) + if(ep->ss_family==AF_INET6){ + inaddr=&((struct sockaddr_in6*)ep)->sin6_addr; + port=((struct sockaddr_in6*)ep)->sin6_port; + } else { +#endif + inaddr=&((struct sockaddr_in*)ep)->sin_addr; + port=((struct sockaddr_in*)ep)->sin_port; +#if defined(AF_INET6) + } +#endif +#ifdef _WIN32 + addrstring = inet_ntoa (*(struct in_addr*)inaddr); + sprintf(buf,"%s:%d",addrstring,ntohs(port)); +#else + inet_ntop(ep->ss_family,inaddr,addrstr,sizeof(addrstr)-1); + sprintf(buf,"%s:%d",addrstr,ntohs(port)); +#endif + return buf; +} + +log_callback_fn zoo_get_log_callback(const zhandle_t* zh) +{ + // Verify we have a valid handle + if (zh == NULL) { + return NULL; + } + + return zh->log_callback; +} + +void zoo_set_log_callback(zhandle_t *zh, log_callback_fn callback) +{ + // Verify we have a valid handle + if (zh == NULL) { + return; + } + + zh->log_callback = callback; +} + +void zoo_deterministic_conn_order(int yesOrNo) +{ + disable_conn_permute=yesOrNo; +} + +/*---------------------------------------------------------------------------* + * SYNC API + *---------------------------------------------------------------------------*/ +int zoo_create(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + char *path_buffer, int path_buffer_len) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + sc->u.str.str = path_buffer; + sc->u.str.str_len = path_buffer_len; + rc=zoo_acreate(zh, path, value, valuelen, acl, flags, SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + } + free_sync_completion(sc); + return rc; +} + +int zoo_create2(zhandle_t *zh, const char *path, const char *value, + int valuelen, const struct ACL_vector *acl, int flags, + char *path_buffer, int path_buffer_len, struct Stat *stat) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + + sc->u.str.str = path_buffer; + sc->u.str.str_len = path_buffer_len; + rc=zoo_acreate2(zh, path, value, valuelen, acl, flags, SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0 && stat) { + *stat = sc->u.stat; + } + } + free_sync_completion(sc); + return rc; +} + +int zoo_delete(zhandle_t *zh, const char *path, int version) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + rc=zoo_adelete(zh, path, version, SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + } + free_sync_completion(sc); + return rc; +} + +int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat) +{ + return zoo_wexists(zh,path,watch?zh->watcher:0,zh->context,stat); +} + +int zoo_wexists(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, struct Stat *stat) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + rc=zoo_awexists(zh,path,watcher,watcherCtx,SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0&& stat) { + *stat = sc->u.stat; + } + } + free_sync_completion(sc); + return rc; +} + +int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, + int* buffer_len, struct Stat *stat) +{ + return zoo_wget(zh,path,watch?zh->watcher:0,zh->context, + buffer,buffer_len,stat); +} + +int zoo_wget(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + char *buffer, int* buffer_len, struct Stat *stat) +{ + struct sync_completion *sc; + int rc=0; + + if(buffer_len==NULL) + return ZBADARGUMENTS; + if((sc=alloc_sync_completion())==NULL) + return ZSYSTEMERROR; + + sc->u.data.buffer = buffer; + sc->u.data.buff_len = *buffer_len; + rc=zoo_awget(zh, path, watcher, watcherCtx, SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0) { + if(stat) + *stat = sc->u.data.stat; + *buffer_len = sc->u.data.buff_len; + } + } + free_sync_completion(sc); + return rc; +} + +int zoo_getconfig(zhandle_t *zh, int watch, char *buffer, + int* buffer_len, struct Stat *stat) +{ + return zoo_wget(zh,ZOO_CONFIG_NODE,watch?zh->watcher:0,zh->context, buffer,buffer_len,stat); +} + +int zoo_wgetconfig(zhandle_t *zh, watcher_fn watcher, void* watcherCtx, + char *buffer, int* buffer_len, struct Stat *stat) +{ + return zoo_wget(zh, ZOO_CONFIG_NODE, watcher, watcherCtx, buffer, buffer_len, stat); +} + + +int zoo_reconfig(zhandle_t *zh, const char *joining, const char *leaving, + const char *members, int64_t version, char *buffer, int* buffer_len, + struct Stat *stat) +{ + struct sync_completion *sc; + int rc=0; + + if(buffer_len==NULL) + return ZBADARGUMENTS; + if((sc=alloc_sync_completion())==NULL) + return ZSYSTEMERROR; + + sc->u.data.buffer = buffer; + sc->u.data.buff_len = *buffer_len; + rc=zoo_areconfig(zh, joining, leaving, members, version, SYNCHRONOUS_MARKER, sc); + + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0) { + if(stat) + *stat = sc->u.data.stat; + *buffer_len = sc->u.data.buff_len; + } + } + free_sync_completion(sc); + return rc; +} + +int zoo_set(zhandle_t *zh, const char *path, const char *buffer, int buflen, + int version) +{ + return zoo_set2(zh, path, buffer, buflen, version, 0); +} + +int zoo_set2(zhandle_t *zh, const char *path, const char *buffer, int buflen, + int version, struct Stat *stat) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + rc=zoo_aset(zh, path, buffer, buflen, version, SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0 && stat) { + *stat = sc->u.stat; + } + } + free_sync_completion(sc); + return rc; +} + +static int zoo_wget_children_(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + struct String_vector *strings) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + rc= zoo_awget_children (zh, path, watcher, watcherCtx, SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0) { + if (strings) { + *strings = sc->u.strs2; + } else { + deallocate_String_vector(&sc->u.strs2); + } + } + } + free_sync_completion(sc); + return rc; +} + +static int zoo_wget_children2_(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + struct String_vector *strings, struct Stat *stat) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + rc= zoo_awget_children2(zh, path, watcher, watcherCtx, SYNCHRONOUS_MARKER, sc); + + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0) { + *stat = sc->u.strs_stat.stat2; + if (strings) { + *strings = sc->u.strs_stat.strs2; + } else { + deallocate_String_vector(&sc->u.strs_stat.strs2); + } + } + } + free_sync_completion(sc); + return rc; +} + +int zoo_get_children(zhandle_t *zh, const char *path, int watch, + struct String_vector *strings) +{ + return zoo_wget_children_(zh,path,watch?zh->watcher:0,zh->context,strings); +} + +int zoo_wget_children(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + struct String_vector *strings) +{ + return zoo_wget_children_(zh,path,watcher,watcherCtx,strings); +} + +int zoo_get_children2(zhandle_t *zh, const char *path, int watch, + struct String_vector *strings, struct Stat *stat) +{ + return zoo_wget_children2_(zh,path,watch?zh->watcher:0,zh->context,strings,stat); +} + +int zoo_wget_children2(zhandle_t *zh, const char *path, + watcher_fn watcher, void* watcherCtx, + struct String_vector *strings, struct Stat *stat) +{ + return zoo_wget_children2_(zh,path,watcher,watcherCtx,strings,stat); +} + +int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, + struct Stat *stat) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + rc=zoo_aget_acl(zh, path, SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + if (rc == 0&& stat) { + *stat = sc->u.acl.stat; + } + if (rc == 0) { + if (acl) { + *acl = sc->u.acl.acl; + } else { + deallocate_ACL_vector(&sc->u.acl.acl); + } + } + } + free_sync_completion(sc); + return rc; +} + +int zoo_set_acl(zhandle_t *zh, const char *path, int version, + const struct ACL_vector *acl) +{ + struct sync_completion *sc = alloc_sync_completion(); + int rc; + if (!sc) { + return ZSYSTEMERROR; + } + rc=zoo_aset_acl(zh, path, version, (struct ACL_vector*)acl, + SYNCHRONOUS_MARKER, sc); + if(rc==ZOK){ + wait_sync_completion(sc); + rc = sc->rc; + } + free_sync_completion(sc); + return rc; +} + +int zoo_remove_watchers(zhandle_t *zh, const char *path, ZooWatcherType wtype, + watcher_fn watcher, void *watcherCtx, int local) +{ + struct sync_completion *sc; + int rc = 0; + + if (!path) + return ZBADARGUMENTS; + + sc = alloc_sync_completion(); + if (!sc) + return ZSYSTEMERROR; + + rc = zoo_aremove_watchers(zh, path, wtype, watcher, watcherCtx, local, + SYNCHRONOUS_MARKER, sc); + if (rc == ZOK) { + wait_sync_completion(sc); + rc = sc->rc; + } + free_sync_completion(sc); + return rc; +} + +int zoo_aremove_watchers(zhandle_t *zh, const char *path, ZooWatcherType wtype, + watcher_fn watcher, void *watcherCtx, int local, + void_completion_t *completion, const void *data) +{ + char *server_path = prepend_string(zh, path); + int rc; + struct oarchive *oa; + struct RequestHeader h = { get_xid(), ZOO_REMOVE_WATCHES }; + struct RemoveWatchesRequest req = { (char*)server_path, wtype }; + watcher_deregistration_t *wdo; + + if (!zh || !isValidPath(server_path, 0)) { + rc = ZBADARGUMENTS; + goto done; + } + + if (!local && is_unrecoverable(zh)) { + rc = ZINVALIDSTATE; + goto done; + } + + if (!pathHasWatcher(zh, server_path, wtype, watcher, watcherCtx)) { + rc = ZNOWATCHER; + goto done; + } + + if (local) { + removeWatchers(zh, server_path, wtype, watcher, watcherCtx); + notify_sync_completion((struct sync_completion *)data); + rc = ZOK; + goto done; + } + + oa = create_buffer_oarchive(); + rc = serialize_RequestHeader(oa, "header", &h); + rc = rc < 0 ? rc : serialize_RemoveWatchesRequest(oa, "req", &req); + if (rc < 0) { + goto done; + } + + wdo = create_watcher_deregistration(server_path, watcher, watcherCtx, + wtype); + if (!wdo) { + rc = ZSYSTEMERROR; + goto done; + } + + enter_critical(zh); + rc = add_completion_deregistration(zh, h.xid, COMPLETION_VOID, + completion, data, 0, wdo, 0); + rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa), + get_buffer_len(oa)); + rc = rc < 0 ? ZMARSHALLINGERROR : ZOK; + leave_critical(zh); + + /* We queued the buffer, so don't free it */ + close_buffer_oarchive(&oa, 0); + + LOG_DEBUG(LOGCALLBACK(zh), "Sending request xid=%#x for path [%s] to %s", + h.xid, path, zoo_get_current_server(zh)); + + adaptor_send_queue(zh, 0); + +done: + free_duplicate_path(server_path, path); + return rc; +} diff --git a/src/c/tests/CollectionUtil.h b/src/c/tests/CollectionUtil.h new file mode 100644 index 00000000000..dd3481175b0 --- /dev/null +++ b/src/c/tests/CollectionUtil.h @@ -0,0 +1,195 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _COLLECTION_UTIL_H_ +#define _COLLECTION_UTIL_H_ + +/** + * \file + * CollectionBuilder and DictionaryBuilder classes and collection utility functions + */ + +namespace Util +{ + +// ********************************************************* +/** A shortcut to use for building collections. + * This class is a wrapper around standard STL collection containers such as vector. + * It allows one to conveniently build collections at the variable initialization time: + * \code + * #include "CollectionUtil.h" + * #include "Vector.h" // for ostream << operator overload for STL vector + * using Util; + * + * int main() + * { + * typedef vector MyVector; + * MyVector myVector=CollectionBuilder()("str1")("str2")("str3"); + * cout< +class CollectionBuilder +{ +public: + /// Type of the collection container. + typedef CONT CollectionType; + /// Container's value type. + typedef typename CollectionType::value_type value_type; + /// Container's constant iterator type. + typedef typename CollectionType::const_iterator const_iterator; + /// Container's size type. + typedef typename CollectionType::size_type size_type; + + /** Operator function call overload to allow call chaining. + * \param value the value to be inserted into the container + */ + CollectionBuilder& operator()(const value_type& value){ + return push_back(value); + } + /** Same as regular STL push_back() but allows call chaining. + * \param value the value to be inserted into the container + */ + CollectionBuilder& push_back(const value_type& value){ + collection_.push_back(value); + return *this; + } + /// \name Standard STL container interface + /// @{ + const_iterator begin() const{return collection_.begin();} + const_iterator end() const{return collection_.end();} + size_type size() const{return collection_.size();} + void clear() {collection_.clear();} + ///@} + /// Explicit typecast operator. + operator const CollectionType&() const {return collection_;} +private: + /// \cond PRIVATE + CollectionType collection_; + /// \endcond +}; + + +// ********************************************************* +/** A shortcut to use for building dictionaries. + * This class is a wrapper around standard STL associative containers such as map. + * It allows one to conveniently build dictionaries at the variable initialization time: + * \code + * #include "CollectionUtil.h" + * #include "Map.h" // for ostream << operator overload for STL map + * using Util; + * + * int main() + * { + * typedef map MyMap; + * MyMap myMap=DictionaryBuilder()("str1",1)("str2",2)("str3",3); + * cout< +class DictionaryBuilder +{ +public: + /// The type of the associative container + typedef CONT DictionaryType; + /// Container's element type (usually a pair) + typedef typename DictionaryType::value_type value_type; + /// Container's key type + typedef typename DictionaryType::key_type key_type; + /// Container's value type + typedef typename DictionaryType::mapped_type mapped_type; + /// Container's constant iterator type + typedef typename DictionaryType::const_iterator const_iterator; + /// Container's writable iterator type + typedef typename DictionaryType::iterator iterator; + /// Container's size type + typedef typename DictionaryType::size_type size_type; + + /** Operator function call overload to allow call chaining. + * \param key the value key to be inserted + * \param value the value to be inserted into the container + * \return a non-const reference to self + */ + DictionaryBuilder& operator()(const key_type& key,const mapped_type& value){ + dict_.insert(value_type(key,value)); + return *this; + } + /** Lookup value by key. + * \param key the key associated with the value. + * \return a non-const iterator pointing to the element whose key matched the \a key parameter + */ + iterator find(const key_type& key){ + return dict_.find(key); + } + /** Lookup value by key. + * \param key the key associated with the value. + * \return a const iterator pointing to the element whose key matched the \a key parameter + */ + const_iterator find(const key_type& key) const{ + return dict_.find(key); + } + + /// \name Standard STL container interface + /// @{ + const_iterator begin() const{return dict_.begin();} + const_iterator end() const{return dict_.end();} + size_type size() const{return dict_.size();} + void clear() {dict_.clear();} + ///@} + /// Explicit typecast operator. + operator const DictionaryType&() const {return dict_;} +private: + DictionaryType dict_; +}; + + +// *********************************************************** +/** Deletes all dynamically allocated elements of a collection. + * C::value_type is expected to be a pointer to a dynamically allocated object, or it won't compile. + * The function will iterate over all container elements and call delete for each of them. + * \param c a collection (vector,set) whose elements are being deleted. + */ +template +void clearCollection(C& c){ + for(typename C::const_iterator it=c.begin();it!=c.end();++it) + delete *it; + c.clear(); +} + +/** Deletes all dynamically allocated values of the assotiative container. + * The function expects the M::value_type to be a pair<..., ptr_to_type>, or it won't compile. + * It first deletes the objects pointed to by ptr_to_type + * and then clears (calls m.clear()) the container. + * \param m an associative container (map,hash_map) whose elements are being deleted. + */ +template +void clearMap(M& m){ + for(typename M::const_iterator it=m.begin();it!=m.end();++it) + delete it->second; + m.clear(); +} + +} // namespace Util + + +#endif // _COLLECTION_UTIL_H_ diff --git a/src/c/tests/CppAssertHelper.h b/src/c/tests/CppAssertHelper.h new file mode 100644 index 00000000000..3926f51efcb --- /dev/null +++ b/src/c/tests/CppAssertHelper.h @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CPPASSERTHELPER_H_ +#define CPPASSERTHELPER_H_ + +#include + +// make it possible to specify location of the ASSERT call +#define CPPUNIT_ASSERT_EQUAL_LOC(expected,actual,file,line) \ + ( CPPUNIT_NS::assertEquals( (expected), \ + (actual), \ + CPPUNIT_NS::SourceLine(file,line), \ + "" ) ) + +#define CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC(message,expected,actual,file,line) \ + ( CPPUNIT_NS::assertEquals( (expected), \ + (actual), \ + CPPUNIT_NS::SourceLine(file,line), \ + (message) ) ) + +#endif /*CPPASSERTHELPER_H_*/ diff --git a/src/c/tests/LibCMocks.cc b/src/c/tests/LibCMocks.cc new file mode 100644 index 00000000000..870a554ca3b --- /dev/null +++ b/src/c/tests/LibCMocks.cc @@ -0,0 +1,347 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include // needed for _POSIX_MONOTONIC_CLOCK +#include + +#include "Util.h" +#include "LibCMocks.h" + +#undef USING_DUMA + +using namespace std; + +// ***************************************************************************** +// gethostbyname + +struct hostent* gethostbyname(const char *name) { + if(!Mock_gethostbyname::mock_) + return LIBC_SYMBOLS.gethostbyname(name); + return Mock_gethostbyname::mock_->call(name); +} + +Mock_gethostbyname* Mock_gethostbyname::mock_=0; + +Mock_gethostbyname::~Mock_gethostbyname(){ + mock_=0; + for(unsigned int i=0;icall(p1,p2); +} +#endif + +void* Mock_calloc::call(size_t p1, size_t p2){ +#ifndef USING_DUMA + if(counter++ ==callsBeforeFailure){ + counter=0; + errno=errnoOnFailure; + return 0; + } + return CALL_REAL(calloc,(p1,p2)); +#else + return 0; +#endif +} + +Mock_calloc* Mock_calloc::mock_=0; + +// ***************************************************************************** +// realloc + +#ifndef USING_DUMA +DECLARE_WRAPPER(void*,realloc,(void* p, size_t s)){ + if(!Mock_realloc::mock_) + return LIBC_SYMBOLS.realloc(p,s); + return Mock_realloc::mock_->call(p,s); +} +#endif + +Mock_realloc* Mock_realloc::mock_=0; + +void* Mock_realloc::call(void* p, size_t s){ + if(counter++ ==callsBeforeFailure){ + counter=0; + errno=errnoOnFailure; + return 0; + } + return LIBC_SYMBOLS.realloc(p,s); +} + +// ***************************************************************************** +// random +RANDOM_RET_TYPE random(){ + if(!Mock_random::mock_) + return LIBC_SYMBOLS.random(); + return Mock_random::mock_->call(); +} + +void srandom(unsigned long seed){ + if (!Mock_random::mock_) + LIBC_SYMBOLS.srandom(seed); + else + Mock_random::mock_->setSeed(seed); +} + +Mock_random* Mock_random::mock_=0; + +int Mock_random::call(){ + assert("Must specify one or more random integers"&&(randomReturns.size()!=0)); + return randomReturns[currentIdx++ % randomReturns.size()]; +} + +// ***************************************************************************** +// free +#ifndef USING_DUMA +DECLARE_WRAPPER(void,free,(void* p)){ + if(Mock_free_noop::mock_ && !Mock_free_noop::mock_->nested) + Mock_free_noop::mock_->call(p); + else + CALL_REAL(free,(p)); +} +#endif + +void Mock_free_noop::call(void* p){ + // on cygwin libc++ is linked statically + // push_back() may call free(), hence the nesting guards + synchronized(mx); + nested++; + callCounter++; + requested.push_back(p); + nested--; +} +void Mock_free_noop::freeRequested(){ +#ifndef USING_DUMA + synchronized(mx); + for(unsigned i=0; icallSocket(domain,type,protocol); +} + +int close(int fd){ + if (!Mock_socket::mock_) + return LIBC_SYMBOLS.close(fd); + return Mock_socket::mock_->callClose(fd); +} + +int getsockopt(int s,int level,int optname,void *optval,socklen_t *optlen){ + if (!Mock_socket::mock_) + return LIBC_SYMBOLS.getsockopt(s,level,optname,optval,optlen); + return Mock_socket::mock_->callGet(s,level,optname,optval,optlen); +} + +int setsockopt(int s,int level,int optname,const void *optval,socklen_t optlen){ + if (!Mock_socket::mock_) + return LIBC_SYMBOLS.setsockopt(s,level,optname,optval,optlen); + return Mock_socket::mock_->callSet(s,level,optname,optval,optlen); +} +int connect(int s,const struct sockaddr *addr,socklen_t len){ + if (!Mock_socket::mock_) + return LIBC_SYMBOLS.connect(s,addr,len); + return Mock_socket::mock_->callConnect(s,addr,len); +} +ssize_t send(int s,const void *buf,size_t len,int flags){ + if (!Mock_socket::mock_) + return LIBC_SYMBOLS.send(s,buf,len,flags); + return Mock_socket::mock_->callSend(s,buf,len,flags); +} + +ssize_t recv(int s,void *buf,size_t len,int flags){ + if (!Mock_socket::mock_) + return LIBC_SYMBOLS.recv(s,buf,len,flags); + return Mock_socket::mock_->callRecv(s,buf,len,flags); +} + +Mock_socket* Mock_socket::mock_=0; + +// ***************************************************************************** +// fcntl +extern "C" int fcntl(int fd,int cmd,...){ + va_list va; + va_start(va,cmd); + void* arg = va_arg(va, void *); + va_end (va); + if (!Mock_fcntl::mock_) + return LIBC_SYMBOLS.fcntl(fd,cmd,arg); + return Mock_fcntl::mock_->call(fd,cmd,arg); +} + +Mock_fcntl* Mock_fcntl::mock_=0; + +// ***************************************************************************** +// select +int select(int nfds,fd_set *rfds,fd_set *wfds,fd_set *efds,struct timeval *timeout){ + if (!Mock_select::mock_) + return LIBC_SYMBOLS.select(nfds,rfds,wfds,efds,timeout); + return Mock_select::mock_->call(nfds,rfds,wfds,efds,timeout); +} + +Mock_select* Mock_select::mock_=0; + +// ***************************************************************************** +// poll +Mock_poll* Mock_poll::mock_=0; +int poll(struct pollfd *fds, POLL_NFDS_TYPE nfds, int timeout){ + if (!Mock_poll::mock_) + return LIBC_SYMBOLS.poll(fds,nfds,timeout); + return Mock_poll::mock_->call(fds,nfds,timeout); + +} + +/* + * Recent gcc with -O2 and glibc FORTIFY feature may cause our poll + * mock to be ignored. + */ +#if __USE_FORTIFY_LEVEL > 0 +int __poll_chk (struct pollfd *__fds, nfds_t __nfds, int __timeout, + __SIZE_TYPE__ __fdslen) { + return poll(__fds, __nfds, __timeout); +} +#endif + +// ***************************************************************************** +// gettimeofday +int gettimeofday(struct timeval *tp, GETTIMEOFDAY_ARG2_TYPE tzp){ + if (!Mock_gettimeofday::mock_) + return LIBC_SYMBOLS.gettimeofday(tp,tzp); + return Mock_gettimeofday::mock_->call(tp,tzp); +} + +Mock_gettimeofday* Mock_gettimeofday::mock_=0; + +// ***************************************************************************** +#ifdef _POSIX_MONOTONIC_CLOCK +// clock_gettime +int clock_gettime(clockid_t id, struct timespec *tp) { + if (!Mock_gettimeofday::mock_) + return LIBC_SYMBOLS.clock_gettime(id,tp); + struct timeval tv = { 0 }; + int res = Mock_gettimeofday::mock_->call(&tv, NULL); + tp->tv_sec = tv.tv_sec; + tp->tv_nsec = tv.tv_usec * 1000; + return res; +} +#endif diff --git a/src/c/tests/LibCMocks.h b/src/c/tests/LibCMocks.h new file mode 100644 index 00000000000..5b07cdae92d --- /dev/null +++ b/src/c/tests/LibCMocks.h @@ -0,0 +1,408 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBCMOCKS_H_ +#define LIBCMOCKS_H_ + +#include +#include +#include + +#include +#include + +#include "MocksBase.h" +#include "LibCSymTable.h" +#include "ThreadingUtil.h" + +// ***************************************************************************** +// gethostbyname + +class Mock_gethostbyname: public Mock +{ +public: + struct HostEntry: public hostent { + HostEntry(const char* hostName,short addrtype); + ~HostEntry(); + HostEntry& addAlias(const char* alias); + HostEntry& addAddress(const char* addr4); + }; + + Mock_gethostbyname():current(0){mock_=this;} + virtual ~Mock_gethostbyname(); + HostEntry& addHostEntry(const char* hostName,short addrtype=AF_INET); + virtual hostent* call(const char* name); + + typedef std::vector HostEntryCollection; + HostEntryCollection gethostbynameReturns; + int current; + static Mock_gethostbyname* mock_; +}; + +class MockFailed_gethostbyname: public Mock_gethostbyname +{ +public: + MockFailed_gethostbyname():h_errnoReturn(HOST_NOT_FOUND) {} + + int h_errnoReturn; + virtual hostent* call(const char* name) { + h_errno=h_errnoReturn; + return 0; + } +}; + +// ***************************************************************************** +// calloc + +class Mock_calloc: public Mock +{ +public: + Mock_calloc():errnoOnFailure(ENOMEM),callsBeforeFailure(-1),counter(0) { + mock_=this; + } + virtual ~Mock_calloc() {mock_=0;} + + int errnoOnFailure; + int callsBeforeFailure; + int counter; + virtual void* call(size_t p1, size_t p2); + + static Mock_calloc* mock_; +}; + +// ***************************************************************************** +// realloc + +class Mock_realloc: public Mock +{ +public: + Mock_realloc():errnoOnFailure(ENOMEM),callsBeforeFailure(-1),counter(0) { + mock_=this; + } + virtual ~Mock_realloc() {mock_=0;} + + int errnoOnFailure; + int callsBeforeFailure; + int counter; + virtual void* call(void* p, size_t s); + + static Mock_realloc* mock_; +}; + +// ***************************************************************************** +// random + +class Mock_random: public Mock +{ +public: + Mock_random():currentIdx(0) {mock_=this;} + virtual ~Mock_random() {mock_=0;} + + int currentIdx; + std::vector randomReturns; + virtual int call(); + void setSeed(unsigned long){currentIdx=0;} + + static Mock_random* mock_; +}; + +// ***************************************************************************** +// no-op free; keeps track of all deallocation requests +class Mock_free_noop: public Mock +{ + Mutex mx; + std::vector requested; +public: + Mock_free_noop():nested(0),callCounter(0){mock_=this;} + virtual ~Mock_free_noop(){ + mock_=0; + freeRequested(); + } + + int nested; + int callCounter; + virtual void call(void* p); + void freeRequested(); + void disable(){mock_=0;} + // returns number of times the pointer was freed + int getFreeCount(void*); + bool isFreed(void*); + + static Mock_free_noop* mock_; +}; + +// ***************************************************************************** +// socket and related system calls + +class Mock_socket: public Mock +{ +public: + static const int FD=63; + Mock_socket():socketReturns(FD),closeReturns(0),getsocketoptReturns(0), + optvalSO_ERROR(0), + setsockoptReturns(0),connectReturns(0),connectErrno(0), + sendErrno(0),recvErrno(0) + { + mock_=this; + } + virtual ~Mock_socket(){mock_=0;} + + int socketReturns; + virtual int callSocket(int domain, int type, int protocol){ + return socketReturns; + } + int closeReturns; + virtual int callClose(int fd){ + return closeReturns; + } + int getsocketoptReturns; + int optvalSO_ERROR; + virtual int callGet(int s,int level,int optname,void *optval,socklen_t *len){ + if(level==SOL_SOCKET && optname==SO_ERROR){ + setSO_ERROR(optval,*len); + } + return getsocketoptReturns; + } + virtual void setSO_ERROR(void *optval,socklen_t len){ + memcpy(optval,&optvalSO_ERROR,len); + } + + int setsockoptReturns; + virtual int callSet(int s,int level,int optname,const void *optval,socklen_t len){ + return setsockoptReturns; + } + int connectReturns; + int connectErrno; + virtual int callConnect(int s,const struct sockaddr *addr,socklen_t len){ + errno=connectErrno; + return connectReturns; + } + + virtual void notifyBufferSent(const std::string& buffer){} + + int sendErrno; + std::string sendBuffer; + virtual ssize_t callSend(int s,const void *buf,size_t len,int flags){ + if(sendErrno!=0){ + errno=sendErrno; + return -1; + } + // first call to send() is always the length of the buffer to follow + bool sendingLength=sendBuffer.size()==0; + // overwrite the length bytes + sendBuffer.assign((const char*)buf,len); + if(!sendingLength){ + notifyBufferSent(sendBuffer); + sendBuffer.erase(); + } + return len; + } + + int recvErrno; + std::string recvReturnBuffer; + virtual ssize_t callRecv(int s,void *buf,size_t len,int flags){ + if(recvErrno!=0){ + errno=recvErrno; + return -1; + } + int k=std::min(len,recvReturnBuffer.length()); + if(k==0) + return 0; + memcpy(buf,recvReturnBuffer.data(),k); + recvReturnBuffer.erase(0,k); + return k; + } + virtual bool hasMoreRecv() const{ + return recvReturnBuffer.size()!=0; + } + static Mock_socket* mock_; +}; + +// ***************************************************************************** +// fcntl +class Mock_fcntl: public Mock +{ +public: + Mock_fcntl():callReturns(0),trapFD(-1){mock_=this;} + ~Mock_fcntl(){mock_=0;} + + int callReturns; + int trapFD; + virtual int call(int fd, int cmd, void* arg){ + if(trapFD==-1) + return LIBC_SYMBOLS.fcntl(fd,cmd,arg); + return callReturns; + } + + static Mock_fcntl* mock_; +}; + +// ***************************************************************************** +// select +class Mock_select: public Mock +{ +public: + Mock_select(Mock_socket* s,int fd):sock(s), + callReturns(0),myFD(fd),timeout(50) + { + mock_=this; + } + ~Mock_select(){mock_=0;} + + Mock_socket* sock; + int callReturns; + int myFD; + int timeout; //in millis + virtual int call(int nfds,fd_set *rfds,fd_set *wfds,fd_set *efds,struct timeval *tv){ + bool isWritableRequested=(wfds && FD_ISSET(myFD,wfds)); + if(rfds) FD_CLR(myFD,rfds); + if(wfds) FD_CLR(myFD,wfds); + // this timeout is only to prevent a tight loop + timeval myTimeout={0,0}; + if(!isWritableRequested && !isFDReadable()){ + myTimeout.tv_sec=timeout/1000; + myTimeout.tv_usec=(timeout%1000)*1000; + } + LIBC_SYMBOLS.select(nfds,rfds,wfds,efds,&myTimeout); + // myFD is always writable + if(isWritableRequested) FD_SET(myFD,wfds); + // myFD is only readable if the socket has anything to read + if(isFDReadable() && rfds) FD_SET(myFD,rfds); + return callReturns; + } + + virtual bool isFDReadable() const { + return sock->hasMoreRecv(); + } + + static Mock_select* mock_; +}; + +// ***************************************************************************** +// poll +// the last element of the pollfd array is expected to be test FD +class Mock_poll: public Mock +{ +public: + Mock_poll(Mock_socket* s,int fd):sock(s), + callReturns(1),myFD(fd),timeout(50) + { + mock_=this; + } + ~Mock_poll(){mock_=0;} + + Mock_socket* sock; + int callReturns; + int myFD; + int timeout; //in millis + virtual int call(struct pollfd *fds, POLL_NFDS_TYPE nfds, int to) { + pollfd* myPoll=0; + if(fds[nfds-1].fd==myFD) + myPoll=&fds[nfds-1]; + bool isWritableRequested=false; + if(myPoll!=0){ + isWritableRequested=myPoll->events&POLLOUT; + nfds--; + } + LIBC_SYMBOLS.poll(fds,nfds,(!isWritableRequested&&!isFDReadable())?timeout:0); + if(myPoll!=0){ + // myFD is always writable if requested + myPoll->revents=isWritableRequested?POLLOUT:0; + // myFD is only readable if the socket has anything to read + myPoll->revents|=isFDReadable()?POLLIN:0; + } + return callReturns; + } + + virtual bool isFDReadable() const { + return sock->hasMoreRecv(); + } + + static Mock_poll* mock_; +}; + +// ***************************************************************************** +// gettimeofday +class Mock_gettimeofday: public Mock +{ +public: + Mock_gettimeofday(){ + LIBC_SYMBOLS.gettimeofday(&tv,0); + mock_=this; + } + Mock_gettimeofday(const Mock_gettimeofday& other):tv(other.tv){} + Mock_gettimeofday(int32_t sec,int32_t usec){ + tv.tv_sec=sec; + tv.tv_usec=usec; + } + ~Mock_gettimeofday(){mock_=0;} + + timeval tv; + virtual int call(struct timeval *tp, GETTIMEOFDAY_ARG2_TYPE tzp){ + *tp=tv; + return 0; + } + operator timeval() const{ + return tv; + } + // advance secs + virtual void tick(int howmuch=1){tv.tv_sec+=howmuch;} + // advance milliseconds + // can move the clock forward as well as backward by providing a negative + // number + virtual void millitick(int howmuch=1){ + int ms=tv.tv_usec/1000+howmuch; + tv.tv_sec+=ms/1000; + // going backward? + if(ms<0){ + ms=1000-(-ms%1000); //wrap millis around + } + tv.tv_usec=(ms%1000)*1000; + } + virtual void tick(const timeval& howmuch){ + // add milliseconds (discarding microsecond portion) + long ms=tv.tv_usec/1000+howmuch.tv_usec/1000; + tv.tv_sec+=howmuch.tv_sec+ms/1000; + tv.tv_usec=(ms%1000)*1000; + } + static Mock_gettimeofday* mock_; +}; + +// discard microseconds! +inline bool operator==(const timeval& lhs, const timeval& rhs){ + return rhs.tv_sec==lhs.tv_sec && rhs.tv_usec/1000==lhs.tv_usec/1000; +} + +// simplistic implementation: no normalization, assume lhs >= rhs, +// discarding microseconds +inline timeval operator-(const timeval& lhs, const timeval& rhs){ + timeval res; + res.tv_sec=lhs.tv_sec-rhs.tv_sec; + res.tv_usec=(lhs.tv_usec/1000-rhs.tv_usec/1000)*1000; + if(res.tv_usec<0){ + res.tv_sec--; + res.tv_usec=1000000+res.tv_usec%1000000; // wrap the millis around + } + return res; +} + +inline int32_t toMilliseconds(const timeval& tv){ + return tv.tv_sec*1000+tv.tv_usec/1000; +} + +#endif /*LIBCMOCKS_H_*/ diff --git a/src/c/tests/LibCSymTable.cc b/src/c/tests/LibCSymTable.cc new file mode 100644 index 00000000000..23862f3c01d --- /dev/null +++ b/src/c/tests/LibCSymTable.cc @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LibCSymTable.h" +#include // needed for _POSIX_MONOTONIC_CLOCK + +#define LOAD_SYM(sym) \ + sym=(sym##_sig)dlsym(handle,#sym); \ + assert("Unable to load "#sym" from libc"&&sym) + + +LibCSymTable& LibCSymTable::instance(){ + static LibCSymTable tbl; + return tbl; +} + +//****************************************************************************** +// preload original libc symbols +LibCSymTable::LibCSymTable() +{ + void* handle=getHandle(); + LOAD_SYM(gethostbyname); + LOAD_SYM(calloc); + LOAD_SYM(realloc); + LOAD_SYM(free); + LOAD_SYM(random); + LOAD_SYM(srandom); + LOAD_SYM(printf); + LOAD_SYM(socket); + LOAD_SYM(close); + LOAD_SYM(getsockopt); + LOAD_SYM(setsockopt); + LOAD_SYM(fcntl); + LOAD_SYM(connect); + LOAD_SYM(send); + LOAD_SYM(recv); + LOAD_SYM(select); + LOAD_SYM(poll); + LOAD_SYM(gettimeofday); +#ifdef _POSIX_MONOTONIC_CLOCK + LOAD_SYM(clock_gettime); +#endif +#ifdef THREADED + LOAD_SYM(pthread_create); + LOAD_SYM(pthread_detach); + LOAD_SYM(pthread_cond_broadcast); + LOAD_SYM(pthread_cond_destroy); + LOAD_SYM(pthread_cond_init); + LOAD_SYM(pthread_cond_signal); + LOAD_SYM(pthread_cond_timedwait); + LOAD_SYM(pthread_cond_wait); + LOAD_SYM(pthread_join); + LOAD_SYM(pthread_mutex_destroy); + LOAD_SYM(pthread_mutex_init); + LOAD_SYM(pthread_mutex_lock); + LOAD_SYM(pthread_mutex_trylock); + LOAD_SYM(pthread_mutex_unlock); +#endif +} + +void* LibCSymTable::getHandle(){ + static void* handle=0; + if(!handle){ +#ifdef __CYGWIN__ + handle=dlopen("cygwin1.dll",RTLD_LAZY); + assert("Unable to dlopen global sym table"&&handle); +#else + handle=RTLD_NEXT; +#endif + } + return handle; +} diff --git a/src/c/tests/LibCSymTable.h b/src/c/tests/LibCSymTable.h new file mode 100644 index 00000000000..1b6f9db996d --- /dev/null +++ b/src/c/tests/LibCSymTable.h @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBCSYMTABLE_H_ +#define LIBCSYMTABLE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include // needed for _POSIX_MONOTONIC_CLOCK + +#ifdef THREADED +#include +#endif + +#include "config.h" + +// TODO: move all these macros to config.h (generated by autoconf) +#ifdef __CYGWIN__ +#if (CYGWIN_VERSION_DLL_MAJOR < 1007) +#define RANDOM_RET_TYPE int +#else +#define RANDOM_RET_TYPE long int +#endif +#define GETTIMEOFDAY_ARG2_TYPE void* +#else +#define RANDOM_RET_TYPE long int +#define GETTIMEOFDAY_ARG2_TYPE struct timezone* +#endif + +#define DECLARE_SYM(ret,sym,sig) \ + typedef ret (*sym##_sig)sig; \ + static sym##_sig preload_##sym () { \ + static sym##_sig ptr=0;\ + if(!ptr){ void* h=getHandle(); ptr=(sym##_sig)dlsym(h,#sym); } \ + assert("Unable to load "#sym" from libc"&&ptr); \ + return ptr; \ + } \ + sym##_sig sym + +#define LIBC_SYMBOLS LibCSymTable::instance() + +//****************************************************************************** +// preload original libc symbols +struct LibCSymTable +{ + DECLARE_SYM(hostent*,gethostbyname,(const char*)); + DECLARE_SYM(void*,calloc,(size_t, size_t)); + DECLARE_SYM(void*,realloc,(void*, size_t)); + DECLARE_SYM(void,free,(void*)); + DECLARE_SYM(RANDOM_RET_TYPE,random,(void)); + DECLARE_SYM(void,srandom,(unsigned long)); + DECLARE_SYM(int,printf,(const char*, ...)); + DECLARE_SYM(int,socket,(int,int,int)); + DECLARE_SYM(int,close,(int)); + DECLARE_SYM(int,getsockopt,(int,int,int,void*,socklen_t*)); + DECLARE_SYM(int,setsockopt,(int,int,int,const void*,socklen_t)); + DECLARE_SYM(int,fcntl,(int,int,...)); + DECLARE_SYM(int,connect,(int,const struct sockaddr*,socklen_t)); + DECLARE_SYM(ssize_t,send,(int,const void*,size_t,int)); + DECLARE_SYM(ssize_t,recv,(int,const void*,size_t,int)); + DECLARE_SYM(int,select,(int,fd_set*,fd_set*,fd_set*,struct timeval*)); + DECLARE_SYM(int,poll,(struct pollfd*,POLL_NFDS_TYPE,int)); + DECLARE_SYM(int,gettimeofday,(struct timeval*,GETTIMEOFDAY_ARG2_TYPE)); +#ifdef _POSIX_MONOTONIC_CLOCK + DECLARE_SYM(int,clock_gettime,(clockid_t clk_id, struct timespec*)); +#endif +#ifdef THREADED + DECLARE_SYM(int,pthread_create,(pthread_t *, const pthread_attr_t *, + void *(*)(void *), void *)); + DECLARE_SYM(int,pthread_detach,(pthread_t)); + DECLARE_SYM(int,pthread_cond_broadcast,(pthread_cond_t *)); + DECLARE_SYM(int,pthread_cond_destroy,(pthread_cond_t *)); + DECLARE_SYM(int,pthread_cond_init,(pthread_cond_t *, const pthread_condattr_t *)); + DECLARE_SYM(int,pthread_cond_signal,(pthread_cond_t *)); + DECLARE_SYM(int,pthread_cond_timedwait,(pthread_cond_t *, + pthread_mutex_t *, const struct timespec *)); + DECLARE_SYM(int,pthread_cond_wait,(pthread_cond_t *, pthread_mutex_t *)); + DECLARE_SYM(int,pthread_join,(pthread_t, void **)); + DECLARE_SYM(int,pthread_mutex_destroy,(pthread_mutex_t *)); + DECLARE_SYM(int,pthread_mutex_init,(pthread_mutex_t *, const pthread_mutexattr_t *)); + DECLARE_SYM(int,pthread_mutex_lock,(pthread_mutex_t *)); + DECLARE_SYM(int,pthread_mutex_trylock,(pthread_mutex_t *)); + DECLARE_SYM(int,pthread_mutex_unlock,(pthread_mutex_t *)); +#endif + LibCSymTable(); + + static void* getHandle(); + static LibCSymTable& instance(); +}; + +#endif /*LIBCSYMTABLE_H_*/ diff --git a/src/c/tests/MocksBase.cc b/src/c/tests/MocksBase.cc new file mode 100644 index 00000000000..60b2c75f25b --- /dev/null +++ b/src/c/tests/MocksBase.cc @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "MocksBase.h" +#include "LibCSymTable.h" + +// ***************************************************************************** +// Mock base +void* Mock::operator new(std::size_t s){ + void* p=malloc(s); + if(!p) + throw std::bad_alloc(); + return p; +} + +void Mock::operator delete(void* p){ + LIBC_SYMBOLS.free(p); +} diff --git a/src/c/tests/MocksBase.h b/src/c/tests/MocksBase.h new file mode 100644 index 00000000000..5b54251eca0 --- /dev/null +++ b/src/c/tests/MocksBase.h @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MOCKSBASE_H_ +#define MOCKSBASE_H_ + +#include + +// ***************************************************************************** +// Mock base + +class Mock +{ +public: + virtual ~Mock(){} + + static void* operator new(std::size_t s); + static void operator delete(void* p); +}; + +#endif /*MOCKSBASE_H_*/ diff --git a/src/c/tests/PthreadMocks.cc b/src/c/tests/PthreadMocks.cc new file mode 100644 index 00000000000..490cebf3361 --- /dev/null +++ b/src/c/tests/PthreadMocks.cc @@ -0,0 +1,106 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "PthreadMocks.h" + +MockPthreadsBase* MockPthreadsBase::mock_=0; + +#undef USING_DUMA + +#ifndef USING_DUMA +int pthread_cond_broadcast (pthread_cond_t *c){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_cond_broadcast(c); + return MockPthreadsBase::mock_->pthread_cond_broadcast(c); +} +int pthread_cond_destroy (pthread_cond_t *c){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_cond_destroy(c); + return MockPthreadsBase::mock_->pthread_cond_destroy(c); +} +int pthread_cond_init (pthread_cond_t *c, const pthread_condattr_t *a){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_cond_init(c,a); + return MockPthreadsBase::mock_->pthread_cond_init(c,a); +} +int pthread_cond_signal (pthread_cond_t *c){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_cond_signal(c); + return MockPthreadsBase::mock_->pthread_cond_signal(c); +} +int pthread_cond_timedwait (pthread_cond_t *c, + pthread_mutex_t *m, const struct timespec *t){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_cond_timedwait(c,m,t); + return MockPthreadsBase::mock_->pthread_cond_timedwait(c,m,t); +} +int pthread_cond_wait (pthread_cond_t *c, pthread_mutex_t *m){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_cond_wait(c,m); + return MockPthreadsBase::mock_->pthread_cond_wait(c,m); +} +int pthread_create (pthread_t *t, const pthread_attr_t *a, + void *(*f)(void *), void *d){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_create(t,a,f,d); + return MockPthreadsBase::mock_->pthread_create(t,a,f,d); +} +int pthread_detach(pthread_t t){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_detach(t); + return MockPthreadsBase::mock_->pthread_detach(t); +} +int pthread_join (pthread_t t, void **r){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_join(t,r); + return MockPthreadsBase::mock_->pthread_join(t,r); +} +int pthread_mutex_destroy (pthread_mutex_t *m){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_mutex_destroy(m); + return MockPthreadsBase::mock_->pthread_mutex_destroy(m); +} +int pthread_mutex_init (pthread_mutex_t *m, const pthread_mutexattr_t *a){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_mutex_init(m,a); + return MockPthreadsBase::mock_->pthread_mutex_init(m,a); +} + +DECLARE_WRAPPER(int,pthread_mutex_lock,(pthread_mutex_t *m)){ + if(!MockPthreadsBase::mock_) + return CALL_REAL(pthread_mutex_lock,(m)); + return MockPthreadsBase::mock_->pthread_mutex_lock(m); +} + +int pthread_mutex_trylock (pthread_mutex_t *m){ + if(!MockPthreadsBase::mock_) + return LIBC_SYMBOLS.pthread_mutex_trylock(m); + return MockPthreadsBase::mock_->pthread_mutex_trylock(m); +} + +DECLARE_WRAPPER(int,pthread_mutex_unlock,(pthread_mutex_t *m)){ + if(!MockPthreadsBase::mock_) + return CALL_REAL(pthread_mutex_unlock,(m)); + return MockPthreadsBase::mock_->pthread_mutex_unlock(m); +} +#endif + +CheckedPthread::ThreadMap CheckedPthread::tmap_; +CheckedPthread::MutexMap CheckedPthread::mmap_; +CheckedPthread::CVMap CheckedPthread::cvmap_; +Mutex CheckedPthread::mx; diff --git a/src/c/tests/PthreadMocks.h b/src/c/tests/PthreadMocks.h new file mode 100644 index 00000000000..3584ec33015 --- /dev/null +++ b/src/c/tests/PthreadMocks.h @@ -0,0 +1,449 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PTHREADMOCKS_H_ +#define PTHREADMOCKS_H_ + +#include +#include +#include + +#include "src/zk_adaptor.h" + +#include "Util.h" +#include "MocksBase.h" +#include "LibCSymTable.h" +#include "ThreadingUtil.h" + +// an ABC for pthreads +class MockPthreadsBase: public Mock +{ +public: + MockPthreadsBase(){mock_=this;} + virtual ~MockPthreadsBase(){mock_=0;} + + virtual int pthread_create(pthread_t * t, const pthread_attr_t *a, + void *(*f)(void *), void *d) =0; + virtual int pthread_join(pthread_t t, void ** r) =0; + virtual int pthread_detach(pthread_t t) =0; + virtual int pthread_cond_broadcast(pthread_cond_t *c) =0; + virtual int pthread_cond_destroy(pthread_cond_t *c) =0; + virtual int pthread_cond_init(pthread_cond_t *c, const pthread_condattr_t *a) =0; + virtual int pthread_cond_signal(pthread_cond_t *c) =0; + virtual int pthread_cond_timedwait(pthread_cond_t *c, + pthread_mutex_t *m, const struct timespec *t) =0; + virtual int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m) =0; + virtual int pthread_mutex_destroy(pthread_mutex_t *m) =0; + virtual int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a) =0; + virtual int pthread_mutex_lock(pthread_mutex_t *m) =0; + virtual int pthread_mutex_trylock(pthread_mutex_t *m) =0; + virtual int pthread_mutex_unlock(pthread_mutex_t *m) =0; + + static MockPthreadsBase* mock_; +}; + +// all pthread functions simply return an error code +// and increment their invocation counter. No actual threads are spawned. +class MockPthreadsNull: public MockPthreadsBase +{ +public: + MockPthreadsNull(): + pthread_createReturns(0),pthread_createCounter(0), + pthread_joinReturns(0),pthread_joinCounter(0),pthread_joinResultReturn(0), + pthread_detachReturns(0),pthread_detachCounter(0), + pthread_cond_broadcastReturns(0),pthread_cond_broadcastCounter(0), + pthread_cond_destroyReturns(0),pthread_cond_destroyCounter(0), + pthread_cond_initReturns(0),pthread_cond_initCounter(0), + pthread_cond_signalReturns(0),pthread_cond_signalCounter(0), + pthread_cond_timedwaitReturns(0),pthread_cond_timedwaitCounter(0), + pthread_cond_waitReturns(0),pthread_cond_waitCounter(0), + pthread_mutex_destroyReturns(0),pthread_mutex_destroyCounter(0), + pthread_mutex_initReturns(0),pthread_mutex_initCounter(0), + pthread_mutex_lockReturns(0),pthread_mutex_lockCounter(0), + pthread_mutex_trylockReturns(0),pthread_mutex_trylockCounter(0), + pthread_mutex_unlockReturns(0),pthread_mutex_unlockCounter(0) + { + memset(threads,0,sizeof(threads)); + } + + short threads[512]; + + int pthread_createReturns; + int pthread_createCounter; + virtual int pthread_create(pthread_t * t, const pthread_attr_t *a, + void *(*f)(void *), void *d){ + char* p=(char*)&threads[pthread_createCounter++]; + p[0]='i'; // mark as created + *t=(pthread_t)p; + return pthread_createReturns; + } + int pthread_joinReturns; + int pthread_joinCounter; + void* pthread_joinResultReturn; + virtual int pthread_join(pthread_t t, void ** r){ + pthread_joinCounter++; + if(r!=0) + *r=pthread_joinResultReturn; + char* p=(char*)t; + p[0]='x';p[1]+=1; + return pthread_joinReturns; + } + int pthread_detachReturns; + int pthread_detachCounter; + virtual int pthread_detach(pthread_t t){ + pthread_detachCounter++; + char* p=(char*)t; + p[0]='x';p[1]+=1; + return pthread_detachReturns; + } + + template + static bool isInitialized(const T& t){ + return ((char*)t)[0]=='i'; + } + template + static bool isDestroyed(const T& t){ + return ((char*)t)[0]=='x'; + } + template + static int getDestroyCounter(const T& t){ + return ((char*)t)[1]; + } + template + static int getInvalidAccessCounter(const T& t){ + return ((char*)t)[2]; + } + int pthread_cond_broadcastReturns; + int pthread_cond_broadcastCounter; + virtual int pthread_cond_broadcast(pthread_cond_t *c){ + pthread_cond_broadcastCounter++; + if(isDestroyed(c))((char*)c)[2]++; + return pthread_cond_broadcastReturns; + } + int pthread_cond_destroyReturns; + int pthread_cond_destroyCounter; + virtual int pthread_cond_destroy(pthread_cond_t *c){ + pthread_cond_destroyCounter++; + char* p=(char*)c; + p[0]='x';p[1]+=1; + return pthread_cond_destroyReturns; + } + int pthread_cond_initReturns; + int pthread_cond_initCounter; + virtual int pthread_cond_init(pthread_cond_t *c, const pthread_condattr_t *a){ + pthread_cond_initCounter++; + char* p=(char*)c; + p[0]='i'; // mark as created + p[1]=0; // destruction counter + p[2]=0; // access after destruction counter + return pthread_cond_initReturns; + } + int pthread_cond_signalReturns; + int pthread_cond_signalCounter; + virtual int pthread_cond_signal(pthread_cond_t *c){ + pthread_cond_signalCounter++; + if(isDestroyed(c))((char*)c)[2]++; + return pthread_cond_signalReturns; + } + int pthread_cond_timedwaitReturns; + int pthread_cond_timedwaitCounter; + virtual int pthread_cond_timedwait(pthread_cond_t *c, + pthread_mutex_t *m, const struct timespec *t){ + pthread_cond_timedwaitCounter++; + if(isDestroyed(c))((char*)c)[2]++; + return pthread_cond_timedwaitReturns; + } + int pthread_cond_waitReturns; + int pthread_cond_waitCounter; + virtual int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m){ + pthread_cond_waitCounter++; + if(isDestroyed(c))((char*)c)[2]++; + return pthread_cond_waitReturns; + } + int pthread_mutex_destroyReturns; + int pthread_mutex_destroyCounter; + virtual int pthread_mutex_destroy(pthread_mutex_t *m){ + pthread_mutex_destroyCounter++; + char* p=(char*)m; + p[0]='x';p[1]+=1; + return pthread_mutex_destroyReturns; + } + int pthread_mutex_initReturns; + int pthread_mutex_initCounter; + virtual int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a){ + pthread_mutex_initCounter++; + char* p=(char*)m; + p[0]='i'; // mark as created + p[1]=0; // destruction counter + p[2]=0; // access after destruction counter + return pthread_mutex_initReturns; + } + int pthread_mutex_lockReturns; + int pthread_mutex_lockCounter; + virtual int pthread_mutex_lock(pthread_mutex_t *m){ + pthread_mutex_lockCounter++; + if(isDestroyed(m))((char*)m)[2]++; + return pthread_mutex_lockReturns; + } + int pthread_mutex_trylockReturns; + int pthread_mutex_trylockCounter; + virtual int pthread_mutex_trylock(pthread_mutex_t *m){ + pthread_mutex_trylockCounter++; + if(isDestroyed(m))((char*)m)[2]++; + return pthread_mutex_trylockReturns; + } + int pthread_mutex_unlockReturns; + int pthread_mutex_unlockCounter; + virtual int pthread_mutex_unlock(pthread_mutex_t *m){ + pthread_mutex_unlockCounter++; + if(isDestroyed(m))((char*)m)[2]++; + return pthread_mutex_unlockReturns; + } +}; + +// simulates the way zookeeper threads make use of api_prolog/epilog and +// +class MockPthreadZKNull: public MockPthreadsNull +{ + typedef std::map Map; + Map map_; +public: + virtual int pthread_create(pthread_t * t, const pthread_attr_t *a, + void *(*f)(void *), void *d){ + int ret=MockPthreadsNull::pthread_create(t,a,f,d); + zhandle_t* zh=(zhandle_t*)d; + adaptor_threads* ad=(adaptor_threads*)zh->adaptor_priv; + api_prolog(zh); + ad->threadsToWait--; + putValue(map_,*t,zh); + return ret; + } + virtual int pthread_join(pthread_t t, void ** r){ + zhandle_t* zh=0; + if(getValue(map_,t,zh)) + api_epilog(zh,0); + return MockPthreadsNull::pthread_join(t,r); + } +}; + +struct ThreadInfo{ + typedef enum {RUNNING,TERMINATED} ThreadState; + + ThreadInfo(): + destructionCounter_(0),invalidAccessCounter_(0),state_(RUNNING) + { + } + + ThreadInfo& incDestroyed() { + destructionCounter_++; + return *this; + } + ThreadInfo& incInvalidAccess(){ + invalidAccessCounter_++; + return *this; + } + ThreadInfo& setTerminated(){ + state_=TERMINATED; + return *this; + } + int destructionCounter_; + int invalidAccessCounter_; + ThreadState state_; +}; + +class CheckedPthread: public MockPthreadsBase +{ + // first => destruction counter + // second => invalid access counter + //typedef std::pair Entry; + typedef ThreadInfo Entry; + typedef std::map ThreadMap; + static ThreadMap tmap_; + static ThreadMap& getMap(const TypeOp::BareT&){return tmap_;} + typedef std::map MutexMap; + static MutexMap mmap_; + static MutexMap& getMap(const TypeOp::BareT&){return mmap_;} + typedef std::map CVMap; + static CVMap cvmap_; + static CVMap& getMap(const TypeOp::BareT&){return cvmap_;} + + static Mutex mx; + + template + static void markDestroyed(T& t){ + typedef typename TypeOp::BareT Type; + Entry e; + synchronized(mx); + if(getValue(getMap(Type()),t,e)){ + putValue(getMap(Type()),t,Entry(e).incDestroyed()); + }else{ + putValue(getMap(Type()),t,Entry().incDestroyed()); + } + } + template + static void markCreated(T& t){ + typedef typename TypeOp::BareT Type; + Entry e; + synchronized(mx); + if(!getValue(getMap(Type()),t,e)) + putValue(getMap(Type()),t,Entry()); + } + template + static void checkAccessed(T& t){ + typedef typename TypeOp::BareT Type; + Entry e; + synchronized(mx); + if(getValue(getMap(Type()),t,e) && e.destructionCounter_>0) + putValue(getMap(Type()),t,Entry(e).incInvalidAccess()); + } + static void setTerminated(pthread_t t){ + Entry e; + synchronized(mx); + if(getValue(tmap_,t,e)) + putValue(tmap_,t,Entry(e).setTerminated()); + } +public: + bool verbose; + CheckedPthread():verbose(false){ + tmap_.clear(); + mmap_.clear(); + cvmap_.clear(); + mx.release(); + } + template + static bool isInitialized(const T& t){ + typedef typename TypeOp::BareT Type; + Entry e; + synchronized(mx); + return getValue(getMap(Type()),t,e) && e.destructionCounter_==0; + } + template + static bool isDestroyed(const T& t){ + typedef typename TypeOp::BareT Type; + Entry e; + synchronized(mx); + return getValue(getMap(Type()),t,e) && e.destructionCounter_>0; + } + static bool isTerminated(pthread_t t){ + Entry e; + synchronized(mx); + return getValue(tmap_,t,e) && e.state_==ThreadInfo::TERMINATED; + } + template + static int getDestroyCounter(const T& t){ + typedef typename TypeOp::BareT Type; + Entry e; + synchronized(mx); + return getValue(getMap(Type()),t,e)?e.destructionCounter_:-1; + } + template + static int getInvalidAccessCounter(const T& t){ + typedef typename TypeOp::BareT Type; + Entry e; + synchronized(mx); + return getValue(getMap(Type()),t,e)?e.invalidAccessCounter_:-1; + } + + struct ThreadContext{ + typedef void *(*ThreadFunc)(void *); + + ThreadContext(ThreadFunc func,void* param):func_(func),param_(param){} + ThreadFunc func_; + void* param_; + }; + static void* threadFuncWrapper(void* v){ + ThreadContext* ctx=(ThreadContext*)v; + pthread_t t=pthread_self(); + markCreated(t); + void* res=ctx->func_(ctx->param_); + setTerminated(pthread_self()); + delete ctx; + return res; + } + virtual int pthread_create(pthread_t * t, const pthread_attr_t *a, + void *(*f)(void *), void *d) + { + int ret=LIBC_SYMBOLS.pthread_create(t,a,threadFuncWrapper, + new ThreadContext(f,d)); + if(verbose) + TEST_TRACE("thread created %p",*t); + return ret; + } + virtual int pthread_join(pthread_t t, void ** r){ + if(verbose) TEST_TRACE("thread joined %p",t); + int ret=LIBC_SYMBOLS.pthread_join(t,r); + if(ret==0) + markDestroyed(t); + return ret; + } + virtual int pthread_detach(pthread_t t){ + if(verbose) TEST_TRACE("thread detached %p",t); + int ret=LIBC_SYMBOLS.pthread_detach(t); + if(ret==0) + markDestroyed(t); + return ret; + } + virtual int pthread_cond_broadcast(pthread_cond_t *c){ + checkAccessed(c); + return LIBC_SYMBOLS.pthread_cond_broadcast(c); + } + virtual int pthread_cond_destroy(pthread_cond_t *c){ + markDestroyed(c); + return LIBC_SYMBOLS.pthread_cond_destroy(c); + } + virtual int pthread_cond_init(pthread_cond_t *c, const pthread_condattr_t *a){ + markCreated(c); + return LIBC_SYMBOLS.pthread_cond_init(c,a); + } + virtual int pthread_cond_signal(pthread_cond_t *c){ + checkAccessed(c); + return LIBC_SYMBOLS.pthread_cond_signal(c); + } + virtual int pthread_cond_timedwait(pthread_cond_t *c, + pthread_mutex_t *m, const struct timespec *t){ + checkAccessed(c); + return LIBC_SYMBOLS.pthread_cond_timedwait(c,m,t); + } + virtual int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m){ + checkAccessed(c); + return LIBC_SYMBOLS.pthread_cond_wait(c,m); + } + virtual int pthread_mutex_destroy(pthread_mutex_t *m){ + markDestroyed(m); + return LIBC_SYMBOLS.pthread_mutex_destroy(m); + } + virtual int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a){ + markCreated(m); + return LIBC_SYMBOLS.pthread_mutex_init(m,a); + } + virtual int pthread_mutex_lock(pthread_mutex_t *m){ + checkAccessed(m); + return LIBC_SYMBOLS.pthread_mutex_lock(m); + } + virtual int pthread_mutex_trylock(pthread_mutex_t *m){ + checkAccessed(m); + return LIBC_SYMBOLS.pthread_mutex_trylock(m); + } + virtual int pthread_mutex_unlock(pthread_mutex_t *m){ + checkAccessed(m); + return LIBC_SYMBOLS.pthread_mutex_unlock(m); + } +}; + +#endif /*PTHREADMOCKS_H_*/ + diff --git a/src/c/tests/TestClient.cc b/src/c/tests/TestClient.cc new file mode 100644 index 00000000000..3fbcb1b6080 --- /dev/null +++ b/src/c/tests/TestClient.cc @@ -0,0 +1,1397 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "CppAssertHelper.h" + +#include +#include +#include +#include + +#include "CollectionUtil.h" +#include "ThreadingUtil.h" + +using namespace Util; + +#include "Vector.h" +using namespace std; + +#include +#include + +#include +#include +#include +#include "Util.h" +#include "ZKMocks.h" + +struct buff_struct_2 { + int32_t len; + int32_t off; + char *buffer; +}; + +// For testing LogMessage Callback functionality +list logMessages; +void logMessageHandler(const char* message) { + cout << "Log Message Received: [" << message << "]" << endl; + logMessages.push_back(message); +} + +static int Stat_eq(struct Stat* a, struct Stat* b) +{ + if (a->czxid != b->czxid) return 0; + if (a->mzxid != b->mzxid) return 0; + if (a->ctime != b->ctime) return 0; + if (a->mtime != b->mtime) return 0; + if (a->version != b->version) return 0; + if (a->cversion != b->cversion) return 0; + if (a->aversion != b->aversion) return 0; + if (a->ephemeralOwner != b->ephemeralOwner) return 0; + if (a->dataLength != b->dataLength) return 0; + if (a->numChildren != b->numChildren) return 0; + if (a->pzxid != b->pzxid) return 0; + return 1; +} +#ifdef THREADED + static void yield(zhandle_t *zh, int i) + { + sleep(i); + } +#else + static void yield(zhandle_t *zh, int seconds) + { + int fd; + int interest; + int events; + struct timeval tv; + int rc; + time_t expires = time(0) + seconds; + time_t timeLeft = seconds; + fd_set rfds, wfds, efds; + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + + while(timeLeft >= 0) { + zookeeper_interest(zh, &fd, &interest, &tv); + if (fd != -1) { + if (interest&ZOOKEEPER_READ) { + FD_SET(fd, &rfds); + } else { + FD_CLR(fd, &rfds); + } + if (interest&ZOOKEEPER_WRITE) { + FD_SET(fd, &wfds); + } else { + FD_CLR(fd, &wfds); + } + } else { + fd = 0; + } + FD_SET(0, &rfds); + if (tv.tv_sec > timeLeft) { + tv.tv_sec = timeLeft; + } + rc = select(fd+1, &rfds, &wfds, &efds, &tv); + timeLeft = expires - time(0); + events = 0; + if (FD_ISSET(fd, &rfds)) { + events |= ZOOKEEPER_READ; + } + if (FD_ISSET(fd, &wfds)) { + events |= ZOOKEEPER_WRITE; + } + zookeeper_process(zh, events); + } + } +#endif + +typedef struct evt { + string path; + int type; +} evt_t; + +typedef struct watchCtx { +private: + list events; + watchCtx(const watchCtx&); + watchCtx& operator=(const watchCtx&); +public: + bool connected; + zhandle_t *zh; + Mutex mutex; + + watchCtx() { + connected = false; + zh = 0; + } + ~watchCtx() { + if (zh) { + zookeeper_close(zh); + zh = 0; + } + } + + evt_t getEvent() { + evt_t evt; + mutex.acquire(); + CPPUNIT_ASSERT( events.size() > 0); + evt = events.front(); + events.pop_front(); + mutex.release(); + return evt; + } + + int countEvents() { + int count; + mutex.acquire(); + count = events.size(); + mutex.release(); + return count; + } + + void putEvent(evt_t evt) { + mutex.acquire(); + events.push_back(evt); + mutex.release(); + } + + bool waitForConnected(zhandle_t *zh) { + time_t expires = time(0) + 10; + while(!connected && time(0) < expires) { + yield(zh, 1); + } + return connected; + } + + bool waitForDisconnected(zhandle_t *zh) { + time_t expires = time(0) + 15; + while(connected && time(0) < expires) { + yield(zh, 1); + } + return !connected; + } + +} watchctx_t; + +class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_simpleSystem); + CPPUNIT_TEST(testLogCallbackSet); + CPPUNIT_TEST(testLogCallbackInit); + CPPUNIT_TEST(testLogCallbackClear); + CPPUNIT_TEST(testAsyncWatcherAutoReset); + CPPUNIT_TEST(testDeserializeString); + CPPUNIT_TEST(testFirstServerDown); +#ifdef THREADED + CPPUNIT_TEST(testNullData); +#ifdef ZOO_IPV6_ENABLED + CPPUNIT_TEST(testIPV6); +#endif + CPPUNIT_TEST(testCreate); + CPPUNIT_TEST(testPath); + CPPUNIT_TEST(testPathValidation); + CPPUNIT_TEST(testPing); + CPPUNIT_TEST(testAcl); + CPPUNIT_TEST(testChroot); + CPPUNIT_TEST(testAuth); + CPPUNIT_TEST(testHangingClient); + CPPUNIT_TEST(testWatcherAutoResetWithGlobal); + CPPUNIT_TEST(testWatcherAutoResetWithLocal); + CPPUNIT_TEST(testGetChildren2); + CPPUNIT_TEST(testLastZxid); + CPPUNIT_TEST(testRemoveWatchers); +#endif + CPPUNIT_TEST_SUITE_END(); + + static void watcher(zhandle_t *, int type, int state, const char *path,void*v){ + watchctx_t *ctx = (watchctx_t*)v; + + if (state == ZOO_CONNECTED_STATE) { + ctx->connected = true; + } else { + ctx->connected = false; + } + if (type != ZOO_SESSION_EVENT) { + evt_t evt; + evt.path = path; + evt.type = type; + ctx->putEvent(evt); + } + } + + static const char hostPorts[]; + + const char *getHostPorts() { + return hostPorts; + } + + zhandle_t *createClient(watchctx_t *ctx) { + return createClient(hostPorts, ctx); + } + + zhandle_t *createClient(watchctx_t *ctx, log_callback_fn logCallback) { + zhandle_t *zk = zookeeper_init2(hostPorts, watcher, 10000, 0, ctx, 0, logCallback); + ctx->zh = zk; + sleep(1); + return zk; + } + + zhandle_t *createClient(const char *hp, watchctx_t *ctx) { + zhandle_t *zk = zookeeper_init(hp, watcher, 10000, 0, ctx, 0); + ctx->zh = zk; + sleep(1); + return zk; + } + + zhandle_t *createchClient(watchctx_t *ctx, const char* chroot) { + zhandle_t *zk = zookeeper_init(chroot, watcher, 10000, 0, ctx, 0); + ctx->zh = zk; + sleep(1); + return zk; + } + + FILE *logfile; +public: + + Zookeeper_simpleSystem() { + logfile = openlogfile("Zookeeper_simpleSystem"); + } + + ~Zookeeper_simpleSystem() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + } + + void startServer() { + char cmd[1024]; + sprintf(cmd, "%s start %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + void stopServer() { + char cmd[1024]; + sprintf(cmd, "%s stop %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + void tearDown() + { + } + + /** have a callback in the default watcher **/ + static void default_zoo_watcher(zhandle_t *zzh, int type, int state, const char *path, void *context){ + int zrc = 0; + struct String_vector str_vec = {0, NULL}; + zrc = zoo_wget_children(zzh, "/mytest", default_zoo_watcher, NULL, &str_vec); + } + + /** ZOOKEEPER-1057 This checks that the client connects to the second server when the first is not reachable **/ + void testFirstServerDown() { + watchctx_t ctx; + + zoo_deterministic_conn_order(true); + + zhandle_t* zk = createClient("127.0.0.1:22182,127.0.0.1:22181", &ctx); + CPPUNIT_ASSERT(zk != 0); + CPPUNIT_ASSERT(ctx.waitForConnected(zk)); + } + + /** this checks for a deadlock in calling zookeeper_close and calls from a default watcher that might get triggered just when zookeeper_close() is in progress **/ + void testHangingClient() { + int zrc = 0; + char buff[10] = "testall"; + char path[512]; + watchctx_t *ctx; + struct String_vector str_vec = {0, NULL}; + zhandle_t *zh = zookeeper_init(hostPorts, NULL, 10000, 0, ctx, 0); + sleep(1); + zrc = zoo_create(zh, "/mytest", buff, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, 512); + zrc = zoo_wget_children(zh, "/mytest", default_zoo_watcher, NULL, &str_vec); + zrc = zoo_create(zh, "/mytest/test1", buff, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, 512); + zrc = zoo_wget_children(zh, "/mytest", default_zoo_watcher, NULL, &str_vec); + zrc = zoo_delete(zh, "/mytest/test1", -1); + zookeeper_close(zh); + } + + void testBadDescriptor() { + int zrc = 0; + watchctx_t *ctx; + zhandle_t *zh = zookeeper_init(hostPorts, NULL, 10000, 0, ctx, 0); + sleep(1); + zh->io_count = 0; + //close socket + close(zh->fd); + sleep(1); + //Check that doIo isn't spinning + CPPUNIT_ASSERT(zh->io_count < 2); + zookeeper_close(zh); + } + + + void testPing() + { + watchctx_t ctxIdle; + watchctx_t ctxWC; + zhandle_t *zkIdle = createClient(&ctxIdle); + zhandle_t *zkWatchCreator = createClient(&ctxWC); + + CPPUNIT_ASSERT(zkIdle); + CPPUNIT_ASSERT(zkWatchCreator); + + char path[80]; + sprintf(path, "/testping"); + int rc = zoo_create(zkWatchCreator, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + for(int i = 0; i < 30; i++) { + sprintf(path, "/testping/%i", i); + rc = zoo_create(zkWatchCreator, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + for(int i = 0; i < 30; i++) { + sprintf(path, "/testping/%i", i); + struct Stat stat; + rc = zoo_exists(zkIdle, path, 1, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + for(int i = 0; i < 30; i++) { + sprintf(path, "/testping/%i", i); + usleep(500000); + rc = zoo_delete(zkWatchCreator, path, -1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + struct Stat stat; + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, zoo_exists(zkIdle, "/testping/0", 0, &stat)); + } + + bool waitForEvent(zhandle_t *zh, watchctx_t *ctx, int seconds) { + time_t expires = time(0) + seconds; + while(ctx->countEvents() == 0 && time(0) < expires) { + yield(zh, 1); + } + return ctx->countEvents() > 0; + } + +#define COUNT 100 + + static zhandle_t *async_zk; + static volatile int count; + static const char* hp_chroot; + + static void statCompletion(int rc, const struct Stat *stat, const void *data) { + int tmp = (int) (long) data; + CPPUNIT_ASSERT_EQUAL(tmp, rc); + } + + static void stringCompletion(int rc, const char *value, const void *data) { + char *path = (char*)data; + + if (rc == ZCONNECTIONLOSS && path) { + // Try again + rc = zoo_acreate(async_zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, 0); + } else if (rc != ZOK) { + // fprintf(stderr, "rc = %d with path = %s\n", rc, (path ? path : "null")); + } + if (path) { + free(path); + } + } + + static void stringStatCompletion(int rc, const char *value, const struct Stat *stat, + const void *data) { + stringCompletion(rc, value, data); + CPPUNIT_ASSERT(stat != 0); + } + + static void create_completion_fn(int rc, const char* value, const void *data) { + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + count++; + } + + static void waitForCreateCompletion(int seconds) { + time_t expires = time(0) + seconds; + while(count == 0 && time(0) < expires) { + sleep(1); + } + count--; + } + + static void watcher_chroot_fn(zhandle_t *zh, int type, + int state, const char *path,void *watcherCtx) { + // check for path + char *client_path = (char *) watcherCtx; + CPPUNIT_ASSERT(strcmp(client_path, path) == 0); + count ++; + } + + static void waitForChrootWatch(int seconds) { + time_t expires = time(0) + seconds; + while (count == 0 && time(0) < expires) { + sleep(1); + } + count--; + } + + static void waitForVoidCompletion(int seconds) { + time_t expires = time(0) + seconds; + while(count == 0 && time(0) < expires) { + sleep(1); + } + count--; + } + + static void voidCompletion(int rc, const void *data) { + int tmp = (int) (long) data; + CPPUNIT_ASSERT_EQUAL(tmp, rc); + count++; + } + + static void verifyCreateFails(const char *path, zhandle_t *zk) { + CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk, + path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0)); + } + + static void verifyCreateOk(const char *path, zhandle_t *zk) { + CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk, + path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0)); + } + + static void verifyCreateFailsSeq(const char *path, zhandle_t *zk) { + CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk, + path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0)); + } + + static void verifyCreateOkSeq(const char *path, zhandle_t *zk) { + CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk, + path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0)); + } + + + /** + returns false if the vectors dont match + **/ + bool compareAcl(struct ACL_vector acl1, struct ACL_vector acl2) { + if (acl1.count != acl2.count) { + return false; + } + struct ACL *aclval1 = acl1.data; + struct ACL *aclval2 = acl2.data; + if (aclval1->perms != aclval2->perms) { + return false; + } + struct Id id1 = aclval1->id; + struct Id id2 = aclval2->id; + if (strcmp(id1.scheme, id2.scheme) != 0) { + return false; + } + if (strcmp(id1.id, id2.id) != 0) { + return false; + } + return true; + } + + void testDeserializeString() { + char *val_str; + int rc = 0; + int val = -1; + struct iarchive *ia; + struct buff_struct_2 *b; + struct oarchive *oa = create_buffer_oarchive(); + oa->serialize_Int(oa, "int", &val); + b = (struct buff_struct_2 *) oa->priv; + ia = create_buffer_iarchive(b->buffer, b->len); + rc = ia->deserialize_String(ia, "string", &val_str); + CPPUNIT_ASSERT_EQUAL(-EINVAL, rc); + } + + void testAcl() { + int rc; + struct ACL_vector aclvec; + struct Stat stat; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + rc = zoo_create(zk, "/acl", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_get_acl(zk, "/acl", &aclvec, &stat ); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + bool cmp = compareAcl(ZOO_OPEN_ACL_UNSAFE, aclvec); + CPPUNIT_ASSERT_EQUAL(true, cmp); + rc = zoo_set_acl(zk, "/acl", -1, &ZOO_READ_ACL_UNSAFE); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_get_acl(zk, "/acl", &aclvec, &stat); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + cmp = compareAcl(ZOO_READ_ACL_UNSAFE, aclvec); + CPPUNIT_ASSERT_EQUAL(true, cmp); + } + + + void testAuth() { + int rc; + count = 0; + watchctx_t ctx1, ctx2, ctx3, ctx4, ctx5; + zhandle_t *zk = createClient(&ctx1); + struct ACL_vector nodeAcl; + struct ACL acl_val; + rc = zoo_add_auth(0, "", 0, 0, voidCompletion, (void*)-1); + CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc); + + rc = zoo_add_auth(zk, 0, 0, 0, voidCompletion, (void*)-1); + CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc); + + // auth as pat, create /tauth1, close session + rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion, + (void*)ZOK); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + waitForVoidCompletion(3); + CPPUNIT_ASSERT(count == 0); + + rc = zoo_create(zk, "/tauth1", "", 0, &ZOO_CREATOR_ALL_ACL, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + { + //create a new client + zk = createClient(&ctx4); + rc = zoo_add_auth(zk, "digest", "", 0, voidCompletion, (void*)ZOK); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + waitForVoidCompletion(3); + CPPUNIT_ASSERT(count == 0); + + rc = zoo_add_auth(zk, "digest", "", 0, voidCompletion, (void*)ZOK); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + waitForVoidCompletion(3); + CPPUNIT_ASSERT(count == 0); + } + + //create a new client + zk = createClient(&ctx2); + + rc = zoo_add_auth(zk, "digest", "pat:passwd2", 11, voidCompletion, + (void*)ZOK); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + waitForVoidCompletion(3); + CPPUNIT_ASSERT(count == 0); + + char buf[1024]; + int blen = sizeof(buf); + struct Stat stat; + rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZNOAUTH, rc); + // add auth pat w/correct pass verify success + rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion, + (void*)ZOK); + + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + waitForVoidCompletion(3); + CPPUNIT_ASSERT(count == 0); + //create a new client + zk = createClient(&ctx3); + rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion, (void*) ZOK); + waitForVoidCompletion(3); + CPPUNIT_ASSERT(count == 0); + rc = zoo_add_auth(zk, "ip", "none", 4, voidCompletion, (void*)ZOK); + //make the server forget the auths + waitForVoidCompletion(3); + CPPUNIT_ASSERT(count == 0); + + stopServer(); + CPPUNIT_ASSERT(ctx3.waitForDisconnected(zk)); + startServer(); + CPPUNIT_ASSERT(ctx3.waitForConnected(zk)); + // now try getting the data + rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + // also check for get + rc = zoo_get_acl(zk, "/", &nodeAcl, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + // check if the acl has all the perms + CPPUNIT_ASSERT_EQUAL((int)1, (int)nodeAcl.count); + acl_val = *(nodeAcl.data); + CPPUNIT_ASSERT_EQUAL((int) acl_val.perms, ZOO_PERM_ALL); + // verify on root node + rc = zoo_set_acl(zk, "/", -1, &ZOO_CREATOR_ALL_ACL); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + + rc = zoo_set_acl(zk, "/", -1, &ZOO_OPEN_ACL_UNSAFE); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + + //[ZOOKEEPER-1108], test that auth info is sent to server, if client is not + //connected to server when zoo_add_auth was called. + zhandle_t *zk_auth = zookeeper_init(hostPorts, NULL, 10000, 0, NULL, 0); + rc = zoo_add_auth(zk_auth, "digest", "pat:passwd", 10, voidCompletion, (void*)ZOK); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + sleep(2); + CPPUNIT_ASSERT(count == 1); + count = 0; + CPPUNIT_ASSERT_EQUAL((int) ZOK, zookeeper_close(zk_auth)); + + // [ZOOKEEPER-800] zoo_add_auth should return ZINVALIDSTATE if + // the connection is closed. + zhandle_t *zk2 = zookeeper_init(hostPorts, NULL, 10000, 0, NULL, 0); + sleep(1); + CPPUNIT_ASSERT_EQUAL((int) ZOK, zookeeper_close(zk2)); + CPPUNIT_ASSERT_EQUAL(0, zoo_state(zk2)); // 0 ==> ZOO_CLOSED_STATE + rc = zoo_add_auth(zk2, "digest", "pat:passwd", 10, voidCompletion, (void*)ZOK); + CPPUNIT_ASSERT_EQUAL((int) ZINVALIDSTATE, rc); + + struct sockaddr addr; + socklen_t addr_len = sizeof(addr); + zk = createClient(&ctx5); + stopServer(); + CPPUNIT_ASSERT(ctx5.waitForDisconnected(zk)); + CPPUNIT_ASSERT(zookeeper_get_connected_host(zk, &addr, &addr_len) == NULL); + addr_len = sizeof(addr); + startServer(); + CPPUNIT_ASSERT(ctx5.waitForConnected(zk)); + CPPUNIT_ASSERT(zookeeper_get_connected_host(zk, &addr, &addr_len) != NULL); + } + + void testCreate() { + watchctx_t ctx; + int rc = 0; + zhandle_t *zk = createClient(&ctx); + CPPUNIT_ASSERT(zk); + char pathbuf[80]; + + struct Stat stat_a = {0}; + struct Stat stat_b = {0}; + rc = zoo_create2(zk, "/testcreateA", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, sizeof(pathbuf), &stat_a); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT(strcmp(pathbuf, "/testcreateA") == 0); + CPPUNIT_ASSERT(stat_a.czxid > 0); + CPPUNIT_ASSERT(stat_a.mtime > 0); + + rc = zoo_create2(zk, "/testcreateB", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, sizeof(pathbuf), &stat_b); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT(strcmp(pathbuf, "/testcreateB") == 0); + CPPUNIT_ASSERT(stat_b.czxid > 0); + CPPUNIT_ASSERT(stat_b.mtime > 0); + + // Should get different Stats back from different creates + CPPUNIT_ASSERT(Stat_eq(&stat_a, &stat_b) != 1); + } + + void testGetChildren2() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + + rc = zoo_create(zk, "/parent", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + rc = zoo_create(zk, "/parent/child_a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + rc = zoo_create(zk, "/parent/child_b", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + rc = zoo_create(zk, "/parent/child_c", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + rc = zoo_create(zk, "/parent/child_d", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + struct String_vector strings; + struct Stat stat_a, stat_b; + + rc = zoo_get_children2(zk, "/parent", 0, &strings, &stat_a); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + rc = zoo_exists(zk, "/parent", 0, &stat_b); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + CPPUNIT_ASSERT(Stat_eq(&stat_a, &stat_b)); + CPPUNIT_ASSERT(stat_a.numChildren == 4); + } + + void testIPV6() { + watchctx_t ctx; + zhandle_t *zk = createClient("::1:22181", &ctx); + CPPUNIT_ASSERT(zk); + int rc = 0; + rc = zoo_create(zk, "/ipv6", NULL, -1, + &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + } + + void testNullData() { + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + CPPUNIT_ASSERT(zk); + int rc = 0; + rc = zoo_create(zk, "/mahadev", NULL, -1, + &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + char buffer[512]; + struct Stat stat; + int len = 512; + rc = zoo_wget(zk, "/mahadev", NULL, NULL, buffer, &len, &stat); + CPPUNIT_ASSERT_EQUAL( -1, len); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_set(zk, "/mahadev", NULL, -1, -1); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_wget(zk, "/mahadev", NULL, NULL, buffer, &len, &stat); + CPPUNIT_ASSERT_EQUAL( -1, len); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + } + + void testPath() { + watchctx_t ctx; + char pathbuf[20]; + zhandle_t *zk = createClient(&ctx); + CPPUNIT_ASSERT(zk); + int rc = 0; + + memset(pathbuf, 'X', 20); + rc = zoo_create(zk, "/testpathpath0", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT_EQUAL('X', pathbuf[0]); + + rc = zoo_create(zk, "/testpathpath1", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 1); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT(strlen(pathbuf) == 0); + + rc = zoo_create(zk, "/testpathpath2", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 2); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT(strcmp(pathbuf, "/") == 0); + + rc = zoo_create(zk, "/testpathpath3", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 3); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT(strcmp(pathbuf, "/t") == 0); + + rc = zoo_create(zk, "/testpathpath7", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 15); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath7") == 0); + + rc = zoo_create(zk, "/testpathpath8", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 16); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath8") == 0); + } + + void testPathValidation() { + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + CPPUNIT_ASSERT(zk); + + verifyCreateFails(0, zk); + verifyCreateFails("", zk); + verifyCreateFails("//", zk); + verifyCreateFails("///", zk); + verifyCreateFails("////", zk); + verifyCreateFails("/.", zk); + verifyCreateFails("/..", zk); + verifyCreateFails("/./", zk); + verifyCreateFails("/../", zk); + verifyCreateFails("/foo/./", zk); + verifyCreateFails("/foo/../", zk); + verifyCreateFails("/foo/.", zk); + verifyCreateFails("/foo/..", zk); + verifyCreateFails("/./.", zk); + verifyCreateFails("/../..", zk); + verifyCreateFails("/foo/bar/", zk); + verifyCreateFails("/foo//bar", zk); + verifyCreateFails("/foo/bar//", zk); + + verifyCreateFails("foo", zk); + verifyCreateFails("a", zk); + + // verify that trailing fails, except for seq which adds suffix + verifyCreateOk("/createseq", zk); + verifyCreateFails("/createseq/", zk); + verifyCreateOkSeq("/createseq/", zk); + verifyCreateOkSeq("/createseq/.", zk); + verifyCreateOkSeq("/createseq/..", zk); + verifyCreateFailsSeq("/createseq//", zk); + verifyCreateFailsSeq("/createseq/./", zk); + verifyCreateFailsSeq("/createseq/../", zk); + + verifyCreateOk("/.foo", zk); + verifyCreateOk("/.f.", zk); + verifyCreateOk("/..f", zk); + verifyCreateOk("/..f..", zk); + verifyCreateOk("/f.c", zk); + verifyCreateOk("/f", zk); + verifyCreateOk("/f/.f", zk); + verifyCreateOk("/f/f.", zk); + verifyCreateOk("/f/..f", zk); + verifyCreateOk("/f/f..", zk); + verifyCreateOk("/f/.f/f", zk); + verifyCreateOk("/f/f./f", zk); + } + + void testChroot() { + // the c client async callbacks do + // not callback with the path, so + // we dont need to test taht for now + // we should fix that though soon! + watchctx_t ctx, ctx_ch; + zhandle_t *zk, *zk_ch; + char buf[60]; + int rc, len; + struct Stat stat; + const char* data = "garbage"; + const char* retStr = "/chroot"; + const char* root= "/"; + zk_ch = createchClient(&ctx_ch, "127.0.0.1:22181/testch1/mahadev"); + CPPUNIT_ASSERT(zk_ch != NULL); + zk = createClient(&ctx); + // first test with a NULL zk handle, make sure client library does not + // dereference a null pointer, but instead returns ZBADARGUMENTS + rc = zoo_create(NULL, "/testch1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc); + rc = zoo_create(zk, "/testch1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_create(zk, "/testch1/mahadev", data, 7, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + // try an exists with / + len = 60; + rc = zoo_get(zk_ch, "/", 0, buf, &len, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + //check if the data is the same + CPPUNIT_ASSERT(strncmp(buf, data, 7) == 0); + //check for watches + rc = zoo_wexists(zk_ch, "/chroot", watcher_chroot_fn, (void *) retStr, &stat); + //now check if we can do create/delete/get/sets/acls/getChildren and others + //check create + rc = zoo_create(zk_ch, "/chroot", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0,0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + waitForChrootWatch(3); + CPPUNIT_ASSERT(count == 0); + rc = zoo_create(zk_ch, "/chroot/child", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + + rc = zoo_delete(zk_ch, "/chroot/child", -1); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat); + CPPUNIT_ASSERT_EQUAL((int) ZNONODE, rc); + rc = zoo_wget(zk_ch, "/chroot", watcher_chroot_fn, (char*) retStr, + buf, &len, &stat); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_set(zk_ch, "/chroot",buf, 3, -1); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + waitForChrootWatch(3); + CPPUNIT_ASSERT(count == 0); + // check for getchildren + struct String_vector children; + rc = zoo_get_children(zk_ch, "/", 0, &children); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL((int)1, (int)children.count); + //check if te child if chroot + CPPUNIT_ASSERT(strcmp((retStr+1), children.data[0]) == 0); + // check for get/set acl + struct ACL_vector acl; + rc = zoo_get_acl(zk_ch, "/", &acl, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL((int)1, (int)acl.count); + CPPUNIT_ASSERT_EQUAL((int)ZOO_PERM_ALL, (int)acl.data->perms); + // set acl + rc = zoo_set_acl(zk_ch, "/chroot", -1, &ZOO_READ_ACL_UNSAFE); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + // see if you add children + rc = zoo_create(zk_ch, "/chroot/child1", "",0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZNOAUTH, rc); + //add wget children test + rc = zoo_wget_children(zk_ch, "/", watcher_chroot_fn, (char*) root, &children); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + //now create a node + rc = zoo_create(zk_ch, "/child2", "",0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + waitForChrootWatch(3); + CPPUNIT_ASSERT(count == 0); + //check for one async call just to make sure + rc = zoo_acreate(zk_ch, "/child3", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, + create_completion_fn, 0); + waitForCreateCompletion(3); + CPPUNIT_ASSERT(count == 0); + + //ZOOKEEPER-1027 correctly return path_buffer without prefixed chroot + const char* path = "/zookeeper1027"; + char path_buffer[1024]; + int path_buffer_len=sizeof(path_buffer); + rc = zoo_create(zk_ch, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, path_buffer, path_buffer_len); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT_EQUAL(string(path), string(path_buffer)); + } + + // Test creating normal handle via zookeeper_init then explicitly setting callback + void testLogCallbackSet() + { + watchctx_t ctx; + CPPUNIT_ASSERT(logMessages.empty()); + zhandle_t *zk = createClient(&ctx); + + zoo_set_log_callback(zk, &logMessageHandler); + CPPUNIT_ASSERT_EQUAL(zoo_get_log_callback(zk), &logMessageHandler); + + // Log 10 messages and ensure all go to callback + int expected = 10; + for (int i = 0; i < expected; i++) + { + LOG_INFO(LOGCALLBACK(zk), "%s #%d", __FUNCTION__, i); + } + CPPUNIT_ASSERT(expected == logMessages.size()); + } + + // Test creating handle via zookeeper_init2 to ensure all connection messages go to callback + void testLogCallbackInit() + { + logMessages.clear(); + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx, &logMessageHandler); + CPPUNIT_ASSERT_EQUAL(zoo_get_log_callback(zk), &logMessageHandler); + + // All the connection messages should have gone to the callback -- don't + // want this to be a maintenance issue so we're not asserting exact count + int numBefore = logMessages.size(); + CPPUNIT_ASSERT(numBefore != 0); + + // Log 10 messages and ensure all go to callback + int expected = 10; + for (int i = 0; i < expected; i++) + { + LOG_INFO(LOGCALLBACK(zk), "%s #%d", __FUNCTION__, i); + } + CPPUNIT_ASSERT(logMessages.size() == numBefore + expected); + } + + // Test clearing log callback -- logging should resume going to logstream + void testLogCallbackClear() + { + logMessages.clear(); + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx, &logMessageHandler); + CPPUNIT_ASSERT_EQUAL(zoo_get_log_callback(zk), &logMessageHandler); + + // All the connection messages should have gone to the callback -- again, we don't + // want this to be a maintenance issue so we're not asserting exact count + int numBefore = logMessages.size(); + CPPUNIT_ASSERT(numBefore > 0); + + // Clear log_callback + zoo_set_log_callback(zk, NULL); + + // Future log messages should go to logstream not callback + LOG_INFO(LOGCALLBACK(zk), __FUNCTION__); + int numAfter = logMessages.size(); + CPPUNIT_ASSERT_EQUAL(numBefore, numAfter); + } + + void testAsyncWatcherAutoReset() + { + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + watchctx_t lctx[COUNT]; + int i; + char path[80]; + int rc; + evt_t evt; + + async_zk = zk; + for(i = 0; i < COUNT; i++) { + sprintf(path, "/awar%d", i); + rc = zoo_awexists(zk, path, watcher, &lctx[i], statCompletion, (void*)ZNONODE); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + yield(zk, 0); + + for(i = 0; i < COUNT/4; i++) { + sprintf(path, "/awar%d", i); + rc = zoo_acreate(zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, + stringCompletion, strdup(path)); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + for(i = COUNT/4; i < COUNT/2; i++) { + sprintf(path, "/awar%d", i); + rc = zoo_acreate2(zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, + stringStatCompletion, strdup(path)); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + yield(zk, 3); + for(i = 0; i < COUNT/2; i++) { + sprintf(path, "/awar%d", i); + CPPUNIT_ASSERT_MESSAGE(path, waitForEvent(zk, &lctx[i], 5)); + evt = lctx[i].getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path.c_str(), ZOO_CREATED_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string(path), evt.path); + } + + for(i = COUNT/2 + 1; i < COUNT*10; i++) { + sprintf(path, "/awar%d", i); + rc = zoo_acreate(zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, strdup(path)); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + yield(zk, 1); + stopServer(); + CPPUNIT_ASSERT(ctx.waitForDisconnected(zk)); + startServer(); + CPPUNIT_ASSERT(ctx.waitForConnected(zk)); + yield(zk, 3); + for(i = COUNT/2+1; i < COUNT; i++) { + sprintf(path, "/awar%d", i); + CPPUNIT_ASSERT_MESSAGE(path, waitForEvent(zk, &lctx[i], 5)); + evt = lctx[i].getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CREATED_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string(path), evt.path); + } + } + + void testWatcherAutoReset(zhandle_t *zk, watchctx_t *ctxGlobal, + watchctx_t *ctxLocal) + { + bool isGlobal = (ctxGlobal == ctxLocal); + int rc; + struct Stat stat; + char buf[1024]; + int blen; + struct String_vector strings; + const char *testName; + + rc = zoo_create(zk, "/watchtest", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_create(zk, "/watchtest/child", "", 0, + &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + if (isGlobal) { + testName = "GlobalTest"; + rc = zoo_get_children(zk, "/watchtest", 1, &strings); + deallocate_String_vector(&strings); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + blen = sizeof(buf); + rc = zoo_get(zk, "/watchtest/child", 1, buf, &blen, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_exists(zk, "/watchtest/child2", 1, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + } else { + testName = "LocalTest"; + rc = zoo_wget_children(zk, "/watchtest", watcher, ctxLocal, + &strings); + deallocate_String_vector(&strings); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + blen = sizeof(buf); + rc = zoo_wget(zk, "/watchtest/child", watcher, ctxLocal, + buf, &blen, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_wexists(zk, "/watchtest/child2", watcher, ctxLocal, + &stat); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + } + + CPPUNIT_ASSERT(ctxLocal->countEvents() == 0); + + stopServer(); + CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk)); + startServer(); + CPPUNIT_ASSERT_MESSAGE(testName, ctxLocal->waitForConnected(zk)); + + CPPUNIT_ASSERT(ctxLocal->countEvents() == 0); + + rc = zoo_set(zk, "/watchtest/child", "1", 1, -1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + struct Stat stat1, stat2; + rc = zoo_set2(zk, "/watchtest/child", "1", 1, -1, &stat1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT(stat1.version >= 0); + rc = zoo_set2(zk, "/watchtest/child", "1", 1, stat1.version, &stat2); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_set(zk, "/watchtest/child", "1", 1, stat2.version); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_create(zk, "/watchtest/child2", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5)); + + evt_t evt = ctxLocal->getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHANGED_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path); + + CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5)); + // The create will trigget the get children and the + // exists watches + evt = ctxLocal->getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CREATED_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string("/watchtest/child2"), evt.path); + CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5)); + evt = ctxLocal->getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHILD_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string("/watchtest"), evt.path); + + // Make sure Pings are giving us problems + sleep(5); + + CPPUNIT_ASSERT(ctxLocal->countEvents() == 0); + + stopServer(); + CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk)); + startServer(); + CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForConnected(zk)); + + if (isGlobal) { + testName = "GlobalTest"; + rc = zoo_get_children(zk, "/watchtest", 1, &strings); + deallocate_String_vector(&strings); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + blen = sizeof(buf); + rc = zoo_get(zk, "/watchtest/child", 1, buf, &blen, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_exists(zk, "/watchtest/child2", 1, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } else { + testName = "LocalTest"; + rc = zoo_wget_children(zk, "/watchtest", watcher, ctxLocal, + &strings); + deallocate_String_vector(&strings); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + blen = sizeof(buf); + rc = zoo_wget(zk, "/watchtest/child", watcher, ctxLocal, + buf, &blen, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_wexists(zk, "/watchtest/child2", watcher, ctxLocal, + &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + zoo_delete(zk, "/watchtest/child2", -1); + + CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5)); + + evt = ctxLocal->getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string("/watchtest/child2"), evt.path); + + CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5)); + evt = ctxLocal->getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHILD_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string("/watchtest"), evt.path); + + stopServer(); + CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk)); + startServer(); + CPPUNIT_ASSERT_MESSAGE(testName, ctxLocal->waitForConnected(zk)); + + zoo_delete(zk, "/watchtest/child", -1); + zoo_delete(zk, "/watchtest", -1); + + CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5)); + + evt = ctxLocal->getEvent(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type); + CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path); + + // Make sure nothing is straggling + sleep(1); + CPPUNIT_ASSERT(ctxLocal->countEvents() == 0); + } + + void testWatcherAutoResetWithGlobal() + { + { + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int rc = zoo_create(zk, "/testarwg", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_create(zk, "/testarwg/arwg", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + } + + { + watchctx_t ctx; + zhandle_t *zk = createchClient(&ctx, "127.0.0.1:22181/testarwg/arwg"); + + testWatcherAutoReset(zk, &ctx, &ctx); + } + } + + void testWatcherAutoResetWithLocal() + { + { + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int rc = zoo_create(zk, "/testarwl", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + rc = zoo_create(zk, "/testarwl/arwl", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + } + + { + watchctx_t ctx; + watchctx_t lctx; + zhandle_t *zk = createchClient(&ctx, "127.0.0.1:22181/testarwl/arwl"); + testWatcherAutoReset(zk, &ctx, &lctx); + } + } + + void testLastZxid() { + // ZOOKEEPER-1417: Test that c-client only update last zxid upon + // receiving request response only. + const int timeout = 5000; + int rc; + watchctx_t ctx1, ctx2; + zhandle_t *zk1 = createClient(&ctx1); + zhandle_t *zk2 = createClient(&ctx2); + CPPUNIT_ASSERT(zk1); + CPPUNIT_ASSERT(zk2); + + int64_t original = zk2->last_zxid; + + // Create txn to increase system zxid + rc = zoo_create(zk1, "/lastzxid", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + // This should be enough time for zk2 to receive ping request + usleep(timeout/2 * 1000); + + // check that zk1's last zxid is updated + struct Stat stat; + rc = zoo_exists(zk1, "/lastzxid", 0, &stat); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + CPPUNIT_ASSERT_EQUAL((int64_t) zk1->last_zxid, stat.czxid); + // zk2's last zxid should remain the same + CPPUNIT_ASSERT_EQUAL(original, (int64_t) zk2->last_zxid); + + // Perform read and also register a watch + rc = zoo_wexists(zk2, "/lastzxid", watcher, &ctx2, &stat); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + int64_t updated = zk2->last_zxid; + // check that zk2's last zxid is updated + CPPUNIT_ASSERT_EQUAL(updated, stat.czxid); + + // Increment system zxid again + rc = zoo_set(zk1, "/lastzxid", NULL, -1, -1); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + + // Wait for zk2 to get watch event + CPPUNIT_ASSERT(waitForEvent(zk2, &ctx2, 5)); + // zk2's last zxid should remain the same + CPPUNIT_ASSERT_EQUAL(updated, (int64_t) zk2->last_zxid); + } + + static void watcher_remove_watchers(zhandle_t *zh, int type, + int state, const char *path,void *watcherCtx) { + count++; + } + + void testRemoveWatchers() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + CPPUNIT_ASSERT(zk); + + count = 0; + + rc = zoo_create(zk, "/something", "", 0, + &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + char buf[1024]; + int blen = sizeof(buf); + rc = zoo_get(zk, "/something", 1, buf, &blen, NULL); + + /* remove all watchers */ + rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_DATA, + NULL, NULL, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + /* remove a specific watcher before it's added (should fail) */ + rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_DATA, + watcher_remove_watchers, NULL, 0); + CPPUNIT_ASSERT_EQUAL((int)ZNOWATCHER, rc); + + /* now add a specific watcher and then remove it */ + rc = zoo_wget(zk, "/something", watcher_remove_watchers, NULL, + buf, &blen, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_DATA, + watcher_remove_watchers, NULL, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + /* ditto for children watcher */ + rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_CHILDREN, + watcher_remove_watchers, NULL, 0); + CPPUNIT_ASSERT_EQUAL((int)ZNOWATCHER, rc); + + struct String_vector str_vec = {0, NULL}; + rc = zoo_wget_children(zk, "/something", watcher_remove_watchers, NULL, + &str_vec); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_CHILDREN, + watcher_remove_watchers, NULL, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + /* add a watch, stop the server, and have remove fail */ + rc = zoo_wget(zk, "/something", watcher_remove_watchers, NULL, + buf, &blen, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + stopServer(); + ctx.waitForDisconnected(zk); + rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_DATA, + watcher_remove_watchers, NULL, 0); + CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS, rc); + + /* bring the server back */ + startServer(); + zk = createClient(&ctx); + + /* add a watch, stop the server, and remove it locally */ + rc = zoo_wget(zk, "/something", watcher_remove_watchers, NULL, + buf, &blen, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + stopServer(); + rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_DATA, + watcher_remove_watchers, NULL, 1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } +}; + +volatile int Zookeeper_simpleSystem::count; +zhandle_t *Zookeeper_simpleSystem::async_zk; +const char Zookeeper_simpleSystem::hostPorts[] = "127.0.0.1:22181"; +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_simpleSystem); diff --git a/src/c/tests/TestClientRetry.cc b/src/c/tests/TestClientRetry.cc new file mode 100644 index 00000000000..c6536dc91e5 --- /dev/null +++ b/src/c/tests/TestClientRetry.cc @@ -0,0 +1,147 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "CppAssertHelper.h" + +#include +#include +#include + +#include "Vector.h" +using namespace std; + +#include + +#include "Util.h" +#include "WatchUtil.h" + +class Zookeeper_clientretry : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_clientretry); +#ifdef THREADED + CPPUNIT_TEST(testRetry); +#endif + CPPUNIT_TEST_SUITE_END(); + + static void watcher(zhandle_t *, int type, int state, const char *path,void*v){ + watchctx_t *ctx = (watchctx_t*)v; + + if (state == ZOO_CONNECTED_STATE) { + ctx->connected = true; + } else { + ctx->connected = false; + } + if (type != ZOO_SESSION_EVENT) { + evt_t evt; + evt.path = path; + evt.type = type; + ctx->putEvent(evt); + } + } + + static const char hostPorts[]; + + const char *getHostPorts() { + return hostPorts; + } + + zhandle_t *createClient(watchctx_t *ctx) { + zhandle_t *zk = zookeeper_init(hostPorts, watcher, 10000, 0, + ctx, 0); + ctx->zh = zk; + sleep(1); + return zk; + } + + FILE *logfile; +public: + + Zookeeper_clientretry() { + logfile = openlogfile("Zookeeper_clientretry"); + } + + ~Zookeeper_clientretry() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + + char cmd[1024]; + sprintf(cmd, "%s stop %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + + /* we are testing that if max cnxns is exceeded the server does the right thing */ + sprintf(cmd, "export ZKMAXCNXNS=1;%s startClean %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + + struct sigaction act; + act.sa_handler = SIG_IGN; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + CPPUNIT_ASSERT(sigaction(SIGPIPE, &act, NULL) == 0); + } + + void tearDown() + { + char cmd[1024]; + sprintf(cmd, "%s stop %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + + /* restart the server in "normal" mode */ + sprintf(cmd, "%s startClean %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + + struct sigaction act; + act.sa_handler = SIG_IGN; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + CPPUNIT_ASSERT(sigaction(SIGPIPE, &act, NULL) == 0); + } + + bool waitForEvent(zhandle_t *zh, watchctx_t *ctx, int seconds) { + time_t expires = time(0) + seconds; + while(ctx->countEvents() == 0 && time(0) < expires) { + yield(zh, 1); + } + return ctx->countEvents() > 0; + } + + static zhandle_t *async_zk; + + void testRetry() + { + watchctx_t ctx1, ctx2; + zhandle_t *zk1 = createClient(&ctx1); + CPPUNIT_ASSERT_EQUAL(true, ctx1.waitForConnected(zk1)); + zhandle_t *zk2 = createClient(&ctx2); + zookeeper_close(zk1); + CPPUNIT_ASSERT_EQUAL(true, ctx2.waitForConnected(zk2)); + ctx1.zh = 0; + } +}; + +zhandle_t *Zookeeper_clientretry::async_zk; +const char Zookeeper_clientretry::hostPorts[] = "127.0.0.1:22181"; +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_clientretry); diff --git a/src/c/tests/TestDriver.cc b/src/c/tests/TestDriver.cc new file mode 100644 index 00000000000..3f32ba483c4 --- /dev/null +++ b/src/c/tests/TestDriver.cc @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Util.h" +#include "zookeeper_log.h" + +using namespace std; + +CPPUNIT_NS_BEGIN + +class EclipseOutputter: public CompilerOutputter +{ +public: + EclipseOutputter(TestResultCollector *result,ostream &stream): + CompilerOutputter(result,stream,"%p:%l: "),stream_(stream) + { + } + virtual void printFailedTestName( TestFailure *failure ){} + virtual void printFailureMessage( TestFailure *failure ) + { + stream_<<": "; + Message msg = failure->thrownException()->message(); + stream_<< msg.shortDescription(); + + string text; + for(int i=0; i the output must be in the compiler error format. + //bool selfTest = (argc > 1) && (std::string("-ide") == argv[1]); + globalTestConfig.addConfigFromCmdLine(argc,argv); + + ZKServer zkserver; + + // Create the event manager and test controller + CPPUNIT_NS::TestResult controller; + // Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); + + // A listener that print dots as tests run. + // CPPUNIT_NS::TextTestProgressListener progress; + // CPPUNIT_NS::BriefTestProgressListener progress; + + // brief + elapsed time + TimingListener progress; + controller.addListener( &progress ); + + CPPUNIT_NS::TestRunner runner; + runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); + + try { + CPPUNIT_NS::stdCOut() << "Running " << endl; + + zoo_set_debug_level(ZOO_LOG_LEVEL_INFO); + //zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG); + + runner.run( controller, globalTestConfig.getTestName()); + + // Print test in a compiler compatible format. + CPPUNIT_NS::EclipseOutputter outputter( &result,cout); + outputter.write(); + + // Uncomment this for XML output +#ifdef ENABLE_XML_OUTPUT + std::ofstream file( "tests.xml" ); + CPPUNIT_NS::XmlOutputter xml( &result, file ); + xml.setStyleSheet( "report.xsl" ); + xml.write(); + file.close(); +#endif + } catch ( std::invalid_argument &e ) { + // Test path not resolved + cout<<"\nERROR: "< +#include "CppAssertHelper.h" + +#include +#include +#include +#include + +#include "CollectionUtil.h" +#include "ThreadingUtil.h" + +using namespace Util; + +#include "Vector.h" +using namespace std; + +#include +#include + +#include +#include +#include +#include "Util.h" + +#ifdef THREADED + static void yield(zhandle_t *zh, int i) + { + sleep(i); + } +#else + static void yield(zhandle_t *zh, int seconds) + { + int fd; + int interest; + int events; + struct timeval tv; + int rc; + time_t expires = time(0) + seconds; + time_t timeLeft = seconds; + fd_set rfds, wfds, efds; + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + + while(timeLeft >= 0) { + zookeeper_interest(zh, &fd, &interest, &tv); + if (fd != -1) { + if (interest&ZOOKEEPER_READ) { + FD_SET(fd, &rfds); + } else { + FD_CLR(fd, &rfds); + } + if (interest&ZOOKEEPER_WRITE) { + FD_SET(fd, &wfds); + } else { + FD_CLR(fd, &wfds); + } + } else { + fd = 0; + } + FD_SET(0, &rfds); + if (tv.tv_sec > timeLeft) { + tv.tv_sec = timeLeft; + } + rc = select(fd+1, &rfds, &wfds, &efds, &tv); + timeLeft = expires - time(0); + events = 0; + if (FD_ISSET(fd, &rfds)) { + events |= ZOOKEEPER_READ; + } + if (FD_ISSET(fd, &wfds)) { + events |= ZOOKEEPER_WRITE; + } + zookeeper_process(zh, events); + } + } +#endif + +typedef struct evt { + string path; + int type; +} evt_t; + +typedef struct watchCtx { +private: + list events; + watchCtx(const watchCtx&); + watchCtx& operator=(const watchCtx&); +public: + bool connected; + zhandle_t *zh; + Mutex mutex; + + watchCtx() { + connected = false; + zh = 0; + } + ~watchCtx() { + if (zh) { + zookeeper_close(zh); + zh = 0; + } + } + + evt_t getEvent() { + evt_t evt; + mutex.acquire(); + CPPUNIT_ASSERT( events.size() > 0); + evt = events.front(); + events.pop_front(); + mutex.release(); + return evt; + } + + int countEvents() { + int count; + mutex.acquire(); + count = events.size(); + mutex.release(); + return count; + } + + void putEvent(evt_t evt) { + mutex.acquire(); + events.push_back(evt); + mutex.release(); + } + + bool waitForConnected(zhandle_t *zh) { + time_t expires = time(0) + 10; + while(!connected && time(0) < expires) { + yield(zh, 1); + } + return connected; + } + bool waitForDisconnected(zhandle_t *zh) { + time_t expires = time(0) + 15; + while(connected && time(0) < expires) { + yield(zh, 1); + } + return !connected; + } +} watchctx_t; + +class Zookeeper_multi : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_multi); +//FIXME: None of these tests pass in single-threaded mode. It seems to be a +//flaw in the test suite setup. +#ifdef THREADED + CPPUNIT_TEST(testCreate); + CPPUNIT_TEST(testCreateDelete); + CPPUNIT_TEST(testInvalidVersion); + CPPUNIT_TEST(testNestedCreate); + CPPUNIT_TEST(testSetData); + CPPUNIT_TEST(testUpdateConflict); + CPPUNIT_TEST(testDeleteUpdateConflict); + CPPUNIT_TEST(testAsyncMulti); + CPPUNIT_TEST(testMultiFail); + CPPUNIT_TEST(testCheck); + CPPUNIT_TEST(testWatch); + CPPUNIT_TEST(testSequentialNodeCreateInAsyncMulti); +#endif + CPPUNIT_TEST_SUITE_END(); + + static void watcher(zhandle_t *, int type, int state, const char *path,void*v){ + watchctx_t *ctx = (watchctx_t*)v; + + if (state == ZOO_CONNECTED_STATE) { + ctx->connected = true; + } else { + ctx->connected = false; + } + if (type != ZOO_SESSION_EVENT) { + evt_t evt; + evt.path = path; + evt.type = type; + ctx->putEvent(evt); + } + } + + static const char hostPorts[]; + + const char *getHostPorts() { + return hostPorts; + } + + zhandle_t *createClient(watchctx_t *ctx) { + return createClient(hostPorts, ctx); + } + + zhandle_t *createClient(const char *hp, watchctx_t *ctx) { + zhandle_t *zk = zookeeper_init(hp, watcher, 10000, 0, ctx, 0); + ctx->zh = zk; + CPPUNIT_ASSERT_EQUAL(true, ctx->waitForConnected(zk)); + return zk; + } + + FILE *logfile; +public: + + Zookeeper_multi() { + logfile = openlogfile("Zookeeper_multi"); + } + + ~Zookeeper_multi() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + } + + void tearDown() + { + } + + static volatile int count; + + static void multi_completion_fn(int rc, const void *data) { + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + count++; + } + + static void multi_completion_fn_no_assert(int rc, const void *data) { + count++; + } + + static void waitForMultiCompletion(int seconds) { + time_t expires = time(0) + seconds; + while(count == 0 && time(0) < expires) { + sleep(1); + } + count--; + } + + static void resetCounter() { + count = 0; + } + + /** + * Test basic multi-op create functionality + */ + void testCreate() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + + int sz = 512; + char p1[sz]; + char p2[sz]; + char p3[sz]; + p1[0] = p2[0] = p3[0] = '\0'; + + int nops = 3 ; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_create_op_init(&ops[1], "/multi1/a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p2, sz); + zoo_create_op_init(&ops[2], "/multi1/b", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p3, sz); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + CPPUNIT_ASSERT(strcmp(p1, "/multi1") == 0); + CPPUNIT_ASSERT(strcmp(p2, "/multi1/a") == 0); + CPPUNIT_ASSERT(strcmp(p3, "/multi1/b") == 0); + + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[1].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[2].err); + } + + /** + * Test create followed by delete + */ + void testCreateDelete() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int sz = 512; + char p1[sz]; + p1[0] = '\0'; + int nops = 2 ; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi2", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_delete_op_init(&ops[1], "/multi2", 0); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + // '/multi2' should have been deleted + rc = zoo_exists(zk, "/multi2", 0, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + } + + /** + * Test invalid versions + */ + void testInvalidVersion() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int nops = 4; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi3", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, NULL, 0); + zoo_delete_op_init(&ops[1], "/multi3", 1); + zoo_create_op_init(&ops[2], "/multi3", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, NULL, 0); + zoo_create_op_init(&ops[3], "/multi3/a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, NULL, 0); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZBADVERSION, rc); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0].err); + CPPUNIT_ASSERT_EQUAL((int)ZBADVERSION, results[1].err); + CPPUNIT_ASSERT_EQUAL((int)ZRUNTIMEINCONSISTENCY, results[2].err); + CPPUNIT_ASSERT_EQUAL((int)ZRUNTIMEINCONSISTENCY, results[3].err); + } + + /** + * Test nested creates that rely on state in earlier op in multi + */ + void testNestedCreate() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int sz = 512; + char p1[sz]; + p1[0] = '\0'; + int nops = 6; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + /* Create */ + zoo_create_op_init(&ops[0], "/multi4", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_create_op_init(&ops[1], "/multi4/a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_create_op_init(&ops[2], "/multi4/a/1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + + /* Delete */ + zoo_delete_op_init(&ops[3], "/multi4/a/1", 0); + zoo_delete_op_init(&ops[4], "/multi4/a", 0); + zoo_delete_op_init(&ops[5], "/multi4", 0); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + // Verify tree deleted + rc = zoo_exists(zk, "/multi4/a/1", 0, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + + rc = zoo_exists(zk, "/multi4/a", 0, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + + rc = zoo_exists(zk, "/multi4", 0, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + } + + /** + * Test setdata functionality + */ + void testSetData() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int sz = 512; + struct Stat s1; + + char buf[sz]; + int blen = sz ; + + char p1[sz], p2[sz]; + + int nops = 2; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi5", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_create_op_init(&ops[1], "/multi5/a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p2, sz); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + yield(zk, 5); + + zoo_op_t setdata_ops[nops]; + zoo_op_result_t setdata_results[nops]; + + zoo_set_op_init(&setdata_ops[0], "/multi5", "1", 1, 0, &s1); + zoo_set_op_init(&setdata_ops[1], "/multi5/a", "2", 1, 0, &s1); + + rc = zoo_multi(zk, nops, setdata_ops, setdata_results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[1].err); + + memset(buf, '\0', blen); + rc = zoo_get(zk, "/multi5", 0, buf, &blen, &s1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL(1, blen); + CPPUNIT_ASSERT(strcmp("1", buf) == 0); + + memset(buf, '\0', blen); + rc = zoo_get(zk, "/multi5/a", 0, buf, &blen, &s1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL(1, blen); + CPPUNIT_ASSERT(strcmp("2", buf) == 0); + } + + /** + * Test update conflicts + */ + void testUpdateConflict() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int sz = 512; + char buf[sz]; + int blen = sz; + char p1[sz]; + p1[0] = '\0'; + struct Stat s1; + int nops = 3; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi6", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_set_op_init(&ops[1], "/multi6", "X", 1, 0, &s1); + zoo_set_op_init(&ops[2], "/multi6", "Y", 1, 0, &s1); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZBADVERSION, rc); + + //Updating version solves conflict -- order matters + ops[2].set_op.version = 1; + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + memset(buf, 0, sz); + rc = zoo_get(zk, "/multi6", 0, buf, &blen, &s1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL(blen, 1); + CPPUNIT_ASSERT(strncmp(buf, "Y", 1) == 0); + } + + /** + * Test delete-update conflicts + */ + void testDeleteUpdateConflict() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int sz = 512; + char buf[sz]; + int blen; + char p1[sz]; + p1[0] = '\0'; + struct Stat stat; + int nops = 3; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi7", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_delete_op_init(&ops[1], "/multi7", 0); + zoo_set_op_init(&ops[2], "/multi7", "Y", 1, 0, &stat); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + + // '/multi' should never have been created as entire op should fail + rc = zoo_exists(zk, "/multi7", 0, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + } + + void testAsyncMulti() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + + int sz = 512; + char p1[sz], p2[sz], p3[sz]; + p1[0] = '\0'; + p2[0] = '\0'; + p3[0] = '\0'; + + int nops = 3; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi8", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_create_op_init(&ops[1], "/multi8/a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p2, sz); + zoo_create_op_init(&ops[2], "/multi8/b", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p3, sz); + + rc = zoo_amulti(zk, nops, ops, results, multi_completion_fn, 0); + waitForMultiCompletion(10); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + CPPUNIT_ASSERT(strcmp(p1, "/multi8") == 0); + CPPUNIT_ASSERT(strcmp(p2, "/multi8/a") == 0); + CPPUNIT_ASSERT(strcmp(p3, "/multi8/b") == 0); + + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[1].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[2].err); + } + + void testMultiFail() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + + int sz = 512; + char p1[sz], p2[sz], p3[sz]; + + p1[0] = '\0'; + p2[0] = '\0'; + p3[0] = '\0'; + + int nops = 3; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_create_op_init(&ops[0], "/multi9", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + zoo_create_op_init(&ops[1], "/multi9", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p2, sz); + zoo_create_op_init(&ops[2], "/multi9/b", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p3, sz); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZNODEEXISTS, rc); + } + + /** + * Test basic multi-op check functionality + */ + void testCheck() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int sz = 512; + char p1[sz]; + p1[0] = '\0'; + struct Stat s1; + + rc = zoo_create(zk, "/multi0", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + // Conditionally create /multi0/a' only if '/multi0' at version 0 + int nops = 2; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_check_op_init(&ops[0], "/multi0", 0); + zoo_create_op_init(&ops[1], "/multi0/a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[1].err); + + // '/multi0/a' should have been created as it passed version check + rc = zoo_exists(zk, "/multi0/a", 0, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + // Only create '/multi0/b' if '/multi0' at version 10 (which it's not) + zoo_op_t ops2[nops]; + zoo_check_op_init(&ops2[0], "/multi0", 10); + zoo_create_op_init(&ops2[1], "/multi0/b", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, p1, sz); + + rc = zoo_multi(zk, nops, ops2, results); + CPPUNIT_ASSERT_EQUAL((int)ZBADVERSION, rc); + + CPPUNIT_ASSERT_EQUAL((int)ZBADVERSION, results[0].err); + CPPUNIT_ASSERT_EQUAL((int)ZRUNTIMEINCONSISTENCY, results[1].err); + + // '/multi0/b' should NOT have been created + rc = zoo_exists(zk, "/multi0/b", 0, NULL); + CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc); + } + + /** + * Do a multi op inside a watch callback context. + */ + static void doMultiInWatch(zhandle_t *zk, int type, int state, const char *path, void *ctx) { + int rc; + int sz = 512; + char p1[sz]; + p1[0] = '\0'; + struct Stat s1; + + int nops = 1; + zoo_op_t ops[nops]; + zoo_op_result_t results[nops]; + + zoo_set_op_init(&ops[0], "/multiwatch", "1", 1, -1, NULL); + + rc = zoo_multi(zk, nops, ops, results); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0].err); + + memset(p1, '\0', sz); + rc = zoo_get(zk, "/multiwatch", 0, p1, &sz, &s1); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + CPPUNIT_ASSERT_EQUAL(1, sz); + CPPUNIT_ASSERT(strcmp("1", p1) == 0); + count++; + } + + /** + * Test multi-op called from a watch + */ + void testWatch() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + int sz = 512; + char p1[sz]; + p1[0] = '\0'; + + rc = zoo_create(zk, "/multiwatch", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, NULL, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + + // create a watch on node '/multiwatch' + rc = zoo_wget(zk, "/multiwatch", doMultiInWatch, &ctx, p1, &sz, NULL); + + // setdata on node '/multiwatch' this should trip the watch + rc = zoo_set(zk, "/multiwatch", NULL, -1, -1); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + + // wait for multi completion in doMultiInWatch + waitForMultiCompletion(5); + } + + /** + * ZOOKEEPER-1624: PendingChanges of create sequential node request didn't + * get rollbacked correctly when multi-op failed. This caused + * create sequential node request in subsequent multi-op to failed because + * sequential node name generation is incorrect. + * + * The check is to make sure that each request in multi-op failed with + * the correct reason. + */ + void testSequentialNodeCreateInAsyncMulti() { + int rc; + watchctx_t ctx; + zhandle_t *zk = createClient(&ctx); + + int iteration = 4; + int nops = 2; + + zoo_op_result_t results[iteration][nops]; + zoo_op_t ops[nops]; + zoo_create_op_init(&ops[0], "/node-", "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, NULL, 0); + zoo_create_op_init(&ops[1], "/dup", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, NULL, 0); + for (int i = 0; i < iteration ; ++i) { + rc = zoo_amulti(zk, nops, ops, results[i], multi_completion_fn_no_assert, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + waitForMultiCompletion(10); + + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0][0].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[1][0].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[2][0].err); + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[3][0].err); + + CPPUNIT_ASSERT_EQUAL((int)ZOK, results[0][1].err); + CPPUNIT_ASSERT_EQUAL((int)ZNODEEXISTS, results[1][1].err); + CPPUNIT_ASSERT_EQUAL((int)ZNODEEXISTS, results[2][1].err); + CPPUNIT_ASSERT_EQUAL((int)ZNODEEXISTS, results[3][1].err); + + resetCounter(); + } +}; + +volatile int Zookeeper_multi::count; +const char Zookeeper_multi::hostPorts[] = "127.0.0.1:22181"; +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_multi); diff --git a/src/c/tests/TestOperations.cc b/src/c/tests/TestOperations.cc new file mode 100644 index 00000000000..b8a4b3f8946 --- /dev/null +++ b/src/c/tests/TestOperations.cc @@ -0,0 +1,710 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "CppAssertHelper.h" + +#include "ZKMocks.h" +#include + +using namespace std; + +class Zookeeper_operations : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_operations); +#ifndef THREADED + CPPUNIT_TEST(testPing); + CPPUNIT_TEST(testUnsolicitedPing); + CPPUNIT_TEST(testTimeoutCausedByWatches1); + CPPUNIT_TEST(testTimeoutCausedByWatches2); +#else + CPPUNIT_TEST(testAsyncWatcher1); + CPPUNIT_TEST(testAsyncGetOperation); +#endif + CPPUNIT_TEST(testOperationsAndDisconnectConcurrently1); + CPPUNIT_TEST(testOperationsAndDisconnectConcurrently2); + CPPUNIT_TEST(testConcurrentOperations1); + CPPUNIT_TEST_SUITE_END(); + zhandle_t *zh; + FILE *logfile; + + static void watcher(zhandle_t *, int, int, const char *,void*){} +public: + Zookeeper_operations() { + logfile = openlogfile("Zookeeper_operations"); + } + + ~Zookeeper_operations() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + + zoo_deterministic_conn_order(0); + zh=0; + } + + void tearDown() + { + zookeeper_close(zh); + } + + class AsyncGetOperationCompletion: public AsyncCompletion{ + public: + AsyncGetOperationCompletion():called_(false),rc_(ZAPIERROR){} + virtual void dataCompl(int rc, const char *value, int len, const Stat *stat){ + synchronized(mx_); + called_=true; + rc_=rc; + value_.erase(); + if(rc!=ZOK) return; + value_.assign(value,len); + if(stat) + stat_=*stat; + } + bool operator()()const{ + synchronized(mx_); + return called_; + } + mutable Mutex mx_; + bool called_; + int rc_; + string value_; + NodeStat stat_; + }; +#ifndef THREADED + // send two get data requests; verify that the corresponding completions called + void testConcurrentOperations1() + { + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + int fd=0; + int interest=0; + timeval tv; + // first operation + AsyncGetOperationCompletion res1; + zkServer.addOperationResponse(new ZooGetResponse("1",1)); + int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // second operation + AsyncGetOperationCompletion res2; + zkServer.addOperationResponse(new ZooGetResponse("2",1)); + rc=zoo_aget(zh,"/x/y/2",0,asyncCompletion,&res2); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // process the send queue + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + while((rc=zookeeper_process(zh,interest))==ZOK) { + millisleep(100); + //printf("%d\n", rc); + } + //printf("RC = %d", rc); + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + CPPUNIT_ASSERT_EQUAL((int)ZOK,res1.rc_); + CPPUNIT_ASSERT_EQUAL(string("1"),res1.value_); + CPPUNIT_ASSERT_EQUAL((int)ZOK,res2.rc_); + CPPUNIT_ASSERT_EQUAL(string("2"),res2.value_); + } + // send two getData requests and disconnect while the second request is + // outstanding; + // verify the completions are called + void testOperationsAndDisconnectConcurrently1() + { + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + int fd=0; + int interest=0; + timeval tv; + // first operation + AsyncGetOperationCompletion res1; + zkServer.addOperationResponse(new ZooGetResponse("1",1)); + int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // second operation + AsyncGetOperationCompletion res2; + zkServer.addOperationResponse(new ZooGetResponse("2",1)); + rc=zoo_aget(zh,"/x/y/2",0,asyncCompletion,&res2); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // process the send queue + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // simulate a disconnect + zkServer.setConnectionLost(); + rc=zookeeper_interest(zh,&fd,&interest,&tv); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc); + CPPUNIT_ASSERT_EQUAL((int)ZOK,res1.rc_); + CPPUNIT_ASSERT_EQUAL(string("1"),res1.value_); + CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,res2.rc_); + CPPUNIT_ASSERT_EQUAL(string(""),res2.value_); + } + // send two getData requests and simulate timeout while the both request + // are pending; + // verify the completions are called + void testOperationsAndDisconnectConcurrently2() + { + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + int fd=0; + int interest=0; + timeval tv; + // first operation + AsyncGetOperationCompletion res1; + zkServer.addOperationResponse(new ZooGetResponse("1",1)); + int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // second operation + AsyncGetOperationCompletion res2; + zkServer.addOperationResponse(new ZooGetResponse("2",1)); + rc=zoo_aget(zh,"/x/y/2",0,asyncCompletion,&res2); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // simulate timeout + timeMock.tick(+10); // advance system time by 10 secs + // the next call to zookeeper_interest should return ZOPERATIONTIMEOUT + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOPERATIONTIMEOUT,rc); + // make sure the completions have been called + CPPUNIT_ASSERT_EQUAL((int)ZOPERATIONTIMEOUT,res1.rc_); + CPPUNIT_ASSERT_EQUAL((int)ZOPERATIONTIMEOUT,res2.rc_); + } + + class PingCountingServer: public ZookeeperServer{ + public: + PingCountingServer():pingCount_(0){} + // called when a client request is received + virtual void onMessageReceived(const RequestHeader& rh, iarchive* ia){ + if(rh.type==ZOO_PING_OP){ + pingCount_++; + } + } + int pingCount_; + }; + + // establish a connection; idle for a while + // verify ping was sent at least once + void testPing() + { + const int TIMEOUT=9; // timeout in secs + Mock_gettimeofday timeMock; + PingCountingServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + // receive timeout is in milliseconds + zh=zookeeper_init("localhost:1234",watcher,TIMEOUT*1000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + int fd=0; + int interest=0; + timeval tv; + // Round 1. + int rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // simulate waiting for the select() call to timeout; + // advance the system clock accordingly + timeMock.tick(tv); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + // verify no ping sent + CPPUNIT_ASSERT(zkServer.pingCount_==0); + + // Round 2. + // the client should have the idle threshold exceeded, by now + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // assume the socket is writable, so no idling here; move on to + // zookeeper_process immediately + rc=zookeeper_process(zh,interest); + // ZNOTHING means the client hasn't received a ping response yet + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + // verify a ping is sent + CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_); + + // Round 3. + // we're going to receive a server PING response and make sure + // that the client has updated its last_recv timestamp + zkServer.addRecvResponse(new PingResponse); + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // pseudo-sleep for a short while (10 ms) + timeMock.millitick(10); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // only one ping so far? + CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_); + CPPUNIT_ASSERT(timeMock==zh->last_recv); + + // Round 4 + // make sure that a ping is not sent if something is outstanding + AsyncGetOperationCompletion res1; + rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + timeMock.tick(tv); + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // pseudo-sleep for a short while (10 ms) + timeMock.millitick(10); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + // only one ping so far? + CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_); + } + + // ZOOKEEPER-2253: Permit unsolicited pings + void testUnsolicitedPing() + { + const int TIMEOUT=9; // timeout in secs + Mock_gettimeofday timeMock; + PingCountingServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + // receive timeout is in milliseconds + zh=zookeeper_init("localhost:1234",watcher,TIMEOUT*1000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + int fd=0; + int interest=0; + timeval tv; + + int rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // verify no ping sent + CPPUNIT_ASSERT(zkServer.pingCount_==0); + + // we're going to receive a unsolicited PING response; ensure + // that the client has updated its last_recv timestamp + timeMock.tick(tv); + zkServer.addRecvResponse(new PingResponse); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT(timeMock==zh->last_recv); + } + + // simulate a watch arriving right before a ping is due + // assert the ping is sent nevertheless + void testTimeoutCausedByWatches1() + { + const int TIMEOUT=9; // timeout in secs + Mock_gettimeofday timeMock; + PingCountingServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + // receive timeout is in milliseconds + zh=zookeeper_init("localhost:1234",watcher,TIMEOUT*1000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + int fd=0; + int interest=0; + timeval tv; + // Round 1. + int rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // simulate waiting for the select() call to timeout; + // advance the system clock accordingly + timeMock.tick(tv); + timeMock.tick(-1); // set the clock to a millisecond before a ping is due + // trigger a watch now + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/x/y/z")); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // arrival of a watch sets the last_recv to the current time + CPPUNIT_ASSERT(timeMock==zh->last_recv); + // spend 1 millisecond by processing the watch + timeMock.tick(1); + + // Round 2. + // a ping is due; zookeeper_interest() must send it now + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // no delay here -- as if the socket is immediately writable + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + // verify a ping is sent + CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_); + } + + // similar to testTimeoutCausedByWatches1, but this time the watch is + // triggered while the client has an outstanding request + // assert the ping is sent on time + void testTimeoutCausedByWatches2() + { + const int TIMEOUT=9; // timeout in secs + Mock_gettimeofday now; + PingCountingServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + // receive timeout is in milliseconds + zh=zookeeper_init("localhost:1234",watcher,TIMEOUT*1000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + // queue up a request; keep it pending (as if the server is busy or has died) + AsyncGetOperationCompletion res1; + zkServer.addOperationResponse(new ZooGetResponse("2",1)); + int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1); + + int fd=0; + int interest=0; + timeval tv; + // Round 1. + // send the queued up zoo_aget() request + Mock_gettimeofday beginningOfTimes(now); // remember when we started + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // no delay -- the socket is writable + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // Round 2. + // what's next? + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // no response from the server yet -- waiting in the select() call + now.tick(tv); + // a watch has arrived, thus preventing the connection from timing out + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/x/y/z")); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); // read the watch message + CPPUNIT_ASSERT_EQUAL(0,zkServer.pingCount_); // not yet! + + //Round 3. + // now is the time to send a ping; make sure it's actually sent + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + // verify a ping is sent + CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_); + // make sure only 1/3 of the timeout has passed + CPPUNIT_ASSERT_EQUAL((int32_t)TIMEOUT/3*1000,toMilliseconds(now-beginningOfTimes)); + } + +#else + class TestGetDataJob: public TestJob{ + public: + TestGetDataJob(ZookeeperServer* svr,zhandle_t* zh, int reps=500) + :svr_(svr),zh_(zh),rc_(ZAPIERROR),reps_(reps){} + virtual void run(){ + int i; + for(i=0;iaddOperationResponse(new ZooGetResponse("1",1)); + rc_=zoo_get(zh_,"/x/y/z",0,&buf,&size,0); + if(rc_!=ZOK){ + break; + } + } + } + ZookeeperServer* svr_; + zhandle_t* zh_; + int rc_; + int reps_; + }; + class TestConcurrentOpJob: public TestGetDataJob{ + public: + static const int REPS=500; + TestConcurrentOpJob(ZookeeperServer* svr,zhandle_t* zh): + TestGetDataJob(svr,zh,REPS){} + virtual TestJob* clone() const { + return new TestConcurrentOpJob(svr_,zh_); + } + virtual void validate(const char* file, int line) const{ + CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC("ZOK != rc",(int)ZOK,rc_,file,line); + } + }; + void testConcurrentOperations1() + { + for(int counter=0; counter<50; counter++){ + // frozen time -- no timeouts and no pings + Mock_gettimeofday timeMock; + + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + + TestJobManager jmgr(TestConcurrentOpJob(&zkServer,zh),10); + jmgr.startAllJobs(); + jmgr.wait(); + // validate test results + VALIDATE_JOBS(jmgr); + } + } + class ZKGetJob: public TestJob{ + public: + static const int REPS=1000; + ZKGetJob(zhandle_t* zh) + :zh_(zh),rc_(ZAPIERROR){} + virtual TestJob* clone() const { + return new ZKGetJob(zh_); + } + virtual void run(){ + int i; + for(i=0;i +#include "CppAssertHelper.h" + +#include +#include + +#include + +#include "Util.h" +#include "WatchUtil.h" + +class Zookeeper_readOnly : public CPPUNIT_NS::TestFixture { + CPPUNIT_TEST_SUITE(Zookeeper_readOnly); +#ifdef THREADED + CPPUNIT_TEST(testReadOnly); +#endif + CPPUNIT_TEST_SUITE_END(); + + static void watcher(zhandle_t* zh, int type, int state, + const char* path, void* v) { + watchctx_t *ctx = (watchctx_t*)v; + + if (state==ZOO_CONNECTED_STATE || state==ZOO_READONLY_STATE) { + ctx->connected = true; + } else { + ctx->connected = false; + } + if (type != ZOO_SESSION_EVENT) { + evt_t evt; + evt.path = path; + evt.type = type; + ctx->putEvent(evt); + } + } + + FILE *logfile; +public: + + Zookeeper_readOnly() { + logfile = openlogfile("Zookeeper_readOnly"); + } + + ~Zookeeper_readOnly() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() { + zoo_set_log_stream(logfile); + } + + void startReadOnly() { + char cmd[1024]; + sprintf(cmd, "%s startReadOnly", ZKSERVER_CMD); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + void stopPeer() { + char cmd[1024]; + sprintf(cmd, "%s stop", ZKSERVER_CMD); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + void testReadOnly() { + startReadOnly(); + watchctx_t watch; + zhandle_t* zh = zookeeper_init("localhost:22181", + watcher, + 10000, + NULL, + &watch, + ZOO_READONLY); + watch.zh = zh; + CPPUNIT_ASSERT(zh != 0); + sleep(1); + int len = 1024; + char buf[len]; + int res = zoo_get(zh, "/", 0, buf, &len, 0); + CPPUNIT_ASSERT_EQUAL((int)ZOK, res); + + char path[1024]; + res = zoo_create(zh, "/test", buf, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, + 512); + CPPUNIT_ASSERT_EQUAL((int)ZNOTREADONLY, res); + stopPeer(); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_readOnly); diff --git a/src/c/tests/TestReconfig.cc b/src/c/tests/TestReconfig.cc new file mode 100644 index 00000000000..056eb569628 --- /dev/null +++ b/src/c/tests/TestReconfig.cc @@ -0,0 +1,600 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Util.h" +#include "LibCMocks.h" +#include "ZKMocks.h" + +using namespace std; + +static const int portOffset = 2000; + +class Client +{ + +private: + // Member variables + zhandle_t *zh; + unsigned int seed; + +public: + /** + * Create a client with given connection host string and add to our internal + * vector of clients. These are disconnected and cleaned up in tearDown(). + */ + Client(const string hosts, unsigned int seed) : + seed((seed * seed) + 0xAFAFAFAF) + { + reSeed(); + + zh = zookeeper_init(hosts.c_str(),0,1000,0,0,0); + CPPUNIT_ASSERT(zh); + + reSeed(); + + cycleNextServer(); + } + + void close() + { + zookeeper_close(zh); + zh = NULL; + } + + bool isReconfig() + { + return zh->reconfig != 0; + } + + /** + * re-seed this client with it's own previously generated seed so its + * random choices are unique and separate from the other clients + */ + void reSeed() + { + srandom(seed); + srand48(seed); + } + + /** + * Get the server that this client is currently connected to. + */ + string getServer() + { + const char* addrstring = zoo_get_current_server(zh); + return string(addrstring); + } + + /** + * Get the server this client is currently connected to with no port + * specification. + */ + string getServerNoPort() + { + string addrstring = getServer(); + + size_t found = addrstring.find(":"); + CPPUNIT_ASSERT(found != string::npos); + + return addrstring.substr(0, found); + } + + /** + * Get the port of the server this client is currently connected to. + */ + uint32_t getServerPort() + { + string addrstring = getServer(); + + size_t found = addrstring.find(":"); + CPPUNIT_ASSERT(found != string::npos); + + string portStr = addrstring.substr(found+1); + + stringstream ss(portStr); + uint32_t port; + ss >> port; + + CPPUNIT_ASSERT(port >= portOffset); + + return port; + } + + /** + * Cycle to the next available server on the next connect attempt. It also + * calls into getServer (above) to return the server connected to. + */ + string cycleNextServer() + { + zoo_cycle_next_server(zh); + return getServer(); + } + + void cycleUntilServer(const string requested) + { + // Call cycleNextServer until the one it's connected to is the one + // specified (disregarding port). + string first; + + while(true) + { + string next = cycleNextServer(); + if (first.empty()) + { + first = next; + } + // Else we've looped around! + else if (first == next) + { + CPPUNIT_ASSERT(false); + } + + // Strip port off + string server = getServerNoPort(); + + // If it matches the requested host we're now 'connected' to the right host + if (server == requested) + { + break; + } + } + } + + /** + * Set servers for this client. + */ + void setServers(const string new_hosts) + { + int rc = zoo_set_servers(zh, new_hosts.c_str()); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + } + + /** + * Set servers for this client and validate reconfig value matches expected. + */ + void setServersAndVerifyReconfig(const string new_hosts, bool is_reconfig) + { + setServers(new_hosts); + CPPUNIT_ASSERT_EQUAL(is_reconfig, isReconfig()); + } + + /** + * Sets the server list this client is connecting to AND if this requires + * the client to be reconfigured (as dictated by internal client policy) + * then it will trigger a call to cycleNextServer. + */ + void setServersAndCycleIfNeeded(const string new_hosts) + { + setServers(new_hosts); + if (isReconfig()) + { + cycleNextServer(); + } + } +}; + +class Zookeeper_reconfig : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_reconfig); + + // Test cases + CPPUNIT_TEST(testcycleNextServer); + CPPUNIT_TEST(testMigrateOrNot); + CPPUNIT_TEST(testMigrationCycle); + + // In threaded mode each 'create' is a thread -- it's not practical to create + // 10,000 threads to test load balancing. The load balancing code can easily + // be tested in single threaded mode as concurrency doesn't affect the algorithm. +#ifndef THREADED + CPPUNIT_TEST(testMigrateProbability); + CPPUNIT_TEST(testLoadBalancing); +#endif + + CPPUNIT_TEST_SUITE_END(); + + FILE *logfile; + + double slackPercent; + static const int numClients = 10000; + static const int portOffset = 2000; + + vector clients; + vector numClientsPerHost; + +public: + Zookeeper_reconfig() : + slackPercent(10.0) + { + logfile = openlogfile("Zookeeper_reconfig"); + } + + ~Zookeeper_reconfig() + { + if (logfile) + { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + zoo_deterministic_conn_order(1); + + numClientsPerHost.resize(numClients); + } + + void tearDown() + { + for (int i = 0; i < clients.size(); i++) + { + clients.at(i).close(); + } + } + + /** + * Create a client with given connection host string and add to our internal + * vector of clients. These are disconnected and cleaned up in tearDown(). + */ + Client& createClient(const string hosts) + { + Client client(hosts, clients.size()); + clients.push_back(client); + + return clients.back(); + } + + /** + * Same as createClient(hosts) only it takes a specific host that this client + * should simulate being connected to. + */ + Client& createClient(const string hosts, const string host) + { + // Ensure requested host is in the list + size_t found = hosts.find(host); + CPPUNIT_ASSERT(found != hosts.npos); + + Client client(hosts, clients.size()); + client.cycleUntilServer(host); + clients.push_back(client); + + return clients.back(); + } + + /** + * Create a connection host list starting at 'start' and stopping at 'stop' + * where start >= stop. This creates a connection string with host:port pairs + * separated by commas. The given 'octet' is the starting octet that is used + * as the last octet in the host's IP. This is decremented on each iteration. + * Each port will be portOffset + octet. + */ + string createHostList(uint32_t start, uint32_t stop = 1, uint32_t octet = 0) + { + if (octet == 0) + { + octet = start; + } + + stringstream ss; + + for (int i = start; i >= stop; i--, octet--) + { + ss << "10.10.10." << octet << ":" << portOffset + octet; + + if (i > stop) + { + ss << ", "; + } + } + + return ss.str(); + } + + /** + * Gets the lower bound of the number of clients per server that we expect + * based on the probabilistic load balancing algorithm implemented by the + * client code. + */ + double lowerboundClientsPerServer(int numClients, int numServers) + { + return (1 - slackPercent/100.0) * numClients / numServers; + } + + /** + * Gets the upper bound of the number of clients per server that we expect + * based on the probabilistic load balancing algorithm implemented by the + * client code. + */ + double upperboundClientsPerServer(int numClients, int numServers) + { + return (1 + slackPercent/100.0) * numClients / numServers; + } + + /** + * Update all the clients to use a new list of servers. This will also cause + * the client to cycle to the next server as needed (e.g. due to a reconfig). + * It then updates the number of clients connected to the server based on + * this change. + * + * Afterwards it validates that all of the servers have the correct amount of + * clients based on the probabilistic load balancing algorithm. + */ + void updateAllClientsAndServers(int start, int stop = 1) + { + string newServers = createHostList(start, stop); + int numServers = start - stop + 1; + + for (int i = 0; i < numClients; i++) { + + Client &client = clients.at(i); + client.reSeed(); + + client.setServersAndCycleIfNeeded(newServers); + numClientsPerHost.at(client.getServerPort() - portOffset - 1)++; + } + + int offset = stop - 1; + for (int index = offset; index < numServers; index++) { + + if (numClientsPerHost.at(index) > upperboundClientsPerServer(numClients, numServers)) + { + cout << "INDEX=" << index << " too many -- actual=" << numClientsPerHost.at(index) + << " expected=" << upperboundClientsPerServer(numClients, numServers) << endl; + } + + + CPPUNIT_ASSERT(numClientsPerHost.at(index) <= upperboundClientsPerServer(numClients, numServers)); + + if (numClientsPerHost.at(index) < lowerboundClientsPerServer(numClients, numServers)) + { + cout << "INDEX=" << index << " too few -- actual=" << numClientsPerHost.at(index) + << " expected=" << lowerboundClientsPerServer(numClients, numServers) << endl; + } + + CPPUNIT_ASSERT(numClientsPerHost.at(index) >= lowerboundClientsPerServer(numClients, numServers)); + numClientsPerHost.at(index) = 0; // prepare for next test + } + } + + /*-------------------------------------------------------------------------* + * TESTCASES + *------------------------------------------------------------------------*/ + + /** + * Very basic sunny day test to ensure basic functionality of zoo_set_servers + * and zoo_cycle_next_server. + */ + void testcycleNextServer() + { + const string initial_hosts = createHostList(10); // 2010..2001 + const string new_hosts = createHostList(4); // 2004..2001 + + Client &client = createClient(initial_hosts); + + client.setServersAndVerifyReconfig(new_hosts, true); + + for (int i = 0; i < 10; i++) + { + string next = client.cycleNextServer(); + } + } + + /** + * Test the migration policy implicit within the probabilistic load balancing + * algorithm the Client implements. Tests all the corner cases whereby the + * list of servers is decreased, increased, and stays the same. Also combines + * various combinations of the currently connected server being in the new + * configuration and not. + */ + void testMigrateOrNot() + { + const string initial_hosts = createHostList(4); // 2004..2001 + + Client &client = createClient(initial_hosts, "10.10.10.3"); + + // Ensemble size decreasing, my server is in the new list + client.setServersAndVerifyReconfig(createHostList(3), false); + + // Ensemble size decreasing, my server is NOT in the new list + client.setServersAndVerifyReconfig(createHostList(2), true); + + // Ensemble size stayed the same, my server is NOT in the new list + client.setServersAndVerifyReconfig(createHostList(2), true); + + // Ensemble size increased, my server is not in the new ensemble + client.setServers(createHostList(4)); + client.cycleUntilServer("10.10.10.1"); + client.setServersAndVerifyReconfig(createHostList(7,2), true); + } + + /** + * This tests that as a client is in reconfig mode it will properly try to + * connect to all the new servers first. Then it will try to connect to all + * the 'old' servers that are staying in the new configuration. Finally it + * will fallback to the normal behavior of trying servers in round-robin. + */ + void testMigrationCycle() + { + int num_initial = 4; + const string initial_hosts = createHostList(num_initial); // {2004..2001} + + int num_new = 10; + string new_hosts = createHostList(12, 3); // {2012..2003} + + // servers from the old list that appear in the new list {2004..2003} + int num_staying = 2; + string oldStaying = createHostList(4, 3); + + // servers in the new list that are not in the old list {2012..2005} + int num_coming = 8; + string newComing = createHostList(12, 5); + + // Ensemble in increasing in size, my server is not in the new ensemble + // load on the old servers must be decreased, so must connect to one of + // new servers (pNew = 1) + Client &client = createClient(initial_hosts, "10.10.10.1"); + client.setServersAndVerifyReconfig(new_hosts, true); + + // Since we're in reconfig mode, next connect should be from new list + // We should try all the new servers *BEFORE* trying any old servers + string seen; + for (int i = 0; i < num_coming; i++) { + string next = client.cycleNextServer(); + + // Assert next server is in the 'new' list + size_t found = newComing.find(next); + CPPUNIT_ASSERT_MESSAGE(next + " not in newComing list", + found != string::npos); + + // Assert not in seen list then append + found = seen.find(next); + CPPUNIT_ASSERT_MESSAGE(next + " in seen list", + found == string::npos); + seen += found + ", "; + } + + // Now it should start connecting to the old servers + seen.clear(); + for (int i = 0; i < num_staying; i++) { + string next = client.cycleNextServer(); + + // Assert it's in the old list + size_t found = oldStaying.find(next); + CPPUNIT_ASSERT(found != string::npos); + + // Assert not in seen list then append + found = seen.find(next); + CPPUNIT_ASSERT(found == string::npos); + seen += found + ", "; + } + + // NOW it goes back to normal as we've tried all the new and old + string first = client.cycleNextServer(); + for (int i = 0; i < num_new - 1; i++) { + client.cycleNextServer(); + } + + CPPUNIT_ASSERT_EQUAL(first, client.cycleNextServer()); + } + + /** + * Test the migration probability to ensure that it conforms to our expected + * lower and upper bounds of the number of clients per server as we are + * reconfigured. + * + * In this case, the list of servers is increased and the client's server is + * in the new list. Whether to move or not depends on the difference of + * server sizes with probability 1 - |old|/|new| the client disconnects. + * + * In the test below 1-9/10 = 1/10 chance of disconnecting + */ + void testMigrateProbability() + { + const string initial_hosts = createHostList(9); // 10.10.10.9:2009...10.10.10.1:2001 + string new_hosts = createHostList(10); // 10.10.10.10:2010...10.10.10.1:2001 + + uint32_t numDisconnects = 0; + for (int i = 0; i < numClients; i++) { + Client &client = createClient(initial_hosts, "10.10.10.3"); + client.setServers(new_hosts); + if (client.isReconfig()) + { + numDisconnects++; + } + } + + // should be numClients/10 in expectation, we test that it's numClients/10 +- slackPercent + CPPUNIT_ASSERT(numDisconnects < upperboundClientsPerServer(numClients, 10)); + } + + /** + * Tests the probabilistic load balancing algorithm implemented by the Client + * code. + * + * Test strategy: + * + * (1) Start with 9 servers and 10,000 clients. Remove a server, update + * everything, and ensure that the clients are redistributed properly. + * + * (2) Remove two more nodes and repeat the same validations of proper client + * redistribution. Ensure no clients are connected to the two removed + * nodes. + * + * (3) Remove the first server in the list and simultaneously add the three + * previously removed servers. Ensure everything is redistributed and + * no clients are connected to the one missing node. + * + * (4) Add the one missing server back into the mix and validate. + */ + void testLoadBalancing() + { + zoo_deterministic_conn_order(0); + + int rc = ZOK; + + uint32_t numServers = 9; + const string initial_hosts = createHostList(numServers); // 10.10.10.9:2009...10.10.10.1:2001 + + // Create connections to servers + for (int i = 0; i < numClients; i++) { + Client &client = createClient(initial_hosts); + numClientsPerHost.at(client.getServerPort() - portOffset - 1)++; + } + + for (int i = 0; i < numServers; i++) { + CPPUNIT_ASSERT(numClientsPerHost.at(i) <= upperboundClientsPerServer(numClients, numServers)); + CPPUNIT_ASSERT(numClientsPerHost.at(i) >= lowerboundClientsPerServer(numClients, numServers)); + numClientsPerHost.at(i) = 0; // prepare for next test + } + + // remove last server + numServers = 8; + updateAllClientsAndServers(numServers); + CPPUNIT_ASSERT_EQUAL((uint32_t)0, numClientsPerHost.at(numServers)); + + // Remove two more nodes + numServers = 6; + updateAllClientsAndServers(numServers); + CPPUNIT_ASSERT_EQUAL((uint32_t)0, numClientsPerHost.at(numServers)); + CPPUNIT_ASSERT_EQUAL((uint32_t)0, numClientsPerHost.at(numServers+1)); + CPPUNIT_ASSERT_EQUAL((uint32_t)0, numClientsPerHost.at(numServers+2)); + + // remove host 0 (first one in list) and add back 6, 7, and 8 + numServers = 8; + updateAllClientsAndServers(numServers, 1); + CPPUNIT_ASSERT_EQUAL((uint32_t)0, numClientsPerHost.at(0)); + + // add back host number 0 + numServers = 9; + updateAllClientsAndServers(numServers); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_reconfig); diff --git a/src/c/tests/TestReconfigServer.cc b/src/c/tests/TestReconfigServer.cc new file mode 100644 index 00000000000..6a429ac82be --- /dev/null +++ b/src/c/tests/TestReconfigServer.cc @@ -0,0 +1,327 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +#include +#include +#include +#include "zookeeper.h" + +#include "Util.h" +#include "ZooKeeperQuorumServer.h" + +class TestReconfigServer : public CPPUNIT_NS::TestFixture { + CPPUNIT_TEST_SUITE(TestReconfigServer); +#ifdef THREADED + CPPUNIT_TEST(testNonIncremental); + CPPUNIT_TEST(testRemoveConnectedFollower); + CPPUNIT_TEST(testRemoveFollower); +#endif + CPPUNIT_TEST_SUITE_END(); + + public: + TestReconfigServer(); + virtual ~TestReconfigServer(); + void setUp(); + void tearDown(); + void testNonIncremental(); + void testRemoveConnectedFollower(); + void testRemoveFollower(); + + private: + static const uint32_t NUM_SERVERS; + FILE* logfile_; + std::vector cluster_; + int32_t getLeader(); + std::vector getFollowers(); + void parseConfig(char* buf, int len, std::vector& servers, + std::string& version); + bool waitForConnected(zhandle_t* zh, uint32_t timeout_sec); +}; + +const uint32_t TestReconfigServer::NUM_SERVERS = 3; + +TestReconfigServer:: +TestReconfigServer() : + logfile_(openlogfile("TestReconfigServer")) { + zoo_set_log_stream(logfile_); +} + +TestReconfigServer:: +~TestReconfigServer() { + if (logfile_) { + fflush(logfile_); + fclose(logfile_); + logfile_ = NULL; + } +} + +void TestReconfigServer:: +setUp() { + cluster_ = ZooKeeperQuorumServer::getCluster(NUM_SERVERS); +} + +void TestReconfigServer:: +tearDown() { + for (int i = 0; i < cluster_.size(); i++) { + delete cluster_[i]; + } + cluster_.clear(); +} + +int32_t TestReconfigServer:: +getLeader() { + for (int32_t i = 0; i < cluster_.size(); i++) { + if (cluster_[i]->isLeader()) { + return i; + } + } + return -1; +} + +std::vector TestReconfigServer:: +getFollowers() { + std::vector followers; + for (int32_t i = 0; i < cluster_.size(); i++) { + if (cluster_[i]->isFollower()) { + followers.push_back(i); + } + } + return followers; +} + +void TestReconfigServer:: +parseConfig(char* buf, int len, std::vector& servers, + std::string& version) { + std::string config(buf, len); + std::stringstream ss(config); + std::string line; + std::string serverPrefix("server."); + std::string versionPrefix("version="); + servers.clear(); + while(std::getline(ss, line, '\n')) { + if (line.compare(0, serverPrefix.size(), serverPrefix) == 0) { + servers.push_back(line); + } else if (line.compare(0, versionPrefix.size(), versionPrefix) == 0) { + version = line.substr(versionPrefix.size()); + } + } +} + +bool TestReconfigServer:: +waitForConnected(zhandle_t* zh, uint32_t timeout_sec) { + for (uint32_t i = 0; i < timeout_sec; i++) { + if (zoo_state(zh) == ZOO_CONNECTED_STATE) { + return true; + } + sleep(1); + } + return false; +} + +/** + * 1. Connect to the leader. + * 2. Remove a follower using incremental reconfig. + * 3. Add the follower back using incremental reconfig. + */ +void TestReconfigServer:: +testRemoveFollower() { + std::vector servers; + std::string version; + struct Stat stat; + int len = 1024; + char buf[len]; + + // get config from leader. + int32_t leader = getLeader(); + CPPUNIT_ASSERT(leader >= 0); + std::string host = cluster_[leader]->getHostPort(); + zhandle_t* zk = zookeeper_init(host.c_str(), NULL, 10000, NULL, NULL, 0); + CPPUNIT_ASSERT_EQUAL(true, waitForConnected(zk, 10)); + CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_getconfig(zk, 0, buf, &len, &stat)); + + // check if all the servers are listed in the config. + parseConfig(buf, len, servers, version); + // initially should be 1<<32, which is 0x100000000. This is the zxid + // of the first NEWLEADER message, used as the initial version + CPPUNIT_ASSERT_EQUAL(std::string("100000000"), version); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS, (uint32_t)(servers.size())); + for (int i = 0; i < cluster_.size(); i++) { + CPPUNIT_ASSERT(std::find(servers.begin(), servers.end(), + cluster_[i]->getServerString()) != servers.end()); + } + + // remove a follower. + std::vector followers = getFollowers(); + len = 1024; + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS - 1, + (uint32_t)(followers.size())); + std::stringstream ss; + ss << followers[0]; + int rc = zoo_reconfig(zk, NULL, ss.str().c_str(), NULL, -1, buf, &len, + &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + parseConfig(buf, len, servers, version); + CPPUNIT_ASSERT_EQUAL(std::string("100000002"), version); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS - 1, (uint32_t)(servers.size())); + for (int i = 0; i < cluster_.size(); i++) { + if (i == followers[0]) { + continue; + } + CPPUNIT_ASSERT(std::find(servers.begin(), servers.end(), + cluster_[i]->getServerString()) != servers.end()); + } + + // add the follower back. + len = 1024; + std::string serverString = cluster_[followers[0]]->getServerString(); + rc = zoo_reconfig(zk, serverString.c_str(), NULL, NULL, -1, buf, &len, + &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + parseConfig(buf, len, servers, version); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS, (uint32_t)(servers.size())); + for (int i = 0; i < cluster_.size(); i++) { + CPPUNIT_ASSERT(std::find(servers.begin(), servers.end(), + cluster_[i]->getServerString()) != servers.end()); + } + zookeeper_close(zk); +} + +/** + * 1. Connect to the leader. + * 2. Remove a follower using non-incremental reconfig. + * 3. Add the follower back using non-incremental reconfig. + */ +void TestReconfigServer:: +testNonIncremental() { + std::vector servers; + std::string version; + struct Stat stat; + int len = 1024; + char buf[len]; + + // get config from leader. + int32_t leader = getLeader(); + CPPUNIT_ASSERT(leader >= 0); + std::string host = cluster_[leader]->getHostPort(); + zhandle_t* zk = zookeeper_init(host.c_str(), NULL, 10000, NULL, NULL, 0); + CPPUNIT_ASSERT_EQUAL(true, waitForConnected(zk, 10)); + CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_getconfig(zk, 0, buf, &len, &stat)); + + // check if all the servers are listed in the config. + parseConfig(buf, len, servers, version); + // initially should be 1<<32, which is 0x100000000. This is the zxid + // of the first NEWLEADER message, used as the initial version + CPPUNIT_ASSERT_EQUAL(std::string("100000000"), version); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS, (uint32_t)(servers.size())); + for (int i = 0; i < cluster_.size(); i++) { + CPPUNIT_ASSERT(std::find(servers.begin(), servers.end(), + cluster_[i]->getServerString()) != servers.end()); + } + + // remove a follower. + std::vector followers = getFollowers(); + len = 1024; + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS - 1, + (uint32_t)(followers.size())); + std::stringstream ss; + for (int i = 1; i < followers.size(); i++) { + ss << cluster_[followers[i]]->getServerString() << ","; + } + ss << cluster_[leader]->getServerString(); + + int rc = zoo_reconfig(zk, NULL, NULL, ss.str().c_str(), -1, buf, &len, + &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + parseConfig(buf, len, servers, version); + CPPUNIT_ASSERT_EQUAL(std::string("100000002"), version); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS - 1, (uint32_t)(servers.size())); + for (int i = 0; i < cluster_.size(); i++) { + if (i == followers[0]) { + continue; + } + CPPUNIT_ASSERT(std::find(servers.begin(), servers.end(), + cluster_[i]->getServerString()) != servers.end()); + } + + // add the follower back. + len = 1024; + ss.str(""); + for (int i = 0; i < cluster_.size(); i++) { + ss << cluster_[i]->getServerString() << ","; + } + rc = zoo_reconfig(zk, NULL, NULL, ss.str().c_str(), -1, buf, &len, + &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, rc); + parseConfig(buf, len, servers, version); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS, (uint32_t)(servers.size())); + for (int i = 0; i < cluster_.size(); i++) { + CPPUNIT_ASSERT(std::find(servers.begin(), servers.end(), + cluster_[i]->getServerString()) != servers.end()); + } + zookeeper_close(zk); +} + +/** + * 1. Connect to a follower. + * 2. Remove the follower the client is connected to. + */ +void TestReconfigServer:: +testRemoveConnectedFollower() { + std::vector servers; + std::string version; + struct Stat stat; + int len = 1024; + char buf[len]; + + // connect to a follower. + int32_t leader = getLeader(); + std::vector followers = getFollowers(); + CPPUNIT_ASSERT(leader >= 0); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS - 1, (uint32_t)(followers.size())); + std::stringstream ss; + for (int i = 0; i < followers.size(); i++) { + ss << cluster_[followers[i]]->getHostPort() << ","; + } + ss << cluster_[leader]->getHostPort(); + std::string hosts = ss.str().c_str(); + zoo_deterministic_conn_order(true); + zhandle_t* zk = zookeeper_init(hosts.c_str(), NULL, 10000, NULL, NULL, 0); + CPPUNIT_ASSERT_EQUAL(true, waitForConnected(zk, 10)); + std::string connectedHost(zoo_get_current_server(zk)); + std::string portString = connectedHost.substr(connectedHost.find(":") + 1); + uint32_t port; + std::istringstream (portString) >> port; + CPPUNIT_ASSERT_EQUAL(cluster_[followers[0]]->getClientPort(), port); + + // remove the follower. + len = 1024; + ss.str(""); + ss << followers[0]; + zoo_reconfig(zk, NULL, ss.str().c_str(), NULL, -1, buf, &len, &stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_getconfig(zk, 0, buf, &len, &stat)); + parseConfig(buf, len, servers, version); + CPPUNIT_ASSERT_EQUAL(NUM_SERVERS - 1, (uint32_t)(servers.size())); + for (int i = 0; i < cluster_.size(); i++) { + if (i == followers[0]) { + continue; + } + CPPUNIT_ASSERT(std::find(servers.begin(), servers.end(), + cluster_[i]->getServerString()) != servers.end()); + } + zookeeper_close(zk); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TestReconfigServer); diff --git a/src/c/tests/TestWatchers.cc b/src/c/tests/TestWatchers.cc new file mode 100644 index 00000000000..0a269341c57 --- /dev/null +++ b/src/c/tests/TestWatchers.cc @@ -0,0 +1,773 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "CppAssertHelper.h" + +#include "ZKMocks.h" +#include "CollectionUtil.h" +#include "Util.h" + +class Zookeeper_watchers : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_watchers); + CPPUNIT_TEST(testDefaultSessionWatcher1); + CPPUNIT_TEST(testDefaultSessionWatcher2); + CPPUNIT_TEST(testObjectSessionWatcher1); + CPPUNIT_TEST(testObjectSessionWatcher2); + CPPUNIT_TEST(testNodeWatcher1); + CPPUNIT_TEST(testChildWatcher1); + CPPUNIT_TEST(testChildWatcher2); + CPPUNIT_TEST_SUITE_END(); + + static void watcher(zhandle_t *, int, int, const char *,void*){} + zhandle_t *zh; + FILE *logfile; + +public: + + Zookeeper_watchers() { + logfile = openlogfile("Zookeeper_watchers"); + } + + ~Zookeeper_watchers() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + + zoo_deterministic_conn_order(0); + zh=0; + } + + void tearDown() + { + zookeeper_close(zh); + } + + class ConnectionWatcher: public WatcherAction{ + public: + ConnectionWatcher():connected_(false),counter_(0){} + virtual void onConnectionEstablished(zhandle_t*){ + synchronized(mx_); + counter_++; + connected_=true; + } + SyncedBoolCondition isConnectionEstablished() const{ + return SyncedBoolCondition(connected_,mx_); + } + bool connected_; + int counter_; + }; + + class DisconnectWatcher: public WatcherAction{ + public: + DisconnectWatcher():disconnected_(false),counter_(0){} + virtual void onConnectionLost(zhandle_t*){ + synchronized(mx_); + counter_++; + disconnected_=true; + } + SyncedBoolCondition isDisconnected() const{ + return SyncedBoolCondition(disconnected_,mx_); + } + bool disconnected_; + int counter_; + }; + + class CountingDataWatcher: public WatcherAction{ + public: + CountingDataWatcher():disconnected_(false),counter_(0){} + virtual void onNodeValueChanged(zhandle_t*,const char* path){ + synchronized(mx_); + counter_++; + } + virtual void onConnectionLost(zhandle_t*){ + synchronized(mx_); + counter_++; + disconnected_=true; + } + bool disconnected_; + int counter_; + }; + + class DeletionCountingDataWatcher: public WatcherAction{ + public: + DeletionCountingDataWatcher():counter_(0){} + virtual void onNodeDeleted(zhandle_t*,const char* path){ + synchronized(mx_); + counter_++; + } + int counter_; + }; + + class ChildEventCountingWatcher: public WatcherAction{ + public: + ChildEventCountingWatcher():counter_(0){} + virtual void onChildChanged(zhandle_t*,const char* path){ + synchronized(mx_); + counter_++; + } + int counter_; + }; + +#ifndef THREADED + + // verify: the default watcher is called once for a session event + void testDefaultSessionWatcher1(){ + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + ConnectionWatcher watcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &watcher,0); + CPPUNIT_ASSERT(zh!=0); + + int fd=0; + int interest=0; + timeval tv; + // open the socket + int rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh)); + // send the handshake packet to the server + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh)); + // receive the server handshake response + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // verify connected + CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE,zoo_state(zh)); + CPPUNIT_ASSERT(watcher.connected_); + CPPUNIT_ASSERT_EQUAL(1,watcher.counter_); + } + + // test case: connect to server, set a default watcher, disconnect from the server + // verify: the default watcher is called once + void testDefaultSessionWatcher2(){ + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + DisconnectWatcher watcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &watcher,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + // first operation + AsyncCompletion ignored; + zkServer.addOperationResponse(new ZooGetResponse("1",1)); + int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // this will process the response and activate the watcher + rc=zookeeper_process(zh,ZOOKEEPER_READ); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // now, disconnect + zkServer.setConnectionLost(); + rc=zookeeper_process(zh,ZOOKEEPER_READ); + CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc); + // verify disconnected + CPPUNIT_ASSERT(watcher.disconnected_); + CPPUNIT_ASSERT_EQUAL(1,watcher.counter_); + } + + // testcase: connect to the server, set a watcher object on a node, + // disconnect from the server + // verify: the watcher object as well as the default watcher are called + void testObjectSessionWatcher1(){ + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + DisconnectWatcher defWatcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + AsyncCompletion ignored; + CountingDataWatcher wobject; + zkServer.addOperationResponse(new ZooStatResponse); + int rc=zoo_awexists(zh,"/x/y/1",activeWatcher,&wobject, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // this will process the response and activate the watcher + rc=zookeeper_process(zh,ZOOKEEPER_READ); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // now, disconnect + zkServer.setConnectionLost(); + rc=zookeeper_process(zh,ZOOKEEPER_READ); + CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc); + + // verify the default watcher has been triggered + CPPUNIT_ASSERT(defWatcher.disconnected_); + // and triggered only once + CPPUNIT_ASSERT_EQUAL(1,defWatcher.counter_); + + // the path-specific watcher has been triggered as well + CPPUNIT_ASSERT(wobject.disconnected_); + // only once! + CPPUNIT_ASSERT_EQUAL(1,wobject.counter_); + } + + // testcase: connect to the server, set a watcher object on a node, + // set a def watcher on another node,disconnect from the server + // verify: the watcher object as well as the default watcher are called + void testObjectSessionWatcher2(){ + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + DisconnectWatcher defWatcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + // set the default watcher + AsyncCompletion ignored; + zkServer.addOperationResponse(new ZooStatResponse); + int rc=zoo_aexists(zh,"/a/b/c",1,asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + CountingDataWatcher wobject; + zkServer.addOperationResponse(new ZooStatResponse); + rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // this will process the response and activate the watcher + while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK) { + millisleep(100); + } + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + // disconnect now + zkServer.setConnectionLost(); + rc=zookeeper_process(zh,ZOOKEEPER_READ); + CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc); + + // verify the default watcher has been triggered + CPPUNIT_ASSERT(defWatcher.disconnected_); + // and triggered only once + CPPUNIT_ASSERT_EQUAL(1,defWatcher.counter_); + + // the path-specific watcher has been triggered as well + CPPUNIT_ASSERT(wobject.disconnected_); + // only once! + CPPUNIT_ASSERT_EQUAL(1,wobject.counter_); + } + + // testcase: register 2 node watches for different paths, trigger the watches + // verify: the data watchers are processed, the default watcher is not called + void testNodeWatcher1(){ + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + DisconnectWatcher defWatcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + AsyncCompletion ignored; + CountingDataWatcher wobject1; + zkServer.addOperationResponse(new ZooStatResponse); + int rc=zoo_awexists(zh,"/a/b/c",activeWatcher,&wobject1, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + CountingDataWatcher wobject2; + zkServer.addOperationResponse(new ZooStatResponse); + rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject2, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // this will process the response and activate the watcher + while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK) { + millisleep(100); + } + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + // we are all set now; let's trigger the watches + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/a/b/c")); + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/x/y/z")); + // make sure all watchers have been processed + while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK) { + millisleep(100); + } + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + CPPUNIT_ASSERT_EQUAL(1,wobject1.counter_); + CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_); + CPPUNIT_ASSERT_EQUAL(0,defWatcher.counter_); + } + + // testcase: set up both a children and a data watchers on the node /a, then + // delete the node by sending a DELETE_EVENT event + // verify: both watchers are triggered + void testChildWatcher1(){ + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + DeletionCountingDataWatcher defWatcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + AsyncCompletion ignored; + DeletionCountingDataWatcher wobject1; + zkServer.addOperationResponse(new ZooStatResponse); + int rc=zoo_awexists(zh,"/a",activeWatcher,&wobject1, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + typedef ZooGetChildrenResponse::StringVector ZooVector; + zkServer.addOperationResponse(new ZooGetChildrenResponse( + Util::CollectionBuilder()("/a/1")("/a/2") + )); + DeletionCountingDataWatcher wobject2; + rc=zoo_awget_children(zh,"/a",activeWatcher, + &wobject2,asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // this will process the response and activate the watcher + while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK) { + millisleep(100); + } + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + // we are all set now; let's trigger the watches + zkServer.addRecvResponse(new ZNodeEvent(ZOO_DELETED_EVENT,"/a")); + // make sure the watchers have been processed + while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK) { + millisleep(100); + } + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + CPPUNIT_ASSERT_EQUAL(1,wobject1.counter_); + CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_); + CPPUNIT_ASSERT_EQUAL(0,defWatcher.counter_); + } + + // testcase: create both a child and data watch on the node /a, send a ZOO_CHILD_EVENT + // verify: only the child watch triggered + void testChildWatcher2(){ + Mock_gettimeofday timeMock; + ZookeeperServer zkServer; + // must call zookeeper_close() while all the mocks are in scope + CloseFinally guard(&zh); + + ChildEventCountingWatcher defWatcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + forceConnected(zh); + + AsyncCompletion ignored; + ChildEventCountingWatcher wobject1; + zkServer.addOperationResponse(new ZooStatResponse); + int rc=zoo_awexists(zh,"/a",activeWatcher,&wobject1, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + typedef ZooGetChildrenResponse::StringVector ZooVector; + zkServer.addOperationResponse(new ZooGetChildrenResponse( + Util::CollectionBuilder()("/a/1")("/a/2") + )); + ChildEventCountingWatcher wobject2; + rc=zoo_awget_children(zh,"/a",activeWatcher, + &wobject2,asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // this will process the response and activate the watcher + while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK) { + millisleep(100); + } + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + // we are all set now; let's trigger the watches + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHILD_EVENT,"/a")); + // make sure the watchers have been processed + while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK) { + millisleep(100); + } + CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); + + CPPUNIT_ASSERT_EQUAL(0,wobject1.counter_); + CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_); + CPPUNIT_ASSERT_EQUAL(0,defWatcher.counter_); + } + +#else + // verify: the default watcher is called once for a session event + void testDefaultSessionWatcher1(){ + Mock_gettimeofday timeMock; + // zookeeper simulator + ZookeeperServer zkServer; + // detects when all watchers have been delivered + WatcherDeliveryTracker deliveryTracker(ZOO_SESSION_EVENT,ZOO_CONNECTED_STATE); + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + ConnectionWatcher watcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &watcher,0); + CPPUNIT_ASSERT(zh!=0); + // wait till watcher proccessing has completed (the connection + // established event) + CPPUNIT_ASSERT(ensureCondition( + deliveryTracker.isWatcherProcessingCompleted(),1000)<1000); + + // verify the watcher has been triggered + CPPUNIT_ASSERT(ensureCondition(watcher.isConnectionEstablished(),1000)<1000); + // triggered only once + CPPUNIT_ASSERT_EQUAL(1,watcher.counter_); + } + + // test case: connect to server, set a default watcher, disconnect from the server + // verify: the default watcher is called once + void testDefaultSessionWatcher2(){ + Mock_gettimeofday timeMock; + // zookeeper simulator + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + // detects when all watchers have been delivered + WatcherDeliveryTracker deliveryTracker(ZOO_SESSION_EVENT,ZOO_CONNECTING_STATE); + DisconnectWatcher watcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &watcher,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + // set a default watch + AsyncCompletion ignored; + // a successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + int rc=zoo_aexists(zh,"/x/y/z",1,asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // now, initiate a disconnect + zkServer.setConnectionLost(); + CPPUNIT_ASSERT(ensureCondition( + deliveryTracker.isWatcherProcessingCompleted(),1000)<1000); + + // verify the watcher has been triggered + CPPUNIT_ASSERT(watcher.disconnected_); + // triggered only once + CPPUNIT_ASSERT_EQUAL(1,watcher.counter_); + } + + // testcase: connect to the server, set a watcher object on a node, + // disconnect from the server + // verify: the watcher object as well as the default watcher are called + void testObjectSessionWatcher1(){ + Mock_gettimeofday timeMock; + // zookeeper simulator + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + // detects when all watchers have been delivered + WatcherDeliveryTracker deliveryTracker(ZOO_SESSION_EVENT,ZOO_CONNECTING_STATE); + DisconnectWatcher defWatcher; + // use the tracker to find out when the watcher has been activated + WatcherActivationTracker activationTracker; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + + AsyncCompletion ignored; + // this successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + CountingDataWatcher wobject; + activationTracker.track(&wobject); + // set a path-specific watcher + int rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // make sure the watcher gets activated before we continue + CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000); + + // now, initiate a disconnect + zkServer.setConnectionLost(); + // make sure all watchers have been processed + CPPUNIT_ASSERT(ensureCondition( + deliveryTracker.isWatcherProcessingCompleted(),1000)<1000); + + // verify the default watcher has been triggered + CPPUNIT_ASSERT(defWatcher.disconnected_); + // and triggered only once + CPPUNIT_ASSERT_EQUAL(1,defWatcher.counter_); + + // the path-specific watcher has been triggered as well + CPPUNIT_ASSERT(wobject.disconnected_); + // only once! + CPPUNIT_ASSERT_EQUAL(1,wobject.counter_); + } + + // testcase: connect to the server, set a watcher object on a node, + // set a def watcher on another node,disconnect from the server + // verify: the watcher object as well as the default watcher are called + void testObjectSessionWatcher2(){ + Mock_gettimeofday timeMock; + // zookeeper simulator + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + // detects when all watchers have been delivered + WatcherDeliveryTracker deliveryTracker(ZOO_SESSION_EVENT,ZOO_CONNECTING_STATE); + DisconnectWatcher defWatcher; + // use the tracker to find out when the watcher has been activated + WatcherActivationTracker activationTracker; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + + // set a default watch + AsyncCompletion ignored; + // a successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + activationTracker.track(&defWatcher); + int rc=zoo_aexists(zh,"/a/b/c",1,asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // make sure the watcher gets activated before we continue + CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000); + + // this successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + CountingDataWatcher wobject; + activationTracker.track(&wobject); + // set a path-specific watcher + rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // make sure the watcher gets activated before we continue + CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000); + + // now, initiate a disconnect + zkServer.setConnectionLost(); + // make sure all watchers have been processed + CPPUNIT_ASSERT(ensureCondition( + deliveryTracker.isWatcherProcessingCompleted(),1000)<1000); + + // verify the default watcher has been triggered + CPPUNIT_ASSERT(defWatcher.disconnected_); + // and triggered only once + CPPUNIT_ASSERT_EQUAL(1,defWatcher.counter_); + + // the path-specific watcher has been triggered as well + CPPUNIT_ASSERT(wobject.disconnected_); + // only once! + CPPUNIT_ASSERT_EQUAL(1,wobject.counter_); + } + + // testcase: register 2 node watches for different paths, trigger the watches + // verify: the data watchers are processed, the default watcher is not called + void testNodeWatcher1(){ + Mock_gettimeofday timeMock; + // zookeeper simulator + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + // detects when all watchers have been delivered + WatcherDeliveryTracker deliveryTracker(ZOO_CHANGED_EVENT,0,false); + CountingDataWatcher defWatcher; + // use the tracker to find out when the watcher has been activated + WatcherActivationTracker activationTracker; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + + // don't care about completions + AsyncCompletion ignored; + // set a one-shot watch + // a successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + CountingDataWatcher wobject1; + activationTracker.track(&wobject1); + int rc=zoo_awexists(zh,"/a/b/c",activeWatcher,&wobject1, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // make sure the watcher gets activated before we continue + CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000); + + // this successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + CountingDataWatcher wobject2; + activationTracker.track(&wobject2); + // set a path-specific watcher + rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject2, + asyncCompletion,&ignored); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // make sure the watcher gets activated before we continue + CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000); + + // we are all set now; let's trigger the watches + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/a/b/c")); + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/x/y/z")); + // make sure all watchers have been processed + CPPUNIT_ASSERT(ensureCondition( + deliveryTracker.deliveryCounterEquals(2),1000)<1000); + + CPPUNIT_ASSERT_EQUAL(1,wobject1.counter_); + CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_); + CPPUNIT_ASSERT_EQUAL(0,defWatcher.counter_); + } + + // testcase: set up both a children and a data watchers on the node /a, then + // delete the node (that is, send a DELETE_EVENT) + // verify: both watchers are triggered + void testChildWatcher1(){ + Mock_gettimeofday timeMock; + // zookeeper simulator + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + // detects when all watchers have been delivered + WatcherDeliveryTracker deliveryTracker(ZOO_DELETED_EVENT,0); + DeletionCountingDataWatcher defWatcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + + // a successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + DeletionCountingDataWatcher wobject1; + Stat stat; + // add a node watch + int rc=zoo_wexists(zh,"/a",activeWatcher,&wobject1,&stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + typedef ZooGetChildrenResponse::StringVector ZooVector; + zkServer.addOperationResponse(new ZooGetChildrenResponse( + Util::CollectionBuilder()("/a/1")("/a/2") + )); + DeletionCountingDataWatcher wobject2; + String_vector children; + rc=zoo_wget_children(zh,"/a",activeWatcher,&wobject2,&children); + deallocate_String_vector(&children); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // we are all set now; let's trigger the watches + zkServer.addRecvResponse(new ZNodeEvent(ZOO_DELETED_EVENT,"/a")); + // make sure the watchers have been processed + CPPUNIT_ASSERT(ensureCondition( + deliveryTracker.isWatcherProcessingCompleted(),1000)<1000); + + CPPUNIT_ASSERT_EQUAL(1,wobject1.counter_); + CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_); + CPPUNIT_ASSERT_EQUAL(0,defWatcher.counter_); + } + + // testcase: create both a child and data watch on the node /a, send a ZOO_CHILD_EVENT + // verify: only the child watch triggered + void testChildWatcher2(){ + Mock_gettimeofday timeMock; + // zookeeper simulator + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // must call zookeeper_close() while all the mocks are in the scope! + CloseFinally guard(&zh); + + // detects when all watchers have been delivered + WatcherDeliveryTracker deliveryTracker(ZOO_CHILD_EVENT,0); + ChildEventCountingWatcher defWatcher; + zh=zookeeper_init("localhost:2121",activeWatcher,10000,TEST_CLIENT_ID, + &defWatcher,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + // a successful server response will activate the watcher + zkServer.addOperationResponse(new ZooStatResponse); + ChildEventCountingWatcher wobject1; + Stat stat; + // add a node watch + int rc=zoo_wexists(zh,"/a",activeWatcher,&wobject1,&stat); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + typedef ZooGetChildrenResponse::StringVector ZooVector; + zkServer.addOperationResponse(new ZooGetChildrenResponse( + Util::CollectionBuilder()("/a/1")("/a/2") + )); + ChildEventCountingWatcher wobject2; + String_vector children; + rc=zoo_wget_children(zh,"/a",activeWatcher,&wobject2,&children); + deallocate_String_vector(&children); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // we are all set now; let's trigger the watches + zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHILD_EVENT,"/a")); + // make sure the watchers have been processed + CPPUNIT_ASSERT(ensureCondition( + deliveryTracker.isWatcherProcessingCompleted(),1000)<1000); + + CPPUNIT_ASSERT_EQUAL(0,wobject1.counter_); + CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_); + CPPUNIT_ASSERT_EQUAL(0,defWatcher.counter_); + } + +#endif //THREADED +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_watchers); diff --git a/src/c/tests/TestZookeeperClose.cc b/src/c/tests/TestZookeeperClose.cc new file mode 100644 index 00000000000..6d704364f98 --- /dev/null +++ b/src/c/tests/TestZookeeperClose.cc @@ -0,0 +1,473 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ZKMocks.h" + +#ifdef THREADED +#include "PthreadMocks.h" +#endif + +using namespace std; + +class Zookeeper_close : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_close); +#ifdef THREADED + CPPUNIT_TEST(testIOThreadStoppedOnExpire); +#endif + CPPUNIT_TEST(testCloseUnconnected); + CPPUNIT_TEST(testCloseUnconnected1); + CPPUNIT_TEST(testCloseConnected1); + CPPUNIT_TEST(testCloseFromWatcher1); + CPPUNIT_TEST_SUITE_END(); + zhandle_t *zh; + static void watcher(zhandle_t *, int, int, const char *,void*){} + FILE *logfile; +public: + + Zookeeper_close() { + logfile = openlogfile("Zookeeper_close"); + } + + ~Zookeeper_close() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + + zoo_deterministic_conn_order(0); + zh=0; + } + + void tearDown() + { + zookeeper_close(zh); + } + + class CloseOnSessionExpired: public WatcherAction{ + public: + CloseOnSessionExpired(bool callClose=true): + callClose_(callClose),rc(ZOK){} + virtual void onSessionExpired(zhandle_t* zh){ + memcpy(&lzh,zh,sizeof(lzh)); + if(callClose_) + rc=zookeeper_close(zh); + } + zhandle_t lzh; + bool callClose_; + int rc; + }; + +#ifndef THREADED + void testCloseUnconnected() + { + zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0); + CPPUNIT_ASSERT(zh!=0); + + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + // make a copy of zhandle before close() overwrites some of + // it members with NULLs + zhandle_t lzh; + memcpy(&lzh,zh,sizeof(lzh)); + int rc=zookeeper_close(zh); + zhandle_t* savezh=zh; zh=0; + freeMock.disable(); // disable mock's fake free()- use libc's free() instead + + // verify that zookeeper_close has done its job + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data)); + // This cannot be maintained properly CPPUNIT_ASSERT_EQUAL(9,freeMock.callCounter); + } + void testCloseUnconnected1() + { + zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0); + CPPUNIT_ASSERT(zh!=0); + // simulate connected state + zh->fd=ZookeeperServer::FD; + zh->state=ZOO_CONNECTED_STATE; + Mock_flush_send_queue zkMock; + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + // make a copy of zhandle before close() overwrites some of + // it members with NULLs + zhandle_t lzh; + memcpy(&lzh,zh,sizeof(lzh)); + int rc=zookeeper_close(zh); + zhandle_t* savezh=zh; zh=0; + freeMock.disable(); // disable mock's fake free()- use libc's free() instead + + // verify that zookeeper_close has done its job + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data)); + // the close request sent? + CPPUNIT_ASSERT_EQUAL(1,zkMock.counter); + } + void testCloseConnected1() + { + ZookeeperServer zkServer; + // poll() will called from zookeeper_close() + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + + zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + CPPUNIT_ASSERT_EQUAL(ZOO_NOTCONNECTED_STATE, zoo_state(zh)); + + Mock_gettimeofday timeMock; + + int fd=0; + int interest=0; + timeval tv; + int rc=zookeeper_interest(zh,&fd,&interest,&tv); + + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh)); + CPPUNIT_ASSERT_EQUAL(ZOOKEEPER_READ|ZOOKEEPER_WRITE,interest); + + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh)); + + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + rc=zookeeper_process(zh,interest); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE,zoo_state(zh)); + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + // make a copy of zhandle before close() overwrites some of + // it members with NULLs + zhandle_t lzh; + memcpy(&lzh,zh,sizeof(lzh)); + zookeeper_close(zh); + zhandle_t* savezh=zh; zh=0; + freeMock.disable(); // disable mock's fake free()- use libc's free() instead + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data)); + // the close request sent? + CPPUNIT_ASSERT_EQUAL(1,(int)zkServer.closeSent); + } + void testCloseFromWatcher1() + { + Mock_gettimeofday timeMock; + + ZookeeperServer zkServer; + // make the server return a non-matching session id + zkServer.returnSessionExpired(); + // poll() will called from zookeeper_close() + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + + CloseOnSessionExpired closeAction; + zh=zookeeper_init("localhost:2121",activeWatcher,10000, + TEST_CLIENT_ID,&closeAction,0); + CPPUNIT_ASSERT(zh!=0); + + int fd=0; + int interest=0; + timeval tv; + // initiate connection + int rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh)); + CPPUNIT_ASSERT_EQUAL(ZOOKEEPER_READ|ZOOKEEPER_WRITE,interest); + rc=zookeeper_process(zh,interest); + // make sure the handshake in progress + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh)); + rc=zookeeper_interest(zh,&fd,&interest,&tv); + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + // should call the watcher with ZOO_EXPIRED_SESSION_STATE state + rc=zookeeper_process(zh,interest); + zhandle_t* savezh=zh; zh=0; + freeMock.disable(); // disable mock's fake free()- use libc's free() instead + + CPPUNIT_ASSERT_EQUAL(ZOO_EXPIRED_SESSION_STATE,zoo_state(savezh)); + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.addrs.data)); + // make sure the close request NOT sent + CPPUNIT_ASSERT_EQUAL(0,(int)zkServer.closeSent); + } +#else + void testCloseUnconnected() + { + // disable threading + MockPthreadZKNull pthreadMock; + zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0); + + CPPUNIT_ASSERT(zh!=0); + adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv; + CPPUNIT_ASSERT(adaptor!=0); + + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + // make a copy of zhandle before close() overwrites some of + // it members with NULLs + zhandle_t lzh; + memcpy(&lzh,zh,sizeof(lzh)); + int rc=zookeeper_close(zh); + zhandle_t* savezh=zh; zh=0; + // we're done, disable mock's fake free(), use libc's free() instead + freeMock.disable(); + + // verify that zookeeper_close has done its job + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor)); + // Cannot be maintained accurately: CPPUNIT_ASSERT_EQUAL(10,freeMock.callCounter); + // threads + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(adaptor->io)); + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(adaptor->completion)); + // mutexes + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->completions_to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->completions_to_process.lock)); + // conditionals + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->completions_to_process.cond)); + CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->completions_to_process.cond)); + } + void testCloseUnconnected1() + { + for(int i=0; i<100;i++){ + zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0); + CPPUNIT_ASSERT(zh!=0); + adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv; + CPPUNIT_ASSERT(adaptor!=0); + int rc=zookeeper_close(zh); + zh=0; + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + } + } + void testCloseConnected1() + { + // frozen time -- no timeouts and no pings + Mock_gettimeofday timeMock; + + for(int i=0;i<100;i++){ + ZookeeperServer zkServer; + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // use a checked version of pthread calls + CheckedPthread threadMock; + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + + zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0); + CPPUNIT_ASSERT(zh!=0); + // make sure the client has connected + CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000); + // make a copy of zhandle before close() overwrites some of + // its members with NULLs + zhandle_t lzh; + memcpy(&lzh,zh,sizeof(lzh)); + int rc=zookeeper_close(zh); + zhandle_t* savezh=zh; zh=0; + // we're done, disable mock's fake free(), use libc's free() instead + freeMock.disable(); + + CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); + adaptor_threads* adaptor=(adaptor_threads*)lzh.adaptor_priv; + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor)); + // threads + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->io)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->completion)); + // mutexes + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->completions_to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->completions_to_process.lock)); + // conditionals + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->completions_to_process.cond)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->completions_to_process.cond)); + } + } + + struct PointerFreed{ + PointerFreed(Mock_free_noop& freeMock,void* ptr): + freeMock_(freeMock),ptr_(ptr){} + bool operator()() const{return freeMock_.isFreed(ptr_); } + Mock_free_noop& freeMock_; + void* ptr_; + }; + // test if zookeeper_close may be called from a watcher callback on + // SESSION_EXPIRED event + void testCloseFromWatcher1() + { + // frozen time -- no timeouts and no pings + Mock_gettimeofday timeMock; + + for(int i=0;i<100;i++){ + ZookeeperServer zkServer; + // make the server return a non-matching session id + zkServer.returnSessionExpired(); + + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // use a checked version of pthread calls + CheckedPthread threadMock; + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + + CloseOnSessionExpired closeAction; + zh=zookeeper_init("localhost:2121",activeWatcher,10000, + TEST_CLIENT_ID,&closeAction,0); + + CPPUNIT_ASSERT(zh!=0); + // we rely on the fact that zh is freed the last right before + // zookeeper_close() returns... + CPPUNIT_ASSERT(ensureCondition(PointerFreed(freeMock,zh),1000)<1000); + zhandle_t* lzh=zh; + zh=0; + // we're done, disable mock's fake free(), use libc's free() instead + freeMock.disable(); + + CPPUNIT_ASSERT_EQUAL((int)ZOK,closeAction.rc); + adaptor_threads* adaptor=(adaptor_threads*)closeAction.lzh.adaptor_priv; + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.addrs.data)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor)); + // threads + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->io)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->completion)); + // mutexes + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.lock)); + // conditionals + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.cond)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.cond)); + } + } + + void testIOThreadStoppedOnExpire() + { + // frozen time -- no timeouts and no pings + Mock_gettimeofday timeMock; + + for(int i=0;i<100;i++){ + ZookeeperServer zkServer; + // make the server return a non-matching session id + zkServer.returnSessionExpired(); + + Mock_poll pollMock(&zkServer,ZookeeperServer::FD); + // use a checked version of pthread calls + CheckedPthread threadMock; + // do not call zookeeper_close() from the watcher + CloseOnSessionExpired closeAction(false); + zh=zookeeper_init("localhost:2121",activeWatcher,10000, + &testClientId,&closeAction,0); + + // this is to ensure that if any assert fires, zookeeper_close() + // will still be called while all the mocks are in the scope! + CloseFinally guard(&zh); + + CPPUNIT_ASSERT(zh!=0); + CPPUNIT_ASSERT(ensureCondition(SessionExpired(zh),1000)<1000); + CPPUNIT_ASSERT(ensureCondition(IOThreadStopped(zh),1000)<1000); + // make sure the watcher has been processed + CPPUNIT_ASSERT(ensureCondition(closeAction.isWatcherTriggered(),1000)<1000); + // make sure the threads have not been destroyed yet + adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv; + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getDestroyCounter(adaptor->io)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getDestroyCounter(adaptor->completion)); + // about to call zookeeper_close() -- no longer need the guard + guard.disarm(); + + // do not actually free the memory while in zookeeper_close() + Mock_free_noop freeMock; + zookeeper_close(zh); + zhandle_t* lzh=zh; zh=0; + // we're done, disable mock's fake free(), use libc's free() instead + freeMock.disable(); + + // memory + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.hostname)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.addrs.data)); + CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor)); + // threads + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->io)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->completion)); + // mutexes + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_process.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_send.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.lock)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.lock)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.lock)); + // conditionals + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.cond)); + CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.cond)); + CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.cond)); + } + } + +#endif +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_close); diff --git a/src/c/tests/TestZookeeperInit.cc b/src/c/tests/TestZookeeperInit.cc new file mode 100644 index 00000000000..6f43e050905 --- /dev/null +++ b/src/c/tests/TestZookeeperInit.cc @@ -0,0 +1,301 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "Util.h" +#include "LibCMocks.h" +#include "ZKMocks.h" + +#ifdef THREADED +#include "PthreadMocks.h" +#else +class MockPthreadsNull; +#endif + +using namespace std; + +class Zookeeper_init : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_init); + CPPUNIT_TEST(testBasic); + CPPUNIT_TEST(testAddressResolution); + CPPUNIT_TEST(testMultipleAddressResolution); + CPPUNIT_TEST(testNullAddressString); + CPPUNIT_TEST(testEmptyAddressString); + CPPUNIT_TEST(testOneSpaceAddressString); + CPPUNIT_TEST(testTwoSpacesAddressString); + CPPUNIT_TEST(testInvalidAddressString1); + CPPUNIT_TEST(testInvalidAddressString2); + CPPUNIT_TEST(testNonexistentHost); + CPPUNIT_TEST(testOutOfMemory_init); + CPPUNIT_TEST(testOutOfMemory_getaddrs1); +#if !defined(__CYGWIN__) // not valid for cygwin + CPPUNIT_TEST(testOutOfMemory_getaddrs2); +#endif + CPPUNIT_TEST(testPermuteAddrsList); + CPPUNIT_TEST_SUITE_END(); + zhandle_t *zh; + MockPthreadsNull* pthreadMock; + static void watcher(zhandle_t *, int , int , const char *,void*){} + FILE *logfile; +public: + Zookeeper_init():zh(0),pthreadMock(0){ + logfile = openlogfile("Zookeeper_init"); + } + + ~Zookeeper_init() { + if (logfile) { + fflush(logfile); + fclose(logfile); + logfile = 0; + } + } + + void setUp() + { + zoo_set_log_stream(logfile); + + zoo_deterministic_conn_order(0); +#ifdef THREADED + // disable threading + pthreadMock=new MockPthreadZKNull; +#endif + zh=0; + } + + void tearDown() + { + zookeeper_close(zh); +#ifdef THREADED + delete pthreadMock; +#endif + } + + void testBasic() + { + const string EXPECTED_HOST("127.0.0.1:2121"); + const unsigned int EXPECTED_ADDRS_COUNT =1; + const int EXPECTED_RECV_TIMEOUT=10000; + clientid_t cid; + memset(&cid,0xFE,sizeof(cid)); + + zh=zookeeper_init(EXPECTED_HOST.c_str(),watcher,EXPECTED_RECV_TIMEOUT, + &cid,(void*)1,0); + + CPPUNIT_ASSERT(zh != NULL); + CPPUNIT_ASSERT(zh->fd == -1); + CPPUNIT_ASSERT(zh->hostname != NULL); + CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs.count); + CPPUNIT_ASSERT_EQUAL(EXPECTED_HOST,string(zh->hostname)); + CPPUNIT_ASSERT(zh->state == ZOO_NOTCONNECTED_STATE); + CPPUNIT_ASSERT(zh->context == (void*)1); + CPPUNIT_ASSERT_EQUAL(EXPECTED_RECV_TIMEOUT,zh->recv_timeout); + CPPUNIT_ASSERT(zh->watcher == watcher); + CPPUNIT_ASSERT(zh->addrs.next==0); + CPPUNIT_ASSERT(zh->primer_buffer.buffer==zh->primer_storage_buffer); + CPPUNIT_ASSERT(zh->primer_buffer.curr_offset ==0); + CPPUNIT_ASSERT(zh->primer_buffer.len == sizeof(zh->primer_storage_buffer)); + CPPUNIT_ASSERT(zh->primer_buffer.next == 0); + CPPUNIT_ASSERT(zh->last_zxid ==0); + CPPUNIT_ASSERT(memcmp(&zh->client_id,&cid,sizeof(cid))==0); + +#ifdef THREADED + // thread specific checks + adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv; + CPPUNIT_ASSERT(adaptor!=0); + CPPUNIT_ASSERT(pthreadMock->pthread_createCounter==2); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(adaptor->io)); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(adaptor->completion)); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->to_process.lock)); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->to_send.lock)); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->sent_requests.lock)); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->completions_to_process.lock)); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->sent_requests.cond)); + CPPUNIT_ASSERT(MockPthreadsNull::isInitialized(&zh->completions_to_process.cond)); +#endif + } + void testAddressResolution() + { + const char EXPECTED_IPS[][4]={{127,0,0,1}}; + const unsigned int EXPECTED_ADDRS_COUNT =COUNTOF(EXPECTED_IPS); + + zoo_deterministic_conn_order(1); + zh=zookeeper_init("127.0.0.1:2121",0,10000,0,0,0); + + CPPUNIT_ASSERT(zh!=0); + CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs.count); + for(int i=0;iaddrs.count;i++){ + sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs.data[i]; + CPPUNIT_ASSERT(memcmp(EXPECTED_IPS[i],&addr->sin_addr,sizeof(addr->sin_addr))==0); + CPPUNIT_ASSERT_EQUAL(2121,(int)ntohs(addr->sin_port)); + } + } + void testMultipleAddressResolution() + { + const string EXPECTED_HOST("127.0.0.1:2121,127.0.0.2:3434"); + const char EXPECTED_IPS[][4]={{127,0,0,1},{127,0,0,2}}; + const unsigned int EXPECTED_ADDRS_COUNT =COUNTOF(EXPECTED_IPS); + + zoo_deterministic_conn_order(1); + zh=zookeeper_init(EXPECTED_HOST.c_str(),0,1000,0,0,0); + + CPPUNIT_ASSERT(zh!=0); + CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs.count); + + for(int i=0;iaddrs.count;i++){ + sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs.data[i]; + CPPUNIT_ASSERT(memcmp(EXPECTED_IPS[i],&addr->sin_addr,sizeof(addr->sin_addr))==0); + if(i<1) + CPPUNIT_ASSERT_EQUAL(2121,(int)ntohs(addr->sin_port)); + else + CPPUNIT_ASSERT_EQUAL(3434,(int)ntohs(addr->sin_port)); + } + } + void testMultipleAddressWithSpace() + { + const string EXPECTED_HOST("127.0.0.1:2121, 127.0.0.2:3434"); + const char EXPECTED_IPS[][4]={{127,0,0,1},{127,0,0,2}}; + const unsigned int EXPECTED_ADDRS_COUNT =COUNTOF(EXPECTED_IPS); + + zoo_deterministic_conn_order(1); + zh=zookeeper_init(EXPECTED_HOST.c_str(),0,1000,0,0,0); + + CPPUNIT_ASSERT(zh!=0); + CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs.count); + + for(int i=0;iaddrs.count;i++){ + sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs.data[i]; + CPPUNIT_ASSERT(memcmp(EXPECTED_IPS[i],&addr->sin_addr,sizeof(addr->sin_addr))==0); + if(i<1) + CPPUNIT_ASSERT_EQUAL(2121,(int)ntohs(addr->sin_port)); + else + CPPUNIT_ASSERT_EQUAL(3434,(int)ntohs(addr->sin_port)); + } + } + void testNullAddressString() + { + zh=zookeeper_init(NULL,0,0,0,0,0); + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(EINVAL,errno); + } + void testEmptyAddressString() + { + const string INVALID_HOST(""); + zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0); + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(EINVAL,errno); + } + void testOneSpaceAddressString() + { + const string INVALID_HOST(" "); + zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0); + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(EINVAL,errno); + } + void testTwoSpacesAddressString() + { + const string INVALID_HOST(" "); + zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0); + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(EINVAL,errno); + } + void testInvalidAddressString1() + { + const string INVALID_HOST("host1"); + zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0); + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(EINVAL,errno); + } + void testInvalidAddressString2() + { + const string INVALID_HOST("host1:1111+host:123"); + zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0); + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT((ENOENT|EINVAL) & errno); + } + void testNonexistentHost() + { + const string EXPECTED_HOST("host1.blabadibla.bla.:1111"); + + zh=zookeeper_init(EXPECTED_HOST.c_str(),0,0,0,0,0); + + CPPUNIT_ASSERT(zh==0); + //With the switch to thread safe getaddrinfo, we don't get + //these global variables + //CPPUNIT_ASSERT_EQUAL(EINVAL,errno); + //CPPUNIT_ASSERT_EQUAL(HOST_NOT_FOUND,h_errno); + } + void testOutOfMemory_init() + { + Mock_calloc mock; + mock.callsBeforeFailure=0; // fail first calloc in init() + + zh=zookeeper_init("ahost:123",watcher,10000,0,0,0); + + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(ENOMEM,errno); + } + void testOutOfMemory_getaddrs1() + { + Mock_realloc reallocMock; + reallocMock.callsBeforeFailure=0; // fail on first call to realloc + + zh=zookeeper_init("127.0.0.1:123",0,0,0,0,0); + + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(ENOMEM,errno); + } + void testOutOfMemory_getaddrs2() + { + Mock_realloc reallocMock; + reallocMock.callsBeforeFailure=1; // fail on the second call to realloc + + zh=zookeeper_init("127.0.0.1:123,127.0.0.2:123,127.0.0.3:123,127.0.0.4:123,127.0.0.5:123,127.0.0.6:123,127.0.0.7:123,127.0.0.8:123,127.0.0.9:123,127.0.0.10:123,127.0.0.11:123,127.0.0.12:123,127.0.0.13:123,127.0.0.14:123,127.0.0.15:123,127.0.0.16:123,127.0.0.17:123",0,0,0,0,0); + + CPPUNIT_ASSERT(zh==0); + CPPUNIT_ASSERT_EQUAL(ENOMEM,errno); + } + void testPermuteAddrsList() + { + const char EXPECTED[][5]={"\0\0\0\0","\1\1\1\1","\2\2\2\2","\3\3\3\3"}; + const unsigned int EXPECTED_ADDR_COUNT=COUNTOF(EXPECTED); + + const int RAND_SEQ[]={0,1,1,-1}; + const int RAND_SIZE=COUNTOF(RAND_SEQ); + Mock_random randomMock; + randomMock.randomReturns.assign(RAND_SEQ,RAND_SEQ+RAND_SIZE-1); + zh=zookeeper_init("0.0.0.0:123,1.1.1.1:123,2.2.2.2:123,3.3.3.3:123",0,1000,0,0,0); + + CPPUNIT_ASSERT(zh!=0); + CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDR_COUNT,zh->addrs.count); + const string EXPECTED_SEQ("3210"); + char ACTUAL_SEQ[EXPECTED_ADDR_COUNT+1]; ACTUAL_SEQ[EXPECTED_ADDR_COUNT]=0; + for(int i=0;iaddrs.count;i++){ + sockaddr_in* addr=(struct sockaddr_in*)&zh->addrs.data[i]; + // match the first byte of the EXPECTED and of the actual address + ACTUAL_SEQ[i]=((char*)&addr->sin_addr)[0]+'0'; + } + CPPUNIT_ASSERT_EQUAL(EXPECTED_SEQ,string(ACTUAL_SEQ)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_init); diff --git a/src/c/tests/ThreadingUtil.cc b/src/c/tests/ThreadingUtil.cc new file mode 100644 index 00000000000..3b5170abbe7 --- /dev/null +++ b/src/c/tests/ThreadingUtil.cc @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "ThreadingUtil.h" +#include "LibCSymTable.h" + +#ifdef THREADED + +// **************************************************************************** +// Mutex wrapper +struct Mutex::Impl{ + Impl(){ + LIBC_SYMBOLS.pthread_mutex_init(&mut_, 0); + } + ~Impl(){ + LIBC_SYMBOLS.pthread_mutex_destroy(&mut_); + } + pthread_mutex_t mut_; +}; + +Mutex::Mutex():impl_(new Impl) {} +Mutex::~Mutex() { delete impl_;} +void Mutex::acquire() { + LIBC_SYMBOLS.pthread_mutex_lock(&impl_->mut_); +} +void Mutex::release() { + LIBC_SYMBOLS.pthread_mutex_unlock(&impl_->mut_); +} + +// **************************************************************************** +// Atomics +int32_t atomic_post_incr(volatile int32_t* operand, int32_t incr) +{ +#if defined(__GNUC__) + return __sync_fetch_and_add(operand,incr); +#else + int32_t result; + __asm__ __volatile__( + "lock xaddl %0,%1\n" + : "=r"(result), "=m"(*operand) + : "0"(incr) + : "memory"); + return result; +#endif +} +int32_t atomic_fetch_store(volatile int32_t *ptr, int32_t value) +{ +#if defined(__GNUC__) + return __sync_lock_test_and_set(ptr,value); +#else + int32_t result; + __asm__ __volatile__("lock xchgl %0,%1\n" + : "=r"(result), "=m"(*ptr) + : "0"(value) + : "memory"); + return result; +#endif +} +#else +int32_t atomic_post_incr(volatile int32_t* operand, int32_t incr){ + int32_t v=*operand; + *operand+=incr; + return v; +} +int32_t atomic_fetch_store(volatile int32_t *ptr, int32_t value) +{ + int32_t result=*ptr; + *ptr=value; + return result; +} +#endif // THREADED diff --git a/src/c/tests/ThreadingUtil.h b/src/c/tests/ThreadingUtil.h new file mode 100644 index 00000000000..9165412bc8b --- /dev/null +++ b/src/c/tests/ThreadingUtil.h @@ -0,0 +1,261 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef THREADINGUTIL_H_ +#define THREADINGUTIL_H_ + +#include + +#ifdef THREADED +#include "pthread.h" +#endif + +// ***************************************************************************** +// Threading primitives + +// atomic post-increment; returns the previous value of the operand +int32_t atomic_post_incr(volatile int32_t* operand, int32_t incr); +// atomic fetch&store; returns the previous value of the operand +int32_t atomic_fetch_store(volatile int32_t *operand, int32_t value); + +// a partial implementation of an atomic integer type +class AtomicInt{ +public: + explicit AtomicInt(int32_t init=0):v_(init){} + AtomicInt(const AtomicInt& other):v_(other){} + // assigment + AtomicInt& operator=(const AtomicInt& lhs){ + atomic_fetch_store(&v_,lhs); + return *this; + } + AtomicInt& operator=(int32_t i){ + atomic_fetch_store(&v_,i); + return *this; + } + // pre-increment + AtomicInt& operator++() { + atomic_post_incr(&v_,1); + return *this; + } + // pre-decrement + AtomicInt& operator--() { + atomic_post_incr(&v_,-1); + return *this; + } + // post-increment + AtomicInt operator++(int){ + return AtomicInt(atomic_post_incr(&v_,1)); + } + // post-decrement + AtomicInt operator--(int){ + return AtomicInt(atomic_post_incr(&v_,-1)); + } + + operator int() const{ + return atomic_post_incr(&v_,0); + } + int get() const{ + return atomic_post_incr(&v_,0); + } +private: + mutable int32_t v_; +}; + +#ifdef THREADED +// **************************************************************************** +#define VALIDATE_JOBS(jm) jm.validateJobs(__FILE__,__LINE__) +#define VALIDATE_JOB(j) j.validate(__FILE__,__LINE__) + +class Mutex{ +public: + Mutex(); + ~Mutex(); + void acquire(); + void release(); +private: + Mutex(const Mutex&); + Mutex& operator=(const Mutex&); + struct Impl; + Impl* impl_; +}; + +class MTLock{ +public: + MTLock(Mutex& m):m_(m){m.acquire();} + ~MTLock(){m_.release();} + Mutex& m_; +}; + +#define synchronized(m) MTLock __lock(m) + +// **************************************************************************** +class Latch { +public: + virtual ~Latch() {} + virtual void await() const =0; + virtual void signalAndWait() =0; + virtual void signal() =0; +}; + +class CountDownLatch: public Latch { +public: + CountDownLatch(int count):count_(count) { + pthread_cond_init(&cond_,0); + pthread_mutex_init(&mut_,0); + } + virtual ~CountDownLatch() { + pthread_mutex_lock(&mut_); + if(count_!=0) { + count_=0; + pthread_cond_broadcast(&cond_); + } + pthread_mutex_unlock(&mut_); + + pthread_cond_destroy(&cond_); + pthread_mutex_destroy(&mut_); + } + + virtual void await() const { + pthread_mutex_lock(&mut_); + awaitImpl(); + pthread_mutex_unlock(&mut_); + } + virtual void signalAndWait() { + pthread_mutex_lock(&mut_); + signalImpl(); + awaitImpl(); + pthread_mutex_unlock(&mut_); + } + virtual void signal() { + pthread_mutex_lock(&mut_); + signalImpl(); + pthread_mutex_unlock(&mut_); + } +private: + void awaitImpl() const{ + while(count_!=0) + pthread_cond_wait(&cond_,&mut_); + } + void signalImpl() { + if(count_>0) { + count_--; + pthread_cond_broadcast(&cond_); + } + } + int count_; + mutable pthread_mutex_t mut_; + mutable pthread_cond_t cond_; +}; + +class TestJob { +public: + typedef long JobId; + TestJob():hasRun_(false),startLatch_(0),endLatch_(0) {} + virtual ~TestJob() { + join(); + } + virtual TestJob* clone() const =0; + + virtual void run() =0; + virtual void validate(const char* file, int line) const =0; + + virtual void start(Latch* startLatch=0,Latch* endLatch=0) { + startLatch_=startLatch;endLatch_=endLatch; + hasRun_=true; + pthread_create(&thread_, 0, thread, this); + } + virtual JobId getJobId() const { + return (JobId)thread_; + } + virtual void join() { + if(!hasRun_) + return; + if(!pthread_equal(thread_,pthread_self())) + pthread_join(thread_,0); + else + pthread_detach(thread_); + } +private: + void awaitStart() { + if(startLatch_==0) return; + startLatch_->signalAndWait(); + } + void signalFinished() { + if(endLatch_==0) return; + endLatch_->signal(); + } + static void* thread(void* p) { + TestJob* j=(TestJob*)p; + j->awaitStart(); // wait for the start command + j->run(); + j->signalFinished(); + return 0; + } + bool hasRun_; + Latch* startLatch_; + Latch* endLatch_; + pthread_t thread_; +}; + +class TestJobManager { + typedef std::vector JobList; +public: + TestJobManager(const TestJob& tj,int threadCount=1): + startLatch_(threadCount),endLatch_(threadCount) + { + for(int i=0;istart(&startLatch_,&endLatch_); + } + virtual void startJobsImmediately() { + for(unsigned i=0;istart(0,&endLatch_); + } + virtual void wait() const { + endLatch_.await(); + } + virtual void validateJobs(const char* file, int line) const{ + for(unsigned i=0;ivalidate(file,line); + } +private: + JobList jobs_; + CountDownLatch startLatch_; + CountDownLatch endLatch_; +}; + +#else // THREADED +// single THREADED +class Mutex{ +public: + void acquire(){} + void release(){} +}; +#define synchronized(m) + +#endif // THREADED + +#endif /*THREADINGUTIL_H_*/ diff --git a/src/c/tests/Util.cc b/src/c/tests/Util.cc new file mode 100644 index 00000000000..2b9da84eb57 --- /dev/null +++ b/src/c/tests/Util.cc @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Util.h" +#include "string.h" + +const std::string EMPTY_STRING; + +TestConfig globalTestConfig; + +void millisleep(int ms){ + timespec ts; + ts.tv_sec=ms/1000; + ts.tv_nsec=(ms%1000)*1000000; // to nanoseconds + nanosleep(&ts,0); +} + +FILE *openlogfile(const char* testname) { + char name[1024]; + strcpy(name, "TEST-"); + strncpy(name + 5, testname, sizeof(name) - 5); +#ifdef THREADED + strcpy(name + strlen(name), "-mt.txt"); +#else + strcpy(name + strlen(name), "-st.txt"); +#endif + + FILE *logfile = fopen(name, "a"); + + if (logfile == 0) { + fprintf(stderr, "Can't open log file %s!\n", name); + return 0; + } + + return logfile; +} diff --git a/src/c/tests/Util.h b/src/c/tests/Util.h new file mode 100644 index 00000000000..0fd178b1160 --- /dev/null +++ b/src/c/tests/Util.h @@ -0,0 +1,137 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UTIL_H_ +#define UTIL_H_ + +#include +#include +#include + +#include "zookeeper_log.h" + +// number of elements in array +#define COUNTOF(array) sizeof(array)/sizeof(array[0]) + +#define DECLARE_WRAPPER(ret,sym,sig) \ + extern "C" ret __real_##sym sig; \ + extern "C" ret __wrap_##sym sig + +#define CALL_REAL(sym,params) \ + __real_##sym params + +// must include "src/zookeeper_log.h" to be able to use this macro +#define TEST_TRACE(x...) \ + log_message(LOGSTREAM, ZOO_LOG_LEVEL_DEBUG,__LINE__,__func__,x) + +extern const std::string EMPTY_STRING; + +// ***************************************************************************** +// A bit of wizardry to get to the bare type from a reference or a pointer +// to the type +template +struct TypeOp { + typedef T BareT; + typedef T ArgT; +}; + +// partial specialization for reference types +template +struct TypeOp{ + typedef T& ArgT; + typedef typename TypeOp::BareT BareT; +}; + +// partial specialization for pointers +template +struct TypeOp{ + typedef T* ArgT; + typedef typename TypeOp::BareT BareT; +}; + +// ***************************************************************************** +// Container utilities + +template +void putValue(std::map& map,const K& k, const V& v){ + typedef std::map Map; + typename Map::const_iterator it=map.find(k); + if(it==map.end()) + map.insert(typename Map::value_type(k,v)); + else + map[k]=v; +} + +template +bool getValue(const std::map& map,const K& k,V& v){ + typedef std::map Map; + typename Map::const_iterator it=map.find(k); + if(it==map.end()) + return false; + v=it->second; + return true; +} + +// ***************************************************************************** +// misc utils + +// millisecond sleep +void millisleep(int ms); +FILE *openlogfile(const char* name); +// evaluate given predicate until it returns true or the timeout +// (in millis) has expired +template +int ensureCondition(const Predicate& p,int timeout){ + int elapsed=0; + while(!p() && elapsed CmdLineOptList; +public: + typedef CmdLineOptList::const_iterator const_iterator; + TestConfig(){} + ~TestConfig(){} + void addConfigFromCmdLine(int argc, char* argv[]){ + if(argc>=2) + testName_=argv[1]; + for(int i=2; i + +// function to conveniently stream vectors +template +std::ostream& operator<<(std::ostream& os,const std::vector& c){ + typedef std::vector V; + os<<"["; + if(c.size()>0){ + for(typename V::const_iterator it=c.begin();it!=c.end();++it) + os<<*it<<","; + os.seekp(-1,std::ios::cur); + } + os<<"]"; + return os; +} + +#endif // _VECTOR_UTIL_H diff --git a/src/c/tests/WatchUtil.h b/src/c/tests/WatchUtil.h new file mode 100644 index 00000000000..035f26ded79 --- /dev/null +++ b/src/c/tests/WatchUtil.h @@ -0,0 +1,153 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WATCH_UTIL_H_ +#define WATCH_UTIL_H_ + +#include +#include +#include + +using namespace std; + +#include "CollectionUtil.h" +#include "ThreadingUtil.h" + +using namespace Util; + +#ifdef THREADED + static void yield(zhandle_t *zh, int i) + { + sleep(i); + } +#else + static void yield(zhandle_t *zh, int seconds) + { + int fd; + int interest; + int events; + struct timeval tv; + int rc; + time_t expires = time(0) + seconds; + time_t timeLeft = seconds; + fd_set rfds, wfds, efds; + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + + while(timeLeft >= 0) { + zookeeper_interest(zh, &fd, &interest, &tv); + if (fd != -1) { + if (interest&ZOOKEEPER_READ) { + FD_SET(fd, &rfds); + } else { + FD_CLR(fd, &rfds); + } + if (interest&ZOOKEEPER_WRITE) { + FD_SET(fd, &wfds); + } else { + FD_CLR(fd, &wfds); + } + } else { + fd = 0; + } + FD_SET(0, &rfds); + if (tv.tv_sec > timeLeft) { + tv.tv_sec = timeLeft; + } + rc = select(fd+1, &rfds, &wfds, &efds, &tv); + timeLeft = expires - time(0); + events = 0; + if (FD_ISSET(fd, &rfds)) { + events |= ZOOKEEPER_READ; + } + if (FD_ISSET(fd, &wfds)) { + events |= ZOOKEEPER_WRITE; + } + zookeeper_process(zh, events); + } + } +#endif + +typedef struct evt { + string path; + int type; +} evt_t; + +typedef struct watchCtx { +private: + list events; + watchCtx(const watchCtx&); + watchCtx& operator=(const watchCtx&); +public: + bool connected; + zhandle_t *zh; + Mutex mutex; + + watchCtx() { + connected = false; + zh = 0; + } + ~watchCtx() { + if (zh) { + zookeeper_close(zh); + zh = 0; + } + } + + evt_t getEvent() { + evt_t evt; + mutex.acquire(); + CPPUNIT_ASSERT( events.size() > 0); + evt = events.front(); + events.pop_front(); + mutex.release(); + return evt; + } + + int countEvents() { + int count; + mutex.acquire(); + count = events.size(); + mutex.release(); + return count; + } + + void putEvent(evt_t evt) { + mutex.acquire(); + events.push_back(evt); + mutex.release(); + } + + bool waitForConnected(zhandle_t *zh) { + time_t expires = time(0) + 10; + while(!connected && time(0) < expires) { + yield(zh, 1); + } + return connected; + } + bool waitForDisconnected(zhandle_t *zh) { + time_t expires = time(0) + 15; + while(connected && time(0) < expires) { + yield(zh, 1); + } + return !connected; + } +} watchctx_t; + +#endif /*WATCH_UTIL_H_*/ diff --git a/src/c/tests/ZKMocks.cc b/src/c/tests/ZKMocks.cc new file mode 100644 index 00000000000..1310ab9d4b8 --- /dev/null +++ b/src/c/tests/ZKMocks.cc @@ -0,0 +1,544 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include // for htonl +#include + +#include +#include + +#ifdef THREADED +#include "PthreadMocks.h" +#endif +#include "ZKMocks.h" + +using namespace std; + +TestClientId testClientId; +const char* TestClientId::PASSWD="1234567890123456"; + +HandshakeRequest* HandshakeRequest::parse(const std::string& buf) { + auto_ptr req(new HandshakeRequest); + + memcpy(&req->protocolVersion,buf.data(), sizeof(req->protocolVersion)); + req->protocolVersion = htonl(req->protocolVersion); + + int offset=sizeof(req->protocolVersion); + + memcpy(&req->lastZxidSeen,buf.data()+offset,sizeof(req->lastZxidSeen)); + req->lastZxidSeen = zoo_htonll(req->lastZxidSeen); + offset+=sizeof(req->lastZxidSeen); + + memcpy(&req->timeOut,buf.data()+offset,sizeof(req->timeOut)); + req->timeOut = htonl(req->timeOut); + offset+=sizeof(req->timeOut); + + memcpy(&req->sessionId,buf.data()+offset,sizeof(req->sessionId)); + req->sessionId = zoo_htonll(req->sessionId); + offset+=sizeof(req->sessionId); + + memcpy(&req->passwd_len,buf.data()+offset,sizeof(req->passwd_len)); + req->passwd_len = htonl(req->passwd_len); + offset+=sizeof(req->passwd_len); + + memcpy(req->passwd,buf.data()+offset,sizeof(req->passwd)); + offset+=sizeof(req->passwd); + + memcpy(&req->readOnly,buf.data()+offset,sizeof(req->readOnly)); + + if(testClientId.client_id==req->sessionId && + !memcmp(testClientId.passwd,req->passwd,sizeof(req->passwd))) + return req.release(); + // the request didn't match -- may not be a handshake request after all + + return 0; +} + +// ***************************************************************************** +// watcher action implementation +void activeWatcher(zhandle_t *zh, + int type, int state, const char *path,void* ctx) { + + if (zh == 0 || ctx == 0) + return; + + WatcherAction* action = (WatcherAction *)ctx; + + if (type == ZOO_SESSION_EVENT) { + if (state == ZOO_EXPIRED_SESSION_STATE) + action->onSessionExpired(zh); + else if(state == ZOO_CONNECTING_STATE) + action->onConnectionLost(zh); + else if(state == ZOO_CONNECTED_STATE) + action->onConnectionEstablished(zh); + } else if (type == ZOO_CHANGED_EVENT) + action->onNodeValueChanged(zh,path); + else if (type == ZOO_DELETED_EVENT) + action->onNodeDeleted(zh,path); + else if (type == ZOO_CHILD_EVENT) + action->onChildChanged(zh,path); + + // TODO: implement for the rest of the event types + + action->setWatcherTriggered(); +} + +SyncedBoolCondition WatcherAction::isWatcherTriggered() const { + return SyncedBoolCondition(triggered_,mx_); +} + +// a set of async completion signatures + +void asyncCompletion(int rc, ACL_vector *acl,Stat *stat, const void *data){ + assert("Completion data is NULL"&&data); + static_cast((void*)data)->aclCompl(rc,acl,stat); +} + +void asyncCompletion(int rc, const char *value, int len, const Stat *stat, + const void *data) { + assert("Completion data is NULL"&&data); + static_cast((void*)data)->dataCompl(rc,value,len,stat); +} + +void asyncCompletion(int rc, const Stat *stat, const void *data) { + assert("Completion data is NULL"&&data); + static_cast((void*)data)->statCompl(rc,stat); +} + +void asyncCompletion(int rc, const char *value, const void *data) { + assert("Completion data is NULL"&&data); + static_cast((void*)data)->stringCompl(rc,value); +} + +void asyncCompletion(int rc,const String_vector *strings, const void *data) { + assert("Completion data is NULL"&&data); + static_cast((void*)data)->stringsCompl(rc,strings); +} + +void asyncCompletion(int rc, const void *data) { + assert("Completion data is NULL"&&data); + static_cast((void*)data)->voidCompl(rc); +} + +// a predicate implementation +bool IOThreadStopped::operator()() const{ +#ifdef THREADED + adaptor_threads* adaptor=(adaptor_threads*)zh_->adaptor_priv; + return CheckedPthread::isTerminated(adaptor->io); +#else + assert("IOThreadStopped predicate is only for use with THREADED client" && + false); + return false; +#endif +} + +//****************************************************************************** +// +DECLARE_WRAPPER(int,flush_send_queue,(zhandle_t*zh, int timeout)) +{ + if(!Mock_flush_send_queue::mock_) + return CALL_REAL(flush_send_queue,(zh,timeout)); + return Mock_flush_send_queue::mock_->call(zh,timeout); +} + +Mock_flush_send_queue* Mock_flush_send_queue::mock_=0; + +//****************************************************************************** +// +DECLARE_WRAPPER(int32_t,get_xid,()) +{ + if(!Mock_get_xid::mock_) + return CALL_REAL(get_xid,()); + return Mock_get_xid::mock_->call(); +} + +Mock_get_xid* Mock_get_xid::mock_=0; + +//****************************************************************************** +// activateWatcher mock + +DECLARE_WRAPPER(void,activateWatcher,(zhandle_t *zh, watcher_registration_t* reg, int rc)) +{ + if(!Mock_activateWatcher::mock_){ + CALL_REAL(activateWatcher,(zh, reg,rc)); + }else{ + Mock_activateWatcher::mock_->call(zh, reg,rc); + } +} +Mock_activateWatcher* Mock_activateWatcher::mock_=0; + +class ActivateWatcherWrapper: public Mock_activateWatcher{ +public: + ActivateWatcherWrapper():ctx_(0),activated_(false){} + + virtual void call(zhandle_t *zh, watcher_registration_t* reg, int rc){ + CALL_REAL(activateWatcher,(zh, reg,rc)); + synchronized(mx_); + if(reg->context==ctx_){ + activated_=true; + ctx_=0; + } + } + + void setContext(void* ctx){ + synchronized(mx_); + ctx_=ctx; + activated_=false; + } + + SyncedBoolCondition isActivated() const{ + return SyncedBoolCondition(activated_,mx_); + } + mutable Mutex mx_; + void* ctx_; + bool activated_; +}; + +WatcherActivationTracker::WatcherActivationTracker(): + wrapper_(new ActivateWatcherWrapper) +{ +} + +WatcherActivationTracker::~WatcherActivationTracker(){ + delete wrapper_; +} + +void WatcherActivationTracker::track(void* ctx){ + wrapper_->setContext(ctx); +} + +SyncedBoolCondition WatcherActivationTracker::isWatcherActivated() const{ + return wrapper_->isActivated(); +} + +//****************************************************************************** +// +DECLARE_WRAPPER(void,deliverWatchers,(zhandle_t* zh,int type,int state, const char* path, watcher_object_list_t **list)) +{ + if(!Mock_deliverWatchers::mock_){ + CALL_REAL(deliverWatchers,(zh,type,state,path, list)); + }else{ + Mock_deliverWatchers::mock_->call(zh,type,state,path, list); + } +} + +Mock_deliverWatchers* Mock_deliverWatchers::mock_=0; + +struct RefCounterValue{ + RefCounterValue(zhandle_t* const& zh,int32_t expectedCounter,Mutex& mx): + zh_(zh),expectedCounter_(expectedCounter),mx_(mx){} + bool operator()() const{ + { + synchronized(mx_); + if(zh_==0) + return false; + } + return inc_ref_counter(zh_,0)==expectedCounter_; + } + zhandle_t* const& zh_; + int32_t expectedCounter_; + Mutex& mx_; +}; + + +class DeliverWatchersWrapper: public Mock_deliverWatchers{ +public: + DeliverWatchersWrapper(int type,int state,bool terminate): + type_(type),state_(state), + allDelivered_(false),terminate_(terminate),zh_(0),deliveryCounter_(0){} + virtual void call(zhandle_t* zh, int type, int state, + const char* path, watcher_object_list **list) { + { + synchronized(mx_); + zh_=zh; + allDelivered_=false; + } + CALL_REAL(deliverWatchers,(zh,type,state,path, list)); + if(type_==type && state_==state){ + if(terminate_){ + // prevent zhandle_t from being prematurely distroyed; + // this will also ensure that zookeeper_close() cleanups the + // thread resources by calling finish_adaptor() + inc_ref_counter(zh,1); + terminateZookeeperThreads(zh); + } + synchronized(mx_); + allDelivered_=true; + deliveryCounter_++; + } + } + SyncedBoolCondition isDelivered() const{ + if(terminate_){ + int i=ensureCondition(RefCounterValue(zh_,1,mx_),1000); + assert(i<1000); + } + return SyncedBoolCondition(allDelivered_,mx_); + } + void resetDeliveryCounter(){ + synchronized(mx_); + deliveryCounter_=0; + } + SyncedIntegerEqual deliveryCounterEquals(int expected) const{ + if(terminate_){ + int i=ensureCondition(RefCounterValue(zh_,1,mx_),1000); + assert(i<1000); + } + return SyncedIntegerEqual(deliveryCounter_,expected,mx_); + } + int type_; + int state_; + mutable Mutex mx_; + bool allDelivered_; + bool terminate_; + zhandle_t* zh_; + int deliveryCounter_; +}; + +WatcherDeliveryTracker::WatcherDeliveryTracker( + int type,int state,bool terminateCompletionThread): + deliveryWrapper_(new DeliverWatchersWrapper( + type,state,terminateCompletionThread)){ +} + +WatcherDeliveryTracker::~WatcherDeliveryTracker(){ + delete deliveryWrapper_; +} + +SyncedBoolCondition WatcherDeliveryTracker::isWatcherProcessingCompleted() const { + return deliveryWrapper_->isDelivered(); +} + +void WatcherDeliveryTracker::resetDeliveryCounter(){ + deliveryWrapper_->resetDeliveryCounter(); +} + +SyncedIntegerEqual WatcherDeliveryTracker::deliveryCounterEquals(int expected) const { + return deliveryWrapper_->deliveryCounterEquals(expected); +} + +//****************************************************************************** +// +string HandshakeResponse::toString() const { + string buf; + int32_t tmp=htonl(protocolVersion); + buf.append((char*)&tmp,sizeof(tmp)); + tmp=htonl(timeOut); + buf.append((char*)&tmp,sizeof(tmp)); + int64_t tmp64=zoo_htonll(sessionId); + buf.append((char*)&tmp64,sizeof(sessionId)); + tmp=htonl(passwd_len); + buf.append((char*)&tmp,sizeof(tmp)); + buf.append(passwd,sizeof(passwd)); + buf.append(&readOnly,sizeof(readOnly)); + // finally set the buffer length + tmp=htonl(buf.size()+sizeof(tmp)); + buf.insert(0,(char*)&tmp, sizeof(tmp)); + return buf; +} + +string ZooGetResponse::toString() const{ + oarchive* oa=create_buffer_oarchive(); + + ReplyHeader h = {xid_,1,ZOK}; + serialize_ReplyHeader(oa, "hdr", &h); + + GetDataResponse resp; + char buf[1024]; + assert("GetDataResponse is too long"&&data_.size()<=sizeof(buf)); + resp.data.len=data_.size(); + resp.data.buff=buf; + data_.copy(resp.data.buff, data_.size()); + resp.stat=stat_; + serialize_GetDataResponse(oa, "reply", &resp); + int32_t len=htonl(get_buffer_len(oa)); + string res((char*)&len,sizeof(len)); + res.append(get_buffer(oa),get_buffer_len(oa)); + + close_buffer_oarchive(&oa,1); + return res; +} + +string ZooStatResponse::toString() const{ + oarchive* oa=create_buffer_oarchive(); + + ReplyHeader h = {xid_,1,rc_}; + serialize_ReplyHeader(oa, "hdr", &h); + + SetDataResponse resp; + resp.stat=stat_; + serialize_SetDataResponse(oa, "reply", &resp); + int32_t len=htonl(get_buffer_len(oa)); + string res((char*)&len,sizeof(len)); + res.append(get_buffer(oa),get_buffer_len(oa)); + + close_buffer_oarchive(&oa,1); + return res; +} + +string ZooGetChildrenResponse::toString() const{ + oarchive* oa=create_buffer_oarchive(); + + ReplyHeader h = {xid_,1,rc_}; + serialize_ReplyHeader(oa, "hdr", &h); + + GetChildrenResponse resp; + // populate the string vector + allocate_String_vector(&resp.children,strings_.size()); + for(int i=0;i<(int)strings_.size();++i) + resp.children.data[i]=strdup(strings_[i].c_str()); + serialize_GetChildrenResponse(oa, "reply", &resp); + deallocate_GetChildrenResponse(&resp); + + int32_t len=htonl(get_buffer_len(oa)); + string res((char*)&len,sizeof(len)); + res.append(get_buffer(oa),get_buffer_len(oa)); + + close_buffer_oarchive(&oa,1); + return res; +} + +string ZNodeEvent::toString() const{ + oarchive* oa=create_buffer_oarchive(); + struct WatcherEvent evt = {type_,0,(char*)path_.c_str()}; + struct ReplyHeader h = {WATCHER_EVENT_XID,0,ZOK }; + + serialize_ReplyHeader(oa, "hdr", &h); + serialize_WatcherEvent(oa, "event", &evt); + + int32_t len=htonl(get_buffer_len(oa)); + string res((char*)&len,sizeof(len)); + res.append(get_buffer(oa),get_buffer_len(oa)); + + close_buffer_oarchive(&oa,1); + return res; +} + +string PingResponse::toString() const{ + oarchive* oa=create_buffer_oarchive(); + + ReplyHeader h = {PING_XID,1,ZOK}; + serialize_ReplyHeader(oa, "hdr", &h); + + int32_t len=htonl(get_buffer_len(oa)); + string res((char*)&len,sizeof(len)); + res.append(get_buffer(oa),get_buffer_len(oa)); + + close_buffer_oarchive(&oa,1); + return res; +} + +//****************************************************************************** +// Zookeeper server simulator +// +bool ZookeeperServer::hasMoreRecv() const{ + return recvHasMore.get()!=0 || connectionLost; +} + +ssize_t ZookeeperServer::callRecv(int s,void *buf,size_t len,int flags){ + if(connectionLost){ + recvReturnBuffer.erase(); + return 0; + } + // done transmitting the current buffer? + if(recvReturnBuffer.size()==0){ + synchronized(recvQMx); + if(recvQueue.empty()){ + recvErrno=EAGAIN; + return Mock_socket::callRecv(s,buf,len,flags); + } + --recvHasMore; + Element& el=recvQueue.front(); + if(el.first!=0){ + recvReturnBuffer=el.first->toString(); + delete el.first; + } + recvErrno=el.second; + recvQueue.pop_front(); + } + return Mock_socket::callRecv(s,buf,len,flags); +} + +void ZookeeperServer::onMessageReceived(const RequestHeader& rh, iarchive* ia){ + // no-op by default +} + +void ZookeeperServer::notifyBufferSent(const std::string& buffer){ + if(HandshakeRequest::isValid(buffer)){ + // could be a connect request + auto_ptr req(HandshakeRequest::parse(buffer)); + if(req.get()!=0){ + // handle the handshake + int64_t sessId=sessionExpired?req->sessionId+1:req->sessionId; + sessionExpired=false; + addRecvResponse(new HandshakeResponse(sessId)); + return; + } + // not a connect request -- fall thru + } + // parse the buffer to extract the request type and its xid + iarchive *ia=create_buffer_iarchive((char*)buffer.data(), buffer.size()); + RequestHeader rh; + deserialize_RequestHeader(ia,"hdr",&rh); + // notify the "server" a client request has arrived + if (rh.xid == -8) { + Element e = Element(new ZooStatResponse,0); + e.first->setXID(-8); + addRecvResponse(e); + close_buffer_iarchive(&ia); + return; + } else { + onMessageReceived(rh,ia); + } + close_buffer_iarchive(&ia); + if(rh.type==ZOO_CLOSE_OP){ + ++closeSent; + return; // no reply for close requests + } + // get the next response from the response queue and append it to the + // receive list + Element e; + { + synchronized(respQMx); + if(respQueue.empty()) + return; + e=respQueue.front(); + respQueue.pop_front(); + } + e.first->setXID(rh.xid); + addRecvResponse(e); +} + +void forceConnected(zhandle_t* zh){ + // simulate connected state + zh->state=ZOO_CONNECTED_STATE; + + // Simulate we're connected to the first host in our host list + zh->fd=ZookeeperServer::FD; + assert(zh->addrs.count > 0); + zh->addr_cur = zh->addrs.data[0]; + zh->addrs.next++; + + zh->input_buffer=0; + gettimeofday(&zh->last_recv,0); + gettimeofday(&zh->last_send,0); +} + +void terminateZookeeperThreads(zhandle_t* zh){ + // this will cause the zookeeper threads to terminate + zh->close_requested=1; +} diff --git a/src/c/tests/ZKMocks.h b/src/c/tests/ZKMocks.h new file mode 100644 index 00000000000..2717ded3087 --- /dev/null +++ b/src/c/tests/ZKMocks.h @@ -0,0 +1,511 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZKMOCKS_H_ +#define ZKMOCKS_H_ + +#include +#include "src/zk_adaptor.h" + +#include "Util.h" +#include "LibCMocks.h" +#include "MocksBase.h" + +// ***************************************************************************** +// sets internal zhandle_t members to certain values to simulate the client +// connected state. This function should only be used with the single-threaded +// Async API tests! +void forceConnected(zhandle_t* zh); + +/** + * Gracefully terminates zookeeper I/O and completion threads. + */ +void terminateZookeeperThreads(zhandle_t* zh); + +// ***************************************************************************** +// Abstract watcher action +struct SyncedBoolCondition; + +class WatcherAction{ +public: + WatcherAction():triggered_(false){} + virtual ~WatcherAction(){} + + virtual void onSessionExpired(zhandle_t*){} + virtual void onConnectionEstablished(zhandle_t*){} + virtual void onConnectionLost(zhandle_t*){} + virtual void onNodeValueChanged(zhandle_t*,const char* path){} + virtual void onNodeDeleted(zhandle_t*,const char* path){} + virtual void onChildChanged(zhandle_t*,const char* path){} + + SyncedBoolCondition isWatcherTriggered() const; + void setWatcherTriggered(){ + synchronized(mx_); + triggered_=true; + } + +protected: + mutable Mutex mx_; + bool triggered_; +}; +// zh->context is a pointer to a WatcherAction instance +// based on the event type and state, the watcher calls a specific watcher +// action method +void activeWatcher(zhandle_t *zh, int type, int state, const char *path,void* ctx); + +// ***************************************************************************** +// a set of async completion signatures +class AsyncCompletion{ +public: + virtual ~AsyncCompletion(){} + virtual void aclCompl(int rc, ACL_vector *acl,Stat *stat){} + virtual void dataCompl(int rc, const char *value, int len, const Stat *stat){} + virtual void statCompl(int rc, const Stat *stat){} + virtual void stringCompl(int rc, const char *value){} + virtual void stringsCompl(int rc,const String_vector *strings){} + virtual void voidCompl(int rc){} +}; +void asyncCompletion(int rc, ACL_vector *acl,Stat *stat, const void *data); +void asyncCompletion(int rc, const char *value, int len, const Stat *stat, + const void *data); +void asyncCompletion(int rc, const Stat *stat, const void *data); +void asyncCompletion(int rc, const char *value, const void *data); +void asyncCompletion(int rc,const String_vector *strings, const void *data); +void asyncCompletion(int rc, const void *data); + +// ***************************************************************************** +// some common predicates to use with ensureCondition(): +// checks if the connection is established +struct ClientConnected{ + ClientConnected(zhandle_t* zh):zh_(zh){} + bool operator()() const{ + return zoo_state(zh_)==ZOO_CONNECTED_STATE; + } + zhandle_t* zh_; +}; +// check in the session expired +struct SessionExpired{ + SessionExpired(zhandle_t* zh):zh_(zh){} + bool operator()() const{ + return zoo_state(zh_)==ZOO_EXPIRED_SESSION_STATE; + } + zhandle_t* zh_; +}; +// checks if the IO thread has stopped; CheckedPthread must be active +struct IOThreadStopped{ + IOThreadStopped(zhandle_t* zh):zh_(zh){} + bool operator()() const; + zhandle_t* zh_; +}; + +// a synchronized boolean condition +struct SyncedBoolCondition{ + SyncedBoolCondition(const bool& cond,Mutex& mx):cond_(cond),mx_(mx){} + bool operator()() const{ + synchronized(mx_); + return cond_; + } + const bool& cond_; + Mutex& mx_; +}; + +// a synchronized integer comparison +struct SyncedIntegerEqual{ + SyncedIntegerEqual(const int& cond,int expected,Mutex& mx): + cond_(cond),expected_(expected),mx_(mx){} + bool operator()() const{ + synchronized(mx_); + return cond_==expected_; + } + const int& cond_; + const int expected_; + Mutex& mx_; +}; + +// ***************************************************************************** +// make sure to call zookeeper_close() even in presence of exceptions +struct CloseFinally{ + CloseFinally(zhandle_t** zh):zh_(zh){} + ~CloseFinally(){ + execute(); + } + int execute(){ + if(zh_==0)return ZOK; + zhandle_t* lzh=*zh_; + *zh_=0; + disarm(); + return zookeeper_close(lzh); + } + void disarm(){zh_=0;} + zhandle_t ** zh_; +}; + +struct TestClientId: clientid_t{ + static const int SESSION_ID=123456789; + static const char* PASSWD; + TestClientId(){ + client_id=SESSION_ID; + memcpy(passwd,PASSWD,sizeof(passwd)); + } +}; + +// ***************************************************************************** +// special client id recongnized by the ZK server simulator +extern TestClientId testClientId; +#define TEST_CLIENT_ID &testClientId + +// ***************************************************************************** +// +struct HandshakeRequest: public connect_req +{ + static HandshakeRequest* parse(const std::string& buf); + static bool isValid(const std::string& buf){ + // this is just quick and dirty check before we go and parse the request + return buf.size()==HANDSHAKE_REQ_SIZE; + } +}; + +// ***************************************************************************** +// flush_send_queue +class Mock_flush_send_queue: public Mock +{ +public: + Mock_flush_send_queue():counter(0),callReturns(ZOK){mock_=this;} + ~Mock_flush_send_queue(){mock_=0;} + + int counter; + int callReturns; + virtual int call(zhandle_t* zh, int timeout){ + counter++; + return callReturns; + } + + static Mock_flush_send_queue* mock_; +}; + +// ***************************************************************************** +// get_xid +class Mock_get_xid: public Mock +{ +public: + static const int32_t XID=123456; + Mock_get_xid(int retValue=XID):callReturns(retValue){mock_=this;} + ~Mock_get_xid(){mock_=0;} + + int callReturns; + virtual int call(){ + return callReturns; + } + + static Mock_get_xid* mock_; +}; + +// ***************************************************************************** +// activateWatcher +class Mock_activateWatcher: public Mock{ +public: + Mock_activateWatcher(){mock_=this;} + virtual ~Mock_activateWatcher(){mock_=0;} + + virtual void call(zhandle_t *zh, watcher_registration_t* reg, int rc){} + static Mock_activateWatcher* mock_; +}; + +class ActivateWatcherWrapper; +class WatcherActivationTracker{ +public: + WatcherActivationTracker(); + ~WatcherActivationTracker(); + + void track(void* ctx); + SyncedBoolCondition isWatcherActivated() const; +private: + ActivateWatcherWrapper* wrapper_; +}; + +// ***************************************************************************** +// deliverWatchers +class Mock_deliverWatchers: public Mock{ +public: + Mock_deliverWatchers(){mock_=this;} + virtual ~Mock_deliverWatchers(){mock_=0;} + + virtual void call(zhandle_t* zh,int type,int state, const char* path, watcher_object_list **){} + static Mock_deliverWatchers* mock_; +}; + +class DeliverWatchersWrapper; +class WatcherDeliveryTracker{ +public: + // filters deliveries by state and type + WatcherDeliveryTracker(int type,int state,bool terminateCompletionThread=true); + ~WatcherDeliveryTracker(); + + // if the thread termination requested (see the ctor params) + // this function will wait for the I/O and completion threads to + // terminate before returning a SyncBoolCondition instance + SyncedBoolCondition isWatcherProcessingCompleted() const; + void resetDeliveryCounter(); + SyncedIntegerEqual deliveryCounterEquals(int expected) const; +private: + DeliverWatchersWrapper* deliveryWrapper_; +}; + +// ***************************************************************************** +// a zookeeper Stat wrapper +struct NodeStat: public Stat +{ + NodeStat(){ + czxid=0; + mzxid=0; + ctime=0; + mtime=0; + version=1; + cversion=0; + aversion=0; + ephemeralOwner=0; + } + NodeStat(const Stat& other){ + memcpy(this,&other,sizeof(*this)); + } +}; + +// ***************************************************************************** +// Abstract server Response +class Response +{ +public: + virtual ~Response(){} + + virtual void setXID(int32_t xid){} + // this method is used by the ZookeeperServer class to serialize + // the instance of Response + virtual std::string toString() const =0; +}; + +// ***************************************************************************** +// Handshake response +class HandshakeResponse: public Response +{ +public: + HandshakeResponse(int64_t sessId=1): + protocolVersion(1),timeOut(10000),sessionId(sessId), + passwd_len(sizeof(passwd)),readOnly(0) + { + memcpy(passwd,"1234567890123456",sizeof(passwd)); + } + int32_t protocolVersion; + int32_t timeOut; + int64_t sessionId; + int32_t passwd_len; + char passwd[16]; + char readOnly; + virtual std::string toString() const ; +}; + +// zoo_get() response +class ZooGetResponse: public Response +{ +public: + ZooGetResponse(const char* data, int len,int32_t xid=0,int rc=ZOK,const Stat& stat=NodeStat()) + :xid_(xid),data_(data,len),rc_(rc),stat_(stat) + { + } + virtual std::string toString() const; + virtual void setXID(int32_t xid) {xid_=xid;} + +private: + int32_t xid_; + std::string data_; + int rc_; + Stat stat_; +}; + +// zoo_exists(), zoo_set() response +class ZooStatResponse: public Response +{ +public: + ZooStatResponse(int32_t xid=0,int rc=ZOK,const Stat& stat=NodeStat()) + :xid_(xid),rc_(rc),stat_(stat) + { + } + virtual std::string toString() const; + virtual void setXID(int32_t xid) {xid_=xid;} + +private: + int32_t xid_; + int rc_; + Stat stat_; +}; + +// zoo_get_children() +class ZooGetChildrenResponse: public Response +{ +public: + typedef std::vector StringVector; + ZooGetChildrenResponse(const StringVector& v,int rc=ZOK): + xid_(0),strings_(v),rc_(rc) + { + } + + virtual std::string toString() const; + virtual void setXID(int32_t xid) {xid_=xid;} + + int32_t xid_; + StringVector strings_; + int rc_; +}; + +// PING response +class PingResponse: public Response +{ +public: + virtual std::string toString() const; +}; + +// watcher znode event +class ZNodeEvent: public Response +{ +public: + ZNodeEvent(int type,const char* path):type_(type),path_(path){} + + virtual std::string toString() const; + +private: + int type_; + std::string path_; +}; + +// **************************************************************************** +// Zookeeper server simulator + +class ZookeeperServer: public Mock_socket +{ +public: + ZookeeperServer(): + serverDownSkipCount_(-1),sessionExpired(false),connectionLost(false) + { + connectReturns=-1; + connectErrno=EWOULDBLOCK; + } + virtual ~ZookeeperServer(){ + clearRecvQueue(); + clearRespQueue(); + } + virtual int callClose(int fd){ + if(fd!=FD) + return LIBC_SYMBOLS.close(fd); + clearRecvQueue(); + clearRespQueue(); + return Mock_socket::callClose(fd); + } + // connection handling + // what to do when the handshake request comes in? + int serverDownSkipCount_; + // this will cause getsockopt(zh->fd,SOL_SOCKET,SO_ERROR,&error,&len) return + // a failure after skipCount dropped to zero, thus simulating a server down + // condition + // passing skipCount==-1 will make every connect attempt succeed + void setServerDown(int skipCount=0){ + serverDownSkipCount_=skipCount; + optvalSO_ERROR=0; + } + virtual void setSO_ERROR(void *optval,socklen_t len){ + if(serverDownSkipCount_!=-1){ + if(serverDownSkipCount_==0) + optvalSO_ERROR=ECONNREFUSED; + else + serverDownSkipCount_--; + } + Mock_socket::setSO_ERROR(optval,len); + } + + // this is a trigger that gets reset back to false + // a connect request will return a non-matching session id thus causing + // the client throw SESSION_EXPIRED + volatile bool sessionExpired; + void returnSessionExpired(){ sessionExpired=true; } + + // this is a one shot trigger that gets reset back to false + // next recv call will return 0 length, thus simulating a connecton loss + volatile bool connectionLost; + void setConnectionLost() {connectionLost=true;} + + // recv + // this queue is used for server responses: client's recv() system call + // returns next available message from this queue + typedef std::pair Element; + typedef std::deque ResponseList; + ResponseList recvQueue; + mutable Mutex recvQMx; + AtomicInt recvHasMore; + ZookeeperServer& addRecvResponse(Response* resp, int errnum=0){ + synchronized(recvQMx); + recvQueue.push_back(Element(resp,errnum)); + ++recvHasMore; + return *this; + } + ZookeeperServer& addRecvResponse(int errnum){ + synchronized(recvQMx); + recvQueue.push_back(Element(0,errnum)); + ++recvHasMore; + return *this; + } + ZookeeperServer& addRecvResponse(const Element& e){ + synchronized(recvQMx); + recvQueue.push_back(e); + ++recvHasMore; + return *this; + } + void clearRecvQueue(){ + synchronized(recvQMx); + recvHasMore=0; + for(unsigned i=0; i +#include +#include +#include +#include +#include + +ZooKeeperQuorumServer:: +ZooKeeperQuorumServer(uint32_t id, uint32_t numServers) : + id_(id), + numServers_(numServers) { + const char* root = getenv("ZKROOT"); + if (root == NULL) { + assert(!"Environment variable 'ZKROOT' is not set"); + } + root_ = root; + createConfigFile(); + createDataDirectory(); + start(); +} + +ZooKeeperQuorumServer:: +~ZooKeeperQuorumServer() { + stop(); +} + +std::string ZooKeeperQuorumServer:: +getHostPort() { + std::stringstream ss; + ss << "localhost:" << getClientPort(); + return ss.str(); +} + +uint32_t ZooKeeperQuorumServer:: +getClientPort() { + return CLIENT_PORT_BASE + id_; +} + +void ZooKeeperQuorumServer:: +start() { + std::string command = root_ + "/bin/zkServer.sh start " + + getConfigFileName(); + assert(system(command.c_str()) == 0); +} + +void ZooKeeperQuorumServer:: +stop() { + std::string command = root_ + "/bin/zkServer.sh stop " + + getConfigFileName(); + assert(system(command.c_str()) == 0); +} + +std::string ZooKeeperQuorumServer:: +getMode() { + char buf[1024]; + std::string result; + std::string command = root_ + "/bin/zkServer.sh status " + + getConfigFileName(); + FILE* output = popen(command.c_str(), "r"); + do { + if (fgets(buf, 1024, output) != NULL) { + result += buf; + } + } while (!feof(output)); + pclose(output); + if (result.find("Mode: leader") != std::string::npos) { + return "leader"; + } else if (result.find("Mode: follower") != std::string::npos) { + return "follower"; + } else { + printf("%s\n", result.c_str()); + return ""; + } +} + +bool ZooKeeperQuorumServer:: +isLeader() { + return getMode() == "leader"; +} + +bool ZooKeeperQuorumServer:: +isFollower() { + return getMode() == "follower"; +} + +void ZooKeeperQuorumServer:: +createConfigFile() { + std::string command = "mkdir -p " + root_ + "/build/test/test-cppunit/conf"; + assert(system(command.c_str()) == 0); + std::ofstream confFile; + std::stringstream ss; + ss << id_ << ".conf"; + std::string fileName = root_ + "/build/test/test-cppunit/conf/" + ss.str(); + confFile.open(fileName.c_str()); + confFile << "tickTime=2000\n"; + confFile << "clientPort=" << getClientPort() << "\n"; + confFile << "initLimit=5\n"; + confFile << "syncLimit=2\n"; + confFile << "dataDir=" << getDataDirectory() << "\n"; + for (int i = 0; i < numServers_; i++) { + confFile << getServerString(i) << "\n"; + } + confFile.close(); +} + +std::string ZooKeeperQuorumServer:: +getConfigFileName() { + std::stringstream ss; + ss << id_ << ".conf"; + return root_ + "/build/test/test-cppunit/conf/" + ss.str(); +} + +void ZooKeeperQuorumServer:: +createDataDirectory() { + std::string dataDirectory = getDataDirectory(); + std::string command = "rm -rf " + dataDirectory; + assert(system(command.c_str()) == 0); + command = "mkdir -p " + dataDirectory; + assert(system(command.c_str()) == 0); + std::ofstream myidFile; + std::string fileName = dataDirectory + "/myid"; + myidFile.open(fileName.c_str()); + myidFile << id_ << "\n"; + myidFile.close(); + setenv("ZOO_LOG_DIR", dataDirectory.c_str(), true); +} + +std::string ZooKeeperQuorumServer:: +getServerString() { + return getServerString(id_); +} + +std::string ZooKeeperQuorumServer:: +getServerString(uint32_t id) { + std::stringstream ss; + ss << "server." << id << "=localhost:" << SERVER_PORT_BASE + id << + ":" << ELECTION_PORT_BASE + id << ":participant;localhost:" << + CLIENT_PORT_BASE + id; + return ss.str(); +} + +std::string ZooKeeperQuorumServer:: +getDataDirectory() { + std::stringstream ss; + ss << "data" << id_; + return root_ + "/build/test/test-cppunit/" + ss.str(); +} + +std::vector ZooKeeperQuorumServer:: +getCluster(uint32_t numServers) { + std::vector cluster; + for (int i = 0; i < numServers; i++) { + cluster.push_back(new ZooKeeperQuorumServer(i, numServers)); + } + + // Wait until all the servers start, and fail if they don't start within 10 + // seconds. + for (int i = 0; i < 10; i++) { + int j = 0; + for (; j < cluster.size(); j++) { + if (cluster[j]->getMode() == "") { + // The server hasn't started. + sleep(1); + break; + } + } + if (j == cluster.size()) { + return cluster; + } + } + assert(!"The cluster didn't start for 10 seconds"); +} diff --git a/src/c/tests/ZooKeeperQuorumServer.h b/src/c/tests/ZooKeeperQuorumServer.h new file mode 100644 index 00000000000..aa8b7ccf6f9 --- /dev/null +++ b/src/c/tests/ZooKeeperQuorumServer.h @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +#ifndef ZOOKEEPER_QUORUM_SERVER_H +#define ZOOKEEPER_QUORUM_SERVER_H + +#include +#include +#include + +class ZooKeeperQuorumServer { + public: + ~ZooKeeperQuorumServer(); + static std::vector getCluster(uint32_t numServers); + std::string getHostPort(); + uint32_t getClientPort(); + void start(); + void stop(); + bool isLeader(); + bool isFollower(); + std::string getServerString(); + + private: + ZooKeeperQuorumServer(); + ZooKeeperQuorumServer(uint32_t id, uint32_t numServers); + ZooKeeperQuorumServer(const ZooKeeperQuorumServer& that); + const ZooKeeperQuorumServer& operator=(const ZooKeeperQuorumServer& that); + void createConfigFile(); + std::string getConfigFileName(); + void createDataDirectory(); + std::string getDataDirectory(); + static std::string getServerString(uint32_t id); + std::string getMode(); + + static const uint32_t SERVER_PORT_BASE = 2000; + static const uint32_t ELECTION_PORT_BASE = 3000; + static const uint32_t CLIENT_PORT_BASE = 4000; + + uint32_t numServers_; + uint32_t id_; + std::string root_; +}; + +#endif // ZOOKEEPER_QUORUM_SERVER_H diff --git a/src/c/tests/quorum.cfg b/src/c/tests/quorum.cfg new file mode 100644 index 00000000000..aa2dd8ce8c0 --- /dev/null +++ b/src/c/tests/quorum.cfg @@ -0,0 +1,8 @@ +tickTime=500 +initLimit=10 +syncLimit=5 +dataDir=/tmp/zkdata +clientPort=22181 +server.1=localhost:22881:33881 +server.2=localhost:22882:33882 +server.3=localhost:22883:33883 diff --git a/src/c/tests/wrappers-mt.opt b/src/c/tests/wrappers-mt.opt new file mode 100644 index 00000000000..01046fbd84a --- /dev/null +++ b/src/c/tests/wrappers-mt.opt @@ -0,0 +1,3 @@ +-Wl,--wrap -Wl,pthread_mutex_lock +-Wl,--wrap -Wl,pthread_mutex_trylock +-Wl,--wrap -Wl,pthread_mutex_unlock diff --git a/src/c/tests/wrappers.opt b/src/c/tests/wrappers.opt new file mode 100644 index 00000000000..bce192fcfa9 --- /dev/null +++ b/src/c/tests/wrappers.opt @@ -0,0 +1,7 @@ +-Wl,--wrap -Wl,calloc +-Wl,--wrap -Wl,free +-Wl,--wrap -Wl,flush_send_queue +-Wl,--wrap -Wl,get_xid +-Wl,--wrap -Wl,deliverWatchers +-Wl,--wrap -Wl,activateWatcher +-Wl,--wrap -Wl,realloc diff --git a/src/c/tests/zkServer.sh b/src/c/tests/zkServer.sh new file mode 100755 index 00000000000..33ab152b1d6 --- /dev/null +++ b/src/c/tests/zkServer.sh @@ -0,0 +1,178 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is the port where zookeeper server runs on. +ZOOPORT=22181 + +if [ "x$1" == "x" ] +then + echo "USAGE: $0 startClean|start|startReadOnly|stop hostPorts" + exit 2 +fi + +case "`uname`" in + CYGWIN*) cygwin=true ;; + *) cygwin=false ;; +esac + +if [ "x$1" == "xstartClean" ] +then + if [ "x${base_dir}" == "x" ] + then + rm -rf /tmp/zkdata + else + rm -rf "${base_dir}/build/tmp" + fi +fi + +if $cygwin +then + # cygwin has a "kill" in the shell itself, gets confused + KILL=/bin/kill +else + KILL=kill +fi + +# Make sure nothing is left over from before +if [ -r "/tmp/zk.pid" ] +then +pid=`cat /tmp/zk.pid` +$KILL -9 $pid +rm -f /tmp/zk.pid +fi + +if [ -r "${base_dir}/build/tmp/zk.pid" ] +then +pid=`cat "${base_dir}/build/tmp/zk.pid"` +$KILL -9 $pid +rm -f "${base_dir}/build/tmp/zk.pid" +fi + +# [ZOOKEEPER-820] If lsof command is present, look for a process listening +# on ZOOPORT and kill it. +which lsof &> /dev/null +if [ $? -eq 0 ] +then + pid=`lsof -i :$ZOOPORT | grep LISTEN | awk '{print $2}'` + if [ -n "$pid" ] + then + $KILL -9 $pid + fi +fi + +if [ "x${base_dir}" == "x" ] +then +zk_base="../../" +else +zk_base="${base_dir}" +fi + +CLASSPATH="$CLASSPATH:${zk_base}/build/classes" +CLASSPATH="$CLASSPATH:${zk_base}/conf" + +for i in "${zk_base}"/build/lib/*.jar +do + CLASSPATH="$CLASSPATH:$i" +done + +for i in "${zk_base}"/src/java/lib/*.jar +do + CLASSPATH="$CLASSPATH:$i" +done + +CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover.jar" + +if $cygwin +then + CLASSPATH=`cygpath -wp "$CLASSPATH"` +fi + +case $1 in +start|startClean) + if [ "x${base_dir}" == "x" ] + then + mkdir -p /tmp/zkdata + java -cp "$CLASSPATH" org.apache.zookeeper.server.ZooKeeperServerMain $ZOOPORT /tmp/zkdata 3000 $ZKMAXCNXNS &> /tmp/zk.log & + pid=$! + echo -n $! > /tmp/zk.pid + else + mkdir -p "${base_dir}/build/tmp/zkdata" + java -cp "$CLASSPATH" org.apache.zookeeper.server.ZooKeeperServerMain $ZOOPORT "${base_dir}/build/tmp/zkdata" 3000 $ZKMAXCNXNS &> "${base_dir}/build/tmp/zk.log" & + pid=$! + echo -n $pid > "${base_dir}/build/tmp/zk.pid" + fi + + # wait max 120 seconds for server to be ready to server clients + # this handles testing on slow hosts + success=false + for i in {1..120} + do + if ps -p $pid > /dev/null + then + java -cp "$CLASSPATH" org.apache.zookeeper.ZooKeeperMain -server localhost:$ZOOPORT ls / > /dev/null 2>&1 + if [ $? -ne 0 ] + then + # server not up yet - wait + sleep 1 + else + # server is up and serving client connections + success=true + break + fi + else + # server died - exit now + echo -n " ZooKeeper server process failed" + break + fi + done + + if $success + then + ## in case for debug, but generally don't use as it messes up the + ## console test output + echo -n " ZooKeeper server started" + else + echo -n " ZooKeeper server NOT started" + fi + + ;; +startReadOnly) + if [ "x${base_dir}" == "x" ] + then + echo "this target is for unit tests only" + exit 2 + else + mkdir -p /tmp/zkdata + rm -f /tmp/zkdata/myid && echo 1 > /tmp/zkdata/myid + + # force read-only mode + java -cp "$CLASSPATH" -Dreadonlymode.enabled=true org.apache.zookeeper.server.quorum.QuorumPeerMain ${base_dir}/src/c/tests/quorum.cfg &> "${base_dir}/build/tmp/zk.log" & + pid=$! + echo -n $pid > "${base_dir}/build/tmp/zk.pid" + sleep 3 # wait until read-only server is up + fi + + ;; +stop) + # Already killed above + ;; +*) + echo "Unknown command " + $1 + exit 2 +esac + diff --git a/src/c/zookeeper-vs2013.sln b/src/c/zookeeper-vs2013.sln new file mode 100644 index 00000000000..7d6499bed6c --- /dev/null +++ b/src/c/zookeeper-vs2013.sln @@ -0,0 +1,37 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30110.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zookeeper", "zookeeper.vcxproj", "{5754FB2B-5EA5-4988-851D-908CA533A626}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cli", "cli.vcxproj", "{F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5754FB2B-5EA5-4988-851D-908CA533A626}.Debug|Win32.ActiveCfg = Debug|Win32 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Debug|Win32.Build.0 = Debug|Win32 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Debug|x64.ActiveCfg = Debug|x64 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Debug|x64.Build.0 = Debug|x64 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Release|Win32.ActiveCfg = Release|Win32 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Release|Win32.Build.0 = Release|Win32 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Release|x64.ActiveCfg = Release|x64 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Release|x64.Build.0 = Release|x64 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Debug|Win32.ActiveCfg = Debug|Win32 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Debug|Win32.Build.0 = Debug|Win32 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Debug|x64.ActiveCfg = Debug|x64 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Debug|x64.Build.0 = Debug|x64 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Release|Win32.ActiveCfg = Release|Win32 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Release|Win32.Build.0 = Release|Win32 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Release|x64.ActiveCfg = Release|x64 + {F267C55D-E02C-4BAF-A246-0AA58E8FE4A6}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/c/zookeeper.sln b/src/c/zookeeper.sln new file mode 100644 index 00000000000..42f41c95264 --- /dev/null +++ b/src/c/zookeeper.sln @@ -0,0 +1,25 @@ +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zookeeper", "zookeeper.vcproj", "{5754FB2B-5EA5-4988-851D-908CA533A626}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Cli", "Cli.vcproj", "{050228F9-070F-4806-A2B5-E6B95D8EC4AF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5754FB2B-5EA5-4988-851D-908CA533A626}.Debug|Win32.ActiveCfg = Debug|Win32 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Debug|Win32.Build.0 = Debug|Win32 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Release|Win32.ActiveCfg = Release|Win32 + {5754FB2B-5EA5-4988-851D-908CA533A626}.Release|Win32.Build.0 = Release|Win32 + {050228F9-070F-4806-A2B5-E6B95D8EC4AF}.Debug|Win32.ActiveCfg = Debug|Win32 + {050228F9-070F-4806-A2B5-E6B95D8EC4AF}.Debug|Win32.Build.0 = Debug|Win32 + {050228F9-070F-4806-A2B5-E6B95D8EC4AF}.Release|Win32.ActiveCfg = Release|Win32 + {050228F9-070F-4806-A2B5-E6B95D8EC4AF}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/c/zookeeper.vcproj b/src/c/zookeeper.vcproj new file mode 100644 index 00000000000..6425fcd64ce --- /dev/null +++ b/src/c/zookeeper.vcproj @@ -0,0 +1,308 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/c/zookeeper.vcxproj b/src/c/zookeeper.vcxproj new file mode 100644 index 00000000000..be4ad9aba39 --- /dev/null +++ b/src/c/zookeeper.vcxproj @@ -0,0 +1,196 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {5754FB2B-5EA5-4988-851D-908CA533A626} + zookeeper + Win32Proj + + + + DynamicLibrary + v120 + + + DynamicLibrary + v120 + + + DynamicLibrary + v120 + MultiByte + + + DynamicLibrary + v120 + MultiByte + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.61030.0 + + + $(ProjectName) + false + + + $(ProjectName) + false + + + true + + + $(ProjectName) + true + + + + Disabled + ./include;./generated;./hashtable;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;ZOOKEEPER_EXPORTS;DLL_EXPORT;THREADED;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + Level3 + EditAndContinue + CompileAsC + + + ws2_32.lib;%(AdditionalDependencies) + true + Windows + false + + MachineX86 + + + + + Disabled + ./include;./generated;./hashtable;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;ZOOKEEPER_EXPORTS;DLL_EXPORT;THREADED;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + ProgramDatabase + CompileAsC + + + ws2_32.lib;%(AdditionalDependencies) + true + Windows + false + + + + + + + ./include;./generated;./hashtable;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;ZOOKEEPER_EXPORTS;DLL_EXPORT;THREADED;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + ProgramDatabase + CompileAsC + + + WS2_32.lib;%(AdditionalDependencies) + true + Windows + true + true + MachineX86 + $(OutDir)\$(TargetName).lib + + + + + ./include;./generated;./hashtable;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;ZOOKEEPER_EXPORTS;DLL_EXPORT;THREADED;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Level3 + ProgramDatabase + CompileAsC + NoListing + + + WS2_32.lib;%(AdditionalDependencies) + true + Windows + true + true + $(OutDir)\$(TargetName).lib + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/c/zookeeper.vcxproj.filters b/src/c/zookeeper.vcxproj.filters new file mode 100644 index 00000000000..a373e802993 --- /dev/null +++ b/src/c/zookeeper.vcxproj.filters @@ -0,0 +1,96 @@ + + + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Header Files + + + Source Files + + + \ No newline at end of file diff --git a/src/contrib/build-contrib.xml b/src/contrib/build-contrib.xml new file mode 100644 index 00000000000..4bbdbc936e6 --- /dev/null +++ b/src/contrib/build-contrib.xml @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/build.xml b/src/contrib/build.xml new file mode 100644 index 00000000000..435d4bc24e6 --- /dev/null +++ b/src/contrib/build.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/fatjar/README.txt b/src/contrib/fatjar/README.txt new file mode 100644 index 00000000000..f8027ae8c9e --- /dev/null +++ b/src/contrib/fatjar/README.txt @@ -0,0 +1,2 @@ +This package contains build to create a fat zookeeper jar. You need to run ant to create the fat jar. +To run the fatjar you can use. java -jar zoookeeper-*fatjar.jar diff --git a/src/contrib/fatjar/build.xml b/src/contrib/fatjar/build.xml new file mode 100644 index 00000000000..bd3d3fd2563 --- /dev/null +++ b/src/contrib/fatjar/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/fatjar/conf/mainClasses b/src/contrib/fatjar/conf/mainClasses new file mode 100644 index 00000000000..2b0fc83f468 --- /dev/null +++ b/src/contrib/fatjar/conf/mainClasses @@ -0,0 +1,10 @@ +::Client Commands +client:org.apache.zookeeper.ZooKeeperMain:Client shell to ZooKeeper +::Server Commands +server:org.apache.zookeeper.server.quorum.QuorumPeerMain:Start ZooKeeper server +::Test Commands +generateLoad:org.apache.zookeeper.test.system.GenerateLoad:A distributed load generator for testing +quorumBench:org.apache.zookeeper.server.QuorumBenchmark:A benchmark of just the quorum protocol +abBench:org.apache.zookeeper.server.quorum.AtomicBroadcastBenchmark:A benchmark of just the atomic broadcast +ic:org.apache.zookeeper.test.system.InstanceContainer:A container that will instantiate classes as directed by an instance manager +systest:org.apache.zookeeper.test.system.BaseSysTest:Start system test diff --git a/src/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java b/src/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java new file mode 100644 index 00000000000..24f81990267 --- /dev/null +++ b/src/contrib/fatjar/src/java/org/apache/zookeeper/util/FatJarMain.java @@ -0,0 +1,120 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * This is a generic Main class that is completely driven by the + * /mainClasses resource on the class path. This resource has the + * format: + *

+ * cmd:mainClass:Description
+ * 
+ * Any lines starting with # will be skipped + * + */ +public class FatJarMain { + static HashMap cmds = new HashMap(); + static ArrayList order = new ArrayList(); + + /** + * @param args the first parameter of args will be used as an + * index into the /mainClasses resource. The rest will be passed + * to the mainClass to run. + * @throws IOException + * @throws ClassNotFoundException + * @throws NoSuchMethodException + * @throws SecurityException + * @throws IllegalAccessException + * @throws IllegalArgumentException + */ + public static void main(String[] args) throws IOException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException { + InputStream is = FatJarMain.class.getResourceAsStream("/mainClasses"); + if (is == null) { + System.err.println("Couldn't find /mainClasses in classpath."); + System.exit(3); + } + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line; + while ((line = br.readLine()) != null) { + String parts[] = line.split(":", 3); + if (parts.length != 3 || (parts[0].length() > 0 && parts[0].charAt(0) == '#')) { + continue; + } + if (parts[0].length() > 0) { + cmds.put(parts[0], new Cmd(parts[0], parts[1], parts[2])); + // We use the order array to preserve the order of the commands + // for help. The hashmap will not preserver order. (It may be overkill.) + order.add(parts[0]); + } else { + // Just put the description in + order.add(parts[2]); + } + } + if (args.length == 0) { + doHelp(); + return; + } + Cmd cmd = cmds.get(args[0]); + if (cmd == null) { + doHelp(); + return; + } + Class clazz = Class.forName(cmd.clazz); + Method main = clazz.getMethod("main", String[].class); + String newArgs[] = new String[args.length - 1]; + System.arraycopy(args, 1, newArgs, 0, newArgs.length); + try { + main.invoke(null, (Object) newArgs); + } catch (InvocationTargetException e) { + if (e.getCause() != null) { + e.getCause().printStackTrace(); + } else { + e.printStackTrace(); + } + } + } + + private static void doHelp() { + System.err.println("USAGE: FatJarMain cmd args"); + System.err.println("Available cmds:"); + for (String c : order) { + Cmd cmd = cmds.get(c); + if (cmd != null) { + System.err.println(" " + c + " " + cmd.desc); + } else { + System.err.println(c); + } + } + System.exit(2); + } + + static class Cmd { + String cmd; + String clazz; + String desc; + Cmd(String cmd, String clazz, String desc) { + this.cmd = cmd; + this.clazz = clazz; + this.desc = desc; + } + } + +} diff --git a/src/contrib/huebrowser/README b/src/contrib/huebrowser/README new file mode 100644 index 00000000000..c03ea90fdd7 --- /dev/null +++ b/src/contrib/huebrowser/README @@ -0,0 +1,62 @@ + +ZooKeeper Browser - Hue Application +=================================== + +The ZooKeeper Browser application allows you to see how the cluster nodes are working and also allows you to do CRUD operations on the znode hierarchy. + +Requirements +------------ + +Hue-1.0: + * http://github.com/downloads/cloudera/hue/hue-1.0.tgz + * http://github.com/downloads/cloudera/hue/release-notes-1.0.html + +ZooKeeper REST gateway: + * available as contrib: contrib/rest + +How to install? +--------------- + +First of all you need to install Hue 1.0 release: + + * http://archive.cloudera.com/cdh/3/hue/sdk/sdk.html + * http://github.com/cloudera/hue/tree/release-1.0 + +After you finish the previous step you should copy the zkui/ folder to apps/ and register the new application: + + * $ ./build/env/bin/python tools/app_reg/app_reg.py --install apps/zkui + * $ ./build/env/bin/python tools/app_reg/app_reg.py --list 2>&1 | grep zkui + zkui 0.1 /Users/philip/src/hue/apps/zkui + + +And restart the Hue application server. + +Configuration +------------- + +Edit zkui/src/zkui/settings.py: + +CLUSTERS = [{ + 'nice_name': 'Default', + 'hostport': 'localhost:2181,localhost:2182,localhost:2183', + 'rest_gateway': 'http://localhost:9998' + }, { + # ... and more clusters + } +] + +What is Hue? +------------ + +Wiki: http://wiki.github.com/cloudera/hue/ +Main Repo: http://github.com/cloudera/hue + +Hue is both a web UI for Hadoop and a framework to create interactive web applications. It features a FileBrowser for accessing HDFS, JobSub and JobBrowser applications for submitting and viewing MapReduce jobs, a Beeswax application for interacting with Hive. On top of that, the web frontend is mostly built from declarative widgets that require no JavaScript and are easy to learn. + +What is ZooKeeper? +------------------ + +http://zookeeper.apache.org/ + +ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed. + diff --git a/src/contrib/huebrowser/zkui/Makefile b/src/contrib/huebrowser/zkui/Makefile new file mode 100644 index 00000000000..9c22d1c22bc --- /dev/null +++ b/src/contrib/huebrowser/zkui/Makefile @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ifeq ($(ROOT),) + $(error "Error: Expect the environment variable $$ROOT to point to the Desktop installation") +endif + +include $(ROOT)/Makefile.sdk diff --git a/src/contrib/huebrowser/zkui/setup.py b/src/contrib/huebrowser/zkui/setup.py new file mode 100644 index 00000000000..68d1352ca2c --- /dev/null +++ b/src/contrib/huebrowser/zkui/setup.py @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from setuptools import setup, find_packages +import os + +def expand_package_data(src_dirs, strip=""): + ret = [] + for src_dir in src_dirs: + for path, dnames, fnames in os.walk(src_dir): + for fname in fnames: + ret.append(os.path.join(path, fname).replace(strip, "")) + return ret + +os.chdir(os.path.dirname(os.path.abspath(__file__))) +setup( + name = "zkui", + version = "0.1", + url = 'http://zookeeper.apache.org/', + description = 'ZooKeeper Browser', + packages = find_packages('src'), + package_dir = {'': 'src'}, + install_requires = ['setuptools', 'desktop'], + entry_points = { 'desktop.sdk.application': 'zkui=zkui' }, + zip_safe = False, + package_data = { + # Include static resources. Package_data doesn't + # deal well with directory globs, so we enumerate + # the files manually. + 'zkui': expand_package_data( + ["src/zkui/templates", "src/zkui/static"], + "src/zkui/") + } +) diff --git a/src/contrib/huebrowser/zkui/src/zkui/__init__.py b/src/contrib/huebrowser/zkui/src/zkui/__init__.py new file mode 100644 index 00000000000..eccc8816c1d --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/src/contrib/huebrowser/zkui/src/zkui/forms.py b/src/contrib/huebrowser/zkui/src/zkui/forms.py new file mode 100644 index 00000000000..6b1f178fb9d --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/forms.py @@ -0,0 +1,29 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django import forms +from django.forms.widgets import Textarea, HiddenInput + +class CreateZNodeForm(forms.Form): + name = forms.CharField(max_length=64) + data = forms.CharField(required=False, widget=Textarea) + sequence = forms.BooleanField(required=False) + +class EditZNodeForm(forms.Form): + data = forms.CharField(required=False, widget=Textarea) + version = forms.IntegerField(required=False, widget=HiddenInput) + + diff --git a/src/contrib/huebrowser/zkui/src/zkui/models.py b/src/contrib/huebrowser/zkui/src/zkui/models.py new file mode 100644 index 00000000000..a46696b6dc2 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/models.py @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + diff --git a/src/contrib/huebrowser/zkui/src/zkui/rest.py b/src/contrib/huebrowser/zkui/src/zkui/rest.py new file mode 100644 index 00000000000..e4874a1ec81 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/rest.py @@ -0,0 +1,230 @@ + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import urllib2 +import urllib +import simplejson + +from contextlib import contextmanager + +class RequestWithMethod(urllib2.Request): + """ Request class that know how to set the method name """ + def __init__(self, *args, **kwargs): + urllib2.Request.__init__(self, *args, **kwargs) + self._method = None + + def get_method(self): + return self._method or \ + urllib2.Request.get_method(self) + + def set_method(self, method): + self._method = method + +class ZooKeeper(object): + + class Error(Exception): pass + + class NotFound(Error): pass + + class ZNodeExists(Error): pass + + class InvalidSession(Error): pass + + class WrongVersion(Error): pass + + def __init__(self, uri = 'http://localhost:9998'): + self._base = uri + self._session = None + + def start_session(self, expire=5, id=None): + """ Create a session and return the ID """ + if id is None: + url = "%s/sessions/v1/?op=create&expire=%d" % (self._base, expire) + self._session = self._do_post(url)['id'] + else: + self._session = id + return self._session + + def close_session(self): + """ Close the session on the server """ + if self._session is not None: + url = '%s/sessions/v1/%s' % (self._base, self._session) + self._do_delete(url) + self._session = None + + def heartbeat(self): + """ Send a heartbeat request. This is needed in order to keep a session alive """ + if self._session is not None: + url = '%s/sessions/v1/%s' % (self._base, self._session) + self._do_put(url, '') + + @contextmanager + def session(self, *args, **kwargs): + """ Session handling using a context manager """ + yield self.start_session(*args, **kwargs) + self.close_session() + + def get(self, path): + """ Get a node """ + url = "%s/znodes/v1%s" % (self._base, path) + return self._do_get(url) + + def get_children(self, path): + """ Get all the children for a given path. This function creates a generator """ + for child_path in self.get_children_paths(path, uris=True): + try: + yield self._do_get(child_path) + except ZooKeeper.NotFound: + continue + + def get_children_paths(self, path, uris=False): + """ Get the paths for children nodes """ + url = "%s/znodes/v1%s?view=children" % (self._base, path) + resp = self._do_get(url) + for child in resp.get('children', []): + yield child if not uris else resp['child_uri_template']\ + .replace('{child}', urllib2.quote(child)) + + def create(self, path, data=None, sequence=False, ephemeral=False): + """ Create a new node. By default this call creates a persistent znode. + + You can also create an ephemeral or a sequential znode. + """ + ri = path.rindex('/') + head, name = path[:ri+1], path[ri+1:] + if head != '/': head = head[:-1] + + flags = { + 'null': 'true' if data is None else 'false', + 'ephemeral': 'true' if ephemeral else 'false', + 'sequence': 'true' if sequence else 'false' + } + if ephemeral: + if self._session: + flags['session'] = self._session + else: + raise ZooKeeper.Error, 'You need a session '\ + 'to create an ephemeral node' + flags = urllib.urlencode(flags) + + url = "%s/znodes/v1%s?op=create&name=%s&%s" % \ + (self._base, head, name, flags) + + return self._do_post(url, data) + + def set(self, path, data=None, version=-1, null=False): + """ Set the value of node """ + url = "%s/znodes/v1%s?%s" % (self._base, path, \ + urllib.urlencode({ + 'version': version, + 'null': 'true' if null else 'false' + })) + return self._do_put(url, data) + + def delete(self, path, version=-1): + """ Delete a znode """ + if type(path) is list: + map(lambda el: self.delete(el, version), path) + return + + url = '%s/znodes/v1%s?%s' % (self._base, path, \ + urllib.urlencode({ + 'version':version + })) + try: + return self._do_delete(url) + except urllib2.HTTPError, e: + if e.code == 412: + raise ZooKeeper.WrongVersion(path) + elif e.code == 404: + raise ZooKeeper.NotFound(path) + raise + + def recursive_delete(self, path): + """ Delete all the nodes from the tree """ + for child in self.get_children_paths(path): + fp = ("%s/%s" % (path, child)).replace('//', '/') + self.recursive_delete(fp) + self.delete(path) + + def exists(self, path): + """ Do a znode exists """ + try: + self.get(path) + return True + except ZooKeeper.NotFound: + return False + + def _do_get(self, uri): + """ Send a GET request and convert errors to exceptions """ + try: + req = urllib2.urlopen(uri) + resp = simplejson.load(req) + + if 'Error' in resp: + raise ZooKeeper.Error(resp['Error']) + + return resp + except urllib2.HTTPError, e: + if e.code == 404: + raise ZooKeeper.NotFound(uri) + raise + + def _do_post(self, uri, data=None): + """ Send a POST request and convert errors to exceptions """ + try: + req = urllib2.Request(uri, {}) + req.add_header('Content-Type', 'application/octet-stream') + if data is not None: + req.add_data(data) + + resp = simplejson.load(urllib2.urlopen(req)) + if 'Error' in resp: + raise ZooKeeper.Error(resp['Error']) + return resp + + except urllib2.HTTPError, e: + if e.code == 201: + return True + elif e.code == 409: + raise ZooKeeper.ZNodeExists(uri) + elif e.code == 401: + raise ZooKeeper.InvalidSession(uri) + raise + + def _do_delete(self, uri): + """ Send a DELETE request """ + req = RequestWithMethod(uri) + req.set_method('DELETE') + req.add_header('Content-Type', 'application/octet-stream') + return urllib2.urlopen(req).read() + + def _do_put(self, uri, data): + """ Send a PUT request """ + try: + req = RequestWithMethod(uri) + req.set_method('PUT') + req.add_header('Content-Type', 'application/octet-stream') + if data is not None: + req.add_data(data) + + return urllib2.urlopen(req).read() + except urllib2.HTTPError, e: + if e.code == 412: # precondition failed + raise ZooKeeper.WrongVersion(uri) + raise + diff --git a/src/contrib/huebrowser/zkui/src/zkui/settings.py b/src/contrib/huebrowser/zkui/src/zkui/settings.py new file mode 100644 index 00000000000..844c6952da8 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/settings.py @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DJANGO_APPS = [ "zkui" ] +NICE_NAME = "ZooKeeper Browser" +REQUIRES_HADOOP = False + +CLUSTERS = [{ + 'nice_name': 'Default', + 'hostport': 'localhost:2181,localhost:2182,localhost:2183', + 'rest_gateway': 'http://localhost:9998' + } +] + +DEPENDER_PACKAGE_YMLS = [ + "src/zkui/static/js/package.yml", +] diff --git a/src/contrib/huebrowser/zkui/src/zkui/static/art/line_icons.png b/src/contrib/huebrowser/zkui/src/zkui/static/art/line_icons.png new file mode 100644 index 00000000000..1da4a294b34 Binary files /dev/null and b/src/contrib/huebrowser/zkui/src/zkui/static/art/line_icons.png differ diff --git a/src/contrib/huebrowser/zkui/src/zkui/static/art/zkui.png b/src/contrib/huebrowser/zkui/src/zkui/static/art/zkui.png new file mode 100644 index 00000000000..cb40df3dd55 Binary files /dev/null and b/src/contrib/huebrowser/zkui/src/zkui/static/art/zkui.png differ diff --git a/src/contrib/huebrowser/zkui/src/zkui/static/bootstrap.js b/src/contrib/huebrowser/zkui/src/zkui/static/bootstrap.js new file mode 100644 index 00000000000..7143c0cf861 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/static/bootstrap.js @@ -0,0 +1,32 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +CCS.Desktop.register({ + Zkui: { + name: 'ZooKeeper Browser', + css: '/zkui/static/css/zkui.css', + require: ['Zkui'], + launch: function (path, options) { + return new Zkui(path || '/zkui/', options); + }, + menu: { + id: 'ccs-zkui-menu', + img: { + src: '/zkui/static/art/zkui.png' + } + }, + help: '/help/zkui/' + } + }); diff --git a/src/contrib/huebrowser/zkui/src/zkui/static/css/zkui.css b/src/contrib/huebrowser/zkui/src/zkui/static/css/zkui.css new file mode 100644 index 00000000000..cd9c5dfaf21 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/static/css/zkui.css @@ -0,0 +1,56 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +.zkui img.zkui_icon { + width: 55px; + height: 55px; + position: absolute; + top: 27px; + left: 3px; +} + +div.zkui .left_col li { + margin: 5px 0px; + font-size: 16px; + background-color: white; + color: black; + padding: 2px 1px 1px 5px; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border: solid black 1px; +} + +div.zkui .left_col li:hover { + background-color: lightBlue; + color: white; +} + +div.zkui .left_col li a { + color: black; + display: block; +} + +div.zkui .left_col li a:hover { + text-decoration: none; +} + +div.zkui .createZnodeForm td, +div.zkui .editZnodeForm td { + padding: 5px; +} + diff --git a/src/contrib/huebrowser/zkui/src/zkui/static/help/index.html b/src/contrib/huebrowser/zkui/src/zkui/static/help/index.html new file mode 100644 index 00000000000..355c8cdd258 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/static/help/index.html @@ -0,0 +1,26 @@ + + +

ZooKeeper Browser

+ + +

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services

+ +

About

+ +

The ZooKeeper Browser application allows you to see how the cluster nodes are working and also allows you to do CRUD operations on the znode hierarchy.

+ diff --git a/src/contrib/huebrowser/zkui/src/zkui/static/js/Source/Zkui/Zkui.js b/src/contrib/huebrowser/zkui/src/zkui/static/js/Source/Zkui/Zkui.js new file mode 100644 index 00000000000..2b77dafd040 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/static/js/Source/Zkui/Zkui.js @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* +--- + +script: Zkui.js + +description: Defines Zkui; a Hue application that extends CCS.JBrowser. + +authors: +- Unknown + +requires: +- ccs-shared/CCS.JBrowser + +provides: [Zkui] + +... +*/ +ART.Sheet.define('window.art.browser.zkui', { + 'min-width': 620 +}); + +var Zkui = new Class({ + + Extends: CCS.JBrowser, + + options: { + className: 'art browser logo_header zkui' + }, + + initialize: function (path, options) { + this.parent(path || '/zkui/', options); + } + + }); diff --git a/src/contrib/huebrowser/zkui/src/zkui/static/js/package.yml b/src/contrib/huebrowser/zkui/src/zkui/static/js/package.yml new file mode 100644 index 00000000000..c2c07adf6f7 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/static/js/package.yml @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +copyright: Apache License v2.0 +version: 0.1 +description: ZooKeeper Browser +name: ZooKeeper Browser +sources: [Source/Zkui/Zkui.js] diff --git a/src/contrib/huebrowser/zkui/src/zkui/stats.py b/src/contrib/huebrowser/zkui/src/zkui/stats.py new file mode 100644 index 00000000000..48f35dd3787 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/stats.py @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import socket +import re + +from StringIO import StringIO + +class Session(object): + + class BrokenLine(Exception): pass + + def __init__(self, session): + m = re.search('/(\d+\.\d+\.\d+\.\d+):(\d+)\[(\d+)\]\((.*)\)', session) + if m: + self.host = m.group(1) + self.port = m.group(2) + self.interest_ops = m.group(3) + for d in m.group(4).split(","): + k,v = d.split("=") + self.__dict__[k] = v + else: + raise Session.BrokenLine() + +class ZooKeeperStats(object): + + def __init__(self, host='localhost', port='2181', timeout=1): + self._address = (host, int(port)) + self._timeout = timeout + + def get_stats(self): + """ Get ZooKeeper server stats as a map """ + data = self._send_cmd('mntr') + if data: + return self._parse(data) + else: + data = self._send_cmd('stat') + return self._parse_stat(data) + + def get_clients(self): + """ Get ZooKeeper server clients """ + clients = [] + + stat = self._send_cmd('stat') + if not stat: + return clients + + sio = StringIO(stat) + + #skip two lines + sio.readline() + sio.readline() + + for line in sio: + if not line.strip(): + break + try: + clients.append(Session(line.strip())) + except Session.BrokenLine: + continue + + return clients + + def _create_socket(self): + return socket.socket() + + def _send_cmd(self, cmd): + """ Send a 4letter word command to the server """ + s = self._create_socket() + s.settimeout(self._timeout) + + s.connect(self._address) + s.send(cmd) + + data = s.recv(2048) + s.close() + + return data + + def _parse(self, data): + """ Parse the output from the 'mntr' 4letter word command """ + h = StringIO(data) + + result = {} + for line in h.readlines(): + try: + key, value = self._parse_line(line) + result[key] = value + except ValueError: + pass # ignore broken lines + + return result + + def _parse_stat(self, data): + """ Parse the output from the 'stat' 4letter word command """ + h = StringIO(data) + + result = {} + + version = h.readline() + if version: + result['zk_version'] = version[version.index(':')+1:].strip() + + # skip all lines until we find the empty one + while h.readline().strip(): pass + + for line in h.readlines(): + m = re.match('Latency min/avg/max: (\d+)/(\d+)/(\d+)', line) + if m is not None: + result['zk_min_latency'] = int(m.group(1)) + result['zk_avg_latency'] = int(m.group(2)) + result['zk_max_latency'] = int(m.group(3)) + continue + + m = re.match('Received: (\d+)', line) + if m is not None: + result['zk_packets_received'] = int(m.group(1)) + continue + + m = re.match('Sent: (\d+)', line) + if m is not None: + result['zk_packets_sent'] = int(m.group(1)) + continue + + m = re.match('Outstanding: (\d+)', line) + if m is not None: + result['zk_outstanding_requests'] = int(m.group(1)) + continue + + m = re.match('Mode: (.*)', line) + if m is not None: + result['zk_server_state'] = m.group(1) + continue + + m = re.match('Node count: (\d+)', line) + if m is not None: + result['zk_znode_count'] = int(m.group(1)) + continue + + return result + + def _parse_line(self, line): + try: + key, value = map(str.strip, line.split('\t')) + except ValueError: + raise ValueError('Found invalid line: %s' % line) + + if not key: + raise ValueError('The key is mandatory and should not be empty') + + try: + value = int(value) + except (TypeError, ValueError): + pass + + return key, value + diff --git a/src/contrib/huebrowser/zkui/src/zkui/templates/clients.mako b/src/contrib/huebrowser/zkui/src/zkui/templates/clients.mako new file mode 100644 index 00000000000..2bee9a7c52d --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/templates/clients.mako @@ -0,0 +1,51 @@ +<%! +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +%> + +<%namespace name="shared" file="shared_components.mako" /> + +${shared.header("ZooKeeper Browser > Clients > %s:%s" % (host, port))} + +

${host}:${port} :: client connections

+
+ +% if clients: + + + + + + + + + + + % for client in clients: + + + + + + + + + % endfor +
HostPortInterest OpsQueuedReceivedSent
${client.host}${client.port}${client.interest_ops}${client.queued}${client.recved}${client.sent}
+% endif + +${shared.footer()} + diff --git a/src/contrib/huebrowser/zkui/src/zkui/templates/create.mako b/src/contrib/huebrowser/zkui/src/zkui/templates/create.mako new file mode 100644 index 00000000000..2a8b8ccca40 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/templates/create.mako @@ -0,0 +1,34 @@ +<%! +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +%> +<%namespace name="shared" file="shared_components.mako" /> + +${shared.header("ZooKeeper Browser > Create Znode")} + +

Create New Znode :: ${path}

+

+ +
+ + ${form.as_table()|n} + +
+ +
+
+ +${shared.footer()} diff --git a/src/contrib/huebrowser/zkui/src/zkui/templates/edit.mako b/src/contrib/huebrowser/zkui/src/zkui/templates/edit.mako new file mode 100644 index 00000000000..997bd07afc1 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/templates/edit.mako @@ -0,0 +1,34 @@ +<%! +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +%> +<%namespace name="shared" file="shared_components.mako" /> + +${shared.header("ZooKeeper Browser > Edit Znode > %s" % path)} + +

Edit Znode Data :: ${path}

+

+ +
+ + ${form.as_table()|n} + +
+ +
+
+ +${shared.footer()} diff --git a/src/contrib/huebrowser/zkui/src/zkui/templates/index.mako b/src/contrib/huebrowser/zkui/src/zkui/templates/index.mako new file mode 100644 index 00000000000..567919dd0f1 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/templates/index.mako @@ -0,0 +1,54 @@ +<%! +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +%> +<%namespace name="shared" file="shared_components.mako" /> + +${shared.header("ZooKeeper Browser")} + +

Overview

+ +
+ +% for i, c in enumerate(overview): +

${i+1}. ${c['nice_name']} Cluster Overview


+ + + + + + + + + + + + % for host, stats in c['stats'].items(): + + + + + + + + % endfor +
NodeRoleAvg LatencyWatch CountVersion
${host}${stats.get('zk_server_state', '')}${stats.get('zk_avg_latency', '')}${stats.get('zk_watch_count', '')}${stats.get('zk_version', '')}
+ +

+% endfor + +${shared.footer()} + diff --git a/src/contrib/huebrowser/zkui/src/zkui/templates/shared_components.mako b/src/contrib/huebrowser/zkui/src/zkui/templates/shared_components.mako new file mode 100644 index 00000000000..f9a45893411 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/templates/shared_components.mako @@ -0,0 +1,66 @@ +<%! +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +%> + +<%! +import datetime +from django.template.defaultfilters import urlencode, escape +from zkui import settings +%> + +<%def name="header(title='ZooKeeper Browser', toolbar=True)"> + + + + ${title} + + + % if toolbar: +
+ +
+ % endif + +
+
+ +
+ +

Clusters

+ +
+ +
+ + +<%def name="info_button(url, text)"> + ${text} + + +<%def name="footer()"> +
+
+ + + diff --git a/src/contrib/huebrowser/zkui/src/zkui/templates/tree.mako b/src/contrib/huebrowser/zkui/src/zkui/templates/tree.mako new file mode 100644 index 00000000000..c74c2020901 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/templates/tree.mako @@ -0,0 +1,75 @@ +<%! +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +%> +<%namespace name="shared" file="shared_components.mako" /> + +${shared.header("ZooKeeper Browser > Tree > %s > %s" % (cluster['nice_name'], path))} + +

${cluster['nice_name'].lower()} :: ${path}

+
+ + + + + + % for child in children: + + % endfor +
Children
+ + ${child} + + Delete +
+
+ + ${shared.info_button(url('zkui.views.create', id=cluster['id'], path=path), 'Create New')} + + +
+ +

data :: base64 :: length :: ${znode.get('dataLength', 0)}

+
+ + +
+ + ${shared.info_button(url('zkui.views.edit_as_base64', id=cluster['id'], path=path), 'Edit as Base64')} + ${shared.info_button(url('zkui.views.edit_as_text', id=cluster['id'], path=path), 'Edit as Text')} + +
+
+ +

stat information

+
+ + + + + % for key in ('pzxid', 'ctime', 'aversion', 'mzxid', \ + 'ephemeralOwner', 'version', 'mtime', 'cversion', 'czxid'): + + % endfor +
KeyValue
${key}${znode[key]}
+ +
+Details on stat information. + +${shared.footer()} + diff --git a/src/contrib/huebrowser/zkui/src/zkui/templates/view.mako b/src/contrib/huebrowser/zkui/src/zkui/templates/view.mako new file mode 100644 index 00000000000..e046afc4fe5 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/templates/view.mako @@ -0,0 +1,128 @@ +<%! +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +%> +<%namespace name="shared" file="shared_components.mako" /> + +${shared.header("ZooKeeper Browser > %s" % cluster['nice_name'])} + +<%def name="show_stats(stats)"> + + Key + Value + + + Version + ${stats.get('zk_version')} + + + Latency + Min: ${stats.get('zk_min_latency', '')} + Avg: ${stats.get('zk_avg_latency', '')} + Max: ${stats.get('zk_max_latency', '')} + + + Packets + Sent: ${stats.get('zk_packets_sent', '')} + Received: ${stats.get('zk_packets_received', '')} + + + + Outstanding Requests + ${stats.get('zk_outstanding_requests', '')} + + + Watch Count + ${stats.get('zk_watch_count', '')} + + + Open FD Count + ${stats.get('zk_open_file_descriptor_count', '')} + + + Max FD Count + ${stats.get('zk_max_file_descriptor_count', '')} + + + + +

${cluster['nice_name']} Cluster Overview

+ +${shared.info_button(url('zkui.views.tree', id=cluster['id'], path='/'), 'View Znode Hierarchy')} + +

+ +% if leader: +

General

+ + + + + + + + + + + + + + + +
KeyValue
ZNode Count${leader.get('zk_znode_count', '')}
Ephemerals Count${leader.get('zk_ephemerals_count', '')}
Approximate Data Size${leader.get('zk_approximate_data_size', '')} bytes
+

+% endif + +% if leader: +

node :: ${leader['host']} :: leader

+ + ${shared.info_button(url('zkui.views.clients', host=leader['host']), 'View Client Connections')} + +

+ + ${show_stats(leader)} + + + + + + + + + + + + + +
Followers${leader.get('zk_followers', '')}
Synced Followers${leader.get('zk_synced_followers', '')}
Pending Syncs${leader.get('zk_pending_syncs', '')}
+

+% endif + +% for stats in followers: +

node :: ${stats['host']} :: follower

+
+ + ${shared.info_button(url('zkui.views.clients', host=stats['host']), 'View Client Connections')} + +

+ + ${show_stats(stats)} +
+

+% endfor + +${shared.footer()} + diff --git a/src/contrib/huebrowser/zkui/src/zkui/urls.py b/src/contrib/huebrowser/zkui/src/zkui/urls.py new file mode 100644 index 00000000000..f795f7e71e5 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/urls.py @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.conf.urls.defaults import patterns, url + +urlpatterns = patterns('zkui', + url(r'^$', 'views.index'), + url(r'view/(?P\d+)$', 'views.view'), + url(r'clients/(?P.+)$', 'views.clients'), + url(r'tree/(?P\d+)(?P.+)$', 'views.tree'), + url(r'create/(?P\d+)(?P.*)$', 'views.create'), + url(r'delete/(?P\d+)(?P.*)$', 'views.delete'), + url(r'edit/base64/(?P\d+)(?P.*)$', 'views.edit_as_base64'), + url(r'edit/text/(?P\d+)(?P.*)$', 'views.edit_as_text') +) diff --git a/src/contrib/huebrowser/zkui/src/zkui/utils.py b/src/contrib/huebrowser/zkui/src/zkui/utils.py new file mode 100644 index 00000000000..fb013170f6c --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/utils.py @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from zkui import settings + +from django.http import Http404 + +def get_cluster_or_404(id): + try: + id = int(id) + if not (0 <= id < len(settings.CLUSTERS)): + raise ValueError, 'Undefined cluster id.' + except (TypeError, ValueError): + raise Http404() + + cluster = settings.CLUSTERS[id] + cluster['id'] = id + + return cluster + diff --git a/src/contrib/huebrowser/zkui/src/zkui/views.py b/src/contrib/huebrowser/zkui/src/zkui/views.py new file mode 100644 index 00000000000..64d926b6063 --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/views.py @@ -0,0 +1,165 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from desktop.lib.django_util import render +from django.http import Http404 + +from zkui import settings +from zkui.stats import ZooKeeperStats +from zkui.rest import ZooKeeper +from zkui.utils import get_cluster_or_404 +from zkui.forms import CreateZNodeForm, EditZNodeForm + +def _get_global_overview(): + overview = [] + for c in settings.CLUSTERS: + overview.append(_get_overview(c)) + return overview + +def _get_overview(cluster): + stats = {} + for s in cluster['hostport'].split(','): + host, port = map(str.strip, s.split(':')) + + zks = ZooKeeperStats(host, port) + stats[s] = zks.get_stats() or {} + + cluster['stats'] = stats + return cluster + +def _group_stats_by_role(cluster): + leader, followers = None, [] + for host, stats in cluster['stats'].items(): + stats['host'] = host + + if stats.get('zk_server_state') == 'leader': + leader = stats + + elif stats.get('zk_server_state') == 'follower': + followers.append(stats) + + return leader, followers + +def index(request): + overview = _get_global_overview() + return render('index.mako', request, + dict(overview=overview)) + +def view(request, id): + cluster = get_cluster_or_404(id) + + cluster = _get_overview(cluster) + leader, followers = _group_stats_by_role(cluster) + + return render('view.mako', request, + dict(cluster=cluster, leader=leader, followers=followers)) + +def clients(request, host): + parts = host.split(':') + if len(parts) != 2: + raise Http404 + + host, port = parts + zks = ZooKeeperStats(host, port) + clients = zks.get_clients() + + return render('clients.mako', request, + dict(host=host, port=port, clients=clients)) + +def tree(request, id, path): + cluster = get_cluster_or_404(id) + zk = ZooKeeper(cluster['rest_gateway']) + + znode = zk.get(path) + children = sorted(zk.get_children_paths(path)) + + return render('tree.mako', request, + dict(cluster=cluster, path=path, \ + znode=znode, children=children)) + +def delete(request, id, path): + cluster = get_cluster_or_404(id) + if request.method == 'POST': + zk = ZooKeeper(cluster['rest_gateway']) + try: + zk.recursive_delete(path) + except ZooKeeper.NotFound: + pass + + return tree(request, id, path[:path.rindex('/')] or '/') + +def create(request, id, path): + cluster = get_cluster_or_404(id) + + if request.method == 'POST': + form = CreateZNodeForm(request.POST) + if form.is_valid(): + zk = ZooKeeper(cluster['rest_gateway']) + + full_path = ("%s/%s" % (path, form.cleaned_data['name']))\ + .replace('//', '/') + + zk.create(full_path, \ + form.cleaned_data['data'], \ + sequence = form.cleaned_data['sequence']) + return tree(request, id, path) + else: + form = CreateZNodeForm() + + return render('create.mako', request, + dict(path=path, form=form)) + +def edit_as_base64(request, id, path): + cluster = get_cluster_or_404(id) + zk = ZooKeeper(cluster['rest_gateway']) + node = zk.get(path) + + if request.method == 'POST': + form = EditZNodeForm(request.POST) + if form.is_valid(): + # TODO is valid base64 string? + data = form.cleaned_data['data'].decode('base64') + zk.set(path, data, form.cleaned_data['version']) + + return tree(request, id, path) + else: + form = EditZNodeForm(dict(\ + data=node.get('data64', ''), + version=node.get('version', '-1'))) + + return render('edit.mako', request, + dict(path=path, form=form)) + +def edit_as_text(request, id, path): + cluster = get_cluster_or_404(id) + zk = ZooKeeper(cluster['rest_gateway']) + node = zk.get(path) + + if request.method == 'POST': + form = EditZNodeForm(request.POST) + if form.is_valid(): + zk.set(path, form.cleaned_data['data']) + + return tree(request, id, path) + else: + form = EditZNodeForm(dict(data=node.get('data64', '')\ + .decode('base64').strip(), + version=node.get('version', '-1'))) + + return render('edit.mako', request, + dict(path=path, form=form)) + + diff --git a/src/contrib/huebrowser/zkui/src/zkui/windmilltests.py b/src/contrib/huebrowser/zkui/src/zkui/windmilltests.py new file mode 100644 index 00000000000..ba44e26865f --- /dev/null +++ b/src/contrib/huebrowser/zkui/src/zkui/windmilltests.py @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from desktop.lib.windmill_util import logged_in_client + +def test_zkui(): + """ launches the default view for zkui """ + client = logged_in_client() + client.click(id='ccs-zkui-menu') + client.waits.forElement(classname='CCS-ZKUI', timeout='2000') diff --git a/src/contrib/loggraph/README.txt b/src/contrib/loggraph/README.txt new file mode 100644 index 00000000000..1865fa5ab0c --- /dev/null +++ b/src/contrib/loggraph/README.txt @@ -0,0 +1,69 @@ +LogGraph README + +1 - About +LogGraph is an application for viewing and filtering zookeeper logs. It can handle transaction logs and message logs. + +2 - Compiling + +Run "ant jar" in src/contrib/loggraph/. This will download all dependencies and compile all the loggraph code. + +Once compilation has finished, you can run it the the loggraph.sh script in src/contrib/loggraph/bin. This will start and embedded web server on your machine. +Navigate to http://localhost:8182/graph/main.html + +3 - Usage +LogGraph presents the user with 4 views, + + a) Simple log view + This view simply displays the log text. This isn't very useful without filters (see "Filtering the logs"). + + b) Server view + The server view shows the interactions between the different servers in an ensemble. The X axis represents time. + * Exceptions show up as red dots. Hovering your mouse over them will give you more details of the exception + * The colour of the line represents the election state of the server. + - orange means LOOKING for leader + - dark green means the server is the leader + - light green means the server is following a leader + - yellow means there isn't enough information to determine the state of the server. + * The gray arrows denote election messages between servers. Pink dashed arrows are messages that were sent but never delivered. + + c) Session view + 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. + 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. + + d) Stats view + There is currently only one statistics view, Transactions/minute. Suggestions for other statistic views are very welcome. + +4 - Filtering the logs +The logs can be filtered in 2 ways, by time and by content. + +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. + +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. + +4.1 - Filter arguments +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 interpretted as hexidecimal. Otherwise it is interpretted as decimal. If the argument begins with a double-quote, (") it is interpretted as a string. Anything else is interpretted as a symbol. + +4.2 - Filter symbols +The possible filter symbols are: + +client-id : number, the session id of the client who initiated a transaction. +cxid : number, the cxid of a transaction +zxid : number, the zxid of a transaction +operation : string, the operation being performed, for example "setData", "createSession", "closeSession", "error", "create" + +4.3 - Filter operations +The possible filter operations are: + +or : logical or, takes 1 or more arguments which must be other statements. +and : logical and, takes 1 or more arguments which must be other statements. +not : logical not, takes 1 argument which must be another statement. +xor : exclusive or, takes 1 or more arguments which must be other statements. += : equals, takes 1 or more arguments, which must all be equal to each other to return true. +> : 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... +< : 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... + +4.3 - Filter examples +Give me all the setData operations with session id 0xdeadbeef or 0xcafeb33r but not with zxid 0x12341234 -> + +(and (= operation "setData") (or (= client-id 0xdeadbeef) (= client-id 0xcafeb33r)) (not (= zxid 0x12341234))) + diff --git a/src/contrib/loggraph/bin/loggraph-dev.sh b/src/contrib/loggraph/bin/loggraph-dev.sh new file mode 100755 index 00000000000..0b82efa35b0 --- /dev/null +++ b/src/contrib/loggraph/bin/loggraph-dev.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +make_canonical () { + cd $1; pwd; +} + +SCRIPTDIR=`dirname $0` +BUILDDIR=`make_canonical $SCRIPTDIR/../../../../build/contrib/loggraph` +LIBDIR=`make_canonical $BUILDDIR/lib` +WEBDIR=`make_canonical $SCRIPTDIR/../web` +ZKDIR=`make_canonical $SCRIPTDIR/../../../../build/` + +if [ ! -x $BUILDDIR ]; then + echo "\n\n*** You need to build loggraph before running it ***\n\n"; + exit; +fi + +for i in `ls $LIBDIR`; do + CLASSPATH=$LIBDIR/$i:$CLASSPATH +done + +for i in $ZKDIR/zookeeper-*.jar; do + CLASSPATH="$i:$CLASSPATH" +done + +CLASSPATH=$BUILDDIR/classes:$WEBDIR:$CLASSPATH +echo $CLASSPATH +java -Dlog4j.configuration=org/apache/zookeeper/graph/log4j.properties -Xdebug -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=n -cp $CLASSPATH org.apache.zookeeper.graph.LogServer $* diff --git a/src/contrib/loggraph/bin/loggraph.sh b/src/contrib/loggraph/bin/loggraph.sh new file mode 100755 index 00000000000..381e5ad478a --- /dev/null +++ b/src/contrib/loggraph/bin/loggraph.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +make_canonical () { + cd $1; pwd; +} + +SCRIPTDIR=`dirname $0` +BUILDDIR=`make_canonical $SCRIPTDIR/../../../../build/contrib/loggraph` +LIBDIR=`make_canonical $BUILDDIR/lib` +ZKDIR=`make_canonical $SCRIPTDIR/../../../../build/` + +if [ ! -x $BUILDDIR ]; then + echo "\n\n*** You need to build loggraph before running it ***\n\n"; + exit; +fi + +for i in `ls $LIBDIR`; do + CLASSPATH=$LIBDIR/$i:$CLASSPATH +done + +for i in `ls $BUILDDIR/*.jar`; do + CLASSPATH=$i:$CLASSPATH +done + +for i in $ZKDIR/zookeeper-*.jar; do + CLASSPATH="$i:$CLASSPATH" +done + +java -cp $CLASSPATH org.apache.zookeeper.graph.LogServer $* + + + + diff --git a/src/contrib/loggraph/build.xml b/src/contrib/loggraph/build.xml new file mode 100644 index 00000000000..0ffea05eb54 --- /dev/null +++ b/src/contrib/loggraph/build.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/loggraph/ivy.xml b/src/contrib/loggraph/ivy.xml new file mode 100644 index 00000000000..ceabe9a2fdd --- /dev/null +++ b/src/contrib/loggraph/ivy.xml @@ -0,0 +1,44 @@ + + + + + + + + ZooKeeper Graphing + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterException.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterException.java new file mode 100644 index 00000000000..237d7a20c4c --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterException.java @@ -0,0 +1,17 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +public class FilterException extends Exception { + public FilterException(String s) { + super(s); + } +}; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java new file mode 100644 index 00000000000..e76f6ff4cfa --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterOp.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.apache.zookeeper.graph.filterops.*; + +import java.util.ArrayList; + +public abstract class FilterOp { + protected ArrayList subOps; + protected ArrayList args; + + public FilterOp() { + subOps = new ArrayList(); + args = new ArrayList(); + } + + public static FilterOp newOp(String op) throws FilterException { + if (op.equals("or")) + return new OrOp(); + if (op.equals("and")) + return new AndOp(); + if (op.equals("not")) + return new NotOp(); + if (op.equals("xor")) + return new XorOp(); + if (op.equals("=")) + return new EqualsOp(); + if (op.equals("<")) + return new LessThanOp(); + if (op.equals(">")) + return new GreaterThanOp(); + + throw new FilterException("Invalid operation '" + op + "'"); + } + + public void addSubOp(FilterOp op) { + subOps.add(op); + } + + public void addArg(Arg arg) { + args.add(arg); + } + + public abstract boolean matches(LogEntry entry) throws FilterException; + + public String toString() { + String op = "(" + getClass().getName(); + for (FilterOp f : subOps) { + op += " " + f; + } + for (Arg a : args) { + op += " " + a; + } + return op + ")"; + } + + public enum ArgType { + STRING, NUMBER, SYMBOL + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterParser.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterParser.java new file mode 100644 index 00000000000..f87b08de119 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/FilterParser.java @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.apache.zookeeper.graph.filterops.*; + +import java.io.IOException; +import java.io.PushbackReader; +import java.io.StringReader; + +public class FilterParser { + private PushbackReader reader; + + public FilterParser(String s) { + reader = new PushbackReader(new StringReader(s)); + } + + public static void main(String[] args) throws IOException, FilterException { + if (args.length == 1) { + System.out.println(new FilterParser(args[0]).parse()); + } else { + System.out.println(new FilterParser("(or (and (= session foobar) (= session barfoo)) (= session sdfs))").parse()); + } + } + + private String readUntilSpace() throws IOException { + StringBuffer buffer = new StringBuffer(); + + int c = reader.read(); + while (!Character.isWhitespace(c) && c != ')' && c != '(') { + buffer.append((char) c); + c = reader.read(); + if (c == -1) { + break; + } + } + reader.unread(c); + + return buffer.toString().trim(); + } + + private StringArg readStringArg() throws IOException, FilterException { + int c = reader.read(); + int last = 0; + if (c != '"') { + throw new FilterException("Check the parser, trying to read a string that doesn't begin with quotes"); + } + StringBuffer buffer = new StringBuffer(); + while (reader.ready()) { + last = c; + c = reader.read(); + if (c == -1) { + break; + } + + if (c == '"' && last != '\\') { + return new StringArg(buffer.toString()); + } else { + buffer.append((char) c); + } + } + throw new FilterException("Unterminated string"); + } + + private NumberArg readNumberArg() throws IOException, FilterException { + String strval = readUntilSpace(); + + try { + if (strval.startsWith("0x")) { + return new NumberArg(Long.valueOf(strval.substring(2), 16)); + } else { + return new NumberArg(Long.valueOf(strval)); + } + } catch (NumberFormatException e) { + throw new FilterException("Not a number [" + strval + "]\n" + e); + } + } + + private SymbolArg readSymbolArg() throws IOException, FilterException { + return new SymbolArg(readUntilSpace()); + } + + public FilterOp parse() throws IOException, FilterException { + int c = reader.read(); + if (c != '(') { + throw new FilterException("Invalid format"); + } + + String opstr = readUntilSpace(); + FilterOp op = FilterOp.newOp(opstr); + + while (reader.ready()) { + c = reader.read(); + if (c == -1) { + break; + } + if (c == '(') { + reader.unread(c); + op.addSubOp(parse()); + } else if (c == ')') { + return op; + } else if (c == '"') { + reader.unread(c); + op.addArg(readStringArg()); + } else if (Character.isDigit(c) || c == '-' || c == '+') { + reader.unread(c); + op.addArg(readNumberArg()); + } else if (Character.isJavaIdentifierStart(c)) { + reader.unread(c); + op.addArg(readSymbolArg()); + } + } + throw new FilterException("Incomplete filter"); + } +}; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java new file mode 100644 index 00000000000..6d2074d702d --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/JsonGenerator.java @@ -0,0 +1,213 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class JsonGenerator { + private JSONObject root; + private HashSet servers; + + /** + Assumes entries are sorted by timestamp. + */ + public JsonGenerator(LogIterator iter) { + servers = new HashSet(); + + Pattern stateChangeP = Pattern.compile("- (LOOKING|FOLLOWING|LEADING)"); + Pattern newElectionP = Pattern.compile("New election. My id = (\\d+), Proposed zxid = (\\d+)"); + Pattern receivedProposalP = Pattern.compile("Notification: (\\d+) \\(n.leader\\), (\\d+) \\(n.zxid\\), (\\d+) \\(n.round\\), .+ \\(n.state\\), (\\d+) \\(n.sid\\), .+ \\(my state\\)"); + Pattern exceptionP = Pattern.compile("xception"); + + root = new JSONObject(); + Matcher m = null; + JSONArray events = new JSONArray(); + root.put("events", events); + + long starttime = Long.MAX_VALUE; + long endtime = 0; + + int leader = 0; + long curEpoch = 0; + boolean newEpoch = false; + + while (iter.hasNext()) { + LogEntry ent = iter.next(); + + if (ent.getTimestamp() < starttime) { + starttime = ent.getTimestamp(); + } + if (ent.getTimestamp() > endtime) { + endtime = ent.getTimestamp(); + } + + if (ent.getType() == LogEntry.Type.TXN) { + events.add(txnEntry((TransactionEntry) ent)); + } else { + Log4JEntry e = (Log4JEntry) ent; + servers.add(e.getNode()); + + if ((m = stateChangeP.matcher(e.getEntry())).find()) { + JSONObject stateChange = new JSONObject(); + stateChange.put("type", "stateChange"); + stateChange.put("time", e.getTimestamp()); + stateChange.put("server", e.getNode()); + stateChange.put("state", m.group(1)); + events.add(stateChange); + + if (m.group(1).equals("LEADING")) { + leader = e.getNode(); + } + } else if ((m = newElectionP.matcher(e.getEntry())).find()) { + Iterator iterator = servers.iterator(); + long zxid = Long.valueOf(m.group(2)); + int count = (int) zxid;// & 0xFFFFFFFFL; + int epoch = (int) Long.rotateRight(zxid, 32);// >> 32; + + if (leader != 0 && epoch > curEpoch) { + JSONObject stateChange = new JSONObject(); + stateChange.put("type", "stateChange"); + stateChange.put("time", e.getTimestamp()); + stateChange.put("server", leader); + stateChange.put("state", "INIT"); + events.add(stateChange); + leader = 0; + } + + while (iterator.hasNext()) { + int dst = iterator.next(); + if (dst != e.getNode()) { + JSONObject msg = new JSONObject(); + msg.put("type", "postmessage"); + msg.put("src", e.getNode()); + msg.put("dst", dst); + msg.put("time", e.getTimestamp()); + msg.put("zxid", m.group(2)); + msg.put("count", count); + msg.put("epoch", epoch); + + events.add(msg); + } + } + } else if ((m = receivedProposalP.matcher(e.getEntry())).find()) { + // Pattern.compile("Notification: \\d+, (\\d+), (\\d+), \\d+, [^,]*, [^,]*, (\\d+)");//, LOOKING, LOOKING, 2 + int src = Integer.valueOf(m.group(4)); + long zxid = Long.valueOf(m.group(2)); + int dst = e.getNode(); + long epoch2 = Long.valueOf(m.group(3)); + + int count = (int) zxid;// & 0xFFFFFFFFL; + int epoch = (int) Long.rotateRight(zxid, 32);// >> 32; + + if (leader != 0 && epoch > curEpoch) { + JSONObject stateChange = new JSONObject(); + stateChange.put("type", "stateChange"); + stateChange.put("time", e.getTimestamp()); + stateChange.put("server", leader); + stateChange.put("state", "INIT"); + events.add(stateChange); + leader = 0; + } + + if (src != dst) { + JSONObject msg = new JSONObject(); + msg.put("type", "delivermessage"); + msg.put("src", src); + msg.put("dst", dst); + msg.put("time", e.getTimestamp()); + msg.put("zxid", zxid); + msg.put("epoch", epoch); + msg.put("count", count); + msg.put("epoch2", epoch2); + + events.add(msg); + } + } else if ((m = exceptionP.matcher(e.getEntry())).find()) { + JSONObject ex = new JSONObject(); + ex.put("type", "exception"); + ex.put("server", e.getNode()); + ex.put("time", e.getTimestamp()); + ex.put("text", e.getEntry()); + events.add(ex); + } + } + JSONObject ex = new JSONObject(); + ex.put("type", "text"); + ex.put("time", ent.getTimestamp()); + String txt = ent.toString(); + ex.put("text", txt); + events.add(ex); + } + // System.out.println("pending messages: "+pendingMessages.size()); + root.put("starttime", starttime); + root.put("endtime", endtime); + + JSONArray serversarray = new JSONArray(); + root.put("servers", serversarray); + + Iterator iterator = servers.iterator(); + while (iterator.hasNext()) { + serversarray.add(iterator.next()); + } + } + + ; + + public static void main(String[] args) throws Exception { + MergedLogSource src = new MergedLogSource(args); + LogIterator iter = src.iterator(); + System.out.println(new JsonGenerator(iter)); + } + + public JSONObject txnEntry(TransactionEntry e) { + JSONObject event = new JSONObject(); + + event.put("time", Long.toString(e.getTimestamp())); + event.put("client", Long.toHexString(e.getClientId())); + event.put("cxid", Long.toHexString(e.getCxid())); + event.put("zxid", Long.toHexString(e.getZxid())); + event.put("op", e.getOp()); + event.put("extra", e.getExtra()); + event.put("type", "transaction"); + + return event; + } + + public String toString() { + return JSONValue.toJSONString(root); + } + + private class Message { + private int from; + private int to; + private long zxid; + + public Message(int from, int to, long zxid) { + this.from = from; + this.to = to; + this.zxid = zxid; + } + + public boolean equals(Message m) { + return (m.from == this.from + && m.to == this.to + && m.zxid == this.zxid); + } + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JEntry.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JEntry.java new file mode 100644 index 00000000000..58d193fb2f9 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JEntry.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +public class Log4JEntry extends LogEntry { + public Log4JEntry(long timestamp, int node, String entry) { + super(timestamp); + setAttribute("log-text", entry); + setAttribute("node", new Integer(node)); + } + + public String getEntry() { + return (String) getAttribute("log-text"); + } + + public String toString() { + return "" + getTimestamp() + "::::" + getNode() + "::::" + getEntry(); + } + + public int getNode() { + return (Integer) getAttribute("node"); + } + + public Type getType() { + return LogEntry.Type.LOG4J; + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java new file mode 100644 index 00000000000..36221c4d11c --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java @@ -0,0 +1,400 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.EOFException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.NoSuchElementException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Log4JSource implements LogSource { + private static final Logger LOG = LoggerFactory.getLogger(Log4JSource.class); + + private static final int skipN = 10000; + private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss,SSS"; + + private LogSkipList skiplist = null; + + private String file = null; + private long starttime = 0; + private long endtime = 0; + private int serverid = 0; + private long size = 0; + + private Pattern timep; + + public Log4JSource(String file) throws IOException { + this.file = file; + + timep = Pattern.compile("^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3})"); + skiplist = new LogSkipList(); + init(); + } + + private static long timestampFromText(SimpleDateFormat format, String s) { + Date d = null; + try { + d = format.parse(s); + } catch (ParseException e) { + return 0; + } + Calendar c = new GregorianCalendar(); + c.setTime(d); + return c.getTimeInMillis(); + } + + public static void main(String[] args) throws IOException { + final Log4JSource s = new Log4JSource(args[0]); + System.out.println(s); + + LogIterator iter; + + if (args.length == 3) { + final long starttime = Long.valueOf(args[1]); + final long endtime = Long.valueOf(args[2]); + iter = s.iterator(starttime, endtime); + + Thread t1 = new Thread() { + public void run() { + + LogIterator iter = s.iterator(starttime, endtime); + System.out.println(iter); + try { + iter.close(); + } catch (IOException ioe) { + System.out.println(ioe.getMessage()); + } + } + + ; + }; + Thread t2 = new Thread() { + public void run() { + + LogIterator iter = s.iterator(starttime, endtime); + System.out.println(iter); + try { + iter.close(); + } catch (IOException ioe) { + System.out.println(ioe.getMessage()); + } + } + + ; + }; + Thread t3 = new Thread() { + public void run() { + + LogIterator iter = s.iterator(starttime, endtime); + System.out.println(iter); + } + + ; + }; + t1.start(); + t2.start(); + // t3.start(); + } else { + iter = s.iterator(); + } + + /*while (iter.hasNext()) { + System.out.println(iter.next()); + }*/ + iter.close(); + } + + public boolean overlapsRange(long starttime, long endtime) { + return (starttime <= this.endtime && endtime >= this.starttime); + } + + public long size() { + return size; + } + + public long getStartTime() { + return starttime; + } + + public long getEndTime() { + return endtime; + } + + public LogSkipList getSkipList() { + return skiplist; + } + + public LogIterator iterator(long starttime, long endtime) throws IllegalArgumentException { + try { + return iterator(starttime, endtime, null); + } catch (FilterException fe) { + assert (false); //"This should never happen, you can't have a filter exception without a filter"); + return null; + } + } + + public LogIterator iterator(long starttime, long endtime, FilterOp filter) throws IllegalArgumentException, FilterException { + // sanitise start and end times + if (endtime < starttime) { + throw new IllegalArgumentException("End time (" + endtime + ") must be greater or equal to starttime (" + starttime + ")"); + } + + return new Log4JSourceIterator(this, starttime, endtime, filter); + } + + public LogIterator iterator() throws IllegalArgumentException { + return iterator(starttime, endtime + 1); + } + + private void init() throws IOException { + File f = new File(file); + RandomAccessFileReader in = new RandomAccessFileReader(f); + SimpleDateFormat dateformat = new SimpleDateFormat(DATE_FORMAT); + Pattern idp = Pattern.compile("\\[myid:(\\d+)\\]"); + + long lastFp = in.getPosition(); + String line = in.readLine(); + Matcher m = null; + + // if we have read data from the file, and it matchs the timep pattern + if ((line != null) && (m = timep.matcher(line)).lookingAt()) { + starttime = timestampFromText(dateformat, m.group(1)); + } else { + throw new IOException("Invalid log4j format. First line doesn't start with time"); + } + + /* + Count number of log entries. Any line starting with a timestamp counts as an entry + */ + String lastentry = line; + try { + while (line != null) { + m = timep.matcher(line); + if (m.lookingAt()) { + if (size % skipN == 0) { + long time = timestampFromText(dateformat, m.group(1)); + skiplist.addMark(time, lastFp, size); + } + size++; + lastentry = line; + } + if (serverid == 0 && (m = idp.matcher(line)).find()) { + serverid = Integer.valueOf(m.group(1)); + } + + lastFp = in.getPosition(); + line = in.readLine(); + } + } catch (EOFException eof) { + // ignore, simply end of file, though really (line!=null) should have caught this + } finally { + in.close(); + } + + m = timep.matcher(lastentry); + if (m.lookingAt()) { + endtime = timestampFromText(dateformat, m.group(1)); + } else { + throw new IOException("Invalid log4j format. Last line doesn't start with time"); + } + } + + public String toString() { + return "Log4JSource(file=" + file + ", size=" + size + ", start=" + starttime + ", end=" + endtime + ", id=" + serverid + ")"; + } + + public int getServerId() { + return serverid; + } + + private class Log4JSourceIterator implements LogIterator { + private RandomAccessFileReader in; + private LogEntry next = null; + private long starttime = 0; + private long endtime = 0; + private String buf = ""; + private Log4JSource src = null; + private long skippedAtStart = 0; + private SimpleDateFormat dateformat = null; + private FilterOp filter = null; + + public Log4JSourceIterator(Log4JSource src, long starttime, long endtime) throws IllegalArgumentException, FilterException { + this(src, starttime, endtime, null); + } + + public Log4JSourceIterator(Log4JSource src, long starttime, long endtime, FilterOp filter) throws IllegalArgumentException, FilterException { + + this.dateformat = new SimpleDateFormat(DATE_FORMAT); + this.src = src; + this.starttime = starttime; + this.endtime = endtime; + + File f = new File(src.file); + try { + in = new RandomAccessFileReader(f); + } catch (FileNotFoundException e) { + throw new IllegalArgumentException("Bad file passed in (" + src.file + ") cannot open:" + e); + } + + // skip to the offset of latest skip point before starttime + LogSkipList.Mark start = src.getSkipList().findMarkBefore(starttime); + try { + in.seek(start.getBytes()); + skippedAtStart = start.getEntriesSkipped(); + } catch (IOException ioe) { + // if we can't skip, we should just read from the start + } + + LogEntry e; + while ((e = readNextEntry()) != null && e.getTimestamp() < endtime) { + if (e.getTimestamp() >= starttime && (filter == null || filter.matches(e))) { + next = e; + return; + } + skippedAtStart++; + } + this.filter = filter; + } + + synchronized public long size() throws IOException { + if (LOG.isTraceEnabled()) { + LOG.trace("size() called"); + } + + if (this.endtime >= src.getEndTime()) { + return src.size() - skippedAtStart; + } + + long pos = in.getPosition(); + + if (LOG.isTraceEnabled()) { + LOG.trace("saved pos () = " + pos); + } + + LogEntry e; + + LogSkipList.Mark lastseg = src.getSkipList().findMarkBefore(this.endtime); + in.seek(lastseg.getBytes()); + buf = ""; // clear the buf so we don't get something we read before we sought + // number of entries skipped to get to the end of the iterator, less the number skipped to get to the start + long count = lastseg.getEntriesSkipped() - skippedAtStart; + + while ((e = readNextEntry()) != null) { + if (LOG.isTraceEnabled()) { + //LOG.trace(e); + } + if (e.getTimestamp() > this.endtime) { + break; + } + count++; + } + in.seek(pos); + buf = ""; + + if (LOG.isTraceEnabled()) { + LOG.trace("size() = " + count); + } + + return count; + } + + synchronized private LogEntry readNextEntry() { + try { + try { + while (true) { + String line = in.readLine(); + if (line == null) { + break; + } + + Matcher m = src.timep.matcher(line); + if (m.lookingAt()) { + if (buf.length() > 0) { + LogEntry e = new Log4JEntry(src.timestampFromText(dateformat, buf), src.getServerId(), buf); + buf = line; + return e; + } + buf = line; + } else if (buf.length() > 0) { + buf += line + "\n"; + } + } + } catch (EOFException eof) { + // ignore, we've simply come to the end of the file + } + if (buf.length() > 0) { + LogEntry e = new Log4JEntry(src.timestampFromText(dateformat, buf), src.getServerId(), buf); + buf = ""; + return e; + } + } catch (Exception e) { + LOG.error("Error reading next entry in file (" + src.file + "): " + e); + return null; + } + return null; + } + + public boolean hasNext() { + return next != null; + } + + public LogEntry next() throws NoSuchElementException { + LogEntry ret = next; + LogEntry e = readNextEntry(); + + if (filter != null) { + try { + while (e != null && !filter.matches(e)) { + e = readNextEntry(); + } + } catch (FilterException fe) { + throw new NoSuchElementException(e.toString()); + } + } + + if (e != null && e.getTimestamp() < endtime) { + next = e; + } else { + next = null; + } + return ret; + } + + public void remove() throws UnsupportedOperationException { + throw new UnsupportedOperationException("remove not supported for L4J logs"); + } + + public void close() throws IOException { + in.close(); + } + + public String toString() { + String size; + try { + size = new Long(size()).toString(); + } catch (IOException ioe) { + size = "Unable to read"; + } + return "Log4JSourceIterator(start=" + starttime + ", end=" + endtime + ", size=" + size + ")"; + } + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java new file mode 100644 index 00000000000..6de84a0657d --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogEntry.java @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import java.io.Serializable; +import java.util.HashMap; + +public abstract class LogEntry implements Serializable { + private HashMap attributes; + + public LogEntry(long timestamp) { + attributes = new HashMap(); + setAttribute("timestamp", new Long(timestamp)); + } + + ; + + public long getTimestamp() { + return (Long) getAttribute("timestamp"); + } + + public abstract Type getType(); + + public void setAttribute(String key, Object v) { + attributes.put(key, v); + } + + public Object getAttribute(String key) { + return attributes.get(key); + } + + public enum Type {UNKNOWN, LOG4J, TXN} +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogIterator.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogIterator.java new file mode 100644 index 00000000000..a7d303baca8 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogIterator.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Iterator; + +public interface LogIterator extends Iterator, Closeable { + long size() throws IOException; + + ; +}; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogServer.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogServer.java new file mode 100644 index 00000000000..f01689be8c9 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogServer.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.apache.zookeeper.graph.servlets.*; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; + +public class LogServer extends ServletContextHandler { + public LogServer(MergedLogSource src) throws Exception { + super(ServletContextHandler.SESSIONS); + setContextPath("/"); + + addServlet(new ServletHolder(new StaticContent()), "/graph/*"); + + addServlet(new ServletHolder(new Fs()), "/fs"); + addServlet(new ServletHolder(new GraphData(src)), "/data"); + addServlet(new ServletHolder(new FileLoader(src)), "/loadfile"); + addServlet(new ServletHolder(new NumEvents(src)), "/info"); + addServlet(new ServletHolder(new Throughput(src)), "/throughput"); + } + + public static void main(String[] args) { + try { + MergedLogSource src = new MergedLogSource(args); + System.out.println(src); + + Server server = new Server(8182); + server.setHandler(new LogServer(src)); + + server.start(); + server.join(); + + } catch (Exception e) { + // Something is wrong. + e.printStackTrace(); + } + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSkipList.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSkipList.java new file mode 100644 index 00000000000..04e87f9cb44 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSkipList.java @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; +import java.util.NoSuchElementException; + +/** + Generic skip list for holding a rough index of a log file. When the log file is loaded, this + index is built by adding a mark every n entries. Then when a specific time position is requested + from the file, a point at most n-1 entries before the time position can be jumped to. + + */ +public class LogSkipList { + private static final Logger LOG = LoggerFactory.getLogger(LogSkipList.class); + + private LinkedList marks; + + public LogSkipList() { + if (LOG.isTraceEnabled()) { + LOG.trace("New skip list"); + } + marks = new LinkedList(); + } + + ; + + public void addMark(long time, long bytes, long skipped) { + if (LOG.isTraceEnabled()) { + LOG.trace("addMark (time:" + time + ", bytes: " + bytes + ", skipped: " + skipped + ")"); + } + marks.add(new Mark(time, bytes, skipped)); + } + + /** + Find the last mark in the skip list before time. + */ + public Mark findMarkBefore(long time) throws NoSuchElementException { + if (LOG.isTraceEnabled()) { + LOG.trace("findMarkBefore(" + time + ")"); + } + + Mark last = marks.getFirst(); + for (Mark m : marks) { + if (m.getTime() > time) { + break; + } + last = m; + } + + if (LOG.isTraceEnabled()) { + LOG.trace("return " + last); + } + + return last; + } + + public class Mark { + private long time; + private long bytes; + private long skipped; + + public Mark(long time, long bytes, long skipped) { + this.time = time; + this.bytes = bytes; + this.skipped = skipped; + } + + public long getTime() { + return this.time; + } + + public long getBytes() { + return this.bytes; + } + + public long getEntriesSkipped() { + return this.skipped; + } + + public String toString() { + return "Mark(time=" + time + ", bytes=" + bytes + ", skipped=" + skipped + ")"; + } + } + +}; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSource.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSource.java new file mode 100644 index 00000000000..7b99f66aa88 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/LogSource.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +public interface LogSource extends Iterable { + public LogIterator iterator(long starttime, long endtime, FilterOp filter) throws IllegalArgumentException, FilterException; + + public LogIterator iterator(long starttime, long endtime) throws IllegalArgumentException; + + public LogIterator iterator() throws IllegalArgumentException; + + public boolean overlapsRange(long starttime, long endtime); + + public long size(); + + public long getStartTime(); + + public long getEndTime(); +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java new file mode 100644 index 00000000000..30dfed3f474 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MeasureThroughput.java @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import java.io.BufferedOutputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.HashSet; + +public class MeasureThroughput { + private static final int MS_PER_SEC = 1000; + private static final int MS_PER_MIN = MS_PER_SEC * 60; + private static final int MS_PER_HOUR = MS_PER_MIN * 60; + + public static void main(String[] args) throws IOException { + MergedLogSource source = new MergedLogSource(args); + + PrintStream ps_ms = new PrintStream(new BufferedOutputStream(new FileOutputStream("throughput-ms.out"))); + PrintStream ps_sec = new PrintStream(new BufferedOutputStream(new FileOutputStream("throughput-sec.out"))); + PrintStream ps_min = new PrintStream(new BufferedOutputStream(new FileOutputStream("throughput-min.out"))); + PrintStream ps_hour = new PrintStream(new BufferedOutputStream(new FileOutputStream("throughput-hour.out"))); + LogIterator iter; + + System.out.println(source); + iter = source.iterator(); + long currentms = 0; + long currentsec = 0; + long currentmin = 0; + long currenthour = 0; + HashSet zxids_ms = new HashSet(); + long zxid_sec = 0; + long zxid_min = 0; + long zxid_hour = 0; + + while (iter.hasNext()) { + LogEntry e = iter.next(); + TransactionEntry cxn = (TransactionEntry) e; + + long ms = cxn.getTimestamp(); + long sec = ms / MS_PER_SEC; + long min = ms / MS_PER_MIN; + long hour = ms / MS_PER_HOUR; + + if (currentms != ms && currentms != 0) { + ps_ms.println("" + currentms + " " + zxids_ms.size()); + + zxid_sec += zxids_ms.size(); + zxid_min += zxids_ms.size(); + zxid_hour += zxids_ms.size(); + zxids_ms.clear(); + } + + if (currentsec != sec && currentsec != 0) { + ps_sec.println("" + currentsec * MS_PER_SEC + " " + zxid_sec); + + zxid_sec = 0; + } + + if (currentmin != min && currentmin != 0) { + ps_min.println("" + currentmin * MS_PER_MIN + " " + zxid_min); + + zxid_min = 0; + } + + if (currenthour != hour && currenthour != 0) { + ps_hour.println("" + currenthour * MS_PER_HOUR + " " + zxid_hour); + + zxid_hour = 0; + } + + currentms = ms; + currentsec = sec; + currentmin = min; + currenthour = hour; + + zxids_ms.add(cxn.getZxid()); + } + + iter.close(); + ps_ms.close(); + ps_sec.close(); + ps_min.close(); + ps_hour.close(); + } +}; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MergedLogSource.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MergedLogSource.java new file mode 100644 index 00000000000..f8351f90b03 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/MergedLogSource.java @@ -0,0 +1,187 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Vector; + +public class MergedLogSource implements LogSource { + private static final Logger LOG = LoggerFactory.getLogger(MergedLogSource.class); + private Vector sources = null; + private long starttime = 0; + private long endtime = 0; + private long size = 0; + + public MergedLogSource(String[] files) throws IOException { + sources = new Vector(); + for (String f : files) { + addSource(f); + } + } + + public static void main(String[] args) throws IOException { + System.out.println("Time: " + System.currentTimeMillis()); + MergedLogSource s = new MergedLogSource(args); + System.out.println(s); + + LogIterator iter; + + iter = s.iterator(); + System.out.println("Time: " + System.currentTimeMillis()); + System.out.println("Iterator Size: " + iter.size()); + System.out.println("Time: " + System.currentTimeMillis()); + /* while (iter.hasNext()) { + System.out.println(iter.next()); + }*/ + iter.close(); + System.out.println("Time: " + System.currentTimeMillis()); + } + + public boolean overlapsRange(long starttime, long endtime) { + return (starttime <= this.endtime && endtime >= this.starttime); + } + + public long size() { + return size; + } + + public long getStartTime() { + return starttime; + } + + public long getEndTime() { + return endtime; + } + + public LogIterator iterator(long starttime, long endtime) throws IllegalArgumentException { + try { + return iterator(starttime, endtime, null); + } catch (FilterException fe) { + assert (false); // shouldn't happen without filter + return null; + } + } + + public LogIterator iterator(long starttime, long endtime, FilterOp filter) throws IllegalArgumentException, FilterException { + // sanitise start and end times + if (endtime < starttime) { + throw new IllegalArgumentException("End time (" + endtime + ") must be greater or equal to starttime (" + starttime + ")"); + } + + return new MergedLogSourceIterator(this, starttime, endtime, filter); + } + + public LogIterator iterator() throws IllegalArgumentException { + return iterator(starttime, endtime + 1); + } + + public void addSource(String f) throws IOException { + LogSource s = null; + if (TxnLogSource.isTransactionFile(f)) { + s = new TxnLogSource(f); + } else { + s = new Log4JSource(f); + } + + size += s.size(); + endtime = s.getEndTime() > endtime ? s.getEndTime() : endtime; + starttime = s.getStartTime() < starttime || starttime == 0 ? s.getStartTime() : starttime; + sources.add(s); + } + + public String toString() { + String s = "MergedLogSource(size=" + size + ", start=" + starttime + ", end=" + endtime + ")"; + for (LogSource src : sources) { + s += "\n\t- " + src; + } + return s; + } + + private class MergedLogSourceIterator implements LogIterator { + private LogEntry next = null; + private long start = 0; + private long end = 0; + private MergedLogSource src = null; + private LogIterator[] sources = null; + private LogEntry[] nexts = null; + private FilterOp filter = null; + + public MergedLogSourceIterator(MergedLogSource src, long starttime, long endtime, FilterOp filter) throws IllegalArgumentException, FilterException { + Vector iters = new Vector(); + for (LogSource s : src.sources) { + if (s.overlapsRange(starttime, endtime)) { + iters.add(s.iterator(starttime, endtime, filter)); + } + } + + sources = new LogIterator[iters.size()]; + sources = iters.toArray(sources); + nexts = new LogEntry[iters.size()]; + for (int i = 0; i < sources.length; i++) { + if (sources[i].hasNext()) + nexts[i] = sources[i].next(); + } + this.filter = filter; + } + + public MergedLogSourceIterator(MergedLogSource src, long starttime, long endtime) throws IllegalArgumentException, FilterException { + this(src, starttime, endtime, null); + } + + public long size() throws IOException { + long size = 0; + for (LogIterator i : sources) { + size += i.size(); + } + return size; + } + + public boolean hasNext() { + for (LogEntry n : nexts) { + if (n != null) return true; + } + return false; + } + + public LogEntry next() { + int min = -1; + for (int i = 0; i < nexts.length; i++) { + if (nexts[i] != null) { + if (min == -1) { + min = i; + } else if (nexts[i].getTimestamp() < nexts[min].getTimestamp()) { + min = i; + } + } + } + if (min == -1) { + return null; + } else { + LogEntry e = nexts[min]; + nexts[min] = sources[min].next(); + return e; + } + } + + public void remove() throws UnsupportedOperationException { + throw new UnsupportedOperationException("remove not supported for Merged logs"); + } + + public void close() throws IOException { + for (LogIterator i : sources) { + i.close(); + } + } + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java new file mode 100644 index 00000000000..5737f805f76 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java @@ -0,0 +1,325 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.io.Reader; + +public class RandomAccessFileReader extends Reader implements DataInput { + private static final Logger LOG = LoggerFactory.getLogger(RandomAccessFileReader.class); + private static final int DEFAULT_BUFFER_SIZE = 512 * 1024; // 512k + private RandomAccessFile file; + private byte[] buffer; + private int buffersize; + private int bufferoffset; + private long fileoffset; + private long fp; + private int point = 0; + + public RandomAccessFileReader(File f) throws FileNotFoundException { + file = new RandomAccessFile(f, "r"); + if (LOG.isDebugEnabled()) { + try { + LOG.debug("Opened file(" + f + ") with FD (" + file.getFD() + ")"); + } catch (IOException ioe) { + LOG.debug("Opened file(" + f + ") coulds get FD"); + } + } + + buffer = new byte[DEFAULT_BUFFER_SIZE]; + buffersize = 0; + bufferoffset = 0; + fileoffset = 0; + fp = 0; + } + + public static void main(String[] args) throws IOException { + RandomAccessFileReader f = new RandomAccessFileReader(new File(args[0])); + + long pos0 = f.getPosition(); + for (int i = 0; i < 5; i++) { + System.out.println(f.readLine()); + } + System.out.println("============="); + long pos1 = f.getPosition(); + System.out.println("pos: " + pos1); + for (int i = 0; i < 5; i++) { + System.out.println(f.readLine()); + } + System.out.println("============="); + f.seek(pos1); + for (int i = 0; i < 5; i++) { + System.out.println(f.readLine()); + } + System.out.println("============="); + f.seek(pos0); + for (int i = 0; i < 5; i++) { + System.out.println(f.readLine()); + } + long pos2 = f.getPosition(); + System.out.println("============="); + System.out.println(f.readLine()); + f.seek(pos2); + System.out.println(f.readLine()); + f.close(); + } + + /** + fill the buffer from the file. + fp keeps track of the file pointer. + fileoffset is the offset into the file to where the buffer came from. + */ + private int fill() throws IOException { + fileoffset = fp; + int read = file.read(buffer, 0, buffer.length); + + if (LOG.isDebugEnabled()) { + String buf = new String(buffer, 0, 40, "UTF-8"); + LOG.debug("fill(buffer=" + buf + ")"); + } + + if (read == -1) { // eof reached + buffersize = 0; + } else { + buffersize = read; + } + fp += buffersize; + bufferoffset = 0; + + return buffersize; + } + + /** + * Reader interface + */ + public boolean markSupported() { + return false; + } + + /** + copy what we can from buffer. if it's not enough, fill buffer again and copy again + */ + synchronized public int read(char[] cbuf, int off, int len) throws IOException { + // This could be faster, but probably wont be used + byte[] b = new byte[2]; + int bytesread = 0; + while (len > 0) { + int read = read(b, 0, 2); + bytesread += read; + if (read < 2) { + return bytesread; + } + cbuf[off] = (char) ((b[0] << 8) | (b[1] & 0xff)); + off += read; + len -= read; + } + + return bytesread; + } + + synchronized public int read(byte[] buf, int off, int len) throws IOException { + if (LOG.isTraceEnabled()) { + LOG.trace("read(buf, off=" + off + ", len=" + len); + } + + int read = 0; + while (len > 0) { + if (buffersize == 0) { + fill(); + if (buffersize == 0) { + break; + } + } + + int tocopy = Math.min(len, buffersize); + if (LOG.isTraceEnabled()) { + LOG.trace("tocopy=" + tocopy); + } + + System.arraycopy(buffer, bufferoffset, buf, off, tocopy); + buffersize -= tocopy; + bufferoffset += tocopy; + + len -= tocopy; + read += tocopy; + off += tocopy; + } + if (LOG.isTraceEnabled()) { + LOG.trace("read=" + read); + } + + return read; + } + + public void close() throws IOException { + file.close(); + } + + /** + * Seek interface + */ + public long getPosition() { + return bufferoffset + fileoffset; + } + + synchronized public void seek(long pos) throws IOException { + if (LOG.isDebugEnabled()) { + LOG.debug("seek(" + pos + ")"); + } + file.seek(pos); + fp = pos; + buffersize = 0; // force a buffer fill on next read + } + + /** + works like the usual readLine but disregards \r to make things easier + */ + synchronized public String readLine() throws IOException { + StringBuffer s = null; + + // go through buffer until i find a \n, if i reach end of buffer first, put whats in buffer into string buffer, + // repeat + buffering: + for (; ; ) { + if (buffersize == 0) { + fill(); + if (buffersize == 0) { + break; + } + } + + for (int i = 0; i < buffersize; i++) { + if (buffer[bufferoffset + i] == '\n') { + if (i > 0) { // if \n is first char in buffer, leave the string buffer empty + if (s == null) { + s = new StringBuffer(); + } + s.append(new String(buffer, bufferoffset, i, "UTF-8")); + } + bufferoffset += i + 1; + buffersize -= i + 1; + break buffering; + } + } + + // We didn't find \n, read the whole buffer into string buffer + if (s == null) { + s = new StringBuffer(); + } + s.append(new String(buffer, bufferoffset, buffersize, "UTF-8")); + buffersize = 0; + } + + if (s == null) { + return null; + } else { + return s.toString(); + } + } + + /** + DataInput interface + */ + public void readFully(byte[] b) throws IOException { + readFully(b, 0, b.length); + } + + public void readFully(byte[] b, int off, int len) throws IOException { + while (len > 0) { + int read = read(b, off, len); + len -= read; + off += read; + + if (read == 0) { + throw new EOFException("End of file reached"); + } + } + } + + public int skipBytes(int n) throws IOException { + seek(getPosition() + n); + return n; + } + + public boolean readBoolean() throws IOException { + return (readByte() != 0); + } + + public byte readByte() throws IOException { + byte[] b = new byte[1]; + readFully(b, 0, 1); + return b[0]; + } + + public int readUnsignedByte() throws IOException { + return (int) readByte(); + } + + public short readShort() throws IOException { + byte[] b = new byte[2]; + readFully(b, 0, 2); + return (short) ((b[0] << 8) | (b[1] & 0xff)); + } + + public int readUnsignedShort() throws IOException { + byte[] b = new byte[2]; + readFully(b, 0, 2); + return (((b[0] & 0xff) << 8) | (b[1] & 0xff)); + } + + public char readChar() throws IOException { + return (char) readShort(); + } + + public int readInt() throws IOException { + byte[] b = new byte[4]; + readFully(b, 0, 4); + return (((b[0] & 0xff) << 24) | ((b[1] & 0xff) << 16) | ((b[2] & 0xff) << 8) | (b[3] & 0xff)); + } + + public long readLong() throws IOException { + byte[] b = new byte[8]; + readFully(b, 0, 8); + + return (((long) (b[0] & 0xff) << 56) | ((long) (b[1] & 0xff) << 48) | + ((long) (b[2] & 0xff) << 40) | ((long) (b[3] & 0xff) << 32) | + ((long) (b[4] & 0xff) << 24) | ((long) (b[5] & 0xff) << 16) | + ((long) (b[6] & 0xff) << 8) | ((long) (b[7] & 0xff))); + } + + public float readFloat() throws IOException { + return Float.intBitsToFloat(readInt()); + } + + public double readDouble() throws IOException { + return Double.longBitsToDouble(readLong()); + } + + public String readUTF() throws IOException { + int len = readUnsignedShort(); + byte[] bytes = new byte[len + 2]; + bytes[0] = (byte) ((len >> 8) & 0xFF); + bytes[1] = (byte) (len & 0xFF); + readFully(bytes, 2, len); + DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); + return dis.readUTF(); + } +}; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/TransactionEntry.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/TransactionEntry.java new file mode 100644 index 00000000000..0c1d02ccc50 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/TransactionEntry.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +public class TransactionEntry extends LogEntry { + public TransactionEntry(long timestamp, long clientId, long Cxid, long Zxid, String op) { + this(timestamp, clientId, Cxid, Zxid, op, ""); + } + + public TransactionEntry(long timestamp, long clientId, long Cxid, long Zxid, String op, String extra) { + super(timestamp); + setAttribute("client-id", new Long(clientId)); + setAttribute("cxid", new Long(Cxid)); + setAttribute("zxid", new Long(Zxid)); + setAttribute("operation", op); + setAttribute("extra", extra); + } + + public long getClientId() { + return (Long) getAttribute("client-id"); + } + + public long getCxid() { + return (Long) getAttribute("cxid"); + } + + public long getZxid() { + return (Long) getAttribute("zxid"); + } + + public String getOp() { + return (String) getAttribute("operation"); + } + + public String getExtra() { + return (String) getAttribute("extra"); + } + + public String toString() { + return getTimestamp() + ":::session(0x" + Long.toHexString(getClientId()) + ") cxid(0x" + Long.toHexString(getCxid()) + ") zxid(0x" + Long.toHexString(getZxid()) + ") op(" + getOp() + ") extra(" + getExtra() + ")"; + } + + public Type getType() { + return LogEntry.Type.TXN; + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/TxnLogSource.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/TxnLogSource.java new file mode 100644 index 00000000000..8fc2a576b3e --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/TxnLogSource.java @@ -0,0 +1,362 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.persistence.FileHeader; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.ErrorTxn; +import org.apache.zookeeper.txn.SetACLTxn; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.EOFException; +import java.io.File; +import java.io.IOException; +import java.util.NoSuchElementException; +import java.util.zip.Adler32; +import java.util.zip.Checksum; + +public class TxnLogSource implements LogSource { + private static final Logger LOG = LoggerFactory.getLogger(TxnLogSource.class); + private static final int skipN = 10000; + private LogSkipList skiplist = null; + private String file = null; + private long starttime = 0; + private long endtime = 0; + private long size = 0; + + public TxnLogSource(String file) throws IOException { + this.file = file; + + skiplist = new LogSkipList(); + + RandomAccessFileReader reader = new RandomAccessFileReader(new File(file)); + try { + BinaryInputArchive logStream = new BinaryInputArchive(reader); + FileHeader fhdr = new FileHeader(); + fhdr.deserialize(logStream, "fileheader"); + + byte[] bytes = null; + while (true) { + long lastFp = reader.getPosition(); + + long crcValue; + + try { + crcValue = logStream.readLong("crcvalue"); + bytes = logStream.readBuffer("txnEntry"); + } catch (EOFException e) { + break; + } + + if (bytes.length == 0) { + break; + } + Checksum crc = new Adler32(); + crc.update(bytes, 0, bytes.length); + if (crcValue != crc.getValue()) { + throw new IOException("CRC doesn't match " + crcValue + + " vs " + crc.getValue()); + } + if (logStream.readByte("EOR") != 'B') { + throw new EOFException("Last transaction was partial."); + } + TxnHeader hdr = new TxnHeader(); + Record r = SerializeUtils.deserializeTxn(bytes, hdr); + + if (starttime == 0) { + starttime = hdr.getTime(); + } + endtime = hdr.getTime(); + + if (size % skipN == 0) { + skiplist.addMark(hdr.getTime(), lastFp, size); + } + size++; + } + if (bytes == null) { + throw new IOException("Nothing read from (" + file + ")"); + } + } finally { + reader.close(); + } + } + + public static boolean isTransactionFile(String file) throws IOException { + RandomAccessFileReader reader = new RandomAccessFileReader(new File(file)); + BinaryInputArchive logStream = new BinaryInputArchive(reader); + FileHeader fhdr = new FileHeader(); + fhdr.deserialize(logStream, "fileheader"); + reader.close(); + + return fhdr.getMagic() == FileTxnLog.TXNLOG_MAGIC; + } + + public static void main(String[] args) throws IOException, FilterException { + TxnLogSource s = new TxnLogSource(args[0]); + System.out.println(s); + + LogIterator iter; + + if (args.length == 3) { + long starttime = Long.valueOf(args[1]); + long endtime = Long.valueOf(args[2]); + FilterOp fo = new FilterParser("(or (and (> zxid 0x2f0bd6f5e0) (< zxid 0x2f0bd6f5e9)) (= operation \"error\"))").parse(); + System.out.println("fo: " + fo); + iter = s.iterator(starttime, endtime, fo); + } else { + iter = s.iterator(); + } + System.out.println(iter); + while (iter.hasNext()) { + System.out.println(iter.next()); + } + iter.close(); + } + + public boolean overlapsRange(long starttime, long endtime) { + return (starttime <= this.endtime && endtime >= this.starttime); + } + + public long size() { + return size; + } + + public long getStartTime() { + return starttime; + } + + public long getEndTime() { + return endtime; + } + + public LogSkipList getSkipList() { + return skiplist; + } + + public LogIterator iterator(long starttime, long endtime) throws IllegalArgumentException { + try { + return iterator(starttime, endtime, null); + } catch (FilterException fe) { + assert (false); // should never ever happen + return null; + } + } + + public LogIterator iterator(long starttime, long endtime, FilterOp filter) throws IllegalArgumentException, FilterException { + // sanitise start and end times + if (endtime < starttime) { + throw new IllegalArgumentException("End time (" + endtime + ") must be greater or equal to starttime (" + starttime + ")"); + } + + return new TxnLogSourceIterator(this, starttime, endtime, filter); + } + + public LogIterator iterator() throws IllegalArgumentException { + return iterator(starttime, endtime + 1); + } + + public String toString() { + return "TxnLogSource(file=" + file + ", size=" + size + ", start=" + starttime + ", end=" + endtime + ")"; + } + + private class TxnLogSourceIterator implements LogIterator { + private LogEntry next = null; + private long starttime = 0; + private long endtime = 0; + private TxnLogSource src = null; + private RandomAccessFileReader reader = null; + private BinaryInputArchive logStream = null; + private long skippedAtStart = 0; + private FilterOp filter = null; + + public TxnLogSourceIterator(TxnLogSource src, long starttime, long endtime) throws IllegalArgumentException, FilterException { + this(src, starttime, endtime, null); + } + + public TxnLogSourceIterator(TxnLogSource src, long starttime, long endtime, FilterOp filter) throws IllegalArgumentException, FilterException { + try { + this.src = src; + this.starttime = starttime; + this.endtime = endtime; + reader = new RandomAccessFileReader(new File(src.file)); + logStream = new BinaryInputArchive(reader); + FileHeader fhdr = new FileHeader(); + fhdr.deserialize(logStream, "fileheader"); + } catch (Exception e) { + throw new IllegalArgumentException("Cannot open transaction log (" + src.file + ") :" + e); + } + + LogSkipList.Mark start = src.getSkipList().findMarkBefore(starttime); + try { + reader.seek(start.getBytes()); + skippedAtStart = start.getEntriesSkipped(); + } catch (IOException ioe) { + // if we can't skip, we should just read from the start + } + + this.filter = filter; + + LogEntry e; + while ((e = readNextEntry()) != null && e.getTimestamp() < endtime) { + if (e.getTimestamp() >= starttime && (filter == null || filter.matches(e))) { + next = e; + return; + } + skippedAtStart++; + } + + + } + + public long size() throws IOException { + if (this.endtime >= src.getEndTime()) { + return src.size() - skippedAtStart; + } + + long pos = reader.getPosition(); + LogEntry e; + + LogSkipList.Mark lastseg = src.getSkipList().findMarkBefore(this.endtime); + reader.seek(lastseg.getBytes()); + // number of entries skipped to get to the end of the iterator, less the number skipped to get to the start + long count = lastseg.getEntriesSkipped() - skippedAtStart; + + while ((e = readNextEntry()) != null) { + if (e.getTimestamp() > this.endtime) { + break; + } + count++; + } + reader.seek(pos); + ; + + return count; + } + + private LogEntry readNextEntry() { + LogEntry e = null; + try { + long crcValue; + byte[] bytes; + try { + crcValue = logStream.readLong("crcvalue"); + + bytes = logStream.readBuffer("txnEntry"); + } catch (EOFException ex) { + return null; + } + + if (bytes.length == 0) { + return null; + } + Checksum crc = new Adler32(); + crc.update(bytes, 0, bytes.length); + if (crcValue != crc.getValue()) { + throw new IOException("CRC doesn't match " + crcValue + + " vs " + crc.getValue()); + } + TxnHeader hdr = new TxnHeader(); + Record r = SerializeUtils.deserializeTxn(bytes, hdr); + + switch (hdr.getType()) { + case OpCode.createSession: { + e = new TransactionEntry(hdr.getTime(), hdr.getClientId(), hdr.getCxid(), hdr.getZxid(), "createSession"); + } + break; + case OpCode.closeSession: { + e = new TransactionEntry(hdr.getTime(), hdr.getClientId(), hdr.getCxid(), hdr.getZxid(), "closeSession"); + } + break; + case OpCode.create: + if (r != null) { + CreateTxn create = (CreateTxn) r; + String path = create.getPath(); + e = new TransactionEntry(hdr.getTime(), hdr.getClientId(), hdr.getCxid(), hdr.getZxid(), "create", path); + } + break; + case OpCode.setData: + if (r != null) { + SetDataTxn set = (SetDataTxn) r; + String path = set.getPath(); + e = new TransactionEntry(hdr.getTime(), hdr.getClientId(), hdr.getCxid(), hdr.getZxid(), "setData", path); + } + break; + case OpCode.setACL: + if (r != null) { + SetACLTxn setacl = (SetACLTxn) r; + String path = setacl.getPath(); + e = new TransactionEntry(hdr.getTime(), hdr.getClientId(), hdr.getCxid(), hdr.getZxid(), "setACL", path); + } + break; + case OpCode.error: + if (r != null) { + ErrorTxn error = (ErrorTxn) r; + + e = new TransactionEntry(hdr.getTime(), hdr.getClientId(), hdr.getCxid(), hdr.getZxid(), "error", "Error: " + error.getErr()); + } + break; + default: + LOG.info("Unknown op: " + hdr.getType()); + break; + } + + if (logStream.readByte("EOR") != 'B') { + throw new EOFException("Last transaction was partial."); + } + } catch (Exception ex) { + LOG.error("Error reading transaction from (" + src.file + ") :" + e); + return null; + } + return e; + } + + public boolean hasNext() { + return next != null; + } + + public LogEntry next() throws NoSuchElementException { + LogEntry ret = next; + LogEntry e = readNextEntry(); + + if (filter != null) { + try { + while (e != null && !filter.matches(e)) { + e = readNextEntry(); + } + } catch (FilterException fe) { + throw new NoSuchElementException(fe.toString()); + } + } + if (e != null && e.getTimestamp() < endtime) { + next = e; + } else { + next = null; + } + return ret; + } + + public void remove() throws UnsupportedOperationException { + throw new UnsupportedOperationException("remove not supported for Txn logs"); + } + + public void close() throws IOException { + reader.close(); + } + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/AndOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/AndOp.java new file mode 100644 index 00000000000..6ad33493e79 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/AndOp.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterException; +import org.apache.zookeeper.graph.FilterOp; +import org.apache.zookeeper.graph.LogEntry; + +public class AndOp extends FilterOp { + public boolean matches(LogEntry entry) throws FilterException { + for (FilterOp f : subOps) { + if (!f.matches(entry)) { + return false; + } + } + return true; + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/Arg.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/Arg.java new file mode 100644 index 00000000000..e258f8a1b17 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/Arg.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterOp.*; + +public class Arg { + protected T value; + private ArgType type; + + protected Arg(ArgType type) { + this.type = type; + } + + public ArgType getType() { + return type; + } + + public T getValue() { + return value; + } + + public String toString() { + return "[" + type + ":" + value + "]"; + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/EqualsOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/EqualsOp.java new file mode 100644 index 00000000000..5a8eb49c9ef --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/EqualsOp.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterException; +import org.apache.zookeeper.graph.FilterOp; +import org.apache.zookeeper.graph.LogEntry; + +public class EqualsOp extends FilterOp { + public boolean matches(LogEntry entry) throws FilterException { + + Object last = null; + for (Arg a : args) { + Object v = a.getValue(); + if (a.getType() == FilterOp.ArgType.SYMBOL) { + String key = (String) a.getValue(); + v = entry.getAttribute(key); + } + + if (last != null + && !last.equals(v)) { + return false; + } + last = v; + } + + return true; + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/GreaterThanOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/GreaterThanOp.java new file mode 100644 index 00000000000..c3583e10e92 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/GreaterThanOp.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterException; +import org.apache.zookeeper.graph.FilterOp; +import org.apache.zookeeper.graph.LogEntry; + +public class GreaterThanOp extends FilterOp { + public boolean matches(LogEntry entry) throws FilterException { + Arg first = args.get(0); + + if (first != null) { + FilterOp.ArgType type = first.getType(); + if (type == FilterOp.ArgType.SYMBOL) { + String key = (String) first.getValue(); + Object v = entry.getAttribute(key); + if (v instanceof String) { + type = FilterOp.ArgType.STRING; + } else if (v instanceof Double || v instanceof Long || v instanceof Integer || v instanceof Short) { + type = FilterOp.ArgType.NUMBER; + } else { + throw new FilterException("LessThanOp: Invalid argument, first argument resolves to neither a String nor a Number"); + } + } + + Object last = null; + for (Arg a : args) { + Object v = a.getValue(); + if (a.getType() == FilterOp.ArgType.SYMBOL) { + String key = (String) a.getValue(); + v = entry.getAttribute(key); + } + + if (last != null) { + if (type == FilterOp.ArgType.STRING) { + if (((String) last).compareTo((String) v) <= 0) { + return false; + } + } else if (type == FilterOp.ArgType.NUMBER) { + // System.out.println("last[" + ((Number)last).longValue() + "] v["+ ((Number)v).longValue() + "]"); + if (((Number) last).longValue() <= ((Number) v).longValue()) { + return false; + } + } + } + last = v; + } + return true; + } else { + return true; + } + } + +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/LessThanOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/LessThanOp.java new file mode 100644 index 00000000000..f5a6364b430 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/LessThanOp.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterException; +import org.apache.zookeeper.graph.FilterOp; +import org.apache.zookeeper.graph.LogEntry; + +public class LessThanOp extends FilterOp { + public boolean matches(LogEntry entry) throws FilterException { + Arg first = args.get(0); + + if (first != null) { + FilterOp.ArgType type = first.getType(); + if (type == FilterOp.ArgType.SYMBOL) { + String key = (String) first.getValue(); + Object v = entry.getAttribute(key); + if (v instanceof String) { + type = FilterOp.ArgType.STRING; + } else if (v instanceof Double || v instanceof Long || v instanceof Integer || v instanceof Short) { + type = FilterOp.ArgType.NUMBER; + } else { + throw new FilterException("LessThanOp: Invalid argument, first argument resolves to neither a String nor a Number"); + } + } + + Object last = null; + for (Arg a : args) { + Object v = a.getValue(); + if (a.getType() == FilterOp.ArgType.SYMBOL) { + String key = (String) a.getValue(); + v = entry.getAttribute(key); + } + + if (last != null) { + if (type == FilterOp.ArgType.STRING) { + if (((String) last).compareTo((String) v) >= 0) { + return false; + } + } else if (type == FilterOp.ArgType.NUMBER) { + if (((Number) last).doubleValue() >= ((Number) v).doubleValue()) { + return false; + } + } + } + last = v; + } + return true; + } else { + return true; + } + } + +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NotOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NotOp.java new file mode 100644 index 00000000000..306b87a38a9 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NotOp.java @@ -0,0 +1,24 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterException; +import org.apache.zookeeper.graph.FilterOp; +import org.apache.zookeeper.graph.LogEntry; + +public class NotOp extends FilterOp { + public boolean matches(LogEntry entry) throws FilterException { + if (subOps.size() != 1) { + throw new FilterException("Not operation can only take one argument"); + } + return !subOps.get(0).matches(entry); + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NumberArg.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NumberArg.java new file mode 100644 index 00000000000..3f0a5eeb38e --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/NumberArg.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterOp.*; + +public class NumberArg extends Arg { + public NumberArg(Long value) { + super(ArgType.NUMBER); + this.value = value; + } +}; + diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/OrOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/OrOp.java new file mode 100644 index 00000000000..e558e48f6a8 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/OrOp.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterException; +import org.apache.zookeeper.graph.FilterOp; +import org.apache.zookeeper.graph.LogEntry; + +public class OrOp extends FilterOp { + public boolean matches(LogEntry entry) throws FilterException { + for (FilterOp f : subOps) { + if (f.matches(entry)) { + return true; + } + } + return false; + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/StringArg.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/StringArg.java new file mode 100644 index 00000000000..8a93aecb1a1 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/StringArg.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterOp.*; + +public class StringArg extends Arg { + public StringArg(String value) { + super(ArgType.STRING); + this.value = value; + } +}; + diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/SymbolArg.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/SymbolArg.java new file mode 100644 index 00000000000..61445277bcd --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/SymbolArg.java @@ -0,0 +1,20 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterOp.*; + +public class SymbolArg extends Arg { + public SymbolArg(String value) { + super(ArgType.SYMBOL); + this.value = value; + } +}; diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/XorOp.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/XorOp.java new file mode 100644 index 00000000000..2b982fa0f2a --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/filterops/XorOp.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.filterops; + +import org.apache.zookeeper.graph.FilterException; +import org.apache.zookeeper.graph.FilterOp; +import org.apache.zookeeper.graph.LogEntry; + +public class XorOp extends FilterOp { + public boolean matches(LogEntry entry) throws FilterException { + int count = 0; + for (FilterOp f : subOps) { + if (f.matches(entry)) { + count++; + if (count > 1) { + return false; + } + } + } + if (count == 1) { + return true; + } + return false; + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/FileLoader.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/FileLoader.java new file mode 100644 index 00000000000..26f5446f846 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/FileLoader.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.servlets; + +import org.apache.zookeeper.graph.*; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +public class FileLoader extends JsonServlet { + private MergedLogSource source = null; + + public FileLoader(MergedLogSource src) throws Exception { + source = src; + } + + String handleRequest(JsonRequest request) throws Exception { + String output = ""; + + String file = request.getString("path", "/"); + JSONObject o = new JSONObject(); + try { + this.source.addSource(file); + o.put("status", "OK"); + + } catch (Exception e) { + o.put("status", "ERR"); + o.put("error", e.toString()); + } + + return JSONValue.toJSONString(o); + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Fs.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Fs.java new file mode 100644 index 00000000000..7f4e681b1a8 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Fs.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.servlets; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Comparator; + +public class Fs extends JsonServlet { + String handleRequest(JsonRequest request) throws Exception { + String output = ""; + JSONArray filelist = new JSONArray(); + + File base = new File(request.getString("path", "/")); + if (!base.exists() || !base.isDirectory()) { + throw new FileNotFoundException("Couldn't find [" + request + "]"); + } + File[] files = base.listFiles(); + Arrays.sort(files, new Comparator() { + public int compare(File o1, File o2) { + if (o1.isDirectory() != o2.isDirectory()) { + if (o1.isDirectory()) { + return -1; + } else { + return 1; + } + } + return o1.getName().compareToIgnoreCase(o2.getName()); + } + }); + + for (File f : files) { + JSONObject o = new JSONObject(); + o.put("file", f.getName()); + o.put("type", f.isDirectory() ? "D" : "F"); + o.put("path", f.getCanonicalPath()); + filelist.add(o); + } + return JSONValue.toJSONString(filelist); + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/GraphData.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/GraphData.java new file mode 100644 index 00000000000..8b72757b766 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/GraphData.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.servlets; + +import org.apache.zookeeper.graph.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GraphData extends JsonServlet { + private static final Logger LOG = LoggerFactory.getLogger(GraphData.class); + private static final int DEFAULT_PERIOD = 1000; + + private LogSource source = null; + + public GraphData(LogSource src) throws Exception { + this.source = src; + } + + String handleRequest(JsonRequest request) throws Exception { + + + long starttime = 0; + long endtime = 0; + long period = 0; + FilterOp fo = null; + + starttime = request.getNumber("start", 0); + endtime = request.getNumber("end", 0); + period = request.getNumber("period", 0); + String filterstr = request.getString("filter", ""); + + if (filterstr.length() > 0) { + fo = new FilterParser(filterstr).parse(); + } + + if (starttime == 0) { + starttime = source.getStartTime(); + } + if (endtime == 0) { + if (period > 0) { + endtime = starttime + period; + } else { + endtime = starttime + DEFAULT_PERIOD; + } + } + + if (LOG.isDebugEnabled()) { + LOG.debug("handle(start= " + starttime + ", end=" + endtime + ", period=" + period + ")"); + } + + LogIterator iterator = (fo != null) ? + source.iterator(starttime, endtime, fo) : source.iterator(starttime, endtime); + return new JsonGenerator(iterator).toString(); + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/JsonServlet.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/JsonServlet.java new file mode 100644 index 00000000000..5d05c91403c --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/JsonServlet.java @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.servlets; + +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +import java.io.IOException; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +abstract public class JsonServlet extends HttpServlet { + abstract String handleRequest(JsonRequest request) throws Exception; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/plain;charset=utf-8"); + response.setStatus(HttpServletResponse.SC_OK); + + try { + String req = request.getRequestURI().substring(request.getServletPath().length()); + + response.getWriter().println(handleRequest(new JsonRequest(request))); + } catch (Exception e) { + JSONObject o = new JSONObject(); + o.put("error", e.toString()); + response.getWriter().println(JSONValue.toJSONString(o)); + } catch (java.lang.OutOfMemoryError oom) { + JSONObject o = new JSONObject(); + o.put("error", "Out of memory. Perhaps you've requested too many logs. Try narrowing you're filter criteria."); + response.getWriter().println(JSONValue.toJSONString(o)); + } + } + + protected class JsonRequest { + private Map map; + + public JsonRequest(ServletRequest request) { + map = request.getParameterMap(); + } + + public long getNumber(String name, long defaultnum) { + String[] vals = (String[]) map.get(name); + if (vals == null || vals.length == 0) { + return defaultnum; + } + + try { + return Long.valueOf(vals[0]); + } catch (NumberFormatException e) { + return defaultnum; + } + } + + public String getString(String name, String defaultstr) { + String[] vals = (String[]) map.get(name); + if (vals == null || vals.length == 0) { + return defaultstr; + } else { + return vals[0]; + } + } + } +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java new file mode 100644 index 00000000000..306ae5c6085 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.servlets; + +import org.apache.zookeeper.graph.*; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class NumEvents extends JsonServlet { + private static final Logger LOG = LoggerFactory.getLogger(NumEvents.class); + private static final int DEFAULT_PERIOD = 1000; + + private LogSource source = null; + + public NumEvents(LogSource src) throws Exception { + this.source = src; + } + + String handleRequest(JsonRequest request) throws Exception { + String output = ""; + + long starttime = 0; + long endtime = 0; + long period = 0; + + starttime = request.getNumber("start", 0); + endtime = request.getNumber("end", 0); + period = request.getNumber("period", 0); + + if (starttime == 0) { + starttime = source.getStartTime(); + } + if (endtime == 0) { + if (period > 0) { + endtime = starttime + period; + } else { + endtime = source.getEndTime(); + } + } + + LogIterator iter = source.iterator(starttime, endtime); + JSONObject data = new JSONObject(); + data.put("startTime", starttime); + data.put("endTime", endtime); + long size = 0; + + size = iter.size(); + + data.put("numEntries", size); + if (LOG.isDebugEnabled()) { + LOG.debug("handle(start= " + starttime + ", end=" + endtime + ", numEntries=" + size + ")"); + } + iter.close(); + return JSONValue.toJSONString(data); + } +} + diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java new file mode 100644 index 00000000000..5bc048a6ccf --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.servlets; + +import java.io.IOException; +import java.io.InputStream; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class StaticContent extends HttpServlet { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String path = request.getRequestURI().substring(request.getServletPath().length()); + + InputStream resource = ClassLoader.getSystemResourceAsStream("org/apache/zookeeper/graph/resources" + path); + if (resource == null) { + response.getWriter().println(path + " not found!"); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + return; + } + try { + while (resource.available() > 0) { + response.getWriter().write(resource.read()); + } + } finally { + resource.close(); + } + // response.setContentType("text/plain;charset=utf-8"); + response.setStatus(HttpServletResponse.SC_OK); + } + +} diff --git a/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java new file mode 100644 index 00000000000..cf2dede3be1 --- /dev/null +++ b/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/Throughput.java @@ -0,0 +1,109 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.graph.servlets; + +import org.apache.zookeeper.graph.*; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +import java.util.HashSet; + + +public class Throughput extends JsonServlet { + private static final int MS_PER_SEC = 1000; + private static final int MS_PER_MIN = MS_PER_SEC * 60; + private static final int MS_PER_HOUR = MS_PER_MIN * 60; + + private LogSource source = null; + + public Throughput(LogSource src) throws Exception { + this.source = src; + } + + public String handleRequest(JsonRequest request) throws Exception { + long starttime = 0; + long endtime = 0; + long period = 0; + long scale = 0; + + starttime = request.getNumber("start", 0); + endtime = request.getNumber("end", 0); + period = request.getNumber("period", 0); + + + if (starttime == 0) { + starttime = source.getStartTime(); + } + if (endtime == 0) { + if (period > 0) { + endtime = starttime + period; + } else { + endtime = source.getEndTime(); + } + } + + String scalestr = request.getString("scale", "minutes"); + if (scalestr.equals("seconds")) { + scale = MS_PER_SEC; + } else if (scalestr.equals("hours")) { + scale = MS_PER_HOUR; + } else { + scale = MS_PER_MIN; + } + + LogIterator iter = source.iterator(starttime, endtime); + + long current = 0; + long currentms = 0; + HashSet zxids_ms = new HashSet(); + long zxidcount = 0; + + JSONArray events = new JSONArray(); + while (iter.hasNext()) { + LogEntry e = iter.next(); + if (e.getType() != LogEntry.Type.TXN) { + continue; + } + + TransactionEntry cxn = (TransactionEntry) e; + + long ms = cxn.getTimestamp(); + long inscale = ms / scale; + + if (currentms != ms && currentms != 0) { + zxidcount += zxids_ms.size(); + zxids_ms.clear(); + } + + if (inscale != current && current != 0) { + JSONObject o = new JSONObject(); + o.put("time", current * scale); + o.put("count", zxidcount); + events.add(o); + zxidcount = 0; + } + current = inscale; + currentms = ms; + + zxids_ms.add(cxn.getZxid()); + } + JSONObject o = new JSONObject(); + o.put("time", current * scale); + o.put("count", zxidcount); + events.add(o); + + iter.close(); + + return JSONValue.toJSONString(events); + } + +}; diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/log4j.properties b/src/contrib/loggraph/web/org/apache/zookeeper/graph/log4j.properties new file mode 100644 index 00000000000..e1121b118d7 --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/log4j.properties @@ -0,0 +1,9 @@ +log4j.rootLogger=TRACE, CONSOLE +# Print the date in ISO 8601 format +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Threshold=TRACE +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n +log4j.logger.org.apache.zookeeper.graph.LogSkipList=off +log4j.logger.org.apache.zookeeper.graph.RandomAccessFileReader=off +#log4j.logger.org.apache.zookeeper.graph.Log4JSource=off \ No newline at end of file diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/date.format.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/date.format.js new file mode 100644 index 00000000000..d6fe4f6096e --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/date.format.js @@ -0,0 +1,130 @@ +/* + * Date Format 1.2.3 + * (c) 2007-2009 Steven Levithan + * MIT license + * + * Includes enhancements by Scott Trenda + * and Kris Kowal + * + * Accepts a date, a mask, or a date and a mask. + * Returns a formatted version of the given date. + * The date defaults to the current date/time. + * The mask defaults to dateFormat.masks.default. + */ + +var dateFormat = function () { + var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, + timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, + timezoneClip = /[^-+\dA-Z]/g, + pad = function (val, len) { + val = String(val); + len = len || 2; + while (val.length < len) { + val = "0" + val; + } + return val; + }; + + // Regexes and supporting functions are cached through closure + return function (date, mask, utc) { + var dF = dateFormat; + + // You can't provide utc if you skip other args (use the "UTC:" mask prefix) + if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { + mask = date; + date = undefined; + } + + // Passing date through Date applies Date.parse, if necessary + date = date ? new Date(date) : new Date; + if (isNaN(date)) { + throw SyntaxError("invalid date"); + } + + mask = String(dF.masks[mask] || mask || dF.masks["default"]); + + // Allow setting the utc argument via the mask + if (mask.slice(0, 4) == "UTC:") { + mask = mask.slice(4); + utc = true; + } + + var _ = utc ? "getUTC" : "get", + d = date[_ + "Date"](), + D = date[_ + "Day"](), + m = date[_ + "Month"](), + y = date[_ + "FullYear"](), + H = date[_ + "Hours"](), + M = date[_ + "Minutes"](), + s = date[_ + "Seconds"](), + L = date[_ + "Milliseconds"](), + o = utc ? 0 : date.getTimezoneOffset(), + flags = { + d: d, + dd: pad(d), + ddd: dF.i18n.dayNames[D], + dddd: dF.i18n.dayNames[D + 7], + m: m + 1, + mm: pad(m + 1), + mmm: dF.i18n.monthNames[m], + mmmm: dF.i18n.monthNames[m + 12], + yy: String(y).slice(2), + yyyy: y, + h: H % 12 || 12, + hh: pad(H % 12 || 12), + H: H, + HH: pad(H), + M: M, + MM: pad(M), + s: s, + ss: pad(s), + l: pad(L, 3), + L: pad(L > 99 ? Math.round(L / 10) : L), + t: H < 12 ? "a" : "p", + tt: H < 12 ? "am" : "pm", + T: H < 12 ? "A" : "P", + TT: H < 12 ? "AM" : "PM", + Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), + o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), + S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10] + }; + + return mask.replace(token, function ($0) { + return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); + }); + }; +}(); + +// Some common format strings +dateFormat.masks = { + "default": "ddd mmm dd yyyy HH:MM:ss", + shortDate: "m/d/yy", + mediumDate: "mmm d, yyyy", + longDate: "mmmm d, yyyy", + fullDate: "dddd, mmmm d, yyyy", + shortTime: "h:MM TT", + mediumTime: "h:MM:ss TT", + longTime: "h:MM:ss TT Z", + isoDate: "yyyy-mm-dd", + isoTime: "HH:MM:ss", + isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", + isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" +}; + +// Internationalization strings +dateFormat.i18n = { + dayNames: [ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" + ], + monthNames: [ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" + ] +}; + +// For convenience... +Date.prototype.format = function (mask, utc) { + return dateFormat(this, mask, utc); +}; + diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.bar.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.bar.js new file mode 100644 index 00000000000..3f4baf0462d --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.bar.js @@ -0,0 +1,388 @@ +/* + * g.Raphael 0.4 - Charting library, based on Raphaël + * + * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com) + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. + */ +Raphael.fn.g.barchart = function (x, y, width, height, values, opts) { + opts = opts || {}; + var type = {round: "round", sharp: "sharp", soft: "soft"}[opts.type] || "square", + gutter = parseFloat(opts.gutter || "20%"), + chart = this.set(), + bars = this.set(), + covers = this.set(), + covers2 = this.set(), + total = Math.max.apply(Math, values), + stacktotal = [], + paper = this, + multi = 0, + colors = opts.colors || this.g.colors, + len = values.length; + if (this.raphael.is(values[0], "array")) { + total = []; + multi = len; + len = 0; + for (var i = values.length; i--;) { + bars.push(this.set()); + total.push(Math.max.apply(Math, values[i])); + len = Math.max(len, values[i].length); + } + if (opts.stacked) { + for (var i = len; i--;) { + var tot = 0; + for (var j = values.length; j--;) { + tot += +values[j][i] || 0; + } + stacktotal.push(tot); + } + } + for (var i = values.length; i--;) { + if (values[i].length < len) { + for (var j = len; j--;) { + values[i].push(0); + } + } + } + total = Math.max.apply(Math, opts.stacked ? stacktotal : total); + } + + total = (opts.to) || total; + var barwidth = width / (len * (100 + gutter) + gutter) * 100, + barhgutter = barwidth * gutter / 100, + barvgutter = opts.vgutter == null ? 20 : opts.vgutter, + stack = [], + X = x + barhgutter, + Y = (height - 2 * barvgutter) / total; + if (!opts.stretch) { + barhgutter = Math.round(barhgutter); + barwidth = Math.floor(barwidth); + } + !opts.stacked && (barwidth /= multi || 1); + for (var i = 0; i < len; i++) { + stack = []; + for (var j = 0; j < (multi || 1); j++) { + var h = Math.round((multi ? values[j][i] : values[i]) * Y), + top = y + height - barvgutter - h, + bar = this.g.finger(Math.round(X + barwidth / 2), top + h, barwidth, h, true, type).attr({stroke: colors[multi ? j : i], fill: colors[multi ? j : i]}); + if (multi) { + bars[j].push(bar); + } else { + bars.push(bar); + } + bar.y = top; + bar.x = Math.round(X + barwidth / 2); + bar.w = barwidth; + bar.h = h; + bar.value = multi ? values[j][i] : values[i]; + if (!opts.stacked) { + X += barwidth; + } else { + stack.push(bar); + } + } + if (opts.stacked) { + var cvr; + covers2.push(cvr = this.rect(stack[0].x - stack[0].w / 2, y, barwidth, height).attr(this.g.shim)); + cvr.bars = this.set(); + var size = 0; + for (var s = stack.length; s--;) { + stack[s].toFront(); + } + for (var s = 0, ss = stack.length; s < ss; s++) { + var bar = stack[s], + cover, + h = (size + bar.value) * Y, + path = this.g.finger(bar.x, y + height - barvgutter - !!size * .5, barwidth, h, true, type, 1); + cvr.bars.push(bar); + size && bar.attr({path: path}); + bar.h = h; + bar.y = y + height - barvgutter - !!size * .5 - h; + covers.push(cover = this.rect(bar.x - bar.w / 2, bar.y, barwidth, bar.value * Y).attr(this.g.shim)); + cover.bar = bar; + cover.value = bar.value; + size += bar.value; + } + X += barwidth; + } + X += barhgutter; + } + covers2.toFront(); + X = x + barhgutter; + if (!opts.stacked) { + for (var i = 0; i < len; i++) { + for (var j = 0; j < (multi || 1); j++) { + var cover; + covers.push(cover = this.rect(Math.round(X), y + barvgutter, barwidth, height - barvgutter).attr(this.g.shim)); + cover.bar = multi ? bars[j][i] : bars[i]; + cover.value = cover.bar.value; + X += barwidth; + } + X += barhgutter; + } + } + chart.label = function (labels, isBottom) { + labels = labels || []; + this.labels = paper.set(); + var L, l = -Infinity; + if (opts.stacked) { + for (var i = 0; i < len; i++) { + var tot = 0; + for (var j = 0; j < (multi || 1); j++) { + tot += multi ? values[j][i] : values[i]; + if (j == multi - 1) { + var label = paper.g.labelise(labels[i], tot, total); + L = paper.g.text(bars[i * (multi || 1) + j].x, y + height - barvgutter / 2, label).insertBefore(covers[i * (multi || 1) + j]); + var bb = L.getBBox(); + if (bb.x - 7 < l) { + L.remove(); + } else { + this.labels.push(L); + l = bb.x + bb.width; + } + } + } + } + } else { + for (var i = 0; i < len; i++) { + for (var j = 0; j < (multi || 1); j++) { + var label = paper.g.labelise(multi ? labels[j] && labels[j][i] : labels[i], multi ? values[j][i] : values[i], total); + L = paper.g.text(bars[i * (multi || 1) + j].x, isBottom ? y + height - barvgutter / 2 : bars[i * (multi || 1) + j].y - 10, label).insertBefore(covers[i * (multi || 1) + j]); + var bb = L.getBBox(); + if (bb.x - 7 < l) { + L.remove(); + } else { + this.labels.push(L); + l = bb.x + bb.width; + } + } + } + } + return this; + }; + chart.hover = function (fin, fout) { + covers2.hide(); + covers.show(); + covers.mouseover(fin).mouseout(fout); + return this; + }; + chart.hoverColumn = function (fin, fout) { + covers.hide(); + covers2.show(); + fout = fout || function () { + }; + covers2.mouseover(fin).mouseout(fout); + return this; + }; + chart.click = function (f) { + covers2.hide(); + covers.show(); + covers.click(f); + return this; + }; + chart.each = function (f) { + if (!Raphael.is(f, "function")) { + return this; + } + for (var i = covers.length; i--;) { + f.call(covers[i]); + } + return this; + }; + chart.eachColumn = function (f) { + if (!Raphael.is(f, "function")) { + return this; + } + for (var i = covers2.length; i--;) { + f.call(covers2[i]); + } + return this; + }; + chart.clickColumn = function (f) { + covers.hide(); + covers2.show(); + covers2.click(f); + return this; + }; + chart.push(bars, covers, covers2); + chart.bars = bars; + chart.covers = covers; + return chart; +}; +Raphael.fn.g.hbarchart = function (x, y, width, height, values, opts) { + opts = opts || {}; + var type = {round: "round", sharp: "sharp", soft: "soft"}[opts.type] || "square", + gutter = parseFloat(opts.gutter || "20%"), + chart = this.set(), + bars = this.set(), + covers = this.set(), + covers2 = this.set(), + total = Math.max.apply(Math, values), + stacktotal = [], + paper = this, + multi = 0, + colors = opts.colors || this.g.colors, + len = values.length; + if (this.raphael.is(values[0], "array")) { + total = []; + multi = len; + len = 0; + for (var i = values.length; i--;) { + bars.push(this.set()); + total.push(Math.max.apply(Math, values[i])); + len = Math.max(len, values[i].length); + } + if (opts.stacked) { + for (var i = len; i--;) { + var tot = 0; + for (var j = values.length; j--;) { + tot += +values[j][i] || 0; + } + stacktotal.push(tot); + } + } + for (var i = values.length; i--;) { + if (values[i].length < len) { + for (var j = len; j--;) { + values[i].push(0); + } + } + } + total = Math.max.apply(Math, opts.stacked ? stacktotal : total); + } + + total = (opts.to) || total; + var barheight = Math.floor(height / (len * (100 + gutter) + gutter) * 100), + bargutter = Math.floor(barheight * gutter / 100), + stack = [], + Y = y + bargutter, + X = (width - 1) / total; + !opts.stacked && (barheight /= multi || 1); + for (var i = 0; i < len; i++) { + stack = []; + for (var j = 0; j < (multi || 1); j++) { + var val = multi ? values[j][i] : values[i], + bar = this.g.finger(x, Y + barheight / 2, Math.round(val * X), barheight - 1, false, type).attr({stroke: colors[multi ? j : i], fill: colors[multi ? j : i]}); + if (multi) { + bars[j].push(bar); + } else { + bars.push(bar); + } + bar.x = x + Math.round(val * X); + bar.y = Y + barheight / 2; + bar.w = Math.round(val * X); + bar.h = barheight; + bar.value = +val; + if (!opts.stacked) { + Y += barheight; + } else { + stack.push(bar); + } + } + if (opts.stacked) { + var cvr = this.rect(x, stack[0].y - stack[0].h / 2, width, barheight).attr(this.g.shim); + covers2.push(cvr); + cvr.bars = this.set(); + var size = 0; + for (var s = stack.length; s--;) { + stack[s].toFront(); + } + for (var s = 0, ss = stack.length; s < ss; s++) { + var bar = stack[s], + cover, + val = Math.round((size + bar.value) * X), + path = this.g.finger(x, bar.y, val, barheight - 1, false, type, 1); + cvr.bars.push(bar); + size && bar.attr({path: path}); + bar.w = val; + bar.x = x + val; + covers.push(cover = this.rect(x + size * X, bar.y - bar.h / 2, bar.value * X, barheight).attr(this.g.shim)); + cover.bar = bar; + size += bar.value; + } + Y += barheight; + } + Y += bargutter; + } + covers2.toFront(); + Y = y + bargutter; + if (!opts.stacked) { + for (var i = 0; i < len; i++) { + for (var j = 0; j < multi; j++) { + var cover = this.rect(x, Y, width, barheight).attr(this.g.shim); + covers.push(cover); + cover.bar = bars[j][i]; + Y += barheight; + } + Y += bargutter; + } + } + chart.label = function (labels, isRight) { + labels = labels || []; + this.labels = paper.set(); + for (var i = 0; i < len; i++) { + for (var j = 0; j < multi; j++) { + var label = paper.g.labelise(multi ? labels[j] && labels[j][i] : labels[i], multi ? values[j][i] : values[i], total); + var X = isRight ? bars[i * (multi || 1) + j].x - barheight / 2 + 3 : x + 5, + A = isRight ? "end" : "start", + L; + this.labels.push(L = paper.g.text(X, bars[i * (multi || 1) + j].y, label).attr({"text-anchor": A}).insertBefore(covers[0])); + if (L.getBBox().x < x + 5) { + L.attr({x: x + 5, "text-anchor": "start"}); + } else { + bars[i * (multi || 1) + j].label = L; + } + } + } + return this; + }; + chart.hover = function (fin, fout) { + covers2.hide(); + covers.show(); + fout = fout || function () { + }; + covers.mouseover(fin).mouseout(fout); + return this; + }; + chart.hoverColumn = function (fin, fout) { + covers.hide(); + covers2.show(); + fout = fout || function () { + }; + covers2.mouseover(fin).mouseout(fout); + return this; + }; + chart.each = function (f) { + if (!Raphael.is(f, "function")) { + return this; + } + for (var i = covers.length; i--;) { + f.call(covers[i]); + } + return this; + }; + chart.eachColumn = function (f) { + if (!Raphael.is(f, "function")) { + return this; + } + for (var i = covers2.length; i--;) { + f.call(covers2[i]); + } + return this; + }; + chart.click = function (f) { + covers2.hide(); + covers.show(); + covers.click(f); + return this; + }; + chart.clickColumn = function (f) { + covers.hide(); + covers2.show(); + covers2.click(f); + return this; + }; + chart.push(bars, covers, covers2); + chart.bars = bars; + chart.covers = covers; + return chart; +}; diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.dot.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.dot.js new file mode 100644 index 00000000000..0b7ba67d342 --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.dot.js @@ -0,0 +1,123 @@ +/* + * g.Raphael 0.4 - Charting library, based on Raphaël + * + * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com) + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. + */ +Raphael.fn.g.dotchart = function (x, y, width, height, valuesx, valuesy, size, opts) { + function drawAxis(ax) { + +ax[0] && (ax[0] = + paper.g.axis(x + gutter, y + gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 2, opts.axisxlabels || null, opts.axisxtype || "t")); + +ax[1] && (ax[1] = + paper.g.axis(x + width - gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 3, opts.axisylabels || null, opts.axisytype + || "t")); + +ax[2] && (ax[2] = + paper.g.axis(x + gutter, y + height - gutter + maxR, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 0, opts.axisxlabels || null, opts.axisxtype + || "t")); + +ax[3] && (ax[3] = + paper.g.axis(x + gutter - maxR, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 1, opts.axisylabels || null, opts.axisytype + || "t")); + } + + opts = opts || {}; + var xdim = this.g.snapEnds(Math.min.apply(Math, valuesx), Math.max.apply(Math, valuesx), valuesx.length - 1), + minx = xdim.from, + maxx = xdim.to, + gutter = opts.gutter || 10, + ydim = this.g.snapEnds(Math.min.apply(Math, valuesy), Math.max.apply(Math, valuesy), valuesy.length - 1), + miny = ydim.from, + maxy = ydim.to, + len = Math.max(valuesx.length, valuesy.length, size.length), + symbol = this.g.markers[opts.symbol] || "disc", + res = this.set(), + series = this.set(), + max = opts.max || 100, + top = Math.max.apply(Math, size), + R = [], + paper = this, + k = Math.sqrt(top / Math.PI) * 2 / max; + + for (var i = 0; i < len; i++) { + R[i] = Math.min(Math.sqrt(size[i] / Math.PI) * 2 / k, max); + } + gutter = Math.max.apply(Math, R.concat(gutter)); + var axis = this.set(), + maxR = Math.max.apply(Math, R); + if (opts.axis) { + var ax = (opts.axis + "").split(/[,\s]+/); + drawAxis(ax); + var g = [], b = []; + for (var i = 0, ii = ax.length; i < ii; i++) { + var bb = ax[i].all ? ax[i].all.getBBox()[["height", "width"][i % 2]] : 0; + g[i] = bb + gutter; + b[i] = bb; + } + gutter = Math.max.apply(Math, g.concat(gutter)); + for (var i = 0, ii = ax.length; i < ii; i++) { + if (ax[i].all) { + ax[i].remove(); + ax[i] = 1; + } + } + drawAxis(ax); + for (var i = 0, ii = ax.length; i < ii; i++) { + if (ax[i].all) { + axis.push(ax[i].all); + } + } + res.axis = axis; + } + var kx = (width - gutter * 2) / ((maxx - minx) || 1), + ky = (height - gutter * 2) / ((maxy - miny) || 1); + for (var i = 0, ii = valuesy.length; i < ii; i++) { + var sym = this.raphael.is(symbol, "array") ? symbol[i] : symbol, + X = x + gutter + (valuesx[i] - minx) * kx, + Y = y + height - gutter - (valuesy[i] - miny) * ky; + sym && R[i] && series.push( + this.g[sym](X, Y, R[i]).attr({fill: opts.heat ? this.g.colorValue(R[i], maxR) : Raphael.fn.g.colors[0], "fill-opacity": opts.opacity ? R[i] / max : 1, stroke: "none"})); + } + var covers = this.set(); + for (var i = 0, ii = valuesy.length; i < ii; i++) { + var X = x + gutter + (valuesx[i] - minx) * kx, + Y = y + height - gutter - (valuesy[i] - miny) * ky; + covers.push(this.circle(X, Y, maxR).attr(this.g.shim)); + opts.href && opts.href[i] && covers[i].attr({href: opts.href[i]}); + covers[i].r = +R[i].toFixed(3); + covers[i].x = +X.toFixed(3); + covers[i].y = +Y.toFixed(3); + covers[i].X = valuesx[i]; + covers[i].Y = valuesy[i]; + covers[i].value = size[i] || 0; + covers[i].dot = series[i]; + } + res.covers = covers; + res.series = series; + res.push(series, axis, covers); + res.hover = function (fin, fout) { + covers.mouseover(fin).mouseout(fout); + return this; + }; + res.click = function (f) { + covers.click(f); + return this; + }; + res.each = function (f) { + if (!Raphael.is(f, "function")) { + return this; + } + for (var i = covers.length; i--;) { + f.call(covers[i]); + } + return this; + }; + res.href = function (map) { + var cover; + for (var i = covers.length; i--;) { + cover = covers[i]; + if (cover.X == map.x && cover.Y == map.y && cover.value == map.value) { + cover.attr({href: map.href}); + } + } + }; + return res; +}; diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.line.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.line.js new file mode 100644 index 00000000000..6185dc774fc --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.line.js @@ -0,0 +1,237 @@ +/* + * g.Raphael 0.4 - Charting library, based on Raphaël + * + * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com) + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. + */ +Raphael.fn.g.linechart = function (x, y, width, height, valuesx, valuesy, opts) { + function shrink(values, dim) { + var k = values.length / dim, + j = 0, + l = k, + sum = 0, + res = []; + while (j < values.length) { + l--; + if (l < 0) { + sum += values[j] * (1 + l); + res.push(sum / k); + sum = values[j++] * -l; + l += k; + } else { + sum += values[j++]; + } + } + return res; + } + + opts = opts || {}; + if (!this.raphael.is(valuesx[0], "array")) { + valuesx = [valuesx]; + } + if (!this.raphael.is(valuesy[0], "array")) { + valuesy = [valuesy]; + } + var allx = Array.prototype.concat.apply([], valuesx), + ally = Array.prototype.concat.apply([], valuesy), + xdim = this.g.snapEnds(Math.min.apply(Math, allx), Math.max.apply(Math, allx), valuesx[0].length - 1), + minx = xdim.from, + maxx = xdim.to, + gutter = opts.gutter || 10, + kx = (width - gutter * 2) / (maxx - minx), + ydim = this.g.snapEnds(Math.min.apply(Math, ally), Math.max.apply(Math, ally), valuesy[0].length - 1), + miny = ydim.from, + maxy = ydim.to, + ky = (height - gutter * 2) / (maxy - miny), + len = Math.max(valuesx[0].length, valuesy[0].length), + symbol = opts.symbol || "", + colors = opts.colors || Raphael.fn.g.colors, + that = this, + columns = null, + dots = null, + chart = this.set(), + path = []; + + for (var i = 0, ii = valuesy.length; i < ii; i++) { + len = Math.max(len, valuesy[i].length); + } + var shades = this.set(); + for (var i = 0, ii = valuesy.length; i < ii; i++) { + if (opts.shade) { + shades.push(this.path().attr({stroke: "none", fill: colors[i], opacity: opts.nostroke ? 1 : .3})); + } + if (valuesy[i].length > width - 2 * gutter) { + valuesy[i] = shrink(valuesy[i], width - 2 * gutter); + len = width - 2 * gutter; + } + if (valuesx[i] && valuesx[i].length > width - 2 * gutter) { + valuesx[i] = shrink(valuesx[i], width - 2 * gutter); + } + } + var axis = this.set(); + if (opts.axis) { + var ax = (opts.axis + "").split(/[,\s]+/); + +ax[0] && axis.push(this.g.axis(x + gutter, y + gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 2, opts.northlabels)); + +ax[1] && axis.push(this.g.axis(x + width - gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 3, opts.eastlabels)); + +ax[2] && axis.push(this.g.axis(x + gutter, y + height - gutter, width - 2 * gutter, minx, maxx, opts.axisxstep || Math.floor((width - 2 * gutter) / 20), 0, opts.southlabels)); + +ax[3] && axis.push(this.g.axis(x + gutter, y + height - gutter, height - 2 * gutter, miny, maxy, opts.axisystep || Math.floor((height - 2 * gutter) / 20), 1, opts.westlabels)); + } + if (opts.northAxisLabel) { + this.g.text(x + gutter + width / 2, gutter, opts.northAxisLabel); + } + if (opts.southAxisLabel) { + this.g.text(x + gutter + width / 2, y + height + 20, opts.southAxisLabel); + } + if (opts.westAxisLabel) { + this.g.text(gutter, y + gutter + height / 2, opts.westAxisLabel).attr({rotation: -90}); + } + if (opts.eastAxisLabel) { + this.g.text(x + gutter + width + 20, y + gutter + height / 2, opts.eastAxisLabel).attr({rotation: 90}); + } + + var lines = this.set(), + symbols = this.set(), + line; + for (var i = 0, ii = valuesy.length; i < ii; i++) { + if (!opts.nostroke) { + lines.push(line = this.path().attr({ + stroke: colors[i], + "stroke-width": opts.width || 2, + "stroke-linejoin": "round", + "stroke-linecap": "round", + "stroke-dasharray": opts.dash || "" + })); + } + var sym = this.raphael.is(symbol, "array") ? symbol[i] : symbol, + symset = this.set(); + path = []; + for (var j = 0, jj = valuesy[i].length; j < jj; j++) { + var X = x + gutter + ((valuesx[i] || valuesx[0])[j] - minx) * kx; + var Y = y + height - gutter - (valuesy[i][j] - miny) * ky; + (Raphael.is(sym, "array") ? sym[j] : sym) && symset.push( + this.g[Raphael.fn.g.markers[this.raphael.is(sym, "array") ? sym[j] : sym]](X, Y, (opts.width || 2) * 3).attr({fill: colors[i], stroke: "none"})); + path = path.concat([j ? "L" : "M", X, Y]); + } + symbols.push(symset); + if (opts.shade) { + shades[i].attr({path: path.concat(["L", X, y + height - gutter, "L", x + gutter + ((valuesx[i] || valuesx[0])[0] - minx) * kx, y + height - gutter, "z"]).join(",")}); + } + !opts.nostroke && line.attr({path: path.join(",")}); + } + + function createColumns(f) { + // unite Xs together + var Xs = []; + for (var i = 0, ii = valuesx.length; i < ii; i++) { + Xs = Xs.concat(valuesx[i]); + } + Xs.sort(); + // remove duplicates + var Xs2 = [], + xs = []; + for (var i = 0, ii = Xs.length; i < ii; i++) { + Xs[i] != Xs[i - 1] && Xs2.push(Xs[i]) && xs.push(x + gutter + (Xs[i] - minx) * kx); + } + Xs = Xs2; + ii = Xs.length; + var cvrs = f || that.set(); + for (var i = 0; i < ii; i++) { + var X = xs[i] - (xs[i] - (xs[i - 1] || x)) / 2, + w = ((xs[i + 1] || x + width) - xs[i]) / 2 + (xs[i] - (xs[i - 1] || x)) / 2, + C; + f ? (C = {}) : cvrs.push(C = that.rect(X - 1, y, Math.max(w + 1, 1), height).attr({stroke: "none", fill: "#000", opacity: 0})); + C.values = []; + C.symbols = that.set(); + C.y = []; + C.x = xs[i]; + C.axis = Xs[i]; + for (var j = 0, jj = valuesy.length; j < jj; j++) { + Xs2 = valuesx[j] || valuesx[0]; + for (var k = 0, kk = Xs2.length; k < kk; k++) { + if (Xs2[k] == Xs[i]) { + C.values.push(valuesy[j][k]); + C.y.push(y + height - gutter - (valuesy[j][k] - miny) * ky); + C.symbols.push(chart.symbols[j][k]); + } + } + } + f && f.call(C); + } + !f && (columns = cvrs); + } + + function createDots(f) { + var cvrs = f || that.set(), + C; + for (var i = 0, ii = valuesy.length; i < ii; i++) { + for (var j = 0, jj = valuesy[i].length; j < jj; j++) { + var X = x + gutter + ((valuesx[i] || valuesx[0])[j] - minx) * kx, + nearX = x + gutter + ((valuesx[i] || valuesx[0])[j ? j - 1 : 1] - minx) * kx, + Y = y + height - gutter - (valuesy[i][j] - miny) * ky; + f ? (C = {}) : cvrs.push(C = that.circle(X, Y, Math.abs(nearX - X) / 2).attr({stroke: "none", fill: "#000", opacity: 0})); + C.x = X; + C.y = Y; + C.value = valuesy[i][j]; + C.line = chart.lines[i]; + C.shade = chart.shades[i]; + C.symbol = chart.symbols[i][j]; + C.symbols = chart.symbols[i]; + C.axis = (valuesx[i] || valuesx[0])[j]; + f && f.call(C); + } + } + !f && (dots = cvrs); + } + + chart.push(lines, shades, symbols, axis, columns, dots); + chart.lines = lines; + chart.shades = shades; + chart.symbols = symbols; + chart.axis = axis; + chart.hoverColumn = function (fin, fout) { + !columns && createColumns(); + columns.mouseover(fin).mouseout(fout); + return this; + }; + chart.clickColumn = function (f) { + !columns && createColumns(); + columns.click(f); + return this; + }; + chart.hrefColumn = function (cols) { + var hrefs = that.raphael.is(arguments[0], "array") ? arguments[0] : arguments; + if (!(arguments.length - 1) && typeof cols == "object") { + for (var x in cols) { + for (var i = 0, ii = columns.length; i < ii; i++) { + if (columns[i].axis == x) { + columns[i].attr("href", cols[x]); + } + } + } + } + !columns && createColumns(); + for (var i = 0, ii = hrefs.length; i < ii; i++) { + columns[i] && columns[i].attr("href", hrefs[i]); + } + return this; + }; + chart.hover = function (fin, fout) { + !dots && createDots(); + dots.mouseover(fin).mouseout(fout); + return this; + }; + chart.click = function (f) { + !dots && createDots(); + dots.click(f); + return this; + }; + chart.each = function (f) { + createDots(f); + return this; + }; + chart.eachColumn = function (f) { + createColumns(f); + return this; + }; + return chart; +}; diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.pie.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.pie.js new file mode 100644 index 00000000000..4dd42bfb4ad --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.pie.js @@ -0,0 +1,223 @@ +/* + * g.Raphael 0.4 - Charting library, based on Raphaël + * + * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com) + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. + */ +Raphael.fn.g.piechart = function (cx, cy, r, values, opts) { + opts = opts || {}; + var paper = this, + sectors = [], + covers = this.set(), + chart = this.set(), + series = this.set(), + order = [], + len = values.length, + angle = 0, + total = 0, + others = 0, + cut = 9, + defcut = true; + chart.covers = covers; + if (len == 1) { + series.push(this.circle(cx, cy, r).attr({fill: this.g.colors[0], stroke: opt.stroke || "#fff", "stroke-width": opts.strokewidth == null ? 1 : opts.strokewidth})); + covers.push(this.circle(cx, cy, r).attr(this.g.shim)); + total = values[0]; + values[0] = { + value: values[0], order: 0, valueOf: function () { + return this.value; + } + }; + series[0].middle = {x: cx, y: cy}; + series[0].mangle = 180; + } else { + function sector(cx, cy, r, startAngle, endAngle, fill) { + var rad = Math.PI / 180, + x1 = cx + r * Math.cos(-startAngle * rad), + x2 = cx + r * Math.cos(-endAngle * rad), + xm = cx + r / 2 * Math.cos(-(startAngle + (endAngle - startAngle) / 2) * rad), + y1 = cy + r * Math.sin(-startAngle * rad), + y2 = cy + r * Math.sin(-endAngle * rad), + ym = cy + r / 2 * Math.sin(-(startAngle + (endAngle - startAngle) / 2) * rad), + res = ["M", cx, cy, "L", x1, y1, "A", r, r, 0, +(Math.abs(endAngle - startAngle) > 180), 1, x2, y2, "z"]; + res.middle = {x: xm, y: ym}; + return res; + } + + for (var i = 0; i < len; i++) { + total += values[i]; + values[i] = { + value: values[i], order: i, valueOf: function () { + return this.value; + } + }; + } + values.sort(function (a, b) { + return b.value - a.value; + }); + for (var i = 0; i < len; i++) { + if (defcut && values[i] * 360 / total <= 1.5) { + cut = i; + defcut = false; + } + if (i > cut) { + defcut = false; + values[cut].value += values[i]; + values[cut].others = true; + others = values[cut].value; + } + } + len = Math.min(cut + 1, values.length); + others && values.splice(len) && (values[cut].others = true); + for (var i = 0; i < len; i++) { + var mangle = angle - 360 * values[i] / total / 2; + if (!i) { + angle = 90 - mangle; + mangle = angle - 360 * values[i] / total / 2; + } + if (opts.init) { + var ipath = sector(cx, cy, 1, angle, angle - 360 * values[i] / total).join(","); + } + var path = sector(cx, cy, r, angle, angle -= 360 * values[i] / total); + var p = this.path(opts.init ? ipath : path).attr({ + fill: opts.colors && opts.colors[i] || this.g.colors[i] || "#666", + stroke: opts.stroke || "#fff", + "stroke-width": (opts.strokewidth == null ? 1 : opts.strokewidth), + "stroke-linejoin": "round" + }); + p.value = values[i]; + p.middle = path.middle; + p.mangle = mangle; + sectors.push(p); + series.push(p); + opts.init && p.animate({path: path.join(",")}, (+opts.init - 1) || 1000, ">"); + } + for (var i = 0; i < len; i++) { + var p = paper.path(sectors[i].attr("path")).attr(this.g.shim); + opts.href && opts.href[i] && p.attr({href: opts.href[i]}); + p.attr = function () { + }; + covers.push(p); + series.push(p); + } + } + + chart.hover = function (fin, fout) { + fout = fout || function () { + }; + var that = this; + for (var i = 0; i < len; i++) { + (function (sector, cover, j) { + var o = { + sector: sector, + cover: cover, + cx: cx, + cy: cy, + mx: sector.middle.x, + my: sector.middle.y, + mangle: sector.mangle, + r: r, + value: values[j], + total: total, + label: that.labels && that.labels[j] + }; + cover.mouseover(function () { + fin.call(o); + }).mouseout(function () { + fout.call(o); + }); + })(series[i], covers[i], i); + } + return this; + }; + // x: where label could be put + // y: where label could be put + // value: value to show + // total: total number to count % + chart.each = function (f) { + var that = this; + for (var i = 0; i < len; i++) { + (function (sector, cover, j) { + var o = { + sector: sector, + cover: cover, + cx: cx, + cy: cy, + x: sector.middle.x, + y: sector.middle.y, + mangle: sector.mangle, + r: r, + value: values[j], + total: total, + label: that.labels && that.labels[j] + }; + f.call(o); + })(series[i], covers[i], i); + } + return this; + }; + chart.click = function (f) { + var that = this; + for (var i = 0; i < len; i++) { + (function (sector, cover, j) { + var o = { + sector: sector, + cover: cover, + cx: cx, + cy: cy, + mx: sector.middle.x, + my: sector.middle.y, + mangle: sector.mangle, + r: r, + value: values[j], + total: total, + label: that.labels && that.labels[j] + }; + cover.click(function () { + f.call(o); + }); + })(series[i], covers[i], i); + } + return this; + }; + chart.inject = function (element) { + element.insertBefore(covers[0]); + }; + var legend = function (labels, otherslabel, mark, dir) { + var x = cx + r + r / 5, + y = cy, + h = y + 10; + labels = labels || []; + dir = (dir && dir.toLowerCase && dir.toLowerCase()) || "east"; + mark = paper.g.markers[mark && mark.toLowerCase()] || "disc"; + chart.labels = paper.set(); + for (var i = 0; i < len; i++) { + var clr = series[i].attr("fill"), + j = values[i].order, + txt; + values[i].others && (labels[j] = otherslabel || "Others"); + labels[j] = paper.g.labelise(labels[j], values[i], total); + chart.labels.push(paper.set()); + chart.labels[i].push(paper.g[mark](x + 5, h, 5).attr({fill: clr, stroke: "none"})); + chart.labels[i].push(txt = paper.text(x + 20, h, labels[j] || values[j]).attr(paper.g.txtattr).attr({fill: opts.legendcolor || "#000", "text-anchor": "start"})); + covers[i].label = chart.labels[i]; + h += txt.getBBox().height * 1.2; + } + var bb = chart.labels.getBBox(), + tr = { + east: [0, -bb.height / 2], + west: [-bb.width - 2 * r - 20, -bb.height / 2], + north: [-r - bb.width / 2, -r - bb.height - 10], + south: [-r - bb.width / 2, r + 10] + }[dir]; + chart.labels.translate.apply(chart.labels, tr); + chart.push(chart.labels); + }; + if (opts.legend) { + legend(opts.legend, opts.legendothers, opts.legendmark, opts.legendpos); + } + chart.push(series, covers); + chart.series = series; + chart.covers = covers; + return chart; +}; diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.raphael.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.raphael.js new file mode 100644 index 00000000000..a0a76073cca --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/g.raphael.js @@ -0,0 +1,490 @@ +/* + * g.Raphael 0.4 - Charting library, based on Raphaël + * + * Copyright (c) 2009 Dmitry Baranovskiy (http://g.raphaeljs.com) + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. + */ + +(function () { + Raphael.fn.g = Raphael.fn.g || {}; + Raphael.fn.g.markers = { + disc: "disc", + o: "disc", + flower: "flower", + f: "flower", + diamond: "diamond", + d: "diamond", + square: "square", + s: "square", + triangle: "triangle", + t: "triangle", + star: "star", + "*": "star", + cross: "cross", + x: "cross", + plus: "plus", + "+": "plus", + arrow: "arrow", + "->": "arrow" + }; + Raphael.fn.g.shim = {stroke: "none", fill: "#000", "fill-opacity": 0}; + Raphael.fn.g.txtattr = {font: "12px Arial, sans-serif"}; + Raphael.fn.g.colors = []; + var hues = [.6, .2, .05, .1333, .75, 0]; + for (var i = 0; i < 10; i++) { + if (i < hues.length) { + Raphael.fn.g.colors.push("hsb(" + hues[i] + ", .75, .75)"); + } else { + Raphael.fn.g.colors.push("hsb(" + hues[i - hues.length] + ", 1, .5)"); + } + } + Raphael.fn.g.text = function (x, y, text) { + return this.text(x, y, text).attr(this.g.txtattr); + }; + Raphael.fn.g.labelise = function (label, val, total) { + if (label) { + return (label + "").replace(/(##+(?:\.#+)?)|(%%+(?:\.%+)?)/g, function (all, value, percent) { + if (value) { + return (+val).toFixed(value.replace(/^#+\.?/g, "").length); + } + if (percent) { + return (val * 100 / total).toFixed(percent.replace(/^%+\.?/g, "").length) + "%"; + } + }); + } else { + return (+val).toFixed(0); + } + }; + + Raphael.fn.g.finger = function (x, y, width, height, dir, ending, isPath) { + // dir 0 for horisontal and 1 for vertical + if ((dir && !height) || (!dir && !width)) { + return isPath ? "" : this.path(); + } + ending = {square: "square", sharp: "sharp", soft: "soft"}[ending] || "round"; + var path; + height = Math.round(height); + width = Math.round(width); + x = Math.round(x); + y = Math.round(y); + switch (ending) { + case "round": + if (!dir) { + var r = Math.floor(height / 2); + if (width < r) { + r = width; + path = ["M", x + .5, y + .5 - Math.floor(height / 2), "l", 0, 0, "a", r, Math.floor(height / 2), 0, 0, 1, 0, height, "l", 0, 0, "z"]; + } else { + path = ["M", x + .5, y + .5 - r, "l", width - r, 0, "a", r, r, 0, 1, 1, 0, height, "l", r - width, 0, "z"]; + } + } else { + var r = Math.floor(width / 2); + if (height < r) { + r = height; + path = ["M", x - Math.floor(width / 2), y, "l", 0, 0, "a", Math.floor(width / 2), r, 0, 0, 1, width, 0, "l", 0, 0, "z"]; + } else { + path = ["M", x - r, y, "l", 0, r - height, "a", r, r, 0, 1, 1, width, 0, "l", 0, height - r, "z"]; + } + } + break; + case "sharp": + if (!dir) { + var half = Math.floor(height / 2); + path = ["M", x, y + half, "l", 0, -height, Math.max(width - half, 0), 0, Math.min(half, width), half, -Math.min(half, width), half + (half * 2 < height), "z"]; + } else { + var half = Math.floor(width / 2); + path = ["M", x + half, y, "l", -width, 0, 0, -Math.max(height - half, 0), half, -Math.min(half, height), half, Math.min(half, height), half, "z"]; + } + break; + case "square": + if (!dir) { + path = ["M", x, y + Math.floor(height / 2), "l", 0, -height, width, 0, 0, height, "z"]; + } else { + path = ["M", x + Math.floor(width / 2), y, "l", 1 - width, 0, 0, -height, width - 1, 0, "z"]; + } + break; + case "soft": + var r; + if (!dir) { + r = Math.min(width, Math.round(height / 5)); + path = ["M", x + .5, y + .5 - Math.floor(height / 2), "l", width - r, 0, "a", r, r, 0, 0, 1, r, r, "l", 0, height - r * 2, "a", r, r, 0, 0, 1, -r, r, "l", r - width, 0, "z"]; + } else { + r = Math.min(Math.round(width / 5), height); + path = ["M", x - Math.floor(width / 2), y, "l", 0, r - height, "a", r, r, 0, 0, 1, r, -r, "l", width - 2 * r, 0, "a", r, r, 0, 0, 1, r, r, "l", 0, height - r, "z"]; + } + } + if (isPath) { + return path.join(","); + } else { + return this.path(path); + } + }; + + // Symbols + Raphael.fn.g.disc = function (cx, cy, r) { + return this.circle(cx, cy, r); + }; + Raphael.fn.g.line = function (cx, cy, r) { + return this.rect(cx - r, cy - r / 5, 2 * r, 2 * r / 5); + }; + Raphael.fn.g.square = function (cx, cy, r) { + r = r * .7; + return this.rect(cx - r, cy - r, 2 * r, 2 * r); + }; + Raphael.fn.g.triangle = function (cx, cy, r) { + r *= 1.75; + return this.path("M".concat(cx, ",", cy, "m0-", r * .58, "l", r * .5, ",", r * .87, "-", r, ",0z")); + }; + Raphael.fn.g.diamond = function (cx, cy, r) { + return this.path(["M", cx, cy - r, "l", r, r, -r, r, -r, -r, r, -r, "z"]); + }; + Raphael.fn.g.flower = function (cx, cy, r, n) { + r = r * 1.25; + var rout = r, + rin = rout * .5; + n = +n < 3 || !n ? 5 : n; + var points = ["M", cx, cy + rin, "Q"], + R; + for (var i = 1; i < n * 2 + 1; i++) { + R = i % 2 ? rout : rin; + points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]); + } + points.push("z"); + return this.path(points.join(",")); + }; + Raphael.fn.g.star = function (cx, cy, r, r2) { + r2 = r2 || r * .5; + var points = ["M", cx, cy + r2, "L"], + R; + for (var i = 1; i < 10; i++) { + R = i % 2 ? r : r2; + points = points.concat([(cx + R * Math.sin(i * Math.PI * .2)).toFixed(3), (cy + R * Math.cos(i * Math.PI * .2)).toFixed(3)]); + } + points.push("z"); + return this.path(points.join(",")); + }; + Raphael.fn.g.cross = function (cx, cy, r) { + r = r / 2.5; + return this.path("M".concat(cx - r, ",", cy, "l", [-r, -r, r, -r, r, r, r, -r, r, r, -r, r, r, r, -r, r, -r, -r, -r, r, -r, -r, "z"])); + }; + Raphael.fn.g.plus = function (cx, cy, r) { + r = r / 2; + return this.path("M".concat(cx - r / 2, ",", cy - r / 2, "l", [0, -r, r, 0, 0, r, r, 0, 0, r, -r, 0, 0, r, -r, 0, 0, -r, -r, 0, 0, -r, "z"])); + }; + Raphael.fn.g.arrow = function (cx, cy, r) { + return this.path("M".concat(cx - r * .7, ",", cy - r * .4, "l", [r * .6, 0, 0, -r * .4, r, r * .8, -r, r * .8, 0, -r * .4, -r * .6, 0], "z")); + }; + + // Tooltips + Raphael.fn.g.tag = function (x, y, text, angle, r) { + angle = angle || 0; + r = r == null ? 5 : r; + text = text == null ? "$9.99" : text; + var R = .5522 * r, + res = this.set(), + d = 3; + res.push(this.path().attr({fill: "#000", stroke: "none"})); + res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff"})); + res.update = function () { + this.rotate(0, x, y); + var bb = this[1].getBBox(); + if (bb.height >= r * 2) { + this[0].attr({ + path: ["M", x, y + r, "a", r, r, 0, 1, 1, 0, -r * 2, r, r, 0, 1, 1, 0, r * 2, "m", 0, -r * 2 - d, "a", r + d, r + d, 0, 1, 0, 0, (r + d) * 2, "L", x + r + d, + y + bb.height / 2 + d, "l", bb.width + 2 * d, 0, 0, -bb.height - 2 * d, -bb.width - 2 * d, 0, "L", x, y - r - d].join(",") + }); + } else { + var dx = Math.sqrt(Math.pow(r + d, 2) - Math.pow(bb.height / 2 + d, 2)); + // ["c", -R, 0, -r, R - r, -r, -r, 0, -R, r - R, -r, r, -r, R, 0, r, r - R, r, r, 0, R, R - r, r, -r, r] + // "a", r, r, 0, 1, 1, 0, -r * 2, r, r, 0, 1, 1, 0, r * 2, + this[0].attr({ + path: ["M", x, y + r, "c", -R, 0, -r, R - r, -r, -r, 0, -R, r - R, -r, r, -r, R, 0, r, r - R, r, r, 0, R, R - r, r, -r, r, "M", x + dx, y - bb.height / 2 - d, "a", + r + d, r + d, 0, 1, 0, 0, bb.height + 2 * d, "l", r + d - dx + bb.width + 2 * d, 0, 0, -bb.height - 2 * d, "L", x + dx, y - bb.height / 2 - d].join(",") + }); + } + this[1].attr({x: x + r + d + bb.width / 2, y: y}); + angle = (360 - angle) % 360; + this.rotate(angle, x, y); + angle > 90 && angle < 270 && this[1].attr({x: x - r - d - bb.width / 2, y: y, rotation: [180 + angle, x, y]}); + return this; + }; + res.update(); + return res; + }; + Raphael.fn.g.popupit = function (x, y, set, dir, size) { + dir = dir == null ? 2 : dir; + size = size || 5; + x = Math.round(x) + .5; + y = Math.round(y) + .5; + var bb = set.getBBox(), + w = Math.round(bb.width / 2), + h = Math.round(bb.height / 2), + dx = [0, w + size * 2, 0, -w - size * 2], + dy = [-h * 2 - size * 3, -h - size, 0, -h - size], + p = ["M", x - dx[dir], y - dy[dir], "l", -size, (dir == 2) * -size, -Math.max(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size, + "l", 0, -Math.max(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0, -Math.max(h - size, 0), "a", size, size, 0, 0, 1, size, -size, + "l", Math.max(w - size, 0), 0, size, !dir * -size, size, !dir * size, Math.max(w - size, 0), 0, "a", size, size, 0, 0, 1, size, size, + "l", 0, Math.max(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0, Math.max(h - size, 0), "a", size, size, 0, 0, 1, -size, size, + "l", -Math.max(w - size, 0), 0, "z"].join(","), + xy = [{x: x, y: y + size * 2 + h}, {x: x - size * 2 - w, y: y}, {x: x, y: y - size * 2 - h}, {x: x + size * 2 + w, y: y}][dir]; + set.translate(xy.x - w - bb.x, xy.y - h - bb.y); + return this.path(p).attr({fill: "#000", stroke: "none"}).insertBefore(set.node ? set : set[0]); + }; + Raphael.fn.g.popup = function (x, y, text, dir, size) { + dir = dir == null ? 2 : dir; + size = size || 5; + text = text || "$9.99"; + var res = this.set(), + d = 3; + res.push(this.path().attr({fill: "#000", stroke: "none"})); + res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff"})); + res.update = function (X, Y, withAnimation) { + X = X || x; + Y = Y || y; + var bb = this[1].getBBox(), + w = bb.width / 2, + h = bb.height / 2, + dx = [0, w + size * 2, 0, -w - size * 2], + dy = [-h * 2 - size * 3, -h - size, 0, -h - size], + p = ["M", X - dx[dir], Y - dy[dir], "l", -size, (dir == 2) * -size, -Math.max(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size, + "l", 0, -Math.max(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0, -Math.max(h - size, 0), "a", size, size, 0, 0, 1, size, -size, + "l", Math.max(w - size, 0), 0, size, !dir * -size, size, !dir * size, Math.max(w - size, 0), 0, "a", size, size, 0, 0, 1, size, size, + "l", 0, Math.max(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0, Math.max(h - size, 0), "a", size, size, 0, 0, 1, -size, size, + "l", -Math.max(w - size, 0), 0, "z"].join(","), + xy = [{x: X, y: Y + size * 2 + h}, {x: X - size * 2 - w, y: Y}, {x: X, y: Y - size * 2 - h}, {x: X + size * 2 + w, y: Y}][dir]; + if (withAnimation) { + this[0].animate({path: p}, 500, ">"); + this[1].animate(xy, 500, ">"); + } else { + this[0].attr({path: p}); + this[1].attr(xy); + } + return this; + }; + return res.update(x, y); + }; + Raphael.fn.g.flag = function (x, y, text, angle) { + angle = angle || 0; + text = text || "$9.99"; + var res = this.set(), + d = 3; + res.push(this.path().attr({fill: "#000", stroke: "none"})); + res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff"})); + res.update = function (x, y) { + this.rotate(0, x, y); + var bb = this[1].getBBox(), + h = bb.height / 2; + this[0].attr({path: ["M", x, y, "l", h + d, -h - d, bb.width + 2 * d, 0, 0, bb.height + 2 * d, -bb.width - 2 * d, 0, "z"].join(",")}); + this[1].attr({x: x + h + d + bb.width / 2, y: y}); + angle = 360 - angle; + this.rotate(angle, x, y); + angle > 90 && angle < 270 && this[1].attr({x: x - r - d - bb.width / 2, y: y, rotation: [180 + angle, x, y]}); + return this; + }; + return res.update(x, y); + }; + Raphael.fn.g.label = function (x, y, text) { + var res = this.set(); + res.push(this.rect(x, y, 10, 10).attr({stroke: "none", fill: "#000"})); + res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff"})); + res.update = function () { + var bb = this[1].getBBox(), + r = Math.min(bb.width + 10, bb.height + 10) / 2; + this[0].attr({x: bb.x - r / 2, y: bb.y - r / 2, width: bb.width + r, height: bb.height + r, r: r}); + }; + res.update(); + return res; + }; + Raphael.fn.g.labelit = function (set) { + var bb = set.getBBox(), + r = Math.min(20, bb.width + 10, bb.height + 10) / 2; + return this.rect(bb.x - r / 2, bb.y - r / 2, bb.width + r, bb.height + r, r).attr({stroke: "none", fill: "#000"}).insertBefore(set[0]); + }; + Raphael.fn.g.drop = function (x, y, text, size, angle) { + size = size || 30; + angle = angle || 0; + var res = this.set(); + res.push(this.path(["M", x, y, "l", size, 0, "A", size * .4, size * .4, 0, 1, 0, x + size * .7, y - size * .7, "z"]).attr({fill: "#000", stroke: "none", rotation: [22.5 - angle, x, y]})); + angle = (angle + 90) * Math.PI / 180; + res.push(this.text(x + size * Math.sin(angle), y + size * Math.cos(angle), text).attr(this.g.txtattr).attr({"font-size": size * 12 / 30, fill: "#fff"})); + res.drop = res[0]; + res.text = res[1]; + return res; + }; + Raphael.fn.g.blob = function (x, y, text, angle, size) { + angle = (+angle + 1 ? angle : 45) + 90; + size = size || 12; + var rad = Math.PI / 180, + fontSize = size * 12 / 12; + var res = this.set(); + res.push(this.path().attr({fill: "#000", stroke: "none"})); + res.push(this.text(x + size * Math.sin((angle) * rad), y + size * Math.cos((angle) * rad) - fontSize / 2, text).attr(this.g.txtattr).attr({"font-size": fontSize, fill: "#fff"})); + res.update = function (X, Y, withAnimation) { + X = X || x; + Y = Y || y; + var bb = this[1].getBBox(), + w = Math.max(bb.width + fontSize, size * 25 / 12), + h = Math.max(bb.height + fontSize, size * 25 / 12), + x2 = X + size * Math.sin((angle - 22.5) * rad), + y2 = Y + size * Math.cos((angle - 22.5) * rad), + x1 = X + size * Math.sin((angle + 22.5) * rad), + y1 = Y + size * Math.cos((angle + 22.5) * rad), + dx = (x1 - x2) / 2, + dy = (y1 - y2) / 2, + rx = w / 2, + ry = h / 2, + k = -Math.sqrt(Math.abs(rx * rx * ry * ry - rx * rx * dy * dy - ry * ry * dx * dx) / (rx * rx * dy * dy + ry * ry * dx * dx)), + cx = k * rx * dy / ry + (x1 + x2) / 2, + cy = k * -ry * dx / rx + (y1 + y2) / 2; + if (withAnimation) { + this.animate({x: cx, y: cy, path: ["M", x, y, "L", x1, y1, "A", rx, ry, 0, 1, 1, x2, y2, "z"].join(",")}, 500, ">"); + } else { + this.attr({x: cx, y: cy, path: ["M", x, y, "L", x1, y1, "A", rx, ry, 0, 1, 1, x2, y2, "z"].join(",")}); + } + return this; + }; + res.update(x, y); + return res; + }; + + Raphael.fn.g.colorValue = function (value, total, s, b) { + return "hsb(" + [Math.min((1 - value / total) * .4, 1), s || .75, b || .75] + ")"; + }; + + Raphael.fn.g.snapEnds = function (from, to, steps) { + var f = from, + t = to; + if (f == t) { + return {from: f, to: t, power: 0}; + } + + function round(a) { + return Math.abs(a - .5) < .25 ? Math.floor(a) + .5 : Math.round(a); + } + + var d = (t - f) / steps, + r = Math.floor(d), + R = r, + i = 0; + if (r) { + while (R) { + i--; + R = Math.floor(d * Math.pow(10, i)) / Math.pow(10, i); + } + i++; + } else { + while (!r) { + i = i || 1; + r = Math.floor(d * Math.pow(10, i)) / Math.pow(10, i); + i++; + } + i && i--; + } + var t = round(to * Math.pow(10, i)) / Math.pow(10, i); + if (t < to) { + t = round((to + .5) * Math.pow(10, i)) / Math.pow(10, i); + } + var f = round((from - (i > 0 ? 0 : .5)) * Math.pow(10, i)) / Math.pow(10, i); + return {from: f, to: t, power: i}; + }; + Raphael.fn.g.axis = function (x, y, length, from, to, steps, orientation, labels, type, dashsize) { + dashsize = dashsize == null ? 3 : dashsize; + type = type || "t"; + steps = steps || 10; + var path = type == "|" || type == " " ? ["M", x + .5, y, "l", 0, .001] : orientation == 1 || orientation == 3 ? ["M", x + .5, y, "l", 0, -length] : ["M", x, y + .5, "l", length, 0], + ends = this.g.snapEnds(from, to, steps), + f = ends.from, + t = ends.to, + i = ends.power, + j = 0, + text = this.set(); + d = (t - f) / steps; + var label = f, + rnd = i > 0 ? i : 0; + dx = length / steps; + if (+orientation == 1 || +orientation == 3) { + var Y = y, + addon = (orientation - 1 ? 1 : -1) * (dashsize + 3 + !!(orientation - 1)); + while (Y >= y - length) { + type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), Y + .5, "l", dashsize * 2 + 1, 0])); + text.push(this.text(x + addon, Y, (labels && labels[j++]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr) + .attr({"text-anchor": orientation - 1 ? "start" : "end"})); + label += d; + Y -= dx; + } + if (Math.round(Y + dx - (y - length))) { + type != "-" && type != " " && (path = path.concat(["M", x - (type == "+" || type == "|" ? dashsize : !(orientation - 1) * dashsize * 2), y - length + .5, "l", dashsize * 2 + 1, 0])); + text.push(this.text(x + addon, y - length, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr) + .attr({"text-anchor": orientation - 1 ? "start" : "end"})); + } + } else { + var X = x, + label = f, + rnd = i > 0 ? i : 0, + addon = (orientation ? -1 : 1) * (dashsize + 9 + !orientation), + dx = length / steps, + txt = 0, + prev = 0; + while (X <= x + length) { + + text.push(txt = this.text(X, y + addon, (labels && labels[j++]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr)); + var bb = txt.getBBox(); + var ds = dashsize; + if (prev >= bb.x - 5) { + text.pop(text.length - 1).remove(); + ds = 1; + } else { + prev = bb.x + bb.width; + } + + type != "-" && type != " " && (path = path.concat(["M", X + .5, y - (type == "+" ? ds : !!orientation * ds * 2), "l", 0, ds * 2 + 1])); + + label += d; + X += dx; + } + if (Math.round(X - dx - x - length)) { + type != "-" && type != " " && (path = path.concat(["M", x + length + .5, y - (type == "+" ? dashsize : !!orientation * dashsize * 2), "l", 0, dashsize * 2 + 1])); + text.push(this.text(x + length, y + addon, (labels && labels[j]) || (Math.round(label) == label ? label : +label.toFixed(rnd))).attr(this.g.txtattr)); + } + } + var res = this.path(path); + res.text = text; + res.all = this.set([res, text]); + res.remove = function () { + this.text.remove(); + this.constructor.prototype.remove.call(this); + }; + return res; + }; + + Raphael.el.lighter = function (times) { + times = times || 2; + var fs = [this.attrs.fill, this.attrs.stroke]; + this.fs = this.fs || [fs[0], fs[1]]; + fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex); + fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex); + fs[0].b = Math.min(fs[0].b * times, 1); + fs[0].s = fs[0].s / times; + fs[1].b = Math.min(fs[1].b * times, 1); + fs[1].s = fs[1].s / times; + this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"}); + }; + Raphael.el.darker = function (times) { + times = times || 2; + var fs = [this.attrs.fill, this.attrs.stroke]; + this.fs = this.fs || [fs[0], fs[1]]; + fs[0] = Raphael.rgb2hsb(Raphael.getRGB(fs[0]).hex); + fs[1] = Raphael.rgb2hsb(Raphael.getRGB(fs[1]).hex); + fs[0].s = Math.min(fs[0].s * times, 1); + fs[0].b = fs[0].b / times; + fs[1].s = Math.min(fs[1].s * times, 1); + fs[1].b = fs[1].b / times; + this.attr({fill: "hsb(" + [fs[0].h, fs[0].s, fs[0].b] + ")", stroke: "hsb(" + [fs[1].h, fs[1].s, fs[1].b] + ")"}); + }; + Raphael.el.original = function () { + if (this.fs) { + this.attr({fill: this.fs[0], stroke: this.fs[1]}); + delete this.fs; + } + }; +})(); \ No newline at end of file diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/load-big.gif b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/load-big.gif new file mode 100644 index 00000000000..ddb7ff1aac1 Binary files /dev/null and b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/load-big.gif differ diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/load.gif b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/load.gif new file mode 100644 index 00000000000..d0bce154234 Binary files /dev/null and b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/load.gif differ diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.css b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.css new file mode 100644 index 00000000000..a11644ca35b --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.css @@ -0,0 +1,152 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +body { + font-family: sans-serif; +} + +div.fileSelector { + border: solid 3px black; + position: absolute; + background: white; + -moz-border-radius: 10px; + border-radius: 10px; + padding: 5px; + font-family: sans-serif; + right: 10px; + top: 10px; +} + +div.fileSelector a { + cursor: pointer; +} + +.fileSelector li.selectedFile { + background: lightgreen; +} + +div.selector { + border: solid 3px black; + position: absolute; + background: white; + -moz-border-radius: 10px; + border-radius: 10px; + padding: 5px; + right: 10px; + top: 10px; + background: #aaaaaa; + opacity: 0.7; +} + +div.selector a { + cursor: pointer; +} + +.fileSelector li.selectedFile { + background: lightgreen; +} + +#fileLoader { + -moz-border-radius: 10px; + border-radius: 10px; + background: #aaaaaa; + opacity: 0.7; + position: absolute; + left: 20px; + top: 20px; +} + +#loadingScreen { + position: absolute; + top: 100px; + margin-left: 40%; + margin-right: 40%; + width: 500px; + background: #aaaaaa; + opacity: 0.7; + -moz-border-radius: 10px; + border-radius: 10px; + text-align: center +} + +#filterinput { + width: 500px; + height: 100px; +} + +/* main interface */ +#actions { + float: right; +} + +#views { + float: left; +} + +.closebutton { + position: absolute; + right: 5px; + float: right; + display: block; + cursor: pointer; +} + +.actionbutton { + color: blue; + text-decoration: none; + padding: 3px; + cursor: pointer; +} + +span:hover.actionbutton { + background: lightblue; +} + +#status { + text-align: center; +} + +#canvas { + width: 100%; + height: 1000px; +} + +#logtable { + width: 100%; +} + +.popUp { + border: 3px solid black; + -moz-border-radius: 10px; + border-radius: 10px; + position: absolute; + background: white; + padding: 10px; + min-width: 300px; +} + +.errorpage { + position: absolute; + top: 100px; + margin-left: 40%; + margin-right: 40%; + width: 500px; + background: #aaaaaa; + opacity: 0.7; + -moz-border-radius: 10px; + border-radius: 10px; + padding: 10px; +} \ No newline at end of file diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.js new file mode 100644 index 00000000000..a274b37ea27 --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.js @@ -0,0 +1,275 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +LogGraph = function (canvas, status) { + this.canvas = document.getElementById(canvas); + this.status = document.getElementById(status); + this.starttime = 0; + this.endtime = 0; + this.period = 0; + this.numEntries = 0; + this.currentRender = 0; + this.filter = ""; + + this.saveFilters = function () { + localStorage.starttime = this.starttime; + localStorage.endtime = this.endtime; + localStorage.period = this.period; + localStorage.filter = this.filter; + + }; + this.loadFilters = function () { + if (localStorage.starttime) { + this.starttime = parseInt(localStorage.starttime); + } + if (localStorage.endtime) { + this.endtime = parseInt(localStorage.endtime); + } + if (localStorage.period) { + this.period = parseInt(localStorage.period); + } + if (localStorage.filter) { + this.filter = localStorage.filter; + } + }; + this.loadFilters(); + var self = this; + + var updateStatus = function (starttime, period, filter, numEntries) { + self.starttime = starttime; + self.endtime = starttime + period; + self.period = period; + self.filter = filter; + self.saveFilters(); + + self.status.innerHTML = + dateFormat(starttime, "HH:MM:ss,l") + " ⇒ " + dateFormat(self.endtime, "HH:MM:ss,l") + "    |    " + numEntries + + " entries    |    " + (filter ? filter : "No filter"); + + if (self.currentRender) { + self.currentRender(); + } + }; + + YUI().use("io-base", function (Y) { + var uri = "/info"; + if (self.starttime) { + var uri = "/info?start=" + self.starttime + "&period=" + self.period + "&filter=" + self.filter; + } + + function complete(id, o, args) { + var data = eval("(" + o.responseText + ")"); // Response data. + var period = data.endTime - data.startTime; + updateStatus(data.startTime, period, self.filter, data.numEntries); + }; + + Y.on('io:complete', complete, Y, []); + var request = Y.io(uri); + }); + + this.addLogs = function () { + new LogGraph.fileSelector(function (files) { + new LogGraph.fileLoader(files); + }); + }; + + this.editFilters = function () { + new LogGraph.filterSelector(this.starttime, this.period, this.filter, updateStatus); + }; + + this.getCleanCanvas = function () { + this.canvas.innerHTML = ""; + return this.canvas; + }; + + this.showLoadingScreen = function () { + this.loadingScreen = document.createElement("div"); + this.loadingScreen.id = "loadingScreen"; + this.loadingScreen.innerHTML = "

Loading...

"; + document.body.appendChild(this.loadingScreen); + }; + + this.hideLoadingScreen = function () { + document.body.removeChild(this.loadingScreen); + this.loadingScreen.style.visibility = "hidden"; + }; + + /*** + * TODO: refactor these to load the data first, before handing to a draw funciton. + * We shouldn't pass the async q into the drawing function + */ + this.showLogs = function () { + var self = this; + YUI().use('async-queue', function (Y) { + var q = new Y.AsyncQueue(self.showLoadingScreen, + // The second callback will pause the Queue and send an XHR for data + function () { + q.pause(); + var loggraph = new LogGraph.LogTable(q, self.getCleanCanvas(), self.starttime, self.endtime, self.filter); + self.currentRender = self.showLogs; + }, + self.hideLoadingScreen); + q.run(); + } + ); + }; + + this.serverGraph = function () { + var self = this; + YUI().use('async-queue', function (Y) { + var q = new Y.AsyncQueue(self.showLoadingScreen, + // The second callback will pause the Queue and send an XHR for data + function () { + q.pause(); + var servergraph = new LogGraph.ServerGraph(q, self.getCleanCanvas(), self.starttime, self.endtime, self.filter); + self.currentRender = self.showLogs; + }, + self.hideLoadingScreen); + q.run(); + } + ); + }; + + this.sessionGraph = function () { + var self = this; + YUI().use('async-queue', function (Y) { + var q = new Y.AsyncQueue(self.showLoadingScreen, + // The second callback will pause the Queue and send an XHR for data + function () { + q.pause(); + var sessiongraph = new LogGraph.SessionGraph(q, self.getCleanCanvas(), self.starttime, self.endtime, self.filter); + self.currentRender = self.sessionGraph; + }, + self.hideLoadingScreen); + q.run(); + } + ); + }; + + this.showStats = function () { + var self = this; + YUI().use('async-queue', function (Y) { + var q = new Y.AsyncQueue(self.showLoadingScreen, + // The second callback will pause the Queue and send an XHR for data + function () { + q.pause(); + var statgraph = new LogGraph.StatsGraph(q, self.getCleanCanvas(), self.starttime, self.endtime, self.filter); + self.currentRender = self.showStats; + }, + self.hideLoadingScreen); + q.run(); + } + ); + }; +}; + +LogGraph.error = function (description) { + var errorPage = document.createElement("div"); + errorPage.className = "errorpage"; + var p = document.createElement("p"); + p.innerHTML = description; + errorPage.appendChild(p); + + var span = document.createElement("span"); + p = document.createElement("p"); + span.className = "actionButton"; + span.innerHTML = "OK"; + span.onclick = function (evt) { + document.body.removeChild(errorPage); + delete errorPage; + } + p.appendChild(span); + errorPage.appendChild(p); + + document.body.appendChild(errorPage); +}; + +LogGraph.ticker = function (allow_dups) { + this.ticks = new Array(); + this.current_tick = 0; + this.allow_dups = allow_dups; + ; + + this.tick = function (time) { + if (time == this.ticks[this.ticks.length - 1] && this.allow_dups == true) { + return this.current_tick; + } + + this.ticks.push(time); + return this.current_tick++; + }; + + this.current = function () { + return this.current_tick; + }; + + this.reset = function () { + while (this.ticks.length) { + this.ticks.pop(); + } + this.current_tick = 0; + }; +}; + +LogGraph.timescale = function (starttime, endtime) { + this.starttime = starttime; + this.endtime = endtime; + this.millis = endtime - starttime; + + this.draw = function (paper) { + var scale = paper.set(); + scale.push(paper.path("M0 0 L" + paper.width + " 0")); + + for (var i = 0; i < paper.width; i += 100) { + scale.push(paper.path("M" + i + " 0 L" + i + " 5")); + // var time = dateFormat((this.starttime + (i*ms_per_pixel)), "h:MM:ss,l"); + // paper.text(i + 5, 10, time); + } + + scale.attr({"stroke-width": 2}); + }; +}; + +/* + Fetch data from an uri and process it, the process data func returns true if any of the data is useful +*/ +LogGraph.loadData = function (asyncq, uri, processdata) { + YUI().use("io-base", function (Y) { + function success(id, o, args) { + var data = eval("(" + o.responseText + ")"); // Response data. + if (data.error) { + LogGraph.error(data.error); + } else { + if (!processdata(data)) { + LogGraph.error("No data. Perhaps you should loosen your filter criteria."); + } + } + asyncq.run(); + }; + + function failure(id, o, args) { + LogGraph.error("Error contacting server: (" + o.status + ") " + o.statusText); + asyncq.run(); + }; + + Y.on('io:success', success, Y, []); + Y.on('io:failure', failure, Y, []); + + var request = Y.io(uri); + }); +} \ No newline at end of file diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.log.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.log.js new file mode 100644 index 00000000000..b6843c23d2b --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.log.js @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +LogGraph.LogTable = function (asyncq, canvas, starttime, endtime, filter) { + this.starttime = starttime; + this.endtime = endtime; + this.filter = filter; + + var table = document.createElement("table"); + table.id = "logtable"; + canvas.appendChild(table); + + this.addLogLine = function (time, text) { + var tr = document.createElement("tr"); + table.appendChild(tr); + + var td = document.createElement("td"); + td.innerHTML = dateFormat(time, "h:MM:ss,l"); + tr.appendChild(td); + + td = document.createElement("td"); + td.innerHTML = text; + tr.appendChild(td); + } + + var self = this; + var processdata = function (data) { + var events = data["events"]; + var count = 0; + for (var i in events) { + var e = events[i]; + if (e.type == "text") { + self.addLogLine(e.time, e.text); + count++; + } + } + return count != 0; + }; + + var uri = "/data?start=" + self.starttime + "&end=" + self.endtime + "&filter=" + self.filter; + LogGraph.loadData(asyncq, uri, processdata); +}; diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.server.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.server.js new file mode 100644 index 00000000000..0cb1eda143c --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.server.js @@ -0,0 +1,333 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +LogGraph.ServerGraph = function (asyncq, canvas, starttime, endtime, filter) { + this.starttime = starttime; + this.endtime = endtime; + this.millis = endtime - starttime; + this.nextserverid = 0; + this.serveroffset = 100; + this.filter = filter; + + this.pixels_per_tick = 20; + this.ticker = new LogGraph.ticker(); + + var paper = Raphael(canvas, 1, 1); + + var self = this; + + this.timescale = new LogGraph.timescale(starttime, endtime); + this.objects = new Array(); + + this.add = function (obj) { + this.objects.push(obj); + } + + this.tick_to_x = function (timestamp) { + var x = timestamp * this.pixels_per_tick; + return x; + }; + + this._drawTime = function (paper, x, time) { + var p = paper.path("M" + x + " 0 L" + x + " " + paper.height); + var t = paper.text(x, 10, dateFormat(time, "h:MM:ss,l")); + + t.hide(); + p.mouseover(function (evt) { + t.show(); + p.attr({stroke: "red"}); + }); + p.mouseout(function (evt) { + t.hide(); + p.attr({stroke: "lightgray"}); + }); + + return p; + }; + + this.draw = function (paper) { + var grid = paper.set(); + for (var i = 0; i < paper.height; i += 20) { + grid.push(paper.path("M0 " + i + " L" + paper.width + " " + i)); + } + var lasttick = this.starttime; + var scale = 500; // 500 ms + + var y = 0; + + for (var t = 0, len = this.ticker.ticks.length; t < len; t++) { + var basex = t * this.pixels_per_tick; + var thistick = this.ticker.ticks[t]; + var nexttick = t + 1 == this.ticker.ticks.length ? this.endtime : this.ticker.ticks[t + 1]; + if (nexttick == thistick) { + continue; + } + var time = thistick - lasttick; + var first = scale - (lasttick % scale); + + /* for (var i = 0; (first+scale*i) < time; i++) { + + var toffset = first+scale*i; + var x = basex + LogGraph._pixels_per_tick * toffset/time; + grid.push(this._drawTime(paper, x, lasttick + toffset, grid)); + + }*/ + + //grid.push(paper.path("M" + i + " 0 L" + i + " " + paper.height)); + lasttick = thistick; + } + grid.attr({stroke: "lightgray"}); + this.timescale.draw(paper); + + for (o in this.objects) { + this.objects[o].draw(paper); + } + }; + + var processdata = function (data) { + var servermap = {}; + var servers = data.servers; + var count = 0; + for (s in servers) { + var server = new LogGraph.ServerGraph.server(self, "Server " + servers[s]); + servermap[servers[s]] = server; + self.add(server); + count++; + } + + var messages = {}; + var events = data.events; + for (var i in events) { + var e = events[i]; + var t = e.time; + if (e.type == "stateChange") { + servermap[e.server].addState(e.state, self.ticker.tick(e.time)); + } + if (e.type == "postmessage") { + src = servermap[e.src]; + dst = servermap[e.dst]; + var key = "key:s" + e.src + ",d" + e.dst + ",z" + e.zxid; + + var m = new LogGraph.ServerGraph.message(self, src, self.ticker.tick(e.time), dst, e.zxid); + messages[key] = m; + } + if (e.type == "delivermessage") { + var key = "key:s" + e.src + ",d" + e.dst + ",z" + e.zxid; + + var m = messages[key]; + if (m) { + m.dsttime = self.ticker.tick(e.time); + m.name = "Propose"; + self.add(m); + delete messages[key]; + } + } + if (e.type == "exception") { + servermap[e.server].addException(self.ticker.tick(e.time), e.text, e.time); + } + count++; + } + + for (var i in messages) { + var m = messages[i]; + m.markIncomplete(); + self.add(m); + count++; + } + + if (count != 0) { + paper.setSize(self.tick_to_x(self.ticker.current()), 1000); + + var line = paper.path("M0 0 L0 1000"); + line.attr({"stroke": "red", "stroke-dasharray": "- "}); + var base = canvas.offsetLeft;// + ((canvas.offsetWidth - paper.width)/2); + canvas.onmousemove = function (evt) { + var x = evt.screenX - base; + + line.attr({"path": "M" + x + " 0 L" + x + " 1000"}); + + }; + + self.draw(paper); + return true; + } else { + return false; + } + }; + + var uri = "/data?start=" + self.starttime + "&end=" + self.endtime + "&filter=" + filter; + + LogGraph.loadData(asyncq, uri, processdata); +}; + +LogGraph.ServerGraph.server = function (graph, name) { + this.graph = graph; + this.serverid = graph.nextserverid++; + this.name = name; + this.y = (this.serverid * 300 + graph.serveroffset); + this.states = new Array(); + this.exception = new Array(); + + this.addState = function (state, time) { + this.states.push([state, time]); + } + + this.addException = function (tick, exception, time) { + this.exception.push(new LogGraph.ServerGraph.exception(this.graph, tick, exception, time)); + } + + this.draw = function (paper) { + var st = paper.set(); + st.push(paper.path("M0 " + this.y + " L" + paper.width + " " + this.y)); + st.push(paper.text(20, this.y - 10, this.name)); + st.attr({stroke: "gray"}); + + var numstates = this.states.length; + + for (s = 0; s < numstates; s++) { + var style = {}; + switch (this.states[s][0]) { + case "INIT": + style = {stroke: "yellow", "stroke-width": 3}; + break; + case "FOLLOWING": + style = {stroke: "lightgreen", "stroke-width": 7}; + break; + case "LEADING": + style = {stroke: "green", "stroke-width": 10}; + break; + case "LOOKING": + style = {stroke: "orange", "stroke-width": 5}; + break; + } + var startx = this.graph.tick_to_x(this.states[s][1]); + var endx = s + 1 < numstates ? this.graph.tick_to_x(this.states[(s + 1)][1]) : paper.width; + var p = paper.path("M" + startx + " " + this.y + " L" + endx + " " + this.y); + p.attr(style); + } + + for (e in this.exception) { + this.exception[e].draw(paper, this); + } + } +}; + +LogGraph.ServerGraph.message = function (graph, src, srctime, dst, zxid) { + this.graph = graph; + this.src = src; + this.srctime = srctime; + this.dst = dst; + this.dsttime = 0; //dsttime; + this.name = "Unknown"; + this.zxid = zxid; + this.moreinfo = "No extra information"; + this.incomplete = false; + + this.markIncomplete = function () { + this.incomplete = true; + this.dsttime = this.srctime; + } + + this.draw = function (paper) { + var srcx = this.graph.tick_to_x(this.srctime); + var dstx = this.graph.tick_to_x(this.dsttime); + + var arrow = paper.set(); + var p = paper.path("M" + srcx + " " + this.src.y + " L" + dstx + " " + this.dst.y); + arrow.push(p); + + var tx = (srcx + dstx) / 2; + var ty = (this.src.y + this.dst.y) / 2; + var t = paper.text(tx, ty, this.name); + + var gradiant = (this.dst.y - this.src.y) / (dstx - srcx); + var angle = Math.atan(gradiant) * 57.2958; + t.rotate(angle, true); + + var arrowl = paper.path("M" + dstx + " " + this.dst.y + " L" + (dstx - 10) + " " + this.dst.y); + arrowl.rotate(angle + 20, dstx, this.dst.y); + arrow.push(arrowl); + var arrowr = paper.path("M" + dstx + " " + this.dst.y + " L" + (dstx - 10) + " " + this.dst.y); + arrowr.rotate(angle - 20, dstx, this.dst.y); + arrow.push(arrowr); + + arrow.attr({"stroke-width": 2, stroke: "gray"}); + if (this.incomplete) { + arrow.attr({"stroke-dasharray": "- .", stroke: "pink", "stroke-width": 2}); + } + arrow.mouseover(function (evt) { + t.attr({"font-size": 20}); + arrow.attr({stroke: "red", "stroke-width": 3}); + }); + arrow.mouseout(function (evt) { + t.attr({"font-size": 10}); + + if (this.incomplete) { + arrow.attr({stroke: "pink", "stroke-width": 2}); + } else { + arrow.attr({stroke: "gray", "stroke-width": 2}); + } + }); + + arrow.click(function (evt) { + var popup = document.createElement("div"); + popup.className = "popUp"; + popup.innerHTML = "zxid: " + parseInt(this.zxid).toString(16); + + popup.style.top = evt.clientY; + popup.style.left = evt.clientX; + document.body.appendChild(popup); + + popup.onclick = function (evt) { + document.body.removeChild(popup); + }; + }); + } +}; + +LogGraph.ServerGraph.exception = function (graph, tick, exceptiontext, time) { + this.graph = graph; + this.time = time; + this.text = exceptiontext; + this.tick = tick; + + var self = this; + + this.draw = function (paper, server) { + var center = this.graph.tick_to_x(this.tick); + var p = paper.circle(center, server.y, 5); + p.attr({stroke: "orange", fill: "red"}); + + p.mouseover(function (evt) { + p.popup = document.createElement("div"); + p.popup.className = "popUp"; + p.popup.innerHTML = self.text.replace("\n", "
"); + ; + p.popup.style.top = server.y + 50; + p.popup.style.left = center + 25; + document.body.appendChild(p.popup); + + p.animate({r: 10}, 500, "elastic"); + }); + p.mouseout(function (evt) { + document.body.removeChild(p.popup); + p.animate({r: 5}, 100); + }); + } +}; + diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.session.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.session.js new file mode 100644 index 00000000000..a30e6edf3e9 --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.session.js @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +LogGraph.SessionGraph = function (asyncq, canvas, starttime, endtime, filter) { + this.sessions = new Array(); + this.counter = 0; + this.exceptions = new Array(); + + this.pix_per_ticks = 4; + this.pix_per_session = 7; + + var paper = Raphael(canvas, 1, 1); + this.ticker = new LogGraph.ticker(); + var self = this; + + this.starttime = starttime; + this.endtime = endtime; + this.filter = filter; + + this.findOrCreateSession = function (id) { + if (this.sessions[id] == undefined) { + this.sessions[id] = new LogGraph.SessionGraph.session(this, ++this.counter, id); + } + return this.sessions[id]; + } + + this.height = function () { + return this.counter * this.pix_per_session + 10; + }; + this.width = function () { + return (self.ticker.current() * this.pix_per_ticks); + }; + + this.draw = function (paper) { + + var line = paper.path("M0 0 L0 " + this.height()); + line.attr({"stroke": "red", "stroke-dasharray": "- "}); + var base = canvas.offsetLeft; + var width = this.width(); + canvas.onmousemove = function (evt) { + var x = evt.clientX - base; + + line.attr({"path": "M" + x + " 0 L" + x + " " + self.height()}); + }; + + for (var i in this.sessions) { + var s = this.sessions[i]; + s.draw(paper); + } + }; + + var processdata = function (data) { + var count = 0; + for (var i in data.events) { + var e = data.events[i]; + if (e.type == "transaction") { + e.tick = self.ticker.tick(e.time, true); + var session = self.findOrCreateSession(e.client); + session.addEvent(e); + count++; + } + } + paper.setSize(self.width(), self.height()); + + if (count != 0) { + self.draw(paper); + return true; + } else { + return false; + } + }; + + var uri = "/data?start=" + self.starttime + "&end=" + self.endtime + "&filter=" + filter; + + LogGraph.loadData(asyncq, uri, processdata); +}; + +LogGraph.SessionGraph.sessionevent = function () { + this.time = time; + this.type = type; + this.client = client; + this.cxid = cxid; + this.zxid = zxid; + this.op = op; + this.extra = extra; +}; + +LogGraph.SessionGraph.sessionEventPopup = function (obj, e, x, y) { + obj.click(function (evt) { + var popup = document.createElement("div"); + popup.className = "popUp"; + + var closebutton = document.createElement("div"); + closebutton.className = "closebutton"; + closebutton.title = "Close popup"; + closebutton.innerHTML = "×"; + popup.appendChild(closebutton); + closebutton.onclick = function (evt) { + popup.style.visibility = "hidden"; + document.body.removeChild(popup) + }; + var txt = document.createElement("span"); + txt.innerHTML = "session: " + e.client + "
op: " + e.op + "
zxid: " + e.zxid + "
time: " + e.time + "
extra: " + e.extra; + popup.appendChild(txt); + + popup.style.top = y; + popup.style.left = x; + document.body.appendChild(popup); + + YUI().use('dd-drag', function (Y) { + //Selector of the node to make draggable + var dd = new Y.DD.Drag({ + node: popup + }); + }); + }); +}; + +LogGraph.SessionGraph.session = function (graph, index, id) { + this.index = index; + this.id = id; + this.graph = graph; + + this.events = new Array(); + this.starttick = 0; + this.endtick = undefined; + + this.addEvent = function (e) { + this.events.push(e); + + if (e.op == "createSession") { + // document.write("createSession for " + id.toString(16)); + this.starttick = e.tick; + } else if (e.op == "closeSession") { + this.endtick = e.tick; + } + }, + + this._attach_action = function (sess, label) { + sess.mouseover(function (evt) { + label.show(); + sess.attr({stroke: "gray"}); + }); + + sess.mouseout(function (evt) { + label.hide(); + sess.attr({stroke: "black"}); + }); + }, + + this.drawEvent = function (paper, y, e) { + var x = e.tick * this.graph.pix_per_ticks; + ; + var s = paper.path("M" + x + " " + (y - 3) + " L" + x + " " + (y + 3)); + s.attr({"stroke-width": 2}); + if (e.op == "error") { + s.attr({"stroke": "red"}); + } + s.mouseover(function (evt) { + s.attr({"stroke-width": 5}); + }); + + s.mouseout(function (evt) { + s.attr({"stroke-width": 2}); + }); + + LogGraph.SessionGraph.sessionEventPopup(s, e, x, y); + }, + + this.draw = function (paper) { + var y = this.index * this.graph.pix_per_session; + ; + var start = this.starttick * this.graph.pix_per_ticks; + var end = this.endtick * this.graph.pix_per_ticks; + + var sess = paper.set(); + + if (this.endtick == undefined) { + end = this.graph.width(); + } + + sess.push(paper.path("M" + start + " " + y + " L" + end + " " + y)); + for (var i in this.events) { + var e = this.events[i]; + this.drawEvent(paper, y, e); + } + + //sess.attr({"stroke-width": 3}); + label = paper.text(start + 100, y, this.id); + label.attr({"font-size": "14px"}); + label.hide(); + this._attach_action(sess, label); + } +}; + diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.stats.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.stats.js new file mode 100644 index 00000000000..a2726cde155 --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.stats.js @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +LogGraph.StatsGraph = function (asyncq, canvas, starttime, endtime, filter) { + var processdata = function (data) { + var r = Raphael(canvas); + var x = data.map(function (x) { + return x.time; + }); + var y = data.map(function (x) { + return x.count; + }); + var xlabels = data.map(function (x) { + return dateFormat(x.time, "HH:MM:ss,l"); + }); + var h1 = function () { + this.tags = r.set(); + for (var i = 0, ii = this.y.length; i < ii; i++) { + this.tags.push(r.g.tag(this.x, this.y[i], this.values[i], 160, 10).insertBefore(this).attr([{fill: "#fff"}, {fill: this.symbols[i].attr("fill")}])); + } + }; + var h2 = function () { + this.tags && this.tags.remove(); + }; + r.g.linechart(40, 40, 1000, 500, x, y, + {shade: true, axis: "0 0 1 1", symbol: "x", southlabels: xlabels, axisxstep: xlabels.length - 1, westAxisLabel: "Write requests", southAxisLabel: "Time (min)"}) + .hoverColumn(h1, h2); + + return true; + //r.g.barchart(0, 0, 1000, 100, y, {shade: true, symbol: "x"}).hoverColumn(h1, h2); + }; + + var uri = "/throughput?scale=minutes"; + LogGraph.loadData(asyncq, uri, processdata); +}; + + diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.ui.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.ui.js new file mode 100644 index 00000000000..1bd0913f10b --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/loggraph.ui.js @@ -0,0 +1,392 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Opens a window to load files into the engine +LogGraph.fileSelector = function (callback) { + var self = this; + this.callback = callback; + this.selectedFiles = new Array(); + + var divTag = document.createElement("div"); + divTag.id = "fileSelector" + Math.round(Math.random() * 100000); + // divTag.className = "popUp"; + divTag.className = "selector fileSelector"; + document.body.appendChild(divTag); + + YUI().use('dd-drag', function (Y) { + //Selector of the node to make draggable + var dd = new Y.DD.Drag({ + node: '#' + divTag.id + }); + }); + + var list = document.createElement("ul"); + divTag.appendChild(list); + var selectedList = document.createElement("selectedlist"); + divTag.appendChild(selectedList); + + var clearanchor = document.createElement("span"); + clearanchor.innerHTML = "Remove All"; + clearanchor.className = "actionbutton"; + clearanchor.style.cssFloat = "right"; + clearanchor.onclick = function () { + self.selectedFiles = new Array(); + self.updateSelectedList(); + }; + divTag.appendChild(clearanchor); + + var doneanchor = document.createElement("span"); + doneanchor.innerHTML = "Process Files"; + doneanchor.className = "actionbutton"; + doneanchor.style.cssFloat = "left"; + doneanchor.onclick = function () { + self.callback(self.selectedFiles); + document.body.removeChild(divTag); + delete divTag; + }; + divTag.appendChild(doneanchor); + + var cancelanchor = document.createElement("span"); + cancelanchor.innerHTML = "Cancel"; + cancelanchor.className = "actionbutton"; + cancelanchor.style.cssFloat = "left"; + cancelanchor.onclick = function () { + document.body.removeChild(divTag); + delete divTag; + }; + divTag.appendChild(cancelanchor); + + this.createFileListItem = function (file) { + var li = document.createElement("li"); + var a = document.createElement("a"); + if (file.type == "D") { + a.innerHTML = file.file + "/"; + a.onclick = function () { + self.updateList(file.path); + }; + } else { + a.innerHTML = file.file; + a.onclick = function () { + self.addSelectedFile(file.path); + }; + } + + a.fullpath = file.path; + ; + li.appendChild(a); + return li; + }; + + this.addSelectedFile = function (file) { + if (this.selectedFiles.indexOf(file) == -1) { + this.selectedFiles.push(file); + this.updateSelectedList(); + } + }; + + this.removeSelectedFile = function (file) { + this.selectedFiles = this.selectedFiles.filter(function (f) { + return !(file == f); + }); + this.updateSelectedList(); + }; + + this.createSelectedListItem = function (file) { + var li = document.createElement("li"); + var a = document.createElement("a"); + li.className = "selectedFile"; + a.onclick = function () { + self.removeSelectedFile(file); + }; + a.innerHTML = file; + li.appendChild(a); + return li; + }; + + this.updateSelectedList = function () { + while (selectedList.firstChild) { + selectedList.removeChild(selectedList.firstChild); + } + + for (var i in this.selectedFiles) { + var f = this.selectedFiles[i]; + selectedList.appendChild(this.createSelectedListItem(f)); + } + }; + + this.updateList = function (base) { + while (list.firstChild) { + list.removeChild(list.firstChild); + } + + // Create a YUI instance using io-base module. + YUI().use("io-base", function (Y) { + var uri = "/fs?path=" + base; + + // Define a function to handle the response data. + function complete(id, o, args) { + var id = id; // Transaction ID. + var data = eval("(" + o.responseText + ")"); // Response data. + var parts = base.split("/").slice(0, -1); + var parent = "" + if (parts.length < 2) { + parent = "/"; + } else { + parent = parts.join("/"); + } + if (base != "/") { + var li = self.createFileListItem({"file": "..", type: "D", path: parent}); + list.appendChild(li); + } + for (var i in data) { + var f = data[i]; + if (f.file[0] != '.') { + var li = self.createFileListItem(f); + list.appendChild(li); + } + } + }; + + Y.on('io:complete', complete, Y, []); + var request = Y.io(uri); + }); + }; + + this.updateList("/"); +}; + +// Open a window which loads files into the engine +LogGraph.fileLoader = function (files) { + var div = document.createElement("div"); + div.id = "fileLoader"; + + var imgArray = new Array(); + var pArray = new Array(); + for (var index in files) { + var f = files[index]; + var p = document.createElement("p"); + var i = document.createElement("img"); + i.src = "load.gif"; + i.style.visibility = "hidden"; + imgArray.push(i); + pArray.push(p); + var span = document.createElement("span"); + span.innerHTML = f; + + p.appendChild(span); + p.appendChild(i); + + div.appendChild(p); + } + + var loadFile = function (index) { + // Create a YUI instance using io-base module. + YUI().use("io-base", function (Y) { + var file = files[index]; + var uri = "/loadfile?path=" + file; + imgArray[index].style.visibility = "visible"; + + // Define a function to handle the response data. + function complete(id, o, args) { + var id = id; // Transaction ID. + var data = eval("(" + o.responseText + ")"); // Response data. + if (data.status == "ERR") { + var err = document.createElement("div"); + err.innerHTML = data.error; + pArray[index].appendChild(err); + } else if (data.status == "OK") { + var ok = document.createElement("div"); + ok.innerHTML = "OK"; + pArray[index].appendChild(ok); + } + + imgArray[index].style.visibility = "hidden"; + if (index + 1 < files.length) { + loadFile(index + 1); + } else { + //alert("DONE"); + } + }; + + Y.on('io:complete', complete, Y, []); + var request = Y.io(uri); + }); + }; + + var doneanchor = document.createElement("a"); + doneanchor.className = "actionbutton"; + doneanchor.innerHTML = "Done"; + doneanchor.onclick = function () { + document.body.removeChild(div); + delete div; + }; + + document.body.appendChild(div); + if (files.length > 0) { + loadFile(0); + } else { + div.innerHTML = "No files to load"; + } + div.appendChild(doneanchor); +} + +// select a time period +LogGraph.filterSelector = function (starttime, period, filter, callback) { + var self = this; + this.callback = callback; + + // Container other widgets will be in + var container = document.createElement("div"); + container.id = "filterSelector" + Math.round(Math.random() * 100000); + container.className = "selector filterSelector"; + document.body.appendChild(container); + + YUI().use('dd-drag', function (Y) { + //Selector of the node to make draggable + var dd = new Y.DD.Drag({ + node: '#' + container.id + }); + }); + + // Temporary loading screen + var loadingp = document.createElement("p"); + loadingp.innerHTML = "Loading..."; + var loadimg = document.createElement("img"); + loadimg.src = "load.gif"; + loadingp.appendChild(loadimg); + container.appendChild(loadingp); + + var addWithLabel = function (container, labeltxt, object) { + var p = document.createElement("p"); + var label = document.createElement("label"); + label.innerHTML = labeltxt + ":"; + p.appendChild(label); + p.appendChild(object); + container.appendChild(p); + }; + var draw = function (minstart, maxstart, entries) { + container.removeChild(loadingp); + var inittime = minstart > starttime ? minstart : starttime; + + var numEntries = 0; + var startspan = document.createElement("span"); + addWithLabel(container, "Start time", startspan); + var startinput = document.createElement("input"); + startinput.type = "hidden"; + startinput.value = inittime; + container.appendChild(startinput); + var sliderspan = document.createElement("span"); + container.appendChild(sliderspan); + + var countspan = document.createElement("p"); + countspan.innerHTML = entries + " entries"; + ; + container.appendChild(countspan); + + var windowinput = document.createElement("input"); + windowinput.type = "text"; + windowinput.value = period; + addWithLabel(container, "Time window (ms)", windowinput); + + var filterinput = document.createElement("textarea"); + filterinput.id = "filterinput"; + filterinput.value = filter; + addWithLabel(container, "Filter", filterinput); + + /* done link, when clicked time is updated, */ + var doneanchor = document.createElement("a"); + doneanchor.className = "actionbutton"; + doneanchor.innerHTML = "Done"; + doneanchor.onclick = function () { + var start = parseInt(startinput.value); + var period = parseInt(windowinput.value); + var filter = filterinput.value; + document.body.removeChild(container); + delete container; + + update(start, period, filter, function () { + callback(start, period, filter, numEntries); + }); + }; + container.appendChild(doneanchor); + + var update = function (start, period, filter, thenrun) { + startspan.innerHTML = dateFormat(start, "HH:MM:ss,l"); + // get the min and max start time + YUI().use("io-base", function (Y) { + var uri = "/info?start=" + start + "&period=" + period + "&filter=" + filter; + + function complete(id, o, args) { + var data = eval("(" + o.responseText + ")"); + countspan.innerHTML = data.numEntries + " entries"; + numEntries = data.numEntries; + if (thenrun) { + thenrun(); + } + }; + + Y.on('io:complete', complete, Y, []); + var request = Y.io(uri); + }); + }; + + var updatewindow = function (evt) { + var start = parseInt(startinput.value); + var period = parseInt(windowinput.value); + var filter = filterinput.value; + update(start, period, filter); + }; + windowinput.onkeyup = updatewindow; + + YUI().use("slider", function (Y) { + var input, slider; + + function updateInput(e) { + this.set("value", e.newVal); + + update(parseInt(startinput.value), parseInt(windowinput.value), filterinput.value); + } + + xSlider = new Y.Slider({min: minstart, max: maxstart, value: inittime, length: "1000px"}); + + // Link the input value to the Slider + xInput = Y.one(startinput); + xInput.setData({slider: xSlider}); + + // Pass the input as the 'this' object inside updateInput + xSlider.after("valueChange", updateInput, xInput); + + // Render the Slider next to the input + xSlider.render(sliderspan); + }); + update(inittime, windowinput.value, filterinput); + }; + + // get the min and max start time + YUI().use("io-base", function (Y) { + var uri = "/info"; + + function complete(id, o, args) { + var data = eval("(" + o.responseText + ")"); + draw(data.startTime, data.endTime, data.numEntries); + }; + + Y.on('io:complete', complete, Y, []); + var request = Y.io(uri); + }); +} \ No newline at end of file diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/main.html b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/main.html new file mode 100644 index 00000000000..e6e855e7604 --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/main.html @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ Edit Filters + Add logs +
+
+ Log view + Servers view + Sessions view + Statistics +
+
+
+
+
+ + diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/raphael.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/raphael.js new file mode 100644 index 00000000000..55a39b0a45d --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/raphael.js @@ -0,0 +1,3410 @@ +/*! + * Raphael 1.3.2 - JavaScript Vector Library + * + * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com) + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. + */ + +Raphael = (function () { + var separator = /[, ]+/, + elements = /^(circle|rect|path|ellipse|text|image)$/, + proto = "prototype", + has = "hasOwnProperty", + doc = document, + win = window, + oldRaphael = { + was: Object[proto][has].call(win, "Raphael"), + is: win.Raphael + }, + R = function () { + if (R.is(arguments[0], "array")) { + var a = arguments[0], + cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))), + res = cnv.set(); + for (var i = 0, ii = a[length]; i < ii; i++) { + var j = a[i] || {}; + elements.test(j.type) && res[push](cnv[j.type]().attr(j)); + } + return res; + } + return create[apply](R, arguments); + }, + Paper = function () { + }, + appendChild = "appendChild", + apply = "apply", + concat = "concat", + E = "", + S = " ", + split = "split", + events = "click dblclick mousedown mousemove mouseout mouseover mouseup"[split](S), + join = "join", + length = "length", + lowerCase = String[proto].toLowerCase, + math = Math, + mmax = math.max, + mmin = math.min, + nu = "number", + toString = "toString", + objectToString = Object[proto][toString], + paper = {}, + pow = math.pow, + push = "push", + rg = /^(?=[\da-f]$)/, + ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i, //" + colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i, + round = math.round, + setAttribute = "setAttribute", + toFloat = parseFloat, + toInt = parseInt, + upperCase = String[proto].toUpperCase, + availableAttrs = { + blur: 0, + "clip-rect": "0 0 1e9 1e9", + cursor: "default", + cx: 0, + cy: 0, + fill: "#fff", + "fill-opacity": 1, + font: '10px "Arial"', + "font-family": '"Arial"', + "font-size": "10", + "font-style": "normal", + "font-weight": 400, + gradient: 0, + height: 0, + href: "http://raphaeljs.com/", + opacity: 1, + path: "M0,0", + r: 0, + rotation: 0, + rx: 0, + ry: 0, + scale: "1 1", + src: "", + stroke: "#000", + "stroke-dasharray": "", + "stroke-linecap": "butt", + "stroke-linejoin": "butt", + "stroke-miterlimit": 0, + "stroke-opacity": 1, + "stroke-width": 1, + target: "_blank", + "text-anchor": "middle", + title: "Raphael", + translation: "0 0", + width: 0, + x: 0, + y: 0 + }, + availableAnimAttrs = { + along: "along", + blur: nu, + "clip-rect": "csv", + cx: nu, + cy: nu, + fill: "colour", + "fill-opacity": nu, + "font-size": nu, + height: nu, + opacity: nu, + path: "path", + r: nu, + rotation: "csv", + rx: nu, + ry: nu, + scale: "csv", + stroke: "colour", + "stroke-opacity": nu, + "stroke-width": nu, + translation: "csv", + width: nu, + x: nu, + y: nu + }, + rp = "replace"; + R.version = "1.3.2"; + R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML"); + if (R.type == "VML") { + var d = doc.createElement("div"); + d.innerHTML = ''; + if (d.childNodes[length] != 2) { + return R.type = null; + } + d = null; + } + R.svg = !(R.vml = R.type == "VML"); + Paper[proto] = R[proto]; + R._id = 0; + R._oid = 0; + R.fn = {}; + R.is = function (o, type) { + type = lowerCase.call(type); + return ((type == "object" || type == "undefined") && typeof o == type) || (o == null && type == "null") || lowerCase.call(objectToString.call(o).slice(8, -1)) == type; + }; + R.setWindow = function (newwin) { + win = newwin; + doc = win.document; + }; + // colour utilities + var toHex = function (color) { + if (R.vml) { + // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/ + var trim = /^\s+|\s+$/g; + toHex = cacher(function (color) { + var bod; + color = (color + E)[rp](trim, E); + try { + var docum = new win.ActiveXObject("htmlfile"); + docum.write(""); + docum.close(); + bod = docum.body; + } catch (e) { + bod = win.createPopup().document.body; + } + var range = bod.createTextRange(); + try { + bod.style.color = color; + var value = range.queryCommandValue("ForeColor"); + value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16); + return "#" + ("000000" + value[toString](16)).slice(-6); + } catch (e) { + return "none"; + } + }); + } else { + var i = doc.createElement("i"); + i.title = "Rapha\xebl Colour Picker"; + i.style.display = "none"; + doc.body[appendChild](i); + toHex = cacher(function (color) { + i.style.color = color; + return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color"); + }); + } + return toHex(color); + }; + var hsbtoString = function () { + return "hsb(" + [this.h, this.s, this.b] + ")"; + }, + rgbtoString = function () { + return this.hex; + }; + R.hsb2rgb = cacher(function (hue, saturation, brightness) { + if (R.is(hue, "object") && "h" in hue && "s" in hue && "b" in hue) { + brightness = hue.b; + saturation = hue.s; + hue = hue.h; + } + var red, + green, + blue; + if (brightness == 0) { + return {r: 0, g: 0, b: 0, hex: "#000"}; + } + if (hue > 1 || saturation > 1 || brightness > 1) { + hue /= 255; + saturation /= 255; + brightness /= 255; + } + var i = ~~(hue * 6), + f = (hue * 6) - i, + p = brightness * (1 - saturation), + q = brightness * (1 - (saturation * f)), + t = brightness * (1 - (saturation * (1 - f))); + red = [brightness, q, p, p, t, brightness, brightness][i]; + green = [t, brightness, brightness, q, p, p, t][i]; + blue = [p, p, t, brightness, brightness, q, p][i]; + red *= 255; + green *= 255; + blue *= 255; + var rgb = {r: red, g: green, b: blue, toString: rgbtoString}, + r = (~~red)[toString](16), + g = (~~green)[toString](16), + b = (~~blue)[toString](16); + r = r[rp](rg, "0"); + g = g[rp](rg, "0"); + b = b[rp](rg, "0"); + rgb.hex = "#" + r + g + b; + return rgb; + }, R); + R.rgb2hsb = cacher(function (red, green, blue) { + if (R.is(red, "object") && "r" in red && "g" in red && "b" in red) { + blue = red.b; + green = red.g; + red = red.r; + } + if (R.is(red, "string")) { + var clr = R.getRGB(red); + red = clr.r; + green = clr.g; + blue = clr.b; + } + if (red > 1 || green > 1 || blue > 1) { + red /= 255; + green /= 255; + blue /= 255; + } + var max = mmax(red, green, blue), + min = mmin(red, green, blue), + hue, + saturation, + brightness = max; + if (min == max) { + return {h: 0, s: 0, b: max}; + } else { + var delta = (max - min); + saturation = delta / max; + if (red == max) { + hue = (green - blue) / delta; + } else if (green == max) { + hue = 2 + ((blue - red) / delta); + } else { + hue = 4 + ((red - green) / delta); + } + hue /= 6; + hue < 0 && hue++; + hue > 1 && hue--; + } + return {h: hue, s: saturation, b: brightness, toString: hsbtoString}; + }, R); + var p2s = /,?([achlmqrstvxz]),?/gi; + R._path2string = function () { + return this.join(",")[rp](p2s, "$1"); + }; + + function cacher(f, scope, postprocessor) { + function newf() { + var arg = Array[proto].slice.call(arguments, 0), + args = arg[join]("\u25ba"), + cache = newf.cache = newf.cache || {}, + count = newf.count = newf.count || []; + if (cache[has](args)) { + return postprocessor ? postprocessor(cache[args]) : cache[args]; + } + count[length] >= 1e3 && delete cache[count.shift()]; + count[push](args); + cache[args] = f[apply](scope, arg); + return postprocessor ? postprocessor(cache[args]) : cache[args]; + } + + return newf; + } + + R.getRGB = cacher(function (colour) { + if (!colour || !!((colour = colour + E).indexOf("-") + 1)) { + return {r: -1, g: -1, b: -1, hex: "none", error: 1}; + } + if (colour == "none") { + return {r: -1, g: -1, b: -1, hex: "none"}; + } + !(({hs: 1, rg: 1})[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour)); + var res, + red, + green, + blue, + t, + rgb = colour.match(colourRegExp); + if (rgb) { + if (rgb[2]) { + blue = toInt(rgb[2].substring(5), 16); + green = toInt(rgb[2].substring(3, 5), 16); + red = toInt(rgb[2].substring(1, 3), 16); + } + if (rgb[3]) { + blue = toInt((t = rgb[3].charAt(3)) + t, 16); + green = toInt((t = rgb[3].charAt(2)) + t, 16); + red = toInt((t = rgb[3].charAt(1)) + t, 16); + } + if (rgb[4]) { + rgb = rgb[4][split](/\s*,\s*/); + red = toFloat(rgb[0]); + green = toFloat(rgb[1]); + blue = toFloat(rgb[2]); + } + if (rgb[5]) { + rgb = rgb[5][split](/\s*,\s*/); + red = toFloat(rgb[0]) * 2.55; + green = toFloat(rgb[1]) * 2.55; + blue = toFloat(rgb[2]) * 2.55; + } + if (rgb[6]) { + rgb = rgb[6][split](/\s*,\s*/); + red = toFloat(rgb[0]); + green = toFloat(rgb[1]); + blue = toFloat(rgb[2]); + return R.hsb2rgb(red, green, blue); + } + if (rgb[7]) { + rgb = rgb[7][split](/\s*,\s*/); + red = toFloat(rgb[0]) * 2.55; + green = toFloat(rgb[1]) * 2.55; + blue = toFloat(rgb[2]) * 2.55; + return R.hsb2rgb(red, green, blue); + } + rgb = {r: red, g: green, b: blue}; + var r = (~~red)[toString](16), + g = (~~green)[toString](16), + b = (~~blue)[toString](16); + r = r[rp](rg, "0"); + g = g[rp](rg, "0"); + b = b[rp](rg, "0"); + rgb.hex = "#" + r + g + b; + return rgb; + } + return {r: -1, g: -1, b: -1, hex: "none", error: 1}; + }, R); + R.getColor = function (value) { + var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75}, + rgb = this.hsb2rgb(start.h, start.s, start.b); + start.h += .075; + if (start.h > 1) { + start.h = 0; + start.s -= .2; + start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b}); + } + return rgb.hex; + }; + R.getColor.reset = function () { + delete this.start; + }; + // path utilities + var pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig, + pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig; + R.parsePathString = cacher(function (pathString) { + if (!pathString) { + return null; + } + var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0}, + data = []; + if (R.is(pathString, "array") && R.is(pathString[0], "array")) { // rough assumption + data = pathClone(pathString); + } + if (!data[length]) { + (pathString + E)[rp](pathCommand, function (a, b, c) { + var params = [], + name = lowerCase.call(b); + c[rp](pathValues, function (a, b) { + b && params[push](+b); + }); + if (name == "m" && params[length] > 2) { + data[push]([b][concat](params.splice(0, 2))); + name = "l"; + b = b == "m" ? "l" : "L"; + } + while (params[length] >= paramCounts[name]) { + data[push]([b][concat](params.splice(0, paramCounts[name]))); + if (!paramCounts[name]) { + break; + } + } + }); + } + data[toString] = R._path2string; + return data; + }); + R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { + var t1 = 1 - t, + x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x, + y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y, + mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x), + my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y), + nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x), + ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y), + ax = (1 - t) * p1x + t * c1x, + ay = (1 - t) * p1y + t * c1y, + cx = (1 - t) * c2x + t * p2x, + cy = (1 - t) * c2y + t * p2y, + alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI); + (mx > nx || my < ny) && (alpha += 180); + return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha}; + }; + var pathDimensions = cacher(function (path) { + if (!path) { + return {x: 0, y: 0, width: 0, height: 0}; + } + path = path2curve(path); + var x = 0, + y = 0, + X = [], + Y = [], + p; + for (var i = 0, ii = path[length]; i < ii; i++) { + p = path[i]; + if (p[0] == "M") { + x = p[1]; + y = p[2]; + X[push](x); + Y[push](y); + } else { + var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]); + X = X[concat](dim.min.x, dim.max.x); + Y = Y[concat](dim.min.y, dim.max.y); + x = p[5]; + y = p[6]; + } + } + var xmin = mmin[apply](0, X), + ymin = mmin[apply](0, Y); + return { + x: xmin, + y: ymin, + width: mmax[apply](0, X) - xmin, + height: mmax[apply](0, Y) - ymin + }; + }), + pathClone = function (pathArray) { + var res = []; + if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption + pathArray = R.parsePathString(pathArray); + } + for (var i = 0, ii = pathArray[length]; i < ii; i++) { + res[i] = []; + for (var j = 0, jj = pathArray[i][length]; j < jj; j++) { + res[i][j] = pathArray[i][j]; + } + } + res[toString] = R._path2string; + return res; + }, + pathToRelative = cacher(function (pathArray) { + if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption + pathArray = R.parsePathString(pathArray); + } + var res = [], + x = 0, + y = 0, + mx = 0, + my = 0, + start = 0; + if (pathArray[0][0] == "M") { + x = pathArray[0][1]; + y = pathArray[0][2]; + mx = x; + my = y; + start++; + res[push](["M", x, y]); + } + for (var i = start, ii = pathArray[length]; i < ii; i++) { + var r = res[i] = [], + pa = pathArray[i]; + if (pa[0] != lowerCase.call(pa[0])) { + r[0] = lowerCase.call(pa[0]); + switch (r[0]) { + case "a": + r[1] = pa[1]; + r[2] = pa[2]; + r[3] = pa[3]; + r[4] = pa[4]; + r[5] = pa[5]; + r[6] = +(pa[6] - x).toFixed(3); + r[7] = +(pa[7] - y).toFixed(3); + break; + case "v": + r[1] = +(pa[1] - y).toFixed(3); + break; + case "m": + mx = pa[1]; + my = pa[2]; + default: + for (var j = 1, jj = pa[length]; j < jj; j++) { + r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3); + } + } + } else { + r = res[i] = []; + if (pa[0] == "m") { + mx = pa[1] + x; + my = pa[2] + y; + } + for (var k = 0, kk = pa[length]; k < kk; k++) { + res[i][k] = pa[k]; + } + } + var len = res[i][length]; + switch (res[i][0]) { + case "z": + x = mx; + y = my; + break; + case "h": + x += +res[i][len - 1]; + break; + case "v": + y += +res[i][len - 1]; + break; + default: + x += +res[i][len - 2]; + y += +res[i][len - 1]; + } + } + res[toString] = R._path2string; + return res; + }, 0, pathClone), + pathToAbsolute = cacher(function (pathArray) { + if (!R.is(pathArray, "array") || !R.is(pathArray && pathArray[0], "array")) { // rough assumption + pathArray = R.parsePathString(pathArray); + } + var res = [], + x = 0, + y = 0, + mx = 0, + my = 0, + start = 0; + if (pathArray[0][0] == "M") { + x = +pathArray[0][1]; + y = +pathArray[0][2]; + mx = x; + my = y; + start++; + res[0] = ["M", x, y]; + } + for (var i = start, ii = pathArray[length]; i < ii; i++) { + var r = res[i] = [], + pa = pathArray[i]; + if (pa[0] != upperCase.call(pa[0])) { + r[0] = upperCase.call(pa[0]); + switch (r[0]) { + case "A": + r[1] = pa[1]; + r[2] = pa[2]; + r[3] = pa[3]; + r[4] = pa[4]; + r[5] = pa[5]; + r[6] = +(pa[6] + x); + r[7] = +(pa[7] + y); + break; + case "V": + r[1] = +pa[1] + y; + break; + case "H": + r[1] = +pa[1] + x; + break; + case "M": + mx = +pa[1] + x; + my = +pa[2] + y; + default: + for (var j = 1, jj = pa[length]; j < jj; j++) { + r[j] = +pa[j] + ((j % 2) ? x : y); + } + } + } else { + for (var k = 0, kk = pa[length]; k < kk; k++) { + res[i][k] = pa[k]; + } + } + switch (r[0]) { + case "Z": + x = mx; + y = my; + break; + case "H": + x = r[1]; + break; + case "V": + y = r[1]; + break; + default: + x = res[i][res[i][length] - 2]; + y = res[i][res[i][length] - 1]; + } + } + res[toString] = R._path2string; + return res; + }, null, pathClone), + l2c = function (x1, y1, x2, y2) { + return [x1, y1, x2, y2, x2, y2]; + }, + q2c = function (x1, y1, ax, ay, x2, y2) { + var _13 = 1 / 3, + _23 = 2 / 3; + return [ + _13 * x1 + _23 * ax, + _13 * y1 + _23 * ay, + _13 * x2 + _23 * ax, + _13 * y2 + _23 * ay, + x2, + y2 + ]; + }, + a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) { + // for more information of where this math came from visit: + // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes + var PI = math.PI, + _120 = PI * 120 / 180, + rad = PI / 180 * (+angle || 0), + res = [], + xy, + rotate = cacher(function (x, y, rad) { + var X = x * math.cos(rad) - y * math.sin(rad), + Y = x * math.sin(rad) + y * math.cos(rad); + return {x: X, y: Y}; + }); + if (!recursive) { + xy = rotate(x1, y1, -rad); + x1 = xy.x; + y1 = xy.y; + xy = rotate(x2, y2, -rad); + x2 = xy.x; + y2 = xy.y; + var cos = math.cos(PI / 180 * angle), + sin = math.sin(PI / 180 * angle), + x = (x1 - x2) / 2, + y = (y1 - y2) / 2; + // rx = mmax(rx, math.abs(x)); + // ry = mmax(ry, math.abs(y)); + var h = (x * x) / (rx * rx) + (y * y) / (ry * ry); + if (h > 1) { + h = math.sqrt(h); + rx = h * rx; + ry = h * ry; + } + var rx2 = rx * rx, + ry2 = ry * ry, + k = (large_arc_flag == sweep_flag ? -1 : 1) * + math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))), + cx = k * rx * y / ry + (x1 + x2) / 2, + cy = k * -ry * x / rx + (y1 + y2) / 2, + f1 = math.asin(((y1 - cy) / ry).toFixed(7)), + f2 = math.asin(((y2 - cy) / ry).toFixed(7)); + + f1 = x1 < cx ? PI - f1 : f1; + f2 = x2 < cx ? PI - f2 : f2; + f1 < 0 && (f1 = PI * 2 + f1); + f2 < 0 && (f2 = PI * 2 + f2); + if (sweep_flag && f1 > f2) { + f1 = f1 - PI * 2; + } + if (!sweep_flag && f2 > f1) { + f2 = f2 - PI * 2; + } + } else { + f1 = recursive[0]; + f2 = recursive[1]; + cx = recursive[2]; + cy = recursive[3]; + } + var df = f2 - f1; + if (math.abs(df) > _120) { + var f2old = f2, + x2old = x2, + y2old = y2; + f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1); + x2 = cx + rx * math.cos(f2); + y2 = cy + ry * math.sin(f2); + res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]); + } + df = f2 - f1; + var c1 = math.cos(f1), + s1 = math.sin(f1), + c2 = math.cos(f2), + s2 = math.sin(f2), + t = math.tan(df / 4), + hx = 4 / 3 * rx * t, + hy = 4 / 3 * ry * t, + m1 = [x1, y1], + m2 = [x1 + hx * s1, y1 - hy * c1], + m3 = [x2 + hx * s2, y2 - hy * c2], + m4 = [x2, y2]; + m2[0] = 2 * m1[0] - m2[0]; + m2[1] = 2 * m1[1] - m2[1]; + if (recursive) { + return [m2, m3, m4][concat](res); + } else { + res = [m2, m3, m4][concat](res)[join]()[split](","); + var newres = []; + for (var i = 0, ii = res[length]; i < ii; i++) { + newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; + } + // alert(newres); + return newres; + } + }, + findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { + var t1 = 1 - t; + return { + x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x, + y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y + }; + }, + curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) { + var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x), + b = 2 * (c1x - p1x) - 2 * (c2x - c1x), + c = p1x - c1x, + t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a, + t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a, + y = [p1y, p2y], + x = [p1x, p2x], + dot; + math.abs(t1) > 1e12 && (t1 = .5); + math.abs(t2) > 1e12 && (t2 = .5); + if (t1 > 0 && t1 < 1) { + dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); + x[push](dot.x); + y[push](dot.y); + } + if (t2 > 0 && t2 < 1) { + dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2); + x[push](dot.x); + y[push](dot.y); + } + a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y); + b = 2 * (c1y - p1y) - 2 * (c2y - c1y); + c = p1y - c1y; + t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a; + t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a; + math.abs(t1) > 1e12 && (t1 = .5); + math.abs(t2) > 1e12 && (t2 = .5); + if (t1 > 0 && t1 < 1) { + dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1); + x[push](dot.x); + y[push](dot.y); + } + if (t2 > 0 && t2 < 1) { + dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2); + x[push](dot.x); + y[push](dot.y); + } + return { + min: {x: mmin[apply](0, x), y: mmin[apply](0, y)}, + max: {x: mmax[apply](0, x), y: mmax[apply](0, y)} + }; + }), + path2curve = cacher(function (path, path2) { + var p = pathToAbsolute(path), + p2 = path2 && pathToAbsolute(path2), + attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null}, + attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null}, + processPath = function (path, d) { + var nx, ny; + if (!path) { + return ["C", d.x, d.y, d.x, d.y, d.x, d.y]; + } + !(path[0] in {T: 1, Q: 1}) && (d.qx = d.qy = null); + switch (path[0]) { + case "M": + d.X = path[1]; + d.Y = path[2]; + break; + case "A": + path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1)))); + break; + case "S": + nx = d.x + (d.x - (d.bx || d.x)); + ny = d.y + (d.y - (d.by || d.y)); + path = ["C", nx, ny][concat](path.slice(1)); + break; + case "T": + d.qx = d.x + (d.x - (d.qx || d.x)); + d.qy = d.y + (d.y - (d.qy || d.y)); + path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2])); + break; + case "Q": + d.qx = path[1]; + d.qy = path[2]; + path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4])); + break; + case "L": + path = ["C"][concat](l2c(d.x, d.y, path[1], path[2])); + break; + case "H": + path = ["C"][concat](l2c(d.x, d.y, path[1], d.y)); + break; + case "V": + path = ["C"][concat](l2c(d.x, d.y, d.x, path[1])); + break; + case "Z": + path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y)); + break; + } + return path; + }, + fixArc = function (pp, i) { + if (pp[i][length] > 7) { + pp[i].shift(); + var pi = pp[i]; + while (pi[length]) { + pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6))); + } + pp.splice(i, 1); + ii = mmax(p[length], p2 && p2[length] || 0); + } + }, + fixM = function (path1, path2, a1, a2, i) { + if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") { + path2.splice(i, 0, ["M", a2.x, a2.y]); + a1.bx = 0; + a1.by = 0; + a1.x = path1[i][1]; + a1.y = path1[i][2]; + ii = mmax(p[length], p2 && p2[length] || 0); + } + }; + for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) { + p[i] = processPath(p[i], attrs); + fixArc(p, i); + p2 && (p2[i] = processPath(p2[i], attrs2)); + p2 && fixArc(p2, i); + fixM(p, p2, attrs, attrs2, i); + fixM(p2, p, attrs2, attrs, i); + var seg = p[i], + seg2 = p2 && p2[i], + seglen = seg[length], + seg2len = p2 && seg2[length]; + attrs.x = seg[seglen - 2]; + attrs.y = seg[seglen - 1]; + attrs.bx = toFloat(seg[seglen - 4]) || attrs.x; + attrs.by = toFloat(seg[seglen - 3]) || attrs.y; + attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x); + attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y); + attrs2.x = p2 && seg2[seg2len - 2]; + attrs2.y = p2 && seg2[seg2len - 1]; + } + return p2 ? [p, p2] : p; + }, null, pathClone), + parseDots = cacher(function (gradient) { + var dots = []; + for (var i = 0, ii = gradient[length]; i < ii; i++) { + var dot = {}, + par = gradient[i].match(/^([^:]*):?([\d\.]*)/); + dot.color = R.getRGB(par[1]); + if (dot.color.error) { + return null; + } + dot.color = dot.color.hex; + par[2] && (dot.offset = par[2] + "%"); + dots[push](dot); + } + for (i = 1, ii = dots[length] - 1; i < ii; i++) { + if (!dots[i].offset) { + var start = toFloat(dots[i - 1].offset || 0), + end = 0; + for (var j = i + 1; j < ii; j++) { + if (dots[j].offset) { + end = dots[j].offset; + break; + } + } + if (!end) { + end = 100; + j = ii; + } + end = toFloat(end); + var d = (end - start) / (j - i + 1); + for (; i < j; i++) { + start += d; + dots[i].offset = start + "%"; + } + } + } + return dots; + }), + getContainer = function (x, y, w, h) { + var container; + if (R.is(x, "string") || R.is(x, "object")) { + container = R.is(x, "string") ? doc.getElementById(x) : x; + if (container.tagName) { + if (y == null) { + return { + container: container, + width: container.style.pixelWidth || container.offsetWidth, + height: container.style.pixelHeight || container.offsetHeight + }; + } else { + return {container: container, width: y, height: w}; + } + } + } else if (R.is(x, nu) && h != null) { + return {container: 1, x: x, y: y, width: w, height: h}; + } + }, + plugins = function (con, add) { + var that = this; + for (var prop in add) { + if (add[has](prop) && !(prop in con)) { + switch (typeof add[prop]) { + case "function": + (function (f) { + con[prop] = con === that ? f : function () { + return f[apply](that, arguments); + }; + })(add[prop]); + break; + case "object": + con[prop] = con[prop] || {}; + plugins.call(this, con[prop], add[prop]); + break; + default: + con[prop] = add[prop]; + break; + } + } + } + }, + tear = function (el, paper) { + el == paper.top && (paper.top = el.prev); + el == paper.bottom && (paper.bottom = el.next); + el.next && (el.next.prev = el.prev); + el.prev && (el.prev.next = el.next); + }, + tofront = function (el, paper) { + if (paper.top === el) { + return; + } + tear(el, paper); + el.next = null; + el.prev = paper.top; + paper.top.next = el; + paper.top = el; + }, + toback = function (el, paper) { + if (paper.bottom === el) { + return; + } + tear(el, paper); + el.next = paper.bottom; + el.prev = null; + paper.bottom.prev = el; + paper.bottom = el; + }, + insertafter = function (el, el2, paper) { + tear(el, paper); + el2 == paper.top && (paper.top = el); + el2.next && (el2.next.prev = el); + el.next = el2.next; + el.prev = el2; + el2.next = el; + }, + insertbefore = function (el, el2, paper) { + tear(el, paper); + el2 == paper.bottom && (paper.bottom = el); + el2.prev && (el2.prev.next = el); + el.prev = el2.prev; + el2.prev = el; + el.next = el2; + }, + removed = function (methodname) { + return function () { + throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object"); + }; + }, + radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/; + + // SVG + if (R.svg) { + Paper[proto].svgns = "http://www.w3.org/2000/svg"; + Paper[proto].xlink = "http://www.w3.org/1999/xlink"; + round = function (num) { + return +num + (~~num === num) * .5; + }; + var roundPath = function (path) { + for (var i = 0, ii = path[length]; i < ii; i++) { + if (lowerCase.call(path[i][0]) != "a") { + for (var j = 1, jj = path[i][length]; j < jj; j++) { + path[i][j] = round(path[i][j]); + } + } else { + path[i][6] = round(path[i][6]); + path[i][7] = round(path[i][7]); + } + } + return path; + }, + $ = function (el, attr) { + if (attr) { + for (var key in attr) { + if (attr[has](key)) { + el[setAttribute](key, attr[key] + E); + } + } + } else { + return doc.createElementNS(Paper[proto].svgns, el); + } + }; + R[toString] = function () { + return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version; + }; + var thePath = function (pathString, SVG) { + var el = $("path"); + SVG.canvas && SVG.canvas[appendChild](el); + var p = new Element(el, SVG); + p.type = "path"; + setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString}); + return p; + }; + var addGradientFill = function (o, gradient, SVG) { + var type = "linear", + fx = .5, fy = .5, + s = o.style; + gradient = (gradient + E)[rp](radial_gradient, function (all, _fx, _fy) { + type = "radial"; + if (_fx && _fy) { + fx = toFloat(_fx); + fy = toFloat(_fy); + var dir = ((fy > .5) * 2 - 1); + pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && + (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) && + fy != .5 && + (fy = fy.toFixed(5) - 1e-5 * dir); + } + return E; + }); + gradient = gradient[split](/\s*\-\s*/); + if (type == "linear") { + var angle = gradient.shift(); + angle = -toFloat(angle); + if (isNaN(angle)) { + return null; + } + var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)], + max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1); + vector[2] *= max; + vector[3] *= max; + if (vector[2] < 0) { + vector[0] = -vector[2]; + vector[2] = 0; + } + if (vector[3] < 0) { + vector[1] = -vector[3]; + vector[3] = 0; + } + } + var dots = parseDots(gradient); + if (!dots) { + return null; + } + var id = o.getAttribute("fill"); + id = id.match(/^url\(#(.*)\)$/); + id && SVG.defs.removeChild(doc.getElementById(id[1])); + + var el = $(type + "Gradient"); + el.id = "r" + (R._id++)[toString](36); + $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]}); + SVG.defs[appendChild](el); + for (var i = 0, ii = dots[length]; i < ii; i++) { + var stop = $("stop"); + $(stop, { + offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%", + "stop-color": dots[i].color || "#fff" + }); + el[appendChild](stop); + } + $(o, { + fill: "url(#" + el.id + ")", + opacity: 1, + "fill-opacity": 1 + }); + s.fill = E; + s.opacity = 1; + s.fillOpacity = 1; + return 1; + }; + var updatePosition = function (o) { + var bbox = o.getBBox(); + $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)}); + }; + var setFillAndStroke = function (o, params) { + var dasharray = { + "": [0], + "none": [0], + "-": [3, 1], + ".": [1, 1], + "-.": [3, 1, 1, 1], + "-..": [3, 1, 1, 1, 1, 1], + ". ": [1, 3], + "- ": [4, 3], + "--": [8, 3], + "- .": [4, 3, 1, 3], + "--.": [8, 3, 1, 3], + "--..": [8, 3, 1, 3, 1, 3] + }, + node = o.node, + attrs = o.attrs, + rot = o.rotate(), + addDashes = function (o, value) { + value = dasharray[lowerCase.call(value)]; + if (value) { + var width = o.attrs["stroke-width"] || "1", + butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0, + dashes = []; + var i = value[length]; + while (i--) { + dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt; + } + $(node, {"stroke-dasharray": dashes[join](",")}); + } + }; + params[has]("rotation") && (rot = params.rotation); + var rotxy = (rot + E)[split](separator); + if (!(rotxy.length - 1)) { + rotxy = null; + } else { + rotxy[1] = +rotxy[1]; + rotxy[2] = +rotxy[2]; + } + toFloat(rot) && o.rotate(0, true); + for (var att in params) { + if (params[has](att)) { + if (!availableAttrs[has](att)) { + continue; + } + var value = params[att]; + attrs[att] = value; + switch (att) { + case "blur": + o.blur(value); + break; + case "rotation": + o.rotate(value, true); + break; + // Hyperlink + case "href": + case "title": + case "target": + var pn = node.parentNode; + if (lowerCase.call(pn.tagName) != "a") { + var hl = $("a"); + pn.insertBefore(hl, node); + hl[appendChild](node); + pn = hl; + } + pn.setAttributeNS(o.paper.xlink, att, value); + break; + case "cursor": + node.style.cursor = value; + break; + case "clip-rect": + var rect = (value + E)[split](separator); + if (rect[length] == 4) { + o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode); + var el = $("clipPath"), + rc = $("rect"); + el.id = "r" + (R._id++)[toString](36); + $(rc, { + x: rect[0], + y: rect[1], + width: rect[2], + height: rect[3] + }); + el[appendChild](rc); + o.paper.defs[appendChild](el); + $(node, {"clip-path": "url(#" + el.id + ")"}); + o.clip = rc; + } + if (!value) { + var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E)); + clip && clip.parentNode.removeChild(clip); + $(node, {"clip-path": E}); + delete o.clip; + } + break; + case "path": + if (o.type == "path") { + $(node, {d: value ? attrs.path = roundPath(pathToAbsolute(value)) : "M0,0"}); + } + break; + case "width": + node[setAttribute](att, value); + if (attrs.fx) { + att = "x"; + value = attrs.x; + } else { + break; + } + case "x": + if (attrs.fx) { + value = -attrs.x - (attrs.width || 0); + } + case "rx": + if (att == "rx" && o.type == "rect") { + break; + } + case "cx": + rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]); + node[setAttribute](att, round(value)); + o.pattern && updatePosition(o); + break; + case "height": + node[setAttribute](att, value); + if (attrs.fy) { + att = "y"; + value = attrs.y; + } else { + break; + } + case "y": + if (attrs.fy) { + value = -attrs.y - (attrs.height || 0); + } + case "ry": + if (att == "ry" && o.type == "rect") { + break; + } + case "cy": + rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]); + node[setAttribute](att, round(value)); + o.pattern && updatePosition(o); + break; + case "r": + if (o.type == "rect") { + $(node, {rx: value, ry: value}); + } else { + node[setAttribute](att, value); + } + break; + case "src": + if (o.type == "image") { + node.setAttributeNS(o.paper.xlink, "href", value); + } + break; + case "stroke-width": + node.style.strokeWidth = value; + // Need following line for Firefox + node[setAttribute](att, value); + if (attrs["stroke-dasharray"]) { + addDashes(o, attrs["stroke-dasharray"]); + } + break; + case "stroke-dasharray": + addDashes(o, value); + break; + case "translation": + var xy = (value + E)[split](separator); + xy[0] = +xy[0] || 0; + xy[1] = +xy[1] || 0; + if (rotxy) { + rotxy[1] += xy[0]; + rotxy[2] += xy[1]; + } + translate.call(o, xy[0], xy[1]); + break; + case "scale": + xy = (value + E)[split](separator); + o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]); + break; + case "fill": + var isURL = (value + E).match(ISURL); + if (isURL) { + el = $("pattern"); + var ig = $("image"); + el.id = "r" + (R._id++)[toString](36); + $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1}); + $(ig, {x: 0, y: 0}); + ig.setAttributeNS(o.paper.xlink, "href", isURL[1]); + el[appendChild](ig); + + var img = doc.createElement("img"); + img.style.cssText = "position:absolute;left:-9999em;top-9999em"; + img.onload = function () { + $(el, {width: this.offsetWidth, height: this.offsetHeight}); + $(ig, {width: this.offsetWidth, height: this.offsetHeight}); + doc.body.removeChild(this); + o.paper.safari(); + }; + doc.body[appendChild](img); + img.src = isURL[1]; + o.paper.defs[appendChild](el); + node.style.fill = "url(#" + el.id + ")"; + $(node, {fill: "url(#" + el.id + ")"}); + o.pattern = el; + o.pattern && updatePosition(o); + break; + } + if (!R.getRGB(value).error) { + delete params.gradient; + delete attrs.gradient; + !R.is(attrs.opacity, "undefined") && + R.is(params.opacity, "undefined") && + $(node, {opacity: attrs.opacity}); + !R.is(attrs["fill-opacity"], "undefined") && + R.is(params["fill-opacity"], "undefined") && + $(node, {"fill-opacity": attrs["fill-opacity"]}); + } else if ((({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper)) { + attrs.gradient = value; + attrs.fill = "none"; + break; + } + case "stroke": + node[setAttribute](att, R.getRGB(value).hex); + break; + case "gradient": + (({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper); + break; + case "opacity": + case "fill-opacity": + if (attrs.gradient) { + var gradient = doc.getElementById(node.getAttribute("fill")[rp](/^url\(#|\)$/g, E)); + if (gradient) { + var stops = gradient.getElementsByTagName("stop"); + stops[stops[length] - 1][setAttribute]("stop-opacity", value); + } + break; + } + default: + att == "font-size" && (value = toInt(value, 10) + "px"); + var cssrule = att[rp](/(\-.)/g, function (w) { + return upperCase.call(w.substring(1)); + }); + node.style[cssrule] = value; + // Need following line for Firefox + node[setAttribute](att, value); + break; + } + } + } + + tuneText(o, params); + if (rotxy) { + o.rotate(rotxy.join(S)); + } else { + toFloat(rot) && o.rotate(rot, true); + } + }; + var leading = 1.2, + tuneText = function (el, params) { + if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) { + return; + } + var a = el.attrs, + node = el.node, + fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10; + + if (params[has]("text")) { + a.text = params.text; + while (node.firstChild) { + node.removeChild(node.firstChild); + } + var texts = (params.text + E)[split]("\n"); + for (var i = 0, ii = texts[length]; i < ii; i++) { + if (texts[i]) { + var tspan = $("tspan"); + i && $(tspan, {dy: fontSize * leading, x: a.x}); + tspan[appendChild](doc.createTextNode(texts[i])); + node[appendChild](tspan); + } + } + } else { + texts = node.getElementsByTagName("tspan"); + for (i = 0, ii = texts[length]; i < ii; i++) { + i && $(texts[i], {dy: fontSize * leading, x: a.x}); + } + } + $(node, {y: a.y}); + var bb = el.getBBox(), + dif = a.y - (bb.y + bb.height / 2); + dif && isFinite(dif) && $(node, {y: a.y + dif}); + }, + Element = function (node, svg) { + var X = 0, + Y = 0; + this[0] = node; + this.id = R._oid++; + this.node = node; + node.raphael = this; + this.paper = svg; + this.attrs = this.attrs || {}; + this.transformations = []; // rotate, translate, scale + this._ = { + tx: 0, + ty: 0, + rt: {deg: 0, cx: 0, cy: 0}, + sx: 1, + sy: 1 + }; + !svg.bottom && (svg.bottom = this); + this.prev = svg.top; + svg.top && (svg.top.next = this); + svg.top = this; + this.next = null; + }; + Element[proto].rotate = function (deg, cx, cy) { + if (this.removed) { + return this; + } + if (deg == null) { + if (this._.rt.cx) { + return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S); + } + return this._.rt.deg; + } + var bbox = this.getBBox(); + deg = (deg + E)[split](separator); + if (deg[length] - 1) { + cx = toFloat(deg[1]); + cy = toFloat(deg[2]); + } + deg = toFloat(deg[0]); + if (cx != null) { + this._.rt.deg = deg; + } else { + this._.rt.deg += deg; + } + (cy == null) && (cx = null); + this._.rt.cx = cx; + this._.rt.cy = cy; + cx = cx == null ? bbox.x + bbox.width / 2 : cx; + cy = cy == null ? bbox.y + bbox.height / 2 : cy; + if (this._.rt.deg) { + this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy); + this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)}); + } else { + this.transformations[0] = E; + this.clip && $(this.clip, {transform: E}); + } + $(this.node, {transform: this.transformations[join](S)}); + return this; + }; + Element[proto].hide = function () { + !this.removed && (this.node.style.display = "none"); + return this; + }; + Element[proto].show = function () { + !this.removed && (this.node.style.display = ""); + return this; + }; + Element[proto].remove = function () { + if (this.removed) { + return; + } + tear(this, this.paper); + this.node.parentNode.removeChild(this.node); + for (var i in this) { + delete this[i]; + } + this.removed = true; + }; + Element[proto].getBBox = function () { + if (this.removed) { + return this; + } + if (this.type == "path") { + return pathDimensions(this.attrs.path); + } + if (this.node.style.display == "none") { + this.show(); + var hide = true; + } + var bbox = {}; + try { + bbox = this.node.getBBox(); + } catch (e) { + // Firefox 3.0.x plays badly here + } finally { + bbox = bbox || {}; + } + if (this.type == "text") { + bbox = {x: bbox.x, y: Infinity, width: 0, height: 0}; + for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) { + var bb = this.node.getExtentOfChar(i); + (bb.y < bbox.y) && (bbox.y = bb.y); + (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y); + (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x); + } + } + hide && this.hide(); + return bbox; + }; + Element[proto].attr = function (name, value) { + if (this.removed) { + return this; + } + if (name == null) { + var res = {}; + for (var i in this.attrs) { + if (this.attrs[has](i)) { + res[i] = this.attrs[i]; + } + } + this._.rt.deg && (res.rotation = this.rotate()); + (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale()); + res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient; + return res; + } + if (value == null && R.is(name, "string")) { + if (name == "translation") { + return translate.call(this); + } + if (name == "rotation") { + return this.rotate(); + } + if (name == "scale") { + return this.scale(); + } + if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) { + return this.attrs.gradient; + } + return this.attrs[name]; + } + if (value == null && R.is(name, "array")) { + var values = {}; + for (var j = 0, jj = name.length; j < jj; j++) { + values[name[j]] = this.attr(name[j]); + } + return values; + } + if (value != null) { + var params = {}; + params[name] = value; + setFillAndStroke(this, params); + } else if (name != null && R.is(name, "object")) { + setFillAndStroke(this, name); + } + return this; + }; + Element[proto].toFront = function () { + if (this.removed) { + return this; + } + this.node.parentNode[appendChild](this.node); + var svg = this.paper; + svg.top != this && tofront(this, svg); + return this; + }; + Element[proto].toBack = function () { + if (this.removed) { + return this; + } + if (this.node.parentNode.firstChild != this.node) { + this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild); + toback(this, this.paper); + var svg = this.paper; + } + return this; + }; + Element[proto].insertAfter = function (element) { + if (this.removed) { + return this; + } + var node = element.node; + if (node.nextSibling) { + node.parentNode.insertBefore(this.node, node.nextSibling); + } else { + node.parentNode[appendChild](this.node); + } + insertafter(this, element, this.paper); + return this; + }; + Element[proto].insertBefore = function (element) { + if (this.removed) { + return this; + } + var node = element.node; + node.parentNode.insertBefore(this.node, node); + insertbefore(this, element, this.paper); + return this; + }; + Element[proto].blur = function (size) { + // Experimental. No Safari support. Use it on your own risk. + var t = this; + if (+size !== 0) { + var fltr = $("filter"), + blur = $("feGaussianBlur"); + t.attrs.blur = size; + fltr.id = "r" + (R._id++)[toString](36); + $(blur, {stdDeviation: +size || 1.5}); + fltr.appendChild(blur); + t.paper.defs.appendChild(fltr); + t._blur = fltr; + $(t.node, {filter: "url(#" + fltr.id + ")"}); + } else { + if (t._blur) { + t._blur.parentNode.removeChild(t._blur); + delete t._blur; + delete t.attrs.blur; + } + t.node.removeAttribute("filter"); + } + }; + var theCircle = function (svg, x, y, r) { + x = round(x); + y = round(y); + var el = $("circle"); + svg.canvas && svg.canvas[appendChild](el); + var res = new Element(el, svg); + res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"}; + res.type = "circle"; + $(el, res.attrs); + return res; + }; + var theRect = function (svg, x, y, w, h, r) { + x = round(x); + y = round(y); + var el = $("rect"); + svg.canvas && svg.canvas[appendChild](el); + var res = new Element(el, svg); + res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"}; + res.type = "rect"; + $(el, res.attrs); + return res; + }; + var theEllipse = function (svg, x, y, rx, ry) { + x = round(x); + y = round(y); + var el = $("ellipse"); + svg.canvas && svg.canvas[appendChild](el); + var res = new Element(el, svg); + res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"}; + res.type = "ellipse"; + $(el, res.attrs); + return res; + }; + var theImage = function (svg, src, x, y, w, h) { + var el = $("image"); + $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"}); + el.setAttributeNS(svg.xlink, "href", src); + svg.canvas && svg.canvas[appendChild](el); + var res = new Element(el, svg); + res.attrs = {x: x, y: y, width: w, height: h, src: src}; + res.type = "image"; + return res; + }; + var theText = function (svg, x, y, text) { + var el = $("text"); + $(el, {x: x, y: y, "text-anchor": "middle"}); + svg.canvas && svg.canvas[appendChild](el); + var res = new Element(el, svg); + res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"}; + res.type = "text"; + setFillAndStroke(res, res.attrs); + return res; + }; + var setSize = function (width, height) { + this.width = width || this.width; + this.height = height || this.height; + this.canvas[setAttribute]("width", this.width); + this.canvas[setAttribute]("height", this.height); + return this; + }; + var create = function () { + var con = getContainer[apply](0, arguments), + container = con && con.container, + x = con.x, + y = con.y, + width = con.width, + height = con.height; + if (!container) { + throw new Error("SVG container not found."); + } + var cnvs = $("svg"); + width = width || 512; + height = height || 342; + $(cnvs, { + xmlns: "http://www.w3.org/2000/svg", + version: 1.1, + width: width, + height: height + }); + if (container == 1) { + cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px"; + doc.body[appendChild](cnvs); + } else { + if (container.firstChild) { + container.insertBefore(cnvs, container.firstChild); + } else { + container[appendChild](cnvs); + } + } + container = new Paper; + container.width = width; + container.height = height; + container.canvas = cnvs; + plugins.call(container, container, R.fn); + container.clear(); + return container; + }; + Paper[proto].clear = function () { + var c = this.canvas; + while (c.firstChild) { + c.removeChild(c.firstChild); + } + this.bottom = this.top = null; + (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl")); + c[appendChild](this.desc); + c[appendChild](this.defs = $("defs")); + }; + Paper[proto].remove = function () { + this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas); + for (var i in this) { + this[i] = removed(i); + } + }; + } + + // VML + if (R.vml) { + var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"}, + bites = /([clmz]),?([^clmz]*)/gi, + val = /-?[^,\s-]+/g, + coordsize = 1e3 + S + 1e3, + zoom = 10, + path2vml = function (path) { + var total = /[ahqstv]/ig, + command = pathToAbsolute; + (path + E).match(total) && (command = path2curve); + total = /[clmz]/g; + if (command == pathToAbsolute && !(path + E).match(total)) { + var res = (path + E)[rp](bites, function (all, command, args) { + var vals = [], + isMove = lowerCase.call(command) == "m", + res = map[command]; + args[rp](val, function (value) { + if (isMove && vals[length] == 2) { + res += vals + map[command == "m" ? "l" : "L"]; + vals = []; + } + vals[push](round(value * zoom)); + }); + return res + vals; + }); + return res; + } + var pa = command(path), p, r; + res = []; + for (var i = 0, ii = pa[length]; i < ii; i++) { + p = pa[i]; + r = lowerCase.call(pa[i][0]); + r == "z" && (r = "x"); + for (var j = 1, jj = p[length]; j < jj; j++) { + r += round(p[j] * zoom) + (j != jj - 1 ? "," : E); + } + res[push](r); + } + return res[join](S); + }; + + R[toString] = function () { + return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version; + }; + thePath = function (pathString, vml) { + var g = createNode("group"); + g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; + g.coordsize = vml.coordsize; + g.coordorigin = vml.coordorigin; + var el = createNode("shape"), ol = el.style; + ol.width = vml.width + "px"; + ol.height = vml.height + "px"; + el.coordsize = coordsize; + el.coordorigin = vml.coordorigin; + g[appendChild](el); + var p = new Element(el, g, vml), + attr = {fill: "none", stroke: "#000"}; + pathString && (attr.path = pathString); + p.isAbsolute = true; + p.type = "path"; + p.path = []; + p.Path = E; + setFillAndStroke(p, attr); + vml.canvas[appendChild](g); + return p; + }; + setFillAndStroke = function (o, params) { + o.attrs = o.attrs || {}; + var node = o.node, + a = o.attrs, + s = node.style, + xy, + res = o; + for (var par in params) { + if (params[has](par)) { + a[par] = params[par]; + } + } + params.href && (node.href = params.href); + params.title && (node.title = params.title); + params.target && (node.target = params.target); + params.cursor && (s.cursor = params.cursor); + "blur" in params && o.blur(params.blur); + if (params.path && o.type == "path") { + a.path = params.path; + node.path = path2vml(a.path); + } + if (params.rotation != null) { + o.rotate(params.rotation, true); + } + if (params.translation) { + xy = (params.translation + E)[split](separator); + translate.call(o, xy[0], xy[1]); + if (o._.rt.cx != null) { + o._.rt.cx += +xy[0]; + o._.rt.cy += +xy[1]; + o.setBox(o.attrs, xy[0], xy[1]); + } + } + if (params.scale) { + xy = (params.scale + E)[split](separator); + o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null); + } + if ("clip-rect" in params) { + var rect = (params["clip-rect"] + E)[split](separator); + if (rect[length] == 4) { + rect[2] = +rect[2] + (+rect[0]); + rect[3] = +rect[3] + (+rect[1]); + var div = node.clipRect || doc.createElement("div"), + dstyle = div.style, + group = node.parentNode; + dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect); + if (!node.clipRect) { + dstyle.position = "absolute"; + dstyle.top = 0; + dstyle.left = 0; + dstyle.width = o.paper.width + "px"; + dstyle.height = o.paper.height + "px"; + group.parentNode.insertBefore(div, group); + div[appendChild](group); + node.clipRect = div; + } + } + if (!params["clip-rect"]) { + node.clipRect && (node.clipRect.style.clip = E); + } + } + if (o.type == "image" && params.src) { + node.src = params.src; + } + if (o.type == "image" && params.opacity) { + node.filterOpacity = " progid:DXImageTransform.Microsoft.Alpha(opacity=" + (params.opacity * 100) + ")"; + s.filter = (node.filterMatrix || E) + (node.filterOpacity || E); + } + params.font && (s.font = params.font); + params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"'); //' + params["font-size"] && (s.fontSize = params["font-size"]); + params["font-weight"] && (s.fontWeight = params["font-weight"]); + params["font-style"] && (s.fontStyle = params["font-style"]); + if (params.opacity != null || + params["stroke-width"] != null || + params.fill != null || + params.stroke != null || + params["stroke-width"] != null || + params["stroke-opacity"] != null || + params["fill-opacity"] != null || + params["stroke-dasharray"] != null || + params["stroke-miterlimit"] != null || + params["stroke-linejoin"] != null || + params["stroke-linecap"] != null) { + node = o.shape || node; + var fill = (node.getElementsByTagName("fill") && node.getElementsByTagName("fill")[0]), + newfill = false; + !fill && (newfill = fill = createNode("fill")); + if ("fill-opacity" in params || "opacity" in params) { + var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1); + opacity < 0 && (opacity = 0); + opacity > 1 && (opacity = 1); + fill.opacity = opacity; + } + params.fill && (fill.on = true); + if (fill.on == null || params.fill == "none") { + fill.on = false; + } + if (fill.on && params.fill) { + var isURL = params.fill.match(ISURL); + if (isURL) { + fill.src = isURL[1]; + fill.type = "tile"; + } else { + fill.color = R.getRGB(params.fill).hex; + fill.src = E; + fill.type = "solid"; + if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || (params.fill + E).charAt() != "r") && addGradientFill(res, params.fill)) { + a.fill = "none"; + a.gradient = params.fill; + } + } + } + newfill && node[appendChild](fill); + var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]), + newstroke = false; + !stroke && (newstroke = stroke = createNode("stroke")); + if ((params.stroke && params.stroke != "none") || + params["stroke-width"] || + params["stroke-opacity"] != null || + params["stroke-dasharray"] || + params["stroke-miterlimit"] || + params["stroke-linejoin"] || + params["stroke-linecap"]) { + stroke.on = true; + } + (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false); + stroke.on && params.stroke && (stroke.color = R.getRGB(params.stroke).hex); + opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1); + var width = (toFloat(params["stroke-width"]) || 1) * .75; + opacity < 0 && (opacity = 0); + opacity > 1 && (opacity = 1); + params["stroke-width"] == null && (width = a["stroke-width"]); + params["stroke-width"] && (stroke.weight = width); + width && width < 1 && (opacity *= width) && (stroke.weight = 1); + stroke.opacity = opacity; + + params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter"); + stroke.miterlimit = params["stroke-miterlimit"] || 8; + params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round"); + if (params["stroke-dasharray"]) { + var dasharray = { + "-": "shortdash", + ".": "shortdot", + "-.": "shortdashdot", + "-..": "shortdashdotdot", + ". ": "dot", + "- ": "dash", + "--": "longdash", + "- .": "dashdot", + "--.": "longdashdot", + "--..": "longdashdotdot" + }; + stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E; + } + newstroke && node[appendChild](stroke); + } + if (res.type == "text") { + s = res.paper.span.style; + a.font && (s.font = a.font); + a["font-family"] && (s.fontFamily = a["font-family"]); + a["font-size"] && (s.fontSize = a["font-size"]); + a["font-weight"] && (s.fontWeight = a["font-weight"]); + a["font-style"] && (s.fontStyle = a["font-style"]); + res.node.string && (res.paper.span.innerHTML = (res.node.string + E)[rp](/")); + res.W = a.w = res.paper.span.offsetWidth; + res.H = a.h = res.paper.span.offsetHeight; + res.X = a.x; + res.Y = a.y + round(res.H / 2); + + // text-anchor emulationm + switch (a["text-anchor"]) { + case "start": + res.node.style["v-text-align"] = "left"; + res.bbx = round(res.W / 2); + break; + case "end": + res.node.style["v-text-align"] = "right"; + res.bbx = -round(res.W / 2); + break; + default: + res.node.style["v-text-align"] = "center"; + break; + } + } + }; + addGradientFill = function (o, gradient) { + o.attrs = o.attrs || {}; + var attrs = o.attrs, + fill = o.node.getElementsByTagName("fill"), + type = "linear", + fxfy = ".5 .5"; + o.attrs.gradient = gradient; + gradient = (gradient + E)[rp](radial_gradient, function (all, fx, fy) { + type = "radial"; + if (fx && fy) { + fx = toFloat(fx); + fy = toFloat(fy); + pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5); + fxfy = fx + S + fy; + } + return E; + }); + gradient = gradient[split](/\s*\-\s*/); + if (type == "linear") { + var angle = gradient.shift(); + angle = -toFloat(angle); + if (isNaN(angle)) { + return null; + } + } + var dots = parseDots(gradient); + if (!dots) { + return null; + } + o = o.shape || o.node; + fill = fill[0] || createNode("fill"); + if (dots[length]) { + fill.on = true; + fill.method = "none"; + fill.type = (type == "radial") ? "gradientradial" : "gradient"; + fill.color = dots[0].color; + fill.color2 = dots[dots[length] - 1].color; + var clrs = []; + for (var i = 0, ii = dots[length]; i < ii; i++) { + dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color); + } + fill.colors && (fill.colors.value = clrs[length] ? clrs[join](",") : "0% " + fill.color); + if (type == "radial") { + fill.focus = "100%"; + fill.focussize = fxfy; + fill.focusposition = fxfy; + } else { + fill.angle = (270 - angle) % 360; + } + } + return 1; + }; + Element = function (node, group, vml) { + var Rotation = 0, + RotX = 0, + RotY = 0, + Scale = 1; + this[0] = node; + this.id = R._oid++; + this.node = node; + node.raphael = this; + this.X = 0; + this.Y = 0; + this.attrs = {}; + this.Group = group; + this.paper = vml; + this._ = { + tx: 0, + ty: 0, + rt: {deg: 0}, + sx: 1, + sy: 1 + }; + !vml.bottom && (vml.bottom = this); + this.prev = vml.top; + vml.top && (vml.top.next = this); + vml.top = this; + this.next = null; + }; + Element[proto].rotate = function (deg, cx, cy) { + if (this.removed) { + return this; + } + if (deg == null) { + if (this._.rt.cx) { + return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S); + } + return this._.rt.deg; + } + deg = (deg + E)[split](separator); + if (deg[length] - 1) { + cx = toFloat(deg[1]); + cy = toFloat(deg[2]); + } + deg = toFloat(deg[0]); + if (cx != null) { + this._.rt.deg = deg; + } else { + this._.rt.deg += deg; + } + cy == null && (cx = null); + this._.rt.cx = cx; + this._.rt.cy = cy; + this.setBox(this.attrs, cx, cy); + this.Group.style.rotation = this._.rt.deg; + // gradient fix for rotation. TODO + // var fill = (this.shape || this.node).getElementsByTagName("fill"); + // fill = fill[0] || {}; + // var b = ((360 - this._.rt.deg) - 270) % 360; + // !R.is(fill.angle, "undefined") && (fill.angle = b); + return this; + }; + Element[proto].setBox = function (params, cx, cy) { + if (this.removed) { + return this; + } + var gs = this.Group.style, + os = (this.shape && this.shape.style) || this.node.style; + params = params || {}; + for (var i in params) { + if (params[has](i)) { + this.attrs[i] = params[i]; + } + } + cx = cx || this._.rt.cx; + cy = cy || this._.rt.cy; + var attr = this.attrs, + x, + y, + w, + h; + switch (this.type) { + case "circle": + x = attr.cx - attr.r; + y = attr.cy - attr.r; + w = h = attr.r * 2; + break; + case "ellipse": + x = attr.cx - attr.rx; + y = attr.cy - attr.ry; + w = attr.rx * 2; + h = attr.ry * 2; + break; + case "rect": + case "image": + x = +attr.x; + y = +attr.y; + w = attr.width || 0; + h = attr.height || 0; + break; + case "text": + this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E); + x = attr.x - round(this.W / 2); + y = attr.y - this.H / 2; + w = this.W; + h = this.H; + break; + case "path": + if (!this.attrs.path) { + x = 0; + y = 0; + w = this.paper.width; + h = this.paper.height; + } else { + var dim = pathDimensions(this.attrs.path); + x = dim.x; + y = dim.y; + w = dim.width; + h = dim.height; + } + break; + default: + x = 0; + y = 0; + w = this.paper.width; + h = this.paper.height; + break; + } + cx = (cx == null) ? x + w / 2 : cx; + cy = (cy == null) ? y + h / 2 : cy; + var left = cx - this.paper.width / 2, + top = cy - this.paper.height / 2, t; + gs.left != (t = left + "px") && (gs.left = t); + gs.top != (t = top + "px") && (gs.top = t); + this.X = this.type == "path" ? -left : x; + this.Y = this.type == "path" ? -top : y; + this.W = w; + this.H = h; + if (this.type == "path") { + os.left != (t = -left * zoom + "px") && (os.left = t); + os.top != (t = -top * zoom + "px") && (os.top = t); + } else if (this.type == "text") { + os.left != (t = -left + "px") && (os.left = t); + os.top != (t = -top + "px") && (os.top = t); + } else { + gs.width != (t = this.paper.width + "px") && (gs.width = t); + gs.height != (t = this.paper.height + "px") && (gs.height = t); + os.left != (t = x - left + "px") && (os.left = t); + os.top != (t = y - top + "px") && (os.top = t); + os.width != (t = w + "px") && (os.width = t); + os.height != (t = h + "px") && (os.height = t); + var arcsize = (+params.r || 0) / mmin(w, h); + if (this.type == "rect" && this.arcsize.toFixed(4) != arcsize.toFixed(4) && (arcsize || this.arcsize)) { + // We should replace element with the new one + var o = createNode("roundrect"), + a = {}, + ii = this.events && this.events[length]; + i = 0; + o.arcsize = arcsize; + o.raphael = this; + this.Group[appendChild](o); + this.Group.removeChild(this.node); + this[0] = this.node = o; + this.arcsize = arcsize; + for (i in attr) { + a[i] = attr[i]; + } + delete a.scale; + this.attr(a); + if (this.events) { + for (; i < ii; i++) { + this.events[i].unbind = addEvent(this.node, this.events[i].name, this.events[i].f, this); + } + } + } + } + }; + Element[proto].hide = function () { + !this.removed && (this.Group.style.display = "none"); + return this; + }; + Element[proto].show = function () { + !this.removed && (this.Group.style.display = "block"); + return this; + }; + Element[proto].getBBox = function () { + if (this.removed) { + return this; + } + if (this.type == "path") { + return pathDimensions(this.attrs.path); + } + return { + x: this.X + (this.bbx || 0), + y: this.Y, + width: this.W, + height: this.H + }; + }; + Element[proto].remove = function () { + if (this.removed) { + return; + } + tear(this, this.paper); + this.node.parentNode.removeChild(this.node); + this.Group.parentNode.removeChild(this.Group); + this.shape && this.shape.parentNode.removeChild(this.shape); + for (var i in this) { + delete this[i]; + } + this.removed = true; + }; + Element[proto].attr = function (name, value) { + if (this.removed) { + return this; + } + if (name == null) { + var res = {}; + for (var i in this.attrs) { + if (this.attrs[has](i)) { + res[i] = this.attrs[i]; + } + } + this._.rt.deg && (res.rotation = this.rotate()); + (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale()); + res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient; + return res; + } + if (value == null && R.is(name, "string")) { + if (name == "translation") { + return translate.call(this); + } + if (name == "rotation") { + return this.rotate(); + } + if (name == "scale") { + return this.scale(); + } + if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) { + return this.attrs.gradient; + } + return this.attrs[name]; + } + if (this.attrs && value == null && R.is(name, "array")) { + var ii, values = {}; + for (i = 0, ii = name[length]; i < ii; i++) { + values[name[i]] = this.attr(name[i]); + } + return values; + } + var params; + if (value != null) { + params = {}; + params[name] = value; + } + value == null && R.is(name, "object") && (params = name); + if (params) { + if (params.text && this.type == "text") { + this.node.string = params.text; + } + setFillAndStroke(this, params); + if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || (params.gradient + E).charAt() != "r")) { + addGradientFill(this, params.gradient); + } + (this.type != "path" || this._.rt.deg) && this.setBox(this.attrs); + } + return this; + }; + Element[proto].toFront = function () { + !this.removed && this.Group.parentNode[appendChild](this.Group); + this.paper.top != this && tofront(this, this.paper); + return this; + }; + Element[proto].toBack = function () { + if (this.removed) { + return this; + } + if (this.Group.parentNode.firstChild != this.Group) { + this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild); + toback(this, this.paper); + } + return this; + }; + Element[proto].insertAfter = function (element) { + if (this.removed) { + return this; + } + if (element.Group.nextSibling) { + element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling); + } else { + element.Group.parentNode[appendChild](this.Group); + } + insertafter(this, element, this.paper); + return this; + }; + Element[proto].insertBefore = function (element) { + if (this.removed) { + return this; + } + element.Group.parentNode.insertBefore(this.Group, element.Group); + insertbefore(this, element, this.paper); + return this; + }; + var blurregexp = / progid:\S+Blur\([^\)]+\)/g; + Element[proto].blur = function (size) { + var s = this.node.style, + f = s.filter; + f = f.replace(blurregexp, ""); + if (+size !== 0) { + this.attrs.blur = size; + s.filter = f + " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (+size || 1.5) + ")"; + s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5)); + } else { + s.filter = f; + s.margin = 0; + delete this.attrs.blur; + } + }; + + theCircle = function (vml, x, y, r) { + var g = createNode("group"), + o = createNode("oval"), + ol = o.style; + g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; + g.coordsize = coordsize; + g.coordorigin = vml.coordorigin; + g[appendChild](o); + var res = new Element(o, g, vml); + res.type = "circle"; + setFillAndStroke(res, {stroke: "#000", fill: "none"}); + res.attrs.cx = x; + res.attrs.cy = y; + res.attrs.r = r; + res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2}); + vml.canvas[appendChild](g); + return res; + }; + theRect = function (vml, x, y, w, h, r) { + var g = createNode("group"), + o = createNode("roundrect"), + arcsize = (+r || 0) / (mmin(w, h)); + g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; + g.coordsize = coordsize; + g.coordorigin = vml.coordorigin; + g[appendChild](o); + o.arcsize = arcsize; + var res = new Element(o, g, vml); + res.type = "rect"; + setFillAndStroke(res, {stroke: "#000"}); + res.arcsize = arcsize; + res.setBox({x: x, y: y, width: w, height: h, r: r}); + vml.canvas[appendChild](g); + return res; + }; + theEllipse = function (vml, x, y, rx, ry) { + var g = createNode("group"), + o = createNode("oval"), + ol = o.style; + g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; + g.coordsize = coordsize; + g.coordorigin = vml.coordorigin; + g[appendChild](o); + var res = new Element(o, g, vml); + res.type = "ellipse"; + setFillAndStroke(res, {stroke: "#000"}); + res.attrs.cx = x; + res.attrs.cy = y; + res.attrs.rx = rx; + res.attrs.ry = ry; + res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2}); + vml.canvas[appendChild](g); + return res; + }; + theImage = function (vml, src, x, y, w, h) { + var g = createNode("group"), + o = createNode("image"), + ol = o.style; + g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; + g.coordsize = coordsize; + g.coordorigin = vml.coordorigin; + o.src = src; + g[appendChild](o); + var res = new Element(o, g, vml); + res.type = "image"; + res.attrs.src = src; + res.attrs.x = x; + res.attrs.y = y; + res.attrs.w = w; + res.attrs.h = h; + res.setBox({x: x, y: y, width: w, height: h}); + vml.canvas[appendChild](g); + return res; + }; + theText = function (vml, x, y, text) { + var g = createNode("group"), + el = createNode("shape"), + ol = el.style, + path = createNode("path"), + ps = path.style, + o = createNode("textpath"); + g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px"; + g.coordsize = coordsize; + g.coordorigin = vml.coordorigin; + path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1); + path.textpathok = true; + ol.width = vml.width; + ol.height = vml.height; + o.string = text + E; + o.on = true; + el[appendChild](o); + el[appendChild](path); + g[appendChild](el); + var res = new Element(o, g, vml); + res.shape = el; + res.textpath = path; + res.type = "text"; + res.attrs.text = text; + res.attrs.x = x; + res.attrs.y = y; + res.attrs.w = 1; + res.attrs.h = 1; + setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"}); + res.setBox(); + vml.canvas[appendChild](g); + return res; + }; + setSize = function (width, height) { + var cs = this.canvas.style; + width == +width && (width += "px"); + height == +height && (height += "px"); + cs.width = width; + cs.height = height; + cs.clip = "rect(0 " + width + " " + height + " 0)"; + return this; + }; + var createNode; + doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)"); + try { + !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml"); + createNode = function (tagName) { + return doc.createElement(''); + }; + } catch (e) { + createNode = function (tagName) { + return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">'); + }; + } + create = function () { + var con = getContainer[apply](0, arguments), + container = con.container, + height = con.height, + s, + width = con.width, + x = con.x, + y = con.y; + if (!container) { + throw new Error("VML container not found."); + } + var res = new Paper, + c = res.canvas = doc.createElement("div"), + cs = c.style; + width = width || 512; + height = height || 342; + width == +width && (width += "px"); + height == +height && (height += "px"); + res.width = 1e3; + res.height = 1e3; + res.coordsize = zoom * 1e3 + S + zoom * 1e3; + res.coordorigin = "0 0"; + res.span = doc.createElement("span"); + res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;"; + c[appendChild](res.span); + cs.cssText = R.format("width:{0};height:{1};position:absolute;clip:rect(0 {0} {1} 0);overflow:hidden", width, height); + if (container == 1) { + doc.body[appendChild](c); + cs.left = x + "px"; + cs.top = y + "px"; + } else { + container.style.width = width; + container.style.height = height; + if (container.firstChild) { + container.insertBefore(c, container.firstChild); + } else { + container[appendChild](c); + } + } + plugins.call(res, res, R.fn); + return res; + }; + Paper[proto].clear = function () { + this.canvas.innerHTML = E; + this.span = doc.createElement("span"); + this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;"; + this.canvas[appendChild](this.span); + this.bottom = this.top = null; + }; + Paper[proto].remove = function () { + this.canvas.parentNode.removeChild(this.canvas); + for (var i in this) { + this[i] = removed(i); + } + return true; + }; + } + + // rest + // Safari or Chrome (WebKit) rendering bug workaround method + if ((/^Apple|^Google/).test(win.navigator.vendor) && !(win.navigator.userAgent.indexOf("Version/4.0") + 1)) { + Paper[proto].safari = function () { + var rect = this.rect(-99, -99, this.width + 99, this.height + 99); + win.setTimeout(function () { + rect.remove(); + }); + }; + } else { + Paper[proto].safari = function () { + }; + } + + // Events + var addEvent = (function () { + if (doc.addEventListener) { + return function (obj, type, fn, element) { + var f = function (e) { + return fn.call(element, e); + }; + obj.addEventListener(type, f, false); + return function () { + obj.removeEventListener(type, f, false); + return true; + }; + }; + } else if (doc.attachEvent) { + return function (obj, type, fn, element) { + var f = function (e) { + return fn.call(element, e || win.event); + }; + obj.attachEvent("on" + type, f); + var detacher = function () { + obj.detachEvent("on" + type, f); + return true; + }; + return detacher; + }; + } + })(); + for (var i = events[length]; i--;) { + (function (eventName) { + Element[proto][eventName] = function (fn) { + if (R.is(fn, "function")) { + this.events = this.events || []; + this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node, eventName, fn, this)}); + } + return this; + }; + Element[proto]["un" + eventName] = function (fn) { + var events = this.events, + l = events[length]; + while (l--) { + if (events[l].name == eventName && events[l].f == fn) { + events[l].unbind(); + events.splice(l, 1); + !events.length && delete this.events; + return this; + } + } + return this; + }; + })(events[i]); + } + Element[proto].hover = function (f_in, f_out) { + return this.mouseover(f_in).mouseout(f_out); + }; + Element[proto].unhover = function (f_in, f_out) { + return this.unmouseover(f_in).unmouseout(f_out); + }; + Paper[proto].circle = function (x, y, r) { + return theCircle(this, x || 0, y || 0, r || 0); + }; + Paper[proto].rect = function (x, y, w, h, r) { + return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0); + }; + Paper[proto].ellipse = function (x, y, rx, ry) { + return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0); + }; + Paper[proto].path = function (pathString) { + pathString && !R.is(pathString, "string") && !R.is(pathString[0], "array") && (pathString += E); + return thePath(R.format[apply](R, arguments), this); + }; + Paper[proto].image = function (src, x, y, w, h) { + return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0); + }; + Paper[proto].text = function (x, y, text) { + return theText(this, x || 0, y || 0, text || E); + }; + Paper[proto].set = function (itemsArray) { + arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length])); + return new Set(itemsArray); + }; + Paper[proto].setSize = setSize; + Paper[proto].top = Paper[proto].bottom = null; + Paper[proto].raphael = R; + + function x_y() { + return this.x + S + this.y; + } + + Element[proto].scale = function (x, y, cx, cy) { + if (x == null && y == null) { + return { + x: this._.sx, + y: this._.sy, + toString: x_y + }; + } + y = y || x; + !+y && (y = x); + var dx, + dy, + dcx, + dcy, + a = this.attrs; + if (x != 0) { + var bb = this.getBBox(), + rcx = bb.x + bb.width / 2, + rcy = bb.y + bb.height / 2, + kx = x / this._.sx, + ky = y / this._.sy; + cx = (+cx || cx == 0) ? cx : rcx; + cy = (+cy || cy == 0) ? cy : rcy; + var dirx = ~~(x / math.abs(x)), + diry = ~~(y / math.abs(y)), + s = this.node.style, + ncx = cx + (rcx - cx) * kx, + ncy = cy + (rcy - cy) * ky; + switch (this.type) { + case "rect": + case "image": + var neww = a.width * dirx * kx, + newh = a.height * diry * ky; + this.attr({ + height: newh, + r: a.r * mmin(dirx * kx, diry * ky), + width: neww, + x: ncx - neww / 2, + y: ncy - newh / 2 + }); + break; + case "circle": + case "ellipse": + this.attr({ + rx: a.rx * dirx * kx, + ry: a.ry * diry * ky, + r: a.r * mmin(dirx * kx, diry * ky), + cx: ncx, + cy: ncy + }); + break; + case "path": + var path = pathToRelative(a.path), + skip = true; + for (var i = 0, ii = path[length]; i < ii; i++) { + var p = path[i], + P0 = upperCase.call(p[0]); + if (P0 == "M" && skip) { + continue; + } else { + skip = false; + } + if (P0 == "A") { + p[path[i][length] - 2] *= kx; + p[path[i][length] - 1] *= ky; + p[1] *= dirx * kx; + p[2] *= diry * ky; + p[5] = +!(dirx + diry ? !+p[5] : +p[5]); + } else if (P0 == "H") { + for (var j = 1, jj = p[length]; j < jj; j++) { + p[j] *= kx; + } + } else if (P0 == "V") { + for (j = 1, jj = p[length]; j < jj; j++) { + p[j] *= ky; + } + } else { + for (j = 1, jj = p[length]; j < jj; j++) { + p[j] *= (j % 2) ? kx : ky; + } + } + } + var dim2 = pathDimensions(path); + dx = ncx - dim2.x - dim2.width / 2; + dy = ncy - dim2.y - dim2.height / 2; + path[0][1] += dx; + path[0][2] += dy; + this.attr({path: path}); + break; + } + if (this.type in {text: 1, image: 1} && (dirx != 1 || diry != 1)) { + if (this.transformations) { + this.transformations[2] = "scale("[concat](dirx, ",", diry, ")"); + this.node[setAttribute]("transform", this.transformations[join](S)); + dx = (dirx == -1) ? -a.x - (neww || 0) : a.x; + dy = (diry == -1) ? -a.y - (newh || 0) : a.y; + this.attr({x: dx, y: dy}); + a.fx = dirx - 1; + a.fy = diry - 1; + } else { + this.node.filterMatrix = " progid:DXImageTransform.Microsoft.Matrix(M11="[concat](dirx, + ", M12=0, M21=0, M22=", diry, + ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')"); + s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E); + } + } else { + if (this.transformations) { + this.transformations[2] = E; + this.node[setAttribute]("transform", this.transformations[join](S)); + a.fx = 0; + a.fy = 0; + } else { + this.node.filterMatrix = E; + s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E); + } + } + a.scale = [x, y, cx, cy][join](S); + this._.sx = x; + this._.sy = y; + } + return this; + }; + Element[proto].clone = function () { + var attr = this.attr(); + delete attr.scale; + delete attr.translation; + return this.paper[this.type]().attr(attr); + }; + var getPointAtSegmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) { + var len = 0, + old; + for (var i = 0; i < 1.001; i += .001) { + var dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i); + i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5)); + if (len >= length) { + return dot; + } + old = dot; + } + }), + getLengthFactory = function (istotal, subpath) { + return function (path, length, onlystart) { + path = path2curve(path); + var x, y, p, l, sp = "", subpaths = {}, point, + len = 0; + for (var i = 0, ii = path.length; i < ii; i++) { + p = path[i]; + if (p[0] == "M") { + x = +p[1]; + y = +p[2]; + } else { + l = segmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]); + if (len + l > length) { + if (subpath && !subpaths.start) { + point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len); + sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y]; + if (onlystart) { + return sp; + } + subpaths.start = sp; + sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join](); + len += l; + x = +p[5]; + y = +p[6]; + continue; + } + if (!istotal && !subpath) { + point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len); + return {x: point.x, y: point.y, alpha: point.alpha}; + } + } + len += l; + x = +p[5]; + y = +p[6]; + } + sp += p; + } + subpaths.end = sp; + point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1); + point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha}); + return point; + }; + }, + segmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) { + var old = {x: 0, y: 0}, + len = 0; + for (var i = 0; i < 1.01; i += .01) { + var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i); + i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5)); + old = dot; + } + return len; + }); + var getTotalLength = getLengthFactory(1), + getPointAtLength = getLengthFactory(), + getSubpathsAtLength = getLengthFactory(0, 1); + Element[proto].getTotalLength = function () { + if (this.type != "path") { + return; + } + return getTotalLength(this.attrs.path); + }; + Element[proto].getPointAtLength = function (length) { + if (this.type != "path") { + return; + } + return getPointAtLength(this.attrs.path, length); + }; + Element[proto].getSubpath = function (from, to) { + if (this.type != "path") { + return; + } + if (math.abs(this.getTotalLength() - to) < 1e-6) { + return getSubpathsAtLength(this.attrs.path, from).end; + } + var a = getSubpathsAtLength(this.attrs.path, to, 1); + return from ? getSubpathsAtLength(a, from).end : a; + }; + + // animation easing formulas + R.easing_formulas = { + linear: function (n) { + return n; + }, + "<": function (n) { + return pow(n, 3); + }, + ">": function (n) { + return pow(n - 1, 3) + 1; + }, + "<>": function (n) { + n = n * 2; + if (n < 1) { + return pow(n, 3) / 2; + } + n -= 2; + return (pow(n, 3) + 2) / 2; + }, + backIn: function (n) { + var s = 1.70158; + return n * n * ((s + 1) * n - s); + }, + backOut: function (n) { + n = n - 1; + var s = 1.70158; + return n * n * ((s + 1) * n + s) + 1; + }, + elastic: function (n) { + if (n == 0 || n == 1) { + return n; + } + var p = .3, + s = p / 4; + return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1; + }, + bounce: function (n) { + var s = 7.5625, + p = 2.75, + l; + if (n < (1 / p)) { + l = s * n * n; + } else { + if (n < (2 / p)) { + n -= (1.5 / p); + l = s * n * n + .75; + } else { + if (n < (2.5 / p)) { + n -= (2.25 / p); + l = s * n * n + .9375; + } else { + n -= (2.625 / p); + l = s * n * n + .984375; + } + } + } + return l; + } + }; + + var animationElements = {length: 0}, + animation = function () { + var Now = +new Date; + for (var l in animationElements) { + if (l != "length" && animationElements[has](l)) { + var e = animationElements[l]; + if (e.stop || e.el.removed) { + delete animationElements[l]; + animationElements[length]--; + continue; + } + var time = Now - e.start, + ms = e.ms, + easing = e.easing, + from = e.from, + diff = e.diff, + to = e.to, + t = e.t, + prev = e.prev || 0, + that = e.el, + callback = e.callback, + set = {}, + now; + if (time < ms) { + var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms; + for (var attr in from) { + if (from[has](attr)) { + switch (availableAnimAttrs[attr]) { + case "along": + now = pos * ms * diff[attr]; + to.back && (now = to.len - now); + var point = getPointAtLength(to[attr], now); + that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0); + diff.x = point.x; + diff.y = point.y; + that.translate(point.x - diff.sx, point.y - diff.sy); + to.rot && that.rotate(diff.r + point.alpha, point.x, point.y); + break; + case "number": + now = +from[attr] + pos * ms * diff[attr]; + break; + case "colour": + now = "rgb(" + [ + upto255(round(from[attr].r + pos * ms * diff[attr].r)), + upto255(round(from[attr].g + pos * ms * diff[attr].g)), + upto255(round(from[attr].b + pos * ms * diff[attr].b)) + ][join](",") + ")"; + break; + case "path": + now = []; + for (var i = 0, ii = from[attr][length]; i < ii; i++) { + now[i] = [from[attr][i][0]]; + for (var j = 1, jj = from[attr][i][length]; j < jj; j++) { + now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j]; + } + now[i] = now[i][join](S); + } + now = now[join](S); + break; + case "csv": + switch (attr) { + case "translation": + var x = diff[attr][0] * (time - prev), + y = diff[attr][1] * (time - prev); + t.x += x; + t.y += y; + now = x + S + y; + break; + case "rotation": + now = +from[attr][0] + pos * ms * diff[attr][0]; + from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]); + break; + case "scale": + now = + [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in to[attr] ? to[attr][2] : E), + (3 in to[attr] ? to[attr][3] : E)][join](S); + break; + case "clip-rect": + now = []; + i = 4; + while (i--) { + now[i] = +from[attr][i] + pos * ms * diff[attr][i]; + } + break; + } + break; + } + set[attr] = now; + } + } + that.attr(set); + that._run && that._run.call(that); + } else { + if (to.along) { + point = getPointAtLength(to.along, to.len * !to.back); + that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy); + to.rot && that.rotate(diff.r + point.alpha, point.x, point.y); + } + (t.x || t.y) && that.translate(-t.x, -t.y); + to.scale && (to.scale = to.scale + E); + that.attr(to); + delete animationElements[l]; + animationElements[length]--; + that.in_animation = null; + R.is(callback, "function") && callback.call(that); + } + e.prev = time; + } + } + R.svg && that && that.paper.safari(); + animationElements[length] && win.setTimeout(animation); + }, + upto255 = function (color) { + return color > 255 ? 255 : (color < 0 ? 0 : color); + }, + translate = function (x, y) { + if (x == null) { + return {x: this._.tx, y: this._.ty, toString: x_y}; + } + this._.tx += +x; + this._.ty += +y; + switch (this.type) { + case "circle": + case "ellipse": + this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy}); + break; + case "rect": + case "image": + case "text": + this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y}); + break; + case "path": + var path = pathToRelative(this.attrs.path); + path[0][1] += +x; + path[0][2] += +y; + this.attr({path: path}); + break; + } + return this; + }; + Element[proto].animateWith = function (element, params, ms, easing, callback) { + animationElements[element.id] && (params.start = animationElements[element.id].start); + return this.animate(params, ms, easing, callback); + }; + Element[proto].animateAlong = along(); + Element[proto].animateAlongBack = along(1); + + function along(isBack) { + return function (path, ms, rotate, callback) { + var params = {back: isBack}; + R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate); + path && path.constructor == Element && (path = path.attrs.path); + path && (params.along = path); + return this.animate(params, ms, callback); + }; + } + + Element[proto].onAnimation = function (f) { + this._run = f || 0; + return this; + }; + Element[proto].animate = function (params, ms, easing, callback) { + if (R.is(easing, "function") || !easing) { + callback = easing || null; + } + var from = {}, + to = {}, + diff = {}; + for (var attr in params) { + if (params[has](attr)) { + if (availableAnimAttrs[has](attr)) { + from[attr] = this.attr(attr); + (from[attr] == null) && (from[attr] = availableAttrs[attr]); + to[attr] = params[attr]; + switch (availableAnimAttrs[attr]) { + case "along": + var len = getTotalLength(params[attr]), + point = getPointAtLength(params[attr], len * !!params.back), + bb = this.getBBox(); + diff[attr] = len / ms; + diff.tx = bb.x; + diff.ty = bb.y; + diff.sx = point.x; + diff.sy = point.y; + to.rot = params.rot; + to.back = params.back; + to.len = len; + params.rot && (diff.r = toFloat(this.rotate()) || 0); + break; + case "number": + diff[attr] = (to[attr] - from[attr]) / ms; + break; + case "colour": + from[attr] = R.getRGB(from[attr]); + var toColour = R.getRGB(to[attr]); + diff[attr] = { + r: (toColour.r - from[attr].r) / ms, + g: (toColour.g - from[attr].g) / ms, + b: (toColour.b - from[attr].b) / ms + }; + break; + case "path": + var pathes = path2curve(from[attr], to[attr]); + from[attr] = pathes[0]; + var toPath = pathes[1]; + diff[attr] = []; + for (var i = 0, ii = from[attr][length]; i < ii; i++) { + diff[attr][i] = [0]; + for (var j = 1, jj = from[attr][i][length]; j < jj; j++) { + diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms; + } + } + break; + case "csv": + var values = (params[attr] + E)[split](separator), + from2 = (from[attr] + E)[split](separator); + switch (attr) { + case "translation": + from[attr] = [0, 0]; + diff[attr] = [values[0] / ms, values[1] / ms]; + break; + case "rotation": + from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]]; + diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0]; + break; + case "scale": + params[attr] = values; + from[attr] = (from[attr] + E)[split](separator); + diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0]; + break; + case "clip-rect": + from[attr] = (from[attr] + E)[split](separator); + diff[attr] = []; + i = 4; + while (i--) { + diff[attr][i] = (values[i] - from[attr][i]) / ms; + } + break; + } + to[attr] = values; + } + } + } + } + this.stop(); + this.in_animation = 1; + animationElements[this.id] = { + start: params.start || +new Date, + ms: ms, + easing: easing, + from: from, + diff: diff, + to: to, + el: this, + callback: callback, + t: {x: 0, y: 0} + }; + ++animationElements[length] == 1 && animation(); + return this; + }; + Element[proto].stop = function () { + animationElements[this.id] && animationElements[length]--; + delete animationElements[this.id]; + return this; + }; + Element[proto].translate = function (x, y) { + return this.attr({translation: x + " " + y}); + }; + Element[proto][toString] = function () { + return "Rapha\xebl\u2019s object"; + }; + R.ae = animationElements; + + // Set + var Set = function (items) { + this.items = []; + this[length] = 0; + if (items) { + for (var i = 0, ii = items[length]; i < ii; i++) { + if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) { + this[this.items[length]] = this.items[this.items[length]] = items[i]; + this[length]++; + } + } + } + }; + Set[proto][push] = function () { + var item, + len; + for (var i = 0, ii = arguments[length]; i < ii; i++) { + item = arguments[i]; + if (item && (item.constructor == Element || item.constructor == Set)) { + len = this.items[length]; + this[len] = this.items[len] = item; + this[length]++; + } + } + return this; + }; + Set[proto].pop = function () { + delete this[this[length]--]; + return this.items.pop(); + }; + for (var method in Element[proto]) { + if (Element[proto][has](method)) { + Set[proto][method] = (function (methodname) { + return function () { + for (var i = 0, ii = this.items[length]; i < ii; i++) { + this.items[i][methodname][apply](this.items[i], arguments); + } + return this; + }; + })(method); + } + } + Set[proto].attr = function (name, value) { + if (name && R.is(name, "array") && R.is(name[0], "object")) { + for (var j = 0, jj = name[length]; j < jj; j++) { + this.items[j].attr(name[j]); + } + } else { + for (var i = 0, ii = this.items[length]; i < ii; i++) { + this.items[i].attr(name, value); + } + } + return this; + }; + Set[proto].animate = function (params, ms, easing, callback) { + (R.is(easing, "function") || !easing) && (callback = easing || null); + var len = this.items[length], + i = len, + set = this, + collector; + callback && (collector = function () { + !--len && callback.call(set); + }); + this.items[--i].animate(params, ms, easing || collector, collector); + while (i--) { + this.items[i].animateWith(this.items[len - 1], params, ms, easing || collector, collector); + } + return this; + }; + Set[proto].insertAfter = function (el) { + var i = this.items[length]; + while (i--) { + this.items[i].insertAfter(el); + } + return this; + }; + Set[proto].getBBox = function () { + var x = [], + y = [], + w = [], + h = []; + for (var i = this.items[length]; i--;) { + var box = this.items[i].getBBox(); + x[push](box.x); + y[push](box.y); + w[push](box.x + box.width); + h[push](box.y + box.height); + } + x = mmin[apply](0, x); + y = mmin[apply](0, y); + return { + x: x, + y: y, + width: mmax[apply](0, w) - x, + height: mmax[apply](0, h) - y + }; + }; + Set[proto].clone = function (s) { + s = new Set; + for (var i = 0, ii = this.items[length]; i < ii; i++) { + s[push](this.items[i].clone()); + } + return s; + }; + + R.registerFont = function (font) { + if (!font.face) { + return font; + } + this.fonts = this.fonts || {}; + var fontcopy = { + w: font.w, + face: {}, + glyphs: {} + }, + family = font.face["font-family"]; + for (var prop in font.face) { + if (font.face[has](prop)) { + fontcopy.face[prop] = font.face[prop]; + } + } + if (this.fonts[family]) { + this.fonts[family][push](fontcopy); + } else { + this.fonts[family] = [fontcopy]; + } + if (!font.svg) { + fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10); + for (var glyph in font.glyphs) { + if (font.glyphs[has](glyph)) { + var path = font.glyphs[glyph]; + fontcopy.glyphs[glyph] = { + w: path.w, + k: {}, + d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) { + return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M"; + }) + "z" + }; + if (path.k) { + for (var k in path.k) { + if (path[has](k)) { + fontcopy.glyphs[glyph].k[k] = path.k[k]; + } + } + } + } + } + } + return font; + }; + Paper[proto].getFont = function (family, weight, style, stretch) { + stretch = stretch || "normal"; + style = style || "normal"; + weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400; + var font = R.fonts[family]; + if (!font) { + var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i"); + for (var fontName in R.fonts) { + if (R.fonts[has](fontName)) { + if (name.test(fontName)) { + font = R.fonts[fontName]; + break; + } + } + } + } + var thefont; + if (font) { + for (var i = 0, ii = font[length]; i < ii; i++) { + thefont = font[i]; + if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) { + break; + } + } + } + return thefont; + }; + Paper[proto].print = function (x, y, string, font, size, origin) { + origin = origin || "middle"; // baseline|middle + var out = this.set(), + letters = (string + E)[split](E), + shift = 0, + path = E, + scale; + R.is(font, "string") && (font = this.getFont(font)); + if (font) { + scale = (size || 16) / font.face["units-per-em"]; + var bb = font.face.bbox.split(separator), + top = +bb[0], + height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2); + for (var i = 0, ii = letters[length]; i < ii; i++) { + var prev = i && font.glyphs[letters[i - 1]] || {}, + curr = font.glyphs[letters[i]]; + shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0; + curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]})); + } + out.scale(scale, scale, top, height).translate(x - top, y - height); + } + return out; + }; + + var formatrg = /\{(\d+)\}/g; + R.format = function (token, array) { + var args = R.is(array, "array") ? [0][concat](array) : arguments; + token && R.is(token, "string") && args[length] - 1 && (token = token[rp](formatrg, function (str, i) { + return args[++i] == null ? E : args[i]; + })); + return token || E; + }; + R.ninja = function () { + oldRaphael.was ? (Raphael = oldRaphael.is) : delete Raphael; + return R; + }; + R.el = Element[proto]; + return R; +})(); \ No newline at end of file diff --git a/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/yui-min.js b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/yui-min.js new file mode 100644 index 00000000000..55f017d9b7f --- /dev/null +++ b/src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/yui-min.js @@ -0,0 +1,12 @@ +/* +Copyright (c) 2010, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.com/yui/license.html +version: 3.1.0 +build: 2026 +*/ +if(typeof YUI==="undefined"){var YUI=function(F,E,D,C,A){var B=this,J=arguments,I,G=J.length,H=(typeof YUI_config!=="undefined")&&YUI_config;if(!(B instanceof YUI)){return new YUI(F,E,D,C,A);}else{B._init();if(H){B._config(H);}for(I=0;I-1){M="3.0.0";}YUI.prototype={_config:function(Y){Y=Y||{};var T,V,W,U=this.config,X=U.modules,S=U.groups;for(V in Y){T=Y[V];if(X&&V=="modules"){for(W in T){X[W]=T[W];}}else{if(S&&V=="groups"){for(W in T){S[W]=T[W];}}else{if(V=="win"){U[V]=T.contentWindow||T;U.doc=U[V].document;}else{U[V]=T;}}}}},_init:function(){var U,V=this,S=YUI.Env,T=V.Env;V.version=M;if(!T){V.Env={mods:{},base:K,cdn:K+M+"/build/",bootstrapped:false,_idx:0,_used:{},_attached:{},_yidx:0,_uidx:0,_guidp:"y",_loaded:{},getBase:function(c,a){var W,X,Z,d,Y;X=(R&&R.getElementsByTagName("script"))||[];for(Z=0;ZJ)?H[J]:true;}}return L;};F.indexOf=(D.indexOf)?function(G,H){return D.indexOf.call(G,H);}:function(G,I){for(var H=0;H-1);};E.owns=F;E.each=function(K,J,L,I){var H=L||B,G;for(G in K){if(I||F(K,G)){J.call(H,K[G],G,K);}}return B;};E.some=function(K,J,L,I){var H=L||B,G;for(G in K){if(I||F(K,G)){if(J.call(H,K[G],G,K)){return true;}}}return false;};E.getValue=function(K,J){if(!B.Lang.isObject(K)){return D;}var H,I=B.Array(J),G=I.length;for(H=0;K!==D&&H=0){for(G=0;H!==D&&G0){C=D(I);if(C){return C;}else{E=I.lastIndexOf("-");if(E>=0){I=I.substring(0,E);if(E>=2&&I.charAt(E-2)==="-"){I=I.substring(0,E-2);}}else{break;}}}}return"";}});},"3.1.0",{requires:["yui-base"]});YUI.add("yui-log",function(A){(function(){var E,D=A,F="yui:log",B="undefined",C={debug:1,info:1,warn:1,error:1};D.log=function(I,Q,G,O){var K,N,L,J,M,H=D,P=H.config;if(P.debug){if(G){N=P.logExclude;L=P.logInclude;if(L&&!(G in L)){K=1;}else{if(N&&(G in N)){K=1;}}}if(!K){if(P.useBrowserConsole){J=(G)?G+": "+I:I;if(H.Lang.isFunction(P.logFn)){P.logFn(I,Q,G);}else{if(typeof console!=B&&console.log){M=(Q&&console[Q]&&(Q in C))?Q:"log";console[M](J);}else{if(typeof opera!=B){opera.postError(J);}}}}if(H.fire&&!O){if(!E){H.publish(F,{broadcast:2});E=1;}H.fire(F,{msg:I,cat:Q,src:G});}}}return H;};D.message=function(){return D.log.apply(D,arguments);};})();},"3.1.0",{requires:["yui-base"]});YUI.add("yui-later",function(A){(function(){var B=A.Lang,C=function(K,E,L,G,H){K=K||0;E=E||{};var F=L,J=A.Array(G),I,D;if(B.isString(L)){F=E[L];}if(!F){}I=function(){F.apply(E,J);};D=(H)?setInterval(I,K):setTimeout(I,K);return{id:D,interval:H,cancel:function(){if(this.interval){clearInterval(D);}else{clearTimeout(D);}}};};A.later=C;B.later=C;})();},"3.1.0",{requires:["yui-base"]});YUI.add("yui-throttle",function(Y){ +/* Based on work by Simon Willison: http://gist.github.com/292562 */ +var throttle=function(fn,ms){ms=(ms)?ms:(Y.config.throttleTime||150);if(ms===-1){return(function(){fn.apply(null,arguments);});}var last=(new Date()).getTime();return(function(){var now=(new Date()).getTime();if(now-last>ms){last=now;fn.apply(null,arguments);}});};Y.throttle=throttle;},"3.1.0",{requires:["yui-base"]});YUI.add("yui",function(A){},"3.1.0",{use:["yui-base","get","intl-base","yui-log","yui-later","yui-throttle"]}); \ No newline at end of file diff --git a/src/contrib/monitoring/JMX-RESOURCES b/src/contrib/monitoring/JMX-RESOURCES new file mode 100644 index 00000000000..1d1aa98fe7e --- /dev/null +++ b/src/contrib/monitoring/JMX-RESOURCES @@ -0,0 +1,38 @@ + +Resources for monitoring ZooKeeper using JMX +-------------------------------------------- + +JMX/REST Bridge +--------------- + +http://code.google.com/p/polarrose-jmx-rest-bridge/ + +"Simple Java Web Application that exposes JMX servers through HTTP. This was written so that external tools can easily query JMX attributes of Java applications. More specifically, this was written to allow Cacti to generate fancy graphs of ActiveMQ instances." + +JMXetric +-------- + +http://code.google.com/p/jmxetric/ + +"JMXetric is a 100% java, configurable JVM agent that periodically polls MBean attributes and reports their values to Ganglia." + +jmxquery +-------- + +http://code.google.com/p/jmxquery/ + +"a plugin for nagios to check jmx" + +check_jmx +--------- + +http://exchange.nagios.org/directory/Plugins/Java-Applications-and-Servers/check_jmx/details + + +jmx2snmp +-------- + +http://github.com/tcurdt/jmx2snmp + +Expose application JMX properties via SNMP + diff --git a/src/contrib/monitoring/README b/src/contrib/monitoring/README new file mode 100644 index 00000000000..d48e2ce26cf --- /dev/null +++ b/src/contrib/monitoring/README @@ -0,0 +1,84 @@ + +Tools and Recipes for ZooKeeper Monitoring +------------------------------------------ + +How To Monitor +-------------- + +A ZooKeeper cluster can be monitored in two ways: + 1. by using the 'mntr' 4letterword command + 2. by using JMX to query the MBeans + +This repo contains tools and recipes for monitoring ZooKeeper using the first method. + +Check the file JMX-RESOURCE for some links to resources that could help you monitor a ZooKeeper cluster using the JMX interface. + +Requirements +------------ + +ZooKeeper 3.4.0 or later or you can apply ZOOKEEPER-744 patch over the latest 3.3.x release. +The server should understand the 'mntr' 4letterword command. + +$ echo 'mntr' | nc localhost 2181 +zk_version 3.4.0--1, built on 06/19/2010 15:07 GMT +zk_avg_latency 141 +zk_max_latency 1788 +zk_min_latency 0 +zk_packets_received 385466 +zk_packets_sent 435364 +zk_outstanding_requests 0 +zk_server_state follower +zk_znode_count 5 +zk_watch_count 0 +zk_ephemerals_count 0 +zk_approximate_data_size 41 +zk_open_file_descriptor_count 20 +zk_max_file_descriptor_count 1024 + +Python 2.6 (maybe it works on previous version but it's not tested yet). + +In a nutshell +------------- + +All you need is check_zookeeper.py It has no external dependencies. + + +*** On Nagios call the script like this: + +./check_zookeeper.py -o nagios -s "" -k -w -c + + +*** On Cacti define a custom data input method using the script like this: + +./check_zookeeper.py -o cacti -s "" -k --leader + +-- outputs a single value for the given key fetched from the cluster leader + +OR + +./check_zookeeper.py -o cacti -s "" -k + +-- outputs multiple values on for each cluster node +ex: localhost_2182:0 localhost_2183:0 localhost_2181:0 localhost_2184:0 localhost_2185:0 + +*** On Ganglia: + +install the plugin found in the ganglia/ subfolder OR + +./check_zookeeper.py -o ganglia -s "" + +it will use gmetric to send zookeeper node status data. + + +Check the subfolders for configuration details and samples for each platform. + +License +------- + +Apache License 2.0 or later. + +ZooKeeper 4letterwords Commands +------------------------------- + +http://zookeeper.apache.org/docs/current/zookeeperAdmin.html#sc_zkCommands + diff --git a/src/contrib/monitoring/cacti/README b/src/contrib/monitoring/cacti/README new file mode 100644 index 00000000000..8188723e5e2 --- /dev/null +++ b/src/contrib/monitoring/cacti/README @@ -0,0 +1,56 @@ +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Recipes for ZooKeeper monitoring using Cacti +-------------------------------------------- + +Cacti install guide: https://help.ubuntu.com/community/Cacti + +Cacti Manual: http://www.cacti.net/downloads/docs/html/ +PDF version: http://www.cacti.net/downloads/docs/pdf/manual.pdf + +Check Chapter 16: Simplest Method of Going from Script to Graph + http://www.cacti.net/downloads/docs/html/how_to.html#SCRIPT_TO_GRAPH + +WARNING: I have wrote these instructions while installing and configuring the plugin on my desktop computer running Ubuntu 9.10. I've installed Cacti using apt-get. + +WARNING: I'm going to make the assumption that you know how to work with Cacti and how to setup Data Input Methods for custom scripts. I'm also going to assume that you have already installed Cacti and everything works as expected. + +You can extend the Cacti's data gathering functionality through external scripts. Cacti comes with a number of scripts out of the box wich are localted in the scripts/ directory. + + +The check_zookeeper.py script can be used a custom data input method for Cacti. + +Single value (check cluster status by sending queries to the leader): +--------------------------------------------------------------------- + +python scripts/check_zookeeper.py -s "localhost:2181,localhost:2182,localhost:2183,localhost:2184,localhost:2185" -k -o cacti --leader + +When you will call the script this way it will about a single value representing the value attached to this . + + +Multiple values (one for each cluster node): +-------------------------------------------- + +python scripts/check_zookeeper.py -s "localhost:2181,localhost:2182,localhost:2183,localhost:2184,localhost:2185" -k -o cacti + +Output: +localhost_2182:0 localhost_2183:0 localhost_2181:0 localhost_2184:0 localhost_2185:0 + + +TBD: Step by step guide + + diff --git a/src/contrib/monitoring/check_zookeeper.py b/src/contrib/monitoring/check_zookeeper.py new file mode 100755 index 00000000000..c00db8bc0b9 --- /dev/null +++ b/src/contrib/monitoring/check_zookeeper.py @@ -0,0 +1,358 @@ +#! /usr/bin/env python +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" Check Zookeeper Cluster + +Generic monitoring script that could be used with multiple platforms (Ganglia, Nagios, Cacti). + +It requires ZooKeeper 3.4.0 or greater. The script needs the 'mntr' 4letter word +command (patch ZOOKEEPER-744) that was now commited to the trunk. +The script also works with ZooKeeper 3.3.x but in a limited way. +""" + +import sys +import socket +import logging +import re +import subprocess + +from StringIO import StringIO +from optparse import OptionParser, OptionGroup + +__version__ = (0, 1, 0) + +log = logging.getLogger() +logging.basicConfig(level=logging.ERROR) + +class NagiosHandler(object): + + @classmethod + def register_options(cls, parser): + group = OptionGroup(parser, 'Nagios specific options') + + group.add_option('-w', '--warning', dest='warning') + group.add_option('-c', '--critical', dest='critical') + + parser.add_option_group(group) + + def analyze(self, opts, cluster_stats): + try: + warning = int(opts.warning) + critical = int(opts.critical) + + except (TypeError, ValueError): + print >>sys.stderr, 'Invalid values for "warning" and "critical".' + return 2 + + if opts.key is None: + print >>sys.stderr, 'You should specify a key name.' + return 2 + + warning_state, critical_state, values = [], [], [] + for host, stats in cluster_stats.items(): + if opts.key in stats: + + value = stats[opts.key] + values.append('%s=%s;%s;%s' % (host, value, warning, critical)) + + if warning >= value > critical or warning <= value < critical: + warning_state.append(host) + + elif (warning < critical and critical <= value) or (warning > critical and critical >= value): + critical_state.append(host) + + if not values: + # Zookeeper may be down, not serving requests or we may have a bad configuration + print 'Critical, %s not found' % opts.key + return 2 + + values = ' '.join(values) + if critical_state: + print 'Critical "%s" %s!|%s' % (opts.key, ', '.join(critical_state), values) + return 2 + + elif warning_state: + print 'Warning "%s" %s!|%s' % (opts.key, ', '.join(warning_state), values) + return 1 + + else: + print 'Ok "%s"!|%s' % (opts.key, values) + return 0 + +class CactiHandler(object): + + @classmethod + def register_options(cls, parser): + group = OptionGroup(parser, 'Cacti specific options') + + group.add_option('-l', '--leader', dest='leader', + action="store_true", help="only query the cluster leader") + + parser.add_option_group(group) + + def analyze(self, opts, cluster_stats): + if opts.key is None: + print >>sys.stderr, 'The key name is mandatory.' + return 1 + + if opts.leader is True: + try: + leader = [x for x in cluster_stats.values() \ + if x.get('zk_server_state', '') == 'leader'][0] + + except IndexError: + print >>sys.stderr, 'No leader found.' + return 3 + + if opts.key in leader: + print leader[opts.key] + return 0 + + else: + print >>sys.stderr, 'Unknown key: "%s"' % opts.key + return 2 + else: + for host, stats in cluster_stats.items(): + if opts.key not in stats: + continue + + host = host.replace(':', '_') + print '%s:%s' % (host, stats[opts.key]), + + +class GangliaHandler(object): + + @classmethod + def register_options(cls, parser): + group = OptionGroup(parser, 'Ganglia specific options') + + group.add_option('-g', '--gmetric', dest='gmetric', + default='/usr/bin/gmetric', help='ganglia gmetric binary '\ + 'location: /usr/bin/gmetric') + + parser.add_option_group(group) + + def call(self, *args, **kwargs): + subprocess.call(*args, **kwargs) + + def analyze(self, opts, cluster_stats): + if len(cluster_stats) != 1: + print >>sys.stderr, 'Only allowed to monitor a single node.' + return 1 + + for host, stats in cluster_stats.items(): + for k, v in stats.items(): + try: + self.call([opts.gmetric, '-n', k, '-v', str(int(v)), '-t', 'uint32']) + except (TypeError, ValueError): + pass + +class ZooKeeperServer(object): + + def __init__(self, host='localhost', port='2181', timeout=1): + self._address = (host, int(port)) + self._timeout = timeout + + def get_stats(self): + """ Get ZooKeeper server stats as a map """ + data = self._send_cmd('mntr') + if data: + return self._parse(data) + else: + data = self._send_cmd('stat') + return self._parse_stat(data) + + def _create_socket(self): + return socket.socket() + + def _send_cmd(self, cmd): + """ Send a 4letter word command to the server """ + s = self._create_socket() + s.settimeout(self._timeout) + + s.connect(self._address) + s.send(cmd) + + data = s.recv(2048) + s.close() + + return data + + def _parse(self, data): + """ Parse the output from the 'mntr' 4letter word command """ + h = StringIO(data) + + result = {} + for line in h.readlines(): + try: + key, value = self._parse_line(line) + result[key] = value + except ValueError: + pass # ignore broken lines + + return result + + def _parse_stat(self, data): + """ Parse the output from the 'stat' 4letter word command """ + h = StringIO(data) + + result = {} + + version = h.readline() + if version: + result['zk_version'] = version[version.index(':')+1:].strip() + + # skip all lines until we find the empty one + while h.readline().strip(): pass + + for line in h.readlines(): + m = re.match('Latency min/avg/max: (\d+)/(\d+)/(\d+)', line) + if m is not None: + result['zk_min_latency'] = int(m.group(1)) + result['zk_avg_latency'] = int(m.group(2)) + result['zk_max_latency'] = int(m.group(3)) + continue + + m = re.match('Received: (\d+)', line) + if m is not None: + result['zk_packets_received'] = int(m.group(1)) + continue + + m = re.match('Sent: (\d+)', line) + if m is not None: + result['zk_packets_sent'] = int(m.group(1)) + continue + + m = re.match('Outstanding: (\d+)', line) + if m is not None: + result['zk_outstanding_requests'] = int(m.group(1)) + continue + + m = re.match('Mode: (.*)', line) + if m is not None: + result['zk_server_state'] = m.group(1) + continue + + m = re.match('Node count: (\d+)', line) + if m is not None: + result['zk_znode_count'] = int(m.group(1)) + continue + + return result + + def _parse_line(self, line): + try: + key, value = map(str.strip, line.split('\t')) + except ValueError: + raise ValueError('Found invalid line: %s' % line) + + if not key: + raise ValueError('The key is mandatory and should not be empty') + + try: + value = int(value) + except (TypeError, ValueError): + pass + + return key, value + +def main(): + opts, args = parse_cli() + + cluster_stats = get_cluster_stats(opts.servers) + if opts.output is None: + dump_stats(cluster_stats) + return 0 + + handler = create_handler(opts.output) + if handler is None: + log.error('undefined handler: %s' % opts.output) + sys.exit(1) + + return handler.analyze(opts, cluster_stats) + +def create_handler(name): + """ Return an instance of a platform specific analyzer """ + try: + return globals()['%sHandler' % name.capitalize()]() + except KeyError: + return None + +def get_all_handlers(): + """ Get a list containing all the platform specific analyzers """ + return [NagiosHandler, CactiHandler, GangliaHandler] + +def dump_stats(cluster_stats): + """ Dump cluster statistics in an user friendly format """ + for server, stats in cluster_stats.items(): + print 'Server:', server + + for key, value in stats.items(): + print "%30s" % key, ' ', value + print + +def get_cluster_stats(servers): + """ Get stats for all the servers in the cluster """ + stats = {} + for host, port in servers: + try: + zk = ZooKeeperServer(host, port) + stats["%s:%s" % (host, port)] = zk.get_stats() + + except socket.error, e: + # ignore because the cluster can still work even + # if some servers fail completely + + # this error should be also visible in a variable + # exposed by the server in the statistics + + logging.info('unable to connect to server '\ + '"%s" on port "%s"' % (host, port)) + + return stats + + +def get_version(): + return '.'.join(map(str, __version__)) + + +def parse_cli(): + parser = OptionParser(usage='./check_zookeeper.py ', version=get_version()) + + parser.add_option('-s', '--servers', dest='servers', + help='a list of SERVERS', metavar='SERVERS') + + parser.add_option('-o', '--output', dest='output', + help='output HANDLER: nagios, ganglia, cacti', metavar='HANDLER') + + parser.add_option('-k', '--key', dest='key') + + for handler in get_all_handlers(): + handler.register_options(parser) + + opts, args = parser.parse_args() + + if opts.servers is None: + parser.error('The list of servers is mandatory') + + opts.servers = [s.split(':') for s in opts.servers.split(',')] + + return (opts, args) + + +if __name__ == '__main__': + sys.exit(main()) + diff --git a/src/contrib/monitoring/ganglia/README b/src/contrib/monitoring/ganglia/README new file mode 100644 index 00000000000..578adfee241 --- /dev/null +++ b/src/contrib/monitoring/ganglia/README @@ -0,0 +1,48 @@ +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Recipes for ZooKeeper monitoring using Ganglia +---------------------------------------------- + +Ganglia Install guide: http://sourceforge.net/apps/trac/ganglia/wiki/Ganglia%203.1.x%20Installation%20and%20Configuration + +Gmond configuration: http://sourceforge.net/apps/trac/ganglia/wiki/Gmond%203.1.x%20General%20Configuration + +WARNING: I have wrote these instructions while installing and configuring the plugin on my desktop computer running Ubuntu 9.10. I've installed Ganglia using apt-get. + +WARNING: I'm going to make the assumption that you know how to work with Ganglia. I'm also going to assume that you have already installed Gangli and everything works as expected. + +You can monitoring ZooKeeper using Ganglia in two ways: + +1. Using a python module: + + WARNING! The python module only works with Ganglia 3.1.x + + a. enable python modules: you can find instructions in modpython.confg + b. copy zookeeper.pyconf in /etc/ganglia/conf.d/ + c. copy zookeeper_ganglia.py in /usr/lib/ganglia/python_plugins + d. restart the ganglia-monitor + + This is the recommended way! + +2. OR Using check_zookeeper.py and gmetric: + + Monitoring ZooKeeper using Ganglia is a simple as calling: + + ./check_zookeeper.py -o ganglia -s localhost:2181 + + on each of the ZooKeeper cluster nodes. I'm making the assumption that you have already configured gmond and installed gmetric on each node. + diff --git a/src/contrib/monitoring/ganglia/Screenshot.png b/src/contrib/monitoring/ganglia/Screenshot.png new file mode 100644 index 00000000000..bc0e41d5f64 Binary files /dev/null and b/src/contrib/monitoring/ganglia/Screenshot.png differ diff --git a/src/contrib/monitoring/ganglia/modpython.conf b/src/contrib/monitoring/ganglia/modpython.conf new file mode 100644 index 00000000000..5cd051a8e33 --- /dev/null +++ b/src/contrib/monitoring/ganglia/modpython.conf @@ -0,0 +1,28 @@ +/* Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +/* Update gmond.conf */ + +modules { + module { + name = "python_module" + path = "/usr/lib/ganglia/modpython.so" + params = "/usr/lib/ganglia/python_modules" + } +} + +include ('/etc/ganglia/conf.d/*.pyconf') + diff --git a/src/contrib/monitoring/ganglia/zookeeper.pyconf b/src/contrib/monitoring/ganglia/zookeeper.pyconf new file mode 100644 index 00000000000..43801a0f2bd --- /dev/null +++ b/src/contrib/monitoring/ganglia/zookeeper.pyconf @@ -0,0 +1,49 @@ +/* Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +/* Update /etc/ganglia/gmond.conf with the content of this file. */ + +/* ATTENTION: Change the host and the port to meet your setup. */ + +modules { + module { + name = "zookeeper_ganglia" + language = "python" + param host { value = "127.0.0.1" } + param port { value = 2181 } + } +} + +collection_group { + collect_every = 20 + time_threshold = 60 + metric { name = "zk_avg_latency" } + metric { name = "zk_max_latency" } + metric { name = "zk_min_latency" } + metric { name = "zk_packets_received" } + metric { name = "zk_packets_sent" } + metric { name = "zk_outstanding_requests" } + metric { name = "zk_znode_count" } + metric { name = "zk_watch_count" } + metric { name = "zk_ephemerals_count" } + metric { name = "zk_approximate_data_size" } + metric { name = "zk_open_file_descriptor_count" } + metric { name = "zk_max_file_descriptor_count" } + metric { name = "zk_followers" } + metric { name = "zk_synced_followers" } + metric { name = "zk_pending_syncs" } +} + diff --git a/src/contrib/monitoring/ganglia/zookeeper_ganglia.py b/src/contrib/monitoring/ganglia/zookeeper_ganglia.py new file mode 100644 index 00000000000..dbcc5f68c9d --- /dev/null +++ b/src/contrib/monitoring/ganglia/zookeeper_ganglia.py @@ -0,0 +1,246 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" Python Ganglia Module for ZooKeeper monitoring + +Inspired by: http://gist.github.com/448007 + +Copy this file to /usr/lib/ganglia/python_plugins + +""" + +import sys +import socket +import time +import re +import copy + +from StringIO import StringIO + +TIME_BETWEEN_QUERIES = 20 +ZK_METRICS = { + 'time' : 0, + 'data' : {} +} +ZK_LAST_METRICS = copy.deepcopy(ZK_METRICS) + + +class ZooKeeperServer(object): + + def __init__(self, host='localhost', port='2181', timeout=1): + self._address = (host, int(port)) + self._timeout = timeout + + def get_stats(self): + """ Get ZooKeeper server stats as a map """ + global ZK_METRICS, ZK_LAST_METRICS + # update cache + ZK_METRICS = { + 'time' : time.time(), + 'data' : {} + } + data = self._send_cmd('mntr') + if data: + parsed_data = self._parse(data) + else: + data = self._send_cmd('stat') + parsed_data = self._parse_stat(data) + ZK_METRICS['data'] = parsed_data + ZK_LAST_METRICS = copy.deepcopy(ZK_METRICS) + return parsed_data + + def _create_socket(self): + return socket.socket() + + def _send_cmd(self, cmd): + """ Send a 4letter word command to the server """ + s = self._create_socket() + s.settimeout(self._timeout) + + s.connect(self._address) + s.send(cmd) + + data = s.recv(2048) + s.close() + + return data + + def _parse(self, data): + """ Parse the output from the 'mntr' 4letter word command """ + h = StringIO(data) + + result = {} + for line in h.readlines(): + try: + key, value = self._parse_line(line) + result[key] = value + except ValueError: + pass # ignore broken lines + + return result + + def _parse_stat(self, data): + """ Parse the output from the 'stat' 4letter word command """ + global ZK_METRICS, ZK_LAST_METRICS + + h = StringIO(data) + + result = {} + + version = h.readline() + if version: + result['zk_version'] = version[version.index(':')+1:].strip() + + # skip all lines until we find the empty one + while h.readline().strip(): pass + + for line in h.readlines(): + m = re.match('Latency min/avg/max: (\d+)/(\d+)/(\d+)', line) + if m is not None: + result['zk_min_latency'] = int(m.group(1)) + result['zk_avg_latency'] = int(m.group(2)) + result['zk_max_latency'] = int(m.group(3)) + continue + + m = re.match('Received: (\d+)', line) + if m is not None: + cur_packets = int(m.group(1)) + packet_delta = cur_packets - ZK_LAST_METRICS['data'].get('zk_packets_received_total', cur_packets) + time_delta = ZK_METRICS['time'] - ZK_LAST_METRICS['time'] + time_delta = 10.0 + try: + result['zk_packets_received_total'] = cur_packets + result['zk_packets_received'] = packet_delta / float(time_delta) + except ZeroDivisionError: + result['zk_packets_received'] = 0 + continue + + m = re.match('Sent: (\d+)', line) + if m is not None: + cur_packets = int(m.group(1)) + packet_delta = cur_packets - ZK_LAST_METRICS['data'].get('zk_packets_sent_total', cur_packets) + time_delta = ZK_METRICS['time'] - ZK_LAST_METRICS['time'] + try: + result['zk_packets_sent_total'] = cur_packets + result['zk_packets_sent'] = packet_delta / float(time_delta) + except ZeroDivisionError: + result['zk_packets_sent'] = 0 + continue + + m = re.match('Outstanding: (\d+)', line) + if m is not None: + result['zk_outstanding_requests'] = int(m.group(1)) + continue + + m = re.match('Mode: (.*)', line) + if m is not None: + result['zk_server_state'] = m.group(1) + continue + + m = re.match('Node count: (\d+)', line) + if m is not None: + result['zk_znode_count'] = int(m.group(1)) + continue + + return result + + def _parse_line(self, line): + try: + key, value = map(str.strip, line.split('\t')) + except ValueError: + raise ValueError('Found invalid line: %s' % line) + + if not key: + raise ValueError('The key is mandatory and should not be empty') + + try: + value = int(value) + except (TypeError, ValueError): + pass + + return key, value + +def metric_handler(name): + if time.time() - ZK_LAST_METRICS['time'] > TIME_BETWEEN_QUERIES: + zk = ZooKeeperServer(metric_handler.host, metric_handler.port, 5) + try: + metric_handler.info = zk.get_stats() + except Exception, e: + print >>sys.stderr, e + metric_handler.info = {} + + return metric_handler.info.get(name, 0) + +def metric_init(params=None): + params = params or {} + + metric_handler.host = params.get('host', 'localhost') + metric_handler.port = int(params.get('port', 2181)) + metric_handler.timestamp = 0 + + metrics = { + 'zk_avg_latency': {'units': 'ms'}, + 'zk_max_latency': {'units': 'ms'}, + 'zk_min_latency': {'units': 'ms'}, + 'zk_packets_received': { + 'units': 'pps', + 'value_type': 'float', + 'format': '%f' + }, + 'zk_packets_sent': { + 'units': 'pps', + 'value_type': 'double', + 'format': '%f' + }, + 'zk_outstanding_requests': {'units': 'connections'}, + 'zk_znode_count': {'units': 'znodes'}, + 'zk_watch_count': {'units': 'watches'}, + 'zk_ephemerals_count': {'units': 'znodes'}, + 'zk_approximate_data_size': {'units': 'bytes'}, + 'zk_open_file_descriptor_count': {'units': 'descriptors'}, + 'zk_max_file_descriptor_count': {'units': 'descriptors'}, + 'zk_followers': {'units': 'nodes'}, + 'zk_synced_followers': {'units': 'nodes'}, + 'zk_pending_syncs': {'units': 'syncs'} + } + metric_handler.descriptors = {} + for name, updates in metrics.iteritems(): + descriptor = { + 'name': name, + 'call_back': metric_handler, + 'time_max': 90, + 'value_type': 'int', + 'units': '', + 'slope': 'both', + 'format': '%d', + 'groups': 'zookeeper', + } + descriptor.update(updates) + metric_handler.descriptors[name] = descriptor + + return metric_handler.descriptors.values() + +def metric_cleanup(): + pass + + +if __name__ == '__main__': + ds = metric_init({'host':'localhost', 'port': '2181'}) + while True: + for d in ds: + print "%s=%s" % (d['name'], metric_handler(d['name'])) + time.sleep(10) + + diff --git a/src/contrib/monitoring/nagios/README.txt b/src/contrib/monitoring/nagios/README.txt new file mode 100644 index 00000000000..317ae14869b --- /dev/null +++ b/src/contrib/monitoring/nagios/README.txt @@ -0,0 +1,86 @@ +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Configuration Recipe for monitoring ZooKeeper using Nagios +---------------------------------------------------------- + +I will start by making the assumption that you already have an working Nagios install. + +WARNING: I have wrote these instructions while installing and configuring the plugin on my desktop computer running Ubuntu 9.10. I've installed Nagios using apt-get. + +WARNING: You should customize the config files as suggested in order to match your Nagios and Zookeeper install. + +WARNING: This README assumes you know how to configure Nagios and how it works. + +WARNING: You should customize the warning and critical levels on service checks to meet your own needs. + +1. Install the plugin + +$ cp check_zookeeper.py /usr/lib/nagios/plugins/ + +2. Install the new commands + +$ cp zookeeper.cfg /etc/nagios-plugins/config + +3. Update the list of servers in zookeeper.cfg for the command 'check_zookeeper' and update the port for the command 'check_zk_node' (default: 2181) + +4. Create a virtual host in Nagios used for monitoring the cluster as a whole -OR- Create a hostgroup named 'zookeeper-servers' and add all the zookeeper cluster nodes. + +5. Define service checks like I have ilustrated bellow or just use the provided definitions. + +define service { + use generic-service + host_name zookeeper-cluster + service_description ... + check_command check_zookeeper!!! +} + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Open_File_Descriptors_Count + check_command check_zk_node!!! +} + +Ex: + +a. check the number of open file descriptors + +define service{ + use generic-service + host_name zookeeper-cluster + service_description ZK_Open_File_Descriptor_Count + check_command check_zookeeper!zk_open_file_descriptor_count!500!800 +} + +b. check the number of ephemerals nodes + +define service { + use generic-service + host_name localhost + service_description ZK_Ephemerals_Count + check_command check_zookeeper!zk_ephemerals_count!10000!100000 +} + +c. check the number of open file descriptors for each host in the group + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Open_File_Descriptors_Count + check_command check_zk_node!zk_open_file_descriptor_count!500!800 +} + diff --git a/src/contrib/monitoring/nagios/Screenshot-1.png b/src/contrib/monitoring/nagios/Screenshot-1.png new file mode 100644 index 00000000000..2dc55c58adc Binary files /dev/null and b/src/contrib/monitoring/nagios/Screenshot-1.png differ diff --git a/src/contrib/monitoring/nagios/Screenshot.png b/src/contrib/monitoring/nagios/Screenshot.png new file mode 100644 index 00000000000..3219fea117b Binary files /dev/null and b/src/contrib/monitoring/nagios/Screenshot.png differ diff --git a/src/contrib/monitoring/nagios/hostgroups.cfg b/src/contrib/monitoring/nagios/hostgroups.cfg new file mode 100644 index 00000000000..ea59a66e874 --- /dev/null +++ b/src/contrib/monitoring/nagios/hostgroups.cfg @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A group containing all the ZooKeeper nodes + +define hostgroup { + hostgroup_name zookeeper-servers + alias ZooKeeper Servers + members localhost +} + + diff --git a/src/contrib/monitoring/nagios/services.cfg b/src/contrib/monitoring/nagios/services.cfg new file mode 100644 index 00000000000..dde6ab75952 --- /dev/null +++ b/src/contrib/monitoring/nagios/services.cfg @@ -0,0 +1,67 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# ZooKeeper Node specific services + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Open_File_Descriptors_Count + check_command check_zk_node!zk_open_file_descriptor_count!500!800 +} + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Ephemerals_Count + check_command check_zk_node!zk_ephemerals_count!10000!100000 +} + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Avg_Latency + check_command check_zk_node!zk_avg_latency!500!1000 +} + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Max_Latency + check_command check_zk_node!zk_max_latency!1000!2000 +} + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Min_Latency + check_command check_zk_node!zk_min_latency!500!1000 +} + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Outstanding_Requests + check_command check_zk_node!zk_outstanding_requests!20!50 +} + +define service { + hostgroup_name zookeeper-servers + use generic-service + service_description ZK_Watch_Count + check_command check_zk_node!zk_watch_count!100!500 +} + diff --git a/src/contrib/monitoring/nagios/zookeeper.cfg b/src/contrib/monitoring/nagios/zookeeper.cfg new file mode 100644 index 00000000000..ed4cfab834f --- /dev/null +++ b/src/contrib/monitoring/nagios/zookeeper.cfg @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 'check_zookeeper' command definition +define command { + command_name check_zookeeper + command_line /usr/lib/nagios/plugins/check_zookeeper.py -s "localhost:2181,localhost:2182,localhost:2183" -o nagios -k '$ARG1$' -w '$ARG2$' -c '$ARG3$' + # ATTENTION: you should update the list of servers defined above +} + +# 'check_zk_node' command definition +define command { + command_name check_zk_node + command_line /usr/lib/nagios/plugins/check_zookeeper.py -s $HOSTADDRESS$:2181 -o nagios -k '$ARG1$' -w '$ARG2$' -c '$ARG3$' + # ATTENTION: you should update the port. default: 2181 +} + diff --git a/src/contrib/monitoring/test.py b/src/contrib/monitoring/test.py new file mode 100755 index 00000000000..3941291fcab --- /dev/null +++ b/src/contrib/monitoring/test.py @@ -0,0 +1,282 @@ +#! /usr/bin/env python +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import socket +import sys + +from StringIO import StringIO + +from check_zookeeper import ZooKeeperServer, NagiosHandler, CactiHandler, GangliaHandler + +ZK_MNTR_OUTPUT = """zk_version\t3.4.0--1, built on 06/19/2010 15:07 GMT +zk_avg_latency\t1 +zk_max_latency\t132 +zk_min_latency\t0 +zk_packets_received\t640 +zk_packets_sent\t639 +zk_outstanding_requests\t0 +zk_server_state\tfollower +zk_znode_count\t4 +zk_watch_count\t0 +zk_ephemerals_count\t0 +zk_approximate_data_size\t27 +zk_open_file_descriptor_count\t22 +zk_max_file_descriptor_count\t1024 +""" + +ZK_MNTR_OUTPUT_WITH_BROKEN_LINES = """zk_version\t3.4.0 +zk_avg_latency\t23 +broken-line + +""" + +ZK_STAT_OUTPUT = """Zookeeper version: 3.3.0-943314, built on 05/11/2010 22:20 GMT +Clients: + /0:0:0:0:0:0:0:1:34564[0](queued=0,recved=1,sent=0) + +Latency min/avg/max: 0/40/121 +Received: 11 +Sent: 10 +Outstanding: 0 +Zxid: 0x700000003 +Mode: follower +Node count: 4 +""" + +class SocketMock(object): + def __init__(self): + self.sent = [] + + def settimeout(self, timeout): + self.timeout = timeout + + def connect(self, address): + self.address = address + + def send(self, data): + self.sent.append(data) + return len(data) + + def recv(self, size): + return ZK_MNTR_OUTPUT[:size] + + def close(self): pass + +class ZK33xSocketMock(SocketMock): + def __init__(self): + SocketMock.__init__(self) + self.got_stat_cmd = False + + def recv(self, size): + if 'stat' in self.sent: + return ZK_STAT_OUTPUT[:size] + else: + return '' + +class UnableToConnectSocketMock(SocketMock): + def connect(self, _): + raise socket.error('[Errno 111] Connection refused') + +def create_server_mock(socket_class): + class ZooKeeperServerMock(ZooKeeperServer): + def _create_socket(self): + return socket_class() + return ZooKeeperServerMock() + +class TestCheckZookeeper(unittest.TestCase): + + def setUp(self): + self.zk = ZooKeeperServer() + + def test_parse_valid_line(self): + key, value = self.zk._parse_line('something\t5') + + self.assertEqual(key, 'something') + self.assertEqual(value, 5) + + def test_parse_line_raises_exception_on_invalid_output(self): + invalid_lines = ['something', '', 'a\tb\tc', '\t1'] + for line in invalid_lines: + self.assertRaises(ValueError, self.zk._parse_line, line) + + def test_parser_on_valid_output(self): + data = self.zk._parse(ZK_MNTR_OUTPUT) + + self.assertEqual(len(data), 14) + self.assertEqual(data['zk_znode_count'], 4) + + def test_parse_should_ignore_invalid_lines(self): + data = self.zk._parse(ZK_MNTR_OUTPUT_WITH_BROKEN_LINES) + + self.assertEqual(len(data), 2) + + def test_parse_stat_valid_output(self): + data = self.zk._parse_stat(ZK_STAT_OUTPUT) + + result = { + 'zk_version' : '3.3.0-943314, built on 05/11/2010 22:20 GMT', + 'zk_min_latency' : 0, + 'zk_avg_latency' : 40, + 'zk_max_latency' : 121, + 'zk_packets_received': 11, + 'zk_packets_sent': 10, + 'zk_server_state': 'follower', + 'zk_znode_count': 4 + } + for k, v in result.iteritems(): + self.assertEqual(v, data[k]) + + def test_recv_valid_output(self): + zk = create_server_mock(SocketMock) + + data = zk.get_stats() + self.assertEqual(len(data), 14) + self.assertEqual(data['zk_znode_count'], 4) + + def test_socket_unable_to_connect(self): + zk = create_server_mock(UnableToConnectSocketMock) + + self.assertRaises(socket.error, zk.get_stats) + + def test_use_stat_cmd_if_mntr_is_not_available(self): + zk = create_server_mock(ZK33xSocketMock) + + data = zk.get_stats() + self.assertEqual(data['zk_version'], '3.3.0-943314, built on 05/11/2010 22:20 GMT') + +class HandlerTestCase(unittest.TestCase): + + def setUp(self): + try: + sys._stdout + except: + sys._stdout = sys.stdout + + sys.stdout = StringIO() + + def tearDown(self): + sys.stdout = sys._stdout + + def output(self): + sys.stdout.seek(0) + return sys.stdout.read() + + +class TestNagiosHandler(HandlerTestCase): + + def _analyze(self, w, c, k, stats): + class Opts(object): + warning = w + critical = c + key = k + + return NagiosHandler().analyze(Opts(), {'localhost:2181':stats}) + + def test_ok_status(self): + r = self._analyze(10, 20, 'a', {'a': 5}) + + self.assertEqual(r, 0) + self.assertEqual(self.output(), 'Ok "a"!|localhost:2181=5;10;20\n') + + r = self._analyze(20, 10, 'a', {'a': 30}) + self.assertEqual(r, 0) + + def test_warning_status(self): + r = self._analyze(10, 20, 'a', {'a': 15}) + self.assertEqual(r, 1) + self.assertEqual(self.output(), + 'Warning "a" localhost:2181!|localhost:2181=15;10;20\n') + + r = self._analyze(20, 10, 'a', {'a': 15}) + self.assertEqual(r, 1) + + def test_critical_status(self): + r = self._analyze(10, 20, 'a', {'a': 30}) + self.assertEqual(r, 2) + self.assertEqual(self.output(), + 'Critical "a" localhost:2181!|localhost:2181=30;10;20\n') + + r = self._analyze(20, 10, 'a', {'a': 5}) + self.assertEqual(r, 2) + + def test_check_a_specific_key_on_all_hosts(self): + class Opts(object): + warning = 10 + critical = 20 + key = 'latency' + + r = NagiosHandler().analyze(Opts(), { + 's1:2181': {'latency': 5}, + 's2:2181': {'latency': 15}, + 's3:2181': {'latency': 35}, + }) + self.assertEqual(r, 2) + self.assertEqual(self.output(), + 'Critical "latency" s3:2181!|s1:2181=5;10;20 '\ + 's3:2181=35;10;20 s2:2181=15;10;20\n') + +class TestCactiHandler(HandlerTestCase): + class Opts(object): + key = 'a' + leader = False + + def __init__(self, leader=False): + self.leader = leader + + def test_output_values_for_all_hosts(self): + r = CactiHandler().analyze(TestCactiHandler.Opts(), { + 's1:2181':{'a':1}, + 's2:2181':{'a':2, 'b':3} + }) + self.assertEqual(r, None) + self.assertEqual(self.output(), 's1_2181:1 s2_2181:2') + + def test_output_single_value_for_leader(self): + r = CactiHandler().analyze(TestCactiHandler.Opts(leader=True), { + 's1:2181': {'a':1, 'zk_server_state': 'leader'}, + 's2:2181': {'a':2} + }) + self.assertEqual(r, 0) + self.assertEqual(self.output(), '1\n') + + +class TestGangliaHandler(unittest.TestCase): + + class TestableGangliaHandler(GangliaHandler): + def __init__(self): + GangliaHandler.__init__(self) + self.cli_calls = [] + + def call(self, cli): + self.cli_calls.append(' '.join(cli)) + + def test_send_single_metric(self): + class Opts(object): + @property + def gmetric(self): return '/usr/bin/gmetric' + opts = Opts() + + h = TestGangliaHandler.TestableGangliaHandler() + h.analyze(opts, {'localhost:2181':{'latency':10}}) + + cmd = "%s -n latency -v 10 -t uint32" % opts.gmetric + assert cmd in h.cli_calls + +if __name__ == '__main__': + unittest.main() + diff --git a/src/contrib/rest/NOTICE.txt b/src/contrib/rest/NOTICE.txt new file mode 100644 index 00000000000..2a92254421e --- /dev/null +++ b/src/contrib/rest/NOTICE.txt @@ -0,0 +1,7 @@ +This contrib module includes software developed under the +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + +This contrib depends on binary only jar libraries developed at: + +https://jersey.dev.java.net/ +https://grizzly.dev.java.net/ diff --git a/src/contrib/rest/README.txt b/src/contrib/rest/README.txt new file mode 100644 index 00000000000..30f2e5d192e --- /dev/null +++ b/src/contrib/rest/README.txt @@ -0,0 +1,72 @@ + +ZooKeeper REST implementation using Jersey JAX-RS. +-------------------------------------------------- + +This is an implementation of version 2 of the ZooKeeper REST spec. + +Note: This interface is currently experimental, may change at any time, +etc... In general you should be using the Java/C client bindings to access +the ZooKeeper server. + +This REST ZooKeeper gateway is useful because most of the languages +have built-in support for working with HTTP based protocols. + +See SPEC.txt for details on the REST binding. + +Quickstart: +----------- + +1) start a zookeeper server on localhost port 2181 + +2) run "ant run" + +3) use a REST client to access the data (see below for more details) + + curl http://localhost:9998/znodes/v1/ + +or use the provided src/python scripts + + zk_dump_tree.py + + +Tests: +---------- + +1) the full testsuite can be run via "ant test" target +2) the python client library also contains a test suite + +Examples Using CURL +------------------- + +First review the spec SPEC.txt in this directory. + +#get the root node data +curl http://localhost:9998/znodes/v1/ + +#get children of the root node +curl http://localhost:9998/znodes/v1/?view=children + +#get "/cluster1/leader" as xml (default is json) +curl -H'Accept: application/xml' http://localhost:9998/znodes/v1/cluster1/leader + +#get the data as text +curl -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/cluster1/leader?dataformat=utf8" + +#set a node (data.txt contains the ascii text you want to set on the node) +curl -T data.txt -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/cluster1/leader?dataformat=utf8" + +#create a node +curl -d "data1" -H'Content-Type: application/octet-stream' -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/?op=create&name=cluster2&dataformat=utf8" + +curl -d "data2" -H'Content-Type: application/octet-stream' -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/cluster2?op=create&name=leader&dataformat=utf8" + +#create a new session +curl -d "" -H'Content-Type: application/octet-stream' -w "\n%{http_code}\n" "http://localhost:9998/sessions/v1/?op=create&expire=10" + +#session heartbeat +curl -X "PUT" -H'Content-Type: application/octet-stream' -w "\n%{http_code}\n" "http://localhost:9998/sessions/v1/02dfdcc8-8667-4e53-a6f8-ca5c2b495a72" + +#delete a session +curl -X "DELETE" -H'Content-Type: application/octet-stream' -w "\n%{http_code}\n" "http://localhost:9998/sessions/v1/02dfdcc8-8667-4e53-a6f8-ca5c2b495a72" + + diff --git a/src/contrib/rest/SPEC.txt b/src/contrib/rest/SPEC.txt new file mode 100644 index 00000000000..8c5f70175a6 --- /dev/null +++ b/src/contrib/rest/SPEC.txt @@ -0,0 +1,355 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +A REST HTTP gateway for ZooKeeper +================================= + +Specification Version: 2 + +ZooKeeper is meant to enable distributed coordination and also store +system configuration and other relatively small amounts of information +that must be stored in a persistent and consistent manner. The +information stored in ZooKeeper is meant to be highly available to a +large number of nodes in a distributed-computing cluster. + +ZooKeeper offers a client-side library that supports rich semantics +that include strict ordering guarantees on operations, the creation of +ephemeral znodes, and the ability to watch for changes to state. +However, where clients need simple "CRUD" (create, read, update, +delete) operations, the ZooKeeper libraries can be cumbersome, both to +the programmers who have to use them (who are increasingly used to +REST-style APIs), and to the operators who have to deploy and update +them (for whom deploying and updating client libraries can be very +painful). + +It turns out that most languages comes with client libraries for HTTP +that are easy and familiar to program against, and deployed as part of +the language runtime. Thus, for simple CRUD clients, an HTTP gateway +would be a less cumbersome interface than the ZooKeeper library. + +This document describes a gatway for using HTTP to interact with a +ZooKeeper repository. + +Binding ZooKeeper to HTTP +------------------------- + +Encoding +-------- + +UTF-8 unless otherwise noted + +Paths +----- + +A ZooKeeper paths are mapped to IRIs and URIs as follows. ZK paths +are converted to IRIs by simply percent-encoding any characters in the +ZK path that are not allowed in IRI paths. ZK paths are converted to +URIs by mapping them first to IRIs, then converting to URIs in the +standard way. + +Going from URIs and IRIs is the reverse of the above but for one +difference: any "." and ".." segments in an IRI or URI must be folded +before conversion. (Fortunately, ZK does not allow "." and ".." +segments in its paths.) + +ZK and IRIs recommend the same practices when it comes to Unicode +normalization: ultimately, normalization is left to application +designers, but both recommend that application designers use NFC as a +best practice. + +Root +---- + +The following examples assume that the ZooKeeper znode heirarchy is +bound to the root of the HTTP servers namespace. This may not be the +case in practice however, the gateway may bind to some prefix, for +example the URL for accessing /a/b/c may be: + + http://localhost/zookeeper/znodes/v1/a/b/c + +This is perfectly valid. Users of the REST service should be aware of +this fact and code their clients to support any root (in this case +"/zookeeper" on the server localhost). + + +Basics: GET, PUT, HEAD, and DELETE +---------------------------------- + +HTTP's GET, PUT, HEAD, and DELETE operations map naturally to +ZooKeeper's "get," "set," "exists," and "delete" operations. + +ZooKeeper znodes have a version number that changes each time the +znode's value is updated. This number is returned by "get," "set," and +"exists" operations. The "set" and "delete" operations optionally take +a version number. If one is supplied, then "set" or "delete" will fail +if the current version of the znode doesn't match the version-number +supplied in the call. This mechanism supports atomic read-modify-write +cycles. Set/delete requests may include an optional parameter +"version" which defaults to no version check. + + +Getting ZooKeeper children +-------------------------- + +We overload the GET method to return the children of a ZooKeeper. In +particular, the GET method takes an optional parameter "view" which +could be set to one of type values, either "data" or "children". The +default is "data". Thus, to get the children of a znode named +"/a/b/c", then the GET request should start: + + GET /znodes/v1/a/b/c?view=children HTTP/1.1 + +If the requested view is "data", then the data of a znode is returned +as described in the previous section. If the requested view is +"children", then a list of children is returned in either an XML +document, or in a JSON object. (The default is JSON, but this can be +controlled changed by setting the Accept header.) + + +Creating a ZooKeeper session +---------------------------- + +In order to be able to create ephemeral nodes you first need to start +a new session. + + POST /sessions/v1?op=create&expire= HTTP/1.1 + +If the session creation is successful, then a 201 code will be returned. + +A session is just an UUID that you can pass around as a parameter and +the REST server will foward your request on the attached persistent +connection. + +Keeping a session alive +----------------------- + +To keep a session alive you must send hearbeat requests: + + PUT /sessions/v1/ HTTP/1.1 + +Closing a ZooKeeper session +--------------------------- + +You can close a connection by sending a DELETE request. + + DELETE /sessions/v1/ HTTP/1.1 + +If you don't close a session it will automatically expire after +the amount of time you specified on creation. + +Creating a ZooKeeper znode +-------------------------- + +We use the POST method to create a ZooKeeper znode. For example, to +create a znode named "c" under a parent named "/a/b", then the POST +request should start: + + POST /znodes/v1/a/b?op=create&name=c HTTP/1.1 + +If the creation is successful, then a 201 code will be returned. If +it fails, then a number of different codes might be returned +(documented in a later subsection). + +ZooKeeper's create operation has a flag that tells the server to +append a sequence-number to the client-supplied znode-name in order to +make the znode-name unique. If you set this flag and ask to create a +znode named "/a/b/c", and a znode named "/a/b" already exists, then +"create" will create a znode named "/a/b/c-#" instead, where "#" is and +integer required to generate a unique name in for format %10d. + +To obtain this behavior, an additional "sequence=true" parameter +should be added to the parameters of the POST. (Note that "sequence" +is an optional parameter, that defaults to "false"; this default may +be provided explicitly if desired.) + +On success the actual path of the created znode will be returned. + +If you want to create an ephemeral node you need to specify an +additional "ephemeral=true" parameter. (Note that "ephemeral" is an optional +parameter, that defaults to "false") + +(Note: ZooKeeper also allows the client to set ACLs for the +newly-created znode. This feature is not currently supported by the +HTTP gateway to ZooKeeper.) + + +Content types and negotiation +----------------------------- + +ZooKeeper REST gateway implementations may support three content-types +for request and response messages: + +* application/octet-stream + + HEAD - returns nothing (note below: status = 204) + GET - returns the znode data as an octet-stream + PUT - send binary data, returns nothing + POST - send binary data, returns the name of the znode + DELETE - returns nothing + + For PUT and HEAD some other content-type (i.e. JSON or XML) must be + used to access the Stat information of a znode. + +* application/json, application/javascript & application/xml + + HEAD - returns nothing + GET - returns a STAT or CHILD structure + PUT - send binary data, returns a STAT structure (sans data field) + POST - send binary data, returns a PATH structure + DELETE - returns nothing + + (structures defined below) + + Results returning DATA may include an optional "dataformat" + parameter which has two possible values; base64 (default) or + utf8. This allows the caller to control the format of returned data + and may simplify usage -- for example cat'ing results to the command + line with something like curl, or accessing a url through a browser. + Care should be exercised however, if utf8 is used on non character + data errors may result. + + "application/javascript" requests may include an optional "callback" + parameter. The response is wrapped in a callback method of your + choice. e.g. appending &callback=foo to your request will result in + a response body of: foo(...). Callbacks may only contain + alphanumeric characters and underscores. + +PATH + path : string + uri: string + + path is the full path to the znode as seen by ZooKeeper + + uri is the full URI of the znode as seen by the REST server, does not + include any query parameters (i.e. it's the path to the REST resource) + +SESSION + id : string UUID + uri : string + +CHILD + PATH + child_uri_template: string + children : [ string* ] + + The children list of strings contains only the name of the child + znodes, not the full path. + + child_uri_template is a template for URI of child znodes as seen by the + REST server. e.g. "http://localhost:9998/znodes/v1/foo/{child}", where + foo is the parent node, and {child} can be substituted with the name + of each child in the children array in order to access that resource. + This template is provided to simplify child access. + +STAT + PATH + encoding : value of "base64" or "utf8" + data : base64 or utf8 encoded string + stat : + czxid : number + mzxid : number + ctime : number + mtime : number + version : number + cversion : number + aversion : number + ephemeralOwner : number + datalength : number + numChildren : number + pzxid : number + + +Error Codes +----------- + +The ZooKeeper gateway uses HTTP response codes as follows: + + * 200 (Success) - ZOK for "get" "set" "delete", "yes" case of "exists" (json/xml) + * 201 (Created) - ZOK for "create" + * 204 (No Content) - ZOK for "yes" case of "exists" (octet) + * 400 (Bad Request) - ZINVALIDACL, ZBADARGUMENTS, version param not a number + * 401 (Unauthorized) - ZAUTHFAILED + * 404 (Not Found) - ZOK for "no" case of "exists;" ZNONODE for "get," "set," and "delete" + * 409 (Conflict) - ZNODEEXISTS, ZNONODE for "create," ZNOTEMPTY, + * 412 (Precondition Failed) - ZBADVERSION + * 415 (Unsupported Media Type) - if content-type of PUT or POST is not "application/octet-stream" + * 500 (Internal Server Error) - Failure in gateway code + * 501 (Not Implemented) - HTTP method other than GET, PUT, HEAD, DELETE + * 502 (Bad Gateway) - All other ZooKeeper error codes + * 503 (Service Unavailable) - ZSESSIONEXPIRED, ZCONNECTIONLOSS, (gateway will try to reestablish the connection, but will not hold the request waiting...) + * 504 (Gateway Timeout) - ZOPERATIONTIMEOUT, or ZooKeeper does not return in a timely manner + +Note that these are the codes used by the HTTP-to-Gateway software +itself. Depending on how this software is configured into a Web +server, the resulting Web Server might behave differently, e.g., it +might do redirection, check other headers, etc. + +Error Messages +-------------- + +Error messages are returned to the caller, format is dependent on the +format requested in the call. + +* application/octet-stream + + A string containing the error message. It should include the request + and information detailing the reason for the error. + +* application/json + + { "request":"GET /a/b/c", "message":"Node doesn't exist" } + +* application/xml + + + + GET /a/b/c + Node doesn't exist + + + +Binding ZooKeeper to an HTTP server +----------------------------------- + +It might be sage to assume that everyone is happy to run an Apache +server, and thus write a "mod_zookeeper" for Apache that works only +for the Apache Web Server. However, different operational +environments prefer different Web Servers, and it would be nice to +support more than one Web server. + +Issues: + + * Configuration. + + * Defining a root: Need to provide a URL alias and associate it + with a server. Need to be able to map different aliases to + different servers (implemented via multiple ZK connections). + + * Sharing connection across multiple processes. + + * Asynchronous. + + * Adaptors. + + * Code re-use. + + +Authentication -- TBD, not currently supported + +...the config file should contain authentication material for the gateway + +...the config file should contain an ACL list to be passed along to "create" + +...would we ever want to authenticate each request to ZooKeeper?... diff --git a/src/contrib/rest/build.xml b/src/contrib/rest/build.xml new file mode 100644 index 00000000000..c1a62c6983b --- /dev/null +++ b/src/contrib/rest/build.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests failed! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/rest/conf/keys/README b/src/contrib/rest/conf/keys/README new file mode 100644 index 00000000000..085810a067b --- /dev/null +++ b/src/contrib/rest/conf/keys/README @@ -0,0 +1,8 @@ + +In order to generate .jks (java keystore files) you need to use keytool. + +The password for the existing .jks is "123456" (without quotes). + +Some tutorials: + - http://www.mobilefish.com/tutorials/java/java_quickguide_keytool.html + diff --git a/src/contrib/rest/conf/keys/rest.cer b/src/contrib/rest/conf/keys/rest.cer new file mode 100644 index 00000000000..13e5aabe562 Binary files /dev/null and b/src/contrib/rest/conf/keys/rest.cer differ diff --git a/src/contrib/rest/conf/keys/rest.jks b/src/contrib/rest/conf/keys/rest.jks new file mode 100644 index 00000000000..539e8be7ba4 Binary files /dev/null and b/src/contrib/rest/conf/keys/rest.jks differ diff --git a/src/contrib/rest/conf/log4j.properties b/src/contrib/rest/conf/log4j.properties new file mode 100644 index 00000000000..95efea9d138 --- /dev/null +++ b/src/contrib/rest/conf/log4j.properties @@ -0,0 +1,60 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# +# ZooKeeper Logging Configuration +# +# Format is " (, )+ +# DEFAULT: console appender only +log4j.rootLogger=INFO, CONSOLE +# Example with rolling log file +#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE +# Example with rolling log file and tracing +#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE +# +# Log INFO level and above messages to the console +# +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Threshold=INFO +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n +# +# Add ROLLINGFILE to rootLogger to get log file output +# Log DEBUG level and above messages to a log file +log4j.appender.ROLLINGFILE=org.apache.log4j.ConsoleAppender +log4j.appender.ROLLINGFILE.Threshold=DEBUG +log4j.appender.ROLLINGFILE.File=bookkeeper.log +log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout +log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n +# Max log file size of 10MB +log4j.appender.ROLLINGFILE.MaxFileSize=10MB +# uncomment the next line to limit number of backup files +#log4j.appender.ROLLINGFILE.MaxBackupIndex=10 +log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout +log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n +# +# Add TRACEFILE to rootLogger to get log file output +# Log DEBUG level and above messages to a log file +log4j.appender.TRACEFILE=org.apache.log4j.FileAppender +log4j.appender.TRACEFILE.Threshold=TRACE +log4j.appender.TRACEFILE.File=bookkeeper_trace.log +log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout +### Notice we are including log4j's NDC here (%x) +log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L][%x] - %m%n diff --git a/src/contrib/rest/conf/rest.properties b/src/contrib/rest/conf/rest.properties new file mode 100644 index 00000000000..94996725045 --- /dev/null +++ b/src/contrib/rest/conf/rest.properties @@ -0,0 +1,55 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# +# ZooKeeper REST Gateway Configuration file +# +rest.port=9998 +# +# Endpoint definition +# +# plain configuration ; +rest.endpoint.1=/;localhost:2181,localhost:2182 +# ... or chrooted to /zookeeper +# rest.endpoint.1 = /;localhost:2181,localhost:2182/zookeeper +# HTTP Basic authentication for this endpoint +# rest.endpoint.1.http.auth = root:root1 +# create -e /a data digest:'demo:ojnHEyje6F33LLzGVzg+yatf4Fc=':cdrwa +# any session on this endpoint will use authentication +# rest.endpoint.1.zk.digest = demo:test +# you can easily generate the ACL using Python: +# import sha; sha.sha('demo:test').digest().encode('base64').strip() +# +# ... you can define as many endpoints as you wish +# +# rest.endpoint.2 = /restricted;localhost:2181 +# rest.endpoint.2.http.auth = admin:pass +# rest.endpoint.3 = /cluster1;localhost:2181,localhost:2182 +# ** you should configure one end-point for each ZooKeeper cluster +# etc. +# Global HTTP Basic Authentication +# You should also enable HTTPS-only access +# The authentication credentials are sent as plain text +# rest.http.auth = guest:guest1 +# Uncomment the lines bellow to allow https-only access +# rest.ssl = true +# rest.ssl.jks = keys/rest.jks +# rest.ssl.jks.pass = 123456 + \ No newline at end of file diff --git a/src/contrib/rest/ivy.xml b/src/contrib/rest/ivy.xml new file mode 100644 index 00000000000..6db5aa91d8f --- /dev/null +++ b/src/contrib/rest/ivy.xml @@ -0,0 +1,48 @@ + + + + + + + + ZooKeeper REST + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/rest/rest.sh b/src/contrib/rest/rest.sh new file mode 100644 index 00000000000..daa819836e2 --- /dev/null +++ b/src/contrib/rest/rest.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# If this scripted is run out of /usr/bin or some other system bin directory +# it should be linked to and not copied. Things like java jar files are found +# relative to the canonical path of this script. +# + +# Only follow symlinks if readlink supports it +if readlink -f "$0" > /dev/null 2>&1 +then + ZKREST=`readlink -f "$0"` +else + ZKREST="$0" +fi +ZKREST_HOME=`dirname "$ZKREST"` + +if $cygwin +then + # cygwin has a "kill" in the shell itself, gets confused + KILL=/bin/kill +else + KILL=kill +fi + +if [ -z $ZKREST_PIDFILE ] + then ZKREST_PIDFILE=$ZKREST_HOME/server.pid +fi + +ZKREST_MAIN=org.apache.zookeeper.server.jersey.RestMain + +ZKREST_CONF=$ZKREST_HOME/conf +ZKREST_LOG=$ZKREST_HOME/zkrest.log + +CLASSPATH="$ZKREST_CONF:$CLASSPATH" + +for i in "$ZKREST_HOME"/lib/*.jar +do + CLASSPATH="$i:$CLASSPATH" +done + +for i in "$ZKREST_HOME"/zookeeper-*.jar +do + CLASSPATH="$i:$CLASSPATH" +done + +case $1 in +start) + echo "Starting ZooKeeper REST Gateway ... " + java -cp "$CLASSPATH" $JVMFLAGS $ZKREST_MAIN >$ZKREST_LOG 2>&1 & + /bin/echo -n $! > "$ZKREST_PIDFILE" + echo STARTED + ;; +stop) + echo "Stopping ZooKeeper REST Gateway ... " + if [ ! -f "$ZKREST_PIDFILE" ] + then + echo "error: could not find file $ZKREST_PIDFILE" + exit 1 + else + $KILL -9 $(cat "$ZKREST_PIDFILE") + rm "$ZKREST_PIDFILE" + echo STOPPED + fi + ;; +restart) + shift + "$0" stop ${@} + sleep 3 + "$0" start ${@} + ;; +*) + echo "Usage: $0 {start|stop|restart}" >&2 + +esac diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/RestMain.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/RestMain.java new file mode 100644 index 00000000000..f01b1a8bd5b --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/RestMain.java @@ -0,0 +1,144 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.grizzly.SSLConfig; +import com.sun.grizzly.http.embed.GrizzlyWebServer; +import com.sun.grizzly.http.servlet.ServletAdapter; +import com.sun.jersey.spi.container.servlet.ServletContainer; + +import org.apache.zookeeper.server.jersey.cfg.Credentials; +import org.apache.zookeeper.server.jersey.cfg.Endpoint; +import org.apache.zookeeper.server.jersey.cfg.RestCfg; +import org.apache.zookeeper.server.jersey.filters.HTTPBasicAuth; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +/** + * Demonstration of how to run the REST service using Grizzly + */ +public class RestMain { + + private static Logger LOG = LoggerFactory.getLogger(RestMain.class); + + private GrizzlyWebServer gws; + private RestCfg cfg; + + public RestMain(RestCfg cfg) { + this.cfg = cfg; + } + + /** + * The entry point for starting the server + * + */ + public static void main(String[] args) throws Exception { + RestCfg cfg = new RestCfg("rest.properties"); + + final RestMain main = new RestMain(cfg); + main.start(); + + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + main.stop(); + System.out.println("Got exit request. Bye."); + } + }); + + printEndpoints(cfg); + System.out.println("Server started."); + } + + private static void printEndpoints(RestCfg cfg) { + int port = cfg.getPort(); + + for (Endpoint e : cfg.getEndpoints()) { + + String context = e.getContext(); + if (context.charAt(context.length() - 1) != '/') { + context += "/"; + } + + System.out.println(String.format( + "Started %s - WADL: http://localhost:%d%sapplication.wadl", + context, port, context)); + } + } + + public void start() throws IOException { + System.out.println("Starting grizzly ..."); + + boolean useSSL = cfg.useSSL(); + gws = new GrizzlyWebServer(cfg.getPort(), "/tmp/23cxv45345/2131xc2/", useSSL); + // BUG: Grizzly needs a doc root if you are going to register multiple adapters + + for (Endpoint e : cfg.getEndpoints()) { + ZooKeeperService.mapContext(e.getContext(), e); + gws.addGrizzlyAdapter(createJerseyAdapter(e), new String[]{e + .getContext()}); + } + + if (useSSL) { + System.out.println("Starting SSL ..."); + String jks = cfg.getJKS("keys/rest.jks"); + String jksPassword = cfg.getJKSPassword(); + + SSLConfig sslConfig = new SSLConfig(); + URL resource = getClass().getClassLoader().getResource(jks); + if (resource == null) { + LOG.error("Unable to find the keystore file: " + jks); + System.exit(2); + } + try { + sslConfig.setKeyStoreFile(new File(resource.toURI()) + .getAbsolutePath()); + } catch (URISyntaxException e1) { + LOG.error("Unable to load keystore: " + jks, e1); + System.exit(2); + } + sslConfig.setKeyStorePass(jksPassword); + gws.setSSLConfig(sslConfig); + } + + gws.start(); + } + + public void stop() { + gws.stop(); + ZooKeeperService.closeAll(); + } + + private ServletAdapter createJerseyAdapter(Endpoint e) { + ServletAdapter jersey = new ServletAdapter(); + + jersey.setServletInstance(new ServletContainer()); + jersey.addInitParameter("com.sun.jersey.config.property.packages", + "org.apache.zookeeper.server.jersey.resources"); + jersey.setContextPath(e.getContext()); + + Credentials c = Credentials.join(e.getCredentials(), cfg + .getCredentials()); + if (!c.isEmpty()) { + jersey.addFilter(new HTTPBasicAuth(c), e.getContext() + + "-basic-auth", null); + } + + return jersey; + } + +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/ZooKeeperService.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/ZooKeeperService.java new file mode 100644 index 00000000000..7dd0466e0b8 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/ZooKeeperService.java @@ -0,0 +1,235 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.jersey.cfg.Endpoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; +import java.util.TreeSet; + +/** + * Singleton which provides JAX-RS resources access to the ZooKeeper client. + * There's a single session for each base uri (so usually just one). + */ +public class ZooKeeperService { + + private static Logger LOG = LoggerFactory.getLogger(ZooKeeperService.class); + + /** Map base uri to ZooKeeper host:port parameters */ + private static Map contextMap = new HashMap(); + + /** Map base uri to ZooKeeper session */ + private static Map zkMap = new HashMap(); + + /** Session timers */ + private static Map zkSessionTimers = new HashMap(); + private static Timer timer = new Timer(); + + /** + * Specify ZooKeeper host:port for a particular context path. The host:port + * string is passed to the ZK client, so this can be formatted with more + * than a single host:port pair. + */ + synchronized public static void mapContext(String contextPath, Endpoint e) { + contextMap.put(contextPath, e); + } + + /** + * Reset timer for a session + */ + synchronized public static void resetTimer(String contextPath, + String session) { + if (session != null) { + String uri = concat(contextPath, session); + + SessionTimerTask t = zkSessionTimers.remove(uri); + t.cancel(); + + zkSessionTimers.put(uri, new SessionTimerTask(t)); + } + } + + /** + * Close the ZooKeeper session and remove it from the internal maps + */ + public static void close(String contextPath) { + close(contextPath, null); + } + + /** + * Close the ZooKeeper session and remove it + */ + synchronized public static void close(String contextPath, String session) { + String uri = concat(contextPath, session); + + TimerTask t = zkSessionTimers.remove(uri); + if (t != null) { + t.cancel(); + } + + ZooKeeper zk = zkMap.remove(uri); + if (zk == null) { + return; + } + try { + zk.close(); + } catch (InterruptedException e) { + LOG.error("Interrupted while closing ZooKeeper connection.", e); + } + } + + /** + * Close all the ZooKeeper sessions and remove them from the internal maps + */ + synchronized public static void closeAll() { + Set sessions = new TreeSet(zkMap.keySet()); + for (String key : sessions) { + close(key); + } + } + + /** + * Is there an active connection for this session? + */ + synchronized public static boolean isConnected(String contextPath, + String session) { + return zkMap.containsKey(concat(contextPath, session)); + } + + /** + * Return a ZooKeeper client not tied to a specific session. + */ + public static ZooKeeper getClient(String contextPath) throws IOException { + return getClient(contextPath, null); + } + + /** + * Return a ZooKeeper client for a session with a default expire time + * + * @throws IOException + */ + public static ZooKeeper getClient(String contextPath, String session) + throws IOException { + return getClient(contextPath, session, 5); + } + + /** + * Return a ZooKeeper client which may or may not be connected, but it will + * not be expired. This method can be called multiple times, the same object + * will be returned except in the case where the session expires (at which + * point a new session will be returned) + */ + synchronized public static ZooKeeper getClient(String contextPath, + String session, int expireTime) throws IOException { + final String connectionId = concat(contextPath, session); + + ZooKeeper zk = zkMap.get(connectionId); + if (zk == null) { + + if (LOG.isInfoEnabled()) { + LOG.info(String.format("creating new " + + "connection for : '%s'", connectionId)); + } + Endpoint e = contextMap.get(contextPath); + zk = new ZooKeeper(e.getHostPort(), 30000, new MyWatcher( + connectionId)); + + for (Map.Entry p : e.getZooKeeperAuthInfo().entrySet()) { + zk.addAuthInfo("digest", String.format("%s:%s", p.getKey(), + p.getValue()).getBytes()); + } + + zkMap.put(connectionId, zk); + + // a session should automatically expire after an amount of time + if (session != null) { + zkSessionTimers.put(connectionId, new SessionTimerTask( + expireTime, session, contextPath, timer)); + } + } + return zk; + } + + private static String concat(String contextPath, String session) { + if (session != null) { + return String.format("%s@%s", contextPath, session); + } + return contextPath; + } + + /** Track the status of the ZooKeeper session */ + private static class MyWatcher implements Watcher { + final String contextPath; + + /** Separate watcher for each base uri */ + public MyWatcher(String contextPath) { + this.contextPath = contextPath; + } + + /** + * Track state - in particular watch for expiration. if it happens for + * re-creation of the ZK client session + */ + synchronized public void process(WatchedEvent event) { + if (event.getState() == KeeperState.Expired) { + close(contextPath); + } + } + } + + /** ZooKeeper session timer */ + private static class SessionTimerTask extends TimerTask { + + private int delay; + private String contextPath, session; + private Timer timer; + + public SessionTimerTask(int delayInSeconds, String session, + String contextPath, Timer timer) { + delay = delayInSeconds * 1000; // convert to milliseconds + this.contextPath = contextPath; + this.session = session; + this.timer = timer; + reset(); + } + + public SessionTimerTask(SessionTimerTask t) { + this(t.delay / 1000, t.session, t.contextPath, t.timer); + } + + @Override + public void run() { + if (LOG.isInfoEnabled()) { + LOG.info(String.format("Session '%s' expired after " + + "'%d' milliseconds.", session, delay)); + } + ZooKeeperService.close(contextPath, session); + } + + public void reset() { + timer.schedule(this, delay); + } + + } + +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Credentials.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Credentials.java new file mode 100644 index 00000000000..910c1197b40 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Credentials.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.cfg; + +import java.util.HashMap; + +public class Credentials extends HashMap { + + public Credentials() { + super(); + } + + public Credentials(String credentials) { + super(); + + if (!credentials.trim().equals("")) { + String[] parts = credentials.split(","); + for (String p : parts) { + String[] userPass = p.split(":"); + put(userPass[0], userPass[1]); + } + } + } + + public static Credentials join(Credentials a, Credentials b) { + Credentials result = new Credentials(); + result.putAll(a); + result.putAll(b); + return result; + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Endpoint.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Endpoint.java new file mode 100644 index 00000000000..57f7bd257ff --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Endpoint.java @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.cfg; + +public class Endpoint { + + private String context; + private HostPortSet hostPort; + private Credentials credentials; + private Credentials zookeeperAuth; + + public Endpoint(String context, String hostPortList) { + this.context = context; + this.hostPort = new HostPortSet(hostPortList); + } + + public String getContext() { + return context; + } + + public String getHostPort() { + return hostPort.toString(); + } + + public Credentials getCredentials() { + return credentials; + } + + public void setCredentials(String c) { + this.credentials = new Credentials(c); + } + + public final Credentials getZooKeeperAuthInfo() { + return zookeeperAuth; + } + + public void setZooKeeperAuthInfo(String digest) { + zookeeperAuth = new Credentials(digest); + } + + @Override + public boolean equals(Object o) { + Endpoint e = (Endpoint) o; + return context.equals(e.context); + } + + @Override + public int hashCode() { + return context.hashCode(); + } + + @Override + public String toString() { + return String.format("", context, hostPort.toString()); + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPort.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPort.java new file mode 100644 index 00000000000..bf7f62ea3d2 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPort.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.cfg; + +public class HostPort { + + private String host; + private int port; + + public HostPort(String hostPort) { + String[] parts = hostPort.split(":"); + host = parts[0]; + port = Integer.parseInt(parts[1]); + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } + + @Override + public boolean equals(Object o) { + HostPort p = (HostPort) o; + return host.equals(p.host) && port == p.port; + } + + @Override + public int hashCode() { + return String.format("%s:%d", host, port).hashCode(); + } + +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPortSet.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPortSet.java new file mode 100644 index 00000000000..adf03552684 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPortSet.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.cfg; + +import java.util.HashSet; +import java.util.Set; + +public class HostPortSet { + + private Set hostPortSet = new HashSet(); + private String original; + + public HostPortSet(String hostPortList) { + original = hostPortList; + + int chrootStart = hostPortList.indexOf('/'); + String hostPortPairs; + if (chrootStart != -1) { + hostPortPairs = hostPortList.substring(0, chrootStart); + } else { + hostPortPairs = hostPortList; + } + + String[] parts = hostPortPairs.split(","); + for (String p : parts) { + hostPortSet.add(new HostPort(p)); + } + } + + @Override + public String toString() { + return original; + } + +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java new file mode 100644 index 00000000000..cd27d2187bc --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java @@ -0,0 +1,103 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.cfg; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +public class RestCfg { + + private Properties cfg = new Properties(); + + private Set endpoints = new HashSet(); + private Credentials credentials = new Credentials(); + + public RestCfg(String resource) throws IOException { + this(RestCfg.class.getClassLoader().getResourceAsStream(resource)); + } + + public RestCfg(InputStream io) throws IOException { + try { + cfg.load(io); + extractEndpoints(); + extractCredentials(); + } finally { + io.close(); + } + } + + private void extractCredentials() { + if (cfg.containsKey("rest.http.auth")) { + credentials = new Credentials(cfg.getProperty("rest.http.auth", "")); + } + } + + private void extractEndpoints() { + int count = 1; + while (true) { + String e = cfg.getProperty( + String.format("rest.endpoint.%d", count), null); + if (e == null) { + break; + } + + String[] parts = e.split(";"); + if (parts.length != 2) { + count++; + continue; + } + Endpoint point = new Endpoint(parts[0], parts[1]); + + String c = cfg.getProperty(String.format( + "rest.endpoint.%d.http.auth", count), ""); + point.setCredentials(c); + + String digest = cfg.getProperty(String.format( + "rest.endpoint.%d.zk.digest", count), ""); + point.setZooKeeperAuthInfo(digest); + + endpoints.add(point); + count++; + } + } + + public int getPort() { + return Integer.parseInt(cfg.getProperty("rest.port", "9998")); + } + + public boolean useSSL() { + return Boolean.valueOf(cfg.getProperty("rest.ssl", "false")); + } + + public final Set getEndpoints() { + return endpoints; + } + + public final Credentials getCredentials() { + return credentials; + } + + public String getJKS() { + return cfg.getProperty("rest.ssl.jks"); + } + + public String getJKS(String def) { + return cfg.getProperty("rest.ssl.jks", def); + } + + public String getJKSPassword() { + return cfg.getProperty("rest.ssl.jks.pass"); + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/filters/HTTPBasicAuth.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/filters/HTTPBasicAuth.java new file mode 100644 index 00000000000..ff714d7af7e --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/filters/HTTPBasicAuth.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.filters; + +import com.sun.jersey.core.util.Base64; + +import org.apache.zookeeper.server.jersey.cfg.Credentials; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class HTTPBasicAuth implements Filter { + + private Credentials credentials; + + public HTTPBasicAuth(Credentials c) { + credentials = c; + } + + @Override + public void doFilter(ServletRequest req0, ServletResponse resp0, + FilterChain chain) throws IOException, ServletException { + + HttpServletRequest request = (HttpServletRequest) req0; + HttpServletResponse response = (HttpServletResponse) resp0; + + String authorization = request.getHeader("Authorization"); + if (authorization != null) { + String c[] = parseAuthorization(authorization); + if (c != null && credentials.containsKey(c[0]) + && credentials.get(c[0]).equals(c[1])) { + chain.doFilter(request, response); + return; + } + } + + response.setHeader("WWW-Authenticate", "Basic realm=\"Restricted\""); + response.sendError(401); + } + + private String[] parseAuthorization(String authorization) { + String parts[] = authorization.split(" "); + if (parts.length == 2 && parts[0].equalsIgnoreCase("Basic")) { + String userPass = Base64.base64Decode(parts[1]); + + int p = userPass.indexOf(":"); + if (p != -1) { + return new String[]{userPass.substring(0, p), + userPass.substring(p + 1)}; + } + } + return null; + } + + @Override + public void init(FilterConfig arg0) throws ServletException { + } + + @Override + public void destroy() { + } + +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildren.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildren.java new file mode 100644 index 00000000000..88b9c20b1e0 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildren.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.jaxb; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + + +/** + * Represents the CHILD using JAXB. + * Special JSON version is required to get proper formatting in both + * JSON and XML output. See details in ZNodeResource. + */ +@XmlRootElement(name = "child") +public class ZChildren { + public String path; + public String uri; + + public String child_uri_template; + @XmlElementWrapper(name = "children") + @XmlElement(name = "child") + public List children; + + public ZChildren() { + // needed by jersey + children = new ArrayList(); + } + + public ZChildren(String path, String uri, String child_uri_template, + List children) { + this.path = path; + this.uri = uri; + this.child_uri_template = child_uri_template; + if (children != null) { + this.children = children; + } else { + this.children = new ArrayList(); + } + } + + @Override + public int hashCode() { + return path.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ZChildren)) { + return false; + } + ZChildren o = (ZChildren) obj; + return path.equals(o.path) && children.equals(o.children); + } + + @Override + public String toString() { + return "ZChildren(" + path + "," + children + ")"; + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenJSON.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenJSON.java new file mode 100644 index 00000000000..b7547b15622 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenJSON.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.jaxb; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; + + +/** + * Represents the CHILD using JAXB. + * Special JSON version is required to get proper formatting in both + * JSON and XML output. See details in ZNodeResource. + */ +@XmlRootElement(name = "child") +public class ZChildrenJSON { + public String path; + public String uri; + + public String child_uri_template; + public List children; + + public ZChildrenJSON() { + // needed by jersey + children = new ArrayList(); + } + + public ZChildrenJSON(String path, String uri, String child_uri_template, + List children) { + this.path = path; + this.uri = uri; + this.child_uri_template = child_uri_template; + if (children != null) { + this.children = children; + } else { + this.children = new ArrayList(); + } + } + + @Override + public int hashCode() { + return path.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ZChildrenJSON)) { + return false; + } + ZChildrenJSON o = (ZChildrenJSON) obj; + return path.equals(o.path) && children.equals(o.children); + } + + @Override + public String toString() { + return "ZChildrenJSON(" + path + "," + children + ")"; + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZError.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZError.java new file mode 100644 index 00000000000..519f2893eba --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZError.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.jaxb; + +import javax.xml.bind.annotation.XmlRootElement; + + +/** + * Represents an ERROR using JAXB. + */ +@XmlRootElement(name = "error") +public class ZError { + public String request; + public String message; + + public ZError() { + // needed by jersey + } + + public ZError(String request, String message) { + this.request = request; + this.message = message; + } + +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZPath.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZPath.java new file mode 100644 index 00000000000..e964cc77d36 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZPath.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.jaxb; + +import javax.xml.bind.annotation.XmlRootElement; + + +/** + * Represents a PATH using JAXB. + */ +@XmlRootElement(name = "path") +public class ZPath { + public String path; + public String uri; + + public ZPath() { + // needed by jersey + } + + public ZPath(String path) { + this(path, null); + } + + public ZPath(String path, String uri) { + this.path = path; + this.uri = uri; + } + + @Override + public int hashCode() { + return path.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ZPath)) { + return false; + } + ZPath o = (ZPath) obj; + return path.equals(o.path); + } + + @Override + public String toString() { + return "ZPath(" + path + ")"; + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZSession.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZSession.java new file mode 100644 index 00000000000..fd38b231acb --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZSession.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.jaxb; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "session") +public class ZSession { + public String id; + public String uri; + + public ZSession() { + // needed by jersey + } + + public ZSession(String id, String uri) { + this.id = id; + this.uri = uri; + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ZSession)) { + return false; + } + ZSession s = (ZSession) obj; + return id.equals(s.id); + } + + @Override + public String toString() { + return "ZSession(" + id + ")"; + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZStat.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZStat.java new file mode 100644 index 00000000000..d4b0dc7f691 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZStat.java @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.jaxb; + +import javax.xml.bind.annotation.XmlRootElement; + + +/** + * Represents a STAT using JAXB. + */ +@XmlRootElement(name = "stat") +public class ZStat { + public String path; + public String uri; + public byte[] data64; + public String dataUtf8; + + public long czxid; + public long mzxid; + public long ctime; + public long mtime; + public int version; + public int cversion; + public int aversion; + public long ephemeralOwner; + public int dataLength; + public int numChildren; + public long pzxid; + + + public ZStat() { + // needed by jersey + } + + public ZStat(String path, byte[] data64, String dataUtf8) { + this.path = path; + this.data64 = data64; + this.dataUtf8 = dataUtf8; + } + + public ZStat(String path, String uri, byte[] data64, String dataUtf8, + long czxid, long mzxid, long ctime, long mtime, int version, + int cversion, int aversion, long ephemeralOwner, int dataLength, + int numChildren, long pzxid) { + this.path = path; + this.uri = uri; + this.data64 = data64; + this.dataUtf8 = dataUtf8; + + this.czxid = czxid; + this.mzxid = mzxid; + this.ctime = ctime; + this.mtime = mtime; + this.version = version; + this.cversion = cversion; + this.aversion = aversion; + this.ephemeralOwner = ephemeralOwner; + this.dataLength = dataLength; + this.numChildren = numChildren; + this.pzxid = pzxid; + } + + @Override + public int hashCode() { + return path.hashCode(); + } + + /** + * This method considers two ZStats equal if their path, encoding, and + * data match. It does not compare the ZooKeeper + * org.apache.zookeeper.data.Stat class fields. + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ZStat)) { + return false; + } + ZStat o = (ZStat) obj; + return toString().equals(o.toString()); + } + + @Override + public String toString() { + return "ZStat(" + path + "," + "b64[" + + (data64 == null ? null : new String(data64)) + "]," + + dataUtf8 + ")"; + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/JAXBContextResolver.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/JAXBContextResolver.java new file mode 100644 index 00000000000..3920969b15a --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/JAXBContextResolver.java @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.resources; + +import com.sun.jersey.api.json.JSONConfiguration; +import com.sun.jersey.api.json.JSONJAXBContext; + +import org.apache.zookeeper.server.jersey.jaxb.ZChildrenJSON; +import org.apache.zookeeper.server.jersey.jaxb.ZPath; +import org.apache.zookeeper.server.jersey.jaxb.ZStat; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; +import javax.xml.bind.JAXBContext; + +/** + * Tell Jersey how to resolve JSON formatting. Specifically detail the + * fields which are arrays and which are numbers (not strings). + */ +@Provider +@SuppressWarnings("unchecked") +public final class JAXBContextResolver implements ContextResolver { + private final JAXBContext context; + + private final Set typesSet; + + public JAXBContextResolver() throws Exception { + Class[] typesArr = + new Class[]{ZPath.class, ZStat.class, ZChildrenJSON.class}; + typesSet = new HashSet(Arrays.asList(typesArr)); + context = new JSONJAXBContext( + JSONConfiguration.mapped() + .arrays("children") + .nonStrings("czxid") + .nonStrings("mzxid") + .nonStrings("ctime") + .nonStrings("mtime") + .nonStrings("version") + .nonStrings("cversion") + .nonStrings("aversion") + .nonStrings("ephemeralOwner") + .nonStrings("dataLength") + .nonStrings("numChildren") + .nonStrings("pzxid") + .build(), + typesArr); + } + + public JAXBContext getContext(Class objectType) { + return (typesSet.contains(objectType)) ? context : null; + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/KeeperExceptionMapper.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/KeeperExceptionMapper.java new file mode 100644 index 00000000000..0ff2dc23207 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/KeeperExceptionMapper.java @@ -0,0 +1,79 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.resources; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.server.jersey.jaxb.ZError; + +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + + +/** + * Map KeeperException to HTTP status codes + */ +@Provider +public class KeeperExceptionMapper implements ExceptionMapper { + private UriInfo ui; + + public KeeperExceptionMapper(@Context UriInfo ui) { + this.ui = ui; + } + + public Response toResponse(KeeperException e) { + Response.Status status; + String message; + + String path = e.getPath(); + + switch (e.code()) { + case AUTHFAILED: + status = Response.Status.UNAUTHORIZED; + message = path + " not authorized"; + break; + case BADARGUMENTS: + status = Response.Status.BAD_REQUEST; + message = path + " bad arguments"; + break; + case BADVERSION: + status = Response.Status.PRECONDITION_FAILED; + message = path + " bad version"; + break; + case INVALIDACL: + status = Response.Status.BAD_REQUEST; + message = path + " invalid acl"; + break; + case NODEEXISTS: + status = Response.Status.CONFLICT; + message = path + " already exists"; + break; + case NONODE: + status = Response.Status.NOT_FOUND; + message = path + " not found"; + break; + case NOTEMPTY: + status = Response.Status.CONFLICT; + message = path + " not empty"; + break; + default: + status = Response.Status.fromStatusCode(502); // bad gateway + message = "Error processing request for " + path + + " : " + e.getMessage(); + } + + return Response.status(status).entity( + new ZError(ui.getRequestUri().toString(), message)).build(); + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java new file mode 100644 index 00000000000..d45cb3eb7a6 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.resources; + +import org.apache.zookeeper.server.jersey.jaxb.ZError; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +/** + * Map RuntimeException to HTTP status codes + */ +@Provider +public class RuntimeExceptionMapper + implements ExceptionMapper { + private UriInfo ui; + + public RuntimeExceptionMapper(@Context UriInfo ui) { + this.ui = ui; + } + + public Response toResponse(RuntimeException e) { + // don't try to handle jersey exceptions ourselves + if (e instanceof WebApplicationException) { + WebApplicationException ie = (WebApplicationException) e; + return ie.getResponse(); + } + + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ZError(ui.getRequestUri().toString(), + "Error processing request due to " + e + )).build(); + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/SessionsResource.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/SessionsResource.java new file mode 100644 index 00000000000..d27564b14d2 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/SessionsResource.java @@ -0,0 +1,128 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.resources; + +import com.sun.jersey.api.json.JSONWithPadding; + +import org.apache.zookeeper.server.jersey.ZooKeeperService; +import org.apache.zookeeper.server.jersey.jaxb.ZError; +import org.apache.zookeeper.server.jersey.jaxb.ZSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URI; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +@Path("sessions/v1/{session: .*}") +public class SessionsResource { + + private static Logger LOG = LoggerFactory.getLogger(SessionsResource.class); + + private String contextPath; + + public SessionsResource(@Context HttpServletRequest request) { + contextPath = request.getContextPath(); + if (contextPath.equals("")) { + contextPath = "/"; + } + } + + private static void throwNotFound(String session, UriInfo ui) + throws WebApplicationException { + throw new WebApplicationException(Response.status( + Response.Status.NOT_FOUND).entity( + new ZError(ui.getRequestUri().toString(), session + + " not found")).build()); + } + + @PUT + @Produces({MediaType.APPLICATION_JSON, "application/javascript", + MediaType.APPLICATION_XML}) + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + public Response keepAliveSession(@PathParam("session") String session, + @Context UriInfo ui, byte[] data) { + + if (!ZooKeeperService.isConnected(contextPath, session)) { + throwNotFound(session, ui); + } + + ZooKeeperService.resetTimer(contextPath, session); + return Response.status(Response.Status.OK).build(); + } + + @POST + @Produces({MediaType.APPLICATION_JSON, "application/javascript", + MediaType.APPLICATION_XML}) + public Response createSession(@QueryParam("op") String op, + @DefaultValue("5") @QueryParam("expire") String expire, + @Context UriInfo ui) { + if (!op.equals("create")) { + throw new WebApplicationException(Response.status( + Response.Status.BAD_REQUEST).entity( + new ZError(ui.getRequestUri().toString(), "")).build()); + } + + int expireInSeconds; + try { + expireInSeconds = Integer.parseInt(expire); + } catch (NumberFormatException e) { + throw new WebApplicationException(Response.status( + Response.Status.BAD_REQUEST).build()); + } + + String uuid = UUID.randomUUID().toString(); + while (ZooKeeperService.isConnected(contextPath, uuid)) { + uuid = UUID.randomUUID().toString(); + } + + // establish the connection to the ZooKeeper cluster + try { + ZooKeeperService.getClient(contextPath, uuid, expireInSeconds); + } catch (IOException e) { + LOG.error("Failed while trying to create a new session", e); + + throw new WebApplicationException(Response.status( + Response.Status.INTERNAL_SERVER_ERROR).build()); + } + + URI uri = ui.getAbsolutePathBuilder().path(uuid).build(); + return Response.created(uri).entity( + new JSONWithPadding(new ZSession(uuid, uri.toString()))) + .build(); + } + + @DELETE + @Produces({MediaType.APPLICATION_JSON, "application/javascript", + MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM}) + public void deleteSession(@PathParam("session") String session, + @Context UriInfo ui) { + ZooKeeperService.close(contextPath, session); + } + +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZErrorWriter.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZErrorWriter.java new file mode 100644 index 00000000000..633ca9b5979 --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZErrorWriter.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.resources; + +import org.apache.zookeeper.server.jersey.jaxb.ZError; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; + +/** + * Tell Jersey how to format an octet response error message. + */ +@Produces(MediaType.APPLICATION_OCTET_STREAM) +@Provider +public class ZErrorWriter implements MessageBodyWriter { + + public long getSize(ZError t, Class type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return -1; + } + + public boolean isWriteable(Class type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return ZError.class.isAssignableFrom(type); + } + + public void writeTo(ZError t, Class type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, + OutputStream os) + throws IOException, WebApplicationException { + PrintStream p = new PrintStream(os); + p.print("Request " + t.request + " failed due to " + t.message); + p.flush(); + } +} diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java new file mode 100644 index 00000000000..6e0c325465c --- /dev/null +++ b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java @@ -0,0 +1,405 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey.resources; + +import com.sun.jersey.api.json.JSONWithPadding; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.jersey.ZooKeeperService; +import org.apache.zookeeper.server.jersey.jaxb.ZChildren; +import org.apache.zookeeper.server.jersey.jaxb.ZChildrenJSON; +import org.apache.zookeeper.server.jersey.jaxb.ZError; +import org.apache.zookeeper.server.jersey.jaxb.ZPath; +import org.apache.zookeeper.server.jersey.jaxb.ZStat; + +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.HEAD; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +/** + * Version 1 implementation of the ZooKeeper REST specification. + */ +// TODO test octet fully +@Path("znodes/v1{path: /.*}") +public class ZNodeResource { + private final ZooKeeper zk; + + public ZNodeResource(@DefaultValue("") @QueryParam("session") String session, + @Context UriInfo ui, + @Context HttpServletRequest request + ) + throws IOException { + + String contextPath = request.getContextPath(); + if (contextPath.equals("")) { + contextPath = "/"; + } + if (session.equals("")) { + session = null; + } else if (!ZooKeeperService.isConnected(contextPath, session)) { + throw new WebApplicationException(Response.status( + Response.Status.UNAUTHORIZED).build()); + } + zk = ZooKeeperService.getClient(contextPath, session); + } + + private static void throwNotFound(String path, UriInfo ui) + throws WebApplicationException { + throw new WebApplicationException(Response.status( + Response.Status.NOT_FOUND).entity( + new ZError(ui.getRequestUri().toString(), path + " not found")) + .build()); + } + + private void ensurePathNotNull(String path) { + if (path == null) { + throw new IllegalArgumentException("Invalid path \"" + path + "\""); + } + } + + @HEAD + @Produces({MediaType.APPLICATION_JSON, "application/javascript", + MediaType.APPLICATION_XML}) + public Response existsZNode(@PathParam("path") String path, + @Context UriInfo ui) throws InterruptedException, KeeperException { + Stat stat = zk.exists(path, false); + if (stat == null) { + throwNotFound(path, ui); + } + return Response.status(Response.Status.OK).build(); + } + + /* + * getZNodeList and getZNodeListJSON are bogus - but necessary. + * Unfortunately Jersey 1.0.3 is unable to render both xml and json properly + * in the case where a object contains a list/array. It's impossible to get + * it to render properly for both. As a result we need to split into two + * jaxb classes. + */ + + @HEAD + @Produces({MediaType.APPLICATION_OCTET_STREAM}) + public Response existsZNodeAsOctet(@PathParam("path") String path, + @Context UriInfo ui) throws InterruptedException, KeeperException { + Stat stat = zk.exists(path, false); + if (stat == null) { + throwNotFound(path, ui); + } + return Response.status(Response.Status.NO_CONTENT).build(); + } + + @GET + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public Response getZNodeListJSON( + @PathParam("path") String path, + @QueryParam("callback") String callback, + @DefaultValue("data") @QueryParam("view") String view, + @DefaultValue("base64") @QueryParam("dataformat") String dataformat, + @Context UriInfo ui) throws InterruptedException, KeeperException { + return getZNodeList(true, path, callback, view, dataformat, ui); + } + + @GET + @Produces(MediaType.APPLICATION_XML) + public Response getZNodeList( + @PathParam("path") String path, + @QueryParam("callback") String callback, + @DefaultValue("data") @QueryParam("view") String view, + @DefaultValue("base64") @QueryParam("dataformat") String dataformat, + @Context UriInfo ui) throws InterruptedException, KeeperException { + return getZNodeList(false, path, callback, view, dataformat, ui); + } + + private Response getZNodeList(boolean json, String path, String callback, + String view, String dataformat, UriInfo ui) + throws InterruptedException, KeeperException { + ensurePathNotNull(path); + + if (view.equals("children")) { + List children = new ArrayList(); + for (String child : zk.getChildren(path, false)) { + children.add(child); + } + + Object child; + String childTemplate = ui.getAbsolutePath().toString(); + if (!childTemplate.endsWith("/")) { + childTemplate += "/"; + } + childTemplate += "{child}"; + if (json) { + child = new ZChildrenJSON(path, + ui.getAbsolutePath().toString(), childTemplate, + children); + } else { + child = new ZChildren(path, ui.getAbsolutePath().toString(), + childTemplate, children); + } + return Response.status(Response.Status.OK).entity( + new JSONWithPadding(child, callback)).build(); + } else { + Stat stat = new Stat(); + byte[] data = zk.getData(path, false, stat); + + byte[] data64; + String dataUtf8; + if (data == null) { + data64 = null; + dataUtf8 = null; + } else if (!dataformat.equals("utf8")) { + data64 = data; + dataUtf8 = null; + } else { + data64 = null; + dataUtf8 = new String(data); + } + ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), + data64, dataUtf8, stat.getCzxid(), stat.getMzxid(), stat + .getCtime(), stat.getMtime(), stat.getVersion(), + stat.getCversion(), stat.getAversion(), stat + .getEphemeralOwner(), stat.getDataLength(), stat + .getNumChildren(), stat.getPzxid()); + + return Response.status(Response.Status.OK).entity( + new JSONWithPadding(zstat, callback)).build(); + } + } + + @GET + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response getZNodeListAsOctet(@PathParam("path") String path) + throws InterruptedException, KeeperException { + ensurePathNotNull(path); + + Stat stat = new Stat(); + byte[] data = zk.getData(path, false, stat); + + if (data == null) { + return Response.status(Response.Status.NO_CONTENT).build(); + } else { + return Response.status(Response.Status.OK).entity(data).build(); + } + } + + @PUT + @Produces({MediaType.APPLICATION_JSON, "application/javascript", + MediaType.APPLICATION_XML}) + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + public Response setZNode( + @PathParam("path") String path, + @QueryParam("callback") String callback, + @DefaultValue("-1") @QueryParam("version") String versionParam, + @DefaultValue("base64") @QueryParam("dataformat") String dataformat, + @DefaultValue("false") @QueryParam("null") String setNull, + @Context UriInfo ui, byte[] data) throws InterruptedException, + KeeperException { + ensurePathNotNull(path); + + int version; + try { + version = Integer.parseInt(versionParam); + } catch (NumberFormatException e) { + throw new WebApplicationException(Response.status( + Response.Status.BAD_REQUEST).entity( + new ZError(ui.getRequestUri().toString(), path + + " bad version " + versionParam)).build()); + } + + if (setNull.equals("true")) { + data = null; + } + + Stat stat = zk.setData(path, data, version); + + ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), null, + null, stat.getCzxid(), stat.getMzxid(), stat.getCtime(), stat + .getMtime(), stat.getVersion(), stat.getCversion(), + stat.getAversion(), stat.getEphemeralOwner(), stat + .getDataLength(), stat.getNumChildren(), stat + .getPzxid()); + + return Response.status(Response.Status.OK).entity( + new JSONWithPadding(zstat, callback)).build(); + } + + @PUT + @Produces(MediaType.APPLICATION_OCTET_STREAM) + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + public void setZNodeAsOctet(@PathParam("path") String path, + @DefaultValue("-1") @QueryParam("version") String versionParam, + @DefaultValue("false") @QueryParam("null") String setNull, + @Context UriInfo ui, byte[] data) throws InterruptedException, + KeeperException { + ensurePathNotNull(path); + + int version; + try { + version = Integer.parseInt(versionParam); + } catch (NumberFormatException e) { + throw new WebApplicationException(Response.status( + Response.Status.BAD_REQUEST).entity( + new ZError(ui.getRequestUri().toString(), path + + " bad version " + versionParam)).build()); + } + + if (setNull.equals("true")) { + data = null; + } + + zk.setData(path, data, version); + } + + @POST + @Produces({MediaType.APPLICATION_JSON, "application/javascript", + MediaType.APPLICATION_XML}) + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + public Response createZNode( + @PathParam("path") String path, + @QueryParam("callback") String callback, + @DefaultValue("create") @QueryParam("op") String op, + @QueryParam("name") String name, + @DefaultValue("base64") @QueryParam("dataformat") String dataformat, + @DefaultValue("false") @QueryParam("null") String setNull, + @DefaultValue("false") @QueryParam("sequence") String sequence, + @DefaultValue("false") @QueryParam("ephemeral") String ephemeral, + @Context UriInfo ui, byte[] data) throws InterruptedException, + KeeperException { + ensurePathNotNull(path); + + if (path.equals("/")) { + path += name; + } else { + path += "/" + name; + } + + if (!op.equals("create")) { + throw new WebApplicationException(Response.status( + Response.Status.BAD_REQUEST).entity( + new ZError(ui.getRequestUri().toString(), path + + " bad operaton " + op)).build()); + } + + if (setNull.equals("true")) { + data = null; + } + + CreateMode createMode; + if (sequence.equals("true")) { + if (ephemeral.equals("false")) { + createMode = CreateMode.PERSISTENT_SEQUENTIAL; + } else { + createMode = CreateMode.EPHEMERAL_SEQUENTIAL; + } + } else if (ephemeral.equals("false")) { + createMode = CreateMode.PERSISTENT; + } else { + createMode = CreateMode.EPHEMERAL; + } + + String newPath = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode); + + URI uri = ui.getAbsolutePathBuilder().path(newPath).build(); + + return Response.created(uri).entity( + new JSONWithPadding(new ZPath(newPath, ui.getAbsolutePath() + .toString()))).build(); + } + + @POST + @Produces(MediaType.APPLICATION_OCTET_STREAM) + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + public Response createZNodeAsOctet(@PathParam("path") String path, + @DefaultValue("create") @QueryParam("op") String op, + @QueryParam("name") String name, + @DefaultValue("false") @QueryParam("null") String setNull, + @DefaultValue("false") @QueryParam("sequence") String sequence, + @Context UriInfo ui, byte[] data) throws InterruptedException, + KeeperException { + ensurePathNotNull(path); + + if (path.equals("/")) { + path += name; + } else { + path += "/" + name; + } + + if (!op.equals("create")) { + throw new WebApplicationException(Response.status( + Response.Status.BAD_REQUEST).entity( + new ZError(ui.getRequestUri().toString(), path + + " bad operaton " + op)).build()); + } + + if (setNull.equals("true")) { + data = null; + } + + CreateMode createMode; + if (sequence.equals("true")) { + createMode = CreateMode.PERSISTENT_SEQUENTIAL; + } else { + createMode = CreateMode.PERSISTENT; + } + + String newPath = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode); + + URI uri = ui.getAbsolutePathBuilder().path(newPath).build(); + + return Response.created(uri).entity( + new ZPath(newPath, ui.getAbsolutePath().toString())).build(); + } + + @DELETE + @Produces({MediaType.APPLICATION_JSON, "application/javascript", + MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM}) + public void deleteZNode(@PathParam("path") String path, + @DefaultValue("-1") @QueryParam("version") String versionParam, + @Context UriInfo ui) throws InterruptedException, KeeperException { + ensurePathNotNull(path); + + int version; + try { + version = Integer.parseInt(versionParam); + } catch (NumberFormatException e) { + throw new WebApplicationException(Response.status( + Response.Status.BAD_REQUEST).entity( + new ZError(ui.getRequestUri().toString(), path + + " bad version " + versionParam)).build()); + } + + zk.delete(path, version); + } + +} diff --git a/src/contrib/rest/src/python/README.txt b/src/contrib/rest/src/python/README.txt new file mode 100644 index 00000000000..acc8ffb8e3d --- /dev/null +++ b/src/contrib/rest/src/python/README.txt @@ -0,0 +1,9 @@ +Some basic python scripts which use the REST interface: + +zkrest.py -- basic REST ZooKeeper client +demo_master_election.py -- shows how to implement master election +demo_queue.py -- basic queue +zk_dump_tree.py -- dumps the nodes & data of a znode hierarchy + +Generally these scripts require: + * simplejson diff --git a/src/contrib/rest/src/python/demo_master_election.py b/src/contrib/rest/src/python/demo_master_election.py new file mode 100644 index 00000000000..c0317c7fe86 --- /dev/null +++ b/src/contrib/rest/src/python/demo_master_election.py @@ -0,0 +1,90 @@ +#! /usr/bin/env python + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import threading +import time + +from zkrest import ZooKeeper + +class Agent(threading.Thread): + """ A basic agent that wants to become a master and exit """ + + root = '/election' + + def __init__(self, id): + super(Agent, self).__init__() + self.zk = ZooKeeper() + self.id = id + + def run(self): + print 'Starting #%s' % self.id + with self.zk.session(expire=5): + + # signal agent presence + r = self.zk.create("%s/agent-" % self.root, + sequence=True, ephemeral=True) + self.me = r['path'] + + while True: + children = sorted([el['path'] \ + for el in self.zk.get_children(self.root)]) + master, previous = children[0], None + try: + index = children.index(self.me) + if index != 0: + previous = children[index-1] + except ValueError: + break + + if previous is None: + self.do_master_work() + # and don't forget to send heartbeat messages + break + else: + # do slave work in another thread + pass + + # wait for the previous agent or current master to exit / finish + while self.zk.exists(previous) or self.zk.exists(master): + time.sleep(0.5) + self.zk.heartbeat() + + # TODO signal the slave thread to exit and wait for it + # and rerun the election loop + + def do_master_work(self): + print "#%s: I'm the master: %s" % (self.id, self.me) + +def main(): + zk = ZooKeeper() + + # create the root node used for master election + if not zk.exists('/election'): + zk.create('/election') + + print 'Starting 10 agents ...' + agents = [Agent(id) for id in range(0,15)] + + map(Agent.start, agents) + map(Agent.join, agents) + + zk.delete('/election') + +if __name__ == '__main__': + sys.exit(main()) diff --git a/src/contrib/rest/src/python/demo_queue.py b/src/contrib/rest/src/python/demo_queue.py new file mode 100644 index 00000000000..9ca4c6440cb --- /dev/null +++ b/src/contrib/rest/src/python/demo_queue.py @@ -0,0 +1,99 @@ +#! /usr/bin/env python + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# This is a simple message queue built on top of ZooKeeper. In order +# to be used in production it needs better error handling but it's +# still useful as a proof-of-concept. + +# Why use ZooKeeper as a queue? Highly available by design and has +# great performance. + +import sys +import threading +import time + +from zkrest import ZooKeeper + +class Queue(object): + def __init__(self, root, zk): + self.root = root + + self.zk = zk + + def put(self, data): + self.zk.create("%s/el-" % self.root, str(data), sequence=True, ephemeral=True) + + # creating ephemeral nodes for easy cleanup + # in a real world scenario you should create + # normal sequential znodes + + def fetch(self): + """ Pull an element from the queue + + This function is not blocking if the queue is empty, it will + just return None. + """ + children = sorted(self.zk.get_children(self.root), \ + lambda a, b: cmp(a['path'], b['path'])) + + if not children: + return None + + try: + first = children[0] + self.zk.delete(first['path'], version=first['version']) + if 'data64' not in first: + return '' + else: + return first['data64'].decode('base64') + + except (ZooKeeper.WrongVersion, ZooKeeper.NotFound): + # someone changed the znode between the get and delete + # this should not happen + # in practice you should retry the fetch + raise + + +def main(): + zk = ZooKeeper() + zk.start_session(expire=60) + + if not zk.exists('/queue'): + zk.create('/queue') + q = Queue('/queue', zk) + + print 'Pushing to queue 1 ... 5' + map(q.put, [1,2,3,4,5]) + + print 'Extracting ...' + while True: + el = q.fetch() + if el is None: + break + print el + + zk.close_session() + zk.delete('/queue') + + print 'Done.' + + +if __name__ == '__main__': + sys.exit(main()) + diff --git a/src/contrib/rest/src/python/test.py b/src/contrib/rest/src/python/test.py new file mode 100644 index 00000000000..363747a6431 --- /dev/null +++ b/src/contrib/rest/src/python/test.py @@ -0,0 +1,163 @@ +#! /usr/bin/env python + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import time +import unittest + +from zkrest import ZooKeeper + +class ZooKeeperREST_TestCase(unittest.TestCase): + + BASE_URI = 'http://localhost:9998' + + def setUp(self): + self.zk = ZooKeeper(self.BASE_URI) + + def tearDown(self): + try: + self.zk.delete('/test') + except ZooKeeper.NotFound: + pass + + def test_get_root_node(self): + assert self.zk.get('/') is not None + + def test_get_node_not_found(self): + self.assertRaises(ZooKeeper.NotFound, \ + self.zk.get, '/dummy-node') + + def test_exists_node(self): + assert self.zk.exists('/zookeeper') is True + + def test_get_children(self): + assert any([child['path'] == '/zookeeper/quota' \ + for child in self.zk.get_children('/zookeeper')]) + + def test_create_znode(self): + try: + self.zk.create('/test') + except ZooKeeper.ZNodeExists: + pass # it's ok if already exists + assert self.zk.exists('/test') is True + + def test_create_hierarchy(self): + try: + self.zk.delete(['/a/b', '/a']) + except ZooKeeper.NotFound: + pass + + self.zk.create('/a') + self.zk.create('/a/b') + + self.zk.delete(['/a/b', '/a']) + + def test_create_with_data(self): + self.zk.create('/test', 'some-data') + + zn = self.zk.get('/test') + self.assertEqual(zn.get('data64', None), \ + 'some-data'.encode('base64').strip()) + + def test_delete_znode(self): + self.zk.create('/test') + + self.zk.delete('/test') + assert not self.zk.exists('/test') + + def test_delete_older_version(self): + self.zk.create('/test') + + zn = self.zk.get('/test') + # do one more modification in order to increase the version number + self.zk.set('/test', 'dummy-data') + + self.assertRaises(ZooKeeper.WrongVersion, \ + self.zk.delete, '/test', version=zn['version']) + + def test_delete_raise_not_found(self): + self.zk.create('/test') + + zn = self.zk.get('/test') + self.zk.delete('/test') + + self.assertRaises(ZooKeeper.NotFound, \ + self.zk.delete, '/test', version=zn['version']) + + def test_set(self): + self.zk.create('/test') + + self.zk.set('/test', 'dummy') + + self.assertEqual(self.zk.get('/test')['data64'], \ + 'dummy'.encode('base64').strip()) + + def test_set_with_older_version(self): + if not self.zk.exists('/test'): + self.zk.create('/test', 'random-data') + + zn = self.zk.get('/test') + self.zk.set('/test', 'new-data') + self.assertRaises(ZooKeeper.WrongVersion, self.zk.set, \ + '/test', 'older-version', version=zn['version']) + + def test_set_null(self): + if not self.zk.exists('/test'): + self.zk.create('/test', 'random-data') + self.zk.set('/test', 'data') + assert 'data64' in self.zk.get('/test') + + self.zk.set('/test', null=True) + assert 'data64' not in self.zk.get('/test') + + def test_create_ephemeral_node(self): + with self.zk.session(): + if self.zk.exists('/ephemeral-test'): + self.zk.delete('/ephemeral-test') + + self.zk.create('/ephemeral-test', ephemeral=True) + zn = self.zk.get('/ephemeral-test') + + assert zn['ephemeralOwner'] != 0 + + def test_create_session(self): + with self.zk.session() as sid: + self.assertEqual(len(sid), 36) # UUID + + def test_session_invalidation(self): + self.zk.start_session(expire=1) + self.zk.create('/ephemeral-test', ephemeral=True) + + # keep the session alive by sending heartbeat requests + for _ in range(1,2): + self.zk.heartbeat() + time.sleep(0.9) + + time.sleep(2) # wait for the session to expire + self.assertRaises(ZooKeeper.InvalidSession, \ + self.zk.create, '/ephemeral-test', ephemeral=True) + + def test_presence_signaling(self): + with self.zk.session(expire=1): + self.zk.create('/i-am-online', ephemeral=True) + assert self.zk.exists('/i-am-online') + assert not self.zk.exists('/i-am-online') + + +if __name__ == '__main__': + unittest.main() + diff --git a/src/contrib/rest/src/python/zk_dump_tree.py b/src/contrib/rest/src/python/zk_dump_tree.py new file mode 100755 index 00000000000..517d23b345d --- /dev/null +++ b/src/contrib/rest/src/python/zk_dump_tree.py @@ -0,0 +1,108 @@ +#!/usr/bin/python + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import getopt +import sys +import simplejson +import urllib2 +from base64 import b64decode + +printdata = False +fullpath = False + +def dump_node(url, depth): + """Dump the node, then dump children recursively + + Arguments: + - `url`: + - `depth`: + """ + req = urllib2.urlopen(url) + resp = simplejson.load(req) + if 'Error' in resp: + raise resp['Error'] + + if fullpath: + name = resp['path'] + else: + name = '/' + resp['path'].split('/')[-1] + + data64 = resp.get('data64') + dataUtf8 = resp.get('dataUtf8') + if data64 and printdata: + data = b64decode(data64) + print '%(indent)s%(name)s = b64(%(data64)s) str(%(data)s)' % \ + {'indent':' '*2*depth, 'name':name, 'data64':data64, 'data':data} + elif dataUtf8 and printdata: + print '%(indent)s%(name)s = %(data)s' % \ + {'indent':' '*2*depth, 'name':name, 'data':dataUtf8} + else: + print '%(indent)s%(name)s' % {'indent':' '*2*depth, 'name':name} + + req = urllib2.urlopen(resp['uri'] + '?view=children') + resp = simplejson.load(req) + + for child in resp.get('children', []): + dump_node(resp['child_uri_template'] + .replace("{child}", urllib2.quote(child)), + depth + 1) + +def zk_dump_tree(url, root): + """Dump the tree starting at the roota + + Arguments: + - `root`: + """ + dump_node(url + '/znodes/v1' + root, 0) + +def usage(): + """Usage + """ + print 'Usage: zk_dump_tree.py [-h|--help -u|--url=url -d|--data -f|--fullpath -r|--root=root]' + print ' where url is the url of the rest server, data is whether to' + print ' to include node data on output, root is the znode root' + print ' fullpath prints the full node path (useful for copy/paste)' + +if __name__ == '__main__': + try: + opts, args = getopt.getopt(sys.argv[1:], + "hu:dfr:", ["help", "url=", "data", "fullpath", "root="]) + except getopt.GetoptError, err: + # print help information and exit: + print str(err) # will print something like "option -a not recognized" + usage() + sys.exit(2) + url ='http://localhost:9998' + root = '/' + for o, a in opts: + if o in ("-d", "--data"): + printdata = True + elif o in ("-h", "--help"): + usage() + sys.exit() + elif o in ("-u", "--url"): + url = a + elif o in ("-r", "--root"): + root = a + elif o in ("-f", "--fullpath"): + fullpath = True + else: + assert False, "unhandled option" + + print 'Accessing REST server at ' + url + zk_dump_tree(url, root) diff --git a/src/contrib/rest/src/python/zkrest.py b/src/contrib/rest/src/python/zkrest.py new file mode 100644 index 00000000000..c009d5d9b10 --- /dev/null +++ b/src/contrib/rest/src/python/zkrest.py @@ -0,0 +1,218 @@ + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import urllib2 +import urllib +import simplejson + +from contextlib import contextmanager + +class RequestWithMethod(urllib2.Request): + """ Request class that know how to set the method name """ + def __init__(self, *args, **kwargs): + urllib2.Request.__init__(self, *args, **kwargs) + self._method = None + + def get_method(self): + return self._method or \ + urllib2.Request.get_method(self) + + def set_method(self, method): + self._method = method + +class ZooKeeper(object): + + class Error(Exception): pass + + class NotFound(Error): pass + + class ZNodeExists(Error): pass + + class InvalidSession(Error): pass + + class WrongVersion(Error): pass + + def __init__(self, uri = 'http://localhost:9998'): + self._base = uri + self._session = None + + def start_session(self, expire=5, id=None): + """ Create a session and return the ID """ + if id is None: + url = "%s/sessions/v1/?op=create&expire=%d" % (self._base, expire) + self._session = self._do_post(url)['id'] + else: + self._session = id + return self._session + + def close_session(self): + """ Close the session on the server """ + if self._session is not None: + url = '%s/sessions/v1/%s' % (self._base, self._session) + self._do_delete(url) + self._session = None + + def heartbeat(self): + """ Send a heartbeat request. This is needed in order to keep a session alive """ + if self._session is not None: + url = '%s/sessions/v1/%s' % (self._base, self._session) + self._do_put(url, '') + + @contextmanager + def session(self, *args, **kwargs): + """ Session handling using a context manager """ + yield self.start_session(*args, **kwargs) + self.close_session() + + def get(self, path): + """ Get a node """ + url = "%s/znodes/v1%s" % (self._base, path) + return self._do_get(url) + + def get_children(self, path): + """ Get all the children for a given path. This function creates a generator """ + url = "%s/znodes/v1%s?view=children" % (self._base, path) + resp = self._do_get(url) + for child in resp.get('children', []): + try: + yield self._do_get(resp['child_uri_template']\ + .replace('{child}', urllib2.quote(child))) + except ZooKeeper.NotFound: + continue + + def create(self, path, data=None, sequence=False, ephemeral=False): + """ Create a new node. By default this call creates a persistent znode. + + You can also create an ephemeral or a sequential znode. + """ + ri = path.rindex('/') + head, name = path[:ri+1], path[ri+1:] + if head != '/': head = head[:-1] + + flags = { + 'null': 'true' if data is None else 'false', + 'ephemeral': 'true' if ephemeral else 'false', + 'sequence': 'true' if sequence else 'false' + } + if ephemeral: + if self._session: + flags['session'] = self._session + else: + raise ZooKeeper.Error, 'You need a session '\ + 'to create an ephemeral node' + flags = urllib.urlencode(flags) + + url = "%s/znodes/v1%s?op=create&name=%s&%s" % \ + (self._base, head, name, flags) + + return self._do_post(url, data) + + def set(self, path, data=None, version=-1, null=False): + """ Set the value of node """ + url = "%s/znodes/v1%s?%s" % (self._base, path, \ + urllib.urlencode({ + 'version': version, + 'null': 'true' if null else 'false' + })) + return self._do_put(url, data) + + def delete(self, path, version=-1): + """ Delete a znode """ + if type(path) is list: + map(lambda el: self.delete(el, version), path) + return + + url = '%s/znodes/v1%s?%s' % (self._base, path, \ + urllib.urlencode({ + 'version':version + })) + try: + return self._do_delete(url) + except urllib2.HTTPError, e: + if e.code == 412: + raise ZooKeeper.WrongVersion(path) + elif e.code == 404: + raise ZooKeeper.NotFound(path) + raise + + def exists(self, path): + """ Do a znode exists """ + try: + self.get(path) + return True + except ZooKeeper.NotFound: + return False + + def _do_get(self, uri): + """ Send a GET request and convert errors to exceptions """ + try: + req = urllib2.urlopen(uri) + resp = simplejson.load(req) + + if 'Error' in resp: + raise ZooKeeper.Error(resp['Error']) + + return resp + except urllib2.HTTPError, e: + if e.code == 404: + raise ZooKeeper.NotFound(uri) + raise + + def _do_post(self, uri, data=None): + """ Send a POST request and convert errors to exceptions """ + try: + req = urllib2.Request(uri, {}) + req.add_header('Content-Type', 'application/octet-stream') + if data is not None: + req.add_data(data) + + resp = simplejson.load(urllib2.urlopen(req)) + if 'Error' in resp: + raise ZooKeeper.Error(resp['Error']) + return resp + + except urllib2.HTTPError, e: + if e.code == 201: + return True + elif e.code == 409: + raise ZooKeeper.ZNodeExists(uri) + elif e.code == 401: + raise ZooKeeper.InvalidSession(uri) + raise + + def _do_delete(self, uri): + """ Send a DELETE request """ + req = RequestWithMethod(uri) + req.set_method('DELETE') + req.add_header('Content-Type', 'application/octet-stream') + return urllib2.urlopen(req).read() + + def _do_put(self, uri, data): + """ Send a PUT request """ + try: + req = RequestWithMethod(uri) + req.set_method('PUT') + req.add_header('Content-Type', 'application/octet-stream') + if data is not None: + req.add_data(data) + + return urllib2.urlopen(req).read() + except urllib2.HTTPError, e: + if e.code == 412: # precondition failed + raise ZooKeeper.WrongVersion(uri) + raise + diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/Base.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/Base.java new file mode 100644 index 00000000000..9722198280f --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/Base.java @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.WebResource; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.JUnit4ZKTestRunner; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.jersey.SetTest.MyWatcher; +import org.apache.zookeeper.server.jersey.cfg.RestCfg; +import org.junit.After; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; + +/** + * Test stand-alone server. + * + */ +@RunWith(JUnit4ZKTestRunner.class) +public class Base { + protected static final Logger LOG = LoggerFactory.getLogger(Base.class); + + protected static final String CONTEXT_PATH = "/zk"; + protected static final int GRIZZLY_PORT = 10104; + protected static final String BASEURI = String.format( + "http://localhost:%d%s", GRIZZLY_PORT, CONTEXT_PATH); + protected static final String ZKHOSTPORT = "localhost:22182"; + protected Client client; + protected WebResource znodesr, sessionsr; + + protected ZooKeeper zk; + + private RestMain rest; + + protected static String createBaseZNode() throws Exception { + ZooKeeper zk = new ZooKeeper(ZKHOSTPORT, 30000, new MyWatcher()); + + String baseZnode = zk.create("/test-", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + zk.close(); + + return baseZnode; + } + + @Before + public void setUp() throws Exception { + RestCfg cfg = new RestCfg(new ByteArrayInputStream(String.format( + "rest.port=%s\n" + + "rest.endpoint.1=%s;%s\n", + GRIZZLY_PORT, CONTEXT_PATH, ZKHOSTPORT).getBytes())); + + rest = new RestMain(cfg); + rest.start(); + + zk = new ZooKeeper(ZKHOSTPORT, 30000, new MyWatcher()); + + client = Client.create(); + znodesr = client.resource(BASEURI).path("znodes/v1"); + sessionsr = client.resource(BASEURI).path("sessions/v1/"); + } + + @After + public void tearDown() throws Exception { + client.destroy(); + zk.close(); + rest.stop(); + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java new file mode 100644 index 00000000000..bee9f2a11ac --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java @@ -0,0 +1,154 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.WebResource.Builder; + +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.jersey.jaxb.ZPath; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.Collection; + +import javax.ws.rs.core.MediaType; + + +/** + * Test stand-alone server. + * + */ +@RunWith(Parameterized.class) +public class CreateTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(CreateTest.class); + + private String accept; + private String path; + private String name; + private String encoding; + private ClientResponse.Status expectedStatus; + private ZPath expectedPath; + private byte[] data; + private boolean sequence; + + public CreateTest(String accept, String path, String name, String encoding, + ClientResponse.Status status, ZPath expectedPath, byte[] data, + boolean sequence) { + this.accept = accept; + this.path = path; + this.name = name; + this.encoding = encoding; + this.expectedStatus = status; + this.expectedPath = expectedPath; + this.data = data; + this.sequence = sequence; + } + + @Parameters + public static Collection data() throws Exception { + String baseZnode = Base.createBaseZNode(); + + return Arrays.asList(new Object[][]{ + {MediaType.APPLICATION_JSON, + baseZnode, "foo bar", "utf8", + ClientResponse.Status.CREATED, + new ZPath(baseZnode + "/foo bar"), null, + false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-t1", "utf8", + ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t1"), + null, false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-t1", "utf8", + ClientResponse.Status.CONFLICT, null, null, false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-t2", "utf8", + ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t2"), + "".getBytes(), false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-t2", "utf8", + ClientResponse.Status.CONFLICT, null, null, false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-t3", "utf8", + ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t3"), + "foo".getBytes(), false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-t3", "utf8", + ClientResponse.Status.CONFLICT, null, null, false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-t4", "base64", + ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t4"), + "foo".getBytes(), false}, + {MediaType.APPLICATION_JSON, baseZnode, "c-", "utf8", + ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-"), null, + true}, + {MediaType.APPLICATION_JSON, baseZnode, "c-", "utf8", + ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-"), null, + true} + }); + } + + @Test + public void testCreate() throws Exception { + WebResource wr = znodesr.path(path).queryParam("dataformat", encoding) + .queryParam("name", name); + if (data == null) { + wr = wr.queryParam("null", "true"); + } + if (sequence) { + wr = wr.queryParam("sequence", "true"); + } + + Builder builder = wr.accept(accept); + + ClientResponse cr; + if (data == null) { + cr = builder.post(ClientResponse.class); + } else { + cr = builder.post(ClientResponse.class, data); + } + Assert.assertEquals(expectedStatus, cr.getClientResponseStatus()); + + if (expectedPath == null) { + return; + } + + ZPath zpath = cr.getEntity(ZPath.class); + if (sequence) { + Assert.assertTrue(zpath.path.startsWith(expectedPath.path)); + Assert.assertTrue(zpath.uri.startsWith(znodesr.path(path).toString())); + } else { + Assert.assertEquals(expectedPath, zpath); + Assert.assertEquals(znodesr.path(path).toString(), zpath.uri); + } + + // use out-of-band method to verify + byte[] data = zk.getData(zpath.path, false, new Stat()); + if (data == null && this.data == null) { + return; + } else if (data == null || this.data == null) { + Assert.assertEquals(data, this.data); + } else { + Assert.assertTrue(new String(data) + " == " + new String(this.data), + Arrays.equals(data, this.data)); + } + } + + public static class MyWatcher implements Watcher { + public void process(WatchedEvent event) { + // FIXME ignore for now + } + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java new file mode 100644 index 00000000000..017d9ba686a --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.Collection; + +import javax.ws.rs.core.MediaType; + + +/** + * Test stand-alone server. + * + */ +@RunWith(Parameterized.class) +public class DeleteTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(DeleteTest.class); + + private String zpath; + private ClientResponse.Status expectedStatus; + + public DeleteTest(String path, String zpath, ClientResponse.Status status) { + this.zpath = zpath; + this.expectedStatus = status; + } + + @Parameters + public static Collection data() throws Exception { + String baseZnode = Base.createBaseZNode(); + + return Arrays.asList(new Object[][]{ + {baseZnode, baseZnode, ClientResponse.Status.NO_CONTENT}, + {baseZnode, baseZnode, ClientResponse.Status.NO_CONTENT} + }); + } + + public void verify(String type) throws Exception { + if (expectedStatus != ClientResponse.Status.NOT_FOUND) { + zpath = zk.create(zpath, null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + } + + ClientResponse cr = znodesr.path(zpath).accept(type).type(type) + .delete(ClientResponse.class); + Assert.assertEquals(expectedStatus, cr.getClientResponseStatus()); + + // use out-of-band method to verify + Stat stat = zk.exists(zpath, false); + Assert.assertNull(stat); + } + + @Test + public void testDelete() throws Exception { + verify(MediaType.APPLICATION_OCTET_STREAM); + verify(MediaType.APPLICATION_JSON); + verify(MediaType.APPLICATION_XML); + } + + public static class MyWatcher implements Watcher { + public void process(WatchedEvent event) { + // FIXME ignore for now + } + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java new file mode 100644 index 00000000000..907bb836543 --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java @@ -0,0 +1,73 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.Collection; + +import javax.ws.rs.core.MediaType; + + +/** + * Test stand-alone server. + * + */ +@RunWith(Parameterized.class) +public class ExistsTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(ExistsTest.class); + + private String path; + private ClientResponse.Status expectedStatus; + + public ExistsTest(String path, ClientResponse.Status status) { + this.path = path; + this.expectedStatus = status; + } + + @Parameters + public static Collection data() throws Exception { + String baseZnode = Base.createBaseZNode(); + + return Arrays.asList(new Object[][]{ + {baseZnode, ClientResponse.Status.OK}, + {baseZnode + "dkdk38383", ClientResponse.Status.NOT_FOUND} + }); + } + + private void verify(String type) { + ClientResponse cr = znodesr.path(path).accept(type).type(type).head(); + if (type.equals(MediaType.APPLICATION_OCTET_STREAM) + && expectedStatus == ClientResponse.Status.OK) { + Assert.assertEquals(ClientResponse.Status.NO_CONTENT, + cr.getClientResponseStatus()); + } else { + Assert.assertEquals(expectedStatus, cr.getClientResponseStatus()); + } + } + + @Test + public void testExists() throws Exception { + verify(MediaType.APPLICATION_OCTET_STREAM); + verify(MediaType.APPLICATION_JSON); + verify(MediaType.APPLICATION_XML); + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java new file mode 100644 index 00000000000..b74c6b28570 --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java @@ -0,0 +1,130 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.server.jersey.jaxb.ZChildren; +import org.apache.zookeeper.server.jersey.jaxb.ZChildrenJSON; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import javax.ws.rs.core.MediaType; + + +/** + * Test stand-alone server. + * + */ +@RunWith(Parameterized.class) +public class GetChildrenTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(GetChildrenTest.class); + + private String accept; + private String path; + private ClientResponse.Status expectedStatus; + private String expectedPath; + private List expectedChildren; + + public GetChildrenTest(String accept, String path, ClientResponse.Status status, + String expectedPath, List expectedChildren) { + this.accept = accept; + this.path = path; + this.expectedStatus = status; + this.expectedPath = expectedPath; + this.expectedChildren = expectedChildren; + } + + @Parameters + public static Collection data() throws Exception { + String baseZnode = Base.createBaseZNode(); + String baseZnode2 = Base.createBaseZNode(); + String baseZnode3 = Base.createBaseZNode(); + String baseZnode4 = Base.createBaseZNode(); + String baseZnode5 = Base.createBaseZNode(); + String baseZnode6 = Base.createBaseZNode(); + + return Arrays.asList(new Object[][]{ + {MediaType.APPLICATION_JSON, baseZnode + "abddkdkd", + ClientResponse.Status.NOT_FOUND, null, null}, + {MediaType.APPLICATION_XML, baseZnode + "abddkdkd", + ClientResponse.Status.NOT_FOUND, null, null}, + {MediaType.APPLICATION_JSON, baseZnode, ClientResponse.Status.OK, + baseZnode, Arrays.asList(new String[]{})}, + {MediaType.APPLICATION_XML, baseZnode, ClientResponse.Status.OK, + baseZnode, Arrays.asList(new String[]{})}, + {MediaType.APPLICATION_JSON, baseZnode, ClientResponse.Status.OK, + baseZnode, Arrays.asList(new String[]{"c1"})}, + {MediaType.APPLICATION_XML, baseZnode4, ClientResponse.Status.OK, + baseZnode4, Arrays.asList(new String[]{"c1"})}, + {MediaType.APPLICATION_JSON, baseZnode2, ClientResponse.Status.OK, + baseZnode2, Arrays.asList(new String[]{"c1", "c2"})}, + {MediaType.APPLICATION_XML, baseZnode5, ClientResponse.Status.OK, + baseZnode5, Arrays.asList(new String[]{"c1", "c2"})}, + {MediaType.APPLICATION_JSON, baseZnode3, ClientResponse.Status.OK, + baseZnode3, Arrays.asList(new String[]{"c1", "c2", "c3", "c4"})}, + {MediaType.APPLICATION_XML, baseZnode6, ClientResponse.Status.OK, + baseZnode6, Arrays.asList(new String[]{"c1", "c2", "c3", "c4"})} + + }); + } + + @Test + public void testGetChildren() throws Exception { + if (expectedChildren != null) { + for (String child : expectedChildren) { + zk.create(expectedPath + "/" + child, null, + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + } + + ClientResponse cr = znodesr.path(path).queryParam("view", "children") + .accept(accept).get(ClientResponse.class); + Assert.assertEquals(expectedStatus, cr.getClientResponseStatus()); + + if (expectedChildren == null) { + return; + } + + if (accept.equals(MediaType.APPLICATION_JSON)) { + ZChildrenJSON zchildren = cr.getEntity(ZChildrenJSON.class); + Collections.sort(expectedChildren); + Collections.sort(zchildren.children); + Assert.assertEquals(expectedChildren, zchildren.children); + Assert.assertEquals(znodesr.path(path).toString(), zchildren.uri); + Assert.assertEquals(znodesr.path(path).toString() + "/{child}", + zchildren.child_uri_template); + } else if (accept.equals(MediaType.APPLICATION_XML)) { + ZChildren zchildren = cr.getEntity(ZChildren.class); + Collections.sort(expectedChildren); + Collections.sort(zchildren.children); + Assert.assertEquals(expectedChildren, zchildren.children); + Assert.assertEquals(znodesr.path(path).toString(), zchildren.uri); + Assert.assertEquals(znodesr.path(path).toString() + "/{child}", + zchildren.child_uri_template); + } else { + Assert.fail("unknown accept type"); + } + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java new file mode 100644 index 00000000000..bcb5d6c7ecb --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java @@ -0,0 +1,114 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; + +import org.apache.zookeeper.server.jersey.jaxb.ZStat; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.Collection; + +import javax.ws.rs.core.MediaType; + + +/** + * Test stand-alone server. + * + */ +@RunWith(Parameterized.class) +public class GetTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(GetTest.class); + + private String accept; + private String path; + private String encoding; + private ClientResponse.Status expectedStatus; + private ZStat expectedStat; + + public GetTest(String accept, String path, String encoding, + ClientResponse.Status status, ZStat stat) { + this.accept = accept; + this.path = path; + this.encoding = encoding; + this.expectedStatus = status; + this.expectedStat = stat; + } + + @Parameters + public static Collection data() throws Exception { + String baseZnode = Base.createBaseZNode(); + + return Arrays.asList(new Object[][]{ + {MediaType.APPLICATION_JSON, baseZnode, "utf8", + ClientResponse.Status.OK, new ZStat(baseZnode, null, null)}, + {MediaType.APPLICATION_JSON, baseZnode, "utf8", + ClientResponse.Status.OK, new ZStat(baseZnode, null, "")}, + {MediaType.APPLICATION_JSON, baseZnode, "utf8", + ClientResponse.Status.OK, new ZStat(baseZnode, null, "foo")}, + {MediaType.APPLICATION_JSON, baseZnode, "base64", + ClientResponse.Status.OK, new ZStat(baseZnode, null, null)}, + {MediaType.APPLICATION_JSON, baseZnode, "base64", + ClientResponse.Status.OK, new ZStat(baseZnode, "".getBytes(), null)}, + {MediaType.APPLICATION_JSON, baseZnode, "base64", + ClientResponse.Status.OK, new ZStat(baseZnode, "".getBytes(), null)}, + {MediaType.APPLICATION_JSON, baseZnode, "base64", + ClientResponse.Status.OK, new ZStat(baseZnode, "foo".getBytes(), null)}, + {MediaType.APPLICATION_JSON, baseZnode + "abaddkdk", "utf8", + ClientResponse.Status.NOT_FOUND, null}, + {MediaType.APPLICATION_JSON, baseZnode + "abaddkdk", "base64", + ClientResponse.Status.NOT_FOUND, null}, + + {MediaType.APPLICATION_XML, baseZnode, "utf8", + ClientResponse.Status.OK, new ZStat(baseZnode, null, "foo")}, + {MediaType.APPLICATION_XML, baseZnode, "base64", + ClientResponse.Status.OK, + new ZStat(baseZnode, "foo".getBytes(), null)}, + {MediaType.APPLICATION_XML, baseZnode + "abaddkdk", "utf8", + ClientResponse.Status.NOT_FOUND, null}, + {MediaType.APPLICATION_XML, baseZnode + "abaddkdk", "base64", + ClientResponse.Status.NOT_FOUND, null} + + }); + } + + @Test + public void testGet() throws Exception { + if (expectedStat != null) { + if (expectedStat.data64 != null || expectedStat.dataUtf8 == null) { + zk.setData(expectedStat.path, expectedStat.data64, -1); + } else { + zk.setData(expectedStat.path, + expectedStat.dataUtf8.getBytes(), -1); + } + } + + ClientResponse cr = znodesr.path(path).queryParam("dataformat", encoding) + .accept(accept).get(ClientResponse.class); + Assert.assertEquals(expectedStatus, cr.getClientResponseStatus()); + + if (expectedStat == null) { + return; + } + + ZStat zstat = cr.getEntity(ZStat.class); + Assert.assertEquals(expectedStat, zstat); + Assert.assertEquals(znodesr.path(path).toString(), zstat.uri); + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RestTestSuite.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RestTestSuite.java new file mode 100644 index 00000000000..2777faf92b3 --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RestTestSuite.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({WadlTest.class, GetTest.class, GetChildrenTest.class, + CreateTest.class, SetTest.class, ExistsTest.class, DeleteTest.class}) +public class RestTestSuite { + + @BeforeClass + public static void setUp() { + // suite setup + } + + @AfterClass + public static void tearDown() { + // suite setup + } + +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java new file mode 100644 index 00000000000..c1772e6c6a1 --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.WebResource.Builder; + +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.jersey.jaxb.ZPath; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; + +import javax.ws.rs.core.MediaType; + +/** + * Test stand-alone server. + * + */ +public class RootTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(RootTest.class); + + @Test + public void testCreate() throws Exception { + String path = "/"; + String name = "roottest-create"; + byte[] data = "foo".getBytes(); + + WebResource wr = znodesr.path(path).queryParam("dataformat", "utf8") + .queryParam("name", name); + Builder builder = wr.accept(MediaType.APPLICATION_JSON); + + ClientResponse cr; + cr = builder.post(ClientResponse.class, data); + Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus()); + + ZPath zpath = cr.getEntity(ZPath.class); + Assert.assertEquals(new ZPath(path + name), zpath); + Assert.assertEquals(znodesr.path(path).toString(), zpath.uri); + + // use out-of-band method to verify + byte[] rdata = zk.getData(zpath.path, false, new Stat()); + Assert.assertTrue(new String(rdata) + " == " + new String(data), + Arrays.equals(rdata, data)); + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SessionTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SessionTest.java new file mode 100644 index 00000000000..42f4b067c12 --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SessionTest.java @@ -0,0 +1,127 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.WebResource.Builder; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.jersey.jaxb.ZSession; +import org.codehaus.jettison.json.JSONException; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +import javax.ws.rs.core.MediaType; + +public class SessionTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(SessionTest.class); + + private ZSession createSession() { + return createSession("30"); + } + + private ZSession createSession(String expire) { + WebResource wr = sessionsr.queryParam("op", "create") + .queryParam("expire", expire); + Builder b = wr.accept(MediaType.APPLICATION_JSON); + + ClientResponse cr = b.post(ClientResponse.class, null); + Assert.assertEquals(ClientResponse.Status.CREATED, cr + .getClientResponseStatus()); + + return cr.getEntity(ZSession.class); + } + + @Test + public void testCreateNewSession() throws JSONException { + ZSession session = createSession(); + Assert.assertEquals(session.id.length(), 36); + + // use out-of-band method to verify + Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id)); + } + + @Test + public void testSessionExpires() throws InterruptedException { + ZSession session = createSession("1"); + + // use out-of-band method to verify + Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id)); + + // wait for the session to be closed + Thread.sleep(1500); + Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id)); + } + + @Test + public void testDeleteSession() { + ZSession session = createSession("30"); + + WebResource wr = sessionsr.path(session.id); + Builder b = wr.accept(MediaType.APPLICATION_JSON); + + Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id)); + ClientResponse cr = b.delete(ClientResponse.class, null); + Assert.assertEquals(ClientResponse.Status.NO_CONTENT, + cr.getClientResponseStatus()); + + Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id)); + } + + @Test + public void testSendHeartbeat() throws InterruptedException { + ZSession session = createSession("2"); + + Thread.sleep(1000); + WebResource wr = sessionsr.path(session.id); + Builder b = wr.accept(MediaType.APPLICATION_JSON); + + ClientResponse cr = b.put(ClientResponse.class, null); + Assert.assertEquals(ClientResponse.Status.OK, cr.getClientResponseStatus()); + + Thread.sleep(1500); + Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id)); + + Thread.sleep(1000); + Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id)); + } + + @Test + public void testCreateEphemeralZNode() + throws KeeperException, InterruptedException, IOException { + ZSession session = createSession("30"); + + WebResource wr = znodesr.path("/") + .queryParam("op", "create") + .queryParam("name", "ephemeral-test") + .queryParam("ephemeral", "true") + .queryParam("session", session.id) + .queryParam("null", "true"); + + Builder b = wr.accept(MediaType.APPLICATION_JSON); + ClientResponse cr = b.post(ClientResponse.class); + Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus()); + + Stat stat = new Stat(); + zk.getData("/ephemeral-test", false, stat); + + ZooKeeper sessionZK = ZooKeeperService.getClient(CONTEXT_PATH, session.id); + Assert.assertEquals(stat.getEphemeralOwner(), sessionZK.getSessionId()); + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java new file mode 100644 index 00000000000..f23fd3c8c5b --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java @@ -0,0 +1,146 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.WebResource.Builder; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.jersey.jaxb.ZStat; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.Collection; + +import javax.ws.rs.core.MediaType; + + +/** + * Test stand-alone server. + * + */ +@RunWith(Parameterized.class) +public class SetTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(SetTest.class); + + private String accept; + private String path; + private String encoding; + private ClientResponse.Status expectedStatus; + private ZStat expectedStat; + private byte[] data; + + public SetTest(String accept, String path, String encoding, + ClientResponse.Status status, ZStat expectedStat, byte[] data) { + this.accept = accept; + this.path = path; + this.encoding = encoding; + this.expectedStatus = status; + this.expectedStat = expectedStat; + this.data = data; + } + + @Parameters + public static Collection data() throws Exception { + String baseZnode = Base.createBaseZNode(); + + return Arrays.asList(new Object[][]{ + {MediaType.APPLICATION_JSON, baseZnode + "/s-t1", "utf8", + ClientResponse.Status.OK, + new ZStat(baseZnode + "/s-t1", null, null), null}, + {MediaType.APPLICATION_JSON, baseZnode + "/s-t2", "utf8", + ClientResponse.Status.OK, + new ZStat(baseZnode + "/s-t2", null, null), new byte[0]}, + {MediaType.APPLICATION_JSON, baseZnode + "/s-t3", "utf8", + ClientResponse.Status.OK, + new ZStat(baseZnode + "/s-t3", null, null), "foobar".getBytes()}, + {MediaType.APPLICATION_JSON, baseZnode + "/s-t4", "base64", + ClientResponse.Status.OK, + new ZStat(baseZnode + "/s-t4", null, null), null}, + {MediaType.APPLICATION_JSON, baseZnode + "/s-t5", "base64", + ClientResponse.Status.OK, + new ZStat(baseZnode + "/s-t5", null, null), new byte[0]}, + {MediaType.APPLICATION_JSON, baseZnode + "/s-t6", "base64", + ClientResponse.Status.OK, + new ZStat(baseZnode + "/s-t6", null, null), + "foobar".getBytes()}, + {MediaType.APPLICATION_JSON, baseZnode + "/dkdkdkd", "utf8", + ClientResponse.Status.NOT_FOUND, null, null}, + {MediaType.APPLICATION_JSON, baseZnode + "/dkdkdkd", "base64", + ClientResponse.Status.NOT_FOUND, null, null}, + }); + } + + @Test + public void testSet() throws Exception { + if (expectedStat != null) { + zk.create(expectedStat.path, "initial".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + + WebResource wr = znodesr.path(path).queryParam("dataformat", encoding); + if (data == null) { + wr = wr.queryParam("null", "true"); + } + + Builder builder = wr.accept(accept) + .type(MediaType.APPLICATION_OCTET_STREAM); + + ClientResponse cr; + if (data == null) { + cr = builder.put(ClientResponse.class); + } else { + // this shouldn't be necessary (wrapping data with string) + // but without it there are problems on the server - ie it + // hangs for 30 seconds and doesn't get the data. + // TODO investigate + cr = builder.put(ClientResponse.class, new String(data)); + } + Assert.assertEquals(expectedStatus, cr.getClientResponseStatus()); + + if (expectedStat == null) { + return; + } + + ZStat zstat = cr.getEntity(ZStat.class); + Assert.assertEquals(expectedStat, zstat); + + // use out-of-band method to verify + byte[] data = zk.getData(zstat.path, false, new Stat()); + if (data == null && this.data == null) { + return; + } else if (data == null || this.data == null) { + Assert.fail((data == null ? null : new String(data)) + " == " + + (this.data == null ? null : new String(this.data))); + } else { + Assert.assertTrue(new String(data) + " == " + new String(this.data), + Arrays.equals(data, this.data)); + } + } + + public static class MyWatcher implements Watcher { + public void process(WatchedEvent event) { + // FIXME ignore for now + } + } +} diff --git a/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/WadlTest.java b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/WadlTest.java new file mode 100644 index 00000000000..4dd42676386 --- /dev/null +++ b/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/WadlTest.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.jersey; + +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.core.header.MediaTypes; + +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Test stand-alone server. + * + */ +public class WadlTest extends Base { + protected static final Logger LOG = LoggerFactory.getLogger(WadlTest.class); + + @Test + public void testApplicationWadl() { + WebResource r = client.resource(BASEURI); + String serviceWadl = r.path("application.wadl"). + accept(MediaTypes.WADL).get(String.class); + Assert.assertTrue("Something wrong. Returned wadl length not > 0.", + serviceWadl.length() > 0); + } +} diff --git a/src/contrib/rest/src/test/zkServer.sh b/src/contrib/rest/src/test/zkServer.sh new file mode 100755 index 00000000000..bff85f33e7b --- /dev/null +++ b/src/contrib/rest/src/test/zkServer.sh @@ -0,0 +1,91 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if [ "x$1" == "x" ] +then + echo "USAGE: $0 startClean|start|stop hostPorts" + exit 2 +fi + +if [ "x$1" == "xstartClean" ] +then + if [ "x${base_dir}" == "x" ] + then + rm -rf /tmp/zkdata + else + rm -rf ${base_dir}/build/tmp + fi +fi + +# Make sure nothing is left over from before +if [ -r "/tmp/zk.pid" ] +then +pid=`cat /tmp/zk.pid` +kill -9 $pid +rm -f /tmp/zk.pid +fi + +if [ -r "${base_dir}/build/tmp/zk.pid" ] +then +pid=`cat ${base_dir}/build/tmp/zk.pid` +kill -9 $pid +rm -f ${base_dir}/build/tmp/zk.pid +fi + +if [ "x${base_dir}" == "x" ] +then +zk_base="../../../" +else +zk_base="${base_dir}" +fi + +CLASSPATH="$CLASSPATH:${zk_base}/build/classes" +CLASSPATH="$CLASSPATH:${zk_base}/conf" + +for i in "${zk_base}"/build/lib/*.jar +do + CLASSPATH="$CLASSPATH:$i" +done + +for i in "${zk_base}"/src/java/lib/*.jar +do + CLASSPATH="$CLASSPATH:$i" +done + +case $1 in +start|startClean) + if [ "x${base_dir}" == "x" ] + then + mkdir -p /tmp/zkdata + java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22182 /tmp/zkdata &> /tmp/zk.log & + echo $! > /tmp/zk.pid + else + mkdir -p ${base_dir}/build/tmp/zkdata + java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22182 ${base_dir}/build/tmp/zkdata &> ${base_dir}/build/tmp/zk.log & + echo $! > ${base_dir}/build/tmp/zk.pid + fi + sleep 5 + ;; +stop) + # Already killed above + ;; +*) + echo "Unknown command " + $1 + exit 2 +esac + diff --git a/src/contrib/zkfuse/Makefile.am b/src/contrib/zkfuse/Makefile.am new file mode 100644 index 00000000000..36da1a50d4e --- /dev/null +++ b/src/contrib/zkfuse/Makefile.am @@ -0,0 +1,4 @@ +## Process this file with automake to produce Makefile.in + +SUBDIRS = src + diff --git a/src/contrib/zkfuse/README.txt b/src/contrib/zkfuse/README.txt new file mode 100644 index 00000000000..901d3634fed --- /dev/null +++ b/src/contrib/zkfuse/README.txt @@ -0,0 +1,63 @@ +Original authors of zkfuse are Swee Lim & Bartlomiej M Niechwiej of Yahoo. +' +ZooKeeper FUSE (File System in Userspace) +========================================= + +Pre-requisites +-------------- +1. Linux system with 2.6.X kernel. +2. Fuse (Filesystem in Userspace) must be installed on the build node. +3. Development build libraries: + a. fuse + b. log4cxx + c. pthread + d. boost + +Build instructions +------------------ +1. cd into this directory +2. autoreconf -if +3. ./configure +4. make +5. zkfuse binary is under the src directory + +Testing Zkfuse +-------------- +1. Depending on permission on /dev/fuse, you may need to sudo -u root. + * If /dev/fuse has permissions 0600, then you have to run Zkfuse as root. + * If /dev/fuse has permissions 0666, then you can run Zkfuse as any user. +2. Create or find a mount point that you have "rwx" permission. + * e.g. mkdir -p /tmp/zkfuse +3. Run Zkfuse as follows: + zkfuse -z -m /tmp/zkfuse -d + -z specifies ZooKeeper address(es) : + -m specifies the mount point + -d specifies the debug mode. + For additional command line options, try "zkfuse -h". + +FAQ +--- +Q. How to fix "warning: macro `AM_PATH_CPPUNIT' not found in library"? +A. * install cppunit (src or pkg) on build machine + +Q. Why can't Zkfuse cannot write to current directory? +A. * If Zkfuse is running as root on a NFS mounted file system, it will not + have root permissions because root user is mapped to another user by + NFS admin. + * If you run Zkfuse as root, it is a good idea to run Zkfuse from a + directory that you have write access to. This will allow core files + to be saved. + +Q. Why Zkfuse cannot mount? +A. * Check that the mount point exists and you have "rwx" permissions. + * Check that previous mounts have been umounted. If Zkfuse does not + exit cleanly, its mount point may have to be umounted manually. + If you cannot umount manually, make sure that there no files is open + within the mount point. + +Q. Why does Zkfuse complain about logging at startup? +A. * Zkfuse uses log4cxx for logging. It is looking for log4cxx.properties + file to obtain its logging configuration. + * There is an example log4cxx.properties file in the Zkfuse source + directory. + diff --git a/src/contrib/zkfuse/build.xml b/src/contrib/zkfuse/build.xml new file mode 100644 index 00000000000..be07b5485fa --- /dev/null +++ b/src/contrib/zkfuse/build.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zkfuse/configure.ac b/src/contrib/zkfuse/configure.ac new file mode 100644 index 00000000000..c86e7cdc84c --- /dev/null +++ b/src/contrib/zkfuse/configure.ac @@ -0,0 +1,72 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) + +AC_INIT([zkfuse], [2.2.0]) +AM_INIT_AUTOMAKE(foreign) + +AC_CONFIG_SRCDIR([src/zkadapter.h]) +AM_CONFIG_HEADER([config.h]) + +PACKAGE=zkfuse +VERSION=1.0 + +AC_SUBST(PACKAGE) +AC_SUBST(VERSION) + +BUILD_PATH="`pwd`" + +# Checks for programs. +AC_LANG_CPLUSPLUS +AC_PROG_CXX + +# Checks for libraries. +AC_CHECK_LIB([fuse], [main]) +AC_CHECK_LIB([log4cxx], [main], [], [AC_MSG_ERROR("We need log4cxx to build zkfuse")]) +AC_CHECK_LIB([thread], [thr_create]) +AC_CHECK_LIB([pthread], [pthread_create]) +AC_CHECK_LIB([rt], [clock_gettime]) +AC_CHECK_LIB([socket], [socket]) +AC_CHECK_LIB([nsl], [gethostbyname]) +AC_CHECK_LIB([ulockmgr], [ulockmgr_op]) + +ZOOKEEPER_PATH=${BUILD_PATH}/../../c +ZOOKEEPER_BUILD_PATH=${BUILD_PATH}/../../../build/c +AC_CHECK_LIB(zookeeper_mt, main, [ZOOKEEPER_LD="-L${ZOOKEEPER_BUILD_PATH}/.libs -lzookeeper_mt"],,["-L${ZOOKEEPER_BUILD_PATH}/.libs"]) + +AC_SUBST(ZOOKEEPER_PATH) +AC_SUBST(ZOOKEEPER_LD) + +# Checks for header files. +AC_HEADER_DIRENT +AC_HEADER_STDC +AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/time.h unistd.h]) +AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/utility.hpp boost/weak_ptr.hpp],, AC_MSG_ERROR([boost library headers not found. Please install boost library.])) + +# Checks for typedefs, structures, and compiler characteristics. +AC_HEADER_STDBOOL +AC_C_CONST +AC_TYPE_UID_T +AC_C_INLINE +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_MODE_T +AC_TYPE_OFF_T +AC_TYPE_SIZE_T +AC_CHECK_MEMBERS([struct stat.st_blksize]) +AC_STRUCT_ST_BLOCKS +AC_HEADER_TIME +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_UINT8_T +AC_C_VOLATILE + +# Checks for library functions. +AC_FUNC_UTIME_NULL +AC_CHECK_FUNCS([gettimeofday memset mkdir rmdir strdup strerror strstr strtol strtoul strtoull utime]) + +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([src/Makefile]) +AC_OUTPUT +AC_C_VOLATILE diff --git a/src/contrib/zkfuse/src/Makefile.am b/src/contrib/zkfuse/src/Makefile.am new file mode 100644 index 00000000000..c0d87e317ff --- /dev/null +++ b/src/contrib/zkfuse/src/Makefile.am @@ -0,0 +1,7 @@ +AM_CXXFLAGS = -I${ZOOKEEPER_PATH}/include -I${ZOOKEEPER_PATH}/generated \ + -I$(top_srcdir)/include -I/usr/include -D_FILE_OFFSET_BITS=64 -D_REENTRANT + +noinst_PROGRAMS = zkfuse + +zkfuse_SOURCES = zkfuse.cc zkadapter.cc thread.cc log.cc +zkfuse_LDADD = ${ZOOKEEPER_LD} \ No newline at end of file diff --git a/src/contrib/zkfuse/src/blockingqueue.h b/src/contrib/zkfuse/src/blockingqueue.h new file mode 100644 index 00000000000..4677290d7b6 --- /dev/null +++ b/src/contrib/zkfuse/src/blockingqueue.h @@ -0,0 +1,154 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __BLOCKINGQUEUE_H__ +#define __BLOCKINGQUEUE_H__ + +#include + +#include "mutex.h" + +using namespace std; +USING_ZKFUSE_NAMESPACE + +namespace zk { + +/** + * \brief An unbounded blocking queue of elements of type E. + * + *

+ * This class is thread safe. + */ +template +class BlockingQueue { + public: + + /** + * \brief Adds the specified element to this queue, waiting if necessary + * \brief for space to become available. + * + * @param e the element to be added + */ + void put(E e); + + /** + * \brief Retrieves and removes the head of this queue, waiting if + * \brief no elements are present in this queue. + * + * @param timeout how long to wait until an element becomes availabe, + * in milliseconds; if 0 then wait forever + * @param timedOut if not NULL then set to true whether this function timed out + * @return the element from the queue + */ + E take(int32_t timeout = 0, bool *timedOut = NULL); + + /** + * Returns the current size of this blocking queue. + * + * @return the number of elements in this queue + */ + int size() const; + + /** + * \brief Returns whether this queue is empty or not. + * + * @return true if this queue has no elements; false otherwise + */ + bool empty() const; + + private: + + /** + * The queue of elements. Deque is used to provide O(1) time + * for head elements removal. + */ + deque m_queue; + + /** + * The mutex used for queue synchronization. + */ + mutable zkfuse::Mutex m_mutex; + + /** + * The conditionial variable associated with the mutex above. + */ + mutable Cond m_cond; + +}; + +template +int BlockingQueue::size() const { + int size; + m_mutex.Acquire(); + size = m_queue.size(); + m_mutex.Release(); + return size; +} + +template +bool BlockingQueue::empty() const { + bool isEmpty; + m_mutex.Acquire(); + isEmpty = m_queue.empty(); + m_mutex.Release(); + return isEmpty; +} + +template +void BlockingQueue::put(E e) { + m_mutex.Acquire(); + m_queue.push_back( e ); + m_cond.Signal(); + m_mutex.Release(); +} + +template + E BlockingQueue::take(int32_t timeout, bool *timedOut) { + m_mutex.Acquire(); + bool hasResult = true; + while (m_queue.empty()) { + if (timeout <= 0) { + m_cond.Wait( m_mutex ); + } else { + if (!m_cond.Wait( m_mutex, timeout )) { + hasResult = false; + break; + } + } + } + if (hasResult) { + E e = m_queue.front(); + m_queue.pop_front(); + m_mutex.Release(); + if (timedOut) { + *timedOut = false; + } + return e; + } else { + m_mutex.Release(); + if (timedOut) { + *timedOut = true; + } + return E(); + } +} + +} + +#endif /* __BLOCKINGQUEUE_H__ */ + diff --git a/src/contrib/zkfuse/src/doxygen.cfg b/src/contrib/zkfuse/src/doxygen.cfg new file mode 100644 index 00000000000..308b09450a4 --- /dev/null +++ b/src/contrib/zkfuse/src/doxygen.cfg @@ -0,0 +1,1242 @@ +# Doxyfile 1.4.3 + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = ZkFuse + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. + +SHOW_DIRECTORIES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the progam writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = YES + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/src/contrib/zkfuse/src/event.cc b/src/contrib/zkfuse/src/event.cc new file mode 100644 index 00000000000..541657e1449 --- /dev/null +++ b/src/contrib/zkfuse/src/event.cc @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "event.h" + +#define LOG_LEVEL LOG_FATAL +#define MODULE_NAME "Event" + +using namespace std; + +namespace zkfuse { + +} /* end of 'namespace zkfuse' */ + diff --git a/src/contrib/zkfuse/src/event.h b/src/contrib/zkfuse/src/event.h new file mode 100644 index 00000000000..0506932f7a3 --- /dev/null +++ b/src/contrib/zkfuse/src/event.h @@ -0,0 +1,553 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __EVENT_H__ +#define __EVENT_H__ + +#include +#include +#include +#include +#ifdef GCC4 +# include +using namespace std::tr1; +#else +# include +using namespace boost; +#endif + +#include "log.h" +#include "blockingqueue.h" +#include "mutex.h" +#include "thread.h" + +using namespace std; +using namespace zk; + +namespace zkfuse { + +//forward declaration of EventSource +template +class EventSource; + +/** + * \brief This interface is implemented by an observer + * \brief of a particular {@link EventSource}. + */ +template +class EventListener { + public: + + /** + * \brief This method is invoked whenever an event + * \brief has been received by the event source being observed. + * + * @param source the source the triggered the event + * @param e the actual event being triggered + */ + virtual void eventReceived(const EventSource &source, const E &e) = 0; +}; + +/** + * \brief This class represents a source of events. + * + *

+ * Each source can have many observers (listeners) attached to it + * and in case of an event, this source may propagate the event + * using {@link #fireEvent} method. + */ +template +class EventSource { + public: + + /** + * \brief The type corresponding to the list of registered event listeners. + */ + typedef set *> EventListeners; + + /** + * \brief Registers a new event listener. + * + * @param listener the listener to be added to the set of listeners + */ + void addListener(EventListener *listener) { + m_listeners.insert( listener ); + } + + /** + * \brief Removes an already registered listener. + * + * @param listener the listener to be removed + */ + void removeListener(EventListener *listener) { + m_listeners.erase( listener ); + } + + /** + * \brief Destructor. + */ + virtual ~EventSource() {} + + protected: + + /** + * \brief Fires the given event to all registered listeners. + * + *

+ * This method essentially iterates over all listeners + * and invokes {@link fireEvent(EventListener *listener, const E &event)} + * for each element. All derived classes are free to + * override the method to provide better error handling + * than the default implementation. + * + * @param event the event to be propagated to all listeners + */ + void fireEvent(const E &event); + + /** + * \brief Sends an event to the given listener. + * + * @param listener the listener to whom pass the event + * @param event the event to be handled + */ + virtual void fireEvent(EventListener *listener, const E &event); + + private: + + /** + * The set of registered event listeners. + */ + EventListeners m_listeners; + +}; + +/** + * \brief The interface of a generic event wrapper. + */ +class AbstractEventWrapper { + public: + + /** + * \brief Destructor. + */ + virtual ~AbstractEventWrapper() {} + + /** + * \brief Returns the underlying wrapee's data. + */ + virtual void *getWrapee() = 0; +}; + +/** + * \brief A template based implementation of {@link AbstractEventWrapper}. + */ +template +class EventWrapper : public AbstractEventWrapper { + public: + EventWrapper(const E &e) : m_e(e) { + } + void *getWrapee() { + return &m_e; + } + private: + E m_e; +}; + +/** + * \brief This class represents a generic event. + */ +class GenericEvent { + public: + + /** + * \brief Constructor. + */ + GenericEvent() : m_type(0) {} + + /** + * \brief Constructor. + * + * @param type the type of this event + * @param eventWarpper the wrapper around event's data + */ + GenericEvent(int type, AbstractEventWrapper *eventWrapper) : + m_type(type), m_eventWrapper(eventWrapper) { + } + + /** + * \brief Returns the type of this event. + * + * @return type of this event + */ + int getType() const { return m_type; } + + /** + * \brief Returns the event's data. + * + * @return the event's data + */ + void *getEvent() const { return m_eventWrapper->getWrapee(); } + + private: + + /** + * The event type. + */ + int m_type; + + /** + * The event represented as abstract wrapper. + */ + shared_ptr m_eventWrapper; + +}; + +/** + * \brief This class adapts {@link EventListener} to a generic listener. + * Essentially this class listens on incoming events and fires them + * as {@link GenericEvent}s. + */ +template +class EventListenerAdapter : public virtual EventListener, + public virtual EventSource +{ + public: + + /** + * \brief Constructor. + * + * @param eventSource the source on which register this listener + */ + EventListenerAdapter(EventSource &eventSource) { + eventSource.addListener(this); + } + + void eventReceived(const EventSource &source, const E &e) { + AbstractEventWrapper *wrapper = new EventWrapper(e); + GenericEvent event(type, wrapper); + fireEvent( event ); + } + +}; + +/** + * \brief This class provides an adapter between an asynchronous and synchronous + * \brief event handling. + * + *

+ * This class queues up all received events and exposes them through + * {@link #getNextEvent()} method. + */ +template +class SynchronousEventAdapter : public EventListener { + public: + + void eventReceived(const EventSource &source, const E &e) { + m_queue.put( e ); + } + + /** + * \brief Returns the next available event from the underlying queue, + * \brief possibly blocking, if no data is available. + * + * @return the next available event + */ + E getNextEvent() { + return m_queue.take(); + } + + /** + * \brief Returns whether there are any events in the queue or not. + * + * @return true if there is at least one event and + * the next call to {@link #getNextEvent} won't block + */ + bool hasEvents() const { + return (m_queue.empty() ? false : true); + } + + /** + * \brief Destructor. + */ + virtual ~SynchronousEventAdapter() {} + + private: + + /** + * The blocking queue of all events received so far. + */ + BlockingQueue m_queue; + +}; + +/** + * This typedef defines the type of a timer Id. + */ +typedef int32_t TimerId; + +/** + * This class represents a timer event parametrized by the user's data type. + */ +template +class TimerEvent { + public: + + /** + * \brief Constructor. + * + * @param id the ID of this event + * @param alarmTime when this event is to be triggered + * @param userData the user data associated with this event + */ + TimerEvent(TimerId id, int64_t alarmTime, const T &userData) : + m_id(id), m_alarmTime(alarmTime), m_userData(userData) + {} + + /** + * \brief Constructor. + */ + TimerEvent() : m_id(-1), m_alarmTime(-1) {} + + /** + * \brief Returns the ID. + * + * @return the ID of this event + */ + TimerId getID() const { return m_id; } + + /** + * \brief Returns the alarm time. + * + * @return the alarm time + */ + int64_t getAlarmTime() const { return m_alarmTime; } + + /** + * \brief Returns the user's data. + * + * @return the user's data + */ + T const &getUserData() const { return m_userData; } + + /** + * \brief Returns whether the given alarm time is less than this event's + * \brief time. + */ + bool operator<(const int64_t alarmTime) const { + return m_alarmTime < alarmTime; + } + + private: + + /** + * The ID of ths event. + */ + TimerId m_id; + + /** + * The time at which this event triggers. + */ + int64_t m_alarmTime; + + /** + * The user specific data associated with this event. + */ + T m_userData; + +}; + +template +class Timer : public EventSource > { + public: + + /** + * \brief Constructor. + */ + Timer() : m_currentEventID(0), m_terminating(false) { + m_workerThread.Create( *this, &Timer::sendAlarms ); + } + + /** + * \brief Destructor. + */ + ~Timer() { + m_terminating = true; + m_lock.notify(); + m_workerThread.Join(); + } + + /** + * \brief Schedules the given event timeFromNow milliseconds. + * + * @param timeFromNow time from now, in milliseconds, when the event + * should be triggered + * @param userData the user data associated with the timer event + * + * @return the ID of the newly created timer event + */ + TimerId scheduleAfter(int64_t timeFromNow, const T &userData) { + return scheduleAt( getCurrentTimeMillis() + timeFromNow, userData ); + } + + /** + * \brief Schedules an event at the given time. + * + * @param absTime absolute time, in milliseconds, at which the event + * should be triggered; the time is measured + * from Jan 1st, 1970 + * @param userData the user data associated with the timer event + * + * @return the ID of the newly created timer event + */ + TimerId scheduleAt(int64_t absTime, const T &userData) { + m_lock.lock(); + typename QueueType::iterator pos = + lower_bound( m_queue.begin(), m_queue.end(), absTime ); + TimerId id = m_currentEventID++; + TimerEvent event(id, absTime, userData); + m_queue.insert( pos, event ); + m_lock.notify(); + m_lock.unlock(); + return id; + } + + /** + * \brief Returns the current time since Jan 1, 1970, in milliseconds. + * + * @return the current time in milliseconds + */ + static int64_t getCurrentTimeMillis() { + struct timeval now; + gettimeofday( &now, NULL ); + return now.tv_sec * 1000LL + now.tv_usec / 1000; + } + + /** + * \brief Cancels the given timer event. + * + * + * @param eventID the ID of the event to be canceled + * + * @return whether the event has been canceled + */ + bool cancelAlarm(TimerId eventID) { + bool canceled = false; + m_lock.lock(); + typename QueueType::iterator i; + for (i = m_queue.begin(); i != m_queue.end(); ++i) { + if (eventID == i->getID()) { + m_queue.erase( i ); + canceled = true; + break; + } + } + m_lock.unlock(); + return canceled; + } + + /** + * Executes the main loop of the worker thread. + */ + void sendAlarms() { + //iterate until terminating + while (!m_terminating) { + m_lock.lock(); + //1 step - wait until there is an event in the queue + if (m_queue.empty()) { + //wait up to 100ms to get next event + m_lock.wait( 100 ); + } + bool fire = false; + if (!m_queue.empty()) { + //retrieve the event from the queue and send it + TimerEvent event = m_queue.front(); + //check whether we can send it right away + int64_t timeToWait = + event.getAlarmTime() - getCurrentTimeMillis(); + if (timeToWait <= 0) { + m_queue.pop_front(); + //we fire only if it's still in the queue and alarm + //time has just elapsed (in case the top event + //is canceled) + fire = true; + } else { + m_lock.wait( timeToWait ); + } + m_lock.unlock(); + if (fire) { + fireEvent( event ); + } + } else { + m_lock.unlock(); + } + } + } + + private: + + /** + * The type of timer events queue. + */ + typedef deque > QueueType; + + /** + * The current event ID, auto-incremented each time a new event + * is created. + */ + TimerId m_currentEventID; + + /** + * The queue of timer events sorted by {@link TimerEvent#alarmTime}. + */ + QueueType m_queue; + + /** + * The lock used to guard {@link #m_queue}. + */ + Lock m_lock; + + /** + * The thread that triggers alarms. + */ + CXXThread > m_workerThread; + + /** + * Whether {@link #m_workerThread} is terminating. + */ + volatile bool m_terminating; + +}; + +template +void EventSource::fireEvent(const E &event) { + for (typename EventListeners::iterator i = m_listeners.begin(); + i != m_listeners.end(); + ++i) + { + fireEvent( *i, event ); + } +} + +template +void EventSource::fireEvent(EventListener *listener, const E &event) { + listener->eventReceived( *this, event ); +} + +} /* end of 'namespace zkfuse' */ + +#endif /* __EVENT_H__ */ diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JFloat.java b/src/contrib/zkfuse/src/log.cc old mode 100755 new mode 100644 similarity index 64% rename from zookeeper/java/src/com/yahoo/jute/compiler/JFloat.java rename to src/contrib/zkfuse/src/log.cc index bccc9cb07e5..e2bfb0dd85a --- a/zookeeper/java/src/com/yahoo/jute/compiler/JFloat.java +++ b/src/contrib/zkfuse/src/log.cc @@ -16,25 +16,21 @@ * limitations under the License. */ -package com.yahoo.jute.compiler; +#include + +#include "log.h" +using namespace std; + /** - * - * @author Milind Bhandarkar + * \brief This class encapsulates a log4cxx configuration. */ -public class JFloat extends JType { - - /** Creates a new instance of JFloat */ - public JFloat() { - super("float", "float", "float", "Float", "Float", "toFloat"); - } - - public String getSignature() { - return "f"; - } - - public String genJavaHashCode(String fname) { - return " ret = Float.floatToIntBits("+fname+");\n"; - } +class LogConfiguration { + public: + LogConfiguration(const string &file) { + PropertyConfigurator::configureAndWatch( file, 5000 ); + } +}; -} +//enforces the configuration to be initialized +static LogConfiguration logConfig( "log4cxx.properties" ); diff --git a/src/contrib/zkfuse/src/log.h b/src/contrib/zkfuse/src/log.h new file mode 100644 index 00000000000..aefce10b1d6 --- /dev/null +++ b/src/contrib/zkfuse/src/log.h @@ -0,0 +1,116 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LOG_H__ +#define __LOG_H__ + +#define ZKFUSE_NAMESPACE zkfuse +#define START_ZKFUSE_NAMESPACE namespace ZKFUSE_NAMESPACE { +#define END_ZKFUSE_NAMESPACE } +#define USING_ZKFUSE_NAMESPACE using namespace ZKFUSE_NAMESPACE; + +#include +#include +#include + +#include +#include +#include +using namespace log4cxx; +using namespace log4cxx::helpers; + +#define PRINTIP(x) ((uint8_t*)&x)[0], ((uint8_t*)&x)[1], \ + ((uint8_t*)&x)[2], ((uint8_t*)&x)[3] + +#define IPFMT "%u.%u.%u.%u" + +#define DECLARE_LOGGER(varName) \ +extern LoggerPtr varName; + +#define DEFINE_LOGGER(varName, logName) \ +static LoggerPtr varName = Logger::getLogger( logName ); + +#define MAX_BUFFER_SIZE 20000 + +#define SPRINTF_LOG_MSG(buffer, fmt, args...) \ + char buffer[MAX_BUFFER_SIZE]; \ + snprintf( buffer, MAX_BUFFER_SIZE, fmt, ##args ); + +// older versions of log4cxx don't support tracing +#ifdef LOG4CXX_TRACE +#define LOG_TRACE(logger, fmt, args...) \ + if (logger->isTraceEnabled()) { \ + SPRINTF_LOG_MSG( __tmp, fmt, ##args ); \ + LOG4CXX_TRACE( logger, __tmp ); \ + } +#else +#define LOG_TRACE(logger, fmt, args...) \ + if (logger->isDebugEnabled()) { \ + SPRINTF_LOG_MSG( __tmp, fmt, ##args ); \ + LOG4CXX_DEBUG( logger, __tmp ); \ + } +#endif + +#define LOG_DEBUG(logger, fmt, args...) \ + if (logger->isDebugEnabled()) { \ + SPRINTF_LOG_MSG( __tmp, fmt, ##args ); \ + LOG4CXX_DEBUG( logger, __tmp ); \ + } + +#define LOG_INFO(logger, fmt, args...) \ + if (logger->isInfoEnabled()) { \ + SPRINTF_LOG_MSG( __tmp, fmt, ##args ); \ + LOG4CXX_INFO( logger, __tmp ); \ + } + +#define LOG_WARN(logger, fmt, args...) \ + if (logger->isWarnEnabled()) { \ + SPRINTF_LOG_MSG( __tmp, fmt, ##args ); \ + LOG4CXX_WARN( logger, __tmp ); \ + } + +#define LOG_ERROR(logger, fmt, args...) \ + if (logger->isErrorEnabled()) { \ + SPRINTF_LOG_MSG( __tmp, fmt, ##args ); \ + LOG4CXX_ERROR( logger, __tmp ); \ + } + +#define LOG_FATAL(logger, fmt, args...) \ + if (logger->isFatalEnabled()) { \ + SPRINTF_LOG_MSG( __tmp, fmt, ##args ); \ + LOG4CXX_FATAL( logger, __tmp ); \ + } + +#ifdef DISABLE_TRACE +# define TRACE(logger, x) +#else +# define TRACE(logger, x) \ +class Trace { \ + public: \ + Trace(const void* p) : _p(p) { \ + LOG_TRACE(logger, "%s %p Enter", __PRETTY_FUNCTION__, p); \ + } \ + ~Trace() { \ + LOG_TRACE(logger, "%s %p Exit", __PRETTY_FUNCTION__, _p); \ + } \ + const void* _p; \ +} traceObj(x); +#endif /* DISABLE_TRACE */ + +#endif /* __LOG_H__ */ + diff --git a/src/contrib/zkfuse/src/log4cxx.properties b/src/contrib/zkfuse/src/log4cxx.properties new file mode 100644 index 00000000000..792c0315222 --- /dev/null +++ b/src/contrib/zkfuse/src/log4cxx.properties @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=TRACE, A1 +# A1 is set to be a ConsoleAppender. +log4j.appender.A1=org.apache.log4cxx.ConsoleAppender +# A1 uses PatternLayout. +log4j.appender.A1.layout=org.apache.log4cxx.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n +log4j.category.zkfuse=TRACE + diff --git a/src/contrib/zkfuse/src/mutex.h b/src/contrib/zkfuse/src/mutex.h new file mode 100644 index 00000000000..86c46043414 --- /dev/null +++ b/src/contrib/zkfuse/src/mutex.h @@ -0,0 +1,169 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MUTEX_H__ +#define __MUTEX_H__ + +#include +#include +#include + +#include "log.h" + +START_ZKFUSE_NAMESPACE + +class Cond; + +class Mutex { + friend class Cond; + public: + Mutex() { + pthread_mutexattr_init( &m_mutexAttr ); + pthread_mutexattr_settype( &m_mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP ); + pthread_mutex_init( &mutex, &m_mutexAttr ); + } + ~Mutex() { + pthread_mutex_destroy(&mutex); + pthread_mutexattr_destroy( &m_mutexAttr ); + } + void Acquire() { Lock(); } + void Release() { Unlock(); } + void Lock() { + pthread_mutex_lock(&mutex); + } + int TryLock() { + return pthread_mutex_trylock(&mutex); + } + void Unlock() { + pthread_mutex_unlock(&mutex); + } + private: + pthread_mutex_t mutex; + pthread_mutexattr_t m_mutexAttr; +}; + +class AutoLock { + public: + AutoLock(Mutex& mutex) : _mutex(mutex) { + mutex.Lock(); + } + ~AutoLock() { + _mutex.Unlock(); + } + private: + friend class AutoUnlockTemp; + Mutex& _mutex; +}; + +class AutoUnlockTemp { + public: + AutoUnlockTemp(AutoLock & autoLock) : _autoLock(autoLock) { + _autoLock._mutex.Unlock(); + } + ~AutoUnlockTemp() { + _autoLock._mutex.Lock(); + } + private: + AutoLock & _autoLock; +}; + +class Cond { + public: + Cond() { + static pthread_condattr_t attr; + static bool inited = false; + if(!inited) { + inited = true; + pthread_condattr_init(&attr); + } + pthread_cond_init(&_cond, &attr); + } + ~Cond() { + pthread_cond_destroy(&_cond); + } + + void Wait(Mutex& mutex) { + pthread_cond_wait(&_cond, &mutex.mutex); + } + + bool Wait(Mutex& mutex, long long int timeout) { + struct timeval now; + gettimeofday( &now, NULL ); + struct timespec abstime; + int64_t microSecs = now.tv_sec * 1000000LL + now.tv_usec; + microSecs += timeout * 1000; + abstime.tv_sec = microSecs / 1000000LL; + abstime.tv_nsec = (microSecs % 1000000LL) * 1000; + if (pthread_cond_timedwait(&_cond, &mutex.mutex, &abstime) == ETIMEDOUT) { + return false; + } else { + return true; + } + } + + void Signal() { + pthread_cond_signal(&_cond); + } + + private: + pthread_cond_t _cond; +}; + +/** + * A wrapper class for {@link Mutex} and {@link Cond}. + */ +class Lock { + public: + + void lock() { + m_mutex.Lock(); + } + + void unlock() { + m_mutex.Unlock(); + } + + void wait() { + m_cond.Wait( m_mutex ); + } + + bool wait(long long int timeout) { + return m_cond.Wait( m_mutex, timeout ); + } + + void notify() { + m_cond.Signal(); + } + + private: + + /** + * The mutex. + */ + Mutex m_mutex; + + /** + * The condition associated with this lock's mutex. + */ + Cond m_cond; +}; + +END_ZKFUSE_NAMESPACE + +#endif /* __MUTEX_H__ */ + diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JLong.java b/src/contrib/zkfuse/src/thread.cc old mode 100755 new mode 100644 similarity index 62% rename from zookeeper/java/src/com/yahoo/jute/compiler/JLong.java rename to src/contrib/zkfuse/src/thread.cc index c22b540b473..f1ed8166fee --- a/zookeeper/java/src/com/yahoo/jute/compiler/JLong.java +++ b/src/contrib/zkfuse/src/thread.cc @@ -16,24 +16,26 @@ * limitations under the License. */ -package com.yahoo.jute.compiler; +#include -/** - * - * @author Milind Bhandarkar - */ -public class JLong extends JType { - - /** Creates a new instance of JLong */ - public JLong() { - super("int64_t", "int64_t", "long", "Long", "Long", "toLong"); - } - - public String getSignature() { - return "l"; - } - - public String genJavaHashCode(String fname) { - return " ret = (int) ("+fname+"^("+fname+">>>32));\n"; +#include "thread.h" + +DEFINE_LOGGER( LOG, "Thread" ) + +START_ZKFUSE_NAMESPACE + +void Thread::Create(void* ctx, ThreadFunc func) +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, _stackSize); + int ret = pthread_create(&mThread, &attr, func, ctx); + if(ret != 0) { + LOG_FATAL( LOG, "pthread_create failed: %s", strerror(errno) ); } + // pthread_attr_destroy(&attr); + _ctx = ctx; + _func = func; } + +END_ZKFUSE_NAMESPACE diff --git a/src/contrib/zkfuse/src/thread.h b/src/contrib/zkfuse/src/thread.h new file mode 100644 index 00000000000..0ed12d7f645 --- /dev/null +++ b/src/contrib/zkfuse/src/thread.h @@ -0,0 +1,99 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __THREAD_H__ +#define __THREAD_H__ + +#include +#include +#include +#include + +#include "log.h" + +START_ZKFUSE_NAMESPACE + +class Thread { + public: + static const size_t defaultStackSize = 1024 * 1024; + typedef void* (*ThreadFunc) (void*); + Thread(size_t stackSize = defaultStackSize) + : _stackSize(stackSize), _ctx(NULL), _func(NULL) + { + memset( &mThread, 0, sizeof(mThread) ); + } + ~Thread() { } + + void Create(void* ctx, ThreadFunc func); + void Join() { + //avoid SEGFAULT because of unitialized mThread + //in case Create(...) was never called + if (_func != NULL) { + pthread_join(mThread, 0); + } + } + private: + pthread_t mThread; + void *_ctx; + ThreadFunc _func; + size_t _stackSize; +}; + + +template +struct ThreadContext { + typedef void (T::*FuncPtr) (void); + ThreadContext(T& ctx, FuncPtr func) : _ctx(ctx), _func(func) {} + void run(void) { + (_ctx.*_func)(); + } + T& _ctx; + FuncPtr _func; +}; + +template +void* ThreadExec(void *obj) { + ThreadContext* tc = (ThreadContext*)(obj); + assert(tc != 0); + tc->run(); + return 0; +} + +template +class CXXThread : public Thread { + public: + typedef void (T::*FuncPtr) (void); + CXXThread(size_t stackSize = Thread::defaultStackSize) + : Thread(stackSize), ctx(0) {} + ~CXXThread() { if (ctx) delete ctx; } + + void Create(T& obj, FuncPtr func) { + assert(ctx == 0); + ctx = new ThreadContext(obj, func); + Thread::Create(ctx, ThreadExec); + } + + private: + ThreadContext* ctx; +}; + + +END_ZKFUSE_NAMESPACE + +#endif /* __THREAD_H__ */ + diff --git a/src/contrib/zkfuse/src/zkadapter.cc b/src/contrib/zkfuse/src/zkadapter.cc new file mode 100644 index 00000000000..7dfb9078fc3 --- /dev/null +++ b/src/contrib/zkfuse/src/zkadapter.cc @@ -0,0 +1,884 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "blockingqueue.h" +#include "thread.h" +#include "zkadapter.h" + +using namespace std; +using namespace zk; + +DEFINE_LOGGER( LOG, "zookeeper.adapter" ) +DEFINE_LOGGER( ZK_LOG, "zookeeper.core" ) + +/** + * \brief A helper class to initialize ZK logging. + */ +class InitZooKeeperLogging +{ + public: + InitZooKeeperLogging() { + if (ZK_LOG->isDebugEnabled() +#ifdef LOG4CXX_TRACE + || ZK_LOG->isTraceEnabled() +#endif + ) + { + zoo_set_debug_level( ZOO_LOG_LEVEL_DEBUG ); + } else if (ZK_LOG->isInfoEnabled()) { + zoo_set_debug_level( ZOO_LOG_LEVEL_INFO ); + } else if (ZK_LOG->isWarnEnabled()) { + zoo_set_debug_level( ZOO_LOG_LEVEL_WARN ); + } else { + zoo_set_debug_level( ZOO_LOG_LEVEL_ERROR ); + } + } +}; + +using namespace std; + +namespace zk +{ + +/** + * \brief This class provides logic for checking if a request can be retried. + */ +class RetryHandler +{ + public: + RetryHandler(const ZooKeeperConfig &zkConfig) + : m_zkConfig(zkConfig) + { + if (zkConfig.getAutoReconnect()) { + retries = 2; + } else { + retries = 0; + } + } + + /** + * \brief Attempts to fix a side effect of the given RC. + * + * @param rc the ZK error code + * @return whether the error code has been handled and the caller should + * retry an operation the caused this error + */ + bool handleRC(int rc) + { + TRACE( LOG, "handleRC" ); + + //check if the given error code is recoverable + if (!retryOnError(rc)) { + return false; + } + LOG_TRACE( LOG, "RC: %d, retries left: %d", rc, retries ); + if (retries-- > 0) { + return true; + } else { + return false; + } + } + + private: + /** + * The ZK config. + */ + const ZooKeeperConfig &m_zkConfig; + + /** + * The number of outstanding retries. + */ + int retries; + + /** + * Checks whether the given error entitles this adapter + * to retry the previous operation. + * + * @param zkErrorCode one of the ZK error code + */ + static bool retryOnError(int zkErrorCode) + { + return (zkErrorCode == ZCONNECTIONLOSS || + zkErrorCode == ZOPERATIONTIMEOUT); + } +}; + + +//the implementation of the global ZK event watcher +void zkWatcher(zhandle_t *zh, int type, int state, const char *path, + void *watcherCtx) +{ + TRACE( LOG, "zkWatcher" ); + + //a workaround for buggy ZK API + string sPath = + (path == NULL || + state == ZOO_SESSION_EVENT || + state == ZOO_NOTWATCHING_EVENT) + ? "" + : string(path); + LOG_INFO( LOG, + "Received a ZK event - type: %d, state: %d, path: '%s'", + type, state, sPath.c_str() ); + ZooKeeperAdapter *zka = (ZooKeeperAdapter *)zoo_get_context(zh); + if (zka != NULL) { + zka->enqueueEvent( type, state, sPath ); + } else { + LOG_ERROR( LOG, + "Skipping ZK event (type: %d, state: %d, path: '%s'), " + "because ZK passed no context", + type, state, sPath.c_str() ); + } +} + + + +// ======================================================================= + +ZooKeeperAdapter::ZooKeeperAdapter(ZooKeeperConfig config, + ZKEventListener *listener, + bool establishConnection) + throw(ZooKeeperException) + : m_zkConfig(config), + mp_zkHandle(NULL), + m_terminating(false), + m_connected(false), + m_state(AS_DISCONNECTED) +{ + TRACE( LOG, "ZooKeeperAdapter" ); + + resetRemainingConnectTimeout(); + + //enforce setting up appropriate ZK log level + static InitZooKeeperLogging INIT_ZK_LOGGING; + + if (listener != NULL) { + addListener(listener); + } + + //start the event dispatcher thread + m_eventDispatcher.Create( *this, &ZooKeeperAdapter::processEvents ); + + //start the user event dispatcher thread + m_userEventDispatcher.Create( *this, &ZooKeeperAdapter::processUserEvents ); + + //optionally establish the connection + if (establishConnection) { + reconnect(); + } +} + +ZooKeeperAdapter::~ZooKeeperAdapter() +{ + TRACE( LOG, "~ZooKeeperAdapter" ); + + try { + disconnect(); + } catch (std::exception &e) { + LOG_ERROR( LOG, + "An exception while disconnecting from ZK: %s", + e.what() ); + } + m_terminating = true; + m_userEventDispatcher.Join(); + m_eventDispatcher.Join(); +} + +void +ZooKeeperAdapter::validatePath(const string &path) throw(ZooKeeperException) +{ + TRACE( LOG, "validatePath" ); + + if (path.find( "/" ) != 0) { + throw ZooKeeperException( string("Node path must start with '/' but" + "it was '") + + path + + "'" ); + } + if (path.length() > 1) { + if (path.rfind( "/" ) == path.length() - 1) { + throw ZooKeeperException( string("Node path must not end with " + "'/' but it was '") + + path + + "'" ); + } + if (path.find( "//" ) != string::npos) { + throw ZooKeeperException( string("Node path must not contain " + "'//' but it was '") + + path + + "'" ); + } + } +} + +void +ZooKeeperAdapter::disconnect() +{ + TRACE( LOG, "disconnect" ); + LOG_TRACE( LOG, "mp_zkHandle: %p, state %d", mp_zkHandle, m_state ); + + m_stateLock.lock(); + if (mp_zkHandle != NULL) { + zookeeper_close( mp_zkHandle ); + mp_zkHandle = NULL; + setState( AS_DISCONNECTED ); + } + m_stateLock.unlock(); +} + +void +ZooKeeperAdapter::reconnect() throw(ZooKeeperException) +{ + TRACE( LOG, "reconnect" ); + + m_stateLock.lock(); + //clear the connection state + disconnect(); + + //establish a new connection to ZooKeeper + mp_zkHandle = zookeeper_init( m_zkConfig.getHosts().c_str(), + zkWatcher, + m_zkConfig.getLeaseTimeout(), + NULL, this, 0); + resetRemainingConnectTimeout(); + if (mp_zkHandle != NULL) { + setState( AS_CONNECTING ); + m_stateLock.unlock(); + } else { + m_stateLock.unlock(); + throw ZooKeeperException( + string("Unable to connect to ZK running at '") + + m_zkConfig.getHosts() + "'" ); + } + + LOG_DEBUG( LOG, "mp_zkHandle: %p, state %d", mp_zkHandle, m_state ); +} + +void +ZooKeeperAdapter::handleEvent(int type, int state, const string &path) +{ + TRACE( LOG, "handleEvent" ); + LOG_TRACE( LOG, + "type: %d, state %d, path: %s", + type, state, path.c_str() ); + Listener2Context context, context2; + //ignore internal ZK events + if (type != ZOO_SESSION_EVENT && type != ZOO_NOTWATCHING_EVENT) { + m_zkContextsMutex.Acquire(); + //check if the user context is available + if (type == ZOO_CHANGED_EVENT || type == ZOO_DELETED_EVENT) { + //we may have two types of interest here, + //in this case lets try to notify twice + context = findAndRemoveListenerContext( GET_NODE_DATA, path ); + context2 = findAndRemoveListenerContext( NODE_EXISTS, path ); + if (context.empty()) { + //make sure that the 2nd context is NULL and + // assign it to the 1st one + context = context2; + context2.clear(); + } + } else if (type == ZOO_CHILD_EVENT) { + context = findAndRemoveListenerContext( GET_NODE_CHILDREN, path ); + } else if (type == ZOO_CREATED_EVENT) { + context = findAndRemoveListenerContext( NODE_EXISTS, path ); + } + m_zkContextsMutex.Release(); + } + + handleEvent( type, state, path, context ); + if (!context2.empty()) { + handleEvent( type, state, path, context2 ); + } +} + +void +ZooKeeperAdapter::handleEvent(int type, + int state, + const string &path, + const Listener2Context &listeners) +{ + TRACE( LOG, "handleEvents" ); + + if (listeners.empty()) { + //propagate with empty context + ZKWatcherEvent event(type, state, path); + fireEvent( event ); + } else { + for (Listener2Context::const_iterator i = listeners.begin(); + i != listeners.end(); + ++i) { + ZKWatcherEvent event(type, state, path, i->second); + if (i->first != NULL) { + fireEvent( i->first, event ); + } else { + fireEvent( event ); + } + } + } +} + +void +ZooKeeperAdapter::enqueueEvent(int type, int state, const string &path) +{ + TRACE( LOG, "enqueueEvents" ); + + m_events.put( ZKWatcherEvent( type, state, path ) ); +} + +void +ZooKeeperAdapter::processEvents() +{ + TRACE( LOG, "processEvents" ); + + while (!m_terminating) { + bool timedOut = false; + ZKWatcherEvent source = m_events.take( 100, &timedOut ); + if (!timedOut) { + if (source.getType() == ZOO_SESSION_EVENT) { + LOG_INFO( LOG, + "Received SESSION event, state: %d. Adapter state: %d", + source.getState(), m_state ); + m_stateLock.lock(); + if (source.getState() == ZOO_CONNECTED_STATE) { + m_connected = true; + resetRemainingConnectTimeout(); + setState( AS_CONNECTED ); + } else if (source.getState() == ZOO_CONNECTING_STATE) { + m_connected = false; + setState( AS_CONNECTING ); + } else if (source.getState() == ZOO_EXPIRED_SESSION_STATE) { + LOG_INFO( LOG, "Received EXPIRED_SESSION event" ); + setState( AS_SESSION_EXPIRED ); + } + m_stateLock.unlock(); + } + m_userEvents.put( source ); + } + } +} + +void +ZooKeeperAdapter::processUserEvents() +{ + TRACE( LOG, "processUserEvents" ); + + while (!m_terminating) { + bool timedOut = false; + ZKWatcherEvent source = m_userEvents.take( 100, &timedOut ); + if (!timedOut) { + try { + handleEvent( source.getType(), + source.getState(), + source.getPath() ); + } catch (std::exception &e) { + LOG_ERROR( LOG, + "Unable to process event (type: %d, state: %d, " + "path: %s), because of exception: %s", + source.getType(), + source.getState(), + source.getPath().c_str(), + e.what() ); + } + } + } +} + +void +ZooKeeperAdapter::registerContext(WatchableMethod method, + const string &path, + ZKEventListener *listener, + ContextType context) +{ + TRACE( LOG, "registerContext" ); + + m_zkContexts[method][path][listener] = context; +} + +ZooKeeperAdapter::Listener2Context +ZooKeeperAdapter::findAndRemoveListenerContext(WatchableMethod method, + const string &path) +{ + TRACE( LOG, "findAndRemoveListenerContext" ); + + Listener2Context listeners; + Path2Listener2Context::iterator elem = m_zkContexts[method].find( path ); + if (elem != m_zkContexts[method].end()) { + listeners = elem->second; + m_zkContexts[method].erase( elem ); + } + return listeners; +} + +void +ZooKeeperAdapter::setState(AdapterState newState) +{ + TRACE( LOG, "setState" ); + if (newState != m_state) { + LOG_INFO( LOG, "Adapter state transition: %d -> %d", m_state, newState ); + m_state = newState; + m_stateLock.notify(); + } else { + LOG_TRACE( LOG, "New state same as the current: %d", newState ); + } +} + + +//TODO move this code to verifyConnection so reconnect() +//is called from one place only +void +ZooKeeperAdapter::waitUntilConnected() + throw(ZooKeeperException) +{ + TRACE( LOG, "waitUntilConnected" ); + long long int timeout = getRemainingConnectTimeout(); + LOG_INFO( LOG, + "Waiting up to %lld ms until a connection to ZK is established", + timeout ); + bool connected; + if (timeout > 0) { + long long int toWait = timeout; + while (m_state != AS_CONNECTED && toWait > 0) { + //check if session expired and reconnect if so + if (m_state == AS_SESSION_EXPIRED) { + LOG_INFO( LOG, + "Reconnecting because the current session has expired" ); + reconnect(); + } + struct timeval now; + gettimeofday( &now, NULL ); + int64_t milliSecs = -(now.tv_sec * 1000LL + now.tv_usec / 1000); + LOG_TRACE( LOG, "About to wait %lld ms", toWait ); + m_stateLock.wait( toWait ); + gettimeofday( &now, NULL ); + milliSecs += now.tv_sec * 1000LL + now.tv_usec / 1000; + toWait -= milliSecs; + } + waitedForConnect( timeout - toWait ); + LOG_INFO( LOG, "Waited %lld ms", timeout - toWait ); + } + connected = (m_state == AS_CONNECTED); + if (!connected) { + if (timeout > 0) { + LOG_WARN( LOG, "Timed out while waiting for connection to ZK" ); + throw ZooKeeperException("Timed out while waiting for " + "connection to ZK"); + } else { + LOG_ERROR( LOG, "Global timeout expired and still not connected to ZK" ); + throw ZooKeeperException("Global timeout expired and still not " + "connected to ZK"); + } + } + LOG_INFO( LOG, "Connected!" ); +} + +void +ZooKeeperAdapter::verifyConnection() throw(ZooKeeperException) +{ + TRACE( LOG, "verifyConnection" ); + + m_stateLock.lock(); + try { + if (m_state == AS_DISCONNECTED) { + throw ZooKeeperException("Disconnected from ZK. " \ + "Please use reconnect() before attempting to use any ZK API"); + } else if (m_state != AS_CONNECTED) { + LOG_TRACE( LOG, "Checking if need to reconnect..." ); + //we are not connected, so check if connection in progress... + if (m_state != AS_CONNECTING) { + LOG_TRACE( LOG, + "yes. Checking if allowed to auto-reconnect..." ); + //...not in progres, so check if we can reconnect + if (!m_zkConfig.getAutoReconnect()) { + //...too bad, disallowed :( + LOG_TRACE( LOG, "no. Sorry." ); + throw ZooKeeperException("ZK connection is down and " + "auto-reconnect is not allowed"); + } else { + LOG_TRACE( LOG, "...yes. About to reconnect" ); + } + //...we are good to retry the connection + reconnect(); + } else { + LOG_TRACE( LOG, "...no, already in CONNECTING state" ); + } + //wait until the connection is established + waitUntilConnected(); + } + } catch (ZooKeeperException &e) { + m_stateLock.unlock(); + throw; + } + m_stateLock.unlock(); +} + +bool +ZooKeeperAdapter::createNode(const string &path, + const string &value, + int flags, + bool createAncestors, + string &returnPath) + throw(ZooKeeperException) +{ + TRACE( LOG, "createNode (internal)" ); + validatePath( path ); + + const int MAX_PATH_LENGTH = 1024; + char realPath[MAX_PATH_LENGTH]; + realPath[0] = 0; + + int rc; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + rc = zoo_create( mp_zkHandle, + path.c_str(), + value.c_str(), + value.length(), + &ZOO_OPEN_ACL_UNSAFE, + flags, + realPath, + MAX_PATH_LENGTH ); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) { + if (rc == ZNODEEXISTS) { + //the node already exists + LOG_WARN( LOG, "Error %d for %s", rc, path.c_str() ); + return false; + } else if (rc == ZNONODE && createAncestors) { + LOG_WARN( LOG, "Error %d for %s", rc, path.c_str() ); + //one of the ancestors doesn't exist so lets start from the root + //and make sure the whole path exists, creating missing nodes if + //necessary + for (string::size_type pos = 1; pos != string::npos; ) { + pos = path.find( "/", pos ); + if (pos != string::npos) { + try { + createNode( path.substr( 0, pos ), "", 0, true ); + } catch (ZooKeeperException &e) { + throw ZooKeeperException( string("Unable to create " + "node ") + + path, + rc ); + } + pos++; + } else { + //no more path components + return createNode( path, value, flags, false, returnPath ); + } + } + } + LOG_ERROR( LOG,"Error %d for %s", rc, path.c_str() ); + throw ZooKeeperException( string("Unable to create node ") + + path, + rc ); + } else { + LOG_INFO( LOG, "%s has been created", realPath ); + returnPath = string( realPath ); + return true; + } +} + +bool +ZooKeeperAdapter::createNode(const string &path, + const string &value, + int flags, + bool createAncestors) + throw(ZooKeeperException) +{ + TRACE( LOG, "createNode" ); + + string createdPath; + return createNode( path, value, flags, createAncestors, createdPath ); +} + +int64_t +ZooKeeperAdapter::createSequence(const string &path, + const string &value, + int flags, + bool createAncestors) + throw(ZooKeeperException) +{ + TRACE( LOG, "createSequence" ); + + string createdPath; + bool result = createNode( path, + value, + flags | ZOO_SEQUENCE, + createAncestors, + createdPath ); + if (!result) { + return -1; + } else { + //extract sequence number from the returned path + if (createdPath.find( path ) != 0) { + throw ZooKeeperException( string("Expecting returned path '") + + createdPath + + "' to start with '" + + path + + "'" ); + } + string seqSuffix = + createdPath.substr( path.length(), + createdPath.length() - path.length() ); + char *ptr = NULL; + int64_t seq = strtol( seqSuffix.c_str(), &ptr, 10 ); + if (ptr != NULL && *ptr != '\0') { + throw ZooKeeperException( string("Expecting a number but got ") + + seqSuffix ); + } + return seq; + } +} + +bool +ZooKeeperAdapter::deleteNode(const string &path, + bool recursive, + int version) + throw(ZooKeeperException) +{ + TRACE( LOG, "deleteNode" ); + + validatePath( path ); + + int rc; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + rc = zoo_delete( mp_zkHandle, path.c_str(), version ); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) { + if (rc == ZNONODE) { + LOG_WARN( LOG, "Error %d for %s", rc, path.c_str() ); + return false; + } + if (rc == ZNOTEMPTY && recursive) { + LOG_WARN( LOG, "Error %d for %s", rc, path.c_str() ); + //get all children and delete them recursively... + vector nodeList; + getNodeChildren( nodeList, path, false ); + for (vector::const_iterator i = nodeList.begin(); + i != nodeList.end(); + ++i) { + deleteNode( *i, true ); + } + //...and finally attempt to delete the node again + return deleteNode( path, false ); + } + LOG_ERROR( LOG, "Error %d for %s", rc, path.c_str() ); + throw ZooKeeperException( string("Unable to delete node ") + path, + rc ); + } else { + LOG_INFO( LOG, "%s has been deleted", path.c_str() ); + return true; + } +} + +bool +ZooKeeperAdapter::nodeExists(const string &path, + ZKEventListener *listener, + void *context, Stat *stat) + throw(ZooKeeperException) +{ + TRACE( LOG, "nodeExists" ); + + validatePath( path ); + + struct Stat tmpStat; + if (stat == NULL) { + stat = &tmpStat; + } + memset( stat, 0, sizeof(Stat) ); + + int rc; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + if (context != NULL) { + m_zkContextsMutex.Acquire(); + rc = zoo_exists( mp_zkHandle, + path.c_str(), + (listener != NULL ? 1 : 0), + stat ); + if (rc == ZOK || rc == ZNONODE) { + registerContext( NODE_EXISTS, path, listener, context ); + } + m_zkContextsMutex.Release(); + } else { + rc = zoo_exists( mp_zkHandle, + path.c_str(), + (listener != NULL ? 1 : 0), + stat ); + } + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) { + if (rc == ZNONODE) { + LOG_TRACE( LOG, "Node %s does not exist", path.c_str() ); + return false; + } + LOG_ERROR( LOG, "Error %d for %s", rc, path.c_str() ); + throw ZooKeeperException( + string("Unable to check existence of node ") + path, + rc ); + } else { + return true; + } +} + +void +ZooKeeperAdapter::getNodeChildren(vector &nodeList, + const string &path, + ZKEventListener *listener, + void *context) + throw (ZooKeeperException) +{ + TRACE( LOG, "getNodeChildren" ); + + validatePath( path ); + + String_vector children; + memset( &children, 0, sizeof(children) ); + + int rc; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + if (context != NULL) { + m_zkContextsMutex.Acquire(); + rc = zoo_get_children( mp_zkHandle, + path.c_str(), + (listener != NULL ? 1 : 0), + &children ); + if (rc == ZOK) { + registerContext( GET_NODE_CHILDREN, path, listener, context ); + } + m_zkContextsMutex.Release(); + } else { + rc = zoo_get_children( mp_zkHandle, + path.c_str(), + (listener != NULL ? 1 : 0), + &children ); + } + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) { + LOG_ERROR( LOG, "Error %d for %s", rc, path.c_str() ); + throw ZooKeeperException( string("Unable to get children of node ") + + path, + rc ); + } else { + for (int i = 0; i < children.count; ++i) { + //convert each child's path from relative to absolute + string absPath(path); + if (path != "/") { + absPath.append( "/" ); + } + absPath.append( children.data[i] ); + nodeList.push_back( absPath ); + } + //make sure the order is always deterministic + sort( nodeList.begin(), nodeList.end() ); + } +} + +string +ZooKeeperAdapter::getNodeData(const string &path, + ZKEventListener *listener, + void *context, Stat *stat) + throw(ZooKeeperException) +{ + TRACE( LOG, "getNodeData" ); + + validatePath( path ); + + const int MAX_DATA_LENGTH = 128 * 1024; + char buffer[MAX_DATA_LENGTH]; + memset( buffer, 0, MAX_DATA_LENGTH ); + struct Stat tmpStat; + if (stat == NULL) { + stat = &tmpStat; + } + memset( stat, 0, sizeof(Stat) ); + + int rc; + int len; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + len = MAX_DATA_LENGTH - 1; + if (context != NULL) { + m_zkContextsMutex.Acquire(); + rc = zoo_get( mp_zkHandle, + path.c_str(), + (listener != NULL ? 1 : 0), + buffer, &len, stat ); + if (rc == ZOK) { + registerContext( GET_NODE_DATA, path, listener, context ); + } + m_zkContextsMutex.Release(); + } else { + rc = zoo_get( mp_zkHandle, + path.c_str(), + (listener != NULL ? 1 : 0), + buffer, &len, stat ); + } + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) { + LOG_ERROR( LOG, "Error %d for %s", rc, path.c_str() ); + throw ZooKeeperException( + string("Unable to get data of node ") + path, rc + ); + } else { + if (len == -1) { + len = 0; + } + return string( buffer, len ); + } +} + +void +ZooKeeperAdapter::setNodeData(const string &path, + const string &value, + int version) + throw(ZooKeeperException) +{ + TRACE( LOG, "setNodeData" ); + + validatePath( path ); + + int rc; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + rc = zoo_set( mp_zkHandle, + path.c_str(), + value.c_str(), + value.length(), + version); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) { + LOG_ERROR( LOG, "Error %d for %s", rc, path.c_str() ); + throw ZooKeeperException( string("Unable to set data for node ") + + path, + rc ); + } +} + +} /* end of 'namespace zk' */ + diff --git a/src/contrib/zkfuse/src/zkadapter.h b/src/contrib/zkfuse/src/zkadapter.h new file mode 100644 index 00000000000..8d4d1d57f0a --- /dev/null +++ b/src/contrib/zkfuse/src/zkadapter.h @@ -0,0 +1,718 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __ZKADAPTER_H__ +#define __ZKADAPTER_H__ + +#include +#include +#include + +extern "C" { +#include "zookeeper.h" +} + +#include "log.h" +#include "mutex.h" +#include "thread.h" +#include "blockingqueue.h" +#include "event.h" + +using namespace std; +using namespace zkfuse; + +namespace zk { + +/** + * \brief A cluster related exception. + */ +class ZooKeeperException : + public std::exception +{ + public: + + /** + * \brief Constructor. + * + * @param msg the detailed message associated with this exception + */ + ZooKeeperException(const string &msg) : + m_message(msg), m_zkErrorCode(0) + {} + + /** + * \brief Constructor. + * + * @param msg the detailed message associated with this exception + * @param errorCode the ZK error code associated with this exception + */ + ZooKeeperException(const string &msg, int errorCode) : + m_zkErrorCode(errorCode) + { + char tmp[100]; + sprintf( tmp, " (ZK error code: %d)", errorCode ); + m_message = msg + tmp; + } + + /** + * \brief Destructor. + */ + ~ZooKeeperException() throw() {} + + /** + * \brief Returns detailed description of the exception. + */ + const char *what() const throw() { + return m_message.c_str(); + } + + /** + * \brief Returns the ZK error code. + */ + int getZKErrorCode() const { + return m_zkErrorCode; + } + + private: + + /** + * The detailed message associated with this exception. + */ + string m_message; + + /** + * The optional error code received from ZK. + */ + int m_zkErrorCode; + +}; + +/** + * \brief This class encapsulates configuration of a ZK client. + */ +class ZooKeeperConfig +{ + public: + + /** + * \brief Constructor. + * + * @param hosts the comma separated list of host and port pairs of ZK nodes + * @param leaseTimeout the lease timeout (heartbeat) + * @param autoReconnect whether to allow for auto-reconnect + * @param connectTimeout the connect timeout, in milliseconds; + */ + ZooKeeperConfig(const string &hosts, + int leaseTimeout, + bool autoReconnect = true, + long long int connectTimeout = 15000) : + m_hosts(hosts), m_leaseTimeout(leaseTimeout), + m_autoReconnect(autoReconnect), m_connectTimeout(connectTimeout) {} + + /** + * \brief Returns the list of ZK hosts to connect to. + */ + string getHosts() const { return m_hosts; } + + /** + * \brief Returns the lease timeout. + */ + int getLeaseTimeout() const { return m_leaseTimeout; } + + /** + * \brief Returns whether {@link ZooKeeperAdapter} should attempt + * \brief to automatically reconnect in case of a connection failure. + */ + bool getAutoReconnect() const { return m_autoReconnect; } + + /** + * \brief Gets the connect timeout. + * + * @return the connect timeout + */ + long long int getConnectTimeout() const { return m_connectTimeout; } + + private: + + /** + * The host addresses of ZK nodes. + */ + const string m_hosts; + + /** + * The ZK lease timeout. + */ + const int m_leaseTimeout; + + /** + * True if this adapater should attempt to autoreconnect in case + * the current session has been dropped. + */ + const bool m_autoReconnect; + + /** + * How long to wait, in milliseconds, before a connection + * is established to ZK. + */ + const long long int m_connectTimeout; + +}; + +/** + * \brief A data value object representing a watcher event received from the ZK. + */ +class ZKWatcherEvent +{ + public: + + /** + * \brief The type representing the user's context. + */ + typedef void *ContextType; + + /** + * \brief Constructor. + * + * @param type the type of this event + * @param state the state of this event + * @param path the corresponding path, may be empty for some event types + * @param context the user specified context; possibly NULL + */ + ZKWatcherEvent() : + m_type(-1), m_state(-1), m_path(""), mp_context(NULL) {} + + /** + * \brief Constructor. + * + * @param type the type of this event + * @param state the state of this event + * @param path the corresponding path, may be empty for some event types + * @param context the user specified context; possibly NULL + */ + ZKWatcherEvent(int type, int state, const string &path, + ContextType context = NULL) : + m_type(type), m_state(state), m_path(path), mp_context(context) {} + + int getType() const { return m_type; } + int getState() const { return m_state; } + string const &getPath() const { return m_path; } + ContextType getContext() const { return mp_context; } + + bool operator==(const ZKWatcherEvent &we) const { + return m_type == we.m_type && m_state == we.m_state + && m_path == we.m_path && mp_context == we.mp_context; + } + + private: + + /** + * The type of this event. It can be either ZOO_CREATED_EVENT, ZOO_DELETED_EVENT, + * ZOO_CHANGED_EVENT, ZOO_CHILD_EVENT, ZOO_SESSION_EVENT or ZOO_NOTWATCHING_EVENT. + * See zookeeper.h for more details. + */ + const int m_type; + + /** + * The state of ZK at the time of sending this event. + * It can be either ZOO_CONNECTING_STATE, ZOO_ASSOCIATING_STATE, + * ZOO_CONNECTED_STATE, ZOO_EXPIRED_SESSION_STATE or AUTH_FAILED_STATE. + * See {@file zookeeper.h} for more details. + */ + const int m_state; + + /** + * The corresponding path of the node in subject. It may be empty + * for some event types. + */ + const string m_path; + + /** + * The pointer to the user specified context, possibly NULL. + */ + ContextType mp_context; + +}; + +/** + * \brief The type definition of ZK event source. + */ +typedef EventSource ZKEventSource; + +/** + * \brief The type definition of ZK event listener. + */ +typedef EventListener ZKEventListener; + +/** + * \brief This is a wrapper around ZK C synchrounous API. + */ +class ZooKeeperAdapter + : public ZKEventSource +{ + public: + /** + * \brief The global function that handles all ZK asynchronous notifications. + */ + friend void zkWatcher(zhandle_t *, int, int, const char *, void *watcherCtx); + + /** + * \brief The type representing the user's context. + */ + typedef void *ContextType; + + /** + * \brief The map type of ZK event listener to user specified context mapping. + */ + typedef map Listener2Context; + + /** + * \brief The map type of ZK path's to listener's contexts. + */ + typedef map Path2Listener2Context; + + /** + * \brief All possible states of this client, in respect to + * \brief connection to the ZK server. + */ + enum AdapterState { + //mp_zkHandle is NULL + AS_DISCONNECTED = 0, + //mp_zkHandle is valid but this client is reconnecting + AS_CONNECTING, + //mp_zkHandle is valid and this client is connected + AS_CONNECTED, + //mp_zkHandle is valid, however no more calls can be made to ZK API + AS_SESSION_EXPIRED + }; + + /** + * \brief Constructor. + * Attempts to create a ZK adapter, optionally connecting + * to the ZK. Note, that if the connection is to be established + * and the given listener is NULL, some events may be lost, + * as they may arrive asynchronously before this method finishes. + * + * @param config the ZK configuration + * @param listener the event listener to be used for listening + * on incoming ZK events; + * if NULL not used + * @param establishConnection whether to establish connection to the ZK + * + * @throw ZooKeeperException if cannot establish connection to the given ZK + */ + ZooKeeperAdapter(ZooKeeperConfig config, + ZKEventListener *listener = NULL, + bool establishConnection = false) + throw(ZooKeeperException); + + /** + * \brief Destructor. + */ + ~ZooKeeperAdapter(); + + /** + * \brief Returns the current config. + */ + const ZooKeeperConfig &getZooKeeperConfig() const { + return m_zkConfig; + } + + /** + * \brief Restablishes connection to the ZK. + * If this adapter is already connected, the current connection + * will be dropped and a new connection will be established. + * + * @throw ZooKeeperException if cannot establish connection to the ZK + */ + void reconnect() throw(ZooKeeperException); + + /** + * \brief Disconnects from the ZK and unregisters {@link #mp_zkHandle}. + */ + void disconnect(); + + /** + * \brief Creates a new node identified by the given path. + * This method will optionally attempt to create all missing ancestors. + * + * @param path the absolute path name of the node to be created + * @param value the initial value to be associated with the node + * @param flags the ZK flags of the node to be created + * @param createAncestors if true and there are some missing ancestor nodes, + * this method will attempt to create them + * + * @return true if the node has been successfully created; false otherwise + * @throw ZooKeeperException if the operation has failed + */ + bool createNode(const string &path, + const string &value = "", + int flags = 0, + bool createAncestors = true) + throw(ZooKeeperException); + + /** + * \brief Creates a new sequence node using the give path as the prefix. + * This method will optionally attempt to create all missing ancestors. + * + * @param path the absolute path name of the node to be created; + * @param value the initial value to be associated with the node + * @param flags the ZK flags of the sequence node to be created + * (in addition to SEQUENCE) + * @param createAncestors if true and there are some missing ancestor + * nodes, this method will attempt to create them + * + * @return the sequence number associate with newly created node, + * or -1 if it couldn't be created + * @throw ZooKeeperException if the operation has failed + */ + int64_t createSequence(const string &path, + const string &value = "", + int flags = 0, + bool createAncestors = true) + throw(ZooKeeperException); + + /** + * \brief Deletes a node identified by the given path. + * + * @param path the absolute path name of the node to be deleted + * @param recursive if true this method will attempt to remove + * all children of the given node if any exist + * @param version the expected version of the node. The function will + * fail if the actual version of the node does not match + * the expected version + * + * @return true if the node has been deleted; false otherwise + * @throw ZooKeeperException if the operation has failed + */ + bool deleteNode(const string &path, bool recursive = false, int version = -1) + throw(ZooKeeperException); + + /** + * \brief Checks whether the given node exists or not. + * + * @param path the absolute path name of the node to be checked + * @param listener the listener for ZK watcher events; + * passing non NULL effectively establishes + * a ZK watch on the given node + * @param context the user specified context that is to be passed + * in a corresponding {@link ZKWatcherEvent} at later time; + * not used if listener is NULL + * @param stat the optional node statistics to be filled in by ZK + * + * @return true if the given node exists; false otherwise + * @throw ZooKeeperException if the operation has failed + */ + bool nodeExists(const string &path, + ZKEventListener *listener = NULL, + void *context = NULL, + Stat *stat = NULL) + throw(ZooKeeperException); + + /** + * \brief Retrieves list of all children of the given node. + * + * @param path the absolute path name of the node for which to get children + * @param listener the listener for ZK watcher events; + * passing non NULL effectively establishes + * a ZK watch on the given node + * @param context the user specified context that is to be passed + * in a corresponding {@link ZKWatcherEvent} at later time; + * not used if listener is NULL + * + * @return the list of absolute paths of child nodes, possibly empty + * @throw ZooKeeperException if the operation has failed + */ + void getNodeChildren(vector &children, + const string &path, + ZKEventListener *listener = NULL, + void *context = NULL) + throw(ZooKeeperException); + + /** + * \brief Gets the given node's data. + * + * @param path the absolute path name of the node to get data from + * @param listener the listener for ZK watcher events; + * passing non NULL effectively establishes + * a ZK watch on the given node + * @param context the user specified context that is to be passed + * in a corresponding {@link ZKWatcherEvent} at later time; + * not used if listener is NULL + * @param stat the optional node statistics to be filled in by ZK + * + * @return the node's data + * @throw ZooKeeperException if the operation has failed + */ + string getNodeData(const string &path, + ZKEventListener *listener = NULL, + void *context = NULL, + Stat *stat = NULL) + throw(ZooKeeperException); + + /** + * \brief Sets the given node's data. + * + * @param path the absolute path name of the node to get data from + * @param value the node's data to be set + * @param version the expected version of the node. The function will + * fail if the actual version of the node does not match + * the expected version + * + * @throw ZooKeeperException if the operation has failed + */ + void setNodeData(const string &path, const string &value, int version = -1) + throw(ZooKeeperException); + + /** + * \brief Validates the given path to a node in ZK. + * + * @param the path to be validated + * + * @throw ZooKeeperException if the given path is not valid + * (for instance it doesn't start with "/") + */ + static void validatePath(const string &path) throw(ZooKeeperException); + + /** + * Returns the current state of this adapter. + * + * @return the current state of this adapter + * @see AdapterState + */ + AdapterState getState() const { + return m_state; + } + + private: + + /** + * This enum defines methods from this class than can trigger an event. + */ + enum WatchableMethod { + NODE_EXISTS = 0, + GET_NODE_CHILDREN, + GET_NODE_DATA + }; + + /** + * \brief Creates a new node identified by the given path. + * This method is used internally to implement {@link createNode(...)} + * and {@link createSequence(...)}. On success, this method will set + * createdPath. + * + * @param path the absolute path name of the node to be created + * @param value the initial value to be associated with the node + * @param flags the ZK flags of the node to be created + * @param createAncestors if true and there are some missing ancestor nodes, + * this method will attempt to create them + * @param createdPath the actual path of the node that has been created; + * useful for sequences + * + * @return true if the node has been successfully created; false otherwise + * @throw ZooKeeperException if the operation has failed + */ + bool createNode(const string &path, + const string &value, + int flags, + bool createAncestors, + string &createdPath) + throw(ZooKeeperException); + + /** + * Handles an asynchronous event received from the ZK. + */ + void handleEvent(int type, int state, const string &path); + + /** + * Handles an asynchronous event received from the ZK. + * This method iterates over all listeners and passes the event + * to each of them. + */ + void handleEvent(int type, int state, const string &path, + const Listener2Context &listeners); + + /** + * \brief Enqueues the given event in {@link #m_events} queue. + */ + void enqueueEvent(int type, int state, const string &path); + + /** + * \brief Processes all ZK adapter events in a loop. + */ + void processEvents(); + + /** + * \brief Processes all user events in a loop. + */ + void processUserEvents(); + + /** + * \brief Registers the given context in the {@link #m_zkContexts} + * \brief contexts map. + * + * @param method the method where the given path is being used + * @param path the path of interest + * @param listener the event listener to call back later on + * @param context the user specified context to be passed back to user + */ + void registerContext(WatchableMethod method, const string &path, + ZKEventListener *listener, ContextType context); + + /** + * \brief Attempts to find a listener to context map in the contexts' + * \brief map, based on the specified criteria. + * If the context is found, it will be removed the udnerlying map. + * + * @param method the method type identify Listener2Context map + * @param path the path to be used to search in the Listener2Context map + * + * @return the context map associated with the given method and path, + * or empty map if not found + */ + Listener2Context findAndRemoveListenerContext(WatchableMethod method, + const string &path); + + /** + * Sets the new state in case it's different then the current one. + * This method assumes that {@link #m_stateLock} has been already locked. + * + * @param newState the new state to be set + */ + void setState(AdapterState newState); + + /** + * Waits until this client gets connected. The total wait time + * is given by {@link getRemainingConnectTimeout()}. + * If a timeout elapses, this method will throw an exception. + * + * @throw ZooKeeperException if unable to connect within the given timeout + */ + void waitUntilConnected() + throw(ZooKeeperException); + + /** + * Verifies whether the connection is established, + * optionally auto reconnecting. + * + * @throw ZooKeeperConnection if this client is disconnected + * and auto-reconnect failed or was not allowed + */ + void verifyConnection() throw(ZooKeeperException); + + /** + * Returns the remaining connect timeout. The timeout resets + * to {@link #m_connectTimeout} on a successfull connection to the ZK. + * + * @return the remaining connect timeout, in milliseconds + */ + long long int getRemainingConnectTimeout() { + return m_remainingConnectTimeout; + } + + /** + * Resets the remaining connect timeout to {@link #m_connectTimeout}. + */ + void resetRemainingConnectTimeout() { + m_remainingConnectTimeout = m_zkConfig.getConnectTimeout(); + } + + /** + * Updates the remaining connect timeout to reflect the given wait time. + * + * @param time the time for how long waited so far on connect to succeed + */ + void waitedForConnect(long long time) { + m_remainingConnectTimeout -= time; + } + + private: + + /** + * The mutex use to protect {@link #m_zkContexts}. + */ + zkfuse::Mutex m_zkContextsMutex; + + /** + * The map of registered ZK paths that are being watched. + * Each entry maps a function type to another map of registered contexts. + * + * @see WatchableMethod + */ + map m_zkContexts; + + /** + * The current ZK configuration. + */ + const ZooKeeperConfig m_zkConfig; + + /** + * The current ZK session. + */ + zhandle_t *mp_zkHandle; + + /** + * The blocking queue of all events waiting to be processed by ZK adapter. + */ + BlockingQueue m_events; + + /** + * The blocking queue of all events waiting to be processed by users + * of ZK adapter. + */ + BlockingQueue m_userEvents; + + /** + * The thread that dispatches all events from {@link #m_events} queue. + */ + CXXThread m_eventDispatcher; + + /** + * The thread that dispatches all events from {@link #m_userEvents} queue. + */ + CXXThread m_userEventDispatcher; + + /** + * Whether {@link #m_eventDispatcher} is terminating. + */ + volatile bool m_terminating; + + /** + * Whether this adapter is connected to the ZK. + */ + volatile bool m_connected; + + /** + * The state of this adapter. + */ + AdapterState m_state; + + /** + * The lock used to synchronize access to {@link #m_state}. + */ + Lock m_stateLock; + + /** + * How much time left for the connect to succeed, in milliseconds. + */ + long long int m_remainingConnectTimeout; + +}; + +} /* end of 'namespace zk' */ + +#endif /* __ZKADAPTER_H__ */ diff --git a/src/contrib/zkfuse/src/zkfuse.cc b/src/contrib/zkfuse/src/zkfuse.cc new file mode 100644 index 00000000000..6a8216885fa --- /dev/null +++ b/src/contrib/zkfuse/src/zkfuse.cc @@ -0,0 +1,4492 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define FUSE_USE_VERSION 26 + +#ifdef HAVE_CONFIG_H +#include +#endif + +#undef _GNU_SOURCE +#define _GNU_SOURCE + +extern "C" { +#include +#include +} +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SETXATTR +#include +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "log.h" +#include "mutex.h" +#include "zkadapter.h" + +#define ZOOKEEPER_ROOT_CHILDREN_WATCH_BUG + +/** + Typedef for ZooKeeperAdapter::Data. +*/ +typedef std::string Data; +/** + Typedef for ZooKeeperAdapter::NodeNames. +*/ +typedef vector NodeNames; + +#define MAX_DATA_SIZE 1024; + +DEFINE_LOGGER(LOG, "zkfuse"); + +inline +uint64_t millisecsToSecs(uint64_t millisecs) +{ + return millisecs / 1000; +} +inline +uint64_t secsToMillisecs(uint64_t secs) +{ + return secs * 1000; +} +inline +uint64_t nanosecsToMillisecs(uint64_t nanosecs) +{ + return nanosecs / 1000000; +} +inline +uint64_t timespecToMillisecs(const struct timespec & ts) +{ + return secsToMillisecs(ts.tv_sec) + nanosecsToMillisecs(ts.tv_nsec); +} + +typedef boost::shared_ptr ZooKeeperAdapterSharedPtr; + +/** + * ZkFuseCommon - holds immutable configuration objects. + * + * No locks are required to access these objects. + * A ZkFuseCommon instance is considered to be a data object and may be copied. + */ +class ZkFuseCommon +{ + private: + /** + References the ZooKeeperAdapter instance to be used. + */ + ZooKeeperAdapterSharedPtr _zkAdapter; + /** + Path to the ZooKeeper root node. + */ + std::string _rootPathName; + /** + Name used to access data "file" when the ZK node has + children. + */ + std::string _dataFileName; + /** + Suffix added to path components to force interpretation of + path components as directory. This is usually only required + for the last component. For example, ZkFuse may consider + a leaf node a regular file, e.g. /a/b/c/leaf. The suffix + can be used to create child under this node, e.g. + mkdir /a/b/c/leaf{forceDirSuffix}/new_leaf. + */ + std::string _forceDirSuffix; + /** + Prefix common to all metadata nodes created by ZkFuse. + */ + std::string _metadataNamePrefix; + /** + Path component name that identifies a directory metadata node. + A directory metadata node is currently empty. It is used by ZkFuse + to create a child when mkdir is used. This prevents ZkFuse + from interpreting the new child as a regular file. + */ + std::string _dirMetadataName; + /** + Path component name that identifies a regular file metadata node. + A regular metadata node holds metadata required to implement + Posix regular file semantics, such as setting mtime. + */ + std::string _regMetadataName; + /** + Number of not-in-use nodes to cache. + */ + unsigned _cacheSize; + /** + Assume this userid owns all nodes. + */ + const uid_t _uid; + /** + Assume this groupid owns all nodes. + */ + const gid_t _gid; + /** + Blocksize used to calculate number of blocks used for stat. + */ + const unsigned _blkSize; + + public: + /** + Constructor. + */ + ZkFuseCommon() + : _zkAdapter(), + _rootPathName("/"), + _dataFileName(), + _forceDirSuffix(), + _metadataNamePrefix(".zkfuse."), + _dirMetadataName(_metadataNamePrefix + "dir"), + _regMetadataName(_metadataNamePrefix + "file"), + _cacheSize(256), + _uid(geteuid()), + _gid(getegid()), + _blkSize(8192) + { + } + /** + Get root path name. Always "/". + \see _rootPathName + */ + const std::string & getRootPathName() const + { + return _rootPathName; + } + /** + Get dataFileName - the name for synthesized files to access + ZooKeeper node data. + \see _dataFileName + */ + const std::string & getDataFileName() const + { + return _dataFileName; + } + /** + Set dataFileName. + \see getDataFileName + \see _dataFileName + */ + void setDataFileName(const std::string & dataFileName) + { + _dataFileName = dataFileName; + } + /** + Get metadataNamePrefix - the common prefix for all ZkFuse created + metadata ZooKeeper nodes. + \see _metadataNamePrefix + */ + const std::string & getMetadataNamePrefix() const + { + return _metadataNamePrefix; + } + /** + Get forceDirSuffix - the suffix added to a path component to force + the path component to be treated like a directory. + \see _forceDirSuffix + */ + const std::string & getForceDirSuffix() const + { + return _forceDirSuffix; + } + /** + Set forceDirSuffix. + \see getForceDirSuffix + \see _forceDirSuffix + */ + void setForceDirSuffix(const std::string & forceDirSuffix) + { + _forceDirSuffix = forceDirSuffix; + } + /** + Get dirMetadataName - path component name of all directory + metadata ZooKeeper nodes. + \see _dirMetadataname + */ + const std::string & getDirMetadataName() const + { + return _dirMetadataName; + } + /** + Get regMetadataName - path component name of all regular file + metadata ZooKeeper nodes. + \see _regMetadataname + */ + const std::string & getRegMetadataName() const + { + return _regMetadataName; + } + /** + Get number of not-in-use ZkFuseFile instances to to cache. + \see _cacheSize + */ + unsigned getCacheSize() const + { + return _cacheSize; + } + /** + Set cache size. + \see getCacheSize + \see _cacheSize + */ + void setCacheSize(unsigned v) + { + _cacheSize = v; + } + /** + Get userid. + \see _uid + */ + uid_t getUid() const + { + return _uid; + } + /** + Get groupid. + \see _gid + */ + gid_t getGid() const + { + return _gid; + } + /** + Get block size. + \see _blkSize + */ + unsigned getBlkSize() const + { + return _blkSize; + } + /** + Get ZooKeeperAdapter. + \see _zkAdapter. + */ + const ZooKeeperAdapterSharedPtr & getZkAdapter() const + { + return _zkAdapter; + } + /** + Set ZooKeeperAdapter. + \see _zkAdaptor + */ + void setZkAdapter(const ZooKeeperAdapterSharedPtr & zkAdapter) + { + _zkAdapter = zkAdapter; + } +}; + +/** + ZkFuseNameType - identifies the type of the ZkFuse path. + */ +enum ZkFuseNameType { + /** + ZkFuse path is not syntheiszed. + ZkFuse should use its default rules to determine the Posix representation + of the path. + */ + ZkFuseNameDefaultType = 0, + /** + ZkFuse path is synthesized and identifies the data part of a + ZooKeeper node, i.e. Posix regular file semantics is expected. + */ + ZkFuseNameRegType = 1, + /** + ZkFuse path is synthesized and identifies the chidlren part of a + ZooKeeper node, i.e. Posix directory semantics is expected. + */ + ZkFuseNameDirType = 2 +}; + +class ZkFuseFile; + +typedef ZkFuseFile * ZkFuseFilePtr; + +class ZkFuseHandleManagerFactory; + +/** + ZkFuseHandleManager - keeps track of all the ZkFuseFile instances + allocated by a ZkFuseHandleManager instance and provides them + with a handle that can be used by FUSE. + + It maps a ZooKeeper path to a handle and a handle to a ZkFuse instance. + It also implements the methods that takes path names as arguments, such + as open, mknod, rmdir, and rename. + + Memory management + - References ZkFuseFile instances using regular pointers + Smart pointer is not used because reference counts are needed to + determine how many time a node is opened as a regular file or + directory. This also avoids circular smart pointer references. + - Each ZkFuseFile instance holds a reference to its ZkFuseHandleManager + using a boost::shared_ptr. This ensures that the ZkFuseHandleManager + instance that has the handle for the ZkFuseFile instance does not + get garbage collected while the ZkFuseFile instance exists. + + Concurrency control + - Except for the immutable ZkFuseCommon, all other member variables + are protected by _mutex. + - A method in this class can hold _mutex when it directly or + indirectly invokes ZkFuseFile methods. A ZkFuseFile method that holds + a ZkFuseFile instance _mutex cannot invoke a ZkFuseHandleManager + method that acquires the ZkFuseHandleManager instance's _mutex. + Otherwise, this may cause a dead lock. + - Methods that with names that begin with "_" do not acquire _mutex. + They are usually called by public methods that acquire and hold _mutex. + */ +class ZkFuseHandleManager : boost::noncopyable +{ + private: + /** + Typedef of handle, which is an int. + */ + typedef int Handle; + /** + Typedef of std::map used to map path to handle. + */ + typedef std::map Map; + /** + Typedef of std::vector used to map handle to ZkFuseFile instances. + */ + typedef std::vector Files; + /** + Typedef of std::vector used to hold unused handles. + */ + typedef std::vector FreeList; + /** + Typedef of boost::weak_ptr to the ZkFuseHandleManager instance. + */ + typedef boost::weak_ptr WeakPtr; + + /* Only ZkFuseHandleManagerFactory can create instances of this class */ + friend class ZkFuseHandleManagerFactory; + + /** + Contains common configuration. + Immutable so that it can be accessed without locks. + */ + const ZkFuseCommon _common; + /** + Maps a path name to a Handle. + */ + Map _map; + /** + Maps a handle to a ZkFuseFile instances. + Also holds pointers to all known ZkFuseFile instances. + An element may point to an allocated ZkFuseFile instance or be NULL. + + An allocated ZkFuseFile instance may be in one of the following states: + - in-use + Currently open, i.e. the ZkFuseFile instance's reference count + greater than 0. + - in-cache + Not currently open, i.e. the ZkFuseFile instances's + reference count is 0. + */ + Files _files; + /** + List of free'ed handles. + */ + FreeList _freeList; + /** + Mutex used to protect this instance. + */ + mutable zkfuse::Mutex _mutex; + /** + Count of number of in-use entries. + It used to calculate number of cached nodes. + Number cached nodes is (_files.size() - _numInUse). + */ + unsigned _numInUse; + /** + WeakPtr to myself. + */ + WeakPtr _thisWeakPtr; + + /** + Obtain a handle for the given path. + - If path is not known, then allocate a new handle and increment + _numInUse, and set newFile to true. The allocated + ZkFuseFile instance's reference count should be 1. + - If path is known, increase the corresponding + ZkFuseFile instance's reference count. + + \return the allocated handle. + \param path the path to lookup. + \param newFile indicates whether a new handle has been allocated. + */ + Handle allocate(const std::string & path, bool & newFile); + + /** + Constructor. + + \param common the immutable common configuration. + \param reserve number of elements to pre-allocate for + _files and _freeList. + */ + ZkFuseHandleManager( + const ZkFuseCommon & common, + const unsigned reserve) + : _common(common), + _files(), + _freeList(), + _mutex(), + _numInUse(0) + { + _files.reserve(reserve); + _files[0] = NULL; /* 0 never allocated */ + _files.resize(1); + _freeList.reserve(reserve); + } + + public: + /** + Typedef for boost::shared_ptr for this ZkFuseHandleManager class. + */ + typedef boost::shared_ptr SharedPtr; + + /** + Destructor. + */ + ~ZkFuseHandleManager() + { + } + /** + Get the ZkFuseFile instance for a handle. + + \return the ZkFuseFile instance identified by the handle. + \param handle get ZkFuseFile instance for this handle. + */ + ZkFuseFilePtr getFile(Handle handle) const + { + AutoLock lock(_mutex); + return _files[handle]; + } + /** + Get the immutable common configuration. + + \return the common configuration instance. + */ + const ZkFuseCommon & getCommon() const + { + return _common; + } + /** + Deallocate a previously allocated handle. + This decrements the reference count of the corresponding + ZkFuseFile instance. If the reference count becomes zero, + decrement _numInUse. It may also cause the ZkFuseFile instance + to be reclaimed if there are too many cached ZkFuseFile instances. + + The ZkFuseFile instance should be reclaimed if the number of + unused ZkFuseFile instances exceeds the configured cache size, i.e. + (_files.size() - _numInUse) > _common.getCacheSize() + and the ZkFuseFile instance has a reference count of zero. + + Reclaiming a ZkFuseFile instance involves removing the ZkFuseFile + instance's path to handle mapping from _map and the handle to the + ZkFuseFile instance mapping from _files, adding the handle to + the _freeList, and finally deleting the ZkFuseFile instance. + + \param handle the handle that should be deallocated. + */ + void deallocate(Handle handle); + /** + Handles ZooKeeper session events. + It invokes the known ZkFuseFile instances to let them know + that their watches will no longer be valid. + */ + void eventReceived(const ZKWatcherEvent & event); + /** + Get data from the specified the ZooKeeper path. + + \return 0 if successful, otherwise return negative errno. + \param path the path of the ZooKeeper node. + \param data return data read. + */ + int getData(const std::string & path, Data & data); + /** + Set data into the specified ZooKeeper path. + + \return 0 if successful, otherwise return negative errno. + \param path the path of the ZooKeeper node. + \param data the data to be written. + \param exists set to true if this path exists. + \param doFlush set to true if new data should be flushed to ZooKeeper. + */ + int setData(const std::string & path, + const Data & data, + bool exists, + bool doFlush); + /** + Create a ZooKeeper node to represent a ZkFuse file or directory. + + \return handle if successful, otherwise return negative errno. + \param path to create. + \param mode should be either S_IFDIR for directory or + S_IFREG for regular file. + \param mayExist if set and the ZooKeeper node already exist, return + valid handle instead of -EEXIST. + \param created returns whether a new ZooKeeper node had been created. + */ + int mknod(const std::string & path, + mode_t mode, + bool mayExist, + bool & created); + /** + Open a ZooKeeper node. + + The justCreated argument is used to differentiate if the _deleted flag + of the ZkFuseFile instance is to be trusted (i.e. the path + does not exist in ZooKeeper.) The _deleted flag is trusted + if the ZkFuseFile instance is known to exist in ZooKeeper after + invoking ZooKeeper with the path. + + If justCreated is true, then the ZkFuseFile instance was just created. + The ZkFuseFile constructor sets the _deleted flag to true because + path is not known to exist and hence should not be accessed. + The justCreated flag will force the ZkFuseFile instance to invoke + ZooKeeper to determine if the path exists. + + \return handle if successful, otherwise return negative errno. + \param path the path to open. + \param justCreated indicates if this is newly created ZkFuseFile instance. + */ + int open(const std::string & path, bool justCreated); + /** + Remove a ZkFuse directory. + + If force is not set, then the ZooKeeper node will be removed only + if it has no data and no child nodes except ZkFuse metadata nodes. + + \return 0 if successful, otherwise return negative errno. + \param path the path to remove. + \param force force removal, i.e. bypass checks. + */ + int rmdir(const char * path, bool force = false); + /** + Make a ZkFuse directory. + + ZkFuse represents a ZooKeeper node with no data and no children + as a regular file. In order to differentiate a newly created + directory from an empty regular file, mkdir will create a directory + metadata node as a child of the directory. + + \return 0 if successful, otherwise return negative errno. + \param path the path of the directory to create. + \param mode create directory with this mode + (mode currently not implemented). + */ + int mkdir(const char * path, mode_t mode); + /** + Remove a ZkFuse regular file. + + A file is the abstraction for the data part of a ZooKeeper node. + - If ZkFuse represents a ZooKeeper node as a directory, the data part + of the node is represented by synthesizing a name for this file. This + synthesized name is visible through readdir if the ZooKeeper node's + data is not empty. Removing such a file is done by truncating + the ZooKeeper node's data to 0 length. + - If ZkFuse represents a ZooKeeper node as a file, then removing the + is done by removing the ZooKeeper node (and its metadata). + + \return 0 if successful, otherwise return negative errno. + \param path the path of the file to remove. + */ + int unlink(const char * path); + /** + Get attributes of a ZkFuse regular file or directory. + + \return 0 if successful, otherwise return negative errno. + \param path get attributes for this path + \param stbuf store attributes here. + */ + int getattr(const char * path, struct stat & stbuf); + /** + Rename a ZkFuse regular file. + + It creates a new ZooKeeper node at toPath, copies data and file + metadata from the ZooKeeper node at fromPath to the new node, + and deletes the current ZooKeeper node. If the current ZooKeeper + node is not deleted if the new ZooKeeper node cannot be created + or the data copy fails. + + It cannot be used to rename a directory. + + \return 0 if successful, otherwise return negative errno. + \param fromPath the current path. + \param toPath rename to this path. + */ + int rename(const char * fromPath, const char * toPath); + /** + Add a child ZooKeeper path to the children information cache + of the ZkFuseFile instance that caches the parent ZooKeeper node. + + This is used to add a child path after a new ZooKeeper node has + been created to the children information cache of the parent + ZooKeeper node. This is needed because waiting for the children + changed event to update the cache may result in inconsistent local + views of the changes. + \see removeChildFromParent + + \parama childPath the path of the child ZooKeeper node. + */ + void addChildToParent(const std::string & childPath) const; + /** + Remove a child ZooKeeper path from the children information cache + of the ZkFuseFile instance that caches the parent ZooKeeper node. + + For example, this should happen whenever a path is deleted. + This child information cache of the parent will eventually be + invalidated by watches. However, the delivery of the children + change event may come after the next access and thus provide + the client with an inconsistent view. One example is that + client deletes the last file in a directory, but the children + changed event is not delivered before the client invokes rmdir. + to remove the parent. In this case, the rmdir fails because + the cached children information of the parent indicates the + "directory" is not empty. + + \param childPath the path of the child ZooKeeper node. + */ + void removeChildFromParent(const std::string & childPath) const; + /** + Return the path for the parent of the specified ZooKeeper path. + + \return the parent path. + \param childPath the child path. + */ + std::string getParentPath(const std::string & childPath) const; + /** + Return the ZooKeeper path from a ZkFuse path. + + The ZkFuse path may be a synthesized path. For example, a synthesized + path is required to access the data part of a ZooKeeper node's + data when ZkFuse represents the ZooKeeper node as directory. + A synthesized path is also required to create a child ZooKeeper node + under a ZooKeeper node that is represented by a regular file. + + \return the ZooKeeper path for path. + \param path the ZkFuse path, which may be a synthesized path. + \param nameType indicate whether the ZkFuse path is synthesized and + whether the synthesized ZkFuse path identifies a + directory or a regular file. + */ + std::string getZkPath(const char * path, ZkFuseNameType & nameType) const; +}; + +/** + ZkFuseHandleManagerFactory - factory for ZkFuseHandleManager. + + This is the only way to create a ZkFuseHandleManager instance. + to make sure that _thisWeakPtr of the instance is intialized + after the instance is created. + */ +class ZkFuseHandleManagerFactory +{ + public: + /** + Create an instance of ZkFuseHandleManager. + + \return the created ZkFuseHandleManager instance. + \param common the common configuration. + \param reserve initially reserve space for this number of handles. + */ + static ZkFuseHandleManager::SharedPtr create( + const ZkFuseCommon & common, + unsigned reserve = 1000) + { + ZkFuseHandleManager::SharedPtr manager + (new ZkFuseHandleManager(common, reserve)); + manager->_thisWeakPtr = manager; + return manager; + } +}; + +/** + ZkFuseAutoHandle - automatically closes handle. + + It holds an opened handle and automatically closes this handle + when it is destroyed. This enables code that open a handle + to be exception safe. + */ +class ZkFuseAutoHandle +{ + private: + /** + Typedef for Handle which is an int. + */ + typedef int Handle; + /** + Holds a reference to the ZkFuseHandlerManager instance that + allocated the handle. + */ + ZkFuseHandleManager::SharedPtr _manager; + /** + The handle that should be closed when this instance is destroyed. + A valid handle has value that is equal or greater than 0. + A negative value indicates an error condition, usually the value + is a negative errno. + */ + Handle _handle; + /** + Caches a reference to the ZkFuseFile instance with this handle. + This is a performance optimization so that _manager.getFile(_handle) + is only called once when the handle is initialized. + */ + ZkFuseFilePtr _file; + + /** + Initialize reference to the ZkFuseFile instance with this handle. + */ + void _initFile() + { + if (_handle >= 0) { + _file = _manager->getFile(_handle); + } else { + _file = NULL; + } + } + + public: + /** + Constructor - takes an previously opened handle. + + \param manager the ZkFuseHandleManager instance who allocated the handle. + \param handle the handle. + */ + ZkFuseAutoHandle( + const ZkFuseHandleManager::SharedPtr & manager, + int handle) + : _manager(manager), + _handle(handle), + _file() + { + _initFile(); + } + /** + Constructor - open path and remember handle. + + \param manager the ZkFuseHandleManager instance who allocated the handle. + \param path open this path and remember its handle in this instance. + */ + ZkFuseAutoHandle( + const ZkFuseHandleManager::SharedPtr & manager, + const std::string & path) + : _manager(manager), + _handle(_manager->open(path, false)), + _file() + { + _initFile(); + } + /** + Constructor - create path and remember handle. + + The creation mode indicates whether the path identifies a regular file + or a directory. + + \param manager the ZkFuseHandleManager instance who allocated the handle. + \param path create this path and remember its handle in this instance. + \param mode the creation mode for the path, should be either + S_IFDIR or S_IFDIR. + \param mayExist, if set and the path already exists, + then the ZkFuseAutoHandle will hold the handle + for the path instead of -EEXIST. + If not set and the path does not exist, then the handle + be -EEXIST. + */ + ZkFuseAutoHandle( + const ZkFuseHandleManager::SharedPtr & manager, + const std::string & path, + mode_t mode, + bool mayExist) + : _manager(manager), + _handle(-1), + _file() + { + bool created; + _handle = _manager->mknod(path, mode, mayExist, created); + _initFile(); + } + /** + Destructor - closes the handle. + */ + ~ZkFuseAutoHandle() + { + reset(); + } + /** + Get the handle. + \see _handle + */ + int get() const + { + return _handle; + } + /** + Get the ZkFuseFile instance of the handle. + \see _file + */ + ZkFuseFilePtr getFile() const + { + return _file; + } + /** + Forget the handle, don't close the handle. + */ + void release() + { + _handle = -1; + _file = NULL; + } + /** + Change the remembered handle. + + It will close the current handle (if valid). + */ + void reset(int handle = -1); +}; + +/** + ZkFuseStat - C++ wrapper for ZooKeeper Stat. + + This wrapper provides ZooKeeper Stat will constructors that + initializes the instance variables of Stat. + */ +class ZkFuseStat : public Stat +{ + public: + /** + Constructor - clear instance variables. + */ + ZkFuseStat() + { + clear(); + } + /** + Destructor - do nothing. + */ + ~ZkFuseStat() + { + } + /** + Clear instance variables. + */ + void clear() + { + czxid = 0; + mzxid = 0; + ctime = 0; + mtime = 0; + version = 0; + cversion = 0; + aversion = 0; + } +}; + +/** + ZkFuseFile - an instance encapsulates the runtime state of an allocated + ZooKeeper node. + + Memory management + - Referenced by the ZkFuseHandleManager that created this instance. + - Uses boost::shared_ptr to reference the ZkFuseHandleManager that + created this instance. This makes sure that this ZkFuseHandleManager + instance cannot be deleted when it has allocated ZkFuseFile instances. + - A ZkFuseHandleManager deletes itself if it can be reclaimed. + It can be reclaimed if it has no watches, its reference count is zero, + and the ZkFuseHandleManager instance would have more than the + configured number of cached ZkFuseFile instances. + - A ZkFuseFile instance cannot be deleted if it has active watches on + its ZooKeeper node. When one of its watches fires, the ZkFuseFile + instance must exist because one of its methods will be invoked + to process the event. If the ZkFuseFile instance has been deleted, + the method will access previously freed memory. + + Concurrency control + - _mutex protects the instance variables of an instance. + - Callers should assume that a public method will acquire _mutex. + - Methods of this class may not hold _mutex while invoking an + ZkFuseHandleManager instance. + - Methods that with names that begin with "_" do not acquire _mutex. + They are usually called by public methods that acquire and hold _mutex. +*/ +class ZkFuseFile : boost::noncopyable +{ + public: + /** + Maximum size for the data part of a ZooKeeper node. + */ + static const unsigned maxDataFileSize = MAX_DATA_SIZE; + + private: + /** + Mode returned by getattr for a ZkFuse directory. + */ + static const mode_t dirMode = (S_IFDIR | 0777); + /** + Mode returned by getattr for a ZkFuse regular file. + */ + static const mode_t regMode = (S_IFREG | 0777); + + /** + References the ZkFuseHandleManager that created this instance. + */ + ZkFuseHandleManager::SharedPtr _manager; + /** + Handle for this instance. + */ + const int _handle; + /** + Path of the ZooKeeper node represented by this instance. + */ + const std::string _path; + /** + Mutex that protects the instance variables of this instance. + */ + mutable zkfuse::Mutex _mutex; + /** + Reference count for this instance, i.e. the number of opens + minus the number of closes. + */ + int _refCount; + /** + Indicates whether the ZooKeeper node exist. + This flag allows caching of deleted ZooKeeper node to avoid + repeated ZooKeeper lookups for a non-existent path, and avoid + using cached information. + + Its value is true if + - it is verified to exist (by calling ZooKeeper), or + - it is existence is unknown because ZooKeeper has not been + invoked to verify its path's existence. + */ + bool _deleted; + /** + Count of current number directory opens minus directory closes. + */ + int _openDirCount; + /** + Indicates whether cached children information is valid. + + It is true if the cached children information is valid. + */ + bool _initializedChildren; + /** + Indicates whether there is an outstanding children watch. + + It is true if it has an outstanding children watch. + */ + bool _hasChildrenListener; + /** + Cached children information. + + The cache is valid if _initializedChildren is true. + */ + NodeNames _children; + + /** + Indicates whether the cached data is valid. + + It is true if the cached data and ZooKeeper Stat are valid. + */ + bool _initializedData; + /** + Indicates whether there is an outstanding data watch. + + It is true if it has an outstanding data watch. + */ + bool _hasDataListener; + /** + Indicates whether the cached data (_activeData) has been modified. + + It is true if the cached data has been modified. + */ + bool _dirtyData; + /** + Currently active data. + + To maintain atomicity of updates and emulate Posix semantics, + when a ZkFuse file remains open, the same data will be accessed + by the file's clients. The data will be flushed to ZooKeeper when + the flush method is called. The flush method may be called + explicitly by a client or implicitly when the ZkFuse file is no + longer currently open. + + _activeData and _activeStat stores the data and ZooKeeper Stat + that will be accessed by the file's clients. + + If there are changes when the ZkFuse file is open, new data is + cached as latest data (by _latestData and _latestStat). + */ + Data _activeData; + /** + Currently active ZooKeeper Stat. + \see _activeData + */ + ZkFuseStat _activeStat; + /** + Latest data. + This is either the same as _activeData or it is newer. It is newer + is it has been updated by event triggered by a data watch. + */ + Data _latestData; + /** + Latest ZooKeeper data. + This is either the same as _activeStat or it is newer. It is newer + is it has been updated by event triggered by a data watch. + */ + ZkFuseStat _latestStat; + + /** + Get userid. + + \return the userid. + */ + uid_t _getUid() const + { + return _manager->getCommon().getUid(); + } + /** + Get groupid. + + \return the groupid. + */ + gid_t _getGid() const + { + return _manager->getCommon().getGid(); + } + /** + Get block size. + + \return the block size. + */ + unsigned _getBlkSize() const + { + return _manager->getCommon().getBlkSize(); + } + /** + Get number of children, include metadata children in the count. + + \return the number of children including metadata children. + */ + unsigned _numChildrenIncludeMeta() const + { + unsigned count = _children.size(); + LOG_DEBUG(LOG, "numChildrenIncludeMeta() returns %u", count); + return count; + } + /** + Get number of children, exclude metadata children in the count. + + \return the number of children excluding metadata children. + */ + unsigned _numChildrenExcludeMeta() const + { + unsigned count = 0; + for (NodeNames::const_iterator it = _children.begin(); + it != _children.end(); + it++) { + if (!_isMeta(*it)) { + count++; + } + } + LOG_DEBUG(LOG, "numChildrenExcludeMeta() returns %u", count); + return count; + } + /** + Whether the ZooKeeper node has children, include metadata + children. + + \return true if it has children including metadata children. + */ + bool _hasChildrenIncludeMeta() const + { + return _numChildrenIncludeMeta() != 0; + } + /** + Return true if the ZooKeeper node has children, include metadata + children. + + \return true if it has children excluding metadata children. + */ + bool _hasChildrenExcludeMeta() const + { + return _numChildrenExcludeMeta() != 0; + } + /** + Whether the ZooKeeper node has data. + + \return true if _activeData is not empty. + */ + bool _hasData() const + { + return _activeData.empty() == false; + } + /** + Whether the ZooKeeper node has child with the specified path. + + \return true if the ZooKeeper node has a child with the specified path. + \param childPath the path of the child. + */ + bool _hasChildPath(const std::string & childPath) const + { + bool hasChild = + std::find(_children.begin(), _children.end(), childPath) + != _children.end(); + LOG_DEBUG(LOG, "hasChild(childPath %s) returns %d", + childPath.c_str(), hasChild); + return hasChild; + } + /** + Whether the given path component is a ZkFuse synthesized path + component. + + A ZkFuse synthesized path component will begin with + the metadataNamePrefix obtained from the common configuration. + \see _metadataNamePrefix + + \return true if the path component is a ZkFuse synthesized path + component. + \param childName the path component to check if it is synthesized by + ZkFuse. + */ + bool _isMeta(const std::string & childName) const + { + bool isMeta; + const std::string & prefix = + _manager->getCommon().getMetadataNamePrefix(); + unsigned offset = + (_path.length() > 1 ? + _path.length() + 1 : + 1 /* special case for root dir */ ); + unsigned minLength = offset + prefix.length(); + if (childName.length() < minLength || + childName.compare(offset, prefix.length(), prefix) != 0) { + isMeta = false; + } else { + isMeta = true; + } + LOG_DEBUG(LOG, "isMeta(childName %s) returns %d", + childName.c_str(), isMeta); + return isMeta; + } + /** + Build a path for a specific child of the ZooKeeper node. + + This is done by appending "/" (unless it is the ZooKeeper node + is the root node) and the name of the child. + + \return the path for the specified child of the ZooKeeper node. + \param name the name of the child. + */ + std::string _getChildPath(const std::string & name) const + { + return buildChildPath(_path, name); + } + /** + Whether the ZooKeeper node has a regular file metadata child node. + + \return true if the ZooKeeper node has a regular file metadata child + node. + */ + bool _hasRegMetadata() const + { + bool res = _hasChildPath( + _getChildPath(_manager->getCommon().getRegMetadataName())); + LOG_DEBUG(LOG, "hasRegMetadata() returns %d", res); + return res; + } + /** + Whether the ZooKeeper node has a directory metadata child node. + + \return true if the ZooKeeper node has a directory metadata child + node. + */ + bool _hasDirMetadata() const + { + bool res = _hasChildPath( + _getChildPath(_manager->getCommon().getDirMetadataName())); + LOG_DEBUG(LOG, "hasDirMetadata() returns %d", res); + return res; + } + /** + Whether ZkFuse should present the ZooKeeper node as a ZkFuse regular + file. + + It should be a ZkFuse regular file it has no children or its + only children is its regular file metadata child node. + + \return true if the Zookeeper node should be presented as a ZkFuse + regular file. + */ + bool _isReg() const + { + unsigned numChildrenIncludeMeta = _numChildrenIncludeMeta(); + bool res = + (numChildrenIncludeMeta == 0) || + (numChildrenIncludeMeta == 1 && _hasRegMetadata() == true); + LOG_DEBUG(LOG, "isReg() returns %d", res); + return res; + } + /** + Whether ZkFuse should present the ZooKeeper node as a ZkFuse directory. + + It should be a ZkFuse directory if it should not be presented as + a ZkFuse regular directory. + \see _isReg + + \return true if the Zookeeper node should be presented as a ZkFuse + directory. + */ + bool _isDir() const + { + return !_isReg(); + } + /** + Whether ZkFuse should present the ZooKeeper node as a ZkFuse regular + file by taking into account the specified ZkFuseNameType. + + The ZkFuseNameType may override the default ZkFuse presentation of + a ZooKeeper node. + + \return true if ZkFuse should present the ZooKeeper node as a ZkFuse + regular file. + \param nameType specifies the ZkFuseNameType. + \param doLock whether _mutex should be acquired, it should be true + if the caller did not acquire _mutex. + */ + bool _isRegNameType(ZkFuseNameType nameType, bool doLock = false) const + { + bool res; + switch (nameType) { + case ZkFuseNameRegType: + res = true; + break; + case ZkFuseNameDirType: + res = false; + break; + case ZkFuseNameDefaultType: + default: + if (doLock) { + AutoLock lock(_mutex); + res = _isReg(); + } else { + res = _isReg(); + } + break; + } + LOG_DEBUG(LOG, "isRegNameType(nameType %d) returns %d", + int(nameType), res); + return res; + } + /** + Whether ZkFuse should present the ZooKeeper node as a ZkFuse + directory by taking into account the specified ZkFuseNameType. + + The ZkFuseNameType may override the default ZkFuse presentation of + a ZooKeeper node. + + \return true if ZkFuse should present the ZooKeeper node as a ZkFuse + directory. + \param nameType specifies the ZkFuseNameType. + \param doLock whether _mutex should be acquired, it should be true + if the caller did not acquire _mutex. + */ + bool _isDirNameType(ZkFuseNameType nameType, bool doLock = false) const + { + bool res; + switch (nameType) { + case ZkFuseNameRegType: + res = false; + break; + case ZkFuseNameDirType: + res = true; + break; + case ZkFuseNameDefaultType: + default: + if (doLock) { + AutoLock lock(_mutex); + res = _isDir(); + } else { + res = _isDir(); + } + break; + } + LOG_DEBUG(LOG, "isDirNameType(nameType %d) returns %d", + int(nameType), res); + return res; + } + /** + ZkFuse regular file metadata. + */ + struct Metadata { + /** + Version of the ZooKeeper node data that this metadata is good for. + */ + uint32_t version; + /** + Acces time in milliseconds. + */ + uint64_t atime; + /** + Modified time in milliseconds. + */ + uint64_t mtime; + + /** + Constructor. + */ + Metadata() + : version(0), + atime(0), + mtime(0) + { + } + }; + /** + Encode Metadata into Data so that it can be stored in a metadata + ZooKeeper node. + + Each Metadata attribute is encoded as ": " on single line + terminated by newline. + + \param meta the input Metadata. + \param data the output Data after encoding. + */ + void _encodeMetadata(const Metadata & meta, Data & data) const + { + LOG_DEBUG(LOG, "encodeMetadata()"); + std::ostringstream oss; + oss << "version: " << meta.version << endl + << "atime: " << meta.atime << endl + << "mtime: " << meta.mtime << endl; + data = oss.str(); + } + /** + Decode Data from a metadata child ZooKeeper node into Metadata. + + Data is a stream of ": " records separated by newline. + + \param data the input Data. + \param meta the output Metadata after decoding. + */ + void _decodeMetadata(const Data & data, Metadata & meta) const + { + LOG_DEBUG(LOG, "decodeMetadata(data %s)", data.c_str()); + std::istringstream iss(data); + char key[128]; + char value[1024]; + while (!iss.eof()) { + key[0] = 0; + value[0] = 0; + iss.get(key, sizeof(key), ' '); + if (iss.eof()) { + break; + } + iss.ignore(32, ' '); + iss.getline(value, sizeof(value)); + LOG_DEBUG(LOG, "key %s value %s", key, value); + if (strcmp(key, "version:") == 0) { + unsigned long long v = strtoull(value, NULL, 0); + LOG_DEBUG(LOG, "version: %llu", v); + meta.version = v; + } + else if (strcmp(key, "atime:") == 0) { + unsigned long long v = strtoull(value, NULL, 0); + LOG_DEBUG(LOG, "atime: %llu", v); + meta.atime = v; + } + else if (strcmp(key, "mtime:") == 0) { + unsigned long long v = strtoull(value, NULL, 0); + LOG_DEBUG(LOG, "mtime: %llu", v); + meta.mtime = v; + } + else { + LOG_WARN(LOG, "decodeMetadata: path %s unknown key %s %s\n", + _path.c_str(), key, value); + } + } + LOG_DEBUG(LOG, "decodeMetadata done"); + } + /** + Flush data to the ZooKeeper node. + + If cached active data has been modified, flush it to the ZooKeeper node. + Returns -EIO if the data cannot be written because the cached active + data is not the expected version, i.e. ZooKeeper returns ZBADVERSION. + -EIO may also indicate a more general failure, such as unable to + communicate with ZooKeeper. + + \return 0 if successful, otherwise negative errno. + */ + int _flush() + { + LOG_DEBUG(LOG, "flush() path %s", _path.c_str()); + + int res = 0; + try { + if (_dirtyData) { + LOG_DEBUG(LOG, "is dirty, active version %d", + _activeStat.version); + _manager->getCommon().getZkAdapter()-> + setNodeData(_path, _activeData, _activeStat.version); + /* assumes version always increments by one if successful */ + _deleted = false; + _activeStat.version++; + _dirtyData = false; + res = 0; + } + else { + LOG_DEBUG(LOG, "not dirty"); + res = 0; + } + } catch (const ZooKeeperException & e) { + if (e.getZKErrorCode() == ZBADVERSION) { + LOG_ERROR(LOG, "flush %s bad version, was %d", + _path.c_str(), _activeStat.version); + res = -EIO; + } + else { + LOG_ERROR(LOG, "flush %s exception %s", + _path.c_str(), e.what()); + res = -EIO; + } + } + + LOG_DEBUG(LOG, "flush returns %d", res); + return res; + } + /** + Truncate or expand the size of the cached active data. + + This method only changes the size of the cached active data. + This change is committed to ZooKeeper when the cached data + is written to the ZooKeeper node by flush(). + + Return -EFBIG is the requested size exceeds the maximum. + + \return 0 if successful, otherwise negative errno. + \param size the requested size. + */ + int _truncate(off_t size) + { + LOG_DEBUG(LOG, "truncate(size %zu) path %s", size, _path.c_str()); + + int res = 0; + + if (!_isInitialized()) { + LOG_DEBUG(LOG, "not initialized"); + res = -EIO; + } + else if (size > _activeData.size()) { + if (size > maxDataFileSize) { + LOG_DEBUG(LOG, "size > maxDataFileSize"); + res = -EFBIG; + } else { + LOG_DEBUG(LOG, "increase to size"); + _activeData.insert(_activeData.begin() + + (size - _activeData.size()), 0); + _dirtyData = true; + res = 0; + } + } + else if (size < _activeData.size()) { + LOG_DEBUG(LOG, "decrease to size"); + _activeData.resize(size); + _dirtyData = true; + res = 0; + } + else { + LOG_DEBUG(LOG, "do nothing, same size"); + } + + LOG_DEBUG(LOG, "truncate returns %d", res); + return res; + } + /** + Remove a ZkFuse directory. + + If force is true, then the ZooKeeper node and its decendants + will be deleted. + + If force is false, then this method implements the semantics + of removing a ZkFuse directory. It will delete the ZooKeeper node + only if the ZooKeeper node have no data and no non-metadata + children. + - Return -ENOTDIR if the ZooKeeper node is not considered + to be a directory (after taking into consideration the specified + ZkFuseNameType). + - Return -ENOTEMPTY if the ZooKeeper node has data or it has + non-metadata children. + - Return -ENOENT if the ZooKeeper cannot be deleted, usually this + is because it does not exist. + + \return 0 if successful, otherwise negative errno. + \param nameType the ZkFuseNameType of the path used to specify the + directory to be removed. It influences whether ZkFuse + considers the ZooKeeper node to be a regular file or + directory. \see ZkFuseNameType + \param force set to true to bypass ZkFuse rmdir semantic check. + */ + int _rmdir(ZkFuseNameType nameType, bool force) + { + LOG_DEBUG(LOG, "rmdir(nameType %d, force %d) path %s", + int(nameType), force, _path.c_str()); + + int res = 0; + try { + if (!force && !_isDirNameType(nameType)) { + LOG_DEBUG(LOG, "failed because not directory"); + res = -ENOTDIR; + } + else if (!force && _hasData()) { + /* rmdir cannot occur if there non-empty "data file" */ + LOG_DEBUG(LOG, "failed because node has data"); + res = -ENOTEMPTY; + } + else if (!force && _hasChildrenExcludeMeta()) { + /* rmdir cannot occur if there are "subdirs" */ + LOG_DEBUG(LOG, "failed because node has children"); + res = -ENOTEMPTY; + } + else { + LOG_DEBUG(LOG, "delete node"); + bool deleted = _manager->getCommon().getZkAdapter()-> + deleteNode(_path, true); + if (deleted) { + _deleted = true; + _clearChildren(); + res = 0; + } else { + /* TODO: differentiate delete error conditions, + * e.g. access permission, not exists, ... ? + */ + LOG_DEBUG(LOG, "delete failed"); + res = -ENOENT; + } + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "rmdir %s exception %s", _path.c_str(), e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "rmdir returns %d", res); + return res; + } + /** + Remove a ZkFuse regular file. + + This method implements the semantics of removing a ZkFuse regular file. + - If the ZkFuse regular file represents the data part of the + ZooKeeper node which is presented as a ZkFuse directory, + the regular file is virtually deleted by truncating the + ZooKeeper node's data. Readdir will not synthesize a regular + file entry for the data part of a ZooKeeper node if + the ZooKeeper node has no data. + - If the ZkFuse regular file represents the data part of the + ZooKeeper node which is presented as a ZkFuse regular file, + the ZooKeeper node and its decendants are deleted. + + Returns -EISDIR if the ZkFuse regular file cannot be deleted + because ZkFuse consider it to be a directory. + + \return 0 if successful, otherwise negative errno. + \param nameType the ZkFuseNameType of the path used to specify the + directory to be removed. It influences whether ZkFuse + considers the ZooKeeper node to be a regular file or + directory. \see ZkFuseNameType + */ + int _unlink(ZkFuseNameType nameType) + { + LOG_DEBUG(LOG, "unlink(nameType %d) path %s", + int(nameType), _path.c_str()); + + int res = 0; + switch (nameType) { + case ZkFuseNameRegType: + if (_isDir()) { + res = _truncate(0); + } else { + res = _rmdir(nameType, true); + } + break; + case ZkFuseNameDirType: + res = -EISDIR; + break; + case ZkFuseNameDefaultType: + default: + if (_isReg()) { + res = _rmdir(nameType, true); + } else { + res = -EISDIR; + } + break; + } + + LOG_DEBUG(LOG, "unlink returns %d", res); + return res; + } + /** + Whether cached children and data are valid. + + \return true if cached children and data are valid. + */ + bool _isInitialized() const + { + return _initializedChildren && _initializedData; + } + /** + Clear and invalidate cached children information. + */ + void _clearChildren() + { + _initializedChildren = false; + _children.clear(); + } + /** + Clear and invalidate cached data. + */ + void _clearData() + { + _initializedData = false; + _dirtyData = false; + _activeData.clear(); + _activeStat.clear(); + _latestData.clear(); + _latestStat.clear(); + } + /** + Whether the ZkFuseFile instance is a zombie. + + It is a zombie if it is not currently open, i.e. its reference count + is 0. + */ + bool _isZombie() const + { + return (_refCount == 0); + } + /** + Whether the ZkFuseFile instance is currently opened as a regular file + only once. + + It is used to determine when the cached data can be replaced with + the latest data. \see _activeData. + + \return true if its currently opened as a regular file only once. + */ + bool _isOnlyRegOpen() const + { + return ((_refCount - _openDirCount) == 1); + } + /** + Get attributes without accessing metadata. + + The atime and mtime returned does not take into consideration + overrides present in a matadata file. + + \return 0 if successful, otherwise negative errno. + \param stbuf return attributes here. + \param nameType specifies the ZkFuseNameType of the ZkFuse path used + to get attributes. It influences whether the directory + or regular file attributes are returned. + */ + int _getattrNoMetaAccess(struct stat & stbuf, ZkFuseNameType nameType) const + { + int res = 0; + if (_deleted) { + LOG_DEBUG(LOG, "deleted"); + res = -ENOENT; + } + else if (!_isInitialized()) { + LOG_DEBUG(LOG, "not initialized"); + res = -EIO; + } + else { + assert(_isInitialized()); + bool isRegular = _isRegNameType(nameType); + if (isRegular) { + LOG_DEBUG(LOG, "regular"); + stbuf.st_mode = regMode; + stbuf.st_nlink = 1; + stbuf.st_size = _activeData.size(); + } else { + LOG_DEBUG(LOG, "directory"); + stbuf.st_mode = dirMode; + stbuf.st_nlink = + _children.size() + (_activeData.empty() ? 0 : 1); + stbuf.st_size = stbuf.st_nlink; + } + stbuf.st_uid = _getUid(); + stbuf.st_gid = _getGid(); + /* IMPORTANT: + * Conversion to secs from millisecs must occur before + * assigning to st_atime, st_mtime, and st_ctime. Otherwise + * truncating from 64-bit to 32-bit will cause lost of + * most significant 32-bits before converting to secs. + */ + stbuf.st_atime = millisecsToSecs(_activeStat.mtime); + stbuf.st_mtime = millisecsToSecs(_activeStat.mtime); + stbuf.st_ctime = millisecsToSecs(_activeStat.ctime); + stbuf.st_blksize = _getBlkSize(); + stbuf.st_blocks = + (stbuf.st_size + stbuf.st_blksize - 1) / stbuf.st_blksize; + res = 0; + } + return res; + } + /** + Get the context that should be registered with the data and + children watches. + + The returned context is a pointer to the ZkFuseFile instance + cast to the desired ContextType. + + \return the context. + */ + ZooKeeperAdapter::ContextType _getZkContext() const + { + return (ZooKeeperAdapter::ContextType) NULL; + } + + /** + DataListener - listener that listens for ZooKeeper data events + and calls dataEventReceived on the ZkFuseFile instance + identified by the event context. + \see dataEventReceived + */ + class DataListener : public ZKEventListener { + public: + /** + Received a data event and invoke ZkFuseFile instance obtained from + event context to handle the event. + */ + virtual void eventReceived(const ZKEventSource & source, + const ZKWatcherEvent & event) + { + assert(event.getContext() != 0); + ZkFuseFile * file = static_cast(event.getContext()); + file->dataEventReceived(event); + } + }; + + /** + DataListener - listener that listens for ZooKeeper children events + and calls childrenEventReceived on the ZkFuseFile instance + identified by the event context. + \see childrenEventReceived + */ + class ChildrenListener : public ZKEventListener { + public: + /** + Received a children event and invoke ZkFuseFile instance obtained from + event context to handle the event. + */ + virtual void eventReceived(const ZKEventSource & source, + const ZKWatcherEvent & event) + { + assert(event.getContext() != 0); + ZkFuseFile * file = static_cast(event.getContext()); + file->childrenEventReceived(event); + } + }; + + /** + Globally shared DataListener. + */ + static DataListener _dataListener; + /** + Globally shared ChildrenListener. + */ + static ChildrenListener _childrenListener; + + public: + /** + Constructor. + + Sets reference count to one, i.e. it has been constructed because + a client is trying to open the path. \see _refCount. + Sets deleted to true. \see _deleted. + Sets number of currently directory opens to zero. \see _openDirCount. + Invalidate cach for children information and data. + + \param manager the ZkFuseHandleManager instance who is creating this + ZkFuseFile instance. + \param handle the handle assigned by the ZkFuseHandleManager instance + for this ZkFuseFile instance. + \param path the ZooKeeper path represented by this ZkFuseFile instance. + */ + ZkFuseFile(const ZkFuseHandleManager::SharedPtr & manager, + const int handle, + const std::string & path) + : _manager(manager), + _handle(handle), + _path(path), + _mutex(), + _refCount(1), + _deleted(true), + /* children stuff */ + _openDirCount(0), + _initializedChildren(false), + _hasChildrenListener(false), + _children(), + /* data stuff */ + _initializedData(false), + _hasDataListener(false), + _dirtyData(false), + _activeData(), + _activeStat(), + _latestData(), + _latestStat() + { + LOG_DEBUG(LOG, "constructor() path %s", _path.c_str()); + } + /** + Destructor. + */ + ~ZkFuseFile() + { + LOG_DEBUG(LOG, "destructor() path %s", _path.c_str()); + + assert(_isZombie()); + _clearChildren(); + _clearData(); + } + /** + Whether the ZooKeeper node represented by this ZkFuseFile instance + has been deleted. + \see _deleted + + \return true if it is deleted. + */ + bool isDeleted() const + { + AutoLock lock(_mutex); + return _deleted; + } + /** + Return the path of the ZooKeeper node represented by this ZkFuseFile + instance. + \see _path. + + \return the ZooKeeper node's path. + */ + const string & getPath() const + { + return _path; + } + /** + Add a childPath to the children information cache. + + \return 0 if successful, otherwise return negative errno. + \param childPath the ZooKeeper path of the child. + */ + int addChild(const std::string & childPath) + { + LOG_DEBUG(LOG, "addChild(childPath %s) path %s", + childPath.c_str(), _path.c_str()); + + int res = 0; + { + AutoLock lock(_mutex); + if (_initializedChildren) { + NodeNames::iterator it = + std::find(_children.begin(), _children.end(), childPath); + if (it == _children.end()) { + LOG_DEBUG(LOG, "child not found, adding child path"); + _children.push_back(childPath); + res = 0; + } + else { + LOG_DEBUG(LOG, "child found"); + res = -EEXIST; + } + } + } + + LOG_DEBUG(LOG, "addChild returns %d", res); + return res; + } + /** + Remove a childPath from the children information cache. + + \return 0 if successful, otherwise return negative errno. + \param childPath the ZooKeeper path of the child. + */ + int removeChild(const std::string & childPath) + { + LOG_DEBUG(LOG, "removeChild(childPath %s) path %s", + childPath.c_str(), _path.c_str()); + + int res = 0; + { + AutoLock lock(_mutex); + if (_initializedChildren) { + NodeNames::iterator it = + std::find(_children.begin(), _children.end(), childPath); + if (it != _children.end()) { + LOG_DEBUG(LOG, "child found"); + _children.erase(it); + res = 0; + } + else { + LOG_DEBUG(LOG, "child not found"); + res = -ENOENT; + } + } + } + + LOG_DEBUG(LOG, "removeChild returns %d", res); + return res; + } + /** + Invalidate the cached children information and cached data. + \see _clearChildren + \see _clearData + + \param clearChildren set to true to invalidate children information cache. + \param clearData set to true to invalidate data cache. + */ + void clear(bool clearChildren = true, bool clearData = true) + { + LOG_DEBUG(LOG, "clear(clearChildren %d, clearData %d) path %s", + clearChildren, clearData, _path.c_str()); + + { + AutoLock lock(_mutex); + if (clearChildren) { + _clearChildren(); + } + if (clearData) { + _clearData(); + } + } + } + /** + Whether reference count is zero. + \see _refCount + + \return true if reference count is zero. + */ + bool isZombie() const + { + AutoLock lock(_mutex); + + return (_refCount == 0); + } + /** + Increment the reference count of the ZkFuseFile instance. + + This method may be called by a ZkFuseFileManager instance while + holding the ZkFuseFileManager's _mutex. To avoid deadlocks, + this methods must never invoke a ZkFuseFileManager instance + directly or indirectly while holding the ZkFuseFile instance's + _mutex. + \see _refCount + + \return the post-increment reference count. + \param count value to increment the reference count by. + */ + int incRefCount(int count = 1) + { + LOG_DEBUG(LOG, "incRefCount(count %d) path %s", count, _path.c_str()); + + int res = 0; + { + AutoLock lock(_mutex); + _refCount += count; + assert(_refCount >= 0); + res = _refCount; + } + + LOG_DEBUG(LOG, "incRefCount returns %d", res); + return res; + } + /** + Decrement the reference count of the ZkFuseFile instance. + + This method may be called by a ZkFuseFileManager instance while + holding the ZkFuseFileManager's _mutex. To avoid deadlocks, + this methods must never invoke a ZkFuseFileManager instance + directly or indirectly while holding the ZkFuseFile instance's + _mutex. + \see _refCount + + \return the post-decrement reference count. + \param count value to decrement the reference count by. + */ + int decRefCount(int count = 1) + { + return incRefCount(-count); + } + /** + Increment the count of number times the ZkFuseFile instance has + been opened as a directory. + + This count is incremented by opendir and decremented by releasedir. + \see _openDirCount. + + \return the post-increment count. + \param count the value to increment the count by. + */ + int incOpenDirCount(int count = 1) + { + LOG_DEBUG(LOG, "incOpenDirCount(count %d) path %s", + count, _path.c_str()); + + int res = 0; + { + AutoLock lock(_mutex); + _openDirCount += count; + assert(_openDirCount >= 0); + res = _openDirCount; + assert(_openDirCount <= _refCount); + } + + LOG_DEBUG(LOG, "incOpenDirCount returns %d", res); + return res; + + } + /** + Decrement the count of number times the ZkFuseFile instance has + been opened as a directory. + + This count is incremented by opendir and decremented by releasedir. + \see _openDirCount. + + \return the post-decrement count. + \param count the value to decrement the count by. + */ + int decOpenDirCount(int count = 1) + { + return incOpenDirCount(-count); + } + /** + Whether ZkFuse should present the ZooKeeper node as a ZkFuse + directory by taking into account the specified ZkFuseNameType. + + The ZkFuseNameType may override the default ZkFuse presentation of + a ZooKeeper node. + \see _isDirNameType + + \return true if ZkFuse should present the ZooKeeper node as a ZkFuse + directory. + \param nameType specifies the ZkFuseNameType. + */ + bool isDirNameType(ZkFuseNameType nameType) const + { + return _isDirNameType(nameType, true); + } + /** + Whether ZkFuse should present the ZooKeeper node as a ZkFuse + regular file by taking into account the specified ZkFuseNameType. + + The ZkFuseNameType may override the default ZkFuse presentation of + a ZooKeeper node. + \see _isRegNameType + + \return true if ZkFuse should present the ZooKeeper node as a ZkFuse + regular file. + \param nameType specifies the ZkFuseNameType. + */ + bool isRegNameType(ZkFuseNameType nameType) const + { + return _isRegNameType(nameType, true); + } + /** + Get the active data. + \see _activeData + + \param data return data here. + */ + void getData(Data & data) const + { + AutoLock lock(_mutex); + + data = _activeData; + } + /** + Set the active data. + \see _activeData + + Return -EFBIG is the data to be written is bigger than the maximum + permitted size (and no data is written). + + \return 0 if successful, otherwise return negative errno. + \param data set to this data. + \param doFlush whether to flush the data to the ZooKeeper node. + */ + int setData(const Data & data, bool doFlush) + { + LOG_DEBUG(LOG, "setData(doFlush %d) path %s", doFlush, _path.c_str()); + int res = 0; + + if (data.size() > maxDataFileSize) { + res = -EFBIG; + } + else { + AutoLock lock(_mutex); + _activeData = data; + _dirtyData = true; + if (doFlush) { + res = _flush(); + } + } + + LOG_DEBUG(LOG, "setData() returns %d", res); + return res; + } + /** + Update the children information and the data caches as needed. + + This method is invoked when a ZkFuse regular file or directory + implemented by this ZkFuseFile instance is opened, e.g. + using open or opendir. It attempts to: + - make sure that the cache has valid children information + - register for watches for changes if no previous watches have + been registered. + + The newFile flag indicates if the ZkFuseFile instance has just + been constructed and that ZooKeeper has not been contacted to + determine if the ZooKeeper path for this file really exist. + When a ZkFuseFile instance is created, the _deleted flag is set to + true because it is safer to assume that the ZooKeeper node does + not exist. The newFile flag causes the _deleted flag to be + ignored and ZooKeeper to be contacted to update the caches. + + If the newFile flag is false, then the ZkFuseFile instance is + currently open and have been opened before. Hence, these previous + opens should have contacted ZooKeeper and would like learned from + ZooKeeper whether the ZooKeeper path exists. Therefore, + the _deleted flag should be trustworthy, i.e. it has accurate + information on whether the ZooKeeper path actually exists. + + \return 0 if successful, otherwise return negative errno. + \param newFile set to true if the ZkFuseFile instance is newly created. + */ + int update(bool newFile) + { + LOG_DEBUG(LOG, "update(newFile %d) path %s", newFile, _path.c_str()); + + int res = 0; + { + AutoLock lock(_mutex); + + /* At this point, cannot be zombie. + */ + assert(!_isZombie()); + if (!newFile && _deleted) { + /* Deleted file, don't bother to update caches */ + LOG_DEBUG(LOG, "deleted, not new file"); + res = -ENOENT; + } + else { + try { + LOG_DEBUG(LOG, "initialized children %d, data %d", + _initializedChildren, _initializedData); + LOG_DEBUG(LOG, "has children watch %d, data watch %d", + _hasChildrenListener, _hasDataListener); + /* + * Children handling starts here. + * If don't have children listener, + * then must establish listener. + * If don't have cached children information, + * then must get children information. + * It just happens, that the same ZooKeeper API + * is used for both. + */ + if (_initializedChildren == false || + _hasChildrenListener == false +#ifdef ZOOKEEPER_ROOT_CHILDREN_WATCH_BUG + /* HACK for root node because changes to children + * on a root node does not cause children watches to + * fire. + */ + || _path.length() == 1 +#endif // ZOOKEEPER_ROOT_CHILDREN_WATCH_BUG + ) { + LOG_DEBUG(LOG, "update children"); + NodeNames children; + _manager->getCommon().getZkAdapter()-> + getNodeChildren( children, _path, + &_childrenListener, _getZkContext()); + _hasChildrenListener = true; + LOG_DEBUG(LOG, "update children done"); + _children.swap(children); + _initializedChildren = true; + /* Since getNodeChildren is successful, the + * path must exist */ + _deleted = false; + } + else { + /* Children information is fresh since + * it is initialized and and have been + * updated by listener. + */ + } + /* + * Data handling starts here. + */ + assert(newFile == false || _isOnlyRegOpen()); + if (!_isOnlyRegOpen()) { + /* If is already currently opened by someone, + * then don't update data with latest from ZooKeeper, + * use current active data (which may be initialized + * or not). + * \see _activeData + */ + LOG_DEBUG(LOG, "node currently in-use, no data update"); + } + else { + /* If not opened/reopened by someone else, + * then perform more comprehensive checks of + * to make data and listener is setup correctly. + * If don't have data listener, + * then must establish listener. + * If don't have cached data, + * then must get data. + * It just happens, that the same ZooKeeper API + * is used for both. + */ + LOG_DEBUG(LOG, "node first use or reuse"); + if (_initializedData == false || + _hasDataListener == false) { + /* Don't have any data for now or need to register + * for callback */ + LOG_DEBUG(LOG, "update data"); + _latestData = + _manager->getCommon().getZkAdapter()-> + getNodeData(_path, &_dataListener, + _getZkContext(), + &_latestStat); + _hasDataListener = true; + LOG_DEBUG(LOG, + "update data done, latest version %d", + _latestStat.version); + /* Since getNodeData is successful, the + * path must exist. */ + _deleted = false; + } + else { + /* Data is fresh since it is initialized and + * and have been updated by listener. + */ + } + /* Update active data to the same as the most + * recently acquire data. + */ + _activeData = _latestData; + _activeStat = _latestStat; + _initializedData = true; + _dirtyData = false; + LOG_DEBUG(LOG, "update set active version %d", + _activeStat.version); + } + res = 0; + } catch (const ZooKeeperException & e) { + /* May have ZNONODE exception if path does exist. */ + if (e.getZKErrorCode() == ZNONODE) { + LOG_DEBUG(LOG, "update %s exception %s", + _path.c_str(), e.what()); + /* Path does not exist, set _deleted, + * clear children information cache + */ + _deleted = true; + _clearChildren(); + res = -ENOENT; + } else { + LOG_ERROR(LOG, "update %s exception %s", + _path.c_str(), e.what()); + res = -EIO; + } + } + } + } + + LOG_DEBUG(LOG, "update returns %d", res); + return res; + } + /** + Process a data event. + + This method may: + - Invalidate the data cache. + - Invoke ZooKeeper to update the data cache and register a new + data watch so that the cache can be kept in-sync with the + ZooKeeper node's data. + + This method does not change the active data. Active data will be + changed to a later version by update() at the appropriate time. + \see update. + */ + void dataEventReceived(const ZKWatcherEvent & event) + { + bool reclaim = false; + int eventType = event.getType(); + int eventState = event.getState(); + + /* + IMPORTANT: + + Do not mark ZkFuseFile instance as deleted when a ZOO_DELETED_EVENT + is received without checking with ZooKeeper. An example of + problematic sequence would be: + + 1. Create node. + 2. Set data and watch. + 3. Delete node. + 4. Create node. + 5. Deleted event received. + + It is a bug to mark the ZkFuseFile instance as deleted after + step 5 because the node exists. + + Therefore, this method should always contact ZooKeeper to keep the + data cache (and deleted status) up-to-date if necessary. + */ + LOG_DEBUG(LOG, "dataEventReceived() path %s, type %d, state %d", + _path.c_str(), eventType, eventState); + { + AutoLock lock(_mutex); + + _hasDataListener = false; + /* If zombie, then invalidate cached data. + * This clears _initializedData and eliminate + * the need to get the latest data from ZooKeeper and + * re-register data watch. + */ + if (_isZombie() && _initializedData) { + LOG_DEBUG(LOG, "invalidate data"); + _clearData(); + } + else if ((_refCount - _openDirCount) > 0) { + /* Don't invalidate cached data because clients of currently + * open files don't expect the data to change from under them. + * If data acted upon by these clients have become stale, + * then the clients will get an error when ZkFuse attempts to + * flush dirty data. The clients will not get error + * notification if they don't modify the stale data. + * + * If data cache is cleared here, then the following code + * to update data cache and re-register data watch will not + * be executed and may result in the cached data being + * out-of-sync with ZooKeeper. + */ + LOG_WARN(LOG, + "%s data has changed while in-use, " + "type %d, state %d, refCount %d", + _path.c_str(), eventType, eventState, _refCount); + } + /* If cache was valid and still connected + * then get the latest data from ZooKeeper + * and re-register data watch. This is required to keep + * the data cache in-sync with ZooKeeper. + */ + if (_initializedData && + eventState == ZOO_CONNECTED_STATE + ) { + try { + LOG_DEBUG(LOG, "register data watcher"); + _latestData = + _manager->getCommon().getZkAdapter()-> + getNodeData(_path, &_dataListener, _getZkContext(), + &_latestStat); + _hasDataListener = true; + LOG_DEBUG(LOG, + "get data done, version %u, cversion %u done", + _latestStat.version, _latestStat.cversion); + _deleted = false; + } catch (const ZooKeeperException & e) { + if (e.getZKErrorCode() == ZNONODE) { + _deleted = true; + _clearChildren(); + } + LOG_ERROR(LOG, "dataEventReceived %s exception %s", + _path.c_str(), e.what()); + } + } + } + LOG_DEBUG(LOG, "dataEventReceived return %d", reclaim); + } + /** + Process a children event. + + This method may: + - Invalidate the children information cache. + - Invoke ZooKeeper to update the children cache and register a new + data watch so that the cache can be kept in-sync with the + ZooKeeper node's children information. + */ + void childrenEventReceived(const ZKWatcherEvent & event) + { + bool reclaim = false; + int eventType = event.getType(); + int eventState = event.getState(); + + LOG_DEBUG(LOG, "childrenEventReceived() path %s, type %d, state %d", + _path.c_str(), eventType, eventState); + { + AutoLock lock(_mutex); + + _hasChildrenListener = false; + /* If zombie or disconnected, then invalidate cached children + * information. This clears _initializedChildren and eliminate + * the need to get the latest children information and + * re-register children watch. + */ + if (_initializedChildren && + (_isZombie() || eventState != ZOO_CONNECTED_STATE)) { + LOG_DEBUG(LOG, "invalidate children"); + _clearChildren(); + } + else if (_initializedChildren) { + /* Keep cached children information so that we have some + * children information if get new children information + * fails. If there is failure, then on next open, + * update() will attempt again to get children information + * again because _hasChildrenListener will be false. + * + * If children information cache is cleared here, then + * the following code to update children information cache + * and re-register children watch will not be executed + * and may result in the cached children information being + * out-of-sync with ZooKeeper. + * + * The children cache will be cleared if unable to + * get children and re-establish watch. + */ + LOG_WARN(LOG, + "%s children has changed while in-use, " + "type %d, state %d, refCount %d", + _path.c_str(), eventType, eventState, _refCount); + } + /* If children cache was valid and still connected, + * then get the latest children information from ZooKeeper + * and re-register children watch. This is required to + * keep the children information cache in-sync with ZooKeeper. + */ + if (_initializedChildren && + eventState == ZOO_CONNECTED_STATE + ) { + /* Should try to keep the cache in-sync, register call + * callback again and get current children. + */ + try { + LOG_DEBUG(LOG, "update children"); + NodeNames children; + _manager->getCommon().getZkAdapter()-> + getNodeChildren(children, _path, + &_childrenListener, _getZkContext()); + _hasChildrenListener = true; + LOG_DEBUG(LOG, "update children done"); + _children.swap(children); + _deleted = false; + } catch (const ZooKeeperException & e) { + if (e.getZKErrorCode() == ZNONODE) { + _deleted = true; + _clearChildren(); + } + LOG_ERROR(LOG, "childrenEventReceived %s exception %s", + _path.c_str(), e.what()); + _children.clear(); + } + } + } + LOG_DEBUG(LOG, "childrenEventReceived returns %d", reclaim); + } + /** + Truncate or expand the size of the cached active data. + + This method only changes the size of the cached active data. + This change is committed to ZooKeeper when the cached data + is written to the ZooKeeper node by flush(). + + Return -EFBIG is the requested size exceeds the maximum. + + \return 0 if successful, otherwise negative errno. + \param size the requested size. + */ + int truncate(off_t size) + { + int res = 0; + + { + AutoLock lock(_mutex); + res = _truncate(size); + } + + return res; + } + /** + Copy range of active data into specified output buffer. + + \return if successful, return number of bytes copied, otherwise + return negative errno. + \param buf address of the output buffer. + \param size size of the output buffer and desired number of bytes to copy. + \param offset offset into active data to start copying from. + */ + int read(char *buf, size_t size, off_t offset) const + { + LOG_DEBUG(LOG, "read(size %zu, off_t %zu) path %s", + size, offset, _path.c_str()); + + int res = 0; + + { + AutoLock lock(_mutex); + if (!_initializedData) { + LOG_DEBUG(LOG, "not initialized"); + res = -EIO; + } + else { + off_t fileSize = _activeData.size(); + if (offset > fileSize) { + LOG_DEBUG(LOG, "offset > fileSize %zu", fileSize); + res = 0; + } + else { + if (offset + size > fileSize) { + size = fileSize - offset; + LOG_DEBUG(LOG, + "reducing read size to %zu for fileSize %zu", + size, fileSize); + } + copy(_activeData.begin() + offset, + _activeData.begin() + offset + size, + buf); + res = size; + } + } + } + + LOG_DEBUG(LOG, "read returns %d", res); + return res; + } + /** + Copy buffer content to active data. + + \return if successful, return number of bytes copied, otherwise + return negative errno. + \param buf address of the buffer. + \param size size of the input buffer and desired number of bytes to copy. + \param offset offset into active data to start copying to. + */ + int write(const char *buf, size_t size, off_t offset) + { + LOG_DEBUG(LOG, "write(size %zu, off_t %zu) path %s", + size, offset, _path.c_str()); + + int res = 0; + + { + AutoLock lock(_mutex); + if (!_initializedData) { + LOG_DEBUG(LOG, "not initialized"); + res = -EIO; + } + else if (offset >= maxDataFileSize) { + LOG_DEBUG(LOG, "offset > maxDataFileSize %u", maxDataFileSize); + res = -ENOSPC; + } + else { + if (offset + size > maxDataFileSize) { + LOG_DEBUG(LOG, + "reducing write size to %zu " + "for maxDataFileSize %u", + size, maxDataFileSize); + size = maxDataFileSize - offset; + } + off_t fileSize = _activeData.size(); + if (offset + size > fileSize) { + LOG_DEBUG(LOG, "resizing to %zu", offset + size); + _activeData.resize(offset + size); + } + copy(buf, buf + size, _activeData.begin() + offset); + memcpy(&_activeData[offset], buf, size); + _dirtyData = true; + res = size; + } + } + + LOG_DEBUG(LOG, "write returns %d", res); + return res; + } + /** + Flush data to the ZooKeeper node. + + If cached active data has been modified, flush it to the ZooKeeper node. + Returns -EIO if the data cannot be written because the cached active + data is not the expected version, i.e. ZooKeeper returns ZBADVERSION. + -EIO may also indicate a more general failure, such as unable to + communicate with ZooKeeper. + + \return 0 if successful, otherwise negative errno. + */ + int flush() + { + int res = 0; + { + AutoLock lock(_mutex); + res = _flush(); + } + return res; + } + /** + Close of the ZkFuse regular file represented by the ZkFuseFile instance. + + This may: + - Flush dirty data to the ZooKeeper node, and return the result of the + flush operation. + - Reclaim the ZkFuseFile instance. + \see ZkFuseHandleManaer::reclaimIfNecessary + + \return result of flush operation - 0 if successful, + otherwise negative errno. + */ + int close() + { + LOG_DEBUG(LOG, "close() path %s", _path.c_str()); + int res = 0; + + bool reclaim = false; + { + AutoLock lock(_mutex); + res = _flush(); + if (_deleted) { + _clearData(); + _clearChildren(); + } + } + _manager->deallocate(_handle); + + LOG_DEBUG(LOG, "close returns %d", res); + return res; + } + /** + Get ZkFuse regular file or directory attributes. + + \return 0 if successful, otherwise negative errno. + \param stbuf return attributes here. + \param nameType specifies the ZkFuseNameType of the ZkFuse path used + to get attributes. It influences whether the directory + or regular file attributes are returned. + */ + int getattr(struct stat & stbuf, ZkFuseNameType nameType) const + { + LOG_DEBUG(LOG, "getattr(nameType %d) path %s", + int(nameType), _path.c_str()); + + int res = 0; + int version = 0; + std::string metaPath; + { + AutoLock lock(_mutex); + + res = _getattrNoMetaAccess(stbuf, nameType); + if (res == 0) { + version = _activeStat.version; + metaPath = _getChildPath( + ((stbuf.st_mode & S_IFMT) == S_IFREG) ? + _manager->getCommon().getRegMetadataName() : + _manager->getCommon().getDirMetadataName()); + if (_hasChildPath(metaPath) == false) { + metaPath.clear(); + } + } + } + if (res == 0 && metaPath.empty() == false) { + Data data; + int metaRes = _manager->getData(metaPath, data); + LOG_DEBUG(LOG, "metaRes %d dataSize %zu", + metaRes, data.size()); + if (metaRes == 0 && data.empty() == false) { + Metadata metadata; + _decodeMetadata(data, metadata); + LOG_DEBUG(LOG, "metadata version %u active version %u", + metadata.version, version); + if (metadata.version == version) { + /* IMPORTANT: + * Must convert from millisecs to secs before setting + * st_atime and st_mtime to avoid truncation error + * due to 64-bit to 32-bit conversion. + */ + stbuf.st_atime = millisecsToSecs(metadata.atime); + stbuf.st_mtime = millisecsToSecs(metadata.mtime); + } + } + } + + LOG_DEBUG(LOG, "getattr returns %d", res); + return res; + } + /** + Read directory entries. + This interface is defined by FUSE. + + \return 0 if successful, otherwise negative errno. + \param buf output buffer to store output directory entries. + \param filler function used to fill the output buffer. + \param offset start filling from a specific offset. + */ + int readdir(void *buf, fuse_fill_dir_t filler, off_t offset) const + { + LOG_DEBUG(LOG, "readdir(offset %zu) path %s", offset, _path.c_str()); + int res = 0; + + int dataFileIndex = -1; + unsigned leftTrim = 0; + typedef std::pair DirEntry; + typedef std::vector DirEntries; + DirEntries dirEntries; + + /* Get directory entries in two phase to avoid invoking + * ZkFuseHandleManager while holding _mutex. + * In first phase, get all the names of child nodes starting + * at offset. Also remember their index for use in second phase. + * The first phase hold _mutex. + */ + { + AutoLock lock(_mutex); + if (!_isInitialized()) { + LOG_DEBUG(LOG, "not initialized"); + res = -EIO; + } + else { + leftTrim = (_path.length() == 1 ? 1 : _path.length() + 1); + unsigned start = offset; + unsigned i; + for (i = start; i < _children.size(); i++) { + const std::string & childName = _children[i]; + if (_isMeta(childName)) { + continue; + } + dirEntries.push_back(DirEntry(childName, i)); + } + if (i == _children.size() && !_activeData.empty()) { + dataFileIndex = i + 1; + } + res = 0; + } + } + + /* Second phase starts here. + * DONOT hold _mutex as this phase invokes ZkFuseHandleManager to + * get attributes for the directory entries. + */ + if (res == 0) { + bool full = false; + for (DirEntries::const_iterator it = dirEntries.begin(); + it != dirEntries.end(); + it++) { + + ZkFuseAutoHandle childAutoHandle(_manager, it->first); + int childRes = childAutoHandle.get(); + if (childRes >= 0) { + struct stat stbuf; + int attrRes = childAutoHandle.getFile()-> + getattr(stbuf, ZkFuseNameDefaultType); + if (attrRes == 0) { + if (filler(buf, it->first.c_str() + leftTrim, + &stbuf, it->second + 1)) { + LOG_DEBUG(LOG, "filler full"); + full = true; + break; + } + } + } + } + if (full == false && dataFileIndex != -1) { + LOG_DEBUG(LOG, "include data file name"); + struct stat stbuf; + int attrRes = getattr(stbuf, ZkFuseNameRegType); + if (attrRes == 0) { + filler(buf, + _manager->getCommon().getDataFileName().c_str(), + &stbuf, dataFileIndex + 1); + } + } + } + + LOG_DEBUG(LOG, "readdir returns %d", res); + return res; + } + /** + Set the access time and modified time. + + Set the access and modifieds times on the ZkFuse regular file + or directory represented by this ZkFuseFile instance. + + Since there is no interface to change these times on a + ZooKeeper node, ZkFuse simulates this by writing to a + metadata node which is a child node of the ZooKeeper node. + ZkFuse writes the current version, the specified access + and modified times to the metadata node. + + When get attributes is invoked, get attributes will check + for the presence of this metadata node and if the version + number matches the current data version, then get attributes + will return the access and modified times stored in the + metadata node. + + \return 0 if successful, otherwise negative errno. + \param atime access time in milliseconds. + \param mtime modified time in milliseconds. + \param nameType specifies the ZkFuseNameType of the ZkFuse path used + to set access and modified times. It influences + whether the directory or regular file access and + modified times are set. + */ + int utime(uint64_t atime, uint64_t mtime, ZkFuseNameType nameType) + { + LOG_DEBUG(LOG, + "utime(atime %llu, mtime %llu, nameType %d) path %s", + (unsigned long long) atime, + (unsigned long long) mtime, + (int) nameType, _path.c_str()); + + int res = 0; + std::string metaPath; + bool exists = false; + Data data; + { + AutoLock lock(_mutex); + + if (!_isInitialized()) { + LOG_DEBUG(LOG, "not initialized"); + res = -EIO; + } + else { + bool isRegular = _isRegNameType(nameType); + Metadata metadata; + metadata.version = _activeStat.version; + metadata.atime = atime; + metadata.mtime = mtime; + metaPath = _getChildPath( + isRegular ? + _manager->getCommon().getRegMetadataName() : + _manager->getCommon().getDirMetadataName()); + exists = _hasChildPath(metaPath); + _encodeMetadata(metadata, data); + res = 0; + } + } + if (res == 0 && metaPath.empty() == false) { + res = _manager->setData(metaPath, data, exists, true); + } + + LOG_DEBUG(LOG, "utime returns %d", res); + return res; + } + /** + Remove a ZkFuse directory. + + If force is true, then the ZooKeeper node and its decendants + will be deleted. + + If force is false, then this method implements the semantics + of removing a ZkFuse directory. It will delete the ZooKeeper node + only if the ZooKeeper node have no data and no non-metadata + children. + - Return -ENOTDIR if the ZooKeeper node is not considered + to be a directory (after taking into consideration the specified + ZkFuseNameType). + - Return -ENOTEMPTY if the ZooKeeper node has data or it has + non-metadata children. + - Return -ENOENT if the ZooKeeper cannot be deleted, usually this + is because it does not exist. + + \return 0 if successful, otherwise negative errno. + \param nameType the ZkFuseNameType of the path used to specify the + directory to be removed. It influences whether ZkFuse + considers the ZooKeeper node to be a regular file or + directory. \see ZkFuseNameType + \param force set to true to bypass ZkFuse rmdir semantic check. + */ + int rmdir(ZkFuseNameType nameType, bool force) + { + int res = 0; + + { + AutoLock lock(_mutex); + res = _rmdir(nameType, force); + } + if (res == 0) { + _manager->removeChildFromParent(_path); + } + return res; + } + /** + Remove a ZkFuse regular file. + + This method implements the semantics of removing a ZkFuse regular file. + - If the ZkFuse regular file represents the data part of the + ZooKeeper node which is presented as a ZkFuse directory, + the regular file is virtually deleted by truncating the + ZooKeeper node's data. Readdir will not synthesize a regular + file entry for the data part of a ZooKeeper node if + the ZooKeeper node has no data. + - If the ZkFuse regular file represents the data part of the + ZooKeeper node which is presented as a ZkFuse regular file, + the ZooKeeper node and its decendants are deleted. + + Returns -EISDIR if the ZkFuse regular file cannot be deleted + because ZkFuse consider it to be a directory. + + \return 0 if successful, otherwise negative errno. + \param nameType the ZkFuseNameType of the path used to specify the + directory to be removed. It influences whether ZkFuse + considers the ZooKeeper node to be a regular file or + directory. \see ZkFuseNameType + */ + int unlink(ZkFuseNameType nameType) + { + int res = 0; + { + AutoLock lock(_mutex); + res = _unlink(nameType); + } + if (res == 0) { + _manager->removeChildFromParent(_path); + } + return res; + } + /** + Utility function to construct a ZooKeeper path for a child + of a ZooKeeper node. + + \return the full path of the child. + \param parent the parent's full path. + \param child the child's parent component. + */ + static std::string buildChildPath(const std::string & parent, + const std::string & child) + { + std::string s; + s.reserve(parent.length() + child.length() + 32); + if (parent.length() > 1) { + // special case for root dir + s += parent; + } + s += "/"; + s += child; + return s; + } +}; + +ZkFuseFile::DataListener ZkFuseFile::_dataListener; +ZkFuseFile::ChildrenListener ZkFuseFile::_childrenListener; + +void ZkFuseAutoHandle::reset(int handle) +{ + int old = _handle; + ZkFuseFilePtr oldFile = _file; + _handle = handle; + _initFile(); + if (old >= 0) { + assert(oldFile != NULL); + oldFile->close(); + } +} + +ZkFuseHandleManager::Handle +ZkFuseHandleManager::allocate(const std::string & path, bool & newFile) +{ + LOG_DEBUG(LOG, "allocate(path %s)", path.c_str()); + + Handle handle; + { + AutoLock lock(_mutex); + Map::iterator it = _map.find(path); + if (it == _map.end()) { + LOG_DEBUG(LOG, "not found"); + if (_freeList.empty()) { + handle = _files.size(); + _files.resize(handle + 1); + LOG_DEBUG(LOG, "free list empty, resize handle %d", handle); + } else { + handle = _freeList.back(); + _freeList.pop_back(); + LOG_DEBUG(LOG, "get from free list, handle %d", handle); + } + assert(_files[handle] == NULL); + _files[handle] = + new ZkFuseFile(SharedPtr(_thisWeakPtr), handle, path); + /* Not really supposed to invoke the new ZkFuseFile instance + * because this method is not supposed to invoke ZkFuseFile + * methods that while holding _mutex. However, it is safe + * to do without casuing deadlock because these methods + * are known not to invoke other methods, especially one + * that invoke this ZkFuseHandleManager instance. + */ + assert(_files[handle]->incRefCount(0) == 1); + _map[path] = handle; + _numInUse++; + LOG_DEBUG(LOG, "numInUse %u", _numInUse); + newFile = true; + } else { + LOG_DEBUG(LOG, "found"); + handle = it->second; + assert(_files[handle] != NULL); + int refCount = _files[handle]->incRefCount(); + if (refCount == 1) { + _numInUse++; + LOG_DEBUG(LOG, "resurrecting zombie, numInUse %u", _numInUse); + } + newFile = false; + } + } + + LOG_DEBUG(LOG, "allocate returns %d, newFile %d", handle, newFile); + return handle; +} + +void ZkFuseHandleManager::deallocate(Handle handle) +{ + LOG_DEBUG(LOG, "deallocate(handle %d)", handle); + + if (handle >= 0) { + bool reclaim = false; + ZkFuseFilePtr file; + { + AutoLock lock(_mutex); + file = _files[handle]; + assert(file != NULL); + int refCount = file->decRefCount(); + const std::string & path = file->getPath(); + LOG_DEBUG(LOG, "path %s ref count %d", path.c_str(), refCount); + if (refCount == 0) { + _numInUse--; + unsigned numCached = _files.size() - _numInUse; + if (numCached > _common.getCacheSize()) { + LOG_TRACE(LOG, + "reclaim path %s, cacheSize %u, filesSize %zu, " + "numInUse %u", + path.c_str(), + _common.getCacheSize(), _files.size(), _numInUse); + _map.erase(path); + _files[handle] = NULL; + _freeList.push_back(handle); + reclaim = true; + } + } + } + if (reclaim) { + delete file; + } + } + else { + LOG_DEBUG(LOG, "handle invalid"); + } + + LOG_DEBUG(LOG, "deallocate done"); +} + +void ZkFuseHandleManager::eventReceived(const ZKWatcherEvent & event) +{ + int eventType = event.getType(); + int eventState = event.getState(); + const std::string & path = event.getPath(); + LOG_DEBUG(LOG, "eventReceived() eventType %d, eventState %d, path %s", + eventType, eventState, path.c_str()); + + if (eventType == ZOO_DELETED_EVENT || + eventType == ZOO_CHANGED_EVENT || + eventType == ZOO_CHILD_EVENT) { + { + AutoLock lock(_mutex); + Map::iterator it = _map.find(path); + if (it != _map.end()) { + LOG_DEBUG(LOG, "path found"); + Handle handle = it->second; + ZkFuseFilePtr file = _files[handle]; + assert(file != NULL); + /* Prevent the ZkFuseFile instance from being + * deleted while handling the event. + */ + int refCount = file->incRefCount(); + if (refCount == 1) { + _numInUse++; + } + /* Pretent to be dir open. + */ + int dirCount = file->incOpenDirCount(); + { + /* _mutex is unlocked in this scope */ + AutoUnlockTemp autoUnlockTemp(lock); + if (eventType == ZOO_CHILD_EVENT) { + file->childrenEventReceived(event); + } + else if (eventType == ZOO_CHANGED_EVENT) { + file->dataEventReceived(event); + } + else { + assert(eventType == ZOO_DELETED_EVENT); + file->dataEventReceived(event); + // file->childrenEventReceived(event); + } + file->decOpenDirCount(); + deallocate(handle); + } + } + else { + LOG_WARN(LOG, + "path %s not found for event type %d, event state %d", + path.c_str(), eventType, eventState); + } + } + } + else if (eventType == ZOO_SESSION_EVENT) { + if (eventState == ZOO_CONNECTING_STATE) { + LOG_TRACE(LOG, "*** CONNECTING ***"); + { + AutoLock lock(_mutex); + for (int handle = 0; handle < _files.size(); handle++) { + ZkFuseFilePtr file = _files[handle]; + if (file != NULL) { + /* prevent the ZkFuseFile instance from being + * deleted while handling the event. + */ + int refCount = file->incRefCount(); + if (refCount == 1) { + _numInUse++; + } + /* Pretent to be dir open. + */ + int dirCount = file->incOpenDirCount(); + { + /* _mutex is unlocked in this scope */ + AutoUnlockTemp autoUnlockTemp(lock); + file->dataEventReceived(event); + file->childrenEventReceived(event); + file->decOpenDirCount(); + deallocate(handle); + } + /* this will eventually call decrement ref count */ + } + } + } + } + else if (eventState == ZOO_CONNECTED_STATE) { + LOG_TRACE(LOG, "*** CONNECTED ***"); + } + } + else { + LOG_WARN(LOG, + "eventReceived ignoring event type %d, event state %d, " + "path %s", eventType, eventState, path.c_str()); + } +} + +int ZkFuseHandleManager::getData(const std::string & path, + Data & data) +{ + LOG_DEBUG(LOG, "getData(path %s)", path.c_str()); + + int res = 0; + data.clear(); + ZkFuseAutoHandle autoHandle(SharedPtr(_thisWeakPtr), path); + res = autoHandle.get(); + if (res >= 0) { + autoHandle.getFile()->getData(data); + res = 0; + } + + LOG_DEBUG(LOG, "getData returns %d", res); + return res; +} + +int ZkFuseHandleManager::setData(const std::string & path, + const Data & data, + bool exists, + bool doFlush) +{ + LOG_DEBUG(LOG, "setData(path %s, exists %d)\n%s", + path.c_str(), exists, data.c_str()); + + int res = 0; + if (exists) { + res = open(path, false); + } else { + bool created; + res = mknod(path, S_IFREG, true, created); + } + if (res >= 0) { + ZkFuseAutoHandle autoHandle(SharedPtr(_thisWeakPtr), res); + res = autoHandle.getFile()->setData(data, doFlush); + } + + LOG_DEBUG(LOG, "setData returns %d", res); + return res; +} + +int ZkFuseHandleManager::mknod(const std::string & path, + mode_t mode, + bool mayExist, + bool & created) +{ + LOG_DEBUG(LOG, "mknod(path %s, mode %o, mayExist %d)", + path.c_str(), mode, mayExist); + + int res = 0; + created = false; + try { + if (S_ISREG(mode) == false && S_ISDIR(mode) == false) { + LOG_DEBUG(LOG, "bad mode %o", mode); + res = -EINVAL; + } + else { + Data data; + LOG_DEBUG(LOG, "create %s", path.c_str()); + created = + _common.getZkAdapter()->createNode(path, data, 0, false); + if (created) { + LOG_DEBUG(LOG, "created"); + if (S_ISDIR(mode)) { + /* is mkdir - create directory marker */ + std::string dirMetaPath = ZkFuseFile::buildChildPath + (path, _common.getDirMetadataName()); + LOG_DEBUG(LOG, "create %s", dirMetaPath.c_str()); + bool created; + int metaRes = mknod(dirMetaPath, S_IFREG, true, created); + if (metaRes >= 0) { + getFile(metaRes)->close(); + } + } + addChildToParent(path); + LOG_DEBUG(LOG, "open after create"); + res = open(path, true); + } else { + LOG_DEBUG(LOG, "create failed"); + int openRes = open(path, false); + if (openRes >= 0) { + if (mayExist == false) { + LOG_DEBUG(LOG, "create failed because already exist"); + getFile(openRes)->close(); + res = -EEXIST; + } else { + res = openRes; + } + } else { + LOG_DEBUG(LOG, "create failed but does not exist"); + res = -ENOENT; + } + } + } + } catch (const ZooKeeperException & e) { + LOG_ERROR(LOG, "mknod %s exception %s", path.c_str(), e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "mknod returns %d created %d", res, created); + return res; +} + +int ZkFuseHandleManager::mkdir(const char * path, mode_t mode) +{ + LOG_DEBUG(LOG, "mkdir(path %s, mode %o)", path, mode); + + int res = 0; + try { + ZkFuseNameType nameType; + std::string zkPath = getZkPath(path, nameType); + mode = (mode & ~S_IFMT) | S_IFDIR; + ZkFuseAutoHandle autoHandle + (SharedPtr(_thisWeakPtr), zkPath, mode, false); + res = autoHandle.get(); + if (res >= 0) { + res = 0; + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "mkdir %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "mkdir returns %d", res); + return res; +} + +int ZkFuseHandleManager::open(const std::string & path, bool justCreated) +{ + LOG_DEBUG(LOG, "open(path %s, justCreated %d)", + path.c_str(), justCreated); + + int res = 0; + try { + bool newFile; + Handle handle = allocate(path, newFile); + ZkFuseAutoHandle autoHandle(SharedPtr(_thisWeakPtr), handle); + res = getFile(handle)->update(newFile || justCreated); + if (res == 0) { + res = handle; + autoHandle.release(); + } + } catch (const ZooKeeperException & e) { + LOG_ERROR(LOG, "open %s exception %s", path.c_str(), e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "open returns %d", res); + return res; +} + +int ZkFuseHandleManager::rmdir(const char * path, bool force) +{ + LOG_DEBUG(LOG, "rmdir(path %s, force %d)", path, force); + + int res = 0; + + try { + ZkFuseNameType nameType; + std::string zkPath = getZkPath(path, nameType); + ZkFuseAutoHandle autoHandle(SharedPtr(_thisWeakPtr), zkPath); + res = autoHandle.get(); + if (res >= 0) { + res = autoHandle.getFile()->rmdir(nameType, force); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "rmdir %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "rmdir returns %d", res); + return res; +} + + +int +ZkFuseHandleManager::unlink(const char * path) +{ + LOG_DEBUG(LOG, "unlink(path %s)", path); + + ZkFuseNameType nameType; + std::string zkPath = getZkPath(path, nameType); + ZkFuseAutoHandle autoHandle(SharedPtr(_thisWeakPtr), zkPath); + int res = autoHandle.get(); + if (res >= 0) { + res = autoHandle.getFile()->unlink(nameType); + } + + LOG_DEBUG(LOG, "unlink returns %d", res); + return res; +} + +int ZkFuseHandleManager::getattr(const char *path, struct stat &stbuf) +{ + LOG_DEBUG(LOG, "getattr(path %s)", path); + + int res = 0; + try { + ZkFuseNameType nameType; + std::string zkPath = getZkPath(path, nameType); + ZkFuseAutoHandle autoHandle(SharedPtr(_thisWeakPtr), zkPath); + res = autoHandle.get(); + if (res >= 0) { + res = autoHandle.getFile()->getattr(stbuf, nameType); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "getattr %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "getattr returns %d", res); + return res; +} + +int +ZkFuseHandleManager::rename(const char * fromPath, const char * toPath) +{ + LOG_DEBUG(LOG, "rename(fromPath %s, toPath %s)", fromPath, toPath); + + ZkFuseNameType fromNameType; + std::string fromZkPath = getZkPath(fromPath, fromNameType); + ZkFuseAutoHandle fromAutoHandle(SharedPtr(_thisWeakPtr), fromZkPath); + int res = fromAutoHandle.get(); + if (res >= 0) { + LOG_DEBUG(LOG, "good fromPath"); + if (fromAutoHandle.getFile()->isDirNameType(fromNameType)) { + LOG_DEBUG(LOG, "fromPath is directory"); + res = -EISDIR; + } + } + if (res >= 0) { + ZkFuseNameType toNameType; + std::string toZkPath = getZkPath(toPath, toNameType); + bool created; + res = mknod(toZkPath.c_str(), S_IFREG, true, created); + if (res >= 0) { + ZkFuseAutoHandle toAutoHandle(SharedPtr(_thisWeakPtr), res); + if (toAutoHandle.getFile()->isDirNameType(toNameType)) { + LOG_DEBUG(LOG, "toPath is directory"); + res = -EISDIR; + } + if (res >= 0) { + LOG_DEBUG(LOG, "copy data"); + Data data; + fromAutoHandle.getFile()->getData(data); + toAutoHandle.getFile()->setData(data, true); + LOG_DEBUG(LOG, "copy metadata"); + struct stat stbuf; + int metaRes = + fromAutoHandle.getFile()->getattr(stbuf, fromNameType); + if (metaRes < 0) { + LOG_DEBUG(LOG, "get metadata failed"); + } + else { + metaRes = toAutoHandle.getFile()-> + utime(secsToMillisecs(stbuf.st_atime), + secsToMillisecs(stbuf.st_mtime), + toNameType); + if (metaRes < 0) { + LOG_DEBUG(LOG, "set metadata failed"); + } + } + } + if (created && res < 0) { + LOG_DEBUG(LOG, "undo create because copy data failed"); + int rmRes = toAutoHandle.getFile()->rmdir(toNameType, true); + } + } + } + if (res >= 0) { + LOG_DEBUG(LOG, "copy successful, unlink fromPath"); + res = fromAutoHandle.getFile()->unlink(fromNameType); + } + + LOG_DEBUG(LOG, "rename returns %d", res); + return res; +} + +void +ZkFuseHandleManager::addChildToParent(const std::string & childPath) const +{ + LOG_DEBUG(LOG, "addChildToParent(childPath %s)", childPath.c_str()); + + std::string parentPath = getParentPath(childPath); + if (!parentPath.empty()) { + AutoLock lock(_mutex); + Map::const_iterator it = _map.find(parentPath); + if (it != _map.end()) { + Handle handle = it->second; + assert(_files[handle] != NULL); + _files[handle]->addChild(childPath); + } + } + + LOG_DEBUG(LOG, "addChildToParent done"); +} + +void +ZkFuseHandleManager::removeChildFromParent(const std::string & childPath) const +{ + LOG_DEBUG(LOG, "removeChildFromParent(childPath %s)", childPath.c_str()); + + std::string parentPath = getParentPath(childPath); + if (!parentPath.empty()) { + AutoLock lock(_mutex); + Map::const_iterator it = _map.find(parentPath); + if (it != _map.end()) { + Handle handle = it->second; + assert(_files[handle] != NULL); + _files[handle]->removeChild(childPath); + } + } + + LOG_DEBUG(LOG, "removeChildFromParent done"); +} + +std::string +ZkFuseHandleManager::getParentPath(const std::string & childPath) const +{ + std::string::size_type lastPos = childPath.rfind('/'); + if (lastPos > 0) { + return std::string(childPath, 0, lastPos); + } + else { + assert(childPath[0] == '/'); + return std::string(); + } +} + +std::string +ZkFuseHandleManager::getZkPath(const char * path, ZkFuseNameType & nameType) + const +{ + LOG_DEBUG(LOG, "getZkPath(path %s)", path); + + std::string res; + unsigned pathLen = strlen(path); + const std::string & dataFileName = _common.getDataFileName(); + unsigned dataSuffixLen = dataFileName.length(); + const char * dataSuffix = dataFileName.c_str(); + unsigned dataSuffixIncludeSlashLen = dataSuffixLen + 1; + const std::string & forceDirSuffix = _common.getForceDirSuffix(); + unsigned forceDirSuffixLen = _common.getForceDirSuffix().length(); + /* Check if path is "/". If so, it is always a directory. + */ + if (pathLen == 1) { + assert(path[0] == '/'); + res = _common.getRootPathName(); + nameType = ZkFuseNameDirType; + } + /* Check if path ends of /{dataSuffix}, e.g. /foo/bar/{dataSuffix}. + * If so remove dataSuffix and nameType is ZkFuseNameRegType. + */ + else if ( + (pathLen >= dataSuffixIncludeSlashLen) && + (path[pathLen - dataSuffixIncludeSlashLen] == '/') && + (strncmp(path + (pathLen - dataSuffixLen), + dataSuffix, dataSuffixLen) == 0) + ) { + if ((pathLen - dataSuffixIncludeSlashLen) == 0) { + res = _common.getRootPathName(); + } else { + res.assign(path, pathLen - dataSuffixIncludeSlashLen); + } + nameType = ZkFuseNameRegType; + } + /* If not ZkFuseNameRegType, then check if path ends of + * {forceDirSuffix}, e.g. /foo/bar{forceDirSuffix}. + * If so remove forceDirSuffix and nameType is ZkFuseNameDirType. + */ + else if (forceDirSuffixLen > 0 && + pathLen >= forceDirSuffixLen && + strncmp(path + (pathLen - forceDirSuffixLen), + forceDirSuffix.c_str(), forceDirSuffixLen) == 0) { + res.assign(path, pathLen - forceDirSuffixLen); + nameType = ZkFuseNameDirType; + } + /* If not ZkFuseNameRegType and not ZkFuseNameDirType, then + * it is ZkFuseNameDefaultType. ZkFuse will infer type from + * ZooKeeper node's content. + */ + else { + res = path; + nameType = ZkFuseNameDefaultType; + } + /* Intermediate components of the path name may have + * forceDirSuffix, e.g. /foo/bar{forceDirSuffix}/baz. + * If so, remove the intermediate {forceDirSuffix}es. + */ + if (forceDirSuffixLen > 0) { + /* pos is an optimization to avoid always scanning from + * beginning of path + */ + unsigned pos = 0; + while ((res.length() - pos) > forceDirSuffixLen + 1) { + const char * found = + strstr(res.c_str() + pos, forceDirSuffix.c_str()); + if (found == NULL) { + break; + } + if (found[forceDirSuffixLen] == '/' || + found[forceDirSuffixLen] == '\0') { + pos = found - res.c_str(); + res.erase(pos, forceDirSuffixLen); + } + else { + pos += forceDirSuffixLen; + } + } + } + + LOG_DEBUG(LOG, "getZkPath returns %s, nameType %d", + res.c_str(), int(nameType)); + return res; +} + +static ZkFuseHandleManager::SharedPtr singletonZkFuseHandleManager; + +inline const ZkFuseHandleManager::SharedPtr & zkFuseHandleManager() +{ + return singletonZkFuseHandleManager; +} + +static +int zkfuse_getattr(const char *path, struct stat *stbuf) +{ + LOG_DEBUG(LOG, "zkfuse_getattr(path %s)", path); + + int res = 0; + try { + res = zkFuseHandleManager()->getattr(path, *stbuf); + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_getattr %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_getattr returns %d", res); + return res; +} + +static +int zkfuse_fgetattr(const char *path, struct stat *stbuf, + struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_fgetattr(path %s)", path); + + int res = 0; + int handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + res = zkFuseHandleManager()->getFile(handle)-> + getattr(*stbuf, ZkFuseNameDefaultType); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_fgetattr %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_fgetattr returns %d", res); + return res; +} + +static +int zkfuse_access(const char *path, int mask) +{ + /* not implemented */ + return -1; +} + +static +int zkfuse_readlink(const char *path, char *buf, size_t size) +{ + /* not implemented */ + return -1; +} + +static +int zkfuse_opendir(const char *path, struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_opendir(path %s)", path); + + int res = 0; + try { + ZkFuseNameType nameType; + std::string zkPath = zkFuseHandleManager()->getZkPath(path, nameType); + if (nameType == ZkFuseNameRegType) { + res = -ENOENT; + } + else { + ZkFuseAutoHandle autoHandle(zkFuseHandleManager(), zkPath); + res = autoHandle.get(); + if (res >= 0) { + autoHandle.getFile()->incOpenDirCount(); + autoHandle.release(); + fi->fh = res; + res = 0; + } + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_opendir %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_opendir returns %d", res); + return res; +} + +static int +zkfuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, + off_t offset, struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_readdir(path %s, offset %zu)", path, offset); + + int res = 0; + int handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + res = zkFuseHandleManager()->getFile(handle)-> + readdir(buf, filler, offset); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_readdir %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_readdir returns %d", res); + return res; +} + +static +int zkfuse_releasedir(const char *path, struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_releasedir(path %s)", path); + + int res = 0; + unsigned handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + zkFuseHandleManager()->getFile(handle)->decOpenDirCount(); + zkFuseHandleManager()->getFile(handle)->close(); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_releasedir %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_releasedir returns %d", res); + return res; +} + +static +int zkfuse_mknod(const char *path, mode_t mode, dev_t rdev) +{ + LOG_DEBUG(LOG, "zkfuse_mknod(path %s, mode %o)", path, mode); + + int res = 0; + try { + ZkFuseNameType nameType; + std::string zkPath = zkFuseHandleManager()->getZkPath(path, nameType); + ZkFuseAutoHandle autoHandle(zkFuseHandleManager(), zkPath, mode, false); + res = autoHandle.get(); + if (res >= 0) { + res = 0; + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_mknod %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_mknod returns %d", res); + return res; +} + +static int zkfuse_mkdir(const char *path, mode_t mode) +{ + LOG_DEBUG(LOG, "zkfuse_mkdir(path %s, mode %o", path, mode); + + int res = 0; + try { + res = zkFuseHandleManager()->mkdir(path, mode); + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_mkdir %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_mkdir returns %d", res); + return res; +} + +static int zkfuse_unlink(const char *path) +{ + LOG_DEBUG(LOG, "zkfuse_unlink(path %s)", path); + + int res = 0; + try { + res = zkFuseHandleManager()->unlink(path); + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_unlink %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_unlink returns %d", res); + return res; +} + +static int zkfuse_rmdir(const char *path) +{ + LOG_DEBUG(LOG, "zkfuse_rmdir(path %s)", path); + + int res = 0; + try { + res = zkFuseHandleManager()->rmdir(path); + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_rmdir %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_rmdir returns %d", res); + + return res; +} + +static int zkfuse_symlink(const char *from, const char *to) +{ + /* not implemented */ + return -1; +} + +static int zkfuse_rename(const char *from, const char *to) +{ + LOG_DEBUG(LOG, "zkfuse_rename(from %s, to %s)", from, to); + + int res = 0; + try { + res = zkFuseHandleManager()->rename(from, to); + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_rename %s %s exception %s", from, to, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_rename returns %d", res); + + return res; +} + +static int zkfuse_link(const char *from, const char *to) +{ + /* not implemented */ + return -1; +} + +static int zkfuse_chmod(const char *path, mode_t mode) +{ + LOG_DEBUG(LOG, "zkfuse_chmod(path %s, mode %o)", path, mode); + int res = 0; + + LOG_DEBUG(LOG, "zkfuse_chmod returns %d", res); + return res; +} + +static int zkfuse_chown(const char *path, uid_t uid, gid_t gid) +{ + LOG_DEBUG(LOG, "zkfuse_chown(path %s, uid %d, gid %d)", path, uid, gid); + + int res = 0; + + if (zkFuseHandleManager()->getCommon().getUid() == uid && + zkFuseHandleManager()->getCommon().getGid() == gid) { + res = 0; + } + else { + res = -EPERM; + } + + LOG_DEBUG(LOG, "zkfuse_chown returns %d", res); + return 0; +} + +static int zkfuse_truncate(const char *path, off_t size) +{ + LOG_DEBUG(LOG, "zkfuse_truncate(path %s, size %zu)", path, size); + + int res = 0; + try { + ZkFuseNameType nameType; + std::string zkPath = zkFuseHandleManager()->getZkPath(path, nameType); + ZkFuseAutoHandle autoHandle(zkFuseHandleManager(), zkPath); + res = autoHandle.get(); + if (res >= 0) { + res = autoHandle.getFile()->truncate(size); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_truncate %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_truncate returns %d", res); + return res; +} + +static +int zkfuse_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_ftruncate(path %s, size %zu)", path, size); + + int res = 0; + unsigned handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + res = zkFuseHandleManager()->getFile(handle)->truncate(size); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_ftruncate %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_ftruncate returns %d", res); + return res; +} + +static +int zkfuse_utimens(const char *path, const struct timespec ts[2]) +{ + LOG_DEBUG(LOG, "zkfuse_utimens(path %s)", path); + + int res = 0; + try { + uint64_t atime = timespecToMillisecs(ts[0]); + uint64_t mtime = timespecToMillisecs(ts[1]); + ZkFuseNameType nameType; + std::string zkPath = zkFuseHandleManager()->getZkPath(path, nameType); + ZkFuseAutoHandle autoHandle(zkFuseHandleManager(), zkPath); + res = autoHandle.get(); + if (res >= 0) { + res = autoHandle.getFile()->utime(atime, mtime, nameType); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_utimens %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_utimens returns %d", res); + return res; +} + +static +int zkfuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) +{ + int fd; + + fd = open(path, fi->flags, mode); + if (fd == -1) + return -errno; + + fi->fh = fd; + return 0; +} + +static +int zkfuse_open(const char *path, struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_open(path %s, flags %o)", path, fi->flags); + + int res = 0; + try { + ZkFuseNameType nameType; + std::string zkPath = zkFuseHandleManager()->getZkPath(path, nameType); + ZkFuseAutoHandle autoHandle(zkFuseHandleManager(), zkPath); + res = autoHandle.get(); + if (res >= 0) { + if (autoHandle.getFile()->isDirNameType(nameType)) { + res = -ENOENT; + } + } + if (res >= 0) { + autoHandle.release(); + fi->fh = res; + res = 0; + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_open %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_open returns %d", res); + return res; +} + +static +int zkfuse_read(const char *path, char *buf, size_t size, off_t offset, + struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_read(path %s, size %zu, offset %zu)", + path, size, offset); + + int res = 0; + unsigned handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + res = zkFuseHandleManager()->getFile(handle)-> + read(buf, size, offset); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_read %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_read returns %d", res); + return res; +} + +static +int zkfuse_write(const char *path, const char *buf, size_t size, + off_t offset, struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_write(path %s, size %zu, offset %zu)", + path, size, offset); + + int res = 0; + unsigned handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + res = zkFuseHandleManager()->getFile(handle)-> + write(buf, size, offset); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_write %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_write returns %d", res); + return res; +} + +static int zkfuse_statfs(const char *path, struct statvfs *stbuf) +{ + /* not implemented */ + return -1; +} + +static +int zkfuse_flush(const char *path, struct fuse_file_info *fi) +{ + /* This is called from every close on an open file, so call the + close on the underlying filesystem. But since flush may be + called multiple times for an open file, this must not really + close the file. This is important if used on a network + filesystem like NFS which flush the data/metadata on close() */ + + LOG_DEBUG(LOG, "zkfuse_flush(path %s)", path); + + int res = 0; + unsigned handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + res = zkFuseHandleManager()->getFile(handle)->flush(); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_flush %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_flush returns %d", res); + return res; +} + +static +int zkfuse_release(const char *path, struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_release(path %s)", path); + + int res = 0; + unsigned handle = fi->fh; + try { + if (handle <= 0) { + res = -EINVAL; + } + else { + zkFuseHandleManager()->getFile(handle)->close(); + } + } catch (const std::exception & e) { + LOG_ERROR(LOG, "zkfuse_release %s exception %s", path, e.what()); + res = -EIO; + } + + LOG_DEBUG(LOG, "zkfuse_release returns %d", res); + return res; +} + +static +int zkfuse_fsync(const char *path, int isdatasync, + struct fuse_file_info *fi) +{ + LOG_DEBUG(LOG, "zkfuse_fsync(path %s, isdatasync %d)", path, isdatasync); + + (void) isdatasync; + int res = zkfuse_flush(path, fi); + + LOG_DEBUG(LOG, "zkfuse_fsync returns %d", res); + return res; +} + +#ifdef HAVE_SETXATTR +/* xattr operations are optional and can safely be left unimplemented */ +static int zkfuse_setxattr(const char *path, const char *name, const char *value, + size_t size, int flags) +{ + int res = lsetxattr(path, name, value, size, flags); + if (res == -1) + return -errno; + return 0; +} + +static int zkfuse_getxattr(const char *path, const char *name, char *value, + size_t size) +{ + int res = lgetxattr(path, name, value, size); + if (res == -1) + return -errno; + return res; +} + +static int zkfuse_listxattr(const char *path, char *list, size_t size) +{ + int res = llistxattr(path, list, size); + if (res == -1) + return -errno; + return res; +} + +static int zkfuse_removexattr(const char *path, const char *name) +{ + int res = lremovexattr(path, name); + if (res == -1) + return -errno; + return 0; +} +#endif /* HAVE_SETXATTR */ + +static +int zkfuse_lock(const char *path, struct fuse_file_info *fi, int cmd, + struct flock *lock) +{ + (void) path; + return ulockmgr_op(fi->fh, cmd, lock, &fi->lock_owner, + sizeof(fi->lock_owner)); +} + + +static +void init_zkfuse_oper(fuse_operations & fo) +{ + memset(&fo, 0, sizeof(fuse_operations)); + fo.getattr = zkfuse_getattr; + fo.fgetattr = zkfuse_fgetattr; + // fo.access = zkfuse_access; + // fo.readlink = zkfuse_readlink; + fo.opendir = zkfuse_opendir; + fo.readdir = zkfuse_readdir; + fo.releasedir = zkfuse_releasedir; + fo.mknod = zkfuse_mknod; + fo.mkdir = zkfuse_mkdir; + // fo.symlink = zkfuse_symlink; + fo.unlink = zkfuse_unlink; + fo.rmdir = zkfuse_rmdir; + fo.rename = zkfuse_rename; + // fo.link = zkfuse_link; + fo.chmod = zkfuse_chmod; + fo.chown = zkfuse_chown; + fo.truncate = zkfuse_truncate; + fo.ftruncate = zkfuse_ftruncate; + fo.utimens = zkfuse_utimens; + // fo.create = zkfuse_create; + fo.open = zkfuse_open; + fo.read = zkfuse_read; + fo.write = zkfuse_write; + fo.statfs = zkfuse_statfs; + fo.flush = zkfuse_flush; + fo.release = zkfuse_release; + fo.fsync = zkfuse_fsync; +#ifdef HAVE_SETXATTR + // fo.setxattr = zkfuse_setxattr; + // fo.getxattr = zkfuse_getxattr; + // fo.listxattr = zkfuse_listxattr; + // fo.removexattr = zkfuse_removexattr; +#endif + fo.lock = zkfuse_lock; +}; + + +/** + * The listener of ZK events. + */ +class SessionEventListener : public ZKEventListener +{ + private: + /** + References the ZkFuseHandleManager instance that should be + invoked to service events. + */ + ZkFuseHandleManager::SharedPtr _manager; + + public: + /** + Sets the ZkFuseHandleManager instance that should be invoked + to service events. + */ + void setManager(const ZkFuseHandleManager::SharedPtr & manager) + { + _manager = manager; + } + /** + Received an event and invoke ZkFuseHandleManager instance to handle + received event. + */ + virtual void eventReceived(const ZKEventSource & source, + const ZKWatcherEvent & event) + { + _manager->eventReceived(event); + } +}; + +void +usage(int argc, char *argv[]) +{ + cout + << argv[0] + << " usage: " + << argv[0] + << " [args-and-values]+" << endl + << "nodepath == a complete path to a ZooKeeper node" << endl + << "\t--cachesize= or -c :" << endl + << " number of ZooKeeper nodes to cache." << endl + << "\t--debug or -d: " << endl + << "\t enable fuse debug mode." << endl + << "\t--help or -h: " << endl + << "\t print this message." << endl + << "\t--mount= or -m : " << endl + << "\t specifies where to mount the zkfuse filesystem." << endl + << "\t--name or -n: " << endl + << "\t name of file for accessing node data." << endl + << "\t--zookeeper= or -z : " << endl + << "\t specifies information needed to connect to zeekeeper." << endl; +} + +int +main(int argc, char *argv[]) +{ + /** + * Initialize log4cxx + */ + const std::string file("log4cxx.properties"); + PropertyConfigurator::configureAndWatch( file, 5000 ); + LOG_INFO(LOG, "Starting zkfuse"); + + /** + * Supported operations. + */ + enum ZkOption { + ZkOptionCacheSize = 1000, + ZkOptionDebug = 1001, + ZkOptionForceDirSuffix = 1002, + ZkOptionHelp = 1003, + ZkOptionMount = 1004, + ZkOptionName = 1005, + ZkOptionZookeeper = 1006, + ZkOptionInvalid = -1 + }; + + static const char *shortOptions = "c:df:hm:n:z:"; + static struct option longOptions[] = { + { "cachesize", 1, 0, ZkOptionCacheSize }, + { "debug", 0, 0, ZkOptionDebug }, + { "forcedirsuffix", 1, 0, ZkOptionForceDirSuffix }, + { "help", 0, 0, ZkOptionHelp }, + { "mount", 1, 0, ZkOptionMount }, + { "name", 1, 0, ZkOptionName }, + { "zookeeper", 1, 0, ZkOptionZookeeper }, + { 0, 0, 0, 0 } + }; + + /** + * Parse arguments + */ + bool debugFlag = false; + std::string mountPoint = "/tmp/zkfuse"; + std::string nameOfFile = "_data_"; + std::string forceDirSuffix = "._dir_"; + std::string zkHost; + unsigned cacheSize = 256; + + while (true) { + int c; + + c = getopt_long(argc, argv, shortOptions, longOptions, 0); + if (c == -1) { + break; + } + + switch (c) { + case ZkOptionInvalid: + cerr + << argv[0] + << ": ERROR: Did not specify legal argument!" + << endl; + return 99; + case 'c': + case ZkOptionCacheSize: + cacheSize = strtoul(optarg, NULL, 0); + break; + case 'd': + case ZkOptionDebug: + debugFlag = true; + break; + case 'f': + case ZkOptionForceDirSuffix: + forceDirSuffix = optarg; + break; + case 'h': + case ZkOptionHelp: + usage(argc, argv); + return 0; + case 'm': + case ZkOptionMount: + mountPoint = optarg; + break; + case 'n': + case ZkOptionName: + nameOfFile = optarg; + break; + case 'z': + case ZkOptionZookeeper: + zkHost = optarg; + break; + } + } + + /** + * Check that zkHost has a value, otherwise abort. + */ + if (zkHost.empty()) { + cerr + << argv[0] + << ": ERROR: " + << "required argument \"--zookeeper \" was not given!" + << endl; + return 99; + } + /** + * Check that zkHost has a value, otherwise abort. + */ + if (forceDirSuffix.empty()) { + cerr + << argv[0] + << ": ERROR: " + << "required argument \"--forcedirsuffix \" " + "not cannot be empty!" + << endl; + return 99; + } + /** + * Check nameOfFile has no forward slash + */ + if (nameOfFile.find_first_of('/') != std::string::npos) { + cerr + << argv[0] + << ": ERROR: " + << "'/' present in name which is not allowed" + << endl; + return 99; + } + + if (debugFlag) { + cout + << "cacheSize = " + << cacheSize + << ", debug = " + << debugFlag + << ", forceDirSuffix = \"" + << forceDirSuffix + << "\", mount = \"" + << mountPoint + << "\", name = \"" + << nameOfFile + << "\", zookeeper = \"" + << zkHost + << "\", optind = " + << optind + << ", argc = " + << argc + << ", current arg = \"" + << (optind >= argc ? "NULL" : argv[optind]) + << "\"" + << endl; + } + + SessionEventListener listener; + SynchronousEventAdapter eventAdapter; + LOG_INFO(LOG, "Create ZK adapter"); + try { + /** + * Create an instance of ZK adapter. + */ + std::string h(zkHost); + ZooKeeperConfig config(h, 1000, true, 10000); + ZkFuseCommon zkFuseCommon; + ZooKeeperAdapterSharedPtr zkPtr( + new ZooKeeperAdapter( + config, + &listener, + false + ) + ); + zkFuseCommon.setZkAdapter(zkPtr); + zkFuseCommon.setDataFileName(nameOfFile); + zkFuseCommon.setForceDirSuffix(forceDirSuffix); + zkFuseCommon.setCacheSize(cacheSize); + singletonZkFuseHandleManager = + ZkFuseHandleManagerFactory::create(zkFuseCommon); + listener.setManager(singletonZkFuseHandleManager); + zkPtr->reconnect(); + + } catch (const ZooKeeperException & e) { + cerr + << argv[0] + << ": ERROR: ZookKeeperException caught: " + << e.what() + << endl; + } catch (std::exception & e) { + cerr + << argv[0] + << ": ERROR: std::exception caught: " + << e.what() + << endl; + } + +#ifdef ZOOKEEPER_ROOT_CHILDREN_WATCH_BUG + cerr << "ZOOKEEPER_ROOT_CHILDREN_WATCH_BUG enabled" << endl; +#endif + /** + * Initialize fuse + */ + LOG_INFO(LOG, "Initialize fuse"); + umask(0); + fuse_operations zkfuse_oper; + init_zkfuse_oper(zkfuse_oper); + int fakeArgc = debugFlag ? 3 : 2; + char * fakeArgv[] = { + argv[0], + strdup(mountPoint.c_str()), + debugFlag ? strdup("-d") : NULL, + NULL + }; + int res = fuse_main(fakeArgc, fakeArgv, &zkfuse_oper, NULL); + for (unsigned i = 1; i <= 2; i++) { + if (fakeArgv[i] != NULL) { + free(fakeArgv[i]); + } + } + + return res; +} diff --git a/src/contrib/zkperl/Changes b/src/contrib/zkperl/Changes new file mode 100644 index 00000000000..c31420e5e86 --- /dev/null +++ b/src/contrib/zkperl/Changes @@ -0,0 +1,65 @@ +Net::ZooKeeper - Perl extension for Apache ZooKeeper + +Revision history +================ + +0.01 Dec 5, 2008 + - initial version + +0.02 Dec 16, 2008 + - support connection to ZooKeeper and get() method + +0.03 Jan 9, 2009 + - implemented watch mechanism for get() + +0.04 Jan 15, 2009 + - all basic ZooKeeper methods supported + +0.05 Jan 21, 2009 + - converted from T_PTROBJ to T_ZK_HASH with PERL_MAGIC_ext, + allows DESTROY() to be called repeatedly + +0.06 Jan 27, 2009 + - converted from attribute accessor methods to inner and outer hashes + with PERL_MAGIC_tied + +0.07 Jan 29, 2009 + - all tied hash methods completed + +0.08 Jan 30, 2009 + - simple thread safety enforced with CLONE_SKIP + +0.09 Feb 12, 2009 + - ACL constants + +0.10 Feb 18, 2009 + - ACL support + +0.11 Feb 21, 2009 + - ZooKeeper version check + +0.20 Feb 25, 2009 + - refactored watches as subclass + +0.30 Feb 27, 2009 + - refactored stats as subclass + +0.31 Mar 6, 2009 + - test suite completed + +0.32 Mar 25, 2009 + - initial documentation completed, first public release + +0.33 Apr 20, 2009 + - copyright donated to ASF + +0.34 Jul 14, 2009 + - support ZooKeeper 3.2.0 release + +0.35 Jul 15, 2009 + - support multiple include and library locations + +0.36 Mar 27, 2011 + - Fix zookeeper version check, but only warn since we haven't been enforcing it in a while + - Look for zookeeper includes in some sane places by default + diff --git a/src/contrib/zkperl/LICENSE b/src/contrib/zkperl/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/src/contrib/zkperl/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/contrib/zkperl/MANIFEST b/src/contrib/zkperl/MANIFEST new file mode 100644 index 00000000000..1b57436d4c4 --- /dev/null +++ b/src/contrib/zkperl/MANIFEST @@ -0,0 +1,23 @@ +Changes +LICENSE +Makefile.PL +MANIFEST +NOTICE +README +typemap +ZooKeeper.pm +ZooKeeper.xs +build/check_zk_version.c +build/check_zk_version.h +t/10_invalid.t +t/15_thread.t +t/20_tie.t +t/22_stat_tie.t +t/24_watch_tie.t +t/30_connect.t +t/35_log.t +t/40_basic.t +t/45_class.t +t/50_access.t +t/60_watch.t +t/util.pl diff --git a/src/contrib/zkperl/Makefile.PL b/src/contrib/zkperl/Makefile.PL new file mode 100644 index 00000000000..9a0996dddcf --- /dev/null +++ b/src/contrib/zkperl/Makefile.PL @@ -0,0 +1,73 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use 5.008_008; + +use Config; +use ExtUtils::MakeMaker; +use Getopt::Long; + +my $ZOO_MAJOR_VERSION = 3; +my $ZOO_REQUIRED_VERSION = qr{^$ZOO_MAJOR_VERSION\.\d+.\d+$}ismx; + +my @zk_inc_paths; +my @zk_lib_paths; + +GetOptions( + 'zookeeper-include=s' => \@zk_inc_paths, + 'zookeeper-lib=s' => \@zk_lib_paths +); + +my $zk_inc_paths = join(' ', map("-I$_", @zk_inc_paths)); +my $zk_lib_paths = join(' ', map("-L$_", @zk_lib_paths)); + +$zk_inc_paths .= ' ' unless ($zk_inc_paths eq ''); +$zk_lib_paths .= ' ' unless ($zk_lib_paths eq ''); + +my $cc = $Config{'cc'}; +my $check_file = 'build/check_zk_version'; + +my $check_out = qx($cc $zk_inc_paths $zk_lib_paths -I. -o $check_file $check_file.c 2>&1); + +if ($?) { + if ($check_out =~ /zookeeper_version\.h/) { + die("Could not determine ZooKeeper version:\n\n$check_out"); + } + else { + ## keep in sync with build/check_zk_version.h + die("Net::ZooKeeper requires at least ZooKeeper version 3.1.1\n"); + } +} + +chomp(my $zk_ver = qx($check_file)); + +if ($? >> 8 != 0) { + die "Couldn't check zookeeper version: $zk_ver: $r"; +} +elsif ($zk_ver !~ $ZOO_REQUIRED_VERSION) { + warn "Net::ZooKeeper requires ZooKeeper 3.x, found $zk_ver!"; +} + +WriteMakefile( + 'INC' => "$zk_inc_paths-I.", + 'LIBS' => [ "$zk_lib_paths-lzookeeper_mt" ], + 'NAME' => 'Net::ZooKeeper', + 'VERSION_FROM' => 'ZooKeeper.pm', + 'clean' => { 'FILES' => 'build/check_zk_version.o' } +); + diff --git a/src/contrib/zkperl/NOTICE b/src/contrib/zkperl/NOTICE new file mode 100644 index 00000000000..b68fdac518e --- /dev/null +++ b/src/contrib/zkperl/NOTICE @@ -0,0 +1,6 @@ +Net::ZooKeeper - Perl extension for Apache ZooKeeper +Copyright 2009 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + diff --git a/src/contrib/zkperl/README b/src/contrib/zkperl/README new file mode 100644 index 00000000000..bbe2a0d8f3b --- /dev/null +++ b/src/contrib/zkperl/README @@ -0,0 +1,86 @@ +Net::ZooKeeper - Perl extension for Apache ZooKeeper +==================================================== + +Net::ZooKeeper provides a Perl interface to the synchronous C API +of Apache ZooKeeper. ZooKeeper is coordination service for +distributed applications. +For details see the ZooKeeper home page at: + +http://zookeeper.apache.org/ + +INSTALLATION + +To install this module type the following, first install the +zookeeper C client, then: + + perl Makefile.PL + make + ZK_TEST_HOSTS=host:port,... make test + make install + +If the C headers and library are installed in non-standard +locations, specify them as arguments to Makefile.PL: + + perl Makefile.PL \ + --zookeeper-include=/path/to/zookeeper/client/include \ + --zookeeper-lib=/path/to/zookeeper/client/lib + +The path supplied to the --zookeeper-include option should +identify the directory that contains the zookeeper.h and other +ZooKeeper C include files. + +The path supplied to the --zookeeper-lib option should identify +the directory that contains the libzookeeper_mt library. + +When running "make test", if no ZK_TEST_HOSTS environment +variable is set, many tests will be skipped because no connection +to a ZooKeeper server is available. To execute these tests, +the ZK_TEST_HOSTS variable may be assigned a list of one or more +ZooKeeper host:port pairs, e.g., "localhost:7100,otherhost:7200". + +The ZK_TEST_PATH environment variable, if defined, specifies +the ZooKeeper path under which all test nodes should be created. +The tests expect to have full read/write/create/delete/admin +ZooKeeper permissions under this path. If no ZK_TEST_PATH +variable is defined, the root ZooKeeper path ("/") is used. + +DEPENDENCIES + +Version 3.1.1 of ZooKeeper is required at a minimum. + +For version 3.1.1, you may also want to apply some of these +additional patches to the ZooKeeper C API code: + +https://issues.apache.org/jira/browse/ZOOKEEPER-262 +https://issues.apache.org/jira/browse/ZOOKEEPER-318 + +For version 3.1.1, you may also want to apply some of these +additional patches to the ZooKeeper C API code: + +https://issues.apache.org/jira/browse/ZOOKEEPER-262 +https://issues.apache.org/jira/browse/ZOOKEEPER-466 + +This module requires that the multi-threaded version of the +ZooKeeper C API client library be available on your system. + +This in turn implies that the POSIX pthread library is available +as well. + +COPYRIGHT AND LICENCE + +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + diff --git a/src/contrib/zkperl/ZooKeeper.pm b/src/contrib/zkperl/ZooKeeper.pm new file mode 100644 index 00000000000..507f0298d16 --- /dev/null +++ b/src/contrib/zkperl/ZooKeeper.pm @@ -0,0 +1,1257 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use 5.008_008; + +use strict; +use warnings; + +package Net::ZooKeeper; + +require Exporter; +require XSLoader; + +our $VERSION = '0.36'; + +our @ISA = qw(Exporter); + +our %EXPORT_TAGS = ( + 'errors' => [qw( + ZOK + ZSYSTEMERROR + ZRUNTIMEINCONSISTENCY + ZDATAINCONSISTENCY + ZCONNECTIONLOSS + ZMARSHALLINGERROR + ZUNIMPLEMENTED + ZOPERATIONTIMEOUT + ZBADARGUMENTS + ZINVALIDSTATE + ZAPIERROR + ZNONODE + ZNOAUTH + ZBADVERSION + ZNOCHILDRENFOREPHEMERALS + ZNODEEXISTS + ZNOTEMPTY + ZSESSIONEXPIRED + ZINVALIDCALLBACK + ZINVALIDACL + ZAUTHFAILED + ZCLOSING + ZNOTHING + )], + 'node_flags' => [qw( + ZOO_EPHEMERAL + ZOO_SEQUENCE + )], + 'acl_perms' => [qw( + ZOO_PERM_READ + ZOO_PERM_WRITE + ZOO_PERM_CREATE + ZOO_PERM_DELETE + ZOO_PERM_ADMIN + ZOO_PERM_ALL + )], + 'acls' => [qw( + ZOO_OPEN_ACL_UNSAFE + ZOO_READ_ACL_UNSAFE + ZOO_CREATOR_ALL_ACL + )], + 'events' => [qw( + ZOO_CREATED_EVENT + ZOO_DELETED_EVENT + ZOO_CHANGED_EVENT + ZOO_CHILD_EVENT + ZOO_SESSION_EVENT + ZOO_NOTWATCHING_EVENT + )], + 'states' => [qw( + ZOO_EXPIRED_SESSION_STATE + ZOO_AUTH_FAILED_STATE + ZOO_CONNECTING_STATE + ZOO_ASSOCIATING_STATE + ZOO_CONNECTED_STATE + )], + 'log_levels' => [qw( + ZOO_LOG_LEVEL_OFF + ZOO_LOG_LEVEL_ERROR + ZOO_LOG_LEVEL_WARN + ZOO_LOG_LEVEL_INFO + ZOO_LOG_LEVEL_DEBUG + )] +); + +{ + my %tags; + + push @{$EXPORT_TAGS{'all'}}, + grep {!$tags{$_}++} @{$EXPORT_TAGS{$_}} foreach (keys(%EXPORT_TAGS)); +} + +our @EXPORT_OK = ( @{$EXPORT_TAGS{'all'}} ); + +XSLoader::load('Net::ZooKeeper', $VERSION); + +1; + +__END__ + +=head1 NAME + +Net::ZooKeeper - Perl extension for Apache ZooKeeper + +=head1 SYNOPSIS + + use Net::ZooKeeper qw(:node_flags :acls); + + my $zkh = Net::ZooKeeper->new('localhost:7000'); + + $zkh->create('/foo', 'bar', + 'flags' => ZOO_EPHEMERAL, + 'acl' => ZOO_OPEN_ACL_UNSAFE) or + die("unable to create node /foo: " . $zkh->get_error() . "\n"); + + print "node /foo has value: " . $zkh->get('/foo') . "\n"; + + $zkh->set('/foo', 'baz'); + + print "node / has child nodes:\n"; + foreach my $path ($zkh->get_children('/')) { + print " /$path\n"; + } + + my $stat = $zkh->stat(); + if ($zkh->exists('/foo', 'stat' => $stat)) { + print "node /foo has stat info:\n"; + while (my($key,$value) = each(%{$stat})) { + print " $key: $value\n"; + } + } + + foreach my $acl_entry ($zkh->get_acl('/foo')) { + print "node /foo has ACL entry:\n"; + print " perms: $acl_entry->{perms}\n"; + print " scheme: $acl_entry->{scheme}\n"; + print " id: $acl_entry->{id}\n"; + } + + my $watch = $zkh->watch('timeout' => 10000); + $zkh->exists('/foo', 'watch' => $watch); + + if ($watch->wait()) { + print "watch triggered on node /foo:\n"; + print " event: $watch->{event}\n"; + print " state: $watch->{state}\n"; + } + else { + print "watch timed out after 10 seconds\n"; + } + + $zkh->delete('/foo'); + +=head1 DESCRIPTION + +Net::ZooKeeper provides a Perl interface to the synchronous C API +of Apache ZooKeeper. ZooKeeper is coordination service for +distributed applications. + +Each connection to ZooKeeper is represented as a handle object +of the class Net::ZooKeeper, similar to the manner in which database +connections are represented in the DBI module. + +To disconnect from ZooKeeper, simply destroy the Net::ZooKeeper +handle object by undefining it or by explicitly calling the +C method. + +The methods which may be invoked on Net::ZooKeeper handles +correspond to the functions of the synchronous ZooKeeper C API; +e.g., the Net::ZooKeeper method C calls the ZooKeeper +C function C, C calls C, +and so forth. + +The synchronous API functions wait for a response from the ZooKeeper +cluster before returning a result to the caller. Using these +functions permits Net::ZooKeeper to provide an interface similar +to that of a DBI driver module. + +=head2 Internal POSIX Threads + +The use of the synchronous ZooKeeper C API still requires that +the ZooKeeper C client code create several POSIX threads which run +concurrently with the main thread containing the Perl interpreter. + +The synchronous API functions are wrappers of the asynchronous +functions in the ZooKeeper C API. When a request is made by the +caller's thread (i.e., the one with the running Perl interpreter), +it is enqueued for delivery at a later time by the ZooKeeper C client +code's IO thread. The caller's thread then waits for notification +before returning from the synchronous API function. + +The IO thread dequeues the request and sends it to the ZooKeeper +cluster, while also ensuring that a regular "heartbeat" is maintained +with the cluster so that the current session does not time out. +When the IO thread receives a response from +the ZooKeeper cluster, it enqueues the response for delivery to the +client by the second thread of the ZooKeeper client code, the +completion thread. + +If the caller is using the asynchronous API, the completion thread +invokes the appropriate callback function provided by the caller +for the given request. In the case of Net::ZooKeeper, it is not +viable for the completion thread to invoke a Perl callback function +at arbitrary times; this could interfere with the state of the +Perl interpreter. + +For this reason Net::ZooKeeper uses the synchronous API only. After +enqueuing requests the synchronous API functions wait for notification +of the corresponding response. The completion thread delivers these +notifications, at which point the synchronous functions return to +their caller. + +Note that the IO and completion threads are POSIX threads, not +Perl ithreads. Net::ZooKeeper defined a C function so +that if Perl ithreads are spawned while a Net::ZooKeeper connection +is active, the Net::ZooKeeper handle objects inherited by the +spawned ithread contain undefined values so that they can not be used. +Thus each ithread will need to create its own private connections to a +ZooKeeper cluster. + +Note also that before invoking C to spawn a new process, +all Net::ZooKeeper handles should be destroyed so that all +connections to ZooKeeper are closed and all internal POSIX threads +have exited. If a child process needs to communicate with +ZooKeeper it should open its own private connections after it is +created by C. + +=head2 Signals + +The ZooKeeper C API uses TCP connections to communicate with +the ZooKeeper cluster. These connections may generate SIGPIPE +signals when they encounter errors, such as when a connection +is terminated by a ZooKeeper server. Therefore most applications +will want to trap or ignore SIGPIPE signals, e.g.: + + local $SIG{'PIPE'} = 'IGNORE'; + +Ignoring SIGPIPE signals (or providing a signal handler that returns +control to the interrupted program after receiving the signal) +will allow the ZooKeeper C client code to detect the connection error +and report it upon return from the next Net::ZooKeeper method. + +=head2 Error Handling + +Net::ZooKeeper methods return different values in the case of an +error depending on their purpose and context. For example, +C returns true if the node exists and false otherwise, +which may indicate either that the node does not exist or that +an error occurred. + +After any method returns a false, empty, or undefined value which +might indicate an error has occurred, the C method +may be called to examine the specific error code, if any. + +If C returns C, no error has occurred. If the +error code is less than C, it indicates a normal error +condition reported by the ZooKeeper server, such as C +(node does not exist) or C (node already exists). + +If the error code is greater than C, then a connection +error or server error has occurred and the client should probably +close the connection by undefining the Net::ZooKeeper handle object +and, if necessary, attempt to create a new connection to the +ZooKeeper cluster. + +=head2 Access Control + +If the ZooKeeper cluster is not configured with C then +it will respect the access controls set for each node in the +ZooKeeper hierarchy. These access controls are defined using ACLs +(Access Control Lists); see the ZooKeeper documentation for compete +details. + +In Net::ZooKeeper, ACLs are represented as arrays of hashes, where +each hash is an ACL entry that must contain three attributes, +C, C, and C. The C attribute's value +should be composed by combining ACL permission flags using the +bitwise OR operator. See C<:acl_perms> for a list of the +available ACL permission flags. + +The ACL for a node may be read using the C method. A +node's ACL may be set when the node is created by passing an ACL +array as the value of the C<'acl'> option to the C method, +and may be updated by passing an ACL array to the C method. + +When a client connects to a ZooKeeper cluster it is automatically +assigned authentication credentials based on its IP address. +Additional authentication credentials may be added using +the C method. Once a credential has been added for +the current session, there is no way to disable it. + +As an example, digest authentication may be enabled for a session +by calling C as follows: + + $zkh->add_auth('digest', "$username:$password"); + +Note that the username and password are transmitted in cleartext +to the ZooKeeper cluster. + +Such authentication credentials would enable access to a node +whose ACL contained an entry with a C attribute of +C<'digest'> and an C attribute containing a Base64-encoded +SHA1 digest of the string C<"$username:$password">. The +Perl modules Digest and MIME::Base64 may be used to create +such ACL ID values as follows: + + use Digest qw(); + use MIME::Base64 qw(); + + my $ctx = Digest->new('SHA-1')->add("$username:$password"); + my $digest = MIME::Base64::encode($ctx->digest()); + +Note that using the C method of the Digest module +will not result in digest strings with the "=" suffix characters +required by ZooKeeper. + +=head2 Logging + +As of ZooKeeper version 3.1.1, logging in the C client code is +implemented with a single, shared file handle to which all +of the internal POSIX threads write log messages; by default, +this file handle is attached to STDERR. + +Moreover, this file handle is shared by all active ZooKeeper +connections (each of which has its own private IO and completion +threads; see L above). + +Net::ZooKeeper therefore does not provide per-connection handle +attributes related to logging. The global function +C may be used to set the current +log level. See C<:log_levels> for a list of the available log +levels. The default log level is C. + +To capture ZooKeeper log messages to a file instead of STDERR, +redirect STDERR to a new file handle in the normal Perl manner: + + open(OLDERR, '>&', fileno(STDERR)) or + die("unable to dup STDERR: $!"); + open(STDERR, '>', $log_file) or + die("unable to redirect STDERR: $!"); + +=head2 Connection Order + +ZooKeeper clusters are typically made up of an odd number of +ZooKeeper servers. When connecting to such a cluster, the +C method should be passed a comma-separated list of +the hostnames and ports for each of the servers in the cluster, +e.g., C<'host1:7000,host2:7000,host2:7100'>. + +The default behaviour of the ZooKeeper client code is to +reorder this list randomly before making any connections. +A connection is then made to the first server in the reordered +list. If that connection fails, the IO thread will +automatically attempt to reconnect to the cluster, this time +to the next server in the list; when the last server in the list +is reached, the IO thread will continue again with the first +server. + +For certain purposes it may be necessary for ZooKeeper clients +to know the exact order in which the IO thread will attempt to +connect to the servers of a cluster. To do so, call +C. Note, +however, that this will affect all Net::ZooKeeper object +handles created by the current process. + +=head1 ATTRIBUTES + +=head2 Net::ZooKeeper + +The Net::ZooKeeper class provides the main interface to the +ZooKeeper client API. The following attributes are available +for each Net::ZooKeeper handle object and are specific to +that handle and the method calls invoked on it. As with DBI +handle objects, attributes may be read and written through +a hash interface, e.g.: + + print sprintf("Session timeout is %.2f seconds.\n", + $zkh->{session_timeout} / 1000); + + $zkh->{watch_timeout} = 10000; + +=over 4 + +=item hosts + +The comma-separated list of ZooKeeper server hostnames and ports +as passed to the C method. Note that by default the +ZooKeeper C client code will reorder this list before attempting +to connect for the first time; see L for details. + +This attribute is B and may not be modified. + +=item session_timeout + +The session timeout value, in milliseconds, as set by the +ZooKeeper server after connection. This value may not be +exactly the same as what was requested in the C<'session_timeout'> +option of the C method; the server will adjust the +requested timeout value so that it is within a certain range +of the server's C setting. See the ZooKeeper +documentation for details. + +Because the actual connection to the ZooKeeper server is +not made during the C method call but shortly +thereafter by the IO thread, note that this value may not +be initialized to its final value until at least one +other method which requires communication with the server +(such as C) has succeeded. + +This attribute is B and may not be modified. + +=item session_id + +The client's session ID value as set by the ZooKeeper server +after connection. This is a binary data string which may +be passed to subsequent C calls as the value of +the C<'session_id'> option, if the user wishes to attempt to +continue a session after a failure. Note that the server +may not honour such an attempt. + +Because the actual connection to the ZooKeeper server is +not made during the C method call but shortly +thereafter by the IO thread, note that this value may not +be initialized to its final value until at least one +other method which requires communication with the server +(such as C) has succeeded. + +This attribute is B and may not be modified. + +=item data_read_len + +The maximum length of node data that will be returned to +the caller by the C method. If a node's data exceeds +this length, the returned value will be shorter than the +actual node data as stored in the ZooKeeper cluster. + +The default maximum length of the node data returned by +C is 1023 bytes. This may be changed by setting +the C attribute to a different value. + +Passing a value for the C<'data_read_len'> option when calling +the C method will temporarily override the per-handle +maximum. + +=item path_read_len + +The maximum length of a newly created node's path that will +be returned to the caller by the C method. If the path +of the newly created node exceeds this length, the returned +value will be shorter than the actual path of the node as stored +in the ZooKeeper cluster. + +The default maximum length of the node path returned by +C is 1023 bytes. This may be changed by setting +the C attribute to a different value. + +Passing a value for the C<'path_read_len'> option when calling +the C method will temporarily override the current +value of this attribute. + +=item watch_timeout + +The C attribute value, in milliseconds, inherited by +all watch objects (of class Net::ZooKeeper::Watch) created by +calls to the C method. When a watch object's +C method is invoked without a C<'timeout'> option, +it waits for an event notification from the ZooKeeper cluster +for no longer than the timeout period specified by the value of +the watch object's C attribute. + +The default C attribute value for all watch objects +created by the C method is 1 minute (60000 +milliseconds). This may be changed for a particular handle +object by setting this attribute to a different value; afterwards, +the new value will be inherited by any watch objects created +by the handle object's C method. Previously +created watch objects will not be affected. + +Passing a value for the C<'timeout'> option when calling +the C method will temporarily override the current +value of this attribute and cause the newly created watch object +to inherit a different value. + +See also the C method, and the C attribute +and C method of the Net::ZooKeeper::Watch class. + +=item pending_watches + +The number of internal ZooKeeper watches created for this handle +object that are still awaiting an event notification from the +ZooKeeper cluster. + +Note that this number may be different than the number of +extant watch objects created by the handle object's C +method, not only because some event notifications may have +occurred, but also if any watch objects have been reassigned +by reusing them in more than one call to any of the C, +C, or C methods. + +This attribute is B and may not be modified. + +=back + +=head2 Net::ZooKeeper::Stat + +The Net::ZooKeeper::Stat class provides a hash interface to +the individual pieces of information which together compose the +state of a given ZooKeeper node. Net::ZooKeeper::Stat objects +are created by calling the C method on a Net::ZooKeeper +handle object, and may then be passed to any methods which accept +a C<'stat'> option value, such as C. + +Net::ZooKeeper::Stat objects may be reused multiple times. +If the Net::ZooKeeper method to which the stat object is +passed succeeds, then the stat object is updated with the newly +retrieved node state information, and any state information +previously stored in the stat object is overwritten. + +All of the attributes of stat objects are B. + +=over 4 + +=item ctime + +The creation time of the node in milliseconds since the epoch. + +=item mtime + +The time of the last modification of the node's data in +milliseconds since the epoch. + +=item data_len + +The length of the node's data in bytes. + +=item num_children + +The number of child nodes beneath of the current node. + +=item ephemeral_owner + +If the node was created with the C flag, +this attribute holds the session ID of the ZooKeeper client +which created the node. If the node was not created with +the C flag, this attribute is set to zero. + +=item version + +The number of revisions of the node's data. The ZooKeeper +cluster will increment this version number whenever the +node's data is changed. When the node is first created this +version number is initialized to zero. + +=item acl_version + +The number of revisions of the node's ACL. The ZooKeeper +cluster will increment this version number whenever the +node's ACL is changed. When the node is first created this +version number is initialized to zero. + +=item children_version + +The number of revisions of the node's list of child nodes. +The ZooKeeper cluster will increment this version number +whenever the list of child nodes is changed. When the node +is first created this version number is initialized to zero. + +=item czxid + +The ZooKeeper transaction ID (ZXID) of the transaction which +created the node. + +=item mzxid + +The ZooKeeper transaction ID (ZXID) of the transaction which +last modified the node's data. This is initially set to +the same transaction ID as the C attribute by the +C method. + +=item children_zxid + +The ZooKeeper transaction ID (ZXID) of the transaction which +last modified the node's list of child nodes. This is +initially set to the same transaction ID as the C +attribute by the C method. + +=back + +=head2 Net::ZooKeeper::Watch + +The Net::ZooKeeper::Watch class provides a hash interface +to the data returned by event notifications from the ZooKeeper +cluster. Net::ZooKeeper::Watch objects are created by calling +the C method on a Net::ZooKeeper handle object, and +may then be passed to any methods which accept a C<'watch'> +option value, such as C. + +Net::ZooKeeper::Watch objects may be reused multiple times. +Regardless of whether the Net::ZooKeeper method to which the +watch object is passed succeeds, the watch object will be +updated to receive an event notification exclusively for the +node referenced in that method call. In the case of an error, +however, the watch object may never receive any event +notification. + +=over 4 + +=item timeout + +The default timeout value, in milliseconds, for all +invocations of the C method made on the watch object. +When the C method is invoked without a +C<'timeout'> option value, it waits for an +event notification from the ZooKeeper cluster for no longer +than the timeout period specified by this attribute. +This default timeout period may be altered by setting this +attribute to a different value. + +Passing a value for the C<'timeout'> option when calling +the C method will temporarily override the current +value of this attribute and cause the C method to +use a different timeout period. + +When a Net::ZooKeeper handle object's C method is +invoked without a C<'timeout'> option, it returns a newly +created watch object whose C attribute value +is initialized to the current value of the handle object's +C attribute. When the C method is invoked +with a C<'timeout'> option, the new watch object's C +attribute value is initialized to the value specified by +the C<'timeout'> option. + +See also the C method, and the C attribute +and C method of the Net::ZooKeeper class. + +=item event + +The type of event which triggered the notification, such +as C if the node's data was changed. +See C<:events> for a list of the possible event types. +If zero, no event notification has occurred yet. + +Note that the events which will trigger a notification +will depend on the Net::ZooKeeper method to which +the watch object was passed. Watches set through the +C and C methods will report events relating +to the node's data, while watches set through the +C method will report events relating to the +creation or deletion of child nodes of the watched node. + +This attribute is B and may not be modified. + +=item state + +The state of the Net::ZooKeeper connection at the time of +the event notification. See C<:states> for a list of +the possible connection states. If zero, no event +notification has occurred yet. + +This attribute is B and may not be modified. + +=back + +=head1 METHODS + +=head2 Net::ZooKeeper + +The following methods are defined for the Net::ZooKeeper class. + +=over 4 + +=item new() + + $zkh = Net::ZooKeeper->new('host1:7000,host2:7000'); + $zkh = Net::ZooKeeper->new('host1:7000,host2:7000', + 'session_timeout' => $session_timeout, + 'session_id' => $session_id); + +Creates a new Net::ZooKeeper handle object and attempts to +connect to the one of the servers of the given ZooKeeper +cluster. As described in the L and +L sections, the ZooKeeper client code will +create an IO thread which maintains the connection with a +regular "heartbeat" request. In the event of a connection error +the IO thread will also attempt to reconnect to another one of +the servers using the same session ID. In general, these actions +should be invisible to the user, although Net::ZooKeeper methods +may return transient errors while the IO thread +reconnects with another server. + +To disconnect, undefine the Net::ZooKeeper handle object +or call the C method. (After calling C +the handle object can not be reused.) + +The ZooKeeper client code will send a "heartbeat" message +if a third of the session timeout period has elapsed without +any communication with the ZooKeeper server. A specific +session timeout period may be requested when creating a +Net::ZooKeeper handle object by supplying a value, in +milliseconds, for the C<'session_timeout'> option. The +ZooKeeper server adjust the requested timeout value so that +it is within a certain range of the server's C setting; +the actual session timeout value will be available as the +value of the handle's C attribute after at +least one method call has succeeded. See the C +attribute for more information. + +If no C<'session_timeout'> option is provided, the default +value of 10 seconds (10000 milliseconds) will be used in the +initial connection request; again, the actual timeout period to +which the server agrees will be available subsequently as the +value of the C attribute. + +Upon successful connection (i.e., after the success of a method +which requires communication with the server), the C +attribute will hold a short binary string which represents the +client's session ID as set by the server. All ephemeral nodes +created by the session are identified by this ID in the +C attribute of any Net::ZooKeeper::Stat objects +used to query their state. + +The ZooKeeper client code will use this session ID internally +whenever it tries to reconnect to another server in the ZooKeeper +cluster after detecting a failed connection. If it successfully +reconnects with the same session ID, the session will continue +and ephemeral nodes belonging to it will not be deleted. + +However, if the server determines that the session has timed +out (for example because no "heartbeat" requests have been +received within the agreed-upon session timeout period), the +session will be terminated by the cluster and all ephemeral nodes +owned by the current session automatically deleted. + +On occasion the ZooKeeper client code may not be able to quickly +reconnect to a live server and the caller may want to destroy +the existing Net::ZooKeeper handle object and attempt a +fresh connection using the same session ID as before with a +new Net::ZooKeeper object. To do so, save the C +attribute value before undefining the old handle object +and then pass that binary string as the value of the +C<'session_id'> option to the C method when creating the +next handle object. After the successful completion of a +method which requires communication with the server, if the +new handle object's C attribute value matches the +old session ID then the session has been successfully maintained; +otherwise, the old session was expired by the cluster. + +=item get_error() + + $code = $zkh->get_error(); + +Returns the ZooKeeper error code, if any, from the most +recent Net::ZooKeeper method invocation. The returned value +will be zero (equivalent to C) if no error occurred, +otherwise non-zero. Non-zero values may be compared to +the error code names exported by the C<:errors> tagset. + +See L for more details. + +=item add_auth() + + $zkh->add_auth('digest', "$username:$password"); + +The C method may be used to add authentication +credentials to a session. Once a credential has been added for +the current session, there is no way to disable it. + +When using the digest authentication scheme, note that the +username and password are transmitted in cleartext +to the ZooKeeper cluster. + +See L for additional details. + +=item create() + + $path = $zkh->create($req_path, $data); + $path = $zkh->create($req_path, $data, + 'flags' => (ZOO_EPHEMERAL | ZOO_SEQUENCE), + 'acl' => ZOO_OPEN_ACL_UNSAFE, + 'path_read_len' => 100); + +Requests that a node be created in the ZooKeeper cluster's +hierarchy with the given path and data. Upon success, +the returns the node's path, otherwise undef. + +The path returned by a successful C method call +may not be the new node's full path as it appears in the +ZooKeeper hierarchy, depending on the length of the actual +path and the value of the handle object's C +attribute. If the length of the actual path exceeds the +current value of the C attribute, the path +returned by the C method will be truncated; note +that the node's path in the ZooKeeper hierarchy is not +affected by this truncation. + +Specifying a value for the C<'path_read_len'> option will +temporarily override the value of the C +attribute for the duration of the C method. + +The flag values available for use with the C<'flags'> option +are C and C; both are +included in the C<:flags> tagset. The flags should be +combined with the bitwise OR operator if more than one +is required. + +The C flag causes the node to be marked as +ephemeral, meaning it will be automatically deleted if it +still exists when the client's session ends. The +C flag causes a unique integer to be appended +to the node's final path component. See the ZooKeeper +documentation for additional advice on how to use these flags. + +When creating a node it may be important to define an ACL +for it; to do this, pass a reference to an ACL array (as +described in L) using the C<'acl'> option. +See also the C<:acl_perms> and C<:acls> tagsets for lists +of the available ACL permission flags and pre-defined ACLs. + +=item delete() + + $ret = $zkh->delete($path); + $ret = $zkh->delete($path, 'version' => $version); + +Requests that a node be deleted from the ZooKeeper hierarchy. +Returns true upon success, false otherwise. + +If a value for the C<'version'> option is supplied, the node +will only be deleted if its version number matches the given +value. See the C attribute of the Net::ZooKeeper::Stat +class for details on node version numbering. + +=item exists() + + $ret = $zkh->exists($path); + $ret = $zkh->exists($path, 'stat' => $stat, 'watch' => $watch); + +Tests whether a given node exists. Returns true if the node +exists, otherwise false. When the C method is successful +but the node does not exist, it returns false, and C +will return C until another method is called on the +handle object. + +The C<'stat'> option may be used to request that a +Net::ZooKeeper::Stat object be updated with the node's +current state information. The stat object will only be +updated if the node exists and the C method +succeeds. The stat object must first have been created +using the C method. + +The C<'watch'> option may be used to request that a +Net::ZooKeeper::Watch object be assigned to receive +notification of an event which alters the node's data. +The watch object must first have been created using the +C method. If the watch object was previously +assigned to receive notifications for another node, it +will be reassigned even if the C method fails. + +=item get_children() + + @child_names = $zkh->get_children($path); + $num_children = $zkh->get_children($path, 'watch' => $watch); + +Queries the names or number of the child nodes stored beneath +a given node in the ZooKeeper hierarchy. In a list context, +returns a list of the child nodes' names upon success, otherwise +an empty list. When the C method is successful +but there are no child nodes, it returns an empty list, and +C will return C until another method is called +on the handle object. + +In a scalar context, C returns the number +of child nodes upon success, otherwise undef. + +The names of the child nodes are simply the final component +of the nodes' paths, i.e., the portion of their path which +follows the path of the given parent node, excluding the +"/" delimiter. + +The C<'watch'> option may be used to request that a +Net::ZooKeeper::Watch object be assigned to receive +notification of an event which alters the node's list of +child nodes. The watch object must first have been created +using the C method. If the watch object was +previously assigned to receive notifications for another node, +it will be reassigned even if the C method fails. + +=item get() + + $data = $zkh->get($path); + $data = $zkh->get($path, 'data_read_len' => 100, + 'stat' => $stat, 'watch' => $watch); + +Queries the data stored in a given node. Returns the +data as a string upon success, otherwise undef. Note +that the data may contain nulls if the node's data is +not a text string. + +If the length of the node's data exceeds the current value +of the handle object's C attribute, the +string returned by the C method will be truncated; +note that the node's data in the ZooKeeper cluster is not +affected by this truncation. + +Specifying a value for the C<'data_read_len'> option will +temporarily override the value of the C +attribute for the duration of the C method. + +The C<'stat'> option may be used to request that a +Net::ZooKeeper::Stat object be updated with the node's +current state information. The stat object will only be +updated if the C method succeeds. The stat object +must first have been created using the C method. + +The C<'watch'> option may be used to request that a +Net::ZooKeeper::Watch object be assigned to receive +notification of an event which alters the node's data. +The watch object must first have been created using the +C method. If the watch object was previously +assigned to receive notifications for another node, it +will be reassigned even if the C method fails. + +=item set() + + $ret = $zkh->set($path, $data); + $ret = $zkh->set($path, $data, 'version' => $version, + 'stat' => $stat); + +Requests that a node's data be updated in the ZooKeeper +hierarchy. Returns true upon success, false otherwise. + +If a value for the C<'version'> option is supplied, the node's +data will only be updated if its version number matches the +given value. See the C attribute of the +Net::ZooKeeper::Stat class for details on node version numbering. + +The C<'stat'> option may be used to request that a +Net::ZooKeeper::Stat object be updated with the node's +current state information. The stat object will only be +updated if the C method succeeds. The stat object +must first have been created using the C method. + +=item get_acl() + + @acl = $zkh->get_acl($path); + $num_acl_entries = $zkh->get_acl($path, 'stat' => $stat); + +Queries the ACL associated with a node in the ZooKeeper +hierarchy, if any. In a list context, returns an array with +the node's ACL entries upon success, otherwise +an empty list. When the C method is successful +but there are no ACL entries, it returns an empty list, and +C will return C until another method is called +on the handle object. + +The elements of the returned array are hashes, each of which +represents one ACL entry. Each hash contains C, +C, and C elements. See the L +section for additional details, and the +C<:acl_perms> and C<:acls> tagsets for lists of the +available ACL permission flags and pre-defined ACLs. + +In a scalar context, C returns the number +of ACL entries upon success, otherwise undef. + +The C<'stat'> option may be used to request that a +Net::ZooKeeper::Stat object be updated with the node's +current state information. The stat object will only be +updated if the C method succeeds. The stat object +must first have been created using the C method. + +=item set_acl() + + $acl = [{ + 'perms' => (ZOO_PERM_READ | ZOO_PERM_WRITE), + 'scheme' => 'digest', + 'id' => "$username:$digest" + }]; + $ret = $zkh->set_acl($path, $acl); + $ret = $zkh->set_acl($path, ZOO_OPEN_ACL_UNSAFE, + 'version' => $version); + +Requests that a node's ACL be updated in the ZooKeeper +hierarchy. Returns true upon success, false otherwise. + +The ACL should be passed as a reference to an array of +hashes, where each hash represents one ACL entry. Each +hash should contain C, C, and C elements +as described in the L section. +See also the C<:acl_perms> and C<:acls> tagsets for lists +of the available ACL permission flags and pre-defined ACLs. + +If a value for the C<'version'> option is supplied, the node's +ACL will only be updated if its version number matches the +given value. See the C attribute of the +Net::ZooKeeper::Stat class for details on node version numbering. + +=item stat() + + $stat = $zkh->stat(); + +Creates a new Net::ZooKeeper::Stat object which may be used +with the C<'stat'> option of the C, C, +C, and C methods. When the stat object +is passed to any of these methods, upon success its attribute +values are updated to reflect the current state of the +node specified in the method call. The stat object is not +updated if the method call does not succeed. + +=item watch() + + $watch = $zkh->watch(); + $watch = $zkh->watch('timeout' => $timeout); + +Creates a new Net::ZooKeeper::Watch object which may be +used to wait for event notifications from the ZooKeeper +cluster. Each time the watch object is passed to any +of the C, C, or C methods, +its attribute values are immediately reset to zero, and will +later be updated upon receipt of an appropriate event +notification for the node specified in the method call. + +The specific types of events which cause notifications to be +sent by the ZooKeeper cluster depend on the method call used. +After use with the C and C methods, the +watch object will be set to receive an event notification +caused by a modification of the node's data or the node itself +(e.g., deletion of the node). After use with the +C method, the watch object will be set to +receive an event notification caused by a modification +of the node's list of child nodes. + +Watch objects receive at most one event notification after +their assignment to a node by one of the C, +C, or C methods. Note that in the +case of an error, the watch object may never receive any +event notification. However, when the parent Net::ZooKeeper +handle object experiences a connection error, the ZooKeeper +client code will notify all pending watches with an event of +type C. See C for more information +regarding the watch object's attribute values after a +connection error. + +A watch object may be reused with another C, +C, or C method call at any time, +in which case the watch object's attribute values +are reset to zero and the watch object will no longer be updated +by any event notification relevant to the previous method call. + +When the C method is invoked without a C<'timeout'> +option, it returns a newly created watch object whose C +attribute value is initialized to the current value of the +Net::ZooKeeper handle object's C attribute. +Otherwise, when the C method is invoked with a +C<'timeout'> option, the new watch object's C attribute +value is initialized to the value specified by the +C<'timeout'> option. + +See also the C attribute, and the C +attribute and C method of the Net::ZooKeeper::Watch +class. + +=back + +=head2 Net::ZooKeeper::Stat + +No methods are defined for the Net::ZooKeeper::Stat class. + +=head2 Net::ZooKeeper::Watch + +Only one method is defined for the Net::ZooKeeper::Watch class. + +=over 4 + +=item wait() + + $ret = $watch->wait(); + $ret = $watch->wait('timeout' => $timeout); + +Waits for an event notification from the ZooKeeper cluster +for the node most recently associated with the watch object. +Nodes are associated with a watch object by passing the +watch object as the value of a C<'watch'> option to a +Net::ZooKeeper method; methods which accept a C<'watch'> option +are C, C, and C. + +When the C method is invoked with a C<'timeout'> +option, it waits for no more than the number of milliseconds +specified by the C<'timeout'> option. +Otherwise, when the C method is invoked without a +C<'timeout'> option, it waits for no more than the timeout +period specified by the value of the watch object's C +attribute. + +The C method returns true if an event notification +was received, otherwise false. When C returns true, +the C and C attributes of the watch object +will be updated with the event's type and the current +connection state. + +When the parent Net::ZooKeeper handle object experiences a +connection error, the ZooKeeper client code will notify all +pending watches with an event of type C. +In this case, the C attribute will report the current +state of the connection to the ZooKeeper cluster. + +See also the C attribute, and the C method +and C attribute of the Net::ZooKeeper class. + +=back + +=head1 FUNCTIONS + +The following functions have global scope and affect all +Net::ZooKeeper handle objects. + +=over 4 + +=item set_log_level() + + Net::ZooKeeper::set_log_level($level); + +The C function may be called to +alter the number and type of messages written to the current log +file handle (if any). The default value is C +which disables all logging. + +See the L section for more details and C<:log_levels> +for a list of the available log levels. + +=item set_deterministic_conn_order() + + Net::ZooKeeper::set_deterministic_conn_order(1); + +The C function +may be called to indicate whether or not the list of ZooKeeper +servers passed to the C method should be randomly permuted. +If set to a true value, the list of servers will not be altered. +The default false value indicates the list of servers will +be randomly reordered prior to connection. + +See the L section for more details. + +=back + +=head1 EXPORTS + +Nothing is exported by default. Various tagsets exist which +group the tags available for export into different categories: + +=over 4 + +=item :errors + +ZooKeeper error codes. These may be compared to the values +returned by the C method. + +=item :node_flags + +The ZooKeeper node flags C and C, +which may be passed in the C<'flags'> option to the C +method. When more than node flag is required they +should be combined using the bitwise OR operator. + +=item :acl_perms + +The ZooKeeper ACL permission flags which may be used in +the value of the C attribute of an ACL entry hash. +When more than one ACL permission flag is required they +should be combined using the bitwise OR operator. + +The available ACL permission flags are C, +C, C, C, +and C. For convenience, C is +defined as the bitwise OR of all of these flags. + +=item :acls + +Common ZooKeeper ACLs which may be useful. C +specifies a node which is entirely open to all users with no +restrictions at all. C specifies +a node which is readable by all users; permissions for other actions +are not defined in this ACL. C specifies a node +for which all actions require the same authentication credentials as +held by the session which created the node; this implies that a +session should authenticate with an appropriate scheme before +creating a node with this ACL. + +=item :events + +The ZooKeeper event types which are returned in value of +the C attribute a Net::ZooKeeper::Watch object after +an event occurs on a watched node. + +=item :states + +The ZooKeeper connection states which are returned in value of +the C attribute of a Net::ZooKeeper::Watch object after +an event occurs on a watched node. + +=item :log_levels + +The ZooKeeper log levels which may be passed to the +C function. The available +log levels are, from least to most verbose, C +(the default), C, C, +C, and C. + +=item :all + +Everything from all of the above tagsets. + +=back + +=head1 SEE ALSO + +The Apache ZooKeeper project's home page at +L provides a wealth of detail +on how to develop applications using ZooKeeper. + +=head1 AUTHOR + +Chris Darroch, Echrisd@apache.orgE + +=head1 COPYRIGHT AND LICENSE + +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +=cut + diff --git a/src/contrib/zkperl/ZooKeeper.xs b/src/contrib/zkperl/ZooKeeper.xs new file mode 100644 index 00000000000..f65e076b2a3 --- /dev/null +++ b/src/contrib/zkperl/ZooKeeper.xs @@ -0,0 +1,2664 @@ +/* Net::ZooKeeper - Perl extension for Apache ZooKeeper + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define PERL_NO_GET_CONTEXT + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include /* pthread_mutex_lock(), etc. */ +#include /* memset(), etc. */ +#include /* CHAR_BIT */ +#include /* gettimeofday() */ + +#include + +#include "build/check_zk_version.h" + + +#define PACKAGE_NAME "Net::ZooKeeper" +#define PACKAGE_SIGNATURE 19631123 + +#define STAT_PACKAGE_NAME "Net::ZooKeeper::Stat" +#define STAT_PACKAGE_SIGNATURE 19960512 + +#define WATCH_PACKAGE_NAME "Net::ZooKeeper::Watch" +#define WATCH_PACKAGE_SIGNATURE 20050326 + +#define MAX_KEY_NAME_LEN 16 /* "children_version" */ + +#define NUM_ACL_ENTRY_KEYS 3 +#define NUM_KEYS 7 +#define NUM_STAT_KEYS 11 +#define NUM_WATCH_KEYS 3 + +#define DEFAULT_RECV_TIMEOUT_MSEC 10000 + +#define DEFAULT_DATA_BUF_LEN 1023 +#define DEFAULT_PATH_BUF_LEN 1023 +#define DEFAULT_WATCH_TIMEOUT 60000 + +#define ZOO_LOG_LEVEL_OFF 0 + +#ifndef strcaseEQ +#define strcaseEQ(a,b) (!strcasecmp((a),(b))) +#endif + + +typedef struct Stat zk_stat_t; + +typedef HV* Net__ZooKeeper__Stat; + +typedef struct zk_watch_t zk_watch_t; + +struct zk_watch_t { + pthread_mutex_t mutex; + pthread_cond_t cond; + int done; + int ret; + int event_type; + int event_state; + unsigned int timeout; + zk_watch_t *prev; + zk_watch_t *next; + int ref_count; +}; + +typedef HV* Net__ZooKeeper__Watch; + +typedef struct { + zhandle_t *handle; + zk_watch_t *first_watch; + int data_buf_len; + int path_buf_len; + unsigned int watch_timeout; + const char *hosts; + int hosts_len; + int last_ret; + int last_errno; +} zk_t; + +typedef HV* Net__ZooKeeper; + +typedef struct { + I32 signature; + union { + zk_t *zk; + zk_stat_t *stat; + zk_watch_t *watch; + } handle; +} zk_handle_t; + +typedef struct { + const char name[MAX_KEY_NAME_LEN + 1]; + U32 name_len; + size_t offset; + size_t size; + U32 hash; +} zk_key_t; + + +static zk_key_t zk_acl_entry_keys[NUM_ACL_ENTRY_KEYS] = { + {"perms", 0, 0, 0, 0}, + {"scheme", 0, 0, 0, 0}, + {"id", 0, 0, 0, 0} +}; + +static zk_key_t zk_keys[NUM_KEYS] = { + {"data_read_len", 0, 0, 0, 0}, + {"path_read_len", 0, 0, 0, 0}, + {"watch_timeout", 0, 0, 0, 0}, + {"hosts", 0, 0, 0, 0}, + {"session_timeout", 0, 0, 0, 0}, + {"session_id", 0, 0, 0, 0}, + {"pending_watches", 0, 0, 0, 0} +}; + +static zk_key_t zk_stat_keys[NUM_STAT_KEYS] = { + {"czxid", 0, offsetof(struct Stat, czxid), + sizeof(((struct Stat*) 0)->czxid), 0}, + {"mzxid", 0, offsetof(struct Stat, mzxid), + sizeof(((struct Stat*) 0)->mzxid), 0}, + {"ctime", 0, offsetof(struct Stat, ctime), + sizeof(((struct Stat*) 0)->ctime), 0}, + {"mtime", 0, offsetof(struct Stat, mtime), + sizeof(((struct Stat*) 0)->mtime), 0}, + {"version", 0, offsetof(struct Stat, version), + sizeof(((struct Stat*) 0)->version), 0}, + {"children_version", 0, offsetof(struct Stat, cversion), + sizeof(((struct Stat*) 0)->cversion), 0}, + {"acl_version", 0, offsetof(struct Stat, aversion), + sizeof(((struct Stat*) 0)->aversion), 0}, + {"ephemeral_owner", 0, offsetof(struct Stat, ephemeralOwner), + sizeof(((struct Stat*) 0)->ephemeralOwner), 0}, + {"data_len", 0, offsetof(struct Stat, dataLength), + sizeof(((struct Stat*) 0)->dataLength), 0}, + {"num_children", 0, offsetof(struct Stat, numChildren), + sizeof(((struct Stat*) 0)->numChildren), 0}, + {"children_zxid", 0, offsetof(struct Stat, pzxid), + sizeof(((struct Stat*) 0)->pzxid), 0} +}; + +static zk_key_t zk_watch_keys[NUM_WATCH_KEYS] = { + {"timeout", 0, 0, 0, 0}, + {"event", 0, 0, 0, 0}, + {"state", 0, 0, 0, 0} +}; + + +static void _zk_watcher(zhandle_t *handle, int type, int state, + const char *path, void *context) +{ + zk_watch_t *watch_ctx = context; + + pthread_mutex_lock(&watch_ctx->mutex); + + watch_ctx->event_type = type; + watch_ctx->event_state = state; + + watch_ctx->done = 1; + + pthread_cond_signal(&watch_ctx->cond); + pthread_mutex_unlock(&watch_ctx->mutex); + + return; +} + +static void _zk_auth_completion(int ret, const void *data) +{ + zk_watch_t *watch_ctx = (zk_watch_t*) data; + + pthread_mutex_lock(&watch_ctx->mutex); + + watch_ctx->ret = ret; + + watch_ctx->done = 1; + + pthread_cond_signal(&watch_ctx->cond); + pthread_mutex_unlock(&watch_ctx->mutex); + + return; +} + +static zk_watch_t *_zk_create_watch(pTHX) +{ + zk_watch_t *watch; + + Newxz(watch, 1, zk_watch_t); + + if (pthread_mutex_init(&watch->mutex, NULL)) { + int save_errno = errno; + + Safefree(watch); + + errno = save_errno; + return NULL; + } + + if (pthread_cond_init(&watch->cond, NULL)) { + int save_errno = errno; + + pthread_mutex_destroy(&watch->mutex); + Safefree(watch); + + errno = save_errno; + return NULL; + } + + return watch; +} + +static void _zk_destroy_watch(pTHX_ zk_watch_t *watch) +{ + pthread_cond_destroy(&watch->cond); + pthread_mutex_destroy(&watch->mutex); + + Safefree(watch); + + return; +} + +static zk_watch_t *_zk_acquire_watch(pTHX) +{ + zk_watch_t *watch = _zk_create_watch(aTHX); + + if (watch) { + watch->ref_count = 1; + } + + return watch; +} + +static void _zk_release_watch(pTHX_ zk_watch_t *watch, int list) +{ + if (list) { + if (watch->prev) { + watch->prev->next = watch->next; + } + if (watch->next) { + watch->next->prev = watch->prev; + } + watch->prev = NULL; + watch->next = NULL; + } + + if (--watch->ref_count == 0) { + _zk_destroy_watch(aTHX_ watch); + } + + return; +} + +static unsigned int _zk_release_watches(pTHX_ zk_watch_t *first_watch, + int final) +{ + zk_watch_t *watch = first_watch->next; + unsigned int pending_watches = 0; + + while (watch) { + zk_watch_t *next_watch = watch->next; + int done = final; + + if (!final) { + pthread_mutex_lock(&watch->mutex); + done = watch->done; + pthread_mutex_unlock(&watch->mutex); + } + + if (done) { + _zk_release_watch(aTHX_ watch, 1); + } + else { + ++pending_watches; + } + + watch = next_watch; + } + + return pending_watches; +} + +static void _zk_replace_watch(pTHX_ zk_handle_t *handle, + zk_watch_t *first_watch, + zk_watch_t *old_watch, zk_watch_t *new_watch) +{ + zk_watch_t *next_watch; + + new_watch->timeout = old_watch->timeout; + + _zk_release_watch(aTHX_ old_watch, 0); + + /* cleanup any completed watches not tied to a handle */ + _zk_release_watches(aTHX_ first_watch, 0); + + next_watch = first_watch->next; + + new_watch->prev = first_watch; + new_watch->next = next_watch; + + if (next_watch) { + next_watch->prev = new_watch; + } + + first_watch->next = new_watch; + + ++new_watch->ref_count; + + handle->handle.watch = new_watch; + + return; +} + +static void _zk_free_acl(pTHX_ struct ACL_vector *acl) +{ + if (acl->data) { + Safefree(acl->data); + } + + return; +} + +static const char *_zk_fill_acl(pTHX_ AV *acl_arr, struct ACL_vector *acl) +{ + I32 num_acl_entries = av_len(acl_arr) + 1; + int i; + + Zero(acl, 1, struct ACL_vector); + + if (num_acl_entries <= 0) { + return NULL; + } + else if (num_acl_entries > PERL_INT_MAX) { + num_acl_entries = PERL_INT_MAX; + } + + Newx(acl->data, num_acl_entries, struct ACL); + + for (i = 0; i < num_acl_entries; ++i) { + SV **acl_entry_ptr; + HV *acl_entry_hash; + zk_key_t *key; + SV **val_ptr; + struct ACL acl_entry; + + acl_entry_ptr = av_fetch(acl_arr, i, 0); + + if (!acl_entry_ptr) { + continue; + } + + if (!SvROK(*acl_entry_ptr) || + SvTYPE(SvRV(*acl_entry_ptr)) != SVt_PVHV) { + _zk_free_acl(aTHX_ acl); + + return "invalid ACL entry hash reference"; + } + + acl_entry_hash = (HV*) SvRV(*acl_entry_ptr); + + key = &zk_acl_entry_keys[0]; + val_ptr = hv_fetch(acl_entry_hash, key->name, key->name_len, 0); + + if (!val_ptr) { + _zk_free_acl(aTHX_ acl); + + return "no ACL entry perms element"; + } + + acl_entry.perms = SvIV(*val_ptr); + + if (!acl_entry.perms || (acl_entry.perms & ~ZOO_PERM_ALL)) { + _zk_free_acl(aTHX_ acl); + + return "invalid ACL entry perms"; + } + + key = &zk_acl_entry_keys[1]; + val_ptr = hv_fetch(acl_entry_hash, key->name, key->name_len, 0); + + if (!val_ptr) { + _zk_free_acl(aTHX_ acl); + + return "no ACL entry scheme element"; + } + + acl_entry.id.scheme = SvPV_nolen(*val_ptr); + + key = &zk_acl_entry_keys[2]; + val_ptr = hv_fetch(acl_entry_hash, key->name, key->name_len, 0); + + if (!val_ptr) { + _zk_free_acl(aTHX_ acl); + + return "no ACL entry id element"; + } + + acl_entry.id.id = SvPV_nolen(*val_ptr); + + ++acl->count; + acl->data[i] = acl_entry; + } + + return NULL; +} + +static void _zk_fill_acl_entry_hash(pTHX_ struct ACL *acl_entry, + HV *acl_entry_hash) +{ + zk_key_t *key; + SV *val; + + key = &zk_acl_entry_keys[0]; + val = newSViv(acl_entry->perms); + + if (!hv_store(acl_entry_hash, key->name, key->name_len, val, key->hash)) { + SvREFCNT_dec(val); + } + + key = &zk_acl_entry_keys[1]; + val = newSVpv(acl_entry->id.scheme, 0); + + if (!hv_store(acl_entry_hash, key->name, key->name_len, val, key->hash)) { + SvREFCNT_dec(val); + } + + key = &zk_acl_entry_keys[2]; + val = newSVpv(acl_entry->id.id, 0); + + if (!hv_store(acl_entry_hash, key->name, key->name_len, val, key->hash)) { + SvREFCNT_dec(val); + } + + return; +} + +static zk_handle_t *_zk_check_handle_inner(pTHX_ HV *attr_hash, + I32 package_signature) +{ + zk_handle_t *handle = NULL; + + if (SvRMAGICAL(attr_hash)) { + MAGIC *magic = mg_find((SV*) attr_hash, PERL_MAGIC_ext); + + if (magic) { + handle = (zk_handle_t*) magic->mg_ptr; + + if (handle->signature != package_signature) { + handle = NULL; + } + } + } + + return handle; +} + +static zk_handle_t *_zk_check_handle_outer(pTHX_ HV *hash, HV **attr_hash_ptr, + const char *package_name, + I32 package_signature) +{ + zk_handle_t *handle = NULL; + + if (attr_hash_ptr) { + *attr_hash_ptr = NULL; + } + + if (SvRMAGICAL((SV*) hash)) { + MAGIC *magic = mg_find((SV*) hash, PERL_MAGIC_tied); + + if (magic) { + SV *attr = magic->mg_obj; + + if (SvROK(attr) && SvTYPE(SvRV(attr)) == SVt_PVHV && + sv_derived_from(attr, package_name)) { + HV *attr_hash = (HV*) SvRV(attr); + + handle = _zk_check_handle_inner(aTHX_ attr_hash, + package_signature); + + if (handle && attr_hash_ptr) { + *attr_hash_ptr = attr_hash; + } + } + } + } + + return handle; +} + +static zk_t *_zk_get_handle_inner(pTHX_ Net__ZooKeeper attr_hash) +{ + zk_handle_t *handle; + + handle = _zk_check_handle_inner(aTHX_ attr_hash, PACKAGE_SIGNATURE); + + return handle ? handle->handle.zk : NULL; +} + +static zk_t *_zk_get_handle_outer(pTHX_ Net__ZooKeeper zkh) +{ + zk_handle_t *handle; + + handle = _zk_check_handle_outer(aTHX_ zkh, NULL, PACKAGE_NAME, + PACKAGE_SIGNATURE); + + return handle ? handle->handle.zk : NULL; +} + +static zk_stat_t *_zks_get_handle_inner(pTHX_ Net__ZooKeeper__Stat attr_hash) +{ + zk_handle_t *handle; + + handle = _zk_check_handle_inner(aTHX_ attr_hash, STAT_PACKAGE_SIGNATURE); + + return handle ? handle->handle.stat : NULL; +} + +static zk_stat_t *_zks_get_handle_outer(pTHX_ Net__ZooKeeper__Stat zksh) +{ + zk_handle_t *handle; + + handle = _zk_check_handle_outer(aTHX_ zksh, NULL, STAT_PACKAGE_NAME, + STAT_PACKAGE_SIGNATURE); + + return handle ? handle->handle.stat : NULL; +} + +static zk_watch_t *_zkw_get_handle_inner(pTHX_ Net__ZooKeeper__Watch attr_hash) +{ + zk_handle_t *handle; + + handle = _zk_check_handle_inner(aTHX_ attr_hash, WATCH_PACKAGE_SIGNATURE); + + return handle ? handle->handle.watch : NULL; +} + +static zk_watch_t *_zkw_get_handle_outer(pTHX_ Net__ZooKeeper__Watch zkwh, + zk_handle_t **handle_ptr) +{ + zk_handle_t *handle; + + handle = _zk_check_handle_outer(aTHX_ zkwh, NULL, WATCH_PACKAGE_NAME, + WATCH_PACKAGE_SIGNATURE); + + if (handle_ptr) { + *handle_ptr = handle; + } + + return handle ? handle->handle.watch : NULL; +} + + +MODULE = Net::ZooKeeper PACKAGE = Net::ZooKeeper PREFIX = zk_ + +REQUIRE: 1.9508 + +PROTOTYPES: ENABLE + +BOOT: +{ + int i; + + for (i = 0; i < NUM_ACL_ENTRY_KEYS; ++i) { + zk_key_t *key = &zk_acl_entry_keys[i]; + + key->name_len = strlen(key->name); + PERL_HASH(key->hash, key->name, key->name_len); + } + + for (i = 0; i < NUM_KEYS; ++i) { + zk_keys[i].name_len = strlen(zk_keys[i].name); + } + + for (i = 0; i < NUM_STAT_KEYS; ++i) { + zk_stat_keys[i].name_len = strlen(zk_stat_keys[i].name); + } + + for (i = 0; i < NUM_WATCH_KEYS; ++i) { + zk_watch_keys[i].name_len = strlen(zk_watch_keys[i].name); + } + + zoo_set_log_stream(NULL); + zoo_set_debug_level(0); +} + + +I32 +zk_constant(alias=Nullch) + char *alias + ALIAS: + ZOK = ZOK + ZSYSTEMERROR = ZSYSTEMERROR + ZRUNTIMEINCONSISTENCY = ZRUNTIMEINCONSISTENCY + ZDATAINCONSISTENCY = ZDATAINCONSISTENCY + ZCONNECTIONLOSS = ZCONNECTIONLOSS + ZMARSHALLINGERROR = ZMARSHALLINGERROR + ZUNIMPLEMENTED = ZUNIMPLEMENTED + ZOPERATIONTIMEOUT = ZOPERATIONTIMEOUT + ZBADARGUMENTS = ZBADARGUMENTS + ZINVALIDSTATE = ZINVALIDSTATE + ZAPIERROR = ZAPIERROR + ZNONODE = ZNONODE + ZNOAUTH = ZNOAUTH + ZBADVERSION = ZBADVERSION + ZNOCHILDRENFOREPHEMERALS = ZNOCHILDRENFOREPHEMERALS + ZNODEEXISTS = ZNODEEXISTS + ZNOTEMPTY = ZNOTEMPTY + ZSESSIONEXPIRED = ZSESSIONEXPIRED + ZINVALIDCALLBACK = ZINVALIDCALLBACK + ZINVALIDACL = ZINVALIDACL + ZAUTHFAILED = ZAUTHFAILED + ZCLOSING = ZCLOSING + ZNOTHING = ZNOTHING + + ZOO_EPHEMERAL = ZOO_EPHEMERAL + ZOO_SEQUENCE = ZOO_SEQUENCE + + ZOO_PERM_READ = ZOO_PERM_READ + ZOO_PERM_WRITE = ZOO_PERM_WRITE + ZOO_PERM_CREATE = ZOO_PERM_CREATE + ZOO_PERM_DELETE = ZOO_PERM_DELETE + ZOO_PERM_ADMIN = ZOO_PERM_ADMIN + ZOO_PERM_ALL = ZOO_PERM_ALL + + ZOO_CREATED_EVENT = ZOO_CREATED_EVENT + ZOO_DELETED_EVENT = ZOO_DELETED_EVENT + ZOO_CHANGED_EVENT = ZOO_CHANGED_EVENT + ZOO_CHILD_EVENT = ZOO_CHILD_EVENT + ZOO_SESSION_EVENT = ZOO_SESSION_EVENT + ZOO_NOTWATCHING_EVENT = ZOO_NOTWATCHING_EVENT + + ZOO_EXPIRED_SESSION_STATE = ZOO_EXPIRED_SESSION_STATE + ZOO_AUTH_FAILED_STATE = ZOO_AUTH_FAILED_STATE + ZOO_CONNECTING_STATE = ZOO_CONNECTING_STATE + ZOO_ASSOCIATING_STATE = ZOO_ASSOCIATING_STATE + ZOO_CONNECTED_STATE = ZOO_CONNECTED_STATE + + ZOO_LOG_LEVEL_OFF = ZOO_LOG_LEVEL_OFF + ZOO_LOG_LEVEL_ERROR = ZOO_LOG_LEVEL_ERROR + ZOO_LOG_LEVEL_WARN = ZOO_LOG_LEVEL_WARN + ZOO_LOG_LEVEL_INFO = ZOO_LOG_LEVEL_INFO + ZOO_LOG_LEVEL_DEBUG = ZOO_LOG_LEVEL_DEBUG + CODE: + if (!ix) { + if (!alias) { + alias = GvNAME(CvGV(cv)); + } + + if (strEQ(alias, "ZOK")) { + RETVAL = ZOK; + } + else if (strEQ(alias, "ZOO_LOG_LEVEL_OFF")) { + RETVAL = ZOO_LOG_LEVEL_OFF; + } + else { + Perl_croak(aTHX_ "unknown " PACKAGE_NAME " constant: %s", + alias); + } + } + else { + RETVAL = ix; + } + OUTPUT: + RETVAL + + +AV * +zk_acl_constant(alias=Nullch) + char *alias + ALIAS: + ZOO_OPEN_ACL_UNSAFE = 1 + ZOO_READ_ACL_UNSAFE = 2 + ZOO_CREATOR_ALL_ACL = 3 + PREINIT: + struct ACL_vector acl; + AV *acl_arr; + int i; + PPCODE: + if (!ix && !alias) { + alias = GvNAME(CvGV(cv)); + } + + if (ix == 1 || (alias != NULL && strEQ(alias, "ZOO_OPEN_ACL_UNSAFE"))) { + acl = ZOO_OPEN_ACL_UNSAFE; + } + else if (ix == 2 || (alias != NULL && strEQ(alias, "ZOO_READ_ACL_UNSAFE"))) { + acl = ZOO_READ_ACL_UNSAFE; + } + else if (ix == 3 || (alias != NULL && strEQ(alias, "ZOO_CREATOR_ALL_ACL"))) { + acl = ZOO_CREATOR_ALL_ACL; + } + else { + Perl_croak(aTHX_ "unknown " PACKAGE_NAME " constant: %s", alias); + } + + acl_arr = newAV(); + + av_extend(acl_arr, acl.count); + + for (i = 0; i < acl.count; ++i) { + HV *acl_entry_hash = newHV(); + SV *val; + + _zk_fill_acl_entry_hash(aTHX_ &acl.data[i], acl_entry_hash); + + val = newRV_noinc((SV*) acl_entry_hash); + + if (!av_store(acl_arr, i, val)) { + SvREFCNT_dec(val); + } + } + + ST(0) = sv_2mortal(newRV_noinc((SV*) acl_arr)); + + XSRETURN(1); + + +void +zk_set_log_level(level) + int level + PPCODE: + if (level < ZOO_LOG_LEVEL_OFF || level > ZOO_LOG_LEVEL_DEBUG) { + Perl_croak(aTHX_ "invalid log level: %d", level); + } + + zoo_set_debug_level(level); + + XSRETURN_EMPTY; + + +void +zk_set_deterministic_conn_order(flag) + bool flag + PPCODE: + zoo_deterministic_conn_order(!!flag); + + XSRETURN_EMPTY; + + +void +zk_new(package, hosts, ...) + char *package + char *hosts + PREINIT: + int recv_timeout = DEFAULT_RECV_TIMEOUT_MSEC; + const clientid_t *client_id = NULL; + zk_t *zk; + zk_handle_t *handle; + HV *stash, *zk_hash, *attr_hash; + SV *attr; + int i; + PPCODE: + if (items > 2 && items % 2) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + for (i = 2; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "session_timeout")) { + recv_timeout = SvIV(ST(i + 1)); + + /* NOTE: would be nice if requirement in zookeeper_interest() + * that recv_timeout*2 be non-negative was documented + */ + if (recv_timeout < 0 || recv_timeout > (PERL_INT_MAX >> 1)) { + Perl_croak(aTHX_ "invalid session timeout: %d", + recv_timeout); + } + } + else if (strcaseEQ(key, "session_id")) { + STRLEN client_id_len; + + client_id = (const clientid_t*) SvPV(ST(i + 1), client_id_len); + + if (client_id_len != sizeof(clientid_t)) { + Perl_croak(aTHX_ "invalid session ID"); + } + } + } + + Newxz(zk, 1, zk_t); + + zk->handle = zookeeper_init(hosts, NULL, recv_timeout, + client_id, NULL, 0); + + if (!zk->handle) { + Safefree(zk); + + XSRETURN_UNDEF; + } + + Newxz(zk->first_watch, 1, zk_watch_t); + + zk->data_buf_len = DEFAULT_DATA_BUF_LEN; + zk->path_buf_len = DEFAULT_PATH_BUF_LEN; + zk->watch_timeout = DEFAULT_WATCH_TIMEOUT; + + zk->hosts_len = strlen(hosts); + zk->hosts = savepvn(hosts, zk->hosts_len); + + Newx(handle, 1, zk_handle_t); + + handle->signature = PACKAGE_SIGNATURE; + handle->handle.zk = zk; + + /* We use several tricks from DBI here. The attr_hash is our + * empty inner hash; we attach extra magic to it in the form of + * our zk_handle_t structure. Then we tie attr_hash to zk_hash, + * our outer hash. This is what is passed around (by reference) by + * callers. + * + * Most methods use _zk_get_handle_outer() which finds our inner + * handle, then returns the zk_t structure from its extra magic + * pointer. + * + * However, the tied hash methods, FETCH(), STORE(), and so forth, + * receive an already-dereferenced inner handle hash. This is + * because we bless both inner and outer handles into this class, + * so when a caller's code references a hash element in our + * outer handle, Perl detects its tied magic, looks up the + * tied object (our inner handle) and invokes the tied hash methods + * in its class on it. Since we blessed it into the same class + * as the outer handle, these methods simply reside in our package. + */ + + stash = gv_stashpv(package, GV_ADDWARN); + + attr_hash = newHV(); + + sv_magic((SV*) attr_hash, Nullsv, PERL_MAGIC_ext, + (const char*) handle, 0); + + attr = sv_bless(newRV_noinc((SV*) attr_hash), stash); + + zk_hash = newHV(); + + sv_magic((SV*) zk_hash, attr, PERL_MAGIC_tied, Nullch, 0); + SvREFCNT_dec(attr); + + ST(0) = sv_bless(sv_2mortal(newRV_noinc((SV*) zk_hash)), stash); + + XSRETURN(1); + + +void +zk_DESTROY(zkh) + Net::ZooKeeper zkh + PREINIT: + zk_handle_t *handle; + HV *attr_hash; + int ret = ZBADARGUMENTS; + PPCODE: + handle = _zk_check_handle_outer(aTHX_ zkh, &attr_hash, + PACKAGE_NAME, PACKAGE_SIGNATURE); + + if (!handle) { + handle = _zk_check_handle_inner(aTHX_ zkh, PACKAGE_SIGNATURE); + + if (handle) { + attr_hash = zkh; + zkh = NULL; + } + } + + if (handle) { + zk_t *zk = handle->handle.zk; + + ret = zookeeper_close(zk->handle); + + /* detach all now-inactive watches still tied to handles */ + _zk_release_watches(aTHX_ zk->first_watch, 1); + + Safefree(zk->first_watch); + Safefree(zk->hosts); + Safefree(zk); + Safefree(handle); + + sv_unmagic((SV*) attr_hash, PERL_MAGIC_ext); + } + + if (zkh && attr_hash) { + sv_unmagic((SV*) zkh, PERL_MAGIC_tied); + } + + if (GIMME_V == G_VOID) { + XSRETURN_EMPTY; + } + else if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zk_CLONE(package) + char *package + PPCODE: + XSRETURN_EMPTY; + + +void +zk_CLONE_SKIP(package) + char *package + PPCODE: + XSRETURN_YES; + + +void +zk_TIEHASH(package, ...) + char *package + PPCODE: + Perl_croak(aTHX_ "tying hashes of class " + PACKAGE_NAME " not supported"); + + +void +zk_UNTIE(attr_hash, ref_count) + Net::ZooKeeper attr_hash + IV ref_count + PPCODE: + Perl_croak(aTHX_ "untying hashes of class " + PACKAGE_NAME " not supported"); + + +void +zk_FIRSTKEY(attr_hash) + Net::ZooKeeper attr_hash + PREINIT: + zk_t *zk; + PPCODE: + zk = _zk_get_handle_inner(aTHX_ attr_hash); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + ST(0) = sv_2mortal(newSVpvn(zk_keys[0].name, zk_keys[0].name_len)); + + XSRETURN(1); + + +void +zk_NEXTKEY(attr_hash, attr_key) + Net::ZooKeeper attr_hash + SV *attr_key + PREINIT: + zk_t *zk; + char *key; + int i; + PPCODE: + zk = _zk_get_handle_inner(aTHX_ attr_hash); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_KEYS; ++i) { + if (strcaseEQ(key, zk_keys[i].name)) { + ++i; + + break; + } + } + + if (i < NUM_KEYS) { + ST(0) = sv_2mortal(newSVpvn(zk_keys[i].name, zk_keys[i].name_len)); + + XSRETURN(1); + } + else { + XSRETURN_EMPTY; + } + + +void +zk_SCALAR(attr_hash) + Net::ZooKeeper attr_hash + PPCODE: + XSRETURN_YES; + + +void +zk_FETCH(attr_hash, attr_key) + Net::ZooKeeper attr_hash + SV *attr_key + PREINIT: + zk_t *zk; + char *key; + SV *val = NULL; + PPCODE: + zk = _zk_get_handle_inner(aTHX_ attr_hash); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + if (strcaseEQ(key, "data_read_len")) { + val = newSViv(zk->data_buf_len); + } + else if (strcaseEQ(key, "path_read_len")) { + val = newSViv(zk->path_buf_len); + } + else if (strcaseEQ(key, "watch_timeout")) { + val = newSVuv(zk->watch_timeout); + } + else if (strcaseEQ(key, "hosts")) { + val = newSVpvn(zk->hosts, zk->hosts_len); + } + else if (strcaseEQ(key, "session_timeout")) { + val = newSViv(zoo_recv_timeout(zk->handle)); + } + else if (strcaseEQ(key, "session_id")) { + const clientid_t *client_id; + clientid_t null_client_id; + + client_id = zoo_client_id(zk->handle); + + memset(&null_client_id, 0, sizeof(clientid_t)); + + if (!memcmp(client_id, &null_client_id, sizeof(clientid_t))) { + val = newSVpv("", 0); + } + else { + val = newSVpvn((const char*) client_id, sizeof(clientid_t)); + } + } + else if (strcaseEQ(key, "pending_watches")) { + /* cleanup any completed watches not tied to a handle */ + val = newSVuv(_zk_release_watches(aTHX_ zk->first_watch, 0)); + } + + if (val) { + ST(0) = sv_2mortal(val); + + XSRETURN(1); + } + + Perl_warn(aTHX_ "invalid element: %s", key); + + XSRETURN_UNDEF; + + +void +zk_STORE(attr_hash, attr_key, attr_val) + Net::ZooKeeper attr_hash + SV *attr_key + SV *attr_val + PREINIT: + zk_t *zk; + char *key; + PPCODE: + zk = _zk_get_handle_inner(aTHX_ attr_hash); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + if (strcaseEQ(key, "data_read_len")) { + int val = SvIV(attr_val); + + if (val < 0) { + Perl_croak(aTHX_ "invalid data read length: %d", val); + } + + zk->data_buf_len = val; + } + else if (strcaseEQ(key, "path_read_len")) { + int val = SvIV(attr_val); + + if (val < 0) { + Perl_croak(aTHX_ "invalid path read length: %d", val); + } + + zk->path_buf_len = val; + } + else if (strcaseEQ(key, "watch_timeout")) { + zk->watch_timeout = SvUV(attr_val); + } + else { + int i; + + for (i = 0; i < NUM_KEYS; ++i) { + if (strcaseEQ(key, zk_keys[i].name)) { + Perl_warn(aTHX_ "read-only element: %s", key); + + XSRETURN_EMPTY; + } + } + + Perl_warn(aTHX_ "invalid element: %s", key); + } + + XSRETURN_EMPTY; + + +void +zk_EXISTS(attr_hash, attr_key) + Net::ZooKeeper attr_hash + SV *attr_key + PREINIT: + zk_t *zk; + char *key; + int i; + PPCODE: + zk = _zk_get_handle_inner(aTHX_ attr_hash); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_KEYS; ++i) { + if (strcaseEQ(key, zk_keys[i].name)) { + XSRETURN_YES; + } + } + + XSRETURN_NO; + + +void +zk_DELETE(attr_hash, attr_key) + Net::ZooKeeper attr_hash + SV *attr_key + PPCODE: + Perl_warn(aTHX_ "deleting elements from hashes of class " + PACKAGE_NAME " not supported"); + + XSRETURN_EMPTY; + + +void +zk_CLEAR(attr_hash) + Net::ZooKeeper attr_hash + PPCODE: + Perl_warn(aTHX_ "clearing hashes of class " + PACKAGE_NAME " not supported"); + + XSRETURN_EMPTY; + + +SV * +zk_get_error(zkh) + Net::ZooKeeper zkh + PREINIT: + zk_t *zk; + CODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + RETVAL = newSViv(zk->last_ret); + errno = zk->last_errno; + OUTPUT: + RETVAL + + +void +zk_add_auth(zkh, scheme, cert) + Net::ZooKeeper zkh + char *scheme + char *cert; cert = (char *) SvPV($arg, cert_len); + PREINIT: + zk_t *zk; + STRLEN cert_len; + zk_watch_t *watch; + int ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (cert_len > PERL_INT_MAX) { + Perl_croak(aTHX_ "invalid certificate length: %u", cert_len); + } + + watch = _zk_create_watch(aTHX); + + if (!watch) { + /* errno will be set */ + zk->last_ret = ZSYSTEMERROR; + zk->last_errno = errno; + + XSRETURN_NO; + } + + errno = 0; + ret = zoo_add_auth(zk->handle, scheme, cert, cert_len, + _zk_auth_completion, watch); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (ret == ZOK) { + pthread_mutex_lock(&watch->mutex); + + while (!watch->done) { + pthread_cond_wait(&watch->cond, &watch->mutex); + } + + pthread_mutex_unlock(&watch->mutex); + + if (watch->done) { + ret = watch->ret; + } + else { + ret = ZINVALIDSTATE; + } + + /* errno may be set while we waited */ + zk->last_ret = ret; + zk->last_errno = errno; + } + + _zk_destroy_watch(aTHX_ watch); + + if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zk_create(zkh, path, buf, ...) + Net::ZooKeeper zkh + char *path + char *buf; buf = (char *) SvPV($arg, buf_len); + PREINIT: + zk_t *zk; + STRLEN buf_len; + int flags = 0; + char *path_buf; + int path_buf_len; + AV *acl_arr = NULL; + struct ACL_vector acl; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 3 && !(items % 2)) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + if (buf_len > PERL_INT_MAX) { + Perl_croak(aTHX_ "invalid data length: %u", buf_len); + } + + path_buf_len = zk->path_buf_len; + + for (i = 3; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "path_read_len")) { + path_buf_len = SvIV(ST(i + 1)); + + if (path_buf_len < 2) { + Perl_croak(aTHX_ "invalid path read length: %d", + path_buf_len); + } + } + else if (strcaseEQ(key, "flags")) { + flags = SvIV(ST(i + 1)); + + if (flags & ~(ZOO_SEQUENCE | ZOO_EPHEMERAL)) { + Perl_croak(aTHX_ "invalid create flags: %d", flags); + } + } + else if (strcaseEQ(key, "acl")) { + const char *err; + + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVAV) { + Perl_croak(aTHX_ "invalid ACL array reference"); + } + + acl_arr = (AV*) SvRV(ST(i + 1)); + + err = _zk_fill_acl(aTHX_ acl_arr, &acl); + + if (err) { + Perl_croak(aTHX_ err); + } + } + } + + /* NOTE: would be nice to be able to rely on null-terminated string */ + ++path_buf_len; + Newxz(path_buf, path_buf_len, char); + + errno = 0; + ret = zoo_create(zk->handle, path, buf, buf_len, + (acl_arr ? &acl : NULL), flags, + path_buf, path_buf_len); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (acl_arr) { + _zk_free_acl(aTHX_ &acl); + } + + if (ret == ZOK) { + ST(0) = sv_newmortal(); +#ifdef SV_HAS_TRAILING_NUL + sv_usepvn_flags(ST(0), path_buf, strlen(path_buf), + SV_HAS_TRAILING_NUL); +#else + sv_usepvn(ST(0), path_buf, strlen(path_buf)); +#endif + SvCUR_set(ST(0), strlen(path_buf)); + + XSRETURN(1); + } + + Safefree(path_buf); + + XSRETURN_UNDEF; + + +void +zk_delete(zkh, path, ...) + Net::ZooKeeper zkh + char *path + PREINIT: + zk_t *zk; + int version = -1; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 2 && items % 2) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + for (i = 2; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "version")) { + version = SvIV(ST(i + 1)); + + if (version < 0) { + Perl_croak(aTHX_ "invalid version requirement: %d", + version); + } + } + } + + errno = 0; + ret = zoo_delete(zk->handle, path, version); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zk_exists(zkh, path, ...) + Net::ZooKeeper zkh + char *path + PREINIT: + zk_t *zk; + zk_stat_t *stat = NULL; + zk_watch_t *old_watch = NULL; + zk_handle_t *watch_handle = NULL; + watcher_fn watcher = NULL; + zk_watch_t *new_watch = NULL; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 2 && items % 2) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + for (i = 2; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "stat")) { + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV || + !sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) { + Perl_croak(aTHX_ "stat is not a hash reference of " + "type " STAT_PACKAGE_NAME); + } + + stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1))); + + if (!stat) { + Perl_croak(aTHX_ "invalid stat handle"); + } + } + else if (strcaseEQ(key, "watch")) { + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV || + !sv_derived_from(ST(i + 1), WATCH_PACKAGE_NAME)) { + Perl_croak(aTHX_ "watch is not a hash reference of " + "type " WATCH_PACKAGE_NAME); + } + + old_watch = _zkw_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)), + &watch_handle); + + if (!old_watch) { + Perl_croak(aTHX_ "invalid watch handle"); + } + } + } + + if (watch_handle) { + new_watch = _zk_acquire_watch(aTHX); + + if (!new_watch) { + /* errno will be set */ + zk->last_ret = ZSYSTEMERROR; + zk->last_errno = errno; + + XSRETURN_NO; + } + + watcher = _zk_watcher; + } + + errno = 0; + ret = zoo_wexists(zk->handle, path, watcher, new_watch, stat); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (watch_handle) { + _zk_replace_watch(aTHX_ watch_handle, zk->first_watch, + old_watch, new_watch); + } + + if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zk_get_children(zkh, path, ...) + Net::ZooKeeper zkh + char *path + PREINIT: + zk_t *zk; + zk_watch_t *old_watch = NULL; + zk_handle_t *watch_handle = NULL; + watcher_fn watcher = NULL; + zk_watch_t *new_watch = NULL; + struct String_vector strings; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 2 && items % 2) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + for (i = 2; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "watch")) { + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV || + !sv_derived_from(ST(i + 1), WATCH_PACKAGE_NAME)) { + Perl_croak(aTHX_ "watch is not a hash reference of " + "type " WATCH_PACKAGE_NAME); + } + + old_watch = _zkw_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)), + &watch_handle); + + if (!old_watch) { + Perl_croak(aTHX_ "invalid watch handle"); + } + } + } + + if (watch_handle) { + new_watch = _zk_acquire_watch(aTHX); + + if (!new_watch) { + /* errno will be set */ + zk->last_ret = ZSYSTEMERROR; + zk->last_errno = errno; + + if (GIMME_V == G_ARRAY) { + XSRETURN_EMPTY; + } + else { + XSRETURN_UNDEF; + } + } + + watcher = _zk_watcher; + } + + Zero(&strings, 1, struct String_vector); + + errno = 0; + ret = zoo_wget_children(zk->handle, path, watcher, new_watch, + &strings); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (watch_handle) { + _zk_replace_watch(aTHX_ watch_handle, zk->first_watch, + old_watch, new_watch); + } + + if (ret == ZOK) { + int num_children; + + num_children = + (strings.count > PERL_INT_MAX) ? PERL_INT_MAX : strings.count; + + if (GIMME_V == G_ARRAY && num_children > 0) { + EXTEND(SP, num_children); + + for (i = 0; i < num_children; ++i) { + ST(i) = sv_2mortal(newSVpv(strings.data[i], 0)); + } + } + + /* NOTE: would be nice if this were documented as required */ + deallocate_String_vector(&strings); + + if (GIMME_V == G_ARRAY) { + if (num_children == 0) { + XSRETURN_EMPTY; + } + + XSRETURN(num_children); + } + else { + ST(0) = sv_2mortal(newSViv(num_children)); + + XSRETURN(1); + } + } + else { + if (GIMME_V == G_ARRAY) { + XSRETURN_EMPTY; + } + else { + XSRETURN_UNDEF; + } + } + + +void +zk_get(zkh, path, ...) + Net::ZooKeeper zkh + char *path + PREINIT: + zk_t *zk; + int buf_len; + zk_stat_t *stat = NULL; + zk_watch_t *old_watch = NULL; + zk_handle_t *watch_handle = NULL; + char *buf; + watcher_fn watcher = NULL; + zk_watch_t *new_watch = NULL; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 2 && items % 2) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + buf_len = zk->data_buf_len; + + for (i = 2; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "data_read_len")) { + buf_len = SvIV(ST(i + 1)); + + if (buf_len < 0) { + Perl_croak(aTHX_ "invalid data read length: %d", + buf_len); + } + } + else if (strcaseEQ(key, "stat")) { + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV || + !sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) { + Perl_croak(aTHX_ "stat is not a hash reference of " + "type " STAT_PACKAGE_NAME); + } + + stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1))); + + if (!stat) { + Perl_croak(aTHX_ "invalid stat handle"); + } + } + else if (strcaseEQ(key, "watch")) { + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV || + !sv_derived_from(ST(i + 1), WATCH_PACKAGE_NAME)) { + Perl_croak(aTHX_ "watch is not a hash reference of " + "type " WATCH_PACKAGE_NAME); + } + + old_watch = _zkw_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)), + &watch_handle); + + if (!old_watch) { + Perl_croak(aTHX_ "invalid watch handle"); + } + } + } + + if (watch_handle) { + new_watch = _zk_acquire_watch(aTHX); + + if (!new_watch) { + /* errno will be set */ + zk->last_ret = ZSYSTEMERROR; + zk->last_errno = errno; + + XSRETURN_UNDEF; + } + + watcher = _zk_watcher; + } + + Newx(buf, buf_len + 1, char); + + errno = 0; + ret = zoo_wget(zk->handle, path, watcher, new_watch, + buf, &buf_len, stat); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (watch_handle) { + _zk_replace_watch(aTHX_ watch_handle, zk->first_watch, + old_watch, new_watch); + } + + if (ret == ZOK) { + ST(0) = sv_newmortal(); +#ifdef SV_HAS_TRAILING_NUL + buf[buf_len] = '\0'; + sv_usepvn_flags(ST(0), buf, buf_len, SV_HAS_TRAILING_NUL); +#else + sv_usepvn(ST(0), buf, buf_len); +#endif + + XSRETURN(1); + } + else { + Safefree(buf); + + XSRETURN_UNDEF; + } + + +void +zk_set(zkh, path, buf, ...) + Net::ZooKeeper zkh + char *path + char *buf; buf = (char *) SvPV($arg, buf_len); + PREINIT: + zk_t *zk; + int version = -1; + zk_stat_t *stat = NULL; + STRLEN buf_len; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 3 && !(items % 2)) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + if (buf_len > PERL_INT_MAX) { + Perl_croak(aTHX_ "invalid data length: %u", buf_len); + } + + for (i = 3; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "version")) { + version = SvIV(ST(i + 1)); + + if (version < 0) { + Perl_croak(aTHX_ "invalid version requirement: %d", + version); + } + } + else if (strcaseEQ(key, "stat")) { + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV || + !sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) { + Perl_croak(aTHX_ "stat is not a hash reference of " + "type " STAT_PACKAGE_NAME); + } + + stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1))); + + if (!stat) { + Perl_croak(aTHX_ "invalid stat handle"); + } + } + } + + errno = 0; + ret = zoo_set2(zk->handle, path, buf, buf_len, version, stat); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zk_get_acl(zkh, path, ...) + Net::ZooKeeper zkh + char *path + PREINIT: + zk_t *zk; + zk_stat_t *stat = NULL; + struct ACL_vector acl; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 2 && items % 2) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + for (i = 2; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "stat")) { + if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV || + !sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) { + Perl_croak(aTHX_ "stat is not a hash reference of " + "type " STAT_PACKAGE_NAME); + } + + stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1))); + + if (!stat) { + Perl_croak(aTHX_ "invalid stat handle"); + } + } + } + + errno = 0; + ret = zoo_get_acl(zk->handle, path, &acl, stat); + + zk->last_ret = ret; + zk->last_errno = errno; + + if (ret == ZOK) { + int num_acl_entries; + + num_acl_entries = + (acl.count > PERL_INT_MAX) ? PERL_INT_MAX : acl.count; + + if (GIMME_V == G_ARRAY && num_acl_entries > 0) { + EXTEND(SP, num_acl_entries); + + for (i = 0; i < num_acl_entries; ++i) { + HV *acl_entry_hash = newHV(); + + _zk_fill_acl_entry_hash(aTHX_ &acl.data[i], + acl_entry_hash); + + ST(i) = sv_2mortal(newRV_noinc((SV*) acl_entry_hash)); + } + } + + /* NOTE: would be nice if this were documented as required */ + deallocate_ACL_vector(&acl); + + if (GIMME_V == G_ARRAY) { + if (num_acl_entries == 0) { + XSRETURN_EMPTY; + } + + XSRETURN(num_acl_entries); + } + else { + ST(0) = sv_2mortal(newSViv(num_acl_entries)); + + XSRETURN(1); + } + } + else { + if (GIMME_V == G_ARRAY) { + XSRETURN_EMPTY; + } + else { + XSRETURN_UNDEF; + } + } + + +void +zk_set_acl(zkh, path, acl_arr, ...) + Net::ZooKeeper zkh + char *path + AV *acl_arr + PREINIT: + zk_t *zk; + const char *err; + int version = -1; + struct ACL_vector acl; + int i, ret; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 3 && !(items % 2)) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + err = _zk_fill_acl(aTHX_ acl_arr, &acl); + + if (err) { + Perl_croak(aTHX_ err); + } + + for (i = 3; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "version")) { + version = SvIV(ST(i + 1)); + + if (version < 0) { + Perl_croak(aTHX_ "invalid version requirement: %d", + version); + } + } + } + + errno = 0; + ret = zoo_set_acl(zk->handle, path, version, &acl); + + zk->last_ret = ret; + zk->last_errno = errno; + + _zk_free_acl(aTHX_ &acl); + + if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zk_stat(zkh) + Net::ZooKeeper zkh + PREINIT: + zk_t *zk; + zk_handle_t *handle; + HV *stash, *stat_hash, *attr_hash; + SV *attr; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + Newx(handle, 1, zk_handle_t); + + handle->signature = STAT_PACKAGE_SIGNATURE; + + Newxz(handle->handle.stat, 1, zk_stat_t); + + /* As in zk_new(), we use two levels of magic here. */ + + stash = gv_stashpv(STAT_PACKAGE_NAME, GV_ADDWARN); + + attr_hash = newHV(); + + sv_magic((SV*) attr_hash, Nullsv, PERL_MAGIC_ext, + (const char*) handle, 0); + + attr = sv_bless(newRV_noinc((SV*) attr_hash), stash); + + stat_hash = newHV(); + + sv_magic((SV*) stat_hash, attr, PERL_MAGIC_tied, Nullch, 0); + SvREFCNT_dec(attr); + + ST(0) = sv_bless(sv_2mortal(newRV_noinc((SV*) stat_hash)), stash); + + XSRETURN(1); + + +void +zk_watch(zkh, ...) + Net::ZooKeeper zkh + PREINIT: + zk_t *zk; + unsigned int timeout; + zk_watch_t *watch; + zk_handle_t *handle; + HV *stash, *watch_hash, *attr_hash; + SV *attr; + int i; + PPCODE: + zk = _zk_get_handle_outer(aTHX_ zkh); + + if (!zk) { + Perl_croak(aTHX_ "invalid handle"); + } + + zk->last_ret = ZOK; + zk->last_errno = 0; + + if (items > 1 && !(items % 2)) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + timeout = zk->watch_timeout; + + for (i = 1; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "timeout")) { + timeout = SvUV(ST(i + 1)); + } + } + + watch = _zk_acquire_watch(aTHX); + + if (!watch) { + /* errno will be set */ + zk->last_ret = ZSYSTEMERROR; + zk->last_errno = errno; + + XSRETURN_UNDEF; + } + + Newx(handle, 1, zk_handle_t); + + handle->signature = WATCH_PACKAGE_SIGNATURE; + handle->handle.watch = watch; + + /* As in zk_new(), we use two levels of magic here. */ + + stash = gv_stashpv(WATCH_PACKAGE_NAME, GV_ADDWARN); + + attr_hash = newHV(); + + watch->timeout = timeout; + + sv_magic((SV*) attr_hash, Nullsv, PERL_MAGIC_ext, + (const char*) handle, 0); + + attr = sv_bless(newRV_noinc((SV*) attr_hash), stash); + + watch_hash = newHV(); + + sv_magic((SV*) watch_hash, attr, PERL_MAGIC_tied, Nullch, 0); + SvREFCNT_dec(attr); + + ST(0) = sv_bless(sv_2mortal(newRV_noinc((SV*) watch_hash)), stash); + + XSRETURN(1); + + +MODULE = Net::ZooKeeper PACKAGE = Net::ZooKeeper::Stat PREFIX = zks_ + +void +zks_DESTROY(zksh) + Net::ZooKeeper::Stat zksh + PREINIT: + zk_handle_t *handle; + HV *attr_hash; + int ret = ZBADARGUMENTS; + PPCODE: + handle = _zk_check_handle_outer(aTHX_ zksh, &attr_hash, + STAT_PACKAGE_NAME, + STAT_PACKAGE_SIGNATURE); + + if (!handle) { + handle = _zk_check_handle_inner(aTHX_ zksh, + STAT_PACKAGE_SIGNATURE); + + if (handle) { + attr_hash = zksh; + zksh = NULL; + } + } + + if (handle) { + ret = ZOK; + + Safefree(handle->handle.stat); + Safefree(handle); + + sv_unmagic((SV*) attr_hash, PERL_MAGIC_ext); + } + + if (zksh && attr_hash) { + sv_unmagic((SV*) zksh, PERL_MAGIC_tied); + } + + if (GIMME_V == G_VOID) { + XSRETURN_EMPTY; + } + else if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zks_CLONE(package) + char *package + PPCODE: + XSRETURN_EMPTY; + + +void +zks_CLONE_SKIP(package) + char *package + PPCODE: + XSRETURN_YES; + + +void +zks_TIEHASH(package, ...) + char *package + PPCODE: + Perl_croak(aTHX_ "tying hashes of class " + STAT_PACKAGE_NAME " not supported"); + + +void +zks_UNTIE(attr_hash, ref_count) + Net::ZooKeeper::Stat attr_hash + IV ref_count + PPCODE: + Perl_croak(aTHX_ "untying hashes of class " + STAT_PACKAGE_NAME " not supported"); + + +void +zks_FIRSTKEY(attr_hash) + Net::ZooKeeper::Stat attr_hash + PREINIT: + zk_stat_t *stat; + PPCODE: + stat = _zks_get_handle_inner(aTHX_ attr_hash); + + if (!stat) { + Perl_croak(aTHX_ "invalid handle"); + } + + ST(0) = sv_2mortal(newSVpvn(zk_stat_keys[0].name, + zk_stat_keys[0].name_len)); + + XSRETURN(1); + + +void +zks_NEXTKEY(attr_hash, attr_key) + Net::ZooKeeper::Stat attr_hash + SV *attr_key + PREINIT: + zk_stat_t *stat; + char *key; + int i; + PPCODE: + stat = _zks_get_handle_inner(aTHX_ attr_hash); + + if (!stat) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_STAT_KEYS; ++i) { + if (strcaseEQ(key, zk_stat_keys[i].name)) { + ++i; + + break; + } + } + + if (i < NUM_STAT_KEYS) { + ST(0) = sv_2mortal(newSVpvn(zk_stat_keys[i].name, + zk_stat_keys[i].name_len)); + + XSRETURN(1); + } + else { + XSRETURN_EMPTY; + } + + +void +zks_SCALAR(attr_hash) + Net::ZooKeeper::Stat attr_hash + PPCODE: + XSRETURN_YES; + + +void +zks_FETCH(attr_hash, attr_key) + Net::ZooKeeper::Stat attr_hash + SV *attr_key + PREINIT: + zk_stat_t *stat; + char *key; + SV *val = NULL; + int i; + PPCODE: + stat = _zks_get_handle_inner(aTHX_ attr_hash); + + if (!stat) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_STAT_KEYS; ++i) { + if (strcaseEQ(key, zk_stat_keys[i].name)) { + if (zk_stat_keys[i].size * CHAR_BIT == 32) { + val = newSViv(*((int32_t*) (((char*) stat) + + zk_stat_keys[i].offset))); + } + else { + /* NOTE: %lld is inconsistent, so cast to a double */ + val = newSVpvf("%.0f", (double) + *((int64_t*) (((char*) stat) + + zk_stat_keys[i].offset))); + } + + break; + } + } + + if (val) { + ST(0) = sv_2mortal(val); + + XSRETURN(1); + } + + Perl_warn(aTHX_ "invalid element: %s", key); + + XSRETURN_UNDEF; + + +void +zks_STORE(attr_hash, attr_key, attr_val) + Net::ZooKeeper::Stat attr_hash + SV *attr_key + SV *attr_val + PREINIT: + zk_stat_t *stat; + char *key; + int i; + PPCODE: + stat = _zks_get_handle_inner(aTHX_ attr_hash); + + if (!stat) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_STAT_KEYS; ++i) { + if (strcaseEQ(key, zk_stat_keys[i].name)) { + Perl_warn(aTHX_ "read-only element: %s", key); + + XSRETURN_EMPTY; + } + } + + Perl_warn(aTHX_ "invalid element: %s", key); + + XSRETURN_EMPTY; + + +void +zks_EXISTS(attr_hash, attr_key) + Net::ZooKeeper::Stat attr_hash + SV *attr_key + PREINIT: + zk_stat_t *stat; + char *key; + int i; + PPCODE: + stat = _zks_get_handle_inner(aTHX_ attr_hash); + + if (!stat) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_STAT_KEYS; ++i) { + if (strcaseEQ(key, zk_stat_keys[i].name)) { + XSRETURN_YES; + } + } + + XSRETURN_NO; + + +void +zks_DELETE(attr_hash, attr_key) + Net::ZooKeeper::Stat attr_hash + SV *attr_key + PPCODE: + Perl_warn(aTHX_ "deleting elements from hashes of class " + STAT_PACKAGE_NAME " not supported"); + + XSRETURN_EMPTY; + + +void +zks_CLEAR(attr_hash) + Net::ZooKeeper::Stat attr_hash + PPCODE: + Perl_warn(aTHX_ "clearing hashes of class " + STAT_PACKAGE_NAME " not supported"); + + XSRETURN_EMPTY; + + +MODULE = Net::ZooKeeper PACKAGE = Net::ZooKeeper::Watch PREFIX = zkw_ + +void +zkw_DESTROY(zkwh) + Net::ZooKeeper::Watch zkwh + PREINIT: + zk_handle_t *handle; + HV *attr_hash; + int ret = ZBADARGUMENTS; + PPCODE: + handle = _zk_check_handle_outer(aTHX_ zkwh, &attr_hash, + WATCH_PACKAGE_NAME, + WATCH_PACKAGE_SIGNATURE); + + if (!handle) { + handle = _zk_check_handle_inner(aTHX_ zkwh, + WATCH_PACKAGE_SIGNATURE); + + if (handle) { + attr_hash = zkwh; + zkwh = NULL; + } + } + + if (handle) { + ret = ZOK; + + _zk_release_watch(aTHX_ handle->handle.watch, 0); + Safefree(handle); + + sv_unmagic((SV*) attr_hash, PERL_MAGIC_ext); + } + + if (zkwh && attr_hash) { + sv_unmagic((SV*) zkwh, PERL_MAGIC_tied); + } + + if (GIMME_V == G_VOID) { + XSRETURN_EMPTY; + } + else if (ret == ZOK) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + + +void +zkw_CLONE(package) + char *package + PPCODE: + XSRETURN_EMPTY; + + +void +zkw_CLONE_SKIP(package) + char *package + PPCODE: + XSRETURN_YES; + + +void +zkw_TIEHASH(package, ...) + char *package + PPCODE: + Perl_croak(aTHX_ "tying hashes of class " + WATCH_PACKAGE_NAME " not supported"); + + +void +zkw_UNTIE(attr_hash, ref_count) + Net::ZooKeeper::Watch attr_hash + IV ref_count + PPCODE: + Perl_croak(aTHX_ "untying hashes of class " + WATCH_PACKAGE_NAME " not supported"); + + +void +zkw_FIRSTKEY(attr_hash) + Net::ZooKeeper::Watch attr_hash + PREINIT: + zk_watch_t *watch; + PPCODE: + watch = _zkw_get_handle_inner(aTHX_ attr_hash); + + if (!watch) { + Perl_croak(aTHX_ "invalid handle"); + } + + ST(0) = sv_2mortal(newSVpvn(zk_watch_keys[0].name, + zk_watch_keys[0].name_len)); + + XSRETURN(1); + + +void +zkw_NEXTKEY(attr_hash, attr_key) + Net::ZooKeeper::Watch attr_hash + SV *attr_key + PREINIT: + zk_watch_t *watch; + char *key; + int i; + PPCODE: + watch = _zkw_get_handle_inner(aTHX_ attr_hash); + + if (!watch) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_WATCH_KEYS; ++i) { + if (strcaseEQ(key, zk_watch_keys[i].name)) { + ++i; + + break; + } + } + + if (i < NUM_WATCH_KEYS) { + ST(0) = sv_2mortal(newSVpvn(zk_watch_keys[i].name, + zk_watch_keys[i].name_len)); + + XSRETURN(1); + } + else { + XSRETURN_EMPTY; + } + + +void +zkw_SCALAR(attr_hash) + Net::ZooKeeper::Watch attr_hash + PPCODE: + XSRETURN_YES; + + +void +zkw_FETCH(attr_hash, attr_key) + Net::ZooKeeper::Watch attr_hash + SV *attr_key + PREINIT: + zk_watch_t *watch; + char *key; + SV *val = NULL; + PPCODE: + watch = _zkw_get_handle_inner(aTHX_ attr_hash); + + if (!watch) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + if (strcaseEQ(key, "timeout")) { + val = newSVuv(watch->timeout); + } + else if (strcaseEQ(key, "event")) { + val = newSViv(watch->event_type); + } + else if (strcaseEQ(key, "state")) { + val = newSViv(watch->event_state); + } + + if (val) { + ST(0) = sv_2mortal(val); + + XSRETURN(1); + } + + Perl_warn(aTHX_ "invalid element: %s", key); + + XSRETURN_UNDEF; + + +void +zkw_STORE(attr_hash, attr_key, attr_val) + Net::ZooKeeper::Watch attr_hash + SV *attr_key + SV *attr_val + PREINIT: + zk_watch_t *watch; + char *key; + PPCODE: + watch = _zkw_get_handle_inner(aTHX_ attr_hash); + + if (!watch) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + if (strcaseEQ(key, "timeout")) { + watch->timeout = SvUV(attr_val); + } + else { + int i; + + for (i = 0; i < NUM_WATCH_KEYS; ++i) { + if (strcaseEQ(key, zk_watch_keys[i].name)) { + Perl_warn(aTHX_ "read-only element: %s", key); + + XSRETURN_EMPTY; + } + } + + Perl_warn(aTHX_ "invalid element: %s", key); + } + + XSRETURN_EMPTY; + + +void +zkw_EXISTS(attr_hash, attr_key) + Net::ZooKeeper::Watch attr_hash + SV *attr_key + PREINIT: + zk_watch_t *watch; + char *key; + int i; + PPCODE: + watch = _zkw_get_handle_inner(aTHX_ attr_hash); + + if (!watch) { + Perl_croak(aTHX_ "invalid handle"); + } + + key = SvPV_nolen(attr_key); + + for (i = 0; i < NUM_WATCH_KEYS; ++i) { + if (strcaseEQ(key, zk_watch_keys[i].name)) { + XSRETURN_YES; + } + } + + XSRETURN_NO; + + +void +zkw_DELETE(attr_hash, attr_key) + Net::ZooKeeper::Watch attr_hash + SV *attr_key + PPCODE: + Perl_warn(aTHX_ "deleting elements from hashes of class " + WATCH_PACKAGE_NAME " not supported"); + + XSRETURN_EMPTY; + + +void +zkw_CLEAR(attr_hash) + Net::ZooKeeper::Watch attr_hash + PPCODE: + Perl_warn(aTHX_ "clearing hashes of class " + WATCH_PACKAGE_NAME " not supported"); + + XSRETURN_EMPTY; + + +void +zkw_wait(zkwh, ...) + Net::ZooKeeper::Watch zkwh + PREINIT: + zk_watch_t *watch; + unsigned int timeout; + struct timeval end_timeval; + int i, done; + struct timespec wait_timespec; + PPCODE: + watch = _zkw_get_handle_outer(aTHX_ zkwh, NULL); + + if (!watch) { + Perl_croak(aTHX_ "invalid handle"); + } + + if (items > 1 && !(items % 2)) { + Perl_croak(aTHX_ "invalid number of arguments"); + } + + timeout = watch->timeout; + + for (i = 1; i < items; i += 2) { + char *key = SvPV_nolen(ST(i)); + + if (strcaseEQ(key, "timeout")) { + timeout = SvUV(ST(i + 1)); + } + } + + gettimeofday(&end_timeval, NULL); + + end_timeval.tv_sec += timeout / 1000; + end_timeval.tv_usec += (timeout % 1000) * 1000; + + wait_timespec.tv_sec = end_timeval.tv_sec; + wait_timespec.tv_nsec = end_timeval.tv_usec * 1000; + + pthread_mutex_lock(&watch->mutex); + + while (!watch->done) { + struct timeval curr_timeval; + + gettimeofday(&curr_timeval, NULL); + + if (end_timeval.tv_sec < curr_timeval.tv_sec || + (end_timeval.tv_sec == curr_timeval.tv_sec && + end_timeval.tv_usec <= curr_timeval.tv_usec)) { + break; + } + + pthread_cond_timedwait(&watch->cond, &watch->mutex, + &wait_timespec); + } + + done = watch->done; + + pthread_mutex_unlock(&watch->mutex); + + if (done) { + XSRETURN_YES; + } + else { + XSRETURN_NO; + } + diff --git a/src/contrib/zkperl/build.xml b/src/contrib/zkperl/build.xml new file mode 100644 index 00000000000..1f8e9c35f5e --- /dev/null +++ b/src/contrib/zkperl/build.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zkperl/build/check_zk_version.c b/src/contrib/zkperl/build/check_zk_version.c new file mode 100644 index 00000000000..b92315361cf --- /dev/null +++ b/src/contrib/zkperl/build/check_zk_version.c @@ -0,0 +1,29 @@ +/* Net::ZooKeeper - Perl extension for Apache ZooKeeper + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "check_zk_version.h" + +int main() { + printf("%d.%d.%d\n", ZOO_MAJOR_VERSION, ZOO_MINOR_VERSION, ZOO_PATCH_VERSION); + return 0; +} + diff --git a/src/contrib/zkperl/build/check_zk_version.h b/src/contrib/zkperl/build/check_zk_version.h new file mode 100644 index 00000000000..67a36420f78 --- /dev/null +++ b/src/contrib/zkperl/build/check_zk_version.h @@ -0,0 +1,27 @@ +/* Net::ZooKeeper - Perl extension for Apache ZooKeeper + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* keep in sync with Makefile.PL */ +#if !defined(ZOO_MAJOR_VERSION) || ZOO_MAJOR_VERSION != 3 || \ + !defined(ZOO_MINOR_VERSION) || ZOO_MINOR_VERSION < 1 || \ + !defined(ZOO_PATCH_VERSION) || \ + (ZOO_MINOR_VERSION == 1 && ZOO_PATCH_VERSION < 1) +#error "Net::ZooKeeper requires at least ZooKeeper version 3.1.1" +#endif + diff --git a/src/contrib/zkperl/t/10_invalid.t b/src/contrib/zkperl/t/10_invalid.t new file mode 100644 index 00000000000..5e080b64c7d --- /dev/null +++ b/src/contrib/zkperl/t/10_invalid.t @@ -0,0 +1,773 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 107; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(1); + + +## new() + +eval { + Net::ZooKeeper->new(); +}; +like($@, qr/Usage: Net::ZooKeeper::new\(package, hosts, \.\.\.\)/, + 'new(): no hostname specified'); + +eval { + Net::ZooKeeper->new($hosts, 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'new(): invalid number of arguments'); + +eval { + Net::ZooKeeper->new($hosts, 'session_timeout' => -3); +}; +like($@, qr/invalid session timeout/, + 'new(): invalid session timeout'); + +eval { + Net::ZooKeeper->new($hosts, 'session_timeout' => 0x4000_0000); +}; +like($@, qr/invalid session timeout/, + 'new(): invalid session timeout'); + +eval { + Net::ZooKeeper->new($hosts, 'session_id' => 'abcdef'); +}; +like($@, qr/invalid session ID/, + 'new(): invalid session ID'); + +my $zkh = Net::ZooKeeper->new($hosts); +isa_ok($zkh, 'Net::ZooKeeper', + 'new(): created handle'); + + +## DESTROY() + +eval { + $zkh->DESTROY('foo'); +}; +like($@, qr/Usage: Net::ZooKeeper::DESTROY\(zkh\)/, + 'DESTROY(): too many arguments'); + +my $bad_zkh = {}; +$bad_zkh = bless($bad_zkh, 'Net::ZooKeeper'); + +my $ret = $bad_zkh->DESTROY(); +ok(!$ret, + 'DESTROY(): no action on invalid handle'); + + +## add_auth() + +eval { + $zkh->add_auth(); +}; +like($@, qr/Usage: Net::ZooKeeper::add_auth\(zkh, scheme, cert\)/, + 'add_auth(): no scheme specified'); + +eval { + $zkh->add_auth('foo'); +}; +like($@, qr/Usage: Net::ZooKeeper::add_auth\(zkh, scheme, cert\)/, + 'add_auth(): no certificate specified'); + +eval { + $zkh->add_auth('foo', 'foo', 'bar'); +}; +like($@, qr/Usage: Net::ZooKeeper::add_auth\(zkh, scheme, cert\)/, + 'add_auth(): too many arguments'); + +eval { + $bad_zkh->add_auth('foo', 'foo'); +}; +like($@, qr/invalid handle/, + 'add_auth(): invalid handle'); + +eval { + Net::ZooKeeper::add_auth(1, 'foo', 'foo'); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'add_auth(): invalid hash reference'); + + +## create() + +eval { + $zkh->create(); +}; +like($@, qr/Usage: Net::ZooKeeper::create\(zkh, path, buf, \.\.\.\)/, + 'create(): no path specified'); + +eval { + $zkh->create($node_path); +}; +like($@, qr/Usage: Net::ZooKeeper::create\(zkh, path, buf, \.\.\.\)/, + 'create(): no data buffer specified'); + +eval { + $zkh->create($node_path, 'foo', 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'create(): invalid number of arguments'); + +eval { + $zkh->create($node_path, 'foo', 'path_read_len' => -3); +}; +like($@, qr/invalid path read length/, + 'create(): invalid path read length'); + +eval { + $zkh->create($node_path, 'foo', 'path_read_len' => 1); +}; +like($@, qr/invalid path read length/, + 'create(): invalid path read length'); + +eval { + $zkh->create($node_path, 'foo', 'flags' => 15); +}; +like($@, qr/invalid create flags/, + 'create(): invalid create flags'); + +eval { + $zkh->create($node_path, 'foo', 'flags' => ZOO_EPHEMERAL, 'acl', 'foo'); +}; +like($@, qr/invalid ACL array reference/, + 'create(): invalid ACL array reference'); + +eval { + $zkh->create($node_path, 'foo', 'acl', {}); +}; +like($@, qr/invalid ACL array reference/, + 'create(): invalid ACL array reference to hash'); + +eval { + my @acl = ('foo', 'bar'); + $zkh->create($node_path, 'foo', 'acl', \@acl); +}; +like($@, qr/invalid ACL entry hash reference/, + 'create(): invalid ACL entry hash reference'); + +eval { + my @acl = ({ 'foo' => 'bar' }); + $zkh->create($node_path, 'foo', 'acl', \@acl); +}; +like($@, qr/no ACL entry perms element/, + 'create(): no ACL entry perms element'); + +eval { + my @acl = ( + { + 'perms' => -1 + } + ); + $zkh->create($node_path, 'foo', 'acl', \@acl); +}; +like($@, qr/invalid ACL entry perms/, + 'create(): invalid ACL entry perms'); + +eval { + my @acl = ( + { + 'perms' => ZOO_PERM_ALL + } + ); + $zkh->create($node_path, 'foo', 'acl', \@acl); +}; +like($@, qr/no ACL entry scheme element/, + 'create(): no ACL entry scheme element'); + +eval { + my @acl = ( + { + 'perms' => ZOO_PERM_ALL, + 'scheme' => 'foo' + } + ); + $zkh->create($node_path, 'foo', 'acl', \@acl); +}; +like($@, qr/no ACL entry id element/, + 'create(): no ACL entry id element'); + +eval { + my @acl = ( + { + 'perms' => ZOO_PERM_ALL, + 'scheme' => 'foo', + 'id' => 'bar' + }, + 'bar' + ); + $zkh->create($node_path, 'foo', 'acl', \@acl); +}; +like($@, qr/invalid ACL entry hash reference/, + 'create(): invalid second ACL entry hash reference'); + +eval { + $bad_zkh->create($node_path, 'foo'); +}; +like($@, qr/invalid handle/, + 'create(): invalid handle'); + +eval { + Net::ZooKeeper::create(1, $node_path, 'foo'); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'create(): invalid hash reference'); + + +## delete() + +eval { + $zkh->delete(); +}; +like($@, qr/Usage: Net::ZooKeeper::delete\(zkh, path, \.\.\.\)/, + 'delete(): no path specified'); + +eval { + $zkh->delete($node_path, 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'delete(): invalid number of arguments'); + +eval { + $zkh->delete($node_path, 'version' => -3); +}; +like($@, qr/invalid version requirement/, + 'delete(): invalid version requirement'); + +eval { + $bad_zkh->delete($node_path); +}; +like($@, qr/invalid handle/, + 'delete(): invalid handle'); + +eval { + Net::ZooKeeper::delete(1, $node_path); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'delete(): invalid hash reference'); + + +## exists() + +eval { + $zkh->exists(); +}; +like($@, qr/Usage: Net::ZooKeeper::exists\(zkh, path, \.\.\.\)/, + 'exists(): no path specified'); + +eval { + $zkh->exists($node_path, 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'exists(): invalid number of arguments'); + +eval { + $zkh->exists($node_path, 'watch', 'bar'); +}; +like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/, + 'exists(): invalid watch hash reference'); + +eval { + $zkh->exists($node_path, 'watch', []); +}; +like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/, + 'exists(): invalid watch hash reference to array'); + +eval { + $zkh->exists($node_path, 'stat', 'bar'); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'exists(): invalid stat hash reference'); + +eval { + $zkh->exists($node_path, 'stat', []); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'exists(): invalid stat hash reference'); + +eval { + $bad_zkh->exists($node_path); +}; +like($@, qr/invalid handle/, + 'exists(): invalid handle'); + +eval { + Net::ZooKeeper::exists(1, $node_path); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'exists(): invalid hash reference'); + + +## get_children() + +eval { + $zkh->get_children(); +}; +like($@, qr/Usage: Net::ZooKeeper::get_children\(zkh, path, \.\.\.\)/, + 'get_children(): no path specified'); + +eval { + $zkh->get_children($node_path, 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'get_children(): invalid number of arguments'); + +eval { + $zkh->get_children($node_path, 'watch', 'bar'); +}; +like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/, + 'get_children(): invalid watch hash reference'); + +eval { + $zkh->get_children($node_path, 'watch', []); +}; +like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/, + 'get_children(): invalid watch ash reference to array'); + +eval { + $bad_zkh->get_children($node_path); +}; +like($@, qr/invalid handle/, + 'get_children(): invalid handle'); + +eval { + Net::ZooKeeper::get_children(1, $node_path); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'get_children(): invalid hash reference'); + + +## get() + +eval { + $zkh->get(); +}; +like($@, qr/Usage: Net::ZooKeeper::get\(zkh, path, \.\.\.\)/, + 'get(): no path specified'); + +eval { + $zkh->get($node_path, 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'get(): invalid number of arguments'); + +eval { + $zkh->get($node_path, 'data_read_len' => -3); +}; +like($@, qr/invalid data read length/, + 'get(): invalid data read length'); + +eval { + $zkh->get($node_path, 'data_read_len' => 10, 'watch', 'bar'); +}; +like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/, + 'get(): invalid watch hash reference'); + +eval { + $zkh->get($node_path, 'watch', []); +}; +like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/, + 'get(): invalid watch hash reference to array'); + +eval { + $zkh->get($node_path, 'stat', 'bar'); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'get(): invalid stat hash reference'); + +eval { + $zkh->get($node_path, 'stat', []); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'get(): invalid stat hash reference'); + +eval { + $bad_zkh->get($node_path); +}; +like($@, qr/invalid handle/, + 'get(): invalid handle'); + +eval { + Net::ZooKeeper::get(1, $node_path); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'get(): invalid hash reference'); + + +## set() + +eval { + $zkh->set(); +}; +like($@, qr/Usage: Net::ZooKeeper::set\(zkh, path, buf, \.\.\.\)/, + 'set(): no path specified'); + +eval { + $zkh->set($node_path); +}; +like($@, qr/Usage: Net::ZooKeeper::set\(zkh, path, buf, \.\.\.\)/, + 'set(): no data buffer specified'); + +eval { + $zkh->set($node_path, 'foo', 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'set(): invalid number of arguments'); + +eval { + $zkh->set($node_path, 'foo', 'version' => -3); +}; +like($@, qr/invalid version requirement/, + 'set(): invalid version requirement'); + +eval { + $zkh->set($node_path, 'foo', 'version', 0, 'stat', 'bar'); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'set(): invalid stat hash reference'); + +eval { + $zkh->set($node_path, 'foo', 'stat', []); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'set(): invalid stat hash reference'); + +eval { + $bad_zkh->set($node_path, 'foo'); +}; +like($@, qr/invalid handle/, + 'set(): invalid handle'); + +eval { + Net::ZooKeeper::set(1, $node_path, 'foo'); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'set(): invalid hash reference'); + + +## get_acl() + +eval { + $zkh->get_acl(); +}; +like($@, qr/Usage: Net::ZooKeeper::get_acl\(zkh, path, \.\.\.\)/, + 'get_acl(): no path specified'); + +eval { + $zkh->get_acl($node_path, 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'get_acl(): invalid number of arguments'); + +eval { + $zkh->get_acl($node_path, 'stat', 'bar'); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'get_acl(): invalid stat hash reference'); + +eval { + $zkh->get_acl($node_path, 'stat', []); +}; +like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/, + 'get_acl(): invalid stat hash reference'); + +eval { + $bad_zkh->get_acl($node_path); +}; +like($@, qr/invalid handle/, + 'get_acl(): invalid handle'); + +eval { + Net::ZooKeeper::get_acl(1, $node_path); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'get_acl(): invalid hash reference'); + + +## set_acl() + +eval { + $zkh->set_acl(); +}; +like($@, qr/Usage: Net::ZooKeeper::set_acl\(zkh, path, acl_arr, \.\.\.\)/, + 'set_acl(): no path specified'); + +eval { + $zkh->set_acl($node_path); +}; +like($@, qr/Usage: Net::ZooKeeper::set_acl\(zkh, path, acl_arr, \.\.\.\)/, + 'set_acl(): no data buffer specified'); + +eval { + $zkh->set_acl($node_path, 'foo'); +}; +like($@, qr/acl_arr is not an array reference/, + 'set_acl(): invalid ACL array reference'); + +eval { + $zkh->set_acl($node_path, {}); +}; +like($@, qr/acl_arr is not an array reference/, + 'set_acl(): invalid ACL array reference to hash'); + +eval { + my @acl = ('foo', 'bar'); + $zkh->set_acl($node_path, \@acl); +}; +like($@, qr/invalid ACL entry hash reference/, + 'set_acl(): invalid ACL entry hash reference'); + +eval { + my @acl = ({ 'foo' => 'bar' }); + $zkh->set_acl($node_path, \@acl); +}; +like($@, qr/no ACL entry perms element/, + 'set_acl(): no ACL entry perms element'); + +eval { + my @acl = ( + { + 'perms' => -1 + } + ); + $zkh->set_acl($node_path, \@acl); +}; +like($@, qr/invalid ACL entry perms/, + 'set_acl(): invalid ACL entry perms'); + +eval { + my @acl = ( + { + 'perms' => ZOO_PERM_ALL + } + ); + $zkh->set_acl($node_path, \@acl); +}; +like($@, qr/no ACL entry scheme element/, + 'set_acl(): no ACL entry scheme element'); + +eval { + my @acl = ( + { + 'perms' => ZOO_PERM_ALL, + 'scheme' => 'foo' + } + ); + $zkh->set_acl($node_path, \@acl); +}; +like($@, qr/no ACL entry id element/, + 'set_acl(): no ACL entry id element'); + +eval { + my @acl = ( + { + 'perms' => ZOO_PERM_ALL, + 'scheme' => 'foo', + 'id' => 'bar' + }, + 'bar' + ); + $zkh->set_acl($node_path, \@acl); +}; +like($@, qr/invalid ACL entry hash reference/, + 'set_acl(): invalid second ACL entry hash reference'); + +eval { + $zkh->set_acl($node_path, [], 'bar'); +}; +like($@, qr/invalid number of arguments/, + 'set_acl(): invalid number of arguments'); + +eval { + $zkh->set_acl($node_path, [], 'version' => -3); +}; +like($@, qr/invalid version requirement/, + 'set_acl(): invalid version requirement'); + +eval { + $bad_zkh->set_acl($node_path, []); +}; +like($@, qr/invalid handle/, + 'set_acl(): invalid handle'); + +eval { + Net::ZooKeeper::set_acl(1, $node_path, []); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'set_acl(): invalid hash reference'); + + +## stat() + +eval { + $zkh->stat('bar'); +}; +like($@, qr/Usage: Net::ZooKeeper::stat\(zkh\)/, + 'stat(): too many arguments'); + +eval { + $bad_zkh->stat(); +}; +like($@, qr/invalid handle/, + 'stat(): invalid handle'); + +eval { + Net::ZooKeeper::stat(1); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'stat(): invalid hash reference'); + +my $stat = $zkh->stat(); +isa_ok($stat, 'Net::ZooKeeper::Stat', + 'stat(): created stat handle'); + + +## stat DESTROY() + +eval { + $stat->DESTROY('foo'); +}; +like($@, qr/Usage: Net::ZooKeeper::Stat::DESTROY\(zksh\)/, + 'stat DESTROY(): too many arguments'); + +my $bad_stat = {}; +$bad_stat = bless($bad_stat, 'Net::ZooKeeper::Stat'); + +$ret = $bad_stat->DESTROY(); +ok(!$ret, + 'stat DESTROY(): no action on invalid handle'); + + +## watch() + +eval { + $zkh->watch('bar'); +}; +like($@, qr/invalid number of arguments/, + 'watch(): invalid number of arguments'); + +eval { + $bad_zkh->watch(); +}; +like($@, qr/invalid handle/, + 'watch(): invalid handle'); + +eval { + Net::ZooKeeper::watch(1); +}; +like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/, + 'watch(): invalid hash reference'); + +my $watch = $zkh->watch(); +isa_ok($watch, 'Net::ZooKeeper::Watch', + 'watch(): created watch handle'); + + +## watch DESTROY() + +eval { + $watch->DESTROY('foo'); +}; +like($@, qr/Usage: Net::ZooKeeper::Watch::DESTROY\(zkwh\)/, + 'watch DESTROY(): too many arguments'); + +my $bad_watch = {}; +$bad_watch = bless($bad_watch, 'Net::ZooKeeper::Watch'); + +$ret = $bad_watch->DESTROY(); +ok(!$ret, + 'watch DESTROY(): no action on invalid handle'); + + +## wait() + +eval { + $watch->wait('bar'); +}; +like($@, qr/invalid number of arguments/, + 'wait(): invalid number of arguments'); + +eval { + $bad_watch->wait(); +}; +like($@, qr/invalid handle/, + 'wait(): invalid watch handle'); + +eval { + Net::ZooKeeper::Watch::wait(1); +}; +like($@, qr/zkwh is not a hash reference of type Net::ZooKeeper::Watch/, + 'wait(): invalid watch hash reference'); + + +## set_log_level() + +eval { + my $f = \&Net::ZooKeeper::set_log_level; + &$f(); +}; +like($@, qr/Usage: Net::ZooKeeper::set_log_level\(level\)/, + 'set_log_level(): no level specified'); + +eval { + my $f = \&Net::ZooKeeper::set_log_level; + &$f(ZOO_LOG_LEVEL_OFF, 'foo'); +}; +like($@, qr/Usage: Net::ZooKeeper::set_log_level\(level\)/, + 'set_log_level(): too many arguments'); + +eval { + Net::ZooKeeper::set_log_level((ZOO_LOG_LEVEL_OFF) - 1); +}; +like($@, qr/invalid log level/, + 'set_log_level(): invalid low log level'); + +eval { + Net::ZooKeeper::set_log_level((ZOO_LOG_LEVEL_DEBUG) + 1); +}; +like($@, qr/invalid log level/, + 'set_log_level(): invalid high log level'); + + +## set_deterministic_conn_order() + +eval { + my $f = \&Net::ZooKeeper::set_deterministic_conn_order; + &$f(); +}; +like($@, qr/Usage: Net::ZooKeeper::set_deterministic_conn_order\(flag\)/, + 'set_deterministic_conn_order(): no flag specified'); + +eval { + my $f = \&Net::ZooKeeper::set_deterministic_conn_order; + &$f(1, 'foo'); +}; +like($@, qr/Usage: Net::ZooKeeper::set_deterministic_conn_order\(flag\)/, + 'set_deterministic_conn_order(): too many arguments'); + diff --git a/src/contrib/zkperl/t/15_thread.t b/src/contrib/zkperl/t/15_thread.t new file mode 100644 index 00000000000..1ef56d0c7c8 --- /dev/null +++ b/src/contrib/zkperl/t/15_thread.t @@ -0,0 +1,121 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use Config; +use File::Spec; +use Test::More; + +BEGIN { + if ($Config{'useithreads'}) { + plan tests => 10; + } + else { + plan skip_all => 'no thread support'; + } +} + +use threads; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +my $zkh = Net::ZooKeeper->new($hosts); + +SKIP: { + skip 'no valid handle', 9 unless (defined($zkh)); + + my($thread) = threads->new(\&thread_test, $zkh); + + SKIP: { + skip 'no valid thread', 3 unless (defined($thread)); + + my(@ret) = $thread->join; + + ok((@ret == 3 and $ret[0]), + 'CLONE_SKIP(): handle reference after spawning thread'); + + ok((@ret == 3 and $ret[1]), + 'CLONE_SKIP(): scalar handle reference after spawning thread'); + + ok((@ret == 3 and $ret[2]), + 'CLONE_SKIP(): undef handle reference after spawning thread'); + } + + my $stat = $zkh->stat(); + + ($thread) = threads->new(\&thread_test, $stat); + + SKIP: { + skip 'no valid thread', 3 unless (defined($thread)); + + my(@ret) = $thread->join; + + ok((@ret == 3 and $ret[0]), + 'stat CLONE_SKIP(): stat handle reference after spawning thread'); + + ok((@ret == 3 and $ret[1]), + 'stat CLONE_SKIP(): scalar stat handle reference after ' . + 'spawning thread'); + + ok((@ret == 3 and $ret[2]), + 'stat CLONE_SKIP(): undef stat handle reference after ' . + 'spawning thread'); + } + + my $watch = $zkh->watch(); + + ($thread) = threads->new(\&thread_test, $watch); + + SKIP: { + skip 'no valid thread', 3 unless (defined($thread)); + + my(@ret) = $thread->join; + + ok((@ret == 3 and $ret[0]), + 'watch CLONE_SKIP(): watch handle reference after spawning thread'); + + ok((@ret == 3 and $ret[1]), + 'watch CLONE_SKIP(): scalar watch handle reference after ' . + 'spawning thread'); + + ok((@ret == 3 and $ret[2]), + 'watch CLONE_SKIP(): undef watch handle reference after ' . + 'spawning thread'); + } +} + +sub thread_test +{ + my $zkh = shift; + + my @ret; + + $ret[0] = ref($zkh) ? 1 : 0; + $ret[1] = ($ret[0] and ref($zkh) eq 'SCALAR') ? 1 : 0; + $ret[2] = ($ret[1] and !defined(${$zkh})) ? 1 : 0; + + return @ret; +} + diff --git a/src/contrib/zkperl/t/20_tie.t b/src/contrib/zkperl/t/20_tie.t new file mode 100644 index 00000000000..37e9a4f4e51 --- /dev/null +++ b/src/contrib/zkperl/t/20_tie.t @@ -0,0 +1,353 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 54; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + skip 'no valid handle', 4 unless (defined($zkh)); + + + ## DESTROY() + + my $attr = tied(%{$zkh}); + + my $ret = $attr->DESTROY(); + ok($ret, + 'DESTROY(): destroyed inner hash'); + + $ret = $attr->DESTROY(); + ok(!$ret, + 'DESTROY(): no action on destroyed inner hash'); + + $ret = $zkh->DESTROY(); + ok(!$ret, + 'DESTROY(): no action on handle with destroyed inner hash'); + + undef $zkh; + ok(!defined($zkh), + 'undef: released handle with destroyed inner hash'); +} + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + skip 'no valid handle', 49 unless (defined($zkh)); + + + ## TIEHASH(), UNTIE() + + eval { + tie(%{$zkh}, 'Net::ZooKeeper'); + }; + like($@, qr/tying hashes of class Net::ZooKeeper not supported/, + 'tie(): tying hashes not supported'); + + eval { + Net::ZooKeeper::TIEHASH('Net::ZooKeeper'); + }; + like($@, qr/tying hashes of class Net::ZooKeeper not supported/, + 'TIEHASH(): tying hashes not supported'); + + eval { + untie(%{$zkh}); + }; + like($@, qr/untying hashes of class Net::ZooKeeper not supported/, + 'untie(): untying hashes not supported'); + + my $attr = tied(%{$zkh}); + + eval { + $attr->UNTIE(0); + }; + like($@, qr/untying hashes of class Net::ZooKeeper not supported/, + 'UNTIE(): untying hashes not supported'); + + + ## FIRSTKEY(), NEXTKEY(), SCALAR() + + my $copy_zkh; + { + my %copy_zkh = %{$zkh}; + $copy_zkh = \%copy_zkh; + } + bless($copy_zkh, 'Net::ZooKeeper'); + is(ref($copy_zkh), 'Net::ZooKeeper', + 'FIRSTKEY(), NEXTKEY(): copied dereferenced handle'); + + eval { + my $val = $copy_zkh->FIRSTKEY(); + }; + like($@, qr/invalid handle/, + 'FETCHKEY(): invalid handle'); + + eval { + my $val = $copy_zkh->NEXTKEY('data_read_len'); + }; + like($@, qr/invalid handle/, + 'NEXTKEY(): invalid handle'); + + my @keys = keys(%{$zkh}); + is(scalar(@keys), 7, + 'keys(): count of keys from handle'); + + @keys = keys(%{$copy_zkh}); + is(scalar(@keys), 7, + 'keys(): count of keys from copied dereferenced handle'); + + is($attr->FIRSTKEY(), 'data_read_len', + 'FIRSTKEY(): retrieved first key using inner hash'); + + is($attr->NEXTKEY('session_id'), 'pending_watches', + 'NEXTKEY(): retrieved last key using inner hash'); + + is($attr->NEXTKEY('pending_watches'), undef, + 'NEXTKEY(): undef returned after last key using inner hash'); + + ok(scalar(%{$zkh}), + 'scalar(): true value returned for dereferenced handle'); + + ok($zkh->SCALAR(), + 'SCALAR(): true value returned'); + + + ## FETCH() + + eval { + my $val = $copy_zkh->FETCH('data_read_len'); + }; + like($@, qr/invalid handle/, + 'FETCH(): invalid handle'); + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + my $val = $zkh->{'foo'}; + ok(!defined($val), + 'FETCH(): undef returned for invalid element'); + + like($msg, qr/invalid element/, + 'FETCH(): invalid element'); + } + + is($zkh->{'data_read_len'}, 1023, + 'FETCH(): default data read length'); + + is($zkh->{'path_read_len'}, 1023, + 'FETCH(): default path read length'); + + is($zkh->{'hosts'}, $hosts, + 'FETCH(): server hosts'); + + is($zkh->{'session_timeout'}, 10000, + 'FETCH(): default session timeout'); + + ok(defined($zkh->{'session_id'}), + 'FETCH(): session ID'); + + SKIP: { + my $zkh = Net::ZooKeeper->new('0.0.0.0:0'); + + skip 'no valid handle with invalid host', 1 unless (defined($zkh)); + + is($zkh->{'session_id'}, '', + 'FETCH(): empty session ID with invalid host'); + } + + is($zkh->{'pending_watches'}, 0, + 'FETCH(): default pending watch list length'); + + is($attr->FETCH('data_read_len'), 1023, + 'FETCH(): default data read length using inner hash'); + + + ## STORE() + + eval { + my $val = $copy_zkh->STORE('data_read_len', 'foo'); + }; + like($@, qr/invalid handle/, + 'STORE(): invalid handle'); + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $zkh->{'foo'} = 'foo'; + like($msg, qr/invalid element/, + 'STORE(): invalid element'); + } + + eval { + $zkh->{'data_read_len'} = -3; + }; + like($@, qr/invalid data read length/, + 'STORE(): invalid data read length'); + + eval { + $zkh->{'path_read_len'} = -3; + }; + like($@, qr/invalid path read length/, + 'STORE(): invalid path read length'); + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $zkh->{'hosts'} = 'foo'; + like($msg, qr/read-only element: hosts/, + 'STORE(): read-only server hosts element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $zkh->{'session_timeout'} = 0; + like($msg, qr/read-only element: session_timeout/, + 'STORE(): read-only session timeout element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $zkh->{'session_id'} = 'foo'; + like($msg, qr/read-only element: session_id/, + 'STORE(): read-only session ID element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $zkh->{'pending_watches'} = 0; + like($msg, qr/read-only element: pending_watches/, + 'STORE(): read-only pending watch list length element'); + } + + $zkh->{'data_read_len'} = 200; + is($zkh->{'data_read_len'}, 200, + 'STORE(): updated data read length'); + + $zkh->{'path_read_len'} = 100; + is($zkh->{'path_read_len'}, 100, + 'STORE(): updated path read length'); + + $attr->STORE('data_read_len', 100); + is($zkh->{'data_read_len'}, 100, + 'STORE(): updated data read length using inner hash'); + + + ## EXISTS() + + eval { + my $val = $copy_zkh->EXISTS('data_read_len'); + }; + like($@, qr/invalid handle/, + 'EXISTS(): invalid handle'); + + ok(!exists($zkh->{'foo'}), + 'exists(): invalid element of handle'); + + ok(exists($zkh->{'data_read_len'}), + 'exists(): data read length'); + + ok(exists($zkh->{'path_read_len'}), + 'exists(): path read length'); + + ok(exists($zkh->{'hosts'}), + 'exists(): server hosts'); + + ok(exists($zkh->{'session_timeout'}), + 'exists(): session timeout'); + + ok(exists($zkh->{'session_id'}), + 'exists(): session ID'); + + ok(exists($zkh->{'pending_watches'}), + 'exists(): pending watch list length'); + + ok($attr->EXISTS('data_read_len'), + 'EXISTS(): data read length using inner hash'); + + + ## DELETE(), CLEAR() + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + delete($zkh->{'data_read_len'}); + like($msg, + qr/deleting elements from hashes of class Net::ZooKeeper not supported/, + 'delete(): deleting hash elements not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $zkh->DELETE({'data_read_len'}); + like($msg, + qr/deleting elements from hashes of class Net::ZooKeeper not supported/, + 'DELETE(): deleting hash elements not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + %{$zkh} = (); + like($msg, qr/clearing hashes of class Net::ZooKeeper not supported/, + 'assign: clearing hashes not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $zkh->CLEAR(); + like($msg, qr/clearing hashes of class Net::ZooKeeper not supported/, + 'CLEAR(): clearing hashes not supported'); + } +} + diff --git a/src/contrib/zkperl/t/22_stat_tie.t b/src/contrib/zkperl/t/22_stat_tie.t new file mode 100644 index 00000000000..02e79131de2 --- /dev/null +++ b/src/contrib/zkperl/t/22_stat_tie.t @@ -0,0 +1,438 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 66; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + my $stat = $zkh->stat() if (defined($zkh)); + + skip 'no valid stat handle', 4 unless (defined($stat)); + + + ## DESTROY() + + my $attr = tied(%{$stat}); + + my $ret = $attr->DESTROY(); + ok($ret, + 'stat DESTROY(): destroyed inner stat hash'); + + $ret = $attr->DESTROY(); + ok(!$ret, + 'stat DESTROY(): no action on destroyed inner stat hash'); + + $ret = $stat->DESTROY(); + ok(!$ret, + 'stat DESTROY(): no action on stat handle with destroyed inner hash'); + + undef $stat; + ok(!defined($stat), + 'undef: released stat handle with destroyed inner hash'); +} + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + my $stat = $zkh->stat() if (defined($zkh)); + + skip 'no valid stat handle', 61 unless (defined($stat)); + + + ## TIEHASH(), UNTIE() + + eval { + tie(%{$stat}, 'Net::ZooKeeper::Stat'); + }; + like($@, qr/tying hashes of class Net::ZooKeeper::Stat not supported/, + 'tie(): tying stat hashes not supported'); + + eval { + Net::ZooKeeper::Stat::TIEHASH('Net::ZooKeeper::Stat'); + }; + like($@, qr/tying hashes of class Net::ZooKeeper::Stat not supported/, + 'stat TIEHASH(): tying stat hashes not supported'); + + eval { + untie(%{$stat}); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Stat not supported/, + 'untie(): untying stat hashes not supported'); + + my $attr = tied(%{$stat}); + + eval { + $attr->UNTIE(0); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Stat not supported/, + 'stat UNTIE(): untying stat hashes not supported'); + + + ## FIRSTKEY(), NEXTKEY(), SCALAR() + + my $copy_stat; + { + my %copy_stat = %{$stat}; + $copy_stat = \%copy_stat; + } + bless($copy_stat, 'Net::ZooKeeper::Stat'); + is(ref($copy_stat), 'Net::ZooKeeper::Stat', + 'stat FIRSTKEY(), NEXTKEY(): copied dereferenced stat handle'); + + eval { + my $val = $copy_stat->FIRSTKEY(); + }; + like($@, qr/invalid handle/, + 'stat FETCHKEY(): invalid stat handle'); + + eval { + my $val = $copy_stat->NEXTKEY('czxid'); + }; + like($@, qr/invalid handle/, + 'stat NEXTKEY(): invalid stat handle'); + + my @keys = keys(%{$stat}); + is(scalar(@keys), 11, + 'keys(): count of keys from stat handle'); + + @keys = keys(%{$copy_stat}); + is(scalar(@keys), 11, + 'keys(): count of keys from copied dereferenced stat handle'); + + is($attr->FIRSTKEY(), 'czxid', + 'stat FIRSTKEY(): retrieved first key using inner stat hash'); + + is($attr->NEXTKEY('num_children'), 'children_zxid', + 'stat NEXTKEY(): retrieved last key using inner stat hash'); + + is($attr->NEXTKEY('children_zxid'), undef, + 'NEXTKEY(): undef returned after last key using inner stat hash'); + + ok(scalar(%{$stat}), + 'scalar(): true value returned for dereferenced stat handle'); + + ok($stat->SCALAR(), + 'stat SCALAR(): true value returned'); + + + ## FETCH() + + eval { + my $val = $copy_stat->FETCH('version'); + }; + like($@, qr/invalid handle/, + 'stat FETCH(): invalid stat handle'); + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + my $val = $stat->{'foo'}; + ok(!defined($val), + 'stat FETCH(): undef returned for invalid element'); + + like($msg, qr/invalid element/, + 'stat FETCH(): invalid element'); + } + + is($stat->{'czxid'}, 0, + 'stat FETCH(): default node creation ZooKeeper transaction ID'); + + is($stat->{'mzxid'}, 0, + 'stat FETCH(): default data last-modified ZooKeeper transaction ID'); + + is($stat->{'ctime'}, 0, + 'stat FETCH(): default node creation time'); + + is($stat->{'mtime'}, 0, + 'stat FETCH(): default data last-modified time'); + + is($stat->{'version'}, 0, + 'stat FETCH(): default data version'); + + is($stat->{'children_version'}, 0, + 'stat FETCH(): default child node list version'); + + is($stat->{'acl_version'}, 0, + 'stat FETCH(): default ACL version'); + + is($stat->{'ephemeral_owner'}, 0, + 'stat FETCH(): ephemeral node owner session ID'); + + is($stat->{'data_len'}, 0, + 'stat FETCH(): default data length'); + + is($stat->{'num_children'}, 0, + 'stat FETCH(): default child node list length'); + + is($stat->{'children_zxid'}, 0, + 'stat FETCH(): default child node list last-modified ' . + 'ZooKeeper transaction ID'); + + is($attr->FETCH('version'), 0, + 'stat FETCH(): default data version using inner stat hash'); + + + ## STORE() + + eval { + my $val = $copy_stat->STORE('version', 'foo'); + }; + like($@, qr/invalid handle/, + 'stat STORE(): invalid stat handle'); + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'foo'} = 'foo'; + like($msg, qr/invalid element/, + 'stat STORE(): invalid element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'czxid'} = 'foo'; + like($msg, qr/read-only element: czxid/, + 'stat STORE(): read-only node creation ' . + 'ZooKeeper transaction ID element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'mzxid'} = 'foo'; + like($msg, qr/read-only element: mzxid/, + 'stat STORE(): read-only data last-modified ' . + 'ZooKeeper transaction ID element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'ctime'} = 'foo'; + like($msg, qr/read-only element: ctime/, + 'stat STORE(): read-only node creation time element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'mtime'} = 'foo'; + like($msg, qr/read-only element: mtime/, + 'stat STORE(): read-only data last-modified time element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'version'} = 'foo'; + like($msg, qr/read-only element: version/, + 'stat STORE(): read-only data version element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'children_version'} = 'foo'; + like($msg, qr/read-only element: children_version/, + 'stat STORE(): read-only child node list version element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'acl_version'} = 'foo'; + like($msg, qr/read-only element: acl_version/, + 'stat STORE(): read-only ACL version element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'ephemeral_owner'} = 'foo'; + like($msg, qr/read-only element: ephemeral_owner/, + 'stat STORE(): read-only ephemeral node owner ' . + 'session ID element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'data_len'} = 'foo'; + like($msg, qr/read-only element: data_len/, + 'stat STORE(): read-only data length element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'num_children'} = 'foo'; + like($msg, qr/read-only element: num_children/, + 'stat STORE(): read-only child node list length element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->{'children_zxid'} = 'foo'; + like($msg, qr/read-only element: children_zxid/, + 'stat STORE(): read-only child node list last-modified ' . + 'ZooKeeper transaction ID element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $attr->STORE('version', 'foo'); + like($msg, qr/read-only element: version/, + 'stat STORE(): read-only data version element using ' . + 'inner stat hash'); + } + + + ## EXISTS() + + eval { + my $val = $copy_stat->EXISTS('version'); + }; + like($@, qr/invalid handle/, + 'stat EXISTS(): invalid stat handle'); + + ok(!exists($stat->{'foo'}), + 'exists(): invalid element of stat handle'); + + ok(exists($stat->{'czxid'}), + 'exists(): node creation ZooKeeper transaction ID'); + + ok(exists($stat->{'mzxid'}), + 'exists(): data last-modified ZooKeeper transaction ID'); + + ok(exists($stat->{'ctime'}), + 'exists(): node creation time'); + + ok(exists($stat->{'mtime'}), + 'exists(): data last-modified time'); + + ok(exists($stat->{'version'}), + 'exists(): data version'); + + ok(exists($stat->{'children_version'}), + 'exists(): child node list version'); + + ok(exists($stat->{'acl_version'}), + 'exists(): ACL version'); + + ok(exists($stat->{'ephemeral_owner'}), + 'exists(): ephemeral node owner session ID'); + + ok(exists($stat->{'data_len'}), + 'exists(): data length'); + + ok(exists($stat->{'num_children'}), + 'exists(): child node list length'); + + ok(exists($stat->{'children_zxid'}), + 'exists(): child node list last-modified ZooKeeper transaction ID'); + + ok($attr->EXISTS('version'), + 'stat EXISTS(): data version using inner stat hash'); + + + ## DELETE(), CLEAR() + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + delete($stat->{'version'}); + like($msg, + qr/deleting elements from hashes of class Net::ZooKeeper::Stat not supported/, + 'delete(): deleting stat hash elements not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->DELETE({'version'}); + like($msg, + qr/deleting elements from hashes of class Net::ZooKeeper::Stat not supported/, + 'stat DELETE(): deleting stat hash elements not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + %{$stat} = (); + like($msg, qr/clearing hashes of class Net::ZooKeeper::Stat not supported/, + 'assign: clearing stat hashes not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $stat->CLEAR(); + like($msg, qr/clearing hashes of class Net::ZooKeeper::Stat not supported/, + 'stat CLEAR(): clearing stat hashes not supported'); + } +} + diff --git a/src/contrib/zkperl/t/24_watch_tie.t b/src/contrib/zkperl/t/24_watch_tie.t new file mode 100644 index 00000000000..e77879e6229 --- /dev/null +++ b/src/contrib/zkperl/t/24_watch_tie.t @@ -0,0 +1,292 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 42; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + my $watch = $zkh->watch() if (defined($zkh)); + + skip 'no valid watch handle', 4 unless (defined($watch)); + + + ## DESTROY() + + my $attr = tied(%{$watch}); + + my $ret = $attr->DESTROY(); + ok($ret, + 'watch DESTROY(): destroyed inner watch hash'); + + $ret = $attr->DESTROY(); + ok(!$ret, + 'watch DESTROY(): no action on destroyed inner watch hash'); + + $ret = $watch->DESTROY(); + ok(!$ret, + 'watch DESTROY(): no action on watch handle with destroyed inner hash'); + + undef $watch; + ok(!defined($watch), + 'undef: released watch handle with destroyed inner hash'); +} + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + my $watch = $zkh->watch() if (defined($zkh)); + + skip 'no valid watch handle', 37 unless (defined($watch)); + + + ## TIEHASH(), UNTIE() + + eval { + tie(%{$watch}, 'Net::ZooKeeper::Watch'); + }; + like($@, qr/tying hashes of class Net::ZooKeeper::Watch not supported/, + 'tie(): tying watch hashes not supported'); + + eval { + Net::ZooKeeper::Watch::TIEHASH('Net::ZooKeeper::Watch'); + }; + like($@, qr/tying hashes of class Net::ZooKeeper::Watch not supported/, + 'watch TIEHASH(): tying watch hashes not supported'); + + eval { + untie(%{$watch}); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Watch not supported/, + 'untie(): untying watch hashes not supported'); + + my $attr = tied(%{$watch}); + + eval { + $attr->UNTIE(0); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Watch not supported/, + 'watch UNTIE(): untying watch hashes not supported'); + + + ## FIRSTKEY(), NEXTKEY(), SCALAR() + + my $copy_watch; + { + my %copy_watch = %{$watch}; + $copy_watch = \%copy_watch; + } + bless($copy_watch, 'Net::ZooKeeper::Watch'); + is(ref($copy_watch), 'Net::ZooKeeper::Watch', + 'watch FIRSTKEY(), NEXTKEY(): copied dereferenced watch handle'); + + eval { + my $val = $copy_watch->FIRSTKEY(); + }; + like($@, qr/invalid handle/, + 'watch FETCHKEY(): invalid watch handle'); + + eval { + my $val = $copy_watch->NEXTKEY('czxid'); + }; + like($@, qr/invalid handle/, + 'watch NEXTKEY(): invalid watch handle'); + + my @keys = keys(%{$watch}); + is(scalar(@keys), 3, + 'keys(): count of keys from watch handle'); + + @keys = keys(%{$copy_watch}); + is(scalar(@keys), 3, + 'keys(): count of keys from copied dereferenced watch handle'); + + is($attr->FIRSTKEY(), 'timeout', + 'watch FIRSTKEY(): retrieved first key using inner watch hash'); + + is($attr->NEXTKEY('event'), 'state', + 'watch NEXTKEY(): retrieved last key using inner watch hash'); + + is($attr->NEXTKEY('state'), undef, + 'NEXTKEY(): undef returned after last key using inner watch hash'); + + ok(scalar(%{$watch}), + 'scalar(): true value returned for dereferenced watch handle'); + + ok($watch->SCALAR(), + 'watch SCALAR(): true value returned'); + + + ## FETCH() + + eval { + my $val = $copy_watch->FETCH('version'); + }; + like($@, qr/invalid handle/, + 'watch FETCH(): invalid watch handle'); + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + my $val = $watch->{'foo'}; + ok(!defined($val), + 'watch FETCH(): undef returned for invalid element'); + + like($msg, qr/invalid element/, + 'watch FETCH(): invalid element'); + } + + is($watch->{'timeout'}, 60000, + 'watch FETCH(): default timeout'); + + is($watch->{'event'}, 0, + 'watch FETCH(): default event'); + + is($watch->{'state'}, 0, + 'watch FETCH(): default state'); + + is($attr->FETCH('timeout'), 60000, + 'watch FETCH(): default timeout using inner watch hash'); + + + ## STORE() + + eval { + my $val = $copy_watch->STORE('version', 'foo'); + }; + like($@, qr/invalid handle/, + 'watch STORE(): invalid watch handle'); + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $watch->{'foo'} = 'foo'; + like($msg, qr/invalid element/, + 'watch STORE(): invalid element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $watch->{'event'} = 'foo'; + like($msg, qr/read-only element: event/, + 'watch STORE(): read-only event element'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $watch->{'state'} = 'foo'; + like($msg, qr/read-only element: state/, + 'watch STORE(): read-only state element'); + } + + $watch->{'timeout'} = 100; + is($watch->{'timeout'}, 100, + 'watch STORE(): updated timeout'); + + $attr->STORE('timeout', 200); + is($watch->{'timeout'}, 200, + 'watch STORE(): updated timeout using inner hash'); + + + ## EXISTS() + + eval { + my $val = $copy_watch->EXISTS('version'); + }; + like($@, qr/invalid handle/, + 'watch EXISTS(): invalid watch handle'); + + ok(!exists($watch->{'foo'}), + 'exists(): invalid element of watch handle'); + + ok(exists($watch->{'timeout'}), + 'exists(): timeout'); + + ok(exists($watch->{'event'}), + 'exists(): event'); + + ok(exists($watch->{'state'}), + 'exists(): state'); + + ok($attr->EXISTS('timeout'), + 'watch EXISTS(): timeout using inner watch hash'); + + + ## DELETE(), CLEAR() + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + delete($watch->{'version'}); + like($msg, + qr/deleting elements from hashes of class Net::ZooKeeper::Watch not supported/, + 'delete(): deleting watch hash elements not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $watch->DELETE({'version'}); + like($msg, + qr/deleting elements from hashes of class Net::ZooKeeper::Watch not supported/, + 'watch DELETE(): deleting watch hash elements not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + %{$watch} = (); + like($msg, qr/clearing hashes of class Net::ZooKeeper::Watch not supported/, + 'assign: clearing watch hashes not supported'); + } + + { + my $msg; + + $SIG{'__WARN__'} = sub { $msg = $_[0]; }; + + $watch->CLEAR(); + like($msg, qr/clearing hashes of class Net::ZooKeeper::Watch not supported/, + 'watch CLEAR(): clearing watch hashes not supported'); + } +} + diff --git a/src/contrib/zkperl/t/30_connect.t b/src/contrib/zkperl/t/30_connect.t new file mode 100644 index 00000000000..c2b68bb4e5f --- /dev/null +++ b/src/contrib/zkperl/t/30_connect.t @@ -0,0 +1,202 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 29; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +## new(), DESTROY() + +Net::ZooKeeper::set_deterministic_conn_order(1); + +my $zkh = Net::ZooKeeper->new($hosts); +isa_ok($zkh, 'Net::ZooKeeper', + 'new(): created handle'); + +SKIP: { + skip 'no valid handle', 3 unless (defined($zkh)); + + my $ret = $zkh->DESTROY(); + ok($ret, + 'DESTROY(): destroyed handle'); + + $ret = $zkh->DESTROY(); + ok(!$ret, + 'DESTROY(): no action on destroyed handle'); + + undef $zkh; + ok(!defined($zkh), + 'undef: released handle'); +} + +Net::ZooKeeper::set_deterministic_conn_order(0); + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + skip 'no valid handle', 10 unless (defined($zkh)); + + my $copy_zkh = $zkh; + isa_ok($copy_zkh, 'Net::ZooKeeper', + 'assign: copied handle'); + + my $ret = $zkh->exists($root_path); + ok(defined($ret), + 'exists(): no error from original handle'); + + undef $zkh; + ok(!defined($zkh), + 'undef: released original handle'); + + $ret = $copy_zkh->exists($root_path); + ok(defined($ret), + 'exists(): no error from first copy of handle'); + + $zkh = $copy_zkh; + isa_ok($zkh, 'Net::ZooKeeper', + 'assign: re-copied handle'); + + $ret = $copy_zkh->DESTROY(); + ok($ret, + 'DESTROY(): destroyed first copy of handle'); + + eval { + $zkh->exists($root_path); + }; + like($@, qr/invalid handle/, + 'exists(): invalid second copy of handle'); + + undef $copy_zkh; + ok(!defined($copy_zkh), + 'undef: released first copy of handle'); + + $ret = $zkh->DESTROY(); + ok(!$ret, + 'DESTROY(): no action on second copy of destroyed handle'); + + undef $zkh; + ok(!defined($zkh), + 'undef: released second copy of handle'); +} + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + skip 'no valid handle', 6 unless (defined($zkh)); + + my $copy_zkh; + { + my %copy_zkh = %{$zkh}; + $copy_zkh = \%copy_zkh; + } + bless($copy_zkh, 'Net::ZooKeeper'); + isa_ok($copy_zkh, 'Net::ZooKeeper', + 'FIRSTKEY(), NEXTKEY(): copied dereferenced handle'); + + eval { + $copy_zkh->exists($root_path); + }; + like($@, qr/invalid handle/, + 'exists(): invalid copy of dereferenced handle'); + + $ret = $copy_zkh->DESTROY(); + ok(!$ret, + 'DESTROY(): no action on copy of dereferenced handle'); + + undef $copy_zkh; + ok(!defined($copy_zkh), + 'undef: released copy of dereferenced handle'); + + my $ret = $zkh->exists($root_path); + ok(defined($ret), + 'exists(): no error from original handle'); + + undef $zkh; + ok(!defined($zkh), + 'undef: released original handle'); +} + +Net::ZooKeeper::set_deterministic_conn_order(1); + +my $zkh1 = Net::ZooKeeper->new($hosts, 'session_timeout' => 0x3FFF_FFFF); +isa_ok($zkh1, 'Net::ZooKeeper', + 'new(): created handle with maximum session timeout'); + +SKIP: { + my $ret = $zkh1->exists($root_path) if (defined($zkh1)); + + skip 'no connection to ZooKeeper', 7 unless + (defined($ret) and $ret); + + + ## FETCH() of read-only attributes + + ok(($zkh1->{'session_timeout'} > 0 and + $zkh1->{'session_timeout'} <= 0x3FFF_FFFF), + 'FETCH(): session timeout reset after connection'); + + my $session_id1 = $zkh1->{'session_id'}; + ok((length($session_id1) > 0), + 'FETCH(): non-empty session ID after connection'); + + SKIP: { + skip 'no session ID after connection', 1 unless + (length($session_id1) > 0); + + my @nonzero_bytes = grep($_ != 0, unpack('c' x length($session_id1), + $session_id1)); + ok((@nonzero_bytes > 0), + 'FETCH(): non-zero session ID after connection'); + } + + ## NOTE: to test re-connections with saved session IDs we create a second + ## connection with the same ID while the first is still active; + ## this is bad practice in normal usage + + my $zkh2 = Net::ZooKeeper->new($hosts, + 'session_id' => $session_id1, + 'session_timeout' => 20000); + isa_ok($zkh2, 'Net::ZooKeeper', + 'new(): created handle with session ID and valid session timeout'); + + $ret = $zkh2->exists($root_path); + ok($ret, + 'new(): reconnection with session ID'); + + SKIP: { + skip 'no connection to ZooKeeper', 2 unless ($ret); + + is($zkh2->{'session_timeout'}, 20000, + 'FETCH(): session timeout unchanged after connection'); + + my $session_id2 = $zkh2->{'session_id'}; + ok((length($session_id2) == length($session_id1) + and $session_id2 eq $session_id1), + 'FETCH(): reconnect with session ID'); + } +} + diff --git a/src/contrib/zkperl/t/35_log.t b/src/contrib/zkperl/t/35_log.t new file mode 100644 index 00000000000..92821afc1f3 --- /dev/null +++ b/src/contrib/zkperl/t/35_log.t @@ -0,0 +1,88 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 3; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +my $zkh = Net::ZooKeeper->new($hosts); + +Net::ZooKeeper::set_log_level(ZOO_LOG_LEVEL_INFO); + +SKIP: { + skip 'no valid handle', 2 unless (defined($zkh)); + + SKIP: { + my $dup = 0; + + if (open(OLDERR, '>&', fileno(STDERR))) { + if (close(STDERR) and open(STDERR, '+>', undef)) { + $dup = 1; + + my $old_select = select(STDERR); + $| = 1; + select($old_select); + } + else { + open(STDERR, '>&', fileno(OLDERR)); + close(OLDERR); + } + } + + skip 'no duplicated stderr', 2 unless ($dup); + + SKIP: { + $zkh->exists($root_path); + + sleep(1); + + skip 'no seek on stderr', 1 unless (seek(STDERR, 0, 0)); + + my $log = ; + like($log, qr/ZOO_/, + 'exists(): generated log message'); + } + + SKIP: { + $zkh->DESTROY(); + + sleep(1); + + skip 'no seek on stderr', 1 unless (seek(STDERR, 0, 0)); + + my $log = ; + like($log, qr/ZOO_/, + 'DESTROY(): generated log message'); + } + + open(STDERR, '>&', fileno(OLDERR)); + close(OLDERR); + } +} + +Net::ZooKeeper::set_log_level(ZOO_LOG_LEVEL_OFF); + diff --git a/src/contrib/zkperl/t/40_basic.t b/src/contrib/zkperl/t/40_basic.t new file mode 100644 index 00000000000..38a8a2138e4 --- /dev/null +++ b/src/contrib/zkperl/t/40_basic.t @@ -0,0 +1,277 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 35; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +my $zkh = Net::ZooKeeper->new($hosts); +my $path; + +SKIP: { + my $ret = $zkh->exists($root_path) if (defined($zkh)); + + skip 'no connection to ZooKeeper', 1 unless + (defined($ret) and $ret); + + $path = $zkh->create($node_path, 'foo', 'acl' => ZOO_OPEN_ACL_UNSAFE); + is($path, $node_path, + 'create(): created node'); +} + +SKIP: { + skip 'no connection to ZooKeeper', 21 unless + (defined($path) and $path eq $node_path); + + + ## exists() + + my $ret = $zkh->exists($node_path); + ok($ret, + 'exists(): checked node existence'); + + $ret = $zkh->exists($node_path . '/NONE'); + ok((!$ret and $zkh->get_error() == ZNONODE and $! eq ''), + 'exists(): checked node non-existence'); + + my $stat = $zkh->stat(); + + $ret = $zkh->exists($node_path, 'stat' => $stat); + ok(($ret and $stat->{'data_len'} == 3), + 'exists(): checked node existence with stat handle'); + + + ## get() + + my $node = $zkh->get($node_path); + is($node, 'foo', + 'get(): retrieved node value'); + + $node = $zkh->get($node_path . '/NONE'); + ok((!defined($node) and $zkh->get_error() == ZNONODE and $! eq ''), + 'get(): undef returned for non-extant node'); + + $node = $zkh->get($node_path, 'data_read_len', 2); + is($node, 'fo', + 'get(): retrieved truncated node value'); + + $node = $zkh->get($node_path, 'data_read_len' => 0); + is($node, '', + 'get(): retrieved zero-length node value'); + + $node = $zkh->get($node_path, 'stat' => $stat); + ok(($node eq 'foo' and $stat->{'data_len'} == 3), + 'get(): retrieved node value with stat handle'); + + + ## set() + + $ret = $zkh->set($node_path, 'foo'); + ok($ret, + 'set(): set node value'); + + SKIP: { + my $ret = $zkh->exists($node_path, 'stat' => $stat); + + skip 'invalid node data', 2 unless + ($ret and $stat->{'version'} == 1); + + $ret = $zkh->set($node_path, 'foo', 'version' => $stat->{'version'}); + ok($ret, + 'set(): set node value with matching version'); + + $ret = $zkh->set($node_path, 'foo', 'version' => $stat->{'version'}); + ok((!$ret and $zkh->get_error() == ZBADVERSION and $! eq ''), + 'set(): node value unchanged if non-matching version'); + } + + $ret = $zkh->set($node_path, 'foobaz', 'stat' => $stat); + ok(($ret and $stat->{'data_len'} == 6), + 'set(): retrieved node value with stat handle'); + + + ## create(), delete() + + $path = $zkh->create($node_path, 'foo', 'acl' => ZOO_OPEN_ACL_UNSAFE); + ok((!defined($path) and $zkh->get_error() == ZNODEEXISTS and $! eq ''), + 'create(): undef when attempting to create extant node'); + + $ret = $zkh->delete($node_path . '/NONE'); + ok((!$ret and $zkh->get_error() == ZNONODE and $! eq ''), + 'delete(): no deletion of non-extant node'); + + $ret = $zkh->delete($node_path); + ok($ret, + 'delete(): deleted node'); + + my $path_read_len = length($node_path) - 2; + + $path = $zkh->create($node_path, 'foo', + 'path_read_len' => $path_read_len, + 'acl' => ZOO_OPEN_ACL_UNSAFE); + is($path, substr($node_path, 0, -2), + 'create(): created node with small return path buffer'); + + $path = $zkh->create("$node_path/s", 'foo', + 'flags' => ZOO_SEQUENCE, + 'acl' => ZOO_OPEN_ACL_UNSAFE); + like($path, qr/^$node_path\/s[0-9]+$/, + 'create(): created sequential node'); + + SKIP: { + my $ret = $zkh->exists($path, 'stat' => $stat); + + unless ($ret and $stat->{'version'} == 0) { + my $ret = $zkh->delete($path); + diag(sprintf('unable to delete node %s: %d, %s', + $path, $zkh->get_error(), $!)) unless ($ret); + + skip 'invalid node data', 2; + } + + $ret = $zkh->delete($path, 'version' => ($stat->{'version'} + 1)); + ok((!$ret and $zkh->get_error() == ZBADVERSION and $! eq ''), + 'delete(): node not deleted if non-matching version'); + + $ret = $zkh->delete($path, 'version' => $stat->{'version'}); + ok($ret, + 'delete(): deleted sequential node with matching version'); + } + + $path = $zkh->create("$node_path/e", 'foo', + 'flags' => ZOO_EPHEMERAL, + 'acl' => ZOO_OPEN_ACL_UNSAFE); + is($path, "$node_path/e", + 'create(): created ephemeral node'); + + $path = $zkh->create("$node_path/es", 'foo', + 'flags' => (ZOO_SEQUENCE | ZOO_EPHEMERAL), + 'acl' => ZOO_OPEN_ACL_UNSAFE); + like($path, qr/^$node_path\/es[0-9]+$/, + 'create(): created ephemeral sequential node'); + + undef $zkh; +} + +$zkh = Net::ZooKeeper->new($hosts); + +SKIP: { + my $ret = $zkh->exists($node_path) if (defined($zkh)); + + skip 'no connection to ZooKeeper', 12 unless + (defined($ret) and $ret); + + $ret = $zkh->exists("$node_path/e"); + ok((!$ret and $zkh->get_error() == ZNONODE and $! eq ''), + 'exists(): checked ephemeral node non-extant after reconnection'); + + $ret = $zkh->exists($path); + ok((!$ret and $zkh->get_error() == ZNONODE and $! eq ''), + 'exists(): checked ephemeral sequential node non-extant ' . + 'after reconnection'); + + + ## get_children() + + my @child_paths = ('abc'); + @child_paths = $zkh->get_children($node_path); + ok((@child_paths == 0 and $zkh->get_error() == ZOK), + 'get_children(): retrieved empty list of child nodes'); + + my $num_children = $zkh->get_children($node_path); + ok((defined($num_children) and $num_children == 0), + 'get_children(): retrieved zero count of child nodes'); + + @child_paths = $zkh->get_children($node_path . '/NONE'); + ok((@child_paths == 0 and $zkh->get_error() == ZNONODE and $! eq ''), + 'get_children(): empty list returned for non-extant node'); + + $num_children = $zkh->get_children($node_path . '/NONE'); + ok((!defined($num_children) and $zkh->get_error() == ZNONODE and $! eq ''), + 'get_children(): undef returned for non-extant node'); + + SKIP: { + my $path = $zkh->create("$node_path/c1", 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE); + + skip 'no connection to ZooKeeper', 6 unless + (defined($path) and $path eq "$node_path/c1"); + + my @child_paths = ('abc'); + @child_paths = $zkh->get_children($node_path); + ok((@child_paths == 1 and $child_paths[0] eq 'c1'), + 'get_children(): retrieved list of single child node'); + + my $num_children = $zkh->get_children($node_path); + ok((defined($num_children) and $num_children == 1), + 'get_children(): retrieved count of single child node'); + + SKIP: { + my $path = $zkh->create("$node_path/c2", 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE); + + skip 'no connection to ZooKeeper', 2 unless + (defined($path) and $path eq "$node_path/c2"); + + my @child_paths = ('abc'); + @child_paths = $zkh->get_children($node_path); + ok((@child_paths == 2 and $child_paths[0] eq 'c1' and + $child_paths[1] eq 'c2'), + 'get_children(): retrieved list of two child nodes'); + + my $num_children = $zkh->get_children($node_path); + ok((defined($num_children) and $num_children == 2), + 'get_children(): retrieved count of two child nodes'); + + my $ret = $zkh->delete("$node_path/c2"); + diag(sprintf('unable to delete node %s: %d, %s', + "$node_path/c2", $zkh->get_error(), $!)) unless + ($ret); + } + + @child_paths = ('abc'); + @child_paths = $zkh->get_children($node_path); + ok((@child_paths == 1 and $child_paths[0] eq 'c1'), + 'get_children(): retrieved list of single child node'); + + $num_children = $zkh->get_children($node_path); + ok((defined($num_children) and $num_children == 1), + 'get_children(): retrieved count of single child node'); + + my $ret = $zkh->delete("$node_path/c1"); + diag(sprintf('unable to delete node %s: %d, %s', + "$node_path/c1", $zkh->get_error(), $!)) unless ($ret); + } + + + ## cleanup + + $ret = $zkh->delete($node_path); + diag(sprintf('unable to delete node %s: %d, %s', + $node_path, $zkh->get_error(), $!)) unless ($ret); +} + diff --git a/src/contrib/zkperl/t/45_class.t b/src/contrib/zkperl/t/45_class.t new file mode 100644 index 00000000000..4aa1a5733bc --- /dev/null +++ b/src/contrib/zkperl/t/45_class.t @@ -0,0 +1,408 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 47; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + skip 'no valid handle', 15 unless (defined($zkh)); + + my $stat = $zkh->stat(); + my $watch = $zkh->watch(); + + + ## DESTROY() on reblessed handle + + bless($zkh, 'My::ZooKeeper'); + is(ref($zkh), 'My::ZooKeeper', + 'bless(): reblessed handle'); + + eval { + $zkh->EXISTS(); + }; + like($@, qr/Can't locate object method "EXISTS" via package "My::ZooKeeper"/, + 'EXISTS(): not defined on reblessed handle'); + + my $attr = tied(%{$zkh}); + + my $ret = $attr->DESTROY(); + ok($ret, + 'DESTROY(): destroyed inner hash of reblessed handle'); + + $ret = $attr->DESTROY(); + ok(!$ret, + 'DESTROY(): no action on destroyed inner hash of reblessed handle'); + + undef $zkh; + ok(!defined($zkh), + 'undef: released reblessed handle'); + + + ## DESTROY() on reblessed stat handle + + bless($stat, 'My::ZooKeeper::Stat'); + is(ref($stat), 'My::ZooKeeper::Stat', + 'bless(): reblessed stat handle'); + + eval { + $stat->EXISTS(1); + }; + like($@, qr/Can't locate object method "EXISTS" via package "My::ZooKeeper::Stat"/, + 'stat EXISTS(): not defined on reblessed stat handle'); + + $attr = tied(%{$stat}); + + $ret = $attr->DESTROY(); + ok($ret, + 'stat DESTROY(): destroyed inner hash of reblessed stat handle'); + + $ret = $attr->DESTROY(); + ok(!$ret, + 'stat DESTROY(): no action on destroyed inner hash of ' . + 'reblessed stat handle'); + + undef $stat; + ok(!defined($stat), + 'undef: released reblessed stat handle'); + + + ## DESTROY() on reblessed watch handle + + bless($watch, 'My::ZooKeeper::Watch'); + is(ref($watch), 'My::ZooKeeper::Watch', + 'bless(): reblessed watch handle'); + + eval { + $watch->EXISTS(1); + }; + like($@, qr/Can't locate object method "EXISTS" via package "My::ZooKeeper::Watch"/, + 'watch EXISTS(): not defined on reblessed watch handle'); + + $attr = tied(%{$watch}); + + $ret = $attr->DESTROY(); + ok($ret, + 'watch DESTROY(): destroyed inner hash of reblessed watch handle'); + + $ret = $attr->DESTROY(); + ok(!$ret, + 'watch DESTROY(): no action on destroyed inner hash of ' . + 'reblessed watch handle'); + + undef $watch; + ok(!defined($watch), + 'undef: released reblessed watch handle'); +} + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + skip 'no valid handle', 9 unless (defined($zkh)); + + my $stat = $zkh->stat(); + my $watch = $zkh->watch(); + + + ## UNTIE() on reblessed handle + + bless($zkh, 'My::ZooKeeper'); + is(ref($zkh), 'My::ZooKeeper', + 'bless(): reblessed handle'); + + eval { + untie(%{$zkh}); + }; + like($@, qr/untying hashes of class Net::ZooKeeper not supported/, + 'untie(): untying hashes from reblessed handle not supported'); + + my $attr = tied(%{$zkh}); + + eval { + $attr->UNTIE(0); + }; + like($@, qr/untying hashes of class Net::ZooKeeper not supported/, + 'UNTIE(): untying hashes from reblessed handle not supported'); + + + ## UNTIE() on reblessed stat handle + + bless($stat, 'My::ZooKeeper::Stat'); + is(ref($stat), 'My::ZooKeeper::Stat', + 'bless(): reblessed stat handle'); + + eval { + untie(%{$stat}); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Stat not supported/, + 'untie(): untying hashes from reblessed stat handle not supported'); + + $attr = tied(%{$stat}); + + eval { + $attr->UNTIE(0); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Stat not supported/, + 'stat UNTIE(): untying hashes from reblessed stat handle ' . + 'not supported'); + + + ## UNTIE() on reblessed watch handle + + bless($watch, 'My::ZooKeeper::Watch'); + is(ref($watch), 'My::ZooKeeper::Watch', + 'bless(): reblessed watch handle'); + + eval { + untie(%{$watch}); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Watch not supported/, + 'untie(): untying hashes from reblessed watch handle not supported'); + + $attr = tied(%{$watch}); + + eval { + $attr->UNTIE(0); + }; + like($@, qr/untying hashes of class Net::ZooKeeper::Watch not supported/, + 'watch UNTIE(): untying hashes from reblessed watch handle ' . + 'not supported'); +} + + +package Net::ZooKeeper::Test; + +use Net::ZooKeeper qw(:acls); + +our @ISA = qw(Net::ZooKeeper); + +sub create +{ + my($self, $path, $buf) = @_; + + return $self->SUPER::create($path, $buf, + 'path_read_len' => length($path), + 'acl' => ZOO_OPEN_ACL_UNSAFE); +} + +sub get_first_child +{ + my($self, $path) = @_; + + my @child_paths = $self->get_children($path); + + if (@child_paths > 0) { + return $path . (($path =~ /\/$/) ? '' : '/') . $child_paths[0]; + } + + return undef; +} + +sub stat +{ + my $self = shift; + + my $stat = $self->SUPER::stat(); + + return bless($stat, 'Net::ZooKeeper::Test::Stat'); +} + + +sub watch +{ + my $self = shift; + + my $watch = $self->SUPER::watch(); + + return bless($watch, 'Net::ZooKeeper::Test::Watch'); +} + + +package Net::ZooKeeper::Test::Stat; + +our @ISA = qw(Net::ZooKeeper::Stat); + +sub get_ctime +{ + my $self = shift; + + return $self->{'ctime'}; +} + + +package Net::ZooKeeper::Test::Watch; + +our @ISA = qw(Net::ZooKeeper::Watch); + +sub get_timeout +{ + my $self = shift; + + return $self->{'timeout'}; +} + + +package main; + +my $sub_zkh = Net::ZooKeeper::Test->new($hosts); +isa_ok($sub_zkh, 'Net::ZooKeeper::Test', + 'new(): created subclassed handle'); + +SKIP: { + skip 'no valid subclassed handle', 21 unless (defined($sub_zkh)); + + is($sub_zkh->{'data_read_len'}, 1023, + 'FETCH(): default data read length using subclassed handle'); + + my $path; + + SKIP: { + my $ret = $sub_zkh->exists($root_path); + + skip 'no connection to ZooKeeper', 1 unless + (defined($ret) and $ret); + + $path = $sub_zkh->create($node_path, 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE); + is($path, $node_path, + 'create(): created node with subclassed handle'); + } + + SKIP: { + skip 'no connection to ZooKeeper', 1 unless + (defined($path) and $path eq $node_path); + + my $child_path = $sub_zkh->get_first_child($root_path); + is($child_path, $node_path, + 'get_first_child(): retrieved first child with subclassed handle'); + } + + my $sub_stat = $sub_zkh->stat(); + isa_ok($sub_stat, 'Net::ZooKeeper::Test::Stat', + 'stat(): created subclassed stat handle'); + + SKIP: { + skip 'no valid subclassed stat handle', 6 unless + (defined($sub_stat)); + + is($sub_stat->{'ctime'}, 0, + 'stat FETCH(): default ctime using subclassed stat handle'); + + SKIP: { + my $ret = $sub_zkh->exists($node_path, 'stat' => $sub_stat) if + (defined($path) and $path eq $node_path); + + skip 'no connection to ZooKeeper', 2 unless + (defined($ret) and $ret); + + my $ctime = $sub_stat->get_ctime(); + ok($ctime > 0, + 'get_ctime(): retrieved ctime with subclassed stat handle'); + + is($sub_stat->{'ctime'}, $ctime, + 'stat FETCH(): ctime using subclassed stat handle'); + } + + my $ret = $sub_stat->DESTROY(); + ok($ret, + 'stat DESTROY(): destroyed subclassed stat handle'); + + $ret = $sub_stat->DESTROY(); + ok(!$ret, + 'stat DESTROY(): no action on destroyed subclassed stat handle'); + + undef $sub_stat; + ok(!defined($sub_stat), + 'undef: released subclassed stat handle'); + } + + my $sub_watch = $sub_zkh->watch(); + isa_ok($sub_watch, 'Net::ZooKeeper::Test::Watch', + 'watch(): created subclassed watch handle'); + + SKIP: { + skip 'no valid subclassed watch handle', 6 unless + (defined($sub_watch)); + + SKIP: { + my $ret = $sub_zkh->exists($root_path, 'watch' => $sub_watch); + + skip 'no connection to ZooKeeper', 3 unless + (defined($ret) and $ret); + + $sub_watch->{'timeout'} = 50; + + is($sub_watch->get_timeout(), 50, + 'get_timeout(): retrieved timeout with subclassed ' . + 'watch handle'); + + is($sub_watch->{'timeout'}, 50, + 'watch FETCH(): timeout using subclassed stat handle'); + + $ret = $sub_watch->wait(); + ok(!$ret, + 'wait(): watch after checking node existence timed out with ' . + 'subclassed watch handle'); + } + + my $ret = $sub_watch->DESTROY(); + ok($ret, + 'watch DESTROY(): destroyed subclassed watch handle'); + + $ret = $sub_watch->DESTROY(); + ok(!$ret, + 'watch DESTROY(): no action on destroyed subclassed watch handle'); + + undef $sub_watch; + ok(!defined($sub_watch), + 'undef: released subclassed watch handle'); + } + + SKIP: { + skip 'no connection to ZooKeeper', 1 unless + (defined($path) and $path eq $node_path); + + my $ret = $sub_zkh->delete($node_path); + ok($ret, + 'delete(): deleted node with subclassed handle'); + } + + my $ret = $sub_zkh->DESTROY(); + ok($ret, + 'DESTROY(): destroyed subclassed handle'); + + $ret = $sub_zkh->DESTROY(); + ok(!$ret, + 'DESTROY(): no action on destroyed subclassed handle'); + + undef $sub_zkh; + ok(!defined($sub_zkh), + 'undef: released subclassed handle'); +} + diff --git a/src/contrib/zkperl/t/50_access.t b/src/contrib/zkperl/t/50_access.t new file mode 100644 index 00000000000..ef61ed6688f --- /dev/null +++ b/src/contrib/zkperl/t/50_access.t @@ -0,0 +1,356 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 40; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + +my($username, $password, $digest) = zk_acl_test_setup(); + + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + my $path = $zkh->create($node_path, 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE) if (defined($zkh)); + + skip 'no connection to ZooKeeper', 36 unless + (defined($path) and $path eq $node_path); + + + ## _zk_acl_constant() + + my $no_read_acl = ZOO_OPEN_ACL_UNSAFE; + ok((ref($no_read_acl) eq 'ARRAY' and + @{$no_read_acl} == 1 and + ref($no_read_acl->[0]) eq 'HASH' and + keys(%{$no_read_acl->[0]}) == 3 and + $no_read_acl->[0]->{'perms'} == ZOO_PERM_ALL), + '_zk_acl_constant(): returned default ACL'); + + my $zoo_read_acl_unsafe = ZOO_READ_ACL_UNSAFE; + ok((ref($zoo_read_acl_unsafe) eq 'ARRAY' and + @{$zoo_read_acl_unsafe} == 1 and + ref($zoo_read_acl_unsafe->[0]) eq 'HASH' and + keys(%{$zoo_read_acl_unsafe->[0]}) == 3 and + $zoo_read_acl_unsafe->[0]->{'perms'} == ZOO_PERM_READ), + '_zk_acl_constant(): returned good ACL'); + + my $zoo_creator_all_acl = ZOO_CREATOR_ALL_ACL; + ok((ref($zoo_creator_all_acl) eq 'ARRAY' and + @{$zoo_creator_all_acl} == 1 and + ref($zoo_creator_all_acl->[0]) eq 'HASH' and + keys(%{$zoo_creator_all_acl->[0]}) == 3 and + $zoo_creator_all_acl->[0]->{'perms'} == ZOO_PERM_ALL), + '_zk_acl_constant(): returned good ACL'); + + $no_read_acl->[0]->{'perms'} &= ~ZOO_PERM_READ; + is($no_read_acl->[0]->{'perms'}, ((ZOO_PERM_ALL) & ~ZOO_PERM_READ), + 'assign: altered default ACL'); + + is(ZOO_OPEN_ACL_UNSAFE->[0]->{'perms'}, ZOO_PERM_ALL, + '_zk_acl_constant(): returned unaltered default ACL'); + + my $copy_no_read_acl = $no_read_acl; + is_deeply($copy_no_read_acl, $no_read_acl, + 'assign: copied default ACL'); + + undef $no_read_acl; + ok(!defined($no_read_acl), + 'undef: released original default ACL'); + + is($copy_no_read_acl->[0]->{'perms'}, ((ZOO_PERM_ALL) & ~ZOO_PERM_READ), + 'undef: no change to copied default ACL'); + + $no_read_acl = $copy_no_read_acl; + is_deeply($no_read_acl, $copy_no_read_acl, + 'assign: re-copied default ACL'); + + + ## create() + + my $acl_node_path = "$node_path/a1"; + + $path = $zkh->create($acl_node_path, 'foo', 'acl' => $no_read_acl); + is($path, $acl_node_path, + 'create(): created node with no-read ACL'); + + my $node = $zkh->get($acl_node_path); + + my $skip_acl; + if (defined($node) and $node eq 'foo') { + $skip_acl = 1; + } + elsif(!defined($node) and $zkh->get_error() == ZNOAUTH) { + $skip_acl = 0; + } + else { + $skip_acl = -1; + diag(sprintf('unable to get node with no-read ACL %s: %d, %s', + $acl_node_path, $zkh->get_error(), $!)); + } + + my $ret = $zkh->delete($acl_node_path); + diag(sprintf('unable to delete node with no-read ACL %s: %d, %s', + $acl_node_path, $zkh->get_error(), $!)) unless ($ret); + + my $digest_acl = [ + { + 'perms' => ZOO_PERM_READ, + 'scheme' => 'world', + 'id' => 'anyone' + }, + { + 'perms' => (ZOO_PERM_WRITE | ZOO_PERM_ADMIN), + 'scheme' => 'digest', + 'id' => "$username:$digest" + } + ]; + + $path = $zkh->create($acl_node_path, 'foo', 'acl' => $digest_acl); + is($path, $acl_node_path, + 'create(): created node with digest auth ACL'); + + SKIP: { + skip 'ZooKeeper skipping ACLs', 1 unless (!$skip_acl); + + my $acl_node_path = "$node_path/a2"; + + my $path = $zkh->create($acl_node_path, 'foo', 'acl' => [ + { + 'perms' => ZOO_PERM_WRITE, + 'scheme' => 'foo', + 'id' => 'bar' + } + ]); + ok((!defined($path) and $zkh->get_error() == ZINVALIDACL and $! eq ''), + 'create(): undef when attempting to create node with invalid ACL'); + } + + + ## get_acl() + + my @acl = ('abc'); + @acl = $zkh->get_acl($node_path . '/NONE'); + ok((@acl == 0 and $zkh->get_error() == ZNONODE and $! eq ''), + 'get_acl(): empty list returned for non-extant node'); + + $num_acl_entries = $zkh->get_acl($node_path . '/NONE'); + ok((!defined($num_acl_entries) and $zkh->get_error() == ZNONODE and + $! eq ''), + 'get_acl(): undef returned for non-extant node'); + + @acl = ('abc'); + @acl = $zkh->get_acl($acl_node_path); + is_deeply(\@acl, $digest_acl, + 'get_acl(): retrieved digest ACL'); + + my $stat = $zkh->stat(); + + @acl = ('abc'); + @acl = $zkh->get_acl($node_path, 'stat' => $stat); + is_deeply(\@acl, ZOO_OPEN_ACL_UNSAFE, + 'get_acl(): retrieved ACL'); + + is($stat->{'data_len'}, 3, + 'get_acl(): retrieved ACL with stat handle'); + + SKIP: { + skip 'ZooKeeper not skipping ACLs', 3 unless ($skip_acl > 0); + + my $acl_node_path = "$node_path/a2"; + + my $path = $zkh->create($acl_node_path, 'foo', 'acl' => []); + is($path, $acl_node_path, + 'create(): created node with empty ACL'); + + my @acl = ('abc'); + @acl = $zkh->get_acl($acl_node_path); + ok((@acl == 0 and $zkh->get_error() == ZOK), + 'get_acl(): retrieved empty ACL'); + + my $num_acl_entries = $zkh->get_acl($acl_node_path); + ok((defined($num_acl_entries) and $num_acl_entries == 0), + 'get_acl(): retrieved zero count of ACL entries'); + + my $ret = $zkh->delete($acl_node_path); + diag(sprintf('unable to delete node with empty ACL %s: %d, %s', + $acl_node_path, $zkh->get_error(), $!)) unless ($ret); + } + + + ## set_acl() + + SKIP: { + skip 'ZooKeeper skipping ACLs', 2 unless (!$skip_acl); + + my $ret = $zkh->set_acl($acl_node_path, [ + { + 'perms' => ZOO_PERM_CREATE, + 'scheme' => 'foo', + 'id' => 'bar' + } + ]); + ok((!$ret and $zkh->get_error() == ZINVALIDACL and $! eq ''), + 'set_acl(): invalid ACL'); + + push @{$digest_acl}, { + 'perms' => (ZOO_PERM_CREATE | ZOO_PERM_DELETE), + 'scheme' => 'ip', + 'id' => '0.0.0.0' + }; + + $ret = $zkh->set_acl($acl_node_path, $digest_acl); + ok((!$ret and $zkh->get_error() == ZNOAUTH and $! eq ''), + 'set_acl(): ACL unchanged if no auth'); + } + + + ## add_auth(), set_acl() + + $ret = $zkh->add_auth('digest', ''); + ok($ret, + 'add_auth(): empty digest cert'); + + SKIP: { + skip 'ZooKeeper skipping ACLs', 1 unless (!$skip_acl); + + my $ret = $zkh->set($acl_node_path, 'foo'); + ok((!$ret and $zkh->get_error() == ZNOAUTH and $! eq ''), + 'set(): node value unchanged if no auth'); + } + + $ret = $zkh->add_auth('digest', "$username:$password"); + ok($ret, + 'add_auth(): valid digest cert'); + + SKIP: { + skip 'ZooKeeper skipping ACLs', 13 unless (!$skip_acl); + + my $ret = $zkh->set($acl_node_path, 'baz'); + ok($ret, + 'set(): set node value with auth'); + + my $node = $zkh->get($acl_node_path); + is($node, 'baz', + 'get(): retrieved node value with auth'); + + $ret = $zkh->set_acl($acl_node_path, $digest_acl); + ok($ret, + 'set_acl(): set digest ACL with auth'); + + my $stat = $zkh->stat(); + + my @acl = ('abc'); + @acl = $zkh->get_acl($acl_node_path, 'stat' => $stat); + is_deeply(\@acl, $digest_acl, + 'get_acl(): retrieved digest ACL with auth'); + + is($stat->{'data_len'}, 3, + 'get_acl(): retrieved digest ACL with stat handle and auth'); + + SKIP: { + skip 'invalid node data', 2 unless ($stat->{'version'} == 1); + + my $ret = $zkh->set_acl($acl_node_path, $digest_acl, + 'version' => $stat->{'version'}); + ok($ret, + 'set_acl(): set digest ACL with matching version with auth'); + + $ret = $zkh->set_acl($acl_node_path, $digest_acl, + 'version' => $stat->{'version'}); + ok((!$ret and $zkh->get_error() == ZBADVERSION and $! eq ''), + 'set_acl(): ACL unchanged if non-matching version'); + } + + my $child_node_path = "$acl_node_path/c1"; + + my $path = $zkh->create($child_node_path, 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE); + ok((!defined($path) and $zkh->get_error() == ZNOAUTH and $! eq ''), + 'create(): undef when attempting to create node if no auth'); + + $digest_acl->[1]->{'perms'} |= ZOO_PERM_CREATE; + $digest_acl->[2]->{'perms'} &= ~ZOO_PERM_CREATE; + + $ret = $zkh->set_acl($acl_node_path, $digest_acl); + ok($ret, + 'set_acl(): set changed digest ACL with auth'); + + $path = $zkh->create($child_node_path, 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE); + is($path, $child_node_path, + 'create(): created node with auth'); + + $ret = $zkh->delete($child_node_path); + ok((!$ret and $zkh->get_error() == ZNOAUTH and $! eq ''), + 'delete(): no deletion of node if no auth'); + + $digest_acl->[1]->{'perms'} |= ZOO_PERM_DELETE; + pop @{$digest_acl}; + + $ret = $zkh->set_acl($acl_node_path, $digest_acl); + ok($ret, + 'set_acl(): set reduced digest ACL with auth'); + + $ret = $zkh->delete($child_node_path); + ok($ret, + 'delete(): deleted node with auth'); + } + + + ## cleanup + + $ret = $zkh->delete($acl_node_path); + diag(sprintf('unable to delete node with digest auth ACL %s: %d, %s', + $acl_node_path, $zkh->get_error(), $!)) unless ($ret); + + $ret = $zkh->delete($node_path); + diag(sprintf('unable to delete node %s: %d, %s', + $node_path, $zkh->get_error(), $!)) unless ($ret); +} + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + my $ret = $zkh->exists($root_path) if (defined($zkh)); + + skip 'no connection to ZooKeeper', 1 unless + (defined($ret) and $ret); + + + ## add_auth() + + $ret = $zkh->add_auth('foo', 'bar'); + my $err = $zkh->get_error(); + ok((!$ret and + ($err == ZAUTHFAILED or + $err == ZCONNECTIONLOSS or + $err == ZSESSIONEXPIRED) + and $! eq ''), + 'set_acl(): invalid scheme'); +} + diff --git a/src/contrib/zkperl/t/60_watch.t b/src/contrib/zkperl/t/60_watch.t new file mode 100644 index 00000000000..7d30602d553 --- /dev/null +++ b/src/contrib/zkperl/t/60_watch.t @@ -0,0 +1,304 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +use File::Spec; +use Test::More tests => 30; + +BEGIN { use_ok('Net::ZooKeeper', qw(:all)) }; + + +my $test_dir; +(undef, $test_dir, undef) = File::Spec->splitpath($0); +require File::Spec->catfile($test_dir, 'util.pl'); + +my($hosts, $root_path, $node_path) = zk_test_setup(0); + + +SKIP: { + my $zkh = Net::ZooKeeper->new($hosts); + + my $path = $zkh->create($node_path, 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE) if (defined($zkh)); + + skip 'no connection to ZooKeeper', 20 unless + (defined($path) and $path eq $node_path); + + + ## exists() + + $zkh->{'watch_timeout'} = 100; + + my $watch = $zkh->watch(); + + my $ret = $zkh->exists($node_path, 'watch' => $watch); + ok($ret, + 'exists(): checked node existence with watch handle'); + + $ret = $watch->wait(); + ok(!$ret, + 'wait(): watch after checking node existence timed out'); + + $ret = $zkh->exists($node_path, 'watch' => $watch); + ok($ret, + 'exists(): checked node existence with renewed watch handle'); + + $ret = $watch->wait(); + ok(!$ret, + 'wait(): watch after checking node existence timed out with ' . + 'renewed watch handle'); + + undef $watch; + ok(!defined($watch), + 'undef: released watch handle'); + + my $pending_watches = $zkh->{'pending_watches'}; + is($pending_watches, 2, + '_zk_release_watches(): report pending watches'); + + + ## get_children() + + $watch = $zkh->watch('timeout' => 50); + + my $num_children = $zkh->get_children($node_path, 'watch' => $watch); + ok((defined($num_children) and $num_children == 0), + 'get_children(): retrieved zero count of child nodes with ' . + 'watch handle'); + + $ret = $watch->wait(); + ok(!$ret, + 'wait(): watch after retrieving child nodes timed out with ' . + 'watch handle'); + + $watch->{'timeout'} = 100; + + my @child_paths = $zkh->get_children($node_path, 'watch' => $watch); + ok((@child_paths == 0), + 'get_children(): retrieved empty list of child nodes with ' . + 'renewed watch handle'); + + $ret = $watch->wait(); + ok(!$ret, + 'wait(): watch after retrieving child nodes timed out with ' . + 'renewed watch handle'); + + $pending_watches = $zkh->{'pending_watches'}; + is($pending_watches, 4, + '_zk_release_watches(): report pending watches'); + + + ## get() + + $watch = $zkh->watch(); + + my $node = $zkh->get($node_path, 'watch' => $watch); + is($node, 'foo', + 'get(): retrieved node value with watch handle'); + + $ret = $watch->wait('timeout' => 0); + ok(!$ret, + 'wait(): watch after retrieving node value timed out with ' . + 'watch handle'); + + $node = $zkh->get($node_path, 'watch' => $watch); + is($node, 'foo', + 'get(): retrieved node value with renewed watch handle'); + + $ret = $watch->wait(); + ok(!$ret, + 'wait(): watch after retrieving node value timed out with ' . + 'renewed watch handle'); + + $pending_watches = $zkh->{'pending_watches'}; + is($pending_watches, 6, + '_zk_release_watches(): all watches pending'); + + + ## _zk_release_watches() + + $ret = $zkh->DESTROY(); + ok($ret, + 'DESTROY(): destroyed handle with pending watches'); + + my $event = $watch->{'event'}; + is($event, 0, + '_zk_release_watches(): watch not destroyed when tied to watch handle'); + + $zkh = Net::ZooKeeper->new($hosts); + + SKIP: { + my $ret = $zkh->exists($node_path, 'watch' => $watch); + + skip 'no connection to ZooKeeper', 2 unless + (defined($ret) and $ret); + + ok($ret, + 'exists(): checked node existence with renewed watch handle ' . + 'from prior connection'); + + $ret = $watch->wait(); + ok(!$ret, + 'wait(): watch after checking node existence timed out with ' . + 'renewed watch handle from prior connection'); + + + } +} + +my $pid = fork(); + +SKIP: { + skip 'unable to fork', 4 unless (defined($pid)); + + my $zkh = Net::ZooKeeper->new($hosts); + + my $ret = $zkh->exists($node_path) if (defined($zkh)); + + if ($pid == 0) { + ## child process + + my $code = 0; + + if (defined($ret) and $ret) { + sleep(1); + + my $ret = $zkh->set($node_path, 'foo'); + + diag(sprintf('set(): failed in child process: %d, %s', + $zkh->get_error(), $!)) unless ($ret); + + $code = !$ret; + + sleep(1); + + my $path = $zkh->create("$node_path/c", 'foo', + 'acl' => ZOO_OPEN_ACL_UNSAFE); + + diag(sprintf('create(): failed in child process: %d, %s', + $zkh->get_error(), $!)) unless + (defined($path) and $path eq "$node_path/c"); + + $code &= !$ret; + + sleep(1); + + $ret = $zkh->delete("$node_path/c"); + + diag(sprintf('delete(): failed in child process: %d, %s', + $zkh->get_error(), $!)) unless ($ret); + + $code &= !$ret; + + sleep(1); + + $ret = $zkh->set($node_path, 'foo'); + + diag(sprintf('set(): failed in child process: %d, %s', + $zkh->get_error(), $!)) unless ($ret); + + $code &= !$ret; + } + + exit($code); + } + else { + ## parent process + + SKIP: { + skip 'no connection to ZooKeeper', 9 unless + (defined($ret) and $ret); + + my $watch = $zkh->watch('timeout' => 5000); + + + ## wait() + + my $ret = $zkh->exists($node_path, 'watch' => $watch); + ok($ret, + 'exists(): checked node existence with watch handle ' . + 'in parent'); + + $ret = $watch->wait(); + ok(($ret and $watch->{'event'} == ZOO_CHANGED_EVENT and + $watch->{'state'} == ZOO_CONNECTED_STATE), + 'wait(): waited for event after checking node existence'); + + my $num_children = $zkh->get_children($node_path, + 'watch' => $watch); + ok((defined($num_children) and $num_children == 0), + 'get_children(): retrieved zero count of child nodes with ' . + 'watch handle in parent'); + + $ret = $watch->wait(); + ok(($ret and $watch->{'event'} == ZOO_CHILD_EVENT and + $watch->{'state'} == ZOO_CONNECTED_STATE), + 'wait(): waited for create child event after ' . + 'retrieving child nodes'); + + my @child_paths = $zkh->get_children($node_path, + 'watch' => $watch); + ok((@child_paths == 1 and $child_paths[0] eq 'c'), + 'get_children(): retrieved list of child nodes with ' . + 'watch handle in parent'); + + $ret = $watch->wait(); + ok(($ret and $watch->{'event'} == ZOO_CHILD_EVENT and + $watch->{'state'} == ZOO_CONNECTED_STATE), + 'wait(): waited for delete child event after ' . + 'retrieving child nodes'); + + my $node = $zkh->get($node_path, 'watch' => $watch); + is($node, 'foo', + 'get(): retrieved node value with watch handle in parent'); + + $ret = $watch->wait(); + ok(($ret and $watch->{'event'} == ZOO_CHANGED_EVENT and + $watch->{'state'} == ZOO_CONNECTED_STATE), + 'wait(): waited for event after retrieving node value'); + + undef $watch; + + my $pending_watches = $zkh->{'pending_watches'}; + is($pending_watches, 0, + '_zk_release_watches(): no watches pending'); + } + + my $reap = waitpid($pid, 0); + + diag(sprintf('child process failed: exit %d, signal %d%s', + ($? >> 8), ($? & 127), + (($? & 128) ? ', core dump' : ''))) if + ($reap == $pid and $? != 0); + } +} + + +## cleanup + +{ + my $zkh = Net::ZooKeeper->new($hosts); + + my $ret = $zkh->exists($node_path) if (defined($zkh)); + + if (defined($ret) and $ret) { + $ret = $zkh->delete($node_path); + diag(sprintf('unable to delete node %s: %d, %s', + $node_path, $zkh->get_error(), $!)) unless ($ret); + } +} + diff --git a/src/contrib/zkperl/t/util.pl b/src/contrib/zkperl/t/util.pl new file mode 100644 index 00000000000..1ca738d9999 --- /dev/null +++ b/src/contrib/zkperl/t/util.pl @@ -0,0 +1,62 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +sub zk_test_setup +{ + my $verbose = shift; + + $SIG{'PIPE'} = 'IGNORE'; + + my $hosts = $ENV{'ZK_TEST_HOSTS'}; + unless (defined($hosts) and $hosts =~ /\S/) { + $hosts = 'localhost:0'; + diag('no ZooKeeper hostnames specified in ZK_TEST_HOSTS env var, ' . + "using $hosts") if ($verbose); + } + + my $root_path = $ENV{'ZK_TEST_PATH'}; + if (defined($root_path) and $root_path =~ /^\//) { + $root_path =~ s/\/+/\//g; + $root_path =~ s/\/$//; + } + else { + $root_path = '/'; + diag('no ZooKeeper path specified in ZK_TEST_PATH env var, ' . + 'using root path') if ($verbose); + } + + my $node_path = $root_path . (($root_path =~ /\/$/) ? '' : '/') . + '_net_zookeeper_test'; + + return ($hosts, $root_path, $node_path); +} + +sub zk_acl_test_setup +{ + my $username = '_net_zookeeper_test'; + + my $password = 'test'; + + ## digest is Base64-encoded SHA1 digest of username:password + my $digest = '2qi7Erp2cXYLGcQbXADiwUFaOGo='; + + return ($username, $password, $digest); +} + +1; + diff --git a/src/contrib/zkperl/typemap b/src/contrib/zkperl/typemap new file mode 100644 index 00000000000..84636fdfe3a --- /dev/null +++ b/src/contrib/zkperl/typemap @@ -0,0 +1,38 @@ +# Net::ZooKeeper - Perl extension for Apache ZooKeeper +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +TYPEMAP +Net::ZooKeeper T_ZK_HANDLE +Net::ZooKeeper::Stat T_ZK_HANDLE +Net::ZooKeeper::Watch T_ZK_HANDLE + +INPUT +T_ZK_HANDLE + if (SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVHV && + sv_derived_from($arg, \"${ntype}\")) { + $var = (HV*) SvRV($arg); + } + else { + Perl_croak(aTHX_ + \"$var is not a hash reference of type ${ntype}\"); + } + +OUTPUT +T_ZK_HANDLE + NOT_IMPLEMENTED + diff --git a/src/contrib/zkpython/README b/src/contrib/zkpython/README new file mode 100644 index 00000000000..89d99989756 --- /dev/null +++ b/src/contrib/zkpython/README @@ -0,0 +1,109 @@ +Early version of ZooKeeper bindings for Python. All functions are imported as methods into the zookeeper module. + +Please do not rely on APIs staying constant in the short term. The handling of exceptions and failure modes is one area that is subject to change. + +DEPENDENCIES: +------------- + +This has only been tested against SVN (i.e. 3.2.0 in development) but should work against 3.1.1. + +You will need the Python development headers installed to build the module - on many package-management systems, these can be found in python-devel. + +Python >= 2.6 is required. We have tested against 2.6. We have not tested against 3.x. + +BUILD AND INSTALL: +------------------- + +To install, make sure that the C client has been built and that the libraries are installed in /usr/local/lib (or change this directory in setup.py). Then run: + +ant install + +from zookeeper/src/contrib/zkpython/. + +To test, run ant test from the same directory. + +You can compile the module without installing by running + +ant compile + +In order to use the module, zookeeper.so must be in your PYTHONPATH or in one of the directories referenced by sys.path. Running ant install should make sure that this is the case, but if you only run ant compile you probably need to add build/contrib/zkpython/* to PYTHONPATH to find the module. The C client libraries must be in a system library path, or LD_LIBRARY_PATH or DYLD_LIBRARY_PATH (Mac OS) for the module to work correctly, otherwise you will see a library not found error when trying to import the module. + +NAMING CONVENTIONS: +-------------------- + +All methods that in the C library are zoo_fn_name have been implemented as zookeeper.fn_name. The exception is any function that has a watch function argument is named without the 'w' prefix (for example, zoo_wexists becomes zookeeper.exists). The variants of these functions without the watch argument (i.e. zoo_exists) have not been implemented on the understanding that they are superseded by the zoo_w* API. + +Enums and integer constants that begin ZOO_int_name are named as zookeeper.int_name. + +PARAMETER CHANGES: +------------------ + +Zookeeper handles are represented as integers to avoid marshalling the entire structure for every call. Therefore they are opaque from Python. + +Any parameter that is used to provide arguments to callback methods is not exposed in the API. Python provides better mechanisms for providing a closure to be called in the future. + +Every callback gets passed the handle of the ZooKeeper instance used to register the callback. + +DATA TYPES: +----------- + +ACL_vectors are lists of dictionaries. Stat structures are dictionaries. String_vectors are lists of strings. + +EXCEPTIONS AND ERROR HANDLING: +------------------------------ + +Currently synchronous calls indicate failure by throwing an exception (note that this includes the synchronous calls to set up asynchronous completion callbacks!). Success is returned as an integer. + +Callbacks signify failure by having the integer response code passed in. + +WHAT'S NEW IN 0.4: +------------------ + +More test coverage. + +Better reference counting, fixing at least two serious bugs. + +Out-of-range zhandles are now checked, fixing a potential security hole. + +Docstrings! Editing and cleanup required, but most of the text is there. + +zookeeper.set_watcher is now implemented correctly. + +zookeeper.client_id is now implemented correctly. zookeeper.init now respects the client_id parameter. + +get_context and set_context have been removed from the API. The context mechanism is used by PyZK to store the callables that are dispatched by C-side watchers. Messing with this from Python-side causes bugs very quickly. You should wrap all desired context up in a callable and then use zookeeper.set_watcher to attach it to the global watcher. + +Many methods now have optional parameters (usually if you can specify a watch, it's optional). The only time where genuinely optional parameters are still mandatory is when a required parameters comes after it. Currently we still respect the ZK C client parameter ordering. For example, you can simply connect with zookeeper.init("host:port") and ignore the other three parameters. + + +WHAT'S NEW IN 0.3: +------------------ + +Some tests in zkpython/test. More to follow! + +A variety of bugfixes. + +Changed the way methods return results - all responses are integers now, for the client to convert to a string if it needs. + +WHAT'S NEW IN 0.2: +------------------ + +The asynchronous API is now implemented (see zookeeper.a*). + +Most enums defined in zookeeper.h are now added as constants to the module. + +_set2 and a few other edge API calls have been implemented. The module is now nearly 100% feature complete! + +A reference count error was tracked down and killed. More probably lurk in there! + +WHAT'S NOT DONE / KNOWN ISSUES / FUTURE WORK: +--------------------------------------------- + +1. There may well be more memory leaks / reference count issues; however I am more confident that common paths are relatively safe. +2. There probably needs to be a more Pythonic Python-side wrapper for these functions (e.g. a zookeeper object, the ability to iterate through a tree of zk nodes) +3. Docstrings need a cleanup. +4. The way exceptions and error codes are returned needs looking at. Currently synchronous calls throw exceptions on everything but ZOK return, but asynchronous completions are simply passed the error code. Async. functions should never throw an exception on the C-side as they are practically impossible to catch. For the sync. functions, exceptions seem more reasonable, but some cases are certainly not exceptional. + +Bug reports / comments very welcome! + +Henry Robinson henry@cloudera.com diff --git a/src/contrib/zkpython/build.xml b/src/contrib/zkpython/build.xml new file mode 100644 index 00000000000..d7e76174779 --- /dev/null +++ b/src/contrib/zkpython/build.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zkpython/ivy.xml b/src/contrib/zkpython/ivy.xml new file mode 100644 index 00000000000..d1c045edd79 --- /dev/null +++ b/src/contrib/zkpython/ivy.xml @@ -0,0 +1,43 @@ + + + + + + + + ZKPython + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zkpython/src/c/pyzk_docstrings.h b/src/contrib/zkpython/src/c/pyzk_docstrings.h new file mode 100644 index 00000000000..d2c4d60f6a4 --- /dev/null +++ b/src/contrib/zkpython/src/c/pyzk_docstrings.h @@ -0,0 +1,594 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PYZK_DOCSTRINGS_H +#define PYZK_DOCSTRINGS_H + +const char pyzk_acreate_doc[] = +"Create a node asynchronously.\n" +"\n" +"This method will create a node in ZooKeeper. A node can only be created if\n" +"it does not already exists. The Create Flags affect the creation of nodes.\n" +"If EPHEMERAL flag is set, the node will automatically get removed if the\n" +"client session goes away. If the SEQUENCE flag is set, a unique\n" +"monotonically increasing sequence number is appended to the path name.\n" +"\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: The name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" value: The data to be stored in the node.\n" +" acl: The initial ACL of the node. If None, the ACL of the parent will be\n" +" used.\n" +"\n" +" (Subsequent parameters are optional)\n" +" flags: this parameter can be set to 0 for normal create or an OR\n" +" of the Create Flags\n" +" completion: the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +"OK operation completed successfully\n" +"NONODE the parent node does not exist.\n" +"NODEEXISTS the node already exists\n" +"NOAUTH the client does not have permission.\n" +"NOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.\n" +"\n" +"RETURNS:\n" +"Returns OK on success or throws of the following errcodes on failure:\n" +"EXCEPTIONS:\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" +"MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +static const char pyzk_client_id_doc[] = +"Return the client session id, only valid if the connections\n" +" is currently connected (ie. last watcher state is CONNECTED_STATE)"; + +static const char pyzk_state_doc[] = +"Get the state of the zookeeper connection.\n" + "The return value will be one of the State Consts."; + +static const char pyzk_adelete_doc[] = +" Delete a node in zookeeper.\n" +"\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(Subsequent parameters are optional)\n" +" version: the expected version of the node. The function will fail if the\n" +" actual version of the node does not match the expected version.\n" +" If -1 is used the version check will not take place. \n" +" completion: the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADVERSION expected version does not match actual version.\n" +"NOTEMPTY children are present; node cannot be deleted.\n" +"Returns OK on success or one of the following errcodes on failure:\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +static const char pyzk_aexists_doc[] = +" checks the existence of a node in zookeeper.\n" +"\n" +" zh the zookeeper handle obtained by a call to zookeeper.init\n" +" path the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(Subsequent parameters are optional)\n" +" watch: if not None, a watch will be set at the server to notify the \n" +"client if the node changes. The watch will be set even if the node does not \n" +"exist. This allows clients to watch for nodes to appear.\n" +"\n" +" completion: the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +" OK operation completed successfully\n" +" NONODE the node does not exist.\n" +" NOAUTH the client does not have permission.\n" +" data the data that will be passed to the completion routine when the \n" +"function completes.\n" +" OK on success or one of the following errcodes on failure:\n" +" BADARGUMENTS - invalid input parameters\n" +" INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" +" MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +static const char pyzk_aget_doc[] = +"Gets the data associated with a node.\n" +"\n" +" zh the zookeeper handle obtained by a call to zookeeper.init\n" +" path the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(Subsequent parameters are optional)\n" +" watcher if not None, a watch will be set at the server to notify \n" +"the client if the node changes.\n" +" completion: the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +" OK operation completed successfully\n" +" NONODE the node does not exist.\n" +" NOAUTH the client does not have permission.\n" +" data the data that will be passed to the completion routine when \n" +"the function completes.\n" +"Returns OK on success or one of the following errcodes on failure:\n" +" BADARGUMENTS - invalid input parameters\n" +" INVALIDSTATE - zhandle state is either in SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + " MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +static const char pyzk_aset_doc[] = +" Sets the data associated with a node.\n" +"\n" +" zh the zookeeper handle obtained by a call to zookeeper.init\n" +" path the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" buffer the buffer holding data to be written to the node.\n" +" buflen the number of bytes from buffer to write.\n" +"\n" +"(Subsequent parameters are optional)\n" +" version the expected version of the node. The function will fail if \n" +"the actual version of the node does not match the expected version. If -1 is \n" +"used the version check will not take place.\n" +"completion: If None, \n" +"the function will execute synchronously. Otherwise, the function will return \n" +"immediately and invoke the completion routine when the request completes.\n" +" completion the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADVERSION expected version does not match actual version.\n" +" data the data that will be passed to the completion routine when \n" +"the function completes.\n" +"Returns OK on success or one of the following errcodes on failure:\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" +"MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +static const char pyzk_aget_children_doc[] = +" Lists the children of a node.\n" +"\n" +"This function is similar to zoo_aget_children except it allows one specify \n" +"a watcher object rather than a boolean watch flag.\n" +" \n" +" zh the zookeeper handle obtained by a call to zookeeper.init\n" +" path the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(Subsequent parameters are optional)\n" +" watcher if non-null, a watch will be set at the server to notify \n" +"the client if the node changes.\n" +"\n" +" completion the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"\n" +"Returns OK on success or one of the following errcodes on failure:\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" +"MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +static const char pyzk_async_doc[] = +" Flush leader channel.\n" +"\n" +" zh the zookeeper handle obtained by a call to zookeeper.init\n" +" path the name of the node. Expressed as a file name with slashes\n" +"separating ancestors of the node.\n" +" completion the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"\n" +"Returns OK on success or one of the following errcodes on failure:\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +const static char pyzk_aget_acl_doc[] = +" Gets the acl associated with a node.\n" +"\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(Subsequent parameters are optional)\n" +" completion: the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"\n" +"Returns:\n" +" OK on success or one of the following errcodes on failure:\n" +" BADARGUMENTS - invalid input parameters\n" +" INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" +" MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +const char pyzk_aset_acl_doc[] = +" Sets the acl associated with a node.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" buffer: the buffer holding the acls to be written to the node.\n" +" completion: the routine to invoke when the request completes. The completion\n" +"will be triggered with one of the following codes passed in as the rc argument:\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"INVALIDACL invalid ACL specified\n" +"BADVERSION expected version does not match actual version.\n" +"" +" Returns OK on success or one of the following errcodes on failure:\n" +" BADARGUMENTS - invalid input parameters\n" +" INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" +" MARSHALLINGERROR - failed to marshall a request; possibly, out of memory"; + +const char pyzk_zerror_doc[] = +"Returns an error string corresponding to an integer error code.\n" +"\n" +"PARAMETERS:\n" +" err: Error code\n" +"RETURNS:\n" + " string corresponding to the return code\n"; + +const char pyzk_add_auth_doc[] = +" specify application credentials.\n" +"\n" +"The application calls this function to specify its credentials for purposes\n" +"of authentication. The server will use the security provider specified by \n" +"the scheme parameter to authenticate the client connection. If the \n" +"authentication request has failed:\n" +"- the server connection is dropped\n" +"- the watcher is called with the AUTH_FAILED_STATE value as the state \n" +"parameter.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" scheme the id of authentication scheme. Natively supported:\n" +"'digest' password-based authentication\n" +" cert: application credentials. The actual value depends on the scheme.\n" +" completion: the routine to invoke when the request completes. One of \n" +"the following result codes may be passed into the completion callback:\n" +"OK operation completed successfully\n" +"AUTHFAILED authentication failed \n" +"\n" +"RETURNS:\n" +"OK on success or one of the following errcodes on failure:\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" +"MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n" + "SYSTEMERROR - a system error occured\n"; + +const char pyzk_is_unrecoverable_doc[] = +" checks if the current zookeeper connection state can't be recovered.\n" +"\n" +" The application must close the zhandle and try to reconnect.\n" +"\n" +"PARAMETERS:\n" +" zh the zookeeper handle (see zookeeper.init)\n" +"\n" +"RETURNS:\n" + "True if connection is unrecoverable, otherwise False\n"; + +const char pyzk_set_debug_level_doc[] = +"\brief sets the debugging level for the library \n" +"\n" +"PARAMETERS:\n" +" logLevel: One of LOG_LEVEL_ERROR, LOG_LEVEL_WARN, LOG_LEVEL_INFO or LOG_LEVEL_DEBUG\n" +"\n" +"RETURNS:\n" + " None\n"; + +static const char pyzk_set_log_stream_doc[] = +" sets the stream to be used by the library for logging \n" +"\n" +"The zookeeper library uses stderr as its default log stream. Applications\n" +"must make sure the stream is writable. Passing in NULL resets the stream \n" + "to its default value (stderr).\n" +"\n" +"PARAMETERS:\n" +" logStream: a writable file object\n" +"RETURNS:\n" +" None\n"; + +static const char pyzk_deterministic_conn_order_doc[] = +" enable/disable quorum endpoint order randomization\n" +"\n" +"If passed a non-zero value, will make the client connect to quorum peers\n" +"in the order as specified in the zookeeper.init() call.\n" +"A zero value causes zookeeper.init() to permute the peer endpoints\n" +"which is good for more even client connection distribution among the \n" +"quorum peers.\n" +"PARAMETERS:\n" +" yesOrNo\n" +"\n" +"RETURNS:\n" + " None\n"; + +static const char pyzk_create_doc[] = +" create a node synchronously.\n" +"\n" +"This method will create a node in ZooKeeper. A node can only be created if\n" +"it does not already exists. The Create Flags affect the creation of nodes.\n" +"If the EPHEMERAL flag is set, the node will automatically get removed if the\n" +"client session goes away. If the SEQUENCE flag is set, a unique\n" +"monotonically increasing sequence number is appended to the path name.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: The name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" value: The data to be stored in the node.\n" +" acl: The initial ACL of the node. If null, the ACL of the parent will be\n" +" used.\n" +" flags: this parameter can be set to 0 for normal create or an OR\n" +" of the Create Flags\n" +" realpath: the real path that is created (this might be different than the\n" +" path to create because of the SEQUENCE flag.\n" +" the maximum length of real path you would want.\n" +"\n" +"RETURNS:\n" +" The actual znode path that was created (may be different from path due to use of SEQUENTIAL\n" +" flag).\n" +"EXCEPTIONS:\n" +" NONODE the parent node does not exist.\n" +" NODEEXISTS the node already exists\n" +" NOAUTH the client does not have permission.\n" +" NOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.\n" +" BADARGUMENTS - invalid input parameters\n" +" INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + " MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + +static const char pyzk_delete_doc[] = +" delete a node in zookeeper synchronously.\n" +"\n" +"PARAMETERS:\n" +" zh the zookeeper handle obtained by a call to zookeeper.init\n" +" path the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(Subsequent parameters are optional)\n" +" version: the expected version of the node. The function will fail if the\n" +" actual version of the node does not match the expected version.\n" +" If -1 (the default) is used the version check will not take place. \n" +"\n" +"RETURNS:\n" +"One of the following values is returned.\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADVERSION expected version does not match actual version.\n" +"NOTEMPTY children are present; node cannot be deleted.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + +static const char pyzk_exists_doc[] = +" checks the existence of a node in zookeeper synchronously.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(Subsequent parameters are optional)\n" +" watch: if nonzero, a watch will be set at the server to notify the \n" +"client if the node changes. The watch will be set even if the node does not \n" +"exist. This allows clients to watch for nodes to appear.\n" +"\n" +"RETURNS:\n" +" the return stat value of the node.\n" +"EXCEPTIONS:\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + + +static const char pyzk_get_children_doc[] = +" lists the children of a node synchronously.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(subsequent parameters are optional)\n" +" watcher: if non-null, a watch will be set at the server to notify \n" +"the client if the node changes.\n" +"\n" +"RETURNS:\n" +" A list of znode names\n" +"EXCEPTIONS:\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + +static const char pyzk_set_doc[] = +"\n" +" sets the data associated with a node. See set2 function if\n" +"you require access to the stat information associated with the znode.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" buffer: the buffer holding data to be written to the node.\n" +"\n" +"(subsequent parameters are optional)\n" +" version: the expected version of the node. The function will fail if \n" +"the actual version of the node does not match the expected version. If -1 is \n" +"used the version check will not take place. \n" +"\n" +"RETURNS:\n" +" the return code for the function call.\n" +"OK operation completed successfully\n" +"EXCEPTIONS:\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADVERSION expected version does not match actual version.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + +static const char pyzk_get_acl_doc[] = +" gets the acl associated with a node synchronously.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" acl: the return value of acls on the path.\n" +"RETURNS:" +" returns the stat of the path specified.\n" +"EXCEPTIONS:" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + + +static const char pyzk_set_acl_doc[] = +" sets the acl associated with a node synchronously.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" version: the expected version of the path.\n" +" acl: the acl to be set on the path. \n" +"\n" +"RETURNS:\n" +"OK operation completed successfully\n" +"EXCEPTIONS:\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"INVALIDACL invalid ACL specified\n" +"BADVERSION expected version does not match actual version.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + +static const char pyzk_close_doc[] = +" close the zookeeper handle and free up any resources.\n" +"\n" +"After this call, the client session will no longer be valid. The function\n" +"will flush any outstanding send requests before return. As a result it may \n" +"block.\n" +"\n" +"This method should only be called only once on a zookeeper handle. Calling\n" +"twice will cause undefined (and probably undesirable behavior).\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +"RETURNS:\n" +"Regardless of the error code returned, the zhandle \n" +"will be destroyed and all resources freed. \n" +"OK - success\n" +"EXCEPTIONS:\n" +"BADARGUMENTS - invalid input parameters\n" +"MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n" +"OPERATIONTIMEOUT - failed to flush the buffers within the specified timeout.\n" +"CONNECTIONLOSS - a network error occured while attempting to send request to server\n" + "SYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details\n"; + +static const char pyzk_set2_doc[] = +"\n" +" sets the data associated with a node, and returns the associated stat structure.\n" +"\n" +"PARAMETERS:\n" +" zh: the zookeeper handle obtained by a call to zookeeper.init\n" +" path: the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +" buffer: the buffer holding data to be written to the node.\n" +"\n" +"(subsequent parameters are optional)\n" +" version: the expected version of the node. The function will fail if \n" +"the actual version of the node does not match the expected version. If -1 is \n" +"used the version check will not take place. \n" +"\n" +"RETURNS:\n" +" the stat structure for the target znode\n" +"OK operation completed successfully\n" +"EXCEPTIONS:\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADVERSION expected version does not match actual version.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + +static const char pyzk_init_doc[] = +"This method creates a new handle and a zookeeper session that corresponds\n" +"to that handle. Session establishment is asynchronous, meaning that the\n" +"session should not be considered established until (and unless) an\n" +"event of state CONNECTED_STATE is received.\n" +"PARAMETERS:\n" +" host: comma separated host:port pairs, each corresponding to a zk\n" +" server. e.g. '127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002'\n" +"\n" +"(subsequent parameters are optional)\n" +" fn: the global watcher callback function. When notifications are\n" +" triggered this function will be invoked.\n" +" recv_timeout: \n" +" (clientid, passwd)\n" +" clientid the id of a previously established session that this\n" +" client will be reconnecting to. Clients can access the session id of an established, valid,\n" +" connection by calling zoo_client_id. If\n" +" the specified clientid has expired, or if the clientid is invalid for \n" +" any reason, the returned zhandle_t will be invalid -- the zhandle_t \n" +" state will indicate the reason for failure (typically\n" +" EXPIRED_SESSION_STATE).\n" +"\n" +"RETURNS:\n" +" an integer handle. If it fails to create \n" +" a new zhandle the function throws an exception.\n"; + +static const char pyzk_get_doc[] = +" gets the data associated with a node synchronously.\n" +"\n" +"\n" +"PARAMETERS:\n" +" zh the zookeeper handle obtained by a call to zookeeper.init\n" +" path the name of the node. Expressed as a file name with slashes \n" +"separating ancestors of the node.\n" +"\n" +"(subsequent parameters are optional)\n" +" watcher if not None, a watch will be set at the server to notify \n" +" the client if the node changes.\n" +" bufferlen: This value defaults to 1024*1024 - 1Mb. This method returns \n" +" the minimum of bufferlen and the true length of the znode's data. \n" +"RETURNS:\n" +" the data associated with the node\n" +"OK operation completed successfully\n" +"NONODE the node does not exist.\n" +"NOAUTH the client does not have permission.\n" +"BADARGUMENTS - invalid input parameters\n" +"INVALIDSTATE - zhandle state is either in SESSION_EXPIRED_STATE or AUTH_FAILED_STATE\n" + "MARSHALLINGERROR - failed to marshall a request; possibly, out of memory\n"; + +#endif diff --git a/src/contrib/zkpython/src/c/zookeeper.c b/src/contrib/zkpython/src/c/zookeeper.c new file mode 100644 index 00000000000..0bf6c59c28e --- /dev/null +++ b/src/contrib/zkpython/src/c/zookeeper.c @@ -0,0 +1,1664 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +////////////////////////////////////////////// +// EXCEPTIONS +PyObject *ZooKeeperException = NULL; +PyObject *SystemErrorException; +PyObject *RuntimeInconsistencyException; +PyObject *DataInconsistencyException; +PyObject *ConnectionLossException; +PyObject *MarshallingErrorException; +PyObject *UnimplementedException; +PyObject *OperationTimeoutException; +PyObject *BadArgumentsException; +PyObject *InvalidStateException; + +PyObject *ApiErrorException; +PyObject *NoNodeException; +PyObject *NoAuthException; +PyObject *NodeExistsException; +PyObject *BadVersionException; +PyObject *NoChildrenForEphemeralsException; +PyObject *NotEmptyException; +PyObject *SessionExpiredException; +PyObject *SessionMovedException; +PyObject *InvalidCallbackException; +PyObject *InvalidACLException; +PyObject *AuthFailedException; +PyObject *ClosingException; +PyObject *NothingException; + +PyObject *err_to_exception(int errcode) { + switch (errcode) { + case ZSYSTEMERROR: + return SystemErrorException; + case ZINVALIDSTATE: + return InvalidStateException; + case ZRUNTIMEINCONSISTENCY: + return RuntimeInconsistencyException; + case ZDATAINCONSISTENCY: + return DataInconsistencyException; + case ZCONNECTIONLOSS: + return ConnectionLossException; + case ZMARSHALLINGERROR: + return MarshallingErrorException; + case ZUNIMPLEMENTED: + return UnimplementedException; + case ZOPERATIONTIMEOUT: + return OperationTimeoutException; + case ZBADARGUMENTS: + return BadArgumentsException; + case ZAPIERROR: + return ApiErrorException; + case ZNONODE: + return NoNodeException; + case ZNOAUTH: + return NoAuthException; + case ZBADVERSION: + return BadVersionException; + case ZNOCHILDRENFOREPHEMERALS: + return NoChildrenForEphemeralsException; + case ZNODEEXISTS: + return NodeExistsException; + case ZINVALIDACL: + return InvalidACLException; + case ZAUTHFAILED: + return AuthFailedException; + case ZNOTEMPTY: + return NotEmptyException; + case ZSESSIONEXPIRED: + return SessionExpiredException; + case ZINVALIDCALLBACK: + return InvalidCallbackException; + case ZSESSIONMOVED: + return SessionMovedException; + case ZCLOSING: + return ClosingException; + case ZNOTHING: + return NothingException; + case ZOK: + default: + return NULL; + } +} + + +#define CHECK_ZHANDLE(z) if ( (z) < 0 || (z) >= num_zhandles) { \ + PyErr_SetString( ZooKeeperException, "zhandle out of range" ); \ +return NULL; \ +} else if ( zhandles[(z)] == NULL ) { \ + PyErr_SetString(ZooKeeperException, "zhandle already freed"); \ + return NULL; \ + } + +/* Contains all the state required for a watcher callback - these are + passed to the *dispatch functions as void*, cast to pywatcher_t and + then their callback member is invoked if not NULL */ +typedef struct { + int zhandle; + PyObject *callback; + int permanent; +}pywatcher_t; + +/* This array exists because we need to ref. count the global watchers + for each connection - but they're inaccessible without pulling in + zk_adaptor.h, which I'm trying to avoid. */ +static pywatcher_t **watchers; + +/* We keep an array of zhandles available for use. When a zhandle is + correctly closed, the C client frees the memory so we set the + zhandles[i] entry to NULL. This entry can then be re-used. */ +static zhandle_t** zhandles = NULL; +static int num_zhandles = 0; +static int max_zhandles = 0; +#define REAL_MAX_ZHANDLES 32768 + +/* -------------------------------------------------------------------------- */ +/* zhandles - unique connection ids - tracking */ +/* -------------------------------------------------------------------------- */ + + +/* Allocates an initial zhandle and watcher array */ +int init_zhandles(int num) { + zhandles = malloc(sizeof(zhandle_t*)*num); + watchers = malloc(sizeof(pywatcher_t*)*num); + if (zhandles == NULL || watchers == NULL) { + return 0; + } + max_zhandles = num; + num_zhandles = 0; + memset(zhandles, 0, sizeof(zhandle_t*)*max_zhandles); + return 1; +} + +/* Note that the following zhandle functions are not thread-safe. The + C-Python runtime does not seem to pre-empt a thread that is in a C + module, so there's no need for synchronisation. */ + +/* Doubles the size of the zhandle / watcher array Returns 0 if the + new array would be >= REAL_MAX_ZHANDLES in size. Called when zhandles + is full. Returns 0 if allocation failed or if max num zhandles + exceeded. */ +int resize_zhandles(void) { + zhandle_t **tmp = zhandles; + pywatcher_t ** wtmp = watchers; + if (max_zhandles >= REAL_MAX_ZHANDLES >> 1) { + return 0; + } + max_zhandles *= 2; + zhandles = malloc(sizeof(zhandle_t*)*max_zhandles); + if (zhandles == NULL) { + PyErr_SetString(PyExc_MemoryError, "malloc for new zhandles failed"); + return 0; + } + memset(zhandles, 0, sizeof(zhandle_t*)*max_zhandles); + memcpy(zhandles, tmp, sizeof(zhandle_t*)*max_zhandles/2); + + watchers = malloc(sizeof(pywatcher_t*)*max_zhandles); + if (watchers == NULL) { + PyErr_SetString(PyExc_MemoryError, "malloc for new watchers failed"); + return 0; + } + memset(watchers, 0, sizeof(pywatcher_t*)*max_zhandles); + memcpy(watchers, wtmp, sizeof(pywatcher_t*)*max_zhandles/2); + + free(wtmp); + free(tmp); + return 1; +} + +/* Find a free zhandle - this iterates through the list of open + zhandles, but we expect it to be infrequently called. There are + optimisations that can be made if this turns out to be problematic. + Returns -1 if no free handle is found - resize_handles() can be + called in that case. */ +unsigned int next_zhandle(void) { + int i = 0; + for (i=0;izhandle = zh; ret->callback = cb; ret->permanent = permanent; + return ret; +} + +/* Releases the reference taken in create_pywatcher to the callback, + then frees the allocated pywatcher_t* */ +void free_pywatcher(pywatcher_t *pw) +{ + if (pw == NULL) { + return; + } + Py_DECREF(pw->callback); + + free(pw); +} + +/* Constructs a new stat object. Returns Py_None if stat == NULL or a + dictionary containing all the stat information otherwise. In either + case, takes a reference to the returned object. */ +PyObject *build_stat( const struct Stat *stat ) +{ + if (stat == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + return Py_BuildValue( "{s:K, s:K, s:K, s:K," + "s:i, s:i, s:i, s:K," + "s:i, s:i, s:K}", + "czxid", stat->czxid, + "mzxid", stat->mzxid, + "ctime", stat->ctime, + "mtime", stat->mtime, + "version", stat->version, + "cversion", stat->cversion, + "aversion", stat->aversion, + "ephemeralOwner", stat->ephemeralOwner, + "dataLength", stat->dataLength, + "numChildren", stat->numChildren, + "pzxid", stat->pzxid ); +} + +/* Creates a new list of strings from a String_vector. Returns the + empty list if the String_vector is NULL. Takes a reference to the + returned PyObject and gives that reference to the caller. */ +PyObject *build_string_vector(const struct String_vector *sv) +{ + PyObject *ret; + if (!sv) { + return PyList_New(0); + } + + ret = PyList_New(sv->count); + if (ret) { + int i; + for (i=0;icount;++i) { +#if PY_MAJOR_VERSION >= 3 + PyObject *s = PyUnicode_FromString(sv->data[i]); +#else + PyObject *s = PyString_FromString(sv->data[i]); +#endif + if (!s) { + if (ret != Py_None) { + Py_DECREF(ret); + } + ret = NULL; + break; + } + PyList_SetItem(ret, i, s); + } + } + return ret; +} + +/* Returns 1 if the PyObject is a valid representation of an ACL, and + 0 otherwise. */ +int check_is_acl(PyObject *o) { + int i; + PyObject *entry; + if (o == NULL) { + return 0; + } + if (!PyList_Check(o)) { + return 0; + } + for (i=0;icount); + int i; + for (i=0;icount;++i) { + PyObject *acl = Py_BuildValue( "{s:i, s:s, s:s}", + "perms", acls->data[i].perms, + "scheme", acls->data[i].id.scheme, + "id", acls->data[i].id.id ); + PyList_SetItem(ret, i, acl); + } + return ret; +} + +/* Parse the Python representation of an ACL list into an ACL_vector + (which needs subsequent freeing) */ +int parse_acls(struct ACL_vector *acls, PyObject *pyacls) +{ + PyObject *a; + int i; + if (acls == NULL || pyacls == NULL) { + PyErr_SetString(PyExc_ValueError, "acls or pyacls NULL in parse_acls"); + return 0; + } + + acls->count = PyList_Size( pyacls ); + + // Is this a list? If not, we can't do anything + if (PyList_Check(pyacls) == 0) { + PyErr_SetString(InvalidACLException, "List of ACLs required in parse_acls"); + return 0; + } + + acls->data = (struct ACL *)calloc(acls->count, sizeof(struct ACL)); + if (acls->data == NULL) { + PyErr_SetString(PyExc_MemoryError, "calloc failed in parse_acls"); + return 0; + } + + for (i=0;icount;++i) { + a = PyList_GetItem(pyacls, i); + // a is now a dictionary + PyObject *perms = PyDict_GetItemString( a, "perms" ); +#if PY_MAJOR_VERSION >= 3 + acls->data[i].perms = (int32_t)(PyLong_AsLong(perms)); + acls->data[i].id.id = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "id" ) ) ); + acls->data[i].id.scheme = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "scheme" ) ) ); +#else + acls->data[i].perms = (int32_t)(PyInt_AsLong(perms)); + acls->data[i].id.id = strdup( PyString_AsString( PyDict_GetItemString( a, "id" ) ) ); + acls->data[i].id.scheme = strdup( PyString_AsString( PyDict_GetItemString( a, "scheme" ) ) ); +#endif + } + return 1; +} + +/* Deallocates the memory allocated inside an ACL_vector, but not the + ACL_vector itself */ +void free_acls( struct ACL_vector *acls ) +{ + if (acls == NULL) { + return; + } + int i; + for (i=0;icount;++i) { + free(acls->data[i].id.id); + free(acls->data[i].id.scheme); + } + free(acls->data); +} + +/* -------------------------------------------------------------------------- */ +/* Watcher and callback implementation */ +/* -------------------------------------------------------------------------- */ + +/* Every watcher invocation goes through this dispatch point, which + a) acquires the global interpreter lock + + b) unpacks the PyObject to call from the passed context pointer, + which handily includes the index of the relevant zookeeper handle + to pass back to Python. + + c) Makes the call into Python, checking for error conditions which + we are responsible for detecting and doing something about (we just + print the error and plough right on) + + d) releases the lock after freeing up the context object, which is + only used for one watch invocation (watches are one-shot, unless + 'permanent' != 0) +*/ +void watcher_dispatch(zhandle_t *zzh, int type, int state, + const char *path, void *context) +{ + PyGILState_STATE gstate; + pywatcher_t *pyw = (pywatcher_t*)context; + PyObject *callback = pyw->callback; + if (callback == NULL) { + // This is unexpected + char msg[256]; + sprintf(msg, "pywatcher: %d %p %d", pyw->zhandle, pyw->callback, pyw->permanent); + PyErr_SetString(PyExc_ValueError, msg); + return; + } + + gstate = PyGILState_Ensure(); + PyObject *arglist = Py_BuildValue("(i,i,i,s)", pyw->zhandle,type, state, path); + if (PyObject_CallObject((PyObject*)callback, arglist) == NULL) { + PyErr_Print(); + } + Py_DECREF(arglist); + if (pyw->permanent == 0 && (type != ZOO_SESSION_EVENT || state < 0)) { + free_pywatcher(pyw); + } + PyGILState_Release(gstate); +} + +/* The completion callbacks (from asynchronous calls) are implemented similarly */ + +/* Called when an asynchronous call that returns void completes and + dispatches user provided callback */ +void void_completion_dispatch(int rc, const void *data) +{ + PyGILState_STATE gstate; + pywatcher_t *pyw = (pywatcher_t*)data; + if (pyw == NULL) + return; + PyObject *callback = pyw->callback; + gstate = PyGILState_Ensure(); + PyObject *arglist = Py_BuildValue("(i,i)", pyw->zhandle, rc); + if (PyObject_CallObject((PyObject*)callback, arglist) == NULL) + PyErr_Print(); + Py_DECREF(arglist); + free_pywatcher(pyw); + PyGILState_Release(gstate); +} + +/* Called when an asynchronous call that returns a stat structure + completes and dispatches user provided callback */ +void stat_completion_dispatch(int rc, const struct Stat *stat, const void *data) +{ + PyGILState_STATE gstate; + pywatcher_t *pyw = (pywatcher_t*)data; + if (pyw == NULL) + return; + PyObject *callback = pyw->callback; + gstate = PyGILState_Ensure(); + PyObject *pystat = build_stat(stat); + PyObject *arglist = Py_BuildValue("(i,i,O)", pyw->zhandle,rc, pystat); + Py_DECREF(pystat); + if (PyObject_CallObject((PyObject*)callback, arglist) == NULL) + PyErr_Print(); + Py_DECREF(arglist); + free_pywatcher(pyw); + PyGILState_Release(gstate); +} + +/* Called when an asynchronous call that returns a stat structure and + some untyped data completes and dispatches user provided + callback (used by aget) */ +void data_completion_dispatch(int rc, const char *value, int value_len, const struct Stat *stat, const void *data) +{ + PyGILState_STATE gstate; + pywatcher_t *pyw = (pywatcher_t*)data; + if (pyw == NULL) + return; + PyObject *callback = pyw->callback; + gstate = PyGILState_Ensure(); + PyObject *pystat = build_stat(stat); + PyObject *arglist = Py_BuildValue("(i,i,s#,O)", pyw->zhandle,rc, value,value_len, pystat); + Py_DECREF(pystat); + + if (PyObject_CallObject((PyObject*)callback, arglist) == NULL) + PyErr_Print(); + Py_DECREF(arglist); + free_pywatcher(pyw); + PyGILState_Release(gstate); +} + +/* Called when an asynchronous call that returns a list of strings + completes and dispatches user provided callback */ +void strings_completion_dispatch(int rc, const struct String_vector *strings, const void *data) +{ + PyGILState_STATE gstate; + pywatcher_t *pyw = (pywatcher_t*)data; + if (pyw == NULL) + return; + PyObject *callback = pyw->callback; + gstate = PyGILState_Ensure(); + PyObject *pystrings = build_string_vector(strings); + if (pystrings) + { + PyObject *arglist = Py_BuildValue("(i,i,O)", pyw->zhandle, rc, pystrings); + if (arglist == NULL || PyObject_CallObject((PyObject*)callback, arglist) == NULL) + PyErr_Print(); + Py_DECREF(arglist); + } + else + PyErr_Print(); + Py_DECREF(pystrings); + free_pywatcher(pyw); + PyGILState_Release(gstate); +} + +/* Called when an asynchronous call that returns a single string + completes and dispatches user provided callback */ +void string_completion_dispatch(int rc, const char *value, const void *data) +{ + PyGILState_STATE gstate; + pywatcher_t *pyw = (pywatcher_t*)data; + if (pyw == NULL) { + return; + } + PyObject *callback = pyw->callback; + gstate = PyGILState_Ensure(); + PyObject *arglist = Py_BuildValue("(i,i,s)", pyw->zhandle,rc, value); + if (PyObject_CallObject((PyObject*)callback, arglist) == NULL) + PyErr_Print(); + Py_DECREF(arglist); + free_pywatcher(pyw); + PyGILState_Release(gstate); +} + +/* Called when an asynchronous call that returns a list of ACLs + completes and dispatches user provided callback */ +void acl_completion_dispatch(int rc, struct ACL_vector *acl, struct Stat *stat, const void *data) +{ + PyGILState_STATE gstate; + pywatcher_t *pyw = (pywatcher_t*)data; + if (pyw == NULL) { + return; + } + PyObject *callback = pyw->callback; + gstate = PyGILState_Ensure(); + PyObject *pystat = build_stat(stat); + PyObject *pyacls = build_acls(acl); + PyObject *arglist = Py_BuildValue("(i,i,O,O)", pyw->zhandle,rc, pyacls, pystat); + + Py_DECREF(pystat); + Py_DECREF(pyacls); + + if (PyObject_CallObject((PyObject*)callback, arglist) == NULL) { + PyErr_Print(); + } + Py_DECREF(arglist); + free_pywatcher(pyw); + PyGILState_Release(gstate); +} + +/* -------------------------------------------------------------------------- */ +/* ZOOKEEPER API IMPLEMENTATION */ +/* -------------------------------------------------------------------------- */ + +static PyObject *pyzookeeper_init(PyObject *self, PyObject *args) +{ + const char *host; + PyObject *watcherfn = Py_None; + int recv_timeout = 10000; + // int clientid = -1; + clientid_t cid; + cid.client_id = -1; + const char *passwd; + int handle = next_zhandle(); + if (handle == -1) { + if (resize_zhandles() == 0) { + return NULL; + } + handle = next_zhandle(); + } + + if (handle == -1) { + PyErr_SetString(ZooKeeperException,"Couldn't find a free zhandle, something is very wrong"); + return NULL; + } + + if (!PyArg_ParseTuple(args, "s|Oi(Ls)", &host, &watcherfn, &recv_timeout, &cid.client_id, &passwd)) + return NULL; + + if (cid.client_id != -1) { + strncpy(cid.passwd, passwd, 16*sizeof(char)); + } + pywatcher_t *pyw = NULL; + if (watcherfn != Py_None) { + pyw = create_pywatcher(handle, watcherfn,1); + if (pyw == NULL) { + return NULL; + } + } + watchers[handle] = pyw; + zhandle_t *zh = zookeeper_init( host, watcherfn != Py_None ? watcher_dispatch : NULL, + recv_timeout, cid.client_id == -1 ? 0 : &cid, + pyw, + 0 ); + + if (zh == NULL) + { + PyErr_SetString( ZooKeeperException, "Could not internally obtain zookeeper handle" ); + return NULL; + } + + zhandles[handle] = zh; + return Py_BuildValue( "i", handle); +} + + +/* -------------------------------------------------------------------------- */ +/* Asynchronous API implementation */ +/* -------------------------------------------------------------------------- */ + +/* Asynchronous node creation, returns integer error code */ +PyObject *pyzoo_acreate(PyObject *self, PyObject *args) +{ + int zkhid; char *path; char *value; int valuelen; + struct ACL_vector acl; int flags = 0; + PyObject *completion_callback = Py_None; + PyObject *pyacls = Py_None; + if (!PyArg_ParseTuple(args, "iss#O|iO", &zkhid, &path, + &value, &valuelen, &pyacls, &flags, + &completion_callback)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + CHECK_ACLS(pyacls); + if (parse_acls(&acl, pyacls) == 0) { + return NULL; + } + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + int err = zoo_acreate( zhandles[zkhid], + path, + value, + valuelen, + pyacls == Py_None ? NULL : &acl, + flags, + string_completion_dispatch, + pyw); + free_acls(&acl); + if (err != ZOK) + { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err); +} + +/* Asynchronous node deletion, returns integer error code */ +PyObject *pyzoo_adelete(PyObject *self, PyObject *args) +{ + int zkhid; char *path; int version = -1; + PyObject *completion_callback = Py_None; + if (!PyArg_ParseTuple(args, "is|iO", &zkhid, &path, &version, &completion_callback)) + return NULL; + CHECK_ZHANDLE(zkhid); + + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + + int err = zoo_adelete( zhandles[zkhid], + path, + version, + void_completion_dispatch, + pyw); + + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err); +} + +/* Asynchronous node existance check, returns integer error code */ +PyObject *pyzoo_aexists(PyObject *self, PyObject *args) +{ + int zkhid; char *path; + PyObject *completion_callback = Py_None; + PyObject *exists_watch = Py_None; + if (!PyArg_ParseTuple(args, "is|OO", &zkhid, &path, + &exists_watch, &completion_callback)) + return NULL; + CHECK_ZHANDLE(zkhid); + void *comp_pyw = NULL; + if (completion_callback != Py_None) { + comp_pyw = create_pywatcher(zkhid, completion_callback, 0); + if (comp_pyw == NULL) { + return NULL; + } + } + void *exist_pyw = NULL; + if (exists_watch != Py_None) { + exist_pyw = create_pywatcher(zkhid, exists_watch, 0); + if (exist_pyw == NULL) { + return NULL; + } + } + + int err = zoo_awexists( zhandles[zkhid], + path, + exists_watch != Py_None ? watcher_dispatch : NULL, + exist_pyw, + stat_completion_dispatch, + comp_pyw); + + if (err != ZOK) + { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err);; +} + +/* Asynchronous node data retrieval, returns integer error code */ +PyObject *pyzoo_aget(PyObject *self, PyObject *args) +{ + int zkhid; char *path; + PyObject *completion_callback = Py_None; + PyObject *get_watch = Py_None; + void *comp_pw = NULL; + void *watch_pw = NULL; + + if (!PyArg_ParseTuple(args, "is|OO", &zkhid, &path, + &get_watch, &completion_callback)) { + return NULL; + } + + CHECK_ZHANDLE(zkhid); + + if (get_watch != Py_None) { + if ((watch_pw = create_pywatcher(zkhid, get_watch, 0)) == NULL) { + return NULL; + } + } + + if (completion_callback != Py_None) { + if ((comp_pw = create_pywatcher(zkhid, completion_callback, 0)) == NULL) { + return NULL; + } + } + + int err = zoo_awget( zhandles[zkhid], + path, + get_watch != Py_None ? watcher_dispatch : NULL, + watch_pw, + data_completion_dispatch, + comp_pw); + + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err); +} + +/* Asynchronous node contents update, returns integer error code */ +PyObject *pyzoo_aset(PyObject *self, PyObject *args) +{ + int zkhid; char *path; char *buffer; int buflen; int version=-1; + PyObject *completion_callback = Py_None; + if (!PyArg_ParseTuple(args, "iss#|iO", &zkhid, &path, &buffer, &buflen, &version, &completion_callback)) + return NULL; + CHECK_ZHANDLE(zkhid); + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + int err = zoo_aset( zhandles[zkhid], + path, + buffer, + buflen, + version, + stat_completion_dispatch, + pyw); + + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err); +} + +/* Asynchronous node child retrieval, returns integer error code */ +PyObject *pyzoo_aget_children(PyObject *self, PyObject *args) +{ + int zkhid; char *path; + PyObject *completion_callback = Py_None; + PyObject *get_watch; + if (!PyArg_ParseTuple(args, "is|OO", &zkhid, &path, + &get_watch, &completion_callback)) + return NULL; + CHECK_ZHANDLE(zkhid); + + void *get_pyw = NULL; + if (get_watch != Py_None) { + get_pyw = create_pywatcher(zkhid, get_watch, 0); + if (get_pyw == NULL) { + return NULL; + } + } + + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + + int err = zoo_awget_children( zhandles[zkhid], + path, + get_watch != Py_None ? watcher_dispatch : NULL, + get_pyw, + strings_completion_dispatch, + pyw); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err);; +} + +/* Asynchronous sync, returns integer error code */ +PyObject *pyzoo_async(PyObject *self, PyObject *args) +{ + int zkhid; char *path; + PyObject *completion_callback = Py_None; + if (!PyArg_ParseTuple(args, "is|O", &zkhid, &path, + &completion_callback)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + + int err = zoo_async( zhandles[zkhid], + path, + string_completion_dispatch, + pyw); + + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err);; +} + +/* Asynchronous node ACL retrieval, returns integer error code */ +PyObject *pyzoo_aget_acl(PyObject *self, PyObject *args) +{ + int zkhid; char *path; + PyObject *completion_callback = Py_None; + if (!PyArg_ParseTuple(args, "is|O", &zkhid, &path, + &completion_callback)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + + int err = zoo_aget_acl( zhandles[zkhid], + path, + acl_completion_dispatch, + pyw); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err);; +} + +/* Asynchronous node ACL update, returns integer error code */ +PyObject *pyzoo_aset_acl(PyObject *self, PyObject *args) +{ + int zkhid; char *path; int version; + PyObject *completion_callback = Py_None, *pyacl; + struct ACL_vector aclv; + if (!PyArg_ParseTuple(args, "isiO|O", &zkhid, &path, &version, + &pyacl, &completion_callback)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + CHECK_ACLS(pyacl); + if (parse_acls(&aclv, pyacl) == 0) { + return NULL; + } + + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + + int err = zoo_aset_acl( zhandles[zkhid], + path, + version, + &aclv, + void_completion_dispatch, + pyw); + free_acls(&aclv); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err);; +} + +/* Asynchronous authorization addition, returns integer error code */ +PyObject *pyzoo_add_auth(PyObject *self, PyObject *args) +{ + int zkhid; + char *scheme, *cert; + int certLen; + PyObject *completion_callback; + + if (!PyArg_ParseTuple(args, "iss#O", &zkhid, &scheme, &cert, &certLen, + &completion_callback)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + + void *pyw = NULL; + if (completion_callback != Py_None) { + pyw = create_pywatcher(zkhid, completion_callback, 0); + if (pyw == NULL) { + return NULL; + } + } + + int err = zoo_add_auth( zhandles[zkhid], + scheme, + cert, + certLen, + void_completion_dispatch, + pyw); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err); +} + +/* -------------------------------------------------------------------------- */ +/* Synchronous API implementation */ +/* -------------------------------------------------------------------------- */ + +/* Synchronous node creation, returns node path string */ +static PyObject *pyzoo_create(PyObject *self, PyObject *args) +{ + char *path; + int zkhid; + char* values; + int valuelen; + PyObject *acl = NULL; + int flags = 0; + char realbuf[256]; + const int maxbuf_len = 256; + if (!PyArg_ParseTuple(args, "iss#O|i",&zkhid, &path, &values, &valuelen,&acl,&flags)) + return NULL; + CHECK_ZHANDLE(zkhid); + struct ACL_vector aclv; + CHECK_ACLS(acl); + if (parse_acls(&aclv,acl) == 0) { + return NULL; + } + zhandle_t *zh = zhandles[zkhid]; + int err = zoo_create(zh, path, values, valuelen, &aclv, flags, realbuf, maxbuf_len); + free_acls(&aclv); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + + return Py_BuildValue("s", realbuf); +} + +/* Synchronous node deletion, returns integer error code */ +static PyObject *pyzoo_delete(PyObject *self, PyObject *args) +{ + int zkhid; + char *path; + int version = -1; + if (!PyArg_ParseTuple(args, "is|i",&zkhid,&path,&version)) + return NULL; + CHECK_ZHANDLE(zkhid); + zhandle_t *zh = zhandles[zkhid]; + int err = zoo_delete(zh, path, version); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err); +} + +/* Synchronous node existance check, returns stat if exists, None if + absent */ +static PyObject *pyzoo_exists(PyObject *self, PyObject *args) +{ + int zkhid; char *path; PyObject *watcherfn = Py_None; + struct Stat stat; + if (!PyArg_ParseTuple(args, "is|O", &zkhid, &path, &watcherfn)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + zhandle_t *zh = zhandles[zkhid]; + pywatcher_t *pw = NULL; + void *callback = NULL; + if (watcherfn != Py_None) { + pw = create_pywatcher(zkhid, watcherfn,0); + callback = watcher_dispatch; + if (pw == NULL) { + return NULL; + } + } + int err = zoo_wexists(zh, path, callback, pw, &stat); + if (err != ZOK && err != ZNONODE) { + PyErr_SetString(err_to_exception(err), zerror(err)); + free_pywatcher(pw); + return NULL; + } + if (err == ZNONODE) { + Py_INCREF(Py_None); + return Py_None; // This isn't exceptional + } + return build_stat(&stat); +} + +/* Synchronous node child retrieval, returns list of children's path + as strings */ +static PyObject *pyzoo_get_children(PyObject *self, PyObject *args) +{ + int zkhid; + char *path; + PyObject *watcherfn = Py_None; + struct String_vector strings; + if (!PyArg_ParseTuple(args, "is|O", &zkhid, &path, &watcherfn)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + pywatcher_t *pw = NULL; + void *callback = NULL; + if (watcherfn != Py_None) { + pw = create_pywatcher( zkhid, watcherfn, 0 ); + callback = watcher_dispatch; + if (pw == NULL) { + return NULL; + } + } + int err = zoo_wget_children(zhandles[zkhid], path, + callback, + pw, &strings ); + + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + free_pywatcher(pw); + return NULL; + } + + PyObject *ret = build_string_vector(&strings); + deallocate_String_vector(&strings); + return ret; +} + +/* Synchronous node data update, returns integer error code */ +static PyObject *pyzoo_set(PyObject *self, PyObject *args) +{ + int zkhid; + char *path; + char *buffer; + int buflen; + int version = -1; + if (!PyArg_ParseTuple(args, "iss#|i", &zkhid, &path, &buffer, &buflen, + &version)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + + int err = zoo_set(zhandles[zkhid], path, buffer, buflen, version); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + + return Py_BuildValue("i", err); +} + +/* Synchronous node data update, returns node's stat data structure */ +static PyObject *pyzoo_set2(PyObject *self, PyObject *args) +{ + int zkhid; + char *path; + char *buffer; + int buflen; + int version = -1; + if (!PyArg_ParseTuple(args, "iss#|i", &zkhid, &path, &buffer, &buflen, + &version)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + struct Stat stat; + int err = zoo_set2(zhandles[zkhid], path, buffer, buflen, version, &stat); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + + return build_stat(&stat); +} + +/* As per ZK documentation, datanodes are limited to 1Mb. Why not do a + stat followed by a get, to determine how big the buffer should be? + Because the znode may get updated between calls, so we can't + guarantee a complete get anyhow. */ +#define GET_BUFFER_SIZE 1024*1024 + +/* pyzoo_get has an extra parameter over the java/C equivalents. If + you set the fourth integer parameter buffer_len, we return + min(buffer_len, datalength) bytes. This is set by default to + GET_BUFFER_SIZE */ +static PyObject *pyzoo_get(PyObject *self, PyObject *args) +{ + int zkhid; + char *path; + char *buffer; + int buffer_len=GET_BUFFER_SIZE; + struct Stat stat; + PyObject *watcherfn = Py_None; + pywatcher_t *pw = NULL; + if (!PyArg_ParseTuple(args, "is|Oi", &zkhid, &path, &watcherfn, &buffer_len)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + if (watcherfn != Py_None) { + pw = create_pywatcher( zkhid, watcherfn,0 ); + if (pw == NULL) { + return NULL; + } + } + buffer = malloc(sizeof(char)*buffer_len); + if (buffer == NULL) { + free_pywatcher(pw); + PyErr_SetString(PyExc_MemoryError, "buffer could not be allocated in pyzoo_get"); + return NULL; + } + + int err = zoo_wget(zhandles[zkhid], path, + watcherfn != Py_None ? watcher_dispatch : NULL, + pw, buffer, + &buffer_len, &stat); + + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + free_pywatcher(pw); + free(buffer); + return NULL; + } + + PyObject *stat_dict = build_stat( &stat ); + PyObject *ret = Py_BuildValue( "(s#,N)", buffer,buffer_len < 0 ? 0 : buffer_len, stat_dict ); + free(buffer); + + return ret; +} + +/* Synchronous node ACL retrieval, returns list of ACLs */ +PyObject *pyzoo_get_acl(PyObject *self, PyObject *args) +{ + int zkhid; + char *path; + struct ACL_vector acl; + struct Stat stat; + if (!PyArg_ParseTuple(args, "is", &zkhid, &path)) + return NULL; + CHECK_ZHANDLE(zkhid); + int err = zoo_get_acl( zhandles[zkhid], path, &acl, &stat ); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + PyObject *pystat = build_stat( &stat ); + PyObject *acls = build_acls( &acl ); + PyObject *ret = Py_BuildValue( "(O,O)", pystat, acls ); + Py_DECREF(pystat); + Py_DECREF(acls); + return ret; +} + +/* Synchronous node ACL update, returns integer error code */ +PyObject *pyzoo_set_acl(PyObject *self, PyObject *args) +{ + int zkhid; + char *path; + int version; + PyObject *pyacls; + struct ACL_vector acl; + if (!PyArg_ParseTuple(args, "isiO", &zkhid, &path, &version, &pyacls)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + if (parse_acls(&acl, pyacls) == 0) { + return NULL; + } + int err = zoo_set_acl(zhandles[zkhid], path, version, &acl ); + free_acls(&acl); + if (err != ZOK) { + PyErr_SetString(err_to_exception(err), zerror(err)); + return NULL; + } + return Py_BuildValue("i", err);; +} + +/* -------------------------------------------------------------------------- */ +/* Session and context methods */ +/* -------------------------------------------------------------------------- */ + +/* Closes a connection, returns integer error code */ +PyObject *pyzoo_close(PyObject *self, PyObject *args) +{ + int zkhid, ret; + if (!PyArg_ParseTuple(args, "i", &zkhid)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + zhandle_t *handle = zhandles[zkhid]; + Py_BEGIN_ALLOW_THREADS + ret = zookeeper_close(handle); + Py_END_ALLOW_THREADS + zhandles[zkhid] = NULL; // The zk C client frees the zhandle + return Py_BuildValue("i", ret); +} + +/* Returns the ID of current client as a tuple (client_id, passwd) */ +PyObject *pyzoo_client_id(PyObject *self, PyObject *args) +{ + int zkhid; + if (!PyArg_ParseTuple(args, "i", &zkhid)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + const clientid_t *cid = zoo_client_id(zhandles[zkhid]); + return Py_BuildValue("(L,s)", cid->client_id, cid->passwd); +} + +/* DO NOT USE - context is used internally. This method is not exposed + in the Python module */ +PyObject *pyzoo_get_context(PyObject *self, PyObject *args) +{ + int zkhid; + if (!PyArg_ParseTuple(args, "i", &zkhid)) + return NULL; + CHECK_ZHANDLE(zkhid); + PyObject *context = NULL; + context = (PyObject*)zoo_get_context(zhandles[zkhid]); + if (context) return context; + Py_INCREF(Py_None); + return Py_None; +} + +/* DO NOT USE - context is used internally. This method is not exposed + in the Python module */ +PyObject *pyzoo_set_context(PyObject *self, PyObject *args) +{ + int zkhid; + PyObject *context; + if (!PyArg_ParseTuple(args, "iO", &zkhid, &context)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + PyObject *py_context = (PyObject*)zoo_get_context(zhandles[zkhid]); + if (py_context != NULL && py_context != Py_None) { + Py_DECREF(py_context); + } + Py_INCREF(context); + zoo_set_context(zhandles[zkhid], (void*)context); + Py_INCREF(Py_None); + return Py_None; +} + + +/* -------------------------------------------------------------------------- */ +/* Miscellaneous methods */ +/* -------------------------------------------------------------------------- */ + +/* Sets the global watcher. Returns None */ +PyObject *pyzoo_set_watcher(PyObject *self, PyObject *args) +{ + int zkhid; + PyObject *watcherfn; + if (!PyArg_ParseTuple(args, "iO", &zkhid, &watcherfn)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + pywatcher_t *pyw = watchers[zkhid]; + if (pyw != NULL) { + free_pywatcher( pyw ); + } + + // Create a *permanent* watcher object, not deallocated when called + pyw = create_pywatcher(zkhid, watcherfn,1); + if (pyw == NULL) { + return NULL; + } + watchers[zkhid] = pyw; + zoo_set_watcher(zhandles[zkhid], watcher_dispatch); + zoo_set_context(zhandles[zkhid], pyw); + Py_INCREF(Py_None); + return Py_None; +} + +/* Returns an integer code representing the current connection + state */ +PyObject *pyzoo_state(PyObject *self, PyObject *args) +{ + int zkhid; + if (!PyArg_ParseTuple(args,"i",&zkhid)) { + return NULL; + } + CHECK_ZHANDLE(zkhid); + int state = zoo_state(zhandles[zkhid]); + return Py_BuildValue("i",state); +} + + +/* Convert an integer error code into a string */ +PyObject *pyzerror(PyObject *self, PyObject *args) +{ + int rc; + if (!PyArg_ParseTuple(args,"i", &rc)) + return NULL; + return Py_BuildValue("s", zerror(rc)); +} + +/* Returns the integer receive timeout for a connection */ +PyObject *pyzoo_recv_timeout(PyObject *self, PyObject *args) +{ + int zkhid; + if (!PyArg_ParseTuple(args,"i",&zkhid)) + return NULL; + CHECK_ZHANDLE(zkhid); + int recv_timeout = zoo_recv_timeout(zhandles[zkhid]); + return Py_BuildValue("i",recv_timeout); +} + +/* Returns True if connection is unrecoverable, False otherwise */ +PyObject *pyis_unrecoverable(PyObject *self, PyObject *args) +{ + int zkhid; + if (!PyArg_ParseTuple(args,"i",&zkhid)) + return NULL; + CHECK_ZHANDLE(zkhid); + int ret = is_unrecoverable(zhandles[zkhid]); + if (ret == ZINVALIDSTATE) + Py_RETURN_TRUE; + Py_RETURN_FALSE; +} + +/* Set the debug level for logging, returns None */ +PyObject *pyzoo_set_debug_level(PyObject *self, PyObject *args) +{ + int loglevel; + if (!PyArg_ParseTuple(args, "i", &loglevel)) + return NULL; + zoo_set_debug_level((ZooLogLevel)loglevel); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *log_stream = NULL; + +/* Set the output file-like object for logging output. Returns Py_None */ +PyObject *pyzoo_set_log_stream(PyObject *self, PyObject *args) +{ + PyObject *pystream = NULL; + if (!PyArg_ParseTuple(args,"O",&pystream)) { + PyErr_SetString(PyExc_ValueError, "Must supply a Python object to set_log_stream"); + return NULL; + } + +#if PY_MAJOR_VERSION >= 3 + extern PyTypeObject PyIOBase_Type; + if (!PyObject_IsInstance(pystream, (PyObject *)&PyIOBase_Type)) { +#else + if(!PyFile_Check(pystream)) { +#endif + + PyErr_SetString(PyExc_ValueError, "Must supply a file object to set_log_stream"); + return NULL; + } + /* Release the previous reference to log_stream that we took */ + if (log_stream != NULL) { + Py_DECREF(log_stream); + } + + log_stream = pystream; + Py_INCREF(log_stream); + +#if PY_MAJOR_VERSION >= 3 + int fd = PyObject_AsFileDescriptor(log_stream); + FILE *fp = fdopen(fd, "w"); +#else + FILE *fp = PyFile_AsFile(log_stream); +#endif + zoo_set_log_stream(fp); + + Py_INCREF(Py_None); + return Py_None; +} + +/* Set the connection order - randomized or in-order. Returns None. */ +PyObject *pyzoo_deterministic_conn_order(PyObject *self, PyObject *args) +{ + int yesOrNo; + if (!PyArg_ParseTuple(args, "i",&yesOrNo)) + return NULL; + zoo_deterministic_conn_order( yesOrNo ); + Py_INCREF(Py_None); + return Py_None; +} + +/* -------------------------------------------------------------------------- */ +/* Module setup */ +/* -------------------------------------------------------------------------- */ + +#include "pyzk_docstrings.h" + +static PyMethodDef ZooKeeperMethods[] = { + {"init", pyzookeeper_init, METH_VARARGS, pyzk_init_doc }, + {"create",pyzoo_create, METH_VARARGS, pyzk_create_doc }, + {"delete",pyzoo_delete, METH_VARARGS, pyzk_delete_doc }, + {"get_children", pyzoo_get_children, METH_VARARGS, pyzk_get_children_doc }, + {"set", pyzoo_set, METH_VARARGS, pyzk_set_doc }, + {"set2", pyzoo_set2, METH_VARARGS, pyzk_set2_doc }, + {"get",pyzoo_get, METH_VARARGS, pyzk_get_doc }, + {"exists",pyzoo_exists, METH_VARARGS, pyzk_exists_doc }, + {"get_acl", pyzoo_get_acl, METH_VARARGS, pyzk_get_acl_doc }, + {"set_acl", pyzoo_set_acl, METH_VARARGS, pyzk_set_acl_doc }, + {"close", pyzoo_close, METH_VARARGS, pyzk_close_doc }, + {"client_id", pyzoo_client_id, METH_VARARGS, pyzk_client_id_doc }, + {"set_watcher", pyzoo_set_watcher, METH_VARARGS }, + {"state", pyzoo_state, METH_VARARGS, pyzk_state_doc }, + {"recv_timeout",pyzoo_recv_timeout, METH_VARARGS }, + {"is_unrecoverable",pyis_unrecoverable, METH_VARARGS, pyzk_is_unrecoverable_doc }, + {"set_debug_level",pyzoo_set_debug_level, METH_VARARGS, pyzk_set_debug_level_doc }, + {"set_log_stream",pyzoo_set_log_stream, METH_VARARGS, pyzk_set_log_stream_doc }, + {"deterministic_conn_order",pyzoo_deterministic_conn_order, METH_VARARGS, pyzk_deterministic_conn_order_doc }, + {"acreate", pyzoo_acreate, METH_VARARGS, pyzk_acreate_doc }, + {"adelete", pyzoo_adelete, METH_VARARGS,pyzk_adelete_doc }, + {"aexists", pyzoo_aexists, METH_VARARGS,pyzk_aexists_doc }, + {"aget", pyzoo_aget, METH_VARARGS, pyzk_aget_doc }, + {"aset", pyzoo_aset, METH_VARARGS, pyzk_aset_doc }, + {"aget_children", pyzoo_aget_children, METH_VARARGS, pyzk_aget_children_doc }, + {"async", pyzoo_async, METH_VARARGS, pyzk_async_doc }, + {"aget_acl", pyzoo_aget_acl, METH_VARARGS, pyzk_aget_acl_doc }, + {"aset_acl", pyzoo_aset_acl, METH_VARARGS, pyzk_aset_acl_doc }, + {"zerror", pyzerror, METH_VARARGS, pyzk_zerror_doc }, + {"add_auth", pyzoo_add_auth, METH_VARARGS, pyzk_add_auth_doc }, + /* DO NOT USE get / set_context. Context is used internally to pass + the python watcher to a dispatch function. If you want context, set + it through set_watcher. */ + // {"get_context", pyzoo_get_context, METH_VARARGS, "" }, + // {"set_context", pyzoo_set_context, METH_VARARGS, "" }, + {NULL, NULL} +}; + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef zookeeper_moddef = { + PyModuleDef_HEAD_INIT, + "zookeeper", + NULL, + 0, + ZooKeeperMethods, + 0, + 0, + 0, + 0 +}; +#endif + +#define ADD_INTCONSTANT(x) PyModule_AddIntConstant(module, #x, ZOO_##x) +#define ADD_INTCONSTANTZ(x) PyModule_AddIntConstant(module, #x, Z##x) + +#define ADD_EXCEPTION(x) x = PyErr_NewException("zookeeper."#x, ZooKeeperException, NULL); \ + Py_INCREF(x); \ + PyModule_AddObject(module, #x, x); + +#if PY_MAJOR_VERSION >= 3 +PyMODINIT_FUNC PyInit_zookeeper(void) { +#else +PyMODINIT_FUNC initzookeeper(void) { +#endif + PyEval_InitThreads(); + +#if PY_MAJOR_VERSION >= 3 + PyObject *module = PyModule_Create(&zookeeper_moddef); +#else + PyObject *module = Py_InitModule("zookeeper", ZooKeeperMethods); +#endif + if (init_zhandles(32) == 0) { + return; // TODO: Is there any way to raise an exception here? + } + + ZooKeeperException = PyErr_NewException("zookeeper.ZooKeeperException", + PyExc_Exception, + NULL); + + PyModule_AddObject(module, "ZooKeeperException", ZooKeeperException); + Py_INCREF(ZooKeeperException); + + int size = 10; + char version_str[size]; + snprintf(version_str, size, "%i.%i.%i", ZOO_MAJOR_VERSION, ZOO_MINOR_VERSION, ZOO_PATCH_VERSION); + + PyModule_AddStringConstant(module, "__version__", version_str); + + ADD_INTCONSTANT(PERM_READ); + ADD_INTCONSTANT(PERM_WRITE); + ADD_INTCONSTANT(PERM_CREATE); + ADD_INTCONSTANT(PERM_DELETE); + ADD_INTCONSTANT(PERM_ALL); + ADD_INTCONSTANT(PERM_ADMIN); + + ADD_INTCONSTANT(EPHEMERAL); + ADD_INTCONSTANT(SEQUENCE); + + ADD_INTCONSTANT(EXPIRED_SESSION_STATE); + ADD_INTCONSTANT(AUTH_FAILED_STATE); + ADD_INTCONSTANT(CONNECTING_STATE); + ADD_INTCONSTANT(ASSOCIATING_STATE); + ADD_INTCONSTANT(CONNECTED_STATE); + + ADD_INTCONSTANT(CREATED_EVENT); + ADD_INTCONSTANT(DELETED_EVENT); + ADD_INTCONSTANT(CHANGED_EVENT); + ADD_INTCONSTANT(CHILD_EVENT); + ADD_INTCONSTANT(SESSION_EVENT); + ADD_INTCONSTANT(NOTWATCHING_EVENT); + + ADD_INTCONSTANT(LOG_LEVEL_ERROR); + ADD_INTCONSTANT(LOG_LEVEL_WARN); + ADD_INTCONSTANT(LOG_LEVEL_INFO); + ADD_INTCONSTANT(LOG_LEVEL_DEBUG); + + ADD_INTCONSTANTZ(SYSTEMERROR); + ADD_INTCONSTANTZ(RUNTIMEINCONSISTENCY); + ADD_INTCONSTANTZ(DATAINCONSISTENCY); + ADD_INTCONSTANTZ(CONNECTIONLOSS); + ADD_INTCONSTANTZ(MARSHALLINGERROR); + ADD_INTCONSTANTZ(UNIMPLEMENTED); + ADD_INTCONSTANTZ(OPERATIONTIMEOUT); + ADD_INTCONSTANTZ(BADARGUMENTS); + ADD_INTCONSTANTZ(INVALIDSTATE); + + ADD_EXCEPTION(SystemErrorException); + ADD_EXCEPTION(RuntimeInconsistencyException); + ADD_EXCEPTION(DataInconsistencyException); + ADD_EXCEPTION(ConnectionLossException); + ADD_EXCEPTION(MarshallingErrorException); + ADD_EXCEPTION(UnimplementedException); + ADD_EXCEPTION(OperationTimeoutException); + ADD_EXCEPTION(BadArgumentsException); + ADD_EXCEPTION(InvalidStateException); + + ADD_INTCONSTANTZ(OK); + ADD_INTCONSTANTZ(APIERROR); + ADD_INTCONSTANTZ(NONODE); + ADD_INTCONSTANTZ(NOAUTH); + ADD_INTCONSTANTZ(BADVERSION); + ADD_INTCONSTANTZ(NOCHILDRENFOREPHEMERALS); + ADD_INTCONSTANTZ(NODEEXISTS); + ADD_INTCONSTANTZ(NOTEMPTY); + ADD_INTCONSTANTZ(SESSIONEXPIRED); + ADD_INTCONSTANTZ(INVALIDCALLBACK); + ADD_INTCONSTANTZ(INVALIDACL); + ADD_INTCONSTANTZ(AUTHFAILED); + ADD_INTCONSTANTZ(CLOSING); + ADD_INTCONSTANTZ(NOTHING); + ADD_INTCONSTANTZ(SESSIONMOVED); + + ADD_EXCEPTION(ApiErrorException); + ADD_EXCEPTION(NoNodeException); + ADD_EXCEPTION(NoAuthException); + ADD_EXCEPTION(BadVersionException); + ADD_EXCEPTION(NoChildrenForEphemeralsException); + ADD_EXCEPTION(NodeExistsException); + ADD_EXCEPTION(NotEmptyException); + ADD_EXCEPTION(SessionExpiredException); + ADD_EXCEPTION(InvalidCallbackException); + ADD_EXCEPTION(InvalidACLException); + ADD_EXCEPTION(AuthFailedException); + ADD_EXCEPTION(ClosingException); + ADD_EXCEPTION(NothingException); + ADD_EXCEPTION(SessionMovedException); + +#if PY_MAJOR_VERSION >= 3 + return module; +#endif +} diff --git a/src/contrib/zkpython/src/examples/README b/src/contrib/zkpython/src/examples/README new file mode 100644 index 00000000000..3c5345425a8 --- /dev/null +++ b/src/contrib/zkpython/src/examples/README @@ -0,0 +1,8 @@ + +This folder contains sample showing how you can use ZooKeeper from Python. + +You should also check the following projects: + +* http://github.com/phunt/zk-smoketest +* http://github.com/henryr/pyzk-recipes + diff --git a/src/contrib/zkpython/src/examples/watch_znode_for_changes.py b/src/contrib/zkpython/src/examples/watch_znode_for_changes.py new file mode 100644 index 00000000000..07100f0209c --- /dev/null +++ b/src/contrib/zkpython/src/examples/watch_znode_for_changes.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python2.6 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" ZNode Change Watcher Skeleton Script + +This script shows you how to write a python program that watches a specific +znode for changes and reacts to them. + +Steps to understand how this script works: + +1. start a standalone ZooKeeper server (by default it listens on localhost:2181) + +Did you know you can deploy "local clusters" by using zkconf[1]? +[1] http://github.com/phunt/zkconf + +2. enter the command line console + +3. create the test node: + [zk: (CONNECTED) 1] create /watch-test dummy-data + Created /watch-test + +4. in another shell start this script in verbose mode + $ python watch_znode_for_changes.py -v + + # you should see a lot of log messages. have a look over them because + # you can easily understand how zookeeper works + +5. update the node data: + + [zk: (CONNECTED) 2] set /watch-test new-data + cZxid = 0xa0000001a + ctime = Fri Jul 09 19:14:45 EEST 2010 + mZxid = 0xa0000001e + mtime = Fri Jul 09 19:18:18 EEST 2010 + pZxid = 0xa0000001a + cversion = 0 + dataVersion = 1 + aclVersion = 0 + ephemeralOwner = 0x0 + dataLength = 8 + numChildren = 0 + + ... and you should see similar log messages: + + 2010-07-09 19:18:18,537:11542(0xb6ea5b70):ZOO_DEBUG@process_completions@1765: Calling a watcher for node [/watch-test], type = -1 event=ZOO_CHANGED_EVENT + 2010-07-09 19:18:18,537 watch_znode_for_changes.py:83 - Running watcher: zh=0 event=3 state=3 path=/watch-test + 2010-07-09 19:18:18,537:11542(0xb6ea5b70):ZOO_DEBUG@zoo_awget@2400: Sending request xid=0x4c374b33 for path [/watch-test] to 127.0.0.1:2181 + 2010-07-09 19:18:18,545:11542(0xb76a6b70):ZOO_DEBUG@zookeeper_process@1980: Queueing asynchronous response + 2010-07-09 19:18:18,545:11542(0xb6ea5b70):ZOO_DEBUG@process_completions@1772: Calling COMPLETION_DATA for xid=0x4c374b33 rc=0 + 2010-07-09 19:18:18,545 watch_znode_for_changes.py:54 - This is where your application does work. + + You can repeat this step multiple times. + +6. that's all. in the end you can delete the node and you should see a ZOO_DELETED_EVENT + +""" + +import logging +import logging.handlers +import signal +import sys +import time +import threading +import zookeeper + +from optparse import OptionParser + +logger = logging.getLogger() + +class MyClass(threading.Thread): + znode = '/watch-test' + + def __init__(self, options, args): + threading.Thread.__init__(self) + + logger.debug('Initializing MyClass thread.') + if options.verbose: + zookeeper.set_debug_level(zookeeper.LOG_LEVEL_DEBUG) + + self.zh = zookeeper.init(options.servers) + if zookeeper.OK != zookeeper.aget(self.zh, self.znode, + self.watcher, self.handler): + logger.critical('Unable to get znode! Exiting.') + sys.exit(1) + + def __del__(self): + zookeeper.close(self.zh) + + def aget(self): + return zookeeper.aget(self.zh, self.znode, self.watcher, self.handler) + + def handler(self, zh, rc, data, stat): + """Handle zookeeper.aget() responses. + + This code handles the zookeeper.aget callback. It does not handle watches. + + Numeric arguments map to constants. See ``DATA`` in ``help(zookeeper)`` + for more information. + + Args: + zh Zookeeper handle that made this request. + rc Return code. + data Data stored in the znode. + + Does not provide a return value. + """ + if zookeeper.OK == rc: + logger.debug('This is where your application does work.') + else: + if zookeeper.NONODE == rc: + # avoid sending too many requests if the node does not yet exists + logger.info('Node not found. Trying again to set the watch.') + time.sleep(1) + + if zookeeper.OK != self.aget(): + logger.critical('Unable to get znode! Exiting.') + sys.exit(1) + + def watcher(self, zh, event, state, path): + """Handle zookeeper.aget() watches. + + This code is called when a znode changes and triggers a data watch. + It is not called to handle the zookeeper.aget call itself. + + Numeric arguments map to constants. See ``DATA`` in ``help(zookeeper)`` + for more information. + + Args: + zh Zookeeper handle that set this watch. + event Event that caused the watch (often called ``type`` elsewhere). + state Connection state. + path Znode that triggered this watch. + + Does not provide a return value. + """ + out = ['Running watcher:', + 'zh=%d' % zh, + 'event=%d' % event, + 'state=%d' % state, + 'path=%s' % path] + logger.debug(' '.join(out)) + if event == zookeeper.CHANGED_EVENT and \ + state == zookeeper.CONNECTED_STATE and \ + self.znode == path: + if zookeeper.OK != self.aget(): + logger.critical('Unable to get znode! Exiting.') + sys.exit(1) + + def run(self): + while True: + time.sleep(86400) + + +def main(argv=None): + # Allow Ctrl-C + signal.signal(signal.SIGINT, signal.SIG_DFL) + + parser = OptionParser() + parser.add_option('-v', '--verbose', + dest='verbose', + default=False, + action='store_true', + help='Verbose logging. (default: %default)') + parser.add_option('-s', '--servers', + dest='servers', + default='localhost:2181', + help='Comma-separated list of host:port pairs. (default: %default)') + + (options, args) = parser.parse_args() + + if options.verbose: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + formatter = logging.Formatter("%(asctime)s %(filename)s:%(lineno)d - %(message)s") + stream_handler = logging.StreamHandler() + stream_handler.setFormatter(formatter) + logger.addHandler(stream_handler) + + logger.info('Starting Zookeeper python example: %s' % ' '.join(sys.argv)) + + mc = MyClass(options, args) + mc.start() + mc.join() + + +if __name__ == '__main__': + main() diff --git a/src/contrib/zkpython/src/packages/deb/zkpython.control/control b/src/contrib/zkpython/src/packages/deb/zkpython.control/control new file mode 100644 index 00000000000..6ec76d06957 --- /dev/null +++ b/src/contrib/zkpython/src/packages/deb/zkpython.control/control @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +Package: zkpython +Version: @version@ +Section: misc +Priority: optional +Architecture: all +Depends: python +Maintainer: Apache Software Foundation +Description: ZooKeeper python binding library +Distribution: development diff --git a/src/contrib/zkpython/src/packages/rpm/spec/zkpython.spec b/src/contrib/zkpython/src/packages/rpm/spec/zkpython.spec new file mode 100644 index 00000000000..d1f981431b6 --- /dev/null +++ b/src/contrib/zkpython/src/packages/rpm/spec/zkpython.spec @@ -0,0 +1,81 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# RPM Spec file for ZooKeeper version @version@ +# + +%define name zkpython +%define version @version@ +%define release @package.release@ + +# Installation Locations +%define _prefix @package.prefix@ + +# Build time settings +%define _build_dir @package.build.dir@ +%define _final_name @final.name@ +%define _python_lib @python.lib@ +%define debug_package %{nil} + +# Disable brp-java-repack-jars for aspect J +%define __os_install_post \ + /usr/lib/rpm/redhat/brp-compress \ + %{!?__debug_package:/usr/lib/rpm/redhat/brp-strip %{__strip}} \ + /usr/lib/rpm/redhat/brp-strip-static-archive %{__strip} \ + /usr/lib/rpm/redhat/brp-strip-comment-note %{__strip} %{__objdump} \ + /usr/lib/rpm/brp-python-bytecompile %{nil} + +# RPM searches perl files for dependancies and this breaks for non packaged perl lib +# like thrift so disable this +%define _use_internal_dependency_generator 0 + +Summary: ZooKeeper python binding library +Group: Development/Libraries +License: Apache License, Version 2.0 +URL: http://zookeeper.apache.org/ +Vendor: Apache Software Foundation +Name: %{name} +Version: %{version} +Release: %{release} +Source0: %{_python_lib} +Prefix: %{_prefix} +Requires: zookeeper-lib == %{version} +AutoReqProv: no +Provides: zkpython + +%description +ZooKeeper python binding library + +%prep +tar fxz %{_python_lib} -C %{_build_dir} + +%build + +######################### +#### INSTALL SECTION #### +######################### +%install + +%pre + +%post + +%preun + +%files +%defattr(-,root,root) +%{_prefix} + diff --git a/src/contrib/zkpython/src/python/setup.py b/src/contrib/zkpython/src/python/setup.py new file mode 100755 index 00000000000..c6a1ceefba6 --- /dev/null +++ b/src/contrib/zkpython/src/python/setup.py @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from distutils.core import setup, Extension + +zookeeper_basedir = "../../../" + +zookeepermodule = Extension("zookeeper", + sources=["src/c/zookeeper.c"], + include_dirs=[zookeeper_basedir + "/src/c/include", + zookeeper_basedir + "/build/c", + zookeeper_basedir + "/src/c/generated"], + libraries=["zookeeper_mt"], + library_dirs=[zookeeper_basedir + "/src/c/.libs/", + zookeeper_basedir + "/build/c/.libs/", + zookeeper_basedir + "/build/test/test-cppunit/.libs", + "/usr/local/lib" + ]) + +setup( name="ZooKeeper", + version = "0.4", + description = "ZooKeeper Python bindings", + ext_modules=[zookeepermodule] ) diff --git a/src/contrib/zkpython/src/python/zk.py b/src/contrib/zkpython/src/python/zk.py new file mode 100755 index 00000000000..9c0f37482ed --- /dev/null +++ b/src/contrib/zkpython/src/python/zk.py @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, time, threading + +f = open("out.log","w") +zookeeper.set_log_stream(f) + +connected = False +conn_cv = threading.Condition( ) + +def my_connection_watcher(handle,type,state,path): + global connected, conn_cv + print("Connected, handle is ", handle) + conn_cv.acquire() + connected = True + conn_cv.notifyAll() + conn_cv.release() + +conn_cv.acquire() +print("Connecting to localhost:2181 -- ") +handle = zookeeper.init("localhost:2181", my_connection_watcher, 10000, 0) +while not connected: + conn_cv.wait() +conn_cv.release() + +def my_getc_watch( handle, type, state, path ): + print("Watch fired -- ") + print(type, state, path) + +ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"}; + +try: + zookeeper.create(handle, "/zk-python", "data", [ZOO_OPEN_ACL_UNSAFE], 0) + zookeeper.get_children(handle, "/zk-python", my_getc_watch) + for i in xrange(5): + print("Creating sequence node ", i, " ", zookeeper.create(handle, "/zk-python/sequencenode", "data", [ZOO_OPEN_ACL_UNSAFE], zookeeper.SEQUENCE )) +except: + pass + +def pp_zk(handle,root, indent = 0): + """Pretty print(a zookeeper tree, starting at root""") + def make_path(child): + if root == "/": + return "/" + child + return root + "/" + child + children = zookeeper.get_children(handle, root, None) + out = "" + for i in xrange(indent): + out += "\t" + out += "|---"+root + " :: " + zookeeper.get(handle, root, None)[0] + print(out) + for child in children: + pp_zk(handle,make_path(child),indent+1) + +print("ZNode tree -- ") +pp_zk(handle,"/") + +print("Getting ACL / Stat for /zk-python --") +(stat, acl) = zookeeper.get_acl(handle, "/zk-python") +print("Stat:: ", stat) +print("Acl:: ", acl) + diff --git a/src/contrib/zkpython/src/test/acl_test.py b/src/contrib/zkpython/src/test/acl_test.py new file mode 100644 index 00000000000..1289c8a3439 --- /dev/null +++ b/src/contrib/zkpython/src/test/acl_test.py @@ -0,0 +1,109 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading + +ZOO_OPEN_ACL_UNSAFE = {"perms":zookeeper.PERM_ALL, "scheme":"world", "id" :"anyone"} +ZOO_ACL_READ = {"perms":zookeeper.PERM_READ, "scheme": "world", + "id":"anyone"} +class ACLTest(zktestbase.TestBase): + """Test whether basic ACL setting and getting work correctly""" + # to do: startup and teardown via scripts? + def setUp(self): + zktestbase.TestBase.setUp(self) + try: + zookeeper.delete(self.handle, "/zk-python-acltest") + zookeeper.delete(self.handle, "/zk-python-aacltest") + except: + pass + + def test_sync_acl(self): + self.assertEqual(self.connected, True) + ret = zookeeper.create(self.handle, "/zk-python-acltest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + acls = zookeeper.get_acl(self.handle, "/zk-python-acltest") + self.assertEqual(acls[1], [ZOO_OPEN_ACL_UNSAFE]) + self.assertRaises(zookeeper.InvalidACLException,zookeeper.set_acl,self.handle, "/zk-python-acltest", -1, ZOO_ACL_READ) + zookeeper.set_acl(self.handle, "/zk-python-acltest", -1, [ZOO_ACL_READ]) + acls = zookeeper.get_acl(self.handle, "/zk-python-acltest") + self.assertEqual(acls[1], [ZOO_ACL_READ]) + + + def test_async_acl(self): + self.cv = threading.Condition() + self.cv = threading.Condition() + def aget_callback(handle, rc, acl, stat): + self.cv.acquire() + self.callback_flag = True + self.rc = rc + self.acl = acl + self.stat = stat + self.cv.notify() + self.cv.release() + + def aset_callback(handle, rc): + self.cv.acquire() + self.callback_flag = True + self.rc = rc + self.cv.notify() + self.cv.release() + + self.assertEqual(self.connected, True, "Not connected!") + ret = zookeeper.create(self.handle, "/zk-python-aacltest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + + self.cv.acquire() + zookeeper.aget_acl(self.handle, "/zk-python-aacltest", aget_callback) + self.cv.wait(15) + self.cv.release() + + self.assertEqual(self.callback_flag, True, "aget_acl timed out") + self.assertEqual(self.rc, zookeeper.OK, "aget failed") + self.assertEqual(self.acl, [ZOO_OPEN_ACL_UNSAFE], "Wrong ACL returned from aget") + + self.cv.acquire() + self.callback_flag = False + zookeeper.aset_acl(self.handle, "/zk-python-aacltest", -1, [ZOO_ACL_READ], aset_callback) + self.cv.wait(15) + self.cv.release() + + self.assertEqual(self.callback_flag, True, "aset_acl timed out") + self.assertEqual(self.rc, zookeeper.OK, "aset failed") + acls = zookeeper.get_acl(self.handle, "/zk-python-aacltest") + self.assertEqual(acls[1], [ZOO_ACL_READ], "Wrong ACL returned from get when aset") + + def test_invalid_acl(self): + self.assertRaises(zookeeper.InvalidACLException, + zookeeper.create, + self.handle, + "/zk-python-aclverifytest", + "", + None, + zookeeper.EPHEMERAL) + + def test_invalid_acl2(self): + """Verify all required keys are present in the ACL.""" + invalid_acl = [{"schema": "digest", "id": "zebra"}] + self.assertRaises(zookeeper.InvalidACLException, + zookeeper.create, + self.handle, + "/zk-python-aclverifytest", + "", + invalid_acl, + zookeeper.EPHEMERAL) + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/async_test.py b/src/contrib/zkpython/src/test/async_test.py new file mode 100644 index 00000000000..e81343570ea --- /dev/null +++ b/src/contrib/zkpython/src/test/async_test.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading + +class AsyncTest(zktestbase.TestBase): + """Test whether async works""" + # to do: startup and teardown via scripts? + def setUp( self ): + zktestbase.TestBase.setUp(self) + + def test_async(self): + self.assertEqual(self.connected, True) + ret = zookeeper.async(self.handle, "/") + self.assertEqual(ret, zookeeper.OK, "async failed") + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/callback_test.py b/src/contrib/zkpython/src/test/callback_test.py new file mode 100644 index 00000000000..55d7fe17866 --- /dev/null +++ b/src/contrib/zkpython/src/test/callback_test.py @@ -0,0 +1,155 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading, gc + +ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} + +class CallbackTest(zktestbase.TestBase): + """ + Test whether callbacks (watchers/completions) are correctly invoked + """ + # to do: startup and teardown via scripts? + def setUp(self): + zktestbase.TestBase.setUp(self) + self.cv = threading.Condition() + + def create_callback(self, callback): + """ + Returns a callable which signals cv and then calls callback + """ + def wrapper(*args, **kwargs): + self.cv.acquire() + callback(*args, **kwargs) + self.cv.notify() + self.cv.release() + return wrapper + + def test_none_callback(self): + """ + Test that no errors are raised when None is passed as a callback. + """ + self.ensureCreated("/zk-python-none-callback-test","test") + # To do this we need to issue two operations, waiting on the second + # to ensure that the first completes + zookeeper.get(self.handle, "/zk-python-none-callback-test", None) + (d,s) = zookeeper.get(self.handle, "/zk-python-none-callback-test") + self.assertEqual(d, "test") + + def callback_harness(self, trigger, test): + self.callback_flag = False + self.cv.acquire() + trigger() + self.cv.wait(15) + test() + + def test_dispatch_types(self): + """ + Test all the various dispatch mechanisms internal to the module. + """ + def dispatch_callback(*args, **kwargs): + self.callback_flag = True + self.ensureCreated("/zk-python-dispatch-test") + self.callback_harness( lambda: zookeeper.adelete(self.handle, + "/zk-python-dispatch-test", + -1, + self.create_callback(dispatch_callback)), + lambda: self.assertEqual(True, self.callback_flag, "Void dispatch not fired")) + + + self.ensureCreated("/zk-python-dispatch-test") + self.callback_harness( lambda: zookeeper.aexists(self.handle, + "/zk-python-dispatch-test", + None, + self.create_callback(dispatch_callback)), + lambda: self.assertEqual(True, self.callback_flag, "Stat dispatch not fired")) + + self.callback_harness( lambda: zookeeper.aget(self.handle, + "/zk-python-dispatch-test", + None, + self.create_callback(dispatch_callback)), + lambda: self.assertEqual(True, self.callback_flag, "Data dispatch not fired")) + + self.callback_harness( lambda: zookeeper.aget_children(self.handle, + "/", + None, + self.create_callback( dispatch_callback )), + lambda: self.assertEqual(True, self.callback_flag, "Strings dispatch not fired")) + + self.callback_harness( lambda: zookeeper.async(self.handle, + "/", + self.create_callback( dispatch_callback )), + lambda: self.assertEqual(True, self.callback_flag, "String dispatch not fired")) + + self.callback_harness( lambda: zookeeper.aget_acl(self.handle, + "/", + self.create_callback( dispatch_callback )), + lambda: self.assertEqual(True, self.callback_flag, "ACL dispatch not fired")) + + def test_multiple_watchers(self): + """ + Test whether multiple watchers are correctly called + """ + cv1, cv2 = threading.Condition(), threading.Condition() + def watcher1(*args, **kwargs): + cv1.acquire() + self.watcher1 = True + cv1.notify() + cv1.release() + + def watcher2(*args, **kwargs): + cv2.acquire() + self.watcher2 = True + cv2.notify() + cv2.release() + + nodename = "/zk-python-multiple-watcher-test" + self.ensureCreated(nodename, "test") + cv1.acquire() + cv2.acquire() + zookeeper.get(self.handle, nodename, watcher1) + zookeeper.get(self.handle, nodename, watcher2) + zookeeper.set(self.handle, nodename, "test") + cv1.wait(15) + cv2.wait(15) + self.assertTrue(self.watcher1 and self.watcher2, "One or more watchers failed to fire") + + def test_lose_scope(self): + """ + The idea is to test that the reference counting doesn't + fail when we retain no references outside of the module + """ + self.ensureDeleted("/zk-python-lose-scope-test") + self.ensureCreated("/zk-python-lose-scope-test") + def set_watcher(): + def fn(): self.callback_flag = True + self.callback_flag = False + zookeeper.exists(self.handle, "/zk-python-lose-scope-test", + self.create_callback( lambda handle, type, state, path: fn() ) + ) + + set_watcher() + gc.collect() + self.cv.acquire() + zookeeper.set(self.handle, "/zk-python-lose-scope-test", "test") + self.cv.wait(15) + self.assertEqual(self.callback_flag, True) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/clientid_test.py b/src/contrib/zkpython/src/test/clientid_test.py new file mode 100755 index 00000000000..90c8f0acc30 --- /dev/null +++ b/src/contrib/zkpython/src/test/clientid_test.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest, threading + +import zookeeper, zktestbase + +class ClientidTest(zktestbase.TestBase): + """Test whether clientids work""" + def setUp(self): + pass + + def testclientid(self): + cv = threading.Condition() + self.connected = False + def connection_watcher(handle, type, state, path): + cv.acquire() + self.connected = True + cv.notify() + cv.release() + + cv.acquire() + self.handle = zookeeper.init(self.host, connection_watcher,10000,(123456,"mypassword")) + self.assertEqual(self.handle, zookeeper.OK) + cv.wait(15.0) + cv.release() + self.assertEqual(self.connected, True, "Connection timed out to " + self.host) + (cid,passwd) = zookeeper.client_id(self.handle) + self.assertEqual(cid,123456) + self.assertEqual(passwd,"mypassword") + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/close_deadlock_test.py b/src/contrib/zkpython/src/test/close_deadlock_test.py new file mode 100644 index 00000000000..921d2cc4b05 --- /dev/null +++ b/src/contrib/zkpython/src/test/close_deadlock_test.py @@ -0,0 +1,50 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading +import time + + +class CloseDeadlockTest(zktestbase.TestBase): + """ + This tests for the issue found in + https://issues.apache.org/jira/browse/ZOOKEEPER-763 + + zookeeper.close blocks on waiting for all completions to + finish. Previously it was doing so while holding teh GIL, stopping + any completions from actually continuing. + + This test is a failure if it does not exit within a few seconds. + """ + def deadlock(): + cv = threading.Condition() + + def callback(*args): + cv.acquire() + cv.notifyAll() + cv.release() + time.sleep(1) + + cv.acquire() + zookeeper.aget(handle, "/", None, callback) + cv.wait() + zookeeper.close(handle) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/connection_test.py b/src/contrib/zkpython/src/test/connection_test.py new file mode 100755 index 00000000000..3913fe3b7d9 --- /dev/null +++ b/src/contrib/zkpython/src/test/connection_test.py @@ -0,0 +1,131 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest, threading, re, sys +if sys.version_info < (3,): + range = xrange + +import zookeeper, zktestbase +ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} + +class ConnectionTest(zktestbase.TestBase): + """Test whether we can make a connection""" + def setUp(self): + pass + + def testconnection(self): + cv = threading.Condition() + self.connected = False + def connection_watcher(handle, type, state, path): + cv.acquire() + self.connected = True + self.assertEqual(zookeeper.CONNECTED_STATE, state) + self.handle = handle + cv.notify() + cv.release() + + cv.acquire() + ret = zookeeper.init(self.host, connection_watcher) + cv.wait(15.0) + cv.release() + self.assertEqual(self.connected, True, "Connection timed out to " + self.host) + self.assertEqual(zookeeper.CONNECTED_STATE, zookeeper.state(self.handle)) + + self.assertEqual(zookeeper.close(self.handle), zookeeper.OK) + # Trying to close the same handle twice is an error, and the C library will segfault on it + # so make sure this is caught at the Python module layer + self.assertRaises(zookeeper.ZooKeeperException, + zookeeper.close, + self.handle) + + self.assertRaises(zookeeper.ZooKeeperException, + zookeeper.get, + self.handle, + "/") + + def testhandlereuse(self): + """ + Test a) multiple concurrent connections b) reuse of closed handles + """ + cv = threading.Condition() + self.connected = False + def connection_watcher(handle, type, state, path): + cv.acquire() + self.connected = True + self.assertEqual(zookeeper.CONNECTED_STATE, state) + self.handle = handle + cv.notify() + cv.release() + + cv.acquire() + handles = [ zookeeper.init(self.host) for i in range(10) ] + ret = zookeeper.init(self.host, connection_watcher) + cv.wait(15.0) + cv.release() + self.assertEqual(self.connected, True, "Connection timed out to " + self.host) + self.assertEqual(True, self.all( [ zookeeper.state(handle) == zookeeper.CONNECTED_STATE for handle in handles ] ), + "Not all connections succeeded") + oldhandle = handles[3] + zookeeper.close(oldhandle) + newhandle = zookeeper.init(self.host) + + # This assertion tests *internal* behaviour; i.e. that the module + # correctly reuses closed handles. This is therefore implementation + # dependent. + self.assertEqual(newhandle, oldhandle, "Didn't get reused handle") + + def testmanyhandles(self): + """ + Test the ability of the module to support many handles. + """ + # We'd like to do more, but currently the C client doesn't + # work with > 83 handles (fails to create a pipe) on MacOS 10.5.8 + handles = [ zookeeper.init(self.host) for i in range(9) ] + + cv = threading.Condition() + self.connected = False + def connection_watcher(handle, type, state, path): + cv.acquire() + self.connected = True + self.assertEqual(zookeeper.CONNECTED_STATE, state) + self.handle = handle + cv.notify() + cv.release() + + cv.acquire() + ret = zookeeper.init(self.host, connection_watcher) + cv.wait(15.0) + cv.release() + self.assertEqual(self.connected, True, "Connection timed out to " + self.host) + + for i,h in enumerate(handles): + path = "/zkpython-test-handles-%s" % str(i) + self.assertEqual(path, zookeeper.create(h, path, "", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL)) + + self.assertEqual(True, self.all( zookeeper.close(h) == zookeeper.OK for h in handles )) + + def testversionstringexists(self): + self.assertTrue(hasattr(zookeeper, '__version__')) + self.assertTrue(re.match("\d.\d.\d", zookeeper.__version__)) + + + def tearDown(self): + pass + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/create_test.py b/src/contrib/zkpython/src/test/create_test.py new file mode 100755 index 00000000000..8ab80f9565a --- /dev/null +++ b/src/contrib/zkpython/src/test/create_test.py @@ -0,0 +1,104 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading + +ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} + +class CreationTest(zktestbase.TestBase): + """Test whether we can create znodes""" + # to do: startup and teardown via scripts? + def setUp(self): + zktestbase.TestBase.setUp(self) + try: + zookeeper.delete(self.handle, "/zk-python-createtest") + zookeeper.delete(self.handle, "/zk-python-acreatetest") + except: + pass + + def test_sync_create(self): + self.assertEqual(self.connected, True) + ret = zookeeper.create(self.handle, "/zk-python-createtest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + self.assertEqual(ret, "/zk-python-createtest") + self.assertRaises(zookeeper.NoChildrenForEphemeralsException, + zookeeper.create, + self.handle, + "/zk-python-createtest/invalid-child", + "", + [ZOO_OPEN_ACL_UNSAFE], + zookeeper.EPHEMERAL) + + def test_sync_create_existing(self): + self.assertEqual(self.connected, True) + ret = zookeeper.create(self.handle, "/zk-python-createtest-existing", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + self.assertEqual(ret, "/zk-python-createtest-existing") + + self.assertRaises(zookeeper.NodeExistsException, + zookeeper.create, + self.handle, + "/zk-python-createtest-existing", + "nodecontents", + [ZOO_OPEN_ACL_UNSAFE], + zookeeper.EPHEMERAL) + + + def test_exception_paths(self): + """ + Make sure common exceptions due to API misuse are correctly propogated + """ + self.assertRaises(zookeeper.BadArgumentsException, + zookeeper.create, + self.handle, + "/zk-python-badargs-test", + "", + [ZOO_OPEN_ACL_UNSAFE], + -1) + self.assertRaises(zookeeper.InvalidACLException, + zookeeper.create, + self.handle, + "/zk-python-invalidacl-test", + "", + ZOO_OPEN_ACL_UNSAFE) # Error - not a list + + + def test_async_create(self): + self.cv = threading.Condition() + def callback(handle, rc, value): + self.cv.acquire() + self.callback_flag = True + self.rc = rc + self.cv.notify() + self.cv.release() + + self.assertEqual(self.connected, True, "Not connected!") + self.cv.acquire() + + ret = zookeeper.acreate(self.handle, "/zk-python-acreatetest", "nodecontents", + [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL, + callback ) + self.assertEqual(ret, zookeeper.OK, "acreate failed") + while not self.callback_flag: + self.cv.wait(15) + self.cv.release() + + self.assertEqual(self.callback_flag, True, "acreate timed out") + self.assertEqual(self.rc, zookeeper.OK) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/delete_test.py b/src/contrib/zkpython/src/test/delete_test.py new file mode 100755 index 00000000000..913b6a9a94e --- /dev/null +++ b/src/contrib/zkpython/src/test/delete_test.py @@ -0,0 +1,68 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading + +class DeletionTest(zktestbase.TestBase): + """Test whether we can delete znodes""" + + def test_sync_delete(self): + ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} + self.assertEqual(self.connected, True) + ret = zookeeper.create(self.handle, "/zk-python-deletetest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + self.assertEqual(ret, "/zk-python-deletetest") + ret = zookeeper.delete(self.handle,"/zk-python-deletetest") + self.assertEqual(ret, zookeeper.OK) + children = zookeeper.get_children(self.handle, "/") + self.assertEqual(False, "zk-python-deletetest" in children) + + # test exception + self.assertRaises(zookeeper.NoNodeException, + zookeeper.delete, + self.handle, + "/zk-python-deletetest") + + def test_async_delete(self): + ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} + self.assertEqual(self.connected, True) + ret = zookeeper.create(self.handle, "/zk-python-adeletetest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + self.assertEqual(ret, "/zk-python-adeletetest") + + self.cv = threading.Condition() + self.callback_flag = False + self.rc = -1 + def callback(handle, rc): + self.cv.acquire() + self.callback_flag = True + self.cv.notify() + self.rc = rc # don't assert this here, as if the assertion fails, the test will block + self.cv.release() + + self.cv.acquire() + ret = zookeeper.adelete(self.handle,"/zk-python-adeletetest",-1,callback) + self.assertEqual(ret, zookeeper.OK, "adelete failed") + while not self.callback_flag: + self.cv.wait(15) + self.cv.release() + + self.assertEqual(self.callback_flag, True, "adelete timed out") + self.assertEqual(self.rc, zookeeper.OK) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/exists_test.py b/src/contrib/zkpython/src/test/exists_test.py new file mode 100755 index 00000000000..ddc6ef3683b --- /dev/null +++ b/src/contrib/zkpython/src/test/exists_test.py @@ -0,0 +1,64 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading + +ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} +class ExistsTest(zktestbase.TestBase): + def setUp( self ): + zktestbase.TestBase.setUp(self) + try: + zookeeper.create(self.handle, "/zk-python-existstest","existstest", [ZOO_OPEN_ACL_UNSAFE],zookeeper.EPHEMERAL) + zookeeper.create(self.handle, "/zk-python-aexiststest","existstest",[ZOO_OPEN_ACL_UNSAFE],zookeeper.EPHEMERAL) + except: + pass + + def test_sync_exists(self): + self.assertEqual(self.connected, True) + ret = zookeeper.exists(self.handle, "/zk-python-existstest", None) + self.assertNotEqual(ret, None, "/zk-python-existstest does not exist (possibly means creation failure)") + + def test_sync_nexists(self): + self.assertEqual(None, zookeeper.exists(self.handle, "/i-dont-exist", None)) + + + def test_async_exists(self): + self.cv = threading.Condition() + def callback(handle, rc, stat): + self.cv.acquire() + self.callback_flag = True + self.cv.notify() + self.cv.release() + self.rc = rc + + self.assertEqual(self.connected, True) + + self.cv.acquire() + ret = zookeeper.aexists(self.handle, "/zk-python-aexiststest", None, + callback ) + self.assertEqual(ret, zookeeper.OK) + while not self.callback_flag: + self.cv.wait(15) + self.cv.release() + + self.assertEqual(self.callback_flag, True, "aexists timed out") + self.assertEqual(self.rc, zookeeper.OK, "Return code not ok:" + zookeeper.zerror(self.rc)) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/get_set_test.py b/src/contrib/zkpython/src/test/get_set_test.py new file mode 100755 index 00000000000..b77b3b22165 --- /dev/null +++ b/src/contrib/zkpython/src/test/get_set_test.py @@ -0,0 +1,211 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zookeeper, zktestbase, unittest, threading, sys +if sys.version_info < (3,): + range = xrange + +ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} + +class GetSetTest(zktestbase.TestBase): + def setUp( self ): + zktestbase.TestBase.setUp(self) + try: + zookeeper.create(self.handle, "/zk-python-getsettest", "on",[ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + zookeeper.create(self.handle, "/zk-python-agetsettest", + "on",[ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) + except: + pass + + def test_empty_node(self): + """ + Test for a bug when instead of empty string we can get + random data from buffer malloc'ed to hold node contents. + See ZOOKEEPER-1906 for details + """ + NODE_PATH = "/zk-python-test-empty-node" + self.ensureDeleted(NODE_PATH) + zookeeper.create(self.handle, NODE_PATH, "", + [{"perms":0x1f, "scheme":"world", "id" :"anyone"}]) + (data,stat) = zookeeper.get(self.handle, NODE_PATH, None) + self.assertEqual(data, "", "Data is not empty as expected: " + data) + + def test_sync_getset(self): + self.assertEqual(self.connected, True, "Not connected!") + (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None) + self.assertEqual(data, "on", "Data is not 'on' as expected: " + data) + ret = zookeeper.set(self.handle, "/zk-python-getsettest", + "off", stat["version"]) + (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None) + self.assertEqual(data, "off", "Data is not 'off' as expected: " + data) + self.assertRaises(zookeeper.BadVersionException, + zookeeper.set, + self.handle, + "/zk-python-getsettest", + "test", + stat["version"]+1) + stat2 = zookeeper.set2(self.handle, "/zk-python-getsettest", + "set2", stat["version"]) + self.assertNotEqual(stat2, None, "set2 call failed, return should not be None") + self.assertEqual(stat2["numChildren"], 0, + "set2 call failed, numChildren not 0 in set2 call") + (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None) + self.assertEqual(data, "set2", "Data is not 'set2' as expected: " + data) + + def test_stat_deleted_node(self): + """ + Test for a bug that surfaced when trying to build a + stat object from a non-existant node. + + """ + self.ensureDeleted("/zk-python-test-deleteme") + self.assertRaises(zookeeper.NoNodeException, + zookeeper.get, + self.handle, + "/zk-python-test-deleteme") + self.cv = threading.Condition() + def callback(handle, rc, value, stat): + self.cv.acquire() + self.stat = stat + self.rc = rc + self.value = value + self.callback_flag = True + self.cv.notify() + self.cv.release() + self.cv.acquire() + zookeeper.aget(self.handle, "/zk-python-test-deleteme", None, callback) + self.cv.wait(15) + self.assertEqual(self.callback_flag, True, "aget timed out!") + self.assertEqual(self.stat, None, "Stat should be none!") + self.assertEqual(self.value, None, "Value should be none!") + + def test_sync_get_large_datanode(self): + """ + Test that we can retrieve datanode sizes up to + 1Mb with default parameters (depends on ZooKeeper server). + """ + + data = ''.join(["A" for x in range(1024*1023)]) + self.ensureDeleted("/zk-python-test-large-datanode") + zookeeper.create(self.handle, "/zk-python-test-large-datanode", data, + [{"perms":0x1f, "scheme":"world", "id" :"anyone"}]) + (ret,stat) = zookeeper.get(self.handle, "/zk-python-test-large-datanode") + self.assertEqual(len(ret), 1024*1023, + "Should have got 1Mb returned, instead got %s" % len(ret)) + (ret,stat) = zookeeper.get(self.handle, "/zk-python-test-large-datanode",None,500) + self.assertEqual(len(ret), 500, + "Should have got 500 bytes returned, instead got %s" % len(ret)) + + + + def test_async_getset(self): + self.cv = threading.Condition() + def get_callback(handle, rc, value, stat): + self.cv.acquire() + self.callback_flag = True + self.rc = rc + self.value = (value,stat) + self.cv.notify() + self.cv.release() + + def set_callback(handle, rc, stat): + self.cv.acquire() + self.callback_flag = True + self.rc = rc + self.value = stat + self.cv.notify() + self.cv.release() + + self.assertEqual(self.connected, True, "Not connected!") + + self.cv.acquire() + self.callback_flag = False + ret = zookeeper.aset(self.handle, "/zk-python-agetsettest", "off", -1, set_callback) + self.assertEqual(ret, zookeeper.OK, "aset failed") + while not self.callback_flag: + self.cv.wait(15) + self.cv.release() + self.assertEqual(self.callback_flag, True, "aset timed out") + + self.cv.acquire() + self.callback_flag = False + ret = zookeeper.aget(self.handle, "/zk-python-agetsettest", None, get_callback) + self.assertEqual(ret, zookeeper.OK, "aget failed") + self.cv.wait(15) + self.cv.release() + self.assertEqual(self.callback_flag, True, "aget timed out") + self.assertEqual(self.value[0], "off", "Data is not 'off' as expected: " + self.value[0]) + + def test_sync_getchildren(self): + self.ensureCreated("/zk-python-getchildrentest", flags=0) + self.ensureCreated("/zk-python-getchildrentest/child") + children = zookeeper.get_children(self.handle, "/zk-python-getchildrentest") + self.assertEqual(len(children), 1, "Expected to find 1 child, got " + str(len(children))) + + def test_async_getchildren(self): + self.ensureCreated("/zk-python-getchildrentest", flags=0) + self.ensureCreated("/zk-python-getchildrentest/child") + + def gc_callback(handle, rc, children): + self.cv.acquire() + self.rc = rc + self.children = children + self.callback_flag = True + self.cv.notify() + self.cv.release() + + self.cv.acquire() + self.callback_flag = False + zookeeper.aget_children(self.handle, "/zk-python-getchildrentest", None, gc_callback) + self.cv.wait(15) + self.assertEqual(self.callback_flag, True, "aget_children timed out") + self.assertEqual(self.rc, zookeeper.OK, "Return code for aget_children was not OK - %s" % zookeeper.zerror(self.rc)) + self.assertEqual(len(self.children), 1, "Expected to find 1 child, got " + str(len(self.children))) + + + def test_async_getchildren_with_watcher(self): + self.ensureCreated("/zk-python-getchildrentest", flags=0) + self.ensureCreated("/zk-python-getchildrentest/child") + + watched = [] + + def watcher(*args): + self.cv.acquire() + watched.append(args) + self.cv.notify() + self.cv.release() + + def children_callback(*args): + self.cv.acquire() + self.cv.notify() + self.cv.release() + + zookeeper.aget_children( + self.handle, "/zk-python-getchildrentest", watcher, children_callback) + + self.cv.acquire() + self.cv.wait() + self.cv.release() + + self.cv.acquire() + self.ensureCreated("/zk-python-getchildrentest/child2") + self.cv.wait(15) + self.assertTrue(watched) + +if __name__ == '__main__': + unittest.main() diff --git a/src/contrib/zkpython/src/test/run_tests.sh b/src/contrib/zkpython/src/test/run_tests.sh new file mode 100755 index 00000000000..18d924085d4 --- /dev/null +++ b/src/contrib/zkpython/src/test/run_tests.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: run_tests.sh testdir [logdir] +# logdir is optional, defaults to cwd + +# get the number of command-line arguments given +ARGC=$# + +# check to make sure enough arguments were given or exit +if [ $ARGC -lt 2 ]; then + export ZKPY_LOG_DIR="." +else + export ZKPY_LOG_DIR=$2 +fi + +# Find the build directory containing zookeeper.so +SO_PATH=`find ../../../build/ -name "zookeeper.so" | head -1` +PYTHONPATH=`dirname $SO_PATH` +LIB_PATH=../../c/.libs/:../../../build/test/test-cppunit/.libs +for test in `ls $1/*_test.py`; +do + echo "Running $test" + LD_LIBRARY_PATH=$LIB_PATH:$LD_LIBRARY_PATH DYLD_LIBRARY_PATH=$LIB_PATH:$DYLD_LIBRARY_PATH PYTHONPATH=$PYTHONPATH python $test +done diff --git a/src/contrib/zkpython/src/test/zkServer.sh b/src/contrib/zkpython/src/test/zkServer.sh new file mode 100755 index 00000000000..51d508f6969 --- /dev/null +++ b/src/contrib/zkpython/src/test/zkServer.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if [ "x$1" == "x" ] +then + echo "USAGE: $0 startClean|start|stop hostPorts" + exit 2 +fi + +if [ "x$1" == "xstartClean" ] +then + if [ "x${base_dir}" == "x" ] + then + rm -rf /tmp/zkdata + else + rm -rf ${base_dir}/build/tmp + fi +fi + +if [ "x${base_dir}" == "x" ] +then +zk_base="../../../" +else +zk_base="${base_dir}" +fi + +CLASSPATH="$CLASSPATH:${zk_base}/build/classes" +CLASSPATH="$CLASSPATH:${zk_base}/conf" + +for i in "${zk_base}"/build/lib/*.jar +do + CLASSPATH="$CLASSPATH:$i" +done + +for i in "${zk_base}"/src/java/lib/*.jar +do + CLASSPATH="$CLASSPATH:$i" +done + +# Make sure nothing is left over from before +#fuser -skn tcp 22182/tcp + +case $1 in +start|startClean) + if [ "x${base_dir}" == "x" ] + then + mkdir -p /tmp/zkdata + java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22182 /tmp/zkdata &> /tmp/zk.log & + else + mkdir -p ${base_dir}/build/tmp/zkdata + java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22182 ${base_dir}/build/tmp/zkdata &> ${base_dir}/build/tmp/zk.log & + fi + sleep 5 + ;; +stop) + # Already killed above + ;; +*) + echo "Unknown command " + $1 + exit 2 +esac + diff --git a/src/contrib/zkpython/src/test/zktestbase.py b/src/contrib/zkpython/src/test/zktestbase.py new file mode 100755 index 00000000000..8229418e3e7 --- /dev/null +++ b/src/contrib/zkpython/src/test/zktestbase.py @@ -0,0 +1,101 @@ +#!/usr/bin/python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import unittest, threading, zookeeper +ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"} + +class TestBase(unittest.TestCase): + SERVER_PORT = 22182 + + def __init__(self,methodName='runTest'): + unittest.TestCase.__init__(self,methodName) + self.host = "localhost:%d" % self.SERVER_PORT + self.connected = False + self.handle = -1 + logdir = os.environ.get("ZKPY_LOG_DIR") + logfile = os.path.join(logdir, self.__class__.__name__ + ".log") + try: + f = open(logfile,"w") + zookeeper.set_log_stream(f) + except IOError: + print("Couldn't open " + logfile + " for writing") + + + def setUp(self): + self.callback_flag = False + self.cv = threading.Condition() + self.connected = False + def connection_watcher(handle, type, state, path): + self.cv.acquire() + self.connected = True + self.cv.notify() + self.cv.release() + + self.cv.acquire() + self.handle = zookeeper.init(self.host, connection_watcher) + self.cv.wait(15.0) + self.cv.release() + + if not self.connected: + raise Exception("Couldn't connect to host -", self.host) + + def newConnection(self): + cv = threading.Condition() + self.pending_connection = False + def connection_watcher(handle, type, state, path): + cv.acquire() + self.pending_connection = True + cv.notify() + cv.release() + + cv.acquire() + handle = zookeeper.init(self.host, connection_watcher) + cv.wait(15.0) + cv.release() + + if not self.pending_connection: + raise Exception("Couldn't connect to host -", self.host) + return handle + + def ensureDeleted(self,path): + self.assertEqual(zookeeper.CONNECTED_STATE, zookeeper.state(self.handle), "Not connected!") + try: + self.assertEqual(zookeeper.OK, zookeeper.delete(self.handle, path)) + except zookeeper.NoNodeException: + pass + + def ensureCreated(self,path,data="",flags=zookeeper.EPHEMERAL): + """ + It's possible not to get the flags you want here if the node already exists + """ + self.assertEqual(zookeeper.CONNECTED_STATE, zookeeper.state(self.handle), "Not connected!") + try: + self.assertEqual(path, zookeeper.create(self.handle, path, data, [ZOO_OPEN_ACL_UNSAFE], flags)) + except zookeeper.NodeExistsException: + pass + + def tearDown(self): + if self.connected: + zookeeper.close(self.handle) + + def all(self, iterable): + for element in iterable: + if not element: + return False + return True diff --git a/src/contrib/zktreeutil/Makefile.am b/src/contrib/zktreeutil/Makefile.am new file mode 100644 index 00000000000..36da1a50d4e --- /dev/null +++ b/src/contrib/zktreeutil/Makefile.am @@ -0,0 +1,4 @@ +## Process this file with automake to produce Makefile.in + +SUBDIRS = src + diff --git a/src/contrib/zktreeutil/README.txt b/src/contrib/zktreeutil/README.txt new file mode 100644 index 00000000000..43b06fa72c2 --- /dev/null +++ b/src/contrib/zktreeutil/README.txt @@ -0,0 +1,74 @@ +========================================== +zktreeutil - Zookeeper Tree Data Utility +Author: Anirban Roy +Organization: Yahoo Inc. +========================================== + +zktreeutil program is intended to manage and manipulate zk-tree data quickly, effi- +ciently and with ease. The utility operates on free-form ZK-tree and hence can be used +for any cluster managed by Zookeeper. Here are the basic functionalities - + +EXPORT: The whole/partial ZK-tree is exported into a XML file. This helps in +capturing a current snapshot of the data for backup/analysis. For a subtree +export, one need to specify the path to the ZK-subtree with proper option. + +IMPORT: The ZK-tree can be imported from XML into ZK cluster. This helps in priming +the new ZK cluster with static configuration. The import can be non-intrusive by +making only the additions in the existing data. The import of subtree is also +possible by optionally providing the path to the ZK-subtree. + +DIFF: Creates a diff between live ZK data vs data saved in XML file. Diff can ignore +some ZK-tree branches (possibly dynamic data) on reading the optional ignore flag +from XML file. Diffing on a ZK-subtree achieved by providing path to ZK-subtree with +diff command. + +UPDATE: Make the incremental changes into the live ZK-tree from saved XML, essentia- +lly after running the diff. + +DUMP: Dumps the ZK-tree on the standard output device reading either from live ZK +server or XML file. Like export, ZK-subtree can be dumped with optionaly +providing the path to the ZK-subtree, and till a certain depth of the (sub)tree. + +The exported ZK data into XML file can be shortened by only keeping the static ZK +nodes which are required to prime a cluster. The dynamic zk nodes (created on-the- +fly) can be ignored by setting a 'ignore' attribute at the root node of the dynamic +subtree (see tests/zk_sample.xml), possibly deleting all inner ZK nodes under that. +Once ignored, the whole subtree is ignored during DIFF, UPDATE and WRITE. + +Pre-requisites +-------------- +1. Linux system with 2.6.X kernel. +2. Zookeeper C client library (locally built at ../../c/.libs) >= 3.X.X +3. Development build libraries (rpm packages): + a. boost-devel >= 1.32.0 + b. libxml2-devel >= 2.7.3 + c. log4cxx0100-devel >= 0.10.0 + +Build instructions +------------------ +1. cd into this directory +2. autoreconf -if +3. ./configure +4. make +5. 'zktreeutil' binary created under src directory + +Limitations +----------- +Current version works with text data only, binary data will be supported in future +versions. + +Testing and usage of zktreeutil +-------------------------------- +1. Run Zookeeper server locally on port 2181 +2. export LD_LIBRARY_PATH=../../c/.libs/:/usr/local/lib/ +3. ./src/zktreeutil --help # show help +4. ./src/zktreeutil --zookeeper=localhost:2181 --import --xmlfile=tests/zk_sample.xml 2>/dev/null # import sample ZK tree +5. ./src/zktreeutil --zookeeper=localhost:2181 --dump --path=/myapp/version-1.0 2>/dev/null # dump Zk subtree +5. ./src/zktreeutil --zookeeper=localhost:2181 --dump --depth=3 2>/dev/null # dump Zk tree till certain depth +6. ./src/zktreeutil --xmlfile=zk_sample.xml -D 2>/dev/null # dump the xml data +7. Change zk_sample.xml with adding/deleting/chaging some nodes +8. ./src/zktreeutil -z localhost:2181 -F -x zk_sample.xml -p /myapp/version-1.0/configuration 2>/dev/null # take a diff of changes +9. ./src/zktreeutil -z localhost:2181 -E 2>/dev/null > zk_sample2.xml # export the mofied ZK tree +10. ./src/zktreeutil -z localhost:2181 -U -x zk_sample.xml -p /myapp/version-1.0/distributions 2>/dev/null # update with incr. changes +11. ./src/zktreeutil --zookeeper=localhost:2181 --import --force --xmlfile=zk_sample2.xml 2>/dev/null # re-prime the ZK tree + diff --git a/src/contrib/zktreeutil/build.xml b/src/contrib/zktreeutil/build.xml new file mode 100644 index 00000000000..bea8a318694 --- /dev/null +++ b/src/contrib/zktreeutil/build.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zktreeutil/configure.ac b/src/contrib/zktreeutil/configure.ac new file mode 100644 index 00000000000..b4a82a76af8 --- /dev/null +++ b/src/contrib/zktreeutil/configure.ac @@ -0,0 +1,66 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) + +AC_INIT([zktreeutil], [1.0.0]) +AM_INIT_AUTOMAKE(foreign) + +AC_CONFIG_SRCDIR([src]) +AM_CONFIG_HEADER([config.h]) + +PACKAGE=zktreeutil +VERSION=1.0.0 + +AC_SUBST(PACKAGE) +AC_SUBST(VERSION) +BUILD_PATH="`pwd`" + +# Checks for programs. +AC_LANG_CPLUSPLUS +AC_PROG_CXX + +# Checks for libxm2. +AM_PATH_XML2(2.7.3) +XML2_INCLUDE="/usr/include/libxml2" +AC_SUBST(XML2_INCLUDE) + +# Zookeeper C client +ZOOKEEPER_PATH=${BUILD_PATH}/../../c +AC_CHECK_LIB(zookeeper_mt, main, [ZOOKEEPER="-L${ZOOKEEPER_PATH}/.libs -lzookeeper_mt"],,["-L${ZOOKEEPER_PATH}/.libs"]) +if test -z "${ZOOKEEPER}"; then + AC_ERROR("... zookeeper C client not found!") +fi + +AC_SUBST(ZOOKEEPER) +AC_SUBST(ZOOKEEPER_PATH) + +### log4cxx ### + +LOG4CXX_VERSION="0.10.0" +LOG4CXX_INCLUDE="/usr/local/include" +LOG4CXX_LIB_PATH="/usr/local/lib" +AC_CHECK_LIB(log4cxx, main, [LOG4CXX="-L${LOG4CXX_LIB_PATH} -llog4cxx"],,["-L${LOG4CXX_LIB_PATH}"]) +if test -z "${LOG4CXX}"; then + AC_ERROR("... log4cxx not found!") +fi + +AC_SUBST(LOG4CXX) +AC_SUBST(LOG4CXX_VERSION) +AC_SUBST(LOG4CXX_INCLUDE) + +# Checks for header files. +AC_HEADER_DIRENT +AC_HEADER_STDC +AC_CHECK_HEADERS([stdlib.h string.h stdio.h unistd.h boost/shared_ptr.hpp boost/algorithm/string.hpp boost/algorithm/string/split.hpp]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_HEADER_STDBOOL +AC_C_CONST +AC_C_INLINE +AC_TYPE_SIZE_T +AC_C_VOLATILE + +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([src/Makefile]) +AC_OUTPUT diff --git a/src/contrib/zktreeutil/src/Makefile.am b/src/contrib/zktreeutil/src/Makefile.am new file mode 100644 index 00000000000..641077a88e4 --- /dev/null +++ b/src/contrib/zktreeutil/src/Makefile.am @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +AM_CXXFLAGS = -I${ZOOKEEPER_PATH}/include -I${ZOOKEEPER_PATH}/generated \ + -I$(top_srcdir)/include -I${LOG4CXX_INCLUDE} -I/usr/include \ + -I${XML2_INCLUDE} + +bin_PROGRAMS = zktreeutil + +zktreeutil_SOURCES = ZkAdaptor.cc ZkTreeUtil.cc ZkTreeUtilMain.cc +zktreeutil_LDADD = ${ZOOKEEPER} ${XML_LIBS} ${LOG4CXX} diff --git a/src/contrib/zktreeutil/src/SimpleTree.h b/src/contrib/zktreeutil/src/SimpleTree.h new file mode 100644 index 00000000000..8226f05c9e1 --- /dev/null +++ b/src/contrib/zktreeutil/src/SimpleTree.h @@ -0,0 +1,150 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SIMPLE_TREE_H__ +#define __SIMPLE_TREE_H__ + +#include +#include + +namespace zktreeutil +{ + using std::vector; + + /** + * \brief A simple tree data-structure template. + */ + template < class KeyType, class DataType > class SimpleTreeNode + { + private: + /** + * \brief The type representing simple-tree node smart-pointer. + */ + typedef boost::shared_ptr< SimpleTreeNode< KeyType, DataType > > SimpleTreeNodeSptr; + + public: + /** + * \brief Constructor. + * + * @param isRoot the flag indicating whether the node is root. + */ + SimpleTreeNode (bool isRoot=false) : isRoot_(isRoot) + { + } + + /** + * \brief Constructor. + * + * @param key the key stored at the tree node + * @param isRoot the flag indicating whether the node is root + */ + SimpleTreeNode (const KeyType& key, bool isRoot=false) : + isRoot_(isRoot), key_(key) + { + } + + /** + * \brief Constructor. + * + * @param key the key stored at the tree node + * @param val the value stored at the tree node + * @param isRoot the flag indicating whether the node is root + */ + SimpleTreeNode (const KeyType& key, const DataType& val, bool isRoot=false) : + isRoot_(isRoot), key_(key), val_(val) + { + } + + /** + * \brief Destructor. + */ + ~SimpleTreeNode () throw() {} + + /** + * \brief Add a child node to this node. + * + * @param node the child node to be added + */ + void addChild (const SimpleTreeNodeSptr node) { children_.push_back (node); } + + /** + * \brief Sets the key of this node. + * + * @param key the key to be set + */ + void setKey (const KeyType& key) { key_ = key; } + + /** + * \brief Sets the data of this node. + * + * @param val the value to be set + */ + void setData (const DataType& val) { val_ = val; } + + /** + * \brief Gets the key of this node. + * + * @return the key of this node + */ + KeyType getKey () const { return key_; } + + /** + * \brief Gets the data of this node. + * + * @return the value of this node + */ + DataType getData () const { return val_; } + + /** + * \brief Gets the i'th of this node. + * + * @param idx the index of the child node + * @return the child node + */ + SimpleTreeNodeSptr getChild (unsigned idx) const { return children_[idx]; } + + /** + * \brief Gets the number of children of this node. + * + * @return the number of children + */ + unsigned numChildren () const { return children_.size(); } + + /** + * \brief Indicates whether this node is root. + * + * @return 'true' if this node is root, 'false' otherwise + */ + bool isRoot () const { return isRoot_; } + + /** + * \brief Indicates whether this node is leaf node. + * + * @return 'true' if this node is leaf node, 'false' otherwise + */ + bool isLeaf () const { return !numChildren(); } + + private: + bool isRoot_; // Flag indicates if the node is root + KeyType key_; // Key of this node + DataType val_; // Value of this node + vector< SimpleTreeNodeSptr > children_; // List of children of this node + }; +} + +#endif // __SIMPLE_TREE_H__ diff --git a/src/contrib/zktreeutil/src/ZkAdaptor.cc b/src/contrib/zktreeutil/src/ZkAdaptor.cc new file mode 100644 index 00000000000..baec8f9b0fa --- /dev/null +++ b/src/contrib/zktreeutil/src/ZkAdaptor.cc @@ -0,0 +1,513 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ZkAdaptor.h" +#include +#include +#include +#include +#include + +// Logger +static log4cxx::LoggerPtr zkLoggerPtr = log4cxx::Logger::getLogger ("zookeeper.core"); + +namespace zktreeutil +{ + /** + * \brief This class provides logic for checking if a request can be retried. + */ + class RetryHandler + { + public: + RetryHandler(const ZooKeeperConfig &zkConfig) : m_zkConfig(zkConfig) + { + if (zkConfig.getAutoReconnect()) + retries = 2; + else + retries = 0; + } + + /** + * \brief Attempts to fix a side effect of the given RC. + * + * @param rc the ZK error code + * @return whether the error code has been handled and the caller should + * retry an operation the caused this error + */ + bool handleRC(int rc) + { + //check if the given error code is recoverable + if (!retryOnError(rc)) + return false; + + std::cerr << "[zktreeuti] Number of retries left: " << retries << std::endl; + if (retries-- > 0) + return true; + else + return false; + } + + private: + /** + * The ZK config. + */ + const ZooKeeperConfig &m_zkConfig; + + /** + * The number of outstanding retries. + */ + int retries; + + /** + * Checks whether the given error entitles this adapter + * to retry the previous operation. + * + * @param zkErrorCode one of the ZK error code + */ + static bool retryOnError(int zkErrorCode) + { + return (zkErrorCode == ZCONNECTIONLOSS || zkErrorCode == ZOPERATIONTIMEOUT); + } + }; + + + // ======================================================================= + + ZooKeeperAdapter::ZooKeeperAdapter(ZooKeeperConfig config) throw(ZooKeeperException) : + m_zkConfig(config), + mp_zkHandle(NULL) + { + // Enforce setting up appropriate ZK log level + if (zkLoggerPtr->isDebugEnabled() +#ifdef LOG4CXX_TRACE + || zkLoggerPtr->isTraceEnabled() +#endif + ) + { + zoo_set_debug_level( ZOO_LOG_LEVEL_DEBUG ); + } else if (zkLoggerPtr->isInfoEnabled()) { + zoo_set_debug_level( ZOO_LOG_LEVEL_INFO ); + } else if (zkLoggerPtr->isWarnEnabled()) { + zoo_set_debug_level( ZOO_LOG_LEVEL_WARN ); + } else { + zoo_set_debug_level( ZOO_LOG_LEVEL_ERROR ); + } + + // Establish the connection + reconnect(); + } + + ZooKeeperAdapter::~ZooKeeperAdapter() + { + try + { + disconnect(); + } + catch (std::exception &e) + { + std::cerr << "[zktreeutil] An exception while disconnecting from ZK: " + << e.what() + << std::endl; + } + } + + void ZooKeeperAdapter::validatePath(const string &path) throw(ZooKeeperException) + { + if (path.find ("/") != 0) + { + std::ostringstream oss; + oss << "Node path must start with '/' but" "it was '" + << path + << "'"; + throw ZooKeeperException (oss.str()); + } + if (path.length() > 1) + { + if (path.rfind ("/") == path.length() - 1) + { + std::ostringstream oss; + oss << "Node path must not end with '/' but it was '" + << path + << "'"; + throw ZooKeeperException (oss.str()); + } + if (path.find( "//" ) != string::npos) + { + std::ostringstream oss; + oss << "Node path must not contain '//' but it was '" + << path + << "'"; + throw ZooKeeperException (oss.str()); + } + } + } + + void ZooKeeperAdapter::disconnect() + { + if (mp_zkHandle != NULL) + { + zookeeper_close (mp_zkHandle); + mp_zkHandle = NULL; + } + } + + void ZooKeeperAdapter::reconnect() throw(ZooKeeperException) + { + // Clear the connection state + disconnect(); + + // Establish a new connection to ZooKeeper + mp_zkHandle = zookeeper_init( m_zkConfig.getHosts().c_str(), + NULL, + m_zkConfig.getLeaseTimeout(), + 0, + NULL, + 0); + if (mp_zkHandle == NULL) + { + // Invalid handle returned + std::ostringstream oss; + oss << "Unable to connect to ZK running at '" + << m_zkConfig.getHosts() + << "'"; + throw ZooKeeperException (oss.str()); + } + + // Enter into connect loop + int64_t connWaitTime = m_zkConfig.getConnectTimeout(); + while (1) + { + int state = zoo_state (mp_zkHandle); + if (state == ZOO_CONNECTED_STATE) + { + // connected + std::cerr << "[zktreeutil] Connected! mp_zkHandle: " + << mp_zkHandle + << std::endl; + return; + } + else if ( state && state != ZOO_CONNECTING_STATE) + { + // Not connecting any more... some other issue + std::ostringstream oss; + oss << "Unable to connect to ZK running at '" + << m_zkConfig.getHosts() + << "'; state=" + << state; + throw ZooKeeperException (oss.str()); + } + + // Still connecting, wait and come back + struct timeval now; + gettimeofday( &now, NULL ); + int64_t milliSecs = -(now.tv_sec * 1000LL + now.tv_usec / 1000); + std::cerr << "[zktreeutil] About to wait 1 sec" << std::endl; + sleep (1); + gettimeofday( &now, NULL ); + milliSecs += now.tv_sec * 1000LL + now.tv_usec / 1000; + connWaitTime -= milliSecs; + // Timed out !!! + if (connWaitTime <= 0) + break; + } + + // Timed out while connecting + std::ostringstream oss; + oss << "Timed out while connecting to ZK running at '" + << m_zkConfig.getHosts() + << "'"; + throw ZooKeeperException (oss.str()); + } + + void ZooKeeperAdapter::verifyConnection() throw(ZooKeeperException) + { + // Check connection state + int state = zoo_state (mp_zkHandle); + if (state != ZOO_CONNECTED_STATE) + { + if (m_zkConfig.getAutoReconnect()) + { + // Trying to reconnect + std::cerr << "[zktreeutil] Trying to reconnect..." << std::endl; + reconnect(); + } + else + { + std::ostringstream oss; + oss << "Disconnected from ZK running at '" + << m_zkConfig.getHosts() + << "'; state=" + << state; + throw ZooKeeperException (oss.str()); + } + } + } + + bool ZooKeeperAdapter::createNode(const string &path, + const string &value, + int flags, + bool createAncestors) throw(ZooKeeperException) + { + const int MAX_PATH_LENGTH = 1024; + char realPath[MAX_PATH_LENGTH]; + realPath[0] = 0; + + int rc; + RetryHandler rh(m_zkConfig); + do + { + verifyConnection(); + rc = zoo_create( mp_zkHandle, + path.c_str(), + value.c_str(), + value.length(), + &ZOO_OPEN_ACL_UNSAFE, + flags, + realPath, + MAX_PATH_LENGTH ); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) // check return status + { + if (rc == ZNODEEXISTS) + { + //the node already exists + std::cerr << "[zktreeutil] ZK node " << path << " already exists" << std::endl; + return false; + } + else if (rc == ZNONODE && createAncestors) + { + std::cerr << "[zktreeutil] Intermediate ZK node missing in path " << path << std::endl; + //one of the ancestors doesn't exist so lets start from the root + //and make sure the whole path exists, creating missing nodes if + //necessary + for (string::size_type pos = 1; pos != string::npos; ) + { + pos = path.find( "/", pos ); + if (pos != string::npos) + { + try + { + createNode( path.substr( 0, pos ), "", 0, true ); + } + catch (ZooKeeperException &e) + { + throw ZooKeeperException( string("Unable to create " "node ") + path, rc ); + } + pos++; + } + else + { + // No more path components + return createNode( path, value, flags, false ); + } + } + } + + // Unexpected error during create + std::cerr << "[zktreeutil] Error in creating ZK node " << path << std::endl; + throw ZooKeeperException( string("Unable to create node ") + path, rc ); + } + + // Success + std::cerr << "[zktreeutil] " << realPath << " has been created" << std::endl; + return true; + } + + bool ZooKeeperAdapter::deleteNode(const string &path, + bool recursive, + int version) throw(ZooKeeperException) + { + // Validate the zk path + validatePath( path ); + + int rc; + RetryHandler rh(m_zkConfig); + do + { + verifyConnection(); + rc = zoo_delete( mp_zkHandle, path.c_str(), version ); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) //check return status + { + if (rc == ZNONODE) + { + std::cerr << "[zktreeutil] ZK Node " + << path + << " does not exist" + << std::endl; + return false; + } + if (rc == ZNOTEMPTY && recursive) + { + std::cerr << "[zktreeutil] ZK Node " + << path + << " not empty; deleting..." + << std::endl; + //get all children and delete them recursively... + vector nodeList = getNodeChildren (path); + for (vector::const_iterator i = nodeList.begin(); + i != nodeList.end(); + ++i) { + deleteNode( *i, true ); + } + //...and finally attempt to delete the node again + return deleteNode( path, false ); + } + + // Unexpected return without success + std::cerr << "[zktreeutil] Unable to delete ZK node " << path << std::endl; + throw ZooKeeperException( string("Unable to delete node ") + path, rc ); + } + + // success + std::cerr << "[zktreeutil] " << path << " has been deleted" << std::endl; + return true; + } + + vector< string > ZooKeeperAdapter::getNodeChildren (const string &path) throw (ZooKeeperException) + { + // Validate the zk path + validatePath( path ); + + String_vector children; + memset( &children, 0, sizeof(children) ); + int rc; + RetryHandler rh(m_zkConfig); + do + { + verifyConnection(); + rc = zoo_get_children( mp_zkHandle, + path.c_str(), + 0, + &children ); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) // check return code + { + std::cerr << "[zktreeutil] Error in fetching children of " << path << std::endl; + throw ZooKeeperException( string("Unable to get children of node ") + path, rc ); + } + else + { + vector< string > nodeList; + for (int i = 0; i < children.count; ++i) + { + //convert each child's path from relative to absolute + string absPath(path); + if (path != "/") + { + absPath.append( "/" ); + } + absPath.append( children.data[i] ); + nodeList.push_back( absPath ); + } + + //make sure the order is always deterministic + sort( nodeList.begin(), nodeList.end() ); + return nodeList; + } + } + + bool ZooKeeperAdapter::nodeExists(const string &path) throw(ZooKeeperException) + { + // Validate the zk path + validatePath( path ); + + struct Stat tmpStat; + struct Stat* stat = &tmpStat; + memset( stat, 0, sizeof(Stat) ); + + int rc; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + rc = zoo_exists( mp_zkHandle, + path.c_str(), + 0, + stat ); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) + { + if (rc == ZNONODE) + return false; + // Some error + std::cerr << "[zktreeutil] Error in checking existance of " << path << std::endl; + throw ZooKeeperException( string("Unable to check existence of node ") + path, rc ); + } else { + return true; + } + } + + string ZooKeeperAdapter::getNodeData(const string &path) throw(ZooKeeperException) + { + // Validate the zk path + validatePath( path ); + + const int MAX_DATA_LENGTH = 128 * 1024; + char buffer[MAX_DATA_LENGTH]; + memset( buffer, 0, MAX_DATA_LENGTH ); + struct Stat tmpStat; + struct Stat* stat = &tmpStat; + memset( stat, 0, sizeof(Stat) ); + + int rc; + int len; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + len = MAX_DATA_LENGTH - 1; + rc = zoo_get( mp_zkHandle, + path.c_str(), + 0, + buffer, &len, stat ); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) // checl return code + { + std::cerr << "[zktreeutil] Error in fetching value of " << path << std::endl; + throw ZooKeeperException( string("Unable to get data of node ") + path, rc ); + } + + // return data + return string( buffer, buffer + len ); + } + + void ZooKeeperAdapter::setNodeData(const string &path, + const string &value, + int version) throw(ZooKeeperException) + { + // Validate the zk path + validatePath( path ); + + int rc; + RetryHandler rh(m_zkConfig); + do { + verifyConnection(); + rc = zoo_set( mp_zkHandle, + path.c_str(), + value.c_str(), + value.length(), + version); + } while (rc != ZOK && rh.handleRC(rc)); + if (rc != ZOK) // check return code + { + std::cerr << "[zktreeutil] Error in setting value of " << path << std::endl; + throw ZooKeeperException( string("Unable to set data for node ") + path, rc ); + } + // success + } + +} /* end of 'namespace zktreeutil' */ diff --git a/src/contrib/zktreeutil/src/ZkAdaptor.h b/src/contrib/zktreeutil/src/ZkAdaptor.h new file mode 100644 index 00000000000..d94b033c51b --- /dev/null +++ b/src/contrib/zktreeutil/src/ZkAdaptor.h @@ -0,0 +1,327 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __ZK_ADAPTER_H__ +#define __ZK_ADAPTER_H__ + +#include +#include + +extern "C" { +#include "zookeeper.h" +} + +namespace zktreeutil +{ + using std::string; + using std::vector; + + /** + * \brief A cluster related exception. + */ + class ZooKeeperException : public std::exception + { + public: + + /** + * \brief Constructor. + * + * @param msg the detailed message associated with this exception + */ + ZooKeeperException(const string& msg) : + m_message(msg), + m_zkErrorCode(0) {} + + /** + * \brief Constructor. + * + * @param msg the detailed message associated with this exception + * @param errorCode the ZK error code associated with this exception + */ + ZooKeeperException(const string &msg, int errorCode) : + m_zkErrorCode(errorCode) + { + char tmp[100]; + sprintf( tmp, " (ZK error code: %d)", errorCode ); + m_message = msg + tmp; + } + + /** + * \brief Destructor. + */ + ~ZooKeeperException() throw() {} + + /** + * \brief Returns detailed description of the exception. + */ + const char *what() const throw() + { + return m_message.c_str(); + } + + /** + * \brief Returns the ZK error code. + */ + int getZKErrorCode() const + { + return m_zkErrorCode; + } + + private: + + /** + * The detailed message associated with this exception. + */ + string m_message; + + /** + * The optional error code received from ZK. + */ + int m_zkErrorCode; + + }; + + /** + * \brief This class encapsulates configuration of a ZK client. + */ + class ZooKeeperConfig + { + public: + + /** + * \brief Constructor. + * + * @param hosts the comma separated list of host and port pairs of ZK nodes + * @param leaseTimeout the lease timeout (heartbeat) + * @param autoReconnect whether to allow for auto-reconnect + * @param connectTimeout the connect timeout, in milliseconds; + */ + ZooKeeperConfig(const string &hosts, + int leaseTimeout, + bool autoReconnect = true, + long long int connectTimeout = 15000) + : m_hosts(hosts), + m_leaseTimeout(leaseTimeout), + m_autoReconnect(autoReconnect), + m_connectTimeout(connectTimeout) {} + + /** + * \brief Returns the list of ZK hosts to connect to. + */ + string getHosts() const { return m_hosts; } + + /** + * \brief Returns the lease timeout. + */ + int getLeaseTimeout() const { return m_leaseTimeout; } + + /** + * \brief Returns whether {@link ZooKeeperAdapter} should attempt + * \brief to automatically reconnect in case of a connection failure. + */ + bool getAutoReconnect() const { return m_autoReconnect; } + + /** + * \brief Gets the connect timeout. + * + * @return the connect timeout + */ + long long int getConnectTimeout() const { return m_connectTimeout; } + + private: + + /** + * The host addresses of ZK nodes. + */ + const string m_hosts; + + /** + * The ZK lease timeout. + */ + const int m_leaseTimeout; + + /** + * True if this adapater should attempt to autoreconnect in case + * the current session has been dropped. + */ + const bool m_autoReconnect; + + /** + * How long to wait, in milliseconds, before a connection + * is established to ZK. + */ + const long long int m_connectTimeout; + }; + + /** + * \brief This is a wrapper around ZK C synchrounous API. + */ + class ZooKeeperAdapter + { + public: + /** + * \brief Constructor. + * Attempts to create a ZK adapter, optionally connecting + * to the ZK. Note, that if the connection is to be established + * and the given listener is NULL, some events may be lost, + * as they may arrive asynchronously before this method finishes. + * + * @param config the ZK configuration + * @throw ZooKeeperException if cannot establish connection to the given ZK + */ + ZooKeeperAdapter(ZooKeeperConfig config) throw(ZooKeeperException); + + /** + * \brief Destructor. + */ + ~ZooKeeperAdapter(); + + /** + * \brief Returns the current config. + */ + const ZooKeeperConfig &getZooKeeperConfig() const { return m_zkConfig; } + + /** + * \brief Restablishes connection to the ZK. + * If this adapter is already connected, the current connection + * will be dropped and a new connection will be established. + * + * @throw ZooKeeperException if cannot establish connection to the ZK + */ + void reconnect() throw(ZooKeeperException); + + /** + * \brief Disconnects from the ZK and unregisters {@link #mp_zkHandle}. + */ + void disconnect(); + + /** + * \brief Creates a new node identified by the given path. + * This method will optionally attempt to create all missing ancestors. + * + * @param path the absolute path name of the node to be created + * @param value the initial value to be associated with the node + * @param flags the ZK flags of the node to be created + * @param createAncestors if true and there are some missing ancestor nodes, + * this method will attempt to create them + * + * @return true if the node has been successfully created; false otherwise + * @throw ZooKeeperException if the operation has failed + */ + bool createNode(const string &path, + const string &value = "", + int flags = 0, + bool createAncestors = true) throw(ZooKeeperException); + + /** + * \brief Deletes a node identified by the given path. + * + * @param path the absolute path name of the node to be deleted + * @param recursive if true this method will attempt to remove + * all children of the given node if any exist + * @param version the expected version of the node. The function will + * fail if the actual version of the node does not match + * the expected version + * + * @return true if the node has been deleted; false otherwise + * @throw ZooKeeperException if the operation has failed + */ + bool deleteNode(const string &path, + bool recursive = false, + int version = -1) throw(ZooKeeperException); + + /** + * \brief Retrieves list of all children of the given node. + * + * @param path the absolute path name of the node for which to get children + * @return the list of absolute paths of child nodes, possibly empty + * @throw ZooKeeperException if the operation has failed + */ + vector getNodeChildren( const string &path) throw(ZooKeeperException); + + /** + * \brief Check the existance of path to a znode. + * + * @param path the absolute path name of the znode + * @return TRUE if the znode exists; FALSE otherwise + * @throw ZooKeeperException if the operation has failed + */ + bool nodeExists(const string &path) throw(ZooKeeperException); + + /** + * \brief Gets the given node's data. + * + * @param path the absolute path name of the node to get data from + * + * @return the node's data + * @throw ZooKeeperException if the operation has failed + */ + string getNodeData(const string &path) throw(ZooKeeperException); + + /** + * \brief Sets the given node's data. + * + * @param path the absolute path name of the node to get data from + * @param value the node's data to be set + * @param version the expected version of the node. The function will + * fail if the actual version of the node does not match + * the expected version + * + * @throw ZooKeeperException if the operation has failed + */ + void setNodeData(const string &path, + const string &value, + int version = -1) throw(ZooKeeperException); + + /** + * \brief Validates the given path to a node in ZK. + * + * @param the path to be validated + * + * @throw ZooKeeperException if the given path is not valid + * (for instance it doesn't start with "/") + */ + static void validatePath(const string &path) throw(ZooKeeperException); + + private: + + /** + * Verifies whether the connection is established, + * optionally auto reconnecting. + * + * @throw ZooKeeperConnection if this client is disconnected + * and auto-reconnect failed or was not allowed + */ + void verifyConnection() throw(ZooKeeperException); + + private: + + /** + * The current ZK configuration. + */ + const ZooKeeperConfig m_zkConfig; + + /** + * The current ZK session. + */ + zhandle_t *mp_zkHandle; + }; + +} /* end of 'namespace zktreeutil' */ + +#endif /* __ZK_ADAPTER_H__ */ diff --git a/src/contrib/zktreeutil/src/ZkTreeUtil.cc b/src/contrib/zktreeutil/src/ZkTreeUtil.cc new file mode 100644 index 00000000000..83f0cbf3f94 --- /dev/null +++ b/src/contrib/zktreeutil/src/ZkTreeUtil.cc @@ -0,0 +1,705 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ZkTreeUtil.h" + +#include +#include +#include +#include +#include + +namespace zktreeutil +{ + using std::map; + using std::pair; + + static ZkTreeNodeSptr loadZkTree_ (ZooKeeperAdapterSptr zkHandle, + const string& path) + { + // Extract the node value + string value = zkHandle->getNodeData(path); + + // Extract nodename from the path + string nodename = "/"; + if (path != "/") + { + vector< string > nodes; + boost::split(nodes, path, boost::is_any_of ("/") ); + nodename = nodes[nodes.size()-1]; + } + + // Create tree-node with name and value + ZkTreeNodeSptr nodeSptr = ZkTreeNodeSptr (new ZkTreeNode (nodename, value)); + std::cerr << "[zktreeutil] loaded nodename: " + << nodename + << " value: " + << value + << std::endl; + + // Load all the children + vector< string > cnodes = zkHandle->getNodeChildren (path); + for (unsigned i = 0; i < cnodes.size(); i++) + nodeSptr->addChild (loadZkTree_ (zkHandle, cnodes[i])); + + // Return the constructed node + return nodeSptr; + } + + static ZkTreeNodeSptr loadZkTreeXml_ (xmlNode* xmlNodePtr) + { + // Null check + if (xmlNodePtr == NULL) + { + std::cerr << "[zktreeutil] empty XML node encountered" << std::endl; + exit (-1); + } + + // Get the node name + xmlChar* name = xmlGetProp (xmlNodePtr, BAD_CAST "name"); + string nameStr = (const char*)name; + std::cerr << "[zktreeutil] node name: " << nameStr; + xmlFree (name); + // Get the node value + string valueStr; + xmlChar* value = xmlGetProp (xmlNodePtr, BAD_CAST "value"); + if (value) + { + valueStr = (const char*)value; + std::cerr << " value: " << valueStr; + } + xmlFree (value); + // Get the ignore flag + bool doIgnore = false; + xmlChar* ignore = xmlGetProp (xmlNodePtr, BAD_CAST "ignore"); + if (ignore) + { + string ignoreStr = (const char*) ignore; + if (ignoreStr == "true" || ignoreStr == "yes" || ignoreStr == "1") + { + doIgnore = true; + std::cerr << " "; + } + } + xmlFree (ignore); + std::cerr << std::endl; + + // Create the zk node + ZkTreeNodeSptr nodeSptr = + ZkTreeNodeSptr (new ZkTreeNode (nameStr, + ZkNodeData (valueStr, doIgnore))); + + // Load the children + for (xmlNode* chldNode = xmlNodePtr->children; + chldNode; + chldNode = chldNode->next) + if (chldNode->type == XML_ELEMENT_NODE) + nodeSptr->addChild (loadZkTreeXml_ (chldNode)); + + // Return the loaded node + return nodeSptr; + } + + static void writeZkTree_ (ZooKeeperAdapterSptr zkHandle, + const ZkTreeNodeSptr zkNodeSptr, + const string& path) + { + // Create the path in zk-tree + zkHandle->createNode(path.c_str(), "", 0, false); + std::cerr << "[zktreeutil] created key: " << path << std::endl; + // Set value for the path + string value = zkNodeSptr->getData().value; + if (value != "") + { + zkHandle->setNodeData (path.c_str(), value.c_str()); + std::cerr << "[zktreeutil] set value: " << std::endl; + } + + // Go deep to write the subtree rooted in the node, if not to be ignored + if (!(zkNodeSptr->getData().ignoreUpdate)) + { + for (unsigned i=0; i < zkNodeSptr->numChildren(); i++) + { + ZkTreeNodeSptr childNodeSptr = zkNodeSptr->getChild (i); + // Add the node name into the path and write in zk-tree + string cpath = ((path != "/")? path : "") + + string("/") + + childNodeSptr->getKey(); + writeZkTree_ (zkHandle, childNodeSptr, cpath); + } + } + + return; + } + + static void addTreeZkAction_ (const ZkTreeNodeSptr zkNodeSptr, + const string& path, + vector< ZkAction >& actions) + { + // Create the key + actions.push_back (ZkAction (ZkAction::CREATE, path)); + + // Set value for the new key + if (zkNodeSptr->getData().value != "") + actions.push_back (ZkAction (ZkAction::VALUE, + path, + zkNodeSptr->getData().value)); + + // Add all the children + for (unsigned i=0; i < zkNodeSptr->numChildren(); i++) + { + ZkTreeNodeSptr childSptr = zkNodeSptr->getChild (i); + string cpath = path + string("/") + childSptr->getKey(); + addTreeZkAction_ (childSptr, cpath, actions); + } + + return; + } + + static xmlNodePtr dumpZkTreeXml_ (const ZkTreeNodeSptr zkNodeSptr) + { + // Create xml node with zknode name and value + string nodename = zkNodeSptr->getKey (); + string value = zkNodeSptr->getData().value; + xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "zknode"); + xmlNewProp (node, BAD_CAST "name", BAD_CAST nodename.c_str()); + if (value.length()) + xmlNewProp (node, BAD_CAST "value", BAD_CAST value.c_str()); + + // Add all the children rotted at this node + for (unsigned i=0; i < zkNodeSptr->numChildren(); i++) + xmlAddChild (node, dumpZkTreeXml_ (zkNodeSptr->getChild (i))); + + // Return xml node + return node; + } + + static void dumpZkTree_ (const ZkTreeNodeSptr zkNodeSptr, + int maxLevel, + int level, + vector< bool >& masks) + { + // Check the max. dlevel to be dumped + if (level > maxLevel) + return; + + + // Create branch + for (int i=0; i < level; i++) + { + if ( i== level-1) std::cout << "| "; + else if (masks[i]) std::cout << " "; + else std::cout << "| "; + } + std::cout << std::endl; + for (int i=0; i < level-1; i++) + { + if (masks[i]) std::cout << " "; + else std::cout << "| "; + } + + // Dump the node name and value + std::cout << "|--[" << zkNodeSptr->getKey(); + if (zkNodeSptr->getData().value != "") + std::cout << " => " << zkNodeSptr->getData().value; + std::cout << "]" << std::endl; + + // Dump all the children + for (unsigned i=0; i < zkNodeSptr->numChildren(); i++) + { + // Add mask for last child + if (i == zkNodeSptr->numChildren()-1) + masks.push_back(true); + else + masks.push_back(false); + dumpZkTree_ (zkNodeSptr->getChild (i), maxLevel, level+1, masks); + } + + masks.pop_back(); + return; + } + + static ZkTreeNodeSptr traverseBranch_ (const ZkTreeNodeSptr& zkRootSptr, + const string& path) + { + // Check if the tree is loaded into memory + if (zkRootSptr == NULL) + { + string errMsg = "[zktreeutil] null root passed for traversing"; + std::cout << errMsg << std::endl; + throw std::logic_error (errMsg); + } + + // Split the path and add intermediate znodes + vector< string > nodes; + boost::split(nodes, path, boost::is_any_of ("/") ); + + // Start traversing the tree + ZkTreeNodeSptr currNodeSptr = zkRootSptr; + for (unsigned znode_idx = 1; znode_idx < nodes.size(); znode_idx++) + { + bool found = false; + for (unsigned i=0; i < currNodeSptr->numChildren(); i++) + { + ZkTreeNodeSptr childNodeSptr = currNodeSptr->getChild(i); + if (childNodeSptr->getKey() == nodes[znode_idx]) + { + // Found! go to the znode + currNodeSptr = childNodeSptr; + found = true; + break; + } + } + if (!found) // No such znode found; return NULL node-ptr + { + string errMsg = string("[zktreeutil] unknown znode during traversal: ") + + nodes[znode_idx]; + std::cout << errMsg << std::endl; + throw std::logic_error (errMsg); + } + } + + return currNodeSptr; + } + + static ZkTreeNodeSptr createAncestors_ (const string& path) + { + // Create the root znode + ZkTreeNodeSptr zkRootSptr = ZkTreeNodeSptr (new ZkTreeNode ("/")); + ZkTreeNodeSptr currNodeSptr = zkRootSptr; + // Split the path and add intermediate znodes + vector< string > nodes; + boost::split(nodes, path, boost::is_any_of ("/") ); + for (unsigned i=1; i < nodes.size()-1; i++) + { + ZkTreeNodeSptr childNodeSptr = ZkTreeNodeSptr (new ZkTreeNode (nodes[i])); + currNodeSptr->addChild (childNodeSptr); + currNodeSptr = childNodeSptr; + } + + //Return the root of the branch + return zkRootSptr; + } + + ZooKeeperAdapterSptr ZkTreeUtil::get_zkHandle (const string& zkHosts) + { + try + { + // Create an instance of ZK adapter. + ZooKeeperConfig config (zkHosts, 10000); + ZooKeeperAdapterSptr zkHandleSptr = + ZooKeeperAdapterSptr (new ZooKeeperAdapter (config)); + return zkHandleSptr; + } + catch (const ZooKeeperException &e) + { + std::cerr << "[zktreeutil] zooKeeper exception caught: " + << e.what() + << std::endl; + throw; + } + catch (std::exception &stde) + { + std::cerr << "[zktreeutil] standard exception caught: " + << stde.what() + << std::endl; + throw; + } + catch (...) + { + std::cerr + << "[zktreeutil] unknown exception while connecting to zookeeper" + << std::endl; + throw; + } + } + + + void ZkTreeUtil::loadZkTree (const string& zkHosts, + const string& path, + bool force) + { + // Check if already loaded + if (loaded_ && !force) + { + std::cerr << "[zktreeutil] zk-tree already loaded into memory" + << std::endl; + return; + } + + // Connect to ZK server + ZooKeeperAdapterSptr zkHandle = get_zkHandle (zkHosts); + std::cerr << "[zktreeutil] connected to ZK serverfor reading" + << std::endl; + + // Check the existance of the path to znode + if (!zkHandle->nodeExists (path)) + { + string errMsg = string("[zktreeutil] path does not exists : ") + path; + std::cout << errMsg << std::endl; + throw std::logic_error (errMsg); + } + + // Load the rooted (sub)tree + ZkTreeNodeSptr zkSubrootSptr = loadZkTree_ (zkHandle, path); + + // Create the ancestors before loading the rooted subtree + if (path != "/") + { + zkRootSptr_ = createAncestors_(path); + string ppath = path.substr (0, path.rfind('/')); + ZkTreeNodeSptr parentSptr = traverseBranch_( zkRootSptr_, ppath); + parentSptr->addChild (zkSubrootSptr); + } + else // Loaded entire zk-tree + { + zkRootSptr_ = zkSubrootSptr; + } + + // Set load flag + loaded_ = true; + return; + } + + void ZkTreeUtil::loadZkTreeXml (const string& zkXmlConfig, + bool force) + { + // Check if already loaded + if (loaded_ && !force) + { + std::cerr << "[zktreeutil] zk-tree already loaded into memory" + << std::endl; + return; + } + + // Parse the file and get the DOM + xmlDocPtr docPtr = xmlReadFile(zkXmlConfig.c_str(), NULL, 0); + if (docPtr == NULL) { + std::cerr << "[zktreeutil] could not parse XML file " + << zkXmlConfig + << std::endl; + exit (-1); + } + std::cerr << "[zktreeutil] zk-tree XML parsing successful" + << std::endl; + + // Get the root element node + xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr); + // Create the root zk node + zkRootSptr_ = ZkTreeNodeSptr (new ZkTreeNode ("/")); + // Load the rooted XML tree + for (xmlNode* chldNode = rootPtr->children; + chldNode; + chldNode = chldNode->next) + { + if (chldNode->type == XML_ELEMENT_NODE) + zkRootSptr_->addChild (loadZkTreeXml_ (chldNode)); + } + + // set oad flag + loaded_ = true; + // Cleanup stuff + xmlFreeDoc(docPtr); + xmlCleanupParser(); + return; + } + + void ZkTreeUtil::writeZkTree (const string& zkHosts, + const string& path, + bool force) const + { + // Connect to ZK server + ZooKeeperAdapterSptr zkHandle = get_zkHandle (zkHosts); + std::cerr << "[zktreeutil] connected to ZK server for writing" + << std::endl; + + // Go to the rooted subtree + ZkTreeNodeSptr zkRootSptr = traverseBranch_ (zkRootSptr_, path); + + // Cleanup before write if forceful write enabled + if (force) + { + if (path != "/") // remove the subtree rooted at the znode + { + // Delete the subtree rooted at the znode before write + if (zkHandle->nodeExists (path)) + { + std::cerr << "[zktreeutil] deleting subtree rooted at " + << path + << "..." + << std::endl; + zkHandle->deleteNode (path, true); + } + } + else // remove the rooted znodes + { + std::cerr << "[zktreeutil] deleting rooted zk-tree" + << "..." + << std::endl; + // Get the root's children + vector< string > cnodes = zkHandle->getNodeChildren ("/"); + for (unsigned i=0; i < cnodes.size(); i++) + { + if ( cnodes[i] != "/zookeeper") // reserved for zookeeper use + zkHandle->deleteNode(cnodes[i], true); + } + } + } + + // Start tree construction + writeZkTree_ (zkHandle, zkRootSptr, path); + return; + } + + void ZkTreeUtil::dumpZkTree (bool xml, int depth) const + { + if (xml) + { + // Creates a new document, a node and set it as a root node + xmlDocPtr docPtr = xmlNewDoc(BAD_CAST "1.0"); + xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "root"); + xmlDocSetRootElement(docPtr, rootNode); + + // Add all the rooted children + for (unsigned i=0; i < zkRootSptr_->numChildren(); i++) + xmlAddChild (rootNode, dumpZkTreeXml_ (zkRootSptr_->getChild (i))); + + // Dumping document to stdio or file + xmlSaveFormatFileEnc("-", docPtr, "UTF-8", 1); + + // Cleanup stuff + xmlFreeDoc(docPtr); + xmlCleanupParser(); + return; + } + + // Dump text + std::cout << "/" << std::endl; + vector< bool > masks; + for (unsigned i=0; i < zkRootSptr_->numChildren(); i++) + { + if (i == zkRootSptr_->numChildren()-1) + masks.push_back(true); + else + masks.push_back(false); + dumpZkTree_ (zkRootSptr_->getChild (i), depth, 1, masks); + } + + return; + } + + vector< ZkAction > ZkTreeUtil::diffZkTree (const string& zkHosts, + const string& path) const + { + // Action container + vector< ZkAction > actions; + + if (!loaded_) + { + std::cout << "[zktreeutil] zk-tree not loaded for diff" + << std::endl; + exit (-1); + } + + // Load the rooted subtree from zookeeper + ZooKeeperAdapterSptr zkHandle = get_zkHandle (zkHosts); + std::cerr << "[zktreeutil] connected to ZK server for reading" + << std::endl; + ZkTreeNodeSptr zkLiveRootSptr = loadZkTree_ (zkHandle, path); + + // Go to the saved rooted subtree + ZkTreeNodeSptr zkLoadedRootSptr = + traverseBranch_ (zkRootSptr_, path); + + // Check the root value first + if (zkLoadedRootSptr->getData().value + != zkLiveRootSptr->getData().value) + { + actions.push_back (ZkAction (ZkAction::VALUE, + path, + zkLoadedRootSptr->getData().value, + zkLiveRootSptr->getData().value)); + } + + // Start traversal from root + vector< string > ppaths; + vector< pair< ZkTreeNodeSptr, ZkTreeNodeSptr > > commonNodes; + ppaths.push_back ((path != "/")? path : ""); + commonNodes.push_back (pair< ZkTreeNodeSptr, ZkTreeNodeSptr > + (zkLoadedRootSptr, zkLiveRootSptr)); + + for (unsigned j=0; j < commonNodes.size(); j++) + { + // Get children of loaded tree + map< string, ZkTreeNodeSptr > loadedChildren; + for (unsigned i=0; i < commonNodes[j].first->numChildren(); i++) + { + ZkTreeNodeSptr childSptr = commonNodes[j].first->getChild (i); + loadedChildren[childSptr->getKey()] = childSptr; + } + // Get children of live tree + map< string, ZkTreeNodeSptr > liveChildren; + for (unsigned i=0; i < commonNodes[j].second->numChildren(); i++) + { + ZkTreeNodeSptr childSptr = commonNodes[j].second->getChild (i); + liveChildren[childSptr->getKey()] = childSptr; + } + + // Start comparing the children + for (map< string, ZkTreeNodeSptr >::const_iterator it = + loadedChildren.begin(); + it != loadedChildren.end(); + it++) + { + bool ignoreKey = it->second->getData().ignoreUpdate; + string loadedVal = it->second->getData().value; + // Path to this node + string path = ppaths[j] + string("/") + it->first; + + map< string, ZkTreeNodeSptr >::const_iterator jt = + liveChildren.find (it->first); + if (jt != liveChildren.end()) + { + // Key is present in live zk-tree + string liveVal = jt->second->getData().value; + // Check value for the key, if not ignored + if (!ignoreKey) + { + if (loadedVal != liveVal) + { + // Value differs, set the new value for the key + actions.push_back (ZkAction (ZkAction::VALUE, + path, + loadedVal, + liveVal)); + } + + // Add node to common nodes + ppaths.push_back (path); + commonNodes.push_back (pair< ZkTreeNodeSptr, ZkTreeNodeSptr > + (it->second, jt->second)); + } + + // Remove the live zk node + liveChildren.erase (it->first); + } + else + { + // Add the subtree rooted to this node, if not ignored + if (!ignoreKey) + addTreeZkAction_ (it->second, path, actions); + } + } + + // Remaining live zk nodes to be deleted + for (map< string, ZkTreeNodeSptr >::const_iterator it = liveChildren.begin(); + it != liveChildren.end(); it++) + { + string path = ppaths[j] + string("/") + it->first; + actions.push_back (ZkAction (ZkAction::DELETE, path)); + } + } + // return the diff actions + return actions; + } + + void ZkTreeUtil::executeZkActions (const string& zkHosts, + const vector< ZkAction >& zkActions, + int execFlags) const + { + // Execute the diff zk actions + if (zkActions.size()) + { + // Connect to Zookeeper for writing + ZooKeeperAdapterSptr zkHandleSptr; + if ((execFlags & EXECUTE) + || (execFlags & INTERACTIVE)) + { + zkHandleSptr = get_zkHandle (zkHosts); + std::cerr << "[zktreeutil] connected to ZK server for writing" + << std::endl; + } + + for (unsigned i=0; i < zkActions.size(); i++) + { + if (zkActions[i].action == ZkAction::CREATE) + { + if (execFlags & PRINT) + std::cout << "CREAT- key:" << zkActions[i].key << std::endl; + if (execFlags & EXECUTE) + { + if (execFlags & INTERACTIVE) + { + string resp; + std::cout << "Execute this action?[yes/no]: "; + std::getline(std::cin, resp); + if (resp != "yes") + continue; + } + zkHandleSptr->createNode(zkActions[i].key.c_str(), "", 0, false); + } + } + else if (zkActions[i].action == ZkAction::DELETE) + { + if (execFlags & PRINT) + std::cout << "DELET- key:" << zkActions[i].key << std::endl; + if (execFlags & EXECUTE) + { + if (execFlags & INTERACTIVE) + { + string resp; + std::cout << "Execute this action?[yes/no]: "; + std::getline(std::cin, resp); + if (resp != "yes") + continue; + } + zkHandleSptr->deleteNode(zkActions[i].key.c_str(), true); + } + } + else if (zkActions[i].action == ZkAction::VALUE) + { + if (execFlags & PRINT) + { + std::cout << "VALUE- key:" + << zkActions[i].key + << " value:" << zkActions[i].newval; + if (zkActions[i].oldval != "") + std::cout << " old_value:" << zkActions[i].oldval; + std::cout << std::endl; + } + if (execFlags & EXECUTE) + { + if (execFlags & INTERACTIVE) + { + string resp; + std::cout << "Execute this action?[yes/no]: "; + std::getline(std::cin, resp); + if (resp != "yes") + continue; + } + zkHandleSptr->setNodeData (zkActions[i].key, zkActions[i].newval); + } + } + } + } + + return; + } + +} + diff --git a/src/contrib/zktreeutil/src/ZkTreeUtil.h b/src/contrib/zktreeutil/src/ZkTreeUtil.h new file mode 100644 index 00000000000..0a9be03f842 --- /dev/null +++ b/src/contrib/zktreeutil/src/ZkTreeUtil.h @@ -0,0 +1,262 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __ZK_TREE_UTIL_H__ +#define __ZK_TREE_UTIL_H__ + +#include +#include +#include "SimpleTree.h" +#include "ZkAdaptor.h" + +namespace zktreeutil +{ + +#define ZKTREEUTIL_INF 1000000000 + /** + * \brief A structure containing ZK node data. + */ + struct ZkNodeData + { + /** + * \brief The value string of the ZK node. + */ + string value; + + /** + * \brief The flag indicating whether children of the + * \brief node shduld be ignored during create/diff/update + */ + bool ignoreUpdate; + + /** + * \brief Constructor. + * + * @param val the value string + * @param ignore the flag indicating ignore any update/diff + */ + ZkNodeData (const string& val, bool ignore=false) + : value (val), ignoreUpdate (ignore) {} + + /** + * \brief Constructor. + * + * @param ignore the flag indicating ignore any update/diff + */ + ZkNodeData (bool ignore=false) + : ignoreUpdate (ignore) {} + }; + + /** + * \brief The type representing a ZK Treenode + */ + typedef SimpleTreeNode< string, ZkNodeData > ZkTreeNode; + + /** + * \brief The type representing a ZK Treenode smart-pointer + */ + typedef boost::shared_ptr< ZkTreeNode > ZkTreeNodeSptr; + + /** + * \brief The type representing a ZK Adapter smart-pointer + */ + typedef boost::shared_ptr< ZooKeeperAdapter > ZooKeeperAdapterSptr; + + /** + * \brief A structure defining a particular action on ZK node; + * \brief the action can be any of - + * \brief CREAT- : creates recussively + * \brief DELET- : deletes recursively + * \brief VALUE- : sets to + */ + struct ZkAction + { + /** + * \brief The action type; any of create/delete/setvalue. + */ + enum ZkActionType + { + NONE, + CREATE, + DELETE, + VALUE, + }; + + /** + * \brief action of this instance + */ + ZkActionType action; + + /** + * \brief ZK node key + */ + string key; + + /** + * \brief value to be set, if action is setvalue + */ + string newval; + + /** + * \brief existing value of the ZK node key + */ + string oldval; + + /** + * \brief Constructor. + */ + ZkAction () + : action (ZkAction::NONE) {} + + /** + * \brief Constructor. + * + * @param act the action to be taken + * @param k the key on which action to be taken + */ + ZkAction (ZkActionType act, const string& k) + : action(act), + key(k) {} + + /** + * \brief Constructor. + * + * @param act the action to be taken + * @param k the key on which action to be taken + * @param v the value of the ZK node key + */ + ZkAction (ZkActionType act, const string& k, const string& v) + : action(act), + key(k), + newval(v) {} + + /** + * \brief Constructor. + * + * @param act the action to be taken + * @param k the key on which action to be taken + * @param nv the new value of the ZK node key + * @param ov the old value of the ZK node key + */ + ZkAction (ZkActionType act, const string& k, const string& nv, const string& ov) + : action (act), + key(k), + newval(nv), + oldval(ov) {} + }; + + /** + * \brief The ZK tree utility class; supports loading ZK tree from ZK server OR + * \brief from saved XML file, saving ZK tree into XML file, dumping the ZK tree + * \brief on standard output, creting a diff between saved ZK tree and live ZK + * \brief tree and incremental update of the live ZK tree. + */ + class ZkTreeUtil + { + public: + /** + * \brief Execution flag on ZkAction + */ + enum ZkActionExecuteFlag + { + NONE = 0, + PRINT = 1, + EXECUTE = 2, + INTERACTIVE = 5, + }; + + public: + /** + * \brief Connects to zookeeper and returns a valid ZK handle + * + * @param zkHosts comma separated list of host:port forming ZK quorum + * @param a valid ZK handle + */ + static ZooKeeperAdapterSptr get_zkHandle (const string& zkHosts); + + + public: + /** + * \brief Constructor. + */ + ZkTreeUtil () : loaded_(false) {} + + /** + * \brief loads the ZK tree from ZK server into memory + * + * @param zkHosts comma separated list of host:port forming ZK quorum + * @param path path to the subtree to be loaded into memory + * @param force forces reloading in case tree already loaded into memory + */ + void loadZkTree (const string& zkHosts, const string& path="/", bool force=false); + + /** + * \brief loads the ZK tree from XML file into memory + * + * @param zkXmlConfig ZK tree XML file + * @param force forces reloading in case tree already loaded into memory + */ + void loadZkTreeXml (const string& zkXmlConfig, bool force=false); + + /** + * \brief writes the in-memory ZK tree on to ZK server + * + * @param zkHosts comma separated list of host:port forming ZK quorum + * @param path path to the subtree to be written to ZK tree + * @param force forces cleanup of the ZK tree on the ZK server before writing + */ + void writeZkTree (const string& zkHosts, const string& path="/", bool force=false) const; + + /** + * \brief dupms the in-memory ZK tree on the standard output device; + * + * @param xml flag indicates whether tree should be dumped in XML format + * @param depth the depth of the tree to be dumped for non-xml dump + */ + void dumpZkTree (bool xml=false, int depth=ZKTREEUTIL_INF) const; + + /** + * \brief returns a list of actions after taking a diff of in-memory + * \brief ZK tree and live ZK tree. + * + * @param zkHosts comma separated list of host:port forming ZK quorum + * @param path path to the subtree in consideration while taking diff with ZK tree + * @return a list of ZKAction instances to be performed on live ZK tree + */ + vector< ZkAction > diffZkTree (const string& zkHosts, const string& path="/") const; + + /** + * \brief performs create/delete/setvalue by executing a set of + * ZkActions on a live ZK tree. + * + * @param zkHosts comma separated list of host:port forming ZK quorum + * @param zkActions set of ZkActions + * @param execFlags flags indicating print/execute/interactive etc + */ + void executeZkActions (const string& zkHosts, + const vector< ZkAction >& zkActions, + int execFlags) const; + + private: + + ZkTreeNodeSptr zkRootSptr_; // ZK tree root node + bool loaded_; // Falg indicating whether ZK tree loaded into memory + }; +} + +#endif // __ZK_TREE_UTIL_H__ diff --git a/src/contrib/zktreeutil/src/ZkTreeUtilMain.cc b/src/contrib/zktreeutil/src/ZkTreeUtilMain.cc new file mode 100644 index 00000000000..8afebf6e2f7 --- /dev/null +++ b/src/contrib/zktreeutil/src/ZkTreeUtilMain.cc @@ -0,0 +1,247 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include +#include "ZkTreeUtil.h" + +using namespace zktreeutil; + +// The set of "long" options accepted by this program. +static struct option long_options[] = { + {"help", no_argument, 0, 'h'}, + {"import", no_argument, 0, 'I'}, + {"export", no_argument, 0, 'E'}, + {"update", no_argument, 0, 'U'}, + {"diff", no_argument, 0, 'F'}, + {"dump", no_argument, 0, 'D'}, + {"force", no_argument, 0, 'f'}, + {"xmlfile", required_argument, 0, 'x'}, + {"path", required_argument, 0, 'p'}, + {"depth", required_argument, 0, 'd'}, + {"zookeeper", required_argument, 0, 'z'}, + {0, 0, 0, 0} +}; +static char *short_options = "IEUFDfx:p:d:hz:"; + +static void usage(int argc, char *argv[]) +{ + std::cout << "ZK-tree utility for managing ZK-tree with XML import/export," << std::endl; + std::cout << "viewing diff between live and saved ZK-tree and performing" << std::endl; + std::cout << "incremental update of the same." << std::endl; + std::cout << "Usage: " << argv[0] << " [args-and-values]+" << std::endl; + std::cout + << "\t--import or -I: " + << std::endl + << "\t Imports the zookeeper tree from XML file. Must be specified with" + << std::endl + << "\t --zookeeper AND --xmlfile options. Optionally takes --path for" + << std::endl + << "\t importing subtree" + << std::endl; + std::cout + << "\t--export or -E: " + << std::endl + << "\t Exports the zookeeper tree to XML file. Must be specified with" + << std::endl + << "\t --zookeeper option. Optionally takes --path for exporting subtree" + << std::endl; + std::cout + << "\t--update or -U: " + << std::endl + << "\t Updates zookeeper tree with changes from XML file. Update operation" + << std::endl + << "\t is interactive unless specified with --force option. Must be speci-" + << std::endl + << "\t fied with --zookeeper AND --xmlfile options. Optionally takes --path" + << std::endl + << "\t for updating subtree." + << std::endl; + std::cout + << "\t--diff or -F: " + << std::endl + << "\t Creates a list of diff actions on ZK tree based on XML data. Must" + << std::endl + << "\t be specified with --zookeeper OR --xmlfile options. Optionally takes" + << std::endl + << "\t --path for subtree diff" + << std::endl; + std::cout + << "\t--dump or -D: " + << std::endl + << "\t Dumps the entire ZK (sub)tree to standard output. Must be specified" + << std::endl + << "\t with --zookeeper OR --xmlfile options. Optionally takes --path and" + << std::endl + << "\t --depth for dumping subtree." + << std::endl; + std::cout + << "\t--xmlfile= or -x : " + << std::endl + << "\t Zookeeper tree-data XML file." + << std::endl; + std::cout + << "\t--path= or -p : " + << std::endl + << "\t Path to the zookeeper subtree rootnode." + << std::endl; + std::cout + << "\t--depth= or -d : " + << std::endl + << "\t Depth of the ZK tree to be dumped (ignored for XML dump)." + << std::endl; + std::cout + << "\t--force or -f: Forces cleanup before import; also used for forceful" + << std::endl + << "\t update. Optionally be specified with --import and --update." + << std::endl; + std::cout + << "\t--help or -h: " + << std::endl + << "\t prints this message" + << std::endl; + std::cout + << "\t--zookeeper= or -z : " + << std::endl + << "\t specifies information to connect to zookeeper." + << std::endl; +} + +int main(int argc, char **argv) +{ + if (argc == 1) { + usage(argc, argv); + exit(0); + } + + // Parse the arguments. + int op = 0; + bool force = false; + string zkHosts; + string xmlFile; + string path = "/"; + int depth = 0; + while (1) + { + int c = getopt_long(argc, argv, short_options, long_options, 0); + if (c == -1) + break; + + switch (c) { + case 'I': op = c; + break; + case 'E': op = c; + break; + case 'U': op = c; + break; + case 'F': op = c; + break; + case 'D': op = c; + break; + case 'f': force = true; + break; + case 'x': xmlFile = optarg; + break; + case 'p': path = optarg; + break; + case 'd': depth = atoi (optarg); + break; + case 'z': zkHosts = optarg; + break; + case 'h': usage (argc, argv); + exit(0); + } + } + + ZkTreeUtil zkTreeUtil; + switch (op) + { + case 'I': { + if (zkHosts == "" || xmlFile == "") + { + std::cout << "[zktreeutil] missing params; please see usage" << std::endl; + exit (-1); + } + zkTreeUtil.loadZkTreeXml (xmlFile); + zkTreeUtil.writeZkTree (zkHosts, path, force); + std::cout << "[zktreeutil] import successful!" << std::endl; + break; + } + case 'E': { + if (zkHosts == "") + { + std::cout << "[zktreeutil] missing params; please see usage" << std::endl; + exit (-1); + } + zkTreeUtil.loadZkTree (zkHosts, path); + zkTreeUtil.dumpZkTree (true); + break; + } + case 'U': { + if (zkHosts == "" || xmlFile == "") + { + std::cout << "[zktreeutil] missing params; please see usage" << std::endl; + exit (-1); + } + zkTreeUtil.loadZkTreeXml (xmlFile); + vector< ZkAction > zkActions = zkTreeUtil.diffZkTree (zkHosts, path); + int flags = ZkTreeUtil::EXECUTE; + if (!force) flags |= ZkTreeUtil::INTERACTIVE; + zkTreeUtil.executeZkActions (zkHosts, zkActions, flags); + std::cout << "[zktreeutil] update successful!" << std::endl; + break; + } + case 'F': { + if (zkHosts == "" || xmlFile == "") + { + std::cout << "[zktreeutil] missing params; please see usage" << std::endl; + exit (-1); + } + zkTreeUtil.loadZkTreeXml (xmlFile); + vector< ZkAction > zkActions = zkTreeUtil.diffZkTree (zkHosts, path); + zkTreeUtil.executeZkActions (zkHosts, zkActions, ZkTreeUtil::PRINT); + break; + } + case 'D': { + if (zkHosts != "") + zkTreeUtil.loadZkTree (zkHosts, path); + else if (xmlFile != "") + zkTreeUtil.loadZkTreeXml (xmlFile); + else + { + std::cout << "[zktreeutil] missing params; please see usage" << std::endl; + exit (-1); + } + // Dump the ZK tree + if (depth) zkTreeUtil.dumpZkTree (false, depth); + else zkTreeUtil.dumpZkTree (false); + break; + } + } + + exit(0); +} + diff --git a/src/contrib/zktreeutil/tests/zk_sample.xml b/src/contrib/zktreeutil/tests/zk_sample.xml new file mode 100644 index 00000000000..d0b9d09f951 --- /dev/null +++ b/src/contrib/zktreeutil/tests/zk_sample.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zooinspector/NOTICE.txt b/src/contrib/zooinspector/NOTICE.txt new file mode 100644 index 00000000000..5420ef0629d --- /dev/null +++ b/src/contrib/zooinspector/NOTICE.txt @@ -0,0 +1,9 @@ +src/java/com/nitido/utils/toaster/Toaster.java: +This java file is copyright by Daniele Piras ("danielepiras80", no email known) released under the Apache Software License 2.0 +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. + +The icons in src/main/resources/icons are taken from the Tango project +downloaded from http://tango.freedesktop.org/releases on 2011-09-06. +The Tango project is public domain. + +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. diff --git a/src/contrib/zooinspector/README.txt b/src/contrib/zooinspector/README.txt new file mode 100644 index 00000000000..3c2a58f42e4 --- /dev/null +++ b/src/contrib/zooinspector/README.txt @@ -0,0 +1,94 @@ +========================================== +ZooInspector - Browser and Editor for ZooKeeper Instances +Author: Colin Goodheart-Smithe +Date: February 2010 +========================================== + +ZooInspector is a Java Swing based application for browsing and editing ZooKeeper instances. + +Contents +-------- + - Features + - Pre-requisites + - Build Instructions + - Using ZooInspector + - Creating and Using Plugins + +Features +-------- + Below is a list of features in the current release of ZooInspector. + - Load connection settings from a zookeeper properties file + - Plugable DataEncryptionManagers to specify how data should be encrypted and decrypted in the Zookeeper instance + - Browseable tree view of the ZooKeeper instance + - View the data in a node + - View the ACL's currently applied to a node + - View the metadata for a node (Version, Number of Children, Last modified Tiem, etc.) + - Plugable NodeViewers interface + - Ability to save/load and set default Node Viewers + +Pre-requisites +-------------- + - The main zookeeper build script must have been run before building this module + +Build Instructions +------------------ + 1. Open a command line. + 2. cd into this directory + 3. Run command: ant + 4. ZooInspector will be built to ../../../build/contrib/ZooInspector + 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 + copied to this directory during the build + 6. By default the zookeeper.cmd and zookeeper.sh files expect zookeeper-3.3.0.jar. If you are using another version + you will need to change these files to point to the zookeeper-3.x.x.jar you copied to the lib directory + 7. To run ZooInspector run zooInspector.cmd (on Windows) or zooInspector.sh (on Linux). If you are using + zookeeper-3.3.0.jar and do not require any classpath changes you can run the zookeeper-dev-ZooInspector.jar + directly + +Using ZooInspector +------------------ + To start ZooInspector run zooInspector.cmd (on Windows) or zooInspector.sh (on Linux). If you are using + zookeeper-3.3.0.jar and do not require any classpath changes you can run the zookeeper-dev-ZooInspector.jar + directly. + + Click the play button on the toolbar to bring up the connection dialog. From here you can enter connection + information for your zookeeper instance. You can also load the connection properties from a file. This file can + have the format as a normal zookeeper properties file (i.e. hosts and timeout key-value pairs) and van optional have + an encryptionManager key-value pair to specify the DataEncryptionManager to use for this connection + (DataEncryptionManagers are explained in further detail in the 'Creating and Using Plugins' section below). You can + also set the entered information as the defaults so that when you first start ZooInspector these settings are + automatically loaded into this dialog. Pressing the OK button with connect to your ZooKeeper instance and show the + current node tree on the left of the main panel. + + Clicking a node in the node tree will load the data for that node into the node viewers. Three node viewers are + currently distributed with ZooInspector: + 1. Node Data - This enables you to see the data current stored on that node. This data can be modified and + saved. The data is decrypted and encrypted using the DataEncryptionManager specified on the connection + dialog. + 2. Node Metadata - This enables you to see the metadata associiated with this node. This is Essentially the data + obtained from the Stat object for this node. + 3. Node ACLs - This allows you to see the ACLs currently applied to this node. Currently there is no ability + to change the ACLs on a node, but it is a feature I would like to add. + Other custom Node Viewers can be added, this is explained in the 'Creating and Using Plugins' section below. + + +Creating and Using Plugins +-------------------------- + There are two types of plugin which can be used with ZooInspector: + 1. DataEncryptionManager - This specifies how data should be encrypted and decrypted when working with a + zookeeper instance. + 2. ZooInspectorNodeViewer - This is a GUI panel which provides a view of visualisation on a node. + More information on these interfaces can be found in the javadocs for this module. + + To use a plugin in ZooInspector, build the plugin to a jar and copy the jar to the lib sub-directory. Edit the + zooInspector.cmd and/or zooInspector.sh files to include your new jar on the classpath and run ZooInspector. + + For DataEncryptionManagers, click the play button to open the connection dialog and enter the full class name of + your DataEncryptionManager in the 'Data Encryption Manager' field. You can make this Data Encryption Manager the + default by clicking 'Set As Default'. Click the 'OK' button to instantiate and use your plugin. + + For ZooInspectorNodeViewers, Click the 'Change Node Viewers' button on the toolbar (looks like a tree with a pencil) + and enter the full classname for your Node Viewer in the field left of the 'Add' button, then click the 'Add' + button. The Node Viewer will be instantiated and should appear in the list. You can change the order of the Node + viewers by clicking the up and dpwn buttons and delete a Node Viewer by clicking the delete button. You can save + to configuration to a file or set it as the default if necessary. Then click the 'OK' button and your Node Viewer + should appear in the tabs on the right of the main panel. \ No newline at end of file diff --git a/src/contrib/zooinspector/TODO b/src/contrib/zooinspector/TODO new file mode 100644 index 00000000000..404d5c9c699 --- /dev/null +++ b/src/contrib/zooinspector/TODO @@ -0,0 +1,19 @@ +- replace JToaster with standard notifications, see: + http://www.galago-project.org/specs/notification/ + http://stackoverflow.com/questions/857154/freedesktop-org-notifications-in-java + DBus and Java: + http://bolta-gecko.blogspot.com/2009/06/using-d-bus-in-java.html + http://dbus.freedesktop.org/doc/dbus-java/ (packaged in Debian) + +- properly respect + http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html + http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html + +- Rename classes to avoid redundand "ZooInspector" prefix. + +- Ant build file has hard coded log4j dependency. (ZK will move to maven anyways...) + +- make directory for config files configurable via commandline parameter + +- Clean up the code! :-) diff --git a/src/contrib/zooinspector/build.xml b/src/contrib/zooinspector/build.xml new file mode 100644 index 00000000000..faf4c14dc84 --- /dev/null +++ b/src/contrib/zooinspector/build.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests failed! + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zooinspector/config/defaultConnectionSettings.cfg b/src/contrib/zooinspector/config/defaultConnectionSettings.cfg new file mode 100644 index 00000000000..90f20ae2e5b --- /dev/null +++ b/src/contrib/zooinspector/config/defaultConnectionSettings.cfg @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#Default connection for ZooInspector +hosts=localhost\:2181 +encryptionManager=org.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager +timeout=5000 +authScheme= +authData= \ No newline at end of file diff --git a/src/contrib/zooinspector/config/defaultNodeViewers.cfg b/src/contrib/zooinspector/config/defaultNodeViewers.cfg new file mode 100644 index 00000000000..38fe9a85e0f --- /dev/null +++ b/src/contrib/zooinspector/config/defaultNodeViewers.cfg @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +org.apache.zookeeper.inspector.gui.nodeviewer.NodeViewerData +org.apache.zookeeper.inspector.gui.nodeviewer.NodeViewerMetaData +org.apache.zookeeper.inspector.gui.nodeviewer.NodeViewerACL diff --git a/src/contrib/zooinspector/ivy.xml b/src/contrib/zooinspector/ivy.xml new file mode 100644 index 00000000000..865072e12d4 --- /dev/null +++ b/src/contrib/zooinspector/ivy.xml @@ -0,0 +1,48 @@ + + + + + + + + ZooInspector + + + + + + + + + + + + + + + + + + + + diff --git a/src/contrib/zooinspector/lib/log4j.properties b/src/contrib/zooinspector/lib/log4j.properties new file mode 100644 index 00000000000..6630f770eef --- /dev/null +++ b/src/contrib/zooinspector/lib/log4j.properties @@ -0,0 +1,8 @@ +# ***** Set root logger level to INFO and it appender to stdout. +log4j.rootLogger=INFO,stdout +# ***** stdout is set to be a ConsoleAppender. +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +# ***** stdout uses PatternLayout. +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +# ***** Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n \ No newline at end of file diff --git a/src/contrib/zooinspector/licences/Apache Software Licence v2.0.txt b/src/contrib/zooinspector/licences/Apache Software Licence v2.0.txt new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/src/contrib/zooinspector/licences/Apache Software Licence v2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/contrib/zooinspector/src/java/com/nitido/utils/toaster/Toaster.java b/src/contrib/zooinspector/src/java/com/nitido/utils/toaster/Toaster.java new file mode 100644 index 00000000000..3cbdb15bae0 --- /dev/null +++ b/src/contrib/zooinspector/src/java/com/nitido/utils/toaster/Toaster.java @@ -0,0 +1,433 @@ +/** + * This java file is copyright by Daniele Piras ("danielepiras80", no email known) released under the Apache Software License 2.0. 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. + * + * + * Java Toaster is a java utility class for your swing applications that show an animate box coming from the bottom of your screen with a notification message and/or an associated image (like msn + * online/offline notifications). + * + * Toaster panel in windows system follow the taskbar; So if the taskbar is into the bottom the panel coming from the bottom and if the taskbar is on the top then the panel coming from the top. + * + * This is a simple example of utilization: + * + * import com.nitido.utils.toaster.*; import javax.swing.*; + * + * public class ToasterTest { + * + * public static void main(String[] args) { // Initialize toaster manager... Toaster toasterManager = new Toaster(); + * + * // Show a simple toaster toasterManager.showToaster( new ImageIcon( "mylogo.gif" ), "A simple toaster with an image" ); } } + */ + +/** + * Java Toaster is a java utility class for your swing applications + * that show an animate box coming from the bottom of your screen + * with a notification message and/or an associated image + * (like msn online/offline notifications). + * + * Toaster panel in windows system follow the taskbar; So if + * the taskbar is into the bottom the panel coming from the bottom + * and if the taskbar is on the top then the panel coming from the top. + * + * This is a simple example of utilization: + * + * import com.nitido.utils.toaster.*; + * import javax.swing.*; + * + * public class ToasterTest + * { + * + * public static void main(String[] args) + * { + * // Initialize toaster manager... + * Toaster toasterManager = new Toaster(); + * + * // Show a simple toaster + * toasterManager.showToaster( new ImageIcon( "mylogo.gif" ), "A simple toaster with an image" ); + * } + * } + */ +package com.nitido.utils.toaster; + +/** + * Class to show tosters in multiplatform + * + * @author daniele piras + * + */ +public class Toaster { + private static final long serialVersionUID = 1L; + // Set the margin + int margin; + // Flag that indicate if use alwaysOnTop or not. + // method always on top start only SINCE JDK 5 ! + boolean useAlwaysOnTop = true; + // Width of the toster + private int toasterWidth = 300; + // Height of the toster + private int toasterHeight = 80; + // Step for the toaster + private int step = 20; + // Step time + private int stepTime = 20; + // Show time + private int displayTime = 3000; + // Current number of toaster... + private int currentNumberOfToaster = 0; + // Last opened toaster + private int maxToaster = 0; + // Max number of toasters for the sceen + private int maxToasterInSceen; + // Font used to display message + private Font font; + // Color for border + private Color borderColor; + // Color for toaster + private Color toasterColor; + // Set message color + private Color messageColor; + + /** + * Constructor to initialized toaster component... + * + * @author daniele piras + * + */ + public Toaster() { + // Set default font... + font = new Font("Arial", Font.BOLD, 12); + // Border color + borderColor = new Color(245, 153, 15); + toasterColor = Color.WHITE; + messageColor = Color.BLACK; + useAlwaysOnTop = true; + // Verify AlwaysOnTop Flag... + try { + JWindow.class.getMethod("setAlwaysOnTop", new Class[]{Boolean.class}); + } catch (Exception e) { + useAlwaysOnTop = false; + } + + } + + /** + * Show a toaster with the specified message and the associated icon. + */ + public void showToaster(Icon icon, String msg) { + SingleToaster singleToaster = new SingleToaster(); + if (icon != null) { + singleToaster.iconLabel.setIcon(icon); + } + singleToaster.message.setText(msg); + singleToaster.animate(); + } + + /** + * Show a toaster with the specified message. + */ + public void showToaster(String msg) { + showToaster(null, msg); + } + + /** + * @return Returns the font + */ + public Font getToasterMessageFont() { + // TODO Auto-generated method stub + return font; + } + + /** + * Set the font for the message + */ + public void setToasterMessageFont(Font f) { + font = f; + } + + /** + * @return Returns the borderColor. + */ + public Color getBorderColor() { + return borderColor; + } + + /** + * @param borderColor The borderColor to set. + */ + public void setBorderColor(Color borderColor) { + this.borderColor = borderColor; + } + + /** + * @return Returns the displayTime. + */ + public int getDisplayTime() { + return displayTime; + } + + /** + * @param displayTime The displayTime to set. + */ + public void setDisplayTime(int displayTime) { + this.displayTime = displayTime; + } + + /** + * @return Returns the margin. + */ + public int getMargin() { + return margin; + } + + /** + * @param margin The margin to set. + */ + public void setMargin(int margin) { + this.margin = margin; + } + + /** + * @return Returns the messageColor. + */ + public Color getMessageColor() { + return messageColor; + } + + /** + * @param messageColor The messageColor to set. + */ + public void setMessageColor(Color messageColor) { + this.messageColor = messageColor; + } + + /** + * @return Returns the step. + */ + public int getStep() { + return step; + } + + /** + * @param step The step to set. + */ + public void setStep(int step) { + this.step = step; + } + + /** + * @return Returns the stepTime. + */ + public int getStepTime() { + return stepTime; + } + + /** + * @param stepTime The stepTime to set. + */ + public void setStepTime(int stepTime) { + this.stepTime = stepTime; + } + + /** + * @return Returns the toasterColor. + */ + public Color getToasterColor() { + return toasterColor; + } + + /** + * @param toasterColor The toasterColor to set. + */ + public void setToasterColor(Color toasterColor) { + this.toasterColor = toasterColor; + } + + /** + * @return Returns the toasterHeight. + */ + public int getToasterHeight() { + return toasterHeight; + } + + /** + * @param toasterHeight The toasterHeight to set. + */ + public void setToasterHeight(int toasterHeight) { + this.toasterHeight = toasterHeight; + } + + /** + * @return Returns the toasterWidth. + */ + public int getToasterWidth() { + return toasterWidth; + } + + /** + * @param toasterWidth The toasterWidth to set. + */ + public void setToasterWidth(int toasterWidth) { + this.toasterWidth = toasterWidth; + } + + /** + * Class that rappresent a single toaster + * + * @author daniele piras + * + */ + class SingleToaster extends javax.swing.JWindow { + private static final long serialVersionUID = 1L; + + // Label to store Icon + private JLabel iconLabel = new JLabel(); + + // Text area for the message + private JTextArea message = new JTextArea(); + + + /*** + * Simple costructor that initialized components... + */ + public SingleToaster() { + initComponents(); + } + + /*** + * Function to initialized components + */ + private void initComponents() { + + setSize(toasterWidth, toasterHeight); + message.setFont(getToasterMessageFont()); + JPanel externalPanel = new JPanel(new BorderLayout(1, 1)); + externalPanel.setBackground(getBorderColor()); + JPanel innerPanel = new JPanel(new BorderLayout(getMargin(), getMargin())); + innerPanel.setBackground(getToasterColor()); + message.setBackground(getToasterColor()); + message.setMargin(new Insets(2, 2, 2, 2)); + message.setLineWrap(true); + message.setWrapStyleWord(true); + + EtchedBorder etchedBorder = (EtchedBorder) BorderFactory + .createEtchedBorder(); + externalPanel.setBorder(etchedBorder); + + externalPanel.add(innerPanel); + message.setForeground(getMessageColor()); + innerPanel.add(iconLabel, BorderLayout.WEST); + innerPanel.add(message, BorderLayout.CENTER); + getContentPane().add(externalPanel); + } + + + /*** + * Start toaster animation... + */ + public void animate() { + (new Animation(this)).start(); + } + + } + + /*** + * Class that manage the animation + */ + class Animation extends Thread { + SingleToaster toaster; + + public Animation(SingleToaster toaster) { + this.toaster = toaster; + } + + + /** + * Animate vertically the toaster. The toaster could be moved from bottom + * to upper or to upper to bottom + * @param posx + * @param fromy + * @param toy + * @throws InterruptedException + */ + protected void animateVertically(int posx, int fromY, int toY) throws InterruptedException { + + toaster.setLocation(posx, fromY); + if (toY < fromY) { + for (int i = fromY; i > toY; i -= step) { + toaster.setLocation(posx, i); + Thread.sleep(stepTime); + } + } else { + for (int i = fromY; i < toY; i += step) { + toaster.setLocation(posx, i); + Thread.sleep(stepTime); + } + } + toaster.setLocation(posx, toY); + } + + public void run() { + try { + boolean animateFromBottom = true; + GraphicsEnvironment ge = GraphicsEnvironment + .getLocalGraphicsEnvironment(); + Rectangle screenRect = ge.getMaximumWindowBounds(); + + int screenHeight = (int) screenRect.height; + + int startYPosition; + int stopYPosition; + + if (screenRect.y > 0) { + animateFromBottom = false; // Animate from top! + } + + maxToasterInSceen = screenHeight / toasterHeight; + + + int posx = (int) screenRect.width - toasterWidth - 1; + + toaster.setLocation(posx, screenHeight); + toaster.setVisible(true); + if (useAlwaysOnTop) { + toaster.setAlwaysOnTop(true); + } + + if (animateFromBottom) { + startYPosition = screenHeight; + stopYPosition = startYPosition - toasterHeight - 1; + if (currentNumberOfToaster > 0) { + stopYPosition = stopYPosition - (maxToaster % maxToasterInSceen * toasterHeight); + } else { + maxToaster = 0; + } + } else { + startYPosition = screenRect.y - toasterHeight; + stopYPosition = screenRect.y; + + if (currentNumberOfToaster > 0) { + stopYPosition = stopYPosition + (maxToaster % maxToasterInSceen * toasterHeight); + } else { + maxToaster = 0; + } + } + + currentNumberOfToaster++; + maxToaster++; + + + animateVertically(posx, startYPosition, stopYPosition); + Thread.sleep(displayTime); + animateVertically(posx, stopYPosition, startYPosition); + + currentNumberOfToaster--; + toaster.setVisible(false); + toaster.dispose(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/ZooInspector.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/ZooInspector.java new file mode 100644 index 00000000000..f8b405a2a58 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/ZooInspector.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector; + +import org.apache.zookeeper.inspector.gui.IconResource; +import org.apache.zookeeper.inspector.gui.ZooInspectorPanel; +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.inspector.manager.ZooInspectorManagerImpl; + +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.*; + +/** + * + */ +public class ZooInspector { + + public static IconResource iconResource; + + /** + * @param args + * - not used. The value of these parameters will have no effect + * on the application + */ + public static void main(String[] args) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + JFrame frame = new JFrame("ZooInspector"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + iconResource = new IconResource(); + final ZooInspectorPanel zooInspectorPanel = new ZooInspectorPanel( + new ZooInspectorManagerImpl(), iconResource); + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + super.windowClosed(e); + zooInspectorPanel.disconnect(true); + } + }); + + frame.setContentPane(zooInspectorPanel); + frame.setSize(1024, 768); + frame.setVisible(true); + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred loading ZooInspector", e); + JOptionPane.showMessageDialog(null, + "ZooInspector failed to start: " + e.getMessage(), "Error", + JOptionPane.ERROR_MESSAGE); + } + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/encryption/BasicDataEncryptionManager.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/encryption/BasicDataEncryptionManager.java new file mode 100644 index 00000000000..48a7f8254eb --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/encryption/BasicDataEncryptionManager.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.encryption; + +/** + * + */ +public class BasicDataEncryptionManager implements DataEncryptionManager { + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.encryption.DataEncryptionManager#decryptData + * (byte[]) + */ + public String decryptData(byte[] encrypted) throws Exception { + return new String(encrypted); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.encryption.DataEncryptionManager#encryptData + * (java.lang.String) + */ + public byte[] encryptData(String data) throws Exception { + if (data == null) { + return new byte[0]; + } + return data.getBytes(); + } + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/encryption/DataEncryptionManager.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/encryption/DataEncryptionManager.java new file mode 100644 index 00000000000..50bda0be760 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/encryption/DataEncryptionManager.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.encryption; + +/** + * A class which describes how data should be encrypted and decrypted + */ +public interface DataEncryptionManager { + /** + * @param data + * - the data to be encrypted + * @return the encrypted data + * @throws Exception + */ + public byte[] encryptData(String data) throws Exception; + + /** + * @param encrypted + * - the data to be decrypted + * @return the decrypted data + * @throws Exception + */ + public String decryptData(byte[] encrypted) throws Exception; +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/IconResource.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/IconResource.java new file mode 100644 index 00000000000..7db93bd4cb8 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/IconResource.java @@ -0,0 +1,99 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.inspector.gui; + +import org.apache.zookeeper.inspector.logger.LoggerFactory; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +import javax.swing.*; + +/** + * @see http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html + * I tried to take icons that are available in the Tango icon set + */ +public class IconResource { + + public static final String ICON_ChangeNodeViewers = ""; + public static final String ICON_TREE_LEAF = "mimetypes/text-x-generic"; + public static final String ICON_TREE_OPEN = "places/folder"; + public static final String ICON_TREE_CLOSE = "places/folder"; + public static final String ICON_INFORMATION = "status/info"; + public static final String ICON_SAVE = "actions/document-save"; + public static final String ICON_UP = "actions/up"; + public static final String ICON_DOWN = "actions/down"; + public static final String ICON_ADD = "actions/add"; + public static final String ICON_REMOVE = "actions/remove"; + public static final String ICON_START = "actions/media-playback-start"; + public static final String ICON_STOP = "actions/media-playback-stop"; + public static final String ICON_DOCUMENT_ADD = "actions/document-new"; + public static final String ICON_REFRESH = "actions/view-refresh"; + public static final String ICON_TRASH = "places/user-trash"; + // better: actions/help-about, but not in tango + public static final String ICON_HELP_ABOUT = "status/info"; + + private static final String DEFAULT_THEME = "Tango"; + private static final String DEFAULT_SIZE = "16x16"; + private static final String FALLBACK_ICON = "face-surprise"; + + // compare http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + private static final String[] DEFAULT_XDG_DATA_DIRS = new String[]{ + "/usr/local/share", + "/usr/share" + }; + + private String theme = DEFAULT_THEME; + private String size = DEFAULT_SIZE; + + public URL find(String name) { + String iconPath = buildIconPath(name); + URL iconUrl = findInPaths(iconPath); + if (null != iconUrl) return iconUrl; + + iconUrl = getClass().getResource(iconPath); + if (null != iconUrl) return iconUrl; + + if (!name.equals(FALLBACK_ICON)) return find(FALLBACK_ICON); + return null; + } + + public ImageIcon get(String name, String description) { + URL iconUrl = find(name); + if (null == iconUrl) { + ImageIcon icon = new ImageIcon(); + icon.setDescription(description); + return icon; + } else { + return new ImageIcon(iconUrl, description); + } + } + + private URL findInPaths(String iconPath) { + for (String dataDir : DEFAULT_XDG_DATA_DIRS) { + File file = new File(dataDir + iconPath); + if (file.exists()) { + try { + return file.toURI().toURL(); + } catch (MalformedURLException e) { + LoggerFactory.getLogger().warn(e.toString()); + } + } + } + return null; + } + + private String buildIconPath(String name) { + return "/icons/" + theme + "/" + size + "/" + name + ".png"; + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/NodeViewersChangeListener.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/NodeViewersChangeListener.java new file mode 100644 index 00000000000..43ca92e29f7 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/NodeViewersChangeListener.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui; + +import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer; + +import java.util.List; + +/** + * A Listener for changes to the configuration of which node viewers are shown + */ +public interface NodeViewersChangeListener { + /** + * Called when the node viewers configuration is changed (i.e node viewers + * are added, removed or the order of the node viewers is changed) + * + * @param newViewers + * - a {@link List} of {@link ZooInspectorNodeViewer}s which are + * to be shown + */ + public void nodeViewersChanged(List newViewers); +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/Toolbar.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/Toolbar.java new file mode 100644 index 00000000000..ffcd8319e47 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/Toolbar.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.inspector.gui; + +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.*; + +public class Toolbar { + + private static final Button[] buttonsToToggle = new Button[]{ + Button.connect, Button.disconnect, Button.refresh, Button.addNode, Button.deleteNode + }; + private final IconResource iconResource; + private final JToolBar toolbar = new JToolBar(); + private final Map buttons = new HashMap(); + + public Toolbar(IconResource iconResource) { + this.iconResource = iconResource; + init(); + } + + public void addActionListener(Button button, ActionListener actionListener) { + buttons.get(button).addActionListener(actionListener); + } + + public JToolBar getJToolBar() { + return toolbar; + } + + public void toggleButtons(boolean connected) { + for (Button button : buttonsToToggle) { + buttons.get(button).setEnabled(connected != button.enabled); + } + } + + private void init() { + toolbar.setFloatable(false); + for (Button button : Button.values()) { + JButton jbutton = button.createJButton(iconResource); + buttons.put(button, jbutton); + toolbar.add(jbutton); + } + } + + public static enum Button { + connect("Connect", IconResource.ICON_START, true), + disconnect("Disconnect", IconResource.ICON_STOP, false), + refresh("Refresh", IconResource.ICON_REFRESH, false), + addNode("Add Node", IconResource.ICON_DOCUMENT_ADD, false), + deleteNode("Delete Node", IconResource.ICON_TRASH, false), + nodeViewers("Change Node Viewers", IconResource.ICON_ChangeNodeViewers, true), + about("About ZooInspector", IconResource.ICON_HELP_ABOUT, true); + + private String toolTip; + private String icon; + private boolean enabled; + + Button(String toolTip, String icon, boolean enabled) { + this.toolTip = toolTip; + this.icon = icon; + this.enabled = enabled; + } + + public JButton createJButton(IconResource iconResource) { + JButton jbutton = new JButton(iconResource.get(icon, toolTip)); + jbutton.setEnabled(enabled); + jbutton.setToolTipText(toolTip); + return jbutton; + } + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorAboutDialog.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorAboutDialog.java new file mode 100644 index 00000000000..9b964ceb7f3 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorAboutDialog.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui; + +import org.apache.zookeeper.inspector.logger.LoggerFactory; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; + +import javax.swing.*; + +/** + * The About Dialog for the application + */ +public class ZooInspectorAboutDialog extends JDialog { + /** + * @param frame + * - the Frame from which the dialog is displayed + */ + public ZooInspectorAboutDialog(Frame frame, IconResource iconResource) { + super(frame); + this.setLayout(new BorderLayout()); + this.setIconImage(iconResource.get(IconResource.ICON_INFORMATION, "About ZooInspector").getImage()); + this.setTitle("About ZooInspector"); + this.setModal(true); + this.setAlwaysOnTop(true); + this.setResizable(false); + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + JEditorPane aboutPane = new JEditorPane(); + aboutPane.setEditable(false); + aboutPane.setOpaque(false); + java.net.URL aboutURL = ZooInspectorAboutDialog.class + .getResource("about.html"); + try { + aboutPane.setPage(aboutURL); + } catch (IOException e) { + LoggerFactory.getLogger().error( + "Error loading about.html, file may be corrupt", e); + } + panel.add(aboutPane, BorderLayout.CENTER); + panel.setPreferredSize(new Dimension(600, 200)); + JPanel buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); + JButton okButton = new JButton("OK"); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ZooInspectorAboutDialog.this.dispose(); + } + }); + buttonsPanel.add(okButton); + this.add(panel, BorderLayout.CENTER); + this.add(buttonsPanel, BorderLayout.SOUTH); + this.pack(); + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorConnectionPropertiesDialog.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorConnectionPropertiesDialog.java new file mode 100644 index 00000000000..0e278648468 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorConnectionPropertiesDialog.java @@ -0,0 +1,303 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui; + +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.inspector.manager.Pair; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; + +import javax.swing.*; + +/** + * The connection properties dialog. This is used to determine the settings for + * connecting to a zookeeper instance + */ +public class ZooInspectorConnectionPropertiesDialog extends JDialog { + + private final HashMap components; + + /** + * @param lastConnectionProps + * - the last connection properties used. if this is the first + * conneciton since starting the applications this will be the + * default settings + * @param connectionPropertiesTemplateAndLabels + * - the connection properties and labels to show in this dialog + * @param zooInspectorPanel + * - the {@link ZooInspectorPanel} linked to this dialog + */ + public ZooInspectorConnectionPropertiesDialog( + Properties lastConnectionProps, + Pair>, Map> connectionPropertiesTemplateAndLabels, + final ZooInspectorPanel zooInspectorPanel) { + final Map> connectionPropertiesTemplate = connectionPropertiesTemplateAndLabels + .getKey(); + final Map connectionPropertiesLabels = connectionPropertiesTemplateAndLabels + .getValue(); + this.setLayout(new BorderLayout()); + this.setTitle("Connection Settings"); + this.setModal(true); + this.setAlwaysOnTop(true); + this.setResizable(false); + final JPanel options = new JPanel(); + final JFileChooser fileChooser = new JFileChooser(); + options.setLayout(new GridBagLayout()); + int i = 0; + components = new HashMap(); + for (Entry> entry : connectionPropertiesTemplate + .entrySet()) { + int rowPos = 2 * i + 1; + JLabel label = new JLabel(connectionPropertiesLabels.get(entry + .getKey())); + GridBagConstraints c1 = new GridBagConstraints(); + c1.gridx = 0; + c1.gridy = rowPos; + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weightx = 0; + c1.weighty = 0; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.HORIZONTAL; + c1.insets = new Insets(5, 5, 5, 5); + c1.ipadx = 0; + c1.ipady = 0; + options.add(label, c1); + if (entry.getValue().size() == 0) { + JTextField text = new JTextField(); + GridBagConstraints c2 = new GridBagConstraints(); + c2.gridx = 2; + c2.gridy = rowPos; + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weightx = 0; + c2.weighty = 0; + c2.anchor = GridBagConstraints.WEST; + c2.fill = GridBagConstraints.HORIZONTAL; + c2.insets = new Insets(5, 5, 5, 5); + c2.ipadx = 0; + c2.ipady = 0; + options.add(text, c2); + components.put(entry.getKey(), text); + } else if (entry.getValue().size() == 1) { + JTextField text = new JTextField(entry.getValue().get(0)); + GridBagConstraints c2 = new GridBagConstraints(); + c2.gridx = 2; + c2.gridy = rowPos; + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weightx = 0; + c2.weighty = 0; + c2.anchor = GridBagConstraints.WEST; + c2.fill = GridBagConstraints.HORIZONTAL; + c2.insets = new Insets(5, 5, 5, 5); + c2.ipadx = 0; + c2.ipady = 0; + options.add(text, c2); + components.put(entry.getKey(), text); + } else { + List list = entry.getValue(); + JComboBox combo = new JComboBox(list.toArray(new String[list + .size()])); + combo.setSelectedItem(list.get(0)); + GridBagConstraints c2 = new GridBagConstraints(); + c2.gridx = 2; + c2.gridy = rowPos; + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weightx = 0; + c2.weighty = 0; + c2.anchor = GridBagConstraints.WEST; + c2.fill = GridBagConstraints.HORIZONTAL; + c2.insets = new Insets(5, 5, 5, 5); + c2.ipadx = 0; + c2.ipady = 0; + options.add(combo, c2); + components.put(entry.getKey(), combo); + } + i++; + } + loadConnectionProps(lastConnectionProps); + JPanel buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new GridBagLayout()); + JButton loadPropsFileButton = new JButton("Load from file"); + loadPropsFileButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + int result = fileChooser + .showOpenDialog(ZooInspectorConnectionPropertiesDialog.this); + if (result == JFileChooser.APPROVE_OPTION) { + File propsFilePath = fileChooser.getSelectedFile(); + Properties props = new Properties(); + try { + FileReader reader = new FileReader(propsFilePath); + try { + props.load(reader); + loadConnectionProps(props); + } finally { + reader.close(); + } + } catch (IOException ex) { + LoggerFactory + .getLogger() + .error( + "An Error occurred loading connection properties from file", + ex); + JOptionPane + .showMessageDialog( + ZooInspectorConnectionPropertiesDialog.this, + "An Error occurred loading connection properties from file", + "Error", JOptionPane.ERROR_MESSAGE); + } + options.revalidate(); + options.repaint(); + } + + } + }); + GridBagConstraints c3 = new GridBagConstraints(); + c3.gridx = 0; + c3.gridy = 0; + c3.gridwidth = 1; + c3.gridheight = 1; + c3.weightx = 0; + c3.weighty = 1; + c3.anchor = GridBagConstraints.SOUTHWEST; + c3.fill = GridBagConstraints.NONE; + c3.insets = new Insets(5, 5, 5, 5); + c3.ipadx = 0; + c3.ipady = 0; + buttonsPanel.add(loadPropsFileButton, c3); + JButton saveDefaultPropsFileButton = new JButton("Set As Default"); + saveDefaultPropsFileButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + + Properties connectionProps = getConnectionProps(); + try { + zooInspectorPanel + .setdefaultConnectionProps(connectionProps); + } catch (IOException ex) { + LoggerFactory + .getLogger() + .error( + "An Error occurred saving the default connection properties file", + ex); + JOptionPane + .showMessageDialog( + ZooInspectorConnectionPropertiesDialog.this, + "An Error occurred saving the default connection properties file", + "Error", JOptionPane.ERROR_MESSAGE); + } + } + }); + GridBagConstraints c6 = new GridBagConstraints(); + c6.gridx = 1; + c6.gridy = 0; + c6.gridwidth = 1; + c6.gridheight = 1; + c6.weightx = 1; + c6.weighty = 1; + c6.anchor = GridBagConstraints.SOUTHWEST; + c6.fill = GridBagConstraints.NONE; + c6.insets = new Insets(5, 5, 5, 5); + c6.ipadx = 0; + c6.ipady = 0; + buttonsPanel.add(saveDefaultPropsFileButton, c6); + JButton okButton = new JButton("OK"); + okButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + ZooInspectorConnectionPropertiesDialog.this.dispose(); + Properties connectionProps = getConnectionProps(); + zooInspectorPanel.connect(connectionProps); + } + }); + GridBagConstraints c4 = new GridBagConstraints(); + c4.gridx = 2; + c4.gridy = 0; + c4.gridwidth = 1; + c4.gridheight = 1; + c4.weightx = 0; + c4.weighty = 1; + c4.anchor = GridBagConstraints.SOUTH; + c4.fill = GridBagConstraints.HORIZONTAL; + c4.insets = new Insets(5, 5, 5, 5); + c4.ipadx = 0; + c4.ipady = 0; + buttonsPanel.add(okButton, c4); + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + ZooInspectorConnectionPropertiesDialog.this.dispose(); + } + }); + GridBagConstraints c5 = new GridBagConstraints(); + c5.gridx = 3; + c5.gridy = 0; + c5.gridwidth = 1; + c5.gridheight = 1; + c5.weightx = 0; + c5.weighty = 1; + c5.anchor = GridBagConstraints.SOUTH; + c5.fill = GridBagConstraints.HORIZONTAL; + c5.insets = new Insets(5, 5, 5, 5); + c5.ipadx = 0; + c5.ipady = 0; + buttonsPanel.add(cancelButton, c5); + this.add(options, BorderLayout.CENTER); + this.add(buttonsPanel, BorderLayout.SOUTH); + this.pack(); + } + + private void loadConnectionProps(Properties props) { + if (props != null) { + for (Object key : props.keySet()) { + String propsKey = (String) key; + if (components.containsKey(propsKey)) { + JComponent component = components.get(propsKey); + String value = props.getProperty(propsKey); + if (component instanceof JTextField) { + ((JTextField) component).setText(value); + } else if (component instanceof JComboBox) { + ((JComboBox) component).setSelectedItem(value); + } + } + } + } + } + + private Properties getConnectionProps() { + Properties connectionProps = new Properties(); + for (Entry entry : components.entrySet()) { + String value = null; + JComponent component = entry.getValue(); + if (component instanceof JTextField) { + value = ((JTextField) component).getText(); + } else if (component instanceof JComboBox) { + value = ((JComboBox) component).getSelectedItem().toString(); + } + connectionProps.put(entry.getKey(), value); + } + return connectionProps; + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersDialog.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersDialog.java new file mode 100644 index 00000000000..10a798d9054 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersDialog.java @@ -0,0 +1,603 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui; + +import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer; +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.inspector.manager.ZooInspectorManager; + +import java.awt.*; +import java.awt.datatransfer.Transferable; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * A {@link JDialog} for configuring which {@link ZooInspectorNodeViewer}s to + * show in the application + */ +public class ZooInspectorNodeViewersDialog extends JDialog implements + ListSelectionListener { + + private final JList viewersList; + private final JFileChooser fileChooser = new JFileChooser(new File(".")); + private final Map buttons = new HashMap(); + + /** + * @param frame + * - the Frame from which the dialog is displayed + * @param currentViewers + * - the {@link ZooInspectorNodeViewer}s to show + * @param listeners + * - the {@link NodeViewersChangeListener}s which need to be + * notified of changes to the node viewers configuration + * @param manager + * - the {@link ZooInspectorManager} for the application + * + */ + public ZooInspectorNodeViewersDialog(Frame frame, + final List currentViewers, + final Collection listeners, + final ZooInspectorManager manager, + final IconResource iconResource) { + super(frame); + final List newViewers = new ArrayList( + currentViewers); + this.setLayout(new BorderLayout()); + this.setIconImage(iconResource.get(IconResource.ICON_ChangeNodeViewers, "") + .getImage()); + this.setTitle("About ZooInspector"); + this.setModal(true); + this.setAlwaysOnTop(true); + this.setResizable(true); + final JPanel panel = new JPanel(); + panel.setLayout(new GridBagLayout()); + viewersList = new JList(); + DefaultListModel model = new DefaultListModel(); + for (ZooInspectorNodeViewer viewer : newViewers) { + model.addElement(viewer); + } + viewersList.setModel(model); + viewersList.setCellRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, + Object value, int index, boolean isSelected, + boolean cellHasFocus) { + ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) value; + JLabel label = (JLabel) super.getListCellRendererComponent( + list, value, index, isSelected, cellHasFocus); + label.setText(viewer.getTitle()); + return label; + } + }); + viewersList.setDropMode(DropMode.INSERT); + viewersList.enableInputMethods(true); + viewersList.setDragEnabled(true); + viewersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + viewersList.getSelectionModel().addListSelectionListener(this); + viewersList.setTransferHandler(new TransferHandler() { + + @Override + public boolean canImport(TransferHandler.TransferSupport info) { + // we only import NodeViewers + if (!info + .isDataFlavorSupported(ZooInspectorNodeViewer.nodeViewerDataFlavor)) { + return false; + } + + JList.DropLocation dl = (JList.DropLocation) info + .getDropLocation(); + if (dl.getIndex() == -1) { + return false; + } + return true; + } + + @Override + public boolean importData(TransferHandler.TransferSupport info) { + JList.DropLocation dl = (JList.DropLocation) info + .getDropLocation(); + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + int index = dl.getIndex(); + boolean insert = dl.isInsert(); + // Get the string that is being dropped. + Transferable t = info.getTransferable(); + String data; + try { + data = (String) t + .getTransferData(ZooInspectorNodeViewer.nodeViewerDataFlavor); + } catch (Exception e) { + return false; + } + try { + ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) Class + .forName(data).newInstance(); + if (listModel.contains(viewer)) { + listModel.removeElement(viewer); + } + if (insert) { + listModel.add(index, viewer); + } else { + listModel.set(index, viewer); + } + return true; + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error instantiating class: " + data, e); + return false; + } + + } + + @Override + public int getSourceActions(JComponent c) { + return MOVE; + } + + @Override + protected Transferable createTransferable(JComponent c) { + JList list = (JList) c; + ZooInspectorNodeViewer value = (ZooInspectorNodeViewer) list + .getSelectedValue(); + return value; + } + }); + JScrollPane scroller = new JScrollPane(viewersList); + GridBagConstraints c1 = new GridBagConstraints(); + c1.gridx = 0; + c1.gridy = 0; + c1.gridwidth = 3; + c1.gridheight = 3; + c1.weightx = 0; + c1.weighty = 1; + c1.anchor = GridBagConstraints.CENTER; + c1.fill = GridBagConstraints.BOTH; + c1.insets = new Insets(5, 5, 5, 5); + c1.ipadx = 0; + c1.ipady = 0; + panel.add(scroller, c1); + + final JTextField newViewerTextField = new JTextField(); + + for (Button button : Button.values()) { + JButton jbutton = button.createJButton(iconResource); + buttons.put(button, jbutton); + } + GridBagConstraints c2 = new GridBagConstraints(); + c2.gridx = 3; + c2.gridy = 0; + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weightx = 0; + c2.weighty = 0; + c2.anchor = GridBagConstraints.NORTH; + c2.fill = GridBagConstraints.HORIZONTAL; + c2.insets = new Insets(5, 5, 5, 5); + c2.ipadx = 0; + c2.ipady = 0; + panel.add(buttons.get(Button.up), c2); + GridBagConstraints c3 = new GridBagConstraints(); + c3.gridx = 3; + c3.gridy = 2; + c3.gridwidth = 1; + c3.gridheight = 1; + c3.weightx = 0; + c3.weighty = 0; + c3.anchor = GridBagConstraints.NORTH; + c3.fill = GridBagConstraints.HORIZONTAL; + c3.insets = new Insets(5, 5, 5, 5); + c3.ipadx = 0; + c3.ipady = 0; + panel.add(buttons.get(Button.down), c3); + GridBagConstraints c4 = new GridBagConstraints(); + c4.gridx = 3; + c4.gridy = 1; + c4.gridwidth = 1; + c4.gridheight = 1; + c4.weightx = 0; + c4.weighty = 0; + c4.anchor = GridBagConstraints.NORTH; + c4.fill = GridBagConstraints.HORIZONTAL; + c4.insets = new Insets(5, 5, 5, 5); + c4.ipadx = 0; + c4.ipady = 0; + panel.add(buttons.get(Button.remove), c4); + GridBagConstraints c5 = new GridBagConstraints(); + c5.gridx = 0; + c5.gridy = 3; + c5.gridwidth = 3; + c5.gridheight = 1; + c5.weightx = 0; + c5.weighty = 0; + c5.anchor = GridBagConstraints.CENTER; + c5.fill = GridBagConstraints.BOTH; + c5.insets = new Insets(5, 5, 5, 5); + c5.ipadx = 0; + c5.ipady = 0; + panel.add(newViewerTextField, c5); + GridBagConstraints c6 = new GridBagConstraints(); + c6.gridx = 3; + c6.gridy = 3; + c6.gridwidth = 1; + c6.gridheight = 1; + c6.weightx = 0; + c6.weighty = 0; + c6.anchor = GridBagConstraints.CENTER; + c6.fill = GridBagConstraints.BOTH; + c6.insets = new Insets(5, 5, 5, 5); + c6.ipadx = 0; + c6.ipady = 0; + panel.add(buttons.get(Button.add), c6); + buttons.get(Button.up).addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) viewersList + .getSelectedValue(); + int index = viewersList.getSelectedIndex(); + if (listModel.contains(viewer)) { + listModel.removeElementAt(index); + listModel.insertElementAt(viewer, index - 1); + viewersList.setSelectedValue(viewer, true); + } + } + }); + buttons.get(Button.down).addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) viewersList + .getSelectedValue(); + int index = viewersList.getSelectedIndex(); + if (listModel.contains(viewer)) { + listModel.removeElementAt(index); + listModel.insertElementAt(viewer, index + 1); + viewersList.setSelectedValue(viewer, true); + } + } + }); + buttons.get(Button.remove).addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) viewersList + .getSelectedValue(); + int index = viewersList.getSelectedIndex(); + if (listModel.contains(viewer)) { + listModel.removeElement(viewer); + viewersList + .setSelectedIndex(index == listModel.size() ? index - 1 + : index); + } + } + }); + buttons.get(Button.add).addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + String className = newViewerTextField.getText(); + if (className == null || className.length() == 0) { + JOptionPane + .showMessageDialog( + ZooInspectorNodeViewersDialog.this, + "Please enter the full class name for a Node Viewer and click the add button", + "Input Error", JOptionPane.ERROR_MESSAGE); + } else { + try { + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) Class + .forName(className).newInstance(); + if (listModel.contains(viewer)) { + JOptionPane + .showMessageDialog( + ZooInspectorNodeViewersDialog.this, + "Node viewer already exists. Each node viewer can only be added once.", + "Input Error", + JOptionPane.ERROR_MESSAGE); + } else { + listModel.addElement(viewer); + } + } catch (Exception ex) { + LoggerFactory + .getLogger() + .error( + "An error occurred while instaniating the node viewer. ", + ex); + JOptionPane.showMessageDialog( + ZooInspectorNodeViewersDialog.this, + "An error occurred while instaniating the node viewer: " + + ex.getMessage(), "Error", + JOptionPane.ERROR_MESSAGE); + } + } + } + }); + + GridBagConstraints c7 = new GridBagConstraints(); + c7.gridx = 0; + c7.gridy = 4; + c7.gridwidth = 1; + c7.gridheight = 1; + c7.weightx = 1; + c7.weighty = 0; + c7.anchor = GridBagConstraints.WEST; + c7.fill = GridBagConstraints.VERTICAL; + c7.insets = new Insets(5, 5, 5, 5); + c7.ipadx = 0; + c7.ipady = 0; + panel.add(buttons.get(Button.save), c7); + GridBagConstraints c8 = new GridBagConstraints(); + c8.gridx = 1; + c8.gridy = 4; + c8.gridwidth = 1; + c8.gridheight = 1; + c8.weightx = 0; + c8.weighty = 0; + c8.anchor = GridBagConstraints.WEST; + c8.fill = GridBagConstraints.VERTICAL; + c8.insets = new Insets(5, 5, 5, 5); + c8.ipadx = 0; + c8.ipady = 0; + panel.add(buttons.get(Button.load), c8); + GridBagConstraints c9 = new GridBagConstraints(); + c9.gridx = 2; + c9.gridy = 4; + c9.gridwidth = 1; + c9.gridheight = 1; + c9.weightx = 0; + c9.weighty = 0; + c9.anchor = GridBagConstraints.WEST; + c9.fill = GridBagConstraints.VERTICAL; + c9.insets = new Insets(5, 5, 5, 5); + c9.ipadx = 0; + c9.ipady = 0; + panel.add(buttons.get(Button.setDefaults), c9); + buttons.get(Button.save).addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + int result = fileChooser + .showSaveDialog(ZooInspectorNodeViewersDialog.this); + if (result == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + int answer = JOptionPane.YES_OPTION; + if (selectedFile.exists()) { + answer = JOptionPane + .showConfirmDialog( + ZooInspectorNodeViewersDialog.this, + "The specified file already exists. do you want to overwrite it?", + "Confirm Overwrite", + JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE); + } + if (answer == JOptionPane.YES_OPTION) { + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + List nodeViewersClassNames = new ArrayList(); + Object[] modelContents = listModel.toArray(); + for (Object o : modelContents) { + nodeViewersClassNames + .add(((ZooInspectorNodeViewer) o) + .getClass().getCanonicalName()); + } + try { + manager.saveNodeViewersFile(selectedFile, + nodeViewersClassNames); + } catch (IOException ex) { + LoggerFactory + .getLogger() + .error( + "Error saving node viewer configuration from file.", + ex); + JOptionPane.showMessageDialog( + ZooInspectorNodeViewersDialog.this, + "Error saving node viewer configuration from file: " + + ex.getMessage(), "Error", + JOptionPane.ERROR_MESSAGE); + } + } + } + } + }); + buttons.get(Button.load).addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + int result = fileChooser + .showOpenDialog(ZooInspectorNodeViewersDialog.this); + if (result == JFileChooser.APPROVE_OPTION) { + try { + List nodeViewersClassNames = manager + .loadNodeViewersFile(fileChooser + .getSelectedFile()); + List nodeViewers = new ArrayList(); + for (String nodeViewersClassName : nodeViewersClassNames) { + ZooInspectorNodeViewer viewer = (ZooInspectorNodeViewer) Class + .forName(nodeViewersClassName) + .newInstance(); + nodeViewers.add(viewer); + } + DefaultListModel model = new DefaultListModel(); + for (ZooInspectorNodeViewer viewer : nodeViewers) { + model.addElement(viewer); + } + viewersList.setModel(model); + panel.revalidate(); + panel.repaint(); + } catch (Exception ex) { + LoggerFactory + .getLogger() + .error( + "Error loading node viewer configuration from file.", + ex); + JOptionPane.showMessageDialog( + ZooInspectorNodeViewersDialog.this, + "Error loading node viewer configuration from file: " + + ex.getMessage(), "Error", + JOptionPane.ERROR_MESSAGE); + } + } + } + }); + buttons.get(Button.setDefaults).addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + int answer = JOptionPane + .showConfirmDialog( + ZooInspectorNodeViewersDialog.this, + "Are you sure you want to save this configuration as the default?", + "Confirm Set Defaults", + JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE); + if (answer == JOptionPane.YES_OPTION) { + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + List nodeViewersClassNames = new ArrayList(); + Object[] modelContents = listModel.toArray(); + for (Object o : modelContents) { + nodeViewersClassNames.add(((ZooInspectorNodeViewer) o) + .getClass().getCanonicalName()); + } + try { + manager + .setDefaultNodeViewerConfiguration(nodeViewersClassNames); + } catch (IOException ex) { + LoggerFactory + .getLogger() + .error( + "Error setting default node viewer configuration.", + ex); + JOptionPane.showMessageDialog( + ZooInspectorNodeViewersDialog.this, + "Error setting default node viewer configuration: " + + ex.getMessage(), "Error", + JOptionPane.ERROR_MESSAGE); + } + } + } + }); + + JPanel buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); + JButton okButton = new JButton("OK"); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ZooInspectorNodeViewersDialog.this.dispose(); + DefaultListModel listModel = (DefaultListModel) viewersList + .getModel(); + newViewers.clear(); + Object[] modelContents = listModel.toArray(); + for (Object o : modelContents) { + newViewers.add((ZooInspectorNodeViewer) o); + } + currentViewers.clear(); + currentViewers.addAll(newViewers); + for (NodeViewersChangeListener listener : listeners) { + listener.nodeViewersChanged(currentViewers); + } + } + }); + buttonsPanel.add(okButton); + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ZooInspectorNodeViewersDialog.this.dispose(); + } + }); + buttonsPanel.add(cancelButton); + this.add(panel, BorderLayout.CENTER); + this.add(buttonsPanel, BorderLayout.SOUTH); + this.pack(); + } + + /* + * (non-Javadoc) + * + * @see + * javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event + * .ListSelectionEvent) + */ + public void valueChanged(ListSelectionEvent e) { + JButton removeButton = buttons.get(Button.remove); + JButton upButton = buttons.get(Button.up); + JButton downButton = buttons.get(Button.down); + int index = viewersList.getSelectedIndex(); + + if (index == -1) { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + } else { + removeButton.setEnabled(true); + if (index == 0) { + upButton.setEnabled(false); + } else { + upButton.setEnabled(true); + } + if (index == ((DefaultListModel) viewersList.getModel()).getSize()) { + downButton.setEnabled(false); + } else { + downButton.setEnabled(true); + } + } + } + + public static enum Button { + up("Move currently selected node viewer up", IconResource.ICON_UP, false), + down("Move currently selected node viewer down", IconResource.ICON_DOWN, false), + add("Add node viewer", IconResource.ICON_ADD, true), + remove("Remove currently selected node viewer", IconResource.ICON_REMOVE, false), + save("Save current node viewer configuration to file", "Save"), + load("Load node viewer configuration from file", "Load"), + setDefaults("Set current configuration asd defaults", "Set as defaults"); + + private String toolTip; + private String icon; + private boolean enabled; + + Button(String toolTip, String icon, boolean enabled) { + this.toolTip = toolTip; + this.icon = icon; + this.enabled = enabled; + } + + Button(String toolTip, String icon) { + this(toolTip, icon, true); + } + + public JButton createJButton(IconResource iconResource) { + ImageIcon imageIcon = iconResource.get(icon, toolTip); + JButton jbutton; + + if (imageIcon == null) { + jbutton = new JButton(icon); + } else { + jbutton = new JButton(imageIcon); + } + + jbutton.setEnabled(enabled); + jbutton.setToolTipText(toolTip); + return jbutton; + } + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersPanel.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersPanel.java new file mode 100644 index 00000000000..d0a4630b618 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorNodeViewersPanel.java @@ -0,0 +1,132 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui; + +import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer; +import org.apache.zookeeper.inspector.manager.ZooInspectorManager; +import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.TreePath; + +/** + * This is the {@link JPanel} which contains the {@link ZooInspectorNodeViewer}s + */ +public class ZooInspectorNodeViewersPanel extends JPanel implements + TreeSelectionListener, ChangeListener { + + private final List nodeVeiwers = new ArrayList(); + private final List needsReload = new ArrayList(); + private final JTabbedPane tabbedPane; + private final List selectedNodes = new ArrayList(); + private final ZooInspectorNodeManager zooInspectorManager; + + /** + * @param zooInspectorManager + * - the {@link ZooInspectorManager} for the application + * @param nodeVeiwers + * - the {@link ZooInspectorNodeViewer}s to show + */ + public ZooInspectorNodeViewersPanel( + ZooInspectorNodeManager zooInspectorManager, + List nodeVeiwers) { + this.zooInspectorManager = zooInspectorManager; + this.setLayout(new BorderLayout()); + tabbedPane = new JTabbedPane(JTabbedPane.TOP, + JTabbedPane.WRAP_TAB_LAYOUT); + setNodeViewers(nodeVeiwers); + tabbedPane.addChangeListener(this); + this.add(tabbedPane, BorderLayout.CENTER); + reloadSelectedViewer(); + } + + /** + * @param nodeViewers + * - the {@link ZooInspectorNodeViewer}s to show + */ + public void setNodeViewers(List nodeViewers) { + this.nodeVeiwers.clear(); + this.nodeVeiwers.addAll(nodeViewers); + needsReload.clear(); + tabbedPane.removeAll(); + for (ZooInspectorNodeViewer nodeViewer : nodeVeiwers) { + nodeViewer.setZooInspectorManager(zooInspectorManager); + needsReload.add(true); + tabbedPane.add(nodeViewer.getTitle(), nodeViewer); + } + this.revalidate(); + this.repaint(); + } + + private void reloadSelectedViewer() { + int index = this.tabbedPane.getSelectedIndex(); + if (index != -1 && this.needsReload.get(index)) { + ZooInspectorNodeViewer viewer = this.nodeVeiwers.get(index); + viewer.nodeSelectionChanged(selectedNodes); + this.needsReload.set(index, false); + } + } + + /* + * (non-Javadoc) + * + * @see + * javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event + * .TreeSelectionEvent) + */ + public void valueChanged(TreeSelectionEvent e) { + TreePath[] paths = e.getPaths(); + selectedNodes.clear(); + for (TreePath path : paths) { + boolean appended = false; + StringBuilder sb = new StringBuilder(); + Object[] pathArray = path.getPath(); + for (Object o : pathArray) { + if (o != null) { + String nodeName = o.toString(); + if (nodeName != null) { + if (nodeName.length() > 0) { + appended = true; + sb.append("/"); //$NON-NLS-1$ + sb.append(o.toString()); + } + } + } + } + if (appended) { + selectedNodes.add(sb.toString()); + } + } + for (int i = 0; i < needsReload.size(); i++) { + this.needsReload.set(i, true); + } + reloadSelectedViewer(); + } + + /* + * (non-Javadoc) + * + * @see + * javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent + * ) + */ + public void stateChanged(ChangeEvent e) { + reloadSelectedViewer(); + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java new file mode 100644 index 00000000000..072bf9639ce --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorPanel.java @@ -0,0 +1,306 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui; + +import org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer; +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.inspector.manager.ZooInspectorManager; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import javax.swing.*; + +/** + * The parent {@link JPanel} for the whole application + */ +public class ZooInspectorPanel extends JPanel implements + NodeViewersChangeListener { + private final IconResource iconResource; + private final Toolbar toolbar; + private final ZooInspectorNodeViewersPanel nodeViewersPanel; + private final ZooInspectorTreeViewer treeViewer; + private final ZooInspectorManager zooInspectorManager; + + private final List listeners = new ArrayList(); + + { + listeners.add(this); + } + + /** + * @param zooInspectorManager + * - the {@link ZooInspectorManager} for the application + */ + public ZooInspectorPanel(final ZooInspectorManager zooInspectorManager, final IconResource iconResource) { + this.zooInspectorManager = zooInspectorManager; + this.iconResource = iconResource; + toolbar = new Toolbar(iconResource); + final ArrayList nodeViewers = new ArrayList(); + try { + List defaultNodeViewersClassNames = this.zooInspectorManager + .getDefaultNodeViewerConfiguration(); + for (String className : defaultNodeViewersClassNames) { + nodeViewers.add((ZooInspectorNodeViewer) Class.forName( + className).newInstance()); + } + } catch (Exception ex) { + LoggerFactory.getLogger().error( + "Error loading default node viewers.", ex); + JOptionPane.showMessageDialog(ZooInspectorPanel.this, + "Error loading default node viewers: " + ex.getMessage(), + "Error", JOptionPane.ERROR_MESSAGE); + } + nodeViewersPanel = new ZooInspectorNodeViewersPanel( + zooInspectorManager, nodeViewers); + treeViewer = new ZooInspectorTreeViewer(zooInspectorManager, + nodeViewersPanel, iconResource); + this.setLayout(new BorderLayout()); + + toolbar.addActionListener(Toolbar.Button.connect, new ActionListener() { + public void actionPerformed(ActionEvent e) { + ZooInspectorConnectionPropertiesDialog zicpd = new ZooInspectorConnectionPropertiesDialog( + zooInspectorManager.getLastConnectionProps(), + zooInspectorManager.getConnectionPropertiesTemplate(), + ZooInspectorPanel.this); + zicpd.setVisible(true); + } + }); + toolbar.addActionListener(Toolbar.Button.disconnect, new ActionListener() { + public void actionPerformed(ActionEvent e) { + disconnect(); + } + }); + toolbar.addActionListener(Toolbar.Button.refresh, new ActionListener() { + public void actionPerformed(ActionEvent e) { + treeViewer.refreshView(); + } + }); + toolbar.addActionListener(Toolbar.Button.addNode, new ActionListener() { + public void actionPerformed(ActionEvent e) { + final List selectedNodes = treeViewer + .getSelectedNodes(); + if (selectedNodes.size() == 1) { + final String nodeName = JOptionPane.showInputDialog( + ZooInspectorPanel.this, + "Please Enter a name for the new node", + "Create Node", JOptionPane.INFORMATION_MESSAGE); + if (nodeName != null && nodeName.length() > 0) { + SwingWorker worker = new SwingWorker() { + + @Override + protected Boolean doInBackground() throws Exception { + return ZooInspectorPanel.this.zooInspectorManager + .createNode(selectedNodes.get(0), + nodeName); + } + + @Override + protected void done() { + treeViewer.refreshView(); + } + }; + worker.execute(); + } + } else { + JOptionPane.showMessageDialog(ZooInspectorPanel.this, + "Please select 1 parent node for the new node."); + } + } + }); + toolbar.addActionListener(Toolbar.Button.deleteNode, new ActionListener() { + public void actionPerformed(ActionEvent e) { + final List selectedNodes = treeViewer + .getSelectedNodes(); + if (selectedNodes.size() == 0) { + JOptionPane.showMessageDialog(ZooInspectorPanel.this, + "Please select at least 1 node to be deleted"); + } else { + int answer = JOptionPane.showConfirmDialog( + ZooInspectorPanel.this, + "Are you sure you want to delete the selected nodes?" + + "(This action cannot be reverted)", + "Confirm Delete", JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE); + if (answer == JOptionPane.YES_OPTION) { + SwingWorker worker = new SwingWorker() { + + @Override + protected Boolean doInBackground() throws Exception { + for (String nodePath : selectedNodes) { + ZooInspectorPanel.this.zooInspectorManager + .deleteNode(nodePath); + } + return true; + } + + @Override + protected void done() { + treeViewer.refreshView(); + } + }; + worker.execute(); + } + } + } + }); + toolbar.addActionListener(Toolbar.Button.nodeViewers, new ActionListener() { + + public void actionPerformed(ActionEvent e) { + ZooInspectorNodeViewersDialog nvd = new ZooInspectorNodeViewersDialog( + JOptionPane.getRootFrame(), nodeViewers, listeners, + zooInspectorManager, iconResource); + nvd.setVisible(true); + } + }); + toolbar.addActionListener(Toolbar.Button.about, new ActionListener() { + public void actionPerformed(ActionEvent e) { + ZooInspectorAboutDialog zicpd = new ZooInspectorAboutDialog( + JOptionPane.getRootFrame(), iconResource); + zicpd.setVisible(true); + } + }); + JScrollPane treeScroller = new JScrollPane(treeViewer); + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, + treeScroller, nodeViewersPanel); + splitPane.setResizeWeight(0.25); + this.add(splitPane, BorderLayout.CENTER); + this.add(toolbar.getJToolBar(), BorderLayout.NORTH); + } + + /** + * @param connectionProps + * the {@link Properties} for connecting to the zookeeper + * instance + */ + public void connect(final Properties connectionProps) { + SwingWorker worker = new SwingWorker() { + + @Override + protected Boolean doInBackground() throws Exception { + zooInspectorManager.setLastConnectionProps(connectionProps); + return zooInspectorManager.connect(connectionProps); + } + + @Override + protected void done() { + try { + if (get()) { + treeViewer.refreshView(); + toolbar.toggleButtons(true); + } else { + JOptionPane.showMessageDialog(ZooInspectorPanel.this, + "Unable to connect to zookeeper", "Error", + JOptionPane.ERROR_MESSAGE); + } + } catch (InterruptedException e) { + LoggerFactory + .getLogger() + .error( + "Error occurred while connecting to ZooKeeper server", + e); + } catch (ExecutionException e) { + LoggerFactory + .getLogger() + .error( + "Error occurred while connecting to ZooKeeper server", + e); + } + } + + }; + worker.execute(); + } + + /** + * + */ + public void disconnect() { + disconnect(false); + } + + /** + * @param wait + * - set this to true if the method should only return once the + * application has successfully disconnected + */ + public void disconnect(boolean wait) { + SwingWorker worker = new SwingWorker() { + + @Override + protected Boolean doInBackground() throws Exception { + return ZooInspectorPanel.this.zooInspectorManager.disconnect(); + } + + @Override + protected void done() { + try { + if (get()) { + treeViewer.clearView(); + toolbar.toggleButtons(false); + } + } catch (InterruptedException e) { + LoggerFactory + .getLogger() + .error( + "Error occurred while disconnecting from ZooKeeper server", + e); + } catch (ExecutionException e) { + LoggerFactory + .getLogger() + .error( + "Error occurred while disconnecting from ZooKeeper server", + e); + } + } + + }; + worker.execute(); + if (wait) { + while (!worker.isDone()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + LoggerFactory + .getLogger() + .error( + "Error occurred while disconnecting from ZooKeeper server", + e); + } + } + } + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.gui.NodeViewersChangeListener# + * nodeViewersChanged(java.util.List) + */ + public void nodeViewersChanged(List newViewers) { + this.nodeViewersPanel.setNodeViewers(newViewers); + } + + /** + * @param connectionProps + * @throws IOException + */ + public void setdefaultConnectionProps(Properties connectionProps) + throws IOException { + this.zooInspectorManager.saveDefaultConnectionFile(connectionProps); + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java new file mode 100644 index 00000000000..6683885ae39 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/ZooInspectorTreeViewer.java @@ -0,0 +1,343 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui; + +import com.nitido.utils.toaster.Toaster; + +import org.apache.zookeeper.inspector.manager.NodeListener; +import org.apache.zookeeper.inspector.manager.ZooInspectorManager; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.swing.*; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; + +/** + * A {@link JPanel} for showing the tree view of all the nodes in the zookeeper + * instance + */ +public class ZooInspectorTreeViewer extends JPanel implements NodeListener { + private final ZooInspectorManager zooInspectorManager; + private final JTree tree; + private final Toaster toasterManager; + private final ImageIcon toasterIcon; + + /** + * @param zooInspectorManager + * - the {@link ZooInspectorManager} for the application + * @param listener + * - the {@link TreeSelectionListener} to listen for changes in + * the selected node on the node tree + */ + public ZooInspectorTreeViewer( + final ZooInspectorManager zooInspectorManager, + TreeSelectionListener listener, IconResource iconResource) { + this.zooInspectorManager = zooInspectorManager; + this.setLayout(new BorderLayout()); + final JPopupMenu popupMenu = new JPopupMenu(); + final JMenuItem addNotify = new JMenuItem("Add Change Notification"); + this.toasterManager = new Toaster(); + this.toasterManager.setBorderColor(Color.BLACK); + this.toasterManager.setMessageColor(Color.BLACK); + this.toasterManager.setToasterColor(Color.WHITE); + toasterIcon = iconResource.get(IconResource.ICON_INFORMATION, ""); + addNotify.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + List selectedNodes = getSelectedNodes(); + zooInspectorManager.addWatchers(selectedNodes, + ZooInspectorTreeViewer.this); + } + }); + final JMenuItem removeNotify = new JMenuItem( + "Remove Change Notification"); + removeNotify.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + List selectedNodes = getSelectedNodes(); + zooInspectorManager.removeWatchers(selectedNodes); + } + }); + tree = new JTree(new DefaultMutableTreeNode()); + tree.setCellRenderer(new ZooInspectorTreeCellRenderer(iconResource)); + tree.setEditable(false); + tree.getSelectionModel().addTreeSelectionListener(listener); + tree.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3) { + // TODO only show add if a selected node isn't being + // watched, and only show remove if a selected node is being + // watched + popupMenu.removeAll(); + popupMenu.add(addNotify); + popupMenu.add(removeNotify); + popupMenu.show(ZooInspectorTreeViewer.this, e.getX(), e + .getY()); + } + } + }); + this.add(tree, BorderLayout.CENTER); + } + + /** + * Refresh the tree view + */ + public void refreshView() { + final Set expandedNodes = new LinkedHashSet(); + int rowCount = tree.getRowCount(); + for (int i = 0; i < rowCount; i++) { + TreePath path = tree.getPathForRow(i); + if (tree.isExpanded(path)) { + expandedNodes.add(path); + } + } + final TreePath[] selectedNodes = tree.getSelectionPaths(); + SwingWorker worker = new SwingWorker() { + + @Override + protected Boolean doInBackground() throws Exception { + tree.setModel(new DefaultTreeModel(new ZooInspectorTreeNode( + "/", null))); + return true; + } + + @Override + protected void done() { + for (TreePath path : expandedNodes) { + tree.expandPath(path); + } + tree.getSelectionModel().setSelectionPaths(selectedNodes); + } + }; + worker.execute(); + } + + /** + * clear the tree view of all nodes + */ + public void clearView() { + tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); + } + + /** + * @return {@link List} of the currently selected nodes + */ + public List getSelectedNodes() { + TreePath[] paths = tree.getSelectionPaths(); + List selectedNodes = new ArrayList(); + if (paths != null) { + for (TreePath path : paths) { + StringBuilder sb = new StringBuilder(); + Object[] pathArray = path.getPath(); + for (Object o : pathArray) { + String nodeName = o.toString(); + if (nodeName.length() > 0) { + sb.append("/"); + sb.append(o.toString()); + } + } + selectedNodes.add(sb.toString()); + } + } + return selectedNodes; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.NodeListener#processEvent(java + * .lang.String, java.lang.String, java.util.Map) + */ + public void processEvent(String nodePath, String eventType, + Map eventInfo) { + StringBuilder sb = new StringBuilder(); + sb.append("Node: "); + sb.append(nodePath); + sb.append("\nEvent: "); + sb.append(eventType); + if (eventInfo != null) { + for (Map.Entry entry : eventInfo.entrySet()) { + sb.append("\n"); + sb.append(entry.getKey()); + sb.append(": "); + sb.append(entry.getValue()); + } + } + this.toasterManager.showToaster(toasterIcon, sb.toString()); + } + + private static class ZooInspectorTreeCellRenderer extends + DefaultTreeCellRenderer { + public ZooInspectorTreeCellRenderer(IconResource iconResource) { + setLeafIcon(iconResource.get(IconResource.ICON_TREE_LEAF, "")); + setOpenIcon(iconResource.get(IconResource.ICON_TREE_OPEN, "")); + setClosedIcon(iconResource.get(IconResource.ICON_TREE_CLOSE, "")); + } + } + + private class ZooInspectorTreeNode implements TreeNode { + private final String nodePath; + private final String nodeName; + private final ZooInspectorTreeNode parent; + + public ZooInspectorTreeNode(String nodePath, ZooInspectorTreeNode parent) { + this.parent = parent; + this.nodePath = nodePath; + int index = nodePath.lastIndexOf("/"); + if (index == -1) { + throw new IllegalArgumentException("Invalid node path" + + nodePath); + } + this.nodeName = nodePath.substring(index + 1); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.tree.TreeNode#children() + */ + public Enumeration children() { + List children = zooInspectorManager + .getChildren(this.nodePath); + Collections.sort(children); + List returnChildren = new ArrayList(); + for (String child : children) { + returnChildren.add(new ZooInspectorTreeNode((this.nodePath + .equals("/") ? "" : this.nodePath) + + "/" + child, this)); + } + return Collections.enumeration(returnChildren); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.tree.TreeNode#getAllowsChildren() + */ + public boolean getAllowsChildren() { + return zooInspectorManager.isAllowsChildren(this.nodePath); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.tree.TreeNode#getChildAt(int) + */ + public TreeNode getChildAt(int childIndex) { + String child = zooInspectorManager.getNodeChild(this.nodePath, + childIndex); + if (child != null) { + return new ZooInspectorTreeNode((this.nodePath.equals("/") ? "" + : this.nodePath) + + "/" + child, this); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see javax.swing.tree.TreeNode#getChildCount() + */ + public int getChildCount() { + return zooInspectorManager.getNumChildren(this.nodePath); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode) + */ + public int getIndex(TreeNode node) { + return zooInspectorManager.getNodeIndex(this.nodePath); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.tree.TreeNode#getParent() + */ + public TreeNode getParent() { + return this.parent; + } + + /* + * (non-Javadoc) + * + * @see javax.swing.tree.TreeNode#isLeaf() + */ + public boolean isLeaf() { + return !zooInspectorManager.hasChildren(this.nodePath); + } + + @Override + public String toString() { + return this.nodeName; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + getOuterType().hashCode(); + result = prime * result + + ((nodePath == null) ? 0 : nodePath.hashCode()); + result = prime * result + + ((parent == null) ? 0 : parent.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ZooInspectorTreeNode other = (ZooInspectorTreeNode) obj; + if (!getOuterType().equals(other.getOuterType())) + return false; + if (nodePath == null) { + if (other.nodePath != null) + return false; + } else if (!nodePath.equals(other.nodePath)) + return false; + if (parent == null) { + if (other.parent != null) + return false; + } else if (!parent.equals(other.parent)) + return false; + return true; + } + + private ZooInspectorTreeViewer getOuterType() { + return ZooInspectorTreeViewer.this; + } + + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html new file mode 100644 index 00000000000..3454af5fa17 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/about.html @@ -0,0 +1,21 @@ + + + + + ZooInspector v0.1 + + +

ZooInspector was developed by Colin Goodheart-Smithe and is + available under the Apache Software Licence v2.0.

+

The Icons used were sourced from the Eclipse project (http://www.eclipse.org) and licensed + under the Eclipse Public Licence v1.0. [http://www.eclipse.org/org/documents/epl-v10.php] +

+

ZooKeeper is available from http://zookeeper.apache.org/ + and is licensed under an Apache Software Licence v2.0

+

The ApacheSoftware Licence v2.0 can be found at http://www.apache.org/licenses/LICENSE-2.0

+ + diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java new file mode 100644 index 00000000000..cd412e6e905 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerACL.java @@ -0,0 +1,171 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui.nodeviewer; + +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.swing.*; + +/** + * A node viewer for displaying the ACLs currently applied to the selected node + */ +public class NodeViewerACL extends ZooInspectorNodeViewer { + private final JPanel aclDataPanel; + private ZooInspectorNodeManager zooInspectorManager; + private String selectedNode; + + /** + * + */ + public NodeViewerACL() { + this.setLayout(new BorderLayout()); + this.aclDataPanel = new JPanel(); + this.aclDataPanel.setBackground(Color.WHITE); + JScrollPane scroller = new JScrollPane(this.aclDataPanel); + this.add(scroller, BorderLayout.CENTER); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * getTitle() + */ + @Override + public String getTitle() { + return "Node ACLs"; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * nodeSelectionChanged(java.util.Set) + */ + @Override + public void nodeSelectionChanged(List selectedNodes) { + this.aclDataPanel.removeAll(); + if (selectedNodes.size() > 0) { + this.selectedNode = selectedNodes.get(0); + SwingWorker>, Void> worker = new SwingWorker>, Void>() { + + @Override + protected List> doInBackground() + throws Exception { + return NodeViewerACL.this.zooInspectorManager + .getACLs(NodeViewerACL.this.selectedNode); + } + + @Override + protected void done() { + List> acls = null; + try { + acls = get(); + } catch (InterruptedException e) { + acls = new ArrayList>(); + LoggerFactory.getLogger().error( + "Error retrieving ACL Information for node: " + + NodeViewerACL.this.selectedNode, e); + } catch (ExecutionException e) { + acls = new ArrayList>(); + LoggerFactory.getLogger().error( + "Error retrieving ACL Information for node: " + + NodeViewerACL.this.selectedNode, e); + } + aclDataPanel.setLayout(new GridBagLayout()); + int j = 0; + for (Map data : acls) { + int rowPos = 2 * j + 1; + JPanel aclPanel = new JPanel(); + aclPanel.setBorder(BorderFactory + .createLineBorder(Color.BLACK)); + aclPanel.setBackground(Color.WHITE); + aclPanel.setLayout(new GridBagLayout()); + int i = 0; + for (Map.Entry entry : data.entrySet()) { + int rowPosACL = 2 * i + 1; + JLabel label = new JLabel(entry.getKey()); + JTextField text = new JTextField(entry.getValue()); + text.setEditable(false); + GridBagConstraints c1 = new GridBagConstraints(); + c1.gridx = 1; + c1.gridy = rowPosACL; + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weightx = 0; + c1.weighty = 0; + c1.anchor = GridBagConstraints.NORTHWEST; + c1.fill = GridBagConstraints.BOTH; + c1.insets = new Insets(5, 5, 5, 5); + c1.ipadx = 0; + c1.ipady = 0; + aclPanel.add(label, c1); + GridBagConstraints c2 = new GridBagConstraints(); + c2.gridx = 3; + c2.gridy = rowPosACL; + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weightx = 0; + c2.weighty = 0; + c2.anchor = GridBagConstraints.NORTHWEST; + c2.fill = GridBagConstraints.BOTH; + c2.insets = new Insets(5, 5, 5, 5); + c2.ipadx = 0; + c2.ipady = 0; + aclPanel.add(text, c2); + i++; + } + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = rowPos; + c.gridwidth = 1; + c.gridheight = 1; + c.weightx = 1; + c.weighty = 1; + c.anchor = GridBagConstraints.NORTHWEST; + c.fill = GridBagConstraints.NONE; + c.insets = new Insets(5, 5, 5, 5); + c.ipadx = 0; + c.ipady = 0; + aclDataPanel.add(aclPanel, c); + } + NodeViewerACL.this.aclDataPanel.revalidate(); + NodeViewerACL.this.aclDataPanel.repaint(); + } + }; + worker.execute(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * setZooInspectorManager + * (org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager) + */ + @Override + public void setZooInspectorManager( + ZooInspectorNodeManager zooInspectorManager) { + this.zooInspectorManager = zooInspectorManager; + } + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerData.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerData.java new file mode 100644 index 00000000000..09034ea907b --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerData.java @@ -0,0 +1,131 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui.nodeviewer; + +import org.apache.zookeeper.inspector.ZooInspector; +import org.apache.zookeeper.inspector.gui.IconResource; +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import java.util.concurrent.ExecutionException; + +import javax.swing.*; + +/** + * A node viewer for displaying the data for the currently selected node + */ +public class NodeViewerData extends ZooInspectorNodeViewer { + private final JTextPane dataArea; + private final JToolBar toolbar; + private ZooInspectorNodeManager zooInspectorManager; + private String selectedNode; + + public NodeViewerData() { + this.setLayout(new BorderLayout()); + this.dataArea = new JTextPane(); + this.toolbar = new JToolBar(); + this.toolbar.setFloatable(false); + JScrollPane scroller = new JScrollPane(this.dataArea); + scroller + .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + this.add(scroller, BorderLayout.CENTER); + this.add(this.toolbar, BorderLayout.NORTH); + JButton saveButton = new JButton(ZooInspector.iconResource.get(IconResource.ICON_SAVE, "")); + saveButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + if (selectedNode != null) { + if (JOptionPane.showConfirmDialog(NodeViewerData.this, + "Are you sure you want to save this node?" + + " (this action cannot be reverted)", + "Confirm Save", JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { + zooInspectorManager.setData(selectedNode, dataArea + .getText()); + } + } + } + }); + this.toolbar.add(saveButton); + + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * getTitle() + */ + @Override + public String getTitle() { + return "Node Data"; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * nodeSelectionChanged(java.util.Set) + */ + @Override + public void nodeSelectionChanged(List selectedNodes) { + if (selectedNodes.size() > 0) { + this.selectedNode = selectedNodes.get(0); + SwingWorker worker = new SwingWorker() { + + @Override + protected String doInBackground() throws Exception { + return NodeViewerData.this.zooInspectorManager + .getData(NodeViewerData.this.selectedNode); + } + + @Override + protected void done() { + String data = ""; + try { + data = get(); + } catch (InterruptedException e) { + LoggerFactory.getLogger().error( + "Error retrieving data for node: " + + NodeViewerData.this.selectedNode, e); + } catch (ExecutionException e) { + LoggerFactory.getLogger().error( + "Error retrieving data for node: " + + NodeViewerData.this.selectedNode, e); + } + NodeViewerData.this.dataArea.setText(data); + } + }; + worker.execute(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * setZooInspectorManager + * (org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager) + */ + @Override + public void setZooInspectorManager( + ZooInspectorNodeManager zooInspectorManager) { + this.zooInspectorManager = zooInspectorManager; + } + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerMetaData.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerMetaData.java new file mode 100644 index 00000000000..5d9de2f674c --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/NodeViewerMetaData.java @@ -0,0 +1,171 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui.nodeviewer; + +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager; + +import java.awt.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.swing.*; + +/** + * A node viewer for displaying the meta data for the currently selected node. + * The meta data is essentially the information from the {@link Stat} for the + * node + */ +public class NodeViewerMetaData extends ZooInspectorNodeViewer { + private final JPanel metaDataPanel; + private ZooInspectorNodeManager zooInspectorManager; + private String selectedNode; + + /** + * + */ + public NodeViewerMetaData() { + this.setLayout(new BorderLayout()); + this.metaDataPanel = new JPanel(); + this.metaDataPanel.setBackground(Color.WHITE); + JScrollPane scroller = new JScrollPane(this.metaDataPanel); + this.add(scroller, BorderLayout.CENTER); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * getTitle() + */ + @Override + public String getTitle() { + return "Node Metadata"; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * nodeSelectionChanged(java.util.Set) + */ + @Override + public void nodeSelectionChanged(List selectedNodes) { + this.metaDataPanel.removeAll(); + if (selectedNodes.size() > 0) { + this.selectedNode = selectedNodes.get(0); + SwingWorker, Void> worker = new SwingWorker, Void>() { + + @Override + protected Map doInBackground() throws Exception { + return NodeViewerMetaData.this.zooInspectorManager + .getNodeMeta(NodeViewerMetaData.this.selectedNode); + } + + @Override + protected void done() { + Map data = null; + try { + data = get(); + } catch (InterruptedException e) { + data = new HashMap(); + LoggerFactory.getLogger().error( + "Error retrieving meta data for node: " + + NodeViewerMetaData.this.selectedNode, + e); + } catch (ExecutionException e) { + data = new HashMap(); + LoggerFactory.getLogger().error( + "Error retrieving meta data for node: " + + NodeViewerMetaData.this.selectedNode, + e); + } + NodeViewerMetaData.this.metaDataPanel + .setLayout(new GridBagLayout()); + JPanel infoPanel = new JPanel(); + infoPanel.setBackground(Color.WHITE); + infoPanel.setLayout(new GridBagLayout()); + int i = 0; + int rowPos = 0; + for (Map.Entry entry : data.entrySet()) { + rowPos = 2 * i + 1; + JLabel label = new JLabel(entry.getKey()); + JTextField text = new JTextField(entry.getValue()); + text.setEditable(false); + GridBagConstraints c1 = new GridBagConstraints(); + c1.gridx = 0; + c1.gridy = rowPos; + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weightx = 0; + c1.weighty = 0; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.HORIZONTAL; + c1.insets = new Insets(5, 5, 5, 5); + c1.ipadx = 0; + c1.ipady = 0; + infoPanel.add(label, c1); + GridBagConstraints c2 = new GridBagConstraints(); + c2.gridx = 2; + c2.gridy = rowPos; + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weightx = 0; + c2.weighty = 0; + c2.anchor = GridBagConstraints.WEST; + c2.fill = GridBagConstraints.HORIZONTAL; + c2.insets = new Insets(5, 5, 5, 5); + c2.ipadx = 0; + c2.ipady = 0; + infoPanel.add(text, c2); + i++; + } + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = rowPos; + c.gridwidth = 1; + c.gridheight = 1; + c.weightx = 1; + c.weighty = 1; + c.anchor = GridBagConstraints.NORTHWEST; + c.fill = GridBagConstraints.NONE; + c.insets = new Insets(5, 5, 5, 5); + c.ipadx = 0; + c.ipady = 0; + NodeViewerMetaData.this.metaDataPanel.add(infoPanel, c); + NodeViewerMetaData.this.metaDataPanel.revalidate(); + NodeViewerMetaData.this.metaDataPanel.repaint(); + } + }; + worker.execute(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer# + * setZooInspectorManager + * (org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager) + */ + @Override + public void setZooInspectorManager( + ZooInspectorNodeManager zooInspectorManager) { + this.zooInspectorManager = zooInspectorManager; + } + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/ZooInspectorNodeViewer.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/ZooInspectorNodeViewer.java new file mode 100644 index 00000000000..eeece118aab --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/gui/nodeviewer/ZooInspectorNodeViewer.java @@ -0,0 +1,131 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.gui.nodeviewer; + +import org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import java.util.List; + +import javax.swing.*; + +/** + * A {@link JPanel} for displaying information about the currently selected + * node(s) + */ +public abstract class ZooInspectorNodeViewer extends JPanel implements + Transferable { + /** + * The {@link DataFlavor} used for DnD in the node viewer configuration + * dialog + */ + public static final DataFlavor nodeViewerDataFlavor = new DataFlavor( + ZooInspectorNodeViewer.class, "nodeviewer"); + + /** + * @param zooInspectorManager + */ + public abstract void setZooInspectorManager( + ZooInspectorNodeManager zooInspectorManager); + + /** + * Called whenever the selected nodes in the tree view changes. + * + * @param selectedNodes + * - the nodes currently selected in the tree view + * + */ + public abstract void nodeSelectionChanged(List selectedNodes); + + /** + * @return the title of the node viewer. this will be shown on the tab for + * this node viewer. + */ + public abstract String getTitle(); + + /* + * (non-Javadoc) + * + * @see + * java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer + * .DataFlavor) + */ + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException { + if (flavor.equals(nodeViewerDataFlavor)) { + return this.getClass().getCanonicalName(); + } else { + return null; + } + } + + /* + * (non-Javadoc) + * + * @see java.awt.datatransfer.Transferable#getTransferDataFlavors() + */ + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor[]{nodeViewerDataFlavor}; + } + + /* + * (non-Javadoc) + * + * @seejava.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt. + * datatransfer.DataFlavor) + */ + public boolean isDataFlavorSupported(DataFlavor flavor) { + return flavor.equals(nodeViewerDataFlavor); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((getTitle() == null) ? 0 : getTitle().hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ZooInspectorNodeViewer other = (ZooInspectorNodeViewer) obj; + if (getClass().getCanonicalName() != other.getClass() + .getCanonicalName()) { + return false; + } + if (getTitle() == null) { + if (other.getTitle() != null) + return false; + } else if (!getTitle().equals(other.getTitle())) + return false; + return true; + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/logger/LoggerFactory.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/logger/LoggerFactory.java new file mode 100644 index 00000000000..688f25ad95d --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/logger/LoggerFactory.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.logger; + +/** + * Provides a {@link Logger} for use across the entire application + * + */ +public class LoggerFactory { + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger("org.apache.zookeeper.inspector"); //$NON-NLS-1$ + + /** + * @return {@link Logger} for ZooInspector + */ + public static org.slf4j.Logger getLogger() { + return logger; + } + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/NodeListener.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/NodeListener.java new file mode 100644 index 00000000000..73b339a3a44 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/NodeListener.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.manager; + +import java.util.Map; + +/** + * A Listener for Events on zookeeper nodes + */ +public interface NodeListener { + /** + * @param nodePath + * - the path of the node + * @param eventType + * - the event type + * @param eventInfo + * - a {@link Map} containing any other information about this + * event + */ + public void processEvent(String nodePath, String eventType, + Map eventInfo); +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/Pair.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/Pair.java new file mode 100644 index 00000000000..c0b6d6ec31e --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/Pair.java @@ -0,0 +1,113 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.manager; + +/** + * A utility class for storing a pair of objects + * + * @param + * @param + */ +public class Pair { + private K key; + private V value; + + /** + * @param key + * @param value + */ + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + /** + * + */ + public Pair() { + // Do Nothing + } + + /** + * @return key + */ + public K getKey() { + return key; + } + + /** + * @param key + */ + public void setKey(K key) { + this.key = key; + } + + /** + * @return value + */ + public V getValue() { + return value; + } + + /** + * @param value + */ + public void setValue(V value) { + this.value = value; + } + + @Override + public String toString() { + return "Pair [" + key + ", " + value + "]"; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Pair other = (Pair) obj; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorManager.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorManager.java new file mode 100644 index 00000000000..9160fb3c2a1 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorManager.java @@ -0,0 +1,131 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.manager; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.swing.*; + +/** + * A Manager for all interactions between the application and the Zookeeper + * instance + */ +public interface ZooInspectorManager extends ZooInspectorNodeManager, + ZooInspectorNodeTreeManager { + + /** + * @param connectionProps + * @return true if successfully connected + */ + public boolean connect(Properties connectionProps); + + /** + * @return true if successfully disconnected + */ + public boolean disconnect(); + + /** + * @return a {@link Pair} containing the following: + *
    + *
  • a {@link Map} of property keys to list of possible values. If + * the list size is 1 the value is taken to be the default value for + * a {@link JTextField}. If the list size is greater than 1, the + * values are taken to be the possible options to show in a + * {@link JComboBox} with the first selected as default.
  • + *
  • a {@link Map} of property keys to the label to show on the UI + *
  • + *
      + * + */ + public Pair>, Map> getConnectionPropertiesTemplate(); + + /** + * @param selectedNodes + * - the nodes to add the watcher to + * @param nodeListener + * - the node listener for this watcher + */ + public void addWatchers(Collection selectedNodes, + NodeListener nodeListener); + + /** + * @param selectedNodes + * - the nodes to remove the watchers from + */ + public void removeWatchers(Collection selectedNodes); + + /** + * @param selectedFile + * - the file to load which contains the node viewers + * configuration + * @return nodeViewers - the class names of the node viewers from the + * configuration + * @throws IOException + * - if the configuration file cannot be loaded + */ + public List loadNodeViewersFile(File selectedFile) + throws IOException; + + /** + * @param selectedFile + * - the file to save the configuration to + * @param nodeViewersClassNames + * - the class names of the node viewers + * @throws IOException + * - if the configuration file cannot be saved + */ + public void saveNodeViewersFile(File selectedFile, + List nodeViewersClassNames) throws IOException; + + /** + * @return nodeViewers - the class names of the node viewers from the + * configuration + * @throws IOException + * - if the default configuration file cannot be loaded + */ + List getDefaultNodeViewerConfiguration() throws IOException; + + /** + * @param nodeViewersClassNames + * - the class names of the node viewers + * @throws IOException + * - if the default configuration file cannot be loaded + */ + public void setDefaultNodeViewerConfiguration( + List nodeViewersClassNames) throws IOException; + + /** + * @return last connection Properties - the connection properties last used + * to connect to the zookeeeper instance + */ + public Properties getLastConnectionProps(); + + /** + * @param connectionProps + * - the connection properties last used to connect to the + * zookeeeper instance + */ + public void setLastConnectionProps(Properties connectionProps); + + /** + * @param props + * - the properties to use as the default connection settings + * @throws IOException + * - if the default configuration file cannot be saved + */ + public void saveDefaultConnectionFile(Properties props) throws IOException; + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorManagerImpl.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorManagerImpl.java new file mode 100644 index 00000000000..303e6e87e9d --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorManagerImpl.java @@ -0,0 +1,875 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.manager; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.Perms; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager; +import org.apache.zookeeper.inspector.encryption.DataEncryptionManager; +import org.apache.zookeeper.inspector.logger.LoggerFactory; +import org.apache.zookeeper.retry.ZooKeeperRetry; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * A default implementation of {@link ZooInspectorManager} for connecting to + * zookeeper instances + */ +public class ZooInspectorManagerImpl implements ZooInspectorManager { + /** + * The key used for the connect string in the connection properties file + */ + public static final String CONNECT_STRING = "hosts"; + /** + * The key used for the session timeout in the connection properties file + */ + public static final String SESSION_TIMEOUT = "timeout"; + /** + * The key used for the data encryption manager in the connection properties + * file + */ + public static final String DATA_ENCRYPTION_MANAGER = "encryptionManager"; + /** + * The key used for the authentication scheme in the connection properties file + */ + public static final String AUTH_SCHEME_KEY = "authScheme"; + /** + * The key used for the authentication data in the connection properties file + */ + public static final String AUTH_DATA_KEY = "authData"; + private static final String A_VERSION = "ACL Version"; + private static final String C_TIME = "Creation Time"; + private static final String C_VERSION = "Children Version"; + private static final String CZXID = "Creation ID"; + private static final String DATA_LENGTH = "Data Length"; + private static final String EPHEMERAL_OWNER = "Ephemeral Owner"; + private static final String M_TIME = "Last Modified Time"; + private static final String MZXID = "Modified ID"; + private static final String NUM_CHILDREN = "Number of Children"; + private static final String PZXID = "Node ID"; + private static final String VERSION = "Data Version"; + private static final String ACL_PERMS = "Permissions"; + private static final String ACL_SCHEME = "Scheme"; + private static final String ACL_ID = "Id"; + private static final String SESSION_STATE = "Session State"; + private static final String SESSION_ID = "Session ID"; + private static final File defaultNodeViewersFile = new File( + "./config/defaultNodeViewers.cfg"); + private static final File defaultConnectionFile = new File( + "./config/defaultConnectionSettings.cfg"); + private final Map watchers = new HashMap(); + protected boolean connected = true; + private DataEncryptionManager encryptionManager; + private String connectString; + private int sessionTimeout; + private ZooKeeper zooKeeper; + private Properties lastConnectionProps; + private String defaultEncryptionManager; + private String defaultTimeout; + private String defaultHosts; + private String defaultAuthScheme; + private String defaultAuthValue; + + /** + * @throws IOException + * - thrown if the default connection settings cannot be loaded + * + */ + public ZooInspectorManagerImpl() throws IOException { + loadDefaultConnectionFile(); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorManager#connect(java + * .util.Properties) + */ + public boolean connect(Properties connectionProps) { + try { + if (this.zooKeeper == null) { + String connectString = connectionProps + .getProperty(CONNECT_STRING); + String sessionTimeout = connectionProps + .getProperty(SESSION_TIMEOUT); + String encryptionManager = connectionProps + .getProperty(DATA_ENCRYPTION_MANAGER); + String authScheme = connectionProps + .getProperty(AUTH_SCHEME_KEY); + String authData = connectionProps + .getProperty(AUTH_DATA_KEY); + + if (connectString == null || sessionTimeout == null) { + throw new IllegalArgumentException( + "Both connect string and session timeout are required."); + } + if (encryptionManager == null) { + this.encryptionManager = new BasicDataEncryptionManager(); + } else { + Class clazz = Class.forName(encryptionManager); + + if (Arrays.asList(clazz.getInterfaces()).contains( + DataEncryptionManager.class)) { + this.encryptionManager = (DataEncryptionManager) Class + .forName(encryptionManager).newInstance(); + } else { + throw new IllegalArgumentException( + "Data encryption manager must implement DataEncryptionManager interface"); + } + } + this.connectString = connectString; + this.sessionTimeout = Integer.valueOf(sessionTimeout); + this.zooKeeper = new ZooKeeperRetry(connectString, Integer + .valueOf(sessionTimeout), new Watcher() { + + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.Expired) { + connected = false; + } + } + }); + if (authData != null && authData.length() > 0) { + this.zooKeeper.addAuthInfo(authScheme, authData.getBytes()); + } + ((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10); + connected = ((ZooKeeperRetry) this.zooKeeper).testConnection(); + } + } catch (Exception e) { + connected = false; + e.printStackTrace(); + } + if (!connected) { + disconnect(); + } + return connected; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorManager#disconnect() + */ + public boolean disconnect() { + try { + if (this.zooKeeper != null) { + this.zooKeeper.close(); + this.zooKeeper = null; + connected = false; + removeWatchers(this.watchers.keySet()); + return true; + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred while disconnecting from ZooKeeper server", + e); + } + return false; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * getChildren(java.lang.String) + */ + public List getChildren(String nodePath) { + if (connected) { + try { + + return zooKeeper.getChildren(nodePath, false); + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred retrieving children of node: " + + nodePath, e); + } + } + return null; + + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager#getData + * (java.lang.String) + */ + public String getData(String nodePath) { + if (connected) { + try { + if (nodePath.length() == 0) { + nodePath = "/"; + } + Stat s = zooKeeper.exists(nodePath, false); + if (s != null) { + return this.encryptionManager.decryptData(zooKeeper + .getData(nodePath, false, s)); + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred getting data for node: " + nodePath, e); + } + } + return null; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * getNodeChild(java.lang.String, int) + */ + public String getNodeChild(String nodePath, int childIndex) { + if (connected) { + try { + Stat s = zooKeeper.exists(nodePath, false); + if (s != null) { + return this.zooKeeper.getChildren(nodePath, false).get( + childIndex); + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred retrieving child " + childIndex + + " of node: " + nodePath, e); + } + } + return null; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * getNodeIndex(java.lang.String) + */ + public int getNodeIndex(String nodePath) { + if (connected) { + int index = nodePath.lastIndexOf("/"); + if (index == -1 + || (!nodePath.equals("/") && nodePath.charAt(nodePath + .length() - 1) == '/')) { + throw new IllegalArgumentException("Invalid node path: " + + nodePath); + } + String parentPath = nodePath.substring(0, index); + String child = nodePath.substring(index + 1); + if (parentPath != null && parentPath.length() > 0) { + List children = this.getChildren(parentPath); + if (children != null) { + return children.indexOf(child); + } + } + } + return -1; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager#getACLs + * (java.lang.String) + */ + public List> getACLs(String nodePath) { + List> returnACLs = new ArrayList>(); + if (connected) { + try { + if (nodePath.length() == 0) { + nodePath = "/"; + } + Stat s = zooKeeper.exists(nodePath, false); + if (s != null) { + List acls = zooKeeper.getACL(nodePath, s); + for (ACL acl : acls) { + Map aclMap = new LinkedHashMap(); + aclMap.put(ACL_SCHEME, acl.getId().getScheme()); + aclMap.put(ACL_ID, acl.getId().getId()); + StringBuilder sb = new StringBuilder(); + int perms = acl.getPerms(); + boolean addedPerm = false; + if ((perms & Perms.READ) == Perms.READ) { + sb.append("Read"); + addedPerm = true; + } + if (addedPerm) { + sb.append(", "); + } + if ((perms & Perms.WRITE) == Perms.WRITE) { + sb.append("Write"); + addedPerm = true; + } + if (addedPerm) { + sb.append(", "); + } + if ((perms & Perms.CREATE) == Perms.CREATE) { + sb.append("Create"); + addedPerm = true; + } + if (addedPerm) { + sb.append(", "); + } + if ((perms & Perms.DELETE) == Perms.DELETE) { + sb.append("Delete"); + addedPerm = true; + } + if (addedPerm) { + sb.append(", "); + } + if ((perms & Perms.ADMIN) == Perms.ADMIN) { + sb.append("Admin"); + addedPerm = true; + } + aclMap.put(ACL_PERMS, sb.toString()); + returnACLs.add(aclMap); + } + } + } catch (InterruptedException e) { + LoggerFactory.getLogger().error( + "Error occurred retrieving ACLs of node: " + nodePath, + e); + } catch (KeeperException e) { + LoggerFactory.getLogger().error( + "Error occurred retrieving ACLs of node: " + nodePath, + e); + } + } + return returnACLs; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * getNodeMeta(java.lang.String) + */ + public Map getNodeMeta(String nodePath) { + Map nodeMeta = new LinkedHashMap(); + if (connected) { + try { + if (nodePath.length() == 0) { + nodePath = "/"; + } + Stat s = zooKeeper.exists(nodePath, false); + if (s != null) { + nodeMeta.put(A_VERSION, String.valueOf(s.getAversion())); + nodeMeta.put(C_TIME, String.valueOf(s.getCtime())); + nodeMeta.put(C_VERSION, String.valueOf(s.getCversion())); + nodeMeta.put(CZXID, String.valueOf(s.getCzxid())); + nodeMeta + .put(DATA_LENGTH, String.valueOf(s.getDataLength())); + nodeMeta.put(EPHEMERAL_OWNER, String.valueOf(s + .getEphemeralOwner())); + nodeMeta.put(M_TIME, String.valueOf(s.getMtime())); + nodeMeta.put(MZXID, String.valueOf(s.getMzxid())); + nodeMeta.put(NUM_CHILDREN, String.valueOf(s + .getNumChildren())); + nodeMeta.put(PZXID, String.valueOf(s.getPzxid())); + nodeMeta.put(VERSION, String.valueOf(s.getVersion())); + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred retrieving meta data for node: " + + nodePath, e); + } + } + return nodeMeta; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * getNumChildren(java.lang.String) + */ + public int getNumChildren(String nodePath) { + if (connected) { + try { + Stat s = zooKeeper.exists(nodePath, false); + if (s != null) { + return s.getNumChildren(); + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred getting the number of children of node: " + + nodePath, e); + } + } + return -1; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * hasChildren(java.lang.String) + */ + public boolean hasChildren(String nodePath) { + return getNumChildren(nodePath) > 0; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * isAllowsChildren(java.lang.String) + */ + public boolean isAllowsChildren(String nodePath) { + if (connected) { + try { + Stat s = zooKeeper.exists(nodePath, false); + if (s != null) { + return s.getEphemeralOwner() == 0; + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred determining whether node is allowed children: " + + nodePath, e); + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorReadOnlyManager# + * getSessionMeta() + */ + public Map getSessionMeta() { + Map sessionMeta = new LinkedHashMap(); + try { + if (zooKeeper != null) { + + sessionMeta.put(SESSION_ID, String.valueOf(zooKeeper + .getSessionId())); + sessionMeta.put(SESSION_STATE, String.valueOf(zooKeeper + .getState().toString())); + sessionMeta.put(CONNECT_STRING, this.connectString); + sessionMeta.put(SESSION_TIMEOUT, String + .valueOf(this.sessionTimeout)); + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred retrieving session meta data.", e); + } + return sessionMeta; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorNodeTreeManager#createNode + * (java.lang.String, java.lang.String) + */ + public boolean createNode(String parent, String nodeName) { + if (connected) { + try { + String[] nodeElements = nodeName.split("/"); + for (String nodeElement : nodeElements) { + String node = parent + "/" + nodeElement; + Stat s = zooKeeper.exists(node, false); + if (s == null) { + zooKeeper.create(node, this.encryptionManager + .encryptData(null), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + parent = node; + } + } + return true; + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred creating node: " + parent + "/" + + nodeName, e); + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorNodeTreeManager#deleteNode + * (java.lang.String) + */ + public boolean deleteNode(String nodePath) { + if (connected) { + try { + Stat s = zooKeeper.exists(nodePath, false); + if (s != null) { + List children = zooKeeper.getChildren(nodePath, + false); + for (String child : children) { + String node = nodePath + "/" + child; + deleteNode(node); + } + zooKeeper.delete(nodePath, -1); + } + return true; + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred deleting node: " + nodePath, e); + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorNodeManager#setData + * (java.lang.String, java.lang.String) + */ + public boolean setData(String nodePath, String data) { + if (connected) { + try { + zooKeeper.setData(nodePath, this.encryptionManager + .encryptData(data), -1); + return true; + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occurred setting data for node: " + nodePath, e); + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorManager# + * getConnectionPropertiesTemplate() + */ + public Pair>, Map> getConnectionPropertiesTemplate() { + Map> template = new LinkedHashMap>(); + template.put(CONNECT_STRING, Arrays + .asList(new String[]{defaultHosts})); + template.put(SESSION_TIMEOUT, Arrays + .asList(new String[]{defaultTimeout})); + template.put(DATA_ENCRYPTION_MANAGER, Arrays + .asList(new String[]{defaultEncryptionManager})); + template.put(AUTH_SCHEME_KEY, Arrays + .asList(new String[]{defaultAuthScheme})); + template.put(AUTH_DATA_KEY, Arrays + .asList(new String[]{defaultAuthValue})); + Map labels = new LinkedHashMap(); + labels.put(CONNECT_STRING, "Connect String"); + labels.put(SESSION_TIMEOUT, "Session Timeout"); + labels.put(DATA_ENCRYPTION_MANAGER, "Data Encryption Manager"); + labels.put(AUTH_SCHEME_KEY, "Authentication Scheme"); + labels.put(AUTH_DATA_KEY, "Authentication Data"); + return new Pair>, Map>( + template, labels); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorManager#addWatchers + * (java.util.Collection, + * org.apache.zookeeper.inspector.manager.NodeListener) + */ + public void addWatchers(Collection selectedNodes, + NodeListener nodeListener) { + // add watcher for each node and add node to collection of + // watched nodes + if (connected) { + for (String node : selectedNodes) { + if (!watchers.containsKey(node)) { + try { + watchers.put(node, new NodeWatcher(node, nodeListener, + zooKeeper)); + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occured adding node watcher for node: " + + node, e); + } + } + } + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.zookeeper.inspector.manager.ZooInspectorManager#removeWatchers + * (java.util.Collection) + */ + public void removeWatchers(Collection selectedNodes) { + // remove watcher for each node and remove node from + // collection of watched nodes + if (connected) { + for (String node : selectedNodes) { + if (watchers.containsKey(node)) { + NodeWatcher watcher = watchers.remove(node); + if (watcher != null) { + watcher.stop(); + } + } + } + } + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorManager# + * loadNodeViewersFile(java.io.File) + */ + public List loadNodeViewersFile(File selectedFile) + throws IOException { + List result = new ArrayList(); + if (defaultNodeViewersFile.exists()) { + FileReader reader = new FileReader(selectedFile); + try { + BufferedReader buff = new BufferedReader(reader); + try { + while (buff.ready()) { + String line = buff.readLine(); + if (line != null && line.length() > 0 && !line.startsWith("#")) { + result.add(line); + } + } + } finally { + buff.close(); + } + } finally { + reader.close(); + } + } + return result; + } + + private void loadDefaultConnectionFile() throws IOException { + if (defaultConnectionFile.exists()) { + Properties props = new Properties(); + + FileReader reader = new FileReader(defaultConnectionFile); + try { + props.load(reader); + } finally { + reader.close(); + } + defaultEncryptionManager = props + .getProperty(DATA_ENCRYPTION_MANAGER) == null ? "org.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager" + : props.getProperty(DATA_ENCRYPTION_MANAGER); + defaultTimeout = props.getProperty(SESSION_TIMEOUT) == null ? "5000" + : props.getProperty(SESSION_TIMEOUT); + defaultHosts = props.getProperty(CONNECT_STRING) == null ? "localhost:2181" + : props.getProperty(CONNECT_STRING); + defaultAuthScheme = props.getProperty(AUTH_SCHEME_KEY) == null ? "" + : props.getProperty(AUTH_SCHEME_KEY); + defaultAuthValue = props.getProperty(AUTH_DATA_KEY) == null ? "" + : props.getProperty(AUTH_DATA_KEY); + } else { + defaultEncryptionManager = "org.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager"; + defaultTimeout = "5000"; + defaultHosts = "localhost:2181"; + defaultAuthScheme = ""; + defaultAuthValue = ""; + } + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorManager# + * saveDefaultConnectionFile(java.util.Properties) + */ + public void saveDefaultConnectionFile(Properties props) throws IOException { + File defaultDir = defaultConnectionFile.getParentFile(); + if (!defaultDir.exists()) { + if (!defaultDir.mkdirs()) { + throw new IOException( + "Failed to create configuration directory: " + + defaultDir.getAbsolutePath()); + } + } + if (!defaultConnectionFile.exists()) { + if (!defaultConnectionFile.createNewFile()) { + throw new IOException( + "Failed to create default connection file: " + + defaultConnectionFile.getAbsolutePath()); + } + } + FileWriter writer = new FileWriter(defaultConnectionFile); + try { + props.store(writer, "Default connection for ZooInspector"); + } finally { + writer.close(); + } + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorManager# + * saveNodeViewersFile(java.io.File, java.util.List) + */ + public void saveNodeViewersFile(File selectedFile, + List nodeViewersClassNames) throws IOException { + if (!selectedFile.exists()) { + if (!selectedFile.createNewFile()) { + throw new IOException( + "Failed to create node viewers configuration file: " + + selectedFile.getAbsolutePath()); + } + } + FileWriter writer = new FileWriter(selectedFile); + try { + BufferedWriter buff = new BufferedWriter(writer); + try { + for (String nodeViewersClassName : nodeViewersClassNames) { + buff.append(nodeViewersClassName); + buff.append("\n"); + } + } finally { + buff.flush(); + buff.close(); + } + } finally { + writer.close(); + } + } + + public List getDefaultNodeViewerConfiguration() throws IOException { + return loadNodeViewersFile(defaultNodeViewersFile); + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorManager# + * setDefaultNodeViewerConfiguration(java.io.File, java.util.List) + */ + public void setDefaultNodeViewerConfiguration( + List nodeViewersClassNames) throws IOException { + File defaultDir = defaultNodeViewersFile.getParentFile(); + if (!defaultDir.exists()) { + if (!defaultDir.mkdirs()) { + throw new IOException( + "Failed to create configuration directory: " + + defaultDir.getAbsolutePath()); + } + } + saveNodeViewersFile(defaultNodeViewersFile, nodeViewersClassNames); + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorManager# + * getLastConnectionProps() + */ + public Properties getLastConnectionProps() { + return this.lastConnectionProps; + } + + /* + * (non-Javadoc) + * + * @seeorg.apache.zookeeper.inspector.manager.ZooInspectorManager# + * setLastConnectionProps(java.util.Properties) + */ + public void setLastConnectionProps(Properties connectionProps) { + this.lastConnectionProps = connectionProps; + } + + /** + * A Watcher which will re-add itself every time an event is fired + * + */ + public class NodeWatcher implements Watcher { + + private final String nodePath; + private final NodeListener nodeListener; + private final ZooKeeper zookeeper; + private boolean closed = false; + + /** + * @param nodePath + * - the path to the node to watch + * @param nodeListener + * the {@link NodeListener} for this node + * @param zookeeper + * - a {@link ZooKeeper} to use to access zookeeper + * @throws InterruptedException + * @throws KeeperException + */ + public NodeWatcher(String nodePath, NodeListener nodeListener, + ZooKeeper zookeeper) throws KeeperException, + InterruptedException { + this.nodePath = nodePath; + this.nodeListener = nodeListener; + this.zookeeper = zookeeper; + Stat s = zooKeeper.exists(nodePath, this); + if (s != null) { + zookeeper.getChildren(nodePath, this); + } + } + + public void process(WatchedEvent event) { + if (!closed) { + try { + if (event.getType() != EventType.NodeDeleted) { + + Stat s = zooKeeper.exists(nodePath, this); + if (s != null) { + zookeeper.getChildren(nodePath, this); + } + } + } catch (Exception e) { + LoggerFactory.getLogger().error( + "Error occured re-adding node watcherfor node " + + nodePath, e); + } + nodeListener.processEvent(event.getPath(), event.getType() + .name(), null); + } + } + + /** + * + */ + public void stop() { + this.closed = true; + } + + } +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorNodeManager.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorNodeManager.java new file mode 100644 index 00000000000..d5489e98347 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorNodeManager.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.manager; + +/** + * A Manager for all interactions between the application and the nodes in a + * Zookeeper instance + * */ +public interface ZooInspectorNodeManager extends ZooInspectorReadOnlyManager { + /** + * @param nodePath + * - the path to the node on which to set the data + * @param data + * - the data to set on the this node + * @return true if the data for the node was successfully updated + */ + public boolean setData(String nodePath, String data); +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorNodeTreeManager.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorNodeTreeManager.java new file mode 100644 index 00000000000..7ba178e7b44 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorNodeTreeManager.java @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.manager; + +/** + * A Manager for all interactions between the application and the node tree in a + * Zookeeper instance + */ +public interface ZooInspectorNodeTreeManager extends + ZooInspectorReadOnlyManager { + + /** + * @param parent + * - the parent node path for the node to add + * @param nodeName + * - the name of the new node + * @return true if the node was successfully created + */ + public abstract boolean createNode(String parent, String nodeName); + + /** + * @param nodePath + * - the path to the node to delete + * @return true if the node was successfully deleted + */ + public abstract boolean deleteNode(String nodePath); + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorReadOnlyManager.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorReadOnlyManager.java new file mode 100644 index 00000000000..166630304b7 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/inspector/manager/ZooInspectorReadOnlyManager.java @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.inspector.manager; + +import java.util.List; +import java.util.Map; + +/** + * A Manager for all read only interactions between the application and a node + * in a Zookeeper instance + */ +public interface ZooInspectorReadOnlyManager { + + /** + * @param nodePath + * - the path to the node to delete + * @return the data for the node + */ + public abstract String getData(String nodePath); + + /** + * @param nodePath + * - the path to the node to delete + * @return the metaData for the node + */ + public abstract Map getNodeMeta(String nodePath); + + /** + * @param nodePath + * - the path to the node to delete + * @return the ACLs set on the node + */ + public abstract List> getACLs(String nodePath); + + /** + * @return the metaData for the current session + */ + public abstract Map getSessionMeta(); + + /** + * @param nodePath + * - the path to the node to delete + * @return true if the node has children + */ + public abstract boolean hasChildren(String nodePath); + + /** + * @param nodePath + * - the path to the node to delete + * @return the index of the node within its siblings + */ + public abstract int getNodeIndex(String nodePath); + + /** + * @param nodePath + * - the path to the node to delete + * @return the number of children of the node + */ + public abstract int getNumChildren(String nodePath); + + /** + * @param nodePath + * - the path to the node to delete + * @param childIndex + * - the index to the node in the list of node children + * @return the path to the node for the child of the nodePath at childIndex + */ + public abstract String getNodeChild(String nodePath, int childIndex); + + /** + * @param nodePath + * - the path to the node to delete + * @return true if the node allows children nodes + */ + public abstract boolean isAllowsChildren(String nodePath); + + /** + * @param nodePath + * - the path to the node to delete + * @return a {@link List} of the children of the node + */ + public abstract List getChildren(String nodePath); + +} diff --git a/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java b/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java new file mode 100644 index 00000000000..803db2f2b76 --- /dev/null +++ b/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java @@ -0,0 +1,281 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.retry; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.inspector.logger.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * A Class which extends {@link ZooKeeper} and will automatically retry calls to + * zookeeper if a {@link KeeperException.ConnectionLossException} occurs + */ +public class ZooKeeperRetry extends ZooKeeper { + + private final Watcher watcher; + private boolean closed = false; + private int limit = -1; + + /** + * @param connectString + * @param sessionTimeout + * @param watcher + * @throws IOException + */ + public ZooKeeperRetry(String connectString, int sessionTimeout, + Watcher watcher) throws IOException { + super(connectString, sessionTimeout, watcher); + this.watcher = watcher; + } + + /** + * @param connectString + * @param sessionTimeout + * @param watcher + * @param sessionId + * @param sessionPasswd + * @throws IOException + */ + public ZooKeeperRetry(String connectString, int sessionTimeout, + Watcher watcher, long sessionId, byte[] sessionPasswd) + throws IOException { + super(connectString, sessionTimeout, watcher, sessionId, sessionPasswd); + this.watcher = watcher; + } + + @Override + public synchronized void close() throws InterruptedException { + this.closed = true; + super.close(); + } + + @Override + public String create(String path, byte[] data, List acl, + CreateMode createMode) throws KeeperException, InterruptedException { + int count = 0; + do { + try { + return super.create(path, data, acl, createMode); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + if (exists(path, false) != null) { + return path; + } + } catch (KeeperException.NodeExistsException e) { + return path; + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + @Override + public void delete(String path, int version) throws InterruptedException, + KeeperException { + int count = 0; + do { + try { + super.delete(path, version); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + if (exists(path, false) == null) { + return; + } + } catch (KeeperException.NoNodeException e) { + break; + } + } while (!closed && (limit == -1 || count++ < limit)); + } + + @Override + public Stat exists(String path, boolean watch) throws KeeperException, + InterruptedException { + int count = 0; + do { + try { + return super.exists(path, watch ? watcher : null); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + @Override + public Stat exists(String path, Watcher watcher) throws KeeperException, + InterruptedException { + int count = 0; + do { + try { + return super.exists(path, watcher); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + @Override + public List getACL(String path, Stat stat) throws KeeperException, + InterruptedException { + int count = 0; + do { + try { + return super.getACL(path, stat); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + @Override + public List getChildren(String path, boolean watch) + throws KeeperException, InterruptedException { + int count = 0; + do { + try { + return super.getChildren(path, watch ? watcher : null); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (!closed && (limit == -1 || count++ < limit)); + return new ArrayList(); + } + + @Override + public List getChildren(String path, Watcher watcher) + throws KeeperException, InterruptedException { + int count = 0; + do { + try { + return super.getChildren(path, watcher); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (!closed && (limit == -1 || count++ < limit)); + return new ArrayList(); + } + + @Override + public byte[] getData(String path, boolean watch, Stat stat) + throws KeeperException, InterruptedException { + int count = 0; + do { + try { + return super.getData(path, watch ? watcher : null, stat); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + @Override + public byte[] getData(String path, Watcher watcher, Stat stat) + throws KeeperException, InterruptedException { + int count = 0; + do { + try { + return super.getData(path, watcher, stat); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + @Override + public Stat setACL(String path, List acl, int version) + throws KeeperException, InterruptedException { + int count = 0; + do { + try { + return super.setACL(path, acl, version); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + Stat s = exists(path, false); + if (s != null) { + if (getACL(path, s).equals(acl)) { + return s; + } + } else { + return null; + } + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + @Override + public Stat setData(String path, byte[] data, int version) + throws KeeperException, InterruptedException { + int count = 0; + do { + try { + return super.setData(path, data, version); + } catch (KeeperException.ConnectionLossException e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + Stat s = exists(path, false); + if (s != null) { + if (getData(path, false, s) == data) { + return s; + } + } else { + return null; + } + } + } while (!closed && (limit == -1 || count++ < limit)); + return null; + } + + /** + * @param limit + */ + public void setRetryLimit(int limit) { + this.limit = limit; + } + + /** + * @return true if successfully connected to zookeeper + */ + public boolean testConnection() { + int count = 0; + do { + try { + return super.exists("/", null) != null; + } catch (Exception e) { + LoggerFactory.getLogger().warn( + "ZooKeeper connection lost. Trying to reconnect."); + } + } while (count++ < 5); + return false; + } + +} diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/add.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/add.png new file mode 100644 index 00000000000..1aa7f095c6c Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/add.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/document-new.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/document-new.png new file mode 100644 index 00000000000..4c3efdd6fa3 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/document-new.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/document-save.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/document-save.png new file mode 100644 index 00000000000..22ff4957102 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/document-save.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/down.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/down.png new file mode 100644 index 00000000000..3dd7fccdf06 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/down.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/media-playback-start.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/media-playback-start.png new file mode 100644 index 00000000000..a7de0feb09f Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/media-playback-start.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/media-playback-stop.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/media-playback-stop.png new file mode 100644 index 00000000000..ede2815e598 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/media-playback-stop.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/remove.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/remove.png new file mode 100644 index 00000000000..00b654e8ca5 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/remove.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/up.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/up.png new file mode 100644 index 00000000000..fa9a7d71b56 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/up.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/view-refresh.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/view-refresh.png new file mode 100644 index 00000000000..3fd71d6e592 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/actions/view-refresh.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/mimetypes/text-x-generic.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/mimetypes/text-x-generic.png new file mode 100644 index 00000000000..2d7f2d6017d Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/mimetypes/text-x-generic.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/places/folder.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/places/folder.png new file mode 100644 index 00000000000..65bd0bbdcb9 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/places/folder.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/places/user-trash.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/places/user-trash.png new file mode 100644 index 00000000000..0e0953c73c6 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/places/user-trash.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/status/info.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/status/info.png new file mode 100644 index 00000000000..8851b99ba10 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/16x16/status/info.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/add.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/add.png new file mode 100644 index 00000000000..306d3d89291 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/add.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/document-new.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/document-new.png new file mode 100644 index 00000000000..e3808a108e3 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/document-new.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/document-save.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/document-save.png new file mode 100644 index 00000000000..a94e0eab97d Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/document-save.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/down.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/down.png new file mode 100644 index 00000000000..af237881737 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/down.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/media-playback-start.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/media-playback-start.png new file mode 100644 index 00000000000..10102d829cd Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/media-playback-start.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/media-playback-stop.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/media-playback-stop.png new file mode 100644 index 00000000000..d0e4733b263 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/media-playback-stop.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/remove.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/remove.png new file mode 100644 index 00000000000..45e5c2a8e98 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/remove.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/up.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/up.png new file mode 100644 index 00000000000..b0a0cd721f2 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/up.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/view-refresh.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/view-refresh.png new file mode 100644 index 00000000000..cab4d02c756 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/actions/view-refresh.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/mimetypes/text-x-generic.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/mimetypes/text-x-generic.png new file mode 100644 index 00000000000..d68a56c68a1 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/mimetypes/text-x-generic.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/places/folder.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/places/folder.png new file mode 100644 index 00000000000..01f45b82aa5 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/places/folder.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/places/user-trash.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/places/user-trash.png new file mode 100644 index 00000000000..05ff0365f5e Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/places/user-trash.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/status/info.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/status/info.png new file mode 100644 index 00000000000..07cf0102d3f Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/22x22/status/info.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/add.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/add.png new file mode 100644 index 00000000000..681e9644271 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/add.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/document-new.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/document-new.png new file mode 100644 index 00000000000..936122256ff Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/document-new.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/document-save.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/document-save.png new file mode 100644 index 00000000000..abdb0c07a1b Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/document-save.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/down.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/down.png new file mode 100644 index 00000000000..0d2938707ba Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/down.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/media-playback-start.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/media-playback-start.png new file mode 100644 index 00000000000..810de6df895 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/media-playback-start.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/media-playback-stop.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/media-playback-stop.png new file mode 100644 index 00000000000..66b0e931849 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/media-playback-stop.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/remove.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/remove.png new file mode 100644 index 00000000000..6454032cb79 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/remove.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/up.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/up.png new file mode 100644 index 00000000000..c24a439c5c4 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/up.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/view-refresh.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/view-refresh.png new file mode 100644 index 00000000000..664520c2d36 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/actions/view-refresh.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/mimetypes/text-x-generic.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/mimetypes/text-x-generic.png new file mode 100644 index 00000000000..f43b5f098dd Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/mimetypes/text-x-generic.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/places/folder.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/places/folder.png new file mode 100644 index 00000000000..c129714da24 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/places/folder.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/places/user-trash.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/places/user-trash.png new file mode 100644 index 00000000000..9bf1fc5bb82 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/places/user-trash.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/status/info.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/status/info.png new file mode 100644 index 00000000000..0feb2b04da5 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/24x24/status/info.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/add.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/add.png new file mode 100644 index 00000000000..2acdd8f514c Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/add.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/document-new.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/document-new.png new file mode 100644 index 00000000000..e6d64bb90b3 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/document-new.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/document-save.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/document-save.png new file mode 100644 index 00000000000..db5c52b769e Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/document-save.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/down.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/down.png new file mode 100644 index 00000000000..dce3f15ef57 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/down.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/media-playback-start.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/media-playback-start.png new file mode 100644 index 00000000000..66f32d89b59 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/media-playback-start.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/media-playback-stop.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/media-playback-stop.png new file mode 100644 index 00000000000..a0947879ee9 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/media-playback-stop.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/remove.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/remove.png new file mode 100644 index 00000000000..c5524f7284e Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/remove.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/up.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/up.png new file mode 100644 index 00000000000..afb307b18c1 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/up.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/view-refresh.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/view-refresh.png new file mode 100644 index 00000000000..606ea9eba46 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/actions/view-refresh.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/mimetypes/text-x-generic.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/mimetypes/text-x-generic.png new file mode 100644 index 00000000000..928a67995ee Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/mimetypes/text-x-generic.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/places/folder.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/places/folder.png new file mode 100644 index 00000000000..472484f1127 Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/places/folder.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/places/user-trash.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/places/user-trash.png new file mode 100644 index 00000000000..9b7a462d7db Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/places/user-trash.png differ diff --git a/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/status/info.png b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/status/info.png new file mode 100644 index 00000000000..2ac57475c3b Binary files /dev/null and b/src/contrib/zooinspector/src/main/resources/icons/Tango/32x32/status/info.png differ diff --git a/src/contrib/zooinspector/zooInspector-dev.sh b/src/contrib/zooinspector/zooInspector-dev.sh new file mode 100755 index 00000000000..f507f68487b --- /dev/null +++ b/src/contrib/zooinspector/zooInspector-dev.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +java -cp ../../../build/contrib/ZooInspector/*:../../../build/*:../../../build/lib/*:lib org.apache.zookeeper.inspector.ZooInspector diff --git a/src/contrib/zooinspector/zooInspector.cmd b/src/contrib/zooinspector/zooInspector.cmd new file mode 100644 index 00000000000..0910798240e --- /dev/null +++ b/src/contrib/zooinspector/zooInspector.cmd @@ -0,0 +1,18 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +java -cp "zookeeper-dev-ZooInspector.jar;lib\*;lib" org.apache.zookeeper.inspector.ZooInspector diff --git a/src/contrib/zooinspector/zooInspector.sh b/src/contrib/zooinspector/zooInspector.sh new file mode 100755 index 00000000000..5e3ebb67d4d --- /dev/null +++ b/src/contrib/zooinspector/zooInspector.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +java -cp "zookeeper-dev-ZooInspector.jar:lib/*:lib" org.apache.zookeeper.inspector.ZooInspector diff --git a/src/docs/forrest.properties b/src/docs/forrest.properties new file mode 100644 index 00000000000..2a9305a857d --- /dev/null +++ b/src/docs/forrest.properties @@ -0,0 +1,90 @@ +# Copyright 2002-2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############## +# Properties used by forrest.build.xml for building the website +# These are the defaults, un-comment them if you need to change them. +############## +# Prints out a summary of Forrest settings for this project +#forrest.echo=true +# Project name (used to name .war file) +#project.name=my-project +# Specifies name of Forrest skin to use +#project.skin=tigris +#project.skin=pelt +# comma separated list, file:// is supported +#forrest.skins.descriptors=http://forrest.apache.org/skins/skins.xml,file:///c:/myskins/skins.xml +############## +# behavioural properties +#project.menu-scheme=tab_attributes +#project.menu-scheme=directories +############## +# layout properties +# Properties that can be set to override the default locations +# +# Parent properties must be set. This usually means uncommenting +# project.content-dir if any other property using it is uncommented +#project.status=status.xml +#project.content-dir=src/documentation +#project.raw-content-dir=${project.content-dir}/content +#project.conf-dir=${project.content-dir}/conf +#project.sitemap-dir=${project.content-dir} +#project.xdocs-dir=${project.content-dir}/content/xdocs +#project.resources-dir=${project.content-dir}/resources +#project.stylesheets-dir=${project.resources-dir}/stylesheets +#project.images-dir=${project.resources-dir}/images +#project.schema-dir=${project.resources-dir}/schema +#project.skins-dir=${project.content-dir}/skins +#project.skinconf=${project.content-dir}/skinconf.xml +#project.lib-dir=${project.content-dir}/lib +#project.classes-dir=${project.content-dir}/classes +#project.translations-dir=${project.content-dir}/translations +############## +# validation properties +# This set of properties determine if validation is performed +# Values are inherited unless overridden. +# e.g. if forrest.validate=false then all others are false unless set to true. +forrest.validate=true +forrest.validate.xdocs=${forrest.validate} +forrest.validate.skinconf=${forrest.validate} +forrest.validate.stylesheets=${forrest.validate} +forrest.validate.skins=${forrest.validate} +forrest.validate.skins.stylesheets=${forrest.validate.skins} +# Make Forrest work with JDK6 +forrest.validate.sitemap=false +# *.failonerror=(true|false) - stop when an XML file is invalid +forrest.validate.failonerror=true +# *.excludes=(pattern) - comma-separated list of path patterns to not validate +# e.g. +#forrest.validate.xdocs.excludes=samples/subdir/**, samples/faq.xml +#forrest.validate.xdocs.excludes= +############## +# General Forrest properties +# The URL to start crawling from +#project.start-uri=linkmap.html +# Set logging level for messages printed to the console +# (DEBUG, INFO, WARN, ERROR, FATAL_ERROR) +#project.debuglevel=ERROR +# Max memory to allocate to Java +#forrest.maxmemory=64m +# Any other arguments to pass to the JVM. For example, to run on an X-less +# server, set to -Djava.awt.headless=true +#forrest.jvmargs= +# The bugtracking URL - the issue number will be appended +#project.bugtracking-url=http://issues.apache.org/bugzilla/show_bug.cgi?id= +#project.bugtracking-url=http://issues.apache.org/jira/browse/ +# The issues list as rss +#project.issues-rss-url= +#I18n Property only works for the "forrest run" target. +#project.i18n=true +project.required.plugins=org.apache.forrest.plugin.output.pdf,org.apache.forrest.plugin.input.simplifiedDocbook diff --git a/src/docs/src/documentation/README.txt b/src/docs/src/documentation/README.txt new file mode 100644 index 00000000000..9bc261b2f15 --- /dev/null +++ b/src/docs/src/documentation/README.txt @@ -0,0 +1,7 @@ +This is the base documentation directory. + +skinconf.xml # This file customizes Forrest for your project. In it, you + # tell forrest the project name, logo, copyright info, etc + +sitemap.xmap # Optional. This sitemap is consulted before all core sitemaps. + # See http://forrest.apache.org/docs/project-sitemap.html diff --git a/src/docs/src/documentation/TODO.txt b/src/docs/src/documentation/TODO.txt new file mode 100644 index 00000000000..84e7dfaff7f --- /dev/null +++ b/src/docs/src/documentation/TODO.txt @@ -0,0 +1,227 @@ +This is a running list of todo documentation items. Feel free +to add to the list or take on an item as you wish (in the form +of a JIRA patch of course). +------------------------------------------------------------- + +recipes.xml:110: +[maybe an illustration would be nice for each recipe?] + +recipes.xml:167: +"wait for each watch event". [how do you wait?] + +recipes.xml:457: +[tbd: myabe helpful to indicate which step this refers to?] + +zookeeperAdmin.xml:77: +because requires a majority [tbd: why?], it is best to use... + +zookeeperAdmin.xml:112: + $yinst -i jdk-1.6.0.00_3 -br test [y! prop - replace with open equiv] + +zookeeperAdmin.xml:99: +- use a maximum heap size of 3GB for a 4GB machine. [tbd: where would they do this? Environment variable, etc?] + +zookeeperAdmin.xml:120 +$ yinst install -nostart zookeeper_server [Y! prop - replace with open eq] + +zookeeperAdmin.xml:171: +In Java, you can run the following command to execute simple operations: [tbd: also, maybe give some of those simple operations?] + +zookeeperAdmin.xml:194: +Running either program gives you a shell in which to execute simple file-system-like operations. [tbd: again, sample + operations?] + +zookeeperAdmin.xml:252: +If servers use different configuration files, +care must be taken to ensure that the list of servers in all of the +standard form, with legal values, etc] + +zookeeperAdmin.xml:408: +(Note: The system property has no zookeeper +prefix, and the configuration variable name is different from +the system property. Yes - it's not consistent, and it's +annoying. [tbd: is there any explanation for +this?]) + +zookeeperAdmin.xml:445: When the election algorithm is + "0" a UDP port with the same port number as the port listed in + the server.num option will be + used. [tbd: should that be server.id? Also, why isn't server.id + documented anywhere?] + +zookeeperAdmin.xml:481: The default to this option is yes, which + means that a leader will accept client connections. + [tbd: how do you specifiy which server is the + leader?] + +zookeeperAdmin.xml:495 When the server + starts up, it determines which server it is by looking for the + file myid in the data directory. + [tdb: should we mention somewhere about creating this file, + myid, in the setup procedure?] + +zookeeperAdmin.xml:508: [tbd: is the next sentence explanation an of what the + election port or is it a description of a special case?] + If you want to test multiple servers on a single + machine, the individual choices of electionPort for each + server can be defined in each server's config files using the + line electionPort=xxxx to avoid clashes. + +zookeeperAdmin.xml:524: If followers fall too far behind a + leader, they will be dropped. [tbd: is this a correct + rewording: if followers fall beyond this limit, they are + dropped?] + +zookeeperAdmin.xml:551: ZooKeeper will not require updates + to be synced to the media. [tbd: useful because..., + dangerous because...] + +zookeeperAdmin.xml:580: Skips ACL checks. [tbd: when? where?] + +zookeeperAdmin.xml:649: [tbd: Patrick, Ben, et al: I believe the Message Broker + team does perform routine monitoring of Zookeeper. But I might be + wrong. To your knowledge, is there any monitoring of a Zookeeper + deployment that will a Zookeeper sys admin will want to do, outside of + Yahoo?] + +zookeeperAdmin.xml:755: Also, + the server lists in each Zookeeper server configuration file + should be consistent with one another. [tbd: I'm assuming + this last part is true. Is it?] + +zookeeperAdmin.xml:812: For best results, take note of the following list of good + Zookeeper practices. [tbd: I just threw this section in. Do we + have list that is is different from the "things to avoid"? If not, I can + easily remove this section.] + + +zookeeperOver.xml:162: Ephemeral nodes are useful when you + want to implement [tbd]. + +zookeeperOver.xml:174: And if the + connection between the client and one of the Zoo Keeper servers is + broken, the client will receive a local notification. These can be used + to [tbd] + +zookeeperOver.xml:215: For more information on these (guarantees), and how they can be used, see + [tbd] + +zookeeperOver.xml:294: shows the high-level components + of the ZooKeeper service. With the exception of the request processor, + [tbd: where does the request processor live?] + +zookeeperOver.xml:298: shows the high-level components + of the ZooKeeper service. With the exception of the request processor, + each of + the servers that make up the ZooKeeper service replicates its own copy + of each of components. [tbd: I changed the wording in this + sentence from the white paper. Can someone please make sure it is still + correct?] + +zookeeperOver.xml:342: The programming interface to ZooKeeper is deliberately simple. + With it, however, you can implement higher order operations, such as + synchronizations primitives, group membership, ownership, etc. Some + distributed applications have used it to: [tbd: add uses from + white paper and video presentation.] + + +zookeeperProgrammers.xml:94: + + [tbd] + + +zookeeperProgrammers.xml:115: Also, + the Simple Programmming + Example [tbd] is helpful for understand the basic + structure of a ZooKeeper client application. + +zookeeperProgrammers.xml:142: The following characters are not + allowed because [tbd: + do we need reasons?] + +zookeeperProgrammers.xml:172: If + the version it supplies doesn't match the actual version of the data, + the update will fail. (This behavior can be overridden. For more + information see... )[tbd... reference here to the section + describing the special version number -1] + +zookeeperProgrammers.xml:197: More information about watches can be + found in the section + + Zookeeper Watches. + [tbd: fix this link] [tbd: Ben there is note from to emphasize + that "it is queued". What is "it" and is what we have here + sufficient?] + +zookeeperProgrammers.xml:335: it will send the session id as a part of the connection handshake. + As a security measure, the server creates a password for the session id + that any ZooKeeper server can validate. [tbd: note from Ben: + "perhaps capability is a better word." need clarification on that.] + + +zookeeperProgrammers.xml:601: Locks + [tbd:...] in Zookeeper Recipes. + [tbd:..]). + +zookeeperProgrammers.xml:766: See INSTALL for general information about running + configure. [tbd: what + is INSTALL? a directory? a file?] + + + +zookeeperProgrammers.xml:813: To verify that the node's been created: + + You should see a list of node who are children of the root node + "/".[tbd: document all the cli commands (I think this is ben's comment) + +zookeeperProgrammers.xml:838: Refer to for examples of usage in Java and C. + [tbd] + +zookeeperProgrammers.xml 847: [tbd: This is a new section. The below + is just placeholder. Eventually, a subsection on each of those operations, with a little + bit of illustrative code for each op.] + +zookeeperProgrammers.xml:915: Program Structure, with Simple Example + +zookeeperProgrammers.xml:999: ZooKeeper Whitepaper [tbd: find url] + +zookeeperProgrammers.xml:1008: API Reference [tbd: find url] + +zookeeperProgrammers.xml:1062: [tbd] + Any other good sources anyone can think of... + + +zookeeperStarted.xml:73: [tbd: should we start w/ a word here about were to get the source, + exactly what to download, how to unpack it, and where to put it? Also, + does the user need to be in sudo, or can they be under their regular + login?] + +zookeeperStarted.xml:84: This should generate a JAR file called zookeeper.jar. To start + Zookeeper, compile and run zookeeper.jar. [tbd, some more + instruction here. Perhaps a command line? Are these two steps or + one?] + +zookeeperStarted.xml:139: ZooKeeper logs messages using log4j -- more detail available in + the Logging + section of the Programmer's Guide.[tbd: + real reference needed] + +zookeeperStarted.xml:201: The C bindings exist in two variants: single + threaded and multi-threaded. These differ only in how the messaging loop + is done. [tbd: what is the messaging loop? Do we talk about it + anywyhere? is this too much info for a getting started guide?] + +zookeeperStarted.xml:217: The entry syncLimit limits how far out of date a server can + be from a leader. [TBD: someone please verify that the previous is + true.] + +zookeeperStarted.xml:232: These are the "electionPort" numbers of the servers (as opposed to + clientPorts), that is ports for [tbd: feedback need: what are + these ports, exactly?] + +zookeeperStarted.xml:258: [tbd: what is the other config param? + (I believe two are mentioned above.)] diff --git a/src/docs/src/documentation/classes/CatalogManager.properties b/src/docs/src/documentation/classes/CatalogManager.properties new file mode 100644 index 00000000000..874614ca2ee --- /dev/null +++ b/src/docs/src/documentation/classes/CatalogManager.properties @@ -0,0 +1,34 @@ +# Copyright 2002-2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#======================================================================= +# CatalogManager.properties +# +# This is the default properties file for Apache Forrest. +# This facilitates local configuration of application-specific catalogs. +# +# See the Apache Forrest documentation: +# http://forrest.apache.org/docs/your-project.html +# http://forrest.apache.org/docs/validation.html +# verbosity ... level of messages for status/debug +# See forrest/src/core/context/WEB-INF/cocoon.xconf +# catalogs ... list of additional catalogs to load +# (Note that Apache Forrest will automatically load its own default catalog +# from src/core/context/resources/schema/catalog.xcat) +# use full pathnames +# pathname separator is always semi-colon (;) regardless of operating system +# directory separator is always slash (/) regardless of operating system +# +#catalogs=/home/me/forrest/my-site/src/documentation/resources/schema/catalog.xcat +catalogs= + diff --git a/src/docs/src/documentation/content/xdocs/index.xml b/src/docs/src/documentation/content/xdocs/index.xml new file mode 100644 index 00000000000..668bcce1b2b --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/index.xml @@ -0,0 +1,145 @@ + + + + + + + +
      + ZooKeeper: Because Coordinating Distributed Systems is a Zoo +
      + + +

      ZooKeeper is a high-performance coordination service for + distributed applications. It exposes common services - such as + naming, configuration management, synchronization, and group + services - in a simple interface so you don't have to write them + from scratch. You can use it off-the-shelf to implement + consensus, group management, leader election, and presence + protocols. And you can build on it for your own, specific needs. +

      + +

      + The following documents describe concepts and procedures to get + you started using ZooKeeper. If you have more questions, please + ask the mailing list or browse the + archives. +

      +
        + +
      • + ZooKeeper Overview +

        Technical Overview Documents for Client Developers, Adminstrators, and Contributors

        +
          +
        • + Overview + - a bird's eye view of ZooKeeper, including design concepts and architecture +
        • +
        • + Getting Started + - a tutorial-style guide for developers to install, run, and program to ZooKeeper +
        • +
        • + Release Notes + - new developer and user facing features, improvements, and incompatibilities +
        • +
        +
      • + +
      • + Developers +

        Documents for Developers using the ZooKeeper Client API

        + +
      • + +
      • + Administrators & Operators +

        Documents for Administrators and Operations Engineers of ZooKeeper Deployments

        +
          +
        • + Administrator's Guide + - a guide for system administrators and anyone else who might deploy ZooKeeper +
        • +
        • + Quota Guide + - a guide for system administrators on Quotas in ZooKeeper. +
        • +
        • + JMX + - how to enable JMX in ZooKeeper +
        • +
        • + Hierarchical quorums +
        • +
        • + Observers + - non-voting ensemble members that easily improve ZooKeeper's scalability +
        • +
        • + Dynamic Reconfiguration + - a guide on how to use dynamic reconfiguration in ZooKeeper +
        • +
        +
      • + +
      • + Contributors +

        Documents for Developers Contributing to the ZooKeeper Open Source Project

        + +
      • + +
      • + Miscellaneous ZooKeeper Documentation + +
      • +
      + + +
      diff --git a/src/docs/src/documentation/content/xdocs/javaExample.xml b/src/docs/src/documentation/content/xdocs/javaExample.xml new file mode 100644 index 00000000000..9e6ea2e28b1 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/javaExample.xml @@ -0,0 +1,712 @@ + + + + +
      + ZooKeeper Java Example + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This article contains sample Java code for a simple watch client. + + + + +
      + A Simple Watch Client + + To introduce you to the ZooKeeper Java API, we develop here a very simple + watch client. This ZooKeeper client watches a ZooKeeper node for changes + and responds to by starting or stopping a program. + + +
      + Requirements + + The client has four requirements: + + + + It takes as parameters: + + + the address of the ZooKeeper service + + + the name of a znode - the one to be watched + + + the name of a file to write the output to + + + an executable with arguments. + + + + + It fetches the data associated with the znode and starts the executable. + + + If the znode changes, the client refetches the contents and restarts the executable. + + + If the znode disappears, the client kills the executable. + + + +
      + +
      + Program Design + + Conventionally, ZooKeeper applications are broken into two units, one which maintains the connection, + and the other which monitors data. In this application, the class called the + Executor + maintains the ZooKeeper connection, and the class called the DataMonitor monitors the data + in the ZooKeeper tree. Also, Executor contains the main thread and contains the execution logic. + It is responsible for what little user interaction there is, as well as interaction with the exectuable program you + pass in as an argument and which the sample (per the requirements) shuts down and restarts, according to the + state of the znode. + + +
      + +
      + +
      + The Executor Class + The Executor object is the primary container of the sample application. It contains + both the ZooKeeper object, DataMonitor, as described above in + . + + + + // from the Executor class... + + public static void main(String[] args) { + if (args.length < 4) { + System.err + .println("USAGE: Executor hostPort znode filename program [args ...]"); + System.exit(2); + } + String hostPort = args[0]; + String znode = args[1]; + String filename = args[2]; + String exec[] = new String[args.length - 3]; + System.arraycopy(args, 3, exec, 0, exec.length); + try { + new Executor(hostPort, znode, filename, exec).run(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Executor(String hostPort, String znode, String filename, + String exec[]) throws KeeperException, IOException { + this.filename = filename; + this.exec = exec; + zk = new ZooKeeper(hostPort, 3000, this); + dm = new DataMonitor(zk, znode, null, this); + } + + public void run() { + try { + synchronized (this) { + while (!dm.dead) { + wait(); + } + } + } catch (InterruptedException e) { + } + } + + + + + Recall that the Executor's job is to start and stop the executable whose name you pass in on the command line. + It does this in response to events fired by the ZooKeeper object. As you can see in the code above, the Executor passes + a reference to itself as the Watcher argument in the ZooKeeper constructor. It also passes a reference to itself + as DataMonitorListener argument to the DataMonitor constructor. Per the Executor's definition, it implements both these + interfaces: + + + + public class Executor implements Watcher, Runnable, DataMonitor.DataMonitorListener { + ... + + + The Watcher interface is defined by the ZooKeeper Java API. + ZooKeeper uses it to communicate back to its container. It supports only one method, process(), and ZooKeeper uses + it to communciates generic events that the main thread would be intersted in, such as the state of the ZooKeeper connection or the ZooKeeper session.The Executor + in this example simply forwards those events down to the DataMonitor to decide what to do with them. It does this simply to illustrate + the point that, by convention, the Executor or some Executor-like object "owns" the ZooKeeper connection, but it is free to delegate the events to other + events to other objects. It also uses this as the default channel on which to fire watch events. (More on this later.) + + + + public void process(WatchedEvent event) { + dm.process(event); + } + + + The + DataMonitorListener + interface, on the other hand, is not part of the the ZooKeeper API. It is a completely custom interface, + designed for this sample application. The DataMonitor object uses it to communicate back to its container, which + is also the the Executor object.The DataMonitorListener interface looks like this: + + + public interface DataMonitorListener { + /** + * The existence status of the node has changed. + */ + void exists(byte data[]); + + /** + * The ZooKeeper session is no longer valid. + * + * @param rc + * the ZooKeeper reason code + */ + void closing(int rc); + } + + This interface is defined in the DataMonitor class and implemented in the Executor class. + When Executor.exists() is invoked, + the Executor decides whether to start up or shut down per the requirements. Recall that the requires say to kill the executable when the + znode ceases to exist. + + + When + Executor.closing() + is invoked, the Executor decides whether or not to shut itself down in response to the ZooKeeper connection permanently disappearing. + + + As you might have guessed, DataMonitor is the object that invokes + these methods, in response to changes in ZooKeeper's state. + + + Here are Executor's implementation of + DataMonitorListener.exists() + and DataMonitorListener.closing: + + + public void exists( byte[] data ) { + if (data == null) { + if (child != null) { + System.out.println("Killing process"); + child.destroy(); + try { + child.waitFor(); + } catch (InterruptedException e) { + } + } + child = null; + } else { + if (child != null) { + System.out.println("Stopping child"); + child.destroy(); + try { + child.waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + try { + FileOutputStream fos = new FileOutputStream(filename); + fos.write(data); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + System.out.println("Starting child"); + child = Runtime.getRuntime().exec(exec); + new StreamWriter(child.getInputStream(), System.out); + new StreamWriter(child.getErrorStream(), System.err); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public void closing(int rc) { + synchronized (this) { + notifyAll(); + } + } + + +
      +
      + The DataMonitor Class + + The DataMonitor class has the meat of the ZooKeeper logic. It is mostly + asynchronous and event driven. DataMonitor kicks things off in the constructor with: + + + public DataMonitor(ZooKeeper zk, String znode, Watcher chainedWatcher, + DataMonitorListener listener) { + this.zk = zk; + this.znode = znode; + this.chainedWatcher = chainedWatcher; + this.listener = listener; + + // Get things started by checking if the node exists. We are going + // to be completely event driven + zk.exists(znode, true, this, null); + } + + + The call to ZooKeeper.exists() checks for the existence of the znode, + sets a watch, and passes a reference to itself (this) + as the completion callback object. In this sense, it kicks things off, since the + real processing happens when the watch is triggered. + + + + Don't confuse the completion callback with the watch callback. The + ZooKeeper.exists() + completion callback, which happens to be the method StatCallback.processResult() implemented + in the DataMonitor object, is invoked when the asynchronous setting of the watch operation + (by ZooKeeper.exists()) completes on the server. + + + The triggering of the watch, on the other hand, sends an event to the Executor object, since + the Executor registered as the Watcher of the ZooKeeper object. + + + As an aside, you might note that the DataMonitor could also register itself as the Watcher + for this particular watch event. This is new to ZooKeeper 3.0.0 (the support of multiple Watchers). In this + example, however, DataMonitor does not register as the Watcher. + + + + When the ZooKeeper.exists() operation completes on the server, the ZooKeeper API invokes this completion callback on + the client: + + + + public void processResult(int rc, String path, Object ctx, Stat stat) { + boolean exists; + switch (rc) { + case Code.Ok: + exists = true; + break; + case Code.NoNode: + exists = false; + break; + case Code.SessionExpired: + case Code.NoAuth: + dead = true; + listener.closing(rc); + return; + default: + // Retry errors + zk.exists(znode, true, this, null); + return; + } + + byte b[] = null; + if (exists) { + try { + b = zk.getData(znode, false, null); + } catch (KeeperException e) { + // We don't need to worry about recovering now. The watch + // callbacks will kick off any exception handling + e.printStackTrace(); + } catch (InterruptedException e) { + return; + } + } + if ((b == null && b != prevData) + || (b != null && !Arrays.equals(prevData, b))) { + listener.exists(b); + prevData = b; + } + } + + + + The code first checks the error codes for znode existence, fatal errors, and + recoverable errors. If the file (or znode) exists, it gets the data from the znode, and + then invoke the exists() callback of Executor if the state has changed. Note, + it doesn't have to do any Exception processing for the getData call because it + has watches pending for anything that could cause an error: if the node is deleted + before it calls ZooKeeper.getData(), the watch event set by + the ZooKeeper.exists() triggers a callback; + if there is a communication error, a connection watch event fires when + the connection comes back up. + + + Finally, notice how DataMonitor processes watch events: + + public void process(WatchedEvent event) { + String path = event.getPath(); + if (event.getType() == Event.EventType.None) { + // We are are being told that the state of the + // connection has changed + switch (event.getState()) { + case SyncConnected: + // In this particular example we don't need to do anything + // here - watches are automatically re-registered with + // server and any watches triggered while the client was + // disconnected will be delivered (in order of course) + break; + case Expired: + // It's all over + dead = true; + listener.closing(KeeperException.Code.SessionExpired); + break; + } + } else { + if (path != null && path.equals(znode)) { + // Something has changed on the node, let's find out + zk.exists(znode, true, this, null); + } + } + if (chainedWatcher != null) { + chainedWatcher.process(event); + } + } + + + If the client-side ZooKeeper libraries can re-establish the + communication channel (SyncConnected event) to ZooKeeper before + session expiration (Expired event) all of the session's watches will + automatically be re-established with the server (auto-reset of watches + is new in ZooKeeper 3.0.0). See + ZooKeeper Watches + + in the programmer guide for more on this. A bit lower down in this + function, when DataMonitor gets an event for a znode, it calls + ZooKeeper.exists() + to find out what has changed. + +
      + +
      + Complete Source Listings + + Executor.java + + /** + * A simple example program to use DataMonitor to start and + * stop executables based on a znode. The program watches the + * specified znode and saves the data that corresponds to the + * znode in the filesystem. It also starts the specified program + * with the specified arguments when the znode exists and kills + * the program if the znode goes away. + */ + import java.io.FileOutputStream; + import java.io.IOException; + import java.io.InputStream; + import java.io.OutputStream; + + import org.apache.zookeeper.KeeperException; + import org.apache.zookeeper.WatchedEvent; + import org.apache.zookeeper.Watcher; + import org.apache.zookeeper.ZooKeeper; + + public class Executor + implements Watcher, Runnable, DataMonitor.DataMonitorListener + { + String znode; + + DataMonitor dm; + + ZooKeeper zk; + + String filename; + + String exec[]; + + Process child; + + public Executor(String hostPort, String znode, String filename, + String exec[]) throws KeeperException, IOException { + this.filename = filename; + this.exec = exec; + zk = new ZooKeeper(hostPort, 3000, this); + dm = new DataMonitor(zk, znode, null, this); + } + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length < 4) { + System.err + .println("USAGE: Executor hostPort znode filename program [args ...]"); + System.exit(2); + } + String hostPort = args[0]; + String znode = args[1]; + String filename = args[2]; + String exec[] = new String[args.length - 3]; + System.arraycopy(args, 3, exec, 0, exec.length); + try { + new Executor(hostPort, znode, filename, exec).run(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /*************************************************************************** + * We do process any events ourselves, we just need to forward them on. + * + * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.proto.WatcherEvent) + */ + public void process(WatchedEvent event) { + dm.process(event); + } + + public void run() { + try { + synchronized (this) { + while (!dm.dead) { + wait(); + } + } + } catch (InterruptedException e) { + } + } + + public void closing(int rc) { + synchronized (this) { + notifyAll(); + } + } + + static class StreamWriter extends Thread { + OutputStream os; + + InputStream is; + + StreamWriter(InputStream is, OutputStream os) { + this.is = is; + this.os = os; + start(); + } + + public void run() { + byte b[] = new byte[80]; + int rc; + try { + while ((rc = is.read(b)) > 0) { + os.write(b, 0, rc); + } + } catch (IOException e) { + } + + } + } + + public void exists(byte[] data) { + if (data == null) { + if (child != null) { + System.out.println("Killing process"); + child.destroy(); + try { + child.waitFor(); + } catch (InterruptedException e) { + } + } + child = null; + } else { + if (child != null) { + System.out.println("Stopping child"); + child.destroy(); + try { + child.waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + try { + FileOutputStream fos = new FileOutputStream(filename); + fos.write(data); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + System.out.println("Starting child"); + child = Runtime.getRuntime().exec(exec); + new StreamWriter(child.getInputStream(), System.out); + new StreamWriter(child.getErrorStream(), System.err); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + + + + + DataMonitor.java + + /** + * A simple class that monitors the data and existence of a ZooKeeper + * node. It uses asynchronous ZooKeeper APIs. + */ + import java.util.Arrays; + + import org.apache.zookeeper.KeeperException; + import org.apache.zookeeper.WatchedEvent; + import org.apache.zookeeper.Watcher; + import org.apache.zookeeper.ZooKeeper; + import org.apache.zookeeper.AsyncCallback.StatCallback; + import org.apache.zookeeper.KeeperException.Code; + import org.apache.zookeeper.data.Stat; + + public class DataMonitor implements Watcher, StatCallback { + + ZooKeeper zk; + + String znode; + + Watcher chainedWatcher; + + boolean dead; + + DataMonitorListener listener; + + byte prevData[]; + + public DataMonitor(ZooKeeper zk, String znode, Watcher chainedWatcher, + DataMonitorListener listener) { + this.zk = zk; + this.znode = znode; + this.chainedWatcher = chainedWatcher; + this.listener = listener; + // Get things started by checking if the node exists. We are going + // to be completely event driven + zk.exists(znode, true, this, null); + } + + /** + * Other classes use the DataMonitor by implementing this method + */ + public interface DataMonitorListener { + /** + * The existence status of the node has changed. + */ + void exists(byte data[]); + + /** + * The ZooKeeper session is no longer valid. + * + * @param rc + * the ZooKeeper reason code + */ + void closing(int rc); + } + + public void process(WatchedEvent event) { + String path = event.getPath(); + if (event.getType() == Event.EventType.None) { + // We are are being told that the state of the + // connection has changed + switch (event.getState()) { + case SyncConnected: + // In this particular example we don't need to do anything + // here - watches are automatically re-registered with + // server and any watches triggered while the client was + // disconnected will be delivered (in order of course) + break; + case Expired: + // It's all over + dead = true; + listener.closing(KeeperException.Code.SessionExpired); + break; + } + } else { + if (path != null && path.equals(znode)) { + // Something has changed on the node, let's find out + zk.exists(znode, true, this, null); + } + } + if (chainedWatcher != null) { + chainedWatcher.process(event); + } + } + + public void processResult(int rc, String path, Object ctx, Stat stat) { + boolean exists; + switch (rc) { + case Code.Ok: + exists = true; + break; + case Code.NoNode: + exists = false; + break; + case Code.SessionExpired: + case Code.NoAuth: + dead = true; + listener.closing(rc); + return; + default: + // Retry errors + zk.exists(znode, true, this, null); + return; + } + + byte b[] = null; + if (exists) { + try { + b = zk.getData(znode, false, null); + } catch (KeeperException e) { + // We don't need to worry about recovering now. The watch + // callbacks will kick off any exception handling + e.printStackTrace(); + } catch (InterruptedException e) { + return; + } + } + if ((b == null && b != prevData) + || (b != null && !Arrays.equals(prevData, b))) { + listener.exists(b); + prevData = b; + } + } + } + + +
      + + +
      diff --git a/src/docs/src/documentation/content/xdocs/recipes.xml b/src/docs/src/documentation/content/xdocs/recipes.xml new file mode 100644 index 00000000000..e7f56a4b8f9 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/recipes.xml @@ -0,0 +1,831 @@ + + + + +
      + ZooKeeper Recipes and Solutions + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This guide contains pseudocode and guidelines for using Zookeeper to + solve common problems in Distributed Application Coordination. It + discusses such problems as event handlers, queues, and locks.. + + + $Revision: 1.6 $ $Date: 2008/09/19 03:46:18 $ + + + +
      + A Guide to Creating Higher-level Constructs with ZooKeeper + + In this article, you'll find guidelines for using + ZooKeeper to implement higher order functions. All of them are conventions + implemented at the client and do not require special support from + ZooKeeper. Hopfully the community will capture these conventions in client-side libraries + to ease their use and to encourage standardization. + + + One of the most interesting things about ZooKeeper is that even + though ZooKeeper uses asynchronous notifications, you + can use it to build synchronous consistency + primitives, such as queues and locks. As you will see, this is possible + because ZooKeeper imposes an overall order on updates, and has mechanisms + to expose this ordering. + + + Note that the recipes below attempt to employ best practices. In + particular, they avoid polling, timers or anything else that would result + in a "herd effect", causing bursts of traffic and limiting + scalability. + + + There are many useful functions that can be imagined that aren't + included here - revocable read-write priority locks, as just one example. + And some of the constructs mentioned here - locks, in particular - + illustrate certain points, even though you may find other constructs, such + as event handles or queues, a more practical means of performing the same + function. In general, the examples in this section are designed to + stimulate thought. + + +
      + Important Note About Error Handling + + When implementing the recipes you must handle recoverable exceptions + (see the FAQ). In + particular, several of the recipes employ sequential ephemeral + nodes. When creating a sequential ephemeral node there is an error case in + which the create() succeeds on the server but the server crashes before + returning the name of the node to the client. When the client reconnects its + session is still valid and, thus, the node is not removed. The implication is + that it is difficult for the client to know if its node was created or not. The + recipes below include measures to handle this. + +
      + +
      + Out of the Box Applications: Name Service, Configuration, Group + Membership + + + Name service and configuration are two of the primary applications + of ZooKeeper. These two functions are provided directly by the ZooKeeper + API. + + + Another function directly provided by ZooKeeper is group + membership. The group is represented by a node. Members of the + group create ephemeral nodes under the group node. Nodes of the members + that fail abnormally will be removed automatically when ZooKeeper detects + the failure. + +
      + +
      + Barriers + + Distributed systems use + barriers + to block processing of a set of nodes until a condition is met + at which time all the nodes are allowed to proceed. Barriers are + implemented in ZooKeeper by designating a barrier node. The + barrier is in place if the barrier node exists. Here's the + pseudo code: + + + + + Client calls the ZooKeeper API's exists() + function on the barrier node, with + watch + set to true. + + + + + If exists() returns false, the + barrier is gone and the client proceeds + + + + + Else, if exists() returns true, + the clients wait for a watch event from ZooKeeper for the barrier + node. + + + + + When the watch event is triggered, the client reissues the + exists( ) + call, again waiting until + the barrier node is removed. + + + + +
      + Double Barriers + + Double barriers enable clients to synchronize the beginning and + the end of a computation. When enough processes have joined the barrier, + processes start their computation and leave the barrier once they have + finished. This recipe shows how to use a ZooKeeper node as a + barrier. + + + The pseudo code in this recipe represents the barrier node as + b. Every client process + p + registers with the barrier node on entry and unregisters when it is + ready to leave. A node registers with the barrier node via the Enter + procedure below, it waits until + x + client process register before proceeding with + the computation. (The x here is up to you to + determine for your system.) + + + + + + + + Enter + + + + + Leave + + + + + + + + + Create a name + + n + = + b+“/”+ + p + + + + + + Set watch: + exists(b + ‘‘/ready’’, + true) + + + + + + Create child: + create( + n, EPHEMERAL) + + + + + + + L = getChildren(b, + false) + + + + + + if fewer children in L than + x, wait for watch event + + + + + else + create(b + ‘‘/ready’’, + REGULAR) + + + + + + + + + + + L = getChildren(b, + false) + + + + + + if no children, exit + + + + if p is only process node in + L, delete(n) and exit + + + + + if p is the lowest process + node in L, wait on highest process node in L + + + + + else + delete(n) + + if + still exists and wait on lowest process node in L + + + + + goto 1 + + + + + + + + On entering, all processes watch on a ready node and + create an ephemeral node as a child of the barrier node. Each process + but the last enters the barrier and waits for the ready node to appear + at line 5. The process that creates the xth node, the last process, will + see x nodes in the list of children and create the ready node, waking up + the other processes. Note that waiting processes wake up only when it is + time to exit, so waiting is efficient. + + + On exit, you can't use a flag such as + ready + because you are watching for process nodes to go away. By using + ephemeral nodes, processes that fail after the barrier has been entered + do not prevent correct processes from finishing. When processes are + ready to leave, they need to delete their process nodes and wait for all + other processes to do the same. + + + Processes exit when there are no process nodes left as children of + b. However, as an efficiency, you can use the + lowest process node as the ready flag. All other processes that are + ready to exit watch for the lowest existing process node to go away, and + the owner of the lowest process watches for any other process node + (picking the highest for simplicity) to go away. This means that only a + single process wakes up on each node deletion except for the last node, + which wakes up everyone when it is removed. + +
      +
      + +
      + Queues + + Distributed queues are a common data structure. To implement a + distributed queue in ZooKeeper, first designate a znode to hold the queue, + the queue node. The distributed clients put something into the queue by + calling create() with a pathname ending in "queue-", with the + sequence + and ephemeral flags in + the create() call set to true. Because the + sequence + flag is set, the new pathnames will have the form + _path-to-queue-node_/queue-X, where X is a monotonic increasing number. A + client that wants to be removed from the queue calls ZooKeeper's getChildren( ) + function, with + watch + set to true on the queue node, and begins + processing nodes with the lowest number. The client does not need to issue + another getChildren( ) until it exhausts + the list obtained from the first getChildren( + ) + call. If there are are no children in the queue node, the + reader waits for a watch notification to check the queue again. + + + + There now exists a Queue implementation in ZooKeeper + recipes directory. This is distributed with the release -- + src/recipes/queue directory of the release artifact. + + + +
      + Priority Queues + + To implement a priority queue, you need only make two simple + changes to the generic queue + recipe + . First, to add to a queue, the pathname ends with + "queue-YY" where YY is the priority of the element with lower numbers + representing higher priority (just like UNIX). Second, when removing + from the queue, a client uses an up-to-date children list meaning that + the client will invalidate previously obtained children lists if a watch + notification triggers for the queue node. + +
      +
      + +
      + Locks + + Fully distributed locks that are globally synchronous, meaning at + any snapshot in time no two clients think they hold the same lock. These + can be implemented using ZooKeeeper. As with priority queues, first define + a lock node. + + + + There now exists a Lock implementation in ZooKeeper + recipes directory. This is distributed with the release -- + src/recipes/lock directory of the release artifact. + + + + Clients wishing to obtain a lock do the following: + + + + Call create( ) with a pathname + of "_locknode_/guid-lock-" and the sequence and + ephemeral + flags set. The + guid + is needed in case the create() result is missed. See the note below. + + + + + Call getChildren( ) on the lock + node without setting the watch flag (this is + important to avoid the herd effect). + + + + + If the pathname created in step 1 + has the lowest sequence number suffix, the + client has the lock and the client exits the protocol. + + + + + The client calls exists( ) with + the watch flag set on the path in the lock directory with the next + lowest sequence number. + + + + + if exists( ) returns false, go + to step 2. Otherwise, wait for a + notification for the pathname from the previous step before going to + step 2. + + + + + The unlock protocol is very simple: clients wishing to release a + lock simply delete the node they created in step 1. + + + Here are a few things to notice: + + + + The removal of a node will only cause one client to wake up + since each node is watched by exactly one client. In this way, you + avoid the herd effect. + + + + + + + There is no polling or timeouts. + + + + + + Because of the way you implement locking, it is easy to see the + amount of lock contention, break locks, debug locking problems, + etc. + + + + +
      + Recoverable Errors and the GUID + + + If a recoverable error occurs calling create() the + client should call getChildren() and check for a node + containing the guid used in the path name. + This handles the case (noted above) of + the create() succeeding on the server but the server crashing before returning the name + of the new node. + + + +
      + +
      + Shared Locks + + You can implement shared locks by with a few changes to the lock + protocol: + + + + + + + + Obtaining a read + lock: + + + + + Obtaining a write + lock: + + + + + + + + + Call create( ) to + create a node with pathname + "guid-/read-". This is the + lock node use later in the protocol. Make sure to set both + the sequence and + ephemeral + flags. + + + + + Call + getChildren( ) + on the lock node without setting the + watch + flag - this is important, as it + avoids the herd effect. + + + + + If there are no children with a pathname starting + with "write-" and having a lower + sequence number than the node created in step 1, the client has the lock and can + exit the protocol. + + + + + Otherwise, call exists( + ), with watch flag, set on + the node in lock directory with pathname staring with + "write-" having the next lowest + sequence number. + + + + + If + exists( ) + returns false, goto step 2. + + + + + Otherwise, wait for a notification for the pathname + from the previous step before going to step + 2 + + + + + + + + + + Call create( ) to + create a node with pathname + "guid-/write-". This is the + lock node spoken of later in the protocol. Make sure to + set both sequence and + ephemeral + flags. + + + + + Call getChildren( ) + on the lock node + without + setting the watch flag - this is + important, as it avoids the herd effect. + + + + + If there are no children with a lower sequence + number than the node created in step 1, the client has the lock and the + client exits the protocol. + + + + + Call + exists( ), + with watch flag set, on the node with + the pathname that has the next lowest sequence + number. + + + + + If + exists( ) + returns false, goto step 2. Otherwise, wait for a + notification for the pathname from the previous step + before going to step 2. + + + + + + + + + + Notes: + + + + It might appear that this recipe creates a herd effect: + when there is a large group of clients waiting for a read + lock, and all getting notified more or less simultaneously + when the "write-" node with the lowest + sequence number is deleted. In fact. that's valid behavior: + as all those waiting reader clients should be released since + they have the lock. The herd effect refers to releasing a + "herd" when in fact only a single or a small number of + machines can proceed. + + + + + + + See the note for Locks on how to use the guid in the node. + + + + +
      + +
      + Revocable Shared Locks + + With minor modifications to the Shared Lock protocol, you make + shared locks revocable by modifying the shared lock protocol: + + + In step 1, of both obtain reader + and writer lock protocols, call getData( + ) + with watch set, immediately after the + call to create( ). If the client + subsequently receives notification for the node it created in step + 1, it does another getData( ) + on that node, with + watch + set and looks for the string "unlock", which + signals to the client that it must release the lock. This is because, + according to this shared lock protocol, you can request the client with + the lock give up the lock by calling setData() + on the lock node, writing "unlock" to that node. + + + Note that this protocol requires the lock holder to consent to + releasing the lock. Such consent is important, especially if the lock + holder needs to do some processing before releasing the lock. Of course + you can always implement Revocable Shared Locks with Freaking + Laser Beams + by stipulating in your protocol that the revoker + is allowed to delete the lock node if after some length of time the lock + isn't deleted by the lock holder. + +
      +
      + +
      + Two-phased Commit + + A two-phase commit protocol is an algorithm that lets all clients in + a distributed system agree either to commit a transaction or abort. + + + In ZooKeeper, you can implement a two-phased commit by having a + coordinator create a transaction node, say "/app/Tx", and one child node + per participating site, say "/app/Tx/s_i". When coordinator creates the + child node, it leaves the content undefined. Once each site involved in + the transaction receives the transaction from the coordinator, the site + reads each child node and sets a watch. Each site then processes the query + and votes "commit" or "abort" by writing to its respective node. Once the + write completes, the other sites are notified, and as soon as all sites + have all votes, they can decide either "abort" or "commit". Note that a + node can decide "abort" earlier if some site votes for "abort". + + + An interesting aspect of this implementation is that the only role + of the coordinator is to decide upon the group of sites, to create the + ZooKeeper nodes, and to propagate the transaction to the corresponding + sites. In fact, even propagating the transaction can be done through + ZooKeeper by writing it in the transaction node. + + + There are two important drawbacks of the approach described above. + One is the message complexity, which is O(n²). The second is the + impossibility of detecting failures of sites through ephemeral nodes. To + detect the failure of a site using ephemeral nodes, it is necessary that + the site create the node. + + + To solve the first problem, you can have only the coordinator + notified of changes to the transaction nodes, and then notify the sites + once coordinator reaches a decision. Note that this approach is scalable, + but it's is slower too, as it requires all communication to go through the + coordinator. + + + To address the second problem, you can have the coordinator + propagate the transaction to the sites, and have each site creating its + own ephemeral node. + +
      + +
      + Leader Election + + A simple way of doing leader election with ZooKeeper is to use the + SEQUENCE|EPHEMERAL + flags when creating + znodes that represent "proposals" of clients. The idea is to have a znode, + say "/election", such that each znode creates a child znode "/election/guid-n_" + with both flags SEQUENCE|EPHEMERAL. With the sequence flag, ZooKeeper + automatically appends a sequence number that is greater than any one + previously appended to a child of "/election". The process that created + the znode with the smallest appended sequence number is the leader. + + + That's not all, though. It is important to watch for failures of the + leader, so that a new client arises as the new leader in the case the + current leader fails. A trivial solution is to have all application + processes watching upon the current smallest znode, and checking if they + are the new leader when the smallest znode goes away (note that the + smallest znode will go away if the leader fails because the node is + ephemeral). But this causes a herd effect: upon a failure of the current + leader, all other processes receive a notification, and execute + getChildren on "/election" to obtain the current list of children of + "/election". If the number of clients is large, it causes a spike on the + number of operations that ZooKeeper servers have to process. To avoid the + herd effect, it is sufficient to watch for the next znode down on the + sequence of znodes. If a client receives a notification that the znode it + is watching is gone, then it becomes the new leader in the case that there + is no smaller znode. Note that this avoids the herd effect by not having + all clients watching the same znode. + + + Here's the pseudo code: + + Let ELECTION be a path of choice of the application. To volunteer to + be a leader: + + + + + Create znode z with path "ELECTION/guid-n_" with both SEQUENCE and + EPHEMERAL flags; + + + + + Let C be the children of "ELECTION", and i be the sequence + number of z; + + + + + Watch for changes on "ELECTION/guid-n_j", where j is the largest + sequence number such that j < i and n_j is a znode in C; + + + + + Upon receiving a notification of znode deletion: + + + + Let C be the new set of children of ELECTION; + + + + If z is the smallest node in C, then execute leader + procedure; + + + + + Otherwise, watch for changes on "ELECTION/guid-n_j", where j is the + largest sequence number such that j < i and n_j is a znode in C; + + + + + Notes: + + + + Note that the znode having no preceding znode on the list of + children does not imply that the creator of this znode is aware that it is + the current leader. Applications may consider creating a separate znode + to acknowledge that the leader has executed the leader procedure. + + + + + + + See the note for Locks on how to use the guid in the node. + + + + +
      +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/releasenotes.xml b/src/docs/src/documentation/content/xdocs/releasenotes.xml new file mode 100644 index 00000000000..77b728ac098 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/releasenotes.xml @@ -0,0 +1,1468 @@ + + + + +
      + ZooKeeper 3.0.0 Release Notes + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + + These release notes include new developer and user facing incompatibilities, features, and major improvements. + + + + + + Migration Instructions + + + + + Changes + + + + +
      + Migration Instructions when Upgrading to 3.0.0 + + + You should only have to read this section if you are upgrading from a previous version of ZooKeeper to version 3.0.0, otw skip down to + changes + + + + + A small number of changes in this release have resulted in non-backward compatible Zookeeper client user code and server instance data. The following instructions provide details on how to + migrate code and date from version 2.2.1 to version 3.0.0. + + + + Note: ZooKeeper increments the major version number (major.minor.fix) when backward incompatible changes are made to the source base. As part of the migration from SourceForge we changed + the package structure (com.yahoo.zookeeper.* to org.apache.zookeeper.*) and felt it was a good time to incorporate some changes that we had been withholding. As a result the following will + be required when migrating from 2.2.1 to 3.0.0 version of ZooKeeper. + + + + + + Migrating Client Code + + + + + Migrating Server Data + + + + + Migrating Server Configuration + + + + +
      + Migrating Client Code + + + The underlying client-server protocol has changed in version 3.0.0 + of ZooKeeper. As a result clients must be upgraded along with + serving clusters to ensure proper operation of the system (old + pre-3.0.0 clients are not guaranteed to operate against upgraded + 3.0.0 servers and vice-versa). + + +
      + Watch Management + + + In previous releases of ZooKeeper any watches registered by clients were lost if the client lost a connection to a ZooKeeper server. + This meant that developers had to track watches they were interested in and reregister them if a session disconnect event was recieved. + In this release the client library tracks watches that a client has registered and reregisters the watches when a connection is made to a new server. + Applications that still manually reregister interest should continue working properly as long as they are able to handle unsolicited watches. + For example, an old application may register a watch for /foo and /goo, lose the connection, and reregister only /goo. + As long as the application is able to recieve a notification for /foo, (probably ignoring it) it does not need to be changed. + One caveat to the watch management: it is possible to miss an event for the creation and deletion of a znode if watching for creation and both the create and delete happens while + the client is disconnected from ZooKeeper. + + + + This release also allows clients to specify call specific watch functions. + This gives the developer the ability to modularize logic in different watch functions rather than cramming everything in the watch function attached to the ZooKeeper handle. + Call specific watch functions receive all session events for as long as they are active, but will only receive the watch callbacks for which they are registered. + +
      + +
      + Java API + + + + The java package structure has changed from com.yahoo.zookeeper* to org.apache.zookeeper*. This will + probably effect all of your java code which makes use of ZooKeeper APIs (typically import statements) + + + + A number of constants used in the client ZooKeeper API were re-specified using enums (rather than ints). See ZOOKEEPER-7, ZOOKEEPER-132 and ZOOKEEPER-139 + for full details + + + + + ZOOKEEPER-18 + removed KeeperStateChanged, use KeeperStateDisconnected instead + + + + + + Also see + the current java API + +
      + +
      + C API + + + + A number of constants used in the client ZooKeeper API were renamed in order to reduce namespace collision, see ZOOKEEPER-6 + for full details + + + + +
      +
      + +
      + Migrating Server Data + + + The following issues resulted in changes to the on-disk data format (the snapshot and transaction log files contained within the ZK data directory) and require a migration utility to + be run. + + + + + + ZOOKEEPER-27 Unique DB identifiers for servers and clients + + + + + ZOOKEEPER-32 CRCs for ZooKeeper data + + + + + ZOOKEEPER-33 Better ACL management + + + + + ZOOKEEPER-38 headers (version+) in log/snap files + + + + + + The following must be run once, and only once, when upgrading the ZooKeeper server instances to version 3.0.0. + + + + + The <dataLogDir> and <dataDir> directories referenced + below are specified by the + dataLogDir + and dataDir specification in your + ZooKeeper config file + respectively. dataLogDir defaults to the + value of dataDir if not specified explicitly + in the ZooKeeper server config file (in which case provide the + same directory for both parameters to the upgrade utility). + + + + + + Shutdown the ZooKeeper server cluster. + + + Backup your <dataLogDir> and <dataDir> directories + + + Run upgrade using + + + + bin/zkServer.sh upgrade <dataLogDir> <dataDir> + + + + or + + + + java -classpath pathtolog4j:pathtozookeeper.jar UpgradeMain <dataLogDir> <dataDir> + + + + where <dataLogDir> is the directory where all transaction logs (log.*) are stored. <dataDir> is the directory where all the snapshots (snapshot.*) are stored. + + + + Restart the cluster. + + + + If you have any failure during the upgrade procedure keep reading to sanitize your database. + + This is how upgrade works in ZooKeeper. This will help you troubleshoot in case you have problems while upgrading + + + Upgrade moves files from <dataLogDir> and <dataDir> to <dataLogDir>/version-1/ and <dataDir>/version-1 respectively (version-1 sub-directory is + created by the upgrade utility). + + + + Upgrade creates a new version sub-directory <dataDir>/version-2 and <dataLogDir>/version-2 + + + Upgrade reads the old database from <dataDir>/version-1 and <dataLogDir>/version-1 into the memory and creates a new upgraded snapshot. + + + Upgrade writes the new database in <dataDir>/version-2. + + + + Troubleshooting. + + + + In case you start ZooKeeper 3.0 without upgrading from 2.0 on a 2.0 database - the servers will start up with an empty database. + This is because the servers assume that <dataDir>/version-2 and <dataLogDir>/version-2 will have the database to start with. Since this will be empty + in case of no upgrade, the servers will start with an empty database. In such a case, shutdown the ZooKeeper servers, remove the version-2 directory (remember + this will lead to loss of updates after you started 3.0.) + and then start the upgrade procedure. + + + + If the upgrade fails while trying to rename files into the version-1 directory, you should try and move all the files under <dataDir>/version-1 + and <dataLogDir>/version-1 to <dataDir> and <dataLogDir> respectively. Then try upgrade again. + + + + If you do not wish to run with ZooKeeper 3.0 and prefer to run with ZooKeeper 2.0 and have already upgraded - you can run ZooKeeper 2 with + the <dataDir> and <dataLogDir> directories changed to <dataDir>/version-1 and <dataLogDir>/version-1. Remember that you will lose all the updates that + you made after the upgrade. + + + + +
      + +
      + Migrating Server Configuration + + + There is a significant change to the ZooKeeper server configuration file. + + + The default election algorithm, specified by + the electionAlg configuration attribute, has + changed from a default of 0 to a default + of 3. See + Cluster + Options + + section of the administrators guide, specifically + the + electionAlg + and server.X properties. + + + + You will either need to explicitly + set electionAlg to it's previous default value + of 0 or change + your server.X options to include the leader + election port. + + +
      + +
      + +
      + Changes Since ZooKeeper 2.2.1 + + + Version 2.2.1 code, documentation, binaries, etc... are still accessible on + SourceForge + + + + Changes Since ZooKeeper 2.2.1 + + + + + + Issue + Notes + + + + + + + ZOOKEEPER-43 + + + + Server side of auto reset watches. + + + + + + ZOOKEEPER-132 + + + + Create Enum to replace CreateFlag in ZooKepper.create method + + + + + + ZOOKEEPER-139 + + + + Create Enums for WatcherEvent's KeeperState and EventType + + + + + + ZOOKEEPER-18 + + + + keeper state inconsistency + + + + + + ZOOKEEPER-38 + + + + headers in log/snap files + + + + + + ZOOKEEPER-8 + + + + Stat enchaned to include num of children and size + + + + + + ZOOKEEPER-6 + + + + List of problem identifiers in zookeeper.h + + + + + + ZOOKEEPER-7 + + + + Use enums rather than ints for types and state + + + + + + ZOOKEEPER-27 + + + + Unique DB identifiers for servers and clients + + + + + + ZOOKEEPER-32 + + + + CRCs for ZooKeeper data + + + + + + ZOOKEEPER-33 + + + + Better ACL management + + + + + + ZOOKEEPER-203 + + + + fix datadir typo in releasenotes + + + + + + ZOOKEEPER-145 + + + + write detailed release notes for users migrating from 2.x to 3.0 + + + + + + ZOOKEEPER-23 + + + + Auto reset of watches on reconnect + + + + + + ZOOKEEPER-191 + + + + forrest docs for upgrade. + + + + + + ZOOKEEPER-201 + + + + validate magic number when reading snapshot and transaction logs + + + + + + ZOOKEEPER-200 + + + + the magic number for snapshot and log must be different + + + + + + ZOOKEEPER-199 + + + + fix log messages in persistence code + + + + + + ZOOKEEPER-197 + + + + create checksums for snapshots + + + + + + ZOOKEEPER-198 + + + + apache license header missing from FollowerSyncRequest.java + + + + + + ZOOKEEPER-5 + + + + Upgrade Feature in Zookeeper server. + + + + + + ZOOKEEPER-194 + + + + Fix terminology in zookeeperAdmin.xml + + + + + + ZOOKEEPER-151 + + + + Document change to server configuration + + + + + + ZOOKEEPER-193 + + + + update java example doc to compile with latest zookeeper + + + + + + ZOOKEEPER-187 + + + + CreateMode api docs missing + + + + + + ZOOKEEPER-186 + + + + add new "releasenotes.xml" to forrest documentation + + + + + + ZOOKEEPER-190 + + + + Reorg links to docs and navs to docs into related sections + + + + + + ZOOKEEPER-189 + + + + forrest build not validated xml of input documents + + + + + + ZOOKEEPER-188 + + + + Check that election port is present for all servers + + + + + + ZOOKEEPER-185 + + + + Improved version of FLETest + + + + + + ZOOKEEPER-184 + + + + tests: An explicit include derective is needed for the usage of memcpy functions + + + + + + ZOOKEEPER-183 + + + + Array subscript is above array bounds in od_completion, src/cli.c. + + + + + + ZOOKEEPER-182 + + + + zookeeper_init accepts empty host-port string and returns valid pointer to zhandle_t. + + + + + + ZOOKEEPER-17 + + + + zookeeper_init doc needs clarification + + + + + + ZOOKEEPER-181 + + + + Some Source Forge Documents did not get moved over: javaExample, zookeeperTutorial, zookeeperInternals + + + + + + ZOOKEEPER-180 + + + + Placeholder sections needed in document for new topics that the umbrella jira discusses + + + + + + ZOOKEEPER-179 + + + + Programmer's Guide "Basic Operations" section is missing content + + + + + + ZOOKEEPER-178 + + + + FLE test. + + + + + + ZOOKEEPER-159 + + + + Cover two corner cases of leader election + + + + + + ZOOKEEPER-156 + + + + update programmer guide with acl details from old wiki page + + + + + + ZOOKEEPER-154 + + + + reliability graph diagram in overview doc needs context + + + + + + ZOOKEEPER-157 + + + + Peer can't find existing leader + + + + + + ZOOKEEPER-155 + + + + improve "the zookeeper project" section of overview doc + + + + + + ZOOKEEPER-140 + + + + Deadlock in QuorumCnxManager + + + + + + ZOOKEEPER-147 + + + + This is version of the documents with most of the [tbd...] scrubbed out + + + + + + ZOOKEEPER-150 + + + + zookeeper build broken + + + + + + ZOOKEEPER-136 + + + + sync causes hang in all followers of quorum. + + + + + + ZOOKEEPER-134 + + + + findbugs cleanup + + + + + + ZOOKEEPER-133 + + + + hudson tests failing intermittently + + + + + + ZOOKEEPER-144 + + + + add tostring support for watcher event, and enums for event type/state + + + + + + ZOOKEEPER-21 + + + + Improve zk ctor/watcher + + + + + + ZOOKEEPER-142 + + + + Provide Javadoc as to the maximum size of the data byte array that may be stored within a znode + + + + + + ZOOKEEPER-93 + + + + Create Documentation for Zookeeper + + + + + + ZOOKEEPER-117 + + + + threading issues in Leader election + + + + + + ZOOKEEPER-137 + + + + client watcher objects can lose events + + + + + + ZOOKEEPER-131 + + + + Old leader election can elect a dead leader over and over again + + + + + + ZOOKEEPER-130 + + + + update build.xml to support apache release process + + + + + + ZOOKEEPER-118 + + + + findbugs flagged switch statement in followerrequestprocessor.run + + + + + + ZOOKEEPER-115 + + + + Potential NPE in QuorumCnxManager + + + + + + ZOOKEEPER-114 + + + + cleanup ugly event messages in zookeeper client + + + + + + ZOOKEEPER-112 + + + + src/java/main ZooKeeper.java has test code embedded into it. + + + + + + ZOOKEEPER-39 + + + + Use Watcher objects rather than boolean on read operations. + + + + + + ZOOKEEPER-97 + + + + supports optional output directory in code generator. + + + + + + ZOOKEEPER-101 + + + + Integrate ZooKeeper with "violations" feature on hudson + + + + + + ZOOKEEPER-105 + + + + Catch Zookeeper exceptions and print on the stderr. + + + + + + ZOOKEEPER-42 + + + + Change Leader Election to fast tcp. + + + + + + ZOOKEEPER-48 + + + + auth_id now handled correctly when no auth ids present + + + + + + ZOOKEEPER-44 + + + + Create sequence flag children with prefixes of 0's so that they can be lexicographically sorted. + + + + + + ZOOKEEPER-108 + + + + Fix sync operation reordering on a Quorum. + + + + + + ZOOKEEPER-25 + + + + Fuse module for Zookeeper. + + + + + + ZOOKEEPER-58 + + + + Race condition on ClientCnxn.java + + + + + + ZOOKEEPER-56 + + + + Add clover support to build.xml. + + + + + + ZOOKEEPER-75 + + + + register the ZooKeeper mailing lists with nabble.com + + + + + + ZOOKEEPER-54 + + + + remove sleeps in the tests. + + + + + + ZOOKEEPER-55 + + + + build.xml failes to retrieve a release number from SVN and the ant target "dist" fails + + + + + + ZOOKEEPER-89 + + + + invoke WhenOwnerListener.whenNotOwner when the ZK connection fails + + + + + + ZOOKEEPER-90 + + + + invoke WhenOwnerListener.whenNotOwner when the ZK session expires and the znode is the leader + + + + + + ZOOKEEPER-82 + + + + Make the ZooKeeperServer more DI friendly. + + + + + + ZOOKEEPER-110 + + + + Build script relies on svnant, which is not compatible with subversion 1.5 working copies + + + + + + ZOOKEEPER-111 + + + + Significant cleanup of existing tests. + + + + + + ZOOKEEPER-122 + + + + Fix NPE in jute's Utils.toCSVString. + + + + + + ZOOKEEPER-123 + + + + Fix the wrong class is specified for the logger. + + + + + + ZOOKEEPER-2 + + + + Fix synchronization issues in QuorumPeer and FastLeader election. + + + + + + ZOOKEEPER-125 + + + + Remove unwanted class declaration in FastLeaderElection. + + + + + + ZOOKEEPER-61 + + + + Address in client/server test cases. + + + + + + ZOOKEEPER-75 + + + + cleanup the library directory + + + + + + ZOOKEEPER-109 + + + + cleanup of NPE and Resource issue nits found by static analysis + + + + + + ZOOKEEPER-76 + + + + Commit 677109 removed the cobertura library, but not the build targets. + + + + + + ZOOKEEPER-63 + + + + Race condition in client close + + + + + + ZOOKEEPER-70 + + + + Add skeleton forrest doc structure for ZooKeeper + + + + + + ZOOKEEPER-79 + + + + Document jacob's leader election on the wiki recipes page + + + + + + ZOOKEEPER-73 + + + + Move ZK wiki from SourceForge to Apache + + + + + + ZOOKEEPER-72 + + + + Initial creation/setup of ZooKeeper ASF site. + + + + + + ZOOKEEPER-71 + + + + Determine what to do re ZooKeeper Changelog + + + + + + ZOOKEEPER-68 + + + + parseACLs in ZooKeeper.java fails to parse elements of ACL, should be lastIndexOf rather than IndexOf + + + + + + ZOOKEEPER-130 + + + + update build.xml to support apache release process. + + + + + + ZOOKEEPER-131 + + + + Fix Old leader election can elect a dead leader over and over again. + + + + + + ZOOKEEPER-137 + + + + client watcher objects can lose events + + + + + + ZOOKEEPER-117 + + + + threading issues in Leader election + + + + + + ZOOKEEPER-128 + + + + test coverage on async client operations needs to be improved + + + + + + ZOOKEEPER-127 + + + + Use of non-standard election ports in config breaks services + + + + + + ZOOKEEPER-53 + + + + tests failing on solaris. + + + + + + ZOOKEEPER-172 + + + + FLE Test + + + + + + ZOOKEEPER-41 + + + + Sample startup script + + + + + + ZOOKEEPER-33 + + + + Better ACL management + + + + + + ZOOKEEPER-49 + + + + SetACL does not work + + + + + + ZOOKEEPER-20 + + + + Child watches are not triggered when the node is deleted + + + + + + ZOOKEEPER-15 + + + + handle failure better in build.xml:test + + + + + + ZOOKEEPER-11 + + + + ArrayList is used instead of List + + + + + + ZOOKEEPER-45 + + + + Restructure the SVN repository after initial import + + + + + + ZOOKEEPER-1 + + + + Initial ZooKeeper code contribution from Yahoo! + + + + + +
      + +
      +
      + diff --git a/src/docs/src/documentation/content/xdocs/site.xml b/src/docs/src/documentation/content/xdocs/site.xml new file mode 100644 index 00000000000..4b429c7e7d7 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/site.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/docs/src/documentation/content/xdocs/tabs.xml b/src/docs/src/documentation/content/xdocs/tabs.xml new file mode 100644 index 00000000000..87c4c884276 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/tabs.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml b/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml new file mode 100644 index 00000000000..330ae96f618 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml @@ -0,0 +1,2434 @@ + + + +
      + ZooKeeper Administrator's Guide + + A Guide to Deployment and Administration + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This document contains information about deploying, administering + and mantaining ZooKeeper. It also discusses best practices and common + problems. + + + + +
      + Deployment + + This section contains information about deploying Zookeeper and + covers these topics: + + + + + + + + + + + + + + + + + + + + + + + The first two sections assume you are interested in installing + ZooKeeper in a production environment such as a datacenter. The final + section covers situations in which you are setting up ZooKeeper on a + limited basis - for evaluation, testing, or development - but not in a + production environment. + + +
      + System Requirements + +
      + Supported Platforms + + ZooKeeper consists of multiple components. Some components are + supported broadly, and other components are supported only on a smaller + set of platforms. + + + + + + Client + is the Java client + library, used by applications to connect to a ZooKeeper ensemble. + + + + + Server + is the Java server + that runs on the ZooKeeper ensemble nodes. + + + + + Native Client + is a client + implemented in C, similar to the Java client, used by applications + to connect to a ZooKeeper ensemble. + + + + + Contrib + refers to multiple + optional add-on components. + + + + + The following matrix describes the level of support committed for + running each component on different operating system platforms. + + + + Support Matrix + + + + Operating System + Client + Server + Native Client + Contrib + + + + + GNU/Linux + Development and Production + Development and Production + Development and Production + Development and Production + + + Solaris + Development and Production + Development and Production + Not Supported + Not Supported + + + FreeBSD + Development and Production + Development and Production + Not Supported + Not Supported + + + Windows + Development and Production + Development and Production + Not Supported + Not Supported + + + Mac OS X + Development Only + Development Only + Not Supported + Not Supported + + + +
      + + For any operating system not explicitly mentioned as supported in + the matrix, components may or may not work. The ZooKeeper community + will fix obvious bugs that are reported for other platforms, but there + is no full support. + +
      + +
      + Required Software + + ZooKeeper runs in Java, release 1.7 or greater (JDK 7 or + greater, FreeBSD support requires openjdk7). It runs as an + ensemble + of ZooKeeper servers. Three + ZooKeeper servers is the minimum recommended size for an + ensemble, and we also recommend that they run on separate + machines. At Yahoo!, ZooKeeper is usually deployed on + dedicated RHEL boxes, with dual-core processors, 2GB of RAM, + and 80GB IDE hard drives. + +
      + +
      + +
      + Clustered (Multi-Server) Setup + + For reliable ZooKeeper service, you should deploy ZooKeeper in a + cluster known as an ensemble. As long as a majority + of the ensemble are up, the service will be available. Because Zookeeper + requires a majority, it is best to use an + odd number of machines. For example, with four machines ZooKeeper can + only handle the failure of a single machine; if two machines fail, the + remaining two machines do not constitute a majority. However, with five + machines ZooKeeper can handle the failure of two machines. + + + Here are the steps to setting a server that will be part of an + ensemble. These steps should be performed on every host in the + ensemble: + + + + + Install the Java JDK. You can use the native packaging system + for your system, or download the JDK from: + + + + http://java.sun.com/javase/downloads/index.jsp + + + + + + Set the Java heap size. This is very important to avoid + swapping, which will seriously degrade ZooKeeper performance. To + determine the correct value, use load tests, and make sure you are + well below the usage limit that would cause you to swap. Be + conservative - use a maximum heap size of 3GB for a 4GB + machine. + + + + + Install the ZooKeeper Server Package. It can be downloaded + from: + + + + http://zookeeper.apache.org/releases.html + + + + + + Create a configuration file. This file can be called anything. + Use the following settings as a starting point: + + + + tickTime=2000 + dataDir=/var/lib/zookeeper/ + clientPort=2181 + initLimit=5 + syncLimit=2 + server.1=zoo1:2888:3888 + server.2=zoo2:2888:3888 + server.3=zoo3:2888:3888 + + + You can find the meanings of these and other configuration + settings in the section. A word + though about a few here: + + + Every machine that is part of the ZooKeeper ensemble should know + about every other machine in the ensemble. You accomplish this with + the series of lines of the form server.id=host:port:port. The parameters host + and port + are straightforward. You attribute the + server id to each machine by creating a file named + myid, one for each server, which resides in + that server's data directory, as specified by the configuration file + parameter dataDir. + + + + + The myid file + consists of a single line containing only the text of that machine's + id. So myid of server 1 would contain the text + "1" and nothing else. The id must be unique within the + ensemble and should have a value between 1 and 255. + + + + + If your configuration file is set up, you can start a + ZooKeeper server: + + + + $ java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.16.jar:conf \ + org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg + + + + QuorumPeerMain starts a ZooKeeper server, + JMX + management beans are also registered which allows + management through a JMX management console. + The ZooKeeper JMX + document + contains details on managing ZooKeeper with JMX. + + + See the script bin/zkServer.sh, + which is included in the release, for an example + of starting server instances. + + + + + + Test your deployment by connecting to the hosts: + + + + In Java, you can run the following command to execute + simple operations: + + + + $ java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.16.jar:conf:src/java/lib/jline-2.11.jar \ + org.apache.zookeeper.ZooKeeperMain -server 127.0.0.1:2181 + + + + + + In C, you can compile either the single threaded client or + the multithreaded client: or n the c subdirectory in the + ZooKeeper sources. This compiles the single threaded + client: + + + + $ make cli_st + + + And this compiles the mulithreaded client: + + + $ make cli_mt + + + + + Running either program gives you a shell in which to execute + simple file-system-like operations. To connect to ZooKeeper with the + multithreaded client, for example, you would run: + + + + $ cli_mt 127.0.0.1:2181 + + + +
      + +
      + Single Server and Developer Setup + + If you want to setup ZooKeeper for development purposes, you will + probably want to setup a single server instance of ZooKeeper, and then + install either the Java or C client-side libraries and bindings on your + development machine. + + + The steps to setting up a single server instance are the similar + to the above, except the configuration file is simpler. You can find the + complete instructions in the Installing and + Running ZooKeeper in Single Server Mode + section of the ZooKeeper Getting Started + Guide. + + + For information on installing the client side libraries, refer to + the + Bindings + section of the ZooKeeper + Programmer's Guide. + +
      +
      + +
      + Administration + + This section contains information about running and maintaining + ZooKeeper and covers these topics: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      + Designing a ZooKeeper Deployment + + The reliablity of ZooKeeper rests on two basic assumptions. + + + Only a minority of servers in a deployment + will fail. Failure in this context + means a machine crash, or some error in the network that + partitions a server off from the majority. + + + + Deployed machines operate correctly. To + operate correctly means to execute code correctly, to have + clocks that work properly, and to have storage and network + components that perform consistently. + + + + + The sections below contain considerations for ZooKeeper + administrators to maximize the probability for these assumptions + to hold true. Some of these are cross-machines considerations, + and others are things you should consider for each and every + machine in your deployment. + + +
      + Cross Machine Requirements + + For the ZooKeeper service to be active, there must be a + majority of non-failing machines that can communicate with + each other. To create a deployment that can tolerate the + failure of F machines, you should count on deploying 2xF+1 + machines. Thus, a deployment that consists of three machines + can handle one failure, and a deployment of five machines can + handle two failures. Note that a deployment of six machines + can only handle two failures since three machines is not a + majority. For this reason, ZooKeeper deployments are usually + made up of an odd number of machines. + + + To achieve the highest probability of tolerating a failure + you should try to make machine failures independent. For + example, if most of the machines share the same switch, + failure of that switch could cause a correlated failure and + bring down the service. The same holds true of shared power + circuits, cooling systems, etc. + +
      + +
      + Single Machine Requirements + + If ZooKeeper has to contend with other applications for + access to resources like storage media, CPU, network, or + memory, its performance will suffer markedly. ZooKeeper has + strong durability guarantees, which means it uses storage + media to log changes before the operation responsible for the + change is allowed to complete. You should be aware of this + dependency then, and take great care if you want to ensure + that ZooKeeper operations aren’t held up by your media. Here + are some things you can do to minimize that sort of + degradation: + + + + + ZooKeeper's transaction log must be on a dedicated + device. (A dedicated partition is not enough.) ZooKeeper + writes the log sequentially, without seeking Sharing your + log device with other processes can cause seeks and + contention, which in turn can cause multi-second + delays. + + + + + Do not put ZooKeeper in a situation that can cause a + swap. In order for ZooKeeper to function with any sort of + timeliness, it simply cannot be allowed to swap. + Therefore, make certain that the maximum heap size given + to ZooKeeper is not bigger than the amount of real memory + available to ZooKeeper. For more on this, see + + below. + + + +
      +
      + +
      + Provisioning + + +
      + +
      + Things to Consider: ZooKeeper Strengths and Limitations + + +
      + +
      + Administering + + +
      + +
      + Maintenance + + Little long term maintenance is required for a ZooKeeper + cluster however you must be aware of the following: + + +
      + Ongoing Data Directory Cleanup + + The ZooKeeper Data + Directory + contains files which are a persistent copy + of the znodes stored by a particular serving ensemble. These + are the snapshot and transactional log files. As changes are + made to the znodes these changes are appended to a + transaction log, occasionally, when a log grows large, a + snapshot of the current state of all znodes will be written + to the filesystem. This snapshot supercedes all previous + logs. + + + A ZooKeeper server will not remove + old snapshots and log files + when using the default + configuration (see autopurge below), this is the + responsibility of the operator. Every serving environment is + different and therefore the requirements of managing these + files may differ from install to install (backup for example). + + + The PurgeTxnLog utility implements a simple retention + policy that administrators can use. The API docs + contains details on + calling conventions (arguments, etc...). + + + In the following example the last count snapshots and + their corresponding logs are retained and the others are + deleted. The value of <count> should typically be + greater than 3 (although not required, this provides 3 backups + in the unlikely event a recent log has become corrupted). This + can be run as a cron job on the ZooKeeper server machines to + clean up the logs daily. + + + java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.16.jar:conf org.apache.zookeeper.server.PurgeTxnLog <dataDir> <snapDir> + -n <count> + + + Automatic purging of the snapshots and corresponding + transaction logs was introduced in version 3.4.0 and can be + enabled via the following configuration parameters autopurge.snapRetainCount + and autopurge.purgeInterval. For more on + this, see + + below. + +
      + +
      + Debug Log Cleanup (log4j) + + See the section on logging + in this document. It is + expected that you will setup a rolling file appender using the + in-built log4j feature. The sample configuration file in the + release tar's conf/log4j.properties provides an example of + this. + +
      + +
      + +
      + Supervision + + You will want to have a supervisory process that manages + each of your ZooKeeper server processes (JVM). The ZK server is + designed to be "fail fast" meaning that it will shutdown + (process exit) if an error occurs that it cannot recover + from. As a ZooKeeper serving cluster is highly reliable, this + means that while the server may go down the cluster as a whole + is still active and serving requests. Additionally, as the + cluster is "self healing" the failed server once restarted will + automatically rejoin the ensemble w/o any manual + interaction. + + + Having a supervisory process such as daemontools + or + SMF + + (other options for supervisory process are also available, it's + up to you which one you would like to use, these are just two + examples) managing your ZooKeeper server ensures that if the + process does exit abnormally it will automatically be restarted + and will quickly rejoin the cluster. + + + It is also recommended to configure the ZooKeeper server process to + terminate and dump its heap if an + OutOfMemoryError + occurs. This is achieved + by launching the JVM with the following arguments on Linux and Windows + respectively. The zkServer.sh and + zkServer.cmd + scripts that ship with ZooKeeper set + these options. + + + -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' + "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%%%p /t /f" +
      + +
      + Monitoring + + The ZooKeeper service can be monitored in one of two + primary ways; 1) the command port through the use of 4 letter words + and 2) JMX. See the appropriate section for + your environment/requirements. + +
      + +
      + Logging + + + ZooKeeper uses + + SLF4J + + version 1.7 as its logging infrastructure. For backward compatibility it is bound to + LOG4J + but you can use + + LOGBack + + or any other supported logging framework of your choice. + + + The ZooKeeper default + log4j.properties + file resides in the conf directory. Log4j requires that + log4j.properties + either be in the working directory + (the directory from which ZooKeeper is run) or be accessible from the classpath. + + + For more information about SLF4J, see + its manual. + + + For more information about LOG4J, see + Log4j Default Initialization Procedure + of the log4j manual. + + +
      + +
      + Troubleshooting + + + Server not coming up because of file corruption + + A server might not be able to read its database and fail to come up because of + some file corruption in the transaction logs of the ZooKeeper server. You will + see some IOException on loading ZooKeeper database. In such a case, + make sure all the other servers in your ensemble are up and working. Use "stat" + command on the command port to see if they are in good health. After you have verified that + all the other servers of the ensemble are up, you can go ahead and clean the database + of the corrupt server. Delete all the files in datadir/version-2 and datalogdir/version-2/. + Restart the server. + + + + +
      + +
      + Configuration Parameters + + ZooKeeper's behavior is governed by the ZooKeeper configuration + file. This file is designed so that the exact same file can be used by + all the servers that make up a ZooKeeper server assuming the disk + layouts are the same. If servers use different configuration files, care + must be taken to ensure that the list of servers in all of the different + configuration files match. + + + + In 3.5.0 and later, some of these parameters should be placed in + a dynamic configuration file. If they are placed in the static + configuration file, ZooKeeper will automatically move them over to the + dynamic configuration file. See + Dynamic Reconfiguration + for more information. + + + +
      + Minimum Configuration + + Here are the minimum configuration keywords that must be defined + in the configuration file: + + + + + clientPort + + + the port to listen for client connections; that is, the + port that clients attempt to connect to. + + + + + + secureClientPort + + + the port to listen on for secure client connections using SSL. + + clientPort + specifies + the port for plaintext connections while + secureClientPort + specifies the port for SSL + connections. Specifying both enables mixed-mode while omitting + either will disable that mode. + + Note that SSL feature will be enabled when user plugs-in + zookeeper.serverCnxnFactory, zookeeper.clientCnxnSocket as Netty. + + + + + + dataDir + + + the location where ZooKeeper will store the in-memory + database snapshots and, unless specified otherwise, the + transaction log of updates to the database. + + + + Be careful where you put the transaction log. A + dedicated transaction log device is key to consistent good + performance. Putting the log on a busy device will adversely + effect performance. + + + + + + + tickTime + + + the length of a single tick, which is the basic time unit + used by ZooKeeper, as measured in milliseconds. It is used to + regulate heartbeats, and timeouts. For example, the minimum + session timeout will be two ticks. + + + + +
      + +
      + Advanced Configuration + + The configuration settings in the section are optional. You can + use them to further fine tune the behaviour of your ZooKeeper servers. + Some can also be set using Java system properties, generally of the + form zookeeper.keyword. The exact system + property, when available, is noted below. + + + + + dataLogDir + + + (No Java system property) + + This option will direct the machine to write the + transaction log to the dataLogDir + rather than the dataDir. This allows a dedicated log + device to be used, and helps avoid competition between logging + and snaphots. + + + + Having a dedicated log device has a large impact on + throughput and stable latencies. It is highly recommened to + dedicate a log device and set dataLogDir + to point to a directory on + that device, and then make sure to point dataDir + to a directory + not + residing on that device. + + + + + + + globalOutstandingLimit + + + (Java system property: zookeeper.globalOutstandingLimit.) + + + Clients can submit requests faster than ZooKeeper can + process them, especially if there are a lot of clients. To + prevent ZooKeeper from running out of memory due to queued + requests, ZooKeeper will throttle clients so that there is no + more than globalOutstandingLimit outstanding requests in the + system. The default limit is 1,000. + + + + + + preAllocSize + + + (Java system property: zookeeper.preAllocSize) + + + To avoid seeks ZooKeeper allocates space in the + transaction log file in blocks of preAllocSize kilobytes. The + default block size is 64M. One reason for changing the size of + the blocks is to reduce the block size if snapshots are taken + more often. (Also, see snapCount). + + + + + + snapCount + + + (Java system property: zookeeper.snapCount) + + + ZooKeeper logs transactions to a transaction + log. After snapCount transactions are written to a log + file a snapshot is started and a new transaction log + file is created. The default snapCount is + 100,000. + + + + + + traceFile + + + (Java system property: requestTraceFile) + + + If this option is defined, requests will be will logged to + a trace file named traceFile.year.month.day. Use of this option + provides useful debugging information, but will impact + performance. (Note: The system property has no zookeeper prefix, + and the configuration variable name is different from the system + property. Yes - it's not consistent, and it's annoying.) + + + + + + maxClientCnxns + + (No Java system property) + + Limits the number of concurrent connections (at the socket + level) that a single client, identified by IP address, may make + to a single member of the ZooKeeper ensemble. This is used to + prevent certain classes of DoS attacks, including file + descriptor exhaustion. The default is 60. Setting this to 0 + entirely removes the limit on concurrent connections. + + + + + + clientPortAddress + + + + New in 3.3.0: + the + address (ipv4, ipv6 or hostname) to listen for client + connections; that is, the address that clients attempt + to connect to. This is optional, by default we bind in + such a way that any connection to the clientPort + for any + address/interface/nic on the server will be + accepted. + + + + + + minSessionTimeout + + (No Java system property) + + + New in 3.3.0: + the + minimum session timeout in milliseconds that the server + will allow the client to negotiate. Defaults to 2 times + the tickTime. + + + + + + maxSessionTimeout + + (No Java system property) + + + New in 3.3.0: + the + maximum session timeout in milliseconds that the server + will allow the client to negotiate. Defaults to 20 times + the tickTime. + + + + + + fsync.warningthresholdms + + (Java system property: fsync.warningthresholdms) + + + + New in 3.3.4: + A + warning message will be output to the log whenever an + fsync in the Transactional Log (WAL) takes longer than + this value. The values is specified in milliseconds and + defaults to 1000. This value can only be set as a + system property. + + + + + + autopurge.snapRetainCount + + + (No Java system property) + + + New in 3.4.0: + When enabled, ZooKeeper auto purge feature retains + the autopurge.snapRetainCount most + recent snapshots and the corresponding transaction logs in the + dataDir + and dataLogDir + respectively and deletes the rest. + Defaults to 3. Minimum value is 3. + + + + + + autopurge.purgeInterval + + + (No Java system property) + + + New in 3.4.0: + The + time interval in hours for which the purge task has to + be triggered. Set to a positive integer (1 and above) + to enable the auto purging. Defaults to 0. + + + + + + syncEnabled + + + (Java system property: zookeeper.observer.syncEnabled) + + + + New in 3.4.6, 3.5.0: + The observers now log transaction and write snapshot to disk + by default like the participants. This reduces the recovery time + of the observers on restart. Set to "false" to disable this + feature. Default is "true" + + + + +
      + +
      + Cluster Options + + The options in this section are designed for use with an ensemble + of servers -- that is, when deploying clusters of servers. + + + + + electionAlg + + + (No Java system property) + + Election implementation to use. A value of "0" corresponds + to the original UDP-based version, "1" corresponds to the + non-authenticated UDP-based version of fast leader election, "2" + corresponds to the authenticated UDP-based version of fast + leader election, and "3" corresponds to TCP-based version of + fast leader election. Currently, algorithm 3 is the default + + + + The implementations of leader election 0, 1, and 2 are now + deprecated. We have the intention + of removing them in the next release, at which point only the + FastLeaderElection will be available. + + + + + + + initLimit + + + (No Java system property) + + Amount of time, in ticks (see tickTime), to allow followers to + connect and sync to a leader. Increased this value as needed, if + the amount of data managed by ZooKeeper is large. + + + + + + leaderServes + + + (Java system property: zookeeper.leaderServes) + + + Leader accepts client connections. Default value is "yes". + The leader machine coordinates updates. For higher update + throughput at thes slight expense of read throughput the leader + can be configured to not accept clients and focus on + coordination. The default to this option is yes, which means + that a leader will accept client connections. + + + + Turning on leader selection is highly recommended when + you have more than three ZooKeeper servers in an ensemble. + + + + + + + server.x=[hostname]:nnnnn[:nnnnn], etc + + + (No Java system property) + + servers making up the ZooKeeper ensemble. When the server + starts up, it determines which server it is by looking for the + file myid in the data directory. That file + contains the server number, in ASCII, and it should match + x + in server.x + in the left hand side of this + setting. + + + The list of servers that make up ZooKeeper servers that is + used by the clients must match the list of ZooKeeper servers + that each ZooKeeper server has. + + + There are two port numbers nnnnn. + The first followers use to connect to the leader, and the second is for + leader election. The leader election port is only necessary if electionAlg + is 1, 2, or 3 (default). If electionAlg is 0, then the second port is not + necessary. If you want to test multiple servers on a single machine, then + different ports can be used for each server. + + + + + + syncLimit + + + (No Java system property) + + Amount of time, in ticks (see tickTime), to allow followers to sync + with ZooKeeper. If followers fall too far behind a leader, they + will be dropped. + + + + + + group.x=nnnnn[:nnnnn] + + + (No Java system property) + + Enables a hierarchical quorum construction."x" is a group identifier + and the numbers following the "=" sign correspond to server identifiers. + The left-hand side of the assignment is a colon-separated list of server + identifiers. Note that groups must be disjoint and the union of all groups + must be the ZooKeeper ensemble. + + + You will find an example + here + + + + + + weight.x=nnnnn + + + (No Java system property) + + Used along with "group", it assigns a weight to a server when + forming quorums. Such a value corresponds to the weight of a server + when voting. There are a few parts of ZooKeeper that require voting + such as leader election and the atomic broadcast protocol. By default + the weight of server is 1. If the configuration defines groups, but not + weights, then a value of 1 will be assigned to all servers. + + + You will find an example + here + + + + + + cnxTimeout + + + (Java system property: zookeeper.cnxTimeout) + + + Sets the timeout value for opening connections for leader election notifications. + Only applicable if you are using electionAlg 3. + + + + Default value is 5 seconds. + + + + + + standaloneEnabled + + + (No Java system property) + + + New in 3.5.0: + When set to false, a single server can be started in replicated + mode, a lone participant can run with observers, and a cluster + can reconfigure down to one node, and up from one node. The + default is true for backwards compatibility. It can be set + using QuorumPeerConfig's setStandaloneEnabled method or by + adding "standaloneEnabled=false" or "standaloneEnabled=true" + to a server's config file. + + + + + +
      + +
      + Encryption, Authentication, Authorization Options + + The options in this section allow control over + encryption/authentication/authorization performed by the service. + + + + + DigestAuthenticationProvider.superDigest + + + (Java system property: zookeeper.DigestAuthenticationProvider.superDigest) + + + By default this feature is + disabled + + + + + New in 3.2: + Enables a ZooKeeper ensemble administrator to access the + znode hierarchy as a "super" user. In particular no ACL + checking occurs for a user authenticated as + super. + + + org.apache.zookeeper.server.auth.DigestAuthenticationProvider + can be used to generate the superDigest, call it with + one parameter of "super:<password>". Provide the + generated "super:<data>" as the system property value + when starting each server of the ensemble. + + + When authenticating to a ZooKeeper server (from a + ZooKeeper client) pass a scheme of "digest" and authdata + of "super:<password>". Note that digest auth passes + the authdata in plaintext to the server, it would be + prudent to use this authentication method only on + localhost (not over the network) or over an encrypted + connection. + + + + + + X509AuthenticationProvider.superUser + + (Java system property: zookeeper.X509AuthenticationProvider.superUser) + + + The SSL-backed way to enable a ZooKeeper ensemble + administrator to access the znode hierarchy as a "super" user. + When this parameter is set to an X500 principal name, only an + authenticated client with that principal will be able to bypass + ACL checking and have full privileges to all znodes. + + + + + + ssl.keyStore.location and ssl.keyStore.password + + (Java system properties: + zookeeper.ssl.keyStore.location + and zookeeper.ssl.keyStore.password) + + + Specifies the file path to a JKS containing the local + credentials to be used for SSL connections, and the + password to unlock the file. + + + + + + ssl.trustStore.location and ssl.trustStore.password + + (Java system properties: + zookeeper.ssl.trustStore.location + and zookeeper.ssl.trustStore.password) + + + Specifies the file path to a JKS containing the remote + credentials to be used for SSL connections, and the + password to unlock the file. + + + + + + ssl.authProvider + + (Java system property: zookeeper.ssl.authProvider) + + + Specifies a subclass of + + org.apache.zookeeper.auth.X509AuthenticationProvider + + to use for secure client authentication. This is useful in + certificate key infrastructures that do not use JKS. It may be + necessary to extend javax.net.ssl.X509KeyManager + and + javax.net.ssl.X509TrustManager + to get the desired behavior from the SSL stack. To configure the + ZooKeeper server to use the custom provider for authentication, + choose a scheme name for the custom AuthenticationProvider and + set the property zookeeper.authProvider.[scheme] + to the fully-qualified class name of the custom + implementation. This will load the provider into the ProviderRegistry. + Then set this property + zookeeper.ssl.authProvider=[scheme] + and that provider + will be used for secure authentication. + + + + + + zookeeper.client.secure + + (Java system property only: zookeeper.client.secure) + + If you want to connect to server's secure client port, you need to + set this property to true on client. + This will connect to server using SSL with specified credentials. Note that + you also need to plug-in Netty client. + + + + + +
      + +
      + Experimental Options/Features + + New features that are currently considered experimental. + + + + Read Only Mode Server + + + (Java system property: readonlymode.enabled) + + + + New in 3.4.0: + Setting this value to true enables Read Only Mode server + support (disabled by default). ROM allows clients + sessions which requested ROM support to connect to the + server even when the server might be partitioned from + the quorum. In this mode ROM clients can still read + values from the ZK service, but will be unable to write + values and see changes from other clients. See + ZOOKEEPER-784 for more details. + + + + + +
      + +
      + Unsafe Options + + The following options can be useful, but be careful when you use + them. The risk of each is explained along with the explanation of what + the variable does. + + + + + forceSync + + + (Java system property: zookeeper.forceSync) + + + Requires updates to be synced to media of the transaction + log before finishing processing the update. If this option is + set to no, ZooKeeper will not require updates to be synced to + the media. + + + + + + jute.maxbuffer: + + + (Java system property: + jute.maxbuffer) + + + This option can only be set as a Java system property. + There is no zookeeper prefix on it. It specifies the maximum + size of the data that can be stored in a znode. The default is + 0xfffff, or just under 1M. If this option is changed, the system + property must be set on all servers and clients otherwise + problems will arise. This is really a sanity check. ZooKeeper is + designed to store data on the order of kilobytes in size. + + + + + + skipACL + + + (Java system property: zookeeper.skipACL) + + + Skips ACL checks. This results in a boost in throughput, + but opens up full access to the data tree to everyone. + + + + + + quorumListenOnAllIPs + + + When set to true the ZooKeeper server will listen + for connections from its peers on all available IP addresses, + and not only the address configured in the server list of the + configuration file. It affects the connections handling the + ZAB protocol and the Fast Leader Election protocol. Default + value is false. + + + + + +
      + +
      + Disabling data directory autocreation + + + New in 3.5: + The default + behavior of a ZooKeeper server is to automatically create the + data directory (specified in the configuration file) when + started if that directory does not already exist. This can be + inconvenient and even dangerous in some cases. Take the case + where a configuration change is made to a running server, + wherein the dataDir parameter + is accidentally changed. When the ZooKeeper server is + restarted it will create this non-existent directory and begin + serving - with an empty znode namespace. This scenario can + result in an effective "split brain" situation (i.e. data in + both the new invalid directory and the original valid data + store). As such is would be good to have an option to turn off + this autocreate behavior. In general for production + environments this should be done, unfortunately however the + default legacy behavior cannot be changed at this point and + therefore this must be done on a case by case basis. This is + left to users and to packagers of ZooKeeper distributions. + + + When running zkServer.sh + autocreate can be disabled + by setting the environment variable ZOO_DATADIR_AUTOCREATE_DISABLE + to 1. + When running ZooKeeper servers directly from class files this + can be accomplished by setting zookeeper.datadir.autocreate=false + on + the java command line, i.e. + -Dzookeeper.datadir.autocreate=false + + + + When this feature is disabled, and the ZooKeeper server + determines that the required directories do not exist it will + generate an error and refuse to start. + + + A new script zkServer-initialize.sh + is provided to + support this new feature. If autocreate is disabled it is + necessary for the user to first install ZooKeeper, then create + the data directory (and potentially txnlog directory), and + then start the server. Otherwise as mentioned in the previous + paragraph the server will not start. Running zkServer-initialize.sh + will create the + required directories, and optionally setup the myid file + (optional command line parameter). This script can be used + even if the autocreate feature itself is not used, and will + likely be of use to users as this (setup, including creation + of the myid file) has been an issue for users in the past. + Note that this script ensures the data directories exist only, + it does not create a config file, but rather requires a config + file to be available in order to execute. + +
      + +
      + Performance Tuning Options + + + New in 3.5.0: + Several subsystems have been reworked + to improve read throughput. This includes multi-threading of the NIO communication subsystem and + request processing pipeline (Commit Processor). NIO is the default client/server communication + subsystem. Its threading model comprises 1 acceptor thread, 1-N selector threads and 0-M + socket I/O worker threads. In the request processing pipeline the system can be configured + to process multiple read request at once while maintaining the same consistency guarantee + (same-session read-after-write). The Commit Processor threading model comprises 1 main + thread and 0-N worker threads. + + + + The default values are aimed at maximizing read throughput on a dedicated ZooKeeper machine. + Both subsystems need to have sufficient amount of threads to achieve peak read throughput. + + + + + + zookeeper.nio.numSelectorThreads + + (Java system property only: zookeeper.nio.numSelectorThreads) + + + New in 3.5.0: + Number of NIO selector threads. At least 1 selector thread required. + It is recommended to use more than one selector for large numbers + of client connections. The default value is sqrt( number of cpu cores / 2 ). + + + + + + zookeeper.nio.numWorkerThreads + + (Java system property only: zookeeper.nio.numWorkerThreads) + + + New in 3.5.0: + Number of NIO worker threads. If configured with 0 worker threads, the selector threads + do the socket I/O directly. The default value is 2 times the number of cpu cores. + + + + + + zookeeper.commitProcessor.numWorkerThreads + + (Java system property only: zookeeper.commitProcessor.numWorkerThreads) + + + New in 3.5.0: + Number of Commit Processor worker threads. If configured with 0 worker threads, the main thread + will process the request directly. The default value is the number of cpu cores. + + + + + + znode.container.checkIntervalMs + + + (Java system property only) + + + New in 3.6.0: + The + time interval in milliseconds for each check of candidate container + nodes. Default is "60000". + + + + + + znode.container.maxPerMinute + + + (Java system property only) + + + New in 3.6.0: + The + maximum number of container nodes that can be deleted per + minute. This prevents herding during container deletion. + Default is "10000". + + + + +
      + +
      + Communication using the Netty framework + + + Netty + is an NIO based client/server communication framework, it + simplifies (over NIO being used directly) many of the + complexities of network level communication for java + applications. Additionally the Netty framework has built + in support for encryption (SSL) and authentication + (certificates). These are optional features and can be + turned on or off individually. + + In versions 3.5+, a ZooKeeper server can use Netty + instead of NIO (default option) by setting the environment + variable + zookeeper.serverCnxnFactory + to org.apache.zookeeper.server.NettyServerCnxnFactory; + for the client, set + zookeeper.clientCnxnSocket + to org.apache.zookeeper.ClientCnxnSocketNetty. + + + + TBD - tuning options for netty - currently there are none that are netty specific but we should add some. Esp around max bound on the number of reader worker threads netty creates. + + + TBD - how to manage encryption + + + TBD - how to manage certificates + + +
      + +
      + AdminServer configuration + + New in 3.5.0: + The following + options are used to configure the AdminServer. + + + + + admin.enableServer + + + (Java system property: zookeeper.admin.enableServer) + + + Set to "false" to disable the AdminServer. By default the + AdminServer is enabled. + + + + + + admin.serverAddress + + + (Java system property: zookeeper.admin.serverAddress) + + + The address the embedded Jetty server listens on. Defaults to 0.0.0.0. + + + + + admin.serverPort + + + (Java system property: zookeeper.admin.serverPort) + + + The port the embedded Jetty server listens on. Defaults to 8080. + + + + + admin.commandURL + + + (Java system property: zookeeper.admin.commandURL) + + + The URL for listing and issuing commands relative to the + root URL. Defaults to "/commands". + + + + +
      + +
      + +
      + ZooKeeper Commands + +
      + The Four Letter Words + ZooKeeper responds to a small set of commands. Each command is + composed of four letters. You issue the commands to ZooKeeper via telnet + or nc, at the client port. + + + Three of the more interesting commands: "stat" gives some + general information about the server and connected clients, + while "srvr" and "cons" give extended details on server and + connections respectively. + + + + + conf + + + + New in 3.3.0: + Print + details about serving configuration. + + + + + + + cons + + + + New in 3.3.0: + List + full connection/session details for all clients connected + to this server. Includes information on numbers of packets + received/sent, session id, operation latencies, last + operation performed, etc... + + + + + + + crst + + + + New in 3.3.0: + Reset + connection/session statistics for all connections. + + + + + + dump + + + Lists the outstanding sessions and ephemeral nodes. This + only works on the leader. + + + + + + envi + + + Print details about serving environment + + + + + ruok + + + Tests if server is running in a non-error state. The server + will respond with imok if it is running. Otherwise it will not + respond at all. + + + A response of "imok" does not necessarily indicate that the + server has joined the quorum, just that the server process is active + and bound to the specified client port. Use "stat" for details on + state wrt quorum and client connection information. + + + + + + srst + + + Reset server statistics. + + + + + srvr + + + + New in 3.3.0: + Lists + full details for the server. + + + + + + stat + + + Lists brief details for the server and connected + clients. + + + + + + wchs + + + + New in 3.3.0: + Lists + brief information on watches for the server. + + + + + + wchc + + + + New in 3.3.0: + Lists + detailed information on watches for the server, by + session. This outputs a list of sessions(connections) + with associated watches (paths). Note, depending on the + number of watches this operation may be expensive (ie + impact server performance), use it carefully. + + + + + + dirs + + + + New in 3.5.1: + Shows the total size of snapshot and log files in bytes + + + + + + wchp + + + + New in 3.3.0: + Lists + detailed information on watches for the server, by path. + This outputs a list of paths (znodes) with associated + sessions. Note, depending on the number of watches this + operation may be expensive (ie impact server performance), + use it carefully. + + + + + + + mntr + + + + New in 3.4.0: + Outputs a list + of variables that could be used for monitoring the health of the cluster. + + + $ echo mntr | nc localhost 2185 + + zk_version 3.4.0 + zk_avg_latency 0 + zk_max_latency 0 + zk_min_latency 0 + zk_packets_received 70 + zk_packets_sent 69 + zk_outstanding_requests 0 + zk_server_state leader + zk_znode_count 4 + zk_watch_count 0 + zk_ephemerals_count 0 + zk_approximate_data_size 27 + zk_followers 4 - only exposed by the Leader + zk_synced_followers 4 - only exposed by the Leader + zk_pending_syncs 0 - only exposed by the Leader + zk_open_file_descriptor_count 23 - only available on Unix platforms + zk_max_file_descriptor_count 1024 - only available on Unix platforms + + + The output is compatible with java properties format and the content + may change over time (new keys added). Your scripts should expect changes. + + + ATTENTION: Some of the keys are platform specific and some of the keys are only exported by the Leader. + + The output contains multiple lines with the following format: + key \t value + + + + + isro + + + + New in 3.4.0: + Tests if + server is running in read-only mode. The server will respond with + "ro" if in read-only mode or "rw" if not in read-only mode. + + + + + + gtmk + + + Gets the current trace mask as a 64-bit signed long value in + decimal format. See stmk for an explanation of + the possible values. + + + + + + stmk + + + Sets the current trace mask. The trace mask is 64 bits, + where each bit enables or disables a specific category of trace + logging on the server. Log4J must be configured to enable + TRACE + level first in order to see trace logging + messages. The bits of the trace mask correspond to the following + trace logging categories. + + + + Trace Mask Bit Values + + + + 0b0000000000 + Unused, reserved for future use. + + + 0b0000000010 + Logs client requests, excluding ping + requests. + + + + 0b0000000100 + Unused, reserved for future use. + + + 0b0000001000 + Logs client ping requests. + + + 0b0000010000 + Logs packets received from the quorum peer that is + the current leader, excluding ping requests. + + + + 0b0000100000 + Logs addition, removal and validation of client + sessions. + + + + 0b0001000000 + Logs delivery of watch events to client + sessions. + + + + 0b0010000000 + Logs ping packets received from the quorum peer + that is the current leader. + + + + 0b0100000000 + Unused, reserved for future use. + + + 0b1000000000 + Unused, reserved for future use. + + + +
      + + All remaining bits in the 64-bit value are unused and + reserved for future use. Multiple trace logging categories are + specified by calculating the bitwise OR of the documented values. + The default trace mask is 0b0100110010. Thus, by default, trace + logging includes client requests, packets received from the + leader and sessions. + + + To set a different trace mask, send a request containing the + stmk + four-letter word followed by the trace + mask represented as a 64-bit signed long value. This example uses + the Perl pack function to construct a trace + mask that enables all trace logging categories described above and + convert it to a 64-bit signed long value with big-endian byte + order. The result is appended to stmk and sent + to the server using netcat. The server responds with the new + trace mask in decimal format. + + + $ perl -e "print 'stmk', pack('q>', 0b0011111010)" | nc localhost 2181 + 250 + +
      +
      +
      + + Here's an example of the + ruok + command: + + + $ echo ruok | nc 127.0.0.1 5111 + imok + + +
      +
      + The AdminServer + New in 3.5.0:The AdminServer is + an embedded Jetty server that provides an HTTP interface to the four + letter word commands. By default, the server is started on port 8080, + and commands are issued by going to the URL "/commands/[command name]", + e.g., http://localhost:8080/commands/stat. The command response is + returned as JSON. Unlike the original protocol, commands are not + restricted to four-letter names, and commands can have multiple names; + for instance, "stmk" can also be referred to as "set_trace_mask". To + view a list of all available commands, point a browser to the URL + /commands (e.g., http://localhost:8080/commands). See the + AdminServer configuration options + + for how to change the port and URLs. + + + The AdminServer is enabled by default, but can be disabled by either: + + + Setting the zookeeper.admin.enableServer system + property to false. + + + + Removing Jetty from the classpath. (This option is + useful if you would like to override ZooKeeper's jetty + dependency.) + + + + Note that the TCP four letter word interface is still available if + the AdminServer is disabled. + +
      +
      + +
      + Data File Management + + ZooKeeper stores its data in a data directory and its transaction + log in a transaction log directory. By default these two directories are + the same. The server can (and should) be configured to store the + transaction log files in a separate directory than the data files. + Throughput increases and latency decreases when transaction logs reside + on a dedicated log devices. + + +
      + The Data Directory + + This directory has two files in it: + + + + + myid + - contains a single integer in + human readable ASCII text that represents the server id. + + + + + + snapshot.<zxid> + - holds the fuzzy + snapshot of a data tree. + + + + + Each ZooKeeper server has a unique id. This id is used in two + places: the myid file and the configuration file. + The myid file identifies the server that + corresponds to the given data directory. The configuration file lists + the contact information for each server identified by its server id. + When a ZooKeeper server instance starts, it reads its id from the + myid + file and then, using that id, reads from the + configuration file, looking up the port on which it should + listen. + + + The snapshot files stored in the data + directory are fuzzy snapshots in the sense that during the time the + ZooKeeper server is taking the snapshot, updates are occurring to the + data tree. The suffix of the snapshot file names + is the zxid, the ZooKeeper transaction id, of the + last committed transaction at the start of the snapshot. Thus, the + snapshot includes a subset of the updates to the data tree that + occurred while the snapshot was in process. The snapshot, then, may + not correspond to any data tree that actually existed, and for this + reason we refer to it as a fuzzy snapshot. Still, ZooKeeper can + recover using this snapshot because it takes advantage of the + idempotent nature of its updates. By replaying the transaction log + against fuzzy snapshots ZooKeeper gets the state of the system at the + end of the log. + +
      + +
      + The Log Directory + + The Log Directory contains the ZooKeeper transaction logs. + Before any update takes place, ZooKeeper ensures that the transaction + that represents the update is written to non-volatile storage. A new + log file is started each time a snapshot is begun. The log file's + suffix is the first zxid written to that log. + +
      + +
      + File Management + + The format of snapshot and log files does not change between + standalone ZooKeeper servers and different configurations of + replicated ZooKeeper servers. Therefore, you can pull these files from + a running replicated ZooKeeper server to a development machine with a + stand-alone ZooKeeper server for trouble shooting. + + + Using older log and snapshot files, you can look at the previous + state of ZooKeeper servers and even restore that state. The + LogFormatter class allows an administrator to look at the transactions + in a log. + + + The ZooKeeper server creates snapshot and log files, but + never deletes them. The retention policy of the data and log + files is implemented outside of the ZooKeeper server. The + server itself only needs the latest complete fuzzy snapshot + and the log files from the start of that snapshot. See the + maintenance + section in + this document for more details on setting a retention policy + and maintenance of ZooKeeper storage. + + + The data stored in these files is not encrypted. In the case of + storing sensitive data in ZooKeeper, necessary measures need to be + taken to prevent unauthorized access. Such measures are external to + ZooKeeper (e.g., control access to the files) and depend on the + individual settings in which it is being deployed. + + +
      +
      + +
      + Things to Avoid + + Here are some common problems you can avoid by configuring + ZooKeeper correctly: + + + + + inconsistent lists of servers + + + The list of ZooKeeper servers used by the clients must match + the list of ZooKeeper servers that each ZooKeeper server has. + Things work okay if the client list is a subset of the real list, + but things will really act strange if clients have a list of + ZooKeeper servers that are in different ZooKeeper clusters. Also, + the server lists in each Zookeeper server configuration file + should be consistent with one another. + + + + + + incorrect placement of transasction log + + + The most performance critical part of ZooKeeper is the + transaction log. ZooKeeper syncs transactions to media before it + returns a response. A dedicated transaction log device is key to + consistent good performance. Putting the log on a busy device will + adversely effect performance. If you only have one storage device, + put trace files on NFS and increase the snapshotCount; it doesn't + eliminate the problem, but it should mitigate it. + + + + + + incorrect Java heap size + + + You should take special care to set your Java max heap size + correctly. In particular, you should not create a situation in + which ZooKeeper swaps to disk. The disk is death to ZooKeeper. + Everything is ordered, so if processing one request swaps the + disk, all other queued requests will probably do the same. the + disk. DON'T SWAP. + + + Be conservative in your estimates: if you have 4G of RAM, do + not set the Java max heap size to 6G or even 4G. For example, it + is more likely you would use a 3G heap for a 4G machine, as the + operating system and the cache also need memory. The best and only + recommend practice for estimating the heap size your system needs + is to run load tests, and then make sure you are well below the + usage limit that would cause the system to swap. + + + + +
      + +
      + Best Practices + + For best results, take note of the following list of good + Zookeeper practices: + + + + For multi-tennant installations see the + section + + detailing ZooKeeper "chroot" support, this can be very useful + when deploying many applications/services interfacing to a + single ZooKeeper cluster. + + +
      +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperHierarchicalQuorums.xml b/src/docs/src/documentation/content/xdocs/zookeeperHierarchicalQuorums.xml new file mode 100644 index 00000000000..e496b34ace6 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperHierarchicalQuorums.xml @@ -0,0 +1,77 @@ + + + + +
      + Introduction to hierarchical quorums + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This document contains information about hierarchical quorums. + + + + + This document gives an example of how to use hierarchical quorums. The basic idea is + very simple. First, we split servers into groups, and add a line for each group listing + the servers that form this group. Next we have to assign a weight to each server. + + + + The following example shows how to configure a system with three groups of three servers + each, and we assign a weight of 1 to each server: + + + + group.1=1:2:3 + group.2=4:5:6 + group.3=7:8:9 + + weight.1=1 + weight.2=1 + weight.3=1 + weight.4=1 + weight.5=1 + weight.6=1 + weight.7=1 + weight.8=1 + weight.9=1 + + + + When running the system, we are able to form a quorum once we have a majority of votes from + a majority of non-zero-weight groups. Groups that have zero weight are discarded and not + considered when forming quorums. Looking at the example, we are able to form a quorum once + we have votes from at least two servers from each of two different groups. + +
      \ No newline at end of file diff --git a/src/docs/src/documentation/content/xdocs/zookeeperInternals.xml b/src/docs/src/documentation/content/xdocs/zookeeperInternals.xml new file mode 100644 index 00000000000..1f82b39ce2f --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperInternals.xml @@ -0,0 +1,623 @@ + + + + +
      + ZooKeeper Internals + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This article contains topics which discuss the inner workings of + ZooKeeper. So far, that's logging and atomic broadcast. + + + + + +
      + Introduction + + This document contains information on the inner workings of ZooKeeper. + So far, it discusses these topics: + + + + + + + + + + + + + + + +
      + +
      + Atomic Broadcast + + + At the heart of ZooKeeper is an atomic messaging system that keeps all of the servers in sync. + + +
      + Guarantees, Properties, and Definitions + + The specific guarantees provided by the messaging system used by ZooKeeper are the following: + + + + + + + Reliable delivery + + + If a message, m, is delivered + by one server, it will be eventually delivered by all servers. + + + + + + + Total order + + + If a message is + delivered before message b by one server, a will be delivered before b by all + servers. If a and b are delivered messages, either a will be delivered before b + or b will be delivered before a. + + + + + + + Causal order + + + + + If a message b is sent after a message a has been delivered by the sender of b, + a must be ordered before b. If a sender sends c after sending b, c must be ordered after b. + + + + + + + + + The ZooKeeper messaging system also needs to be efficient, reliable, and easy to + implement and maintain. We make heavy use of messaging, so we need the system to + be able to handle thousands of requests per second. Although we can require at + least k+1 correct servers to send new messages, we must be able to recover from + correlated failures such as power outages. When we implemented the system we had + little time and few engineering resources, so we needed a protocol that is + accessible to engineers and is easy to implement. We found that our protocol + satisfied all of these goals. + + + + + Our protocol assumes that we can construct point-to-point FIFO channels between + the servers. While similar services usually assume message delivery that can + lose or reorder messages, our assumption of FIFO channels is very practical + given that we use TCP for communication. Specifically we rely on the following property of TCP: + + + + + + + Ordered delivery + + + Data is delivered in the same order it is sent and a message m is + delivered only after all messages sent before m have been delivered. + (The corollary to this is that if message m is lost all messages after m will be lost.) + + + + + + + No message after close + + + Once a FIFO channel is closed, no messages will be received from it. + + + + + + + FLP proved that consensus cannot be achieved in asynchronous distributed systems + if failures are possible. To ensure we achieve consensus in the presence of failures + we use timeouts. However, we rely on times for liveness not for correctness. So, + if timeouts stop working (clocks malfunction for example) the messaging system may + hang, but it will not violate its guarantees. + + + When describing the ZooKeeper messaging protocol we will talk of packets, + proposals, and messages: + + + + + Packet + + + a sequence of bytes sent through a FIFO channel + + + + + + Proposal + + + a unit of agreement. Proposals are agreed upon by exchanging packets + with a quorum of ZooKeeper servers. Most proposals contain messages, however the + NEW_LEADER proposal is an example of a proposal that does not correspond to a message. + + + + + + + Message + + + a sequence of bytes to be atomically broadcast to all ZooKeeper + servers. A message put into a proposal and agreed upon before it is delivered. + + + + + + + + As stated above, ZooKeeper guarantees a total order of messages, and it also + guarantees a total order of proposals. ZooKeeper exposes the total ordering using + a ZooKeeper transaction id (zxid). All proposals will be stamped with a zxid when + it is proposed and exactly reflects the total ordering. Proposals are sent to all + ZooKeeper servers and committed when a quorum of them acknowledge the proposal. + If a proposal contains a message, the message will be delivered when the proposal + is committed. Acknowledgement means the server has recorded the proposal to persistent storage. + Our quorums have the requirement that any pair of quorum must have at least one server + in common. We ensure this by requiring that all quorums have size (n/2+1) where + n is the number of servers that make up a ZooKeeper service. + + + + The zxid has two parts: the epoch and a counter. In our implementation the zxid + is a 64-bit number. We use the high order 32-bits for the epoch and the low order + 32-bits for the counter. Because it has two parts represent the zxid both as a + number and as a pair of integers, (epoch, count). The epoch number represents a + change in leadership. Each time a new leader comes into power it will have its + own epoch number. We have a simple algorithm to assign a unique zxid to a proposal: + the leader simply increments the zxid to obtain a unique zxid for each proposal. + Leadership activation will ensure that only one leader uses a given epoch, so our + simple algorithm guarantees that every proposal will have a unique id. + + + + + ZooKeeper messaging consists of two phases: + + + + + + Leader activation + + + In this phase a leader establishes the correct state of the system + and gets ready to start making proposals. + + + + + + + Active messaging + + + In this phase a leader accepts messages to propose and coordinates message delivery. + + + + + + ZooKeeper is a holistic protocol. We do not focus on individual proposals, rather + look at the stream of proposals as a whole. Our strict ordering allows us to do this + efficiently and greatly simplifies our protocol. Leadership activation embodies + this holistic concept. A leader becomes active only when a quorum of followers + (The leader counts as a follower as well. You can always vote for yourself ) has synced + up with the leader, they have the same state. This state consists of all of the + proposals that the leader believes have been committed and the proposal to follow + the leader, the NEW_LEADER proposal. (Hopefully you are thinking to + yourself, Does the set of proposals that the leader believes has been committed + included all the proposals that really have been committed? + The answer is yes. + Below, we make clear why.) + + +
      + +
      + + Leader Activation + + Leader activation includes leader election. We currently have two leader election + algorithms in ZooKeeper: LeaderElection and FastLeaderElection (AuthFastLeaderElection + is a variant of FastLeaderElection that uses UDP and allows servers to perform a simple + form of authentication to avoid IP spoofing). ZooKeeper messaging doesn't care about the + exact method of electing a leader has long as the following holds: + + + + + + The leader has seen the highest zxid of all the followers. + + + A quorum of servers have committed to following the leader. + + + + + + Of these two requirements only the first, the highest zxid amoung the followers + needs to hold for correct operation. The second requirement, a quorum of followers, + just needs to hold with high probability. We are going to recheck the second requirement, + so if a failure happens during or after the leader election and quorum is lost, + we will recover by abandoning leader activation and running another election. + + + + After leader election a single server will be designated as a leader and start + waiting for followers to connect. The rest of the servers will try to connect to + the leader. The leader will sync up with followers by sending any proposals they + are missing, or if a follower is missing too many proposals, it will send a full + snapshot of the state to the follower. + + + + There is a corner case in which a follower that has proposals, U, not seen + by a leader arrives. Proposals are seen in order, so the proposals of U will have a zxids + higher than zxids seen by the leader. The follower must have arrived after the + leader election, otherwise the follower would have been elected leader given that + it has seen a higher zxid. Since committed proposals must be seen by a quorum of + servers, and a quorum of servers that elected the leader did not see U, the proposals + of you have not been committed, so they can be discarded. When the follower connects + to the leader, the leader will tell the follower to discard U. + + + + A new leader establishes a zxid to start using for new proposals by getting the + epoch, e, of the highest zxid it has seen and setting the next zxid to use to be + (e+1, 0), fter the leader syncs with a follower, it will propose a NEW_LEADER + proposal. Once the NEW_LEADER proposal has been committed, the leader will activate + and start receiving and issuing proposals. + + + + It all sounds complicated but here are the basic rules of operation during leader + activation: + + + + + A follower will ACK the NEW_LEADER proposal after it has synced with the leader. + + + A follower will only ACK a NEW_LEADER proposal with a given zxid from a single server. + + + A new leader will COMMIT the NEW_LEADER proposal when a quorum of followers have ACKed it. + + + A follower will commit any state it received from the leader when the NEW_LEADER proposal is COMMIT. + + + A new leader will not accept new proposals until the NEW_LEADER proposal has been COMMITED. + + + + + If leader election terminates erroneously, we don't have a problem since the + NEW_LEADER proposal will not be committed since the leader will not have quorum. + When this happens, the leader and any remaining followers will timeout and go back + to leader election. + + +
      + +
      + Active Messaging + + Leader Activation does all the heavy lifting. Once the leader is coronated he can + start blasting out proposals. As long as he remains the leader no other leader can + emerge since no other leader will be able to get a quorum of followers. If a new + leader does emerge, + it means that the leader has lost quorum, and the new leader will clean up any + mess left over during her leadership activation. + + + ZooKeeper messaging operates similar to a classic two-phase commit. + + + + + + + + + All communication channels are FIFO, so everything is done in order. Specifically + the following operating constraints are observed: + + + + + + The leader sends proposals to all followers using + the same order. Moreover, this order follows the order in which requests have been + received. Because we use FIFO channels this means that followers also receive proposals in order. + + + + + Followers process messages in the order they are received. This + means that messages will be ACKed in order and the leader will receive ACKs from + followers in order, due to the FIFO channels. It also means that if message $m$ + has been written to non-volatile storage, all messages that were proposed before + $m$ have been written to non-volatile storage. + + + + + The leader will issue a COMMIT to all followers as soon as a + quorum of followers have ACKed a message. Since messages are ACKed in order, + COMMITs will be sent by the leader as received by the followers in order. + + + + + COMMITs are processed in order. Followers deliver a proposals + message when that proposal is committed. + + + + + +
      + +
      + Summary + So there you go. Why does it work? Specifically, why does a set of proposals + believed by a new leader always contain any proposal that has actually been committed? + First, all proposals have a unique zxid, so unlike other protocols, we never have + to worry about two different values being proposed for the same zxid; followers + (a leader is also a follower) see and record proposals in order; proposals are + committed in order; there is only one active leader at a time since followers only + follow a single leader at a time; a new leader has seen all committed proposals + from the previous epoch since it has seen the highest zxid from a quorum of servers; + any uncommited proposals from a previous epoch seen by a new leader will be committed + by that leader before it becomes active. + +
      + +
      + Comparisons + + Isn't this just Multi-Paxos? No, Multi-Paxos requires some way of assuring that + there is only a single coordinator. We do not count on such assurances. Instead + we use the leader activation to recover from leadership change or old leaders + believing they are still active. + + + + Isn't this just Paxos? Your active messaging phase looks just like phase 2 of Paxos? + Actually, to us active messaging looks just like 2 phase commit without the need to + handle aborts. Active messaging is different from both in the sense that it has + cross proposal ordering requirements. If we do not maintain strict FIFO ordering of + all packets, it all falls apart. Also, our leader activation phase is different from + both of them. In particular, our use of epochs allows us to skip blocks of uncommitted + proposals and to not worry about duplicate proposals for a given zxid. + + +
      + +
      + +
      + Quorums + + + Atomic broadcast and leader election use the notion of quorum to guarantee a consistent + view of the system. By default, ZooKeeper uses majority quorums, which means that every + voting that happens in one of these protocols requires a majority to vote on. One example is + acknowledging a leader proposal: the leader can only commit once it receives an + acknowledgement from a quorum of servers. + + + + If we extract the properties that we really need from our use of majorities, we have that we only + need to guarantee that groups of processes used to validate an operation by voting (e.g., acknowledging + a leader proposal) pairwise intersect in at least one server. Using majorities guarantees such a property. + However, there are other ways of constructing quorums different from majorities. For example, we can assign + weights to the votes of servers, and say that the votes of some servers are more important. To obtain a quorum, + we get enough votes so that the sum of weights of all votes is larger than half of the total sum of all weights. + + + + A different construction that uses weights and is useful in wide-area deployments (co-locations) is a hierarchical + one. With this construction, we split the servers into disjoint groups and assign weights to processes. To form + a quorum, we have to get a hold of enough servers from a majority of groups G, such that for each group g in G, + the sum of votes from g is larger than half of the sum of weights in g. Interestingly, this construction enables + smaller quorums. If we have, for example, 9 servers, we split them into 3 groups, and assign a weight of 1 to each + server, then we are able to form quorums of size 4. Note that two subsets of processes composed each of a majority + of servers from each of a majority of groups necessarily have a non-empty intersection. It is reasonable to expect + that a majority of co-locations will have a majority of servers available with high probability. + + + + With ZooKeeper, we provide a user with the ability of configuring servers to use majority quorums, weights, or a + hierarchy of groups. + +
      + +
      + + Logging + + Zookeeper uses + slf4j + as an abstraction layer for logging. + log4j + in version 1.2 is chosen as the final logging implementation for now. + For better embedding support, it is planned in the future to leave the decision of choosing the final logging implementation to the end user. + Therefore, always use the slf4j api to write log statements in the code, but configure log4j for how to log at runtime. + Note that slf4j has no FATAL level, former messages at FATAL level have been moved to ERROR level. + For information on configuring log4j for + ZooKeeper, see the Logging section + of the + ZooKeeper Administrator's Guide. + + + +
      + Developer Guidelines + + Please follow the + slf4j manual + when creating log statements within code. + Also read the + FAQ on performance + , when creating log statements. Patch reviewers will look for the following: + +
      + Logging at the Right Level + + There are several levels of logging in slf4j. + It's important to pick the right one. In order of higher to lower severity: + + + + ERROR level designates error events that might still allow the application to continue running. + + + WARN level designates potentially harmful situations. + + + INFO level designates informational messages that highlight the progress of the application at coarse-grained level. + + + DEBUG Level designates fine-grained informational events that are most useful to debug an application. + + + TRACE Level designates finer-grained informational events than the DEBUG. + + + + + ZooKeeper is typically run in production such that log messages of INFO level + severity and higher (more severe) are output to the log. + + + +
      + +
      + Use of Standard slf4j Idioms + + + Static Message Logging + + + LOG.debug("process completed successfully!"); + + + + However when creating parameterized messages are required, use formatting anchors. + + + + LOG.debug("got {} messages in {} minutes",new Object[]{count,time}); + + + + + Naming + + + + Loggers should be named after the class in which they are used. + + + + public class Foo { + private static final Logger LOG = LoggerFactory.getLogger(Foo.class); + .... + public Foo() { + LOG.info("constructing Foo"); + + + + Exception handling + + + try { + // code + } catch (XYZException e) { + // do this + LOG.error("Something bad happened", e); + // don't do this (generally) + // LOG.error(e); + // why? because "don't do" case hides the stack trace + + // continue process here as you need... recover or (re)throw + } + +
      +
      + +
      + +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperJMX.xml b/src/docs/src/documentation/content/xdocs/zookeeperJMX.xml new file mode 100644 index 00000000000..45b81b406fe --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperJMX.xml @@ -0,0 +1,267 @@ + + + + +
      + ZooKeeper JMX + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + ZooKeeper support for JMX + + + +
      + JMX + Apache ZooKeeper has extensive support for JMX, allowing you + to view and manage a ZooKeeper serving ensemble. + + + This document assumes that you have basic knowledge of + JMX. See + Sun JMX Technology + page to get started with JMX. + + + See the + JMX Management Guide + for details on setting up local and + remote management of VM instances. By default the included + zkServer.sh + supports only local management - + review the linked document to enable support for remote management + (beyond the scope of this document). + + +
      + +
      + Starting ZooKeeper with JMX enabled + + The class + org.apache.zookeeper.server.quorum.QuorumPeerMain + will start a JMX manageable ZooKeeper server. This class + registers the proper MBeans during initalization to support JMX + monitoring and management of the + instance. See bin/zkServer.sh for one + example of starting ZooKeeper using QuorumPeerMain. + +
      + +
      + Run a JMX console + + There are a number of JMX consoles available which can connect + to the running server. For this example we will use Sun's + jconsole. + + + The Java JDK ships with a simple JMX console + named + jconsole + which can be used to connect to ZooKeeper and inspect a running + server. Once you've started ZooKeeper using QuorumPeerMain + start jconsole, which typically resides in + JDK_HOME/bin/jconsole + + + When the "new connection" window is displayed either connect + to local process (if jconsole started on same host as Server) or + use the remote process connection. + + + By default the "overview" tab for the VM is displayed (this + is a great way to get insight into the VM btw). Select + the "MBeans" tab. + + + You should now see + org.apache.ZooKeeperService + on the left hand side. Expand this item and depending on how you've + started the server you will be able to monitor and manage various + service related features. + + + Also note that ZooKeeper will register log4j MBeans as + well. In the same section along the left hand side you will see + "log4j". Expand that to manage log4j through JMX. Of particular + interest is the ability to dynamically change the logging levels + used by editing the appender and root thresholds. Log4j MBean + registration can be disabled by passing + -Dzookeeper.jmx.log4j.disable=true + to the JVM + when starting ZooKeeper. + + +
      + +
      + ZooKeeper MBean Reference + + This table details JMX for a server participating in a + replicated ZooKeeper ensemble (ie not standalone). This is the + typical case for a production environment. + + + + MBeans, their names and description + + + + + MBean + MBean Object Name + Description + + + + + Quorum + ReplicatedServer_id<#> + Represents the Quorum, or Ensemble - parent of all + cluster members. Note that the object name includes the + "myid" of the server (name suffix) that your JMX agent has + connected to. + + + + LocalPeer|RemotePeer + replica.<#> + Represents a local or remote peer (ie server + participating in the ensemble). Note that the object name + includes the "myid" of the server (name suffix). + + + + LeaderElection + LeaderElection + Represents a ZooKeeper cluster leader election which is + in progress. Provides information about the election, such as + when it started. + + + + Leader + Leader + Indicates that the parent replica is the leader and + provides attributes/operations for that server. Note that + Leader is a subclass of ZooKeeperServer, so it provides + all of the information normally associated with a + ZooKeeperServer node. + + + + Follower + Follower + Indicates that the parent replica is a follower and + provides attributes/operations for that server. Note that + Follower is a subclass of ZooKeeperServer, so it provides + all of the information normally associated with a + ZooKeeperServer node. + + + + DataTree + InMemoryDataTree + Statistics on the in memory znode database, also + operations to access finer (and more computationally + intensive) statistics on the data (such as ephemeral + count). InMemoryDataTrees are children of ZooKeeperServer + nodes. + + + + ServerCnxn + <session_id> + Statistics on each client connection, also + operations on those connections (such as + termination). Note the object name is the session id of + the connection in hex form. + + + + +
      + + This table details JMX for a standalone server. Typically + standalone is only used in development situations. + + + + MBeans, their names and description + + + + + MBean + MBean Object Name + Description + + + + + ZooKeeperServer + StandaloneServer_port<#> + Statistics on the running server, also operations + to reset these attributes. Note that the object name + includes the client port of the server (name + suffix). + + + + DataTree + InMemoryDataTree + Statistics on the in memory znode database, also + operations to access finer (and more computationally + intensive) statistics on the data (such as ephemeral + count). + + + + ServerCnxn + <session_id> + Statistics on each client connection, also + operations on those connections (such as + termination). Note the object name is the session id of + the connection in hex form. + + + + +
      + +
      + +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperObservers.xml b/src/docs/src/documentation/content/xdocs/zookeeperObservers.xml new file mode 100644 index 00000000000..9ae03e4f0dd --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperObservers.xml @@ -0,0 +1,150 @@ + + + + +
      + ZooKeeper Observers + + + + Licensed under the Apache License, Version 2.0 (the "License"); you + may not use this file except in compliance with the License. You may + obtain a copy of the License + at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License. + + + + + This guide contains information about using non-voting servers, or + observers in your ZooKeeper ensembles. + + + + +
      + Observers: Scaling ZooKeeper Without Hurting Write Performance + + + Although ZooKeeper performs very well by having clients connect directly + to voting members of the ensemble, this architecture makes it hard to + scale out to huge numbers of clients. The problem is that as we add more + voting members, the write performance drops. This is due to the fact that + a write operation requires the agreement of (in general) at least half the + nodes in an ensemble and therefore the cost of a vote can increase + significantly as more voters are added. + + + We have introduced a new type of ZooKeeper node called + an Observer which helps address this problem and + further improves ZooKeeper's scalability. Observers are non-voting members + of an ensemble which only hear the results of votes, not the agreement + protocol that leads up to them. Other than this simple distinction, + Observers function exactly the same as Followers - clients may connect to + them and send read and write requests to them. Observers forward these + requests to the Leader like Followers do, but they then simply wait to + hear the result of the vote. Because of this, we can increase the number + of Observers as much as we like without harming the performance of votes. + + + Observers have other advantages. Because they do not vote, they are not a + critical part of the ZooKeeper ensemble. Therefore they can fail, or be + disconnected from the cluster, without harming the availability of the + ZooKeeper service. The benefit to the user is that Observers may connect + over less reliable network links than Followers. In fact, Observers may be + used to talk to a ZooKeeper server from another data center. Clients of + the Observer will see fast reads, as all reads are served locally, and + writes result in minimal network traffic as the number of messages + required in the absence of the vote protocol is smaller. + +
      +
      + How to use Observers + Setting up a ZooKeeper ensemble that uses Observers is very simple, + and requires just two changes to your config files. Firstly, in the config + file of every node that is to be an Observer, you must place this line: + + + peerType=observer + + + + This line tells ZooKeeper that the server is to be an Observer. Secondly, + in every server config file, you must add :observer to the server + definition line of each Observer. For example: + + + + server.1:localhost:2181:3181:observer + + + + This tells every other server that server.1 is an Observer, and that they + should not expect it to vote. This is all the configuration you need to do + to add an Observer to your ZooKeeper cluster. Now you can connect to it as + though it were an ordinary Follower. Try it out, by running: + + + bin/zkCli.sh -server localhost:2181 + + + where localhost:2181 is the hostname and port number of the Observer as + specified in every config file. You should see a command line prompt + through which you can issue commands like ls to query + the ZooKeeper service. + +
      + +
      + Example use cases + + Two example use cases for Observers are listed below. In fact, wherever + you wish to scale the number of clients of your ZooKeeper ensemble, or + where you wish to insulate the critical part of an ensemble from the load + of dealing with client requests, Observers are a good architectural + choice. + + + + As a datacenter bridge: Forming a ZK ensemble between two + datacenters is a problematic endeavour as the high variance in latency + between the datacenters could lead to false positive failure detection + and partitioning. However if the ensemble runs entirely in one + datacenter, and the second datacenter runs only Observers, partitions + aren't problematic as the ensemble remains connected. Clients of the + Observers may still see and issue proposals. + + + + As a link to a message bus: Some companies have expressed an + interest in using ZK as a component of a persistent reliable message + bus. Observers would give a natural integration point for this work: a + plug-in mechanism could be used to attach the stream of proposals an + Observer sees to a publish-subscribe system, again without loading the + core ensemble. + + + +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperOtherInfo.xml b/src/docs/src/documentation/content/xdocs/zookeeperOtherInfo.xml new file mode 100644 index 00000000000..449d339f98e --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperOtherInfo.xml @@ -0,0 +1,48 @@ + + + + +
      + ZooKeeper + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + currently empty + + + +
      + Other Info + currently empty +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperOver.xml b/src/docs/src/documentation/content/xdocs/zookeeperOver.xml new file mode 100644 index 00000000000..f511d43bd28 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperOver.xml @@ -0,0 +1,521 @@ + + + + +
      + ZooKeeper + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This document contains overview information about ZooKeeper. It + discusses design goals, key concepts, implementation, and + performance. + + + + +
      + ZooKeeper: A Distributed Coordination Service for Distributed + Applications + + + ZooKeeper is a distributed, open-source coordination service for + distributed applications. It exposes a simple set of primitives that + distributed applications can build upon to implement higher level services + for synchronization, configuration maintenance, and groups and naming. It + is designed to be easy to program to, and uses a data model styled after + the familiar directory tree structure of file systems. It runs in Java and + has bindings for both Java and C. + + + Coordination services are notoriously hard to get right. They are + especially prone to errors such as race conditions and deadlock. The + motivation behind ZooKeeper is to relieve distributed applications the + responsibility of implementing coordination services from scratch. + + +
      + Design Goals + + + ZooKeeper is simple. + ZooKeeper + allows distributed processes to coordinate with each other through a + shared hierarchal namespace which is organized similarly to a standard + file system. The name space consists of data registers - called znodes, + in ZooKeeper parlance - and these are similar to files and directories. + Unlike a typical file system, which is designed for storage, ZooKeeper + data is kept in-memory, which means ZooKeeper can achieve high + throughput and low latency numbers. + + + The ZooKeeper implementation puts a premium on high performance, + highly available, strictly ordered access. The performance aspects of + ZooKeeper means it can be used in large, distributed systems. The + reliability aspects keep it from being a single point of failure. The + strict ordering means that sophisticated synchronization primitives can + be implemented at the client. + + + + ZooKeeper is replicated. + Like the + distributed processes it coordinates, ZooKeeper itself is intended to be + replicated over a sets of hosts called an ensemble. + + +
      + ZooKeeper Service + + + + + + +
      + + The servers that make up the ZooKeeper service must all know about + each other. They maintain an in-memory image of state, along with a + transaction logs and snapshots in a persistent store. As long as a + majority of the servers are available, the ZooKeeper service will be + available. + + + Clients connect to a single ZooKeeper server. The client maintains + a TCP connection through which it sends requests, gets responses, gets + watch events, and sends heart beats. If the TCP connection to the server + breaks, the client will connect to a different server. + + + + ZooKeeper is ordered. + ZooKeeper + stamps each update with a number that reflects the order of all + ZooKeeper transactions. Subsequent operations can use the order to + implement higher-level abstractions, such as synchronization + primitives. + + + + ZooKeeper is fast. + It is + especially fast in "read-dominant" workloads. ZooKeeper applications run + on thousands of machines, and it performs best where reads are more + common than writes, at ratios of around 10:1. + +
      + +
      + Data model and the hierarchical namespace + + The name space provided by ZooKeeper is much like that of a + standard file system. A name is a sequence of path elements separated by + a slash (/). Every node in ZooKeeper's name space is identified by a + path. + + +
      + ZooKeeper's Hierarchical Namespace + + + + + + +
      +
      + +
      + Nodes and ephemeral nodes + + Unlike standard file systems, each node in a ZooKeeper + namespace can have data associated with it as well as children. It is + like having a file-system that allows a file to also be a directory. + (ZooKeeper was designed to store coordination data: status information, + configuration, location information, etc., so the data stored at each + node is usually small, in the byte to kilobyte range.) We use the term + znode + to make it clear that we are talking about + ZooKeeper data nodes. + + + Znodes maintain a stat structure that includes version numbers for + data changes, ACL changes, and timestamps, to allow cache validations + and coordinated updates. Each time a znode's data changes, the version + number increases. For instance, whenever a client retrieves data it also + receives the version of the data. + + + The data stored at each znode in a namespace is read and written + atomically. Reads get all the data bytes associated with a znode and a + write replaces all the data. Each node has an Access Control List (ACL) + that restricts who can do what. + + + ZooKeeper also has the notion of ephemeral nodes. These znodes + exists as long as the session that created the znode is active. When the + session ends the znode is deleted. Ephemeral nodes are useful when you + want to implement [tbd]. + +
      + +
      + Conditional updates and watches + + ZooKeeper supports the concept of watches. + Clients can set a watch on a znode. A watch will be triggered and + removed when the znode changes. When a watch is triggered, the client + receives a packet saying that the znode has changed. If the + connection between the client and one of the Zoo Keeper servers is + broken, the client will receive a local notification. These can be used + to [tbd]. + +
      + +
      + Guarantees + + ZooKeeper is very fast and very simple. Since its goal, though, is + to be a basis for the construction of more complicated services, such as + synchronization, it provides a set of guarantees. These are: + + + + + Sequential Consistency - Updates from a client will be applied + in the order that they were sent. + + + + + Atomicity - Updates either succeed or fail. No partial + results. + + + + + Single System Image - A client will see the same view of the + service regardless of the server that it connects to. + + + + + + + Reliability - Once an update has been applied, it will persist + from that time forward until a client overwrites the update. + + + + + + + Timeliness - The clients view of the system is guaranteed to + be up-to-date within a certain time bound. + + + + + For more information on these, and how they can be used, see + [tbd] + +
      + +
      + Simple API + + One of the design goals of ZooKeeper is provide a very simple + programming interface. As a result, it supports only these + operations: + + + + + create + + + creates a node at a location in the tree + + + + + delete + + + deletes a node + + + + + exists + + + tests if a node exists at a location + + + + + get data + + + reads the data from a node + + + + + set data + + + writes data to a node + + + + + get children + + + retrieves a list of children of a node + + + + + sync + + + waits for data to be propagated + + + + + For a more in-depth discussion on these, and how they can be used + to implement higher level operations, please refer to + [tbd] + +
      + +
      + Implementation + + + + shows the high-level components + of the ZooKeeper service. With the exception of the request processor, + each of + the servers that make up the ZooKeeper service replicates its own copy + of each of the components. + + +
      + ZooKeeper Components + + + + + + +
      + + The replicated database is an in-memory database containing the + entire data tree. Updates are logged to disk for recoverability, and + writes are serialized to disk before they are applied to the in-memory + database. + + + Every ZooKeeper server services clients. Clients connect to + exactly one server to submit irequests. Read requests are serviced from + the local replica of each server database. Requests that change the + state of the service, write requests, are processed by an agreement + protocol. + + + As part of the agreement protocol all write requests from clients + are forwarded to a single server, called the + leader. The rest of the ZooKeeper servers, called + followers, receive message proposals from the + leader and agree upon message delivery. The messaging layer takes care + of replacing leaders on failures and syncing followers with + leaders. + + + ZooKeeper uses a custom atomic messaging protocol. Since the + messaging layer is atomic, ZooKeeper can guarantee that the local + replicas never diverge. When the leader receives a write request, it + calculates what the state of the system is when the write is to be + applied and transforms this into a transaction that captures this new + state. + +
      + +
      + Uses + + The programming interface to ZooKeeper is deliberately simple. + With it, however, you can implement higher order operations, such as + synchronizations primitives, group membership, ownership, etc. Some + distributed applications have used it to: [tbd: add uses from + white paper and video presentation.] + For more information, see + [tbd] + +
      + +
      + Performance + + ZooKeeper is designed to be highly performant. But is it? The + results of the ZooKeeper's development team at Yahoo! Research indicate + that it is. (See.) It is especially high + performance in applications where reads outnumber writes, since writes + involve synchronizing the state of all servers. (Reads outnumbering + writes is typically the case for a coordination service.) + + +
      + ZooKeeper Throughput as the Read-Write Ratio Varies + + + + + + +
      + The figure + + is a throughput + graph of ZooKeeper release 3.2 running on servers with dual 2Ghz + Xeon and two SATA 15K RPM drives. One drive was used as a + dedicated ZooKeeper log device. The snapshots were written to + the OS drive. Write requests were 1K writes and the reads were + 1K reads. "Servers" indicate the size of the ZooKeeper + ensemble, the number of servers that make up the + service. Approximately 30 other servers were used to simulate + the clients. The ZooKeeper ensemble was configured such that + leaders do not allow connections from clients. + + + + In version 3.2 r/w performance improved by ~2x + compared to the previous + 3.1 release. + + + + Benchmarks also indicate that it is reliable, too. + + shows how a deployment responds to + various failures. The events marked in the figure are the + following: + + + + + Failure and recovery of a follower + + + + Failure and recovery of a different follower + + + + Failure of the leader + + + + Failure and recovery of two followers + + + + Failure of another leader + + +
      + +
      + Reliability + + To show the behavior of the system over time as + failures are injected we ran a ZooKeeper service made up of + 7 machines. We ran the same saturation benchmark as before, + but this time we kept the write percentage at a constant + 30%, which is a conservative ratio of our expected + workloads. + +
      + Reliability in the Presence of Errors + + + + + +
      + + The are a few important observations from this graph. First, if + followers fail and recover quickly, then ZooKeeper is able to sustain a + high throughput despite the failure. But maybe more importantly, the + leader election algorithm allows for the system to recover fast enough + to prevent throughput from dropping substantially. In our observations, + ZooKeeper takes less than 200ms to elect a new leader. Third, as + followers recover, ZooKeeper is able to raise throughput again once they + start processing requests. + +
      + +
      + The ZooKeeper Project + + ZooKeeper has been + + successfully used + + in many industrial applications. It is used at Yahoo! as the + coordination and failure recovery service for Yahoo! Message + Broker, which is a highly scalable publish-subscribe system + managing thousands of topics for replication and data + delivery. It is used by the Fetching Service for Yahoo! + crawler, where it also manages failure recovery. A number of + Yahoo! advertising systems also use ZooKeeper to implement + reliable services. + + + All users and developers are encouraged to join the + community and contribute their expertise. See the + + Zookeeper Project on Apache + + for more information. + +
      +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml b/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml new file mode 100644 index 00000000000..9d9d731d898 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml @@ -0,0 +1,2176 @@ + + + +
      + ZooKeeper Programmer's Guide + + Developing Distributed Applications that use ZooKeeper + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This guide contains detailed information about creating + distributed applications that use ZooKeeper. It discusses the basic + operations ZooKeeper supports, and how these can be used to build + higher-level abstractions. It contains solutions to common tasks, a + troubleshooting guide, and links to other information. + + + $Revision: 1.14 $ $Date: 2008/09/19 05:31:45 $ + + + +
      + Introduction + + This document is a guide for developers wishing to create + distributed applications that take advantage of ZooKeeper's coordination + services. It contains conceptual and practical information. + + + The first four sections of this guide present higher level + discussions of various ZooKeeper concepts. These are necessary both for an + understanding of how ZooKeeper works as well how to work with it. It does + not contain source code, but it does assume a familiarity with the + problems associated with distributed computing. The sections in this first + group are: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The next four sections provide practical programming + information. These are: + + + + + + + + + + + + + + + + + + + [tbd] + + + + + + + + + + + The book concludes with an appendix + containing links to other + useful, ZooKeeper-related information. + + + Most of information in this document is written to be accessible as + stand-alone reference material. However, before starting your first + ZooKeeper application, you should probably at least read the chaptes on + the ZooKeeper Data Model and ZooKeeper Basic Operations. Also, + the Simple Programmming + Example + + [tbd] is helpful for understanding the basic + structure of a ZooKeeper client application. + +
      + +
      + The ZooKeeper Data Model + + ZooKeeper has a hierarchal name space, much like a distributed file + system. The only difference is that each node in the namespace can have + data associated with it as well as children. It is like having a file + system that allows a file to also be a directory. Paths to nodes are + always expressed as canonical, absolute, slash-separated paths; there are + no relative reference. Any unicode character can be used in a path subject + to the following constraints: + + + + + The null character (\u0000) cannot be part of a path name. (This + causes problems with the C binding.) + + + + + The following characters can't be used because they don't + display well, or render in confusing ways: \u0001 - \u001F and \u007F + - \u009F. + + + + + The following characters are not allowed: \ud800 - uF8FF, + \uFFF0 - uFFFF. + + + + + The "." character can be used as part of another name, but "." + and ".." cannot alone be used to indicate a node along a path, + because ZooKeeper doesn't use relative paths. The following would be + invalid: "/a/b/./c" or "/a/b/../c". + + + + + The token "zookeeper" is reserved. + + + +
      + ZNodes + + Every node in a ZooKeeper tree is referred to as a + znode. Znodes maintain a stat structure that + includes version numbers for data changes, acl changes. The stat + structure also has timestamps. The version number, together with the + timestamp, allows ZooKeeper to validate the cache and to coordinate + updates. Each time a znode's data changes, the version number increases. + For instance, whenever a client retrieves data, it also receives the + version of the data. And when a client performs an update or a delete, + it must supply the version of the data of the znode it is changing. If + the version it supplies doesn't match the actual version of the data, + the update will fail. (This behavior can be overridden. For more + information see... ) + [tbd...] + + + + In distributed application engineering, the word + node + can refer to a generic host machine, a + server, a member of an ensemble, a client process, etc. In the ZooKeeper + documentation, znodes refer to the data nodes. + Servers + refer to machines that make up the + ZooKeeper service; quorum peers refer to the + servers that make up an ensemble; client refers to any host or process + which uses a ZooKeeper service. + + + + Znodes are the main enitity that a programmer access. They have + several characteristics that are worth mentioning here. + + +
      + Watches + + Clients can set watches on znodes. Changes to that znode trigger + the watch and then clear the watch. When a watch triggers, ZooKeeper + sends the client a notification. More information about watches can be + found in the section + ZooKeeper Watches. + +
      + +
      + Data Access + + The data stored at each znode in a namespace is read and written + atomically. Reads get all the data bytes associated with a znode and a + write replaces all the data. Each node has an Access Control List + (ACL) that restricts who can do what. + + + ZooKeeper was not designed to be a general database or large + object store. Instead, it manages coordination data. This data can + come in the form of configuration, status information, rendezvous, etc. + A common property of the various forms of coordination data is that + they are relatively small: measured in kilobytes. + The ZooKeeper client and the server implementations have sanity checks + to ensure that znodes have less than 1M of data, but the data should + be much less than that on average. Operating on relatively large data + sizes will cause some operations to take much more time than others and + will affect the latencies of some operations because of the extra time + needed to move more data over the network and onto storage media. If + large data storage is needed, the usually pattern of dealing with such + data is to store it on a bulk storage system, such as NFS or HDFS, and + store pointers to the storage locations in ZooKeeper. + +
      + +
      + Ephemeral Nodes + + ZooKeeper also has the notion of ephemeral nodes. These znodes + exists as long as the session that created the znode is active. When + the session ends the znode is deleted. Because of this behavior + ephemeral znodes are not allowed to have children. + +
      + +
      + Sequence Nodes -- Unique Naming + + When creating a znode you can also request that + ZooKeeper append a monotonically increasing counter to the end + of path. This counter is unique to the parent znode. The + counter has a format of %010d -- that is 10 digits with 0 + (zero) padding (the counter is formatted in this way to + simplify sorting), i.e. "<path>0000000001". See + Queue + Recipe + + for an example use of this feature. Note: the + counter used to store the next sequence number is a signed int + (4bytes) maintained by the parent node, the counter will + overflow when incremented beyond 2147483647 (resulting in a + name "<path>-2147483647"). + +
      + +
      + Container Nodes + + + Added in 3.6.0 + + + ZooKeeper has the notion of container nodes. Container nodes are + special purpose nodes useful for recipes such as leader, lock, etc. + When the last child of a container is deleted, the container becomes + a candidate to be deleted by the server at some point in the future. + + + Given this property, you should be prepared to get + KeeperException.NoNodeException when creating children inside of + container nodes. i.e. when creating child nodes inside of container nodes + always check for KeeperException.NoNodeException and recreate the container + node when it occurs. + +
      +
      + +
      + Time in ZooKeeper + + ZooKeeper tracks time multiple ways: + + + + + Zxid + + + Every change to the ZooKeeper state receives a stamp in the + form of a zxid (ZooKeeper Transaction Id). + This exposes the total ordering of all changes to ZooKeeper. Each + change will have a unique zxid and if zxid1 is smaller than zxid2 + then zxid1 happened before zxid2. + + + + + + Version numbers + + + Every change to a node will cause an increase to one of the + version numbers of that node. The three version numbers are version + (number of changes to the data of a znode), cversion (number of + changes to the children of a znode), and aversion (number of changes + to the ACL of a znode). + + + + + + Ticks + + + When using multi-server ZooKeeper, servers use ticks to define + timing of events such as status uploads, session timeouts, + connection timeouts between peers, etc. The tick time is only + indirectly exposed through the minimum session timeout (2 times the + tick time); if a client requests a session timeout less than the + minimum session timeout, the server will tell the client that the + session timeout is actually the minimum session timeout. + + + + + + Real time + + + ZooKeeper doesn't use real time, or clock time, at all except + to put timestamps into the stat structure on znode creation and + znode modification. + + + +
      + +
      + ZooKeeper Stat Structure + + The Stat structure for each znode in ZooKeeper is made up of the + following fields: + + + + + + czxid + + + The zxid of the change that caused this znode to be + created. + + + + + + mzxid + + + The zxid of the change that last modified this znode. + + + + + pzxid + + + The zxid of the change that last modified children of this znode. + + + + + ctime + + + The time in milliseconds from epoch when this znode was + created. + + + + + + mtime + + + The time in milliseconds from epoch when this znode was last + modified. + + + + + + version + + + The number of changes to the data of this znode. + + + + + cversion + + + The number of changes to the children of this znode. + + + + + aversion + + + The number of changes to the ACL of this znode. + + + + + ephemeralOwner + + + The session id of the owner of this znode if the znode is an + ephemeral node. If it is not an ephemeral node, it will be + zero. + + + + + + dataLength + + + The length of the data field of this znode. + + + + + numChildren + + + The number of children of this znode. + + + +
      +
      + +
      + ZooKeeper Sessions + + A ZooKeeper client establishes a session with the ZooKeeper + service by creating a handle to the service using a language + binding. Once created, the handle starts of in the CONNECTING state + and the client library tries to connect to one of the servers that + make up the ZooKeeper service at which point it switches to the + CONNECTED state. During normal operation will be in one of these + two states. If an unrecoverable error occurs, such as session + expiration or authentication failure, or if the application explicitly + closes the handle, the handle will move to the CLOSED state. + The following figure shows the possible state transitions of a + ZooKeeper client: + + + + + + + + + To create a client session the application code must provide + a connection string containing a comma separated list of host:port pairs, + each corresponding to a ZooKeeper server (e.g. "127.0.0.1:4545" or + "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"). The ZooKeeper + client library will pick an arbitrary server and try to connect to + it. If this connection fails, or if the client becomes + disconnected from the server for any reason, the client will + automatically try the next server in the list, until a connection + is (re-)established. + + + Added in 3.2.0: An + optional "chroot" suffix may also be appended to the connection + string. This will run the client commands while interpreting all + paths relative to this root (similar to the unix chroot + command). If used the example would look like: + "127.0.0.1:4545/app/a" or + "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" where the + client would be rooted at "/app/a" and all paths would be relative + to this root - ie getting/setting/etc... "/foo/bar" would result + in operations being run on "/app/a/foo/bar" (from the server + perspective). This feature is particularly useful in multi-tenant + environments where each user of a particular ZooKeeper service + could be rooted differently. This makes re-use much simpler as + each user can code his/her application as if it were rooted at + "/", while actual location (say /app/a) could be determined at + deployment time. + + + When a client gets a handle to the ZooKeeper service, + ZooKeeper creates a ZooKeeper session, represented as a 64-bit + number, that it assigns to the client. If the client connects to a + different ZooKeeper server, it will send the session id as a part + of the connection handshake. As a security measure, the server + creates a password for the session id that any ZooKeeper server + can validate.The password is sent to the client with the session + id when the client establishes the session. The client sends this + password with the session id whenever it reestablishes the session + with a new server. + + + One of the parameters to the ZooKeeper client library call + to create a ZooKeeper session is the session timeout in + milliseconds. The client sends a requested timeout, the server + responds with the timeout that it can give the client. The current + implementation requires that the timeout be a minimum of 2 times + the tickTime (as set in the server configuration) and a maximum of + 20 times the tickTime. The ZooKeeper client API allows access to + the negotiated timeout. + + + When a client (session) becomes partitioned from the ZK + serving cluster it will begin searching the list of servers that + were specified during session creation. Eventually, when + connectivity between the client and at least one of the servers is + re-established, the session will either again transition to the + "connected" state (if reconnected within the session timeout + value) or it will transition to the "expired" state (if + reconnected after the session timeout). It is not advisable to + create a new session object (a new ZooKeeper.class or zookeeper + handle in the c binding) for disconnection. The ZK client library + will handle reconnect for you. In particular we have heuristics + built into the client library to handle things like "herd effect", + etc... Only create a new session when you are notified of session + expiration (mandatory). + + + Session expiration is managed by the ZooKeeper cluster + itself, not by the client. When the ZK client establishes a + session with the cluster it provides a "timeout" value detailed + above. This value is used by the cluster to determine when the + client's session expires. Expirations happens when the cluster + does not hear from the client within the specified session timeout + period (i.e. no heartbeat). At session expiration the cluster will + delete any/all ephemeral nodes owned by that session and + immediately notify any/all connected clients of the change (anyone + watching those znodes). At this point the client of the expired + session is still disconnected from the cluster, it will not be + notified of the session expiration until/unless it is able to + re-establish a connection to the cluster. The client will stay in + disconnected state until the TCP connection is re-established with + the cluster, at which point the watcher of the expired session + will receive the "session expired" notification. + + + Example state transitions for an expired session as seen by + the expired session's watcher: + + + + + 'connected' : session is established and client + is communicating with cluster (client/server communication is + operating properly) + + + + .... client is partitioned from the + cluster + + + + 'disconnected' : client has lost connectivity + with the cluster + + + + .... time elapses, after 'timeout' period the + cluster expires the session, nothing is seen by client as it is + disconnected from cluster + + + + .... time elapses, the client regains network + level connectivity with the cluster + + + + 'expired' : eventually the client reconnects to + the cluster, it is then notified of the + expiration + + + + + Another parameter to the ZooKeeper session establishment + call is the default watcher. Watchers are notified when any state + change occurs in the client. For example if the client loses + connectivity to the server the client will be notified, or if the + client's session expires, etc... This watcher should consider the + initial state to be disconnected (i.e. before any state changes + events are sent to the watcher by the client lib). In the case of + a new connection, the first event sent to the watcher is typically + the session connection event. + + + The session is kept alive by requests sent by the client. If + the session is idle for a period of time that would timeout the + session, the client will send a PING request to keep the session + alive. This PING request not only allows the ZooKeeper server to + know that the client is still active, but it also allows the + client to verify that its connection to the ZooKeeper server is + still active. The timing of the PING is conservative enough to + ensure reasonable time to detect a dead connection and reconnect + to a new server. + + + + Once a connection to the server is successfully established + (connected) there are basically two cases where the client lib generates + connectionloss (the result code in c binding, exception in Java -- see + the API documentation for binding specific details) when either a synchronous or + asynchronous operation is performed and one of the following holds: + + + + + The application calls an operation on a session that is no + longer alive/valid + + + + The ZooKeeper client disconnects from a server when there + are pending operations to that server, i.e., there is a pending asynchronous call. + + + + + Added in 3.2.0 -- SessionMovedException. There is an internal + exception that is generally not seen by clients called the SessionMovedException. + This exception occurs because a request was received on a connection for a session + which has been reestablished on a different server. The normal cause of this error is + a client that sends a request to a server, but the network packet gets delayed, so + the client times out and connects to a new server. When the delayed packet arrives at + the first server, the old server detects that the session has moved, and closes the + client connection. Clients normally do not see this error since they do not read + from those old connections. (Old connections are usually closed.) One situation in which this + condition can be seen is when two clients try to reestablish the same connection using + a saved session id and password. One of the clients will reestablish the connection + and the second client will be disconnected (causing the pair to attempt to re-establish + its connection/session indefinitely). + + + Updating the list of servers. We allow a client to + update the connection string by providing a new comma separated list of host:port pairs, + each corresponding to a ZooKeeper server. The function invokes a probabilistic load-balancing + algorithm which may cause the client to disconnect from its current host with the goal + to achieve expected uniform number of connections per server in the new list. + In case the current host to which the client is connected is not in the new list + this call will always cause the connection to be dropped. Otherwise, the decision + is based on whether the number of servers has increased or decreased and by how much. + + + + For example, if the previous connection string contained 3 hosts and now the list contains + these 3 hosts and 2 more hosts, 40% of clients connected to each of the 3 hosts will + move to one of the new hosts in order to balance the load. The algorithm will cause the client + to drop its connection to the current host to which it is connected with probability 0.4 and in this + case cause the client to connect to one of the 2 new hosts, chosen at random. + + + + Another example -- suppose we have 5 hosts and now update the list to remove 2 of the hosts, + the clients connected to the 3 remaining hosts will stay connected, whereas all clients connected + to the 2 removed hosts will need to move to one of the 3 hosts, chosen at random. If the connection + is dropped, the client moves to a special mode where he chooses a new server to connect to using the + probabilistic algorithm, and not just round robin. + + + + In the first example, each client decides to disconnect with probability 0.4 but once the decision is + made, it will try to connect to a random new server and only if it cannot connect to any of the new + servers will it try to connect to the old ones. After finding a server, or trying all servers in the + new list and failing to connect, the client moves back to the normal mode of operation where it picks + an arbitrary server from the connectString and attempt to connect to it. If that fails, is will continue + trying different random servers in round robin. (see above the algorithm used to initially choose a server) + + +
      + +
      + ZooKeeper Watches + + All of the read operations in ZooKeeper - getData(), getChildren(), and exists() + - have the option of setting a watch as a + side effect. Here is ZooKeeper's definition of a watch: a watch event is + one-time trigger, sent to the client that set the watch, which occurs when + the data for which the watch was set changes. There are three key points + to consider in this definition of a watch: + + + + + + One-time trigger + + + One watch event will be sent to the client when the data has changed. + For example, if a client does a getData("/znode1", true) and later the + data for /znode1 is changed or deleted, the client will get a watch + event for /znode1. If /znode1 changes again, no watch event will be + sent unless the client has done another read that sets a new + watch. + + + + + + Sent to the client + + + This implies that an event is on the way to the client, but may + not reach the client before the successful return code to the change + operation reaches the client that initiated the change. Watches are + sent asynchronously to watchers. ZooKeeper provides an ordering + guarantee: a client will never see a change for which it has set a + watch until it first sees the watch event. Network delays or other + factors may cause different clients to see watches and return codes + from updates at different times. The key point is that everything seen + by the different clients will have a consistent order. + + + + + + The data for which the watch was + set + + + + This refers to the different ways a node can change. It + helps to think of ZooKeeper as maintaining two lists of + watches: data watches and child watches. getData() and + exists() set data watches. getChildren() sets child + watches. Alternatively, it may help to think of watches being + set according to the kind of data returned. getData() and + exists() return information about the data of the node, + whereas getChildren() returns a list of children. Thus, + setData() will trigger data watches for the znode being set + (assuming the set is successful). A successful create() will + trigger a data watch for the znode being created and a child + watch for the parent znode. A successful delete() will trigger + both a data watch and a child watch (since there can be no + more children) for a znode being deleted as well as a child + watch for the parent znode. + + + + + Watches are maintained locally at the ZooKeeper server to which the + client is connected. This allows watches to be lightweight to set, + maintain, and dispatch. When a client connects to a new server, the watch + will be triggered for any session events. Watches will not be received + while disconnected from a server. When a client reconnects, any previously + registered watches will be reregistered and triggered if needed. In + general this all occurs transparently. There is one case where a watch + may be missed: a watch for the existence of a znode not yet created will + be missed if the znode is created and deleted while disconnected. + + +
      + Semantics of Watches + + We can set watches with the three calls that read the state of + ZooKeeper: exists, getData, and getChildren. The following list details + the events that a watch can trigger and the calls that enable them: + + + + + + Created event: + + Enabled with a call to exists. + + + + + Deleted event: + + Enabled with a call to exists, getData, and getChildren. + + + + + Changed event: + + Enabled with a call to exists and getData. + + + + + Child event: + + Enabled with a call to getChildren. + + +
      + +
      + Remove Watches + We can remove the watches registered on a znode with a call to + removeWatches. Also, a ZooKeeper client can remove watches locally even + if there is no server connection by setting the local flag to true. The + following list details the events which will be triggered after the + successful watch removal. + + + + + Child Remove event: + + Watcher which was added with a call to getChildren. + + + + + Data Remove event: + + Watcher which was added with a call to exists or getData. + + +
      + +
      + What ZooKeeper Guarantees about Watches + + With regard to watches, ZooKeeper maintains these + guarantees: + + + + + Watches are ordered with respect to other events, other + watches, and asynchronous replies. The ZooKeeper client libraries + ensures that everything is dispatched in order. + + + + + + + A client will see a watch event for a znode it is watching + before seeing the new data that corresponds to that znode. + + + + + + + The order of watch events from ZooKeeper corresponds to the + order of the updates as seen by the ZooKeeper service. + + + +
      + +
      + Things to Remember about Watches + + + + Watches are one time triggers; if you get a watch event and + you want to get notified of future changes, you must set another + watch. + + + + + + + Because watches are one time triggers and there is latency + between getting the event and sending a new request to get a watch + you cannot reliably see every change that happens to a node in + ZooKeeper. Be prepared to handle the case where the znode changes + multiple times between getting the event and setting the watch + again. (You may not care, but at least realize it may + happen.) + + + + + + + A watch object, or function/context pair, will only be + triggered once for a given notification. For example, if the same + watch object is registered for an exists and a getData call for the + same file and that file is then deleted, the watch object would + only be invoked once with the deletion notification for the file. + + + + + + + When you disconnect from a server (for example, when the + server fails), you will not get any watches until the connection + is reestablished. For this reason session events are sent to all + outstanding watch handlers. Use session events to go into a safe + mode: you will not be receiving events while disconnected, so your + process should act conservatively in that mode. + + + +
      +
      + +
      + ZooKeeper access control using ACLs + + ZooKeeper uses ACLs to control access to its znodes (the + data nodes of a ZooKeeper data tree). The ACL implementation is + quite similar to UNIX file access permissions: it employs + permission bits to allow/disallow various operations against a + node and the scope to which the bits apply. Unlike standard UNIX + permissions, a ZooKeeper node is not limited by the three standard + scopes for user (owner of the file), group, and world + (other). ZooKeeper does not have a notion of an owner of a + znode. Instead, an ACL specifies sets of ids and permissions that + are associated with those ids. + + + Note also that an ACL pertains only to a specific znode. In + particular it does not apply to children. For example, if + /app + is only readable by ip:172.16.16.1 and + /app/status + is world readable, anyone will + be able to read /app/status; ACLs are not + recursive. + + + ZooKeeper supports pluggable authentication schemes. Ids are + specified using the form scheme:id, + where scheme is a the authentication scheme + that the id corresponds to. For + example, ip:172.16.16.1 is an id for a + host with the address 172.16.16.1. + + + When a client connects to ZooKeeper and authenticates + itself, ZooKeeper associates all the ids that correspond to a + client with the clients connection. These ids are checked against + the ACLs of znodes when a clients tries to access a node. ACLs are + made up of pairs of (scheme:expression, + perms). The format of + the expression is specific to the scheme. For + example, the pair + (ip:19.22.0.0/16, READ) + gives the READ permission to any clients with + an IP address that starts with 19.22. + + +
      + ACL Permissions + + ZooKeeper supports the following permissions: + + + + CREATE: you can create a child node + + + + READ: you can get data from a node and list its children. + + + + WRITE: you can set data for a node + + + + DELETE: you can delete a child node + + + + ADMIN: you can set permissions + + + + + The + CREATE + and DELETE permissions have been broken out + of the WRITE permission for finer grained + access controls. The cases for + CREATE + and DELETE are the following: + + + You want A to be able to do a set on a ZooKeeper node, but + not be able to + CREATE + or DELETE children. + + + + CREATE + without DELETE: clients create requests by + creating ZooKeeper nodes in a parent directory. You want all + clients to be able to add, but only request processor can + delete. (This is kind of like the APPEND permission for + files.) + + + Also, the ADMIN permission is there + since ZooKeeper doesn’t have a notion of file owner. In some + sense the ADMIN permission designates the + entity as the owner. ZooKeeper doesn’t support the LOOKUP + permission (execute permission bit on directories to allow you + to LOOKUP even though you can't list the directory). Everyone + implicitly has LOOKUP permission. This allows you to stat a + node, but nothing more. (The problem is, if you want to call + zoo_exists() on a node that doesn't exist, there is no + permission to check.) + + +
      + Builtin ACL Schemes + + ZooKeeeper has the following built in schemes: + + + + + world + has a + single id, anyone, that represents + anyone. + + + + + + auth + doesn't + use any id, represents any authenticated + user. + + + + + + digest + uses + a username:password string to generate + MD5 hash which is then used as an ACL ID + identity. Authentication is done by sending + the username:password in clear text. When + used in the ACL the expression will be + the + username:base64 + encoded + SHA1 + password digest. + + + + + + ip + uses the + client host IP as an ACL ID identity. The ACL expression is of + the form addr/bits where the most + significant + bits + of addr are matched against the most + significant bits of the client host + IP. + + + + + + x509 + uses the client + X500 Principal as an ACL ID identity. The ACL expression is the exact + X500 Principal name of a client. When using the secure port, clients + are automatically authenticated and their auth info for the x509 scheme + is set. + + + + +
      + +
      + ZooKeeper C client API + + The following constants are provided by the ZooKeeper C + library: + + + + + + const + int ZOO_PERM_READ; //can read node’s value and list its children + + + + + const + int ZOO_PERM_WRITE;// can set the node’s value + + + + + const + int ZOO_PERM_CREATE; //can create children + + + + + const + int ZOO_PERM_DELETE;// can delete children + + + + + const + int ZOO_PERM_ADMIN; //can execute set_acl() + + + + + const + int ZOO_PERM_ALL;// all of the above flags OR’d together + + + + + The following are the standard ACL IDs: + + + + + struct + Id ZOO_ANYONE_ID_UNSAFE; //(‘world’,’anyone’) + + + + + struct + Id ZOO_AUTH_IDS;// (‘auth’,’’) + + + + + ZOO_AUTH_IDS empty identity string should be interpreted as “the identity of the creator”. + + ZooKeeper client comes with three standard ACLs: + + + + + struct + ACL_vector ZOO_OPEN_ACL_UNSAFE; //(ZOO_PERM_ALL,ZOO_ANYONE_ID_UNSAFE) + + + + + struct + ACL_vector ZOO_READ_ACL_UNSAFE;// (ZOO_PERM_READ, ZOO_ANYONE_ID_UNSAFE) + + + + + struct + ACL_vector ZOO_CREATOR_ALL_ACL; //(ZOO_PERM_ALL,ZOO_AUTH_IDS) + + + + + The ZOO_OPEN_ACL_UNSAFE is completely open free for all + ACL: any application can execute any operation on the node and + can create, list and delete its children. The + ZOO_READ_ACL_UNSAFE is read-only access for any + application. CREATE_ALL_ACL grants all permissions to the + creator of the node. The creator must have been authenticated by + the server (for example, using “digest” + scheme) before it can create nodes with this ACL. + + + The following ZooKeeper operations deal with ACLs: + + + + + int + zoo_add_auth + (zhandle_t *zh,const + char* + scheme,const + char* + cert, int certLen, void_completion_t + completion, const + void + *data); + + + + + The application uses the zoo_add_auth function to + authenticate itself to the server. The function can be called + multiple times if the application wants to authenticate using + different schemes and/or identities. + + + + + + int + zoo_create + (zhandle_t *zh, const + char + *path, const + char + *value, + int + valuelen, const + struct + ACL_vector *acl, + int + flags, + char + *realpath, + int + max_realpath_len); + + + + + zoo_create(...) operation creates a new node. The acl + parameter is a list of ACLs associated with the node. The parent + node must have the CREATE permission bit set. + + + + + + int + zoo_get_acl + (zhandle_t *zh, const + char + *path,struct ACL_vector + *acl, struct Stat *stat); + + + + + This operation returns a node’s ACL info. + + + + + int + zoo_set_acl + (zhandle_t *zh, const + char + *path, + int + version,const + struct + ACL_vector *acl); + + + + + This function replaces node’s ACL list with a new one. The + node must have the ADMIN permission set. + + + Here is a sample code that makes use of the above APIs to + authenticate itself using the “foo” scheme + and create an ephemeral node “/xyz” with create-only + permissions. + + + + This is a very simple example which is intended to show + how to interact with ZooKeeper ACLs + specifically. See + .../trunk/src/c/src/cli.c + for an example of a proper C client implementation + + + + + #include <string.h> + #include <errno.h> + + #include "zookeeper.h" + + static zhandle_t *zh; + + /** + * In this example this method gets the cert for your + * environment -- you must provide + */ + char *foo_get_cert_once(char* id) { return 0; } + + /** Watcher function -- empty for this example, not something you should + * do in real code */ + void watcher(zhandle_t *zzh, int type, int state, const char *path, + void *watcherCtx) {} + + int main(int argc, char argv) { + char buffer[512]; + char p[2048]; + char *cert=0; + char appId[64]; + + strcpy(appId, "example.foo_test"); + cert = foo_get_cert_once(appId); + if(cert!=0) { + fprintf(stderr, + "Certificate for appid [%s] is [%s]\n",appId,cert); + strncpy(p,cert, sizeof(p)-1); + free(cert); + } else { + fprintf(stderr, "Certificate for appid [%s] not found\n",appId); + strcpy(p, "dummy"); + } + + zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG); + + zh = zookeeper_init("localhost:3181", watcher, 10000, 0, 0, 0); + if (!zh) { + return errno; + } + if(zoo_add_auth(zh,"foo",p,strlen(p),0,0)!=ZOK) + return 2; + + struct ACL CREATE_ONLY_ACL[] = {{ZOO_PERM_CREATE, ZOO_AUTH_IDS}}; + struct ACL_vector CREATE_ONLY = {1, CREATE_ONLY_ACL}; + int rc = zoo_create(zh,"/xyz","value", 5, &CREATE_ONLY, ZOO_EPHEMERAL, + buffer, sizeof(buffer)-1); + + /** this operation will fail with a ZNOAUTH error */ + int buflen= sizeof(buffer); + struct Stat stat; + rc = zoo_get(zh, "/xyz", 0, buffer, &buflen, &stat); + if (rc) { + fprintf(stderr, "Error %d for %s\n", rc, __LINE__); + } + + zookeeper_close(zh); + return 0; + } + +
      +
      +
      + +
      + Pluggable ZooKeeper authentication + + ZooKeeper runs in a variety of different environments with + various different authentication schemes, so it has a completely + pluggable authentication framework. Even the builtin authentication + schemes use the pluggable authentication framework. + + + To understand how the authentication framework works, first you must + understand the two main authentication operations. The framework + first must authenticate the client. This is usually done as soon as + the client connects to a server and consists of validating information + sent from or gathered about a client and associating it with the connection. + The second operation handled by the framework is finding the entries in an + ACL that correspond to client. ACL entries are <idspec, + permissions> pairs. The idspec may be + a simple string match against the authentication information associated + with the connection or it may be a expression that is evaluated against that + information. It is up to the implementation of the authentication plugin + to do the match. Here is the interface that an authentication plugin must + implement: + + + + public interface AuthenticationProvider { + String getScheme(); + KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte authData[]); + boolean isValid(String id); + boolean matches(String id, String aclExpr); + boolean isAuthenticated(); + } + + + The first method getScheme returns the string + that identifies the plugin. Because we support multiple methods of authentication, + an authentication credential or an idspec will always be + prefixed with scheme:. The ZooKeeper server uses the scheme + returned by the authentication plugin to determine which ids the scheme + applies to. + + + + handleAuthentication + is called when a client + sends authentication information to be associated with a connection. The + client specifies the scheme to which the information corresponds. The + ZooKeeper server passes the information to the authentication plugin whose + getScheme + matches the scheme passed by the client. The + implementor of handleAuthentication will usually return + an error if it determines that the information is bad, or it will associate information + with the connection using cnxn.getAuthInfo().add(new Id(getScheme(), data)). + + + The authentication plugin is involved in both setting and using ACLs. When an + ACL is set for a znode, the ZooKeeper server will pass the id part of the entry to + the isValid(String id) method. It is up to the plugin to verify + that the id has a correct form. For example, + ip:172.16.0.0/16 + is a valid id, but ip:host.com is not. If the new ACL includes + an "auth" entry, isAuthenticated is used to see if the + authentication information for this scheme that is assocatied with the connection + should be added to the ACL. Some schemes + should not be included in auth. For example, the IP address of the client is not + considered as an id that should be added to the ACL if auth is specified. + + + ZooKeeper invokes + matches(String id, String aclExpr) + when checking an ACL. It + needs to match authentication information of the client against the relevant ACL + entries. To find the entries which apply to the client, the ZooKeeper server will + find the scheme of each entry and if there is authentication information + from that client for that scheme, + matches(String id, String aclExpr) + will be called with id set to the authentication information + that was previously added to the connection by handleAuthentication and + aclExpr + set to the id of the ACL entry. The authentication plugin + uses its own logic and matching scheme to determine if id is included + in aclExpr. + + + There are two built in authentication plugins: ip and + digest. Additional plugins can adding using system properties. At + startup the ZooKeeper server will look for system properties that start with + "zookeeper.authProvider." and interpret the value of those properties as the class name + of an authentication plugin. These properties can be set using the + -Dzookeeeper.authProvider.X=com.f.MyAuth + or adding entries such as + the following in the server configuration file: + + + + authProvider.1=com.f.MyAuth + authProvider.2=com.f.MyAuth2 + + + Care should be taking to ensure that the suffix on the property is unique. If there are + duplicates such as -Dzookeeeper.authProvider.X=com.f.MyAuth -Dzookeeper.authProvider.X=com.f.MyAuth2, + only one will be used. Also all servers must have the same plugins defined, otherwise clients using + the authentication schemes provided by the plugins will have problems connecting to some servers. + +
      + +
      + Consistency Guarantees + + ZooKeeper is a high performance, scalable service. Both reads and + write operations are designed to be fast, though reads are faster than + writes. The reason for this is that in the case of reads, ZooKeeper can + serve older data, which in turn is due to ZooKeeper's consistency + guarantees: + + + + + Sequential Consistency + + + Updates from a client will be applied in the order that they + were sent. + + + + + + Atomicity + + + Updates either succeed or fail -- there are no partial + results. + + + + + + Single System Image + + + A client will see the same view of the service regardless of + the server that it connects to. + + + + + + Reliability + + + Once an update has been applied, it will persist from that + time forward until a client overwrites the update. This guarantee + has two corollaries: + + + + + If a client gets a successful return code, the update will + have been applied. On some failures (communication errors, + timeouts, etc) the client will not know if the update has + applied or not. We take steps to minimize the failures, but the + guarantee is only present with successful return codes. + (This is called the monotonicity condition in Paxos.) + + + + + Any updates that are seen by the client, through a read + request or successful update, will never be rolled back when + recovering from server failures. + + + + + + + + Timeliness + + + The clients view of the system is guaranteed to be up-to-date + within a certain time bound (on the order of tens of seconds). + Either system changes will be seen by a client within this bound, or + the client will detect a service outage. + + + + + + Using these consistency guarantees it is easy to build higher level + functions such as leader election, barriers, queues, and read/write + revocable locks solely at the ZooKeeper client (no additions needed to + ZooKeeper). See + Recipes and Solutions + for more details. + + + + Sometimes developers mistakenly assume one other guarantee that + ZooKeeper does not in fact make. This is: + + + + + Simultaneously Consistent Cross-Client Views + + + ZooKeeper does not guarantee that at every instance in + time, two different clients will have identical views of + ZooKeeper data. Due to factors like network delays, one client + may perform an update before another client gets notified of the + change. Consider the scenario of two clients, A and B. If client + A sets the value of a znode /a from 0 to 1, then tells client B + to read /a, client B may read the old value of 0, depending on + which server it is connected to. If it + is important that Client A and Client B read the same value, + Client B should should call the sync() + method from the ZooKeeper API + method before it performs its read. + + + So, ZooKeeper by itself doesn't guarantee that changes occur + synchronously across all servers, but ZooKeeper + primitives can be used to construct higher level functions that + provide useful client synchronization. (For more information, + see the ZooKeeper Recipes. + [tbd:..]). + + + + + +
      + +
      + Bindings + + The ZooKeeper client libraries come in two languages: Java and C. + The following sections describe these. + + +
      + Java Binding + + There are two packages that make up the ZooKeeper Java binding: + org.apache.zookeeper + and org.apache.zookeeper.data. The rest of the + packages that make up ZooKeeper are used internally or are part of the + server implementation. The org.apache.zookeeper.data + package is made up of + generated classes that are used simply as containers. + + + The main class used by a ZooKeeper Java client is the ZooKeeper + class. Its two constructors differ only + by an optional session id and password. ZooKeeper supports session + recovery accross instances of a process. A Java program may save its + session id and password to stable storage, restart, and recover the + session that was used by the earlier instance of the program. + + + When a ZooKeeper object is created, two threads are created as + well: an IO thread and an event thread. All IO happens on the IO thread + (using Java NIO). All event callbacks happen on the event thread. + Session maintenance such as reconnecting to ZooKeeper servers and + maintaining heartbeat is done on the IO thread. Responses for + synchronous methods are also processed in the IO thread. All responses + to asynchronous methods and watch events are processed on the event + thread. There are a few things to notice that result from this + design: + + + + + All completions for asynchronous calls and watcher callbacks + will be made in order, one at a time. The caller can do any + processing they wish, but no other callbacks will be processed + during that time. + + + + + Callbacks do not block the processing of the IO thread or the + processing of the synchronous calls. + + + + + Synchronous calls may not return in the correct order. For + example, assume a client does the following processing: issues an + asynchronous read of node /a with + watch + set to true, and then in the completion + callback of the read it does a synchronous read of /a. (Maybe not good practice, but not illegal + either, and it makes for a simple example.) + + + Note that if there is a change to /a + between the asynchronous read and the + synchronous read, the client library will receive the watch event + saying /a changed before the + response for the synchronous read, but because the completion + callback is blocking the event queue, the synchronous read will + return with the new value of + /a + before the watch event is processed. + + + + + Finally, the rules associated with shutdown are straightforward: + once a ZooKeeper object is closed or receives a fatal event + (SESSION_EXPIRED and AUTH_FAILED), the ZooKeeper object becomes invalid. + On a close, the two threads shut down and any further access on zookeeper + handle is undefined behavior and should be avoided. + +
      + +
      + C Binding + + The C binding has a single-threaded and multi-threaded library. + The multi-threaded library is easiest to use and is most similar to the + Java API. This library will create an IO thread and an event dispatch + thread for handling connection maintenance and callbacks. The + single-threaded library allows ZooKeeper to be used in event driven + applications by exposing the event loop used in the multi-threaded + library. + + + The package includes two shared libraries: zookeeper_st and + zookeeper_mt. The former only provides the asynchronous APIs and + callbacks for integrating into the application's event loop. The only + reason this library exists is to support the platforms were a + pthread + library is not available or is unstable + (i.e. FreeBSD 4.x). In all other cases, application developers should + link with zookeeper_mt, as it includes support for both Sync and Async + API. + + +
      + Installation + + If you're building the client from a check-out from the Apache + repository, follow the steps outlined below. If you're building from a + project source package downloaded from apache, skip to step 3. + + + + + Run ant compile_jute from the ZooKeeper + top level directory (.../trunk). + This will create a directory named "generated" under + .../trunk/src/c. + + + + + Change directory to the + .../trunk/src/c + and run autoreconf -if to bootstrap autoconf, automake + and libtool. Make sure you have autoconf version 2.59 + or greater installed. + Skip to step4. + + + + + If you are building from a project source package, + unzip/untar the source tarball and cd to the + zookeeper-x.x.x/src/c + directory. + + + + + Run ./configure <your-options> to + generate the makefile. Here are some of options the configure + utility supports that can be + useful in this step: + + + + + + --enable-debug + + + Enables optimization and enables debug info compiler + options. (Disabled by default.) + + + + + + --without-syncapi + + + Disables Sync API support; zookeeper_mt library won't be + built. (Enabled by default.) + + + + + + --disable-static + + + Do not build static libraries. (Enabled by + default.) + + + + + + --disable-shared + + + Do not build shared libraries. (Enabled by + default.) + + + + + + See INSTALL for general information about running + configure. + + + + + + Run make or make + install + to build the libraries and install them. + + + + + To generate doxygen documentation for the ZooKeeper API, run + make doxygen-doc. All documentation will be + placed in a new subfolder named docs. By default, this command + only generates HTML. For information on other document formats, + run + ./configure --help + + + +
      + +
      + Using the C Client + + You can test your client by running a ZooKeeper server (see + instructions on the project wiki page on how to run it) and connecting + to it using one of the cli applications that were built as part of the + installation procedure. cli_mt (multithreaded, built against + zookeeper_mt library) is shown in this example, but you could also use + cli_st (singlethreaded, built against zookeeper_st library): + + + + $ cli_mt zookeeper_host:9876 + + + This is a client application that gives you a shell for + executing simple ZooKeeper commands. Once successfully started + and connected to the server it displays a shell prompt. You + can now enter ZooKeeper commands. For example, to create a + node: + + + + > create /my_new_node + + + To verify that the node's been created: + + + > ls / + + + You should see a list of node who are children of the root node + "/". + + + In order to be able to use the ZooKeeper API in your application + you have to remember to + + + + + Include ZooKeeper header: #include + <zookeeper/zookeeper.h> + + + + + If you are building a multithreaded client, compile with + -DTHREADED compiler flag to enable the multi-threaded version of + the library, and then link against against the + zookeeper_mt + library. If you are building a + single-threaded client, do not compile with -DTHREADED, and be + sure to link against thezookeeper_st + library. + + + + + Refer to + + for examples of usage in Java and C. + [tbd] + +
      +
      +
      + +
      + Building Blocks: A Guide to ZooKeeper Operations + + This section surveys all the operations a developer can perform + against a ZooKeeper server. It is lower level information than the earlier + concepts chapters in this manual, but higher level than the ZooKeeper API + Reference. It covers these topics: + + + + + + + + + + +
      + Handling Errors + + Both the Java and C client bindings may report errors. The Java client binding does so by throwing KeeperException, calling code() on the exception will return the specific error + code. The C client binding returns an error code as defined in the enum ZOO_ERRORS. API callbacks indicate result code for both language bindings. See the API documentation (javadoc + for Java, doxygen for C) for full details on the possible errors and their meaning. + +
      + +
      + Connecting to ZooKeeper + + +
      + +
      + Read Operations + + +
      + +
      + Write Operations + + +
      + +
      + Handling Watches + + +
      + +
      + Miscelleaneous ZooKeeper Operations + +
      + + +
      + +
      + Program Structure, with Simple Example + + + [tbd] + +
      + +
      + Gotchas: Common Problems and Troubleshooting + + So now you know ZooKeeper. It's fast, simple, your application + works, but wait ... something's wrong. Here are some pitfalls that + ZooKeeper users fall into: + + + + + If you are using watches, you must look for the connected watch + event. When a ZooKeeper client disconnects from a server, you will + not receive notification of changes until reconnected. If you are + watching for a znode to come into existance, you will miss the event + if the znode is created and deleted while you are disconnected. + + + + + You must test ZooKeeper server failures. The ZooKeeper service + can survive failures as long as a majority of servers are active. The + question to ask is: can your application handle it? In the real world + a client's connection to ZooKeeper can break. (ZooKeeper server + failures and network partitions are common reasons for connection + loss.) The ZooKeeper client library takes care of recovering your + connection and letting you know what happened, but you must make sure + that you recover your state and any outstanding requests that failed. + Find out if you got it right in the test lab, not in production - test + with a ZooKeeper service made up of a several of servers and subject + them to reboots. + + + + + The list of ZooKeeper servers used by the client must match the + list of ZooKeeper servers that each ZooKeeper server has. Things can + work, although not optimally, if the client list is a subset of the + real list of ZooKeeper servers, but not if the client lists ZooKeeper + servers not in the ZooKeeper cluster. + + + + + Be careful where you put that transaction log. The most + performance-critical part of ZooKeeper is the transaction log. + ZooKeeper must sync transactions to media before it returns a + response. A dedicated transaction log device is key to consistent good + performance. Putting the log on a busy device will adversely effect + performance. If you only have one storage device, put trace files on + NFS and increase the snapshotCount; it doesn't eliminate the problem, + but it can mitigate it. + + + + + Set your Java max heap size correctly. It is very important to + avoid swapping. + Going to disk unnecessarily will + almost certainly degrade your performance unacceptably. Remember, in + ZooKeeper, everything is ordered, so if one request hits the disk, all + other queued requests hit the disk. + + + To avoid swapping, try to set the heapsize to the amount of + physical memory you have, minus the amount needed by the OS and cache. + The best way to determine an optimal heap size for your configurations + is to run load tests. If for some reason you + can't, be conservative in your estimates and choose a number well + below the limit that would cause your machine to swap. For example, on + a 4G machine, a 3G heap is a conservative estimate to start + with. + + + +
      + + + Links to Other Information + + Outside the formal documentation, there're several other sources of + information for ZooKeeper developers. + + + + + ZooKeeper Whitepaper + [tbd: find url] + + + + The definitive discussion of ZooKeeper design and performance, + by Yahoo! Research + + + + + + API Reference + [tbd: find url] + + + + The complete reference to the ZooKeeper API + + + + + + ZooKeeper + Talk at the Hadoup Summit 2008 + + + + + A video introduction to ZooKeeper, by Benjamin Reed of Yahoo! + Research + + + + + + + Barrier and + Queue Tutorial + + + + + The excellent Java tutorial by Flavio Junqueira, implementing + simple barriers and producer-consumer queues using ZooKeeper. + + + + + + + ZooKeeper + - A Reliable, Scalable Distributed Coordination System + + + + + An article by Todd Hoff (07/15/2008) + + + + + + ZooKeeper Recipes + + + + Pseudo-level discussion of the implementation of various + synchronization solutions with ZooKeeper: Event Handles, Queues, + Locks, and Two-phase Commits. + + + + + + + [tbd] + + + + Any other good sources anyone can think of... + + + + +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperQuotas.xml b/src/docs/src/documentation/content/xdocs/zookeeperQuotas.xml new file mode 100644 index 00000000000..fe8b8b657fc --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperQuotas.xml @@ -0,0 +1,81 @@ + + + +
      + ZooKeeper Quota's Guide + A Guide to Deployment and Administration + + + + Licensed under the Apache License, Version 2.0 (the "License"); you + may not use this file except in compliance with the License. You may + obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + + . + + Unless required by applicable law or agreed to in + writing, software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + express or implied. See the License for the specific language + governing permissions and limitations under the License. + + + + This document contains information about deploying, + administering and mantaining ZooKeeper. It also discusses best + practices and common problems. + + + +
      + Quotas + ZooKeeper has both namespace and bytes quotas. You can use the ZooKeeperMain class to setup quotas. + ZooKeeper prints WARN messages if users exceed the quota assigned to them. The messages + are printed in the log of the ZooKeeper. + + + $java -cp zookeeper.jar:src/java/lib/log4j-1.2.16.jar:src/java/lib/jline-2.11.jar:conf \ + org.apache.zookeeper.ZooKeeperMain -server host:port + + + The above command gives you a command line option of using quotas. +
      + Setting Quotas + You can use + setquota + to set a quota on a ZooKeeper node. It has an option of setting quota with + -n (for namespace) + and -b (for bytes). + + The ZooKeeper quota are stored in ZooKeeper itself in /zookeeper/quota. To disable other people from + changing the quota's set the ACL for /zookeeper/quota such that only admins are able to read and write to it. + +
      +
      + Listing Quotas + You can use + listquota + to list a quota on a ZooKeeper node. + +
      +
      + Deleting Quotas + You can use + delquota + to delete quota on a ZooKeeper node. + +
      +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml b/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml new file mode 100644 index 00000000000..39796db5125 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml @@ -0,0 +1,903 @@ + + + +
      + ZooKeeper Dynamic Reconfiguration + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This document contains information about Dynamic Reconfiguration in + ZooKeeper. + + + +
      + Overview + Prior to the 3.5.0 release, the membership and all other configuration + parameters of Zookeeper were static - loaded during boot and immutable at + runtime. Operators resorted to ''rolling restarts'' - a manually intensive + and error-prone method of changing the configuration that has caused data + loss and inconsistency in production. + + Starting with 3.5.0, “rolling restarts” are no longer needed! + ZooKeeper comes with full support for automated configuration changes: the + set of Zookeeper servers, their roles (participant / observer), all ports, + and even the quorum system can be changed dynamically, without service + interruption and while maintaining data consistency. Reconfigurations are + performed immediately, just like other operations in ZooKeeper. Multiple + changes can be done using a single reconfiguration command. The dynamic + reconfiguration functionality does not limit operation concurrency, does + not require client operations to be stopped during reconfigurations, has a + very simple interface for administrators and no added complexity to other + client operations. + + New client-side features allow clients to find out about configuration + changes and to update the connection string (list of servers and their + client ports) stored in their ZooKeeper handle. A probabilistic algorithm + is used to rebalance clients across the new configuration servers while + keeping the extent of client migrations proportional to the change in + ensemble membership. + + This document provides the administrator manual for reconfiguration. + For a detailed description of the reconfiguration algorithms, performance + measurements, and more, please see our paper: + + + + Shraer, A., Reed, B., Malkhi, D., Junqueira, F. Dynamic + Reconfiguration of Primary/Backup Clusters. In USENIX Annual + Technical Conference (ATC)(2012), 425-437 + + + Links: paper (pdf), slides (pdf), video, + hadoop summit slides + + + + + +
      +
      + Changes to Configuration Format +
      + Specifying the client port + A client port of a server is the port on which the server accepts + client connection requests. Starting with 3.5.0 the + clientPort + and clientPortAddress + configuration parameters should no longer be used. Instead, + this information is now part of the server keyword specification, which + becomes as follows: + + + = ::[:role];[:]]]> + + The client port specification is to the right of the semicolon. The + client port address is optional, and if not specified it defaults to + "0.0.0.0". As usual, role is also optional, it can be + participant + or + observer + (participant by default). + + Examples of legal server statements: + + + + server.5 = 125.23.63.23:1234:1235;1236 + + + + + server.5 = 125.23.63.23:1234:1235:participant;1236 + + + + + server.5 = 125.23.63.23:1234:1235:observer;1236 + + + + + server.5 = 125.23.63.23:1234:1235;125.23.63.24:1236 + + + + + server.5 = 125.23.63.23:1234:1235:participant;125.23.63.23:1236 + + + +
      +
      + The <emphasis>standaloneEnabled</emphasis> flag + + Prior to 3.5.0, one could run ZooKeeper in Standalone mode or in a + Distributed mode. These are separate implementation stacks, and + switching between them during run time is not possible. By default (for + backward compatibility) standaloneEnabled is set to + true. The consequence of using this default is that + if started with a single server the ensemble will not be allowed to + grow, and if started with more than one server it will not be allowed to + shrink to contain fewer than two participants. + + Setting the flag to false instructs the system + to run the Distributed software stack even if there is only a single + participant in the ensemble. To achieve this the (static) configuration + file should contain: + + + standaloneEnabled=false + + With this setting it is possible to start a ZooKeeper ensemble + containing a single participant and to dynamically grow it by adding + more servers. Similarly, it is possible to shrink an ensemble so that + just a single participant remains, by removing servers. + + Since running the Distributed mode allows more flexibility, we + recommend setting the flag to false. We expect that + the legacy Standalone mode will be deprecated in the future. + +
      +
      + Dynamic configuration file + Starting with 3.5.0 we're distinguishing between dynamic + configuration parameters, which can be changed during runtime, and + static configuration parameters, which are read from a configuration + file when a server boots and don't change during its execution. For now, + the following configuration keywords are considered part of the dynamic + configuration: server, + group + and weight. + + Dynamic configuration parameters are stored in a separate file on + the server (which we call the dynamic configuration file). This file is + linked from the static config file using the new + dynamicConfigFile + keyword. + + + Example + + + zoo_replicated1.cfg + tickTime=2000 + dataDir=/zookeeper/data/zookeeper1 + initLimit=5 + syncLimit=2 + dynamicConfigFile=/zookeeper/conf/zoo_replicated1.cfg.dynamic + + + + zoo_replicated1.cfg.dynamic + server.1=125.23.63.23:2780:2783:participant;2791 + server.2=125.23.63.24:2781:2784:participant;2792 + server.3=125.23.63.25:2782:2785:participant;2793 + + + When the ensemble configuration changes, the static configuration + parameters remain the same. The dynamic parameters are pushed by + ZooKeeper and overwrite the dynamic configuration files on all servers. + Thus, the dynamic configuration files on the different servers are + usually identical (they can only differ momentarily when a + reconfiguration is in progress, or if a new configuration hasn't + propagated yet to some of the servers). Once created, the dynamic + configuration file should not be manually altered. Changed are only made + through the new reconfiguration commands outlined below. Note that + changing the config of an offline cluster could result in an + inconsistency with respect to configuration information stored in the + ZooKeeper log (and the special configuration znode, populated from the + log) and is therefore highly discouraged. + + + Example 2 + + Users may prefer to initially specify a single configuration file. + The following is thus also legal: + + + zoo_replicated1.cfg + tickTime=2000 + dataDir=/zookeeper/data/zookeeper1 + initLimit=5 + syncLimit=2 + clientPort=2791 // note that this line is now redundant and therefore not recommended + server.1=125.23.63.23:2780:2783:participant; + 2791 + server.2=125.23.63.24:2781:2784:participant;2792 + server.3=125.23.63.25:2782:2785:participant;2793 + + + The configuration files on each server will be automatically split + into dynamic and static files, if they are not already in this format. + So the configuration file above will be automatically transformed into + the two files in Example 1. Note that the clientPort and + clientPortAddress lines (if specified) will be automatically removed + during this process, if they are redundant (as in the example above). + The original static configuration file is backed up (in a .bak + file). + +
      +
      + Backward compatibility + We still support the old configuration format. For example, the + following configuration file is acceptable (but not recommended): + + + zoo_replicated1.cfg + tickTime=2000 + dataDir=/zookeeper/data/zookeeper1 + initLimit=5 + syncLimit=2 + clientPort=2791 + server.1=125.23.63.23:2780:2783:participant + server.2=125.23.63.24:2781:2784:participant + server.3=125.23.63.25:2782:2785:participant + + + During boot, a dynamic configuration file is created and contains + the dynamic part of the configuration as explained earlier. In this + case, however, the line "clientPort=2791" will remain in the static + configuration file of server 1 since it is not redundant -- it was not + specified as part of the "server.1=..." using the format explained in + the section. If a reconfiguration + is invoked that sets the client port of server 1, we remove + "clientPort=2791" from the static configuration file (the dynamic file + now contain this information as part of the specification of server + 1). + +
      +
      +
      + Upgrading to 3.5.0 + Upgrading a running ZooKeeper ensemble to 3.5.0 should be done only + after upgrading your ensemble to the 3.4.6 release. Note that this is only + necessary for rolling upgrades (if you're fine with shutting down the + system completely, you don't have to go through 3.4.6). If you attempt a + rolling upgrade without going through 3.4.6 (for example from 3.4.5), you + may get the following error: + + 2013-01-30 11:32:10,663 [myid:2] - INFO [localhost/127.0.0.1:2784:QuorumCnxManager$Listener@498] - Received connection request /127.0.0.1:60876 + 2013-01-30 11:32:10,663 [myid:2] - WARN [localhost/127.0.0.1:2784:QuorumCnxManager@349] - Invalid server id: -65536 + + During a rolling upgrade, each server is taken down in turn and + rebooted with the new 3.5.0 binaries. Before starting the server with + 3.5.0 binaries, we highly recommend updating the configuration file so + that all server statements "server.x=..." contain client ports (see the + section). As explained earlier + you may leave the configuration in a single file, as well as leave the + clientPort/clientPortAddress statements (although if you specify client + ports in the new format, these statements are now redundant). + +
      +
      + Dynamic Reconfiguration of the ZooKeeper Ensemble + The ZooKeeper Java and C API were extended with getConfig and reconfig + commands that facilitate reconfiguration. Both commands have a synchronous + (blocking) variant and an asynchronous one. We demonstrate these commands + here using the Java CLI, but note that you can similarly use the C CLI or + invoke the commands directly from a program just like any other ZooKeeper + command. + +
      + Retrieving the current dynamic configuration + The dynamic configuration is stored in a special znode + ZooDefs.CONFIG_NODE = /zookeeper/config. The new + config + CLI command reads this znode (currently it is + simply a wrapper to get /zookeeper/config). As with + normal reads, to retrieve the latest committed value you should do a + sync + first. + + [zk: 127.0.0.1:2791(CONNECTED) 3] config + server.1=localhost:2780:2783:participant;localhost:2791 + server.2=localhost:2781:2784:participant;localhost:2792 + server.3=localhost:2782:2785:participant;localhost:2793 + version=400000003 + + Notice the last line of the output. This is the configuration + version. The version equals to the zxid of the reconfiguration command + which created this configuration. The version of the first established + configuration equals to the zxid of the NEWLEADER message sent by the + first successfully established leader. When a configuration is written + to a dynamic configuration file, the version automatically becomes part + of the filename and the static configuration file is updated with the + path to the new dynamic configuration file. Configuration files + corresponding to earlier versions are retained for backup + purposes. + + During boot time the version (if it exists) is extracted from the + filename. The version should never be altered manually by users or the + system administrator. It is used by the system to know which + configuration is most up-to-date. Manipulating it manually can result in + data loss and inconsistency. + + Just like a get command, the + config + CLI command accepts the + + flag for setting a watch on the znode, and flag for + displaying the Stats of the znode. It additionally accepts a new flag + + which outputs only the version and the client + connection string corresponding to the current configuration. For + example, for the configuration above we would get: + + [zk: 127.0.0.1:2791(CONNECTED) 17] config -c + 400000003 localhost:2791,localhost:2793,localhost:2792 + + Note that when using the API directly, this command is called + getConfig. + + As any read command it returns the configuration known to the + follower to which your client is connected, which may be slightly + out-of-date. One can use the sync command for + stronger guarantees. For example using the Java API: + + zk.sync(ZooDefs.CONFIG_NODE, void_callback, context); + zk.getConfig(watcher, callback, context); + + Note: in 3.5.0 it doesn't really matter which path is passed to the + sync() + command as all the server's state is brought + up to date with the leader (so one could use a different path instead of + ZooDefs.CONFIG_NODE). However, this may change in the future. + +
      +
      + Modifying the current dynamic configuration + Modifying the configuration is done through the + reconfig + command. There are two modes of + reconfiguration: incremental and non-incremental (bulk). The + non-incremental simply specifies the new dynamic configuration of the + system. The incremental specifies changes to the current configuration. + The reconfig command returns the new + configuration. + + A few examples are in: ReconfigTest.java, + ReconfigRecoveryTest.java + and + TestReconfigServer.cc. + +
      + General + + Removing servers: + Any server can + be removed, including the leader (although removing the leader will + result in a short unavailability, see Figures 6 and 8 in the paper). The server will not be shut-down automatically. + Instead, it becomes a "non-voting follower". This is somewhat similar + to an observer in that its votes don't count towards the Quorum of + votes necessary to commit operations. However, unlike a non-voting + follower, an observer doesn't actually see any operation proposals and + does not ACK them. Thus a non-voting follower has a more significant + negative effect on system throughput compared to an observer. + Non-voting follower mode should only be used as a temporary mode, + before shutting the server down, or adding it as a follower or as an + observer to the ensemble. We do not shut the server down automatically + for two main reasons. The first reason is that we do not want all the + clients connected to this server to be immediately disconnected, + causing a flood of connection requests to other servers. Instead, it + is better if each client decides when to migrate independently. The + second reason is that removing a server may sometimes (rarely) be + necessary in order to change it from "observer" to "participant" (this + is explained in the section). + + Note that the new configuration should have some minimal number of + participants in order to be considered legal. If the proposed change + would leave the cluster with less than 2 participants and standalone + mode is enabled (standaloneEnabled=true, see the section), the reconfig will not be + processed (BadArgumentsException). If standalone mode is disabled + (standaloneEnabled=false) then its legal to remain with 1 or more + participants. + + + Adding servers: + Before a + reconfiguration is invoked, the administrator must make sure that a + quorum (majority) of participants from the new configuration are + already connected and synced with the current leader. To achieve this + we need to connect a new joining server to the leader before it is + officially part of the ensemble. This is done by starting the joining + server using an initial list of servers which is technically not a + legal configuration of the system but (a) contains the joiner, and (b) + gives sufficient information to the joiner in order for it to find and + connect to the current leader. We list a few different options of + doing this safely. + + + + Initial configuration of joiners is comprised of servers in + the last committed configuration and one or more joiners, where + joiners are listed as observers. + For example, if servers D and E are added at the same time to (A, + B, C) and server C is being removed, the initial configuration of + D could be (A, B, C, D) or (A, B, C, D, E), where D and E are + listed as observers. Similarly, the configuration of E could be + (A, B, C, E) or (A, B, C, D, E), where D and E are listed as + observers. Note that listing the joiners as + observers will not actually make them observers - it will only + prevent them from accidentally forming a quorum with other + joiners. + Instead, they will contact the servers in the + current configuration and adopt the last committed configuration + (A, B, C), where the joiners are absent. Configuration files of + joiners are backed up and replaced automatically as this happens. + After connecting to the current leader, joiners become non-voting + followers until the system is reconfigured and they are added to + the ensemble (as participant or observer, as appropriate). + + + + Initial configuration of each joiner is comprised of servers + in the last committed configuration + the + joiner itself, listed as a participant. + For example, to + add a new server D to a configuration consisting of servers (A, B, + C), the administrator can start D using an initial configuration + file consisting of servers (A, B, C, D). If both D and E are added + at the same time to (A, B, C), the initial configuration of D + could be (A, B, C, D) and the configuration of E could be (A, B, + C, E). Similarly, if D is added and C is removed at the same time, + the initial configuration of D could be (A, B, C, D). Never list + more than one joiner as participant in the initial configuration + (see warning below). + + + + Whether listing the joiner as an observer or as participant, + it is also fine not to list all the current configuration servers, + as long as the current leader is in the list. For example, when + adding D we could start D with a configuration file consisting of + just (A, D) if A is the current leader. however this is more + fragile since if A fails before D officially joins the ensemble, D + doesn’t know anyone else and therefore the administrator will have + to intervene and restart D with another server list. + + + + + Warning + Never specify more than one joining server in the same initial + configuration as participants. Currently, the joining servers don’t + know that they are joining an existing ensemble; if multiple joiners + are listed as participants they may form an independent quorum + creating a split-brain situation such as processing operations + independently from your main ensemble. It is OK to list multiple + joiners as observers in an initial config. + + + Finally, note that once connected to the leader, a joiner adopts + the last committed configuration, in which it is absent (the initial + config of the joiner is backed up before being rewritten). If the + joiner restarts in this state, it will not be able to boot since it is + absent from its configuration file. In order to start it you’ll once + again have to specify an initial configuration. + + + Modifying server parameters: + One + can modify any of the ports of a server, or its role + (participant/observer) by adding it to the ensemble with different + parameters. This works in both the incremental and the bulk + reconfiguration modes. It is not necessary to remove the server and + then add it back; just specify the new parameters as if the server is + not yet in the system. The server will detect the configuration change + and perform the necessary adjustments. See an example in the section + + and an exception to this + rule in the section. + + It is also possible to change the Quorum System used by the + ensemble (for example, change the Majority Quorum System to a + Hierarchical Quorum System on the fly). This, however, is only allowed + using the bulk (non-incremental) reconfiguration mode. In general, + incremental reconfiguration only works with the Majority Quorum + System. Bulk reconfiguration works with both Hierarchical and Majority + Quorum Systems. + + + Performance Impact: + There is + practically no performance impact when removing a follower, since it + is not being automatically shut down (the effect of removal is that + the server's votes are no longer being counted). When adding a server, + there is no leader change and no noticeable performance disruption. + For details and graphs please see Figures 6, 7 and 8 in the paper. + + The most significant disruption will happen when a leader change + is caused, in one of the following cases: + + + + Leader is removed from the ensemble. + + + Leader's role is changed from participant to observer. + + + The port used by the leader to send transactions to others + (quorum port) is modified. + + + + In these cases we perform a leader hand-off where the old leader + nominates a new leader. The resulting unavailability is usually + shorter than when a leader crashes since detecting leader failure is + unnecessary and electing a new leader can usually be avoided during a + hand-off (see Figures 6 and 8 in the paper). + + When the client port of a server is modified, it does not drop + existing client connections. New connections to the server will have + to use the new client port. + + + Progress guarantees: + Up to the + invocation of the reconfig operation, a quorum of the old + configuration is required to be available and connected for ZooKeeper + to be able to make progress. Once reconfig is invoked, a quorum of + both the old and of the new configurations must be available. The + final transition happens once (a) the new configuration is activated, + and (b) all operations scheduled before the new configuration is + activated by the leader are committed. Once (a) and (b) happen, only a + quorum of the new configuration is required. Note, however, that + neither (a) nor (b) are visible to a client. Specifically, when a + reconfiguration operation commits, it only means that an activation + message was sent out by the leader. It does not necessarily mean that + a quorum of the new configuration got this message (which is required + in order to activate it) or that (b) has happened. If one wants to + make sure that both (a) and (b) has already occurred (for example, in + order to know that it is safe to shut down old servers that were + removed), one can simply invoke an update + (set-data, or some other quorum operation, but not + a sync) and wait for it to commit. An alternative + way to achieve this was to introduce another round to the + reconfiguration protocol (which, for simplicity and compatibility with + Zab, we decided to avoid). + +
      +
      + Incremental mode + The incremental mode allows adding and removing servers to the + current configuration. Multiple changes are allowed. For + example: + + + > reconfig -remove 3 -add + server.5=125.23.63.23:1234:1235;1236 + + + Both the add and the remove options get a list of comma separated + arguments (no spaces): + + + > reconfig -remove 3,4 -add + server.5=localhost:2111:2112;2113,6=localhost:2114:2115:observer;2116 + + + The format of the server statement is exactly the same as + described in the section + + and + includes the client port. Notice that here instead of "server.5=" you + can just say "5=". In the example above, if server 5 is already in the + system, but has different ports or is not an observer, it is updated + and once the configuration commits becomes an observer and starts + using these new ports. This is an easy way to turn participants into + observers and vise versa or change any of their ports, without + rebooting the server. + + ZooKeeper supports two types of Quorum Systems – the simple + Majority system (where the leader commits operations after receiving + ACKs from a majority of voters) and a more complex Hierarchical + system, where votes of different servers have different weights and + servers are divided into voting groups. Currently, incremental + reconfiguration is allowed only if the last proposed configuration + known to the leader uses a Majority Quorum System + (BadArgumentsException is thrown otherwise). + + Incremental mode - examples using the Java API: + leavingServers = new ArrayList(); +leavingServers.add("1"); +leavingServers.add("2"); +byte[] config = zk.reconfig(null, leavingServers, null, -1, new Stat());]]> + + leavingServers = new ArrayList(); +List joiningServers = new ArrayList(); +leavingServers.add("1"); +joiningServers.add("server.4=localhost:1234:1235;1236"); +byte[] config = zk.reconfig(joiningServers, leavingServers, null, -1, new Stat()); + +String configStr = new String(config); +System.out.println(configStr);]]> + There is also an asynchronous API, and an API accepting comma + separated Strings instead of List<String>. See + src/java/main/org/apache/zookeeper/ZooKeeper.java. + +
      +
      + Non-incremental mode + The second mode of reconfiguration is non-incremental, whereby a + client gives a complete specification of the new dynamic system + configuration. The new configuration can either be given in place or + read from a file: + + > reconfig -file newconfig.cfg + //newconfig.cfg is a dynamic config file, see + + + + > reconfig -members + server.1=125.23.63.23:2780:2783:participant;2791,server.2=125.23.63.24:2781:2784:participant;2792,server.3=125.23.63.25:2782:2785:participant;2793 + + + The new configuration may use a different Quorum System. For + example, you may specify a Hierarchical Quorum System even if the + current ensemble uses a Majority Quorum System. + + Bulk mode - example using the Java API: + newMembers = new ArrayList(); +newMembers.add("server.1=1111:1234:1235;1236"); +newMembers.add("server.2=1112:1237:1238;1239"); +newMembers.add("server.3=1114:1240:1241:observer;1242"); + +byte[] config = zk.reconfig(null, null, newMembers, -1, new Stat()); + +String configStr = new String(config); +System.out.println(configStr);]]> + There is also an asynchronous API, and an API accepting comma + separated String containing the new members instead of + List<String>. See + src/java/main/org/apache/zookeeper/ZooKeeper.java. + +
      +
      + Conditional reconfig + Sometimes (especially in non-incremental mode) a new proposed + configuration depends on what the client "believes" to be the current + configuration, and should be applied only to that configuration. + Specifically, the reconfig succeeds only if the + last configuration at the leader has the specified version. + + + reconfig -file -v ]]> + + In the previously listed Java examples, instead of -1 one could + specify a configuration version to condition the + reconfiguration. + +
      +
      + Error conditions + In addition to normal ZooKeeper error conditions, a + reconfiguration may fail for the following reasons: + + + + another reconfig is currently in progress + (ReconfigInProgress) + + + + the proposed change would leave the cluster with less than 2 + participants, in case standalone mode is enabled, or, if + standalone mode is disabled then its legal to remain with 1 or + more participants (BadArgumentsException) + + + + no quorum of the new configuration was connected and + up-to-date with the leader when the reconfiguration processing + began (NewConfigNoQuorum) + + + + + -v x + was specified, but the version + y + of the latest configuration is not + x + (BadVersionException) + + + + an incremental reconfiguration was requested but the last + configuration at the leader uses a Quorum System which is + different from the Majority system (BadArgumentsException) + + + + syntax error (BadArgumentsException) + + + I/O exception when reading the configuration from a file + (BadArgumentsException) + + + + Most of these are illustrated by test-cases in + ReconfigFailureCases.java. + +
      +
      + Additional comments + + Liveness: + To better understand + the difference between incremental and non-incremental + reconfiguration, suppose that client C1 adds server D to the system + while a different client C2 adds server E. With the non-incremental + mode, each client would first invoke config to find + out the current configuration, and then locally create a new list of + servers by adding its own suggested server. The new configuration can + then be submitted using the non-incremental + reconfig + command. After both reconfigurations + complete, only one of E or D will be added (not both), depending on + which client's request arrives second to the leader, overwriting the + previous configuration. The other client can repeat the process until + its change takes effect. This method guarantees system-wide progress + (i.e., for one of the clients), but does not ensure that every client + succeeds. To have more control C2 may request to only execute the + reconfiguration in case the version of the current configuration + hasn't changed, as explained in the section. In this way it may avoid blindly + overwriting the configuration of C1 if C1's configuration reached the + leader first. + + With incremental reconfiguration, both changes will take effect as + they are simply applied by the leader one after the other to the + current configuration, whatever that is (assuming that the second + reconfig request reaches the leader after it sends a commit message + for the first reconfig request -- currently the leader will refuse to + propose a reconfiguration if another one is already pending). Since + both clients are guaranteed to make progress, this method guarantees + stronger liveness. In practice, multiple concurrent reconfigurations + are probably rare. Non-incremental reconfiguration is currently the + only way to dynamically change the Quorum System. Incremental + configuration is currently only allowed with the Majority Quorum + System. + + + Changing an observer into a + follower: + + Clearly, changing a server that participates in + voting into an observer may fail if error (2) occurs, i.e., if fewer + than the minimal allowed number of participants would remain. However, + converting an observer into a participant may sometimes fail for a + more subtle reason: Suppose, for example, that the current + configuration is (A, B, C, D), where A is the leader, B and C are + followers and D is an observer. In addition, suppose that B has + crashed. If a reconfiguration is submitted where D is said to become a + follower, it will fail with error (3) since in this configuration, a + majority of voters in the new configuration (any 3 voters), must be + connected and up-to-date with the leader. An observer cannot + acknowledge the history prefix sent during reconfiguration, and + therefore it does not count towards these 3 required servers and the + reconfiguration will be aborted. In case this happens, a client can + achieve the same task by two reconfig commands: first invoke a + reconfig to remove D from the configuration and then invoke a second + command to add it back as a participant (follower). During the + intermediate state D is a non-voting follower and can ACK the state + transfer performed during the second reconfig comand. + +
      +
      +
      +
      + Rebalancing Client Connections + When a ZooKeeper cluster is started, if each client is given the same + connection string (list of servers), the client will randomly choose a + server in the list to connect to, which makes the expected number of + client connections per server the same for each of the servers. We + implemented a method that preserves this property when the set of servers + changes through reconfiguration. See Sections 4 and 5.1 in the paper. + + In order for the method to work, all clients must subscribe to + configuration changes (by setting a watch on /zookeeper/config either + directly or through the getConfig API command). When + the watch is triggered, the client should read the new configuration by + invoking sync and getConfig and if + the configuration is indeed new invoke the + updateServerList + API command. To avoid mass client + migration at the same time, it is better to have each client sleep a + random short period of time before invoking + updateServerList. + + A few examples can be found in: + StaticHostProviderTest.java + and + TestReconfig.cc + + Example (this is not a recipe, but a simplified example just to + explain the general idea): + + this.configVersion) { + hostList = config[1]; + try { + // the following command is not blocking but may cause the client to close the socket and + // migrate to a different server. In practice its better to wait a short period of time, chosen + // randomly, so that different clients migrate at different times + zk.updateServerList(hostList); + } catch (IOException e) { + System.err.println("Error updating server list"); + e.printStackTrace(); + } + this.configVersion = version; +} } }]]> +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperStarted.xml b/src/docs/src/documentation/content/xdocs/zookeeperStarted.xml new file mode 100644 index 00000000000..1846f653db1 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperStarted.xml @@ -0,0 +1,477 @@ + + + + +
      + ZooKeeper Getting Started Guide + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This guide contains detailed information about creating + distributed applications that use ZooKeeper. It discusses the basic + operations ZooKeeper supports, and how these can be used to build + higher-level abstractions. It contains solutions to common tasks, a + troubleshooting guide, and links to other information. + + + + +
      + Getting Started: Coordinating Distributed Applications with + ZooKeeper + + + This document contains information to get you started quickly with + ZooKeeper. It is aimed primarily at developers hoping to try it out, and + contains simple installation instructions for a single ZooKeeper server, a + few commands to verify that it is running, and a simple programming + example. Finally, as a convenience, there are a few sections regarding + more complicated installations, for example running replicated + deployments, and optimizing the transaction log. However for the complete + instructions for commercial deployments, please refer to the ZooKeeper + Administrator's Guide. + + +
      + Pre-requisites + + See + System Requirements + in the Admin guide. + +
      + +
      + Download + + To get a ZooKeeper distribution, download a recent + + stable + + release from one of the Apache Download + Mirrors. + +
      + +
      + Standalone Operation + + Setting up a ZooKeeper server in standalone mode is + straightforward. The server is contained in a single JAR file, + so installation consists of creating a configuration. + + + Once you've downloaded a stable ZooKeeper release unpack + it and cd to the root + + + To start ZooKeeper you need a configuration file. Here is a sample, + create it in conf/zoo.cfg: + + + + tickTime=2000 + dataDir=/var/lib/zookeeper + clientPort=2181 + + + This file can be called anything, but for the sake of this + discussion call + it conf/zoo.cfg. Change the + value of dataDir to specify an + existing (empty to start with) directory. Here are the meanings + for each of the fields: + + + + + + tickTime + + + + the basic time unit in milliseconds used by ZooKeeper. It is + used to do heartbeats and the minimum session timeout will be + twice the tickTime. + + + + + + + + + dataDir + + + + the location to store the in-memory database snapshots and, + unless specified otherwise, the transaction log of updates to the + database. + + + + + + + clientPort + + + + the port to listen for client connections + + + + + Now that you created the configuration file, you can start + ZooKeeper: + + + bin/zkServer.sh start + + ZooKeeper logs messages using log4j -- more detail + available in the + Logging + section of the Programmer's Guide. You will see log messages + coming to the console (default) and/or a log file depending on + the log4j configuration. + + + The steps outlined here run ZooKeeper in standalone mode. There is + no replication, so if ZooKeeper process fails, the service will go down. + This is fine for most development situations, but to run ZooKeeper in + replicated mode, please see Running Replicated + ZooKeeper. + +
      + +
      + Managing ZooKeeper Storage + For long running production systems ZooKeeper storage must + be managed externally (dataDir and logs). See the section on + maintenance + + for + more details. + +
      + +
      + Connecting to ZooKeeper + + Once ZooKeeper is running, you have several options for connection + to it: + + + + + Java: Use + + + bin/zkCli.sh -server 127.0.0.1:2181 + + This lets you perform simple, file-like operations. + + + + C: compile cli_mt + (multi-threaded) or cli_st (single-threaded) by running + make cli_mt + or make + cli_st + in + the src/c subdirectory in + the ZooKeeper sources. See the README contained within + src/c + for full details. + + + You can run the program + from src/c using: + + + LD_LIBRARY_PATH=. cli_mt 127.0.0.1:2181 + + or + + LD_LIBRARY_PATH=. cli_st 127.0.0.1:2181 + This will give you a simple shell to execute file + system like operations on ZooKeeper. + + + + Once you have connected, you should see something like: + + + + + From the shell, type help to get a listing of commands that can be executed from the client, as in: + + + + From here, you can try a few simple commands to get a feel for this simple command line interface. First, start by issuing the list command, as + in ls, yielding: + + + + Next, create a new znode by running create /zk_test my_data. This creates a new znode and associates the string "my_data" with the node. + You should see: + + + + Issue another ls / command to see what the directory looks like: + + + + + Notice that the zk_test directory has now been created. + + Next, verify that the data was associated with the znode by running the get command, as in: + + + + We can change the data associated with zk_test by issuing the set command, as in: + + + + + (Notice we did a get after setting the data and it did, indeed, change. + + Finally, let's delete the node by issuing: + + + + That's it for now. To explore more, continue with the rest of this document and see the Programmer's Guide. + +
      + +
      + Programming to ZooKeeper + + ZooKeeper has a Java bindings and C bindings. They are + functionally equivalent. The C bindings exist in two variants: single + threaded and multi-threaded. These differ only in how the messaging loop + is done. For more information, see the Programming + Examples in the ZooKeeper Programmer's Guide + for + sample code using of the different APIs. + +
      + +
      + Running Replicated ZooKeeper + + Running ZooKeeper in standalone mode is convenient for evaluation, + some development, and testing. But in production, you should run + ZooKeeper in replicated mode. A replicated group of servers in the same + application is called a quorum, and in replicated + mode, all servers in the quorum have copies of the same configuration + file. The file is similar to the one used in standalone mode, but with a + few differences. Here is an example: + + + + tickTime=2000 + dataDir=/var/lib/zookeeper + clientPort=2181 + initLimit=5 + syncLimit=2 + server.1=zoo1:2888:3888 + server.2=zoo2:2888:3888 + server.3=zoo3:2888:3888 + + + The new entry, initLimit is + timeouts ZooKeeper uses to limit the length of time the ZooKeeper + servers in quorum have to connect to a leader. The entry syncLimit + limits how far out of date a server can + be from a leader. + + + With both of these timeouts, you specify the unit of time using + tickTime. In this example, the timeout + for initLimit is 5 ticks at 2000 milleseconds a tick, or 10 + seconds. + + + The entries of the form server.X list the + servers that make up the ZooKeeper service. When the server starts up, + it knows which server it is by looking for the file + myid + in the data directory. That file has the + contains the server number, in ASCII. + + + Finally, note the two port numbers after each server + name: " 2888" and "3888". Peers use the former port to connect + to other peers. Such a connection is necessary so that peers + can communicate, for example, to agree upon the order of + updates. More specifically, a ZooKeeper server uses this port + to connect followers to the leader. When a new leader arises, a + follower opens a TCP connection to the leader using this + port. Because the default leader election also uses TCP, we + currently require another port for leader election. This is the + second port in the server entry. + + + + If you want to test multiple servers on a single + machine, specify the servername + as localhost with unique quorum & + leader election ports (i.e. 2888:3888, 2889:3889, 2890:3890 in + the example above) for each server.X in that server's config + file. Of course separate dataDirs and + distinct clientPorts are also necessary + (in the above replicated example, running on a + single localhost, you would still have + three config files). + + +
      + +
      + Other Optimizations + + There are a couple of other configuration parameters that can + greatly increase performance: + + + + + To get low latencies on updates it is important to + have a dedicated transaction log directory. By default + transaction logs are put in the same directory as the data + snapshots and myid file. The dataLogDir + parameters indicates a different directory to use for the + transaction logs. + + + + + + [tbd: what is the other config param?] + + + +
      +
      +
      diff --git a/src/docs/src/documentation/content/xdocs/zookeeperTutorial.xml b/src/docs/src/documentation/content/xdocs/zookeeperTutorial.xml new file mode 100644 index 00000000000..0d717ddb702 --- /dev/null +++ b/src/docs/src/documentation/content/xdocs/zookeeperTutorial.xml @@ -0,0 +1,696 @@ + + + + +
      + Programming with ZooKeeper - A basic tutorial + + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may + obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing permissions + and limitations under the License. + + + + + This article contains sample Java code for simple implementations of barrier + and consumers queues.. + + + + + +
      + Introduction + + In this tutorial, we show simple implementations of barriers and + producer-consumer queues using ZooKeeper. We call the respective classes Barrier and Queue. + These examples assume that you have at least one ZooKeeper server running. + + + Both primitives use the following common excerpt of code: + + + static ZooKeeper zk = null; + static Integer mutex; + + String root; + + SyncPrimitive(String address) { + if(zk == null){ + try { + System.out.println("Starting ZK:"); + zk = new ZooKeeper(address, 3000, this); + mutex = new Integer(-1); + System.out.println("Finished starting ZK: " + zk); + } catch (IOException e) { + System.out.println(e.toString()); + zk = null; + } + } + } + + synchronized public void process(WatchedEvent event) { + synchronized (mutex) { + mutex.notify(); + } + } + + + Both classes extend SyncPrimitive. In this way, we execute steps that are + common to all primitives in the constructor of SyncPrimitive. To keep the examples + simple, we create a ZooKeeper object the first time we instantiate either a barrier + object or a queue object, and we declare a static variable that is a reference + to this object. The subsequent instances of Barrier and Queue check whether a + ZooKeeper object exists. Alternatively, we could have the application creating a + ZooKeeper object and passing it to the constructor of Barrier and Queue. + + + We use the process() method to process notifications triggered due to watches. + In the following discussion, we present code that sets watches. A watch is internal + structure that enables ZooKeeper to notify a client of a change to a node. For example, + if a client is waiting for other clients to leave a barrier, then it can set a watch and + wait for modifications to a particular node, which can indicate that it is the end of the wait. + This point becomes clear once we go over the examples. + +
      + +
      + Barriers + + + A barrier is a primitive that enables a group of processes to synchronize the + beginning and the end of a computation. The general idea of this implementation + is to have a barrier node that serves the purpose of being a parent for individual + process nodes. Suppose that we call the barrier node "/b1". Each process "p" then + creates a node "/b1/p". Once enough processes have created their corresponding + nodes, joined processes can start the computation. + + + In this example, each process instantiates a Barrier object, and its constructor takes as parameters: + + + + the address of a ZooKeeper server (e.g., "zoo1.foo.com:2181") + + + the path of the barrier node on ZooKeeper (e.g., "/b1") + + + the size of the group of processes + + + + The constructor of Barrier passes the address of the Zookeeper server to the + constructor of the parent class. The parent class creates a ZooKeeper instance if + one does not exist. The constructor of Barrier then creates a + barrier node on ZooKeeper, which is the parent node of all process nodes, and + we call root (Note: This is not the ZooKeeper root "/"). + + + + /** + * Barrier constructor + * + * @param address + * @param root + * @param size + */ + Barrier(String address, String root, int size) { + super(address); + this.root = root; + this.size = size; + + // Create barrier node + if (zk != null) { + try { + Stat s = zk.exists(root, false); + if (s == null) { + zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + } catch (KeeperException e) { + System.out + .println("Keeper exception when instantiating queue: " + + e.toString()); + } catch (InterruptedException e) { + System.out.println("Interrupted exception"); + } + } + + // My node name + try { + name = new String(InetAddress.getLocalHost().getCanonicalHostName().toString()); + } catch (UnknownHostException e) { + System.out.println(e.toString()); + } + + } + + + To enter the barrier, a process calls enter(). The process creates a node under + the root to represent it, using its host name to form the node name. It then wait + until enough processes have entered the barrier. A process does it by checking + the number of children the root node has with "getChildren()", and waiting for + notifications in the case it does not have enough. To receive a notification when + there is a change to the root node, a process has to set a watch, and does it + through the call to "getChildren()". In the code, we have that "getChildren()" + has two parameters. The first one states the node to read from, and the second is + a boolean flag that enables the process to set a watch. In the code the flag is true. + + + + /** + * Join barrier + * + * @return + * @throws KeeperException + * @throws InterruptedException + */ + + boolean enter() throws KeeperException, InterruptedException{ + zk.create(root + "/" + name, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL_SEQUENTIAL); + while (true) { + synchronized (mutex) { + List<String> list = zk.getChildren(root, true); + + if (list.size() < size) { + mutex.wait(); + } else { + return true; + } + } + } + } + + + Note that enter() throws both KeeperException and InterruptedException, so it is + the responsibility of the application to catch and handle such exceptions. + + + + Once the computation is finished, a process calls leave() to leave the barrier. + First it deletes its corresponding node, and then it gets the children of the root + node. If there is at least one child, then it waits for a notification (obs: note + that the second parameter of the call to getChildren() is true, meaning that + ZooKeeper has to set a watch on the the root node). Upon reception of a notification, + it checks once more whether the root node has any children. + + + + /** + * Wait until all reach barrier + * + * @return + * @throws KeeperException + * @throws InterruptedException + */ + + boolean leave() throws KeeperException, InterruptedException{ + zk.delete(root + "/" + name, 0); + while (true) { + synchronized (mutex) { + List<String> list = zk.getChildren(root, true); + if (list.size() > 0) { + mutex.wait(); + } else { + return true; + } + } + } + } + } + +
      +
      + Producer-Consumer Queues + + A producer-consumer queue is a distributed data structure that groups of processes + use to generate and consume items. Producer processes create new elements and add + them to the queue. Consumer processes remove elements from the list, and process them. + In this implementation, the elements are simple integers. The queue is represented + by a root node, and to add an element to the queue, a producer process creates a new node, + a child of the root node. + + + + The following excerpt of code corresponds to the constructor of the object. As + with Barrier objects, it first calls the constructor of the parent class, SyncPrimitive, + that creates a ZooKeeper object if one doesn't exist. It then verifies if the root + node of the queue exists, and creates if it doesn't. + + + /** + * Constructor of producer-consumer queue + * + * @param address + * @param name + */ + Queue(String address, String name) { + super(address); + this.root = name; + // Create ZK node name + if (zk != null) { + try { + Stat s = zk.exists(root, false); + if (s == null) { + zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + } catch (KeeperException e) { + System.out + .println("Keeper exception when instantiating queue: " + + e.toString()); + } catch (InterruptedException e) { + System.out.println("Interrupted exception"); + } + } + } + + + + A producer process calls "produce()" to add an element to the queue, and passes + an integer as an argument. To add an element to the queue, the method creates a + new node using "create()", and uses the SEQUENCE flag to instruct ZooKeeper to + append the value of the sequencer counter associated to the root node. In this way, + we impose a total order on the elements of the queue, thus guaranteeing that the + oldest element of the queue is the next one consumed. + + + + /** + * Add element to the queue. + * + * @param i + * @return + */ + + boolean produce(int i) throws KeeperException, InterruptedException{ + ByteBuffer b = ByteBuffer.allocate(4); + byte[] value; + + // Add child with value i + b.putInt(i); + value = b.array(); + zk.create(root + "/element", value, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + + return true; + } + + + To consume an element, a consumer process obtains the children of the root node, + reads the node with smallest counter value, and returns the element. Note that + if there is a conflict, then one of the two contending processes won't be able to + delete the node and the delete operation will throw an exception. + + + + A call to getChildren() returns the list of children in lexicographic order. + As lexicographic order does not necessary follow the numerical order of the counter + values, we need to decide which element is the smallest. To decide which one has + the smallest counter value, we traverse the list, and remove the prefix "element" + from each one. + + + + /** + * Remove first element from the queue. + * + * @return + * @throws KeeperException + * @throws InterruptedException + */ + int consume() throws KeeperException, InterruptedException{ + int retvalue = -1; + Stat stat = null; + + // Get the first element available + while (true) { + synchronized (mutex) { + List<String> list = zk.getChildren(root, true); + if (list.size() == 0) { + System.out.println("Going to wait"); + mutex.wait(); + } else { + Integer min = new Integer(list.get(0).substring(7)); + for(String s : list){ + Integer tempValue = new Integer(s.substring(7)); + //System.out.println("Temporary value: " + tempValue); + if(tempValue < min) min = tempValue; + } + System.out.println("Temporary value: " + root + "/element" + min); + byte[] b = zk.getData(root + "/element" + min, + false, stat); + zk.delete(root + "/element" + min, 0); + ByteBuffer buffer = ByteBuffer.wrap(b); + retvalue = buffer.getInt(); + + return retvalue; + } + } + } + } + } + + +
      +
      + Complete Source Listing + + SyncPrimitive.Java + + import java.io.IOException; + import java.net.InetAddress; + import java.net.UnknownHostException; + import java.nio.ByteBuffer; + import java.util.List; + import java.util.Random; + + import org.apache.zookeeper.CreateMode; + import org.apache.zookeeper.KeeperException; + import org.apache.zookeeper.WatchedEvent; + import org.apache.zookeeper.Watcher; + import org.apache.zookeeper.ZooKeeper; + import org.apache.zookeeper.ZooDefs.Ids; + import org.apache.zookeeper.data.Stat; + + public class SyncPrimitive implements Watcher { + + static ZooKeeper zk = null; + static Integer mutex; + + String root; + + SyncPrimitive(String address) { + if(zk == null){ + try { + System.out.println("Starting ZK:"); + zk = new ZooKeeper(address, 3000, this); + mutex = new Integer(-1); + System.out.println("Finished starting ZK: " + zk); + } catch (IOException e) { + System.out.println(e.toString()); + zk = null; + } + } + //else mutex = new Integer(-1); + } + + synchronized public void process(WatchedEvent event) { + synchronized (mutex) { + //System.out.println("Process: " + event.getType()); + mutex.notify(); + } + } + + /** + * Barrier + */ + static public class Barrier extends SyncPrimitive { + int size; + String name; + + /** + * Barrier constructor + * + * @param address + * @param root + * @param size + */ + Barrier(String address, String root, int size) { + super(address); + this.root = root; + this.size = size; + + // Create barrier node + if (zk != null) { + try { + Stat s = zk.exists(root, false); + if (s == null) { + zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + } catch (KeeperException e) { + System.out + .println("Keeper exception when instantiating queue: " + + e.toString()); + } catch (InterruptedException e) { + System.out.println("Interrupted exception"); + } + } + + // My node name + try { + name = new String(InetAddress.getLocalHost().getCanonicalHostName().toString()); + } catch (UnknownHostException e) { + System.out.println(e.toString()); + } + + } + + /** + * Join barrier + * + * @return + * @throws KeeperException + * @throws InterruptedException + */ + + boolean enter() throws KeeperException, InterruptedException{ + zk.create(root + "/" + name, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL_SEQUENTIAL); + while (true) { + synchronized (mutex) { + List<String> list = zk.getChildren(root, true); + + if (list.size() < size) { + mutex.wait(); + } else { + return true; + } + } + } + } + + /** + * Wait until all reach barrier + * + * @return + * @throws KeeperException + * @throws InterruptedException + */ + + boolean leave() throws KeeperException, InterruptedException{ + zk.delete(root + "/" + name, 0); + while (true) { + synchronized (mutex) { + List<String> list = zk.getChildren(root, true); + if (list.size() > 0) { + mutex.wait(); + } else { + return true; + } + } + } + } + } + + /** + * Producer-Consumer queue + */ + static public class Queue extends SyncPrimitive { + + /** + * Constructor of producer-consumer queue + * + * @param address + * @param name + */ + Queue(String address, String name) { + super(address); + this.root = name; + // Create ZK node name + if (zk != null) { + try { + Stat s = zk.exists(root, false); + if (s == null) { + zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + } catch (KeeperException e) { + System.out + .println("Keeper exception when instantiating queue: " + + e.toString()); + } catch (InterruptedException e) { + System.out.println("Interrupted exception"); + } + } + } + + /** + * Add element to the queue. + * + * @param i + * @return + */ + + boolean produce(int i) throws KeeperException, InterruptedException{ + ByteBuffer b = ByteBuffer.allocate(4); + byte[] value; + + // Add child with value i + b.putInt(i); + value = b.array(); + zk.create(root + "/element", value, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + + return true; + } + + + /** + * Remove first element from the queue. + * + * @return + * @throws KeeperException + * @throws InterruptedException + */ + int consume() throws KeeperException, InterruptedException{ + int retvalue = -1; + Stat stat = null; + + // Get the first element available + while (true) { + synchronized (mutex) { + List<String> list = zk.getChildren(root, true); + if (list.size() == 0) { + System.out.println("Going to wait"); + mutex.wait(); + } else { + Integer min = new Integer(list.get(0).substring(7)); + for(String s : list){ + Integer tempValue = new Integer(s.substring(7)); + //System.out.println("Temporary value: " + tempValue); + if(tempValue < min) min = tempValue; + } + System.out.println("Temporary value: " + root + "/element" + min); + byte[] b = zk.getData(root + "/element" + min, + false, stat); + zk.delete(root + "/element" + min, 0); + ByteBuffer buffer = ByteBuffer.wrap(b); + retvalue = buffer.getInt(); + + return retvalue; + } + } + } + } + } + + public static void main(String args[]) { + if (args[0].equals("qTest")) + queueTest(args); + else + barrierTest(args); + + } + + public static void queueTest(String args[]) { + Queue q = new Queue(args[1], "/app1"); + + System.out.println("Input: " + args[1]); + int i; + Integer max = new Integer(args[2]); + + if (args[3].equals("p")) { + System.out.println("Producer"); + for (i = 0; i < max; i++) + try{ + q.produce(10 + i); + } catch (KeeperException e){ + + } catch (InterruptedException e){ + + } + } else { + System.out.println("Consumer"); + + for (i = 0; i < max; i++) { + try{ + int r = q.consume(); + System.out.println("Item: " + r); + } catch (KeeperException e){ + i--; + } catch (InterruptedException e){ + + } + } + } + } + + public static void barrierTest(String args[]) { + Barrier b = new Barrier(args[1], "/b1", new Integer(args[2])); + try{ + boolean flag = b.enter(); + System.out.println("Entered barrier: " + args[2]); + if(!flag) System.out.println("Error when entering the barrier"); + } catch (KeeperException e){ + + } catch (InterruptedException e){ + + } + + // Generate random integer + Random rand = new Random(); + int r = rand.nextInt(100); + // Loop for rand iterations + for (int i = 0; i < r; i++) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + + } + } + try{ + b.leave(); + } catch (KeeperException e){ + + } catch (InterruptedException e){ + + } + System.out.println("Left barrier"); + } + } + + +
      + +
      + + diff --git a/src/docs/src/documentation/resources/images/2pc.jpg b/src/docs/src/documentation/resources/images/2pc.jpg new file mode 100755 index 00000000000..fe4488fd9d8 Binary files /dev/null and b/src/docs/src/documentation/resources/images/2pc.jpg differ diff --git a/src/docs/src/documentation/resources/images/bk-overview.jpg b/src/docs/src/documentation/resources/images/bk-overview.jpg new file mode 100644 index 00000000000..6e12fb4f09f Binary files /dev/null and b/src/docs/src/documentation/resources/images/bk-overview.jpg differ diff --git a/src/docs/src/documentation/resources/images/favicon.ico b/src/docs/src/documentation/resources/images/favicon.ico new file mode 100644 index 00000000000..161bcf7841c Binary files /dev/null and b/src/docs/src/documentation/resources/images/favicon.ico differ diff --git a/src/docs/src/documentation/resources/images/hadoop-logo.jpg b/src/docs/src/documentation/resources/images/hadoop-logo.jpg new file mode 100644 index 00000000000..809525d9f15 Binary files /dev/null and b/src/docs/src/documentation/resources/images/hadoop-logo.jpg differ diff --git a/src/docs/src/documentation/resources/images/state_dia.dia b/src/docs/src/documentation/resources/images/state_dia.dia new file mode 100755 index 00000000000..4a58a00854e Binary files /dev/null and b/src/docs/src/documentation/resources/images/state_dia.dia differ diff --git a/src/docs/src/documentation/resources/images/state_dia.jpg b/src/docs/src/documentation/resources/images/state_dia.jpg new file mode 100755 index 00000000000..b6f4a8b068a Binary files /dev/null and b/src/docs/src/documentation/resources/images/state_dia.jpg differ diff --git a/src/docs/src/documentation/resources/images/zkarch.jpg b/src/docs/src/documentation/resources/images/zkarch.jpg new file mode 100644 index 00000000000..a0e5fccba6f Binary files /dev/null and b/src/docs/src/documentation/resources/images/zkarch.jpg differ diff --git a/src/docs/src/documentation/resources/images/zkcomponents.jpg b/src/docs/src/documentation/resources/images/zkcomponents.jpg new file mode 100644 index 00000000000..7690578575a Binary files /dev/null and b/src/docs/src/documentation/resources/images/zkcomponents.jpg differ diff --git a/src/docs/src/documentation/resources/images/zknamespace.jpg b/src/docs/src/documentation/resources/images/zknamespace.jpg new file mode 100644 index 00000000000..05534bc6605 Binary files /dev/null and b/src/docs/src/documentation/resources/images/zknamespace.jpg differ diff --git a/src/docs/src/documentation/resources/images/zkperfRW-3.2.jpg b/src/docs/src/documentation/resources/images/zkperfRW-3.2.jpg new file mode 100644 index 00000000000..594b50bb525 Binary files /dev/null and b/src/docs/src/documentation/resources/images/zkperfRW-3.2.jpg differ diff --git a/src/docs/src/documentation/resources/images/zkperfRW.jpg b/src/docs/src/documentation/resources/images/zkperfRW.jpg new file mode 100644 index 00000000000..ad3019f4195 Binary files /dev/null and b/src/docs/src/documentation/resources/images/zkperfRW.jpg differ diff --git a/src/docs/src/documentation/resources/images/zkperfreliability.jpg b/src/docs/src/documentation/resources/images/zkperfreliability.jpg new file mode 100644 index 00000000000..232bba80436 Binary files /dev/null and b/src/docs/src/documentation/resources/images/zkperfreliability.jpg differ diff --git a/src/docs/src/documentation/resources/images/zkservice.jpg b/src/docs/src/documentation/resources/images/zkservice.jpg new file mode 100644 index 00000000000..1ec91543f63 Binary files /dev/null and b/src/docs/src/documentation/resources/images/zkservice.jpg differ diff --git a/src/docs/src/documentation/resources/images/zookeeper_small.gif b/src/docs/src/documentation/resources/images/zookeeper_small.gif new file mode 100644 index 00000000000..4e8014f8fe7 Binary files /dev/null and b/src/docs/src/documentation/resources/images/zookeeper_small.gif differ diff --git a/src/docs/src/documentation/skinconf.xml b/src/docs/src/documentation/skinconf.xml new file mode 100644 index 00000000000..c9f0ca03dd9 --- /dev/null +++ b/src/docs/src/documentation/skinconf.xml @@ -0,0 +1,360 @@ + + + + + + + + + + + + true + + false + + true + + true + + + true + + + true + + + true + + + false + + + true + + + ZooKeeper + ZooKeeper: distributed coordination + http://zookeeper.apache.org/ + images/zookeeper_small.gif + + + Hadoop + Apache Hadoop + http://hadoop.apache.org/ + images/hadoop-logo.jpg + + + + + + + images/favicon.ico + + + 2008-2013 + The Apache Software Foundation. + http://www.apache.org/licenses/ + + + + + + + + + + + + + + + + + + + p.quote { + margin-left: 2em; + padding: .5em; + background-color: #f0f0f0; + font-family: monospace; + } + + pre.code { + margin-left: 0em; + padding: 0.5em; + background-color: #f0f0f0; + font-family: monospace; + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1in + 1in + 1.25in + 1in + + + + false + + + false + + + + + + Built with Apache Forrest + http://forrest.apache.org/ + images/built-with-forrest-button.png + 88 + 31 + + + + + + diff --git a/src/docs/status.xml b/src/docs/status.xml new file mode 100644 index 00000000000..f421c454ba5 --- /dev/null +++ b/src/docs/status.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + Initial Import + + + + + + + + + Customize this template project with your project's details. This + TODO list is generated from 'status.xml'. + + + Add lots of content. XML content goes in + src/documentation/content/xdocs, or wherever the + ${project.xdocs-dir} + property (set in + forrest.properties) points. + + + Mail + forrest-dev@xml.apache.org + + with feedback. + + + + + + diff --git a/src/java/OldChangeLog b/src/java/OldChangeLog new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/java/lib/cobertura/README.txt b/src/java/lib/cobertura/README.txt new file mode 100644 index 00000000000..f5ba88f1feb --- /dev/null +++ b/src/java/lib/cobertura/README.txt @@ -0,0 +1,3 @@ +Download the cobertura binary from the following location and unpack it into this directory. Run "cobertura-report" target from build.xml to generate coverage report. + +http://cobertura.sourceforge.net/download.html diff --git a/src/java/lib/javacc.LICENSE.txt b/src/java/lib/javacc.LICENSE.txt new file mode 100644 index 00000000000..2b7a7d7b0be --- /dev/null +++ b/src/java/lib/javacc.LICENSE.txt @@ -0,0 +1,26 @@ +Copyright (c) 2006, Sun Microsystems, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Sun Microsystems, Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/java/lib/jdiff/zookeeper_3.1.1.xml b/src/java/lib/jdiff/zookeeper_3.1.1.xml new file mode 100644 index 00000000000..12e8f9c8082 --- /dev/null +++ b/src/java/lib/jdiff/zookeeper_3.1.1.xml @@ -0,0 +1,2717 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • --short - prints a short version string "1.2.3" +
    • --revision - prints a short version string with the SVN + repository revision "1.2.3-94" +
    • --full - prints the revision and the build date +
    ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The client object will pick an arbitrary server and try to connect to it. + If failed, it will try the next one in the list, until a connection is + established, or all the servers have been tried. + + @param host + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + + @throws IOException in cases of network failure]]> + + + + + + + The client object will pick an arbitrary server and try to connect to it. + If failed, it will try the next one in the list, until a connection is + established, or all the servers have been tried. +

    + Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + client connection, these values must be passed as sessionId and + sessionPasswd respectively if reconnecting. Otherwise, if not + reconnecting, use the other constructor which does not require these + parameters. + + @param host + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param sessionId + specific session id to use if reconnecting + @param sessionPasswd + password for this session + + @throws IOException in cases of network failure]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The flags argument specifies whether the created node will be ephemeral + or not. +

    + An ephemeral node will be removed by the ZooKeeper automatically when the + session associated with the creation of the node expires. +

    + The flags argument can also specify to create a sequential node. The + actual path name of a sequential node will be the given path plus a + suffix "_i" where i is the current sequential number of the node. Once + such a node is created, the sequential number will be incremented by one. +

    + If a node with the same actual path already exists in the ZooKeeper, a + KeeperException with error code KeeperException.NodeExists will be + thrown. Note that since a different actual path is used for each + invocation of creating sequential node with the same path argument, the + call will never throw "file exists" KeeperException. +

    + If the parent node does not exist in the ZooKeeper, a KeeperException + with error code KeeperException.NoNode will be thrown. +

    + An ephemeral node cannot have children. If the parent node of the given + path is ephemeral, a KeeperException with error code + KeeperException.NoChildrenForEphemerals will be thrown. +

    + This operation, if successful, will trigger all the watches left on the + node of the given path by exists and getData API calls, and the watches + left on the parent node by getChildren API calls. +

    + If a node is created successfully, the ZooKeeper server will trigger the + watches on the path left by exists calls, and the watches on the parent + of the node by getChildren calls. +

    + The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperExecption to be thrown. + + @param path + the path for the node + @param data + the initial data for the node + @param acl + the acl for the node + @param flags + specifying whether the node to be created is ephemeral + and/or sequential + @return the actual path of the created node + @throws KeeperException if the server returns a non-zero error code + @throws org.apache.zookeeper.KeeperException.InvalidACLException if the ACL is invalid + @throws InterruptedException if the transaction is interrupted + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + , CreateMode)]]> + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if the nodes does not exist. +

    + A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. +

    + A KeeperException with error code KeeperException.NotEmpty will be thrown + if the node has children. +

    + This operation, if successful, will trigger all the watches on the node + of the given path left by exists API calls, and the watches on the parent + node left by getChildren API calls. + + @param path + the path of the node to be deleted. + @param version + the expected node version. + @throws InterruptedException IF the server transaction is interrupted + @throws KeeperException If the server signals an error with a non-zero return code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch will be + triggered by a successful operation that creates/delete the node or sets + the data on the node. + + @param path the node path + @param watcher explicit watcher + @return the stat of the node of the given path; return null if no such a + node exists. + @throws KeeperException If the server signals an error + @throws InterruptedException If the server transaction is interrupted. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch will be + triggered by a successful operation that creates/delete the node or sets + the data on the node. + + @param path + the node path + @param watch + whether need to watch this node + @return the stat of the node of the given path; return null if no such a + node exists. + @throws KeeperException If the server signals an error + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is + thrown), a watch will be left on the node with the given path. The watch + will be triggered by a successful operation that sets data on the node, or + deletes the node. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path the given path + @param watcher explicit watcher + @param stat the stat of the node + @return the data of the node + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + If the watch is true and the call is successful (no exception is + thrown), a watch will be left on the node with the given path. The watch + will be triggered by a successful operation that sets data on the node, or + deletes the node. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path the given path + @param watch whether need to watch this node + @param stat the stat of the node + @return the data of the node + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This operation, if successful, will trigger all the watches on the node + of the given path left by getData calls. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. +

    + A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. +

    + The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperExecption to be thrown. + + @param path + the path of the node + @param data + the data to set + @param version + the expected matching version + @return the state of the node + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + the given path for the node + @param stat + the stat of the node will be copied to this parameter. + @return the ACL array of the given node. + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. +

    + A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. + + @param path + @param acl + @param version + @return the stat of the node. + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

    + The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + @param watcher explicit watcher + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

    + The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + @param watch + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Once a connection to a server is established, a session ID is assigned to the + client. The client will send heart beats to the server periodically to keep + the session valid. +

    + The application can call ZooKeeper APIs through a client as long as the + session ID of the client remains valid. +

    + If for some reason, the client fails to send heart beats to the server for a + prolonged period of time (exceeding the sessionTimeout value, for instance), + the server will expire the session, and the session ID will become invalid. + The client object will no longer be usable. To make ZooKeeper API calls, the + application must create a new client object. +

    + If the ZooKeeper server the client currently connects to fails or otherwise + does not respond, the client will automatically try to connect to another + server before its session ID expires. If successful, the application can + continue to use the client. +

    + Some successful ZooKeeper API calls can leave watches on the "data nodes" in + the ZooKeeper server. Other successful ZooKeeper API calls can trigger those + watches. Once a watch is triggered, an event will be delivered to the client + which left the watch at the first place. Each watch can be triggered only + once. Thus, up to one event will be delivered to a client for every watch it + leaves. +

    + A client needs an object of a class implementing Watcher interface for + processing the events delivered to the client. + + When a client drops current connection and re-connects to a server, all the + existing watches are considered as being triggered but the undelivered events + are lost. To emulate this, the client will generate a special event to tell + the event handler a connection has been dropped. This special event has type + EventNone and state sKeeperStateDisconnected.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/lib/jdiff/zookeeper_3.5.2-alpha-SNAPSHOT.xml b/src/java/lib/jdiff/zookeeper_3.5.2-alpha-SNAPSHOT.xml new file mode 100644 index 00000000000..791c648f99d --- /dev/null +++ b/src/java/lib/jdiff/zookeeper_3.5.2-alpha-SNAPSHOT.xml @@ -0,0 +1,5782 @@ + + + + + + + + + + + + + + ZooKeeper provides asynchronous version as equivalent to synchronous APIs.]]> + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

    + On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

      +
    • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
    • +
    + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param acl ACL Id in + {@link org.apache.zookeeper.ZooDefs.Ids}. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

    + On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

      +
    • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
    • +
    + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param children An unordered array of children of the node on + given path.]]> +
    +
    + + + +
    + + + + + + + + + + + + name and path are usually + equal, unless a sequential node has been created. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> + + + + + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

    + On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

      +
    • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
    • +
    + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param data The {@link org.apache.zookeeper.server.DataNode#data} + of the node. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> +
    +
    + + + +
    + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. + All opResults are + non-{@link org.apache.zookeeper.OpResult.ErrorResult}, + +

    + On failure, rc is a failure code in + {@link org.apache.zookeeper.KeeperException.Code}. + All opResults are + {@link org.apache.zookeeper.OpResult.ErrorResult}. + All operations will be rollback-ed even if operations + before the failing one were successful. + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param opResults The list of results. + One result for each operation, + and the order matches that of input.]]> + + + + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

    + On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

      +
    • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
    • +
    • + {@link org.apache.zookeeper.KeeperException.Code#BADVERSION} + - The given version doesn't match the node's version + for some API calls. +
    • +
    + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> +
    +
    + + + +
    + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

    + On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

      +
    • + {@link org.apache.zookeeper.KeeperException.Code#NODEEXISTS} + - The node on give path already exists for some API calls. +
    • +
    • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
    • +
    • + {@link + org.apache.zookeeper.KeeperException.Code#NOCHILDRENFOREPHEMERALS} + - an ephemeral node cannot have children. There is discussion in + community. It might be changed in the future. +
    • +
    + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param name The name of the Znode that was created. + On success, name and path are usually + equal, unless a sequential node has been created.]]> +
    +
    + + + +
    + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

    + On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

      +
    • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
    • +
    • + {@link org.apache.zookeeper.KeeperException.Code#BADVERSION} + - The given version doesn't match the node's version + for some API calls. +
    • +
    • + {@link org.apache.zookeeper.KeeperException.Code#NOTEMPTY} + - the node has children and some API calls cannnot succeed, + e.g. {@link + org.apache.zookeeper.ZooKeeper#delete(String, int, + org.apache.zookeeper.AsyncCallback.VoidCallback, Object)}. +
    • +
    + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls.]]> +
    +
    + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + null. + @param memoryLimit virtual memory limit + @return a String[] with the ulimit command arguments or + null if we are running on a non *nix platform or + if the limit is unspecified.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Shell interface. + @param cmd shell command to execute. + @return the output of the executed command.]]> + + + + + + + + + Shell interface. + @param env the map of environment key=value + @param cmd shell command to execute. + @param timeout time in milliseconds after which script should be marked timeout + @return the output of the executed command.o]]> + + + + + + + + Shell interface. + @param env the map of environment key=value + @param cmd shell command to execute. + @return the output of the executed command.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Shell can be used to run unix commands like du or + df. It also offers facilities to gate commands by + time-intervals.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ShellCommandExecutorshould be used in cases where the output + of the command needs no explicit parsing and where the command, working + directory and the environment remains unchanged. The output of the command + is stored as-is and is expected to be small.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  • --short - prints a short version string "1.2.3" +
  • --revision - prints a short version string with the SVN + repository revision "1.2.3-94" +
  • --full - prints the revision and the build date +
]]> + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Important: All versions, of all nodes, under the given node are deleted. +

+ If there is an error with deleting one of the sub-nodes in the tree, + this operation would abort and would be the responsibility of the app to handle the same. + + See {@link #delete(String, int)} for more details. + + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + Important: All versions, of all nodes, under the given node are deleted. +

+ If there is an error with deleting one of the sub-nodes in the tree, + this operation would abort and would be the responsibility of the app to handle the same. +

+ @param zk the zookeeper handle + @param pathRoot the path to be deleted + @param cb call back method + @param ctx the context the callback method is called with + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + Important: This is not an atomic snapshot of the tree ever, but the + state as it exists across multiple RPCs from zkClient to the ensemble. + For practical purposes, it is suggested to bring the clients to the ensemble + down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior. + + @param zk the zookeeper handle + @param pathRoot The znode path, for which the entire subtree needs to be listed. + @throws InterruptedException + @throws KeeperException]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

+ The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed. +

+ Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + + @throws IOException + in cases of network failure + @throws IllegalArgumentException + if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

+ The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed. +

+ Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

+ For backward compatibility, there is another version + {@link #ZooKeeper(String, int, Watcher, boolean)} which uses + default {@link StaticHostProvider} + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + @param aHostProvider + use this as HostProvider to enable custom behaviour. + + @throws IOException + in cases of network failure + @throws IllegalArgumentException + if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

+ The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed. +

+ Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

+ + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + + @throws IOException + in cases of network failure + @throws IllegalArgumentException + if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

+ The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). +

+ Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

+ Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + client connection, these values must be passed as sessionId and + sessionPasswd respectively if reconnecting. Otherwise, if not + reconnecting, use the other constructor which does not require these + parameters. + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param sessionId + specific session id to use if reconnecting + @param sessionPasswd + password for this session + + @throws IOException in cases of network failure + @throws IllegalArgumentException if an invalid chroot path is specified + @throws IllegalArgumentException for an invalid list of ZooKeeper hosts]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

+ The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). +

+ Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

+ Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + client connection, these values must be passed as sessionId and + sessionPasswd respectively if reconnecting. Otherwise, if not + reconnecting, use the other constructor which does not require these + parameters. +

+ For backward compatibility, there is another version + {@link #ZooKeeper(String, int, Watcher, long, byte[], boolean)} which uses + default {@link StaticHostProvider} + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param sessionId + specific session id to use if reconnecting + @param sessionPasswd + password for this session + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + @param aHostProvider + use this as HostProvider to enable custom behaviour. + @throws IOException in cases of network failure + @throws IllegalArgumentException if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

+ The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). +

+ Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

+ Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + client connection, these values must be passed as sessionId and + sessionPasswd respectively if reconnecting. Otherwise, if not + reconnecting, use the other constructor which does not require these + parameters. +

+ This constructor uses a StaticHostProvider; there is another one + to enable custom behaviour. + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param sessionId + specific session id to use if reconnecting + @param sessionPasswd + password for this session + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + @throws IOException in cases of network failure + @throws IllegalArgumentException if an invalid chroot path is specified]]> + + + + + + + + The function invokes a + probabilistic load-balancing algorithm which may cause the client to disconnect from + its current host with the goal to achieve expected uniform number of connections per server + in the new list. In case the current host to which the client is connected is not in the new + list this call will always cause the connection to be dropped. Otherwise, the decision + is based on whether the number of servers has increased or decreased and by how much. + For example, if the previous connection string contained 3 hosts and now the list contains + these 3 hosts and 2 more hosts, 40% of clients connected to each of the 3 hosts will + move to one of the new hosts in order to balance the load. The algorithm will disconnect + from the current host with probability 0.4 and in this case cause the client to connect + to one of the 2 new hosts, chosen at random. +

+ If the connection is dropped, the client moves to a special mode "reconfigMode" where he chooses + a new server to connect to using the probabilistic algorithm. After finding a server, + or exhausting all servers in the new list after trying all of them and failing to connect, + the client moves back to the normal mode of operation where it will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + + @throws IOException in cases of network failure]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The flags argument specifies whether the created node will be ephemeral + or not. +

+ An ephemeral node will be removed by the ZooKeeper automatically when the + session associated with the creation of the node expires. +

+ The flags argument can also specify to create a sequential node. The + actual path name of a sequential node will be the given path plus a + suffix "i" where i is the current sequential number of the node. The sequence + number is always fixed length of 10 digits, 0 padded. Once + such a node is created, the sequential number will be incremented by one. +

+ If a node with the same actual path already exists in the ZooKeeper, a + KeeperException with error code KeeperException.NodeExists will be + thrown. Note that since a different actual path is used for each + invocation of creating sequential node with the same path argument, the + call will never throw "file exists" KeeperException. +

+ If the parent node does not exist in the ZooKeeper, a KeeperException + with error code KeeperException.NoNode will be thrown. +

+ An ephemeral node cannot have children. If the parent node of the given + path is ephemeral, a KeeperException with error code + KeeperException.NoChildrenForEphemerals will be thrown. +

+ This operation, if successful, will trigger all the watches left on the + node of the given path by exists and getData API calls, and the watches + left on the parent node by getChildren API calls. +

+ If a node is created successfully, the ZooKeeper server will trigger the + watches on the path left by exists calls, and the watches on the parent + of the node by getChildren calls. +

+ The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperExecption to be thrown. + + @param path + the path for the node + @param data + the initial data for the node + @param acl + the acl for the node + @param createMode + specifying whether the node to be created is ephemeral + and/or sequential + @return the actual path of the created node + @throws KeeperException if the server returns a non-zero error code + @throws KeeperException.InvalidACLException if the ACL is invalid, null, or empty + @throws InterruptedException if the transaction is interrupted + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + The flags argument specifies whether the created node will be ephemeral + or not. +

+ An ephemeral node will be removed by the ZooKeeper automatically when the + session associated with the creation of the node expires. +

+ The flags argument can also specify to create a sequential node. The + actual path name of a sequential node will be the given path plus a + suffix "i" where i is the current sequential number of the node. The sequence + number is always fixed length of 10 digits, 0 padded. Once + such a node is created, the sequential number will be incremented by one. +

+ If a node with the same actual path already exists in the ZooKeeper, a + KeeperException with error code KeeperException.NodeExists will be + thrown. Note that since a different actual path is used for each + invocation of creating sequential node with the same path argument, the + call will never throw "file exists" KeeperException. +

+ If the parent node does not exist in the ZooKeeper, a KeeperException + with error code KeeperException.NoNode will be thrown. +

+ An ephemeral node cannot have children. If the parent node of the given + path is ephemeral, a KeeperException with error code + KeeperException.NoChildrenForEphemerals will be thrown. +

+ This operation, if successful, will trigger all the watches left on the + node of the given path by exists and getData API calls, and the watches + left on the parent node by getChildren API calls. +

+ If a node is created successfully, the ZooKeeper server will trigger the + watches on the path left by exists calls, and the watches on the parent + of the node by getChildren calls. +

+ The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperExecption to be thrown. + + @param path + the path for the node + @param data + the initial data for the node + @param acl + the acl for the node + @param createMode + specifying whether the node to be created is ephemeral + and/or sequential + @param stat + The output Stat object. + @return the actual path of the created node + @throws KeeperException if the server returns a non-zero error code + @throws KeeperException.InvalidACLException if the ACL is invalid, null, or empty + @throws InterruptedException if the transaction is interrupted + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if the nodes does not exist. +

+ A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. +

+ A KeeperException with error code KeeperException.NotEmpty will be thrown + if the node has children. +

+ This operation, if successful, will trigger all the watches on the node + of the given path left by exists API calls, and the watches on the parent + node left by getChildren API calls. + + @param path + the path of the node to be deleted. + @param version + the expected node version. + @throws InterruptedException IF the server transaction is interrupted + @throws KeeperException If the server signals an error with a non-zero + return code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + On success, a list of results is returned. + On failure, an exception is raised which contains partial results and + error details, see {@link KeeperException#getResults} +

+ Note: The maximum allowable size of all of the data arrays in all of + the setData operations in this single request is typically 1 MB + (1,048,576 bytes). This limit is specified on the server via + jute.maxbuffer. + Requests larger than this will cause a KeeperException to be + thrown. + + @param ops An iterable that contains the operations to be done. + These should be created using the factory methods on {@link Op}. + @return A list of results, one for each input Op, the order of + which exactly matches the order of the ops input + operations. + @throws InterruptedException If the operation was interrupted. + The operation may or may not have succeeded, but will not have + partially succeeded if this exception is thrown. + @throws KeeperException If the operation could not be completed + due to some error in doing one of the specified ops. + @throws IllegalArgumentException if an invalid path is specified + + @since 3.4.0]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch will be + triggered by a successful operation that creates/delete the node or sets + the data on the node. + + @param path the node path + @param watcher explicit watcher + @return the stat of the node of the given path; return null if no such a + node exists. + @throws KeeperException If the server signals an error + @throws InterruptedException If the server transaction is interrupted. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch will be + triggered by a successful operation that creates/delete the node or sets + the data on the node. + + @param path + the node path + @param watch + whether need to watch this node + @return the stat of the node of the given path; return null if no such a + node exists. + @throws KeeperException If the server signals an error + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is + thrown), a watch will be left on the node with the given path. The watch + will be triggered by a successful operation that sets data on the node, or + deletes the node. +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path the given path + @param watcher explicit watcher + @param stat the stat of the node + @return the data of the node + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + If the watch is true and the call is successful (no exception is + thrown), a watch will be left on the node with the given path. The watch + will be triggered by a successful operation that sets data on the node, or + deletes the node. +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path the given path + @param watch whether need to watch this node + @param stat the stat of the node + @return the data of the node + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is + thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch + will be triggered by a successful reconfig operation +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if the configuration node doesn't exists. + + @param watcher explicit watcher + @param stat the stat of the configuration node ZooDefs.CONFIG_NODE + @return configuration data stored in ZooDefs.CONFIG_NODE + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + If the watch is true and the call is successful (no exception is + thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch + will be triggered by a successful reconfig operation +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param watch whether need to watch this node + @param stat the stat of the configuration node ZooDefs.CONFIG_NODE + @return configuration data stored in ZooDefs.CONFIG_NODE + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This operation, if successful, will trigger all the watches on the node + of the given path left by getData calls. +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. +

+ A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. +

+ The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperException to be thrown. + + @param path + the path of the node + @param data + the data to set + @param version + the expected matching version + @return the state of the node + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + the given path for the node + @param stat + the stat of the node will be copied to this parameter if + not null. + @return the ACL array of the given node. + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. +

+ A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. + + @param path + @param acl + @param version + @return the stat of the node. + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

+ The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + @param watcher explicit watcher + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

+ The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + @param watch + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

+ The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @since 3.3.0 + + @param path + @param watcher explicit watcher + @param stat stat of the znode designated by path + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

+ The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

+ A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @since 3.3.0 + + @param path + @param watch + @param stat stat of the znode designated by path + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero + error code.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Watcher shouldn't be null. A successful call guarantees that, the + removed watcher won't be triggered. +

+ + @param path + - the path of the node + @param watcher + - a concrete watcher + @param watcherType + - the type of watcher to be removed + @param local + - whether the watcher can be removed locally when there is no + server connection + @throws InterruptedException + if the server transaction is interrupted. + @throws KeeperException.NoWatcherException + if no watcher exists that match the specified parameters + @throws KeeperException + if the server signals an error with a non-zero error code. + @throws IllegalArgumentException + if any of the following is true: +
    +
  • {@code path} is invalid +
  • {@code watcher} is null +
+ + @since 3.5.0]]> +
+
+ + + + + + + + + + + + + + + + + + + + A successful call guarantees that, the removed watchers won't be + triggered. +

+ + @param path + - the path of the node + @param watcherType + - the type of watcher to be removed + @param local + - whether watches can be removed locally when there is no + server connection + @throws InterruptedException + if the server transaction is interrupted. + @throws KeeperException.NoWatcherException + if no watcher exists that match the specified parameters + @throws KeeperException + if the server signals an error with a non-zero error code. + @throws IllegalArgumentException + if an invalid {@code path} is specified + + @since 3.5.0]]> +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Once a connection to a server is established, a session ID is assigned to the + client. The client will send heart beats to the server periodically to keep + the session valid. +

+ The application can call ZooKeeper APIs through a client as long as the + session ID of the client remains valid. +

+ If for some reason, the client fails to send heart beats to the server for a + prolonged period of time (exceeding the sessionTimeout value, for instance), + the server will expire the session, and the session ID will become invalid. + The client object will no longer be usable. To make ZooKeeper API calls, the + application must create a new client object. +

+ If the ZooKeeper server the client currently connects to fails or otherwise + does not respond, the client will automatically try to connect to another + server before its session ID expires. If successful, the application can + continue to use the client. +

+ The ZooKeeper API methods are either synchronous or asynchronous. Synchronous + methods blocks until the server has responded. Asynchronous methods just queue + the request for sending and return immediately. They take a callback object that + will be executed either on successful execution of the request or on error with + an appropriate return code (rc) indicating the error. +

+ Some successful ZooKeeper API calls can leave watches on the "data nodes" in + the ZooKeeper server. Other successful ZooKeeper API calls can trigger those + watches. Once a watch is triggered, an event will be delivered to the client + which left the watch at the first place. Each watch can be triggered only + once. Thus, up to one event will be delivered to a client for every watch it + leaves. +

+ A client needs an object of a class implementing Watcher interface for + processing the events delivered to the client. + + When a client drops current connection and re-connects to a server, all the + existing watches are considered as being triggered but the undelivered events + are lost. To emulate this, the client will generate a special event to tell + the event handler a connection has been dropped. This special event has type + EventNone and state sKeeperStateDisconnected.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/lib/jdiff/zookeeper_3.6.0-SNAPSHOT.xml b/src/java/lib/jdiff/zookeeper_3.6.0-SNAPSHOT.xml new file mode 100644 index 00000000000..5c27201406d --- /dev/null +++ b/src/java/lib/jdiff/zookeeper_3.6.0-SNAPSHOT.xml @@ -0,0 +1,5782 @@ + + + + + + + + + + + + + + ZooKeeper provides asynchronous version as equivalent to synchronous APIs.]]> + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

+ On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

    +
  • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
  • +
+ + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param acl ACL Id in + {@link org.apache.zookeeper.ZooDefs.Ids}. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

+ On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

    +
  • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
  • +
+ + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param children An unordered array of children of the node on + given path.]]> +
+
+ + + +
+ + + + + + + + + + + + name and path are usually + equal, unless a sequential node has been created. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> + + + + + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

+ On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

    +
  • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
  • +
+ + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param data The {@link org.apache.zookeeper.server.DataNode#data} + of the node. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> +
+
+ + + +
+ + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. + All opResults are + non-{@link org.apache.zookeeper.OpResult.ErrorResult}, + +

+ On failure, rc is a failure code in + {@link org.apache.zookeeper.KeeperException.Code}. + All opResults are + {@link org.apache.zookeeper.OpResult.ErrorResult}. + All operations will be rollback-ed even if operations + before the failing one were successful. + + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param opResults The list of results. + One result for each operation, + and the order matches that of input.]]> + + + + + + + + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

+ On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

    +
  • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
  • +
  • + {@link org.apache.zookeeper.KeeperException.Code#BADVERSION} + - The given version doesn't match the node's version + for some API calls. +
  • +
+ + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param stat {@link org.apache.zookeeper.data.Stat} object of + the node on given path.]]> +
+
+ + + +
+ + + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

+ On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

    +
  • + {@link org.apache.zookeeper.KeeperException.Code#NODEEXISTS} + - The node on give path already exists for some API calls. +
  • +
  • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
  • +
  • + {@link + org.apache.zookeeper.KeeperException.Code#NOCHILDRENFOREPHEMERALS} + - an ephemeral node cannot have children. There is discussion in + community. It might be changed in the future. +
  • +
+ + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls. + @param name The name of the Znode that was created. + On success, name and path are usually + equal, unless a sequential node has been created.]]> +
+
+ + + +
+ + + + + + + + + + + On success, rc is + {@link org.apache.zookeeper.KeeperException.Code#OK}. +

+ On failure, rc is set to the corresponding failure code in + {@link org.apache.zookeeper.KeeperException}. +

    +
  • + {@link org.apache.zookeeper.KeeperException.Code#NONODE} + - The node on given path doesn't exist for some API calls. +
  • +
  • + {@link org.apache.zookeeper.KeeperException.Code#BADVERSION} + - The given version doesn't match the node's version + for some API calls. +
  • +
  • + {@link org.apache.zookeeper.KeeperException.Code#NOTEMPTY} + - the node has children and some API calls cannnot succeed, + e.g. {@link + org.apache.zookeeper.ZooKeeper#delete(String, int, + org.apache.zookeeper.AsyncCallback.VoidCallback, Object)}. +
  • +
+ + @param rc The return code or the result of the call. + @param path The path that we passed to asynchronous calls. + @param ctx Whatever context object that we passed to + asynchronous calls.]]> +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + null. + @param memoryLimit virtual memory limit + @return a String[] with the ulimit command arguments or + null if we are running on a non *nix platform or + if the limit is unspecified.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Shell interface. + @param cmd shell command to execute. + @return the output of the executed command.]]> + + + + + + + + + Shell interface. + @param env the map of environment key=value + @param cmd shell command to execute. + @param timeout time in milliseconds after which script should be marked timeout + @return the output of the executed command.o]]> + + + + + + + + Shell interface. + @param env the map of environment key=value + @param cmd shell command to execute. + @return the output of the executed command.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Shell can be used to run unix commands like du or + df. It also offers facilities to gate commands by + time-intervals.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ShellCommandExecutorshould be used in cases where the output + of the command needs no explicit parsing and where the command, working + directory and the environment remains unchanged. The output of the command + is stored as-is and is expected to be small.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  • --short - prints a short version string "1.2.3" +
  • --revision - prints a short version string with the SVN + repository revision "1.2.3-94" +
  • --full - prints the revision and the build date + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Important: All versions, of all nodes, under the given node are deleted. +

    + If there is an error with deleting one of the sub-nodes in the tree, + this operation would abort and would be the responsibility of the app to handle the same. + + See {@link #delete(String, int)} for more details. + + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + Important: All versions, of all nodes, under the given node are deleted. +

    + If there is an error with deleting one of the sub-nodes in the tree, + this operation would abort and would be the responsibility of the app to handle the same. +

    + @param zk the zookeeper handle + @param pathRoot the path to be deleted + @param cb call back method + @param ctx the context the callback method is called with + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + Important: This is not an atomic snapshot of the tree ever, but the + state as it exists across multiple RPCs from zkClient to the ensemble. + For practical purposes, it is suggested to bring the clients to the ensemble + down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior. + + @param zk the zookeeper handle + @param pathRoot The znode path, for which the entire subtree needs to be listed. + @throws InterruptedException + @throws KeeperException]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

    + The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed. +

    + Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + + @throws IOException + in cases of network failure + @throws IllegalArgumentException + if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

    + The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed. +

    + Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

    + For backward compatibility, there is another version + {@link #ZooKeeper(String, int, Watcher, boolean)} which uses + default {@link StaticHostProvider} + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + @param aHostProvider + use this as HostProvider to enable custom behaviour. + + @throws IOException + in cases of network failure + @throws IllegalArgumentException + if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

    + The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed. +

    + Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

    + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + + @throws IOException + in cases of network failure + @throws IllegalArgumentException + if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

    + The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). +

    + Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

    + Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + client connection, these values must be passed as sessionId and + sessionPasswd respectively if reconnecting. Otherwise, if not + reconnecting, use the other constructor which does not require these + parameters. + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param sessionId + specific session id to use if reconnecting + @param sessionPasswd + password for this session + + @throws IOException in cases of network failure + @throws IllegalArgumentException if an invalid chroot path is specified + @throws IllegalArgumentException for an invalid list of ZooKeeper hosts]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

    + The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). +

    + Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

    + Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + client connection, these values must be passed as sessionId and + sessionPasswd respectively if reconnecting. Otherwise, if not + reconnecting, use the other constructor which does not require these + parameters. +

    + For backward compatibility, there is another version + {@link #ZooKeeper(String, int, Watcher, long, byte[], boolean)} which uses + default {@link StaticHostProvider} + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param sessionId + specific session id to use if reconnecting + @param sessionPasswd + password for this session + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + @param aHostProvider + use this as HostProvider to enable custom behaviour. + @throws IOException in cases of network failure + @throws IllegalArgumentException if an invalid chroot path is specified]]> + + + + + + + Session establishment is asynchronous. This constructor will initiate + connection to the server and return immediately - potentially (usually) + before the session is fully established. The watcher argument specifies + the watcher that will be notified of any changes in state. This + notification can come at any point before or after the constructor call + has returned. +

    + The instantiated ZooKeeper client object will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). +

    + Added in 3.2.0: An optional "chroot" suffix may also be appended to the + connection string. This will run the client commands while interpreting + all paths relative to this root (similar to the unix chroot command). +

    + Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + client connection, these values must be passed as sessionId and + sessionPasswd respectively if reconnecting. Otherwise, if not + reconnecting, use the other constructor which does not require these + parameters. +

    + This constructor uses a StaticHostProvider; there is another one + to enable custom behaviour. + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + @param sessionTimeout + session timeout in milliseconds + @param watcher + a watcher object which will be notified of state changes, may + also be notified for node events + @param sessionId + specific session id to use if reconnecting + @param sessionPasswd + password for this session + @param canBeReadOnly + (added in 3.4) whether the created client is allowed to go to + read-only mode in case of partitioning. Read-only mode + basically means that if the client can't find any majority + servers but there's partitioned server it could reach, it + connects to one in read-only mode, i.e. read requests are + allowed while write requests are not. It continues seeking for + majority in the background. + @throws IOException in cases of network failure + @throws IllegalArgumentException if an invalid chroot path is specified]]> + + + + + + + + The function invokes a + probabilistic load-balancing algorithm which may cause the client to disconnect from + its current host with the goal to achieve expected uniform number of connections per server + in the new list. In case the current host to which the client is connected is not in the new + list this call will always cause the connection to be dropped. Otherwise, the decision + is based on whether the number of servers has increased or decreased and by how much. + For example, if the previous connection string contained 3 hosts and now the list contains + these 3 hosts and 2 more hosts, 40% of clients connected to each of the 3 hosts will + move to one of the new hosts in order to balance the load. The algorithm will disconnect + from the current host with probability 0.4 and in this case cause the client to connect + to one of the 2 new hosts, chosen at random. +

    + If the connection is dropped, the client moves to a special mode "reconfigMode" where he chooses + a new server to connect to using the probabilistic algorithm. After finding a server, + or exhausting all servers in the new list after trying all of them and failing to connect, + the client moves back to the normal mode of operation where it will pick an arbitrary server + from the connectString and attempt to connect to it. If establishment of + the connection fails, another server in the connect string will be tried + (the order is non-deterministic, as we random shuffle the list), until a + connection is established. The client will continue attempts until the + session is explicitly closed (or the session is expired by the server). + + @param connectString + comma separated host:port pairs, each corresponding to a zk + server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + If the optional chroot suffix is used the example would look + like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + where the client would be rooted at "/app/a" and all paths + would be relative to this root - ie getting/setting/etc... + "/foo/bar" would result in operations being run on + "/app/a/foo/bar" (from the server perspective). + + @throws IOException in cases of network failure]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The flags argument specifies whether the created node will be ephemeral + or not. +

    + An ephemeral node will be removed by the ZooKeeper automatically when the + session associated with the creation of the node expires. +

    + The flags argument can also specify to create a sequential node. The + actual path name of a sequential node will be the given path plus a + suffix "i" where i is the current sequential number of the node. The sequence + number is always fixed length of 10 digits, 0 padded. Once + such a node is created, the sequential number will be incremented by one. +

    + If a node with the same actual path already exists in the ZooKeeper, a + KeeperException with error code KeeperException.NodeExists will be + thrown. Note that since a different actual path is used for each + invocation of creating sequential node with the same path argument, the + call will never throw "file exists" KeeperException. +

    + If the parent node does not exist in the ZooKeeper, a KeeperException + with error code KeeperException.NoNode will be thrown. +

    + An ephemeral node cannot have children. If the parent node of the given + path is ephemeral, a KeeperException with error code + KeeperException.NoChildrenForEphemerals will be thrown. +

    + This operation, if successful, will trigger all the watches left on the + node of the given path by exists and getData API calls, and the watches + left on the parent node by getChildren API calls. +

    + If a node is created successfully, the ZooKeeper server will trigger the + watches on the path left by exists calls, and the watches on the parent + of the node by getChildren calls. +

    + The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperExecption to be thrown. + + @param path + the path for the node + @param data + the initial data for the node + @param acl + the acl for the node + @param createMode + specifying whether the node to be created is ephemeral + and/or sequential + @return the actual path of the created node + @throws KeeperException if the server returns a non-zero error code + @throws KeeperException.InvalidACLException if the ACL is invalid, null, or empty + @throws InterruptedException if the transaction is interrupted + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + The flags argument specifies whether the created node will be ephemeral + or not. +

    + An ephemeral node will be removed by the ZooKeeper automatically when the + session associated with the creation of the node expires. +

    + The flags argument can also specify to create a sequential node. The + actual path name of a sequential node will be the given path plus a + suffix "i" where i is the current sequential number of the node. The sequence + number is always fixed length of 10 digits, 0 padded. Once + such a node is created, the sequential number will be incremented by one. +

    + If a node with the same actual path already exists in the ZooKeeper, a + KeeperException with error code KeeperException.NodeExists will be + thrown. Note that since a different actual path is used for each + invocation of creating sequential node with the same path argument, the + call will never throw "file exists" KeeperException. +

    + If the parent node does not exist in the ZooKeeper, a KeeperException + with error code KeeperException.NoNode will be thrown. +

    + An ephemeral node cannot have children. If the parent node of the given + path is ephemeral, a KeeperException with error code + KeeperException.NoChildrenForEphemerals will be thrown. +

    + This operation, if successful, will trigger all the watches left on the + node of the given path by exists and getData API calls, and the watches + left on the parent node by getChildren API calls. +

    + If a node is created successfully, the ZooKeeper server will trigger the + watches on the path left by exists calls, and the watches on the parent + of the node by getChildren calls. +

    + The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperExecption to be thrown. + + @param path + the path for the node + @param data + the initial data for the node + @param acl + the acl for the node + @param createMode + specifying whether the node to be created is ephemeral + and/or sequential + @param stat + The output Stat object. + @return the actual path of the created node + @throws KeeperException if the server returns a non-zero error code + @throws KeeperException.InvalidACLException if the ACL is invalid, null, or empty + @throws InterruptedException if the transaction is interrupted + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if the nodes does not exist. +

    + A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. +

    + A KeeperException with error code KeeperException.NotEmpty will be thrown + if the node has children. +

    + This operation, if successful, will trigger all the watches on the node + of the given path left by exists API calls, and the watches on the parent + node left by getChildren API calls. + + @param path + the path of the node to be deleted. + @param version + the expected node version. + @throws InterruptedException IF the server transaction is interrupted + @throws KeeperException If the server signals an error with a non-zero + return code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + On success, a list of results is returned. + On failure, an exception is raised which contains partial results and + error details, see {@link KeeperException#getResults} +

    + Note: The maximum allowable size of all of the data arrays in all of + the setData operations in this single request is typically 1 MB + (1,048,576 bytes). This limit is specified on the server via + jute.maxbuffer. + Requests larger than this will cause a KeeperException to be + thrown. + + @param ops An iterable that contains the operations to be done. + These should be created using the factory methods on {@link Op}. + @return A list of results, one for each input Op, the order of + which exactly matches the order of the ops input + operations. + @throws InterruptedException If the operation was interrupted. + The operation may or may not have succeeded, but will not have + partially succeeded if this exception is thrown. + @throws KeeperException If the operation could not be completed + due to some error in doing one of the specified ops. + @throws IllegalArgumentException if an invalid path is specified + + @since 3.4.0]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch will be + triggered by a successful operation that creates/delete the node or sets + the data on the node. + + @param path the node path + @param watcher explicit watcher + @return the stat of the node of the given path; return null if no such a + node exists. + @throws KeeperException If the server signals an error + @throws InterruptedException If the server transaction is interrupted. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch will be + triggered by a successful operation that creates/delete the node or sets + the data on the node. + + @param path + the node path + @param watch + whether need to watch this node + @return the stat of the node of the given path; return null if no such a + node exists. + @throws KeeperException If the server signals an error + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is + thrown), a watch will be left on the node with the given path. The watch + will be triggered by a successful operation that sets data on the node, or + deletes the node. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path the given path + @param watcher explicit watcher + @param stat the stat of the node + @return the data of the node + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + If the watch is true and the call is successful (no exception is + thrown), a watch will be left on the node with the given path. The watch + will be triggered by a successful operation that sets data on the node, or + deletes the node. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path the given path + @param watch whether need to watch this node + @param stat the stat of the node + @return the data of the node + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is + thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch + will be triggered by a successful reconfig operation +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if the configuration node doesn't exists. + + @param watcher explicit watcher + @param stat the stat of the configuration node ZooDefs.CONFIG_NODE + @return configuration data stored in ZooDefs.CONFIG_NODE + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + If the watch is true and the call is successful (no exception is + thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch + will be triggered by a successful reconfig operation +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param watch whether need to watch this node + @param stat the stat of the configuration node ZooDefs.CONFIG_NODE + @return configuration data stored in ZooDefs.CONFIG_NODE + @throws KeeperException If the server signals an error with a non-zero error code + @throws InterruptedException If the server transaction is interrupted.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This operation, if successful, will trigger all the watches on the node + of the given path left by getData calls. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. +

    + A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. +

    + The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + Arrays larger than this will cause a KeeperException to be thrown. + + @param path + the path of the node + @param data + the data to set + @param version + the expected matching version + @return the state of the node + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + the given path for the node + @param stat + the stat of the node will be copied to this parameter if + not null. + @return the ACL array of the given node. + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. +

    + A KeeperException with error code KeeperException.BadVersion will be + thrown if the given version does not match the node's version. + + @param path + @param acl + @param version + @return the stat of the node. + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

    + The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + @param watcher explicit watcher + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

    + The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @param path + @param watch + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + If the watch is non-null and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

    + The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @since 3.3.0 + + @param path + @param watcher explicit watcher + @param stat stat of the znode designated by path + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero error code. + @throws IllegalArgumentException if an invalid path is specified]]> + + + + + + + + + + + If the watch is true and the call is successful (no exception is thrown), + a watch will be left on the node with the given path. The watch willbe + triggered by a successful operation that deletes the node of the given + path or creates/delete a child under the node. +

    + The list of children returned is not sorted and no guarantee is provided + as to its natural or lexical order. +

    + A KeeperException with error code KeeperException.NoNode will be thrown + if no node with the given path exists. + + @since 3.3.0 + + @param path + @param watch + @param stat stat of the znode designated by path + @return an unordered array of children of the node with the given path + @throws InterruptedException If the server transaction is interrupted. + @throws KeeperException If the server signals an error with a non-zero + error code.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Watcher shouldn't be null. A successful call guarantees that, the + removed watcher won't be triggered. +

    + + @param path + - the path of the node + @param watcher + - a concrete watcher + @param watcherType + - the type of watcher to be removed + @param local + - whether the watcher can be removed locally when there is no + server connection + @throws InterruptedException + if the server transaction is interrupted. + @throws KeeperException.NoWatcherException + if no watcher exists that match the specified parameters + @throws KeeperException + if the server signals an error with a non-zero error code. + @throws IllegalArgumentException + if any of the following is true: +
      +
    • {@code path} is invalid +
    • {@code watcher} is null +
    + + @since 3.5.0]]> +
    +
    + + + + + + + + + + + + + + + + + + + + A successful call guarantees that, the removed watchers won't be + triggered. +

    + + @param path + - the path of the node + @param watcherType + - the type of watcher to be removed + @param local + - whether watches can be removed locally when there is no + server connection + @throws InterruptedException + if the server transaction is interrupted. + @throws KeeperException.NoWatcherException + if no watcher exists that match the specified parameters + @throws KeeperException + if the server signals an error with a non-zero error code. + @throws IllegalArgumentException + if an invalid {@code path} is specified + + @since 3.5.0]]> +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Once a connection to a server is established, a session ID is assigned to the + client. The client will send heart beats to the server periodically to keep + the session valid. +

    + The application can call ZooKeeper APIs through a client as long as the + session ID of the client remains valid. +

    + If for some reason, the client fails to send heart beats to the server for a + prolonged period of time (exceeding the sessionTimeout value, for instance), + the server will expire the session, and the session ID will become invalid. + The client object will no longer be usable. To make ZooKeeper API calls, the + application must create a new client object. +

    + If the ZooKeeper server the client currently connects to fails or otherwise + does not respond, the client will automatically try to connect to another + server before its session ID expires. If successful, the application can + continue to use the client. +

    + The ZooKeeper API methods are either synchronous or asynchronous. Synchronous + methods blocks until the server has responded. Asynchronous methods just queue + the request for sending and return immediately. They take a callback object that + will be executed either on successful execution of the request or on error with + an appropriate return code (rc) indicating the error. +

    + Some successful ZooKeeper API calls can leave watches on the "data nodes" in + the ZooKeeper server. Other successful ZooKeeper API calls can trigger those + watches. Once a watch is triggered, an event will be delivered to the client + which left the watch at the first place. Each watch can be triggered only + once. Thus, up to one event will be delivered to a client for every watch it + leaves. +

    + A client needs an object of a class implementing Watcher interface for + processing the events delivered to the client. + + When a client drops current connection and re-connects to a server, all the + existing watches are considered as being triggered but the undelivered events + are lost. To emulate this, the client will generate a special event to tell + the event handler a connection has been dropped. This special event has type + EventNone and state sKeeperStateDisconnected.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/lib/jline-2.11.LICENSE.txt b/src/java/lib/jline-2.11.LICENSE.txt new file mode 100644 index 00000000000..4ac9522bd8c --- /dev/null +++ b/src/java/lib/jline-2.11.LICENSE.txt @@ -0,0 +1,35 @@ +Copyright (c) 2002-2012, the original author or authors. +All rights reserved. + +http://www.opensource.org/licenses/bsd-license.php + +Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the following +conditions are met: + +Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with +the distribution. + +Neither the name of JLine nor the names of its contributors +may be used to endorse or promote products derived from this +software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/src/java/lib/log4j-1.2.16.LICENSE.txt b/src/java/lib/log4j-1.2.16.LICENSE.txt new file mode 100644 index 00000000000..6279e5206de --- /dev/null +++ b/src/java/lib/log4j-1.2.16.LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 1999-2005 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/java/lib/servlet-api-2.5.LICENSE.txt b/src/java/lib/servlet-api-2.5.LICENSE.txt new file mode 100644 index 00000000000..afb49b23a70 --- /dev/null +++ b/src/java/lib/servlet-api-2.5.LICENSE.txt @@ -0,0 +1,93 @@ +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 1. + +Definitions. + +1.1. Contributor means each individual or entity that creates or contributes to the creation of Modifications. + +1.2. Contributor Version means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor. + +1.3. Covered Software means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof. + +1.4. Executable means the Covered Software in any form other than Source Code. + +1.5. Initial Developer means the individual or entity that first makes Original Software available under this License. + +1.6. Larger Work means a work which combines Covered Software or portions thereof with code not governed by the terms of this License. + +1.7. License means this document. + +1.8. Licensable means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein. + +1.9. Modifications means the Source Code and Executable form of any of the following: A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications; B. Any new file that contains any part of the Original Software or previous Modification; or C. Any new file that is contributed or otherwise made available under the terms of this License. + +1.10. Original Software means the Source Code and Executable form of computer software code that is originally released under this License. + +1.11. Patent Claims means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor. + +1.12. Source Code means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code. + +1.13. You (or Your) means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, You includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, control means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. + +2. License Grants. + + 2.1. The Initial Developer Grant. Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof); + + (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License; + + (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices. + +2.2. Contributor Grant. Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination). + +(c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party. + +(d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor. + +3. Distribution Obligations. + +3.1. Availability of Source Code. Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange. + +3.2. Modifications. The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License. + +3.3. Required Notices. You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer. + +3.4. Application of Additional Terms. You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. + +3.5. Distribution of Executable Versions. You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipients rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. + +3.6. Larger Works. You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software. + +4. Versions of the License. + +4.1. New Versions. Sun Microsystems, Inc. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License. + +4.2. Effect of New Versions. You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward. + +4.3. Modified Versions. When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License. + +5. DISCLAIMER OF WARRANTY. COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +6. TERMINATION. + +6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. + +6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as Participant) alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant. + +6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination. + +7. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTYS NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +8. U.S. GOVERNMENT END USERS. The Covered Software is a commercial item, as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of commercial computer software (as that term is defined at 48 C.F.R. 252.227-7014(a)(1)) and commercial computer software documentation as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License. + +9. MISCELLANEOUS. This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdictions conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software. + +10. RESPONSIBILITY FOR CLAIMS. As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability. + +NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) The code released under the CDDL shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California. diff --git a/src/java/lib/slf4j-1.7.5.LICENSE.txt b/src/java/lib/slf4j-1.7.5.LICENSE.txt new file mode 100644 index 00000000000..07892565242 --- /dev/null +++ b/src/java/lib/slf4j-1.7.5.LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2004-2008 QOS.ch All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/zookeeper/java/src/com/yahoo/jute/BinaryInputArchive.java b/src/java/main/org/apache/jute/BinaryInputArchive.java old mode 100755 new mode 100644 similarity index 53% rename from zookeeper/java/src/com/yahoo/jute/BinaryInputArchive.java rename to src/java/main/org/apache/jute/BinaryInputArchive.java index 8cdfa2f648f..57828410549 --- a/zookeeper/java/src/com/yahoo/jute/BinaryInputArchive.java +++ b/src/java/main/org/apache/jute/BinaryInputArchive.java @@ -1,122 +1,130 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.jute; +package org.apache.jute; import java.io.DataInput; -import java.io.IOException; import java.io.DataInputStream; +import java.io.IOException; import java.io.InputStream; /** * - * @author Milind Bhandarkar */ public class BinaryInputArchive implements InputArchive { - + static public final String UNREASONBLE_LENGTH = "Unreasonable length = "; + static public final int maxBuffer = Integer.getInteger("jute.maxbuffer", 0xfffff); private DataInput in; - - static public BinaryInputArchive getArchive(InputStream strm) { - return new BinaryInputArchive(new DataInputStream(strm)); - } - - static private class BinaryIndex implements Index { - private int nelems; - BinaryIndex(int nelems) { - this.nelems = nelems; - } - public boolean done() { - return (nelems <= 0); - } - public void incr() { - nelems--; - } - } + /** Creates a new instance of BinaryInputArchive */ public BinaryInputArchive(DataInput in) { this.in = in; } - + + static public BinaryInputArchive getArchive(InputStream strm) { + return new BinaryInputArchive(new DataInputStream(strm)); + } + public byte readByte(String tag) throws IOException { return in.readByte(); } - + public boolean readBool(String tag) throws IOException { return in.readBoolean(); } - + public int readInt(String tag) throws IOException { return in.readInt(); } - + public long readLong(String tag) throws IOException { return in.readLong(); } - + public float readFloat(String tag) throws IOException { return in.readFloat(); } - + public double readDouble(String tag) throws IOException { return in.readDouble(); } - + public String readString(String tag) throws IOException { - int len = in.readInt(); - if (len == -1) return null; - byte b[] = new byte[len]; - in.readFully(b); - return new String(b, "UTF8"); + int len = in.readInt(); + if (len == -1) return null; + checkLength(len); + byte b[] = new byte[len]; + in.readFully(b); + return new String(b, "UTF8"); } - + public byte[] readBuffer(String tag) throws IOException { int len = readInt(tag); if (len == -1) return null; - if (len < 0 || len > 128*1024) { - throw new RuntimeException("Unreasonable length = " + len); - } + checkLength(len); byte[] arr = new byte[len]; in.readFully(arr); return arr; } - + public void readRecord(Record r, String tag) throws IOException { r.deserialize(this, tag); } - - public void startRecord(String tag) throws IOException {} - - public void endRecord(String tag) throws IOException {} - + + public void startRecord(String tag) throws IOException { + } + + public void endRecord(String tag) throws IOException { + } + public Index startVector(String tag) throws IOException { int len = readInt(tag); if (len == -1) { - return null; + return null; } - return new BinaryIndex(len); + return new BinaryIndex(len); + } + + public void endVector(String tag) throws IOException { } - - public void endVector(String tag) throws IOException {} - + public Index startMap(String tag) throws IOException { return new BinaryIndex(readInt(tag)); } - - public void endMap(String tag) throws IOException {} - + + public void endMap(String tag) throws IOException { + } + + // Since this is a rough sanity check, add some padding to maxBuffer to + // make up for extra fields, etc. (otherwise e.g. clients may be able to + // write buffers larger than we can read from disk!) + private void checkLength(int len) throws IOException { + if (len < 0 || len > maxBuffer + 1024) { + throw new IOException(UNREASONBLE_LENGTH + len); + } + } + + static private class BinaryIndex implements Index { + private int nelems; + + BinaryIndex(int nelems) { + this.nelems = nelems; + } + + public boolean done() { + return (nelems <= 0); + } + + public void incr() { + nelems--; + } + } } diff --git a/src/java/main/org/apache/jute/BinaryOutputArchive.java b/src/java/main/org/apache/jute/BinaryOutputArchive.java new file mode 100644 index 00000000000..1b81d3fecf0 --- /dev/null +++ b/src/java/main/org/apache/jute/BinaryOutputArchive.java @@ -0,0 +1,143 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute; + +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.TreeMap; + +/** + * + */ +public class BinaryOutputArchive implements OutputArchive { + private ByteBuffer bb = ByteBuffer.allocate(1024); + + private DataOutput out; + + /** Creates a new instance of BinaryOutputArchive */ + public BinaryOutputArchive(DataOutput out) { + this.out = out; + } + + public static BinaryOutputArchive getArchive(OutputStream strm) { + return new BinaryOutputArchive(new DataOutputStream(strm)); + } + + public void writeByte(byte b, String tag) throws IOException { + out.writeByte(b); + } + + public void writeBool(boolean b, String tag) throws IOException { + out.writeBoolean(b); + } + + public void writeInt(int i, String tag) throws IOException { + out.writeInt(i); + } + + public void writeLong(long l, String tag) throws IOException { + out.writeLong(l); + } + + public void writeFloat(float f, String tag) throws IOException { + out.writeFloat(f); + } + + public void writeDouble(double d, String tag) throws IOException { + out.writeDouble(d); + } + + /** + * create our own char encoder to utf8. This is faster + * then string.getbytes(UTF8). + * @param s the string to encode into utf8 + * @return utf8 byte sequence. + */ + final private ByteBuffer stringToByteBuffer(CharSequence s) { + bb.clear(); + final int len = s.length(); + for (int i = 0; i < len; i++) { + if (bb.remaining() < 3) { + ByteBuffer n = ByteBuffer.allocate(bb.capacity() << 1); + bb.flip(); + n.put(bb); + bb = n; + } + char c = s.charAt(i); + if (c < 0x80) { + bb.put((byte) c); + } else if (c < 0x800) { + bb.put((byte) (0xc0 | (c >> 6))); + bb.put((byte) (0x80 | (c & 0x3f))); + } else { + bb.put((byte) (0xe0 | (c >> 12))); + bb.put((byte) (0x80 | ((c >> 6) & 0x3f))); + bb.put((byte) (0x80 | (c & 0x3f))); + } + } + bb.flip(); + return bb; + } + + public void writeString(String s, String tag) throws IOException { + if (s == null) { + writeInt(-1, "len"); + return; + } + ByteBuffer bb = stringToByteBuffer(s); + writeInt(bb.remaining(), "len"); + out.write(bb.array(), bb.position(), bb.limit()); + } + + public void writeBuffer(byte barr[], String tag) + throws IOException { + if (barr == null) { + out.writeInt(-1); + return; + } + out.writeInt(barr.length); + out.write(barr); + } + + public void writeRecord(Record r, String tag) throws IOException { + r.serialize(this, tag); + } + + public void startRecord(Record r, String tag) throws IOException { + } + + public void endRecord(Record r, String tag) throws IOException { + } + + public void startVector(List v, String tag) throws IOException { + if (v == null) { + writeInt(-1, tag); + return; + } + writeInt(v.size(), tag); + } + + public void endVector(List v, String tag) throws IOException { + } + + public void startMap(TreeMap v, String tag) throws IOException { + writeInt(v.size(), tag); + } + + public void endMap(TreeMap v, String tag) throws IOException { + } + +} diff --git a/zookeeper/java/src/com/yahoo/jute/CsvInputArchive.java b/src/java/main/org/apache/jute/CsvInputArchive.java old mode 100755 new mode 100644 similarity index 71% rename from zookeeper/java/src/com/yahoo/jute/CsvInputArchive.java rename to src/java/main/org/apache/jute/CsvInputArchive.java index 842dcb9b434..f8ea56635d4 --- a/zookeeper/java/src/com/yahoo/jute/CsvInputArchive.java +++ b/src/java/main/org/apache/jute/CsvInputArchive.java @@ -1,58 +1,43 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.jute; +package org.apache.jute; -import java.io.InputStreamReader; -import java.io.InputStream; import java.io.IOException; -import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.PushbackReader; import java.io.UnsupportedEncodingException; /** * - * @author Milind Bhandarkar */ class CsvInputArchive implements InputArchive { - + private PushbackReader stream; - - private class CsvIndex implements Index { - public boolean done() { - char c = '\0'; - try { - c = (char) stream.read(); - stream.unread(c); - } catch (IOException ex) { - } - return (c == '}') ? true : false; - } - public void incr() {} + + /** Creates a new instance of CsvInputArchive */ + public CsvInputArchive(InputStream in) + throws UnsupportedEncodingException { + stream = new PushbackReader(new InputStreamReader(in, "UTF-8")); } - - private void throwExceptionOnError(String tag) throws IOException { - throw new IOException("Error deserializing "+tag); + + static CsvInputArchive getArchive(InputStream strm) + throws UnsupportedEncodingException { + return new CsvInputArchive(strm); } - + private String readField(String tag) throws IOException { try { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); while (true) { char c = (char) stream.read(); switch (c) { @@ -68,83 +53,72 @@ private String readField(String tag) throws IOException { } } } catch (IOException ex) { - throw new IOException("Error reading "+tag); + throw new IOException("Error reading " + tag); } } - - static CsvInputArchive getArchive(InputStream strm) - throws UnsupportedEncodingException { - return new CsvInputArchive(strm); - } - - /** Creates a new instance of CsvInputArchive */ - public CsvInputArchive(InputStream in) - throws UnsupportedEncodingException { - stream = new PushbackReader(new InputStreamReader(in, "UTF-8")); - } - + public byte readByte(String tag) throws IOException { return (byte) readLong(tag); } - + public boolean readBool(String tag) throws IOException { String sval = readField(tag); return "T".equals(sval) ? true : false; } - + public int readInt(String tag) throws IOException { return (int) readLong(tag); } - + public long readLong(String tag) throws IOException { String sval = readField(tag); try { long lval = Long.parseLong(sval); return lval; } catch (NumberFormatException ex) { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } } - + public float readFloat(String tag) throws IOException { return (float) readDouble(tag); } - + public double readDouble(String tag) throws IOException { String sval = readField(tag); try { double dval = Double.parseDouble(sval); return dval; } catch (NumberFormatException ex) { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } } - + public String readString(String tag) throws IOException { String sval = readField(tag); return Utils.fromCSVString(sval); - + } - + public byte[] readBuffer(String tag) throws IOException { String sval = readField(tag); return Utils.fromCSVBuffer(sval); } - + public void readRecord(Record r, String tag) throws IOException { r.deserialize(this, tag); } - + public void startRecord(String tag) throws IOException { if (tag != null && !"".equals(tag)) { char c1 = (char) stream.read(); char c2 = (char) stream.read(); if (c1 != 's' || c2 != '{') { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } } } - + public void endRecord(String tag) throws IOException { char c = (char) stream.read(); if (tag == null || "".equals(tag)) { @@ -154,31 +128,31 @@ public void endRecord(String tag) throws IOException { return; } } - + if (c != '}') { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } c = (char) stream.read(); if (c != ',') { stream.unread(c); } - + return; } - + public Index startVector(String tag) throws IOException { char c1 = (char) stream.read(); char c2 = (char) stream.read(); if (c1 != 'v' || c2 != '{') { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } return new CsvIndex(); } - + public void endVector(String tag) throws IOException { char c = (char) stream.read(); if (c != '}') { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } c = (char) stream.read(); if (c != ',') { @@ -186,20 +160,20 @@ public void endVector(String tag) throws IOException { } return; } - + public Index startMap(String tag) throws IOException { char c1 = (char) stream.read(); char c2 = (char) stream.read(); if (c1 != 'm' || c2 != '{') { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } return new CsvIndex(); } - + public void endMap(String tag) throws IOException { char c = (char) stream.read(); if (c != '}') { - throw new IOException("Error deserializing "+tag); + throw new IOException("Error deserializing " + tag); } c = (char) stream.read(); if (c != ',') { @@ -207,4 +181,19 @@ public void endMap(String tag) throws IOException { } return; } + + private class CsvIndex implements Index { + public boolean done() { + char c = '\0'; + try { + c = (char) stream.read(); + stream.unread(c); + } catch (IOException ex) { + } + return (c == '}') ? true : false; + } + + public void incr() { + } + } } diff --git a/zookeeper/java/src/com/yahoo/jute/CsvOutputArchive.java b/src/java/main/org/apache/jute/CsvOutputArchive.java old mode 100755 new mode 100644 similarity index 66% rename from zookeeper/java/src/com/yahoo/jute/CsvOutputArchive.java rename to src/java/main/org/apache/jute/CsvOutputArchive.java index 488835207c5..3159fa7950f --- a/zookeeper/java/src/com/yahoo/jute/CsvOutputArchive.java +++ b/src/java/main/org/apache/jute/CsvOutputArchive.java @@ -1,112 +1,106 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.jute; +package org.apache.jute; import java.io.IOException; -import java.io.ByteArrayOutputStream; -import java.util.TreeMap; -import java.util.ArrayList; -import java.io.PrintStream; import java.io.OutputStream; +import java.io.PrintStream; import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.TreeMap; /** * - * @author Milind Bhandarkar */ public class CsvOutputArchive implements OutputArchive { private PrintStream stream; private boolean isFirst = true; - + + /** Creates a new instance of CsvOutputArchive */ + public CsvOutputArchive(OutputStream out) + throws UnsupportedEncodingException { + stream = new PrintStream(out, true, "UTF-8"); + } + static CsvOutputArchive getArchive(OutputStream strm) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { return new CsvOutputArchive(strm); } - + private void throwExceptionOnError(String tag) throws IOException { if (stream.checkError()) { - throw new IOException("Error serializing "+tag); + throw new IOException("Error serializing " + tag); } } - + private void printCommaUnlessFirst() { if (!isFirst) { stream.print(","); } isFirst = false; } - - /** Creates a new instance of CsvOutputArchive */ - public CsvOutputArchive(OutputStream out) - throws UnsupportedEncodingException { - stream = new PrintStream(out, true, "UTF-8"); - } - + public void writeByte(byte b, String tag) throws IOException { - writeLong((long)b, tag); + writeLong((long) b, tag); } - + public void writeBool(boolean b, String tag) throws IOException { printCommaUnlessFirst(); String val = b ? "T" : "F"; stream.print(val); throwExceptionOnError(tag); } - + public void writeInt(int i, String tag) throws IOException { - writeLong((long)i, tag); + writeLong((long) i, tag); } - + public void writeLong(long l, String tag) throws IOException { printCommaUnlessFirst(); stream.print(l); throwExceptionOnError(tag); } - + public void writeFloat(float f, String tag) throws IOException { - writeDouble((double)f, tag); + writeDouble((double) f, tag); } - + public void writeDouble(double d, String tag) throws IOException { printCommaUnlessFirst(); stream.print(d); throwExceptionOnError(tag); } - + public void writeString(String s, String tag) throws IOException { printCommaUnlessFirst(); stream.print(Utils.toCSVString(s)); throwExceptionOnError(tag); } - + public void writeBuffer(byte buf[], String tag) - throws IOException { + throws IOException { printCommaUnlessFirst(); stream.print(Utils.toCSVBuffer(buf)); throwExceptionOnError(tag); } - + public void writeRecord(Record r, String tag) throws IOException { + if (r == null) { + return; + } r.serialize(this, tag); } - + public void startRecord(Record r, String tag) throws IOException { if (tag != null && !"".equals(tag)) { printCommaUnlessFirst(); @@ -114,7 +108,7 @@ public void startRecord(Record r, String tag) throws IOException { isFirst = true; } } - + public void endRecord(Record r, String tag) throws IOException { if (tag == null || "".equals(tag)) { stream.print("\n"); @@ -124,25 +118,25 @@ public void endRecord(Record r, String tag) throws IOException { isFirst = false; } } - - public void startVector(ArrayList v, String tag) throws IOException { + + public void startVector(List v, String tag) throws IOException { printCommaUnlessFirst(); stream.print("v{"); isFirst = true; } - - public void endVector(ArrayList v, String tag) throws IOException { + + public void endVector(List v, String tag) throws IOException { stream.print("}"); isFirst = false; } - - public void startMap(TreeMap v, String tag) throws IOException { + + public void startMap(TreeMap v, String tag) throws IOException { printCommaUnlessFirst(); stream.print("m{"); isFirst = true; } - - public void endMap(TreeMap v, String tag) throws IOException { + + public void endMap(TreeMap v, String tag) throws IOException { stream.print("}"); isFirst = false; } diff --git a/src/java/main/org/apache/jute/Index.java b/src/java/main/org/apache/jute/Index.java new file mode 100644 index 00000000000..94b4593afa4 --- /dev/null +++ b/src/java/main/org/apache/jute/Index.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute; + +/** + * Interface that acts as an iterator for deserializing maps. + * The deserializer returns an instance that the record uses to + * read vectors and maps. An example of usage is as follows: + * + * + * Index idx = startVector(...); + * while (!idx.done()) { + * .... // read element of a vector + * idx.incr(); + * } + * + * + */ +public interface Index { + public boolean done(); + + public void incr(); +} diff --git a/zookeeper/java/src/com/yahoo/jute/InputArchive.java b/src/java/main/org/apache/jute/InputArchive.java old mode 100755 new mode 100644 similarity index 57% rename from zookeeper/java/src/com/yahoo/jute/InputArchive.java rename to src/java/main/org/apache/jute/InputArchive.java index c250b7ad1b0..e5ed3ba5048 --- a/zookeeper/java/src/com/yahoo/jute/InputArchive.java +++ b/src/java/main/org/apache/jute/InputArchive.java @@ -1,45 +1,50 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.jute; +package org.apache.jute; import java.io.IOException; -import java.io.ByteArrayOutputStream; /** * Interface that all the Deserializers have to implement. * - * @author Milind Bhandarkar */ public interface InputArchive { public byte readByte(String tag) throws IOException; + public boolean readBool(String tag) throws IOException; + public int readInt(String tag) throws IOException; + public long readLong(String tag) throws IOException; + public float readFloat(String tag) throws IOException; + public double readDouble(String tag) throws IOException; + public String readString(String tag) throws IOException; + public byte[] readBuffer(String tag) throws IOException; + public void readRecord(Record r, String tag) throws IOException; + public void startRecord(String tag) throws IOException; + public void endRecord(String tag) throws IOException; + public Index startVector(String tag) throws IOException; + public void endVector(String tag) throws IOException; + public Index startMap(String tag) throws IOException; + public void endMap(String tag) throws IOException; } diff --git a/src/java/main/org/apache/jute/OutputArchive.java b/src/java/main/org/apache/jute/OutputArchive.java new file mode 100644 index 00000000000..2a74df4e0df --- /dev/null +++ b/src/java/main/org/apache/jute/OutputArchive.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute; + +import java.io.IOException; +import java.util.List; +import java.util.TreeMap; + +/** + * Interface that alll the serializers have to implement. + * + */ +public interface OutputArchive { + public void writeByte(byte b, String tag) throws IOException; + + public void writeBool(boolean b, String tag) throws IOException; + + public void writeInt(int i, String tag) throws IOException; + + public void writeLong(long l, String tag) throws IOException; + + public void writeFloat(float f, String tag) throws IOException; + + public void writeDouble(double d, String tag) throws IOException; + + public void writeString(String s, String tag) throws IOException; + + public void writeBuffer(byte buf[], String tag) + throws IOException; + + public void writeRecord(Record r, String tag) throws IOException; + + public void startRecord(Record r, String tag) throws IOException; + + public void endRecord(Record r, String tag) throws IOException; + + public void startVector(List v, String tag) throws IOException; + + public void endVector(List v, String tag) throws IOException; + + public void startMap(TreeMap v, String tag) throws IOException; + + public void endMap(TreeMap v, String tag) throws IOException; + +} diff --git a/src/java/main/org/apache/jute/Record.java b/src/java/main/org/apache/jute/Record.java new file mode 100644 index 00000000000..91cddfdf244 --- /dev/null +++ b/src/java/main/org/apache/jute/Record.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute; + +import java.io.IOException; + +/** + * Interface that is implemented by generated classes. + * + */ +public interface Record { + public void serialize(OutputArchive archive, String tag) + throws IOException; + + public void deserialize(InputArchive archive, String tag) + throws IOException; +} diff --git a/zookeeper/java/src/com/yahoo/jute/RecordReader.java b/src/java/main/org/apache/jute/RecordReader.java old mode 100755 new mode 100644 similarity index 59% rename from zookeeper/java/src/com/yahoo/jute/RecordReader.java rename to src/java/main/org/apache/jute/RecordReader.java index 725b692f556..f655d2a145b --- a/zookeeper/java/src/com/yahoo/jute/RecordReader.java +++ b/src/java/main/org/apache/jute/RecordReader.java @@ -1,70 +1,68 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.jute; +package org.apache.jute; import java.io.IOException; import java.io.InputStream; -import java.io.DataInputStream; -import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; -import javax.xml.parsers.ParserConfigurationException; -import org.xml.sax.SAXException; /** * Front-end interface to deserializers. Also acts as a factory * for deserializers. * - * @author Milind Bhandarkar */ public class RecordReader { - - private InputArchive archive; - static private HashMap archiveFactory; - + static private HashMap archiveFactory; + static { - archiveFactory = new HashMap(); - Class[] params = { InputStream.class }; + archiveFactory = new HashMap(); + try { archiveFactory.put("binary", BinaryInputArchive.class.getDeclaredMethod( - "getArchive", params)); + "getArchive", new Class[]{InputStream.class})); archiveFactory.put("csv", CsvInputArchive.class.getDeclaredMethod( - "getArchive", params)); + "getArchive", new Class[]{InputStream.class})); archiveFactory.put("xml", XmlInputArchive.class.getDeclaredMethod( - "getArchive", params)); + "getArchive", new Class[]{InputStream.class})); } catch (SecurityException ex) { ex.printStackTrace(); } catch (NoSuchMethodException ex) { ex.printStackTrace(); } } - + + private InputArchive archive; + + /** + * Creates a new instance of RecordReader. + * @param in Stream from which to deserialize a record + * @param format Deserialization format ("binary", "xml", or "csv") + */ + public RecordReader(InputStream in, String format) + throws IOException { + archive = createArchive(in, format); + } + static private InputArchive createArchive(InputStream in, String format) - throws IOException { + throws IOException { Method factory = (Method) archiveFactory.get(format); if (factory != null) { - Object[] params = { in }; + Object[] params = {in}; try { return (InputArchive) factory.invoke(null, params); } catch (IllegalArgumentException ex) { @@ -77,16 +75,7 @@ static private InputArchive createArchive(InputStream in, String format) } return null; } - /** - * Creates a new instance of RecordReader. - * @param in Stream from which to deserialize a record - * @param format Deserialization format ("binary", "xml", or "csv") - */ - public RecordReader(InputStream in, String format) - throws IOException { - archive = createArchive(in, format); - } - + /** * Deserialize a record * @param r Record to be deserialized @@ -94,5 +83,5 @@ public RecordReader(InputStream in, String format) public void read(Record r) throws IOException { r.deserialize(archive, ""); } - + } diff --git a/src/java/main/org/apache/jute/RecordWriter.java b/src/java/main/org/apache/jute/RecordWriter.java new file mode 100644 index 00000000000..11fcd846ea0 --- /dev/null +++ b/src/java/main/org/apache/jute/RecordWriter.java @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; + +/** + * Front-end for serializers. Also serves as a factory for serializers. + * + */ +public class RecordWriter { + + static private HashMap archiveFactory = constructFactory(); + private OutputArchive archive; + + /** + * Creates a new instance of RecordWriter + * @param out Output stream where the records will be serialized + * @param format Serialization format ("binary", "xml", or "csv") + */ + public RecordWriter(OutputStream out, String format) + throws IOException { + archive = createArchive(out, format); + } + + static HashMap constructFactory() { + HashMap factory = new HashMap(); + + try { + factory.put("binary", + BinaryOutputArchive.class.getDeclaredMethod( + "getArchive", new Class[]{OutputStream.class})); + factory.put("csv", + CsvOutputArchive.class.getDeclaredMethod( + "getArchive", new Class[]{OutputStream.class})); + factory.put("xml", + XmlOutputArchive.class.getDeclaredMethod( + "getArchive", new Class[]{OutputStream.class})); + } catch (SecurityException ex) { + ex.printStackTrace(); + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + return factory; + } + + static private OutputArchive createArchive(OutputStream out, + String format) + throws IOException { + Method factory = (Method) archiveFactory.get(format); + if (factory != null) { + Object[] params = {out}; + try { + return (OutputArchive) factory.invoke(null, params); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } catch (InvocationTargetException ex) { + ex.printStackTrace(); + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + } + } + return null; + } + + /** + * Serialize a record + * @param r record to be serialized + */ + public void write(Record r) throws IOException { + r.serialize(archive, ""); + } +} diff --git a/src/java/main/org/apache/jute/Utils.java b/src/java/main/org/apache/jute/Utils.java new file mode 100644 index 00000000000..523d84e5e37 --- /dev/null +++ b/src/java/main/org/apache/jute/Utils.java @@ -0,0 +1,289 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Various utility functions for Hadoop record I/O runtime. + */ +public class Utils { + + private static final char[] hexchars = {'0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F'}; + + /** Cannot create a new instance of Utils */ + private Utils() { + super(); + } + + /** + * equals function that actually compares two buffers. + * + * @param onearray First buffer + * @param twoarray Second buffer + * @return true if one and two contain exactly the same content, else false. + */ + public static boolean bufEquals(byte onearray[], byte twoarray[]) { + if (onearray == twoarray) return true; + boolean ret = (onearray.length == twoarray.length); + if (!ret) { + return ret; + } + for (int idx = 0; idx < onearray.length; idx++) { + if (onearray[idx] != twoarray[idx]) { + return false; + } + } + return true; + } + + /** + * + * @param s + * @return + */ + static String toXMLString(String s) { + if (s == null) + return ""; + + StringBuilder sb = new StringBuilder(); + for (int idx = 0; idx < s.length(); idx++) { + char ch = s.charAt(idx); + if (ch == '<') { + sb.append("<"); + } else if (ch == '&') { + sb.append("&"); + } else if (ch == '%') { + sb.append("%25"); + } else if (ch < 0x20) { + sb.append("%"); + sb.append(hexchars[ch / 16]); + sb.append(hexchars[ch % 16]); + } else { + sb.append(ch); + } + } + return sb.toString(); + } + + static private int h2c(char ch) { + if (ch >= '0' && ch <= '9') { + return ch - '0'; + } else if (ch >= 'A' && ch <= 'F') { + return ch - 'A'; + } else if (ch >= 'a' && ch <= 'f') { + return ch - 'a'; + } + return 0; + } + + /** + * + * @param s + * @return + */ + static String fromXMLString(String s) { + StringBuilder sb = new StringBuilder(); + for (int idx = 0; idx < s.length(); ) { + char ch = s.charAt(idx++); + if (ch == '%') { + char ch1 = s.charAt(idx++); + char ch2 = s.charAt(idx++); + char res = (char) (h2c(ch1) * 16 + h2c(ch2)); + sb.append(res); + } else { + sb.append(ch); + } + } + + return sb.toString(); + } + + /** + * + * @param s + * @return + */ + static String toCSVString(String s) { + if (s == null) + return ""; + + StringBuilder sb = new StringBuilder(s.length() + 1); + sb.append('\''); + int len = s.length(); + for (int i = 0; i < len; i++) { + char c = s.charAt(i); + switch (c) { + case '\0': + sb.append("%00"); + break; + case '\n': + sb.append("%0A"); + break; + case '\r': + sb.append("%0D"); + break; + case ',': + sb.append("%2C"); + break; + case '}': + sb.append("%7D"); + break; + case '%': + sb.append("%25"); + break; + default: + sb.append(c); + } + } + return sb.toString(); + } + + /** + * + * @param s + * @throws java.io.IOException + * @return + */ + static String fromCSVString(String s) throws IOException { + if (s.charAt(0) != '\'') { + throw new IOException("Error deserializing string."); + } + int len = s.length(); + StringBuilder sb = new StringBuilder(len - 1); + for (int i = 1; i < len; i++) { + char c = s.charAt(i); + if (c == '%') { + char ch1 = s.charAt(i + 1); + char ch2 = s.charAt(i + 2); + i += 2; + if (ch1 == '0' && ch2 == '0') { + sb.append('\0'); + } else if (ch1 == '0' && ch2 == 'A') { + sb.append('\n'); + } else if (ch1 == '0' && ch2 == 'D') { + sb.append('\r'); + } else if (ch1 == '2' && ch2 == 'C') { + sb.append(','); + } else if (ch1 == '7' && ch2 == 'D') { + sb.append('}'); + } else if (ch1 == '2' && ch2 == '5') { + sb.append('%'); + } else { + throw new IOException("Error deserializing string."); + } + } else { + sb.append(c); + } + } + return sb.toString(); + } + + /** + * + * @param s + * @return + */ + static String toXMLBuffer(byte barr[]) { + if (barr == null || barr.length == 0) { + return ""; + } + StringBuilder sb = new StringBuilder(2 * barr.length); + for (int idx = 0; idx < barr.length; idx++) { + sb.append(Integer.toHexString(barr[idx])); + } + return sb.toString(); + } + + /** + * + * @param s + * @throws java.io.IOException + * @return + */ + static byte[] fromXMLBuffer(String s) + throws IOException { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + if (s.length() == 0) { + return stream.toByteArray(); + } + int blen = s.length() / 2; + byte[] barr = new byte[blen]; + for (int idx = 0; idx < blen; idx++) { + char c1 = s.charAt(2 * idx); + char c2 = s.charAt(2 * idx + 1); + barr[idx] = Byte.parseByte("" + c1 + c2, 16); + } + stream.write(barr); + return stream.toByteArray(); + } + + /** + * + * @param buf + * @return + */ + static String toCSVBuffer(byte barr[]) { + if (barr == null || barr.length == 0) { + return ""; + } + StringBuilder sb = new StringBuilder(barr.length + 1); + sb.append('#'); + for (int idx = 0; idx < barr.length; idx++) { + sb.append(Integer.toHexString(barr[idx])); + } + return sb.toString(); + } + + /** + * Converts a CSV-serialized representation of buffer to a new + * ByteArrayOutputStream. + * @param s CSV-serialized representation of buffer + * @throws java.io.IOException + * @return Deserialized ByteArrayOutputStream + */ + static byte[] fromCSVBuffer(String s) + throws IOException { + if (s.charAt(0) != '#') { + throw new IOException("Error deserializing buffer."); + } + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + if (s.length() == 1) { + return stream.toByteArray(); + } + int blen = (s.length() - 1) / 2; + byte[] barr = new byte[blen]; + for (int idx = 0; idx < blen; idx++) { + char c1 = s.charAt(2 * idx + 1); + char c2 = s.charAt(2 * idx + 2); + barr[idx] = Byte.parseByte("" + c1 + c2, 16); + } + stream.write(barr); + return stream.toByteArray(); + } + + public static int compareBytes(byte b1[], int off1, int len1, byte b2[], int off2, int len2) { + int i; + for (i = 0; i < len1 && i < len2; i++) { + if (b1[off1 + i] != b2[off2 + i]) { + return b1[off1 + i] < b2[off2 + i] ? -1 : 1; + } + } + if (len1 != len2) { + return len1 < len2 ? -1 : 1; + } + return 0; + } +} diff --git a/zookeeper/java/src/com/yahoo/jute/XmlInputArchive.java b/src/java/main/org/apache/jute/XmlInputArchive.java old mode 100755 new mode 100644 similarity index 62% rename from zookeeper/java/src/com/yahoo/jute/XmlInputArchive.java rename to src/java/main/org/apache/jute/XmlInputArchive.java index 9863dff965d..673f7132f15 --- a/zookeeper/java/src/com/yahoo/jute/XmlInputArchive.java +++ b/src/java/main/org/apache/jute/XmlInputArchive.java @@ -1,146 +1,41 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.jute; +package org.apache.jute; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; -import java.io.InputStream; import java.io.IOException; -import java.io.ByteArrayOutputStream; +import java.io.InputStream; import java.util.ArrayList; -import org.xml.sax.*; -import org.xml.sax.helpers.DefaultHandler; -import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + /** * - * @author Milind Bhandarkar */ class XmlInputArchive implements InputArchive { - - static private class Value { - private String type; - private StringBuffer sb; - - public Value(String t) { - type = t; - sb = new StringBuffer(); - } - public void addChars(char[] buf, int offset, int len) { - sb.append(buf, offset, len); - } - public String getValue() { return sb.toString(); } - public String getType() { return type; } - } - - private class XMLParser extends DefaultHandler { - private boolean charsValid = false; - - private ArrayList valList; - - private XMLParser(ArrayList vlist) { - valList = vlist; - } - - public void startDocument() throws SAXException {} - - public void endDocument() throws SAXException {} - - public void startElement(String ns, - String sname, - String qname, - Attributes attrs) throws SAXException { - charsValid = false; - if ("boolean".equals(qname) || - "i4".equals(qname) || - "int".equals(qname) || - "string".equals(qname) || - "double".equals(qname) || - "ex:i1".equals(qname) || - "ex:i8".equals(qname) || - "ex:float".equals(qname)) { - charsValid = true; - valList.add(new Value(qname)); - } else if ("struct".equals(qname) || - "array".equals(qname)) { - valList.add(new Value(qname)); - } - } - - public void endElement(String ns, - String sname, - String qname) throws SAXException { - charsValid = false; - if ("struct".equals(qname) || - "array".equals(qname)) { - valList.add(new Value("/"+qname)); - } - } - - public void characters(char buf[], int offset, int len) - throws SAXException { - if (charsValid) { - Value v = (Value) valList.get(valList.size()-1); - v.addChars(buf, offset,len); - } - } - - } - - private class XmlIndex implements Index { - public boolean done() { - Value v = (Value) valList.get(vIdx); - if ("/array".equals(v.getType())) { - valList.set(vIdx, null); - vIdx++; - return true; - } else { - return false; - } - } - public void incr() {} - } - - private ArrayList valList; + + private ArrayList valList; private int vLen; private int vIdx; - - private Value next() throws IOException { - if (vIdx < vLen) { - Value v = (Value) valList.get(vIdx); - valList.set(vIdx, null); - vIdx++; - return v; - } else { - throw new IOException("Error in deserialization."); - } - } - - static XmlInputArchive getArchive(InputStream strm) - throws ParserConfigurationException, SAXException, IOException { - return new XmlInputArchive(strm); - } - + /** Creates a new instance of BinaryInputArchive */ public XmlInputArchive(InputStream in) - throws ParserConfigurationException, SAXException, IOException { - valList = new ArrayList(); + throws ParserConfigurationException, SAXException, IOException { + valList = new ArrayList(); DefaultHandler handler = new XMLParser(valList); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); @@ -148,104 +43,217 @@ public XmlInputArchive(InputStream in) vLen = valList.size(); vIdx = 0; } - + + static XmlInputArchive getArchive(InputStream strm) + throws ParserConfigurationException, SAXException, IOException { + return new XmlInputArchive(strm); + } + + private Value next() throws IOException { + if (vIdx < vLen) { + Value v = valList.get(vIdx); + valList.set(vIdx, null); + vIdx++; + return v; + } else { + throw new IOException("Error in deserialization."); + } + } + public byte readByte(String tag) throws IOException { Value v = next(); if (!"ex:i1".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return Byte.parseByte(v.getValue()); } - + public boolean readBool(String tag) throws IOException { Value v = next(); if (!"boolean".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return "1".equals(v.getValue()); } - + public int readInt(String tag) throws IOException { Value v = next(); if (!"i4".equals(v.getType()) && !"int".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return Integer.parseInt(v.getValue()); } - + public long readLong(String tag) throws IOException { Value v = next(); if (!"ex:i8".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return Long.parseLong(v.getValue()); } - + public float readFloat(String tag) throws IOException { Value v = next(); if (!"ex:float".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return Float.parseFloat(v.getValue()); } - + public double readDouble(String tag) throws IOException { Value v = next(); if (!"double".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return Double.parseDouble(v.getValue()); } - + public String readString(String tag) throws IOException { Value v = next(); if (!"string".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return Utils.fromXMLString(v.getValue()); } - + public byte[] readBuffer(String tag) throws IOException { Value v = next(); if (!"string".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return Utils.fromXMLBuffer(v.getValue()); } - + public void readRecord(Record r, String tag) throws IOException { r.deserialize(this, tag); } - + public void startRecord(String tag) throws IOException { Value v = next(); if (!"struct".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } } - + public void endRecord(String tag) throws IOException { Value v = next(); if (!"/struct".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } } - + public Index startVector(String tag) throws IOException { Value v = next(); if (!"array".equals(v.getType())) { - throw new IOException("Error deserializing "+tag+"."); + throw new IOException("Error deserializing " + tag + "."); } return new XmlIndex(); } - - public void endVector(String tag) throws IOException {} - + + public void endVector(String tag) throws IOException { + } + public Index startMap(String tag) throws IOException { return startVector(tag); } - - public void endMap(String tag) throws IOException { endVector(tag); } + + public void endMap(String tag) throws IOException { + endVector(tag); + } + + static private class Value { + private String type; + private StringBuffer sb; + + public Value(String t) { + type = t; + sb = new StringBuffer(); + } + + public void addChars(char[] buf, int offset, int len) { + sb.append(buf, offset, len); + } + + public String getValue() { + return sb.toString(); + } + + public String getType() { + return type; + } + } + + private static class XMLParser extends DefaultHandler { + private boolean charsValid = false; + + private ArrayList valList; + + private XMLParser(ArrayList vlist) { + valList = vlist; + } + + public void startDocument() throws SAXException { + } + + public void endDocument() throws SAXException { + } + + public void startElement(String ns, + String sname, + String qname, + Attributes attrs) throws SAXException { + charsValid = false; + if ("boolean".equals(qname) || + "i4".equals(qname) || + "int".equals(qname) || + "string".equals(qname) || + "double".equals(qname) || + "ex:i1".equals(qname) || + "ex:i8".equals(qname) || + "ex:float".equals(qname)) { + charsValid = true; + valList.add(new Value(qname)); + } else if ("struct".equals(qname) || + "array".equals(qname)) { + valList.add(new Value(qname)); + } + } + + public void endElement(String ns, + String sname, + String qname) throws SAXException { + charsValid = false; + if ("struct".equals(qname) || + "array".equals(qname)) { + valList.add(new Value("/" + qname)); + } + } + + public void characters(char buf[], int offset, int len) + throws SAXException { + if (charsValid) { + Value v = valList.get(valList.size() - 1); + v.addChars(buf, offset, len); + } + } + + } + + private class XmlIndex implements Index { + public boolean done() { + Value v = valList.get(vIdx); + if ("/array".equals(v.getType())) { + valList.set(vIdx, null); + vIdx++; + return true; + } else { + return false; + } + } + + public void incr() { + } + } } diff --git a/zookeeper/java/src/com/yahoo/jute/XmlOutputArchive.java b/src/java/main/org/apache/jute/XmlOutputArchive.java old mode 100755 new mode 100644 similarity index 77% rename from zookeeper/java/src/com/yahoo/jute/XmlOutputArchive.java rename to src/java/main/org/apache/jute/XmlOutputArchive.java index a68f81cc9ea..05aadb4f9e1 --- a/zookeeper/java/src/com/yahoo/jute/XmlOutputArchive.java +++ b/src/java/main/org/apache/jute/XmlOutputArchive.java @@ -1,68 +1,69 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.jute; +package org.apache.jute; import java.io.IOException; -import java.io.ByteArrayOutputStream; -import java.util.TreeMap; -import java.util.ArrayList; -import java.io.PrintStream; import java.io.OutputStream; +import java.io.PrintStream; +import java.util.List; import java.util.Stack; +import java.util.TreeMap; /** * - * @author Milind Bhandarkar */ class XmlOutputArchive implements OutputArchive { private PrintStream stream; - + private int indent = 0; - - private Stack compoundStack; - + + private Stack compoundStack; + + /** Creates a new instance of XmlOutputArchive */ + public XmlOutputArchive(OutputStream out) { + stream = new PrintStream(out); + compoundStack = new Stack(); + } + + static XmlOutputArchive getArchive(OutputStream strm) { + return new XmlOutputArchive(strm); + } + private void putIndent() { - StringBuffer sb = new StringBuffer(""); + StringBuilder sb = new StringBuilder(""); for (int idx = 0; idx < indent; idx++) { sb.append(" "); } stream.print(sb.toString()); } - + private void addIndent() { indent++; } - + private void closeIndent() { indent--; } - + private void printBeginEnvelope(String tag) { if (!compoundStack.empty()) { - String s = (String) compoundStack.peek(); + String s = compoundStack.peek(); if ("struct".equals(s)) { putIndent(); stream.print("\n"); addIndent(); putIndent(); - stream.print(""+tag+"\n"); + stream.print("" + tag + "\n"); putIndent(); stream.print(""); } else if ("vector".equals(s)) { @@ -74,10 +75,10 @@ private void printBeginEnvelope(String tag) { stream.print(""); } } - + private void printEndEnvelope(String tag) { if (!compoundStack.empty()) { - String s = (String) compoundStack.peek(); + String s = compoundStack.peek(); if ("struct".equals(s)) { stream.print("\n"); closeIndent(); @@ -92,56 +93,46 @@ private void printEndEnvelope(String tag) { stream.print("\n"); } } - + private void insideVector(String tag) { printBeginEnvelope(tag); compoundStack.push("vector"); } - + private void outsideVector(String tag) throws IOException { - String s = (String) compoundStack.pop(); + String s = compoundStack.pop(); if (!"vector".equals(s)) { throw new IOException("Error serializing vector."); } printEndEnvelope(tag); } - + private void insideMap(String tag) { printBeginEnvelope(tag); compoundStack.push("map"); } - + private void outsideMap(String tag) throws IOException { - String s = (String) compoundStack.pop(); + String s = compoundStack.pop(); if (!"map".equals(s)) { throw new IOException("Error serializing map."); } printEndEnvelope(tag); } - + private void insideRecord(String tag) { printBeginEnvelope(tag); compoundStack.push("struct"); } - + private void outsideRecord(String tag) throws IOException { - String s = (String) compoundStack.pop(); + String s = compoundStack.pop(); if (!"struct".equals(s)) { throw new IOException("Error serializing record."); } printEndEnvelope(tag); } - - static XmlOutputArchive getArchive(OutputStream strm) { - return new XmlOutputArchive(strm); - } - - /** Creates a new instance of XmlOutputArchive */ - public XmlOutputArchive(OutputStream out) { - stream = new PrintStream(out); - compoundStack = new Stack(); - } - + public void writeByte(byte b, String tag) throws IOException { printBeginEnvelope(tag); stream.print(""); @@ -149,7 +140,7 @@ public void writeByte(byte b, String tag) throws IOException { stream.print(""); printEndEnvelope(tag); } - + public void writeBool(boolean b, String tag) throws IOException { printBeginEnvelope(tag); stream.print(""); @@ -157,7 +148,7 @@ public void writeBool(boolean b, String tag) throws IOException { stream.print(""); printEndEnvelope(tag); } - + public void writeInt(int i, String tag) throws IOException { printBeginEnvelope(tag); stream.print(""); @@ -165,7 +156,7 @@ public void writeInt(int i, String tag) throws IOException { stream.print(""); printEndEnvelope(tag); } - + public void writeLong(long l, String tag) throws IOException { printBeginEnvelope(tag); stream.print(""); @@ -173,7 +164,7 @@ public void writeLong(long l, String tag) throws IOException { stream.print(""); printEndEnvelope(tag); } - + public void writeFloat(float f, String tag) throws IOException { printBeginEnvelope(tag); stream.print(""); @@ -181,7 +172,7 @@ public void writeFloat(float f, String tag) throws IOException { stream.print(""); printEndEnvelope(tag); } - + public void writeDouble(double d, String tag) throws IOException { printBeginEnvelope(tag); stream.print(""); @@ -189,7 +180,7 @@ public void writeDouble(double d, String tag) throws IOException { stream.print(""); printEndEnvelope(tag); } - + public void writeString(String s, String tag) throws IOException { printBeginEnvelope(tag); stream.print(""); @@ -197,53 +188,53 @@ public void writeString(String s, String tag) throws IOException { stream.print(""); printEndEnvelope(tag); } - + public void writeBuffer(byte buf[], String tag) - throws IOException { + throws IOException { printBeginEnvelope(tag); stream.print(""); stream.print(Utils.toXMLBuffer(buf)); stream.print(""); printEndEnvelope(tag); } - + public void writeRecord(Record r, String tag) throws IOException { r.serialize(this, tag); } - + public void startRecord(Record r, String tag) throws IOException { insideRecord(tag); stream.print("\n"); addIndent(); } - + public void endRecord(Record r, String tag) throws IOException { closeIndent(); putIndent(); stream.print(""); outsideRecord(tag); } - - public void startVector(ArrayList v, String tag) throws IOException { + + public void startVector(List v, String tag) throws IOException { insideVector(tag); stream.print("\n"); addIndent(); } - - public void endVector(ArrayList v, String tag) throws IOException { + + public void endVector(List v, String tag) throws IOException { closeIndent(); putIndent(); stream.print(""); outsideVector(tag); } - - public void startMap(TreeMap v, String tag) throws IOException { + + public void startMap(TreeMap v, String tag) throws IOException { insideMap(tag); stream.print("\n"); addIndent(); } - - public void endMap(TreeMap v, String tag) throws IOException { + + public void endMap(TreeMap v, String tag) throws IOException { closeIndent(); putIndent(); stream.print(""); diff --git a/src/java/main/org/apache/jute/compiler/CGenerator.java b/src/java/main/org/apache/jute/compiler/CGenerator.java new file mode 100644 index 00000000000..9391184395f --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/CGenerator.java @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * C++ Code generator front-end for Hadoop record I/O. + */ +class CGenerator { + private final File outputDirectory; + private String mName; + private ArrayList mInclFiles; + private ArrayList mRecList; + + /** Creates a new instance of CppGenerator + * + * @param name possibly full pathname to the file + * @param ilist included files (as JFile) + * @param rlist List of records defined within this file + * @param outputDirectory + */ + CGenerator(String name, ArrayList ilist, ArrayList rlist, + File outputDirectory) { + this.outputDirectory = outputDirectory; + mName = (new File(name)).getName(); + mInclFiles = ilist; + mRecList = rlist; + } + + /** + * Generate C++ code. This method only creates the requested file(s) + * and spits-out file-level elements (such as include statements etc.) + * record-level code is generated by JRecord. + */ + void genCode() throws IOException { + if (!outputDirectory.exists()) { + if (!outputDirectory.mkdirs()) { + throw new IOException("unable to create output directory " + + outputDirectory); + } + } + FileWriter c = new FileWriter(new File(outputDirectory, mName + ".c")); + FileWriter h = new FileWriter(new File(outputDirectory, mName + ".h")); + + h.write("/**\n"); + h.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + h.write("* or more contributor license agreements. See the NOTICE file\n"); + h.write("* distributed with this work for additional information\n"); + h.write("* regarding copyright ownership. The ASF licenses this file\n"); + h.write("* to you under the Apache License, Version 2.0 (the\n"); + h.write("* \"License\"); you may not use this file except in compliance\n"); + h.write("* with the License. You may obtain a copy of the License at\n"); + h.write("*\n"); + h.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + h.write("*\n"); + h.write("* Unless required by applicable law or agreed to in writing, software\n"); + h.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + h.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + h.write("* See the License for the specific language governing permissions and\n"); + h.write("* limitations under the License.\n"); + h.write("*/\n"); + h.write("\n"); + + c.write("/**\n"); + c.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + c.write("* or more contributor license agreements. See the NOTICE file\n"); + c.write("* distributed with this work for additional information\n"); + c.write("* regarding copyright ownership. The ASF licenses this file\n"); + c.write("* to you under the Apache License, Version 2.0 (the\n"); + c.write("* \"License\"); you may not use this file except in compliance\n"); + c.write("* with the License. You may obtain a copy of the License at\n"); + c.write("*\n"); + c.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + c.write("*\n"); + c.write("* Unless required by applicable law or agreed to in writing, software\n"); + c.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + c.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + c.write("* See the License for the specific language governing permissions and\n"); + c.write("* limitations under the License.\n"); + c.write("*/\n"); + c.write("\n"); + + h.write("#ifndef __" + mName.toUpperCase().replace('.', '_') + "__\n"); + h.write("#define __" + mName.toUpperCase().replace('.', '_') + "__\n"); + + h.write("#include \"recordio.h\"\n"); + for (Iterator i = mInclFiles.iterator(); i.hasNext(); ) { + JFile f = i.next(); + h.write("#include \"" + f.getName() + ".h\"\n"); + } + // required for compilation from C++ + h.write("\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"); + + c.write("#include \n"); // need it for calloc() & free() + c.write("#include \"" + mName + ".h\"\n\n"); + + for (Iterator i = mRecList.iterator(); i.hasNext(); ) { + JRecord jr = i.next(); + jr.genCCode(h, c); + } + + h.write("\n#ifdef __cplusplus\n}\n#endif\n\n"); + h.write("#endif //" + mName.toUpperCase().replace('.', '_') + "__\n"); + + h.close(); + c.close(); + } +} diff --git a/src/java/main/org/apache/jute/compiler/CSharpGenerator.java b/src/java/main/org/apache/jute/compiler/CSharpGenerator.java new file mode 100644 index 00000000000..873702d4bb7 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/CSharpGenerator.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +public class CSharpGenerator { + private final File outputDirectory; + private ArrayList mRecList; + + /** Creates a new instance of CSharpGenerator + * + * @param name possibly full pathname to the file + * @param ilist included files (as JFile) + * @param rlist List of records defined within this file + * @param outputDirectory + */ + CSharpGenerator(String name, ArrayList ilist, ArrayList rlist, + File outputDirectory) { + this.outputDirectory = outputDirectory; + mRecList = rlist; + } + + /** + * Generate C# code. This method only creates the requested file(s) + * and spits-out file-level elements (such as include statements etc.) + * record-level code is generated by JRecord. + */ + void genCode() throws IOException { + for (JRecord rec : mRecList) { + rec.genCsharpCode(outputDirectory); + } + } +} diff --git a/src/java/main/org/apache/jute/compiler/CppGenerator.java b/src/java/main/org/apache/jute/compiler/CppGenerator.java new file mode 100644 index 00000000000..c25b75d427e --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/CppGenerator.java @@ -0,0 +1,117 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * C++ Code generator front-end for Hadoop record I/O. + */ +class CppGenerator { + private final File outputDirectory; + private String mName; + private ArrayList mInclFiles; + private ArrayList mRecList; + + /** Creates a new instance of CppGenerator + * + * @param name possibly full pathname to the file + * @param ilist included files (as JFile) + * @param rlist List of records defined within this file + * @param outputDirectory + */ + CppGenerator(String name, ArrayList ilist, ArrayList rlist, + File outputDirectory) { + this.outputDirectory = outputDirectory; + mName = (new File(name)).getName(); + mInclFiles = ilist; + mRecList = rlist; + } + + /** + * Generate C++ code. This method only creates the requested file(s) + * and spits-out file-level elements (such as include statements etc.) + * record-level code is generated by JRecord. + */ + void genCode() throws IOException { + if (!outputDirectory.exists()) { + if (!outputDirectory.mkdirs()) { + throw new IOException("unable to create output directory " + + outputDirectory); + } + } + FileWriter cc = new FileWriter(new File(outputDirectory, mName + ".cc")); + FileWriter hh = new FileWriter(new File(outputDirectory, mName + ".hh")); + + hh.write("/**\n"); + hh.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + hh.write("* or more contributor license agreements. See the NOTICE file\n"); + hh.write("* distributed with this work for additional information\n"); + hh.write("* regarding copyright ownership. The ASF licenses this file\n"); + hh.write("* to you under the Apache License, Version 2.0 (the\n"); + hh.write("* \"License\"); you may not use this file except in compliance\n"); + hh.write("* with the License. You may obtain a copy of the License at\n"); + hh.write("*\n"); + hh.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + hh.write("*\n"); + hh.write("* Unless required by applicable law or agreed to in writing, software\n"); + hh.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + hh.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + hh.write("* See the License for the specific language governing permissions and\n"); + hh.write("* limitations under the License.\n"); + hh.write("*/\n"); + hh.write("\n"); + + cc.write("/**\n"); + cc.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + cc.write("* or more contributor license agreements. See the NOTICE file\n"); + cc.write("* distributed with this work for additional information\n"); + cc.write("* regarding copyright ownership. The ASF licenses this file\n"); + cc.write("* to you under the Apache License, Version 2.0 (the\n"); + cc.write("* \"License\"); you may not use this file except in compliance\n"); + cc.write("* with the License. You may obtain a copy of the License at\n"); + cc.write("*\n"); + cc.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + cc.write("*\n"); + cc.write("* Unless required by applicable law or agreed to in writing, software\n"); + cc.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + cc.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + cc.write("* See the License for the specific language governing permissions and\n"); + cc.write("* limitations under the License.\n"); + cc.write("*/\n"); + cc.write("\n"); + + hh.write("#ifndef __" + mName.toUpperCase().replace('.', '_') + "__\n"); + hh.write("#define __" + mName.toUpperCase().replace('.', '_') + "__\n"); + + hh.write("#include \"recordio.hh\"\n"); + for (Iterator i = mInclFiles.iterator(); i.hasNext(); ) { + JFile f = i.next(); + hh.write("#include \"" + f.getName() + ".hh\"\n"); + } + cc.write("#include \"" + mName + ".hh\"\n"); + + for (Iterator i = mRecList.iterator(); i.hasNext(); ) { + JRecord jr = i.next(); + jr.genCppCode(hh, cc); + } + + hh.write("#endif //" + mName.toUpperCase().replace('.', '_') + "__\n"); + + hh.close(); + cc.close(); + } +} diff --git a/src/java/main/org/apache/jute/compiler/JBoolean.java b/src/java/main/org/apache/jute/compiler/JBoolean.java new file mode 100644 index 00000000000..f6aa73070cb --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JBoolean.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JBoolean extends JType { + + /** Creates a new instance of JBoolean */ + public JBoolean() { + super("int32_t", "bool", "bool", "boolean", "Bool", "Boolean", "bool", "toBoolean"); + } + + public String getSignature() { + return "z"; + } + + public String genJavaCompareTo(String fname) { + return " ret = (" + fname + " == peer." + fname + ")? 0 : (" + fname + "?1:-1);\n"; + } + + public String genJavaHashCode(String fname) { + return " ret = (" + fname + ")?0:1;\n"; + } + + String genCsharpHashCode(String fname) { + return " ret = (" + capitalize(fname) + ")?0:1;\n"; + } + + String genCsharpCompareTo(String name) { + return " ret = (" + capitalize(name) + " == peer." + capitalize(name) + ")? 0 : (" + capitalize(name) + "?1:-1);\n"; + } +} diff --git a/src/java/main/org/apache/jute/compiler/JBuffer.java b/src/java/main/org/apache/jute/compiler/JBuffer.java new file mode 100644 index 00000000000..fe277ddb679 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JBuffer.java @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JBuffer extends JCompType { + + /** Creates a new instance of JBuffer */ + public JBuffer() { + super("struct buffer", " ::std::string", "byte[]", "byte[]", "Buffer", "byte[]", "byte[]"); + } + + public String genCppGetSet(String fname, int fIdx) { + String cgetFunc = " virtual const " + getCppType() + "& get" + fname + "() const {\n"; + cgetFunc += " return m" + fname + ";\n"; + cgetFunc += " }\n"; + String getFunc = " virtual " + getCppType() + "& get" + fname + "() {\n"; + getFunc += " bs_.set(" + fIdx + ");return m" + fname + ";\n"; + getFunc += " }\n"; + return cgetFunc + getFunc; + } + + public String getSignature() { + return "B"; + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + String ret = ""; + if (decl) { + ret = " byte[] " + fname + ";\n"; + } + return ret + " " + fname + "=a_.readBuffer(\"" + tag + "\");\n"; + } + + public String genJavaWriteWrapper(String fname, String tag) { + return " a_.writeBuffer(" + fname + ",\"" + tag + "\");\n"; + } + + public String genJavaCompareTo(String fname, String other) { + StringBuilder sb = new StringBuilder(); + sb.append(" {\n"); + sb.append(" byte[] my = " + fname + ";\n"); + sb.append(" byte[] ur = " + other + ";\n"); + sb.append(" ret = org.apache.jute.Utils.compareBytes(my,0,my.length,ur,0,ur.length);\n"); + sb.append(" }\n"); + return sb.toString(); + } + + public String genJavaCompareTo(String fname) { + return genJavaCompareTo(fname, "peer." + fname); + } + + public String genJavaCompareToWrapper(String fname, String other) { + return " " + genJavaCompareTo(fname, other); + } + + public String genJavaEquals(String fname, String peer) { + return " ret = org.apache.jute.Utils.bufEquals(" + fname + "," + peer + ");\n"; + } + + public String genJavaHashCode(String fname) { + return " ret = java.util.Arrays.toString(" + fname + ").hashCode();\n"; + } + + public String genJavaSlurpBytes(String b, String s, String l) { + StringBuilder sb = new StringBuilder(); + sb.append(" {\n"); + sb.append(" int i = org.apache.jute.Utils.readVInt(" + b + ", " + s + ");\n"); + sb.append(" int z = WritableUtils.getVIntSize(i);\n"); + sb.append(" " + s + " += z+i; " + l + " -= (z+i);\n"); + sb.append(" }\n"); + return sb.toString(); + } + + public String genJavaCompareBytes() { + StringBuilder sb = new StringBuilder(); + sb.append(" {\n"); + sb.append(" int i1 = org.apache.jute.Utils.readVInt(b1, s1);\n"); + sb.append(" int i2 = org.apache.jute.Utils.readVInt(b2, s2);\n"); + sb.append(" int z1 = WritableUtils.getVIntSize(i1);\n"); + sb.append(" int z2 = WritableUtils.getVIntSize(i2);\n"); + sb.append(" s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n"); + sb.append(" int r1 = org.apache.jute.Utils.compareBytes(b1,s1,l1,b2,s2,l2);\n"); + sb.append(" if (r1 != 0) { return (r1<0)?-1:0; }\n"); + sb.append(" s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n"); + sb.append(" }\n"); + return sb.toString(); + } +} diff --git a/src/java/main/org/apache/jute/compiler/JByte.java b/src/java/main/org/apache/jute/compiler/JByte.java new file mode 100644 index 00000000000..8bcbb8e4a0d --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JByte.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JByte extends JType { + + /** Creates a new instance of JByte */ + public JByte() { + super("char", "int8_t", "byte", "byte", "Byte", "Byte", "byte", "toByte"); + } + + public String getSignature() { + return "b"; + } +} diff --git a/src/java/main/org/apache/jute/compiler/JCompType.java b/src/java/main/org/apache/jute/compiler/JCompType.java new file mode 100644 index 00000000000..ea9bd931861 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JCompType.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * Abstract base class for all the "compound" types such as ustring, + * buffer, vector, map, and record. + */ +abstract class JCompType extends JType { + + /** Creates a new instance of JCompType */ + JCompType(String cType, String cppType, String csharpType, String javaType, String suffix, String wrapper, String csharpWrapper) { + super(cType, cppType, csharpType, javaType, suffix, wrapper, csharpWrapper, null); + } + + String genCppGetSet(String fname, int fIdx) { + String cgetFunc = " virtual const " + getCppType() + "& get" + fname + "() const {\n"; + cgetFunc += " return m" + fname + ";\n"; + cgetFunc += " }\n"; + String getFunc = " virtual " + getCppType() + "& get" + fname + "() {\n"; + getFunc += " bs_.set(" + fIdx + ");return m" + fname + ";\n"; + getFunc += " }\n"; + return cgetFunc + getFunc; + } + + String genJavaCompareTo(String fname) { + return " ret = " + fname + ".compareTo(peer." + fname + ");\n"; + } + + String genJavaEquals(String fname, String peer) { + return " ret = " + fname + ".equals(" + peer + ");\n"; + } + + String genJavaHashCode(String fname) { + return " ret = " + fname + ".hashCode();\n"; + } + + String genCsharpHashCode(String fname) { + return " ret = " + capitalize(fname) + ".GetHashCode();\n"; + } + + String genCsharpEquals(String name, String peer) { + String[] peerSplit = peer.split("\\."); + return " ret = " + capitalize(name) + ".Equals(" + peerSplit[0] + "." + capitalize(peerSplit[1]) + ");\n"; + } + + String genCsharpCompareTo(String name) { + return " ret = " + capitalize(name) + ".CompareTo(peer." + capitalize(name) + ");\n"; + } +} diff --git a/src/java/main/org/apache/jute/compiler/JDouble.java b/src/java/main/org/apache/jute/compiler/JDouble.java new file mode 100644 index 00000000000..89a3df2821c --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JDouble.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JDouble extends JType { + + /** Creates a new instance of JDouble */ + public JDouble() { + super("double", "double", "double", "double", "Double", "Double", "double", "toDouble"); + } + + public String getSignature() { + return "d"; + } + + public String genJavaHashCode(String fname) { + String tmp = "Double.doubleToLongBits(" + fname + ")"; + return " ret = (int)(" + tmp + "^(" + tmp + ">>>32));\n"; + } + +} diff --git a/src/java/main/org/apache/jute/compiler/JField.java b/src/java/main/org/apache/jute/compiler/JField.java new file mode 100644 index 00000000000..af5cdb8cab8 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JField.java @@ -0,0 +1,134 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JField { + private JType mType; + private String mName; + + /** + * Creates a new instance of JField + */ + public JField(JType type, String name) { + mType = type; + mName = name; + } + + public String getSignature() { + return mType.getSignature(); + } + + public String genCppDecl() { + return mType.genCppDecl(mName); + } + + public String genCDecl() { + return mType.genCDecl(mName); + } + + public String genCsharpDecl() { + return mType.genCsharpDecl(mName); + } + + public String genCsharpConstructorParam(String fname) { + return mType.genCsharpConstructorParam(fname); + } + + public String genJavaDecl() { + return mType.genJavaDecl(mName); + } + + public String genJavaConstructorParam(String fname) { + return mType.genJavaConstructorParam(fname); + } + + public String getName() { + return mName; + } + + public String getCsharpName() { + return "Id".equals(mName) ? "ZKId" : mName; + } + + public String getTag() { + return mName; + } + + public JType getType() { + return mType; + } + + public String genCppGetSet(int fIdx) { + return mType.genCppGetSet(mName, fIdx); + } + + public String genCsharpConstructorSet(String fname) { + return mType.genCsharpConstructorSet(mName, fname); + } + + public String genCsharpGetSet(int fIdx) { + return mType.genCsharpGetSet(getCsharpName(), fIdx); + } + + public String genCsharpWriteMethodName() { + return mType.genCsharpWriteMethod(getCsharpName(), getTag()); + } + + public String genCsharpReadMethodName() { + return mType.genCsharpReadMethod(getCsharpName(), getTag()); + } + + public String genCsharpCompareTo() { + return mType.genCsharpCompareTo(getCsharpName()); + } + + public String genCsharpEquals() { + return mType.genCsharpEquals(getCsharpName(), "peer." + getCsharpName()); + } + + public String genCsharpHashCode() { + return mType.genCsharpHashCode(getCsharpName()); + } + + + public String genJavaGetSet(int fIdx) { + return mType.genJavaGetSet(mName, fIdx); + } + + public String genJavaWriteMethodName() { + return mType.genJavaWriteMethod(getName(), getTag()); + } + + public String genJavaReadMethodName() { + return mType.genJavaReadMethod(getName(), getTag()); + } + + public String genJavaCompareTo() { + return mType.genJavaCompareTo(getName()); + } + + public String genJavaEquals() { + return mType.genJavaEquals(getName(), "peer." + getName()); + } + + public String genJavaHashCode() { + return mType.genJavaHashCode(getName()); + } + + public String genJavaConstructorSet(String fname) { + return mType.genJavaConstructorSet(mName, fname); + } + +} diff --git a/src/java/main/org/apache/jute/compiler/JFile.java b/src/java/main/org/apache/jute/compiler/JFile.java new file mode 100644 index 00000000000..1ff1db23593 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JFile.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +/** + * Container for the Hadoop Record DDL. + * The main components of the file are filename, list of included files, + * and records defined in that file. + * + */ +public class JFile { + + private String mName; + private ArrayList mInclFiles; + private ArrayList mRecords; + + /** Creates a new instance of JFile + * + * @param name possibly full pathname to the file + * @param inclFiles included files (as JFile) + * @param recList List of records defined within this file + */ + public JFile(String name, ArrayList inclFiles, + ArrayList recList) { + mName = name; + mInclFiles = inclFiles; + mRecords = recList; + } + + /** Strip the other pathname components and return the basename */ + String getName() { + int idx = mName.lastIndexOf('/'); + return (idx > 0) ? mName.substring(idx) : mName; + } + + /** Generate record code in given language. Language should be all + * lowercase. + * @param outputDirectory + */ + public void genCode(String language, File outputDirectory) + throws IOException { + if ("c++".equals(language)) { + CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords, + outputDirectory); + gen.genCode(); + } else if ("java".equals(language)) { + JavaGenerator gen = new JavaGenerator(mName, mInclFiles, mRecords, + outputDirectory); + gen.genCode(); + } else if ("c".equals(language)) { + CGenerator gen = new CGenerator(mName, mInclFiles, mRecords, + outputDirectory); + gen.genCode(); + } else if ("csharp".equals(language)) { + CSharpGenerator gen = new CSharpGenerator(mName, mInclFiles, mRecords, + outputDirectory); + gen.genCode(); + } else { + throw new IOException("Cannnot recognize language:" + language); + } + } +} diff --git a/src/java/main/org/apache/jute/compiler/JFloat.java b/src/java/main/org/apache/jute/compiler/JFloat.java new file mode 100644 index 00000000000..d982cca68b3 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JFloat.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JFloat extends JType { + + /** Creates a new instance of JFloat */ + public JFloat() { + super("float", "float", "float", "float", "Float", "Float", "float", "toFloat"); + } + + public String getSignature() { + return "f"; + } + + public String genJavaHashCode(String fname) { + return " ret = Float.floatToIntBits(" + fname + ");\n"; + } + +} diff --git a/src/java/main/org/apache/jute/compiler/JInt.java b/src/java/main/org/apache/jute/compiler/JInt.java new file mode 100644 index 00000000000..dec72263a7a --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JInt.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JInt extends JType { + + /** Creates a new instance of JInt */ + public JInt() { + super("int32_t", "int32_t", "int", "int", "Int", "Integer", "int", "toInt"); + } + + public String getSignature() { + return "i"; + } +} diff --git a/src/java/main/org/apache/jute/compiler/JLong.java b/src/java/main/org/apache/jute/compiler/JLong.java new file mode 100644 index 00000000000..2e1d52a6515 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JLong.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JLong extends JType { + + /** Creates a new instance of JLong */ + public JLong() { + super("int64_t", "int64_t", "long", "long", "Long", "Long", "long", "toLong"); + } + + public String getSignature() { + return "l"; + } + + public String genJavaHashCode(String fname) { + return " ret = (int) (" + fname + "^(" + fname + ">>>32));\n"; + } +} diff --git a/src/java/main/org/apache/jute/compiler/JMap.java b/src/java/main/org/apache/jute/compiler/JMap.java new file mode 100644 index 00000000000..6d8c693d321 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JMap.java @@ -0,0 +1,148 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JMap extends JCompType { + + static private int level = 0; + private JType mKey; + private JType mValue; + + /** Creates a new instance of JMap */ + public JMap(JType t1, JType t2) { + super("#error", " ::std::map<" + t1.getCppType() + "," + t2.getCppType() + ">", + "System.Collections.Generic.SortedDictionary", "java.util.TreeMap", "Map", "System.Collections.Generic.SortedDictionary", "java.util.TreeMap"); + mKey = t1; + mValue = t2; + } + + static private String getLevel() { + return Integer.toString(level); + } + + static private void incrLevel() { + level++; + } + + static private void decrLevel() { + level--; + } + + static private String getId(String id) { + return id + getLevel(); + } + + public String getSignature() { + return "{" + mKey.getSignature() + mValue.getSignature() + "}"; + } + + public String genJavaCompareTo(String fname) { + return " throw new UnsupportedOperationException(\"comparing " + + fname + " is unimplemented\");\n"; + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + StringBuilder ret = new StringBuilder(""); + if (decl) { + ret.append(" java.util.TreeMap " + fname + ";\n"); + } + ret.append(" {\n"); + incrLevel(); + ret.append(" org.apache.jute.Index " + getId("midx") + " = a_.startMap(\"" + tag + "\");\n"); + ret.append(" " + fname + "=new java.util.TreeMap();\n"); + ret.append(" for (; !" + getId("midx") + ".done(); " + getId("midx") + ".incr()) {\n"); + ret.append(mKey.genJavaReadWrapper(getId("k"), getId("k"), true)); + ret.append(mValue.genJavaReadWrapper(getId("v"), getId("v"), true)); + ret.append(" " + fname + ".put(" + getId("k") + "," + getId("v") + ");\n"); + ret.append(" }\n"); + ret.append(" a_.endMap(\"" + tag + "\");\n"); + decrLevel(); + ret.append(" }\n"); + return ret.toString(); + } + + public String genJavaReadMethod(String fname, String tag) { + return genJavaReadWrapper(fname, tag, false); + } + + public String genJavaWriteWrapper(String fname, String tag) { + StringBuilder ret = new StringBuilder(" {\n"); + incrLevel(); + ret.append(" a_.startMap(" + fname + ",\"" + tag + "\");\n"); + ret.append(" java.util.Set " + getId("es") + " = " + fname + ".entrySet();\n"); + ret.append(" for(java.util.Iterator " + getId("midx") + " = " + getId("es") + ".iterator(); " + getId("midx") + ".hasNext(); ) {\n"); + ret.append(" java.util.Map.Entry " + getId("me") + " = (java.util.Map.Entry) " + getId("midx") + ".next();\n"); + ret.append(" " + mKey.getJavaWrapperType() + " " + getId("k") + " = (" + mKey.getJavaWrapperType() + ") " + getId("me") + ".getKey();\n"); + ret.append(" " + mValue.getJavaWrapperType() + " " + getId("v") + " = (" + mValue.getJavaWrapperType() + ") " + getId("me") + ".getValue();\n"); + ret.append(mKey.genJavaWriteWrapper(getId("k"), getId("k"))); + ret.append(mValue.genJavaWriteWrapper(getId("v"), getId("v"))); + ret.append(" }\n"); + ret.append(" a_.endMap(" + fname + ",\"" + tag + "\");\n"); + ret.append(" }\n"); + decrLevel(); + return ret.toString(); + } + + public String genJavaWriteMethod(String fname, String tag) { + return genJavaWriteWrapper(fname, tag); + } + + public String genCsharpWriteWrapper(String fname, int tag) { + StringBuilder ret = new StringBuilder(" {\n"); + incrLevel(); + ret.append(" a_.StartMap(" + fname + ",\"" + tag + "\");\n"); + ret.append(" java.util.Set " + getId("es") + " = " + fname + ".entrySet();\n"); + ret.append(" for(java.util.Iterator " + getId("midx") + " = " + getId("es") + ".iterator(); " + getId("midx") + ".hasNext(); ) {\n"); + ret.append(" java.util.Map.Entry " + getId("me") + " = (java.util.Map.Entry) " + getId("midx") + ".next();\n"); + ret.append(" " + mKey.getCsharpWrapperType() + " " + getId("k") + " = (" + mKey.getCsharpWrapperType() + ") " + getId("me") + ".getKey();\n"); + ret.append(" " + mValue.getCsharpWrapperType() + " " + getId("v") + " = (" + mValue.getCsharpWrapperType() + ") " + getId("me") + ".getValue();\n"); + ret.append(mKey.genCsharpWriteWrapper(getId("k"), getId("k"))); + ret.append(mValue.genCsharpWriteWrapper(getId("v"), getId("v"))); + ret.append(" }\n"); + ret.append(" a_.EndMap(" + fname + ",\"" + tag + "\");\n"); + ret.append(" }\n"); + decrLevel(); + return ret.toString(); + } + + String genCsharpWriteMethod(String fname, int tag) { + return genCsharpWriteWrapper(fname, tag); + } + + public String genCsharpReadWrapper(String fname, int tag, boolean decl) { + StringBuilder ret = new StringBuilder(""); + if (decl) { + ret.append(" System.Collections.SortedDictionary " + capitalize(fname) + ";\n"); + } + ret.append(" {\n"); + incrLevel(); + ret.append(" Org.Apache.Jute.IIndex " + getId("midx") + " = a_.StartMap(\"" + tag + "\");\n"); + ret.append(" " + fname + "= new System.Collections.SortedDictionary();\n"); + ret.append(" for (; !" + getId("midx") + ".done(); " + getId("midx") + ".incr()) {\n"); + ret.append(mKey.genCsharpReadWrapper(getId("k"), getId("k"), true)); + ret.append(mValue.genCsharpReadWrapper(getId("v"), getId("v"), true)); + ret.append(" " + fname + ".Add(" + getId("k") + "," + getId("v") + ");\n"); + ret.append(" }\n"); + ret.append(" a_.EndMap(\"" + tag + "\");\n"); + decrLevel(); + ret.append(" }\n"); + return ret.toString(); + } + + + String genCsharpReadMethod(String fname, int tag) { + return genCsharpReadWrapper(fname, tag, false); + } +} diff --git a/src/java/main/org/apache/jute/compiler/JRecord.java b/src/java/main/org/apache/jute/compiler/JRecord.java new file mode 100644 index 00000000000..07f30189623 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JRecord.java @@ -0,0 +1,752 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +/** + * + */ +public class JRecord extends JCompType { + + static HashMap vectorStructs = new HashMap(); + private String mFQName; + private String mName; + private String mModule; + private ArrayList mFields; + + /** + * Creates a new instance of JRecord + */ + public JRecord(String name, ArrayList flist) { + super("struct " + name.substring(name.lastIndexOf('.') + 1), + name.replaceAll("\\.", "::"), getCsharpFQName(name), name, "Record", name, getCsharpFQName("IRecord")); + mFQName = name; + int idx = name.lastIndexOf('.'); + mName = name.substring(idx + 1); + mModule = name.substring(0, idx); + mFields = flist; + } + + static String extractMethodSuffix(JType t) { + if (t instanceof JRecord) { + return extractStructName(t); + } + return t.getMethodSuffix(); + } + + static private String extractStructName(JType t) { + String type = t.getCType(); + if (!type.startsWith("struct ")) return type; + return type.substring("struct ".length()); + } + + public static String getCsharpFQName(String name) { + String[] packages = name.split("\\."); + StringBuffer fQName = new StringBuffer(); + for (int i = 0; i < packages.length; i++) { + String pack = packages[i]; + pack = capitalize(pack); + pack = "Id".equals(pack) ? "ZKId" : pack; + fQName.append(capitalize(pack)); + if (i != packages.length - 1) fQName.append("."); + } + return fQName.toString(); + } + + public String getName() { + return mName; + } + + public String getCsharpName() { + return "Id".equals(mName) ? "ZKId" : mName; + } + + public String getJavaFQName() { + return mFQName; + } + + public String getCppFQName() { + return mFQName.replaceAll("\\.", "::"); + } + + public String getJavaPackage() { + return mModule; + } + + public String getCppNameSpace() { + return mModule.replaceAll("\\.", "::"); + } + + public String getCsharpNameSpace() { + String[] parts = mModule.split("\\."); + StringBuffer namespace = new StringBuffer(); + for (int i = 0; i < parts.length; i++) { + String capitalized = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1).toLowerCase(); + namespace.append(capitalized); + if (i != parts.length - 1) namespace.append("."); + } + return namespace.toString(); + } + + public ArrayList getFields() { + return mFields; + } + + public String getSignature() { + StringBuilder sb = new StringBuilder(); + sb.append("L").append(mName).append("("); + for (Iterator i = mFields.iterator(); i.hasNext(); ) { + String s = i.next().getSignature(); + sb.append(s); + } + sb.append(")"); + return sb.toString(); + } + + public String genCppDecl(String fname) { + return " " + getCppNameSpace() + "::" + mName + " m" + fname + ";\n"; + } + + public String genJavaReadMethod(String fname, String tag) { + return genJavaReadWrapper(fname, tag, false); + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + StringBuilder ret = new StringBuilder(""); + if (decl) { + ret.append(" " + getJavaFQName() + " " + fname + ";\n"); + } + ret.append(" " + fname + "= new " + getJavaFQName() + "();\n"); + ret.append(" a_.readRecord(" + fname + ",\"" + tag + "\");\n"); + return ret.toString(); + } + + public String genJavaWriteWrapper(String fname, String tag) { + return " a_.writeRecord(" + fname + ",\"" + tag + "\");\n"; + } + + String genCsharpReadMethod(String fname, String tag) { + //return " "+capitalize(fname)+"=a_.Read"+mMethodSuffix+"(" + capitalize(fname) + ",\""+tag+"\");\n"; + return genCsharpReadWrapper(capitalize(fname), tag, false); + } + + public String genCsharpReadWrapper(String fname, String tag, boolean decl) { + StringBuilder ret = new StringBuilder(""); + if (decl) { + ret.append(" " + getCsharpFQName(mFQName) + " " + fname + ";\n"); + } + ret.append(" " + fname + "= new " + getCsharpFQName(mFQName) + "();\n"); + ret.append(" a_.ReadRecord(" + fname + ",\"" + tag + "\");\n"); + return ret.toString(); + } + + public String genCsharpWriteWrapper(String fname, String tag) { + return " a_.WriteRecord(" + fname + ",\"" + tag + "\");\n"; + } + + public void genCCode(FileWriter h, FileWriter c) throws IOException { + for (JField f : mFields) { + if (f.getType() instanceof JVector) { + JVector jv = (JVector) f.getType(); + JType jvType = jv.getElementType(); + String struct_name = JVector.extractVectorName(jvType); + if (vectorStructs.get(struct_name) == null) { + vectorStructs.put(struct_name, struct_name); + h.write("struct " + struct_name + " {\n int32_t count;\n" + jv.getElementType().genCDecl("*data") + "\n};\n"); + h.write("int serialize_" + struct_name + "(struct oarchive *out, const char *tag, struct " + struct_name + " *v);\n"); + h.write("int deserialize_" + struct_name + "(struct iarchive *in, const char *tag, struct " + struct_name + " *v);\n"); + h.write("int allocate_" + struct_name + "(struct " + struct_name + " *v, int32_t len);\n"); + h.write("int deallocate_" + struct_name + "(struct " + struct_name + " *v);\n"); + c.write("int allocate_" + struct_name + "(struct " + struct_name + " *v, int32_t len) {\n"); + c.write(" if (!len) {\n"); + c.write(" v->count = 0;\n"); + c.write(" v->data = 0;\n"); + c.write(" } else {\n"); + c.write(" v->count = len;\n"); + c.write(" v->data = calloc(sizeof(*v->data), len);\n"); + c.write(" }\n"); + c.write(" return 0;\n"); + c.write("}\n"); + c.write("int deallocate_" + struct_name + "(struct " + struct_name + " *v) {\n"); + c.write(" if (v->data) {\n"); + c.write(" int32_t i;\n"); + c.write(" for(i=0;icount; i++) {\n"); + c.write(" deallocate_" + JRecord.extractMethodSuffix(jvType) + "(&v->data[i]);\n"); + c.write(" }\n"); + c.write(" free(v->data);\n"); + c.write(" v->data = 0;\n"); + c.write(" }\n"); + c.write(" return 0;\n"); + c.write("}\n"); + c.write("int serialize_" + struct_name + "(struct oarchive *out, const char *tag, struct " + struct_name + " *v)\n"); + c.write("{\n"); + c.write(" int32_t count = v->count;\n"); + c.write(" int rc = 0;\n"); + c.write(" int32_t i;\n"); + c.write(" rc = out->start_vector(out, tag, &count);\n"); + c.write(" for(i=0;icount;i++) {\n"); + genSerialize(c, jvType, "data", "data[i]"); + c.write(" }\n"); + c.write(" rc = rc ? rc : out->end_vector(out, tag);\n"); + c.write(" return rc;\n"); + c.write("}\n"); + c.write("int deserialize_" + struct_name + "(struct iarchive *in, const char *tag, struct " + struct_name + " *v)\n"); + c.write("{\n"); + c.write(" int rc = 0;\n"); + c.write(" int32_t i;\n"); + c.write(" rc = in->start_vector(in, tag, &v->count);\n"); + c.write(" v->data = calloc(v->count, sizeof(*v->data));\n"); + c.write(" for(i=0;icount;i++) {\n"); + genDeserialize(c, jvType, "value", "data[i]"); + c.write(" }\n"); + c.write(" rc = in->end_vector(in, tag);\n"); + c.write(" return rc;\n"); + c.write("}\n"); + + } + } + } + String rec_name = getName(); + h.write("struct " + rec_name + " {\n"); + for (JField f : mFields) { + h.write(f.genCDecl()); + } + h.write("};\n"); + h.write("int serialize_" + rec_name + "(struct oarchive *out, const char *tag, struct " + rec_name + " *v);\n"); + h.write("int deserialize_" + rec_name + "(struct iarchive *in, const char *tag, struct " + rec_name + "*v);\n"); + h.write("void deallocate_" + rec_name + "(struct " + rec_name + "*);\n"); + c.write("int serialize_" + rec_name + "(struct oarchive *out, const char *tag, struct " + rec_name + " *v)"); + c.write("{\n"); + c.write(" int rc;\n"); + c.write(" rc = out->start_record(out, tag);\n"); + for (JField f : mFields) { + genSerialize(c, f.getType(), f.getTag(), f.getName()); + } + c.write(" rc = rc ? rc : out->end_record(out, tag);\n"); + c.write(" return rc;\n"); + c.write("}\n"); + c.write("int deserialize_" + rec_name + "(struct iarchive *in, const char *tag, struct " + rec_name + "*v)"); + c.write("{\n"); + c.write(" int rc;\n"); + c.write(" rc = in->start_record(in, tag);\n"); + for (JField f : mFields) { + genDeserialize(c, f.getType(), f.getTag(), f.getName()); + } + c.write(" rc = rc ? rc : in->end_record(in, tag);\n"); + c.write(" return rc;\n"); + c.write("}\n"); + c.write("void deallocate_" + rec_name + "(struct " + rec_name + "*v)"); + c.write("{\n"); + for (JField f : mFields) { + if (f.getType() instanceof JRecord) { + c.write(" deallocate_" + extractStructName(f.getType()) + "(&v->" + f.getName() + ");\n"); + } else if (f.getType() instanceof JVector) { + JVector vt = (JVector) f.getType(); + c.write(" deallocate_" + JVector.extractVectorName(vt.getElementType()) + "(&v->" + f.getName() + ");\n"); + } else if (f.getType() instanceof JCompType) { + c.write(" deallocate_" + extractMethodSuffix(f.getType()) + "(&v->" + f.getName() + ");\n"); + } + } + c.write("}\n"); + } + + private void genSerialize(FileWriter c, JType type, String tag, String name) throws IOException { + if (type instanceof JRecord) { + c.write(" rc = rc ? rc : serialize_" + extractStructName(type) + "(out, \"" + tag + "\", &v->" + name + ");\n"); + } else if (type instanceof JVector) { + c.write(" rc = rc ? rc : serialize_" + JVector.extractVectorName(((JVector) type).getElementType()) + "(out, \"" + tag + "\", &v->" + name + ");\n"); + } else { + c.write(" rc = rc ? rc : out->serialize_" + extractMethodSuffix(type) + "(out, \"" + tag + "\", &v->" + name + ");\n"); + } + } + + private void genDeserialize(FileWriter c, JType type, String tag, String name) throws IOException { + if (type instanceof JRecord) { + c.write(" rc = rc ? rc : deserialize_" + extractStructName(type) + "(in, \"" + tag + "\", &v->" + name + ");\n"); + } else if (type instanceof JVector) { + c.write(" rc = rc ? rc : deserialize_" + JVector.extractVectorName(((JVector) type).getElementType()) + "(in, \"" + tag + "\", &v->" + name + ");\n"); + } else { + c.write(" rc = rc ? rc : in->deserialize_" + extractMethodSuffix(type) + "(in, \"" + tag + "\", &v->" + name + ");\n"); + } + } + + public void genCppCode(FileWriter hh, FileWriter cc) + throws IOException { + String[] ns = getCppNameSpace().split("::"); + for (int i = 0; i < ns.length; i++) { + hh.write("namespace " + ns[i] + " {\n"); + } + + hh.write("class " + getName() + " : public ::hadoop::Record {\n"); + hh.write("private:\n"); + + for (Iterator i = mFields.iterator(); i.hasNext(); ) { + JField jf = i.next(); + hh.write(jf.genCppDecl()); + } + hh.write(" mutable std::bitset<" + mFields.size() + "> bs_;\n"); + hh.write("public:\n"); + hh.write(" virtual void serialize(::hadoop::OArchive& a_, const char* tag) const;\n"); + hh.write(" virtual void deserialize(::hadoop::IArchive& a_, const char* tag);\n"); + hh.write(" virtual const ::std::string& type() const;\n"); + hh.write(" virtual const ::std::string& signature() const;\n"); + hh.write(" virtual bool validate() const;\n"); + hh.write(" virtual bool operator<(const " + getName() + "& peer_) const;\n"); + hh.write(" virtual bool operator==(const " + getName() + "& peer_) const;\n"); + hh.write(" virtual ~" + getName() + "() {};\n"); + int fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + hh.write(jf.genCppGetSet(fIdx)); + } + hh.write("}; // end record " + getName() + "\n"); + for (int i = ns.length - 1; i >= 0; i--) { + hh.write("} // end namespace " + ns[i] + "\n"); + } + cc.write("void " + getCppFQName() + "::serialize(::hadoop::OArchive& a_, const char* tag) const {\n"); + cc.write(" if (!validate()) throw new ::hadoop::IOException(\"All fields not set.\");\n"); + cc.write(" a_.startRecord(*this,tag);\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + String name = jf.getName(); + if (jf.getType() instanceof JBuffer) { + cc.write(" a_.serialize(m" + name + ",m" + name + ".length(),\"" + jf.getTag() + "\");\n"); + } else { + cc.write(" a_.serialize(m" + name + ",\"" + jf.getTag() + "\");\n"); + } + cc.write(" bs_.reset(" + fIdx + ");\n"); + } + cc.write(" a_.endRecord(*this,tag);\n"); + cc.write(" return;\n"); + cc.write("}\n"); + + cc.write("void " + getCppFQName() + "::deserialize(::hadoop::IArchive& a_, const char* tag) {\n"); + cc.write(" a_.startRecord(*this,tag);\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + String name = jf.getName(); + if (jf.getType() instanceof JBuffer) { + cc.write(" { size_t len=0; a_.deserialize(m" + name + ",len,\"" + jf.getTag() + "\");}\n"); + } else { + cc.write(" a_.deserialize(m" + name + ",\"" + jf.getTag() + "\");\n"); + } + cc.write(" bs_.set(" + fIdx + ");\n"); + } + cc.write(" a_.endRecord(*this,tag);\n"); + cc.write(" return;\n"); + cc.write("}\n"); + + cc.write("bool " + getCppFQName() + "::validate() const {\n"); + cc.write(" if (bs_.size() != bs_.count()) return false;\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = (JField) i.next(); + JType type = jf.getType(); + if (type instanceof JRecord) { + cc.write(" if (!m" + jf.getName() + ".validate()) return false;\n"); + } + } + cc.write(" return true;\n"); + cc.write("}\n"); + + cc.write("bool " + getCppFQName() + "::operator< (const " + getCppFQName() + "& peer_) const {\n"); + cc.write(" return (1\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); ) { + JField jf = i.next(); + String name = jf.getName(); + cc.write(" && (m" + name + " < peer_.m" + name + ")\n"); + } + cc.write(" );\n"); + cc.write("}\n"); + + cc.write("bool " + getCppFQName() + "::operator== (const " + getCppFQName() + "& peer_) const {\n"); + cc.write(" return (1\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); ) { + JField jf = i.next(); + String name = jf.getName(); + cc.write(" && (m" + name + " == peer_.m" + name + ")\n"); + } + cc.write(" );\n"); + cc.write("}\n"); + + cc.write("const ::std::string&" + getCppFQName() + "::type() const {\n"); + cc.write(" static const ::std::string type_(\"" + mName + "\");\n"); + cc.write(" return type_;\n"); + cc.write("}\n"); + + cc.write("const ::std::string&" + getCppFQName() + "::signature() const {\n"); + cc.write(" static const ::std::string sig_(\"" + getSignature() + "\");\n"); + cc.write(" return sig_;\n"); + cc.write("}\n"); + + } + + public void genJavaCode(File outputDirectory) throws IOException { + String pkg = getJavaPackage(); + String pkgpath = pkg.replaceAll("\\.", "/"); + File pkgdir = new File(outputDirectory, pkgpath); + if (!pkgdir.exists()) { + // create the pkg directory + if (!pkgdir.mkdirs()) { + throw new IOException("Cannnot create directory: " + pkgpath); + } + } else if (!pkgdir.isDirectory()) { + throw new IOException(pkgpath + " is not a directory."); + } + File jfile = new File(pkgdir, getName() + ".java"); + FileWriter jj = new FileWriter(jfile); + jj.write("// File generated by hadoop record compiler. Do not edit.\n"); + jj.write("/**\n"); + jj.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + jj.write("* or more contributor license agreements. See the NOTICE file\n"); + jj.write("* distributed with this work for additional information\n"); + jj.write("* regarding copyright ownership. The ASF licenses this file\n"); + jj.write("* to you under the Apache License, Version 2.0 (the\n"); + jj.write("* \"License\"); you may not use this file except in compliance\n"); + jj.write("* with the License. You may obtain a copy of the License at\n"); + jj.write("*\n"); + jj.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + jj.write("*\n"); + jj.write("* Unless required by applicable law or agreed to in writing, software\n"); + jj.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + jj.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + jj.write("* See the License for the specific language governing permissions and\n"); + jj.write("* limitations under the License.\n"); + jj.write("*/\n"); + jj.write("\n"); + jj.write("package " + getJavaPackage() + ";\n\n"); + jj.write("import org.apache.jute.*;\n"); + jj.write("public class " + getName() + " implements Record {\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); ) { + JField jf = i.next(); + jj.write(jf.genJavaDecl()); + } + jj.write(" public " + getName() + "() {\n"); + jj.write(" }\n"); + + jj.write(" public " + getName() + "(\n"); + int fIdx = 0; + int fLen = mFields.size(); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaConstructorParam(jf.getName())); + jj.write((fLen - 1 == fIdx) ? "" : ",\n"); + } + jj.write(") {\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaConstructorSet(jf.getName())); + } + jj.write(" }\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaGetSet(fIdx)); + } + jj.write(" public void serialize(OutputArchive a_, String tag) throws java.io.IOException {\n"); + jj.write(" a_.startRecord(this,tag);\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaWriteMethodName()); + } + jj.write(" a_.endRecord(this,tag);\n"); + jj.write(" }\n"); + + jj.write(" public void deserialize(InputArchive a_, String tag) throws java.io.IOException {\n"); + jj.write(" a_.startRecord(tag);\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaReadMethodName()); + } + jj.write(" a_.endRecord(tag);\n"); + jj.write("}\n"); + + jj.write(" public String toString() {\n"); + jj.write(" try {\n"); + jj.write(" java.io.ByteArrayOutputStream s =\n"); + jj.write(" new java.io.ByteArrayOutputStream();\n"); + jj.write(" CsvOutputArchive a_ = \n"); + jj.write(" new CsvOutputArchive(s);\n"); + jj.write(" a_.startRecord(this,\"\");\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaWriteMethodName()); + } + jj.write(" a_.endRecord(this,\"\");\n"); + jj.write(" return new String(s.toByteArray(), \"UTF-8\");\n"); + jj.write(" } catch (Throwable ex) {\n"); + jj.write(" ex.printStackTrace();\n"); + jj.write(" }\n"); + jj.write(" return \"ERROR\";\n"); + jj.write(" }\n"); + + jj.write(" public void write(java.io.DataOutput out) throws java.io.IOException {\n"); + jj.write(" BinaryOutputArchive archive = new BinaryOutputArchive(out);\n"); + jj.write(" serialize(archive, \"\");\n"); + jj.write(" }\n"); + + jj.write(" public void readFields(java.io.DataInput in) throws java.io.IOException {\n"); + jj.write(" BinaryInputArchive archive = new BinaryInputArchive(in);\n"); + jj.write(" deserialize(archive, \"\");\n"); + jj.write(" }\n"); + + jj.write(" public int compareTo (Object peer_) throws ClassCastException {\n"); + boolean unimplemented = false; + for (JField f : mFields) { + if ((f.getType() instanceof JMap) + || (f.getType() instanceof JVector)) { + unimplemented = true; + } + } + if (unimplemented) { + jj.write(" throw new UnsupportedOperationException(\"comparing " + + getName() + " is unimplemented\");\n"); + } else { + jj.write(" if (!(peer_ instanceof " + getName() + ")) {\n"); + jj.write(" throw new ClassCastException(\"Comparing different types of records.\");\n"); + jj.write(" }\n"); + jj.write(" " + getName() + " peer = (" + getName() + ") peer_;\n"); + jj.write(" int ret = 0;\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaCompareTo()); + jj.write(" if (ret != 0) return ret;\n"); + } + jj.write(" return ret;\n"); + } + jj.write(" }\n"); + + jj.write(" public boolean equals(Object peer_) {\n"); + jj.write(" if (!(peer_ instanceof " + getName() + ")) {\n"); + jj.write(" return false;\n"); + jj.write(" }\n"); + jj.write(" if (peer_ == this) {\n"); + jj.write(" return true;\n"); + jj.write(" }\n"); + jj.write(" " + getName() + " peer = (" + getName() + ") peer_;\n"); + jj.write(" boolean ret = false;\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaEquals()); + jj.write(" if (!ret) return ret;\n"); + } + jj.write(" return ret;\n"); + jj.write(" }\n"); + + jj.write(" public int hashCode() {\n"); + jj.write(" int result = 17;\n"); + jj.write(" int ret;\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + jj.write(jf.genJavaHashCode()); + jj.write(" result = 37*result + ret;\n"); + } + jj.write(" return result;\n"); + jj.write(" }\n"); + jj.write(" public static String signature() {\n"); + jj.write(" return \"" + getSignature() + "\";\n"); + jj.write(" }\n"); + + jj.write("}\n"); + + jj.close(); + } + + public void genCsharpCode(File outputDirectory) throws IOException { + if (!outputDirectory.exists()) { + // create the pkg directory + if (!outputDirectory.mkdirs()) { + throw new IOException("Cannnot create directory: " + outputDirectory); + } + } else if (!outputDirectory.isDirectory()) { + throw new IOException(outputDirectory + " is not a directory."); + } + File csharpFile = new File(outputDirectory, getName() + ".cs"); + FileWriter cs = new FileWriter(csharpFile); + cs.write("// File generated by hadoop record compiler. Do not edit.\n"); + cs.write("/**\n"); + cs.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + cs.write("* or more contributor license agreements. See the NOTICE file\n"); + cs.write("* distributed with this work for additional information\n"); + cs.write("* regarding copyright ownership. The ASF licenses this file\n"); + cs.write("* to you under the Apache License, Version 2.0 (the\n"); + cs.write("* \"License\"); you may not use this file except in compliance\n"); + cs.write("* with the License. You may obtain a copy of the License at\n"); + cs.write("*\n"); + cs.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + cs.write("*\n"); + cs.write("* Unless required by applicable law or agreed to in writing, software\n"); + cs.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + cs.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + cs.write("* See the License for the specific language governing permissions and\n"); + cs.write("* limitations under the License.\n"); + cs.write("*/\n"); + cs.write("\n"); + cs.write("using System;\n"); + cs.write("using Org.Apache.Jute;\n"); + cs.write("\n"); + cs.write("namespace " + getCsharpNameSpace() + "\n"); + cs.write("{\n"); + + String className = getCsharpName(); + cs.write("public class " + className + " : IRecord, IComparable \n"); + cs.write("{\n"); + cs.write(" public " + className + "() {\n"); + cs.write(" }\n"); + + cs.write(" public " + className + "(\n"); + int fIdx = 0; + int fLen = mFields.size(); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpConstructorParam(jf.getCsharpName())); + cs.write((fLen - 1 == fIdx) ? "" : ",\n"); + } + cs.write(") {\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpConstructorSet(jf.getCsharpName())); + } + cs.write(" }\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpGetSet(fIdx)); + cs.write("\n"); + } + cs.write(" public void Serialize(IOutputArchive a_, String tag) {\n"); + cs.write(" a_.StartRecord(this,tag);\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpWriteMethodName()); + } + cs.write(" a_.EndRecord(this,tag);\n"); + cs.write(" }\n"); + + cs.write(" public void Deserialize(IInputArchive a_, String tag) {\n"); + cs.write(" a_.StartRecord(tag);\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpReadMethodName()); + } + cs.write(" a_.EndRecord(tag);\n"); + cs.write("}\n"); + + cs.write(" public override String ToString() {\n"); + cs.write(" try {\n"); + cs.write(" System.IO.MemoryStream ms = new System.IO.MemoryStream();\n"); + cs.write(" MiscUtil.IO.EndianBinaryWriter writer =\n"); + cs.write(" new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, ms, System.Text.Encoding.UTF8);\n"); + cs.write(" BinaryOutputArchive a_ = \n"); + cs.write(" new BinaryOutputArchive(writer);\n"); + cs.write(" a_.StartRecord(this,\"\");\n"); + fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpWriteMethodName()); + } + cs.write(" a_.EndRecord(this,\"\");\n"); + cs.write(" ms.Position = 0;\n"); + cs.write(" return System.Text.Encoding.UTF8.GetString(ms.ToArray());\n"); + cs.write(" } catch (Exception ex) {\n"); + cs.write(" Console.WriteLine(ex.StackTrace);\n"); + cs.write(" }\n"); + cs.write(" return \"ERROR\";\n"); + cs.write(" }\n"); + + cs.write(" public void Write(MiscUtil.IO.EndianBinaryWriter writer) {\n"); + cs.write(" BinaryOutputArchive archive = new BinaryOutputArchive(writer);\n"); + cs.write(" Serialize(archive, \"\");\n"); + cs.write(" }\n"); + + cs.write(" public void ReadFields(MiscUtil.IO.EndianBinaryReader reader) {\n"); + cs.write(" BinaryInputArchive archive = new BinaryInputArchive(reader);\n"); + cs.write(" Deserialize(archive, \"\");\n"); + cs.write(" }\n"); + + cs.write(" public int CompareTo (object peer_) {\n"); + boolean unimplemented = false; + for (JField f : mFields) { + if ((f.getType() instanceof JMap) + || (f.getType() instanceof JVector)) { + unimplemented = true; + } + } + if (unimplemented) { + cs.write(" throw new InvalidOperationException(\"comparing " + + getCsharpName() + " is unimplemented\");\n"); + } else { + cs.write(" if (!(peer_ is " + getCsharpName() + ")) {\n"); + cs.write(" throw new InvalidOperationException(\"Comparing different types of records.\");\n"); + cs.write(" }\n"); + cs.write(" " + getCsharpName() + " peer = (" + getCsharpName() + ") peer_;\n"); + cs.write(" int ret = 0;\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpCompareTo()); + cs.write(" if (ret != 0) return ret;\n"); + } + cs.write(" return ret;\n"); + } + cs.write(" }\n"); + + cs.write(" public override bool Equals(object peer_) {\n"); + cs.write(" if (!(peer_ is " + getCsharpName() + ")) {\n"); + cs.write(" return false;\n"); + cs.write(" }\n"); + cs.write(" if (peer_ == this) {\n"); + cs.write(" return true;\n"); + cs.write(" }\n"); + cs.write(" bool ret = false;\n"); + cs.write(" " + getCsharpName() + " peer = (" + getCsharpName() + ")peer_;\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpEquals()); + cs.write(" if (!ret) return ret;\n"); + } + cs.write(" return ret;\n"); + cs.write(" }\n"); + + cs.write(" public override int GetHashCode() {\n"); + cs.write(" int result = 17;\n"); + cs.write(" int ret;\n"); + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = i.next(); + cs.write(jf.genCsharpHashCode()); + cs.write(" result = 37*result + ret;\n"); + } + cs.write(" return result;\n"); + cs.write(" }\n"); + cs.write(" public static string Signature() {\n"); + cs.write(" return \"" + getSignature() + "\";\n"); + cs.write(" }\n"); + + cs.write("}\n"); + cs.write("}\n"); + + cs.close(); + } +} diff --git a/src/java/main/org/apache/jute/compiler/JString.java b/src/java/main/org/apache/jute/compiler/JString.java new file mode 100644 index 00000000000..771472b8c96 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JString.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * + */ +public class JString extends JCompType { + + /** Creates a new instance of JString */ + public JString() { + super("char *", " ::std::string", "string", "String", "String", "String", "string"); + } + + public String getSignature() { + return "s"; + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + String ret = ""; + if (decl) { + ret = " String " + fname + ";\n"; + } + return ret + " " + fname + "=a_.readString(\"" + tag + "\");\n"; + } + + public String genJavaWriteWrapper(String fname, String tag) { + return " a_.writeString(" + fname + ",\"" + tag + "\");\n"; + } +} diff --git a/src/java/main/org/apache/jute/compiler/JType.java b/src/java/main/org/apache/jute/compiler/JType.java new file mode 100644 index 00000000000..2dfbdfb4102 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JType.java @@ -0,0 +1,199 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +/** + * Abstract Base class for all types supported by Hadoop Record I/O. + * + */ +abstract public class JType { + + protected String mMethodSuffix; + private String mCName; + private String mCppName; + private String mCsharpName; + private String mJavaName; + private String mWrapper; + private String mSharpWrapper; + private String mUnwrapMethod; + + /** + * Creates a new instance of JType + */ + JType(String cname, String cppname, String csharpName, String javaname, String suffix, String wrapper, String csharpWrapper, String unwrap) { + mCName = cname; + mCppName = cppname; + mCsharpName = "Id".equals(csharpName) ? "ZKId" : csharpName; + mJavaName = javaname; + mMethodSuffix = suffix; + mWrapper = wrapper; + mSharpWrapper = csharpWrapper; + mUnwrapMethod = unwrap; + } + + static String capitalize(String s) { + return s.substring(0, 1).toUpperCase() + s.substring(1); + } + + abstract String getSignature(); + + String genCppDecl(String fname) { + return " " + mCppName + " m" + fname + ";\n"; + } + + String genCDecl(String name) { + return " " + mCName + " " + name + ";\n"; + } + + public String genCsharpDecl(String name) { + return " private " + mCsharpName + " " + name + ";\n"; + } + + String genJavaDecl(String fname) { + return " private " + mJavaName + " " + fname + ";\n"; + } + + String genJavaConstructorParam(String fname) { + return " " + mJavaName + " " + fname; + } + + String genCppGetSet(String fname, int fIdx) { + String getFunc = " virtual " + mCppName + " get" + fname + "() const {\n"; + getFunc += " return m" + fname + ";\n"; + getFunc += " }\n"; + String setFunc = " virtual void set" + fname + "(" + mCppName + " m_) {\n"; + setFunc += " m" + fname + "=m_; bs_.set(" + fIdx + ");\n"; + setFunc += " }\n"; + return getFunc + setFunc; + } + + String genCsharpGetSet(String fname, int fIdx) { + String getFunc = " public " + getCsharpType() + " " + capitalize(fname) + " { get; set; } "; + return getFunc; + } + + String genJavaGetSet(String fname, int fIdx) { + String getFunc = " public " + mJavaName + " get" + capitalize(fname) + "() {\n"; + getFunc += " return " + fname + ";\n"; + getFunc += " }\n"; + String setFunc = " public void set" + capitalize(fname) + "(" + mJavaName + " m_) {\n"; + setFunc += " " + fname + "=m_;\n"; + setFunc += " }\n"; + return getFunc + setFunc; + } + + String getCType() { + return mCName; + } + + String getCppType() { + return mCppName; + } + + String getCsharpType() { + return mCsharpName; + } + + String getJavaType() { + return mJavaName; + } + + String getJavaWrapperType() { + return mWrapper; + } + + String getCsharpWrapperType() { + return mSharpWrapper; + } + + String getMethodSuffix() { + return mMethodSuffix; + } + + String genJavaWriteMethod(String fname, String tag) { + return " a_.write" + mMethodSuffix + "(" + fname + ",\"" + tag + "\");\n"; + } + + String genJavaReadMethod(String fname, String tag) { + return " " + fname + "=a_.read" + mMethodSuffix + "(\"" + tag + "\");\n"; + } + + String genJavaReadWrapper(String fname, String tag, boolean decl) { + String ret = ""; + if (decl) { + ret = " " + mWrapper + " " + fname + ";\n"; + } + return ret + " " + fname + "=new " + mWrapper + "(a_.read" + mMethodSuffix + "(\"" + tag + "\"));\n"; + } + + String genJavaWriteWrapper(String fname, String tag) { + return " a_.write" + mMethodSuffix + "(" + fname + "." + mUnwrapMethod + "(),\"" + tag + "\");\n"; + } + + String genJavaCompareTo(String fname) { + return " ret = (" + fname + " == peer." + fname + ")? 0 :((" + fname + "", "System.Collections.Generic.List<" + t.getCsharpType() + ">", "java.util.List<" + t.getJavaType() + ">", "Vector", + "System.Collections.Generic.List<" + t.getCsharpType() + ">", "java.util.ArrayList<" + t.getJavaType() + ">"); + mElement = t; + } + + static private String getId(String id) { + return id + getLevel(); + } + + static private String getLevel() { + return Integer.toString(level); + } + + static private void incrLevel() { + level++; + } + + static private void decrLevel() { + level--; + } + + static public String extractVectorName(JType jvType) { + return JRecord.extractMethodSuffix(jvType) + "_vector"; + } + + public String getSignature() { + return "[" + mElement.getSignature() + "]"; + } + + public String genJavaCompareTo(String fname) { + return " throw new UnsupportedOperationException(\"comparing " + + fname + " is unimplemented\");\n"; + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + StringBuilder ret = new StringBuilder(""); + if (decl) { + ret.append(" java.util.List " + fname + ";\n"); + } + ret.append(" {\n"); + incrLevel(); + ret.append(" Index " + getId("vidx") + " = a_.startVector(\"" + tag + "\");\n"); + ret.append(" if (" + getId("vidx") + "!= null) {"); + ret.append(" " + fname + "=new java.util.ArrayList<" + mElement.getJavaType() + ">();\n"); + ret.append(" for (; !" + getId("vidx") + ".done(); " + getId("vidx") + ".incr()) {\n"); + ret.append(mElement.genJavaReadWrapper(getId("e"), getId("e"), true)); + ret.append(" " + fname + ".add(" + getId("e") + ");\n"); + ret.append(" }\n"); + ret.append(" }\n"); + ret.append(" a_.endVector(\"" + tag + "\");\n"); + decrLevel(); + ret.append(" }\n"); + return ret.toString(); + } + + public String genJavaReadMethod(String fname, String tag) { + return genJavaReadWrapper(fname, tag, false); + } + + public String genJavaWriteWrapper(String fname, String tag) { + StringBuilder ret = new StringBuilder(" {\n"); + incrLevel(); + ret.append(" a_.startVector(" + fname + ",\"" + tag + "\");\n"); + ret.append(" if (" + fname + "!= null) {"); + ret.append(" int " + getId("len") + " = " + fname + ".size();\n"); + ret.append(" for(int " + getId("vidx") + " = 0; " + getId("vidx") + "<" + getId("len") + "; " + getId("vidx") + "++) {\n"); + ret.append(" " + mElement.getJavaWrapperType() + " " + getId("e") + " = (" + mElement.getJavaWrapperType() + ") " + fname + ".get(" + getId("vidx") + ");\n"); + ret.append(mElement.genJavaWriteWrapper(getId("e"), getId("e"))); + ret.append(" }\n"); + ret.append(" }\n"); + ret.append(" a_.endVector(" + fname + ",\"" + tag + "\");\n"); + ret.append(" }\n"); + decrLevel(); + return ret.toString(); + } + + public String genJavaWriteMethod(String fname, String tag) { + return genJavaWriteWrapper(fname, tag); + } + + public JType getElementType() { + return mElement; + } + + public String genCsharpWriteWrapper(String fname, String tag) { + StringBuilder ret = new StringBuilder(" {\n"); + incrLevel(); + ret.append(" a_.StartVector(" + capitalize(fname) + ",\"" + tag + "\");\n"); + ret.append(" if (" + capitalize(fname) + "!= null) {"); + ret.append(" int " + getId("len") + " = " + capitalize(fname) + ".Count;\n"); + ret.append(" for(int " + getId("vidx") + " = 0; " + getId("vidx") + "<" + getId("len") + "; " + getId("vidx") + "++) {\n"); + ret.append(" " + mElement.getCsharpWrapperType() + " " + getId("e") + " = (" + mElement.getCsharpWrapperType() + ") " + capitalize(fname) + "[" + getId("vidx") + "];\n"); + ret.append(mElement.genCsharpWriteWrapper(getId("e"), getId("e"))); + ret.append(" }\n"); + ret.append(" }\n"); + ret.append(" a_.EndVector(" + capitalize(fname) + ",\"" + tag + "\");\n"); + ret.append(" }\n"); + decrLevel(); + return ret.toString(); + } + + String genCsharpWriteMethod(String fname, String tag) { + return genCsharpWriteWrapper(fname, tag); + } + + public String genCsharpReadWrapper(String fname, String tag, boolean decl) { + StringBuilder ret = new StringBuilder(""); + if (decl) { + ret.append(" System.Collections.Generic.List<" + mElement.getCsharpType() + "> " + capitalize(fname) + ";\n"); + } + ret.append(" {\n"); + incrLevel(); + ret.append(" IIndex " + getId("vidx") + " = a_.StartVector(\"" + tag + "\");\n"); + ret.append(" if (" + getId("vidx") + "!= null) {"); + ret.append(" " + capitalize(fname) + "=new System.Collections.Generic.List<" + mElement.getCsharpType() + ">();\n"); + ret.append(" for (; !" + getId("vidx") + ".Done(); " + getId("vidx") + ".Incr()) {\n"); + ret.append(mElement.genCsharpReadWrapper(getId("e"), getId("e"), true)); + ret.append(" " + capitalize(fname) + ".Add(" + getId("e") + ");\n"); + ret.append(" }\n"); + ret.append(" }\n"); + ret.append(" a_.EndVector(\"" + tag + "\");\n"); + decrLevel(); + ret.append(" }\n"); + return ret.toString(); + } + + String genCsharpReadMethod(String fname, String tag) { + return genCsharpReadWrapper(fname, tag, false); + } +} diff --git a/src/java/main/org/apache/jute/compiler/JavaGenerator.java b/src/java/main/org/apache/jute/compiler/JavaGenerator.java new file mode 100644 index 00000000000..6c17885a942 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/JavaGenerator.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.jute.compiler; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * Java Code generator front-end for Hadoop record I/O. + */ +class JavaGenerator { + private final File outputDirectory; + private ArrayList mRecList; + + /** Creates a new instance of JavaGenerator + * + * @param name possibly full pathname to the file + * @param incl included files (as JFile) + * @param records List of records defined within this file + * @param outputDirectory + */ + JavaGenerator(String name, ArrayList incl, + ArrayList records, File outputDirectory) { + mRecList = records; + this.outputDirectory = outputDirectory; + } + + /** + * Generate Java code for records. This method is only a front-end to + * JRecord, since one file is generated for each record. + */ + void genCode() throws IOException { + for (Iterator i = mRecList.iterator(); i.hasNext(); ) { + JRecord rec = i.next(); + rec.genJavaCode(outputDirectory); + } + } +} diff --git a/src/java/main/org/apache/jute/compiler/generated/package.html b/src/java/main/org/apache/jute/compiler/generated/package.html new file mode 100644 index 00000000000..3fcc599df56 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/generated/package.html @@ -0,0 +1,28 @@ + + + + + + Hadoop Record Compiler: Parser + + +This package contains code generated by JavaCC from the +Hadoop record syntax file rcc.jj. For details about the +record file syntax please @see org.apache.hadoop.record. + + diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/rcc.jj b/src/java/main/org/apache/jute/compiler/generated/rcc.jj old mode 100755 new mode 100644 similarity index 79% rename from zookeeper/java/src/com/yahoo/jute/compiler/generated/rcc.jj rename to src/java/main/org/apache/jute/compiler/generated/rcc.jj index 9bfd4ee3081..94d4f42f6b3 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/rcc.jj +++ b/src/java/main/org/apache/jute/compiler/generated/rcc.jj @@ -21,27 +21,28 @@ PARSER_BEGIN(Rcc) * limitations under the License. */ -package com.yahoo.jute.compiler.generated; +package org.apache.jute.compiler.generated; -import com.yahoo.jute.compiler.*; +import org.apache.jute.compiler.*; import java.util.ArrayList; import java.util.Hashtable; -import java.util.Iterator; import java.io.File; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.IOException; +@SuppressWarnings("unused") public class Rcc { - private static String language = "java"; - private static ArrayList recFiles = new ArrayList(); - private static JFile curFile; - private static Hashtable recTab; + private static Hashtable recTab = new Hashtable(); private static String curDir = System.getProperty("user.dir"); private static String curFileName; private static String curModuleName; public static void main(String args[]) { + String language = "java"; + ArrayList recFiles = new ArrayList(); + JFile curFile=null; + for (int i=0; i(); + return parser.Input(); + } finally { + try { + reader.close(); + } catch (IOException e) { + } + } + } } PARSER_END(Rcc) @@ -161,10 +167,10 @@ TOKEN : JFile Input() : { - ArrayList ilist = new ArrayList(); - ArrayList rlist = new ArrayList(); + ArrayList ilist = new ArrayList(); + ArrayList rlist = new ArrayList(); JFile i; - ArrayList l; + ArrayList l; } { ( @@ -218,10 +224,10 @@ JFile Include() : } } -ArrayList Module() : +ArrayList Module() : { String mName; - ArrayList rlist; + ArrayList rlist; } { @@ -249,9 +255,9 @@ String ModuleName() : { return name; } } -ArrayList RecordList() : +ArrayList RecordList() : { - ArrayList rlist = new ArrayList(); + ArrayList rlist = new ArrayList(); JRecord r; } { @@ -265,7 +271,7 @@ ArrayList RecordList() : JRecord Record() : { String rname; - ArrayList flist = new ArrayList(); + ArrayList flist = new ArrayList(); Token t; JField f; } @@ -331,7 +337,7 @@ JType Type() : if (rname.indexOf('.', 0) < 0) { rname = curModuleName + "." + rname; } - JRecord r = (JRecord) recTab.get(rname); + JRecord r = recTab.get(rname); if (r == null) { System.out.println("Type " + rname + " not known. Exiting."); System.exit(1); diff --git a/src/java/main/org/apache/jute/compiler/package.html b/src/java/main/org/apache/jute/compiler/package.html new file mode 100644 index 00000000000..2c6c8eb0aa1 --- /dev/null +++ b/src/java/main/org/apache/jute/compiler/package.html @@ -0,0 +1,30 @@ + + + + + + Hadoop Record Compiler + + +This package contains classes needed for code generation +from the hadoop record compiler. CppGenerator and JavaGenerator +are the main entry points from the parser. There are classes +corrsponding to every primitive type and compound type +included in Hadoop record I/O syntax. + + diff --git a/zookeeper/java/src/com/yahoo/jute/package.html b/src/java/main/org/apache/jute/package.html old mode 100755 new mode 100644 similarity index 60% rename from zookeeper/java/src/com/yahoo/jute/package.html rename to src/java/main/org/apache/jute/package.html index bbd5cc44da2..4ec67744e80 --- a/zookeeper/java/src/com/yahoo/jute/package.html +++ b/src/java/main/org/apache/jute/package.html @@ -1,17 +1,33 @@ + - + Hadoop Record I/O - - - Hadoop record I/O contains classes and a record description language - translator for simplifying serialization and deserialization of records in a - language-neutral manner. - -

    Introduction

    - - Software systems of any significant complexity require mechanisms for data + + +Hadoop record I/O contains classes and a record description language +translator for simplifying serialization and deserialization of records in a +language-neutral manner. + +

    Introduction

    + +Software systems of any significant complexity require mechanisms for data interchange with the outside world. These interchanges typically involve the marshaling and unmarshaling of logical units of data to and from data streams (files, network connections, memory buffers etc.). Applications usually have @@ -23,29 +39,29 @@

    Introduction

    written serialization code can be susceptible to bugs especially when records have a large number of fields or a record definition changes between software versions. Lastly, it can be very useful for applications written in different -programming languages to be able to share and interchange data. This can be +programming languages to be able to share and interchange data. This can be made a lot easier by describing the data records manipulated by these applications in a language agnostic manner and using the descriptions to derive -implementations of serialization in multiple target languages. +implementations of serialization in multiple target languages. -This document describes Hadoop Record I/O, a mechanism that is aimed +This document describes Hadoop Record I/O, a mechanism that is aimed at -
      -
    • enabling the specification of simple serializable data types (records) -
    • enabling the generation of code in multiple target languages for -marshaling and unmarshaling such types -
    • providing target language specific support that will enable application -programmers to incorporate generated code into their applications +
        +
      • enabling the specification of simple serializable data types (records) +
      • enabling the generation of code in multiple target languages for + marshaling and unmarshaling such types +
      • providing target language specific support that will enable application + programmers to incorporate generated code into their applications
      The goals of Hadoop Record I/O are similar to those of mechanisms such as XDR, ASN.1, PADS and ICE. While these systems all include a DDL that enables the specification of most record types, they differ widely in what else they focus on. The focus in Hadoop Record I/O is on data marshaling and -multi-lingual support. We take a translator-based approach to serialization. +multi-lingual support. We take a translator-based approach to serialization. Hadoop users have to describe their data in a simple data description language. The Hadoop DDL translator rcc generates code that users -can invoke in order to read/write their data from/to simple stream +can invoke in order to read/write their data from/to simple stream abstractions. Next we list explicitly some of the goals and non-goals of Hadoop Record I/O. @@ -53,45 +69,45 @@

      Introduction

      Goals

        -
      • Support for commonly used primitive types. Hadoop should include as -primitives commonly used builtin types from programming languages we intend to -support. +
      • Support for commonly used primitive types. Hadoop should include as + primitives commonly used builtin types from programming languages we intend to + support. -
      • Support for common data compositions (including recursive compositions). -Hadoop should support widely used composite types such as structs and -vectors. +
      • Support for common data compositions (including recursive compositions). + Hadoop should support widely used composite types such as structs and + vectors. -
      • Code generation in multiple target languages. Hadoop should be capable of -generating serialization code in multiple target languages and should be -easily extensible to new target languages. The initial target languages are -C++ and Java. +
      • Code generation in multiple target languages. Hadoop should be capable of + generating serialization code in multiple target languages and should be + easily extensible to new target languages. The initial target languages are + C++ and Java. -
      • Support for generated target languages. Hadooop should include support -in the form of headers, libraries, packages for supported target languages -that enable easy inclusion and use of generated code in applications. +
      • Support for generated target languages. Hadooop should include support + in the form of headers, libraries, packages for supported target languages + that enable easy inclusion and use of generated code in applications. -
      • Support for multiple output encodings. Candidates include -packed binary, comma-separated text, XML etc. +
      • Support for multiple output encodings. Candidates include + packed binary, comma-separated text, XML etc. -
      • Support for specifying record types in a backwards/forwards compatible -manner. This will probably be in the form of support for optional fields in -records. This version of the document does not include a description of the -planned mechanism, we intend to include it in the next iteration. +
      • Support for specifying record types in a backwards/forwards compatible + manner. This will probably be in the form of support for optional fields in + records. This version of the document does not include a description of the + planned mechanism, we intend to include it in the next iteration.

      Non-Goals

        -
      • Serializing existing arbitrary C++ classes. -
      • Serializing complex data structures such as trees, linked lists etc. -
      • Built-in indexing schemes, compression, or check-sums. -
      • Dynamic construction of objects from an XML schema. +
      • Serializing existing arbitrary C++ classes. +
      • Serializing complex data structures such as trees, linked lists etc. +
      • Built-in indexing schemes, compression, or check-sums. +
      • Dynamic construction of objects from an XML schema.
      The remainder of this document describes the features of Hadoop record I/O in more detail. Section 2 describes the data types supported by the system. -Section 3 lays out the DDL syntax with some examples of simple records. +Section 3 lays out the DDL syntax with some examples of simple records. Section 4 describes the process of code generation with rcc. Section 5 describes target language mappings and support for Hadoop types. We include a fairly complete description of C++ mappings with intent to include Java and @@ -116,16 +132,16 @@

      Primitive Types

      adopted "standard" implementation. The complete list of primitive types is:
        -
      • byte: An 8-bit unsigned integer. -
      • boolean: A boolean value. -
      • int: A 32-bit signed integer. -
      • long: A 64-bit signed integer. -
      • float: A single precision floating point number as described by - IEEE-754. -
      • double: A double precision floating point number as described by - IEEE-754. -
      • ustring: A string consisting of Unicode characters. -
      • buffer: An arbitrary sequence of bytes. +
      • byte: An 8-bit unsigned integer. +
      • boolean: A boolean value. +
      • int: A 32-bit signed integer. +
      • long: A 64-bit signed integer. +
      • float: A single precision floating point number as described by + IEEE-754. +
      • double: A double precision floating point number as described by + IEEE-754. +
      • ustring: A string consisting of Unicode characters. +
      • buffer: An arbitrary sequence of bytes.
      @@ -137,18 +153,18 @@

      Composite Types

        -
      • record: An aggregate type like a C-struct. This is a list of -typed fields that are together considered a single unit of data. A record -is serialized by sequentially serializing its constituent fields. In addition -to serialization a record has comparison operations (equality and less-than) -implemented for it, these are defined as memberwise comparisons. +
      • record: An aggregate type like a C-struct. This is a list of + typed fields that are together considered a single unit of data. A record + is serialized by sequentially serializing its constituent fields. In addition + to serialization a record has comparison operations (equality and less-than) + implemented for it, these are defined as memberwise comparisons. -
      • vector: A sequence of entries of the same data type, primitive -or composite. +
      • vector: A sequence of entries of the same data type, primitive + or composite. -
      • map: An associative container mapping instances of a key type to -instances of a value type. The key and value types may themselves be primitive -or composite types. +
      • map: An associative container mapping instances of a key type to + instances of a value type. The key and value types may themselves be primitive + or composite types.
      @@ -165,7 +181,7 @@

      DDL Syntax and Examples

      We now describe the syntax of the Hadoop data description language. This is followed by a few examples of DDL usage. - +

      Hadoop DDL Syntax

      
      @@ -192,30 +208,30 @@ 

      Hadoop DDL Syntax

        -
      • include: An include declaration specifies a DDL file to be -referenced when generating code for types in the current DDL file. Record types -in the current compilation unit may refer to types in all included files. -File inclusion is recursive. An include does not trigger code -generation for the referenced file. +
      • include: An include declaration specifies a DDL file to be + referenced when generating code for types in the current DDL file. Record types + in the current compilation unit may refer to types in all included files. + File inclusion is recursive. An include does not trigger code + generation for the referenced file. -
      • module: Every Hadoop DDL file must have a single module -declaration that follows the list of includes and precedes all record -declarations. A module declaration identifies a scope within which -the names of all types in the current file are visible. Module names are -mapped to C++ namespaces, Java packages etc. in generated code. +
      • module: Every Hadoop DDL file must have a single module + declaration that follows the list of includes and precedes all record + declarations. A module declaration identifies a scope within which + the names of all types in the current file are visible. Module names are + mapped to C++ namespaces, Java packages etc. in generated code. -
      • class: Records types are specified through class -declarations. A class declaration is like a Java class declaration. -It specifies a named record type and a list of fields that constitute records -of the type. Usage is illustrated in the following examples. +
      • class: Records types are specified through class + declarations. A class declaration is like a Java class declaration. + It specifies a named record type and a list of fields that constitute records + of the type. Usage is illustrated in the following examples.

      Examples

        -
      • A simple DDL file links.jr with just one record declaration. -
        
        +    
      • A simple DDL file links.jr with just one record declaration. +
        
         module links {
             class Link {
                 ustring URL;
        @@ -225,8 +241,8 @@ 

        Examples

        }
        -
      • A DDL file outlinks.jr which includes another -
        
        +    
      • A DDL file outlinks.jr which includes another +
        
         include "links.jr"
         
         module outlinks {
        @@ -240,7 +256,7 @@ 

        Examples

        Code Generation

        -The Hadoop translator is written in Java. Invocation is done by executing a +The Hadoop translator is written in Java. Invocation is done by executing a wrapper shell script named named rcc. It takes a list of record description files as a mandatory argument and an optional language argument (the default is Java) --language or @@ -252,7 +268,7 @@

        Code Generation

        Target Language Mappings and Support

        -For all target languages, the unit of code generation is a record type. +For all target languages, the unit of code generation is a record type. For each record type, Hadoop generates code for serialization and deserialization, record comparison and access to record members. @@ -324,49 +340,49 @@

        C++

          -
        • RecFormat: An enumeration of the serialization encodings supported -by this implementation of Hadoop. +
        • RecFormat: An enumeration of the serialization encodings supported + by this implementation of Hadoop. -
        • InStream: A simple abstraction for an input stream. This has a -single public read method that reads n bytes from the stream into -the buffer buf. Has the same semantics as a blocking read system -call. Returns the number of bytes read or -1 if an error occurs. +
        • InStream: A simple abstraction for an input stream. This has a + single public read method that reads n bytes from the stream into + the buffer buf. Has the same semantics as a blocking read system + call. Returns the number of bytes read or -1 if an error occurs. -
        • OutStream: A simple abstraction for an output stream. This has a -single write method that writes n bytes to the stream from the -buffer buf. Has the same semantics as a blocking write system -call. Returns the number of bytes written or -1 if an error occurs. +
        • OutStream: A simple abstraction for an output stream. This has a + single write method that writes n bytes to the stream from the + buffer buf. Has the same semantics as a blocking write system + call. Returns the number of bytes written or -1 if an error occurs. -
        • RecordReader: A RecordReader reads records one at a time from -an underlying stream in a specified record format. The reader is instantiated -with a stream and a serialization format. It has a read method that -takes an instance of a record and deserializes the record from the stream. +
        • RecordReader: A RecordReader reads records one at a time from + an underlying stream in a specified record format. The reader is instantiated + with a stream and a serialization format. It has a read method that + takes an instance of a record and deserializes the record from the stream. -
        • RecordWriter: A RecordWriter writes records one at a -time to an underlying stream in a specified record format. The writer is -instantiated with a stream and a serialization format. It has a -write method that takes an instance of a record and serializes the -record to the stream. +
        • RecordWriter: A RecordWriter writes records one at a + time to an underlying stream in a specified record format. The writer is + instantiated with a stream and a serialization format. It has a + write method that takes an instance of a record and serializes the + record to the stream. -
        • Record: The base class for all generated record types. This has two -public methods type and signature that return the typename and the -type signature of the record. +
        • Record: The base class for all generated record types. This has two + public methods type and signature that return the typename and the + type signature of the record.
        Two files are generated for each record file (note: not for each record). If a -record file is named "name.jr", the generated files are -"name.jr.cc" and "name.jr.hh" containing serialization +record file is named "name.jr", the generated files are +"name.jr.cc" and "name.jr.hh" containing serialization implementations and record type declarations respectively. For each record in the DDL file, the generated header file will contain a class definition corresponding to the record type, method definitions for the -generated type will be present in the '.cc' file. The generated class will +generated type will be present in the '.cc' file. The generated class will inherit from the abstract class hadoop::Record. The DDL files module declaration determines the namespace the record belongs to. Each '.' delimited token in the module declaration results in the creation of a namespace. For instance, the declaration module docs.links -results in the creation of a docs namespace and a nested +results in the creation of a docs namespace and a nested docs::links namespace. In the preceding examples, the Link class is placed in the links namespace. The header file corresponding to the links.jr file will contain: @@ -382,16 +398,16 @@

        C++

        Each field within the record will cause the generation of a private member declaration of the appropriate type in the class declaration, and one or more acccessor methods. The generated class will implement the serialize and -deserialize methods defined in hadoop::Record+. It will also +deserialize methods defined in hadoop::Record+. It will also implement the inspection methods type and signature from hadoop::Record. A default constructor and virtual destructor will also be generated. Serialization code will read/write records into streams that implement the hadoop::InStream and the hadoop::OutStream interfaces. -For each member of a record an accessor method is generated that returns -either the member or a reference to the member. For members that are returned -by value, a setter method is also generated. This is true for primitive -data members of the types byte, int, long, boolean, float and +For each member of a record an accessor method is generated that returns +either the member or a reference to the member. For members that are returned +by value, a setter method is also generated. This is true for primitive +data members of the types byte, int, long, boolean, float and double. For example, for a int field called MyField the folowing code is generated. @@ -615,34 +631,34 @@

        Binary Serialization Format

        Composite types are serialized as follows:
          -
        • class: Sequence of serialized members. -
        • vector: The number of elements serialized as an int. Followed by a -sequence of serialized elements. -
        • map: The number of key value pairs serialized as an int. Followed -by a sequence of serialized (key,value) pairs. +
        • class: Sequence of serialized members. +
        • vector: The number of elements serialized as an int. Followed by a + sequence of serialized elements. +
        • map: The number of key value pairs serialized as an int. Followed + by a sequence of serialized (key,value) pairs.
        Serialization of primitives is more interesting, with a zero compression -optimization for integral types and normalization to UTF-8 for strings. +optimization for integral types and normalization to UTF-8 for strings. Primitive types are serialized as follows:
          -
        • byte: Represented by 1 byte, as is. -
        • boolean: Represented by 1-byte (0 or 1) -
        • int/long: Integers and longs are serialized zero compressed. -Represented as 1-byte if -120 <= value < 128. Otherwise, serialized as a -sequence of 2-5 bytes for ints, 2-9 bytes for longs. The first byte represents -the number of trailing bytes, N, as the negative number (-120-N). For example, -the number 1024 (0x400) is represented by the byte sequence 'x86 x04 x00'. -This doesn't help much for 4-byte integers but does a reasonably good job with -longs without bit twiddling. -
        • float/double: Serialized in IEEE 754 single and double precision -format in network byte order. This is the format used by Java. -
        • ustring: Serialized as 4-byte zero compressed length followed by -data encoded as UTF-8. Strings are normalized to UTF-8 regardless of native -language representation. -
        • buffer: Serialized as a 4-byte zero compressed length followed by the -raw bytes in the buffer. +
        • byte: Represented by 1 byte, as is. +
        • boolean: Represented by 1-byte (0 or 1) +
        • int/long: Integers and longs are serialized zero compressed. + Represented as 1-byte if -120 <= value < 128. Otherwise, serialized as a + sequence of 2-5 bytes for ints, 2-9 bytes for longs. The first byte represents + the number of trailing bytes, N, as the negative number (-120-N). For example, + the number 1024 (0x400) is represented by the byte sequence 'x86 x04 x00'. + This doesn't help much for 4-byte integers but does a reasonably good job with + longs without bit twiddling. +
        • float/double: Serialized in IEEE 754 single and double precision + format in network byte order. This is the format used by Java. +
        • ustring: Serialized as 4-byte zero compressed length followed by + data encoded as UTF-8. Strings are normalized to UTF-8 regardless of native + language representation. +
        • buffer: Serialized as a 4-byte zero compressed length followed by the + raw bytes in the buffer.
        @@ -652,20 +668,20 @@

        CSV Serialization Format

        Excel CSV format, but we believe the additional structure is useful because
          -
        • it makes parsing a lot easier without detracting too much from legibility -
        • the delimiters around composites make it obvious when one is reading a -sequence of Hadoop records +
        • it makes parsing a lot easier without detracting too much from legibility +
        • the delimiters around composites make it obvious when one is reading a + sequence of Hadoop records
        Serialization formats for the various types are detailed in the grammar that -follows. The notable feature of the formats is the use of delimiters for +follows. The notable feature of the formats is the use of delimiters for indicating the certain field types.
          -
        • A string field begins with a single quote ('). -
        • A buffer field begins with a sharp (#). -
        • A class, vector or map begins with 's{', 'v{' or 'm{' respectively and -ends with '}'. +
        • A string field begins with a single quote ('). +
        • A buffer field begins with a sharp (#). +
        • A class, vector or map begins with 's{', 'v{' or 'm{' respectively and + ends with '}'.
        The CSV format can be described by the following grammar: @@ -701,44 +717,44 @@

        XML Serialization Format

        records is always UTF-8. Primitive types are serialized as follows:
          -
        • byte: XML tag <ex:i1>. Values: 1-byte unsigned -integers represented in US-ASCII -
        • boolean: XML tag <boolean>. Values: "0" or "1" -
        • int: XML tags <i4> or <int>. Values: 4-byte -signed integers represented in US-ASCII. -
        • long: XML tag <ex:i8>. Values: 8-byte signed integers -represented in US-ASCII. -
        • float: XML tag <ex:float>. Values: Single precision -floating point numbers represented in US-ASCII. -
        • double: XML tag <double>. Values: Double precision -floating point numbers represented in US-ASCII. -
        • ustring: XML tag <;string>. Values: String values -represented as UTF-8. XML does not permit all Unicode characters in literal -data. In particular, NULLs and control chars are not allowed. Additionally, -XML processors are required to replace carriage returns with line feeds and to -replace CRLF sequences with line feeds. Programming languages that we work -with do not impose these restrictions on string types. To work around these -restrictions, disallowed characters and CRs are percent escaped in strings. -The '%' character is also percent escaped. -
        • buffer: XML tag <string&>. Values: Arbitrary binary -data. Represented as hexBinary, each byte is replaced by its 2-byte -hexadecimal representation. +
        • byte: XML tag <ex:i1>. Values: 1-byte unsigned + integers represented in US-ASCII +
        • boolean: XML tag <boolean>. Values: "0" or "1" +
        • int: XML tags <i4> or <int>. Values: 4-byte + signed integers represented in US-ASCII. +
        • long: XML tag <ex:i8>. Values: 8-byte signed integers + represented in US-ASCII. +
        • float: XML tag <ex:float>. Values: Single precision + floating point numbers represented in US-ASCII. +
        • double: XML tag <double>. Values: Double precision + floating point numbers represented in US-ASCII. +
        • ustring: XML tag <;string>. Values: String values + represented as UTF-8. XML does not permit all Unicode characters in literal + data. In particular, NULLs and control chars are not allowed. Additionally, + XML processors are required to replace carriage returns with line feeds and to + replace CRLF sequences with line feeds. Programming languages that we work + with do not impose these restrictions on string types. To work around these + restrictions, disallowed characters and CRs are percent escaped in strings. + The '%' character is also percent escaped. +
        • buffer: XML tag <string&>. Values: Arbitrary binary + data. Represented as hexBinary, each byte is replaced by its 2-byte + hexadecimal representation.
        Composite types are serialized as follows:
          -
        • class: XML tag <struct>. A struct is a sequence of -<member> elements. Each <member> element has a <name> -element and a <value> element. The <name> is a string that must -match /[a-zA-Z][a-zA-Z0-9_]*/. The value of the member is represented -by a <value> element. +
        • class: XML tag <struct>. A struct is a sequence of + <member> elements. Each <member> element has a <name> + element and a <value> element. The <name> is a string that must + match /[a-zA-Z][a-zA-Z0-9_]*/. The value of the member is represented + by a <value> element. -
        • vector: XML tag <array<. An <array> contains a -single <data> element. The <data> element is a sequence of -<value> elements each of which represents an element of the vector. +
        • vector: XML tag <array<. An <array> contains a + single <data> element. The <data> element is a sequence of + <value> elements each of which represents an element of the vector. -
        • map: XML tag <array>. Same as vector. +
        • map: XML tag <array>. Same as vector.
        @@ -781,5 +797,5 @@

        XML Serialization Format

        </value>
        - + diff --git a/src/java/main/org/apache/recipes/README.txt b/src/java/main/org/apache/recipes/README.txt new file mode 100644 index 00000000000..4f880cdfbba --- /dev/null +++ b/src/java/main/org/apache/recipes/README.txt @@ -0,0 +1,25 @@ +1) This source directory contains various Zookeeper recipe implementations. + +2) The recipe directory name should specify the name of the recipe you are implementing - eg. lock/. + +3) It would be great if you can provide both the java and c recipes for the zookeeper recipes. +The c recipes go in to recipe-name/src/c and the java implementation goes into recipe-name/src/java. + +4) The recipes hold high standards like our zookeeper c/java libraries, so make sure that you include +some unit testing with both the c and java recipe code. + +5) Also, please name your c client public methods as +zkr_recipe-name_methodname +(eg. zkr_lock_lock in lock/src/c) + +6) The various recipes are in ../../docs/recipes.html or +../../docs/reciped.pdf. Also, this is not an exhaustive list by any chance. +Zookeeper is used (and can be used) for more than what we have listed in the docs. + +7) To run the c tests in all the recipes, +- make sure the main zookeeper c libraries in +{top}/src/c/ are compiled. Run autoreconf -if;./configure; make. The libaries +will be installed in {top}/src/c/.libs. +- run autoreconf if;./configure;make run-check + in src/recipes/$recipename/src/c + diff --git a/src/java/main/org/apache/recipes/build-recipes.xml b/src/java/main/org/apache/recipes/build-recipes.xml new file mode 100644 index 00000000000..2e1e511be75 --- /dev/null +++ b/src/java/main/org/apache/recipes/build-recipes.xml @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/main/org/apache/recipes/build.xml b/src/java/main/org/apache/recipes/build.xml new file mode 100644 index 00000000000..78f2dfd98d5 --- /dev/null +++ b/src/java/main/org/apache/recipes/build.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/main/org/apache/recipes/election/README.txt b/src/java/main/org/apache/recipes/election/README.txt new file mode 100644 index 00000000000..10447ed4dac --- /dev/null +++ b/src/java/main/org/apache/recipes/election/README.txt @@ -0,0 +1,27 @@ + + +1) This election interface recipe implements the leader election recipe +mentioned in ../../../docs/recipes.[html,pdf]. + +2) To compile the leader election java recipe you can just run ant jar from +this directory. +Please report any bugs on the jira + +http://issues.apache.org/jira/browse/ZOOKEEPER + + diff --git a/src/java/main/org/apache/recipes/election/build.xml b/src/java/main/org/apache/recipes/election/build.xml new file mode 100644 index 00000000000..3195658a712 --- /dev/null +++ b/src/java/main/org/apache/recipes/election/build.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests failed! + + + + + + + + + + + + + + + + + + diff --git a/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderElectionAware.java b/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderElectionAware.java new file mode 100644 index 00000000000..83404e3d4d6 --- /dev/null +++ b/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderElectionAware.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.recipes.election.src.java.org.apache.zookeeper.recipes.leader; + +import org.apache.recipes.election.src.java.org.apache.zookeeper.recipes.leader.LeaderElectionSupport.EventType; + +/** + * An interface to be implemented by clients that want to receive election events. + */ +public interface LeaderElectionAware { + + /** + * Called during each state transition. Current, low level events are provided at the beginning and end of each state. For instance, START may be followed by OFFER_START, OFFER_COMPLETE, + * DETERMINE_START, DETERMINE_COMPLETE, and so on. + */ + public void onElectionEvent(EventType eventType); + +} diff --git a/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupport.java b/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupport.java new file mode 100644 index 00000000000..3e97db22a50 --- /dev/null +++ b/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupport.java @@ -0,0 +1,386 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.recipes.election.src.java.org.apache.zookeeper.recipes.leader; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + *

        A leader election support library implementing the ZooKeeper election recipe.

        This support library is meant to simplify the construction of an exclusive leader system on top of Apache + * ZooKeeper. Any application that can become the leader (usually a process that provides a service, exclusively) would configure an instance of this class with their hostname, at least one listener + * (an implementation of {@link LeaderElectionAware}), and either an instance of {@link ZooKeeper} or the proper connection information. Once configured, invoking {@link #start()} will cause the + * client to connect to ZooKeeper and create a leader offer. The library then determines if it has been elected the leader using the algorithm described below. The client application can follow all + * state transitions via the listener callback.

        Leader election algorithm

        The library starts in a START state. Through each state transition, a state start and a state complete event + * are sent to all listeners. When {@link #start()} is called, a leader offer is created in ZooKeeper. A leader offer is an ephemeral sequential node that indicates a process that can act as a leader + * for this service. A read of all leader offers is then performed. The offer with the lowest sequence number is said to be the leader. The process elected leader will transition to the leader state. + * All other processes will transition to a ready state. Internally, the library creates a ZooKeeper watch on the leader offer with the sequence ID of N - 1 (where N is the process's sequence ID). If + * that offer disappears due to a process failure, the watching process will run through the election determination process again to see if it should become the leader. Note that sequence ID may not + * be contiguous due to failed processes. A process may revoke its offer to be the leader at any time by calling {@link #stop()}.

        Guarantees (not) Made and Caveats

        • It is + * possible for a (poorly implemented) process to create a leader offer, get the lowest sequence ID, but have something terrible occur where it maintains its connection to ZK (and thus its ephemeral + * leader offer node) but doesn't actually provide the service in question. It is up to the user to ensure any failure to become the leader - and whatever that means in the context of the user's + * application - results in a revocation of its leader offer (i.e. that {@link #stop()} is called).
        • It is possible for ZK timeouts and retries to play a role in service liveliness. In other + * words, if process A has the lowest sequence ID but requires a few attempts to read the other leader offers' sequence IDs, election can seem slow. Users should apply timeouts during the + * determination process if they need to hit a specific SLA.
        • The library makes a "best effort" to detect catastrophic failures of the process. It is possible that an unforeseen event results + * in (for instance) an unchecked exception that propagates passed normal error handling code. This normally doesn't matter as the same exception would almost certain destroy the entire process and + * thus the connection to ZK and the leader offer resulting in another round of leader determination.

        + */ +public class LeaderElectionSupport implements Watcher { + + private static final Logger logger = LoggerFactory + .getLogger(LeaderElectionSupport.class); + + private ZooKeeper zooKeeper; + + private State state; + private Set listeners; + + private String rootNodeName; + private LeaderOffer leaderOffer; + private String hostName; + + public LeaderElectionSupport() { + state = State.STOP; + listeners = Collections.synchronizedSet(new HashSet()); + } + + /** + *

        Start the election process. This method will create a leader offer, determine its status, and either become the leader or become ready. If an instance of {@link ZooKeeper} has not yet been + * configured by the user, a new instance is created using the connectString and sessionTime specified.

        Any (anticipated) failures result in a failed event being sent to all listeners. + *

        + */ + public synchronized void start() { + state = State.START; + dispatchEvent(EventType.START); + + logger.info("Starting leader election support"); + + if (zooKeeper == null) { + throw new IllegalStateException( + "No instance of zookeeper provided. Hint: use setZooKeeper()"); + } + + if (hostName == null) { + throw new IllegalStateException( + "No hostname provided. Hint: use setHostName()"); + } + + try { + makeOffer(); + determineElectionStatus(); + } catch (KeeperException e) { + becomeFailed(e); + return; + } catch (InterruptedException e) { + becomeFailed(e); + return; + } + } + + /** + * Stops all election services, revokes any outstanding leader offers, and disconnects from ZooKeeper. + */ + public synchronized void stop() { + state = State.STOP; + dispatchEvent(EventType.STOP_START); + + logger.info("Stopping leader election support"); + + if (leaderOffer != null) { + try { + zooKeeper.delete(leaderOffer.getNodePath(), -1); + logger.info("Removed leader offer {}", leaderOffer.getNodePath()); + } catch (InterruptedException e) { + becomeFailed(e); + } catch (KeeperException e) { + becomeFailed(e); + } + } + + dispatchEvent(EventType.STOP_COMPLETE); + } + + private void makeOffer() throws KeeperException, InterruptedException { + state = State.OFFER; + dispatchEvent(EventType.OFFER_START); + + leaderOffer = new LeaderOffer(); + + leaderOffer.setHostName(hostName); + leaderOffer.setNodePath(zooKeeper.create(rootNodeName + "/" + "n_", + hostName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL_SEQUENTIAL)); + + logger.debug("Created leader offer {}", leaderOffer); + + dispatchEvent(EventType.OFFER_COMPLETE); + } + + private void determineElectionStatus() throws KeeperException, + InterruptedException { + + state = State.DETERMINE; + dispatchEvent(EventType.DETERMINE_START); + + String[] components = leaderOffer.getNodePath().split("/"); + + leaderOffer.setId(Integer.valueOf(components[components.length - 1] + .substring("n_".length()))); + + List leaderOffers = toLeaderOffers(zooKeeper.getChildren( + rootNodeName, false)); + + /* + * For each leader offer, find out where we fit in. If we're first, we + * become the leader. If we're not elected the leader, attempt to stat the + * offer just less than us. If they exist, watch for their failure, but if + * they don't, become the leader. + */ + for (int i = 0; i < leaderOffers.size(); i++) { + LeaderOffer leaderOffer = leaderOffers.get(i); + + if (leaderOffer.getId().equals(this.leaderOffer.getId())) { + logger.debug("There are {} leader offers. I am {} in line.", + leaderOffers.size(), i); + + dispatchEvent(EventType.DETERMINE_COMPLETE); + + if (i == 0) { + becomeLeader(); + } else { + becomeReady(leaderOffers.get(i - 1)); + } + + /* Once we've figured out where we are, we're done. */ + break; + } + } + } + + private void becomeReady(LeaderOffer neighborLeaderOffer) + throws KeeperException, InterruptedException { + + logger.info("{} not elected leader. Watching node:{}", + leaderOffer.getNodePath(), neighborLeaderOffer.getNodePath()); + + /* + * Make sure to pass an explicit Watcher because we could be sharing this + * zooKeeper instance with someone else. + */ + Stat stat = zooKeeper.exists(neighborLeaderOffer.getNodePath(), this); + + if (stat != null) { + dispatchEvent(EventType.READY_START); + logger.debug( + "We're behind {} in line and they're alive. Keeping an eye on them.", + neighborLeaderOffer.getNodePath()); + state = State.READY; + dispatchEvent(EventType.READY_COMPLETE); + } else { + /* + * If the stat fails, the node has gone missing between the call to + * getChildren() and exists(). We need to try and become the leader. + */ + logger + .info( + "We were behind {} but it looks like they died. Back to determination.", + neighborLeaderOffer.getNodePath()); + determineElectionStatus(); + } + + } + + private void becomeLeader() { + state = State.ELECTED; + dispatchEvent(EventType.ELECTED_START); + + logger.info("Becoming leader with node:{}", leaderOffer.getNodePath()); + + dispatchEvent(EventType.ELECTED_COMPLETE); + } + + private void becomeFailed(Exception e) { + logger.error("Failed in state {} - Exception:{}", state, e); + + state = State.FAILED; + dispatchEvent(EventType.FAILED); + } + + /** + * Fetch the (user supplied) hostname of the current leader. Note that by the time this method returns, state could have changed so do not depend on this to be strongly consistent. This method has + * to read all leader offers from ZooKeeper to deterime who the leader is (i.e. there is no caching) so consider the performance implications of frequent invocation. If there are no leader offers + * this method returns null. + * + * @return hostname of the current leader + */ + public String getLeaderHostName() throws KeeperException, + InterruptedException { + + List leaderOffers = toLeaderOffers(zooKeeper.getChildren( + rootNodeName, false)); + + if (leaderOffers.size() > 0) { + return leaderOffers.get(0).getHostName(); + } + + return null; + } + + private List toLeaderOffers(List strings) + throws KeeperException, InterruptedException { + + List leaderOffers = new ArrayList(strings.size()); + + /* + * Turn each child of rootNodeName into a leader offer. This is a tuple of + * the sequence number and the node name. + */ + for (String offer : strings) { + String hostName = new String(zooKeeper.getData( + rootNodeName + "/" + offer, false, null)); + + leaderOffers.add(new LeaderOffer(Integer.valueOf(offer.substring("n_" + .length())), rootNodeName + "/" + offer, hostName)); + } + + /* + * We sort leader offers by sequence number (which may not be zero-based or + * contiguous) and keep their paths handy for setting watches. + */ + Collections.sort(leaderOffers, new LeaderOffer.IdComparator()); + + return leaderOffers; + } + + @Override + public void process(WatchedEvent event) { + if (event.getType().equals(Watcher.Event.EventType.NodeDeleted)) { + if (!event.getPath().equals(leaderOffer.getNodePath()) + && state != State.STOP) { + logger.debug( + "Node {} deleted. Need to run through the election process.", + event.getPath()); + try { + determineElectionStatus(); + } catch (KeeperException e) { + becomeFailed(e); + } catch (InterruptedException e) { + becomeFailed(e); + } + } + } + } + + private void dispatchEvent(EventType eventType) { + logger.debug("Dispatching event:{}", eventType); + + synchronized (listeners) { + if (listeners.size() > 0) { + for (LeaderElectionAware observer : listeners) { + observer.onElectionEvent(eventType); + } + } + } + } + + /** + * Adds {@code listener} to the list of listeners who will receive events. + */ + public void addListener(LeaderElectionAware listener) { + listeners.add(listener); + } + + /** + * Remove {@code listener} from the list of listeners who receive events. + */ + public void removeListener(LeaderElectionAware listener) { + listeners.remove(listener); + } + + @Override + public String toString() { + return "{ state:" + state + " leaderOffer:" + leaderOffer + " zooKeeper:" + + zooKeeper + " hostName:" + hostName + " listeners:" + listeners + + " }"; + } + + /** + *

        Gets the ZooKeeper root node to use for this service.

        For instance, a root node of {@code /mycompany/myservice} would be the parent of all leader offers for this service. Obviously + * all processes that wish to contend for leader status need to use the same root node. Note: We assume this node already exists.

        + * + * @return a znode path + */ + public String getRootNodeName() { + return rootNodeName; + } + + /** + *

        Sets the ZooKeeper root node to use for this service.

        For instance, a root node of {@code /mycompany/myservice} would be the parent of all leader offers for this service. Obviously + * all processes that wish to contend for leader status need to use the same root node. Note: We assume this node already exists.

        + */ + public void setRootNodeName(String rootNodeName) { + this.rootNodeName = rootNodeName; + } + + /** + * The {@link ZooKeeper} instance to use for all operations. Provided this overrides any connectString or sessionTimeout set. + */ + public ZooKeeper getZooKeeper() { + return zooKeeper; + } + + public void setZooKeeper(ZooKeeper zooKeeper) { + this.zooKeeper = zooKeeper; + } + + /** + * The hostname of this process. Mostly used as a convenience for logging and to respond to {@link #getLeaderHostName()} requests. + */ + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + /** + * The type of event. + */ + public static enum EventType { + START, OFFER_START, OFFER_COMPLETE, DETERMINE_START, DETERMINE_COMPLETE, ELECTED_START, ELECTED_COMPLETE, READY_START, READY_COMPLETE, FAILED, STOP_START, STOP_COMPLETE, + } + + /** + * The internal state of the election support service. + */ + public static enum State { + START, OFFER, DETERMINE, ELECTED, READY, FAILED, STOP + } +} diff --git a/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderOffer.java b/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderOffer.java new file mode 100644 index 00000000000..d710badcf5d --- /dev/null +++ b/src/java/main/org/apache/recipes/election/src/java/org/apache/zookeeper/recipes/leader/LeaderOffer.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.recipes.election.src.java.org.apache.zookeeper.recipes.leader; + +import java.util.Comparator; + +/** + * A leader offer is a numeric id / path pair. The id is the sequential node id assigned by ZooKeeper where as the path is the absolute path to the ZNode. + */ +public class LeaderOffer { + + private Integer id; + private String nodePath; + private String hostName; + + public LeaderOffer() { + // Default constructor + } + + public LeaderOffer(Integer id, String nodePath, String hostName) { + this.id = id; + this.nodePath = nodePath; + this.hostName = hostName; + } + + @Override + public String toString() { + return "{ id:" + id + " nodePath:" + nodePath + " hostName:" + hostName + + " }"; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getNodePath() { + return nodePath; + } + + public void setNodePath(String nodePath) { + this.nodePath = nodePath; + } + + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + /** + * Compare two instances of {@link LeaderOffer} using only the {code}id{code} member. + */ + public static class IdComparator implements Comparator { + + @Override + public int compare(LeaderOffer o1, LeaderOffer o2) { + return o1.getId().compareTo(o2.getId()); + } + + } + +} diff --git a/src/java/main/org/apache/recipes/election/test/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java b/src/java/main/org/apache/recipes/election/test/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java new file mode 100644 index 00000000000..929d95680d1 --- /dev/null +++ b/src/java/main/org/apache/recipes/election/test/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.recipes.election.test.org.apache.zookeeper.recipes.leader; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.recipes.leader.LeaderElectionSupport.EventType; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +public class LeaderElectionSupportTest extends ClientBase { + + private static final Logger logger = LoggerFactory + .getLogger(LeaderElectionSupportTest.class); + private static final String testRootNode = "/" + System.currentTimeMillis() + + "_"; + + private ZooKeeper zooKeeper; + + @Before + public void setUp() throws Exception { + super.setUp(); + + zooKeeper = createClient(); + + zooKeeper.create(testRootNode + Thread.currentThread().getId(), + new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + + @After + public void tearDown() throws Exception { + if (zooKeeper != null) { + zooKeeper.delete(testRootNode + Thread.currentThread().getId(), -1); + } + + super.tearDown(); + } + + @Test + public void testNode() throws IOException, InterruptedException, + KeeperException { + + LeaderElectionSupport electionSupport = createLeaderElectionSupport(); + + electionSupport.start(); + Thread.sleep(3000); + electionSupport.stop(); + } + + @Test + public void testNodes3() throws IOException, InterruptedException, + KeeperException { + + int testIterations = 3; + final CountDownLatch latch = new CountDownLatch(testIterations); + final AtomicInteger failureCounter = new AtomicInteger(); + + for (int i = 0; i < testIterations; i++) { + runElectionSupportThread(latch, failureCounter); + } + + Assert.assertEquals(0, failureCounter.get()); + + if (!latch.await(10, TimeUnit.SECONDS)) { + logger + .info( + "Waited for all threads to start, but timed out. We had {} failures.", + failureCounter); + } + } + + @Test + public void testNodes9() throws IOException, InterruptedException, + KeeperException { + + int testIterations = 9; + final CountDownLatch latch = new CountDownLatch(testIterations); + final AtomicInteger failureCounter = new AtomicInteger(); + + for (int i = 0; i < testIterations; i++) { + runElectionSupportThread(latch, failureCounter); + } + + Assert.assertEquals(0, failureCounter.get()); + + if (!latch.await(10, TimeUnit.SECONDS)) { + logger + .info( + "Waited for all threads to start, but timed out. We had {} failures.", + failureCounter); + } + } + + @Test + public void testNodes20() throws IOException, InterruptedException, + KeeperException { + + int testIterations = 20; + final CountDownLatch latch = new CountDownLatch(testIterations); + final AtomicInteger failureCounter = new AtomicInteger(); + + for (int i = 0; i < testIterations; i++) { + runElectionSupportThread(latch, failureCounter); + } + + Assert.assertEquals(0, failureCounter.get()); + + if (!latch.await(10, TimeUnit.SECONDS)) { + logger + .info( + "Waited for all threads to start, but timed out. We had {} failures.", + failureCounter); + } + } + + @Test + public void testNodes100() throws IOException, InterruptedException, + KeeperException { + + int testIterations = 100; + final CountDownLatch latch = new CountDownLatch(testIterations); + final AtomicInteger failureCounter = new AtomicInteger(); + + for (int i = 0; i < testIterations; i++) { + runElectionSupportThread(latch, failureCounter); + } + + Assert.assertEquals(0, failureCounter.get()); + + if (!latch.await(20, TimeUnit.SECONDS)) { + logger + .info( + "Waited for all threads to start, but timed out. We had {} failures.", + failureCounter); + } + } + + @Test + public void testOfferShuffle() throws InterruptedException { + int testIterations = 10; + final CountDownLatch latch = new CountDownLatch(testIterations); + final AtomicInteger failureCounter = new AtomicInteger(); + List threads = new ArrayList(testIterations); + + for (int i = 1; i <= testIterations; i++) { + threads.add(runElectionSupportThread(latch, failureCounter, + Math.min(i * 1200, 10000))); + } + + if (!latch.await(60, TimeUnit.SECONDS)) { + logger + .info( + "Waited for all threads to start, but timed out. We had {} failures.", + failureCounter); + } + } + + @Test + public void testGetLeaderHostName() throws KeeperException, + InterruptedException { + + LeaderElectionSupport electionSupport = createLeaderElectionSupport(); + + electionSupport.start(); + + // Sketchy: We assume there will be a leader (probably us) in 3 seconds. + Thread.sleep(3000); + + String leaderHostName = electionSupport.getLeaderHostName(); + + Assert.assertNotNull(leaderHostName); + Assert.assertEquals("foohost", leaderHostName); + + electionSupport.stop(); + } + + @Test + public void testReadyOffer() throws Exception { + final ArrayList events = new ArrayList(); + final CountDownLatch electedComplete = new CountDownLatch(1); + + final LeaderElectionSupport electionSupport1 = createLeaderElectionSupport(); + electionSupport1.start(); + LeaderElectionSupport electionSupport2 = createLeaderElectionSupport(); + LeaderElectionAware listener = new LeaderElectionAware() { + boolean stoppedElectedNode = false; + + @Override + public void onElectionEvent(EventType eventType) { + events.add(eventType); + if (!stoppedElectedNode + && eventType == EventType.DETERMINE_COMPLETE) { + stoppedElectedNode = true; + try { + // stopping the ELECTED node, so re-election will happen. + electionSupport1.stop(); + } catch (Exception e) { + logger.error("Unexpected error", e); + } + } + if (eventType == EventType.ELECTED_COMPLETE) { + electedComplete.countDown(); + } + } + }; + electionSupport2.addListener(listener); + electionSupport2.start(); + // waiting for re-election. + electedComplete.await(CONNECTION_TIMEOUT / 3, TimeUnit.MILLISECONDS); + + final ArrayList expectedevents = new ArrayList(); + expectedevents.add(EventType.START); + expectedevents.add(EventType.OFFER_START); + expectedevents.add(EventType.OFFER_COMPLETE); + expectedevents.add(EventType.DETERMINE_START); + expectedevents.add(EventType.DETERMINE_COMPLETE); + expectedevents.add(EventType.DETERMINE_START); + expectedevents.add(EventType.DETERMINE_COMPLETE); + expectedevents.add(EventType.ELECTED_START); + expectedevents.add(EventType.ELECTED_COMPLETE); + Assert.assertEquals("Events has failed to executed in the order", + expectedevents, events); + electionSupport2.stop(); + } + + private LeaderElectionSupport createLeaderElectionSupport() { + LeaderElectionSupport electionSupport = new LeaderElectionSupport(); + + electionSupport.setZooKeeper(zooKeeper); + electionSupport.setRootNodeName(testRootNode + + Thread.currentThread().getId()); + electionSupport.setHostName("foohost"); + + return electionSupport; + } + + private Thread runElectionSupportThread(final CountDownLatch latch, + final AtomicInteger failureCounter) { + return runElectionSupportThread(latch, failureCounter, 3000); + } + + private Thread runElectionSupportThread(final CountDownLatch latch, + final AtomicInteger failureCounter, final long sleepDuration) { + + final LeaderElectionSupport electionSupport = createLeaderElectionSupport(); + + Thread t = new Thread() { + + @Override + public void run() { + try { + electionSupport.start(); + Thread.sleep(sleepDuration); + electionSupport.stop(); + + latch.countDown(); + } catch (Exception e) { + logger.warn("Failed to run leader election due to: {}", + e.getMessage()); + failureCounter.incrementAndGet(); + } + } + }; + + t.start(); + + return t; + } + +} diff --git a/src/java/main/org/apache/recipes/lock/README.txt b/src/java/main/org/apache/recipes/lock/README.txt new file mode 100644 index 00000000000..1fc4fbfc5c8 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/README.txt @@ -0,0 +1,28 @@ + + +1) This lock interface recipe implements the lock recipe +mentioned in ../../../docs/recipes.[html,pdf]. + +2) To compile the lock java recipe you can just run ant jar from +this directory. For compiling the c libarary go to src/c and read +the INSTALLATION instructions. +Please report any bugs on the jira + +http://issues.apache.org/jira/browse/ZOOKEEPER + + diff --git a/src/java/main/org/apache/recipes/lock/build.xml b/src/java/main/org/apache/recipes/lock/build.xml new file mode 100644 index 00000000000..71c74214997 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/build.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests failed! + + + + + + + + + + + + + + + + + + diff --git a/src/java/main/org/apache/recipes/lock/src/c/INSTALL b/src/java/main/org/apache/recipes/lock/src/c/INSTALL new file mode 100644 index 00000000000..5458714e1e2 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/INSTALL @@ -0,0 +1,234 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/src/java/main/org/apache/recipes/lock/src/c/LICENSE b/src/java/main/org/apache/recipes/lock/src/c/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/java/main/org/apache/recipes/lock/src/c/Makefile.am b/src/java/main/org/apache/recipes/lock/src/c/Makefile.am new file mode 100644 index 00000000000..9b36b43e104 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/Makefile.am @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include $(top_srcdir)/aminclude.am + +AM_CFLAGS = -Wall -fPIC -I${ZOOKEEPER_PATH}/include -I${ZOOKEEPER_PATH}/generated \ + -I$(top_srcdir)/include -I/usr/include +AM_CPPFLAGS = -Wall -I${ZOOKEEPER_PATH}/include -I${ZOOKEEPER_PATH}/generated\ + -I${top_srcdir}/include -I/usr/include +EXTRA_DIST = LICENSE +lib_LTLIBRARIES = libzoolock.la +libzoolock_la_SOURCES = src/zoo_lock.c include/zoo_lock.h +libzoolock_la_CPPFLAGS = -DDLOPEN_MODULE +libzoolock_la_LDFLAGS = -version-info 0:1:0 + +#run the tests now + +TEST_SOURCES = tests/TestDriver.cc tests/TestClient.cc tests/Util.cc + + +check_PROGRAMS = zklocktest +nodist_zklocktest_SOURCES = ${TEST_SOURCES} +zklocktest_LDADD = ${ZOOKEEPER_LD} libzoolock.la -lpthread ${CPPUNIT_LIBS} +zklocktest_CXXFLAGS = -DUSE_STATIC_LIB ${CPPUNIT_CFLAGS} + +run-check: check + ./zklocktest ${TEST_OPTIONS} + +clean-local: clean-check + ${RM} ${DX_CLEANFILES} + +clean-check: + ${RM} ${nodist_zklocktest_OBJECTS} diff --git a/src/java/main/org/apache/recipes/lock/src/c/README.txt b/src/java/main/org/apache/recipes/lock/src/c/README.txt new file mode 100644 index 00000000000..326bba85d4d --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/README.txt @@ -0,0 +1,28 @@ + Zookeeper C lock client library + + +INSTALLATION + +If you're building the client from a source checkout you need to +follow the steps outlined below. If you're building from a release +tar downloaded from Apache please skip to step 2. + +1) make sure that you compile the main zookeeper c client library. + +2) change directory to src/recipes/lock/src/c + and do a "autoreconf -if" to bootstrap + autoconf, automake and libtool. Please make sure you have autoconf + version 2.59 or greater installed. +3) do a "./configure [OPTIONS]" to generate the makefile. See INSTALL + for general information about running configure. + +4) do a "make" or "make install" to build the libraries and install them. + Alternatively, you can also build and run a unit test suite (and + you probably should). Please make sure you have cppunit-1.10.x or + higher installed before you execute step 4. Once ./configure has + finished, do a "make run-check". It will build the libraries, build + the tests and run them. +5) to generate doxygen documentation do a "make doxygen-doc". All + documentations will be placed to a new subfolder named docs. By + default only HTML documentation is generated. For information on + other document formats please use "./configure --help" diff --git a/src/java/main/org/apache/recipes/lock/src/c/acinclude.m4 b/src/java/main/org/apache/recipes/lock/src/c/acinclude.m4 new file mode 100644 index 00000000000..d0041d8c26a --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/acinclude.m4 @@ -0,0 +1,312 @@ +# This file is part of Autoconf. -*- Autoconf -*- + +# Copyright (C) 2004 Oren Ben-Kiki +# This file is distributed under the same terms as the Autoconf macro files. + +# Generate automatic documentation using Doxygen. Works in concert with the +# aminclude.m4 file and a compatible doxygen configuration file. Defines the +# following public macros: +# +# DX_???_FEATURE(ON|OFF) - control the default setting fo a Doxygen feature. +# Supported features are 'DOXYGEN' itself, 'DOT' for generating graphics, +# 'HTML' for plain HTML, 'CHM' for compressed HTML help (for MS users), 'CHI' +# for generating a seperate .chi file by the .chm file, and 'MAN', 'RTF', +# 'XML', 'PDF' and 'PS' for the appropriate output formats. The environment +# variable DOXYGEN_PAPER_SIZE may be specified to override the default 'a4wide' +# paper size. +# +# By default, HTML, PDF and PS documentation is generated as this seems to be +# the most popular and portable combination. MAN pages created by Doxygen are +# usually problematic, though by picking an appropriate subset and doing some +# massaging they might be better than nothing. CHM and RTF are specific for MS +# (note that you can't generate both HTML and CHM at the same time). The XML is +# rather useless unless you apply specialized post-processing to it. +# +# The macro mainly controls the default state of the feature. The use can +# override the default by specifying --enable or --disable. The macros ensure +# that contradictory flags are not given (e.g., --enable-doxygen-html and +# --enable-doxygen-chm, --enable-doxygen-anything with --disable-doxygen, etc.) +# Finally, each feature will be automatically disabled (with a warning) if the +# required programs are missing. +# +# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN with +# the following parameters: a one-word name for the project for use as a +# filename base etc., an optional configuration file name (the default is +# 'Doxyfile', the same as Doxygen's default), and an optional output directory +# name (the default is 'doxygen-doc'). + +## ----------## +## Defaults. ## +## ----------## + +DX_ENV="" +AC_DEFUN([DX_FEATURE_doc], ON) +AC_DEFUN([DX_FEATURE_dot], ON) +AC_DEFUN([DX_FEATURE_man], OFF) +AC_DEFUN([DX_FEATURE_html], ON) +AC_DEFUN([DX_FEATURE_chm], OFF) +AC_DEFUN([DX_FEATURE_chi], OFF) +AC_DEFUN([DX_FEATURE_rtf], OFF) +AC_DEFUN([DX_FEATURE_xml], OFF) +AC_DEFUN([DX_FEATURE_pdf], ON) +AC_DEFUN([DX_FEATURE_ps], ON) + +## --------------- ## +## Private macros. ## +## --------------- ## + +# DX_ENV_APPEND(VARIABLE, VALUE) +# ------------------------------ +# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen. +AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])]) + +# DX_DIRNAME_EXPR +# --------------- +# Expand into a shell expression prints the directory part of a path. +AC_DEFUN([DX_DIRNAME_EXPR], + [[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']]) + +# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF) +# ------------------------------------- +# Expands according to the M4 (static) status of the feature. +AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])]) + +# DX_REQUIRE_PROG(VARIABLE, PROGRAM) +# ---------------------------------- +# Require the specified program to be found for the DX_CURRENT_FEATURE to work. +AC_DEFUN([DX_REQUIRE_PROG], [ +AC_PATH_TOOL([$1], [$2]) +if test "$DX_FLAG_$[DX_CURRENT_FEATURE$$1]" = 1; then + AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION]) + AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +fi +]) + +# DX_TEST_FEATURE(FEATURE) +# ------------------------ +# Expand to a shell expression testing whether the feature is active. +AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1]) + +# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE) +# ------------------------------------------------- +# Verify that a required features has the right state before trying to turn on +# the DX_CURRENT_FEATURE. +AC_DEFUN([DX_CHECK_DEPEND], [ +test "$DX_FLAG_$1" = "$2" \ +|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1, + requires, contradicts) doxygen-DX_CURRENT_FEATURE]) +]) + +# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE) +# ---------------------------------------------------------- +# Turn off the DX_CURRENT_FEATURE if the required feature is off. +AC_DEFUN([DX_CLEAR_DEPEND], [ +test "$DX_FLAG_$1" = "$2" || AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +]) + +# DX_FEATURE_ARG(FEATURE, DESCRIPTION, +# CHECK_DEPEND, CLEAR_DEPEND, +# REQUIRE, DO-IF-ON, DO-IF-OFF) +# -------------------------------------------- +# Parse the command-line option controlling a feature. CHECK_DEPEND is called +# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND), +# otherwise CLEAR_DEPEND is called to turn off the default state if a required +# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional +# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and +# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature. +AC_DEFUN([DX_ARG_ABLE], [ + AC_DEFUN([DX_CURRENT_FEATURE], [$1]) + AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2]) + AC_ARG_ENABLE(doxygen-$1, + [AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1], + [--enable-doxygen-$1]), + DX_IF_FEATURE([$1], [don't $2], [$2]))], + [ +case "$enableval" in +#( +y|Y|yes|Yes|YES) + AC_SUBST([DX_FLAG_$1], 1) + $3 +;; #( +n|N|no|No|NO) + AC_SUBST([DX_FLAG_$1], 0) +;; #( +*) + AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1]) +;; +esac +], [ +AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)]) +$4 +]) +if DX_TEST_FEATURE([$1]); then + $5 + : +fi +if DX_TEST_FEATURE([$1]); then + AM_CONDITIONAL(DX_COND_$1, :) + $6 + : +else + AM_CONDITIONAL(DX_COND_$1, false) + $7 + : +fi +]) + +## -------------- ## +## Public macros. ## +## -------------- ## + +# DX_XXX_FEATURE(DEFAULT_STATE) +# ----------------------------- +AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])]) +AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])]) +AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])]) +AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])]) +AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])]) +AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])]) +AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])]) +AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])]) + +# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR]) +# --------------------------------------------------------- +# PROJECT also serves as the base name for the documentation files. +# The default CONFIG-FILE is "Doxyfile" and OUTPUT-DOC-DIR is "doxygen-doc". +AC_DEFUN([DX_INIT_DOXYGEN], [ + +# Files: +AC_SUBST([DX_PROJECT], [$1]) +AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])]) +AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])]) + +# Environment variables used inside doxygen.cfg: +DX_ENV_APPEND(SRCDIR, $srcdir) +DX_ENV_APPEND(PROJECT, $DX_PROJECT) +DX_ENV_APPEND(DOCDIR, $DX_DOCDIR) +DX_ENV_APPEND(VERSION, $PACKAGE_VERSION) + +# Doxygen itself: +DX_ARG_ABLE(doc, [generate any doxygen documentation], + [], + [], + [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen) + DX_REQUIRE_PROG([DX_PERL], perl)], + [DX_ENV_APPEND(PERL_PATH, $DX_PERL)]) + +# Dot for graphics: +DX_ARG_ABLE(dot, [generate graphics for doxygen documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_DOT], dot)], + [DX_ENV_APPEND(HAVE_DOT, YES) + DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])], + [DX_ENV_APPEND(HAVE_DOT, NO)]) + +# Man pages generation: +DX_ARG_ABLE(man, [generate doxygen manual pages], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_MAN, YES)], + [DX_ENV_APPEND(GENERATE_MAN, NO)]) + +# RTF file generation: +DX_ARG_ABLE(rtf, [generate doxygen RTF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_RTF, YES)], + [DX_ENV_APPEND(GENERATE_RTF, NO)]) + +# XML file generation: +DX_ARG_ABLE(xml, [generate doxygen XML documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_XML, YES)], + [DX_ENV_APPEND(GENERATE_XML, NO)]) + +# (Compressed) HTML help generation: +DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_HHC], hhc)], + [DX_ENV_APPEND(HHC_PATH, $DX_HHC) + DX_ENV_APPEND(GENERATE_HTML, YES) + DX_ENV_APPEND(GENERATE_HTMLHELP, YES)], + [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)]) + +# Seperate CHI file generation. +DX_ARG_ABLE(chi, [generate doxygen seperate compressed HTML help index file], + [DX_CHECK_DEPEND(chm, 1)], + [DX_CLEAR_DEPEND(chm, 1)], + [], + [DX_ENV_APPEND(GENERATE_CHI, YES)], + [DX_ENV_APPEND(GENERATE_CHI, NO)]) + +# Plain HTML pages generation: +DX_ARG_ABLE(html, [generate doxygen plain HTML documentation], + [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)], + [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)], + [], + [DX_ENV_APPEND(GENERATE_HTML, YES)], + [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)]) + +# PostScript file generation: +DX_ARG_ABLE(ps, [generate doxygen PostScript documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_LATEX], latex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_DVIPS], dvips) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# PDF file generation: +DX_ARG_ABLE(pdf, [generate doxygen PDF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# LaTeX generation for PS and/or PDF: +if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then + AM_CONDITIONAL(DX_COND_latex, :) + DX_ENV_APPEND(GENERATE_LATEX, YES) +else + AM_CONDITIONAL(DX_COND_latex, false) + DX_ENV_APPEND(GENERATE_LATEX, NO) +fi + +# Paper size for PS and/or PDF: +AC_ARG_VAR(DOXYGEN_PAPER_SIZE, + [a4wide (default), a4, letter, legal or executive]) +case "$DOXYGEN_PAPER_SIZE" in +#( +"") + AC_SUBST(DOXYGEN_PAPER_SIZE, "") +;; #( +a4wide|a4|letter|legal|executive) + DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE) +;; #( +*) + AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE']) +;; +esac + +#For debugging: +#echo DX_FLAG_doc=$DX_FLAG_doc +#echo DX_FLAG_dot=$DX_FLAG_dot +#echo DX_FLAG_man=$DX_FLAG_man +#echo DX_FLAG_html=$DX_FLAG_html +#echo DX_FLAG_chm=$DX_FLAG_chm +#echo DX_FLAG_chi=$DX_FLAG_chi +#echo DX_FLAG_rtf=$DX_FLAG_rtf +#echo DX_FLAG_xml=$DX_FLAG_xml +#echo DX_FLAG_pdf=$DX_FLAG_pdf +#echo DX_FLAG_ps=$DX_FLAG_ps +#echo DX_ENV=$DX_ENV +]) diff --git a/src/java/main/org/apache/recipes/lock/src/c/aminclude.am b/src/java/main/org/apache/recipes/lock/src/c/aminclude.am new file mode 100644 index 00000000000..420049eca35 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/aminclude.am @@ -0,0 +1,186 @@ +# Copyright (C) 2004 Oren Ben-Kiki +# This file is distributed under the same terms as the Automake macro files. + +# Generate automatic documentation using Doxygen. Goals and variables values +# are controlled by the various DX_COND_??? conditionals set by autoconf. +# +# The provided goals are: +# doxygen-doc: Generate all doxygen documentation. +# doxygen-run: Run doxygen, which will generate some of the documentation +# (HTML, CHM, CHI, MAN, RTF, XML) but will not do the post +# processing required for the rest of it (PS, PDF, and some MAN). +# doxygen-man: Rename some doxygen generated man pages. +# doxygen-ps: Generate doxygen PostScript documentation. +# doxygen-pdf: Generate doxygen PDF documentation. +# +# Note that by default these are not integrated into the automake goals. If +# doxygen is used to generate man pages, you can achieve this integration by +# setting man3_MANS to the list of man pages generated and then adding the +# dependency: +# +# $(man3_MANS): doxygen-doc +# +# This will cause make to run doxygen and generate all the documentation. +# +# The following variable is intended for use in Makefile.am: +# +# DX_CLEANFILES = everything to clean. +# +# This is usually added to MOSTLYCLEANFILES. + +## --------------------------------- ## +## Format-independent Doxygen rules. ## +## --------------------------------- ## + +if DX_COND_doc + +## ------------------------------- ## +## Rules specific for HTML output. ## +## ------------------------------- ## + +if DX_COND_html + +DX_CLEAN_HTML = @DX_DOCDIR@/html + +endif DX_COND_html + +## ------------------------------ ## +## Rules specific for CHM output. ## +## ------------------------------ ## + +if DX_COND_chm + +DX_CLEAN_CHM = @DX_DOCDIR@/chm + +if DX_COND_chi + +DX_CLEAN_CHI = @DX_DOCDIR@/@PACKAGE@.chi + +endif DX_COND_chi + +endif DX_COND_chm + +## ------------------------------ ## +## Rules specific for MAN output. ## +## ------------------------------ ## + +if DX_COND_man + +DX_CLEAN_MAN = @DX_DOCDIR@/man + +endif DX_COND_man + +## ------------------------------ ## +## Rules specific for RTF output. ## +## ------------------------------ ## + +if DX_COND_rtf + +DX_CLEAN_RTF = @DX_DOCDIR@/rtf + +endif DX_COND_rtf + +## ------------------------------ ## +## Rules specific for XML output. ## +## ------------------------------ ## + +if DX_COND_xml + +DX_CLEAN_XML = @DX_DOCDIR@/xml + +endif DX_COND_xml + +## ----------------------------- ## +## Rules specific for PS output. ## +## ----------------------------- ## + +if DX_COND_ps + +DX_CLEAN_PS = @DX_DOCDIR@/@PACKAGE@.ps + +DX_PS_GOAL = doxygen-ps + +doxygen-ps: @DX_DOCDIR@/@PACKAGE@.ps + +@DX_DOCDIR@/@PACKAGE@.ps: @DX_DOCDIR@/@PACKAGE@.tag + cd @DX_DOCDIR@/latex; \ + rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ + $(DX_LATEX) refman.tex; \ + $(MAKEINDEX_PATH) refman.idx; \ + $(DX_LATEX) refman.tex; \ + countdown=5; \ + while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ + refman.log > /dev/null 2>&1 \ + && test $$countdown -gt 0; do \ + $(DX_LATEX) refman.tex; \ + countdown=`expr $$countdown - 1`; \ + done; \ + $(DX_DVIPS) -o ../@PACKAGE@.ps refman.dvi + +endif DX_COND_ps + +## ------------------------------ ## +## Rules specific for PDF output. ## +## ------------------------------ ## + +if DX_COND_pdf + +DX_CLEAN_PDF = @DX_DOCDIR@/@PACKAGE@.pdf + +DX_PDF_GOAL = doxygen-pdf + +doxygen-pdf: @DX_DOCDIR@/@PACKAGE@.pdf + +@DX_DOCDIR@/@PACKAGE@.pdf: @DX_DOCDIR@/@PACKAGE@.tag + cd @DX_DOCDIR@/latex; \ + rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ + $(DX_PDFLATEX) refman.tex; \ + $(DX_MAKEINDEX) refman.idx; \ + $(DX_PDFLATEX) refman.tex; \ + countdown=5; \ + while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ + refman.log > /dev/null 2>&1 \ + && test $$countdown -gt 0; do \ + $(DX_PDFLATEX) refman.tex; \ + countdown=`expr $$countdown - 1`; \ + done; \ + mv refman.pdf ../@PACKAGE@.pdf + +endif DX_COND_pdf + +## ------------------------------------------------- ## +## Rules specific for LaTeX (shared for PS and PDF). ## +## ------------------------------------------------- ## + +if DX_COND_latex + +DX_CLEAN_LATEX = @DX_DOCDIR@/latex + +endif DX_COND_latex + +.PHONY: doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL) + +.INTERMEDIATE: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) + +doxygen-run: @DX_DOCDIR@/@PACKAGE@.tag + +doxygen-doc: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) + +@DX_DOCDIR@/@PACKAGE@.tag: $(DX_CONFIG) $(pkginclude_HEADERS) + rm -rf @DX_DOCDIR@ + $(DX_ENV) $(DX_DOXYGEN) $(srcdir)/$(DX_CONFIG) + +DX_CLEANFILES = \ + @DX_DOCDIR@/@PACKAGE@.tag \ + -r \ + $(DX_CLEAN_HTML) \ + $(DX_CLEAN_CHM) \ + $(DX_CLEAN_CHI) \ + $(DX_CLEAN_MAN) \ + $(DX_CLEAN_RTF) \ + $(DX_CLEAN_XML) \ + $(DX_CLEAN_PS) \ + $(DX_CLEAN_PDF) \ + $(DX_CLEAN_LATEX) + +endif DX_COND_doc diff --git a/src/java/main/org/apache/recipes/lock/src/c/c-doc.Doxyfile b/src/java/main/org/apache/recipes/lock/src/c/c-doc.Doxyfile new file mode 100644 index 00000000000..c56e86dc524 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/c-doc.Doxyfile @@ -0,0 +1,1252 @@ +# Doxyfile 1.4.7 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = $(PROJECT)-$(VERSION) + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = $(DOCDIR) + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST = YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = include/zoo_lock.h + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = $(GENERATE_HTML) + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = $(GENERATE_HTMLHELP) + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = ../$(PROJECT).chm + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = $(HHC_PATH) + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = $(GENERATE_CHI) + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = $(GENERATE_LATEX) + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = $(PAPER_SIZE) + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = $(GENERATE_PDF) + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = $(GENERATE_RTF) + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = $(GENERATE_MAN) + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = $(GENERATE_XML) + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = $(DOCDIR)/$(PROJECT).tag + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = $(HAVE_DOT) + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = $(DOT_PATH) + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/src/java/main/org/apache/recipes/lock/src/c/configure.ac b/src/java/main/org/apache/recipes/lock/src/c/configure.ac new file mode 100644 index 00000000000..3954123ee77 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/configure.ac @@ -0,0 +1,82 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) + +AC_INIT([zoolock], [3.2.0]) + +AC_CONFIG_SRCDIR([include/zoo_lock.h]) + +PACKAGE=zoolock +VERSION=1.0 + +AC_SUBST(PACKAGE) +AC_SUBST(VERSION) + +BUILD_PATH="`pwd`" + +# Checks for programs. +AC_LANG_CPLUSPLUS + +AM_INIT_AUTOMAKE([-Wall foreign]) +# Checks for libraries. + +#initialize Doxygen support +DX_HTML_FEATURE(ON) +DX_CHM_FEATURE(OFF) +DX_CHI_FEATURE(OFF) +DX_MAN_FEATURE(OFF) +DX_RTF_FEATURE(OFF) +DX_XML_FEATURE(OFF) +DX_PDF_FEATURE(OFF) +DX_PS_FEATURE(OFF) +DX_INIT_DOXYGEN([zookeeper-locks],[c-doc.Doxyfile],[docs]) + + +ZOOKEEPER_PATH=${BUILD_PATH}/../../../../../src/c +ZOOKEEPER_LD=-L${BUILD_PATH}/../../../../../src/c\ -lzookeeper_mt + +AC_SUBST(ZOOKEEPER_PATH) +AC_SUBST(ZOOKEEPER_LD) + +# Checks for header files. +AC_HEADER_DIRENT +AC_HEADER_STDC +AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/time.h unistd.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_HEADER_STDBOOL +AC_C_CONST +AC_TYPE_UID_T +AC_C_INLINE +AC_TYPE_OFF_T +AC_TYPE_SIZE_T +AC_STRUCT_ST_BLOCKS +AC_HEADER_TIME +AC_C_VOLATILE +AC_PROG_CC +AC_PROG_LIBTOOL +#check for cppunit +AM_PATH_CPPUNIT(1.10.2) +# Checks for library functions. +AC_FUNC_UTIME_NULL +AC_CHECK_FUNCS([gettimeofday memset mkdir rmdir strdup strerror strstr strtol strtoul strtoull utime]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT +AC_C_VOLATILE diff --git a/src/java/main/org/apache/recipes/lock/src/c/include/zoo_lock.h b/src/java/main/org/apache/recipes/lock/src/c/include/zoo_lock.h new file mode 100644 index 00000000000..5c06bbf2ff2 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/include/zoo_lock.h @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef ZOOKEEPER_LOCK_H_ +#define ZOOKEEPER_LOCK_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +/** + * \brief the call back function called on status change of lock + * + * the call back funtion is called with a rc of 0 if lock is acquired and + * with an rc of 1 if the lock is released + * \param rc the value to let us know if its locked or unlocked + * \param cbdata the callback data that we passed when initializing + * the zookeeper lock. + */ + +typedef void (* zkr_lock_completion) (int rc, void* cbdata); + +/** + * \file zoo_lock.h + * \brief zookeeper recipe for locking and leader election. + * this api implements a writelock on a given path in zookeeper. + * this api can also be used for leader election. + */ + +struct zkr_lock_mutex { + zhandle_t *zh; + char *path; + struct ACL_vector *acl; + char *id; + void *cbdata; + zkr_lock_completion completion; + pthread_mutex_t pmutex; + int isOwner; + char* ownerid; +}; + +typedef struct zkr_lock_mutex zkr_lock_mutex_t; + + +/** + * \brief initializing a zookeeper lock. + * + * this method instantiates the zookeeper mutex lock. + * \param mutex the mutex to initialize + * \param zh the zookeeper handle to use + * \param path the path in zookeeper to use for locking + * \param acl the acls to use in zookeeper. + * \return return 0 if successful. + */ +ZOOAPI int zkr_lock_init(zkr_lock_mutex_t *mutex, zhandle_t* zh, + char* path, struct ACL_vector *acl); + +/** + * \brief initializing a zookeeper lock. + * + * + * this method instantiates the zookeeper mutex lock with + * a completion function. + * + * \param mutex the mutex to initialize + * \param zh the zookeeper handle to use + * \param path the path in zookeeper to use for locking + * \param acl the acls to use in zookeeper. + * \param completion the callback thats called when lock + * is acquired and released. + * \param cbdata the callback method is called with data + * \return return 0 if successful. + */ +ZOOAPI int zkr_lock_init_cb(zkr_lock_mutex_t *mutex, zhandle_t* zh, + char* path, struct ACL_vector *acl, + zkr_lock_completion completion, void* cbdata); + +/** + * \brief lock the zookeeper mutex + * + * this method tries locking the mutex + * \param mutex the zookeeper mutex + * \return return 0 if there is no error. check + * with zkr_lock_isowner() if you have the lock + */ +ZOOAPI int zkr_lock_lock(zkr_lock_mutex_t *mutex); + +/** + * \brief unlock the zookeeper mutex + * + * this method unlocks the zookeeper mutex + * \param mutex the zookeeper mutex + * \return return 0 if there is not error in executing unlock. + * else returns non zero + */ +ZOOAPI int zkr_lock_unlock(zkr_lock_mutex_t *mutex); + +/** + * \brief set the callback function for zookeeper mutex + * + * this method sets the callback for zookeeper mutex + * \param mutex the zookeeper mutex + * \param callback the call back completion function + */ +ZOOAPI void zkr_lock_setcallback(zkr_lock_mutex_t *mutex, + zkr_lock_completion completion); + +/** + * \brief get the callback function for zookeeper mutex + * + * this method gets the callback funtion for zookeeper mutex + * \param mutex the zookeeper mutex + * \return the lock completion function + */ +ZOOAPI zkr_lock_completion zkr_lock_getcallback(zkr_lock_mutex_t *mutex); + +/** + * \brief destroy the mutex + * this method free the mutex + * \param mutex destroy the zookepeer lock. + * \return return 0 if destroyed. + */ +ZOOAPI int zkr_lock_destroy(zkr_lock_mutex_t* mutex); + +/** + * \brief return the parent path this mutex is using + * this method returns the parent path + * \param mutex the mutex + * \return return the parent path + */ +ZOOAPI char* zkr_lock_getpath(zkr_lock_mutex_t *mutex); + +/** + * \brief return if this mutex is owner of the lock + * this method returns if its owner or not + * \param mutex the mutex + * \return return true if is owner and false if not + */ +ZOOAPI int zkr_lock_isowner(zkr_lock_mutex_t *mutex); + +/** + * \brief return the id for this mutex + * this mutex retunrns the id string + * \param mutex the mutex + * \return the id for this mutex + */ +ZOOAPI char* zkr_lock_getid(zkr_lock_mutex_t *mutex); + +#ifdef __cplusplus +} +#endif +#endif //ZOOKEEPER_LOCK_H_ diff --git a/src/java/main/org/apache/recipes/lock/src/c/src/zoo_lock.c b/src/java/main/org/apache/recipes/lock/src/c/src/zoo_lock.c new file mode 100644 index 00000000000..8a6d81763f4 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/src/zoo_lock.c @@ -0,0 +1,396 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef DLL_EXPORT +#define USE_STATIC_LIB +#endif + +#if defined(__CYGWIN__) +#define USE_IPV6 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_UTSNAME_H +#include +#endif + +#ifdef HAVE_GETPWUID_R +#include +#endif + +#define IF_DEBUG(x) if (logLevel==ZOO_LOG_LEVEL_DEBUG) {x;} + + +ZOOAPI int zkr_lock_init(zkr_lock_mutex_t* mutex, zhandle_t* zh, + char* path, struct ACL_vector *acl) { + mutex->zh = zh; + mutex->path = path; + mutex->acl = acl; + mutex->completion = NULL; + mutex->cbdata = NULL; + mutex->id = NULL; + mutex->ownerid = NULL; + mutex->isOwner = 0; + pthread_mutex_init(&(mutex->pmutex), NULL); + return 0; +} + +ZOOAPI int zkr_lock_init_cb(zkr_lock_mutex_t *mutex, zhandle_t* zh, + char *path, struct ACL_vector *acl, + zkr_lock_completion completion, void* cbdata) { + mutex->zh = zh; + mutex->path = path; + mutex->acl = acl; + mutex->completion = completion; + mutex->cbdata = cbdata; + mutex->isOwner = 0; + mutex->ownerid = NULL; + mutex->id = NULL; + pthread_mutex_init(&(mutex->pmutex), NULL); + return 0; +} + +/** + * unlock the mutex + */ +ZOOAPI int zkr_lock_unlock(zkr_lock_mutex_t *mutex) { + pthread_mutex_lock(&(mutex->pmutex)); + zhandle_t *zh = mutex->zh; + if (mutex->id != NULL) { + int len = strlen(mutex->path) + strlen(mutex->id) + 2; + char buf[len]; + sprintf(buf, "%s/%s", mutex->path, mutex->id); + int ret = 0; + int count = 0; + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (.5)*1000000; + ret = ZCONNECTIONLOSS; + while (ret == ZCONNECTIONLOSS && (count < 3)) { + ret = zoo_delete(zh, buf, -1); + if (ret == ZCONNECTIONLOSS) { + LOG_DEBUG(("connectionloss while deleting the node")); + nanosleep(&ts, 0); + count++; + } + } + if (ret == ZOK || ret == ZNONODE) { + zkr_lock_completion completion = mutex->completion; + if (completion != NULL) { + completion(1, mutex->cbdata); + } + + free(mutex->id); + mutex->id = NULL; + pthread_mutex_unlock(&(mutex->pmutex)); + return 0; + } + LOG_WARN(("not able to connect to server - giving up")); + pthread_mutex_unlock(&(mutex->pmutex)); + return ZCONNECTIONLOSS; + } + pthread_mutex_unlock(&(mutex->pmutex)); + return ZSYSTEMERROR; +} + +static void free_String_vector(struct String_vector *v) { + if (v->data) { + int32_t i; + for (i=0; icount; i++) { + free(v->data[i]); + } + free(v->data); + v->data = 0; + } +} + +static int vstrcmp(const void* str1, const void* str2) { + const char **a = (const char**)str1; + const char **b = (const char**) str2; + return strcmp(strrchr(*a, '-')+1, strrchr(*b, '-')+1); +} + +static void sort_children(struct String_vector *vector) { + qsort( vector->data, vector->count, sizeof(char*), &vstrcmp); +} + +static char* child_floor(char **sorted_data, int len, char *element) { + char* ret = NULL; + int i =0; + for (i=0; i < len; i++) { + if (strcmp(sorted_data[i], element) < 0) { + ret = sorted_data[i]; + } + } + return ret; +} + +static void lock_watcher_fn(zhandle_t* zh, int type, int state, + const char* path, void *watcherCtx) { + //callback that we registered + //should be called + zkr_lock_lock((zkr_lock_mutex_t*) watcherCtx); +} + +/** + * get the last name of the path + */ +static char* getName(char* str) { + char* name = strrchr(str, '/'); + if (name == NULL) + return NULL; + return strdup(name + 1); +} + +/** + * just a method to retry get children + */ +static int retry_getchildren(zhandle_t *zh, char* path, struct String_vector *vector, + struct timespec *ts, int retry) { + int ret = ZCONNECTIONLOSS; + int count = 0; + while (ret == ZCONNECTIONLOSS && count < retry) { + ret = zoo_get_children(zh, path, 0, vector); + if (ret == ZCONNECTIONLOSS) { + LOG_DEBUG(("connection loss to the server")); + nanosleep(ts, 0); + count++; + } + } + return ret; +} + +/** see if our node already exists + * if it does then we dup the name and + * return it + */ +static char* lookupnode(struct String_vector *vector, char *prefix) { + char *ret = NULL; + if (vector->data) { + int i = 0; + for (i = 0; i < vector->count; i++) { + char* child = vector->data[i]; + if (strncmp(prefix, child, strlen(prefix)) == 0) { + ret = strdup(child); + break; + } + } + } + return ret; +} + +/** retry zoo_wexists + */ +static int retry_zoowexists(zhandle_t *zh, char* path, watcher_fn watcher, void* ctx, + struct Stat *stat, struct timespec *ts, int retry) { + int ret = ZCONNECTIONLOSS; + int count = 0; + while (ret == ZCONNECTIONLOSS && count < retry) { + ret = zoo_wexists(zh, path, watcher, ctx, stat); + if (ret == ZCONNECTIONLOSS) { + LOG_DEBUG(("connectionloss while setting watch on my predecessor")); + nanosleep(ts, 0); + count++; + } + } + return ret; +} + +/** + * the main code that does the zookeeper leader + * election. this code creates its own ephemeral + * node on the given path and sees if its the first + * one on the list and claims to be a leader if and only + * if its the first one of children in the paretn path + */ +static int zkr_lock_operation(zkr_lock_mutex_t *mutex, struct timespec *ts) { + zhandle_t *zh = mutex->zh; + char *path = mutex->path; + char *id = mutex->id; + struct Stat stat; + char* owner_id = NULL; + int retry = 3; + do { + const clientid_t *cid = zoo_client_id(zh); + // get the session id + int64_t session = cid->client_id; + char prefix[30]; + int ret = 0; +#if defined(__x86_64__) + snprintf(prefix, 30, "x-%016lx-", session); +#else + snprintf(prefix, 30, "x-%016llx-", session); +#endif + struct String_vector vectorst; + vectorst.data = NULL; + vectorst.count = 0; + ret = ZCONNECTIONLOSS; + ret = retry_getchildren(zh, path, &vectorst, ts, retry); + if (ret != ZOK) + return ret; + struct String_vector *vector = &vectorst; + mutex->id = lookupnode(vector, prefix); + free_String_vector(vector); + if (mutex->id == NULL) { + int len = strlen(path) + strlen(prefix) + 2; + char buf[len]; + char retbuf[len+20]; + snprintf(buf, len, "%s/%s", path, prefix); + ret = ZCONNECTIONLOSS; + ret = zoo_create(zh, buf, NULL, 0, mutex->acl, + ZOO_EPHEMERAL|ZOO_SEQUENCE, retbuf, (len+20)); + + // do not want to retry the create since + // we would end up creating more than one child + if (ret != ZOK) { + LOG_WARN(("could not create zoo node %s", buf)); + return ret; + } + mutex->id = getName(retbuf); + } + + if (mutex->id != NULL) { + ret = ZCONNECTIONLOSS; + ret = retry_getchildren(zh, path, vector, ts, retry); + if (ret != ZOK) { + LOG_WARN(("could not connect to server")); + return ret; + } + //sort this list + sort_children(vector); + owner_id = vector->data[0]; + mutex->ownerid = strdup(owner_id); + id = mutex->id; + char* lessthanme = child_floor(vector->data, vector->count, id); + if (lessthanme != NULL) { + int flen = strlen(mutex->path) + strlen(lessthanme) + 2; + char last_child[flen]; + sprintf(last_child, "%s/%s",mutex->path, lessthanme); + ret = ZCONNECTIONLOSS; + ret = retry_zoowexists(zh, last_child, &lock_watcher_fn, mutex, + &stat, ts, retry); + // cannot watch my predecessor i am giving up + // we need to be able to watch the predecessor + // since if we do not become a leader the others + // will keep waiting + if (ret != ZOK) { + free_String_vector(vector); + LOG_WARN(("unable to watch my predecessor")); + ret = zkr_lock_unlock(mutex); + while (ret == 0) { + //we have to give up our leadership + // since we cannot watch out predecessor + ret = zkr_lock_unlock(mutex); + } + return ret; + } + // we are not the owner of the lock + mutex->isOwner = 0; + } + else { + // this is the case when we are the owner + // of the lock + if (strcmp(mutex->id, owner_id) == 0) { + LOG_DEBUG(("got the zoo lock owner - %s", mutex->id)); + mutex->isOwner = 1; + if (mutex->completion != NULL) { + mutex->completion(0, mutex->cbdata); + } + return ZOK; + } + } + free_String_vector(vector); + return ZOK; + } + } while (mutex->id == NULL); + return ZOK; +} + +ZOOAPI int zkr_lock_lock(zkr_lock_mutex_t *mutex) { + pthread_mutex_lock(&(mutex->pmutex)); + zhandle_t *zh = mutex->zh; + char *path = mutex->path; + struct Stat stat; + int exists = zoo_exists(zh, path, 0, &stat); + int count = 0; + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (.5)*1000000; + // retry to see if the path exists and + // and create if the path does not exist + while ((exists == ZCONNECTIONLOSS || exists == ZNONODE) && (count <4)) { + count++; + // retry the operation + if (exists == ZCONNECTIONLOSS) + exists = zoo_exists(zh, path, 0, &stat); + else if (exists == ZNONODE) + exists = zoo_create(zh, path, NULL, 0, mutex->acl, 0, NULL, 0); + nanosleep(&ts, 0); + + } + + // need to check if we cannot still access the server + int check_retry = ZCONNECTIONLOSS; + count = 0; + while (check_retry != ZOK && count <4) { + check_retry = zkr_lock_operation(mutex, &ts); + if (check_retry != ZOK) { + nanosleep(&ts, 0); + count++; + } + } + pthread_mutex_unlock(&(mutex->pmutex)); + return zkr_lock_isowner(mutex); +} + + +ZOOAPI char* zkr_lock_getpath(zkr_lock_mutex_t *mutex) { + return mutex->path; +} + +ZOOAPI int zkr_lock_isowner(zkr_lock_mutex_t *mutex) { + return (mutex->id != NULL && mutex->ownerid != NULL + && (strcmp(mutex->id, mutex->ownerid) == 0)); +} + +ZOOAPI char* zkr_lock_getid(zkr_lock_mutex_t *mutex) { + return mutex->ownerid; +} + +ZOOAPI int zkr_lock_destroy(zkr_lock_mutex_t* mutex) { + if (mutex->id) + free(mutex->id); + mutex->path = NULL; + mutex->acl = NULL; + mutex->completion = NULL; + pthread_mutex_destroy(&(mutex->pmutex)); + mutex->isOwner = 0; + if (mutex->ownerid) + free(mutex->ownerid); + return 0; +} + diff --git a/src/java/main/org/apache/recipes/lock/src/c/tests/TestClient.cc b/src/java/main/org/apache/recipes/lock/src/c/tests/TestClient.cc new file mode 100644 index 00000000000..2cc56cf344a --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/c/tests/TestClient.cc @@ -0,0 +1,201 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + + +using namespace std; + +#include +#include + +#include +#include + +static void yield(zhandle_t *zh, int i) +{ + sleep(i); +} + +typedef struct evt { + string path; + int type; +} evt_t; + +typedef struct watchCtx { +private: + list events; +public: + bool connected; + zhandle_t *zh; + + watchCtx() { + connected = false; + zh = 0; + } + ~watchCtx() { + if (zh) { + zookeeper_close(zh); + zh = 0; + } + } + + evt_t getEvent() { + evt_t evt; + evt = events.front(); + events.pop_front(); + return evt; + } + + int countEvents() { + int count; + count = events.size(); + return count; + } + + void putEvent(evt_t evt) { + events.push_back(evt); + } + + bool waitForConnected(zhandle_t *zh) { + time_t expires = time(0) + 10; + while(!connected && time(0) < expires) { + yield(zh, 1); + } + return connected; + } + bool waitForDisconnected(zhandle_t *zh) { + time_t expires = time(0) + 15; + while(connected && time(0) < expires) { + yield(zh, 1); + } + return !connected; + } +} watchctx_t; + +class Zookeeper_locktest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_locktest); + CPPUNIT_TEST(testlock); + CPPUNIT_TEST_SUITE_END(); + + static void watcher(zhandle_t *, int type, int state, const char *path,void*v){ + watchctx_t *ctx = (watchctx_t*)v; + + if (state == ZOO_CONNECTED_STATE) { + ctx->connected = true; + } else { + ctx->connected = false; + } + if (type != ZOO_SESSION_EVENT) { + evt_t evt; + evt.path = path; + evt.type = type; + ctx->putEvent(evt); + } + } + + static const char hostPorts[]; + + const char *getHostPorts() { + return hostPorts; + } + + zhandle_t *createClient(watchctx_t *ctx) { + zhandle_t *zk = zookeeper_init(hostPorts, watcher, 10000, 0, + ctx, 0); + ctx->zh = zk; + sleep(1); + return zk; + } + +public: + +#define ZKSERVER_CMD "./tests/zkServer.sh" + + void setUp() + { + char cmd[1024]; + sprintf(cmd, "%s startClean %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + + void startServer() { + char cmd[1024]; + sprintf(cmd, "%s start %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + void stopServer() { + tearDown(); + } + + void tearDown() + { + char cmd[1024]; + sprintf(cmd, "%s stop %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + + void testlock() + { + watchctx_t ctx; + int rc; + struct Stat stat; + char buf[1024]; + int blen; + struct String_vector strings; + const char *testName; + zkr_lock_mutex_t mutexes[3]; + int count = 3; + int i = 0; + char* path = "/test-lock"; + for (i=0; i< 3; i++) { + zhandle_t *zh = createClient(&ctx); + zkr_lock_init(&mutexes[i], zh, path, &ZOO_OPEN_ACL_UNSAFE); + zkr_lock_lock(&mutexes[i]); + } + sleep(30); + zkr_lock_mutex leader = mutexes[0]; + zkr_lock_mutex mutex; + int ret = strcmp(leader.id, leader.ownerid); + CPPUNIT_ASSERT(ret == 0); + for(i=1; i < count; i++) { + mutex = mutexes[i]; + CPPUNIT_ASSERT(strcmp(mutex.id, mutex.ownerid) != 0); + } + zkr_lock_unlock(&leader); + sleep(30); + zkr_lock_mutex secondleader = mutexes[1]; + CPPUNIT_ASSERT(strcmp(secondleader.id , secondleader.ownerid) == 0); + for (i=2; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Util.h" + +using namespace std; + +CPPUNIT_NS_BEGIN + +class EclipseOutputter: public CompilerOutputter +{ +public: + EclipseOutputter(TestResultCollector *result,ostream &stream): + CompilerOutputter(result,stream,"%p:%l: "),stream_(stream) + { + } + virtual void printFailedTestName( TestFailure *failure ){} + virtual void printFailureMessage( TestFailure *failure ) + { + stream_<<": "; + Message msg = failure->thrownException()->message(); + stream_<< msg.shortDescription(); + + string text; + for(int i=0; i the output must be in the compiler error format. + //bool selfTest = (argc > 1) && (std::string("-ide") == argv[1]); + globalTestConfig.addConfigFromCmdLine(argc,argv); + + // Create the event manager and test controller + CPPUNIT_NS::TestResult controller; + // Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); + + // Add a listener that print dots as tests run. + // CPPUNIT_NS::TextTestProgressListener progress; + CPPUNIT_NS::BriefTestProgressListener progress; + controller.addListener( &progress ); + + CPPUNIT_NS::TestRunner runner; + runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); + + try + { + cout << "Running " << globalTestConfig.getTestName(); + runner.run( controller, globalTestConfig.getTestName()); + cout< +#include +#include + +// number of elements in array +#define COUNTOF(array) sizeof(array)/sizeof(array[0]) + +#define DECLARE_WRAPPER(ret,sym,sig) \ + extern "C" ret __real_##sym sig; \ + extern "C" ret __wrap_##sym sig + +#define CALL_REAL(sym,params) \ + __real_##sym params + +// must include "src/zookeeper_log.h" to be able to use this macro +#define TEST_TRACE(x) \ + log_message(3,__LINE__,__func__,format_log_message x) + +extern const std::string EMPTY_STRING; + +// ***************************************************************************** +// A bit of wizardry to get to the bare type from a reference or a pointer +// to the type +template +struct TypeOp { + typedef T BareT; + typedef T ArgT; +}; + +// partial specialization for reference types +template +struct TypeOp{ + typedef T& ArgT; + typedef typename TypeOp::BareT BareT; +}; + +// partial specialization for pointers +template +struct TypeOp{ + typedef T* ArgT; + typedef typename TypeOp::BareT BareT; +}; + +// ***************************************************************************** +// Container utilities + +template +void putValue(std::map& map,const K& k, const V& v){ + typedef std::map Map; + typename Map::const_iterator it=map.find(k); + if(it==map.end()) + map.insert(typename Map::value_type(k,v)); + else + map[k]=v; +} + +template +bool getValue(const std::map& map,const K& k,V& v){ + typedef std::map Map; + typename Map::const_iterator it=map.find(k); + if(it==map.end()) + return false; + v=it->second; + return true; +} + +// ***************************************************************************** +// misc utils + +// millisecond sleep +void millisleep(int ms); +// evaluate given predicate until it returns true or the timeout +// (in millis) has expired +template +int ensureCondition(const Predicate& p,int timeout){ + int elapsed=0; + while(!p() && elapsed CmdLineOptList; +public: + typedef CmdLineOptList::const_iterator const_iterator; + TestConfig(){} + ~TestConfig(){} + void addConfigFromCmdLine(int argc, char* argv[]){ + if(argc>=2) + testName_=argv[1]; + for(int i=2; i /tmp/zk.log & + echo $! > /tmp/zk.pid + sleep 5 + ;; +stop) + # Already killed above + ;; +*) + echo "Unknown command " + $1 + exit 2 +esac + diff --git a/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/LockListener.java b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/LockListener.java new file mode 100644 index 00000000000..87afe6833f8 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/LockListener.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.lock.src.java.org.apache.zookeeper.recipes.lock; + +/** + * This class has two methods which are call + * back methods when a lock is acquired and + * when the lock is released. + * + */ +public interface LockListener { + /** + * call back called when the lock + * is acquired + */ + public void lockAcquired(); + + /** + * call back called when the lock is + * released. + */ + public void lockReleased(); +} diff --git a/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java new file mode 100644 index 00000000000..36d13c86c1a --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java @@ -0,0 +1,186 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.lock.src.java.org.apache.zookeeper.recipes.lock; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.recipes.lock.src.java.org.apache.zookeeper.recipes.lock.ZooKeeperOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * A base class for protocol implementations which provides a number of higher + * level helper methods for working with ZooKeeper along with retrying synchronous + * operations if the connection to ZooKeeper closes such as + * {@link #retryOperation(ZooKeeperOperation)} + * + */ +class ProtocolSupport { + private static final Logger LOG = LoggerFactory.getLogger(ProtocolSupport.class); + + protected final ZooKeeper zookeeper; + private AtomicBoolean closed = new AtomicBoolean(false); + private long retryDelay = 500L; + private int retryCount = 10; + private List acl = ZooDefs.Ids.OPEN_ACL_UNSAFE; + + public ProtocolSupport(ZooKeeper zookeeper) { + this.zookeeper = zookeeper; + } + + /** + * Closes this strategy and releases any ZooKeeper resources; but keeps the + * ZooKeeper instance open + */ + public void close() { + if (closed.compareAndSet(false, true)) { + doClose(); + } + } + + /** + * return zookeeper client instance + * @return zookeeper client instance + */ + public ZooKeeper getZookeeper() { + return zookeeper; + } + + /** + * return the acl its using + * @return the acl. + */ + public List getAcl() { + return acl; + } + + /** + * set the acl + * @param acl the acl to set to + */ + public void setAcl(List acl) { + this.acl = acl; + } + + /** + * get the retry delay in milliseconds + * @return the retry delay + */ + public long getRetryDelay() { + return retryDelay; + } + + /** + * Sets the time waited between retry delays + * @param retryDelay the retry delay + */ + public void setRetryDelay(long retryDelay) { + this.retryDelay = retryDelay; + } + + /** + * Allow derived classes to perform + * some custom closing operations to release resources + */ + protected void doClose() { + } + + + /** + * Perform the given operation, retrying if the connection fails + * @return object. it needs to be cast to the callee's expected + * return type. + */ + protected Object retryOperation(ZooKeeperOperation operation) + throws KeeperException, InterruptedException { + KeeperException exception = null; + for (int i = 0; i < retryCount; i++) { + try { + return operation.execute(); + } catch (KeeperException.SessionExpiredException e) { + LOG.warn("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e); + throw e; + } catch (KeeperException.ConnectionLossException e) { + if (exception == null) { + exception = e; + } + LOG.debug("Attempt " + i + " failed with connection loss so " + + "attempting to reconnect: " + e, e); + retryDelay(i); + } + } + throw exception; + } + + /** + * Ensures that the given path exists with no data, the current + * ACL and no flags + * @param path + */ + protected void ensurePathExists(String path) { + ensureExists(path, null, acl, CreateMode.PERSISTENT); + } + + /** + * Ensures that the given path exists with the given data, ACL and flags + * @param path + * @param acl + * @param flags + */ + protected void ensureExists(final String path, final byte[] data, + final List acl, final CreateMode flags) { + try { + retryOperation(new ZooKeeperOperation() { + public boolean execute() throws KeeperException, InterruptedException { + Stat stat = zookeeper.exists(path, false); + if (stat != null) { + return true; + } + zookeeper.create(path, data, acl, flags); + return true; + } + }); + } catch (KeeperException e) { + LOG.warn("Caught: " + e, e); + } catch (InterruptedException e) { + LOG.warn("Caught: " + e, e); + } + } + + /** + * Returns true if this protocol has been closed + * @return true if this protocol is closed + */ + protected boolean isClosed() { + return closed.get(); + } + + /** + * Performs a retry delay if this is not the first attempt + * @param attemptCount the number of the attempts performed so far + */ + protected void retryDelay(int attemptCount) { + if (attemptCount > 0) { + try { + Thread.sleep(attemptCount * retryDelay); + } catch (InterruptedException e) { + LOG.debug("Failed to sleep: " + e, e); + } + } + } +} diff --git a/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/WriteLock.java b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/WriteLock.java new file mode 100644 index 00000000000..661f86bb2ac --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/WriteLock.java @@ -0,0 +1,291 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.lock.src.java.org.apache.zookeeper.recipes.lock; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import static org.apache.zookeeper.CreateMode.EPHEMERAL_SEQUENTIAL; + +/** + * A protocol to implement an exclusive + * write lock or to elect a leader.

        You invoke {@link #lock()} to + * start the process of grabbing the lock; you may get the lock then or it may be + * some time later.

        You can register a listener so that you are invoked + * when you get the lock; otherwise you can ask if you have the lock + * by calling {@link #isOwner()} + * + */ +public class WriteLock extends ProtocolSupport { + private static final Logger LOG = LoggerFactory.getLogger(WriteLock.class); + + private final String dir; + private String id; + private ZNodeName idName; + private String ownerId; + private String lastChildId; + private byte[] data = {0x12, 0x34}; + private LockListener callback; + private LockZooKeeperOperation zop; + + /** + * zookeeper contructor for writelock + * @param zookeeper zookeeper client instance + * @param dir the parent path you want to use for locking + * @param acls the acls that you want to use for all the paths, + * if null world read/write is used. + */ + public WriteLock(ZooKeeper zookeeper, String dir, List acl) { + super(zookeeper); + this.dir = dir; + if (acl != null) { + setAcl(acl); + } + this.zop = new LockZooKeeperOperation(); + } + + /** + * zookeeper contructor for writelock with callback + * @param zookeeper the zookeeper client instance + * @param dir the parent path you want to use for locking + * @param acl the acls that you want to use for all the paths + * @param callback the call back instance + */ + public WriteLock(ZooKeeper zookeeper, String dir, List acl, + LockListener callback) { + this(zookeeper, dir, acl); + this.callback = callback; + } + + /** + * return the current locklistener + * @return the locklistener + */ + public LockListener getLockListener() { + return this.callback; + } + + /** + * register a different call back listener + * @param callback the call back instance + */ + public void setLockListener(LockListener callback) { + this.callback = callback; + } + + /** + * Removes the lock or associated znode if + * you no longer require the lock. this also + * removes your request in the queue for locking + * in case you do not already hold the lock. + * @throws RuntimeException throws a runtime exception + * if it cannot connect to zookeeper. + */ + public synchronized void unlock() throws RuntimeException { + + if (!isClosed() && id != null) { + // we don't need to retry this operation in the case of failure + // as ZK will remove ephemeral files and we don't wanna hang + // this process when closing if we cannot reconnect to ZK + try { + + ZooKeeperOperation zopdel = new ZooKeeperOperation() { + public boolean execute() throws KeeperException, + InterruptedException { + zookeeper.delete(id, -1); + return Boolean.TRUE; + } + }; + zopdel.execute(); + } catch (InterruptedException e) { + LOG.warn("Caught: " + e, e); + //set that we have been interrupted. + Thread.currentThread().interrupt(); + } catch (KeeperException.NoNodeException e) { + // do nothing + } catch (KeeperException e) { + LOG.warn("Caught: " + e, e); + throw (RuntimeException) new RuntimeException(e.getMessage()). + initCause(e); + } finally { + if (callback != null) { + callback.lockReleased(); + } + id = null; + } + } + } + + /** + * Attempts to acquire the exclusive write lock returning whether or not it was + * acquired. Note that the exclusive lock may be acquired some time later after + * this method has been invoked due to the current lock owner going away. + */ + public synchronized boolean lock() throws KeeperException, InterruptedException { + if (isClosed()) { + return false; + } + ensurePathExists(dir); + + return (Boolean) retryOperation(zop); + } + + /** + * return the parent dir for lock + * @return the parent dir used for locks. + */ + public String getDir() { + return dir; + } + + ; + + /** + * Returns true if this node is the owner of the + * lock (or the leader) + */ + public boolean isOwner() { + return id != null && ownerId != null && id.equals(ownerId); + } + + /** + * return the id for this lock + * @return the id for this lock + */ + public String getId() { + return this.id; + } + + /** + * the watcher called on + * getting watch while watching + * my predecessor + */ + private class LockWatcher implements Watcher { + public void process(WatchedEvent event) { + // lets either become the leader or watch the new/updated node + LOG.debug("Watcher fired on path: " + event.getPath() + " state: " + + event.getState() + " type " + event.getType()); + try { + lock(); + } catch (Exception e) { + LOG.warn("Failed to acquire lock: " + e, e); + } + } + } + + /** + * a zoookeeper operation that is mainly responsible + * for all the magic required for locking. + */ + private class LockZooKeeperOperation implements ZooKeeperOperation { + + /** find if we have been created earler if not create our node + * + * @param prefix the prefix node + * @param zookeeper teh zookeeper client + * @param dir the dir paretn + * @throws KeeperException + * @throws InterruptedException + */ + private void findPrefixInChildren(String prefix, ZooKeeper zookeeper, String dir) + throws KeeperException, InterruptedException { + List names = zookeeper.getChildren(dir, false); + for (String name : names) { + if (name.startsWith(prefix)) { + id = name; + if (LOG.isDebugEnabled()) { + LOG.debug("Found id created las`t time: " + id); + } + break; + } + } + if (id == null) { + id = zookeeper.create(dir + "/" + prefix, data, + getAcl(), EPHEMERAL_SEQUENTIAL); + + if (LOG.isDebugEnabled()) { + LOG.debug("Created id: " + id); + } + } + + } + + /** + * the command that is run and retried for actually + * obtaining the lock + * @return if the command was successful or not + */ + public boolean execute() throws KeeperException, InterruptedException { + do { + if (id == null) { + long sessionId = zookeeper.getSessionId(); + String prefix = "x-" + sessionId + "-"; + // lets try look up the current ID if we failed + // in the middle of creating the znode + findPrefixInChildren(prefix, zookeeper, dir); + idName = new ZNodeName(id); + } + if (id != null) { + List names = zookeeper.getChildren(dir, false); + if (names.isEmpty()) { + LOG.warn("No children in: " + dir + " when we've just " + + "created one! Lets recreate it..."); + // lets force the recreation of the id + id = null; + } else { + // lets sort them explicitly (though they do seem to come back in order ususally :) + SortedSet sortedNames = new TreeSet(); + for (String name : names) { + sortedNames.add(new ZNodeName(dir + "/" + name)); + } + ownerId = sortedNames.first().getName(); + SortedSet lessThanMe = sortedNames.headSet(idName); + if (!lessThanMe.isEmpty()) { + ZNodeName lastChildName = lessThanMe.last(); + lastChildId = lastChildName.getName(); + if (LOG.isDebugEnabled()) { + LOG.debug("watching less than me node: " + lastChildId); + } + Stat stat = zookeeper.exists(lastChildId, new LockWatcher()); + if (stat != null) { + return Boolean.FALSE; + } else { + LOG.warn("Could not find the" + + " stats for less than me: " + lastChildName.getName()); + } + } else { + if (isOwner()) { + if (callback != null) { + callback.lockAcquired(); + } + return Boolean.TRUE; + } + } + } + } + } + while (id == null); + return Boolean.FALSE; + } + } +} + diff --git a/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ZNodeName.java b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ZNodeName.java new file mode 100644 index 00000000000..938aaa70322 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ZNodeName.java @@ -0,0 +1,103 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.lock.src.java.org.apache.zookeeper.recipes.lock; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Represents an ephemeral znode name which has an ordered sequence number + * and can be sorted in order + * + */ +class ZNodeName implements Comparable { + private static final Logger LOG = LoggerFactory.getLogger(ZNodeName.class); + private final String name; + private String prefix; + private int sequence = -1; + + public ZNodeName(String name) { + if (name == null) { + throw new NullPointerException("id cannot be null"); + } + this.name = name; + this.prefix = name; + int idx = name.lastIndexOf('-'); + if (idx >= 0) { + this.prefix = name.substring(0, idx); + try { + this.sequence = Integer.parseInt(name.substring(idx + 1)); + // If an exception occurred we misdetected a sequence suffix, + // so return -1. + } catch (NumberFormatException e) { + LOG.info("Number format exception for " + idx, e); + } catch (ArrayIndexOutOfBoundsException e) { + LOG.info("Array out of bounds for " + idx, e); + } + } + } + + @Override + public String toString() { + return name.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ZNodeName sequence = (ZNodeName) o; + + if (!name.equals(sequence.name)) return false; + + return true; + } + + @Override + public int hashCode() { + return name.hashCode() + 37; + } + + public int compareTo(ZNodeName that) { + int answer = this.prefix.compareTo(that.prefix); + if (answer == 0) { + int s1 = this.sequence; + int s2 = that.sequence; + if (s1 == -1 && s2 == -1) { + return this.name.compareTo(that.name); + } + answer = s1 == -1 ? 1 : s2 == -1 ? -1 : s1 - s2; + } + return answer; + } + + /** + * Returns the name of the znode + */ + public String getName() { + return name; + } + + /** + * Returns the sequence number + */ + public int getZNodeName() { + return sequence; + } + + /** + * Returns the text prefix before the sequence number + */ + public String getPrefix() { + return prefix; + } +} diff --git a/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ZooKeeperOperation.java b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ZooKeeperOperation.java new file mode 100644 index 00000000000..26725778613 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/src/java/org/apache/zookeeper/recipes/lock/ZooKeeperOperation.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.lock.src.java.org.apache.zookeeper.recipes.lock; + +import org.apache.zookeeper.KeeperException; + +/** + * A callback object which can be used for implementing retry-able operations in the + * {@link org.apache.zookeeper.recipes.lock.ProtocolSupport} class + * + */ +public interface ZooKeeperOperation { + + /** + * Performs the operation - which may be involved multiple times if the connection + * to ZooKeeper closes during this operation + * + * @return the result of the operation or null + * @throws KeeperException + * @throws InterruptedException + */ + public boolean execute() throws KeeperException, InterruptedException; +} diff --git a/src/java/main/org/apache/recipes/lock/test/org/apache/zookeeper/recipes/lock/WriteLockTest.java b/src/java/main/org/apache/recipes/lock/test/org/apache/zookeeper/recipes/lock/WriteLockTest.java new file mode 100644 index 00000000000..80bb9279543 --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/test/org/apache/zookeeper/recipes/lock/WriteLockTest.java @@ -0,0 +1,149 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.lock.test.org.apache.zookeeper.recipes.lock; + +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * test for writelock + */ +public class WriteLockTest extends ClientBase { + protected int sessionTimeout = 10 * 1000; + protected String dir = "/" + getClass().getName(); + protected WriteLock[] nodes; + protected CountDownLatch latch = new CountDownLatch(1); + private boolean restartServer = true; + private boolean workAroundClosingLastZNodeFails = true; + private boolean killLeader = true; + + @Test + public void testRun() throws Exception { + runTest(3); + } + + protected void runTest(int count) throws Exception { + nodes = new WriteLock[count]; + for (int i = 0; i < count; i++) { + ZooKeeper keeper = createClient(); + WriteLock leader = new WriteLock(keeper, dir, null); + leader.setLockListener(new LockCallback()); + nodes[i] = leader; + + leader.lock(); + } + + // lets wait for any previous leaders to die and one of our new + // nodes to become the new leader + latch.await(30, TimeUnit.SECONDS); + + WriteLock first = nodes[0]; + dumpNodes(count); + + // lets assert that the first election is the leader + Assert.assertTrue("The first znode should be the leader " + first.getId(), first.isOwner()); + + for (int i = 1; i < count; i++) { + WriteLock node = nodes[i]; + Assert.assertFalse("Node should not be the leader " + node.getId(), node.isOwner()); + } + + if (count > 1) { + if (killLeader) { + System.out.println("Now killing the leader"); + // now lets kill the leader + latch = new CountDownLatch(1); + first.unlock(); + latch.await(30, TimeUnit.SECONDS); + //Thread.sleep(10000); + WriteLock second = nodes[1]; + dumpNodes(count); + // lets assert that the first election is the leader + Assert.assertTrue("The second znode should be the leader " + second.getId(), second.isOwner()); + + for (int i = 2; i < count; i++) { + WriteLock node = nodes[i]; + Assert.assertFalse("Node should not be the leader " + node.getId(), node.isOwner()); + } + } + + + if (restartServer) { + // now lets stop the server + System.out.println("Now stopping the server"); + stopServer(); + Thread.sleep(10000); + + // TODO lets assert that we are no longer the leader + dumpNodes(count); + + System.out.println("Starting the server"); + startServer(); + Thread.sleep(10000); + + for (int i = 0; i < count - 1; i++) { + System.out.println("Calling acquire for node: " + i); + nodes[i].lock(); + } + dumpNodes(count); + System.out.println("Now closing down..."); + } + } + } + + protected void dumpNodes(int count) { + for (int i = 0; i < count; i++) { + WriteLock node = nodes[i]; + System.out.println("node: " + i + " id: " + + node.getId() + " is leader: " + node.isOwner()); + } + } + + @After + public void tearDown() throws Exception { + if (nodes != null) { + for (int i = 0; i < nodes.length; i++) { + WriteLock node = nodes[i]; + if (node != null) { + System.out.println("Closing node: " + i); + node.close(); + if (workAroundClosingLastZNodeFails && i == nodes.length - 1) { + System.out.println("Not closing zookeeper: " + i + " due to bug!"); + } else { + System.out.println("Closing zookeeper: " + i); + node.getZookeeper().close(); + System.out.println("Closed zookeeper: " + i); + } + } + } + } + System.out.println("Now lets stop the server"); + super.tearDown(); + + } + + class LockCallback implements LockListener { + public void lockAcquired() { + latch.countDown(); + } + + public void lockReleased() { + + } + + } +} diff --git a/src/java/main/org/apache/recipes/lock/test/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java b/src/java/main/org/apache/recipes/lock/test/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java new file mode 100644 index 00000000000..beec5b3393c --- /dev/null +++ b/src/java/main/org/apache/recipes/lock/test/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.lock.test.org.apache.zookeeper.recipes.lock; + + +import org.junit.Assert; +import org.junit.Test; + +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * test for znodenames + */ +public class ZNodeNameTest { + @Test + public void testOrderWithSamePrefix() throws Exception { + String[] names = {"x-3", "x-5", "x-11", "x-1"}; + String[] expected = {"x-1", "x-3", "x-5", "x-11"}; + assertOrderedNodeNames(names, expected); + } + + @Test + public void testOrderWithDifferentPrefixes() throws Exception { + String[] names = {"r-3", "r-2", "r-1", "w-2", "w-1"}; + String[] expected = {"r-1", "r-2", "r-3", "w-1", "w-2"}; + assertOrderedNodeNames(names, expected); + } + + protected void assertOrderedNodeNames(String[] names, String[] expected) { + int size = names.length; + Assert.assertEquals("The two arrays should be the same size!", names.length, expected.length); + SortedSet nodeNames = new TreeSet(); + for (String name : names) { + nodeNames.add(new ZNodeName(name)); + } + + int index = 0; + for (ZNodeName nodeName : nodeNames) { + String name = nodeName.getName(); + Assert.assertEquals("Node " + index, expected[index++], name); + } + } + +} diff --git a/src/java/main/org/apache/recipes/queue/README.txt b/src/java/main/org/apache/recipes/queue/README.txt new file mode 100644 index 00000000000..d59a3c3170a --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/README.txt @@ -0,0 +1,30 @@ + + +1) This queue interface recipe implements the queue recipe +mentioned in ../../../docs/recipes.[html,pdf]. +A more detailed explanation is at http://www.cloudera.com/blog/2009/05/28/building-a-distributed-concurrent-queue-with-apache-zookeeper/ + +2) This recipe does not handle KeeperException.ConnectionLossException or ZCONNECTIONLOSS. It will only work correctly once ZOOKEEPER-22 https://issues.apache.org/jira/browse/ZOOKEEPER-22 is resolved. + +3) To compile the queue java recipe you can just run ant jar from +this directory. +Please report any bugs on the jira + +http://issues.apache.org/jira/browse/ZOOKEEPER + + diff --git a/src/java/main/org/apache/recipes/queue/build.xml b/src/java/main/org/apache/recipes/queue/build.xml new file mode 100644 index 00000000000..a77269fc4e4 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/build.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests failed! + + + + + + + + + + + + + + + + + + diff --git a/src/java/main/org/apache/recipes/queue/src/c/INSTALL b/src/java/main/org/apache/recipes/queue/src/c/INSTALL new file mode 100644 index 00000000000..5458714e1e2 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/INSTALL @@ -0,0 +1,234 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/src/java/main/org/apache/recipes/queue/src/c/LICENSE b/src/java/main/org/apache/recipes/queue/src/c/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/java/main/org/apache/recipes/queue/src/c/Makefile.am b/src/java/main/org/apache/recipes/queue/src/c/Makefile.am new file mode 100644 index 00000000000..ecef3cc790b --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/Makefile.am @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include $(top_srcdir)/aminclude.am + +AM_CFLAGS = -Wall -fPIC -I${ZOOKEEPER_PATH}/include -I${ZOOKEEPER_PATH}/generated \ + -I$(top_srcdir)/include -I/usr/include +AM_CPPFLAGS = -Wall -I${ZOOKEEPER_PATH}/include -I${ZOOKEEPER_PATH}/generated\ + -I${top_srcdir}/include -I/usr/include +EXTRA_DIST = LICENSE +lib_LTLIBRARIES = libzooqueue.la +libzooqueue_la_SOURCES = src/zoo_queue.c include/zoo_queue.h +libzooqueue_la_CPPFLAGS = -DDLOPEN_MODULE +libzooqueue_la_LDFLAGS = -version-info 0:1:0 + +#run the tests now + +TEST_SOURCES = tests/TestDriver.cc tests/TestClient.cc tests/Util.cc + + +check_PROGRAMS = zkqueuetest +nodist_zkqueuetest_SOURCES = ${TEST_SOURCES} +zkqueuetest_LDADD = ${ZOOKEEPER_LD} libzooqueue.la -lpthread ${CPPUNIT_LIBS} +zkqueuetest_CXXFLAGS = -DUSE_STATIC_LIB ${CPPUNIT_CFLAGS} + +run-check: check + ./zkqueuetest ${TEST_OPTIONS} + +clean-local: clean-check + ${RM} ${DX_CLEANFILES} + +clean-check: + ${RM} ${nodist_zkqueuetest_OBJECTS} diff --git a/src/java/main/org/apache/recipes/queue/src/c/README.txt b/src/java/main/org/apache/recipes/queue/src/c/README.txt new file mode 100644 index 00000000000..7ef253fc981 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/README.txt @@ -0,0 +1,30 @@ + Zookeeper C queue client library + + +INSTALLATION + +If you're building the client from a source checkout you need to +follow the steps outlined below. If you're building from a release +tar downloaded from Apache please skip to step 2. + +This recipe does not handle ZCONNECTIONLOSS. It will only work correctly once ZOOKEEPER-22 https://issues.apache.org/jira/browse/ZOOKEEPER-22 is resolved. + +1) make sure that you compile the main zookeeper c client library. + +2) change directory to src/recipes/queue/src/c + and do a "autoreconf -if" to bootstrap + autoconf, automake and libtool. Please make sure you have autoconf + version 2.59 or greater installed. +3) do a "./configure [OPTIONS]" to generate the makefile. See INSTALL + for general information about running configure. + +4) do a "make" or "make install" to build the libraries and install them. + Alternatively, you can also build and run a unit test suite (and + you probably should). Please make sure you have cppunit-1.10.x or + higher installed before you execute step 4. Once ./configure has + finished, do a "make run-check". It will build the libraries, build + the tests and run them. +5) to generate doxygen documentation do a "make doxygen-doc". All + documentations will be placed to a new subfolder named docs. By + default only HTML documentation is generated. For information on + other document formats please use "./configure --help" diff --git a/src/java/main/org/apache/recipes/queue/src/c/acinclude.m4 b/src/java/main/org/apache/recipes/queue/src/c/acinclude.m4 new file mode 100644 index 00000000000..d0041d8c26a --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/acinclude.m4 @@ -0,0 +1,312 @@ +# This file is part of Autoconf. -*- Autoconf -*- + +# Copyright (C) 2004 Oren Ben-Kiki +# This file is distributed under the same terms as the Autoconf macro files. + +# Generate automatic documentation using Doxygen. Works in concert with the +# aminclude.m4 file and a compatible doxygen configuration file. Defines the +# following public macros: +# +# DX_???_FEATURE(ON|OFF) - control the default setting fo a Doxygen feature. +# Supported features are 'DOXYGEN' itself, 'DOT' for generating graphics, +# 'HTML' for plain HTML, 'CHM' for compressed HTML help (for MS users), 'CHI' +# for generating a seperate .chi file by the .chm file, and 'MAN', 'RTF', +# 'XML', 'PDF' and 'PS' for the appropriate output formats. The environment +# variable DOXYGEN_PAPER_SIZE may be specified to override the default 'a4wide' +# paper size. +# +# By default, HTML, PDF and PS documentation is generated as this seems to be +# the most popular and portable combination. MAN pages created by Doxygen are +# usually problematic, though by picking an appropriate subset and doing some +# massaging they might be better than nothing. CHM and RTF are specific for MS +# (note that you can't generate both HTML and CHM at the same time). The XML is +# rather useless unless you apply specialized post-processing to it. +# +# The macro mainly controls the default state of the feature. The use can +# override the default by specifying --enable or --disable. The macros ensure +# that contradictory flags are not given (e.g., --enable-doxygen-html and +# --enable-doxygen-chm, --enable-doxygen-anything with --disable-doxygen, etc.) +# Finally, each feature will be automatically disabled (with a warning) if the +# required programs are missing. +# +# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN with +# the following parameters: a one-word name for the project for use as a +# filename base etc., an optional configuration file name (the default is +# 'Doxyfile', the same as Doxygen's default), and an optional output directory +# name (the default is 'doxygen-doc'). + +## ----------## +## Defaults. ## +## ----------## + +DX_ENV="" +AC_DEFUN([DX_FEATURE_doc], ON) +AC_DEFUN([DX_FEATURE_dot], ON) +AC_DEFUN([DX_FEATURE_man], OFF) +AC_DEFUN([DX_FEATURE_html], ON) +AC_DEFUN([DX_FEATURE_chm], OFF) +AC_DEFUN([DX_FEATURE_chi], OFF) +AC_DEFUN([DX_FEATURE_rtf], OFF) +AC_DEFUN([DX_FEATURE_xml], OFF) +AC_DEFUN([DX_FEATURE_pdf], ON) +AC_DEFUN([DX_FEATURE_ps], ON) + +## --------------- ## +## Private macros. ## +## --------------- ## + +# DX_ENV_APPEND(VARIABLE, VALUE) +# ------------------------------ +# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen. +AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])]) + +# DX_DIRNAME_EXPR +# --------------- +# Expand into a shell expression prints the directory part of a path. +AC_DEFUN([DX_DIRNAME_EXPR], + [[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']]) + +# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF) +# ------------------------------------- +# Expands according to the M4 (static) status of the feature. +AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])]) + +# DX_REQUIRE_PROG(VARIABLE, PROGRAM) +# ---------------------------------- +# Require the specified program to be found for the DX_CURRENT_FEATURE to work. +AC_DEFUN([DX_REQUIRE_PROG], [ +AC_PATH_TOOL([$1], [$2]) +if test "$DX_FLAG_$[DX_CURRENT_FEATURE$$1]" = 1; then + AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION]) + AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +fi +]) + +# DX_TEST_FEATURE(FEATURE) +# ------------------------ +# Expand to a shell expression testing whether the feature is active. +AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1]) + +# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE) +# ------------------------------------------------- +# Verify that a required features has the right state before trying to turn on +# the DX_CURRENT_FEATURE. +AC_DEFUN([DX_CHECK_DEPEND], [ +test "$DX_FLAG_$1" = "$2" \ +|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1, + requires, contradicts) doxygen-DX_CURRENT_FEATURE]) +]) + +# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE) +# ---------------------------------------------------------- +# Turn off the DX_CURRENT_FEATURE if the required feature is off. +AC_DEFUN([DX_CLEAR_DEPEND], [ +test "$DX_FLAG_$1" = "$2" || AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0) +]) + +# DX_FEATURE_ARG(FEATURE, DESCRIPTION, +# CHECK_DEPEND, CLEAR_DEPEND, +# REQUIRE, DO-IF-ON, DO-IF-OFF) +# -------------------------------------------- +# Parse the command-line option controlling a feature. CHECK_DEPEND is called +# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND), +# otherwise CLEAR_DEPEND is called to turn off the default state if a required +# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional +# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and +# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature. +AC_DEFUN([DX_ARG_ABLE], [ + AC_DEFUN([DX_CURRENT_FEATURE], [$1]) + AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2]) + AC_ARG_ENABLE(doxygen-$1, + [AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1], + [--enable-doxygen-$1]), + DX_IF_FEATURE([$1], [don't $2], [$2]))], + [ +case "$enableval" in +#( +y|Y|yes|Yes|YES) + AC_SUBST([DX_FLAG_$1], 1) + $3 +;; #( +n|N|no|No|NO) + AC_SUBST([DX_FLAG_$1], 0) +;; #( +*) + AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1]) +;; +esac +], [ +AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)]) +$4 +]) +if DX_TEST_FEATURE([$1]); then + $5 + : +fi +if DX_TEST_FEATURE([$1]); then + AM_CONDITIONAL(DX_COND_$1, :) + $6 + : +else + AM_CONDITIONAL(DX_COND_$1, false) + $7 + : +fi +]) + +## -------------- ## +## Public macros. ## +## -------------- ## + +# DX_XXX_FEATURE(DEFAULT_STATE) +# ----------------------------- +AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])]) +AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])]) +AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])]) +AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])]) +AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])]) +AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])]) +AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])]) +AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])]) +AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])]) + +# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR]) +# --------------------------------------------------------- +# PROJECT also serves as the base name for the documentation files. +# The default CONFIG-FILE is "Doxyfile" and OUTPUT-DOC-DIR is "doxygen-doc". +AC_DEFUN([DX_INIT_DOXYGEN], [ + +# Files: +AC_SUBST([DX_PROJECT], [$1]) +AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])]) +AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])]) + +# Environment variables used inside doxygen.cfg: +DX_ENV_APPEND(SRCDIR, $srcdir) +DX_ENV_APPEND(PROJECT, $DX_PROJECT) +DX_ENV_APPEND(DOCDIR, $DX_DOCDIR) +DX_ENV_APPEND(VERSION, $PACKAGE_VERSION) + +# Doxygen itself: +DX_ARG_ABLE(doc, [generate any doxygen documentation], + [], + [], + [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen) + DX_REQUIRE_PROG([DX_PERL], perl)], + [DX_ENV_APPEND(PERL_PATH, $DX_PERL)]) + +# Dot for graphics: +DX_ARG_ABLE(dot, [generate graphics for doxygen documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_DOT], dot)], + [DX_ENV_APPEND(HAVE_DOT, YES) + DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])], + [DX_ENV_APPEND(HAVE_DOT, NO)]) + +# Man pages generation: +DX_ARG_ABLE(man, [generate doxygen manual pages], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_MAN, YES)], + [DX_ENV_APPEND(GENERATE_MAN, NO)]) + +# RTF file generation: +DX_ARG_ABLE(rtf, [generate doxygen RTF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_RTF, YES)], + [DX_ENV_APPEND(GENERATE_RTF, NO)]) + +# XML file generation: +DX_ARG_ABLE(xml, [generate doxygen XML documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [], + [DX_ENV_APPEND(GENERATE_XML, YES)], + [DX_ENV_APPEND(GENERATE_XML, NO)]) + +# (Compressed) HTML help generation: +DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_HHC], hhc)], + [DX_ENV_APPEND(HHC_PATH, $DX_HHC) + DX_ENV_APPEND(GENERATE_HTML, YES) + DX_ENV_APPEND(GENERATE_HTMLHELP, YES)], + [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)]) + +# Seperate CHI file generation. +DX_ARG_ABLE(chi, [generate doxygen seperate compressed HTML help index file], + [DX_CHECK_DEPEND(chm, 1)], + [DX_CLEAR_DEPEND(chm, 1)], + [], + [DX_ENV_APPEND(GENERATE_CHI, YES)], + [DX_ENV_APPEND(GENERATE_CHI, NO)]) + +# Plain HTML pages generation: +DX_ARG_ABLE(html, [generate doxygen plain HTML documentation], + [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)], + [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)], + [], + [DX_ENV_APPEND(GENERATE_HTML, YES)], + [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)]) + +# PostScript file generation: +DX_ARG_ABLE(ps, [generate doxygen PostScript documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_LATEX], latex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_DVIPS], dvips) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# PDF file generation: +DX_ARG_ABLE(pdf, [generate doxygen PDF documentation], + [DX_CHECK_DEPEND(doc, 1)], + [DX_CLEAR_DEPEND(doc, 1)], + [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex) + DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex) + DX_REQUIRE_PROG([DX_EGREP], egrep)]) + +# LaTeX generation for PS and/or PDF: +if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then + AM_CONDITIONAL(DX_COND_latex, :) + DX_ENV_APPEND(GENERATE_LATEX, YES) +else + AM_CONDITIONAL(DX_COND_latex, false) + DX_ENV_APPEND(GENERATE_LATEX, NO) +fi + +# Paper size for PS and/or PDF: +AC_ARG_VAR(DOXYGEN_PAPER_SIZE, + [a4wide (default), a4, letter, legal or executive]) +case "$DOXYGEN_PAPER_SIZE" in +#( +"") + AC_SUBST(DOXYGEN_PAPER_SIZE, "") +;; #( +a4wide|a4|letter|legal|executive) + DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE) +;; #( +*) + AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE']) +;; +esac + +#For debugging: +#echo DX_FLAG_doc=$DX_FLAG_doc +#echo DX_FLAG_dot=$DX_FLAG_dot +#echo DX_FLAG_man=$DX_FLAG_man +#echo DX_FLAG_html=$DX_FLAG_html +#echo DX_FLAG_chm=$DX_FLAG_chm +#echo DX_FLAG_chi=$DX_FLAG_chi +#echo DX_FLAG_rtf=$DX_FLAG_rtf +#echo DX_FLAG_xml=$DX_FLAG_xml +#echo DX_FLAG_pdf=$DX_FLAG_pdf +#echo DX_FLAG_ps=$DX_FLAG_ps +#echo DX_ENV=$DX_ENV +]) diff --git a/src/java/main/org/apache/recipes/queue/src/c/aminclude.am b/src/java/main/org/apache/recipes/queue/src/c/aminclude.am new file mode 100644 index 00000000000..420049eca35 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/aminclude.am @@ -0,0 +1,186 @@ +# Copyright (C) 2004 Oren Ben-Kiki +# This file is distributed under the same terms as the Automake macro files. + +# Generate automatic documentation using Doxygen. Goals and variables values +# are controlled by the various DX_COND_??? conditionals set by autoconf. +# +# The provided goals are: +# doxygen-doc: Generate all doxygen documentation. +# doxygen-run: Run doxygen, which will generate some of the documentation +# (HTML, CHM, CHI, MAN, RTF, XML) but will not do the post +# processing required for the rest of it (PS, PDF, and some MAN). +# doxygen-man: Rename some doxygen generated man pages. +# doxygen-ps: Generate doxygen PostScript documentation. +# doxygen-pdf: Generate doxygen PDF documentation. +# +# Note that by default these are not integrated into the automake goals. If +# doxygen is used to generate man pages, you can achieve this integration by +# setting man3_MANS to the list of man pages generated and then adding the +# dependency: +# +# $(man3_MANS): doxygen-doc +# +# This will cause make to run doxygen and generate all the documentation. +# +# The following variable is intended for use in Makefile.am: +# +# DX_CLEANFILES = everything to clean. +# +# This is usually added to MOSTLYCLEANFILES. + +## --------------------------------- ## +## Format-independent Doxygen rules. ## +## --------------------------------- ## + +if DX_COND_doc + +## ------------------------------- ## +## Rules specific for HTML output. ## +## ------------------------------- ## + +if DX_COND_html + +DX_CLEAN_HTML = @DX_DOCDIR@/html + +endif DX_COND_html + +## ------------------------------ ## +## Rules specific for CHM output. ## +## ------------------------------ ## + +if DX_COND_chm + +DX_CLEAN_CHM = @DX_DOCDIR@/chm + +if DX_COND_chi + +DX_CLEAN_CHI = @DX_DOCDIR@/@PACKAGE@.chi + +endif DX_COND_chi + +endif DX_COND_chm + +## ------------------------------ ## +## Rules specific for MAN output. ## +## ------------------------------ ## + +if DX_COND_man + +DX_CLEAN_MAN = @DX_DOCDIR@/man + +endif DX_COND_man + +## ------------------------------ ## +## Rules specific for RTF output. ## +## ------------------------------ ## + +if DX_COND_rtf + +DX_CLEAN_RTF = @DX_DOCDIR@/rtf + +endif DX_COND_rtf + +## ------------------------------ ## +## Rules specific for XML output. ## +## ------------------------------ ## + +if DX_COND_xml + +DX_CLEAN_XML = @DX_DOCDIR@/xml + +endif DX_COND_xml + +## ----------------------------- ## +## Rules specific for PS output. ## +## ----------------------------- ## + +if DX_COND_ps + +DX_CLEAN_PS = @DX_DOCDIR@/@PACKAGE@.ps + +DX_PS_GOAL = doxygen-ps + +doxygen-ps: @DX_DOCDIR@/@PACKAGE@.ps + +@DX_DOCDIR@/@PACKAGE@.ps: @DX_DOCDIR@/@PACKAGE@.tag + cd @DX_DOCDIR@/latex; \ + rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ + $(DX_LATEX) refman.tex; \ + $(MAKEINDEX_PATH) refman.idx; \ + $(DX_LATEX) refman.tex; \ + countdown=5; \ + while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ + refman.log > /dev/null 2>&1 \ + && test $$countdown -gt 0; do \ + $(DX_LATEX) refman.tex; \ + countdown=`expr $$countdown - 1`; \ + done; \ + $(DX_DVIPS) -o ../@PACKAGE@.ps refman.dvi + +endif DX_COND_ps + +## ------------------------------ ## +## Rules specific for PDF output. ## +## ------------------------------ ## + +if DX_COND_pdf + +DX_CLEAN_PDF = @DX_DOCDIR@/@PACKAGE@.pdf + +DX_PDF_GOAL = doxygen-pdf + +doxygen-pdf: @DX_DOCDIR@/@PACKAGE@.pdf + +@DX_DOCDIR@/@PACKAGE@.pdf: @DX_DOCDIR@/@PACKAGE@.tag + cd @DX_DOCDIR@/latex; \ + rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \ + $(DX_PDFLATEX) refman.tex; \ + $(DX_MAKEINDEX) refman.idx; \ + $(DX_PDFLATEX) refman.tex; \ + countdown=5; \ + while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \ + refman.log > /dev/null 2>&1 \ + && test $$countdown -gt 0; do \ + $(DX_PDFLATEX) refman.tex; \ + countdown=`expr $$countdown - 1`; \ + done; \ + mv refman.pdf ../@PACKAGE@.pdf + +endif DX_COND_pdf + +## ------------------------------------------------- ## +## Rules specific for LaTeX (shared for PS and PDF). ## +## ------------------------------------------------- ## + +if DX_COND_latex + +DX_CLEAN_LATEX = @DX_DOCDIR@/latex + +endif DX_COND_latex + +.PHONY: doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL) + +.INTERMEDIATE: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) + +doxygen-run: @DX_DOCDIR@/@PACKAGE@.tag + +doxygen-doc: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL) + +@DX_DOCDIR@/@PACKAGE@.tag: $(DX_CONFIG) $(pkginclude_HEADERS) + rm -rf @DX_DOCDIR@ + $(DX_ENV) $(DX_DOXYGEN) $(srcdir)/$(DX_CONFIG) + +DX_CLEANFILES = \ + @DX_DOCDIR@/@PACKAGE@.tag \ + -r \ + $(DX_CLEAN_HTML) \ + $(DX_CLEAN_CHM) \ + $(DX_CLEAN_CHI) \ + $(DX_CLEAN_MAN) \ + $(DX_CLEAN_RTF) \ + $(DX_CLEAN_XML) \ + $(DX_CLEAN_PS) \ + $(DX_CLEAN_PDF) \ + $(DX_CLEAN_LATEX) + +endif DX_COND_doc diff --git a/src/java/main/org/apache/recipes/queue/src/c/c-doc.Doxyfile b/src/java/main/org/apache/recipes/queue/src/c/c-doc.Doxyfile new file mode 100644 index 00000000000..32e09a1c87b --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/c-doc.Doxyfile @@ -0,0 +1,1252 @@ +# Doxyfile 1.4.7 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = $(PROJECT)-$(VERSION) + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = $(DOCDIR) + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST = YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = include/zoo_queue.h + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = $(GENERATE_HTML) + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = $(GENERATE_HTMLHELP) + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = ../$(PROJECT).chm + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = $(HHC_PATH) + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = $(GENERATE_CHI) + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = $(GENERATE_LATEX) + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = $(PAPER_SIZE) + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = $(GENERATE_PDF) + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = $(GENERATE_RTF) + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = $(GENERATE_MAN) + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = $(GENERATE_XML) + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = $(DOCDIR)/$(PROJECT).tag + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = $(HAVE_DOT) + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = $(DOT_PATH) + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/src/java/main/org/apache/recipes/queue/src/c/configure.ac b/src/java/main/org/apache/recipes/queue/src/c/configure.ac new file mode 100644 index 00000000000..a9fb7b13087 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/configure.ac @@ -0,0 +1,82 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) + +AC_INIT([zooqueue], [3.2.0]) + +AC_CONFIG_SRCDIR([include/zoo_queue.h]) + +PACKAGE=zooqueue +VERSION=1.0 + +AC_SUBST(PACKAGE) +AC_SUBST(VERSION) + +BUILD_PATH="`pwd`" + +# Checks for programs. +AC_LANG_CPLUSPLUS + +AM_INIT_AUTOMAKE([-Wall foreign]) +# Checks for libraries. + +#initialize Doxygen support +DX_HTML_FEATURE(ON) +DX_CHM_FEATURE(OFF) +DX_CHI_FEATURE(OFF) +DX_MAN_FEATURE(OFF) +DX_RTF_FEATURE(OFF) +DX_XML_FEATURE(OFF) +DX_PDF_FEATURE(OFF) +DX_PS_FEATURE(OFF) +DX_INIT_DOXYGEN([zookeeper-queues],[c-doc.Doxyfile],[docs]) + + +ZOOKEEPER_PATH=${BUILD_PATH}/../../../../../src/c +ZOOKEEPER_LD=-L${BUILD_PATH}/../../../../../src/c\ -lzookeeper_mt + +AC_SUBST(ZOOKEEPER_PATH) +AC_SUBST(ZOOKEEPER_LD) + +# Checks for header files. +AC_HEADER_DIRENT +AC_HEADER_STDC +AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/time.h unistd.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_HEADER_STDBOOL +AC_C_CONST +AC_TYPE_UID_T +AC_C_INLINE +AC_TYPE_OFF_T +AC_TYPE_SIZE_T +AC_STRUCT_ST_BLOCKS +AC_HEADER_TIME +AC_C_VOLATILE +AC_PROG_CC +AC_PROG_LIBTOOL +#check for cppunit +AM_PATH_CPPUNIT(1.10.2) +# Checks for library functions. +AC_FUNC_UTIME_NULL +AC_CHECK_FUNCS([gettimeofday memset mkdir rmdir strdup strerror strstr strtol strtoul strtoull utime]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT +AC_C_VOLATILE diff --git a/src/java/main/org/apache/recipes/queue/src/c/include/zoo_queue.h b/src/java/main/org/apache/recipes/queue/src/c/include/zoo_queue.h new file mode 100644 index 00000000000..ccc4602f6b9 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/include/zoo_queue.h @@ -0,0 +1,118 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZOOKEEPER_QUEUE_H_ +#define ZOOKEEPER_QUEUE_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * \file zoo_queue.h + * \brief zookeeper recipe for queues. + */ + + +struct zkr_queue { + zhandle_t *zh; + char *path; + struct ACL_vector *acl; + pthread_mutex_t pmutex; + char *node_name; + int node_name_length; + char *cached_create_path; +}; + +typedef struct zkr_queue zkr_queue_t; + + +/** + * \brief initializes a zookeeper queue + * + * this method instantiates a zookeeper queue + * \param queue the zookeeper queue to initialize + * \param zh the zookeeper handle to use + * \param path the path in zookeeper to use for the queue + * \param acl the acl to use in zookeeper. + * \return return 0 if successful. + */ +ZOOAPI int zkr_queue_init(zkr_queue_t *queue, zhandle_t* zh, char* path, struct ACL_vector *acl); + +/** + * \brief adds an element to a zookeeper queue + * + * this method adds an element to the back of a zookeeper queue. + * \param queue the zookeeper queue to add the element to + * \param data a pointer to a data buffer + * \param buffer_len the length of the buffer + * \return returns 0 (ZOK) if successful, otherwise returns a zookeeper error code. + */ +ZOOAPI int zkr_queue_offer(zkr_queue_t *queue, const char *data, int buffer_len); + +/** + * \brief returns the head of a zookeeper queue + * + * this method returns the head of a zookeeper queue without removing it. + * \param queue the zookeeper queue to add the element to + * \param buffer a pointer to a data buffer + * \param buffer_len a pointer to the length of the buffer + * \return returns 0 (ZOK) and sets *buffer_len to the length of data written if successful (-1 if the queue is empty). Otherwise it will set *buffer_len to -1 and return a zookeeper error code. + */ +ZOOAPI int zkr_queue_element(zkr_queue_t *queue, char *buffer, int *buffer_len); + +/** + * \brief returns the head of a zookeeper queue + * + * this method returns the head of a zookeeper queue without removing it. + * \param queue the zookeeper queue to get the head of + * \param buffer a pointer to a data buffer + * \param buffer_len a pointer to the length of the buffer + * \return returns 0 (ZOK) and sets *buffer_len to the length of data written if successful (-1 if the queue is empty). Otherwise it will set *buffer_len to -1 and return a zookeeper error code. + */ +ZOOAPI int zkr_queue_remove(zkr_queue_t *queue, char *buffer, int *buffer_len); + +/** + * \brief removes and returns the head of a zookeeper queue, blocks if necessary + * + * this method returns the head of a zookeeper queue without removing it. + * \param queue the zookeeper queue to remove and return the head of + * \param buffer a pointer to a data buffer + * \param buffer_len a pointer to the length of the buffer + * \return returns 0 (ZOK) and sets *buffer_len to the length of data written if successful. Otherwise it will set *buffer_len to -1 and return a zookeeper error code. + */ +ZOOAPI int zkr_queue_take(zkr_queue_t *queue, char *buffer, int *buffer_len); + +/** + * \brief destroys a zookeeper queue structure + * + * this destroys a zookeeper queue structure, this is only a local operation and will not affect + * the state of the queue on the zookeeper server. + * \param queue the zookeeper queue to destroy + */ +void zkr_queue_destroy(zkr_queue_t *queue); + + +#ifdef __cplusplus +} +#endif +#endif //ZOOKEEPER_QUEUE_H_ diff --git a/src/java/main/org/apache/recipes/queue/src/c/src/zoo_queue.c b/src/java/main/org/apache/recipes/queue/src/c/src/zoo_queue.c new file mode 100644 index 00000000000..89ec24b6eda --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/src/zoo_queue.c @@ -0,0 +1,442 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef DLL_EXPORT +#define USE_STATIC_LIB +#endif + +#if defined(__CYGWIN__) +#define USE_IPV6 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_UTSNAME_H +#include +#endif + +#ifdef HAVE_GETPWUID_R +#include +#endif + +#define IF_DEBUG(x) if (logLevel==ZOO_LOG_LEVEL_DEBUG) {x;} + + +static void free_String_vector(struct String_vector *v) { + if (v->data) { + int32_t i; + for (i=0; icount; i++) { + free(v->data[i]); + } + free(v->data); + v->data = 0; + } +} + + +static int vstrcmp(const void* str1, const void* str2) { + const char **a = (const char**)str1; + const char **b = (const char**) str2; + return strcmp(*a, *b); +} + +static void sort_children(struct String_vector *vector) { + qsort( vector->data, vector->count, sizeof(char*), &vstrcmp); +} + + +static void concat_path_nodename_n(char *buffer, int len, const char *path, const char *node_name){ + snprintf(buffer, len, "%s/%s", path, node_name); +} + +static char *concat_path_nodename(const char *path, const char *node_name){ + int node_path_length = strlen(path) + 1+ strlen(node_name) +1; + char *node_path = (char *) malloc(node_path_length * sizeof(char)); + concat_path_nodename_n(node_path, node_path_length, path, node_name); + return node_path; +} + + +static void zkr_queue_cache_create_path(zkr_queue_t *queue){ + if(queue->cached_create_path != NULL){ + free(queue->cached_create_path); + } + queue->cached_create_path = concat_path_nodename(queue->path, queue->node_name); +} + +ZOOAPI int zkr_queue_init(zkr_queue_t *queue, zhandle_t* zh, char* path, struct ACL_vector *acl){ + queue->zh = zh; + queue->path = path; + queue->node_name = "qn-"; + queue->node_name_length = strlen(queue->node_name); + queue->cached_create_path = NULL; + queue->acl = acl; + pthread_mutex_init(&(queue->pmutex), NULL); + zkr_queue_cache_create_path(queue); + return 0; +} + +static ZOOAPI int create_queue_root(zkr_queue_t *queue){ + return zoo_create(queue->zh, queue->path, NULL, 0, queue->acl, 0, NULL, 0 ); +} + +static int valid_child_name(zkr_queue_t *queue, const char *child_name){ + return strncmp(queue->node_name, child_name, queue->node_name_length); +} + +ZOOAPI int zkr_queue_offer(zkr_queue_t *queue, const char *data, int buffer_len){ + for(;;){ + int rc = zoo_create(queue->zh, queue->cached_create_path, data, buffer_len, queue->acl, ZOO_SEQUENCE, NULL, 0 ); + switch(rc){ + int create_root_rc; + case ZNONODE: + create_root_rc = create_queue_root(queue); + switch(create_root_rc){ + case ZNODEEXISTS: + case ZOK: + break; + default: + return create_root_rc; + } + break; + default: + return rc; + } + } +} + + +ZOOAPI int zkr_queue_element(zkr_queue_t *queue, char *buffer, int *buffer_len){ + int path_length = strlen(queue->path); + for(;;){ + struct String_vector stvector; + struct String_vector *vector = &stvector; + /*Get sorted children*/ + int get_children_rc = zoo_get_children(queue->zh, queue->path, 0, vector); + switch(get_children_rc){ + case ZOK: + break; + case ZNONODE: + *buffer_len = -1; + return ZOK; + default: + return get_children_rc; + } + if(stvector.count == 0){ + *buffer_len = -1; + return ZOK; + } + + sort_children(vector); + /*try all*/ + int i; + for(i=0; i < stvector.count; i++){ + char *child_name = stvector.data[i]; + int child_path_length = path_length + 1 + strlen(child_name) +1; + char child_path[child_path_length]; + concat_path_nodename_n(child_path, child_path_length, queue->path, child_name); + int get_rc = zoo_get(queue->zh, child_path, 0, buffer, buffer_len, NULL); + switch(get_rc){ + case ZOK: + free_String_vector(vector); + return ZOK; + case ZNONODE: + break; + default: + free_String_vector(vector); + return get_rc; + } + } + + free_String_vector(vector); + } +} + +ZOOAPI int zkr_queue_remove(zkr_queue_t *queue, char *buffer, int *buffer_len){ + int path_length = strlen(queue->path); + for(;;){ + struct String_vector stvector; + struct String_vector *vector = &stvector; + /*Get sorted children*/ + int get_children_rc = zoo_get_children(queue->zh, queue->path, 0, &stvector); + switch(get_children_rc){ + case ZOK: + break; + case ZNONODE: + *buffer_len = -1; + return ZOK; + + default: + *buffer_len = -1; + return get_children_rc; + } + if(stvector.count == 0){ + *buffer_len = -1; + return ZOK; + } + + sort_children(vector); + /*try all*/ + int i; + for( i=0; i < stvector.count; i++){ + char *child_name = stvector.data[i]; + int child_path_length = path_length + 1 + strlen(child_name) +1; + char child_path[child_path_length]; + concat_path_nodename_n(child_path, child_path_length, queue->path, child_name); + int get_rc = zoo_get(queue->zh, child_path, 0, buffer, buffer_len, NULL); + switch(get_rc){ + int delete_rc; + case ZOK: + delete_rc = zoo_delete(queue->zh, child_path, -1); + switch(delete_rc){ + case ZOK: + free_String_vector(vector); + return delete_rc; + case ZNONODE: + break; + default: + free_String_vector(vector); + *buffer_len = -1; + return delete_rc; + } + break; + case ZNONODE: + break; + default: + free_String_vector(vector); + *buffer_len = -1; + return get_rc; + } + } + free_String_vector(vector); + } +} + +/** + * The take_latch structure roughly emulates a Java CountdownLatch with 1 as the initial value. + * It is meant to be used by a setter thread and a waiter thread. + * + * This latch is specialized to be used with the queue, all latches created for the same queue structure will use the same mutex. + * + * The setter thread at some point will call take_latch_setter_trigger_latch() on the thread. + * + * The waiter thread creates the latch and at some point either calls take_latch_waiter_await()s or take_latch_waiter_mark_unneeded()s it. + * The await function will return after the setter thread has triggered the latch. + * The mark unneeded function will return immediately and avoid some unneeded initialization. + * + * Whichever thread is last to call their required function disposes of the latch. + * + * The latch may disposed if no threads will call the waiting, marking, or triggering functions using take_latch_destroy_syncrhonized(). + */ + +struct take_latch { + enum take_state {take_init, take_waiting, take_triggered, take_not_needed} state; + pthread_cond_t latch_condition; + zkr_queue_t *queue; +}; + + +typedef struct take_latch take_latch_t; + + +static void take_latch_init( take_latch_t *latch, zkr_queue_t *queue){ + pthread_mutex_t *mutex = &(queue->pmutex); + pthread_mutex_lock(mutex); + latch->state = take_init; + latch->queue = queue; + pthread_mutex_unlock(mutex); +} + +static take_latch_t *create_take_latch(zkr_queue_t *queue){ + take_latch_t *new_take_latch = (take_latch_t *) malloc(sizeof(take_latch_t)); + take_latch_init(new_take_latch, queue); + return new_take_latch; +} + + +//Only call this when you own the mutex +static void take_latch_destroy_unsafe(take_latch_t *latch){ + if(latch->state == take_waiting){ + pthread_cond_destroy(&(latch->latch_condition)); + } + free(latch); +} + +static void take_latch_destroy_synchronized(take_latch_t *latch){ + pthread_mutex_t *mutex = &(latch->queue->pmutex); + pthread_mutex_lock(mutex); + take_latch_destroy_unsafe(latch); + pthread_mutex_unlock(mutex); +} + +static void take_latch_setter_trigger_latch(take_latch_t *latch){ + pthread_mutex_t *mutex = &(latch->queue->pmutex); + pthread_mutex_lock(mutex); + switch(latch->state){ + case take_init: + latch->state = take_triggered; + break; + case take_not_needed: + take_latch_destroy_unsafe(latch); + break; + case take_triggered: + LOG_DEBUG(("Error! Latch was triggered twice.")); + break; + case take_waiting: + pthread_cond_signal(&(latch->latch_condition)); + break; + } + pthread_mutex_unlock(mutex); +} + +static void take_latch_waiter_await(take_latch_t *latch){ + pthread_mutex_t *mutex = &(latch->queue->pmutex); + pthread_mutex_lock(mutex); + switch(latch->state){ + case take_init: + pthread_cond_init(&(latch->latch_condition),NULL); + latch->state = take_waiting; + pthread_cond_wait(&(latch->latch_condition),mutex); + take_latch_destroy_unsafe(latch); + break; + case take_waiting: + LOG_DEBUG(("Error! Called await twice.")); + break; + case take_not_needed: + LOG_DEBUG(("Error! Waiting after marking not needed.")); + break; + case take_triggered: + take_latch_destroy_unsafe(latch); + break; + } + pthread_mutex_unlock(mutex); +} + +static void take_latch_waiter_mark_unneeded(take_latch_t *latch){ + pthread_mutex_t *mutex = &(latch->queue->pmutex); + pthread_mutex_lock(mutex); + switch(latch->state){ + case take_init: + latch->state = take_not_needed; + break; + case take_waiting: + LOG_DEBUG(("Error! Can't mark unneeded after waiting.")); + break; + case take_not_needed: + LOG_DEBUG(("Marked unneeded twice.")); + break; + case take_triggered: + take_latch_destroy_unsafe(latch); + break; + } + pthread_mutex_unlock(mutex); +} + +static void take_watcher(zhandle_t *zh, int type, int state, const char *path, void *watcherCtx){ + take_latch_t *latch = (take_latch_t *) watcherCtx; + take_latch_setter_trigger_latch(latch); +} + + + +ZOOAPI int zkr_queue_take(zkr_queue_t *queue, char *buffer, int *buffer_len){ + int path_length = strlen(queue->path); +take_attempt: + for(;;){ + struct String_vector stvector; + struct String_vector *vector = &stvector; + /*Get sorted children*/ + take_latch_t *take_latch = create_take_latch(queue); + int get_children_rc = zoo_wget_children(queue->zh, queue->path, take_watcher, take_latch, &stvector); + switch(get_children_rc){ + case ZOK: + break; + int create_queue_rc; + case ZNONODE: + take_latch_destroy_synchronized(take_latch); + create_queue_rc = create_queue_root(queue); + switch(create_queue_rc){ + case ZNODEEXISTS: + case ZOK: + goto take_attempt; + default: + *buffer_len = -1; + return create_queue_rc; + } + default: + take_latch_destroy_synchronized(take_latch); + *buffer_len = -1; + return get_children_rc; + } + if(stvector.count == 0){ + take_latch_waiter_await(take_latch); + }else{ + take_latch_waiter_mark_unneeded(take_latch); + } + + sort_children(vector); + /*try all*/ + int i; + for( i=0; i < stvector.count; i++){ + char *child_name = stvector.data[i]; + int child_path_length = path_length + 1 + strlen(child_name) +1; + char child_path[child_path_length]; + concat_path_nodename_n(child_path, child_path_length, queue->path, child_name); + int get_rc = zoo_get(queue->zh, child_path, 0, buffer, buffer_len, NULL); + switch(get_rc){ + int delete_rc; + case ZOK: + delete_rc = zoo_delete(queue->zh, child_path, -1); + switch(delete_rc){ + case ZOK: + free_String_vector(vector); + return delete_rc; + case ZNONODE: + break; + default: + free_String_vector(vector); + *buffer_len = -1; + return delete_rc; + } + break; + case ZNONODE: + break; + default: + free_String_vector(vector); + *buffer_len = -1; + return get_rc; + } + } + free_String_vector(vector); + } +} + +ZOOAPI void zkr_queue_destroy(zkr_queue_t *queue){ + pthread_mutex_destroy(&(queue->pmutex)); + if(queue->cached_create_path != NULL){ + free(queue->cached_create_path); + } +} diff --git a/src/java/main/org/apache/recipes/queue/src/c/tests/TestClient.cc b/src/java/main/org/apache/recipes/queue/src/c/tests/TestClient.cc new file mode 100644 index 00000000000..5446d9b82fa --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/tests/TestClient.cc @@ -0,0 +1,452 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + + +using namespace std; + +#include +#include + +#include +#include + +static void yield(zhandle_t *zh, int i) +{ + sleep(i); +} + +typedef struct evt { + string path; + int type; +} evt_t; + +typedef struct watchCtx { +private: + list events; +public: + bool connected; + zhandle_t *zh; + + watchCtx() { + connected = false; + zh = 0; + } + ~watchCtx() { + if (zh) { + zookeeper_close(zh); + zh = 0; + } + } + + evt_t getEvent() { + evt_t evt; + evt = events.front(); + events.pop_front(); + return evt; + } + + int countEvents() { + int count; + count = events.size(); + return count; + } + + void putEvent(evt_t evt) { + events.push_back(evt); + } + + bool waitForConnected(zhandle_t *zh) { + time_t expires = time(0) + 10; + while(!connected && time(0) < expires) { + yield(zh, 1); + } + return connected; + } + bool waitForDisconnected(zhandle_t *zh) { + time_t expires = time(0) + 15; + while(connected && time(0) < expires) { + yield(zh, 1); + } + return !connected; + } +} watchctx_t; + +extern "C" { + + const char *thread_test_string="Hello World!"; + + void *offer_thread_shared_queue(void *queue_handle){ + zkr_queue_t *queue = (zkr_queue_t *) queue_handle; + + int test_string_buffer_length = strlen(thread_test_string) + 1; + int offer_rc = zkr_queue_offer(queue, thread_test_string, test_string_buffer_length); + pthread_exit(NULL); + } + + void *take_thread_shared_queue(void *queue_handle){ + zkr_queue_t *queue = (zkr_queue_t *) queue_handle; + + int test_string_buffer_length = strlen(thread_test_string) + 1; + int receive_buffer_capacity = test_string_buffer_length; + int receive_buffer_length = receive_buffer_capacity; + char *receive_buffer = (char *) malloc(sizeof(char) * receive_buffer_capacity); + + int remove_rc = zkr_queue_take(queue, receive_buffer, &receive_buffer_length); + switch(remove_rc){ + case ZOK: + pthread_exit(receive_buffer); + default: + free(receive_buffer); + pthread_exit(NULL); + } + } + + int valid_test_string(void *result){ + char *result_string = (char *) result; + return !strncmp(result_string, thread_test_string, strlen(thread_test_string)); + } +} + +class Zookeeper_queuetest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(Zookeeper_queuetest); + CPPUNIT_TEST(testInitDestroy); + CPPUNIT_TEST(testOffer1); + CPPUNIT_TEST(testOfferRemove1); + CPPUNIT_TEST(testOfferRemove2); + CPPUNIT_TEST(testOfferRemove3); + CPPUNIT_TEST(testOfferRemove4); + CPPUNIT_TEST(testOfferRemove5); + CPPUNIT_TEST(testOfferRemove6); + CPPUNIT_TEST(testOfferTake1); + CPPUNIT_TEST(testOfferTake2); + CPPUNIT_TEST(testOfferTake3); + CPPUNIT_TEST(testOfferTake4); + CPPUNIT_TEST(testOfferTake5); + CPPUNIT_TEST(testOfferTake6); + CPPUNIT_TEST_SUITE_END(); + + static void watcher(zhandle_t *, int type, int state, const char *path,void*v){ + watchctx_t *ctx = (watchctx_t*)v; + + if (state == ZOO_CONNECTED_STATE) { + ctx->connected = true; + } else { + ctx->connected = false; + } + if (type != ZOO_SESSION_EVENT) { + evt_t evt; + evt.path = path; + evt.type = type; + ctx->putEvent(evt); + } + } + + static const char hostPorts[]; + + const char *getHostPorts() { + return hostPorts; + } + + zhandle_t *createClient(watchctx_t *ctx) { + zhandle_t *zk = zookeeper_init(hostPorts, watcher, 10000, 0, + ctx, 0); + ctx->zh = zk; + sleep(1); + return zk; + } + +public: + +#define ZKSERVER_CMD "./tests/zkServer.sh" + + void setUp() + { + char cmd[1024]; + sprintf(cmd, "%s startClean %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + + void startServer() { + char cmd[1024]; + sprintf(cmd, "%s start %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + void stopServer() { + tearDown(); + } + + void tearDown() + { + char cmd[1024]; + sprintf(cmd, "%s stop %s", ZKSERVER_CMD, getHostPorts()); + CPPUNIT_ASSERT(system(cmd) == 0); + } + + void initializeQueuesAndHandles(int num_clients, zhandle_t *zoohandles[], + watchctx_t ctxs[], zkr_queue_t queues[], char *path){ + int i; + for(i=0; i< num_clients; i++){ + zoohandles[i] = createClient(&ctxs[i]); + zkr_queue_init(&queues[i], zoohandles[i], path, &ZOO_OPEN_ACL_UNSAFE); + } + } + + void cleanUpQueues(int num_clients, zkr_queue_t queues[]){ + int i; + for(i=0; i < num_clients; i++){ + zkr_queue_destroy(&queues[i]); + } + } + + void testInitDestroy(){ + int num_clients = 1; + watchctx_t ctxs[num_clients]; + zhandle_t *zoohandles[num_clients]; + zkr_queue_t queues[num_clients]; + char *path= (char *)"/testInitDestroy"; + + int i; + for(i=0; i< num_clients; i++){ + zoohandles[i] = createClient(&ctxs[i]); + zkr_queue_init(&queues[i], zoohandles[i], path, &ZOO_OPEN_ACL_UNSAFE); + } + + for(i=0; i< num_clients; i++){ + zkr_queue_destroy(&queues[i]); + } + + } + + void testOffer1(){ + int num_clients = 1; + watchctx_t ctxs[num_clients]; + zhandle_t *zoohandles[num_clients]; + zkr_queue_t queues[num_clients]; + char *path= (char *)"/testOffer1"; + + initializeQueuesAndHandles(num_clients, zoohandles, ctxs, queues, path); + + const char *test_string="Hello World!"; + int test_string_length = strlen(test_string); + int test_string_buffer_length = test_string_length + 1; + char buffer[test_string_buffer_length]; + + int offer_rc = zkr_queue_offer(&queues[0], test_string, test_string_buffer_length); + CPPUNIT_ASSERT(offer_rc == ZOK); + + int removed_element_buffer_length = test_string_buffer_length; + int remove_rc = zkr_queue_remove(&queues[0], buffer, &removed_element_buffer_length); + CPPUNIT_ASSERT(remove_rc == ZOK); + CPPUNIT_ASSERT(removed_element_buffer_length == test_string_buffer_length); + CPPUNIT_ASSERT(strncmp(test_string,buffer,test_string_length)==0); + + cleanUpQueues(num_clients,queues); + } + + void create_n_remove_m(char *path, int n, int m){ + int num_clients = 2; + watchctx_t ctxs[num_clients]; + zhandle_t *zoohandles[num_clients]; + zkr_queue_t queues[num_clients]; + + initializeQueuesAndHandles(num_clients, zoohandles, ctxs, queues, path); + + int i; + int max_digits = sizeof(int)*3; + const char *test_string = "Hello World!"; + int buffer_length = strlen(test_string) + max_digits + 1; + char correct_buffer[buffer_length]; + char receive_buffer[buffer_length]; + + for(i = 0; i < n; i++){ + snprintf(correct_buffer, buffer_length, "%s%d", test_string,i); + int offer_rc = zkr_queue_offer(&queues[0], correct_buffer, buffer_length); + CPPUNIT_ASSERT(offer_rc == ZOK); + } + printf("Offers\n"); + for(i=0; i=n){ + CPPUNIT_ASSERT(receive_buffer_length == -1); + }else{ + CPPUNIT_ASSERT(strncmp(correct_buffer,receive_buffer, buffer_length)==0); + } + } + + cleanUpQueues(num_clients,queues); + } + + void testOfferRemove1(){ + create_n_remove_m((char *)"/testOfferRemove1", 0,1); + } + + void testOfferRemove2(){ + create_n_remove_m((char *)"/testOfferRemove2", 1,1); + } + + void testOfferRemove3(){ + create_n_remove_m((char *)"/testOfferRemove3", 10,1); + } + + void testOfferRemove4(){ + create_n_remove_m((char *)"/testOfferRemove4", 10,10); + } + + void testOfferRemove5(){ + create_n_remove_m((char *)"/testOfferRemove5", 10,5); + } + + void testOfferRemove6(){ + create_n_remove_m((char *)"/testOfferRemove6", 10,11); + } + + void create_n_take_m(char *path, int n, int m){ + CPPUNIT_ASSERT(m<=n); + int num_clients = 2; + watchctx_t ctxs[num_clients]; + zhandle_t *zoohandles[num_clients]; + zkr_queue_t queues[num_clients]; + + initializeQueuesAndHandles(num_clients, zoohandles, ctxs, queues, path); + + int i; + int max_digits = sizeof(int)*3; + const char *test_string = "Hello World!"; + int buffer_length = strlen(test_string) + max_digits + 1; + char correct_buffer[buffer_length]; + char receive_buffer[buffer_length]; + + for(i = 0; i < n; i++){ + snprintf(correct_buffer, buffer_length, "%s%d", test_string,i); + int offer_rc = zkr_queue_offer(&queues[0], correct_buffer, buffer_length); + CPPUNIT_ASSERT(offer_rc == ZOK); + } + printf("Offers\n"); + for(i=0; i=n){ + CPPUNIT_ASSERT(receive_buffer_length == -1); + }else{ + CPPUNIT_ASSERT(strncmp(correct_buffer,receive_buffer, buffer_length)==0); + } + } + + cleanUpQueues(num_clients,queues); + } + + void testOfferTake1(){ + create_n_take_m((char *)"/testOfferTake1", 2,1); + } + + void testOfferTake2(){ + create_n_take_m((char *)"/testOfferTake2", 1,1); + } + + void testOfferTake3(){ + create_n_take_m((char *)"/testOfferTake3", 10,1); + } + + void testOfferTake4(){ + create_n_take_m((char *)"/testOfferTake4", 10,10); + } + + void testOfferTake5(){ + create_n_take_m((char *)"/testOfferTake5", 10,5); + } + + void testOfferTake6(){ + create_n_take_m((char *)"/testOfferTake6", 12,11); + } + + void testTakeThreaded(){ + int num_clients = 1; + watchctx_t ctxs[num_clients]; + zhandle_t *zoohandles[num_clients]; + zkr_queue_t queues[num_clients]; + char *path=(char *)"/testTakeThreaded"; + + initializeQueuesAndHandles(num_clients, zoohandles, ctxs, queues, path); + pthread_t take_thread; + + pthread_create(&take_thread, NULL, take_thread_shared_queue, (void *) &queues[0]); + + usleep(1000); + + pthread_t offer_thread; + pthread_create(&offer_thread, NULL, offer_thread_shared_queue, (void *) &queues[0]); + pthread_join(offer_thread, NULL); + + void *take_thread_result; + pthread_join(take_thread, &take_thread_result); + CPPUNIT_ASSERT(take_thread_result != NULL); + CPPUNIT_ASSERT(valid_test_string(take_thread_result)); + + cleanUpQueues(num_clients,queues); + } + + void testTakeThreaded2(){ + int num_clients = 1; + watchctx_t ctxs[num_clients]; + zhandle_t *zoohandles[num_clients]; + zkr_queue_t queues[num_clients]; + char *path=(char *)"/testTakeThreaded2"; + + initializeQueuesAndHandles(num_clients, zoohandles, ctxs, queues, path); + + int take_attempts; + int num_take_attempts = 2; + for(take_attempts=0; take_attempts < num_take_attempts; take_attempts++){ + pthread_t take_thread; + + pthread_create(&take_thread, NULL, take_thread_shared_queue, (void *) &queues[0]); + + usleep(1000); + + pthread_t offer_thread; + pthread_create(&offer_thread, NULL, offer_thread_shared_queue, (void *) &queues[0]); + pthread_join(offer_thread, NULL); + + void *take_thread_result; + pthread_join(take_thread, &take_thread_result); + CPPUNIT_ASSERT(take_thread_result != NULL); + CPPUNIT_ASSERT(valid_test_string(take_thread_result)); + + } + cleanUpQueues(num_clients,queues); + } +}; + +const char Zookeeper_queuetest::hostPorts[] = "127.0.0.1:22181"; +CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_queuetest); diff --git a/src/java/main/org/apache/recipes/queue/src/c/tests/TestDriver.cc b/src/java/main/org/apache/recipes/queue/src/c/tests/TestDriver.cc new file mode 100644 index 00000000000..2b818f45087 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/c/tests/TestDriver.cc @@ -0,0 +1,114 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Util.h" + +using namespace std; + +CPPUNIT_NS_BEGIN + +class EclipseOutputter: public CompilerOutputter +{ +public: + EclipseOutputter(TestResultCollector *result,ostream &stream): + CompilerOutputter(result,stream,"%p:%l: "),stream_(stream) + { + } + virtual void printFailedTestName( TestFailure *failure ){} + virtual void printFailureMessage( TestFailure *failure ) + { + stream_<<": "; + Message msg = failure->thrownException()->message(); + stream_<< msg.shortDescription(); + + string text; + for(int i=0; i the output must be in the compiler error format. + //bool selfTest = (argc > 1) && (std::string("-ide") == argv[1]); + globalTestConfig.addConfigFromCmdLine(argc,argv); + + // Create the event manager and test controller + CPPUNIT_NS::TestResult controller; + // Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); + + // Add a listener that print dots as tests run. + // CPPUNIT_NS::TextTestProgressListener progress; + CPPUNIT_NS::BriefTestProgressListener progress; + controller.addListener( &progress ); + + CPPUNIT_NS::TestRunner runner; + runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); + + try + { + cout << "Running " << globalTestConfig.getTestName(); + runner.run( controller, globalTestConfig.getTestName()); + cout< +#include +#include + +// number of elements in array +#define COUNTOF(array) sizeof(array)/sizeof(array[0]) + +#define DECLARE_WRAPPER(ret,sym,sig) \ + extern "C" ret __real_##sym sig; \ + extern "C" ret __wrap_##sym sig + +#define CALL_REAL(sym,params) \ + __real_##sym params + +// must include "src/zookeeper_log.h" to be able to use this macro +#define TEST_TRACE(x) \ + log_message(3,__LINE__,__func__,format_log_message x) + +extern const std::string EMPTY_STRING; + +// ***************************************************************************** +// A bit of wizardry to get to the bare type from a reference or a pointer +// to the type +template +struct TypeOp { + typedef T BareT; + typedef T ArgT; +}; + +// partial specialization for reference types +template +struct TypeOp{ + typedef T& ArgT; + typedef typename TypeOp::BareT BareT; +}; + +// partial specialization for pointers +template +struct TypeOp{ + typedef T* ArgT; + typedef typename TypeOp::BareT BareT; +}; + +// ***************************************************************************** +// Container utilities + +template +void putValue(std::map& map,const K& k, const V& v){ + typedef std::map Map; + typename Map::const_iterator it=map.find(k); + if(it==map.end()) + map.insert(typename Map::value_type(k,v)); + else + map[k]=v; +} + +template +bool getValue(const std::map& map,const K& k,V& v){ + typedef std::map Map; + typename Map::const_iterator it=map.find(k); + if(it==map.end()) + return false; + v=it->second; + return true; +} + +// ***************************************************************************** +// misc utils + +// millisecond sleep +void millisleep(int ms); +// evaluate given predicate until it returns true or the timeout +// (in millis) has expired +template +int ensureCondition(const Predicate& p,int timeout){ + int elapsed=0; + while(!p() && elapsed CmdLineOptList; +public: + typedef CmdLineOptList::const_iterator const_iterator; + TestConfig(){} + ~TestConfig(){} + void addConfigFromCmdLine(int argc, char* argv[]){ + if(argc>=2) + testName_=argv[1]; + for(int i=2; i /tmp/zk.log & + echo $! > /tmp/zk.pid + sleep 5 + ;; +stop) + # Already killed above + ;; +*) + echo "Unknown command " + $1 + exit 2 +esac + diff --git a/src/java/main/org/apache/recipes/queue/src/java/org/apache/zookeeper/recipes/queue/DistributedQueue.java b/src/java/main/org/apache/recipes/queue/src/java/org/apache/zookeeper/recipes/queue/DistributedQueue.java new file mode 100644 index 00000000000..b41d4cdcfce --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/src/java/org/apache/zookeeper/recipes/queue/DistributedQueue.java @@ -0,0 +1,301 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.recipes.queue.src.java.org.apache.zookeeper.recipes.queue; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.TreeMap; +import java.util.concurrent.CountDownLatch; + +/** + * + * A protocol to implement a distributed queue. + * + */ + +public class DistributedQueue { + private static final Logger LOG = LoggerFactory.getLogger(DistributedQueue.class); + + private final String dir; + private final String prefix = "qn-"; + private ZooKeeper zookeeper; + private List acl = ZooDefs.Ids.OPEN_ACL_UNSAFE; + + + public DistributedQueue(ZooKeeper zookeeper, String dir, List acl) { + this.dir = dir; + + if (acl != null) { + this.acl = acl; + } + this.zookeeper = zookeeper; + + } + + + /** + * Returns a Map of the children, ordered by id. + * @param watcher optional watcher on getChildren() operation. + * @return map from id to child name for all children + */ + private TreeMap orderedChildren(Watcher watcher) throws KeeperException, InterruptedException { + TreeMap orderedChildren = new TreeMap(); + + List childNames = null; + try { + childNames = zookeeper.getChildren(dir, watcher); + } catch (KeeperException.NoNodeException e) { + throw e; + } + + for (String childName : childNames) { + try { + //Check format + if (!childName.regionMatches(0, prefix, 0, prefix.length())) { + LOG.warn("Found child node with improper name: " + childName); + continue; + } + String suffix = childName.substring(prefix.length()); + Long childId = new Long(suffix); + orderedChildren.put(childId, childName); + } catch (NumberFormatException e) { + LOG.warn("Found child node with improper format : " + childName + " " + e, e); + } + } + + return orderedChildren; + } + + /** + * Find the smallest child node. + * @return The name of the smallest child node. + */ + private String smallestChildName() throws KeeperException, InterruptedException { + long minId = Long.MAX_VALUE; + String minName = ""; + + List childNames = null; + + try { + childNames = zookeeper.getChildren(dir, false); + } catch (KeeperException.NoNodeException e) { + LOG.warn("Caught: " + e, e); + return null; + } + + for (String childName : childNames) { + try { + //Check format + if (!childName.regionMatches(0, prefix, 0, prefix.length())) { + LOG.warn("Found child node with improper name: " + childName); + continue; + } + String suffix = childName.substring(prefix.length()); + long childId = Long.parseLong(suffix); + if (childId < minId) { + minId = childId; + minName = childName; + } + } catch (NumberFormatException e) { + LOG.warn("Found child node with improper format : " + childName + " " + e, e); + } + } + + + if (minId < Long.MAX_VALUE) { + return minName; + } else { + return null; + } + } + + /** + * Return the head of the queue without modifying the queue. + * @return the data at the head of the queue. + * @throws NoSuchElementException + * @throws KeeperException + * @throws InterruptedException + */ + public byte[] element() throws NoSuchElementException, KeeperException, InterruptedException { + TreeMap orderedChildren; + + // element, take, and remove follow the same pattern. + // We want to return the child node with the smallest sequence number. + // Since other clients are remove()ing and take()ing nodes concurrently, + // the child with the smallest sequence number in orderedChildren might be gone by the time we check. + // We don't call getChildren again until we have tried the rest of the nodes in sequence order. + while (true) { + try { + orderedChildren = orderedChildren(null); + } catch (KeeperException.NoNodeException e) { + throw new NoSuchElementException(); + } + if (orderedChildren.size() == 0) throw new NoSuchElementException(); + + for (String headNode : orderedChildren.values()) { + if (headNode != null) { + try { + return zookeeper.getData(dir + "/" + headNode, false, null); + } catch (KeeperException.NoNodeException e) { + //Another client removed the node first, try next + } + } + } + + } + } + + + /** + * Attempts to remove the head of the queue and return it. + * @return The former head of the queue + * @throws NoSuchElementException + * @throws KeeperException + * @throws InterruptedException + */ + public byte[] remove() throws NoSuchElementException, KeeperException, InterruptedException { + TreeMap orderedChildren; + // Same as for element. Should refactor this. + while (true) { + try { + orderedChildren = orderedChildren(null); + } catch (KeeperException.NoNodeException e) { + throw new NoSuchElementException(); + } + if (orderedChildren.size() == 0) throw new NoSuchElementException(); + + for (String headNode : orderedChildren.values()) { + String path = dir + "/" + headNode; + try { + byte[] data = zookeeper.getData(path, false, null); + zookeeper.delete(path, -1); + return data; + } catch (KeeperException.NoNodeException e) { + // Another client deleted the node first. + } + } + + } + } + + /** + * Removes the head of the queue and returns it, blocks until it succeeds. + * @return The former head of the queue + * @throws NoSuchElementException + * @throws KeeperException + * @throws InterruptedException + */ + public byte[] take() throws KeeperException, InterruptedException { + TreeMap orderedChildren; + // Same as for element. Should refactor this. + while (true) { + LatchChildWatcher childWatcher = new LatchChildWatcher(); + try { + orderedChildren = orderedChildren(childWatcher); + } catch (KeeperException.NoNodeException e) { + zookeeper.create(dir, new byte[0], acl, CreateMode.PERSISTENT); + continue; + } + if (orderedChildren.size() == 0) { + childWatcher.await(); + continue; + } + + for (String headNode : orderedChildren.values()) { + String path = dir + "/" + headNode; + try { + byte[] data = zookeeper.getData(path, false, null); + zookeeper.delete(path, -1); + return data; + } catch (KeeperException.NoNodeException e) { + // Another client deleted the node first. + } + } + } + } + + /** + * Inserts data into queue. + * @param data + * @return true if data was successfully added + */ + public boolean offer(byte[] data) throws KeeperException, InterruptedException { + for (; ; ) { + try { + zookeeper.create(dir + "/" + prefix, data, acl, CreateMode.PERSISTENT_SEQUENTIAL); + return true; + } catch (KeeperException.NoNodeException e) { + zookeeper.create(dir, new byte[0], acl, CreateMode.PERSISTENT); + } + } + + } + + /** + * Returns the data at the first element of the queue, or null if the queue is empty. + * @return data at the first element of the queue, or null. + * @throws KeeperException + * @throws InterruptedException + */ + public byte[] peek() throws KeeperException, InterruptedException { + try { + return element(); + } catch (NoSuchElementException e) { + return null; + } + } + + /** + * Attempts to remove the head of the queue and return it. Returns null if the queue is empty. + * @return Head of the queue or null. + * @throws KeeperException + * @throws InterruptedException + */ + public byte[] poll() throws KeeperException, InterruptedException { + try { + return remove(); + } catch (NoSuchElementException e) { + return null; + } + } + + private class LatchChildWatcher implements Watcher { + + CountDownLatch latch; + + public LatchChildWatcher() { + latch = new CountDownLatch(1); + } + + public void process(WatchedEvent event) { + LOG.debug("Watcher fired on path: " + event.getPath() + " state: " + + event.getState() + " type " + event.getType()); + latch.countDown(); + } + + public void await() throws InterruptedException { + latch.await(); + } + } + + +} diff --git a/src/java/main/org/apache/recipes/queue/test/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java b/src/java/main/org/apache/recipes/queue/test/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java new file mode 100644 index 00000000000..51207c99135 --- /dev/null +++ b/src/java/main/org/apache/recipes/queue/test/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java @@ -0,0 +1,278 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.recipes.queue.test.org.apache.zookeeper.recipes.queue; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +import java.util.NoSuchElementException; + + +public class DistributedQueueTest extends ClientBase { + + @After + public void tearDown() throws Exception { + super.tearDown(); + LOG.info("FINISHED " + getTestName()); + } + + + @Test + public void testOffer1() throws Exception { + String dir = "/testOffer1"; + String testString = "Hello World"; + final int num_clients = 1; + ZooKeeper clients[] = new ZooKeeper[num_clients]; + DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + + queueHandles[0].offer(testString.getBytes()); + + byte dequeuedBytes[] = queueHandles[0].remove(); + Assert.assertEquals(new String(dequeuedBytes), testString); + } + + @Test + public void testOffer2() throws Exception { + String dir = "/testOffer2"; + String testString = "Hello World"; + final int num_clients = 2; + ZooKeeper clients[] = new ZooKeeper[num_clients]; + DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + + queueHandles[0].offer(testString.getBytes()); + + byte dequeuedBytes[] = queueHandles[1].remove(); + Assert.assertEquals(new String(dequeuedBytes), testString); + } + + @Test + public void testTake1() throws Exception { + String dir = "/testTake1"; + String testString = "Hello World"; + final int num_clients = 1; + ZooKeeper clients[] = new ZooKeeper[num_clients]; + DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + + queueHandles[0].offer(testString.getBytes()); + + byte dequeuedBytes[] = queueHandles[0].take(); + Assert.assertEquals(new String(dequeuedBytes), testString); + } + + + @Test + public void testRemove1() throws Exception { + String dir = "/testRemove1"; + String testString = "Hello World"; + final int num_clients = 1; + ZooKeeper clients[] = new ZooKeeper[num_clients]; + DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + + try { + queueHandles[0].remove(); + } catch (NoSuchElementException e) { + return; + } + Assert.assertTrue(false); + } + + public void createNremoveMtest(String dir, int n, int m) throws Exception { + String testString = "Hello World"; + final int num_clients = 2; + ZooKeeper clients[] = new ZooKeeper[num_clients]; + DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + + for (int i = 0; i < n; i++) { + String offerString = testString + i; + queueHandles[0].offer(offerString.getBytes()); + } + + byte data[] = null; + for (int i = 0; i < m; i++) { + data = queueHandles[1].remove(); + } + Assert.assertEquals(new String(data), testString + (m - 1)); + } + + @Test + public void testRemove2() throws Exception { + createNremoveMtest("/testRemove2", 10, 2); + } + + @Test + public void testRemove3() throws Exception { + createNremoveMtest("/testRemove3", 1000, 1000); + } + + public void createNremoveMelementTest(String dir, int n, int m) throws Exception { + String testString = "Hello World"; + final int num_clients = 2; + ZooKeeper clients[] = new ZooKeeper[num_clients]; + DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + + for (int i = 0; i < n; i++) { + String offerString = testString + i; + queueHandles[0].offer(offerString.getBytes()); + } + + byte data[] = null; + for (int i = 0; i < m; i++) { + data = queueHandles[1].remove(); + } + Assert.assertEquals(new String(queueHandles[1].element()), testString + m); + } + + @Test + public void testElement1() throws Exception { + createNremoveMelementTest("/testElement1", 1, 0); + } + + @Test + public void testElement2() throws Exception { + createNremoveMelementTest("/testElement2", 10, 2); + } + + @Test + public void testElement3() throws Exception { + createNremoveMelementTest("/testElement3", 1000, 500); + } + + @Test + public void testElement4() throws Exception { + createNremoveMelementTest("/testElement4", 1000, 1000 - 1); + } + + @Test + public void testTakeWait1() throws Exception { + String dir = "/testTakeWait1"; + final String testString = "Hello World"; + final int num_clients = 1; + final ZooKeeper clients[] = new ZooKeeper[num_clients]; + final DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + + final byte[] takeResult[] = new byte[1][]; + Thread takeThread = new Thread() { + public void run() { + try { + takeResult[0] = queueHandles[0].take(); + } catch (KeeperException e) { + + } catch (InterruptedException e) { + + } + } + }; + takeThread.start(); + + Thread.sleep(1000); + Thread offerThread = new Thread() { + public void run() { + try { + queueHandles[0].offer(testString.getBytes()); + } catch (KeeperException e) { + + } catch (InterruptedException e) { + + } + } + }; + offerThread.start(); + offerThread.join(); + + takeThread.join(); + + Assert.assertTrue(takeResult[0] != null); + Assert.assertEquals(new String(takeResult[0]), testString); + } + + @Test + public void testTakeWait2() throws Exception { + String dir = "/testTakeWait2"; + final String testString = "Hello World"; + final int num_clients = 1; + final ZooKeeper clients[] = new ZooKeeper[num_clients]; + final DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; + for (int i = 0; i < clients.length; i++) { + clients[i] = createClient(); + queueHandles[i] = new DistributedQueue(clients[i], dir, null); + } + int num_attempts = 2; + for (int i = 0; i < num_attempts; i++) { + final byte[] takeResult[] = new byte[1][]; + final String threadTestString = testString + i; + Thread takeThread = new Thread() { + public void run() { + try { + takeResult[0] = queueHandles[0].take(); + } catch (KeeperException e) { + + } catch (InterruptedException e) { + + } + } + }; + takeThread.start(); + + Thread.sleep(1000); + Thread offerThread = new Thread() { + public void run() { + try { + queueHandles[0].offer(threadTestString.getBytes()); + } catch (KeeperException e) { + + } catch (InterruptedException e) { + + } + } + }; + offerThread.start(); + offerThread.join(); + + takeThread.join(); + + Assert.assertTrue(takeResult[0] != null); + Assert.assertEquals(new String(takeResult[0]), threadTestString); + } + } +} + diff --git a/src/java/main/org/apache/zookeeper/AsyncCallback.java b/src/java/main/org/apache/zookeeper/AsyncCallback.java new file mode 100644 index 00000000000..e7f5915f8b1 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/AsyncCallback.java @@ -0,0 +1,313 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; + +import java.util.List; + +/** + * Interface definitions of asynchronous callbacks. + * An asynchronous callback is deferred to invoke after a function returns. + * Asynchronous calls usually improve system efficiency on IO-related APIs. + *

        + * ZooKeeper provides asynchronous version as equivalent to synchronous APIs. + */ +public interface AsyncCallback { + + /** + * This callback is used to retrieve the stat of the node. + */ + interface StatCallback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + *

        + * On success, rc is + * {@link org.apache.zookeeper.KeeperException.Code#OK}. + *

        + * On failure, rc is set to the corresponding failure code in + * {@link org.apache.zookeeper.KeeperException}. + *

          + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NONODE} + * - The node on given path doesn't exist for some API calls. + *
        • + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#BADVERSION} + * - The given version doesn't match the node's version + * for some API calls. + *
        • + *
        + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param stat {@link org.apache.zookeeper.data.Stat} object of + * the node on given path. + */ + public void processResult(int rc, String path, Object ctx, Stat stat); + } + + /** + * This callback is used to retrieve the data and stat of the node. + */ + interface DataCallback extends AsyncCallback { + /** + * Process the result of asynchronous calls. + *

        + * On success, rc is + * {@link org.apache.zookeeper.KeeperException.Code#OK}. + *

        + * On failure, rc is set to the corresponding failure code in + * {@link org.apache.zookeeper.KeeperException}. + *

          + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NONODE} + * - The node on given path doesn't exist for some API calls. + *
        • + *
        + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param data The {@link org.apache.zookeeper.server.DataNode#data} + * of the node. + * @param stat {@link org.apache.zookeeper.data.Stat} object of + * the node on given path. + */ + public void processResult(int rc, String path, Object ctx, byte data[], + Stat stat); + } + + /** + * This callback is used to retrieve the ACL and stat of the node. + */ + interface ACLCallback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + *

        + * On success, rc is + * {@link org.apache.zookeeper.KeeperException.Code#OK}. + *

        + * On failure, rc is set to the corresponding failure code in + * {@link org.apache.zookeeper.KeeperException}. + *

          + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NONODE} + * - The node on given path doesn't exist for some API calls. + *
        • + *
        + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param acl ACL Id in + * {@link org.apache.zookeeper.ZooDefs.Ids}. + * @param stat {@link org.apache.zookeeper.data.Stat} object of + * the node on given path. + */ + public void processResult(int rc, String path, Object ctx, + List acl, Stat stat); + } + + /** + * This callback is used to retrieve the children of the node. + */ + interface ChildrenCallback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + *

        + * On success, rc is + * {@link org.apache.zookeeper.KeeperException.Code#OK}. + *

        + * On failure, rc is set to the corresponding failure code in + * {@link org.apache.zookeeper.KeeperException}. + *

          + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NONODE} + * - The node on given path doesn't exist for some API calls. + *
        • + *
        + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param children An unordered array of children of the node on + * given path. + */ + public void processResult(int rc, String path, Object ctx, + List children); + } + + /** + * This callback is used to retrieve the children and stat of the node. + */ + interface Children2Callback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + * See {@link org.apache.zookeeper.AsyncCallback.ChildrenCallback}. + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param children An unordered array of children of the node on + * given path. + * @param stat {@link org.apache.zookeeper.data.Stat} object of + * the node on given path. + */ + public void processResult(int rc, String path, Object ctx, + List children, Stat stat); + } + + /** + * This callback is used to retrieve the name and stat of the node. + */ + interface Create2Callback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + * See {@link org.apache.zookeeper.AsyncCallback.StringCallback}. + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param name The name of the Znode that was created. + * On success, name and path are usually + * equal, unless a sequential node has been created. + * @param stat {@link org.apache.zookeeper.data.Stat} object of + * the node on given path. + */ + public void processResult(int rc, String path, Object ctx, + String name, Stat stat); + } + + /** + * This callback is used to retrieve the name of the node. + */ + interface StringCallback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + *

        + * On success, rc is + * {@link org.apache.zookeeper.KeeperException.Code#OK}. + *

        + * On failure, rc is set to the corresponding failure code in + * {@link org.apache.zookeeper.KeeperException}. + *

          + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NODEEXISTS} + * - The node on give path already exists for some API calls. + *
        • + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NONODE} + * - The node on given path doesn't exist for some API calls. + *
        • + *
        • + * {@link + * org.apache.zookeeper.KeeperException.Code#NOCHILDRENFOREPHEMERALS} + * - an ephemeral node cannot have children. There is discussion in + * community. It might be changed in the future. + *
        • + *
        + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param name The name of the Znode that was created. + * On success, name and path are usually + * equal, unless a sequential node has been created. + */ + public void processResult(int rc, String path, Object ctx, String name); + } + + /** + * This callback doesn't retrieve anything from the node. It is useful + * for some APIs that doesn't want anything sent back, e.g. {@link + * org.apache.zookeeper.ZooKeeper#sync(String, + * org.apache.zookeeper.AsyncCallback.VoidCallback, Object)}. + */ + interface VoidCallback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + *

        + * On success, rc is + * {@link org.apache.zookeeper.KeeperException.Code#OK}. + *

        + * On failure, rc is set to the corresponding failure code in + * {@link org.apache.zookeeper.KeeperException}. + *

          + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NONODE} + * - The node on given path doesn't exist for some API calls. + *
        • + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#BADVERSION} + * - The given version doesn't match the node's version + * for some API calls. + *
        • + *
        • + * {@link org.apache.zookeeper.KeeperException.Code#NOTEMPTY} + * - the node has children and some API calls cannnot succeed, + * e.g. {@link + * org.apache.zookeeper.ZooKeeper#delete(String, int, + * org.apache.zookeeper.AsyncCallback.VoidCallback, Object)}. + *
        • + *
        + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + */ + public void processResult(int rc, String path, Object ctx); + } + + /** + * This callback is used to process the multiple results from + * a single multi call. + * See {@link org.apache.zookeeper.ZooKeeper#multi} for more information. + */ + interface MultiCallback extends AsyncCallback { + /** + * Process the result of the asynchronous call. + *

        + * On success, rc is + * {@link org.apache.zookeeper.KeeperException.Code#OK}. + * All opResults are + * non-{@link org.apache.zookeeper.OpResult.ErrorResult}, + * + *

        + * On failure, rc is a failure code in + * {@link org.apache.zookeeper.KeeperException.Code}. + * All opResults are + * {@link org.apache.zookeeper.OpResult.ErrorResult}. + * All operations will be rollback-ed even if operations + * before the failing one were successful. + * + * @param rc The return code or the result of the call. + * @param path The path that we passed to asynchronous calls. + * @param ctx Whatever context object that we passed to + * asynchronous calls. + * @param opResults The list of results. + * One result for each operation, + * and the order matches that of input. + */ + public void processResult(int rc, String path, Object ctx, + List opResults); + } +} diff --git a/src/java/main/org/apache/zookeeper/ClientCnxn.java b/src/java/main/org/apache/zookeeper/ClientCnxn.java new file mode 100644 index 00000000000..715c3c19296 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ClientCnxn.java @@ -0,0 +1,1577 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.AsyncCallback.ACLCallback; +import org.apache.zookeeper.AsyncCallback.Children2Callback; +import org.apache.zookeeper.AsyncCallback.ChildrenCallback; +import org.apache.zookeeper.AsyncCallback.Create2Callback; +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.AsyncCallback.MultiCallback; +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.AsyncCallback.StringCallback; +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.OpResult.ErrorResult; +import org.apache.zookeeper.Watcher.Event; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.ZooKeeper.States; +import org.apache.zookeeper.ZooKeeper.WatchRegistration; +import org.apache.zookeeper.client.HostProvider; +import org.apache.zookeeper.client.ZooKeeperSaslClient; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.proto.AuthPacket; +import org.apache.zookeeper.proto.ConnectRequest; +import org.apache.zookeeper.proto.Create2Response; +import org.apache.zookeeper.proto.CreateResponse; +import org.apache.zookeeper.proto.ExistsResponse; +import org.apache.zookeeper.proto.GetACLResponse; +import org.apache.zookeeper.proto.GetChildren2Response; +import org.apache.zookeeper.proto.GetChildrenResponse; +import org.apache.zookeeper.proto.GetDataResponse; +import org.apache.zookeeper.proto.GetSASLRequest; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; +import org.apache.zookeeper.proto.SetACLResponse; +import org.apache.zookeeper.proto.SetDataResponse; +import org.apache.zookeeper.proto.SetWatches; +import org.apache.zookeeper.proto.WatcherEvent; +import org.apache.zookeeper.server.ByteBufferInputStream; +import org.apache.zookeeper.server.ZooKeeperThread; +import org.apache.zookeeper.server.ZooTrace; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.ConnectException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.LinkedBlockingQueue; + +import javax.security.auth.login.LoginException; +import javax.security.sasl.SaslException; + +/** + * This class manages the socket i/o for the client. ClientCnxn maintains a list + * of available servers to connect to and "transparently" switches servers it is + * connected to as needed. + * + */ +public class ClientCnxn { + public static final int packetLen = Integer.getInteger("jute.maxbuffer", + 4096 * 1024); + private static final Logger LOG = LoggerFactory.getLogger(ClientCnxn.class); + private static final String ZK_SASL_CLIENT_USERNAME = + "zookeeper.sasl.client.username"; + /* ZOOKEEPER-706: If a session has a large number of watches set then + * attempting to re-establish those watches after a connection loss may + * fail due to the SetWatches request exceeding the server's configured + * jute.maxBuffer value. To avoid this we instead split the watch + * re-establishement across multiple SetWatches calls. This constant + * controls the size of each call. It is set to 128kB to be conservative + * with respect to the server's 1MB default for jute.maxBuffer. + */ + private static final int SET_WATCHES_MAX_LENGTH = 128 * 1024; + /** This controls whether automatic watch resetting is enabled. + * Clients automatically reset watches during session reconnect, this + * option allows the client to turn off this behavior by setting + * the environment variable "zookeeper.disableAutoWatchReset" to "true" */ + private static boolean disableAutoWatchReset; + + static { + // this var should not be public, but otw there is no easy way + // to test + disableAutoWatchReset = + Boolean.getBoolean("zookeeper.disableAutoWatchReset"); + if (LOG.isDebugEnabled()) { + LOG.debug("zookeeper.disableAutoWatchReset is " + + disableAutoWatchReset); + } + } + + final String chrootPath; + final SendThread sendThread; + final EventThread eventThread; + private final CopyOnWriteArraySet authInfo = new CopyOnWriteArraySet(); + /** + * These are the packets that have been sent and are waiting for a response. + */ + private final LinkedList pendingQueue = new LinkedList(); + /** + * These are the packets that need to be sent. + */ + private final LinkedBlockingDeque outgoingQueue = new LinkedBlockingDeque(); + private final int sessionTimeout; + + private final ZooKeeper zooKeeper; + + private final ClientWatchManager watcher; + /** + * A set of ZooKeeper hosts this client could connect to. + */ + private final HostProvider hostProvider; + public ZooKeeperSaslClient zooKeeperSaslClient; + /** + * Is set to true when a connection to a r/w server is established for the + * first time; never changed afterwards. + *

        + * Is used to handle situations when client without sessionId connects to a + * read-only server. Such client receives "fake" sessionId from read-only + * server, but this sessionId is invalid for other servers. So when such + * client finds a r/w server, it sends 0 instead of fake sessionId during + * connection handshake and establishes new, valid session. + *

        + * If this field is false (which implies we haven't seen r/w server before) + * then non-zero sessionId is fake, otherwise it is valid. + */ + volatile boolean seenRwServerBefore = false; + // @VisibleForTesting + volatile States state = States.NOT_CONNECTED; + private int connectTimeout; + /** + * The timeout in ms the client negotiated with the server. This is the + * "real" timeout, not the timeout request by the client (which may have + * been increased/decreased by the server which applies bounds to this + * value. + */ + private volatile int negotiatedSessionTimeout; + private int readTimeout; + private long sessionId; + private byte sessionPasswd[] = new byte[16]; + /** + * If true, the connection is allowed to go to r-o mode. This field's value + * is sent, besides other data, during session creation handshake. If the + * server on the other side of the wire is partitioned it'll accept + * read-only clients only. + */ + private boolean readOnly; + /** + * Set to true when close is called. Latches the connection such that we + * don't attempt to re-connect to the server if in the middle of closing the + * connection (client sends session disconnect to server as part of close + * operation) + */ + private volatile boolean closing = false; + private Object eventOfDeath = new Object(); + private volatile long lastZxid; + private int xid = 1; + + /** + * Creates a connection object. The actual network connect doesn't get + * established until needed. The start() instance method must be called + * subsequent to construction. + * + * @param chrootPath - the chroot of this client. Should be removed from this Class in ZOOKEEPER-838 + * @param hostProvider + * the list of ZooKeeper servers to connect to + * @param sessionTimeout + * the timeout for connections. + * @param zooKeeper + * the zookeeper object that this connection is related to. + * @param watcher watcher for this connection + * @param clientCnxnSocket + * the socket implementation used (e.g. NIO/Netty) + * @param canBeReadOnly + * whether the connection is allowed to go to read-only + * mode in case of partitioning + * @throws IOException + */ + public ClientCnxn(String chrootPath, HostProvider hostProvider, int sessionTimeout, ZooKeeper zooKeeper, + ClientWatchManager watcher, ClientCnxnSocket clientCnxnSocket, boolean canBeReadOnly) + throws IOException { + this(chrootPath, hostProvider, sessionTimeout, zooKeeper, watcher, + clientCnxnSocket, 0, new byte[16], canBeReadOnly); + } + + /** + * Creates a connection object. The actual network connect doesn't get + * established until needed. The start() instance method must be called + * subsequent to construction. + * + * @param chrootPath - the chroot of this client. Should be removed from this Class in ZOOKEEPER-838 + * @param hostProvider + * the list of ZooKeeper servers to connect to + * @param sessionTimeout + * the timeout for connections. + * @param zooKeeper + * the zookeeper object that this connection is related to. + * @param watcher watcher for this connection + * @param clientCnxnSocket + * the socket implementation used (e.g. NIO/Netty) + * @param sessionId session id if re-establishing session + * @param sessionPasswd session passwd if re-establishing session + * @param canBeReadOnly + * whether the connection is allowed to go to read-only + * mode in case of partitioning + * @throws IOException + */ + public ClientCnxn(String chrootPath, HostProvider hostProvider, int sessionTimeout, ZooKeeper zooKeeper, + ClientWatchManager watcher, ClientCnxnSocket clientCnxnSocket, + long sessionId, byte[] sessionPasswd, boolean canBeReadOnly) { + this.zooKeeper = zooKeeper; + this.watcher = watcher; + this.sessionId = sessionId; + this.sessionPasswd = sessionPasswd; + this.sessionTimeout = sessionTimeout; + this.hostProvider = hostProvider; + this.chrootPath = chrootPath; + + connectTimeout = sessionTimeout / hostProvider.size(); + readTimeout = sessionTimeout * 2 / 3; + readOnly = canBeReadOnly; + + sendThread = new SendThread(clientCnxnSocket); + eventThread = new EventThread(); + + } + + /** + * tests use this to check on reset of watches + * @return if the auto reset of watches are disabled + */ + public static boolean getDisableAutoResetWatch() { + return disableAutoWatchReset; + } + + /** + * tests use this to set the auto reset + * @param b the value to set disable watches to + */ + public static void setDisableAutoResetWatch(boolean b) { + disableAutoWatchReset = b; + } + + /** + * Guard against creating "-EventThread-EventThread-EventThread-..." thread + * names when ZooKeeper object is being created from within a watcher. + * See ZOOKEEPER-795 for details. + */ + private static String makeThreadName(String suffix) { + String name = Thread.currentThread().getName(). + replaceAll("-EventThread", ""); + return name + suffix; + } + + public long getSessionId() { + return sessionId; + } + + public byte[] getSessionPasswd() { + return sessionPasswd; + } + + public int getSessionTimeout() { + return negotiatedSessionTimeout; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + SocketAddress local = sendThread.getClientCnxnSocket().getLocalSocketAddress(); + SocketAddress remote = sendThread.getClientCnxnSocket().getRemoteSocketAddress(); + sb + .append("sessionid:0x").append(Long.toHexString(getSessionId())) + .append(" local:").append(local) + .append(" remoteserver:").append(remote) + .append(" lastZxid:").append(lastZxid) + .append(" xid:").append(xid) + .append(" sent:").append(sendThread.getClientCnxnSocket().getSentCount()) + .append(" recv:").append(sendThread.getClientCnxnSocket().getRecvCount()) + .append(" queuedpkts:").append(outgoingQueue.size()) + .append(" pendingresp:").append(pendingQueue.size()) + .append(" queuedevents:").append(eventThread.waitingEvents.size()); + + return sb.toString(); + } + + public void start() { + sendThread.start(); + eventThread.start(); + } + + private void finishPacket(Packet p) { + int err = p.replyHeader.getErr(); + if (p.watchRegistration != null) { + p.watchRegistration.register(err); + } + // Add all the removed watch events to the event queue, so that the + // clients will be notified with 'Data/Child WatchRemoved' event type. + if (p.watchDeregistration != null) { + Map> materializedWatchers = null; + try { + materializedWatchers = p.watchDeregistration.unregister(err); + for (Entry> entry : materializedWatchers + .entrySet()) { + Set watchers = entry.getValue(); + if (watchers.size() > 0) { + queueEvent(p.watchDeregistration.getClientPath(), err, + watchers, entry.getKey()); + // ignore connectionloss when removing from local + // session + p.replyHeader.setErr(Code.OK.intValue()); + } + } + } catch (KeeperException.NoWatcherException nwe) { + LOG.error("Failed to find watcher!", nwe); + p.replyHeader.setErr(nwe.code().intValue()); + } catch (KeeperException ke) { + LOG.error("Exception when removing watcher", ke); + p.replyHeader.setErr(ke.code().intValue()); + } + } + + if (p.cb == null) { + synchronized (p) { + p.finished = true; + p.notifyAll(); + } + } else { + p.finished = true; + eventThread.queuePacket(p); + } + } + + void queueEvent(String clientPath, int err, + Set materializedWatchers, EventType eventType) { + KeeperState sessionState = KeeperState.SyncConnected; + if (KeeperException.Code.SESSIONEXPIRED.intValue() == err + || KeeperException.Code.CONNECTIONLOSS.intValue() == err) { + sessionState = Event.KeeperState.Disconnected; + } + WatchedEvent event = new WatchedEvent(eventType, sessionState, + clientPath); + eventThread.queueEvent(event, materializedWatchers); + } + + void queueCallback(AsyncCallback cb, int rc, String path, Object ctx) { + eventThread.queueCallback(cb, rc, path, ctx); + } + + private void conLossPacket(Packet p) { + if (p.replyHeader == null) { + return; + } + switch (state) { + case AUTH_FAILED: + p.replyHeader.setErr(KeeperException.Code.AUTHFAILED.intValue()); + break; + case CLOSED: + p.replyHeader.setErr(KeeperException.Code.SESSIONEXPIRED.intValue()); + break; + default: + p.replyHeader.setErr(KeeperException.Code.CONNECTIONLOSS.intValue()); + } + finishPacket(p); + } + + public long getLastZxid() { + return lastZxid; + } + + /** + * Shutdown the send/event threads. This method should not be called + * directly - rather it should be called as part of close operation. This + * method is primarily here to allow the tests to verify disconnection + * behavior. + */ + public void disconnect() { + if (LOG.isDebugEnabled()) { + LOG.debug("Disconnecting client for session: 0x" + + Long.toHexString(getSessionId())); + } + + sendThread.close(); + eventThread.queueEventOfDeath(); + if (null != zooKeeperSaslClient) { + zooKeeperSaslClient.shutdown(); + } + } + + /** + * Close the connection, which includes; send session disconnect to the + * server, shutdown the send/event threads. + * + * @throws IOException + */ + public void close() throws IOException { + if (LOG.isDebugEnabled()) { + LOG.debug("Closing client for session: 0x" + + Long.toHexString(getSessionId())); + } + + try { + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.closeSession); + + submitRequest(h, null, null, null); + } catch (InterruptedException e) { + // ignore, close the send/event threads + } finally { + disconnect(); + } + } + + /* + * getXid() is called externally by ClientCnxnNIO::doIO() when packets are sent from the outgoingQueue to + * the server. Thus, getXid() must be public. + */ + synchronized public int getXid() { + return xid++; + } + + public ReplyHeader submitRequest(RequestHeader h, Record request, + Record response, WatchRegistration watchRegistration) + throws InterruptedException { + return submitRequest(h, request, response, watchRegistration, null); + } + + public ReplyHeader submitRequest(RequestHeader h, Record request, + Record response, WatchRegistration watchRegistration, + WatchDeregistration watchDeregistration) + throws InterruptedException { + ReplyHeader r = new ReplyHeader(); + Packet packet = queuePacket(h, r, request, response, null, null, null, + null, watchRegistration, watchDeregistration); + synchronized (packet) { + while (!packet.finished) { + packet.wait(); + } + } + return r; + } + + public void saslCompleted() { + sendThread.getClientCnxnSocket().saslCompleted(); + } + + public void sendPacket(Record request, Record response, AsyncCallback cb, int opCode) + throws IOException { + // Generate Xid now because it will be sent immediately, + // by call to sendThread.sendPacket() below. + int xid = getXid(); + RequestHeader h = new RequestHeader(); + h.setXid(xid); + h.setType(opCode); + + ReplyHeader r = new ReplyHeader(); + r.setXid(xid); + + Packet p = new Packet(h, r, request, response, null, false); + p.cb = cb; + sendThread.sendPacket(p); + } + + Packet queuePacket(RequestHeader h, ReplyHeader r, Record request, + Record response, AsyncCallback cb, String clientPath, + String serverPath, Object ctx, WatchRegistration watchRegistration) { + return queuePacket(h, r, request, response, cb, clientPath, serverPath, + ctx, watchRegistration, null); + } + + Packet queuePacket(RequestHeader h, ReplyHeader r, Record request, + Record response, AsyncCallback cb, String clientPath, + String serverPath, Object ctx, WatchRegistration watchRegistration, + WatchDeregistration watchDeregistration) { + Packet packet = null; + + // Note that we do not generate the Xid for the packet yet. It is + // generated later at send-time, by an implementation of ClientCnxnSocket::doIO(), + // where the packet is actually sent. + packet = new Packet(h, r, request, response, watchRegistration); + packet.cb = cb; + packet.ctx = ctx; + packet.clientPath = clientPath; + packet.serverPath = serverPath; + packet.watchDeregistration = watchDeregistration; + // The synchronized block here is for two purpose: + // 1. synchronize with the final cleanup() in SendThread.run() to avoid race + // 2. synchronized against each packet. So if a closeSession packet is added, + // later packet will be notified. + synchronized (state) { + if (!state.isAlive() || closing) { + conLossPacket(packet); + } else { + // If the client is asking to close the session then + // mark as closing + if (h.getType() == OpCode.closeSession) { + closing = true; + } + outgoingQueue.add(packet); + } + } + sendThread.getClientCnxnSocket().packetAdded(); + return packet; + } + + public void addAuthInfo(String scheme, byte auth[]) { + if (!state.isAlive()) { + return; + } + authInfo.add(new AuthData(scheme, auth)); + queuePacket(new RequestHeader(-4, OpCode.auth), null, + new AuthPacket(0, scheme, auth), null, null, null, null, + null, null); + } + + States getState() { + return state; + } + + static class AuthData { + String scheme; + byte data[]; + + AuthData(String scheme, byte data[]) { + this.scheme = scheme; + this.data = data; + } + } + + /** + * This class allows us to pass the headers and the relevant records around. + */ + static class Packet { + public boolean readOnly; + RequestHeader requestHeader; + ReplyHeader replyHeader; + Record request; + Record response; + ByteBuffer bb; + /** Client's view of the path (may differ due to chroot) **/ + String clientPath; + /** Servers's view of the path (may differ due to chroot) **/ + String serverPath; + boolean finished; + AsyncCallback cb; + Object ctx; + WatchRegistration watchRegistration; + WatchDeregistration watchDeregistration; + + /** Convenience ctor */ + Packet(RequestHeader requestHeader, ReplyHeader replyHeader, + Record request, Record response, + WatchRegistration watchRegistration) { + this(requestHeader, replyHeader, request, response, + watchRegistration, false); + } + + Packet(RequestHeader requestHeader, ReplyHeader replyHeader, + Record request, Record response, + WatchRegistration watchRegistration, boolean readOnly) { + + this.requestHeader = requestHeader; + this.replyHeader = replyHeader; + this.request = request; + this.response = response; + this.readOnly = readOnly; + this.watchRegistration = watchRegistration; + } + + public void createBB() { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + boa.writeInt(-1, "len"); // We'll fill this in later + if (requestHeader != null) { + requestHeader.serialize(boa, "header"); + } + if (request instanceof ConnectRequest) { + request.serialize(boa, "connect"); + // append "am-I-allowed-to-be-readonly" flag + boa.writeBool(readOnly, "readOnly"); + } else if (request != null) { + request.serialize(boa, "request"); + } + baos.close(); + this.bb = ByteBuffer.wrap(baos.toByteArray()); + this.bb.putInt(this.bb.capacity() - 4); + this.bb.rewind(); + } catch (IOException e) { + LOG.warn("Ignoring unexpected exception", e); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("clientPath:" + clientPath); + sb.append(" serverPath:" + serverPath); + sb.append(" finished:" + finished); + + sb.append(" header:: " + requestHeader); + sb.append(" replyHeader:: " + replyHeader); + sb.append(" request:: " + request); + sb.append(" response:: " + response); + + // jute toString is horrible, remove unnecessary newlines + return sb.toString().replaceAll("\r*\n+", " "); + } + } + + private static class WatcherSetEventPair { + private final Set watchers; + private final WatchedEvent event; + + public WatcherSetEventPair(Set watchers, WatchedEvent event) { + this.watchers = watchers; + this.event = event; + } + } + + static class EndOfStreamException extends IOException { + private static final long serialVersionUID = -5438877188796231422L; + + public EndOfStreamException(String msg) { + super(msg); + } + + @Override + public String toString() { + return "EndOfStreamException: " + getMessage(); + } + } + + private static class SessionTimeoutException extends IOException { + private static final long serialVersionUID = 824482094072071178L; + + public SessionTimeoutException(String msg) { + super(msg); + } + } + + private static class SessionExpiredException extends IOException { + private static final long serialVersionUID = -1388816932076193249L; + + public SessionExpiredException(String msg) { + super(msg); + } + } + + private static class RWServerFoundException extends IOException { + private static final long serialVersionUID = 90431199887158758L; + + public RWServerFoundException(String msg) { + super(msg); + } + } + + private static class LocalCallback { + private final AsyncCallback cb; + private final int rc; + private final String path; + private final Object ctx; + + public LocalCallback(AsyncCallback cb, int rc, String path, Object ctx) { + this.cb = cb; + this.rc = rc; + this.path = path; + this.ctx = ctx; + } + } + + class EventThread extends ZooKeeperThread { + private final LinkedBlockingQueue waitingEvents = + new LinkedBlockingQueue(); + + /** This is really the queued session state until the event + * thread actually processes the event and hands it to the watcher. + * But for all intents and purposes this is the state. + */ + private volatile KeeperState sessionState = KeeperState.Disconnected; + + private volatile boolean wasKilled = false; + private volatile boolean isRunning = false; + + EventThread() { + super(makeThreadName("-EventThread")); + setDaemon(true); + } + + public void queueEvent(WatchedEvent event) { + queueEvent(event, null); + } + + private void queueEvent(WatchedEvent event, + Set materializedWatchers) { + if (event.getType() == EventType.None + && sessionState == event.getState()) { + return; + } + sessionState = event.getState(); + final Set watchers; + if (materializedWatchers == null) { + // materialize the watchers based on the event + watchers = watcher.materialize(event.getState(), + event.getType(), event.getPath()); + } else { + watchers = new HashSet(); + watchers.addAll(materializedWatchers); + } + WatcherSetEventPair pair = new WatcherSetEventPair(watchers, event); + // queue the pair (watch set & event) for later processing + waitingEvents.add(pair); + } + + public void queueCallback(AsyncCallback cb, int rc, String path, + Object ctx) { + waitingEvents.add(new LocalCallback(cb, rc, path, ctx)); + } + + public void queuePacket(Packet packet) { + if (wasKilled) { + synchronized (waitingEvents) { + if (isRunning) waitingEvents.add(packet); + else processEvent(packet); + } + } else { + waitingEvents.add(packet); + } + } + + public void queueEventOfDeath() { + waitingEvents.add(eventOfDeath); + } + + @Override + public void run() { + try { + isRunning = true; + while (true) { + Object event = waitingEvents.take(); + if (event == eventOfDeath) { + wasKilled = true; + } else { + processEvent(event); + } + if (wasKilled) + synchronized (waitingEvents) { + if (waitingEvents.isEmpty()) { + isRunning = false; + break; + } + } + } + } catch (InterruptedException e) { + LOG.error("Event thread exiting due to interruption", e); + } + + LOG.info("EventThread shut down for session: 0x{}", + Long.toHexString(getSessionId())); + } + + private void processEvent(Object event) { + try { + if (event instanceof WatcherSetEventPair) { + // each watcher will process the event + WatcherSetEventPair pair = (WatcherSetEventPair) event; + for (Watcher watcher : pair.watchers) { + try { + watcher.process(pair.event); + } catch (Throwable t) { + LOG.error("Error while calling watcher ", t); + } + } + } else if (event instanceof LocalCallback) { + LocalCallback lcb = (LocalCallback) event; + if (lcb.cb instanceof StatCallback) { + ((StatCallback) lcb.cb).processResult(lcb.rc, lcb.path, + lcb.ctx, null); + } else if (lcb.cb instanceof DataCallback) { + ((DataCallback) lcb.cb).processResult(lcb.rc, lcb.path, + lcb.ctx, null, null); + } else if (lcb.cb instanceof ACLCallback) { + ((ACLCallback) lcb.cb).processResult(lcb.rc, lcb.path, + lcb.ctx, null, null); + } else if (lcb.cb instanceof ChildrenCallback) { + ((ChildrenCallback) lcb.cb).processResult(lcb.rc, + lcb.path, lcb.ctx, null); + } else if (lcb.cb instanceof Children2Callback) { + ((Children2Callback) lcb.cb).processResult(lcb.rc, + lcb.path, lcb.ctx, null, null); + } else if (lcb.cb instanceof StringCallback) { + ((StringCallback) lcb.cb).processResult(lcb.rc, + lcb.path, lcb.ctx, null); + } else { + ((VoidCallback) lcb.cb).processResult(lcb.rc, lcb.path, + lcb.ctx); + } + } else { + Packet p = (Packet) event; + int rc = 0; + String clientPath = p.clientPath; + if (p.replyHeader.getErr() != 0) { + rc = p.replyHeader.getErr(); + } + if (p.cb == null) { + LOG.warn("Somehow a null cb got to EventThread!"); + } else if (p.response instanceof ExistsResponse + || p.response instanceof SetDataResponse + || p.response instanceof SetACLResponse) { + StatCallback cb = (StatCallback) p.cb; + if (rc == 0) { + if (p.response instanceof ExistsResponse) { + cb.processResult(rc, clientPath, p.ctx, + ((ExistsResponse) p.response) + .getStat()); + } else if (p.response instanceof SetDataResponse) { + cb.processResult(rc, clientPath, p.ctx, + ((SetDataResponse) p.response) + .getStat()); + } else if (p.response instanceof SetACLResponse) { + cb.processResult(rc, clientPath, p.ctx, + ((SetACLResponse) p.response) + .getStat()); + } + } else { + cb.processResult(rc, clientPath, p.ctx, null); + } + } else if (p.response instanceof GetDataResponse) { + DataCallback cb = (DataCallback) p.cb; + GetDataResponse rsp = (GetDataResponse) p.response; + if (rc == 0) { + cb.processResult(rc, clientPath, p.ctx, rsp + .getData(), rsp.getStat()); + } else { + cb.processResult(rc, clientPath, p.ctx, null, + null); + } + } else if (p.response instanceof GetACLResponse) { + ACLCallback cb = (ACLCallback) p.cb; + GetACLResponse rsp = (GetACLResponse) p.response; + if (rc == 0) { + cb.processResult(rc, clientPath, p.ctx, rsp + .getAcl(), rsp.getStat()); + } else { + cb.processResult(rc, clientPath, p.ctx, null, + null); + } + } else if (p.response instanceof GetChildrenResponse) { + ChildrenCallback cb = (ChildrenCallback) p.cb; + GetChildrenResponse rsp = (GetChildrenResponse) p.response; + if (rc == 0) { + cb.processResult(rc, clientPath, p.ctx, rsp + .getChildren()); + } else { + cb.processResult(rc, clientPath, p.ctx, null); + } + } else if (p.response instanceof GetChildren2Response) { + Children2Callback cb = (Children2Callback) p.cb; + GetChildren2Response rsp = (GetChildren2Response) p.response; + if (rc == 0) { + cb.processResult(rc, clientPath, p.ctx, rsp + .getChildren(), rsp.getStat()); + } else { + cb.processResult(rc, clientPath, p.ctx, null, null); + } + } else if (p.response instanceof CreateResponse) { + StringCallback cb = (StringCallback) p.cb; + CreateResponse rsp = (CreateResponse) p.response; + if (rc == 0) { + cb.processResult(rc, clientPath, p.ctx, + (chrootPath == null + ? rsp.getPath() + : rsp.getPath() + .substring(chrootPath.length()))); + } else { + cb.processResult(rc, clientPath, p.ctx, null); + } + } else if (p.response instanceof Create2Response) { + Create2Callback cb = (Create2Callback) p.cb; + Create2Response rsp = (Create2Response) p.response; + if (rc == 0) { + cb.processResult(rc, clientPath, p.ctx, + (chrootPath == null + ? rsp.getPath() + : rsp.getPath() + .substring(chrootPath.length())), rsp.getStat()); + } else { + cb.processResult(rc, clientPath, p.ctx, null, null); + } + } else if (p.response instanceof MultiResponse) { + MultiCallback cb = (MultiCallback) p.cb; + MultiResponse rsp = (MultiResponse) p.response; + if (rc == 0) { + List results = rsp.getResultList(); + int newRc = rc; + for (OpResult result : results) { + if (result instanceof ErrorResult + && KeeperException.Code.OK.intValue() != (newRc = ((ErrorResult) result) + .getErr())) { + break; + } + } + cb.processResult(newRc, clientPath, p.ctx, results); + } else { + cb.processResult(rc, clientPath, p.ctx, null); + } + } else if (p.cb instanceof VoidCallback) { + VoidCallback cb = (VoidCallback) p.cb; + cb.processResult(rc, clientPath, p.ctx); + } + } + } catch (Throwable t) { + LOG.error("Caught unexpected throwable", t); + } + } + } + + /** + * This class services the outgoing request queue and generates the heart + * beats. It also spawns the ReadThread. + */ + class SendThread extends ZooKeeperThread { + private final static int minPingRwTimeout = 100; + private final static int maxPingRwTimeout = 60000; + private static final String RETRY_CONN_MSG = + ", closing socket connection and attempting reconnect"; + private final ClientCnxnSocket clientCnxnSocket; + private long lastPingSentNs; + private Random r = new Random(System.nanoTime()); + + // TODO: can not name this method getState since Thread.getState() + // already exists + // It would be cleaner to make class SendThread an implementation of + // Runnable + private boolean isFirstConnect = true; + private InetSocketAddress rwServerAddress = null; + private int pingRwTimeout = minPingRwTimeout; + // Set to true if and only if constructor of ZooKeeperSaslClient + // throws a LoginException: see startConnect() below. + private boolean saslLoginFailed = false; + + SendThread(ClientCnxnSocket clientCnxnSocket) { + super(makeThreadName("-SendThread()")); + state = States.CONNECTING; + this.clientCnxnSocket = clientCnxnSocket; + setDaemon(true); + } + + void readResponse(ByteBuffer incomingBuffer) throws IOException { + ByteBufferInputStream bbis = new ByteBufferInputStream( + incomingBuffer); + BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis); + ReplyHeader replyHdr = new ReplyHeader(); + + replyHdr.deserialize(bbia, "header"); + if (replyHdr.getXid() == -2) { + // -2 is the xid for pings + if (LOG.isDebugEnabled()) { + LOG.debug("Got ping response for sessionid: 0x" + + Long.toHexString(sessionId) + + " after " + + ((System.nanoTime() - lastPingSentNs) / 1000000) + + "ms"); + } + return; + } + if (replyHdr.getXid() == -4) { + // -4 is the xid for AuthPacket + if (replyHdr.getErr() == KeeperException.Code.AUTHFAILED.intValue()) { + state = States.AUTH_FAILED; + eventThread.queueEvent(new WatchedEvent(Watcher.Event.EventType.None, + Watcher.Event.KeeperState.AuthFailed, null)); + } + if (LOG.isDebugEnabled()) { + LOG.debug("Got auth sessionid:0x" + + Long.toHexString(sessionId)); + } + return; + } + if (replyHdr.getXid() == -1) { + // -1 means notification + if (LOG.isDebugEnabled()) { + LOG.debug("Got notification sessionid:0x" + + Long.toHexString(sessionId)); + } + WatcherEvent event = new WatcherEvent(); + event.deserialize(bbia, "response"); + + // convert from a server path to a client path + if (chrootPath != null) { + String serverPath = event.getPath(); + if (serverPath.compareTo(chrootPath) == 0) + event.setPath("/"); + else if (serverPath.length() > chrootPath.length()) + event.setPath(serverPath.substring(chrootPath.length())); + else { + LOG.warn("Got server path " + event.getPath() + + " which is too short for chroot path " + + chrootPath); + } + } + + WatchedEvent we = new WatchedEvent(event); + if (LOG.isDebugEnabled()) { + LOG.debug("Got " + we + " for sessionid 0x" + + Long.toHexString(sessionId)); + } + + eventThread.queueEvent(we); + return; + } + + // If SASL authentication is currently in progress, construct and + // send a response packet immediately, rather than queuing a + // response as with other packets. + if (tunnelAuthInProgress()) { + GetSASLRequest request = new GetSASLRequest(); + request.deserialize(bbia, "token"); + zooKeeperSaslClient.respondToServer(request.getToken(), + ClientCnxn.this); + return; + } + + Packet packet; + synchronized (pendingQueue) { + if (pendingQueue.size() == 0) { + throw new IOException("Nothing in the queue, but got " + + replyHdr.getXid()); + } + packet = pendingQueue.remove(); + } + /* + * Since requests are processed in order, we better get a response + * to the first request! + */ + try { + if (packet.requestHeader.getXid() != replyHdr.getXid()) { + packet.replyHeader.setErr( + KeeperException.Code.CONNECTIONLOSS.intValue()); + throw new IOException("Xid out of order. Got Xid " + + replyHdr.getXid() + " with err " + + +replyHdr.getErr() + + " expected Xid " + + packet.requestHeader.getXid() + + " for a packet with details: " + + packet); + } + + packet.replyHeader.setXid(replyHdr.getXid()); + packet.replyHeader.setErr(replyHdr.getErr()); + packet.replyHeader.setZxid(replyHdr.getZxid()); + if (replyHdr.getZxid() > 0) { + lastZxid = replyHdr.getZxid(); + } + if (packet.response != null && replyHdr.getErr() == 0) { + packet.response.deserialize(bbia, "response"); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Reading reply sessionid:0x" + + Long.toHexString(sessionId) + ", packet:: " + packet); + } + } finally { + finishPacket(packet); + } + } + + /** + * Used by ClientCnxnSocket + * + * @return + */ + ZooKeeper.States getZkState() { + return state; + } + + ClientCnxnSocket getClientCnxnSocket() { + return clientCnxnSocket; + } + + /** + * Setup session, previous watches, authentication. + */ + void primeConnection() throws IOException { + LOG.info("Socket connection established, initiating session, client: {}, server: {}", + clientCnxnSocket.getLocalSocketAddress(), + clientCnxnSocket.getRemoteSocketAddress()); + isFirstConnect = false; + long sessId = (seenRwServerBefore) ? sessionId : 0; + ConnectRequest conReq = new ConnectRequest(0, lastZxid, + sessionTimeout, sessId, sessionPasswd); + // We add backwards since we are pushing into the front + // Only send if there's a pending watch + // TODO: here we have the only remaining use of zooKeeper in + // this class. It's to be eliminated! + if (!disableAutoWatchReset) { + List dataWatches = zooKeeper.getDataWatches(); + List existWatches = zooKeeper.getExistWatches(); + List childWatches = zooKeeper.getChildWatches(); + if (!dataWatches.isEmpty() + || !existWatches.isEmpty() || !childWatches.isEmpty()) { + Iterator dataWatchesIter = prependChroot(dataWatches).iterator(); + Iterator existWatchesIter = prependChroot(existWatches).iterator(); + Iterator childWatchesIter = prependChroot(childWatches).iterator(); + long setWatchesLastZxid = lastZxid; + + while (dataWatchesIter.hasNext() + || existWatchesIter.hasNext() || childWatchesIter.hasNext()) { + List dataWatchesBatch = new ArrayList(); + List existWatchesBatch = new ArrayList(); + List childWatchesBatch = new ArrayList(); + int batchLength = 0; + + // Note, we may exceed our max length by a bit when we add the last + // watch in the batch. This isn't ideal, but it makes the code simpler. + while (batchLength < SET_WATCHES_MAX_LENGTH) { + final String watch; + if (dataWatchesIter.hasNext()) { + watch = dataWatchesIter.next(); + dataWatchesBatch.add(watch); + } else if (existWatchesIter.hasNext()) { + watch = existWatchesIter.next(); + existWatchesBatch.add(watch); + } else if (childWatchesIter.hasNext()) { + watch = childWatchesIter.next(); + childWatchesBatch.add(watch); + } else { + break; + } + batchLength += watch.length(); + } + + SetWatches sw = new SetWatches(setWatchesLastZxid, + dataWatchesBatch, + existWatchesBatch, + childWatchesBatch); + RequestHeader header = new RequestHeader(-8, OpCode.setWatches); + Packet packet = new Packet(header, new ReplyHeader(), sw, null, null); + outgoingQueue.addFirst(packet); + } + } + } + + for (AuthData id : authInfo) { + outgoingQueue.addFirst(new Packet(new RequestHeader(-4, + OpCode.auth), null, new AuthPacket(0, id.scheme, + id.data), null, null)); + } + outgoingQueue.addFirst(new Packet(null, null, conReq, + null, null, readOnly)); + clientCnxnSocket.connectionPrimed(); + if (LOG.isDebugEnabled()) { + LOG.debug("Session establishment request sent on " + + clientCnxnSocket.getRemoteSocketAddress()); + } + } + + private List prependChroot(List paths) { + if (chrootPath != null && !paths.isEmpty()) { + for (int i = 0; i < paths.size(); ++i) { + String clientPath = paths.get(i); + String serverPath; + // handle clientPath = "/" + if (clientPath.length() == 1) { + serverPath = chrootPath; + } else { + serverPath = chrootPath + clientPath; + } + paths.set(i, serverPath); + } + } + return paths; + } + + private void sendPing() { + lastPingSentNs = System.nanoTime(); + RequestHeader h = new RequestHeader(-2, OpCode.ping); + queuePacket(h, null, null, null, null, null, null, null, null); + } + + private void startConnect() throws IOException { + if (!isFirstConnect) { + try { + Thread.sleep(r.nextInt(1000)); + } catch (InterruptedException e) { + LOG.warn("Unexpected exception", e); + } + } + state = States.CONNECTING; + + InetSocketAddress addr; + if (rwServerAddress != null) { + addr = rwServerAddress; + rwServerAddress = null; + } else { + addr = hostProvider.next(1000); + } + + String hostPort = addr.getHostString() + ":" + addr.getPort(); + MDC.put("myid", hostPort); + setName(getName().replaceAll("\\(.*\\)", "(" + hostPort + ")")); + if (ZooKeeperSaslClient.isEnabled()) { + try { + String principalUserName = System.getProperty( + ZK_SASL_CLIENT_USERNAME, "zookeeper"); + zooKeeperSaslClient = + new ZooKeeperSaslClient( + principalUserName + "/" + addr.getHostString()); + } catch (LoginException e) { + // An authentication error occurred when the SASL client tried to initialize: + // for Kerberos this means that the client failed to authenticate with the KDC. + // This is different from an authentication error that occurs during communication + // with the Zookeeper server, which is handled below. + LOG.warn("SASL configuration failed: " + e + " Will continue connection to Zookeeper server without " + + "SASL authentication, if Zookeeper server allows it."); + eventThread.queueEvent(new WatchedEvent( + Watcher.Event.EventType.None, + Watcher.Event.KeeperState.AuthFailed, null)); + saslLoginFailed = true; + } + } + logStartConnect(addr); + + clientCnxnSocket.connect(addr); + } + + private void logStartConnect(InetSocketAddress addr) { + String msg = "Opening socket connection to server " + addr; + if (zooKeeperSaslClient != null) { + msg += ". " + zooKeeperSaslClient.getConfigStatus(); + } + LOG.info(msg); + } + + @Override + public void run() { + clientCnxnSocket.introduce(this, sessionId, outgoingQueue); + clientCnxnSocket.updateNow(); + clientCnxnSocket.updateLastSendAndHeard(); + int to; + long lastPingRwServer = Time.currentElapsedTime(); + final int MAX_SEND_PING_INTERVAL = 10000; //10 seconds + while (state.isAlive()) { + try { + if (!clientCnxnSocket.isConnected()) { + // don't re-establish connection if we are closing + if (closing) { + break; + } + startConnect(); + clientCnxnSocket.updateLastSendAndHeard(); + } + + if (state.isConnected()) { + // determine whether we need to send an AuthFailed event. + if (zooKeeperSaslClient != null) { + boolean sendAuthEvent = false; + if (zooKeeperSaslClient.getSaslState() == ZooKeeperSaslClient.SaslState.INITIAL) { + try { + zooKeeperSaslClient.initialize(ClientCnxn.this); + } catch (SaslException e) { + LOG.error("SASL authentication with Zookeeper Quorum member failed: " + e); + state = States.AUTH_FAILED; + sendAuthEvent = true; + } + } + KeeperState authState = zooKeeperSaslClient.getKeeperState(); + if (authState != null) { + if (authState == KeeperState.AuthFailed) { + // An authentication error occurred during authentication with the Zookeeper Server. + state = States.AUTH_FAILED; + sendAuthEvent = true; + } else { + if (authState == KeeperState.SaslAuthenticated) { + sendAuthEvent = true; + } + } + } + + if (sendAuthEvent == true) { + eventThread.queueEvent(new WatchedEvent( + Watcher.Event.EventType.None, + authState, null)); + } + } + to = readTimeout - clientCnxnSocket.getIdleRecv(); + } else { + to = connectTimeout - clientCnxnSocket.getIdleRecv(); + } + + if (to <= 0) { + String warnInfo; + warnInfo = "Client session timed out, have not heard from server in " + + clientCnxnSocket.getIdleRecv() + + "ms" + + " for sessionid 0x" + + Long.toHexString(sessionId); + LOG.warn(warnInfo); + throw new SessionTimeoutException(warnInfo); + } + if (state.isConnected()) { + //1000(1 second) is to prevent race condition missing to send the second ping + //also make sure not to send too many pings when readTimeout is small + int timeToNextPing = readTimeout / 2 - clientCnxnSocket.getIdleSend() - + ((clientCnxnSocket.getIdleSend() > 1000) ? 1000 : 0); + //send a ping request either time is due or no packet sent out within MAX_SEND_PING_INTERVAL + if (timeToNextPing <= 0 || clientCnxnSocket.getIdleSend() > MAX_SEND_PING_INTERVAL) { + sendPing(); + clientCnxnSocket.updateLastSend(); + } else { + if (timeToNextPing < to) { + to = timeToNextPing; + } + } + } + + // If we are in read-only mode, seek for read/write server + if (state == States.CONNECTEDREADONLY) { + long now = Time.currentElapsedTime(); + int idlePingRwServer = (int) (now - lastPingRwServer); + if (idlePingRwServer >= pingRwTimeout) { + lastPingRwServer = now; + idlePingRwServer = 0; + pingRwTimeout = + Math.min(2 * pingRwTimeout, maxPingRwTimeout); + pingRwServer(); + } + to = Math.min(to, pingRwTimeout - idlePingRwServer); + } + + clientCnxnSocket.doTransport(to, pendingQueue, ClientCnxn.this); + } catch (Throwable e) { + if (closing) { + if (LOG.isDebugEnabled()) { + // closing so this is expected + LOG.debug("An exception was thrown while closing send thread for session 0x" + + Long.toHexString(getSessionId()) + + " : " + e.getMessage()); + } + break; + } else { + // this is ugly, you have a better way speak up + if (e instanceof SessionExpiredException) { + LOG.info(e.getMessage() + ", closing socket connection"); + } else if (e instanceof SessionTimeoutException) { + LOG.info(e.getMessage() + RETRY_CONN_MSG); + } else if (e instanceof EndOfStreamException) { + LOG.info(e.getMessage() + RETRY_CONN_MSG); + } else if (e instanceof RWServerFoundException) { + LOG.info(e.getMessage()); + } else { + LOG.warn( + "Session 0x" + + Long.toHexString(getSessionId()) + + " for server " + + clientCnxnSocket.getRemoteSocketAddress() + + ", unexpected error" + + RETRY_CONN_MSG, e); + } + // At this point, there might still be new packets appended to outgoingQueue. + // they will be handled in next connection or cleared up if closed. + cleanup(); + if (state.isAlive()) { + eventThread.queueEvent(new WatchedEvent( + Event.EventType.None, + Event.KeeperState.Disconnected, + null)); + } + clientCnxnSocket.updateNow(); + clientCnxnSocket.updateLastSendAndHeard(); + } + } + } + synchronized (state) { + // When it comes to this point, it guarantees that later queued + // packet to outgoingQueue will be notified of death. + cleanup(); + } + clientCnxnSocket.close(); + if (state.isAlive()) { + eventThread.queueEvent(new WatchedEvent(Event.EventType.None, + Event.KeeperState.Disconnected, null)); + } + ZooTrace.logTraceMessage(LOG, ZooTrace.getTextTraceLevel(), + "SendThread exited loop for session: 0x" + + Long.toHexString(getSessionId())); + } + + private void pingRwServer() throws RWServerFoundException { + String result = null; + InetSocketAddress addr = hostProvider.next(0); + LOG.info("Checking server " + addr + " for being r/w." + + " Timeout " + pingRwTimeout); + + Socket sock = null; + BufferedReader br = null; + try { + sock = new Socket(addr.getHostString(), addr.getPort()); + sock.setSoLinger(false, -1); + sock.setSoTimeout(1000); + sock.setTcpNoDelay(true); + sock.getOutputStream().write("isro".getBytes()); + sock.getOutputStream().flush(); + sock.shutdownOutput(); + br = new BufferedReader( + new InputStreamReader(sock.getInputStream())); + result = br.readLine(); + } catch (ConnectException e) { + // ignore, this just means server is not up + } catch (IOException e) { + // some unexpected error, warn about it + LOG.warn("Exception while seeking for r/w server " + + e.getMessage(), e); + } finally { + if (sock != null) { + try { + sock.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } + if (br != null) { + try { + br.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } + } + + if ("rw".equals(result)) { + pingRwTimeout = minPingRwTimeout; + // save the found address so that it's used during the next + // connection attempt + rwServerAddress = addr; + throw new RWServerFoundException("Majority server found at " + + addr.getHostString() + ":" + addr.getPort()); + } + } + + private void cleanup() { + clientCnxnSocket.cleanup(); + synchronized (pendingQueue) { + for (Packet p : pendingQueue) { + conLossPacket(p); + } + pendingQueue.clear(); + } + // We can't call outgoingQueue.clear() here because + // between iterating and clear up there might be new + // packets added in queuePacket(). + Iterator iter = outgoingQueue.iterator(); + while (iter.hasNext()) { + Packet p = iter.next(); + conLossPacket(p); + iter.remove(); + } + } + + /** + * Callback invoked by the ClientCnxnSocket once a connection has been + * established. + * + * @param _negotiatedSessionTimeout + * @param _sessionId + * @param _sessionPasswd + * @param isRO + * @throws IOException + */ + void onConnected(int _negotiatedSessionTimeout, long _sessionId, + byte[] _sessionPasswd, boolean isRO) throws IOException { + negotiatedSessionTimeout = _negotiatedSessionTimeout; + if (negotiatedSessionTimeout <= 0) { + state = States.CLOSED; + + eventThread.queueEvent(new WatchedEvent( + Watcher.Event.EventType.None, + Watcher.Event.KeeperState.Expired, null)); + eventThread.queueEventOfDeath(); + + String warnInfo; + warnInfo = "Unable to reconnect to ZooKeeper service, session 0x" + + Long.toHexString(sessionId) + " has expired"; + LOG.warn(warnInfo); + throw new SessionExpiredException(warnInfo); + } + if (!readOnly && isRO) { + LOG.error("Read/write client got connected to read-only server"); + } + readTimeout = negotiatedSessionTimeout * 2 / 3; + connectTimeout = negotiatedSessionTimeout / hostProvider.size(); + hostProvider.onConnected(); + sessionId = _sessionId; + sessionPasswd = _sessionPasswd; + state = (isRO) ? + States.CONNECTEDREADONLY : States.CONNECTED; + seenRwServerBefore |= !isRO; + LOG.info("Session establishment complete on server " + + clientCnxnSocket.getRemoteSocketAddress() + + ", sessionid = 0x" + Long.toHexString(sessionId) + + ", negotiated timeout = " + negotiatedSessionTimeout + + (isRO ? " (READ-ONLY mode)" : "")); + KeeperState eventState = (isRO) ? + KeeperState.ConnectedReadOnly : KeeperState.SyncConnected; + eventThread.queueEvent(new WatchedEvent( + Watcher.Event.EventType.None, + eventState, null)); + } + + void close() { + state = States.CLOSED; + clientCnxnSocket.onClosing(); + } + + void testableCloseSocket() throws IOException { + clientCnxnSocket.testableCloseSocket(); + } + + public boolean tunnelAuthInProgress() { + // 1. SASL client is disabled. + if (!ZooKeeperSaslClient.isEnabled()) { + return false; + } + + // 2. SASL login failed. + if (saslLoginFailed == true) { + return false; + } + + // 3. SendThread has not created the authenticating object yet, + // therefore authentication is (at the earliest stage of being) in progress. + if (zooKeeperSaslClient == null) { + return true; + } + + // 4. authenticating object exists, so ask it for its progress. + return zooKeeperSaslClient.clientTunneledAuthenticationInProgress(); + } + + public void sendPacket(Packet p) throws IOException { + clientCnxnSocket.sendPacket(p); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/ClientCnxnSocket.java b/src/java/main/org/apache/zookeeper/ClientCnxnSocket.java new file mode 100644 index 00000000000..3313a8cbf07 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ClientCnxnSocket.java @@ -0,0 +1,216 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.BinaryInputArchive; +import org.apache.zookeeper.ClientCnxn.Packet; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.proto.ConnectResponse; +import org.apache.zookeeper.server.ByteBufferInputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.concurrent.LinkedBlockingDeque; + +/** + * A ClientCnxnSocket does the lower level communication with a socket + * implementation. + * + * This code has been moved out of ClientCnxn so that a Netty implementation can + * be provided as an alternative to the NIO socket code. + * + */ +abstract class ClientCnxnSocket { + private static final Logger LOG = LoggerFactory.getLogger(ClientCnxnSocket.class); + /** + * This buffer is only used to read the length of the incoming message. + */ + protected final ByteBuffer lenBuffer = ByteBuffer.allocateDirect(4); + protected boolean initialized; + /** + * After the length is read, a new incomingBuffer is allocated in + * readLength() to receive the full message. + */ + protected ByteBuffer incomingBuffer = lenBuffer; + protected long sentCount = 0; + protected long recvCount = 0; + protected long lastHeard; + protected long lastSend; + protected long now; + protected ClientCnxn.SendThread sendThread; + protected LinkedBlockingDeque outgoingQueue; + + /** + * The sessionId is only available here for Log and Exception messages. + * Otherwise the socket doesn't need to know it. + */ + protected long sessionId; + + void introduce(ClientCnxn.SendThread sendThread, long sessionId, + LinkedBlockingDeque outgoingQueue) { + this.sendThread = sendThread; + this.sessionId = sessionId; + this.outgoingQueue = outgoingQueue; + } + + void updateNow() { + now = Time.currentElapsedTime(); + } + + int getIdleRecv() { + return (int) (now - lastHeard); + } + + int getIdleSend() { + return (int) (now - lastSend); + } + + long getSentCount() { + return sentCount; + } + + long getRecvCount() { + return recvCount; + } + + void updateLastHeard() { + this.lastHeard = now; + } + + void updateLastSend() { + this.lastSend = now; + } + + void updateLastSendAndHeard() { + this.lastSend = now; + this.lastHeard = now; + } + + protected void readLength() throws IOException { + int len = incomingBuffer.getInt(); + if (len < 0 || len >= ClientCnxn.packetLen) { + throw new IOException("Packet len" + len + " is out of range!"); + } + incomingBuffer = ByteBuffer.allocate(len); + } + + void readConnectResult() throws IOException { + if (LOG.isTraceEnabled()) { + StringBuilder buf = new StringBuilder("0x["); + for (byte b : incomingBuffer.array()) { + buf.append(Integer.toHexString(b) + ","); + } + buf.append("]"); + LOG.trace("readConnectResult " + incomingBuffer.remaining() + " " + + buf.toString()); + } + ByteBufferInputStream bbis = new ByteBufferInputStream(incomingBuffer); + BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis); + ConnectResponse conRsp = new ConnectResponse(); + conRsp.deserialize(bbia, "connect"); + + // read "is read-only" flag + boolean isRO = false; + try { + isRO = bbia.readBool("readOnly"); + } catch (IOException e) { + // this is ok -- just a packet from an old server which + // doesn't contain readOnly field + LOG.warn("Connected to an old server; r-o mode will be unavailable"); + } + + this.sessionId = conRsp.getSessionId(); + sendThread.onConnected(conRsp.getTimeOut(), this.sessionId, + conRsp.getPasswd(), isRO); + } + + abstract boolean isConnected(); + + abstract void connect(InetSocketAddress addr) throws IOException; + + /** + * Returns the address to which the socket is connected. + */ + abstract SocketAddress getRemoteSocketAddress(); + + /** + * Returns the address to which the socket is bound. + */ + abstract SocketAddress getLocalSocketAddress(); + + /** + * Clean up resources for a fresh new socket. + * It's called before reconnect or close. + */ + abstract void cleanup(); + + /** + * new packets are added to outgoingQueue. + */ + abstract void packetAdded(); + + /** + * connState is marked CLOSED and notify ClientCnxnSocket to react. + */ + abstract void onClosing(); + + /** + * Sasl completes. Allows non-priming packgets to be sent. + * Note that this method will only be called if Sasl starts and completes. + */ + abstract void saslCompleted(); + + /** + * being called after ClientCnxn finish PrimeConnection + */ + abstract void connectionPrimed(); + + /** + * Do transportation work: + * - read packets into incomingBuffer. + * - write outgoing queue packets. + * - update relevant timestamp. + * + * @param waitTimeOut timeout in blocking wait. Unit in MilliSecond. + * @param pendingQueue These are the packets that have been sent and + * are waiting for a response. + * @param cnxn + * @throws IOException + * @throws InterruptedException + */ + abstract void doTransport(int waitTimeOut, List pendingQueue, + ClientCnxn cnxn) + throws IOException, InterruptedException; + + /** + * Close the socket. + */ + abstract void testableCloseSocket() throws IOException; + + /** + * Close this client. + */ + abstract void close(); + + /** + * Send Sasl packets directly. + * The Sasl process will send the first (requestHeader == null) packet, + * and then block the doTransport write, + * finally unblock it when finished. + */ + abstract void sendPacket(Packet p) throws IOException; +} diff --git a/src/java/main/org/apache/zookeeper/ClientCnxnSocketNIO.java b/src/java/main/org/apache/zookeeper/ClientCnxnSocketNIO.java new file mode 100644 index 00000000000..4eca70455b1 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ClientCnxnSocketNIO.java @@ -0,0 +1,423 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.zookeeper.ClientCnxn.EndOfStreamException; +import org.apache.zookeeper.ClientCnxn.Packet; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.concurrent.LinkedBlockingDeque; + +public class ClientCnxnSocketNIO extends ClientCnxnSocket { + private static final Logger LOG = LoggerFactory + .getLogger(ClientCnxnSocketNIO.class); + + private final Selector selector = Selector.open(); + + private SelectionKey sockKey; + + private SocketAddress localSocketAddress; + + private SocketAddress remoteSocketAddress; + + ClientCnxnSocketNIO() throws IOException { + super(); + } + + @Override + boolean isConnected() { + return sockKey != null; + } + + /** + * @return true if a packet was received + * @throws InterruptedException + * @throws IOException + */ + void doIO(List pendingQueue, ClientCnxn cnxn) + throws InterruptedException, IOException { + SocketChannel sock = (SocketChannel) sockKey.channel(); + if (sock == null) { + throw new IOException("Socket is null!"); + } + if (sockKey.isReadable()) { + int rc = sock.read(incomingBuffer); + if (rc < 0) { + throw new EndOfStreamException( + "Unable to read additional data from server sessionid 0x" + + Long.toHexString(sessionId) + + ", likely server has closed socket"); + } + if (!incomingBuffer.hasRemaining()) { + incomingBuffer.flip(); + if (incomingBuffer == lenBuffer) { + recvCount++; + readLength(); + } else if (!initialized) { + readConnectResult(); + enableRead(); + if (findSendablePacket(outgoingQueue, + sendThread.tunnelAuthInProgress()) != null) { + // Since SASL authentication has completed (if client is configured to do so), + // outgoing packets waiting in the outgoingQueue can now be sent. + enableWrite(); + } + lenBuffer.clear(); + incomingBuffer = lenBuffer; + updateLastHeard(); + initialized = true; + } else { + sendThread.readResponse(incomingBuffer); + lenBuffer.clear(); + incomingBuffer = lenBuffer; + updateLastHeard(); + } + } + } + if (sockKey.isWritable()) { + Packet p = findSendablePacket(outgoingQueue, + sendThread.tunnelAuthInProgress()); + + if (p != null) { + updateLastSend(); + // If we already started writing p, p.bb will already exist + if (p.bb == null) { + if ((p.requestHeader != null) && + (p.requestHeader.getType() != OpCode.ping) && + (p.requestHeader.getType() != OpCode.auth)) { + p.requestHeader.setXid(cnxn.getXid()); + } + p.createBB(); + } + sock.write(p.bb); + if (!p.bb.hasRemaining()) { + sentCount++; + outgoingQueue.removeFirstOccurrence(p); + if (p.requestHeader != null + && p.requestHeader.getType() != OpCode.ping + && p.requestHeader.getType() != OpCode.auth) { + synchronized (pendingQueue) { + pendingQueue.add(p); + } + } + } + } + if (outgoingQueue.isEmpty()) { + // No more packets to send: turn off write interest flag. + // Will be turned on later by a later call to enableWrite(), + // from within ZooKeeperSaslClient (if client is configured + // to attempt SASL authentication), or in either doIO() or + // in doTransport() if not. + disableWrite(); + } else if (!initialized && p != null && !p.bb.hasRemaining()) { + // On initial connection, write the complete connect request + // packet, but then disable further writes until after + // receiving a successful connection response. If the + // session is expired, then the server sends the expiration + // response and immediately closes its end of the socket. If + // the client is simultaneously writing on its end, then the + // TCP stack may choose to abort with RST, in which case the + // client would never receive the session expired event. See + // http://docs.oracle.com/javase/6/docs/technotes/guides/net/articles/connection_release.html + disableWrite(); + } else { + // Just in case + enableWrite(); + } + } + } + + private Packet findSendablePacket(LinkedBlockingDeque outgoingQueue, + boolean tunneledAuthInProgres) { + if (outgoingQueue.isEmpty()) { + return null; + } + // If we've already starting sending the first packet, we better finish + if (outgoingQueue.getFirst().bb != null || !tunneledAuthInProgres) { + return outgoingQueue.getFirst(); + } + // Since client's authentication with server is in progress, + // send only the null-header packet queued by primeConnection(). + // This packet must be sent so that the SASL authentication process + // can proceed, but all other packets should wait until + // SASL authentication completes. + Iterator iter = outgoingQueue.iterator(); + while (iter.hasNext()) { + Packet p = iter.next(); + if (p.requestHeader == null) { + // We've found the priming-packet. Move it to the beginning of the queue. + iter.remove(); + outgoingQueue.addFirst(p); + return p; + } else { + // Non-priming packet: defer it until later, leaving it in the queue + // until authentication completes. + LOG.debug("deferring non-priming packet {} until SASL authentation completes.", p); + } + } + return null; + } + + @Override + void cleanup() { + if (sockKey != null) { + SocketChannel sock = (SocketChannel) sockKey.channel(); + sockKey.cancel(); + try { + sock.socket().shutdownInput(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Ignoring exception during shutdown input", e); + } + } + try { + sock.socket().shutdownOutput(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Ignoring exception during shutdown output", + e); + } + } + try { + sock.socket().close(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Ignoring exception during socket close", e); + } + } + try { + sock.close(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Ignoring exception during channel close", e); + } + } + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("SendThread interrupted during sleep, ignoring"); + } + } + sockKey = null; + } + + @Override + void close() { + try { + if (LOG.isTraceEnabled()) { + LOG.trace("Doing client selector close"); + } + selector.close(); + if (LOG.isTraceEnabled()) { + LOG.trace("Closed client selector"); + } + } catch (IOException e) { + LOG.warn("Ignoring exception during selector close", e); + } + } + + /** + * create a socket channel. + * @return the created socket channel + * @throws IOException + */ + SocketChannel createSock() throws IOException { + SocketChannel sock; + sock = SocketChannel.open(); + sock.configureBlocking(false); + sock.socket().setSoLinger(false, -1); + sock.socket().setTcpNoDelay(true); + return sock; + } + + /** + * register with the selection and connect + * @param sock the {@link SocketChannel} + * @param addr the address of remote host + * @throws IOException + */ + void registerAndConnect(SocketChannel sock, InetSocketAddress addr) + throws IOException { + sockKey = sock.register(selector, SelectionKey.OP_CONNECT); + boolean immediateConnect = sock.connect(addr); + if (immediateConnect) { + sendThread.primeConnection(); + } + } + + @Override + void connect(InetSocketAddress addr) throws IOException { + SocketChannel sock = createSock(); + try { + registerAndConnect(sock, addr); + } catch (IOException e) { + LOG.error("Unable to open socket to " + addr); + sock.close(); + throw e; + } + initialized = false; + + /* + * Reset incomingBuffer + */ + lenBuffer.clear(); + incomingBuffer = lenBuffer; + } + + /** + * Returns the address to which the socket is connected. + * + * @return ip address of the remote side of the connection or null if not + * connected + */ + @Override + SocketAddress getRemoteSocketAddress() { + return remoteSocketAddress; + } + + /** + * Returns the local address to which the socket is bound. + * + * @return ip address of the remote side of the connection or null if not + * connected + */ + @Override + SocketAddress getLocalSocketAddress() { + return localSocketAddress; + } + + private void updateSocketAddresses() { + Socket socket = ((SocketChannel) sockKey.channel()).socket(); + localSocketAddress = socket.getLocalSocketAddress(); + remoteSocketAddress = socket.getRemoteSocketAddress(); + } + + @Override + void packetAdded() { + wakeupCnxn(); + } + + @Override + void onClosing() { + wakeupCnxn(); + } + + private synchronized void wakeupCnxn() { + selector.wakeup(); + } + + @Override + void doTransport(int waitTimeOut, List pendingQueue, ClientCnxn cnxn) + throws IOException, InterruptedException { + selector.select(waitTimeOut); + Set selected; + synchronized (this) { + selected = selector.selectedKeys(); + } + // Everything below and until we get back to the select is + // non blocking, so time is effectively a constant. That is + // Why we just have to do this once, here + updateNow(); + for (SelectionKey k : selected) { + SocketChannel sc = ((SocketChannel) k.channel()); + if ((k.readyOps() & SelectionKey.OP_CONNECT) != 0) { + if (sc.finishConnect()) { + updateLastSendAndHeard(); + updateSocketAddresses(); + sendThread.primeConnection(); + } + } else if ((k.readyOps() & (SelectionKey.OP_READ | SelectionKey.OP_WRITE)) != 0) { + doIO(pendingQueue, cnxn); + } + } + if (sendThread.getZkState().isConnected()) { + if (findSendablePacket(outgoingQueue, + sendThread.tunnelAuthInProgress()) != null) { + enableWrite(); + } + } + selected.clear(); + } + + //TODO should this be synchronized? + @Override + void testableCloseSocket() throws IOException { + LOG.info("testableCloseSocket() called"); + // sockKey may be concurrently accessed by multiple + // threads. We use tmp here to avoid a race condition + SelectionKey tmp = sockKey; + if (tmp != null) { + ((SocketChannel) tmp.channel()).socket().close(); + } + } + + @Override + void saslCompleted() { + enableWrite(); + } + + synchronized void enableWrite() { + int i = sockKey.interestOps(); + if ((i & SelectionKey.OP_WRITE) == 0) { + sockKey.interestOps(i | SelectionKey.OP_WRITE); + } + } + + private synchronized void disableWrite() { + int i = sockKey.interestOps(); + if ((i & SelectionKey.OP_WRITE) != 0) { + sockKey.interestOps(i & (~SelectionKey.OP_WRITE)); + } + } + + synchronized private void enableRead() { + int i = sockKey.interestOps(); + if ((i & SelectionKey.OP_READ) == 0) { + sockKey.interestOps(i | SelectionKey.OP_READ); + } + } + + @Override + void connectionPrimed() { + sockKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE); + } + + Selector getSelector() { + return selector; + } + + @Override + void sendPacket(Packet p) throws IOException { + SocketChannel sock = (SocketChannel) sockKey.channel(); + if (sock == null) { + throw new IOException("Socket is null!"); + } + p.createBB(); + ByteBuffer pbb = p.bb; + sock.write(pbb); + } +} diff --git a/src/java/main/org/apache/zookeeper/ClientCnxnSocketNetty.java b/src/java/main/org/apache/zookeeper/ClientCnxnSocketNetty.java new file mode 100644 index 00000000000..ee8982fe583 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ClientCnxnSocketNetty.java @@ -0,0 +1,431 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.zookeeper.ClientCnxn.EndOfStreamException; +import org.apache.zookeeper.ClientCnxn.Packet; +import org.apache.zookeeper.common.X509Util; +import org.jboss.netty.bootstrap.ClientBootstrap; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelFutureListener; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.channel.ChannelPipelineFactory; +import org.jboss.netty.channel.ChannelStateEvent; +import org.jboss.netty.channel.Channels; +import org.jboss.netty.channel.ExceptionEvent; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelUpstreamHandler; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +import org.jboss.netty.handler.ssl.SslHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; + +import static org.apache.zookeeper.common.X509Exception.SSLContextException; + +/** + * ClientCnxnSocketNetty implements ClientCnxnSocket abstract methods. + * It's responsible for connecting to server, reading/writing network traffic and + * being a layer between network data and higher level packets. + */ +public class ClientCnxnSocketNetty extends ClientCnxnSocket { + private static final Logger LOG = LoggerFactory.getLogger(ClientCnxnSocketNetty.class); + + ChannelFactory channelFactory = new NioClientSocketChannelFactory( + Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); + Channel channel; + CountDownLatch firstConnect; + ChannelFuture connectFuture; + Lock connectLock = new ReentrantLock(); + AtomicBoolean disconnected = new AtomicBoolean(); + AtomicBoolean needSasl = new AtomicBoolean(); + Semaphore waitSasl = new Semaphore(0); + + /** + * lifecycles diagram: + *

        + * loop: + * - try: + * - - !isConnected() + * - - - connect() + * - - doTransport() + * - catch: + * - - cleanup() + * close() + *

        + * Other non-lifecycle methods are in jeopardy getting a null channel + * when calling in concurrency. We must handle it. + */ + + @Override + boolean isConnected() { + // Assuming that isConnected() is only used to initiate connection, + // not used by some other connection status judgement. + return channel != null; + } + + @Override + void connect(InetSocketAddress addr) throws IOException { + firstConnect = new CountDownLatch(1); + + ClientBootstrap bootstrap = new ClientBootstrap(channelFactory); + + bootstrap.setPipelineFactory(new ZKClientPipelineFactory()); + bootstrap.setOption("soLinger", -1); + bootstrap.setOption("tcpNoDelay", true); + + connectFuture = bootstrap.connect(addr); + connectFuture.addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture channelFuture) throws Exception { + // this lock guarantees that channel won't be assgined after cleanup(). + connectLock.lock(); + try { + if (!channelFuture.isSuccess() || connectFuture == null) { + LOG.info("future isn't success, cause: {}", channelFuture.getCause()); + return; + } + // setup channel, variables, connection, etc. + channel = channelFuture.getChannel(); + + disconnected.set(false); + initialized = false; + lenBuffer.clear(); + incomingBuffer = lenBuffer; + + sendThread.primeConnection(); + updateNow(); + updateLastSendAndHeard(); + + if (sendThread.tunnelAuthInProgress()) { + waitSasl.drainPermits(); + needSasl.set(true); + sendPrimePacket(); + } else { + needSasl.set(false); + } + + // we need to wake up on first connect to avoid timeout. + wakeupCnxn(); + firstConnect.countDown(); + LOG.info("channel is connected: {}", channelFuture.getChannel()); + } finally { + connectLock.unlock(); + } + } + }); + } + + @Override + void cleanup() { + connectLock.lock(); + try { + if (connectFuture != null) { + connectFuture.cancel(); + connectFuture = null; + } + if (channel != null) { + channel.close().awaitUninterruptibly(); + channel = null; + } + } finally { + connectLock.unlock(); + } + Iterator iter = outgoingQueue.iterator(); + while (iter.hasNext()) { + Packet p = iter.next(); + if (p == WakeupPacket.getInstance()) { + iter.remove(); + } + } + } + + @Override + void close() { + channelFactory.releaseExternalResources(); + } + + @Override + void saslCompleted() { + needSasl.set(false); + waitSasl.release(); + } + + @Override + void connectionPrimed() { + } + + @Override + void packetAdded() { + } + + @Override + void onClosing() { + firstConnect.countDown(); + wakeupCnxn(); + LOG.info("channel is told closing"); + } + + private void wakeupCnxn() { + if (needSasl.get()) { + waitSasl.release(); + } + outgoingQueue.add(WakeupPacket.getInstance()); + } + + @Override + void doTransport(int waitTimeOut, + List pendingQueue, + ClientCnxn cnxn) + throws IOException, InterruptedException { + try { + if (!firstConnect.await(waitTimeOut, TimeUnit.MILLISECONDS)) { + return; + } + Packet head = null; + if (needSasl.get()) { + if (!waitSasl.tryAcquire(waitTimeOut, TimeUnit.MILLISECONDS)) { + return; + } + } else { + if ((head = outgoingQueue.poll(waitTimeOut, TimeUnit.MILLISECONDS)) == null) { + return; + } + } + // check if being waken up on closing. + if (!sendThread.getZkState().isAlive()) { + // adding back the patck to notify of failure in conLossPacket(). + addBack(head); + return; + } + // channel disconnection happened + if (disconnected.get()) { + addBack(head); + throw new EndOfStreamException("channel for sessionid 0x" + + Long.toHexString(sessionId) + + " is lost"); + } + if (head != null) { + doWrite(pendingQueue, head, cnxn); + } + } finally { + updateNow(); + } + } + + private void addBack(Packet head) { + if (head != null && head != WakeupPacket.getInstance()) { + outgoingQueue.addFirst(head); + } + } + + private void sendPkt(Packet p) { + // Assuming the packet will be sent out successfully. Because if it fails, + // the channel will close and clean up queues. + p.createBB(); + updateLastSend(); + sentCount++; + channel.write(ChannelBuffers.wrappedBuffer(p.bb)); + } + + private void sendPrimePacket() { + // assuming the first packet is the priming packet. + sendPkt(outgoingQueue.remove()); + } + + /** + * doWrite handles writing the packets from outgoingQueue via network to server. + */ + private void doWrite(List pendingQueue, Packet p, ClientCnxn cnxn) { + updateNow(); + while (true) { + if (p != WakeupPacket.getInstance()) { + if ((p.requestHeader != null) && + (p.requestHeader.getType() != ZooDefs.OpCode.ping) && + (p.requestHeader.getType() != ZooDefs.OpCode.auth)) { + p.requestHeader.setXid(cnxn.getXid()); + synchronized (pendingQueue) { + pendingQueue.add(p); + } + } + sendPkt(p); + } + if (outgoingQueue.isEmpty()) { + break; + } + p = outgoingQueue.remove(); + } + } + + @Override + void sendPacket(ClientCnxn.Packet p) throws IOException { + if (channel == null) { + throw new IOException("channel has been closed"); + } + sendPkt(p); + } + + @Override + SocketAddress getRemoteSocketAddress() { + Channel copiedChanRef = channel; + return (copiedChanRef == null) ? null : copiedChanRef.getRemoteAddress(); + } + + @Override + SocketAddress getLocalSocketAddress() { + Channel copiedChanRef = channel; + return (copiedChanRef == null) ? null : copiedChanRef.getLocalAddress(); + } + + @Override + void testableCloseSocket() throws IOException { + Channel copiedChanRef = channel; + if (copiedChanRef != null) { + copiedChanRef.disconnect().awaitUninterruptibly(); + } + } + + + // *************** CientCnxnSocketNetty ****************** + private static class WakeupPacket { + private static final Packet instance = new Packet(null, null, null, null, null); + + protected WakeupPacket() { + // Exists only to defeat instantiation. + } + + public static Packet getInstance() { + return instance; + } + } + + /** + * ZKClientPipelineFactory is the netty pipeline factory for this netty + * connection implementation. + */ + private class ZKClientPipelineFactory implements ChannelPipelineFactory { + private SSLContext sslContext = null; + private SSLEngine sslEngine = null; + + @Override + public ChannelPipeline getPipeline() throws Exception { + ChannelPipeline pipeline = Channels.pipeline(); + if (Boolean.getBoolean(ZooKeeper.SECURE_CLIENT)) { + initSSL(pipeline); + } + pipeline.addLast("handler", new ZKClientHandler()); + return pipeline; + } + + // The synchronized is to prevent the race on shared variable "sslEngine". + // Basically we only need to create it once. + private synchronized void initSSL(ChannelPipeline pipeline) throws SSLContextException { + if (sslContext == null || sslEngine == null) { + sslContext = X509Util.createSSLContext(); + sslEngine = sslContext.createSSLEngine(); + sslEngine.setUseClientMode(true); + } + pipeline.addLast("ssl", new SslHandler(sslEngine)); + LOG.info("SSL handler added for channel: {}", pipeline.getChannel()); + } + } + + /** + * ZKClientHandler is the netty handler that sits in netty upstream last + * place. It mainly handles read traffic and helps synchronize connection state. + */ + private class ZKClientHandler extends SimpleChannelUpstreamHandler { + AtomicBoolean channelClosed = new AtomicBoolean(false); + + @Override + public void channelDisconnected(ChannelHandlerContext ctx, + ChannelStateEvent e) throws Exception { + LOG.info("channel is disconnected: {}", ctx.getChannel()); + cleanup(); + } + + /** + * netty handler has encountered problems. We are cleaning it up and tell outside to close + * the channel/connection. + */ + private void cleanup() { + if (!channelClosed.compareAndSet(false, true)) { + return; + } + disconnected.set(true); + onClosing(); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, + MessageEvent e) throws Exception { + updateNow(); + ChannelBuffer buf = (ChannelBuffer) e.getMessage(); + while (buf.readable()) { + if (incomingBuffer.remaining() > buf.readableBytes()) { + int newLimit = incomingBuffer.position() + + buf.readableBytes(); + incomingBuffer.limit(newLimit); + } + buf.readBytes(incomingBuffer); + incomingBuffer.limit(incomingBuffer.capacity()); + + if (!incomingBuffer.hasRemaining()) { + incomingBuffer.flip(); + if (incomingBuffer == lenBuffer) { + recvCount++; + readLength(); + } else if (!initialized) { + readConnectResult(); + lenBuffer.clear(); + incomingBuffer = lenBuffer; + initialized = true; + updateLastHeard(); + } else { + sendThread.readResponse(incomingBuffer); + lenBuffer.clear(); + incomingBuffer = lenBuffer; + updateLastHeard(); + } + } + } + wakeupCnxn(); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, + ExceptionEvent e) throws Exception { + LOG.warn("Exception caught: {}", e, e.getCause()); + cleanup(); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/ClientWatchManager.java b/src/java/main/org/apache/zookeeper/ClientWatchManager.java new file mode 100644 index 00000000000..17af69894a7 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ClientWatchManager.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import java.util.Set; + +/** + */ +public interface ClientWatchManager { + /** + * Return a set of watchers that should be notified of the event. The + * manager must not notify the watcher(s), however it will update it's + * internal structure as if the watches had triggered. The intent being + * that the callee is now responsible for notifying the watchers of the + * event, possibly at some later time. + * + * @param state event state + * @param type event type + * @param path event path + * @return may be empty set but must not be null + */ + public Set materialize(Watcher.Event.KeeperState state, + Watcher.Event.EventType type, String path); +} diff --git a/src/java/main/org/apache/zookeeper/CreateMode.java b/src/java/main/org/apache/zookeeper/CreateMode.java new file mode 100644 index 00000000000..3a5308db9fe --- /dev/null +++ b/src/java/main/org/apache/zookeeper/CreateMode.java @@ -0,0 +1,132 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/*** + * CreateMode value determines how the znode is created on ZooKeeper. + */ +public enum CreateMode { + + /** + * The znode will not be automatically deleted upon client's disconnect. + */ + PERSISTENT(0, false, false, false), + /** + * The znode will not be automatically deleted upon client's disconnect, + * and its name will be appended with a monotonically increasing number. + */ + PERSISTENT_SEQUENTIAL(2, false, true, false), + /** + * The znode will be deleted upon the client's disconnect. + */ + EPHEMERAL(1, true, false, false), + /** + * The znode will be deleted upon the client's disconnect, and its name + * will be appended with a monotonically increasing number. + */ + EPHEMERAL_SEQUENTIAL(3, true, true, false), + /** + * The znode will be a container node. Container + * nodes are special purpose nodes useful for recipes such as leader, lock, + * etc. When the last child of a container is deleted, the container becomes + * a candidate to be deleted by the server at some point in the future. + * Given this property, you should be prepared to get + * {@link org.apache.zookeeper.KeeperException.NoNodeException} + * when creating children inside of this container node. + */ + CONTAINER(4, false, false, true); + + private static final Logger LOG = LoggerFactory.getLogger(CreateMode.class); + private final boolean isContainer; + private boolean ephemeral; + private boolean sequential; + private int flag; + + CreateMode(int flag, boolean ephemeral, boolean sequential, + boolean isContainer) { + this.flag = flag; + this.ephemeral = ephemeral; + this.sequential = sequential; + this.isContainer = isContainer; + } + + /** + * Map an integer value to a CreateMode value + */ + static public CreateMode fromFlag(int flag) throws KeeperException { + switch (flag) { + case 0: + return CreateMode.PERSISTENT; + + case 1: + return CreateMode.EPHEMERAL; + + case 2: + return CreateMode.PERSISTENT_SEQUENTIAL; + + case 3: + return CreateMode.EPHEMERAL_SEQUENTIAL; + + case 4: + return CreateMode.CONTAINER; + + default: + String errMsg = "Received an invalid flag value: " + flag + + " to convert to a CreateMode"; + LOG.error(errMsg); + throw new KeeperException.BadArgumentsException(errMsg); + } + } + + /** + * Map an integer value to a CreateMode value + */ + static public CreateMode fromFlag(int flag, CreateMode defaultMode) { + switch (flag) { + case 0: + return CreateMode.PERSISTENT; + + case 1: + return CreateMode.EPHEMERAL; + + case 2: + return CreateMode.PERSISTENT_SEQUENTIAL; + + case 3: + return CreateMode.EPHEMERAL_SEQUENTIAL; + + case 4: + return CreateMode.CONTAINER; + + default: + return defaultMode; + } + } + + public boolean isEphemeral() { + return ephemeral; + } + + public boolean isSequential() { + return sequential; + } + + public boolean isContainer() { + return isContainer; + } + + public int toFlag() { + return flag; + } +} diff --git a/src/java/main/org/apache/zookeeper/Environment.java b/src/java/main/org/apache/zookeeper/Environment.java new file mode 100644 index 00000000000..c6d40555198 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Environment.java @@ -0,0 +1,112 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.slf4j.Logger; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; + +/** + * Provide insight into the runtime environment. + * + */ +public class Environment { + public static final String JAAS_CONF_KEY = "java.security.auth.login.config"; + + private static void put(ArrayList l, String k, String v) { + l.add(new Entry(k, v)); + } + + public static List list() { + ArrayList l = new ArrayList(); + put(l, "zookeeper.version", Version.getFullVersion()); + + try { + put(l, "host.name", + InetAddress.getLocalHost().getCanonicalHostName()); + } catch (UnknownHostException e) { + put(l, "host.name", ""); + } + + put(l, "java.version", + System.getProperty("java.version", "")); + put(l, "java.vendor", + System.getProperty("java.vendor", "")); + put(l, "java.home", + System.getProperty("java.home", "")); + put(l, "java.class.path", + System.getProperty("java.class.path", "")); + put(l, "java.library.path", + System.getProperty("java.library.path", "")); + put(l, "java.io.tmpdir", + System.getProperty("java.io.tmpdir", "")); + put(l, "java.compiler", + System.getProperty("java.compiler", "")); + put(l, "os.name", + System.getProperty("os.name", "")); + put(l, "os.arch", + System.getProperty("os.arch", "")); + put(l, "os.version", + System.getProperty("os.version", "")); + put(l, "user.name", + System.getProperty("user.name", "")); + put(l, "user.home", + System.getProperty("user.home", "")); + put(l, "user.dir", + System.getProperty("user.dir", "")); + + // Get memory information. + Runtime runtime = Runtime.getRuntime(); + int mb = 1024 * 1024; + put(l, "os.memory.free", + Long.toString(runtime.freeMemory() / mb) + "MB"); + put(l, "os.memory.max", + Long.toString(runtime.maxMemory() / mb) + "MB"); + put(l, "os.memory.total", + Long.toString(runtime.totalMemory() / mb) + "MB"); + + return l; + } + + public static void logEnv(String msg, Logger log) { + List env = Environment.list(); + for (Entry e : env) { + log.info(msg + e.toString()); + } + } + + public static class Entry { + private String k; + private String v; + + public Entry(String k, String v) { + this.k = k; + this.v = v; + } + + public String getKey() { + return k; + } + + public String getValue() { + return v; + } + + @Override + public String toString() { + return k + "=" + v; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java b/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java new file mode 100644 index 00000000000..1c7152fb00c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import jline.console.completer.Completer; + +import java.util.Collections; +import java.util.List; + +class JLineZNodeCompleter implements Completer { + private ZooKeeper zk; + + public JLineZNodeCompleter(ZooKeeper zk) { + this.zk = zk; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + public int complete(String buffer, int cursor, List candidates) { + // Guarantee that the final token is the one we're expanding + buffer = buffer.substring(0, cursor); + String token = ""; + if (!buffer.endsWith(" ")) { + String[] tokens = buffer.split(" "); + if (tokens.length != 0) { + token = tokens[tokens.length - 1]; + } + } + + if (token.startsWith("/")) { + return completeZNode(buffer, token, candidates); + } + return completeCommand(buffer, token, candidates); + } + + private int completeCommand(String buffer, String token, + List candidates) { + for (String cmd : ZooKeeperMain.getCommands()) { + if (cmd.startsWith(token)) { + candidates.add(cmd); + } + } + return buffer.lastIndexOf(" ") + 1; + } + + private int completeZNode(String buffer, String token, + List candidates) { + String path = token; + int idx = path.lastIndexOf("/") + 1; + String prefix = path.substring(idx); + try { + // Only the root path can end in a /, so strip it off every other prefix + String dir = idx == 1 ? "/" : path.substring(0, idx - 1); + List children = zk.getChildren(dir, false); + for (String child : children) { + if (child.startsWith(prefix)) { + candidates.add(child); + } + } + } catch (InterruptedException e) { + return 0; + } catch (KeeperException e) { + return 0; + } + Collections.sort(candidates); + return candidates.size() == 0 ? buffer.length() : buffer.lastIndexOf("/") + 1; + } +} diff --git a/src/java/main/org/apache/zookeeper/KeeperException.java b/src/java/main/org/apache/zookeeper/KeeperException.java new file mode 100644 index 00000000000..6feb2d8c240 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/KeeperException.java @@ -0,0 +1,799 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("serial") +public abstract class KeeperException extends Exception { + /** + * All multi-requests that result in an exception retain the results + * here so that it is possible to examine the problems in the catch + * scope. Non-multi requests will get a null if they try to access + * these results. + */ + private List results; + private Code code; + private String path; + + public KeeperException(Code code) { + this.code = code; + } + + KeeperException(Code code, String path) { + this.code = code; + this.path = path; + } + + /** + * All non-specific keeper exceptions should be constructed via + * this factory method in order to guarantee consistency in error + * codes and such. If you know the error code, then you should + * construct the special purpose exception directly. That will + * allow you to have the most specific possible declarations of + * what exceptions might actually be thrown. + * + * @param code The error code. + * @param path The ZooKeeper path being operated on. + * @return The specialized exception, presumably to be thrown by + * the caller. + */ + public static KeeperException create(Code code, String path) { + KeeperException r = create(code); + r.path = path; + return r; + } + + /** + * @deprecated deprecated in 3.1.0, use {@link #create(Code, String)} + * instead + */ + @Deprecated + public static KeeperException create(int code, String path) { + KeeperException r = create(Code.get(code)); + r.path = path; + return r; + } + + /** + * @deprecated deprecated in 3.1.0, use {@link #create(Code)} + * instead + */ + @Deprecated + public static KeeperException create(int code) { + return create(Code.get(code)); + } + + /** + * All non-specific keeper exceptions should be constructed via + * this factory method in order to guarantee consistency in error + * codes and such. If you know the error code, then you should + * construct the special purpose exception directly. That will + * allow you to have the most specific possible declarations of + * what exceptions might actually be thrown. + * + * @param code The error code of your new exception. This will + * also determine the specific type of the exception that is + * returned. + * @return The specialized exception, presumably to be thrown by + * the caller. + */ + public static KeeperException create(Code code) { + switch (code) { + case SYSTEMERROR: + return new SystemErrorException(); + case RUNTIMEINCONSISTENCY: + return new RuntimeInconsistencyException(); + case DATAINCONSISTENCY: + return new DataInconsistencyException(); + case CONNECTIONLOSS: + return new ConnectionLossException(); + case MARSHALLINGERROR: + return new MarshallingErrorException(); + case UNIMPLEMENTED: + return new UnimplementedException(); + case OPERATIONTIMEOUT: + return new OperationTimeoutException(); + case NEWCONFIGNOQUORUM: + return new NewConfigNoQuorum(); + case RECONFIGINPROGRESS: + return new ReconfigInProgress(); + case BADARGUMENTS: + return new BadArgumentsException(); + case APIERROR: + return new APIErrorException(); + case NONODE: + return new NoNodeException(); + case NOAUTH: + return new NoAuthException(); + case BADVERSION: + return new BadVersionException(); + case NOCHILDRENFOREPHEMERALS: + return new NoChildrenForEphemeralsException(); + case NODEEXISTS: + return new NodeExistsException(); + case INVALIDACL: + return new InvalidACLException(); + case AUTHFAILED: + return new AuthFailedException(); + case NOTEMPTY: + return new NotEmptyException(); + case SESSIONEXPIRED: + return new SessionExpiredException(); + case INVALIDCALLBACK: + return new InvalidCallbackException(); + case SESSIONMOVED: + return new SessionMovedException(); + case NOTREADONLY: + return new NotReadOnlyException(); + case EPHEMERALONLOCALSESSION: + return new EphemeralOnLocalSessionException(); + case NOWATCHER: + return new NoWatcherException(); + case OK: + default: + throw new IllegalArgumentException("Invalid exception code"); + } + } + + static String getCodeMessage(Code code) { + switch (code) { + case OK: + return "ok"; + case SYSTEMERROR: + return "SystemError"; + case RUNTIMEINCONSISTENCY: + return "RuntimeInconsistency"; + case DATAINCONSISTENCY: + return "DataInconsistency"; + case CONNECTIONLOSS: + return "ConnectionLoss"; + case MARSHALLINGERROR: + return "MarshallingError"; + case NEWCONFIGNOQUORUM: + return "NewConfigNoQuorum"; + case RECONFIGINPROGRESS: + return "ReconfigInProgress"; + case UNIMPLEMENTED: + return "Unimplemented"; + case OPERATIONTIMEOUT: + return "OperationTimeout"; + case BADARGUMENTS: + return "BadArguments"; + case APIERROR: + return "APIError"; + case NONODE: + return "NoNode"; + case NOAUTH: + return "NoAuth"; + case BADVERSION: + return "BadVersion"; + case NOCHILDRENFOREPHEMERALS: + return "NoChildrenForEphemerals"; + case NODEEXISTS: + return "NodeExists"; + case INVALIDACL: + return "InvalidACL"; + case AUTHFAILED: + return "AuthFailed"; + case NOTEMPTY: + return "Directory not empty"; + case SESSIONEXPIRED: + return "Session expired"; + case INVALIDCALLBACK: + return "Invalid callback"; + case SESSIONMOVED: + return "Session moved"; + case NOTREADONLY: + return "Not a read-only call"; + case EPHEMERALONLOCALSESSION: + return "Ephemeral node on local session"; + case NOWATCHER: + return "No such watcher"; + default: + return "Unknown error " + code; + } + } + + /** + * Read the error code for this exception + * @return the error code for this exception + * @deprecated deprecated in 3.1.0, use {@link #code()} instead + */ + @Deprecated + public int getCode() { + return code.code; + } + + /** + * Set the code for this exception + * @param code error code + * @deprecated deprecated in 3.1.0, exceptions should be immutable, this + * method should not be used + */ + @Deprecated + public void setCode(int code) { + this.code = Code.get(code); + } + + /** + * Read the error Code for this exception + * @return the error Code for this exception + */ + public Code code() { + return code; + } + + /** + * Read the path for this exception + * @return the path associated with this error, null if none + */ + public String getPath() { + return path; + } + + @Override + public String getMessage() { + if (path == null) { + return "KeeperErrorCode = " + getCodeMessage(code); + } + return "KeeperErrorCode = " + getCodeMessage(code) + " for " + path; + } + + void setMultiResults(List results) { + this.results = results; + } + + /** + * If this exception was thrown by a multi-request then the (partial) results + * and error codes can be retrieved using this getter. + * @return A copy of the list of results from the operations in the multi-request. + * + * @since 3.4.0 + * + */ + public List getResults() { + return results != null ? new ArrayList(results) : null; + } + + /** Codes which represent the various KeeperException + * types. This enum replaces the deprecated earlier static final int + * constants. The old, deprecated, values are in "camel case" while the new + * enum values are in all CAPS. + */ + public static enum Code implements CodeDeprecated { + /** Everything is OK */ + OK(Ok), + + /** System and server-side errors. + * This is never thrown by the server, it shouldn't be used other than + * to indicate a range. Specifically error codes greater than this + * value, but lesser than {@link #APIERROR}, are system errors. + */ + SYSTEMERROR(SystemError), + + /** A runtime inconsistency was found */ + RUNTIMEINCONSISTENCY(RuntimeInconsistency), + /** A data inconsistency was found */ + DATAINCONSISTENCY(DataInconsistency), + /** Connection to the server has been lost */ + CONNECTIONLOSS(ConnectionLoss), + /** Error while marshalling or unmarshalling data */ + MARSHALLINGERROR(MarshallingError), + /** Operation is unimplemented */ + UNIMPLEMENTED(Unimplemented), + /** Operation timeout */ + OPERATIONTIMEOUT(OperationTimeout), + /** Invalid arguments */ + BADARGUMENTS(BadArguments), + /** No quorum of new config is connected and up-to-date with the leader of last commmitted config - try + * invoking reconfiguration after new servers are connected and synced */ + NEWCONFIGNOQUORUM(NewConfigNoQuorum), + /** Another reconfiguration is in progress -- concurrent reconfigs not supported (yet) */ + RECONFIGINPROGRESS(ReconfigInProgress), + /** Unknown session (internal server use only) */ + UNKNOWNSESSION(UnknownSession), + + /** API errors. + * This is never thrown by the server, it shouldn't be used other than + * to indicate a range. Specifically error codes greater than this + * value are API errors (while values less than this indicate a + * {@link #SYSTEMERROR}). + */ + APIERROR(APIError), + + /** Node does not exist */ + NONODE(NoNode), + /** Not authenticated */ + NOAUTH(NoAuth), + /** Version conflict + In case of reconfiguration: reconfig requested from config version X but last seen config has a different version Y */ + BADVERSION(BadVersion), + /** Ephemeral nodes may not have children */ + NOCHILDRENFOREPHEMERALS(NoChildrenForEphemerals), + /** The node already exists */ + NODEEXISTS(NodeExists), + /** The node has children */ + NOTEMPTY(NotEmpty), + /** The session has been expired by the server */ + SESSIONEXPIRED(SessionExpired), + /** Invalid callback specified */ + INVALIDCALLBACK(InvalidCallback), + /** Invalid ACL specified */ + INVALIDACL(InvalidACL), + /** Client authentication failed */ + AUTHFAILED(AuthFailed), + /** Session moved to another server, so operation is ignored */ + SESSIONMOVED(-118), + /** State-changing request is passed to read-only server */ + NOTREADONLY(-119), + /** Attempt to create ephemeral node on a local session */ + EPHEMERALONLOCALSESSION(EphemeralOnLocalSession), + /** Attempts to remove a non-existing watcher */ + NOWATCHER(-121); + + private static final Map lookup + = new HashMap(); + + static { + for (Code c : EnumSet.allOf(Code.class)) + lookup.put(c.code, c); + } + + private final int code; + + Code(int code) { + this.code = code; + } + + /** + * Get the Code value for a particular integer error code + * @param code int error code + * @return Code value corresponding to specified int code, or null + */ + public static Code get(int code) { + return lookup.get(code); + } + + /** + * Get the int value for a particular Code. + * @return error code as integer + */ + public int intValue() { + return code; + } + } + + /** This interface contains the original static final int constants + * which have now been replaced with an enumeration in Code. Do not + * reference this class directly, if necessary (legacy code) continue + * to access the constants through Code. + * Note: an interface is used here due to the fact that enums cannot + * reference constants defined within the same enum as said constants + * are considered initialized _after_ the enum itself. By using an + * interface as a super type this allows the deprecated constants to + * be initialized first and referenced when constructing the enums. I + * didn't want to have constants declared twice. This + * interface should be private, but it's declared public to enable + * javadoc to include in the user API spec. + */ + @Deprecated + public interface CodeDeprecated { + /** + * @deprecated deprecated in 3.1.0, use {@link Code#OK} instead + */ + @Deprecated + public static final int Ok = 0; + + /** + * @deprecated deprecated in 3.1.0, use {@link Code#SYSTEMERROR} instead + */ + @Deprecated + public static final int SystemError = -1; + /** + * @deprecated deprecated in 3.1.0, use + * {@link Code#RUNTIMEINCONSISTENCY} instead + */ + @Deprecated + public static final int RuntimeInconsistency = -2; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#DATAINCONSISTENCY} + * instead + */ + @Deprecated + public static final int DataInconsistency = -3; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#CONNECTIONLOSS} + * instead + */ + @Deprecated + public static final int ConnectionLoss = -4; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#MARSHALLINGERROR} + * instead + */ + @Deprecated + public static final int MarshallingError = -5; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#UNIMPLEMENTED} + * instead + */ + @Deprecated + public static final int Unimplemented = -6; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#OPERATIONTIMEOUT} + * instead + */ + @Deprecated + public static final int OperationTimeout = -7; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#BADARGUMENTS} + * instead + */ + @Deprecated + public static final int BadArguments = -8; + + @Deprecated + public static final int UnknownSession = -12; + + /** + * @deprecated deprecated in 3.1.0, use {@link Code#NEWCONFIGNOQUORUM} + * instead + */ + @Deprecated + public static final int NewConfigNoQuorum = -13; + + /** + * @deprecated deprecated in 3.1.0, use {@link Code#RECONFIGINPROGRESS} + * instead + */ + @Deprecated + public static final int ReconfigInProgress = -14; + + /** + * @deprecated deprecated in 3.1.0, use {@link Code#APIERROR} instead + */ + @Deprecated + public static final int APIError = -100; + + /** + * @deprecated deprecated in 3.1.0, use {@link Code#NONODE} instead + */ + @Deprecated + public static final int NoNode = -101; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#NOAUTH} instead + */ + @Deprecated + public static final int NoAuth = -102; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#BADVERSION} instead + */ + @Deprecated + public static final int BadVersion = -103; + /** + * @deprecated deprecated in 3.1.0, use + * {@link Code#NOCHILDRENFOREPHEMERALS} + * instead + */ + @Deprecated + public static final int NoChildrenForEphemerals = -108; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#NODEEXISTS} instead + */ + @Deprecated + public static final int NodeExists = -110; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#NOTEMPTY} instead + */ + @Deprecated + public static final int NotEmpty = -111; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#SESSIONEXPIRED} instead + */ + @Deprecated + public static final int SessionExpired = -112; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#INVALIDCALLBACK} + * instead + */ + @Deprecated + public static final int InvalidCallback = -113; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#INVALIDACL} instead + */ + @Deprecated + public static final int InvalidACL = -114; + /** + * @deprecated deprecated in 3.1.0, use {@link Code#AUTHFAILED} instead + */ + @Deprecated + public static final int AuthFailed = -115; + + // This value will be used directly in {@link CODE#SESSIONMOVED} + // public static final int SessionMoved = -118; + + @Deprecated + public static final int EphemeralOnLocalSession = -120; + + } + + /** + * @see Code#APIERROR + */ + public static class APIErrorException extends KeeperException { + public APIErrorException() { + super(Code.APIERROR); + } + } + + /** + * @see Code#AUTHFAILED + */ + public static class AuthFailedException extends KeeperException { + public AuthFailedException() { + super(Code.AUTHFAILED); + } + } + + /** + * @see Code#BADARGUMENTS + */ + public static class BadArgumentsException extends KeeperException { + public BadArgumentsException() { + super(Code.BADARGUMENTS); + } + + public BadArgumentsException(String path) { + super(Code.BADARGUMENTS, path); + } + } + + /** + * @see Code#BADVERSION + */ + public static class BadVersionException extends KeeperException { + public BadVersionException() { + super(Code.BADVERSION); + } + + public BadVersionException(String path) { + super(Code.BADVERSION, path); + } + } + + /** + * @see Code#CONNECTIONLOSS + */ + public static class ConnectionLossException extends KeeperException { + public ConnectionLossException() { + super(Code.CONNECTIONLOSS); + } + } + + /** + * @see Code#DATAINCONSISTENCY + */ + public static class DataInconsistencyException extends KeeperException { + public DataInconsistencyException() { + super(Code.DATAINCONSISTENCY); + } + } + + /** + * @see Code#INVALIDACL + */ + public static class InvalidACLException extends KeeperException { + public InvalidACLException() { + super(Code.INVALIDACL); + } + + public InvalidACLException(String path) { + super(Code.INVALIDACL, path); + } + } + + /** + * @see Code#INVALIDCALLBACK + */ + public static class InvalidCallbackException extends KeeperException { + public InvalidCallbackException() { + super(Code.INVALIDCALLBACK); + } + } + + /** + * @see Code#MARSHALLINGERROR + */ + public static class MarshallingErrorException extends KeeperException { + public MarshallingErrorException() { + super(Code.MARSHALLINGERROR); + } + } + + /** + * @see Code#NOAUTH + */ + public static class NoAuthException extends KeeperException { + public NoAuthException() { + super(Code.NOAUTH); + } + } + + /** + * @see Code#NEWCONFIGNOQUORUM + */ + public static class NewConfigNoQuorum extends KeeperException { + public NewConfigNoQuorum() { + super(Code.NEWCONFIGNOQUORUM); + } + } + + /** + * @see Code#RECONFIGINPROGRESS + */ + public static class ReconfigInProgress extends KeeperException { + public ReconfigInProgress() { + super(Code.RECONFIGINPROGRESS); + } + } + + /** + * @see Code#NOCHILDRENFOREPHEMERALS + */ + public static class NoChildrenForEphemeralsException extends KeeperException { + public NoChildrenForEphemeralsException() { + super(Code.NOCHILDRENFOREPHEMERALS); + } + + public NoChildrenForEphemeralsException(String path) { + super(Code.NOCHILDRENFOREPHEMERALS, path); + } + } + + /** + * @see Code#NODEEXISTS + */ + public static class NodeExistsException extends KeeperException { + public NodeExistsException() { + super(Code.NODEEXISTS); + } + + public NodeExistsException(String path) { + super(Code.NODEEXISTS, path); + } + } + + /** + * @see Code#NONODE + */ + public static class NoNodeException extends KeeperException { + public NoNodeException() { + super(Code.NONODE); + } + + public NoNodeException(String path) { + super(Code.NONODE, path); + } + } + + /** + * @see Code#NOTEMPTY + */ + public static class NotEmptyException extends KeeperException { + public NotEmptyException() { + super(Code.NOTEMPTY); + } + + public NotEmptyException(String path) { + super(Code.NOTEMPTY, path); + } + } + + /** + * @see Code#OPERATIONTIMEOUT + */ + public static class OperationTimeoutException extends KeeperException { + public OperationTimeoutException() { + super(Code.OPERATIONTIMEOUT); + } + } + + /** + * @see Code#RUNTIMEINCONSISTENCY + */ + public static class RuntimeInconsistencyException extends KeeperException { + public RuntimeInconsistencyException() { + super(Code.RUNTIMEINCONSISTENCY); + } + } + + /** + * @see Code#SESSIONEXPIRED + */ + public static class SessionExpiredException extends KeeperException { + public SessionExpiredException() { + super(Code.SESSIONEXPIRED); + } + } + + /** + * @see Code#UNKNOWNSESSION + */ + public static class UnknownSessionException extends KeeperException { + public UnknownSessionException() { + super(Code.UNKNOWNSESSION); + } + } + + /** + * @see Code#SESSIONMOVED + */ + public static class SessionMovedException extends KeeperException { + public SessionMovedException() { + super(Code.SESSIONMOVED); + } + } + + /** + * @see Code#NOTREADONLY + */ + public static class NotReadOnlyException extends KeeperException { + public NotReadOnlyException() { + super(Code.NOTREADONLY); + } + } + + /** + * @see Code#EPHEMERALONLOCALSESSION + */ + public static class EphemeralOnLocalSessionException extends KeeperException { + public EphemeralOnLocalSessionException() { + super(Code.EPHEMERALONLOCALSESSION); + } + } + + /** + * @see Code#SYSTEMERROR + */ + public static class SystemErrorException extends KeeperException { + public SystemErrorException() { + super(Code.SYSTEMERROR); + } + } + + /** + * @see Code#UNIMPLEMENTED + */ + public static class UnimplementedException extends KeeperException { + public UnimplementedException() { + super(Code.UNIMPLEMENTED); + } + } + + /** + * @see Code#NOWATCHER + */ + public static class NoWatcherException extends KeeperException { + public NoWatcherException() { + super(Code.NOWATCHER); + } + + public NoWatcherException(String path) { + super(Code.NOWATCHER, path); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/Login.java b/src/java/main/org/apache/zookeeper/Login.java new file mode 100644 index 00000000000..fbe8e997eed --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Login.java @@ -0,0 +1,390 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +/** + * This class is responsible for refreshing Kerberos credentials for + * logins for both Zookeeper client and server. + * See ZooKeeperSaslServer for server-side usage. + * See ZooKeeperSaslClient for client-side usage. + */ + +import org.apache.zookeeper.client.ZooKeeperSaslClient; +import org.apache.zookeeper.common.Time; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.Random; +import java.util.Set; + +import javax.security.auth.Subject; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.kerberos.KerberosPrincipal; +import javax.security.auth.kerberos.KerberosTicket; +import javax.security.auth.login.AppConfigurationEntry; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; + +public class Login { + private static final Logger LOG = LoggerFactory.getLogger(Login.class); + // LoginThread will sleep until 80% of time from last refresh to + // ticket's expiry has been reached, at which time it will wake + // and try to renew the ticket. + private static final float TICKET_RENEW_WINDOW = 0.80f; + /** + * Percentage of random jitter added to the renewal time + */ + private static final float TICKET_RENEW_JITTER = 0.05f; + // Regardless of TICKET_RENEW_WINDOW setting above and the ticket expiry time, + // thread will not sleep between refresh attempts any less than 1 minute (60*1000 milliseconds = 1 minute). + // Change the '1' to e.g. 5, to change this to 5 minutes. + private static final long MIN_TIME_BEFORE_RELOGIN = 1 * 60 * 1000L; + /** Random number generator */ + private static Random rng = new Random(); + public CallbackHandler callbackHandler; + private Subject subject = null; + private Thread t = null; + private boolean isKrbTicket = false; + private boolean isUsingTicketCache = false; + private LoginContext login = null; + private String loginContextName = null; + private String principal = null; + + // Initialize 'lastLogin' to do a login at first time + private long lastLogin = Time.currentElapsedTime() - MIN_TIME_BEFORE_RELOGIN; + + /** + * LoginThread constructor. The constructor starts the thread used + * to periodically re-login to the Kerberos Ticket Granting Server. + * @param loginContextName + * name of section in JAAS file that will be use to login. + * Passed as first param to javax.security.auth.login.LoginContext(). + * + * @param callbackHandler + * Passed as second param to javax.security.auth.login.LoginContext(). + * @throws javax.security.auth.login.LoginException + * Thrown if authentication fails. + */ + public Login(final String loginContextName, CallbackHandler callbackHandler) + throws LoginException { + this.callbackHandler = callbackHandler; + login = login(loginContextName); + this.loginContextName = loginContextName; + subject = login.getSubject(); + isKrbTicket = !subject.getPrivateCredentials(KerberosTicket.class).isEmpty(); + AppConfigurationEntry entries[] = Configuration.getConfiguration().getAppConfigurationEntry(loginContextName); + for (AppConfigurationEntry entry : entries) { + // there will only be a single entry, so this for() loop will only be iterated through once. + if (entry.getOptions().get("useTicketCache") != null) { + String val = (String) entry.getOptions().get("useTicketCache"); + if (val.equals("true")) { + isUsingTicketCache = true; + } + } + if (entry.getOptions().get("principal") != null) { + principal = (String) entry.getOptions().get("principal"); + } + break; + } + + if (!isKrbTicket) { + // if no TGT, do not bother with ticket management. + return; + } + + // Refresh the Ticket Granting Ticket (TGT) periodically. How often to refresh is determined by the + // TGT's existing expiry date and the configured MIN_TIME_BEFORE_RELOGIN. For testing and development, + // you can decrease the interval of expiration of tickets (for example, to 3 minutes) by running : + // "modprinc -maxlife 3mins " in kadmin. + t = new Thread(new Runnable() { + public void run() { + LOG.info("TGT refresh thread started."); + while (true) { // renewal thread's main loop. if it exits from here, thread will exit. + KerberosTicket tgt = getTGT(); + long now = Time.currentWallTime(); + long nextRefresh; + Date nextRefreshDate; + if (tgt == null) { + nextRefresh = now + MIN_TIME_BEFORE_RELOGIN; + nextRefreshDate = new Date(nextRefresh); + LOG.warn("No TGT found: will try again at {}", nextRefreshDate); + } else { + nextRefresh = getRefreshTime(tgt); + long expiry = tgt.getEndTime().getTime(); + Date expiryDate = new Date(expiry); + if ((isUsingTicketCache) && (tgt.getEndTime().equals(tgt.getRenewTill()))) { + Object[] logPayload = {expiryDate, principal, principal}; + LOG.error("The TGT cannot be renewed beyond the next expiry date: {}." + + "This process will not be able to authenticate new SASL connections after that " + + "time (for example, it will not be authenticate a new connection with a Zookeeper " + + "Quorum member). Ask your system administrator to either increase the " + + "'renew until' time by doing : 'modprinc -maxrenewlife {}' within " + + "kadmin, or instead, to generate a keytab for {}. Because the TGT's " + + "expiry cannot be further extended by refreshing, exiting refresh thread now.", logPayload); + return; + } + // determine how long to sleep from looking at ticket's expiry. + // We should not allow the ticket to expire, but we should take into consideration + // MIN_TIME_BEFORE_RELOGIN. Will not sleep less than MIN_TIME_BEFORE_RELOGIN, unless doing so + // would cause ticket expiration. + if ((nextRefresh > expiry) || + ((now + MIN_TIME_BEFORE_RELOGIN) > expiry)) { + // expiry is before next scheduled refresh). + nextRefresh = now; + } else { + if (nextRefresh < (now + MIN_TIME_BEFORE_RELOGIN)) { + // next scheduled refresh is sooner than (now + MIN_TIME_BEFORE_LOGIN). + Date until = new Date(nextRefresh); + Date newuntil = new Date(now + MIN_TIME_BEFORE_RELOGIN); + Object[] logPayload = {until, newuntil, (MIN_TIME_BEFORE_RELOGIN / 1000)}; + LOG.warn("TGT refresh thread time adjusted from : {} to : {} since " + + "the former is sooner than the minimum refresh interval (" + + "{} seconds) from now.", logPayload); + } + nextRefresh = Math.max(nextRefresh, now + MIN_TIME_BEFORE_RELOGIN); + } + nextRefreshDate = new Date(nextRefresh); + if (nextRefresh > expiry) { + Object[] logPayload = {nextRefreshDate, expiryDate}; + LOG.error("next refresh: {} is later than expiry {}." + + " This may indicate a clock skew problem. Check that this host and the KDC's " + + "hosts' clocks are in sync. Exiting refresh thread.", logPayload); + return; + } + } + if (now == nextRefresh) { + LOG.info("refreshing now because expiry is before next scheduled refresh time."); + } else if (now < nextRefresh) { + Date until = new Date(nextRefresh); + LOG.info("TGT refresh sleeping until: {}", until.toString()); + try { + Thread.sleep(nextRefresh - now); + } catch (InterruptedException ie) { + LOG.warn("TGT renewal thread has been interrupted and will exit."); + break; + } + } else { + LOG.error("nextRefresh:{} is in the past: exiting refresh thread. Check" + + " clock sync between this host and KDC - (KDC's clock is likely ahead of this host)." + + " Manual intervention will be required for this client to successfully authenticate." + + " Exiting refresh thread.", nextRefreshDate); + break; + } + if (isUsingTicketCache) { + String cmd = "/usr/bin/kinit"; + if (System.getProperty("zookeeper.kinit") != null) { + cmd = System.getProperty("zookeeper.kinit"); + } + String kinitArgs = "-R"; + int retry = 1; + while (retry >= 0) { + try { + LOG.debug("running ticket cache refresh command: {} {}", cmd, kinitArgs); + Shell.execCommand(cmd, kinitArgs); + break; + } catch (Exception e) { + if (retry > 0) { + --retry; + // sleep for 10 seconds + try { + Thread.sleep(10 * 1000); + } catch (InterruptedException ie) { + LOG.error("Interrupted while renewing TGT, exiting Login thread"); + return; + } + } else { + Object[] logPayload = {cmd, kinitArgs, e.toString(), e}; + LOG.warn("Could not renew TGT due to problem running shell command: '{}" + + " {}'; exception was:{}. Exiting refresh thread.", logPayload); + return; + } + } + } + } + try { + int retry = 1; + while (retry >= 0) { + try { + reLogin(); + break; + } catch (LoginException le) { + if (retry > 0) { + --retry; + // sleep for 10 seconds. + try { + Thread.sleep(10 * 1000); + } catch (InterruptedException e) { + LOG.error("Interrupted during login retry after LoginException:", le); + throw le; + } + } else { + LOG.error("Could not refresh TGT for principal: {}.", principal, le); + } + } + } + } catch (LoginException le) { + LOG.error("Failed to refresh TGT: refresh thread exiting now.", le); + break; + } + } + } + }); + t.setDaemon(true); + } + + public void startThreadIfNeeded() { + // thread object 't' will be null if a refresh thread is not needed. + if (t != null) { + t.start(); + } + } + + public void shutdown() { + if ((t != null) && (t.isAlive())) { + t.interrupt(); + try { + t.join(); + } catch (InterruptedException e) { + LOG.warn("error while waiting for Login thread to shutdown: ", e); + } + } + } + + public Subject getSubject() { + return subject; + } + + public String getLoginContextName() { + return loginContextName; + } + + private synchronized LoginContext login(final String loginContextName) throws LoginException { + if (loginContextName == null) { + throw new LoginException("loginContext name (JAAS file section header) was null. " + + "Please check your java.security.login.auth.config (=" + + System.getProperty("java.security.login.auth.config") + + ") and your " + ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY + "(=" + + System.getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client") + ")"); + } + LoginContext loginContext = new LoginContext(loginContextName, callbackHandler); + loginContext.login(); + LOG.info("successfully logged in."); + return loginContext; + } + + // c.f. org.apache.hadoop.security.UserGroupInformation. + private long getRefreshTime(KerberosTicket tgt) { + long start = tgt.getStartTime().getTime(); + long expires = tgt.getEndTime().getTime(); + LOG.info("TGT valid starting at: {}", tgt.getStartTime().toString()); + LOG.info("TGT expires: {}", tgt.getEndTime().toString()); + long proposedRefresh = start + (long) ((expires - start) * + (TICKET_RENEW_WINDOW + (TICKET_RENEW_JITTER * rng.nextDouble()))); + if (proposedRefresh > expires) { + // proposedRefresh is too far in the future: it's after ticket expires: simply return now. + return Time.currentWallTime(); + } else { + return proposedRefresh; + } + } + + private synchronized KerberosTicket getTGT() { + Set tickets = subject.getPrivateCredentials(KerberosTicket.class); + for (KerberosTicket ticket : tickets) { + KerberosPrincipal server = ticket.getServer(); + if (server.getName().equals("krbtgt/" + server.getRealm() + "@" + server.getRealm())) { + LOG.debug("Found tgt {}.", ticket); + return ticket; + } + } + return null; + } + + private boolean hasSufficientTimeElapsed() { + long now = Time.currentElapsedTime(); + if (now - getLastLogin() < MIN_TIME_BEFORE_RELOGIN) { + LOG.warn("Not attempting to re-login since the last re-login was " + + "attempted less than {} seconds before.", + (MIN_TIME_BEFORE_RELOGIN / 1000)); + return false; + } + // register most recent relogin attempt + setLastLogin(now); + return true; + } + + /** + * Returns login object + * @return login + */ + private LoginContext getLogin() { + return login; + } + + /** + * Set the login object + * @param login + */ + private void setLogin(LoginContext login) { + this.login = login; + } + + /** + * Get the time of the last login. + * @return the number of milliseconds since the beginning of time. + */ + private long getLastLogin() { + return lastLogin; + } + + /** + * Set the last login time. + * @param time the number of milliseconds since the beginning of time + */ + private void setLastLogin(long time) { + lastLogin = time; + } + + /** + * Re-login a principal. This method assumes that {@link #login(String)} has happened already. + * @throws javax.security.auth.login.LoginException on a failure + */ + // c.f. HADOOP-6559 + private synchronized void reLogin() + throws LoginException { + if (!isKrbTicket) { + return; + } + LoginContext login = getLogin(); + if (login == null) { + throw new LoginException("login must be done first"); + } + if (!hasSufficientTimeElapsed()) { + return; + } + LOG.info("Initiating logout for {}", principal); + synchronized (Login.class) { + //clear up the kerberos state. But the tokens are not cleared! As per + //the Java kerberos login module code, only the kerberos credentials + //are cleared + login.logout(); + //login and also update the subject field of this instance to + //have the new credentials (pass it to the LoginContext constructor) + login = new LoginContext(loginContextName, getSubject()); + LOG.info("Initiating re-login for {}", principal); + login.login(); + setLogin(login); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/MultiResponse.java b/src/java/main/org/apache/zookeeper/MultiResponse.java new file mode 100644 index 00000000000..2a91af3afa3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/MultiResponse.java @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.proto.Create2Response; +import org.apache.zookeeper.proto.CreateResponse; +import org.apache.zookeeper.proto.ErrorResponse; +import org.apache.zookeeper.proto.MultiHeader; +import org.apache.zookeeper.proto.SetDataResponse; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Handles the response from a multi request. Such a response consists of a sequence of responses each prefixed by a MultiResponse that indicates the type of the response. The end of the list is + * indicated by a MultiHeader with a negative type. Each individual response is in the same format as with the corresponding operation in the original request list. + */ +public class MultiResponse implements Record, Iterable { + private List results = new ArrayList(); + + public void add(OpResult x) { + results.add(x); + } + + @Override + public Iterator iterator() { + return results.iterator(); + } + + public int size() { + return results.size(); + } + + @Override + public void serialize(OutputArchive archive, String tag) throws IOException { + archive.startRecord(this, tag); + + for (OpResult result : results) { + int err = result.getType() == ZooDefs.OpCode.error ? ((OpResult.ErrorResult) result).getErr() : 0; + + new MultiHeader(result.getType(), false, err).serialize(archive, tag); + + switch (result.getType()) { + case ZooDefs.OpCode.create: + new CreateResponse(((OpResult.CreateResult) result).getPath()).serialize(archive, tag); + break; + case ZooDefs.OpCode.create2: + OpResult.CreateResult createResult = (OpResult.CreateResult) result; + new Create2Response(createResult.getPath(), + createResult.getStat()).serialize(archive, tag); + break; + case ZooDefs.OpCode.delete: + case ZooDefs.OpCode.check: + break; + case ZooDefs.OpCode.setData: + new SetDataResponse(((OpResult.SetDataResult) result).getStat()).serialize(archive, tag); + break; + case ZooDefs.OpCode.error: + new ErrorResponse(((OpResult.ErrorResult) result).getErr()).serialize(archive, tag); + break; + default: + throw new IOException("Invalid type " + result.getType() + " in MultiResponse"); + } + } + new MultiHeader(-1, true, -1).serialize(archive, tag); + archive.endRecord(this, tag); + } + + @Override + public void deserialize(InputArchive archive, String tag) throws IOException { + results = new ArrayList(); + + archive.startRecord(tag); + MultiHeader h = new MultiHeader(); + h.deserialize(archive, tag); + while (!h.getDone()) { + switch (h.getType()) { + case ZooDefs.OpCode.create: + CreateResponse cr = new CreateResponse(); + cr.deserialize(archive, tag); + results.add(new OpResult.CreateResult(cr.getPath())); + break; + + case ZooDefs.OpCode.create2: + Create2Response cr2 = new Create2Response(); + cr2.deserialize(archive, tag); + results.add(new OpResult.CreateResult(cr2.getPath(), cr2.getStat())); + break; + + case ZooDefs.OpCode.delete: + results.add(new OpResult.DeleteResult()); + break; + + case ZooDefs.OpCode.setData: + SetDataResponse sdr = new SetDataResponse(); + sdr.deserialize(archive, tag); + results.add(new OpResult.SetDataResult(sdr.getStat())); + break; + + case ZooDefs.OpCode.check: + results.add(new OpResult.CheckResult()); + break; + + case ZooDefs.OpCode.error: + //FIXME: need way to more cleanly serialize/deserialize exceptions + ErrorResponse er = new ErrorResponse(); + er.deserialize(archive, tag); + results.add(new OpResult.ErrorResult(er.getErr())); + break; + + default: + throw new IOException("Invalid type " + h.getType() + " in MultiResponse"); + } + h.deserialize(archive, tag); + } + archive.endRecord(tag); + } + + public List getResultList() { + return results; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof MultiResponse)) return false; + + MultiResponse other = (MultiResponse) o; + + if (results != null) { + Iterator i = other.results.iterator(); + for (OpResult result : results) { + if (i.hasNext()) { + if (!result.equals(i.next())) { + return false; + } + } else { + return false; + } + } + return !i.hasNext(); + } else return other.results == null; + } + + @Override + public int hashCode() { + int hash = results.size(); + for (OpResult result : results) { + hash = (hash * 35) + result.hashCode(); + } + return hash; + } +} diff --git a/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java b/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java new file mode 100644 index 00000000000..53b726f59d5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.proto.CheckVersionRequest; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.proto.DeleteRequest; +import org.apache.zookeeper.proto.MultiHeader; +import org.apache.zookeeper.proto.SetDataRequest; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Encodes a composite transaction. In the wire format, each transaction consists of a single MultiHeader followed by the appropriate request. Each of these MultiHeaders has a type which indicates + * the type of the following transaction or a negative number if no more transactions are included. + */ +public class MultiTransactionRecord implements Record, Iterable { + private List ops = new ArrayList(); + + public MultiTransactionRecord() { + } + + public MultiTransactionRecord(Iterable ops) { + for (Op op : ops) { + add(op); + } + } + + @Override + public Iterator iterator() { + return ops.iterator(); + } + + public void add(Op op) { + ops.add(op); + } + + public int size() { + return ops.size(); + } + + @Override + public void serialize(OutputArchive archive, String tag) throws IOException { + archive.startRecord(this, tag); + for (Op op : ops) { + MultiHeader h = new MultiHeader(op.getType(), false, -1); + h.serialize(archive, tag); + switch (op.getType()) { + case ZooDefs.OpCode.create: + case ZooDefs.OpCode.create2: + case ZooDefs.OpCode.createContainer: + case ZooDefs.OpCode.delete: + case ZooDefs.OpCode.setData: + case ZooDefs.OpCode.check: + op.toRequestRecord().serialize(archive, tag); + break; + default: + throw new IOException("Invalid type of op"); + } + } + new MultiHeader(-1, true, -1).serialize(archive, tag); + archive.endRecord(this, tag); + } + + @Override + public void deserialize(InputArchive archive, String tag) throws IOException { + archive.startRecord(tag); + MultiHeader h = new MultiHeader(); + h.deserialize(archive, tag); + + while (!h.getDone()) { + switch (h.getType()) { + case ZooDefs.OpCode.create: + case ZooDefs.OpCode.create2: + case ZooDefs.OpCode.createContainer: + CreateRequest cr = new CreateRequest(); + cr.deserialize(archive, tag); + add(Op.create(cr.getPath(), cr.getData(), cr.getAcl(), cr.getFlags())); + break; + case ZooDefs.OpCode.delete: + DeleteRequest dr = new DeleteRequest(); + dr.deserialize(archive, tag); + add(Op.delete(dr.getPath(), dr.getVersion())); + break; + case ZooDefs.OpCode.setData: + SetDataRequest sdr = new SetDataRequest(); + sdr.deserialize(archive, tag); + add(Op.setData(sdr.getPath(), sdr.getData(), sdr.getVersion())); + break; + case ZooDefs.OpCode.check: + CheckVersionRequest cvr = new CheckVersionRequest(); + cvr.deserialize(archive, tag); + add(Op.check(cvr.getPath(), cvr.getVersion())); + break; + default: + throw new IOException("Invalid type of op"); + } + h.deserialize(archive, tag); + } + archive.endRecord(tag); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof MultiTransactionRecord)) return false; + + MultiTransactionRecord that = (MultiTransactionRecord) o; + + if (ops != null) { + Iterator other = that.ops.iterator(); + for (Op op : ops) { + boolean hasMoreData = other.hasNext(); + if (!hasMoreData) { + return false; + } + Op otherOp = other.next(); + if (!op.equals(otherOp)) { + return false; + } + } + return !other.hasNext(); + } else { + return that.ops == null; + } + + } + + @Override + public int hashCode() { + int h = 1023; + for (Op op : ops) { + h = h * 25 + op.hashCode(); + } + return h; + } +} diff --git a/src/java/main/org/apache/zookeeper/Op.java b/src/java/main/org/apache/zookeeper/Op.java new file mode 100644 index 00000000000..886fd57bae6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Op.java @@ -0,0 +1,336 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.Record; +import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.proto.CheckVersionRequest; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.proto.DeleteRequest; +import org.apache.zookeeper.proto.SetDataRequest; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * Represents a single operation in a multi-operation transaction. Each operation can be a create, update or delete or can just be a version check. + * + * Sub-classes of Op each represent each detailed type but should not normally be referenced except via the provided factory methods. + * + * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) + * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode, org.apache.zookeeper.AsyncCallback.StringCallback, Object) + * @see ZooKeeper#delete(String, int) + * @see ZooKeeper#setData(String, byte[], int) + */ +public abstract class Op { + private int type; + private String path; + + // prevent untyped construction + private Op(int type, String path) { + this.type = type; + this.path = path; + } + + /** + * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name. + * + * @param path the path for the node + * @param data the initial data for the node + * @param acl the acl for the node + * @param flags specifying whether the node to be created is ephemeral and/or sequential but using the integer encoding. + * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) + * @see CreateMode#fromFlag(int) + */ + public static Op create(String path, byte[] data, List acl, int flags) { + return new Create(path, data, acl, flags); + } + + /** + * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name. + * + * @param path the path for the node + * @param data the initial data for the node + * @param acl the acl for the node + * @param createMode specifying whether the node to be created is ephemeral and/or sequential + * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) + */ + public static Op create(String path, byte[] data, List acl, CreateMode createMode) { + return new Create(path, data, acl, createMode); + } + + /** + * Constructs a delete operation. Arguments are as for the ZooKeeper method of the same name. + * + * @param path the path of the node to be deleted. + * @param version the expected node version. + * @see ZooKeeper#delete(String, int) + */ + public static Op delete(String path, int version) { + return new Delete(path, version); + } + + /** + * Constructs an update operation. Arguments are as for the ZooKeeper method of the same name. + * + * @param path the path of the node + * @param data the data to set + * @param version the expected matching version + * @see ZooKeeper#setData(String, byte[], int) + */ + public static Op setData(String path, byte[] data, int version) { + return new SetData(path, data, version); + } + + + /** + * Constructs an version check operation. Arguments are as for the ZooKeeper.setData method except that no data is provided since no update is intended. The purpose for this is to allow + * read-modify-write operations that apply to multiple znodes, but where some of the znodes are involved only in the read, not the write. A similar effect could be achieved by writing the same + * data back, but that leads to way more version updates than are necessary and more writing in general. + * + * @param path the path of the node + * @param version the expected matching version + */ + public static Op check(String path, int version) { + return new Check(path, version); + } + + /** + * Gets the integer type code for an Op. This code should be as from ZooDefs.OpCode + * + * @return The type code. + * @see ZooDefs.OpCode + */ + public int getType() { + return type; + } + + /** + * Gets the path for an Op. + * + * @return The path. + */ + public String getPath() { + return path; + } + + /** + * Encodes an op for wire transmission. + * + * @return An appropriate Record structure. + */ + public abstract Record toRequestRecord(); + + /** + * Reconstructs the transaction with the chroot prefix. + * + * @return transaction with chroot. + */ + abstract Op withChroot(String addRootPrefix); + + /** + * Performs client path validations. + * + * @throws IllegalArgumentException if an invalid path is specified + * @throws KeeperException.BadArgumentsException if an invalid create mode flag is specified + */ + void validate() throws KeeperException { + PathUtils.validatePath(path); + } + + ////////////////// + // these internal classes are public, but should not generally be referenced. + // + public static class Create extends Op { + private byte[] data; + private List acl; + private int flags; + + private Create(String path, byte[] data, List acl, int flags) { + super(getOpcode(CreateMode.fromFlag(flags, CreateMode.PERSISTENT)), path); + this.data = data; + this.acl = acl; + this.flags = flags; + } + + private Create(String path, byte[] data, List acl, CreateMode createMode) { + super(getOpcode(createMode), path); + this.data = data; + this.acl = acl; + this.flags = createMode.toFlag(); + } + + private static int getOpcode(CreateMode createMode) { + return createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Create)) return false; + + Create op = (Create) o; + + boolean aclEquals = true; + Iterator i = op.acl.iterator(); + for (ACL acl : op.acl) { + boolean hasMoreData = i.hasNext(); + if (!hasMoreData) { + aclEquals = false; + break; + } + ACL otherAcl = i.next(); + if (!acl.equals(otherAcl)) { + aclEquals = false; + break; + } + } + return !i.hasNext() && getType() == op.getType() && Arrays.equals(data, op.data) && flags == op.flags && aclEquals; + } + + @Override + public int hashCode() { + return getType() + getPath().hashCode() + Arrays.hashCode(data); + } + + @Override + public Record toRequestRecord() { + return new CreateRequest(getPath(), data, acl, flags); + } + + @Override + Op withChroot(String path) { + return new Create(path, data, acl, flags); + } + + @Override + void validate() throws KeeperException { + CreateMode createMode = CreateMode.fromFlag(flags); + PathUtils.validatePath(getPath(), createMode.isSequential()); + } + } + + public static class Delete extends Op { + private int version; + + private Delete(String path, int version) { + super(ZooDefs.OpCode.delete, path); + this.version = version; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Delete)) return false; + + Delete op = (Delete) o; + + return getType() == op.getType() && version == op.version + && getPath().equals(op.getPath()); + } + + @Override + public int hashCode() { + return getType() + getPath().hashCode() + version; + } + + @Override + public Record toRequestRecord() { + return new DeleteRequest(getPath(), version); + } + + @Override + Op withChroot(String path) { + return new Delete(path, version); + } + } + + public static class SetData extends Op { + private byte[] data; + private int version; + + private SetData(String path, byte[] data, int version) { + super(ZooDefs.OpCode.setData, path); + this.data = data; + this.version = version; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SetData)) return false; + + SetData op = (SetData) o; + + return getType() == op.getType() && version == op.version + && getPath().equals(op.getPath()) && Arrays.equals(data, op.data); + } + + @Override + public int hashCode() { + return getType() + getPath().hashCode() + Arrays.hashCode(data) + version; + } + + @Override + public Record toRequestRecord() { + return new SetDataRequest(getPath(), data, version); + } + + @Override + Op withChroot(String path) { + return new SetData(path, data, version); + } + } + + public static class Check extends Op { + private int version; + + private Check(String path, int version) { + super(ZooDefs.OpCode.check, path); + this.version = version; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Check)) return false; + + Check op = (Check) o; + + return getType() == op.getType() && getPath().equals(op.getPath()) && version == op.version; + } + + @Override + public int hashCode() { + return getType() + getPath().hashCode() + version; + } + + @Override + public Record toRequestRecord() { + return new CheckVersionRequest(getPath(), version); + } + + @Override + Op withChroot(String path) { + return new Check(path, version); + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/OpResult.java b/src/java/main/org/apache/zookeeper/OpResult.java new file mode 100644 index 00000000000..cb9c1796b04 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/OpResult.java @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper; + + +import org.apache.zookeeper.data.Stat; + +/** + * Encodes the result of a single part of a multiple operation commit. + */ +public abstract class OpResult { + private int type; + + private OpResult(int type) { + this.type = type; + } + + /** + * Encodes the return type as from ZooDefs.OpCode. Can be used to dispatch to the correct cast needed for getting the desired additional result data. + * + * @return an integer identifying what kind of operation this result came from. + * @see ZooDefs.OpCode + */ + public int getType() { + return type; + } + + /** + * A result from a create operation. This kind of result allows the path to be retrieved since the create might have been a sequential create. + */ + public static class CreateResult extends OpResult { + private String path; + private Stat stat; + + public CreateResult(String path) { + this(ZooDefs.OpCode.create, path, null); + } + + public CreateResult(String path, Stat stat) { + this(ZooDefs.OpCode.create2, path, stat); + } + + private CreateResult(int opcode, String path, Stat stat) { + super(opcode); + this.path = path; + this.stat = stat; + } + + public String getPath() { + return path; + } + + public Stat getStat() { + return stat; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof CreateResult)) return false; + + CreateResult other = (CreateResult) o; + + boolean statsAreEqual = (stat == null && other.stat == null || + (stat != null && other.stat != null && + stat.getMzxid() == other.stat.getMzxid())); + return getType() == other.getType() && + path.equals(other.getPath()) && statsAreEqual; + } + + @Override + public int hashCode() { + return (int) (getType() * 35 + path.hashCode() + + (stat == null ? 0 : stat.getMzxid())); + } + } + + /** + * A result from a delete operation. No special values are available. + */ + public static class DeleteResult extends OpResult { + public DeleteResult() { + super(ZooDefs.OpCode.delete); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DeleteResult)) return false; + + DeleteResult opResult = (DeleteResult) o; + return getType() == opResult.getType(); + } + + @Override + public int hashCode() { + return getType(); + } + } + + /** + * A result from a setData operation. This kind of result provides access to the Stat structure from the update. + */ + public static class SetDataResult extends OpResult { + private Stat stat; + + public SetDataResult(Stat stat) { + super(ZooDefs.OpCode.setData); + this.stat = stat; + } + + public Stat getStat() { + return stat; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SetDataResult)) return false; + + SetDataResult other = (SetDataResult) o; + return getType() == other.getType() && stat.getMzxid() == other.stat.getMzxid(); + } + + @Override + public int hashCode() { + return (int) (getType() * 35 + stat.getMzxid()); + } + } + + /** + * A result from a version check operation. No special values are available. + */ + public static class CheckResult extends OpResult { + public CheckResult() { + super(ZooDefs.OpCode.check); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof CheckResult)) return false; + + CheckResult other = (CheckResult) o; + return getType() == other.getType(); + } + + @Override + public int hashCode() { + return getType(); + } + } + + /** + * An error result from any kind of operation. The point of error results is that they contain an error code which helps understand what happened. + * + * @see KeeperException.Code + */ + public static class ErrorResult extends OpResult { + private int err; + + public ErrorResult(int err) { + super(ZooDefs.OpCode.error); + this.err = err; + } + + public int getErr() { + return err; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ErrorResult)) return false; + + ErrorResult other = (ErrorResult) o; + return getType() == other.getType() && err == other.getErr(); + } + + @Override + public int hashCode() { + return getType() * 35 + err; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/Quotas.java b/src/java/main/org/apache/zookeeper/Quotas.java new file mode 100644 index 00000000000..add869f8c05 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Quotas.java @@ -0,0 +1,61 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +/** + * this class manages quotas + * and has many other utils + * for quota + */ +public class Quotas { + + /** the zookeeper nodes that acts as the management and status node **/ + public static final String procZookeeper = "/zookeeper"; + + /** the zookeeper quota node that acts as the quota + * management node for zookeeper */ + public static final String quotaZookeeper = "/zookeeper/quota"; + + /** + * the limit node that has the limit of + * a subtree + */ + public static final String limitNode = "zookeeper_limits"; + + /** + * the stat node that monitors the limit of + * a subtree. + */ + public static final String statNode = "zookeeper_stats"; + + /** + * return the quota path associated with this + * prefix + * @param path the actual path in zookeeper. + * @return the limit quota path + */ + public static String quotaPath(String path) { + return quotaZookeeper + path + + "/" + limitNode; + } + + /** + * return the stat quota path associated with this + * prefix. + * @param path the actual path in zookeeper + * @return the stat quota path + */ + public static String statPath(String path) { + return quotaZookeeper + path + "/" + + statNode; + } +} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/ServerAdminClient.java b/src/java/main/org/apache/zookeeper/ServerAdminClient.java similarity index 67% rename from zookeeper/java/src/com/yahoo/zookeeper/ServerAdminClient.java rename to src/java/main/org/apache/zookeeper/ServerAdminClient.java index 1bf1f90192d..69bbc66feee 100644 --- a/zookeeper/java/src/com/yahoo/zookeeper/ServerAdminClient.java +++ b/src/java/main/org/apache/zookeeper/ServerAdminClient.java @@ -1,20 +1,18 @@ -/* - * Copyright 2008, Yahoo! Inc. +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.zookeeper; +package org.apache.zookeeper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; @@ -22,50 +20,16 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.nio.ByteBuffer; -import java.util.StringTokenizer; - -import com.yahoo.zookeeper.server.ZooLog; public class ServerAdminClient { - - private static long getMask(String mask) { - long retv = 0; - if (mask.equalsIgnoreCase("CLIENT_REQUEST_TRACE_MASK")) { - retv = ZooLog.CLIENT_REQUEST_TRACE_MASK; - } else if (mask.equalsIgnoreCase("CLIENT_DATA_PACKET_TRACE_MASK")) { - retv = ZooLog.CLIENT_DATA_PACKET_TRACE_MASK; - } else if (mask.equalsIgnoreCase("CLIENT_PING_TRACE_MASK")) { - retv = ZooLog.CLIENT_PING_TRACE_MASK; - } else if (mask.equalsIgnoreCase("SERVER_PACKET_TRACE_MASK")) { - retv = ZooLog.SERVER_PACKET_TRACE_MASK; - } else if (mask.equalsIgnoreCase("SESSION_TRACE_MASK")) { - retv = ZooLog.SESSION_TRACE_MASK; - } else if (mask.equalsIgnoreCase("EVENT_DELIVERY_TRACE_MASK")) { - retv = ZooLog.EVENT_DELIVERY_TRACE_MASK; - } else if (mask.equalsIgnoreCase("SERVER_PING_TRACE_MASK")) { - retv = ZooLog.SERVER_PING_TRACE_MASK; - } else if (mask.equalsIgnoreCase("WARNING_TRACE_MASK")) { - retv = ZooLog.WARNING_TRACE_MASK; - } - return retv; - } - - private static long getMasks(String masks) { - long retv = 0; - StringTokenizer st = new StringTokenizer(masks, "|"); - while (st.hasMoreTokens()) { - String mask = st.nextToken().trim(); - retv = retv | getMask(mask); - } - return retv; - } + private static final Logger LOG = LoggerFactory.getLogger(ServerAdminClient.class); public static void ruok(String host, int port) { + Socket s = null; try { byte[] reqBytes = new byte[4]; ByteBuffer req = ByteBuffer.wrap(reqBytes); req.putInt(ByteBuffer.wrap("ruok".getBytes()).getInt()); - Socket s = null; s = new Socket(); s.setSoLinger(false, 10); s.setSoTimeout(20000); @@ -81,17 +45,25 @@ public static void ruok(String host, int port) { int rc = is.read(resBytes); String retv = new String(resBytes); System.out.println("rc=" + rc + " retv=" + retv); - } catch (IOException ioe) { - ioe.printStackTrace(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } } } public static void dump(String host, int port) { + Socket s = null; try { byte[] reqBytes = new byte[4]; ByteBuffer req = ByteBuffer.wrap(reqBytes); req.putInt(ByteBuffer.wrap("dump".getBytes()).getInt()); - Socket s = null; s = new Socket(); s.setSoLinger(false, 10); s.setSoTimeout(20000); @@ -107,17 +79,25 @@ public static void dump(String host, int port) { int rc = is.read(resBytes); String retv = new String(resBytes); System.out.println("rc=" + rc + " retv=" + retv); - } catch (IOException ioe) { - ioe.printStackTrace(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } } } public static void stat(String host, int port) { + Socket s = null; try { byte[] reqBytes = new byte[4]; ByteBuffer req = ByteBuffer.wrap(reqBytes); req.putInt(ByteBuffer.wrap("stat".getBytes()).getInt()); - Socket s = null; s = new Socket(); s.setSoLinger(false, 10); s.setSoTimeout(20000); @@ -133,17 +113,25 @@ public static void stat(String host, int port) { int rc = is.read(resBytes); String retv = new String(resBytes); System.out.println("rc=" + rc + " retv=" + retv); - } catch (IOException ioe) { - ioe.printStackTrace(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } } } public static void kill(String host, int port) { + Socket s = null; try { byte[] reqBytes = new byte[4]; ByteBuffer req = ByteBuffer.wrap(reqBytes); req.putInt(ByteBuffer.wrap("kill".getBytes()).getInt()); - Socket s = null; s = new Socket(); s.setSoLinger(false, 10); s.setSoTimeout(20000); @@ -158,12 +146,21 @@ public static void kill(String host, int port) { int rc = is.read(resBytes); String retv = new String(resBytes); System.out.println("rc=" + rc + " retv=" + retv); - } catch (IOException ioe) { - ioe.printStackTrace(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } } } public static void setTraceMask(String host, int port, String traceMaskStr) { + Socket s = null; try { byte[] reqBytes = new byte[12]; ByteBuffer req = ByteBuffer.wrap(reqBytes); @@ -171,7 +168,6 @@ public static void setTraceMask(String host, int port, String traceMaskStr) { req.putInt(ByteBuffer.wrap("stmk".getBytes()).getInt()); req.putLong(traceMask); - Socket s = null; s = new Socket(); s.setSoLinger(false, 10); s.setSoTimeout(20000); @@ -191,18 +187,26 @@ public static void setTraceMask(String host, int port, String traceMaskStr) { + Long.toOctalString(retv) + " masks=0" + Long.toOctalString(traceMask)); assert (retv == traceMask); - } catch (IOException ioe) { - ioe.printStackTrace(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } } } public static void getTraceMask(String host, int port) { + Socket s = null; try { byte[] reqBytes = new byte[12]; ByteBuffer req = ByteBuffer.wrap(reqBytes); req.putInt(ByteBuffer.wrap("gtmk".getBytes()).getInt()); - Socket s = null; s = new Socket(); s.setSoLinger(false, 10); s.setSoTimeout(20000); @@ -220,14 +224,22 @@ public static void getTraceMask(String host, int port) { long retv = res.getLong(); System.out.println("rc=" + rc + " retv=0" + Long.toOctalString(retv)); - } catch (IOException ioe) { - ioe.printStackTrace(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } finally { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + } } } private static void usage() { System.out - .println("usage: java [-cp CLASSPATH] com.yahoo.zookeeper.ServerAdminClient " + .println("usage: java [-cp CLASSPATH] org.apache.zookeeper.ServerAdminClient " + "host port op (ruok|stat|dump|kill|gettracemask|settracemask) [arguments]"); } diff --git a/src/java/main/org/apache/zookeeper/Shell.java b/src/java/main/org/apache/zookeeper/Shell.java new file mode 100644 index 00000000000..b255edac8db --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Shell.java @@ -0,0 +1,468 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +/* This file copied from Hadoop's security branch, + * with the following changes: + * 1. package changed from org.apache.hadoop.util to + * org.apache.zookeeper. + * 2. Usage of Hadoop's Configuration class removed since + * it is not available in Zookeeper: instead, system properties + * are used. + * 3. The deprecated getUlimitMemoryCommand() method removed since + * it is not needed. + */ + + +package org.apache.zookeeper; + +import org.apache.zookeeper.common.Time; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * A base class for running a Unix command. + * + * Shell can be used to run unix commands like du or + * df. It also offers facilities to gate commands by + * time-intervals. + */ +abstract public class Shell { + + /** a Unix command to get the current user's name */ + public final static String USER_NAME_COMMAND = "whoami"; + /** a Unix command to set permission */ + public static final String SET_PERMISSION_COMMAND = "chmod"; + /** a Unix command to set owner */ + public static final String SET_OWNER_COMMAND = "chown"; + public static final String SET_GROUP_COMMAND = "chgrp"; + /** a Unix command to get ulimit of a process. */ + public static final String ULIMIT_COMMAND = "ulimit"; + /** Set to true on Windows platforms */ + public static final boolean WINDOWS /* borrowed from Path.WINDOWS */ + = System.getProperty("os.name").startsWith("Windows"); + private static final Logger LOG = LoggerFactory.getLogger(Shell.class); + /**Time after which the executing script would be timedout*/ + protected long timeOutInterval = 0L; + /** If or not script timed out*/ + private AtomicBoolean timedOut; + private long interval; // refresh interval in msec + private long lastTime; // last time the command was performed + private Map environment; // env for the command execution + private File dir; + private Process process; // sub process used to execute the command + private int exitCode; + /**If or not script finished executing*/ + private volatile AtomicBoolean completed; + public Shell() { + this(0L); + } + /** + * @param interval the minimum duration to wait before re-executing the + * command. + */ + public Shell(long interval) { + this.interval = interval; + this.lastTime = (interval < 0) ? 0 : -interval; + } + + /** a Unix command to get the current user's groups list */ + public static String[] getGroupsCommand() { + return new String[]{"bash", "-c", "groups"}; + } + + /** a Unix command to get a given user's groups list */ + public static String[] getGroupsForUserCommand(final String user) { + //'groups username' command return is non-consistent across different unixes + return new String[]{"bash", "-c", "id -Gn " + user}; + } + + /** Return a Unix command to get permission information. */ + public static String[] getGET_PERMISSION_COMMAND() { + //force /bin/ls, except on windows. + return new String[]{(WINDOWS ? "ls" : "/bin/ls"), "-ld"}; + } + + /** + * Get the Unix command for setting the maximum virtual memory available + * to a given child process. This is only relevant when we are forking a + * process from within the Mapper or the Reducer implementations. + * Also see Hadoop Pipes and Hadoop Streaming. + * + * It also checks to ensure that we are running on a *nix platform else + * (e.g. in Cygwin/Windows) it returns null. + * @param memoryLimit virtual memory limit + * @return a String[] with the ulimit command arguments or + * null if we are running on a non *nix platform or + * if the limit is unspecified. + */ + public static String[] getUlimitMemoryCommand(int memoryLimit) { + // ulimit isn't supported on Windows + if (WINDOWS) { + return null; + } + + return new String[]{ULIMIT_COMMAND, "-v", String.valueOf(memoryLimit)}; + } + + /** + * Static method to execute a shell command. + * Covers most of the simple cases without requiring the user to implement + * the Shell interface. + * @param cmd shell command to execute. + * @return the output of the executed command. + */ + public static String execCommand(String... cmd) throws IOException { + return execCommand(null, cmd, 0L); + } + + /** + * Static method to execute a shell command. + * Covers most of the simple cases without requiring the user to implement + * the Shell interface. + * @param env the map of environment key=value + * @param cmd shell command to execute. + * @param timeout time in milliseconds after which script should be marked timeout + * @return the output of the executed command.o + */ + + public static String execCommand(Map env, String[] cmd, + long timeout) throws IOException { + ShellCommandExecutor exec = new ShellCommandExecutor(cmd, null, env, + timeout); + exec.execute(); + return exec.getOutput(); + } + + /** + * Static method to execute a shell command. + * Covers most of the simple cases without requiring the user to implement + * the Shell interface. + * @param env the map of environment key=value + * @param cmd shell command to execute. + * @return the output of the executed command. + */ + public static String execCommand(Map env, String... cmd) + throws IOException { + return execCommand(env, cmd, 0L); + } + + /** set the environment for the command + * @param env Mapping of environment variables + */ + protected void setEnvironment(Map env) { + this.environment = env; + } + + /** set the working directory + * @param dir The directory where the command would be executed + */ + protected void setWorkingDirectory(File dir) { + this.dir = dir; + } + + /** check to see if a command needs to be executed and execute if needed */ + protected void run() throws IOException { + if (lastTime + interval > Time.currentElapsedTime()) + return; + exitCode = 0; // reset for next run + runCommand(); + } + + /** Run a command */ + private void runCommand() throws IOException { + ProcessBuilder builder = new ProcessBuilder(getExecString()); + Timer timeOutTimer = null; + ShellTimeoutTimerTask timeoutTimerTask = null; + timedOut = new AtomicBoolean(false); + completed = new AtomicBoolean(false); + + if (environment != null) { + builder.environment().putAll(this.environment); + } + if (dir != null) { + builder.directory(this.dir); + } + + process = builder.start(); + if (timeOutInterval > 0) { + timeOutTimer = new Timer(); + timeoutTimerTask = new ShellTimeoutTimerTask( + this); + //One time scheduling. + timeOutTimer.schedule(timeoutTimerTask, timeOutInterval); + } + final BufferedReader errReader = + new BufferedReader(new InputStreamReader(process + .getErrorStream())); + BufferedReader inReader = + new BufferedReader(new InputStreamReader(process + .getInputStream())); + final StringBuffer errMsg = new StringBuffer(); + + // read error and input streams as this would free up the buffers + // free the error stream buffer + Thread errThread = new Thread() { + @Override + public void run() { + try { + String line = errReader.readLine(); + while ((line != null) && !isInterrupted()) { + errMsg.append(line); + errMsg.append(System.getProperty("line.separator")); + line = errReader.readLine(); + } + } catch (IOException ioe) { + LOG.warn("Error reading the error stream", ioe); + } + } + }; + try { + errThread.start(); + } catch (IllegalStateException ise) { + } + try { + parseExecResult(inReader); // parse the output + // clear the input stream buffer + String line = inReader.readLine(); + while (line != null) { + line = inReader.readLine(); + } + // wait for the process to finish and check the exit code + exitCode = process.waitFor(); + try { + // make sure that the error thread exits + errThread.join(); + } catch (InterruptedException ie) { + LOG.warn("Interrupted while reading the error stream", ie); + } + completed.set(true); + //the timeout thread handling + //taken care in finally block + if (exitCode != 0) { + throw new ExitCodeException(exitCode, errMsg.toString()); + } + } catch (InterruptedException ie) { + throw new IOException(ie.toString()); + } finally { + if ((timeOutTimer != null) && !timedOut.get()) { + timeOutTimer.cancel(); + } + // close the input stream + try { + inReader.close(); + } catch (IOException ioe) { + LOG.warn("Error while closing the input stream", ioe); + } + if (!completed.get()) { + errThread.interrupt(); + } + try { + errReader.close(); + } catch (IOException ioe) { + LOG.warn("Error while closing the error stream", ioe); + } + process.destroy(); + lastTime = Time.currentElapsedTime(); + } + } + + /** return an array containing the command name & its parameters */ + protected abstract String[] getExecString(); + + /** Parse the execution result */ + protected abstract void parseExecResult(BufferedReader lines) + throws IOException; + + /** get the current sub-process executing the given command + * @return process executing the command + */ + public Process getProcess() { + return process; + } + + /** get the exit code + * @return the exit code of the process + */ + public int getExitCode() { + return exitCode; + } + + /** + * To check if the passed script to shell command executor timed out or + * not. + * + * @return if the script timed out. + */ + public boolean isTimedOut() { + return timedOut.get(); + } + + /** + * Set if the command has timed out. + * + */ + private void setTimedOut() { + this.timedOut.set(true); + } + + /** + * This is an IOException with exit code added. + */ + @SuppressWarnings("serial") + public static class ExitCodeException extends IOException { + int exitCode; + + public ExitCodeException(int exitCode, String message) { + super(message); + this.exitCode = exitCode; + } + + public int getExitCode() { + return exitCode; + } + } + + /** + * A simple shell command executor. + * + * ShellCommandExecutorshould be used in cases where the output + * of the command needs no explicit parsing and where the command, working + * directory and the environment remains unchanged. The output of the command + * is stored as-is and is expected to be small. + */ + public static class ShellCommandExecutor extends Shell { + + private String[] command; + private StringBuffer output; + + + public ShellCommandExecutor(String[] execString) { + this(execString, null); + } + + public ShellCommandExecutor(String[] execString, File dir) { + this(execString, dir, null); + } + + public ShellCommandExecutor(String[] execString, File dir, + Map env) { + this(execString, dir, env, 0L); + } + + /** + * Create a new instance of the ShellCommandExecutor to execute a command. + * + * @param execString The command to execute with arguments + * @param dir If not-null, specifies the directory which should be set + * as the current working directory for the command. + * If null, the current working directory is not modified. + * @param env If not-null, environment of the command will include the + * key-value pairs specified in the map. If null, the current + * environment is not modified. + * @param timeout Specifies the time in milliseconds, after which the + * command will be killed and the status marked as timedout. + * If 0, the command will not be timed out. + */ + public ShellCommandExecutor(String[] execString, File dir, + Map env, long timeout) { + command = execString.clone(); + if (dir != null) { + setWorkingDirectory(dir); + } + if (env != null) { + setEnvironment(env); + } + timeOutInterval = timeout; + } + + + /** Execute the shell command. */ + public void execute() throws IOException { + this.run(); + } + + protected String[] getExecString() { + return command; + } + + protected void parseExecResult(BufferedReader lines) throws IOException { + output = new StringBuffer(); + char[] buf = new char[512]; + int nRead; + while ((nRead = lines.read(buf, 0, buf.length)) > 0) { + output.append(buf, 0, nRead); + } + } + + /** Get the output of the shell command.*/ + public String getOutput() { + return (output == null) ? "" : output.toString(); + } + + /** + * Returns the commands of this instance. + * Arguments with spaces in are presented with quotes round; other + * arguments are presented raw + * + * @return a string representation of the object. + */ + public String toString() { + StringBuilder builder = new StringBuilder(); + String[] args = getExecString(); + for (String s : args) { + if (s.indexOf(' ') >= 0) { + builder.append('"').append(s).append('"'); + } else { + builder.append(s); + } + builder.append(' '); + } + return builder.toString(); + } + } + + /** + * Timer which is used to timeout scripts spawned off by shell. + */ + private static class ShellTimeoutTimerTask extends TimerTask { + + private Shell shell; + + public ShellTimeoutTimerTask(Shell shell) { + this.shell = shell; + } + + @Override + public void run() { + Process p = shell.getProcess(); + try { + p.exitValue(); + } catch (Exception e) { + //Process has not terminated. + //So check if it has completed + //if not just destroy it. + if (p != null && !shell.completed.get()) { + shell.setTimedOut(); + p.destroy(); + } + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/StatsTrack.java b/src/java/main/org/apache/zookeeper/StatsTrack.java new file mode 100644 index 00000000000..6ed8bec59ee --- /dev/null +++ b/src/java/main/org/apache/zookeeper/StatsTrack.java @@ -0,0 +1,95 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +/** + * a class that represents the stats associated with quotas + */ +public class StatsTrack { + private int count; + private long bytes; + private String countStr = "count"; + private String byteStr = "bytes"; + + /** + * a default constructor for + * stats + */ + public StatsTrack() { + this(null); + } + + /** + * the stat string should be of the form count=int,bytes=long + * if stats is called with null the count and bytes are initialized + * to -1. + * @param stats the stat string to be intialized with + */ + public StatsTrack(String stats) { + if (stats == null) { + stats = "count=-1,bytes=-1"; + } + String[] split = stats.split(","); + if (split.length != 2) { + throw new IllegalArgumentException("invalid string " + stats); + } + count = Integer.parseInt(split[0].split("=")[1]); + bytes = Long.parseLong(split[1].split("=")[1]); + } + + + /** + * get the count of nodes allowed as part of quota + * + * @return the count as part of this string + */ + public int getCount() { + return this.count; + } + + /** + * set the count for this stat tracker. + * + * @param count + * the count to set with + */ + public void setCount(int count) { + this.count = count; + } + + /** + * get the count of bytes allowed as part of quota + * + * @return the bytes as part of this string + */ + public long getBytes() { + return this.bytes; + } + + /** + * set teh bytes for this stat tracker. + * + * @param bytes + * the bytes to set with + */ + public void setBytes(long bytes) { + this.bytes = bytes; + } + + @Override + /* + * returns the string that maps to this stat tracking. + */ + public String toString() { + return countStr + "=" + count + "," + byteStr + "=" + bytes; + } +} diff --git a/src/java/main/org/apache/zookeeper/Testable.java b/src/java/main/org/apache/zookeeper/Testable.java new file mode 100644 index 00000000000..918d87762a8 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Testable.java @@ -0,0 +1,22 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +/** + * Abstraction that exposes various methods useful for testing ZooKeeper + */ +public interface Testable { + /** + * Cause the ZooKeeper instance to behave as if the session expired + */ + void injectSessionExpiration(); +} diff --git a/src/java/main/org/apache/zookeeper/Transaction.java b/src/java/main/org/apache/zookeeper/Transaction.java new file mode 100644 index 00000000000..4d5a8901d30 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Transaction.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.zookeeper.AsyncCallback.MultiCallback; +import org.apache.zookeeper.data.ACL; + +import java.util.ArrayList; +import java.util.List; + +/** + * Provides a builder style interface for doing multiple updates. This is really just a thin layer on top of Zookeeper.multi(). + * + * @since 3.4.0 + */ +public class Transaction { + private ZooKeeper zk; + private List ops = new ArrayList(); + + protected Transaction(ZooKeeper zk) { + this.zk = zk; + } + + public Transaction create(final String path, byte data[], List acl, + CreateMode createMode) { + ops.add(Op.create(path, data, acl, createMode.toFlag())); + return this; + } + + public Transaction delete(final String path, int version) { + ops.add(Op.delete(path, version)); + return this; + } + + public Transaction check(String path, int version) { + ops.add(Op.check(path, version)); + return this; + } + + public Transaction setData(final String path, byte data[], int version) { + ops.add(Op.setData(path, data, version)); + return this; + } + + public List commit() throws InterruptedException, KeeperException { + return zk.multi(ops); + } + + public void commit(MultiCallback cb, Object ctx) { + zk.multi(ops, cb, ctx); + } +} diff --git a/src/java/main/org/apache/zookeeper/Version.java b/src/java/main/org/apache/zookeeper/Version.java new file mode 100644 index 00000000000..a7e848cc12c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Version.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +public class Version implements org.apache.zookeeper.version.Info { + + public static int getRevision() { + return REVISION; + } + + public static String getBuildDate() { + return BUILD_DATE; + } + + public static String getVersion() { + return MAJOR + "." + MINOR + "." + MICRO + + (QUALIFIER == null ? "" : "-" + QUALIFIER); + } + + public static String getVersionRevision() { + return getVersion() + "-" + getRevision(); + } + + public static String getFullVersion() { + return getVersionRevision() + ", built on " + getBuildDate(); + } + + public static void printUsage() { + System.out + .print("Usage:\tjava -cp ... org.apache.zookeeper.Version " + + "[--full | --short | --revision],\n\tPrints --full version " + + "info if no arg specified."); + System.exit(1); + } + + /** + * Prints the current version, revision and build date to the standard out. + * + * @param args + *

          + *
        • --short - prints a short version string "1.2.3" + *
        • --revision - prints a short version string with the SVN + * repository revision "1.2.3-94" + *
        • --full - prints the revision and the build date + *
        + */ + public static void main(String[] args) { + if (args.length > 1) { + printUsage(); + } + if (args.length == 0 || (args.length == 1 && args[0].equals("--full"))) { + System.out.println(getFullVersion()); + System.exit(0); + } + if (args[0].equals("--short")) + System.out.println(getVersion()); + else if (args[0].equals("--revision")) + System.out.println(getVersionRevision()); + else + printUsage(); + System.exit(0); + } +} diff --git a/src/java/main/org/apache/zookeeper/WatchDeregistration.java b/src/java/main/org/apache/zookeeper/WatchDeregistration.java new file mode 100644 index 00000000000..7c2ca2acd25 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/WatchDeregistration.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.ZooKeeper.ZKWatchManager; + +import java.util.Map; +import java.util.Set; + +/** + * Handles the special case of removing watches which has registered for a + * client path + */ +public class WatchDeregistration { + + private final String clientPath; + private final Watcher watcher; + private final WatcherType watcherType; + private final boolean local; + private final ZKWatchManager zkManager; + + public WatchDeregistration(String clientPath, Watcher watcher, + WatcherType watcherType, boolean local, ZKWatchManager zkManager) { + this.clientPath = clientPath; + this.watcher = watcher; + this.watcherType = watcherType; + this.local = local; + this.zkManager = zkManager; + } + + /** + * Unregistering watcher that was added on path. + * + * @param rc + * the result code of the operation that attempted to remove + * watch on the path. + */ + public Map> unregister(int rc) + throws KeeperException { + return zkManager.removeWatcher(clientPath, watcher, watcherType, local, + rc); + } + + /** + * Returns client path which has specified for unregistering its watcher + * + * @return client path + */ + public String getClientPath() { + return clientPath; + } +} diff --git a/src/java/main/org/apache/zookeeper/WatchedEvent.java b/src/java/main/org/apache/zookeeper/WatchedEvent.java new file mode 100644 index 00000000000..20c3f281708 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/WatchedEvent.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.proto.WatcherEvent; + +/** + * A WatchedEvent represents a change on the ZooKeeper that a Watcher + * is able to respond to. The WatchedEvent includes exactly what happened, + * the current state of the ZooKeeper, and the path of the znode that + * was involved in the event. + */ +public class WatchedEvent { + final private KeeperState keeperState; + final private EventType eventType; + private String path; + + /** + * Create a WatchedEvent with specified type, state and path + */ + public WatchedEvent(EventType eventType, KeeperState keeperState, String path) { + this.keeperState = keeperState; + this.eventType = eventType; + this.path = path; + } + + /** + * Convert a WatcherEvent sent over the wire into a full-fledged WatcherEvent + */ + public WatchedEvent(WatcherEvent eventMessage) { + keeperState = KeeperState.fromInt(eventMessage.getState()); + eventType = EventType.fromInt(eventMessage.getType()); + path = eventMessage.getPath(); + } + + public KeeperState getState() { + return keeperState; + } + + public EventType getType() { + return eventType; + } + + public String getPath() { + return path; + } + + @Override + public String toString() { + return "WatchedEvent state:" + keeperState + + " type:" + eventType + " path:" + path; + } + + /** + * Convert WatchedEvent to type that can be sent over network + */ + public WatcherEvent getWrapper() { + return new WatcherEvent(eventType.getIntValue(), + keeperState.getIntValue(), + path); + } +} diff --git a/src/java/main/org/apache/zookeeper/Watcher.java b/src/java/main/org/apache/zookeeper/Watcher.java new file mode 100644 index 00000000000..829e9e23063 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/Watcher.java @@ -0,0 +1,194 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +/** + * This interface specifies the public interface an event handler class must + * implement. A ZooKeeper client will get various events from the ZooKeeper + * server it connects to. An application using such a client handles these + * events by registering a callback object with the client. The callback object + * is expected to be an instance of a class that implements Watcher interface. + * + */ +public interface Watcher { + + abstract public void process(WatchedEvent event); + + /** + * Enumeration of types of watchers + */ + public enum WatcherType { + Children(1), Data(2), Any(3); + + // Integer representation of value + private final int intValue; + + private WatcherType(int intValue) { + this.intValue = intValue; + } + + public static WatcherType fromInt(int intValue) { + switch (intValue) { + case 1: + return WatcherType.Children; + case 2: + return WatcherType.Data; + case 3: + return WatcherType.Any; + + default: + throw new RuntimeException( + "Invalid integer value for conversion to WatcherType"); + } + } + + public int getIntValue() { + return intValue; + } + } + + /** + * This interface defines the possible states an Event may represent + */ + public interface Event { + /** + * Enumeration of states the ZooKeeper may be at the event + */ + public enum KeeperState { + /** Unused, this state is never generated by the server */ + @Deprecated + Unknown(-1), + + /** The client is in the disconnected state - it is not connected + * to any server in the ensemble. */ + Disconnected(0), + + /** Unused, this state is never generated by the server */ + @Deprecated + NoSyncConnected(1), + + /** The client is in the connected state - it is connected + * to a server in the ensemble (one of the servers specified + * in the host connection parameter during ZooKeeper client + * creation). */ + SyncConnected(3), + + /** + * Auth failed state + */ + AuthFailed(4), + + /** + * The client is connected to a read-only server, that is the + * server which is not currently connected to the majority. + * The only operations allowed after receiving this state is + * read operations. + * This state is generated for read-only clients only since + * read/write clients aren't allowed to connect to r/o servers. + */ + ConnectedReadOnly(5), + + /** + * SaslAuthenticated: used to notify clients that they are SASL-authenticated, + * so that they can perform Zookeeper actions with their SASL-authorized permissions. + */ + SaslAuthenticated(6), + + /** The serving cluster has expired this session. The ZooKeeper + * client connection (the session) is no longer valid. You must + * create a new client connection (instantiate a new ZooKeeper + * instance) if you with to access the ensemble. */ + Expired(-112); + + private final int intValue; // Integer representation of value + // for sending over wire + + KeeperState(int intValue) { + this.intValue = intValue; + } + + public static KeeperState fromInt(int intValue) { + switch (intValue) { + case -1: + return KeeperState.Unknown; + case 0: + return KeeperState.Disconnected; + case 1: + return KeeperState.NoSyncConnected; + case 3: + return KeeperState.SyncConnected; + case 4: + return KeeperState.AuthFailed; + case 5: + return KeeperState.ConnectedReadOnly; + case 6: + return KeeperState.SaslAuthenticated; + case -112: + return KeeperState.Expired; + + default: + throw new RuntimeException("Invalid integer value for conversion to KeeperState"); + } + } + + public int getIntValue() { + return intValue; + } + } + + /** + * Enumeration of types of events that may occur on the ZooKeeper + */ + public enum EventType { + None(-1), + NodeCreated(1), + NodeDeleted(2), + NodeDataChanged(3), + NodeChildrenChanged(4), + DataWatchRemoved(5), + ChildWatchRemoved(6); + + private final int intValue; // Integer representation of value + // for sending over wire + + EventType(int intValue) { + this.intValue = intValue; + } + + public static EventType fromInt(int intValue) { + switch (intValue) { + case -1: + return EventType.None; + case 1: + return EventType.NodeCreated; + case 2: + return EventType.NodeDeleted; + case 3: + return EventType.NodeDataChanged; + case 4: + return EventType.NodeChildrenChanged; + case 5: + return EventType.DataWatchRemoved; + case 6: + return EventType.ChildWatchRemoved; + + default: + throw new RuntimeException("Invalid integer value for conversion to EventType"); + } + } + + public int getIntValue() { + return intValue; + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/ZKUtil.java b/src/java/main/org/apache/zookeeper/ZKUtil.java new file mode 100644 index 00000000000..ea2bf6f0992 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ZKUtil.java @@ -0,0 +1,115 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.common.PathUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + +public class ZKUtil { + private static final Logger LOG = LoggerFactory.getLogger(ZKUtil.class); + + /** + * Recursively delete the node with the given path. + *

        + * Important: All versions, of all nodes, under the given node are deleted. + *

        + * If there is an error with deleting one of the sub-nodes in the tree, + * this operation would abort and would be the responsibility of the app to handle the same. + * + * See {@link #delete(String, int)} for more details. + * + * @throws IllegalArgumentException if an invalid path is specified + */ + public static void deleteRecursive(ZooKeeper zk, final String pathRoot) + throws InterruptedException, KeeperException { + PathUtils.validatePath(pathRoot); + + List tree = listSubTreeBFS(zk, pathRoot); + LOG.debug("Deleting " + tree); + LOG.debug("Deleting " + tree.size() + " subnodes "); + for (int i = tree.size() - 1; i >= 0; --i) { + //Delete the leaves first and eventually get rid of the root + zk.delete(tree.get(i), -1); //Delete all versions of the node with -1. + } + } + + + /** + * Recursively delete the node with the given path. (async version). + * + *

        + * Important: All versions, of all nodes, under the given node are deleted. + *

        + * If there is an error with deleting one of the sub-nodes in the tree, + * this operation would abort and would be the responsibility of the app to handle the same. + *

        + * @param zk the zookeeper handle + * @param pathRoot the path to be deleted + * @param cb call back method + * @param ctx the context the callback method is called with + * @throws IllegalArgumentException if an invalid path is specified + */ + public static void deleteRecursive(ZooKeeper zk, final String pathRoot, VoidCallback cb, + Object ctx) + throws InterruptedException, KeeperException { + PathUtils.validatePath(pathRoot); + + List tree = listSubTreeBFS(zk, pathRoot); + LOG.debug("Deleting " + tree); + LOG.debug("Deleting " + tree.size() + " subnodes "); + for (int i = tree.size() - 1; i >= 0; --i) { + //Delete the leaves first and eventually get rid of the root + zk.delete(tree.get(i), -1, cb, ctx); //Delete all versions of the node with -1. + } + } + + /** + * BFS Traversal of the system under pathRoot, with the entries in the list, in the + * same order as that of the traversal. + *

        + * Important: This is not an atomic snapshot of the tree ever, but the + * state as it exists across multiple RPCs from zkClient to the ensemble. + * For practical purposes, it is suggested to bring the clients to the ensemble + * down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior. + * + * @param zk the zookeeper handle + * @param pathRoot The znode path, for which the entire subtree needs to be listed. + * @throws InterruptedException + * @throws KeeperException + */ + public static List listSubTreeBFS(ZooKeeper zk, final String pathRoot) throws + KeeperException, InterruptedException { + Deque queue = new LinkedList(); + List tree = new ArrayList(); + queue.add(pathRoot); + tree.add(pathRoot); + while (true) { + String node = queue.pollFirst(); + if (node == null) { + break; + } + List children = zk.getChildren(node, false); + for (final String child : children) { + final String childPath = node + "/" + child; + queue.add(childPath); + tree.add(childPath); + } + } + return tree; + } +} \ No newline at end of file diff --git a/zookeeper/java/src/com/yahoo/zookeeper/ZooDefs.java b/src/java/main/org/apache/zookeeper/ZooDefs.java old mode 100755 new mode 100644 similarity index 53% rename from zookeeper/java/src/com/yahoo/zookeeper/ZooDefs.java rename to src/java/main/org/apache/zookeeper/ZooDefs.java index 545d12f6c03..96d01aaf348 --- a/zookeeper/java/src/com/yahoo/zookeeper/ZooDefs.java +++ b/src/java/main/org/apache/zookeeper/ZooDefs.java @@ -1,28 +1,29 @@ -/* - * Copyright 2008, Yahoo! Inc. +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.zookeeper; +package org.apache.zookeeper; + +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; import java.util.ArrayList; import java.util.Collections; -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Id; - public class ZooDefs { + + final public static String CONFIG_NODE = "/zookeeper/config"; + final public static String[] opNames = {"notification", "create", + "delete", "exists", "getData", "setData", "getACL", "setACL", + "getChildren", "getChildren2", "getMaxChildren", "setMaxChildren", "ping", "reconfig", "getConfig"}; + public interface OpCode { public final int notification = 0; @@ -42,10 +43,34 @@ public interface OpCode { public final int getChildren = 8; + public final int sync = 9; + public final int ping = 11; + public final int getChildren2 = 12; + + public final int check = 13; + + public final int multi = 14; + + public final int create2 = 15; + + public final int reconfig = 16; + + public final int checkWatches = 17; + + public final int removeWatches = 18; + + public final int createContainer = 19; + + public final int deleteContainer = 20; + public final int auth = 100; + public final int setWatches = 101; + + public final int sasl = 102; + public final int createSession = -10; public final int closeSession = -11; @@ -53,12 +78,6 @@ public interface OpCode { public final int error = -1; } - public interface CreateFlags { - int EPHEMERAL = 1 << 0; - - int SEQUENCE = 1 << 1; - } - public interface Perms { int READ = 1 << 0; @@ -70,7 +89,7 @@ public interface Perms { int ADMIN = 1 << 4; - int ALL = READ | WRITE | CREATE | DELETE; + int ALL = READ | WRITE | CREATE | DELETE | ADMIN; } public interface Ids { @@ -86,7 +105,7 @@ public interface Ids { public final Id AUTH_IDS = new Id("auth", ""); /** - * This is a completely open ACL with the exception of ADMIN permission. + * This is a completely open ACL . */ public final ArrayList OPEN_ACL_UNSAFE = new ArrayList( Collections.singletonList(new ACL(Perms.ALL, ANYONE_ID_UNSAFE))); @@ -95,8 +114,7 @@ public interface Ids { * This ACL gives the creators authentication id's all permissions. */ public final ArrayList CREATOR_ALL_ACL = new ArrayList( - Collections.singletonList(new ACL(Perms.ALL | Perms.ADMIN, - AUTH_IDS))); + Collections.singletonList(new ACL(Perms.ALL, AUTH_IDS))); /** * This ACL gives the world the ability to read. @@ -105,8 +123,4 @@ public interface Ids { Collections .singletonList(new ACL(Perms.READ, ANYONE_ID_UNSAFE))); } - - final public static String[] opNames = { "notification", "create", - "delete", "exists", "getData", "setData", "getACL", "setACL", - "getChildren", "getMaxChildren", "setMaxChildren", "ping" }; } diff --git a/src/java/main/org/apache/zookeeper/ZooKeeper.java b/src/java/main/org/apache/zookeeper/ZooKeeper.java new file mode 100644 index 00000000000..7a5c0cab3d1 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ZooKeeper.java @@ -0,0 +1,2700 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.Record; +import org.apache.zookeeper.AsyncCallback.ACLCallback; +import org.apache.zookeeper.AsyncCallback.Children2Callback; +import org.apache.zookeeper.AsyncCallback.ChildrenCallback; +import org.apache.zookeeper.AsyncCallback.Create2Callback; +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.AsyncCallback.MultiCallback; +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.AsyncCallback.StringCallback; +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.KeeperException.NoWatcherException; +import org.apache.zookeeper.OpResult.ErrorResult; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.client.ConnectStringParser; +import org.apache.zookeeper.client.HostProvider; +import org.apache.zookeeper.client.StaticHostProvider; +import org.apache.zookeeper.client.ZooKeeperSaslClient; +import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.common.StringUtils; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.proto.CheckWatchesRequest; +import org.apache.zookeeper.proto.Create2Response; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.proto.CreateResponse; +import org.apache.zookeeper.proto.DeleteRequest; +import org.apache.zookeeper.proto.ExistsRequest; +import org.apache.zookeeper.proto.GetACLRequest; +import org.apache.zookeeper.proto.GetACLResponse; +import org.apache.zookeeper.proto.GetChildren2Request; +import org.apache.zookeeper.proto.GetChildren2Response; +import org.apache.zookeeper.proto.GetChildrenRequest; +import org.apache.zookeeper.proto.GetChildrenResponse; +import org.apache.zookeeper.proto.GetDataRequest; +import org.apache.zookeeper.proto.GetDataResponse; +import org.apache.zookeeper.proto.ReconfigRequest; +import org.apache.zookeeper.proto.RemoveWatchesRequest; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; +import org.apache.zookeeper.proto.SetACLRequest; +import org.apache.zookeeper.proto.SetACLResponse; +import org.apache.zookeeper.proto.SetDataRequest; +import org.apache.zookeeper.proto.SetDataResponse; +import org.apache.zookeeper.proto.SyncRequest; +import org.apache.zookeeper.proto.SyncResponse; +import org.apache.zookeeper.server.DataTree; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * This is the main class of ZooKeeper client library. To use a ZooKeeper + * service, an application must first instantiate an object of ZooKeeper class. + * All the iterations will be done by calling the methods of ZooKeeper class. + * The methods of this class are thread-safe unless otherwise noted. + *

        + * Once a connection to a server is established, a session ID is assigned to the + * client. The client will send heart beats to the server periodically to keep + * the session valid. + *

        + * The application can call ZooKeeper APIs through a client as long as the + * session ID of the client remains valid. + *

        + * If for some reason, the client fails to send heart beats to the server for a + * prolonged period of time (exceeding the sessionTimeout value, for instance), + * the server will expire the session, and the session ID will become invalid. + * The client object will no longer be usable. To make ZooKeeper API calls, the + * application must create a new client object. + *

        + * If the ZooKeeper server the client currently connects to fails or otherwise + * does not respond, the client will automatically try to connect to another + * server before its session ID expires. If successful, the application can + * continue to use the client. + *

        + * The ZooKeeper API methods are either synchronous or asynchronous. Synchronous + * methods blocks until the server has responded. Asynchronous methods just queue + * the request for sending and return immediately. They take a callback object that + * will be executed either on successful execution of the request or on error with + * an appropriate return code (rc) indicating the error. + *

        + * Some successful ZooKeeper API calls can leave watches on the "data nodes" in + * the ZooKeeper server. Other successful ZooKeeper API calls can trigger those + * watches. Once a watch is triggered, an event will be delivered to the client + * which left the watch at the first place. Each watch can be triggered only + * once. Thus, up to one event will be delivered to a client for every watch it + * leaves. + *

        + * A client needs an object of a class implementing Watcher interface for + * processing the events delivered to the client. + * + * When a client drops current connection and re-connects to a server, all the + * existing watches are considered as being triggered but the undelivered events + * are lost. To emulate this, the client will generate a special event to tell + * the event handler a connection has been dropped. This special event has type + * EventNone and state sKeeperStateDisconnected. + * + */ +public class ZooKeeper { + + public static final String ZOOKEEPER_CLIENT_CNXN_SOCKET = "zookeeper.clientCnxnSocket"; + // Setting this to "true" will enable encrypted client-server communication. + public static final String SECURE_CLIENT = "zookeeper.client.secure"; + private static final Logger LOG; + + static { + //Keep these two lines together to keep the initialization order explicit + LOG = LoggerFactory.getLogger(ZooKeeper.class); + Environment.logEnv("Client environment:", LOG); + } + + protected final ClientCnxn cnxn; + private final HostProvider hostProvider; + private final ZKWatchManager watchManager; + + /** + * To create a ZooKeeper client object, the application needs to pass a + * connection string containing a comma separated list of host:port pairs, + * each corresponding to a ZooKeeper server. + *

        + * Session establishment is asynchronous. This constructor will initiate + * connection to the server and return immediately - potentially (usually) + * before the session is fully established. The watcher argument specifies + * the watcher that will be notified of any changes in state. This + * notification can come at any point before or after the constructor call + * has returned. + *

        + * The instantiated ZooKeeper client object will pick an arbitrary server + * from the connectString and attempt to connect to it. If establishment of + * the connection fails, another server in the connect string will be tried + * (the order is non-deterministic, as we random shuffle the list), until a + * connection is established. The client will continue attempts until the + * session is explicitly closed. + *

        + * Added in 3.2.0: An optional "chroot" suffix may also be appended to the + * connection string. This will run the client commands while interpreting + * all paths relative to this root (similar to the unix chroot command). + * + * @param connectString + * comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + * the optional chroot suffix is used the example would look + * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + * where the client would be rooted at "/app/a" and all paths + * would be relative to this root - ie getting/setting/etc... + * "/foo/bar" would result in operations being run on + * "/app/a/foo/bar" (from the server perspective). + * @param sessionTimeout + * session timeout in milliseconds + * @param watcher + * a watcher object which will be notified of state changes, may + * also be notified for node events + * + * @throws IOException + * in cases of network failure + * @throws IllegalArgumentException + * if an invalid chroot path is specified + */ + public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher) + throws IOException { + this(connectString, sessionTimeout, watcher, false); + } + + /** + * To create a ZooKeeper client object, the application needs to pass a + * connection string containing a comma separated list of host:port pairs, + * each corresponding to a ZooKeeper server. + *

        + * Session establishment is asynchronous. This constructor will initiate + * connection to the server and return immediately - potentially (usually) + * before the session is fully established. The watcher argument specifies + * the watcher that will be notified of any changes in state. This + * notification can come at any point before or after the constructor call + * has returned. + *

        + * The instantiated ZooKeeper client object will pick an arbitrary server + * from the connectString and attempt to connect to it. If establishment of + * the connection fails, another server in the connect string will be tried + * (the order is non-deterministic, as we random shuffle the list), until a + * connection is established. The client will continue attempts until the + * session is explicitly closed. + *

        + * Added in 3.2.0: An optional "chroot" suffix may also be appended to the + * connection string. This will run the client commands while interpreting + * all paths relative to this root (similar to the unix chroot command). + *

        + * For backward compatibility, there is another version + * {@link #ZooKeeper(String, int, Watcher, boolean)} which uses + * default {@link StaticHostProvider} + * + * @param connectString + * comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + * the optional chroot suffix is used the example would look + * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + * where the client would be rooted at "/app/a" and all paths + * would be relative to this root - ie getting/setting/etc... + * "/foo/bar" would result in operations being run on + * "/app/a/foo/bar" (from the server perspective). + * @param sessionTimeout + * session timeout in milliseconds + * @param watcher + * a watcher object which will be notified of state changes, may + * also be notified for node events + * @param canBeReadOnly + * (added in 3.4) whether the created client is allowed to go to + * read-only mode in case of partitioning. Read-only mode + * basically means that if the client can't find any majority + * servers but there's partitioned server it could reach, it + * connects to one in read-only mode, i.e. read requests are + * allowed while write requests are not. It continues seeking for + * majority in the background. + * @param aHostProvider + * use this as HostProvider to enable custom behaviour. + * + * @throws IOException + * in cases of network failure + * @throws IllegalArgumentException + * if an invalid chroot path is specified + */ + public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher, + boolean canBeReadOnly, HostProvider aHostProvider) + throws IOException { + LOG.info("Initiating client connection, connectString=" + connectString + + " sessionTimeout=" + sessionTimeout + " watcher=" + watcher); + + watchManager = defaultWatchManager(); + watchManager.defaultWatcher = watcher; + + ConnectStringParser connectStringParser = new ConnectStringParser( + connectString); + hostProvider = aHostProvider; + + cnxn = new ClientCnxn(connectStringParser.getChrootPath(), + hostProvider, sessionTimeout, this, watchManager, + getClientCnxnSocket(), canBeReadOnly); + cnxn.start(); + } + + /** + * To create a ZooKeeper client object, the application needs to pass a + * connection string containing a comma separated list of host:port pairs, + * each corresponding to a ZooKeeper server. + *

        + * Session establishment is asynchronous. This constructor will initiate + * connection to the server and return immediately - potentially (usually) + * before the session is fully established. The watcher argument specifies + * the watcher that will be notified of any changes in state. This + * notification can come at any point before or after the constructor call + * has returned. + *

        + * The instantiated ZooKeeper client object will pick an arbitrary server + * from the connectString and attempt to connect to it. If establishment of + * the connection fails, another server in the connect string will be tried + * (the order is non-deterministic, as we random shuffle the list), until a + * connection is established. The client will continue attempts until the + * session is explicitly closed. + *

        + * Added in 3.2.0: An optional "chroot" suffix may also be appended to the + * connection string. This will run the client commands while interpreting + * all paths relative to this root (similar to the unix chroot command). + *

        + * + * @param connectString + * comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If + * the optional chroot suffix is used the example would look + * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + * where the client would be rooted at "/app/a" and all paths + * would be relative to this root - ie getting/setting/etc... + * "/foo/bar" would result in operations being run on + * "/app/a/foo/bar" (from the server perspective). + * @param sessionTimeout + * session timeout in milliseconds + * @param watcher + * a watcher object which will be notified of state changes, may + * also be notified for node events + * @param canBeReadOnly + * (added in 3.4) whether the created client is allowed to go to + * read-only mode in case of partitioning. Read-only mode + * basically means that if the client can't find any majority + * servers but there's partitioned server it could reach, it + * connects to one in read-only mode, i.e. read requests are + * allowed while write requests are not. It continues seeking for + * majority in the background. + * + * @throws IOException + * in cases of network failure + * @throws IllegalArgumentException + * if an invalid chroot path is specified + */ + public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher, + boolean canBeReadOnly) throws IOException { + this(connectString, sessionTimeout, watcher, canBeReadOnly, + createDefaultHostProvider(connectString)); + } + + /** + * To create a ZooKeeper client object, the application needs to pass a + * connection string containing a comma separated list of host:port pairs, + * each corresponding to a ZooKeeper server. + *

        + * Session establishment is asynchronous. This constructor will initiate + * connection to the server and return immediately - potentially (usually) + * before the session is fully established. The watcher argument specifies + * the watcher that will be notified of any changes in state. This + * notification can come at any point before or after the constructor call + * has returned. + *

        + * The instantiated ZooKeeper client object will pick an arbitrary server + * from the connectString and attempt to connect to it. If establishment of + * the connection fails, another server in the connect string will be tried + * (the order is non-deterministic, as we random shuffle the list), until a + * connection is established. The client will continue attempts until the + * session is explicitly closed (or the session is expired by the server). + *

        + * Added in 3.2.0: An optional "chroot" suffix may also be appended to the + * connection string. This will run the client commands while interpreting + * all paths relative to this root (similar to the unix chroot command). + *

        + * Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + * client connection, these values must be passed as sessionId and + * sessionPasswd respectively if reconnecting. Otherwise, if not + * reconnecting, use the other constructor which does not require these + * parameters. + * + * @param connectString + * comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + * If the optional chroot suffix is used the example would look + * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + * where the client would be rooted at "/app/a" and all paths + * would be relative to this root - ie getting/setting/etc... + * "/foo/bar" would result in operations being run on + * "/app/a/foo/bar" (from the server perspective). + * @param sessionTimeout + * session timeout in milliseconds + * @param watcher + * a watcher object which will be notified of state changes, may + * also be notified for node events + * @param sessionId + * specific session id to use if reconnecting + * @param sessionPasswd + * password for this session + * + * @throws IOException in cases of network failure + * @throws IllegalArgumentException if an invalid chroot path is specified + * @throws IllegalArgumentException for an invalid list of ZooKeeper hosts + */ + public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher, + long sessionId, byte[] sessionPasswd) + throws IOException { + this(connectString, sessionTimeout, watcher, sessionId, sessionPasswd, false); + } + + /** + * To create a ZooKeeper client object, the application needs to pass a + * connection string containing a comma separated list of host:port pairs, + * each corresponding to a ZooKeeper server. + *

        + * Session establishment is asynchronous. This constructor will initiate + * connection to the server and return immediately - potentially (usually) + * before the session is fully established. The watcher argument specifies + * the watcher that will be notified of any changes in state. This + * notification can come at any point before or after the constructor call + * has returned. + *

        + * The instantiated ZooKeeper client object will pick an arbitrary server + * from the connectString and attempt to connect to it. If establishment of + * the connection fails, another server in the connect string will be tried + * (the order is non-deterministic, as we random shuffle the list), until a + * connection is established. The client will continue attempts until the + * session is explicitly closed (or the session is expired by the server). + *

        + * Added in 3.2.0: An optional "chroot" suffix may also be appended to the + * connection string. This will run the client commands while interpreting + * all paths relative to this root (similar to the unix chroot command). + *

        + * Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + * client connection, these values must be passed as sessionId and + * sessionPasswd respectively if reconnecting. Otherwise, if not + * reconnecting, use the other constructor which does not require these + * parameters. + *

        + * For backward compatibility, there is another version + * {@link #ZooKeeper(String, int, Watcher, long, byte[], boolean)} which uses + * default {@link StaticHostProvider} + * + * @param connectString + * comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + * If the optional chroot suffix is used the example would look + * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + * where the client would be rooted at "/app/a" and all paths + * would be relative to this root - ie getting/setting/etc... + * "/foo/bar" would result in operations being run on + * "/app/a/foo/bar" (from the server perspective). + * @param sessionTimeout + * session timeout in milliseconds + * @param watcher + * a watcher object which will be notified of state changes, may + * also be notified for node events + * @param sessionId + * specific session id to use if reconnecting + * @param sessionPasswd + * password for this session + * @param canBeReadOnly + * (added in 3.4) whether the created client is allowed to go to + * read-only mode in case of partitioning. Read-only mode + * basically means that if the client can't find any majority + * servers but there's partitioned server it could reach, it + * connects to one in read-only mode, i.e. read requests are + * allowed while write requests are not. It continues seeking for + * majority in the background. + * @param aHostProvider + * use this as HostProvider to enable custom behaviour. + * @throws IOException in cases of network failure + * @throws IllegalArgumentException if an invalid chroot path is specified + */ + public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher, + long sessionId, byte[] sessionPasswd, boolean canBeReadOnly, + HostProvider aHostProvider) throws IOException { + LOG.info("Initiating client connection, connectString=" + connectString + + " sessionTimeout=" + sessionTimeout + + " watcher=" + watcher + + " sessionId=" + Long.toHexString(sessionId) + + " sessionPasswd=" + + (sessionPasswd == null ? "" : "")); + + watchManager = defaultWatchManager(); + watchManager.defaultWatcher = watcher; + + ConnectStringParser connectStringParser = new ConnectStringParser( + connectString); + hostProvider = aHostProvider; + + cnxn = new ClientCnxn(connectStringParser.getChrootPath(), + hostProvider, sessionTimeout, this, watchManager, + getClientCnxnSocket(), sessionId, sessionPasswd, canBeReadOnly); + cnxn.seenRwServerBefore = true; // since user has provided sessionId + cnxn.start(); + } + + /** + * To create a ZooKeeper client object, the application needs to pass a + * connection string containing a comma separated list of host:port pairs, + * each corresponding to a ZooKeeper server. + *

        + * Session establishment is asynchronous. This constructor will initiate + * connection to the server and return immediately - potentially (usually) + * before the session is fully established. The watcher argument specifies + * the watcher that will be notified of any changes in state. This + * notification can come at any point before or after the constructor call + * has returned. + *

        + * The instantiated ZooKeeper client object will pick an arbitrary server + * from the connectString and attempt to connect to it. If establishment of + * the connection fails, another server in the connect string will be tried + * (the order is non-deterministic, as we random shuffle the list), until a + * connection is established. The client will continue attempts until the + * session is explicitly closed (or the session is expired by the server). + *

        + * Added in 3.2.0: An optional "chroot" suffix may also be appended to the + * connection string. This will run the client commands while interpreting + * all paths relative to this root (similar to the unix chroot command). + *

        + * Use {@link #getSessionId} and {@link #getSessionPasswd} on an established + * client connection, these values must be passed as sessionId and + * sessionPasswd respectively if reconnecting. Otherwise, if not + * reconnecting, use the other constructor which does not require these + * parameters. + *

        + * This constructor uses a StaticHostProvider; there is another one + * to enable custom behaviour. + * + * @param connectString + * comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + * If the optional chroot suffix is used the example would look + * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + * where the client would be rooted at "/app/a" and all paths + * would be relative to this root - ie getting/setting/etc... + * "/foo/bar" would result in operations being run on + * "/app/a/foo/bar" (from the server perspective). + * @param sessionTimeout + * session timeout in milliseconds + * @param watcher + * a watcher object which will be notified of state changes, may + * also be notified for node events + * @param sessionId + * specific session id to use if reconnecting + * @param sessionPasswd + * password for this session + * @param canBeReadOnly + * (added in 3.4) whether the created client is allowed to go to + * read-only mode in case of partitioning. Read-only mode + * basically means that if the client can't find any majority + * servers but there's partitioned server it could reach, it + * connects to one in read-only mode, i.e. read requests are + * allowed while write requests are not. It continues seeking for + * majority in the background. + * @throws IOException in cases of network failure + * @throws IllegalArgumentException if an invalid chroot path is specified + */ + public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher, + long sessionId, byte[] sessionPasswd, boolean canBeReadOnly) + throws IOException { + this(connectString, sessionTimeout, watcher, sessionId, sessionPasswd, + canBeReadOnly, createDefaultHostProvider(connectString)); + } + + // default hostprovider + private static HostProvider createDefaultHostProvider(String connectString) { + return new StaticHostProvider( + new ConnectStringParser(connectString).getServerAddresses()); + } + + private static ClientCnxnSocket getClientCnxnSocket() throws IOException { + String clientCnxnSocketName = System + .getProperty(ZOOKEEPER_CLIENT_CNXN_SOCKET); + if (clientCnxnSocketName == null) { + clientCnxnSocketName = ClientCnxnSocketNIO.class.getName(); + } + try { + return (ClientCnxnSocket) Class.forName(clientCnxnSocketName) + .newInstance(); + } catch (Exception e) { + IOException ioe = new IOException("Couldn't instantiate " + + clientCnxnSocketName); + ioe.initCause(e); + throw ioe; + } + } + + /** + * This function allows a client to update the connection string by providing + * a new comma separated list of host:port pairs, each corresponding to a + * ZooKeeper server. + *

        + * The function invokes a + * probabilistic load-balancing algorithm which may cause the client to disconnect from + * its current host with the goal to achieve expected uniform number of connections per server + * in the new list. In case the current host to which the client is connected is not in the new + * list this call will always cause the connection to be dropped. Otherwise, the decision + * is based on whether the number of servers has increased or decreased and by how much. + * For example, if the previous connection string contained 3 hosts and now the list contains + * these 3 hosts and 2 more hosts, 40% of clients connected to each of the 3 hosts will + * move to one of the new hosts in order to balance the load. The algorithm will disconnect + * from the current host with probability 0.4 and in this case cause the client to connect + * to one of the 2 new hosts, chosen at random. + *

        + * If the connection is dropped, the client moves to a special mode "reconfigMode" where he chooses + * a new server to connect to using the probabilistic algorithm. After finding a server, + * or exhausting all servers in the new list after trying all of them and failing to connect, + * the client moves back to the normal mode of operation where it will pick an arbitrary server + * from the connectString and attempt to connect to it. If establishment of + * the connection fails, another server in the connect string will be tried + * (the order is non-deterministic, as we random shuffle the list), until a + * connection is established. The client will continue attempts until the + * session is explicitly closed (or the session is expired by the server). + + * @param connectString + * comma separated host:port pairs, each corresponding to a zk + * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" + * If the optional chroot suffix is used the example would look + * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" + * where the client would be rooted at "/app/a" and all paths + * would be relative to this root - ie getting/setting/etc... + * "/foo/bar" would result in operations being run on + * "/app/a/foo/bar" (from the server perspective). + * + * @throws IOException in cases of network failure + */ + public void updateServerList(String connectString) throws IOException { + ConnectStringParser connectStringParser = new ConnectStringParser(connectString); + Collection serverAddresses = connectStringParser.getServerAddresses(); + + ClientCnxnSocket clientCnxnSocket = cnxn.sendThread.getClientCnxnSocket(); + InetSocketAddress currentHost = (InetSocketAddress) clientCnxnSocket.getRemoteSocketAddress(); + + boolean reconfigMode = hostProvider.updateServerList(serverAddresses, currentHost); + + // cause disconnection - this will cause next to be called + // which will in turn call nextReconfigMode + if (reconfigMode) clientCnxnSocket.testableCloseSocket(); + } + + public ZooKeeperSaslClient getSaslClient() { + return cnxn.zooKeeperSaslClient; + } + + List getDataWatches() { + synchronized (watchManager.dataWatches) { + List rc = new ArrayList(watchManager.dataWatches.keySet()); + return rc; + } + } + + List getExistWatches() { + synchronized (watchManager.existWatches) { + List rc = new ArrayList(watchManager.existWatches.keySet()); + return rc; + } + } + + List getChildWatches() { + synchronized (watchManager.childWatches) { + List rc = new ArrayList(watchManager.childWatches.keySet()); + return rc; + } + } + + // VisibleForTesting + public Testable getTestable() { + return new ZooKeeperTestable(this, cnxn); + } + + /* Useful for testing watch handling behavior */ + protected ZKWatchManager defaultWatchManager() { + return new ZKWatchManager(); + } + + /** + * The session id for this ZooKeeper client instance. The value returned is + * not valid until the client connects to a server and may change after a + * re-connect. + * + * This method is NOT thread safe + * + * @return current session id + */ + public long getSessionId() { + return cnxn.getSessionId(); + } + + /** + * The session password for this ZooKeeper client instance. The value + * returned is not valid until the client connects to a server and may + * change after a re-connect. + * + * This method is NOT thread safe + * + * @return current session password + */ + public byte[] getSessionPasswd() { + return cnxn.getSessionPasswd(); + } + + /** + * The negotiated session timeout for this ZooKeeper client instance. The + * value returned is not valid until the client connects to a server and + * may change after a re-connect. + * + * This method is NOT thread safe + * + * @return current session timeout + */ + public int getSessionTimeout() { + return cnxn.getSessionTimeout(); + } + + /** + * Add the specified scheme:auth information to this connection. + * + * This method is NOT thread safe + * + * @param scheme + * @param auth + */ + public void addAuthInfo(String scheme, byte auth[]) { + cnxn.addAuthInfo(scheme, auth); + } + + /** + * Specify the default watcher for the connection (overrides the one + * specified during construction). + * + * @param watcher + */ + public synchronized void register(Watcher watcher) { + watchManager.defaultWatcher = watcher; + } + + /** + * Close this client object. Once the client is closed, its session becomes + * invalid. All the ephemeral nodes in the ZooKeeper server associated with + * the session will be removed. The watches left on those nodes (and on + * their parents) will be triggered. + * + * @throws InterruptedException + */ + public synchronized void close() throws InterruptedException { + if (!cnxn.getState().isAlive()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Close called on already closed client"); + } + return; + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Closing session: 0x" + Long.toHexString(getSessionId())); + } + + try { + cnxn.close(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Ignoring unexpected exception during close", e); + } + } + + LOG.info("Session: 0x" + Long.toHexString(getSessionId()) + " closed"); + } + + /** + * Prepend the chroot to the client path (if present). The expectation of + * this function is that the client path has been validated before this + * function is called + * @param clientPath path to the node + * @return server view of the path (chroot prepended to client path) + */ + private String prependChroot(String clientPath) { + if (cnxn.chrootPath != null) { + // handle clientPath = "/" + if (clientPath.length() == 1) { + return cnxn.chrootPath; + } + return cnxn.chrootPath + clientPath; + } else { + return clientPath; + } + } + + /** + * Create a node with the given path. The node data will be the given data, + * and node acl will be the given acl. + *

        + * The flags argument specifies whether the created node will be ephemeral + * or not. + *

        + * An ephemeral node will be removed by the ZooKeeper automatically when the + * session associated with the creation of the node expires. + *

        + * The flags argument can also specify to create a sequential node. The + * actual path name of a sequential node will be the given path plus a + * suffix "i" where i is the current sequential number of the node. The sequence + * number is always fixed length of 10 digits, 0 padded. Once + * such a node is created, the sequential number will be incremented by one. + *

        + * If a node with the same actual path already exists in the ZooKeeper, a + * KeeperException with error code KeeperException.NodeExists will be + * thrown. Note that since a different actual path is used for each + * invocation of creating sequential node with the same path argument, the + * call will never throw "file exists" KeeperException. + *

        + * If the parent node does not exist in the ZooKeeper, a KeeperException + * with error code KeeperException.NoNode will be thrown. + *

        + * An ephemeral node cannot have children. If the parent node of the given + * path is ephemeral, a KeeperException with error code + * KeeperException.NoChildrenForEphemerals will be thrown. + *

        + * This operation, if successful, will trigger all the watches left on the + * node of the given path by exists and getData API calls, and the watches + * left on the parent node by getChildren API calls. + *

        + * If a node is created successfully, the ZooKeeper server will trigger the + * watches on the path left by exists calls, and the watches on the parent + * of the node by getChildren calls. + *

        + * The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + * Arrays larger than this will cause a KeeperExecption to be thrown. + * + * @param path + * the path for the node + * @param data + * the initial data for the node + * @param acl + * the acl for the node + * @param createMode + * specifying whether the node to be created is ephemeral + * and/or sequential + * @return the actual path of the created node + * @throws KeeperException if the server returns a non-zero error code + * @throws KeeperException.InvalidACLException if the ACL is invalid, null, or empty + * @throws InterruptedException if the transaction is interrupted + * @throws IllegalArgumentException if an invalid path is specified + */ + public String create(final String path, byte data[], List acl, + CreateMode createMode) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath, createMode.isSequential()); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create); + CreateRequest request = new CreateRequest(); + CreateResponse response = new CreateResponse(); + request.setData(data); + request.setFlags(createMode.toFlag()); + request.setPath(serverPath); + if (acl != null && acl.size() == 0) { + throw new KeeperException.InvalidACLException(); + } + request.setAcl(acl); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + if (cnxn.chrootPath == null) { + return response.getPath(); + } else { + return response.getPath().substring(cnxn.chrootPath.length()); + } + } + + /** + * Create a node with the given path and returns the Stat of that node. The + * node data will be the given data and node acl will be the given acl. + *

        + * The flags argument specifies whether the created node will be ephemeral + * or not. + *

        + * An ephemeral node will be removed by the ZooKeeper automatically when the + * session associated with the creation of the node expires. + *

        + * The flags argument can also specify to create a sequential node. The + * actual path name of a sequential node will be the given path plus a + * suffix "i" where i is the current sequential number of the node. The sequence + * number is always fixed length of 10 digits, 0 padded. Once + * such a node is created, the sequential number will be incremented by one. + *

        + * If a node with the same actual path already exists in the ZooKeeper, a + * KeeperException with error code KeeperException.NodeExists will be + * thrown. Note that since a different actual path is used for each + * invocation of creating sequential node with the same path argument, the + * call will never throw "file exists" KeeperException. + *

        + * If the parent node does not exist in the ZooKeeper, a KeeperException + * with error code KeeperException.NoNode will be thrown. + *

        + * An ephemeral node cannot have children. If the parent node of the given + * path is ephemeral, a KeeperException with error code + * KeeperException.NoChildrenForEphemerals will be thrown. + *

        + * This operation, if successful, will trigger all the watches left on the + * node of the given path by exists and getData API calls, and the watches + * left on the parent node by getChildren API calls. + *

        + * If a node is created successfully, the ZooKeeper server will trigger the + * watches on the path left by exists calls, and the watches on the parent + * of the node by getChildren calls. + *

        + * The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + * Arrays larger than this will cause a KeeperExecption to be thrown. + * + * @param path + * the path for the node + * @param data + * the initial data for the node + * @param acl + * the acl for the node + * @param createMode + * specifying whether the node to be created is ephemeral + * and/or sequential + * @param stat + * The output Stat object. + * @return the actual path of the created node + * @throws KeeperException if the server returns a non-zero error code + * @throws KeeperException.InvalidACLException if the ACL is invalid, null, or empty + * @throws InterruptedException if the transaction is interrupted + * @throws IllegalArgumentException if an invalid path is specified + */ + public String create(final String path, byte data[], List acl, + CreateMode createMode, Stat stat) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath, createMode.isSequential()); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create2); + CreateRequest request = new CreateRequest(); + Create2Response response = new Create2Response(); + request.setData(data); + request.setFlags(createMode.toFlag()); + request.setPath(serverPath); + if (acl != null && acl.size() == 0) { + throw new KeeperException.InvalidACLException(); + } + request.setAcl(acl); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + if (stat != null) { + DataTree.copyStat(response.getStat(), stat); + } + if (cnxn.chrootPath == null) { + return response.getPath(); + } else { + return response.getPath().substring(cnxn.chrootPath.length()); + } + } + + /** + * The asynchronous version of create. + * + * @see #create(String, byte[], List, CreateMode) + */ + public void create(final String path, byte data[], List acl, + CreateMode createMode, StringCallback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath, createMode.isSequential()); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create); + CreateRequest request = new CreateRequest(); + CreateResponse response = new CreateResponse(); + ReplyHeader r = new ReplyHeader(); + request.setData(data); + request.setFlags(createMode.toFlag()); + request.setPath(serverPath); + request.setAcl(acl); + cnxn.queuePacket(h, r, request, response, cb, clientPath, + serverPath, ctx, null); + } + + /** + * The asynchronous version of create. + * + * @see #create(String, byte[], List, CreateMode, Stat) + */ + public void create(final String path, byte data[], List acl, + CreateMode createMode, Create2Callback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath, createMode.isSequential()); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create2); + CreateRequest request = new CreateRequest(); + Create2Response response = new Create2Response(); + ReplyHeader r = new ReplyHeader(); + request.setData(data); + request.setFlags(createMode.toFlag()); + request.setPath(serverPath); + request.setAcl(acl); + cnxn.queuePacket(h, r, request, response, cb, clientPath, + serverPath, ctx, null); + } + + /** + * Delete the node with the given path. The call will succeed if such a node + * exists, and the given version matches the node's version (if the given + * version is -1, it matches any node's versions). + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if the nodes does not exist. + *

        + * A KeeperException with error code KeeperException.BadVersion will be + * thrown if the given version does not match the node's version. + *

        + * A KeeperException with error code KeeperException.NotEmpty will be thrown + * if the node has children. + *

        + * This operation, if successful, will trigger all the watches on the node + * of the given path left by exists API calls, and the watches on the parent + * node left by getChildren API calls. + * + * @param path + * the path of the node to be deleted. + * @param version + * the expected node version. + * @throws InterruptedException IF the server transaction is interrupted + * @throws KeeperException If the server signals an error with a non-zero + * return code. + * @throws IllegalArgumentException if an invalid path is specified + */ + public void delete(final String path, int version) + throws InterruptedException, KeeperException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath; + + // maintain semantics even in chroot case + // specifically - root cannot be deleted + // I think this makes sense even in chroot case. + if (clientPath.equals("/")) { + // a bit of a hack, but delete(/) will never succeed and ensures + // that the same semantics are maintained + serverPath = clientPath; + } else { + serverPath = prependChroot(clientPath); + } + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.delete); + DeleteRequest request = new DeleteRequest(); + request.setPath(serverPath); + request.setVersion(version); + ReplyHeader r = cnxn.submitRequest(h, request, null, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + } + + /** + * Executes multiple ZooKeeper operations or none of them. + *

        + * On success, a list of results is returned. + * On failure, an exception is raised which contains partial results and + * error details, see {@link KeeperException#getResults} + *

        + * Note: The maximum allowable size of all of the data arrays in all of + * the setData operations in this single request is typically 1 MB + * (1,048,576 bytes). This limit is specified on the server via + * jute.maxbuffer. + * Requests larger than this will cause a KeeperException to be + * thrown. + * + * @param ops An iterable that contains the operations to be done. + * These should be created using the factory methods on {@link Op}. + * @return A list of results, one for each input Op, the order of + * which exactly matches the order of the ops input + * operations. + * @throws InterruptedException If the operation was interrupted. + * The operation may or may not have succeeded, but will not have + * partially succeeded if this exception is thrown. + * @throws KeeperException If the operation could not be completed + * due to some error in doing one of the specified ops. + * @throws IllegalArgumentException if an invalid path is specified + * + * @since 3.4.0 + */ + public List multi(Iterable ops) throws InterruptedException, KeeperException { + for (Op op : ops) { + op.validate(); + } + return multiInternal(generateMultiTransaction(ops)); + } + + /** + * The asynchronous version of multi. + * + * @see #multi(Iterable) + */ + public void multi(Iterable ops, MultiCallback cb, Object ctx) { + List results = validatePath(ops); + if (results.size() > 0) { + cb.processResult(KeeperException.Code.BADARGUMENTS.intValue(), + null, ctx, results); + return; + } + multiInternal(generateMultiTransaction(ops), cb, ctx); + } + + private List validatePath(Iterable ops) { + List results = new ArrayList(); + boolean error = false; + for (Op op : ops) { + try { + op.validate(); + } catch (IllegalArgumentException iae) { + LOG.error("IllegalArgumentException: " + iae.getMessage()); + ErrorResult err = new ErrorResult( + KeeperException.Code.BADARGUMENTS.intValue()); + results.add(err); + error = true; + continue; + } catch (KeeperException ke) { + LOG.error("KeeperException: " + ke.getMessage()); + ErrorResult err = new ErrorResult(ke.code().intValue()); + results.add(err); + error = true; + continue; + } + ErrorResult err = new ErrorResult( + KeeperException.Code.RUNTIMEINCONSISTENCY.intValue()); + results.add(err); + } + if (false == error) { + results.clear(); + } + return results; + } + + private MultiTransactionRecord generateMultiTransaction(Iterable ops) { + // reconstructing transaction with the chroot prefix + List transaction = new ArrayList(); + for (Op op : ops) { + transaction.add(withRootPrefix(op)); + } + return new MultiTransactionRecord(transaction); + } + + private Op withRootPrefix(Op op) { + if (null != op.getPath()) { + final String serverPath = prependChroot(op.getPath()); + if (!op.getPath().equals(serverPath)) { + return op.withChroot(serverPath); + } + } + return op; + } + + protected void multiInternal(MultiTransactionRecord request, MultiCallback cb, Object ctx) { + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.multi); + MultiResponse response = new MultiResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, null, null, ctx, null); + } + + protected List multiInternal(MultiTransactionRecord request) + throws InterruptedException, KeeperException { + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.multi); + MultiResponse response = new MultiResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr())); + } + + List results = response.getResultList(); + + ErrorResult fatalError = null; + for (OpResult result : results) { + if (result instanceof ErrorResult && ((ErrorResult) result).getErr() != KeeperException.Code.OK.intValue()) { + fatalError = (ErrorResult) result; + break; + } + } + + if (fatalError != null) { + KeeperException ex = KeeperException.create(KeeperException.Code.get(fatalError.getErr())); + ex.setMultiResults(results); + throw ex; + } + + return results; + } + + /** + * A Transaction is a thin wrapper on the {@link #multi} method + * which provides a builder object that can be used to construct + * and commit an atomic set of operations. + * + * @since 3.4.0 + * + * @return a Transaction builder object + */ + public Transaction transaction() { + return new Transaction(this); + } + + /** + * The asynchronous version of delete. + * + * @see #delete(String, int) + */ + public void delete(final String path, int version, VoidCallback cb, + Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath; + + // maintain semantics even in chroot case + // specifically - root cannot be deleted + // I think this makes sense even in chroot case. + if (clientPath.equals("/")) { + // a bit of a hack, but delete(/) will never succeed and ensures + // that the same semantics are maintained + serverPath = clientPath; + } else { + serverPath = prependChroot(clientPath); + } + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.delete); + DeleteRequest request = new DeleteRequest(); + request.setPath(serverPath); + request.setVersion(version); + cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath, + serverPath, ctx, null); + } + + /** + * Return the stat of the node of the given path. Return null if no such a + * node exists. + *

        + * If the watch is non-null and the call is successful (no exception is thrown), + * a watch will be left on the node with the given path. The watch will be + * triggered by a successful operation that creates/delete the node or sets + * the data on the node. + * + * @param path the node path + * @param watcher explicit watcher + * @return the stat of the node of the given path; return null if no such a + * node exists. + * @throws KeeperException If the server signals an error + * @throws InterruptedException If the server transaction is interrupted. + * @throws IllegalArgumentException if an invalid path is specified + */ + public Stat exists(final String path, Watcher watcher) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new ExistsWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.exists); + ExistsRequest request = new ExistsRequest(); + request.setPath(serverPath); + request.setWatch(watcher != null); + SetDataResponse response = new SetDataResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, wcb); + if (r.getErr() != 0) { + if (r.getErr() == KeeperException.Code.NONODE.intValue()) { + return null; + } + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + + return response.getStat().getCzxid() == -1 ? null : response.getStat(); + } + + /** + * Return the stat of the node of the given path. Return null if no such a + * node exists. + *

        + * If the watch is true and the call is successful (no exception is thrown), + * a watch will be left on the node with the given path. The watch will be + * triggered by a successful operation that creates/delete the node or sets + * the data on the node. + * + * @param path + * the node path + * @param watch + * whether need to watch this node + * @return the stat of the node of the given path; return null if no such a + * node exists. + * @throws KeeperException If the server signals an error + * @throws InterruptedException If the server transaction is interrupted. + */ + public Stat exists(String path, boolean watch) throws KeeperException, + InterruptedException { + return exists(path, watch ? watchManager.defaultWatcher : null); + } + + /** + * The asynchronous version of exists. + * + * @see #exists(String, Watcher) + */ + public void exists(final String path, Watcher watcher, + StatCallback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new ExistsWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.exists); + ExistsRequest request = new ExistsRequest(); + request.setPath(serverPath); + request.setWatch(watcher != null); + SetDataResponse response = new SetDataResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, wcb); + } + + /** + * The asynchronous version of exists. + * + * @see #exists(String, boolean) + */ + public void exists(String path, boolean watch, StatCallback cb, Object ctx) { + exists(path, watch ? watchManager.defaultWatcher : null, cb, ctx); + } + + /** + * Return the data and the stat of the node of the given path. + *

        + * If the watch is non-null and the call is successful (no exception is + * thrown), a watch will be left on the node with the given path. The watch + * will be triggered by a successful operation that sets data on the node, or + * deletes the node. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @param path the given path + * @param watcher explicit watcher + * @param stat the stat of the node + * @return the data of the node + * @throws KeeperException If the server signals an error with a non-zero error code + * @throws InterruptedException If the server transaction is interrupted. + * @throws IllegalArgumentException if an invalid path is specified + */ + public byte[] getData(final String path, Watcher watcher, Stat stat) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new DataWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getData); + GetDataRequest request = new GetDataRequest(); + request.setPath(serverPath); + request.setWatch(watcher != null); + GetDataResponse response = new GetDataResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, wcb); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + if (stat != null) { + DataTree.copyStat(response.getStat(), stat); + } + return response.getData(); + } + + /** + * Return the data and the stat of the node of the given path. + *

        + * If the watch is true and the call is successful (no exception is + * thrown), a watch will be left on the node with the given path. The watch + * will be triggered by a successful operation that sets data on the node, or + * deletes the node. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @param path the given path + * @param watch whether need to watch this node + * @param stat the stat of the node + * @return the data of the node + * @throws KeeperException If the server signals an error with a non-zero error code + * @throws InterruptedException If the server transaction is interrupted. + */ + public byte[] getData(String path, boolean watch, Stat stat) + throws KeeperException, InterruptedException { + return getData(path, watch ? watchManager.defaultWatcher : null, stat); + } + + /** + * The asynchronous version of getData. + * + * @see #getData(String, Watcher, Stat) + */ + public void getData(final String path, Watcher watcher, + DataCallback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new DataWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getData); + GetDataRequest request = new GetDataRequest(); + request.setPath(serverPath); + request.setWatch(watcher != null); + GetDataResponse response = new GetDataResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, wcb); + } + + /** + * The asynchronous version of getData. + * + * @see #getData(String, boolean, Stat) + */ + public void getData(String path, boolean watch, DataCallback cb, Object ctx) { + getData(path, watch ? watchManager.defaultWatcher : null, cb, ctx); + } + + /** + * Return the last committed configuration (as known to the server to which the client is connected) + * and the stat of the configuration. + *

        + * If the watch is non-null and the call is successful (no exception is + * thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch + * will be triggered by a successful reconfig operation + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if the configuration node doesn't exists. + * + * @param watcher explicit watcher + * @param stat the stat of the configuration node ZooDefs.CONFIG_NODE + * @return configuration data stored in ZooDefs.CONFIG_NODE + * @throws KeeperException If the server signals an error with a non-zero error code + * @throws InterruptedException If the server transaction is interrupted. + */ + public byte[] getConfig(Watcher watcher, Stat stat) + throws KeeperException, InterruptedException { + final String configZnode = ZooDefs.CONFIG_NODE; + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new DataWatchRegistration(watcher, configZnode); + } + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getData); + GetDataRequest request = new GetDataRequest(); + request.setPath(configZnode); + request.setWatch(watcher != null); + GetDataResponse response = new GetDataResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, wcb); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + configZnode); + } + if (stat != null) { + DataTree.copyStat(response.getStat(), stat); + } + return response.getData(); + } + + /** + * The asynchronous version of getConfig. + * + * @see #getConfig(Watcher, Stat) + */ + public void getConfig(Watcher watcher, + DataCallback cb, Object ctx) { + final String configZnode = ZooDefs.CONFIG_NODE; + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new DataWatchRegistration(watcher, configZnode); + } + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getData); + GetDataRequest request = new GetDataRequest(); + request.setPath(configZnode); + request.setWatch(watcher != null); + GetDataResponse response = new GetDataResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + configZnode, configZnode, ctx, wcb); + } + + /** + * Return the last committed configuration (as known to the server to which the client is connected) + * and the stat of the configuration. + *

        + * If the watch is true and the call is successful (no exception is + * thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch + * will be triggered by a successful reconfig operation + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @param watch whether need to watch this node + * @param stat the stat of the configuration node ZooDefs.CONFIG_NODE + * @return configuration data stored in ZooDefs.CONFIG_NODE + * @throws KeeperException If the server signals an error with a non-zero error code + * @throws InterruptedException If the server transaction is interrupted. + */ + public byte[] getConfig(boolean watch, Stat stat) + throws KeeperException, InterruptedException { + return getConfig(watch ? watchManager.defaultWatcher : null, stat); + } + + /** + * The Asynchronous version of getConfig. + * + * @see #getData(String, boolean, Stat) + */ + public void getConfig(boolean watch, DataCallback cb, Object ctx) { + getConfig(watch ? watchManager.defaultWatcher : null, cb, ctx); + } + + /** + * Reconfigure - add/remove servers. Return the new configuration. + * @param joiningServers + * a comma separated list of servers being added (incremental reconfiguration) + * @param leavingServers + * a comma separated list of servers being removed (incremental reconfiguration) + * @param newMembers + * a comma separated list of new membership (non-incremental reconfiguration) + * @param fromConfig + * version of the current configuration (optional - causes reconfiguration to throw an exception if configuration is no longer current) + * @param stat the stat of /zookeeper/config znode will be copied to this + * parameter if not null. + * @return new configuration + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero error code. + */ + public byte[] reconfig(String joiningServers, String leavingServers, String newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.reconfig); + ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig); + GetDataResponse response = new GetDataResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), ""); + } + if (stat != null) { + DataTree.copyStat(response.getStat(), stat); + } + return response.getData(); + } + + /** + * Convenience wrapper around reconfig that takes Lists of strings instead of comma-separated servers. + * + * @see #reconfig + * + */ + public byte[] reconfig(List joiningServers, List leavingServers, List newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { + return reconfig(StringUtils.joinStrings(joiningServers, ","), + StringUtils.joinStrings(leavingServers, ","), + StringUtils.joinStrings(newMembers, ","), + fromConfig, stat); + } + + /** + * The Asynchronous version of reconfig. + * + * @see #reconfig + * + **/ + public void reconfig(String joiningServers, String leavingServers, + String newMembers, long fromConfig, DataCallback cb, Object ctx) { + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.reconfig); + ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig); + GetDataResponse response = new GetDataResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + ZooDefs.CONFIG_NODE, ZooDefs.CONFIG_NODE, ctx, null); + } + + /** + * Convenience wrapper around asynchronous reconfig that takes Lists of strings instead of comma-separated servers. + * + * @see #reconfig + * + */ + public void reconfig(List joiningServers, + List leavingServers, List newMembers, long fromConfig, + DataCallback cb, Object ctx) { + reconfig(StringUtils.joinStrings(joiningServers, ","), + StringUtils.joinStrings(leavingServers, ","), + StringUtils.joinStrings(newMembers, ","), + fromConfig, cb, ctx); + } + + /** + * Set the data for the node of the given path if such a node exists and the + * given version matches the version of the node (if the given version is + * -1, it matches any node's versions). Return the stat of the node. + *

        + * This operation, if successful, will trigger all the watches on the node + * of the given path left by getData calls. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + *

        + * A KeeperException with error code KeeperException.BadVersion will be + * thrown if the given version does not match the node's version. + *

        + * The maximum allowable size of the data array is 1 MB (1,048,576 bytes). + * Arrays larger than this will cause a KeeperException to be thrown. + * + * @param path + * the path of the node + * @param data + * the data to set + * @param version + * the expected matching version + * @return the state of the node + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero error code. + * @throws IllegalArgumentException if an invalid path is specified + */ + public Stat setData(final String path, byte data[], int version) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.setData); + SetDataRequest request = new SetDataRequest(); + request.setPath(serverPath); + request.setData(data); + request.setVersion(version); + SetDataResponse response = new SetDataResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + return response.getStat(); + } + + /** + * The asynchronous version of setData. + * + * @see #setData(String, byte[], int) + */ + public void setData(final String path, byte data[], int version, + StatCallback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.setData); + SetDataRequest request = new SetDataRequest(); + request.setPath(serverPath); + request.setData(data); + request.setVersion(version); + SetDataResponse response = new SetDataResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, null); + } + + /** + * Return the ACL and stat of the node of the given path. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @param path + * the given path for the node + * @param stat + * the stat of the node will be copied to this parameter if + * not null. + * @return the ACL array of the given node. + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero error code. + * @throws IllegalArgumentException if an invalid path is specified + */ + public List getACL(final String path, Stat stat) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getACL); + GetACLRequest request = new GetACLRequest(); + request.setPath(serverPath); + GetACLResponse response = new GetACLResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + if (stat != null) { + DataTree.copyStat(response.getStat(), stat); + } + return response.getAcl(); + } + + /** + * The asynchronous version of getACL. + * + * @see #getACL(String, Stat) + */ + public void getACL(final String path, Stat stat, ACLCallback cb, + Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getACL); + GetACLRequest request = new GetACLRequest(); + request.setPath(serverPath); + GetACLResponse response = new GetACLResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, null); + } + + /** + * Set the ACL for the node of the given path if such a node exists and the + * given version matches the version of the node. Return the stat of the + * node. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + *

        + * A KeeperException with error code KeeperException.BadVersion will be + * thrown if the given version does not match the node's version. + * + * @param path + * @param acl + * @param version + * @return the stat of the node. + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero error code. + * @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide. + * @throws IllegalArgumentException if an invalid path is specified + */ + public Stat setACL(final String path, List acl, int version) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.setACL); + SetACLRequest request = new SetACLRequest(); + request.setPath(serverPath); + if (acl != null && acl.size() == 0) { + throw new KeeperException.InvalidACLException(clientPath); + } + request.setAcl(acl); + request.setVersion(version); + SetACLResponse response = new SetACLResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + return response.getStat(); + } + + /** + * The asynchronous version of setACL. + * + * @see #setACL(String, List, int) + */ + public void setACL(final String path, List acl, int version, + StatCallback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.setACL); + SetACLRequest request = new SetACLRequest(); + request.setPath(serverPath); + request.setAcl(acl); + request.setVersion(version); + SetACLResponse response = new SetACLResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, null); + } + + /** + * Return the list of the children of the node of the given path. + *

        + * If the watch is non-null and the call is successful (no exception is thrown), + * a watch will be left on the node with the given path. The watch willbe + * triggered by a successful operation that deletes the node of the given + * path or creates/delete a child under the node. + *

        + * The list of children returned is not sorted and no guarantee is provided + * as to its natural or lexical order. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @param path + * @param watcher explicit watcher + * @return an unordered array of children of the node with the given path + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero error code. + * @throws IllegalArgumentException if an invalid path is specified + */ + public List getChildren(final String path, Watcher watcher) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new ChildWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getChildren); + GetChildrenRequest request = new GetChildrenRequest(); + request.setPath(serverPath); + request.setWatch(watcher != null); + GetChildrenResponse response = new GetChildrenResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, wcb); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + return response.getChildren(); + } + + /** + * Return the list of the children of the node of the given path. + *

        + * If the watch is true and the call is successful (no exception is thrown), + * a watch will be left on the node with the given path. The watch willbe + * triggered by a successful operation that deletes the node of the given + * path or creates/delete a child under the node. + *

        + * The list of children returned is not sorted and no guarantee is provided + * as to its natural or lexical order. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @param path + * @param watch + * @return an unordered array of children of the node with the given path + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero error code. + */ + public List getChildren(String path, boolean watch) + throws KeeperException, InterruptedException { + return getChildren(path, watch ? watchManager.defaultWatcher : null); + } + + /** + * The asynchronous version of getChildren. + * + * @see #getChildren(String, Watcher) + */ + public void getChildren(final String path, Watcher watcher, + ChildrenCallback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new ChildWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getChildren); + GetChildrenRequest request = new GetChildrenRequest(); + request.setPath(serverPath); + request.setWatch(watcher != null); + GetChildrenResponse response = new GetChildrenResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, wcb); + } + + /** + * The asynchronous version of getChildren. + * + * @see #getChildren(String, boolean) + */ + public void getChildren(String path, boolean watch, ChildrenCallback cb, + Object ctx) { + getChildren(path, watch ? watchManager.defaultWatcher : null, cb, ctx); + } + + /** + * For the given znode path return the stat and children list. + *

        + * If the watch is non-null and the call is successful (no exception is thrown), + * a watch will be left on the node with the given path. The watch willbe + * triggered by a successful operation that deletes the node of the given + * path or creates/delete a child under the node. + *

        + * The list of children returned is not sorted and no guarantee is provided + * as to its natural or lexical order. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @since 3.3.0 + * + * @param path + * @param watcher explicit watcher + * @param stat stat of the znode designated by path + * @return an unordered array of children of the node with the given path + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero error code. + * @throws IllegalArgumentException if an invalid path is specified + */ + public List getChildren(final String path, Watcher watcher, + Stat stat) + throws KeeperException, InterruptedException { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new ChildWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getChildren2); + GetChildren2Request request = new GetChildren2Request(); + request.setPath(serverPath); + request.setWatch(watcher != null); + GetChildren2Response response = new GetChildren2Response(); + ReplyHeader r = cnxn.submitRequest(h, request, response, wcb); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + if (stat != null) { + DataTree.copyStat(response.getStat(), stat); + } + return response.getChildren(); + } + + /** + * For the given znode path return the stat and children list. + *

        + * If the watch is true and the call is successful (no exception is thrown), + * a watch will be left on the node with the given path. The watch willbe + * triggered by a successful operation that deletes the node of the given + * path or creates/delete a child under the node. + *

        + * The list of children returned is not sorted and no guarantee is provided + * as to its natural or lexical order. + *

        + * A KeeperException with error code KeeperException.NoNode will be thrown + * if no node with the given path exists. + * + * @since 3.3.0 + * + * @param path + * @param watch + * @param stat stat of the znode designated by path + * @return an unordered array of children of the node with the given path + * @throws InterruptedException If the server transaction is interrupted. + * @throws KeeperException If the server signals an error with a non-zero + * error code. + */ + public List getChildren(String path, boolean watch, Stat stat) + throws KeeperException, InterruptedException { + return getChildren(path, watch ? watchManager.defaultWatcher : null, + stat); + } + + /** + * The asynchronous version of getChildren. + * + * @since 3.3.0 + * + * @see #getChildren(String, Watcher, Stat) + */ + public void getChildren(final String path, Watcher watcher, + Children2Callback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + // the watch contains the un-chroot path + WatchRegistration wcb = null; + if (watcher != null) { + wcb = new ChildWatchRegistration(watcher, clientPath); + } + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.getChildren2); + GetChildren2Request request = new GetChildren2Request(); + request.setPath(serverPath); + request.setWatch(watcher != null); + GetChildren2Response response = new GetChildren2Response(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, wcb); + } + + /** + * The asynchronous version of getChildren. + * + * @since 3.3.0 + * + * @see #getChildren(String, boolean, Stat) + */ + public void getChildren(String path, boolean watch, Children2Callback cb, + Object ctx) { + getChildren(path, watch ? watchManager.defaultWatcher : null, cb, ctx); + } + + /** + * Asynchronous sync. Flushes channel between process and leader. + * @param path + * @param cb a handler for the callback + * @param ctx context to be provided to the callback + * @throws IllegalArgumentException if an invalid path is specified + */ + public void sync(final String path, VoidCallback cb, Object ctx) { + final String clientPath = path; + PathUtils.validatePath(clientPath); + + final String serverPath = prependChroot(clientPath); + + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.sync); + SyncRequest request = new SyncRequest(); + SyncResponse response = new SyncResponse(); + request.setPath(serverPath); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + clientPath, serverPath, ctx, null); + } + + /** + * For the given znode path, removes the specified watcher of given + * watcherType. + * + *

        + * Watcher shouldn't be null. A successful call guarantees that, the + * removed watcher won't be triggered. + *

        + * + * @param path + * - the path of the node + * @param watcher + * - a concrete watcher + * @param watcherType + * - the type of watcher to be removed + * @param local + * - whether the watcher can be removed locally when there is no + * server connection + * @throws InterruptedException + * if the server transaction is interrupted. + * @throws KeeperException.NoWatcherException + * if no watcher exists that match the specified parameters + * @throws KeeperException + * if the server signals an error with a non-zero error code. + * @throws IllegalArgumentException + * if any of the following is true: + *
          + *
        • {@code path} is invalid + *
        • {@code watcher} is null + *
        + * + * @since 3.5.0 + */ + public void removeWatches(String path, Watcher watcher, + WatcherType watcherType, boolean local) + throws InterruptedException, KeeperException { + validateWatcher(watcher); + removeWatches(ZooDefs.OpCode.checkWatches, path, watcher, + watcherType, local); + } + + /** + * The asynchronous version of removeWatches. + * + * @see #removeWatches + */ + public void removeWatches(String path, Watcher watcher, + WatcherType watcherType, boolean local, VoidCallback cb, Object ctx) { + validateWatcher(watcher); + removeWatches(ZooDefs.OpCode.checkWatches, path, watcher, + watcherType, local, cb, ctx); + } + + /** + * For the given znode path, removes all the registered watchers of given + * watcherType. + * + *

        + * A successful call guarantees that, the removed watchers won't be + * triggered. + *

        + * + * @param path + * - the path of the node + * @param watcherType + * - the type of watcher to be removed + * @param local + * - whether watches can be removed locally when there is no + * server connection + * @throws InterruptedException + * if the server transaction is interrupted. + * @throws KeeperException.NoWatcherException + * if no watcher exists that match the specified parameters + * @throws KeeperException + * if the server signals an error with a non-zero error code. + * @throws IllegalArgumentException + * if an invalid {@code path} is specified + * + * @since 3.5.0 + */ + public void removeAllWatches(String path, WatcherType watcherType, + boolean local) throws InterruptedException, KeeperException { + + removeWatches(ZooDefs.OpCode.removeWatches, path, null, watcherType, + local); + } + + /** + * The asynchronous version of removeAllWatches. + * + * @see #removeAllWatches + */ + public void removeAllWatches(String path, WatcherType watcherType, + boolean local, VoidCallback cb, Object ctx) { + + removeWatches(ZooDefs.OpCode.removeWatches, path, null, + watcherType, local, cb, ctx); + } + + private void validateWatcher(Watcher watcher) { + if (watcher == null) { + throw new IllegalArgumentException( + "Invalid Watcher, shouldn't be null!"); + } + } + + private void removeWatches(int opCode, String path, Watcher watcher, + WatcherType watcherType, boolean local) + throws InterruptedException, KeeperException { + PathUtils.validatePath(path); + final String clientPath = path; + final String serverPath = prependChroot(clientPath); + WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher, + watcherType, local, watchManager); + + RequestHeader h = new RequestHeader(); + h.setType(opCode); + Record request = getRemoveWatchesRequest(opCode, watcherType, + serverPath); + + ReplyHeader r = cnxn.submitRequest(h, request, null, null, wcb); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), + clientPath); + } + } + + private void removeWatches(int opCode, String path, Watcher watcher, + WatcherType watcherType, boolean local, VoidCallback cb, Object ctx) { + PathUtils.validatePath(path); + final String clientPath = path; + final String serverPath = prependChroot(clientPath); + WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher, + watcherType, local, watchManager); + + RequestHeader h = new RequestHeader(); + h.setType(opCode); + Record request = getRemoveWatchesRequest(opCode, watcherType, + serverPath); + + cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath, + serverPath, ctx, null, wcb); + } + + private Record getRemoveWatchesRequest(int opCode, WatcherType watcherType, + final String serverPath) { + Record request = null; + switch (opCode) { + case ZooDefs.OpCode.checkWatches: + CheckWatchesRequest chkReq = new CheckWatchesRequest(); + chkReq.setPath(serverPath); + chkReq.setType(watcherType.getIntValue()); + request = chkReq; + break; + case ZooDefs.OpCode.removeWatches: + RemoveWatchesRequest rmReq = new RemoveWatchesRequest(); + rmReq.setPath(serverPath); + rmReq.setType(watcherType.getIntValue()); + request = rmReq; + break; + default: + LOG.warn("unknown type " + opCode); + break; + } + return request; + } + + public States getState() { + return cnxn.getState(); + } + + /** + * String representation of this ZooKeeper client. Suitable for things + * like logging. + * + * Do NOT count on the format of this string, it may change without + * warning. + * + * @since 3.3.0 + */ + @Override + public String toString() { + States state = getState(); + return ("State:" + state.toString() + + (state.isConnected() ? + " Timeout:" + getSessionTimeout() + " " : + " ") + + cnxn); + } + + /** + * Wait up to wait milliseconds for the underlying threads to shutdown. + * THIS METHOD IS EXPECTED TO BE USED FOR TESTING ONLY!!! + * + * @since 3.3.0 + * + * @param wait max wait in milliseconds + * @return true iff all threads are shutdown, otw false + */ + protected boolean testableWaitForShutdown(int wait) + throws InterruptedException { + cnxn.sendThread.join(wait); + if (cnxn.sendThread.isAlive()) return false; + cnxn.eventThread.join(wait); + if (cnxn.eventThread.isAlive()) return false; + return true; + } + + /** + * Returns the address to which the socket is connected. Useful for testing + * against an ensemble - test client may need to know which server + * to shutdown if interested in verifying that the code handles + * disconnection/reconnection correctly. + * THIS METHOD IS EXPECTED TO BE USED FOR TESTING ONLY!!! + * + * @since 3.3.0 + * + * @return ip address of the remote side of the connection or null if + * not connected + */ + protected SocketAddress testableRemoteSocketAddress() { + return cnxn.sendThread.getClientCnxnSocket().getRemoteSocketAddress(); + } + + /** + * Returns the local address to which the socket is bound. + * THIS METHOD IS EXPECTED TO BE USED FOR TESTING ONLY!!! + * + * @since 3.3.0 + * + * @return ip address of the remote side of the connection or null if + * not connected + */ + protected SocketAddress testableLocalSocketAddress() { + return cnxn.sendThread.getClientCnxnSocket().getLocalSocketAddress(); + } + + public enum States { + CONNECTING, ASSOCIATING, CONNECTED, CONNECTEDREADONLY, + CLOSED, AUTH_FAILED, NOT_CONNECTED; + + public boolean isAlive() { + return this != CLOSED && this != AUTH_FAILED; + } + + /** + * Returns whether we are connected to a server (which + * could possibly be read-only, if this client is allowed + * to go to read-only mode) + * */ + public boolean isConnected() { + return this == CONNECTED || this == CONNECTEDREADONLY; + } + } + + /** + * Manage watchers & handle events generated by the ClientCnxn object. + * + * We are implementing this as a nested class of ZooKeeper so that + * the public methods will not be exposed as part of the ZooKeeper client + * API. + */ + static class ZKWatchManager implements ClientWatchManager { + private final Map> dataWatches = + new HashMap>(); + private final Map> existWatches = + new HashMap>(); + private final Map> childWatches = + new HashMap>(); + + private volatile Watcher defaultWatcher; + + final private void addTo(Set from, Set to) { + if (from != null) { + to.addAll(from); + } + } + + public Map> removeWatcher(String clientPath, + Watcher watcher, WatcherType watcherType, boolean local, int rc) + throws KeeperException { + // Validate the provided znode path contains the given watcher of + // watcherType + containsWatcher(clientPath, watcher, watcherType); + + Map> removedWatchers = new HashMap>(); + HashSet childWatchersToRem = new HashSet(); + removedWatchers + .put(EventType.ChildWatchRemoved, childWatchersToRem); + HashSet dataWatchersToRem = new HashSet(); + removedWatchers.put(EventType.DataWatchRemoved, dataWatchersToRem); + boolean removedWatcher = false; + switch (watcherType) { + case Children: { + synchronized (childWatches) { + removedWatcher = removeWatches(childWatches, watcher, + clientPath, local, rc, childWatchersToRem); + } + break; + } + case Data: { + synchronized (dataWatches) { + removedWatcher = removeWatches(dataWatches, watcher, + clientPath, local, rc, dataWatchersToRem); + } + + synchronized (existWatches) { + boolean removedDataWatcher = removeWatches(existWatches, + watcher, clientPath, local, rc, dataWatchersToRem); + removedWatcher |= removedDataWatcher; + } + break; + } + case Any: { + synchronized (childWatches) { + removedWatcher = removeWatches(childWatches, watcher, + clientPath, local, rc, childWatchersToRem); + } + + synchronized (dataWatches) { + boolean removedDataWatcher = removeWatches(dataWatches, + watcher, clientPath, local, rc, dataWatchersToRem); + removedWatcher |= removedDataWatcher; + } + synchronized (existWatches) { + boolean removedDataWatcher = removeWatches(existWatches, + watcher, clientPath, local, rc, dataWatchersToRem); + removedWatcher |= removedDataWatcher; + } + } + } + // Watcher function doesn't exists for the specified params + if (!removedWatcher) { + throw new KeeperException.NoWatcherException(clientPath); + } + return removedWatchers; + } + + private boolean contains(String path, Watcher watcherObj, + Map> pathVsWatchers) { + boolean watcherExists = true; + if (pathVsWatchers == null || pathVsWatchers.size() == 0) { + watcherExists = false; + } else { + Set watchers = pathVsWatchers.get(path); + if (watchers == null) { + watcherExists = false; + } else if (watcherObj == null) { + watcherExists = watchers.size() > 0; + } else { + watcherExists = watchers.contains(watcherObj); + } + } + return watcherExists; + } + + /** + * Validate the provided znode path contains the given watcher and + * watcherType + * + * @param path + * - client path + * @param watcher + * - watcher object reference + * @param watcherType + * - type of the watcher + * @throws NoWatcherException + */ + void containsWatcher(String path, Watcher watcher, + WatcherType watcherType) throws NoWatcherException { + boolean containsWatcher = false; + switch (watcherType) { + case Children: { + synchronized (childWatches) { + containsWatcher = contains(path, watcher, childWatches); + } + break; + } + case Data: { + synchronized (dataWatches) { + containsWatcher = contains(path, watcher, dataWatches); + } + + synchronized (existWatches) { + boolean contains_temp = contains(path, watcher, + existWatches); + containsWatcher |= contains_temp; + } + break; + } + case Any: { + synchronized (childWatches) { + containsWatcher = contains(path, watcher, childWatches); + } + + synchronized (dataWatches) { + boolean contains_temp = contains(path, watcher, dataWatches); + containsWatcher |= contains_temp; + } + synchronized (existWatches) { + boolean contains_temp = contains(path, watcher, + existWatches); + containsWatcher |= contains_temp; + } + } + } + // Watcher function doesn't exists for the specified params + if (!containsWatcher) { + throw new KeeperException.NoWatcherException(path); + } + } + + protected boolean removeWatches(Map> pathVsWatcher, + Watcher watcher, String path, boolean local, int rc, + Set removedWatchers) throws KeeperException { + if (!local && rc != Code.OK.intValue()) { + throw KeeperException + .create(KeeperException.Code.get(rc), path); + } + boolean success = false; + // When local flag is true, remove watchers for the given path + // irrespective of rc. Otherwise shouldn't remove watchers locally + // when sees failure from server. + if (rc == Code.OK.intValue() || (local && rc != Code.OK.intValue())) { + // Remove all the watchers for the given path + if (watcher == null) { + Set pathWatchers = pathVsWatcher.remove(path); + if (pathWatchers != null) { + // found path watchers + removedWatchers.addAll(pathWatchers); + success = true; + } + } else { + Set watchers = pathVsWatcher.get(path); + if (watchers != null) { + if (watchers.remove(watcher)) { + // found path watcher + removedWatchers.add(watcher); + // cleanup + if (watchers.size() <= 0) { + pathVsWatcher.remove(path); + } + success = true; + } + } + } + } + return success; + } + + /* (non-Javadoc) + * @see org.apache.zookeeper.ClientWatchManager#materialize(Event.KeeperState, + * Event.EventType, java.lang.String) + */ + @Override + public Set materialize(Watcher.Event.KeeperState state, + Watcher.Event.EventType type, + String clientPath) { + Set result = new HashSet(); + + switch (type) { + case None: + result.add(defaultWatcher); + boolean clear = ClientCnxn.getDisableAutoResetWatch() && + state != Watcher.Event.KeeperState.SyncConnected; + + synchronized (dataWatches) { + for (Set ws : dataWatches.values()) { + result.addAll(ws); + } + if (clear) { + dataWatches.clear(); + } + } + + synchronized (existWatches) { + for (Set ws : existWatches.values()) { + result.addAll(ws); + } + if (clear) { + existWatches.clear(); + } + } + + synchronized (childWatches) { + for (Set ws : childWatches.values()) { + result.addAll(ws); + } + if (clear) { + childWatches.clear(); + } + } + + return result; + case NodeDataChanged: + case NodeCreated: + synchronized (dataWatches) { + addTo(dataWatches.remove(clientPath), result); + } + synchronized (existWatches) { + addTo(existWatches.remove(clientPath), result); + } + break; + case NodeChildrenChanged: + synchronized (childWatches) { + addTo(childWatches.remove(clientPath), result); + } + break; + case NodeDeleted: + synchronized (dataWatches) { + addTo(dataWatches.remove(clientPath), result); + } + // XXX This shouldn't be needed, but just in case + synchronized (existWatches) { + Set list = existWatches.remove(clientPath); + if (list != null) { + addTo(existWatches.remove(clientPath), result); + LOG.warn("We are triggering an exists watch for delete! Shouldn't happen!"); + } + } + synchronized (childWatches) { + addTo(childWatches.remove(clientPath), result); + } + break; + default: + String msg = "Unhandled watch event type " + type + + " with state " + state + " on path " + clientPath; + LOG.error(msg); + throw new RuntimeException(msg); + } + + return result; + } + } + + /* + * Methods to aid in testing follow. + * + * THESE METHODS ARE EXPECTED TO BE USED FOR TESTING ONLY!!! + */ + + /** + * Register a watcher for a particular path. + */ + abstract class WatchRegistration { + private Watcher watcher; + private String clientPath; + + public WatchRegistration(Watcher watcher, String clientPath) { + this.watcher = watcher; + this.clientPath = clientPath; + } + + abstract protected Map> getWatches(int rc); + + /** + * Register the watcher with the set of watches on path. + * @param rc the result code of the operation that attempted to + * add the watch on the path. + */ + public void register(int rc) { + if (shouldAddWatch(rc)) { + Map> watches = getWatches(rc); + synchronized (watches) { + Set watchers = watches.get(clientPath); + if (watchers == null) { + watchers = new HashSet(); + watches.put(clientPath, watchers); + } + watchers.add(watcher); + } + } + } + + /** + * Determine whether the watch should be added based on return code. + * @param rc the result code of the operation that attempted to add the + * watch on the node + * @return true if the watch should be added, otw false + */ + protected boolean shouldAddWatch(int rc) { + return rc == 0; + } + } + + /** Handle the special case of exists watches - they add a watcher + * even in the case where NONODE result code is returned. + */ + class ExistsWatchRegistration extends WatchRegistration { + public ExistsWatchRegistration(Watcher watcher, String clientPath) { + super(watcher, clientPath); + } + + @Override + protected Map> getWatches(int rc) { + return rc == 0 ? watchManager.dataWatches : watchManager.existWatches; + } + + @Override + protected boolean shouldAddWatch(int rc) { + return rc == 0 || rc == KeeperException.Code.NONODE.intValue(); + } + } + + class DataWatchRegistration extends WatchRegistration { + public DataWatchRegistration(Watcher watcher, String clientPath) { + super(watcher, clientPath); + } + + @Override + protected Map> getWatches(int rc) { + return watchManager.dataWatches; + } + } + + class ChildWatchRegistration extends WatchRegistration { + public ChildWatchRegistration(Watcher watcher, String clientPath) { + super(watcher, clientPath); + } + + @Override + protected Map> getWatches(int rc) { + return watchManager.childWatches; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/ZooKeeperMain.java b/src/java/main/org/apache/zookeeper/ZooKeeperMain.java new file mode 100644 index 00000000000..a8587ea42a6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ZooKeeperMain.java @@ -0,0 +1,677 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.commons.cli.ParseException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.cli.AddAuthCommand; +import org.apache.zookeeper.cli.CliCommand; +import org.apache.zookeeper.cli.CloseCommand; +import org.apache.zookeeper.cli.CreateCommand; +import org.apache.zookeeper.cli.DelQuotaCommand; +import org.apache.zookeeper.cli.DeleteAllCommand; +import org.apache.zookeeper.cli.DeleteCommand; +import org.apache.zookeeper.cli.GetAclCommand; +import org.apache.zookeeper.cli.GetCommand; +import org.apache.zookeeper.cli.GetConfigCommand; +import org.apache.zookeeper.cli.ListQuotaCommand; +import org.apache.zookeeper.cli.Ls2Command; +import org.apache.zookeeper.cli.LsCommand; +import org.apache.zookeeper.cli.ReconfigCommand; +import org.apache.zookeeper.cli.RemoveWatchesCommand; +import org.apache.zookeeper.cli.SetAclCommand; +import org.apache.zookeeper.cli.SetCommand; +import org.apache.zookeeper.cli.SetQuotaCommand; +import org.apache.zookeeper.cli.StatCommand; +import org.apache.zookeeper.cli.SyncCommand; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * The command line client to ZooKeeper. + * + */ +public class ZooKeeperMain { + protected static final Map commandMap = new HashMap(); + protected static final Map commandMapCli = + new HashMap(); + private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperMain.class); + + static { + commandMap.put("connect", "host:port"); + commandMap.put("history", ""); + commandMap.put("redo", "cmdno"); + commandMap.put("printwatches", "on|off"); + commandMap.put("quit", ""); + + new CloseCommand().addToMap(commandMapCli); + new CreateCommand().addToMap(commandMapCli); + new DeleteCommand().addToMap(commandMapCli); + new DeleteAllCommand().addToMap(commandMapCli); + // Depricated: rmr + new DeleteAllCommand("rmr").addToMap(commandMapCli); + new SetCommand().addToMap(commandMapCli); + new GetCommand().addToMap(commandMapCli); + new LsCommand().addToMap(commandMapCli); + new Ls2Command().addToMap(commandMapCli); + new GetAclCommand().addToMap(commandMapCli); + new SetAclCommand().addToMap(commandMapCli); + new StatCommand().addToMap(commandMapCli); + new SyncCommand().addToMap(commandMapCli); + new SetQuotaCommand().addToMap(commandMapCli); + new ListQuotaCommand().addToMap(commandMapCli); + new DelQuotaCommand().addToMap(commandMapCli); + new AddAuthCommand().addToMap(commandMapCli); + new ReconfigCommand().addToMap(commandMapCli); + new GetConfigCommand().addToMap(commandMapCli); + new RemoveWatchesCommand().addToMap(commandMapCli); + + // add all to commandMap + for (Entry entry : commandMapCli.entrySet()) { + commandMap.put(entry.getKey(), entry.getValue().getOptionStr()); + } + } + + protected MyCommandOptions cl = new MyCommandOptions(); + protected HashMap history = new HashMap(); + protected int commandCount = 0; + protected boolean printWatches = true; + protected ZooKeeper zk; + protected String host = ""; + + public ZooKeeperMain(String args[]) throws IOException, InterruptedException { + cl.parseOptions(args); + System.out.println("Connecting to " + cl.getOption("server")); + connectToZK(cl.getOption("server")); + //zk = new ZooKeeper(cl.getOption("server"), +// Integer.parseInt(cl.getOption("timeout")), new MyWatcher()); + } + + public ZooKeeperMain(ZooKeeper zk) { + this.zk = zk; + } + + static void usage() { + System.err.println("ZooKeeper -server host:port cmd args"); + List cmdList = new ArrayList(commandMap.keySet()); + Collections.sort(cmdList); + for (String cmd : cmdList) { + System.err.println("\t" + cmd + " " + commandMap.get(cmd)); + } + } + + public static List getCommands() { + List cmdList = new ArrayList(commandMap.keySet()); + Collections.sort(cmdList); + return cmdList; + } + + public static void printMessage(String msg) { + System.out.println("\n" + msg); + } + + public static void main(String args[]) + throws KeeperException, IOException, InterruptedException { + ZooKeeperMain main = new ZooKeeperMain(args); + main.run(); + } + + /** + * trim the quota tree to recover unwanted tree elements + * in the quota's tree + * @param zk the zookeeper client + * @param path the path to start from and go up and see if their + * is any unwanted parent in the path. + * @return true if sucessful + * @throws KeeperException + * @throws IOException + * @throws InterruptedException + */ + private static boolean trimProcQuotas(ZooKeeper zk, String path) + throws KeeperException, IOException, InterruptedException { + if (Quotas.quotaZookeeper.equals(path)) { + return true; + } + List children = zk.getChildren(path, false); + if (children.size() == 0) { + zk.delete(path, -1); + String parent = path.substring(0, path.lastIndexOf('/')); + return trimProcQuotas(zk, parent); + } else { + return true; + } + } + + /** + * this method deletes quota for a node. + * @param zk the zookeeper client + * @param path the path to delete quota for + * @param bytes true if number of bytes needs to + * be unset + * @param numNodes true if number of nodes needs + * to be unset + * @return true if quota deletion is successful + * @throws KeeperException + * @throws IOException + * @throws InterruptedException + */ + public static boolean delQuota(ZooKeeper zk, String path, + boolean bytes, boolean numNodes) + throws KeeperException, IOException, InterruptedException { + String parentPath = Quotas.quotaZookeeper + path; + String quotaPath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode; + if (zk.exists(quotaPath, false) == null) { + System.out.println("Quota does not exist for " + path); + return true; + } + byte[] data = null; + try { + data = zk.getData(quotaPath, false, new Stat()); + } catch (KeeperException.NoNodeException ne) { + System.err.println("quota does not exist for " + path); + return true; + } + StatsTrack strack = new StatsTrack(new String(data)); + if (bytes && !numNodes) { + strack.setBytes(-1L); + zk.setData(quotaPath, strack.toString().getBytes(), -1); + } else if (!bytes && numNodes) { + strack.setCount(-1); + zk.setData(quotaPath, strack.toString().getBytes(), -1); + } else if (bytes && numNodes) { + // delete till you can find a node with more than + // one child + List children = zk.getChildren(parentPath, false); + /// delete the direct children first + for (String child : children) { + zk.delete(parentPath + "/" + child, -1); + } + // cut the tree till their is more than one child + trimProcQuotas(zk, parentPath); + } + return true; + } + + private static void checkIfParentQuota(ZooKeeper zk, String path) + throws InterruptedException, KeeperException { + final String[] splits = path.split("/"); + String quotaPath = Quotas.quotaZookeeper; + for (String str : splits) { + if (str.length() == 0) { + // this should only be for the beginning of the path + // i.e. "/..." - split(path)[0] is empty string before first '/' + continue; + } + quotaPath += "/" + str; + List children = null; + try { + children = zk.getChildren(quotaPath, false); + } catch (KeeperException.NoNodeException ne) { + LOG.debug("child removed during quota check", ne); + return; + } + if (children.size() == 0) { + return; + } + for (String child : children) { + if (Quotas.limitNode.equals(child)) { + throw new IllegalArgumentException(path + " has a parent " + + quotaPath + " which has a quota"); + } + } + } + } + + /** + * this method creates a quota node for the path + * @param zk the ZooKeeper client + * @param path the path for which quota needs to be created + * @param bytes the limit of bytes on this path + * @param numNodes the limit of number of nodes on this path + * @return true if its successful and false if not. + */ + public static boolean createQuota(ZooKeeper zk, String path, + long bytes, int numNodes) + throws KeeperException, IOException, InterruptedException { + // check if the path exists. We cannot create + // quota for a path that already exists in zookeeper + // for now. + Stat initStat = zk.exists(path, false); + if (initStat == null) { + throw new IllegalArgumentException(path + " does not exist."); + } + // now check if their is already existing + // parent or child that has quota + + String quotaPath = Quotas.quotaZookeeper; + // check for more than 2 children -- + // if zookeeper_stats and zookeeper_qutoas + // are not the children then this path + // is an ancestor of some path that + // already has quota + String realPath = Quotas.quotaZookeeper + path; + try { + List children = zk.getChildren(realPath, false); + for (String child : children) { + if (!child.startsWith("zookeeper_")) { + throw new IllegalArgumentException(path + " has child " + + child + " which has a quota"); + } + } + } catch (KeeperException.NoNodeException ne) { + // this is fine + } + + //check for any parent that has been quota + checkIfParentQuota(zk, path); + + // this is valid node for quota + // start creating all the parents + if (zk.exists(quotaPath, false) == null) { + try { + zk.create(Quotas.procZookeeper, null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.create(Quotas.quotaZookeeper, null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ne) { + // do nothing + } + } + + // now create the direct children + // and the stat and quota nodes + String[] splits = path.split("/"); + StringBuilder sb = new StringBuilder(); + sb.append(quotaPath); + for (int i = 1; i < splits.length; i++) { + sb.append("/" + splits[i]); + quotaPath = sb.toString(); + try { + zk.create(quotaPath, null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ne) { + //do nothing + } + } + String statPath = quotaPath + "/" + Quotas.statNode; + quotaPath = quotaPath + "/" + Quotas.limitNode; + StatsTrack strack = new StatsTrack(null); + strack.setBytes(bytes); + strack.setCount(numNodes); + try { + zk.create(quotaPath, strack.toString().getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + StatsTrack stats = new StatsTrack(null); + stats.setBytes(0L); + stats.setCount(0); + zk.create(statPath, stats.toString().getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ne) { + byte[] data = zk.getData(quotaPath, false, new Stat()); + StatsTrack strackC = new StatsTrack(new String(data)); + if (bytes != -1L) { + strackC.setBytes(bytes); + } + if (numNodes != -1) { + strackC.setCount(numNodes); + } + zk.setData(quotaPath, strackC.toString().getBytes(), -1); + } + return true; + } + + public boolean getPrintWatches() { + return printWatches; + } + + /** + * Makes a list of possible completions, either for commands + * or for zk nodes if the token to complete begins with / + * + */ + + + protected void addToHistory(int i, String cmd) { + history.put(i, cmd); + } + + protected String getPrompt() { + return "[zk: " + host + "(" + zk.getState() + ")" + " " + commandCount + "] "; + } + + protected void connectToZK(String newHost) throws InterruptedException, IOException { + if (zk != null && zk.getState().isAlive()) { + zk.close(); + } + host = newHost; + boolean readOnly = cl.getOption("readonly") != null; + if (cl.getOption("secure") != null) { + System.setProperty(ZooKeeper.SECURE_CLIENT, "true"); + System.out.println("Secure connection is enabled"); + } + zk = new ZooKeeper(host, + Integer.parseInt(cl.getOption("timeout")), + new MyWatcher(), readOnly); + } + + void run() throws KeeperException, IOException, InterruptedException { + if (cl.getCommand() == null) { + System.out.println("Welcome to ZooKeeper!"); + + boolean jlinemissing = false; + // only use jline if it's in the classpath + try { + Class consoleC = Class.forName("jline.console.ConsoleReader"); + Class completorC = + Class.forName("org.apache.zookeeper.JLineZNodeCompleter"); + + System.out.println("JLine support is enabled"); + + Object console = + consoleC.getConstructor().newInstance(); + + Object completor = + completorC.getConstructor(ZooKeeper.class).newInstance(zk); + Method addCompletor = consoleC.getMethod("addCompleter", + Class.forName("jline.console.completer.Completer")); + addCompletor.invoke(console, completor); + + String line; + Method readLine = consoleC.getMethod("readLine", String.class); + while ((line = (String) readLine.invoke(console, getPrompt())) != null) { + executeLine(line); + } + } catch (ClassNotFoundException e) { + LOG.debug("Unable to start jline", e); + jlinemissing = true; + } catch (NoSuchMethodException e) { + LOG.debug("Unable to start jline", e); + jlinemissing = true; + } catch (InvocationTargetException e) { + LOG.debug("Unable to start jline", e); + jlinemissing = true; + } catch (IllegalAccessException e) { + LOG.debug("Unable to start jline", e); + jlinemissing = true; + } catch (InstantiationException e) { + LOG.debug("Unable to start jline", e); + jlinemissing = true; + } + + if (jlinemissing) { + System.out.println("JLine support is disabled"); + BufferedReader br = + new BufferedReader(new InputStreamReader(System.in)); + + String line; + while ((line = br.readLine()) != null) { + executeLine(line); + } + } + } else { + // Command line args non-null. Run what was passed. + processCmd(cl); + } + } + + public void executeLine(String line) + throws InterruptedException, IOException, KeeperException { + if (!line.equals("")) { + cl.parseCommand(line); + addToHistory(commandCount, line); + processCmd(cl); + commandCount++; + } + } + + protected boolean processCmd(MyCommandOptions co) + throws KeeperException, IOException, InterruptedException { + try { + return processZKCmd(co); + } catch (IllegalArgumentException e) { + System.err.println("Command failed: " + e); + } catch (KeeperException.NoNodeException e) { + System.err.println("Node does not exist: " + e.getPath()); + } catch (KeeperException.NoChildrenForEphemeralsException e) { + System.err.println("Ephemerals cannot have children: " + + e.getPath()); + } catch (KeeperException.NodeExistsException e) { + System.err.println("Node already exists: " + e.getPath()); + } catch (KeeperException.NotEmptyException e) { + System.err.println("Node not empty: " + e.getPath()); + } catch (KeeperException.NotReadOnlyException e) { + System.err.println("Not a read-only call: " + e.getPath()); + } catch (KeeperException.InvalidACLException e) { + System.err.println("Acl is not valid : " + e.getPath()); + } catch (KeeperException.NoAuthException e) { + System.err.println("Authentication is not valid : " + e.getPath()); + } catch (KeeperException.BadArgumentsException e) { + System.err.println("Arguments are not valid : " + e.getPath()); + } catch (KeeperException.BadVersionException e) { + System.err.println("version No is not valid : " + e.getPath()); + } catch (KeeperException.ReconfigInProgress e) { + System.err.println("Another reconfiguration is in progress -- concurrent " + + "reconfigs not supported (yet)"); + } catch (KeeperException.NewConfigNoQuorum e) { + System.err.println("No quorum of new config is connected and " + + "up-to-date with the leader of last commmitted config - try invoking reconfiguration after " + + "new servers are connected and synced"); + } + return false; + } + + protected boolean processZKCmd(MyCommandOptions co) + throws KeeperException, IOException, InterruptedException { + String[] args = co.getArgArray(); + String cmd = co.getCommand(); + if (args.length < 1) { + usage(); + return false; + } + + if (!commandMap.containsKey(cmd)) { + usage(); + return false; + } + + boolean watch = false; + LOG.debug("Processing " + cmd); + + try { + if (cmd.equals("quit")) { + zk.close(); + System.exit(0); + } else if (cmd.equals("redo") && args.length >= 2) { + Integer i = Integer.decode(args[1]); + if (commandCount <= i) { // don't allow redoing this redo + System.out.println("Command index out of range"); + return false; + } + cl.parseCommand(history.get(i)); + if (cl.getCommand().equals("redo")) { + System.out.println("No redoing redos"); + return false; + } + history.put(commandCount, history.get(i)); + processCmd(cl); + } else if (cmd.equals("history")) { + for (int i = commandCount - 10; i <= commandCount; ++i) { + if (i < 0) continue; + System.out.println(i + " - " + history.get(i)); + } + } else if (cmd.equals("printwatches")) { + if (args.length == 1) { + System.out.println("printwatches is " + (printWatches ? "on" : "off")); + } else { + printWatches = args[1].equals("on"); + } + } else if (cmd.equals("connect")) { + if (args.length >= 2) { + connectToZK(args[1]); + } else { + connectToZK(host); + } + } + + // Below commands all need a live connection + if (zk == null || !zk.getState().isAlive()) { + System.out.println("Not connected"); + return false; + } + + // execute from commandMap + CliCommand cliCmd = commandMapCli.get(cmd); + if (cliCmd != null) { + cliCmd.setZk(zk); + watch = cliCmd.parse(args).exec(); + } else if (!commandMap.containsKey(cmd)) { + usage(); + } + + } catch (ParseException ex) { + System.err.println(ex.getMessage()); + usage(); + return false; + } + return watch; + } + + /** + * A storage class for both command line options and shell commands. + * + */ + static class MyCommandOptions { + + public static final Pattern ARGS_PATTERN = Pattern.compile("\\s*([^\"\']\\S*|\"[^\"]*\"|'[^']*')\\s*"); + public static final Pattern QUOTED_PATTERN = Pattern.compile("^([\'\"])(.*)(\\1)$"); + private Map options = new HashMap(); + private List cmdArgs = null; + private String command = null; + + public MyCommandOptions() { + options.put("server", "localhost:2181"); + options.put("timeout", "30000"); + } + + public String getOption(String opt) { + return options.get(opt); + } + + public String getCommand() { + return command; + } + + public String getCmdArgument(int index) { + return cmdArgs.get(index); + } + + public int getNumArguments() { + return cmdArgs.size(); + } + + public String[] getArgArray() { + return cmdArgs.toArray(new String[0]); + } + + /** + * Parses a command line that may contain one or more flags + * before an optional command string + * @param args command line arguments + * @return true if parsing succeeded, false otherwise. + */ + public boolean parseOptions(String[] args) { + List argList = Arrays.asList(args); + Iterator it = argList.iterator(); + + while (it.hasNext()) { + String opt = it.next(); + try { + if (opt.equals("-server")) { + options.put("server", it.next()); + } else if (opt.equals("-timeout")) { + options.put("timeout", it.next()); + } else if (opt.equals("-r")) { + options.put("readonly", "true"); + } + } catch (NoSuchElementException e) { + System.err.println("Error: no argument found for option " + + opt); + return false; + } + + if (!opt.startsWith("-")) { + command = opt; + cmdArgs = new ArrayList(); + cmdArgs.add(command); + while (it.hasNext()) { + cmdArgs.add(it.next()); + } + return true; + } + } + return true; + } + + /** + * Breaks a string into command + arguments. + * @param cmdstring string of form "cmd arg1 arg2..etc" + * @return true if parsing succeeded. + */ + public boolean parseCommand(String cmdstring) { + Matcher matcher = ARGS_PATTERN.matcher(cmdstring); + + List args = new LinkedList(); + while (matcher.find()) { + String value = matcher.group(1); + if (QUOTED_PATTERN.matcher(value).matches()) { + // Strip off the surrounding quotes + value = value.substring(1, value.length() - 1); + } + args.add(value); + } + if (args.isEmpty()) { + return false; + } + command = args.get(0); + cmdArgs = args; + return true; + } + } + + private class MyWatcher implements Watcher { + public void process(WatchedEvent event) { + if (getPrintWatches()) { + ZooKeeperMain.printMessage("WATCHER::"); + ZooKeeperMain.printMessage(event.toString()); + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/ZooKeeperTestable.java b/src/java/main/org/apache/zookeeper/ZooKeeperTestable.java new file mode 100644 index 00000000000..9a6f3f560bb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/ZooKeeperTestable.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class ZooKeeperTestable implements Testable { + private static final Logger LOG = LoggerFactory + .getLogger(ZooKeeperTestable.class); + + private final ZooKeeper zooKeeper; + private final ClientCnxn clientCnxn; + + ZooKeeperTestable(ZooKeeper zooKeeper, ClientCnxn clientCnxn) { + this.zooKeeper = zooKeeper; + this.clientCnxn = clientCnxn; + } + + @Override + public void injectSessionExpiration() { + LOG.info("injectSessionExpiration() called"); + + clientCnxn.eventThread.queueEvent(new WatchedEvent( + Watcher.Event.EventType.None, + Watcher.Event.KeeperState.Expired, null)); + clientCnxn.eventThread.queueEventOfDeath(); + clientCnxn.state = ZooKeeper.States.CLOSED; + clientCnxn.sendThread.getClientCnxnSocket().onClosing(); + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/AclParser.java b/src/java/main/org/apache/zookeeper/cli/AclParser.java new file mode 100644 index 00000000000..0ba7bb3e5de --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/AclParser.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; + +import java.util.ArrayList; +import java.util.List; + +/** + * a parser for ACL strings + */ +public class AclParser { + + /** + * parse string into list of ACL + * @param aclString + * @return + */ + public static List parse(String aclString) { + List acl; + String acls[] = aclString.split(","); + acl = new ArrayList(); + for (String a : acls) { + int firstColon = a.indexOf(':'); + int lastColon = a.lastIndexOf(':'); + if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) { + System.err.println(a + " does not have the form scheme:id:perm"); + continue; + } + ACL newAcl = new ACL(); + newAcl.setId(new Id(a.substring(0, firstColon), a.substring( + firstColon + 1, lastColon))); + newAcl.setPerms(getPermFromString(a.substring(lastColon + 1))); + acl.add(newAcl); + } + return acl; + } + + static private int getPermFromString(String permString) { + int perm = 0; + for (int i = 0; i < permString.length(); i++) { + switch (permString.charAt(i)) { + case 'r': + perm |= ZooDefs.Perms.READ; + break; + case 'w': + perm |= ZooDefs.Perms.WRITE; + break; + case 'c': + perm |= ZooDefs.Perms.CREATE; + break; + case 'd': + perm |= ZooDefs.Perms.DELETE; + break; + case 'a': + perm |= ZooDefs.Perms.ADMIN; + break; + default: + System.err.println("Unknown perm type: " + permString.charAt(i)); + } + } + return perm; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/AddAuthCommand.java b/src/java/main/org/apache/zookeeper/cli/AddAuthCommand.java new file mode 100644 index 00000000000..81b1bcc9334 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/AddAuthCommand.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; + +import java.io.IOException; + +/** + * addAuth command for cli + */ +public class AddAuthCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + + public AddAuthCommand() { + super("addauth", "scheme auth"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + CommandLine cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, IOException, + InterruptedException { + byte[] b = null; + if (args.length >= 3) { + b = args[2].getBytes(); + } + + zk.addAuthInfo(args[1], b); + + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/CliCommand.java b/src/java/main/org/apache/zookeeper/cli/CliCommand.java new file mode 100644 index 00000000000..ee225d5cabd --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/CliCommand.java @@ -0,0 +1,118 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.ParseException; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooKeeper; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.Map; + +/** + * base class for all CLI commands + */ +abstract public class CliCommand { + + protected ZooKeeper zk; + protected PrintStream out; + protected PrintStream err; + private String cmdStr; + private String optionStr; + + /** + * a CLI command with command string and options. + * Using System.out and System.err for printing + * @param cmdStr the string used to call this command + * @param optionStr the string used to call this command + */ + public CliCommand(String cmdStr, String optionStr) { + this.out = System.out; + this.err = System.err; + this.cmdStr = cmdStr; + this.optionStr = optionStr; + } + + /** + * Set out printStream (useable for testing) + * @param out + */ + public void setOut(PrintStream out) { + this.out = out; + } + + /** + * Set err printStream (useable for testing) + * @param err + */ + public void setErr(PrintStream err) { + this.err = err; + } + + /** + * set the zookeper instance + * @param zk the zookeper instance + */ + public void setZk(ZooKeeper zk) { + this.zk = zk; + } + + /** + * get the string used to call this command + * @return + */ + public String getCmdStr() { + return cmdStr; + } + + /** + * get the option string + * @return + */ + public String getOptionStr() { + return optionStr; + } + + /** + * get a usage string, contains the command and the options + * @return + */ + public String getUsageStr() { + return cmdStr + " " + optionStr; + } + + /** + * add this command to a map. Use the command string as key. + * @param cmdMap + */ + public void addToMap(Map cmdMap) { + cmdMap.put(cmdStr, this); + } + + /** + * parse the command arguments + * @param cmdArgs + * @return this CliCommand + * @throws ParseException + */ + abstract public CliCommand parse(String cmdArgs[]) throws ParseException; + + /** + * + * @return + * @throws KeeperException + * @throws IOException + * @throws InterruptedException + */ + abstract public boolean exec() throws KeeperException, + IOException, InterruptedException; +} diff --git a/src/java/main/org/apache/zookeeper/cli/CloseCommand.java b/src/java/main/org/apache/zookeeper/cli/CloseCommand.java new file mode 100644 index 00000000000..894175e7133 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/CloseCommand.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.ParseException; +import org.apache.zookeeper.KeeperException; + +import java.io.IOException; + +/** + * close command for cli + */ +public class CloseCommand extends CliCommand { + + public CloseCommand() { + super("close", ""); + } + + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + return this; + } + + @Override + public boolean exec() throws KeeperException, IOException, InterruptedException { + zk.close(); + + return false; + } + +} diff --git a/src/java/main/org/apache/zookeeper/cli/CreateCommand.java b/src/java/main/org/apache/zookeeper/cli/CreateCommand.java new file mode 100644 index 00000000000..f9e4a189823 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/CreateCommand.java @@ -0,0 +1,99 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.data.ACL; + +import java.util.List; + +/** + * create command for cli + */ +public class CreateCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + private CommandLine cl; + + { + options.addOption(new Option("e", false, "ephemeral")); + options.addOption(new Option("s", false, "sequential")); + options.addOption(new Option("c", false, "container")); + } + + public CreateCommand() { + super("create", "[-s] [-e] [-c] path [data] [acl]"); + } + + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + return this; + } + + + @Override + public boolean exec() throws KeeperException, InterruptedException { + CreateMode flags = CreateMode.PERSISTENT; + boolean hasE = cl.hasOption("e"); + boolean hasS = cl.hasOption("s"); + boolean hasC = cl.hasOption("c"); + if (hasC && (hasE || hasS)) { + err.println("-c cannot be combined with -s or -e. Containers cannot be ephemeral or sequential."); + return false; + } + + if (hasE && hasS) { + flags = CreateMode.EPHEMERAL_SEQUENTIAL; + } else if (hasE) { + flags = CreateMode.EPHEMERAL; + } else if (hasS) { + flags = CreateMode.PERSISTENT_SEQUENTIAL; + } else if (hasC) { + flags = CreateMode.CONTAINER; + } + String path = args[1]; + byte[] data = null; + if (args.length > 2) { + data = args[2].getBytes(); + } + List acl = ZooDefs.Ids.OPEN_ACL_UNSAFE; + if (args.length > 3) { + acl = AclParser.parse(args[3]); + } + try { + String newPath = zk.create(path, data, acl, flags); + err.println("Created " + newPath); + } catch (KeeperException.EphemeralOnLocalSessionException e) { + err.println("Unable to create ephemeral node on a local session"); + return false; + } catch (KeeperException.InvalidACLException ex) { + err.println(ex.getMessage()); + return false; + } + return true; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/DelQuotaCommand.java b/src/java/main/org/apache/zookeeper/cli/DelQuotaCommand.java new file mode 100644 index 00000000000..e709e444d92 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/DelQuotaCommand.java @@ -0,0 +1,152 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionGroup; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Quotas; +import org.apache.zookeeper.StatsTrack; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; + +import java.io.IOException; +import java.util.List; + +/** + * delQuota command for cli + */ +public class DelQuotaCommand extends CliCommand { + + private Options options = new Options(); + private String[] args; + private CommandLine cl; + + public DelQuotaCommand() { + super("delquota", "[-n|-b] path"); + + OptionGroup og1 = new OptionGroup(); + og1.addOption(new Option("b", false, "bytes quota")); + og1.addOption(new Option("n", false, "num quota")); + options.addOptionGroup(og1); + } + + /** + * this method deletes quota for a node. + * + * @param zk the zookeeper client + * @param path the path to delete quota for + * @param bytes true if number of bytes needs to be unset + * @param numNodes true if number of nodes needs to be unset + * @return true if quota deletion is successful + * @throws KeeperException + * @throws IOException + * @throws InterruptedException + */ + public static boolean delQuota(ZooKeeper zk, String path, + boolean bytes, boolean numNodes) + throws KeeperException, IOException, InterruptedException { + String parentPath = Quotas.quotaZookeeper + path; + String quotaPath = Quotas.quotaZookeeper + path + "/" + + Quotas.limitNode; + if (zk.exists(quotaPath, false) == null) { + System.out.println("Quota does not exist for " + path); + return true; + } + byte[] data = null; + try { + data = zk.getData(quotaPath, false, new Stat()); + } catch (KeeperException.NoNodeException ne) { + System.err.println("quota does not exist for " + path); + return true; + } + StatsTrack strack = new StatsTrack(new String(data)); + if (bytes && !numNodes) { + strack.setBytes(-1L); + zk.setData(quotaPath, strack.toString().getBytes(), -1); + } else if (!bytes && numNodes) { + strack.setCount(-1); + zk.setData(quotaPath, strack.toString().getBytes(), -1); + } else if (bytes && numNodes) { + // delete till you can find a node with more than + // one child + List children = zk.getChildren(parentPath, false); + /// delete the direct children first + for (String child : children) { + zk.delete(parentPath + "/" + child, -1); + } + // cut the tree till their is more than one child + trimProcQuotas(zk, parentPath); + } + return true; + } + + /** + * trim the quota tree to recover unwanted tree elements in the quota's tree + * + * @param zk the zookeeper client + * @param path the path to start from and go up and see if their is any + * unwanted parent in the path. + * @return true if sucessful + * @throws KeeperException + * @throws IOException + * @throws InterruptedException + */ + private static boolean trimProcQuotas(ZooKeeper zk, String path) + throws KeeperException, IOException, InterruptedException { + if (Quotas.quotaZookeeper.equals(path)) { + return true; + } + List children = zk.getChildren(path, false); + if (children.size() == 0) { + zk.delete(path, -1); + String parent = path.substring(0, path.lastIndexOf('/')); + return trimProcQuotas(zk, parent); + } else { + return true; + } + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, IOException, + InterruptedException { + //if neither option -n or -b is specified, we delete + // the quota node for thsi node. + String path = args[1]; + if (cl.hasOption("b")) { + delQuota(zk, path, true, false); + } else if (cl.hasOption("n")) { + delQuota(zk, path, false, true); + } else if (args.length == 2) { + // we dont have an option specified. + // just delete whole quota node + delQuota(zk, path, true, true); + } + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/DeleteAllCommand.java b/src/java/main/org/apache/zookeeper/cli/DeleteAllCommand.java new file mode 100644 index 00000000000..987996b5c3e --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/DeleteAllCommand.java @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZKUtil; + +/** + * deleteAll command for cli + */ +public class DeleteAllCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + + public DeleteAllCommand() { + this("deleteall"); + } + + public DeleteAllCommand(String cmdStr) { + super(cmdStr, "path"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + CommandLine cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, + InterruptedException { + printDeprecatedWarning(); + + String path = args[1]; + ZKUtil.deleteRecursive(zk, path); + return false; + } + + private void printDeprecatedWarning() { + if ("rmr".equals(args[0])) { + err.println("The command 'rmr' has been deprecated. " + + "Please use 'deleteall' instead."); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/DeleteCommand.java b/src/java/main/org/apache/zookeeper/cli/DeleteCommand.java new file mode 100644 index 00000000000..55b263823c2 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/DeleteCommand.java @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; + +/** + * delete command for cli + */ +public class DeleteCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + private CommandLine cl; + + { + options.addOption("v", true, "version"); + } + + public DeleteCommand() { + super("delete", "[-v version] path"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + retainCompatibility(cmdArgs); + + return this; + } + + private void retainCompatibility(String[] cmdArgs) throws ParseException { + // delete path [version] + if (args.length > 2) { + // rewrite to option + String[] newCmd = new String[4]; + newCmd[0] = cmdArgs[0]; + newCmd[1] = "-v"; + newCmd[2] = cmdArgs[2]; // version + newCmd[3] = cmdArgs[1]; // path + err.println("'delete path [version]' has been deprecated. " + + "Please use 'delete [-v version] path' instead."); + Parser parser = new PosixParser(); + cl = parser.parse(options, newCmd); + args = cl.getArgs(); + } + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + String path = args[1]; + int version; + if (cl.hasOption("v")) { + version = Integer.parseInt(cl.getOptionValue("v")); + } else { + version = -1; + } + + try { + zk.delete(path, version); + } catch (KeeperException.BadVersionException ex) { + err.println(ex.getMessage()); + } + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/GetAclCommand.java b/src/java/main/org/apache/zookeeper/cli/GetAclCommand.java new file mode 100644 index 00000000000..d2ca91c4dfa --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/GetAclCommand.java @@ -0,0 +1,89 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; + +import java.util.List; + +/** + * getAcl command for cli + */ +public class GetAclCommand extends CliCommand { + + private static Options options = new Options(); + private String args[]; + private CommandLine cl; + + { + options.addOption("s", false, "stats"); + } + + public GetAclCommand() { + super("getAcl", "[-s] path"); + } + + private static String getPermString(int perms) { + StringBuilder p = new StringBuilder(); + if ((perms & ZooDefs.Perms.CREATE) != 0) { + p.append('c'); + } + if ((perms & ZooDefs.Perms.DELETE) != 0) { + p.append('d'); + } + if ((perms & ZooDefs.Perms.READ) != 0) { + p.append('r'); + } + if ((perms & ZooDefs.Perms.WRITE) != 0) { + p.append('w'); + } + if ((perms & ZooDefs.Perms.ADMIN) != 0) { + p.append('a'); + } + return p.toString(); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + String path = args[1]; + Stat stat = new Stat(); + List acl = zk.getACL(path, stat); + for (ACL a : acl) { + out.println(a.getId() + ": " + + getPermString(a.getPerms())); + } + + if (cl.hasOption("s")) { + new StatPrinter(out).print(stat); + } + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/GetCommand.java b/src/java/main/org/apache/zookeeper/cli/GetCommand.java new file mode 100644 index 00000000000..1e73bd02d08 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/GetCommand.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; + +/** + * get command for cli + */ +public class GetCommand extends CliCommand { + + private static Options options = new Options(); + private String args[]; + private CommandLine cl; + + { + options.addOption("s", false, "stats"); + options.addOption("w", false, "watch"); + } + + public GetCommand() { + super("get", "[-s] [-w] path"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + retainCompatibility(cmdArgs); + + return this; + } + + private void retainCompatibility(String[] cmdArgs) throws ParseException { + // get path [watch] + if (args.length > 2) { + // rewrite to option + cmdArgs[2] = "-w"; + err.println("'get path [watch]' has been deprecated. " + + "Please use 'get [-s] [-w] path' instead."); + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + } + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + boolean watch = cl.hasOption("w"); + String path = args[1]; + Stat stat = new Stat(); + byte data[] = zk.getData(path, watch, stat); + data = (data == null) ? "null".getBytes() : data; + out.println(new String(data)); + if (cl.hasOption("s")) { + new StatPrinter(out).print(stat); + } + return watch; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/GetConfigCommand.java b/src/java/main/org/apache/zookeeper/cli/GetConfigCommand.java new file mode 100644 index 00000000000..6fce3cf5d19 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/GetConfigCommand.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.util.ConfigUtils; + +/** + * get command for cli + */ +public class GetConfigCommand extends CliCommand { + + private static Options options = new Options(); + private String args[]; + private CommandLine cl; + + { + options.addOption("s", false, "stats"); + options.addOption("w", false, "watch"); + options.addOption("c", false, "client connection string"); + } + + public GetConfigCommand() { + super("config", "[-c] [-w] [-s]"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 1) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + boolean watch = cl.hasOption("w"); + Stat stat = new Stat(); + byte data[] = zk.getConfig(watch, stat); + data = (data == null) ? "null".getBytes() : data; + if (cl.hasOption("c")) { + out.println(ConfigUtils.getClientConfigStr(new String(data))); + } else { + out.println(new String(data)); + } + + if (cl.hasOption("s")) { + new StatPrinter(out).print(stat); + } + + return watch; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/ListQuotaCommand.java b/src/java/main/org/apache/zookeeper/cli/ListQuotaCommand.java new file mode 100644 index 00000000000..f75fde020c5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/ListQuotaCommand.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Quotas; +import org.apache.zookeeper.StatsTrack; +import org.apache.zookeeper.data.Stat; + +/** + * listQuta command for cli + */ +public class ListQuotaCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + + public ListQuotaCommand() { + super("listquota", "path"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + CommandLine cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, + InterruptedException { + String path = args[1]; + String absolutePath = Quotas.quotaZookeeper + path + "/" + + Quotas.limitNode; + try { + err.println("absolute path is " + absolutePath); + Stat stat = new Stat(); + byte[] data = zk.getData(absolutePath, false, stat); + StatsTrack st = new StatsTrack(new String(data)); + out.println("Output quota for " + path + " " + + st.toString()); + + data = zk.getData(Quotas.quotaZookeeper + path + "/" + + Quotas.statNode, false, stat); + out.println("Output stat for " + path + " " + + new StatsTrack(new String(data)).toString()); + } catch (KeeperException.NoNodeException ne) { + err.println("quota for " + path + " does not exist."); + } + + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/Ls2Command.java b/src/java/main/org/apache/zookeeper/cli/Ls2Command.java new file mode 100644 index 00000000000..e96d71eba12 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/Ls2Command.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; + +import java.util.List; + +/** + * ls2 command for cli + */ +public class Ls2Command extends CliCommand { + + private static Options options = new Options(); + private String args[]; + + public Ls2Command() { + super("ls2", "path [watch]"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + CommandLine cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + err.println("'ls2' has been deprecated. " + + "Please use 'ls [-s] path' instead."); + String path = args[1]; + boolean watch = args.length > 2; + Stat stat = new Stat(); + List children = zk.getChildren(path, watch, stat); + out.println(children); + new StatPrinter(out).print(stat); + return watch; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/LsCommand.java b/src/java/main/org/apache/zookeeper/cli/LsCommand.java new file mode 100644 index 00000000000..0a8bffb5276 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/LsCommand.java @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; + +import java.util.Collections; +import java.util.List; + +/** + * ls command for cli + */ +public class LsCommand extends CliCommand { + + private static Options options = new Options(); + private String args[]; + private CommandLine cl; + + { + options.addOption("?", false, "help"); + options.addOption("s", false, "stat"); + options.addOption("w", false, "watch"); + } + + public LsCommand() { + super("ls", "[-s] [-w] path"); + } + + private void printHelp() { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("ls [options] path", options); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (cl.hasOption("?")) { + printHelp(); + } + + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + retainCompatibility(cmdArgs); + + return this; + } + + private void retainCompatibility(String[] cmdArgs) throws ParseException { + // get path [watch] + if (args.length > 2) { + // rewrite to option + cmdArgs[2] = "-w"; + err.println("'ls path [watch]' has been deprecated. " + + "Please use 'ls [-w] path' instead."); + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + } + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + String path = args[1]; + boolean watch = cl.hasOption("w"); + boolean withStat = cl.hasOption("s"); + try { + Stat stat = new Stat(); + List children; + if (withStat) { + // with stat + children = zk.getChildren(path, watch, stat); + } else { + // without stat + children = zk.getChildren(path, watch); + } + out.println(printChildren(children)); + if (withStat) { + new StatPrinter(out).print(stat); + } + } catch (KeeperException.NoAuthException ex) { + err.println(ex.getMessage()); + watch = false; + } + return watch; + } + + private String printChildren(List children) { + Collections.sort(children); + StringBuilder sb = new StringBuilder(); + sb.append("["); + boolean first = true; + for (String child : children) { + if (!first) { + sb.append(", "); + } else { + first = false; + } + sb.append(child); + } + sb.append("]"); + return sb.toString(); + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java b/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java new file mode 100644 index 00000000000..418200a3dec --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java @@ -0,0 +1,147 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; + +import java.io.FileInputStream; +import java.util.Properties; + +/** + * reconfig command for cli + */ +public class ReconfigCommand extends CliCommand { + + private static Options options = new Options(); + /* version - version of config from which we want to reconfigure - if current config is different + * reconfiguration will fail. Should be ommitted from the CLI to disable this option. + */ + long version = -1; + /* joining - comma separated list of server config strings for servers to be added to the ensemble. + * Each entry is identical in syntax as it would appear in a configuration file. Only used for + * incremental reconfigurations. + */ + private String joining; + /* leaving - comma separated list of server IDs to be removed from the ensemble. Only used for + * incremental reconfigurations. + */ + private String leaving; + /* members - comma separated list of new membership information (e.g., contents of a membership + * configuration file) - for use only with a non-incremental reconfiguration. This may be specified + * manually via the -members flag or it will automatically be filled in by reading the contents + * of an actual configuration file using the -file flag. + */ + private String members; + private CommandLine cl; + + { + options.addOption("s", false, "stats"); + options.addOption("v", true, "required current config version"); + options.addOption("file", true, "path of config file to parse for membership"); + options.addOption("members", true, "comma-separated list of config strings for " + + "non-incremental reconfig"); + options.addOption("add", true, "comma-separated list of config strings for " + + "new servers"); + options.addOption("remove", true, "comma-separated list of server IDs to remove"); + } + + public ReconfigCommand() { + super("reconfig", "[-s] " + + "[-v version] " + + "[[-file path] | " + + "[-members serverID=host:port1:port2;port3[,...]*]] | " + + "[-add serverId=host:port1:port2;port3[,...]]* " + + "[-remove serverId[,...]*]"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + joining = null; + leaving = null; + members = null; + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + if (!(cl.hasOption("file") || cl.hasOption("members")) && !cl.hasOption("add") && !cl.hasOption("remove")) { + throw new ParseException(getUsageStr()); + } + if (cl.hasOption("v")) { + try { + version = Long.parseLong(cl.getOptionValue("v"), 16); + } catch (NumberFormatException e) { + throw new ParseException("-v must be followed by a long (configuration version)"); + } + } else { + version = -1; + } + + // Simple error checking for conflicting modes + if ((cl.hasOption("file") || cl.hasOption("members")) && (cl.hasOption("add") || cl.hasOption("remove"))) { + throw new ParseException("Can't use -file or -members together with -add or -remove (mixing incremental" + + " and non-incremental modes is not allowed)"); + } + if (cl.hasOption("file") && cl.hasOption("members")) { + throw new ParseException("Can't use -file and -members together (conflicting non-incremental modes)"); + } + + // Set the joining/leaving/members values based on the mode we're in + if (cl.hasOption("add")) { + joining = cl.getOptionValue("add").toLowerCase(); + } + if (cl.hasOption("remove")) { + leaving = cl.getOptionValue("remove").toLowerCase(); + } + if (cl.hasOption("members")) { + members = cl.getOptionValue("members").toLowerCase(); + } + if (cl.hasOption("file")) { + try { + FileInputStream inConfig = new FileInputStream(cl.getOptionValue("file")); + Properties dynamicCfg = new Properties(); + try { + dynamicCfg.load(inConfig); + } finally { + inConfig.close(); + } + //check that membership makes sense; leader will make these checks again + //don't check for leader election ports since + //client doesn't know what leader election alg is used + members = QuorumPeerConfig.parseDynamicConfig(dynamicCfg, 0, true, false).toString(); + } catch (Exception e) { + throw new ParseException("Error processing " + cl.getOptionValue("file") + e.getMessage()); + } + } + return this; + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + try { + Stat stat = new Stat(); + byte[] curConfig = zk.reconfig(joining, + leaving, members, version, stat); + out.println("Committed new configuration:\n" + new String(curConfig)); + + if (cl.hasOption("s")) { + new StatPrinter(out).print(stat); + } + } catch (KeeperException ex) { + err.println(ex.getMessage()); + } + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/RemoveWatchesCommand.java b/src/java/main/org/apache/zookeeper/cli/RemoveWatchesCommand.java new file mode 100644 index 00000000000..729b4384aae --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/RemoveWatchesCommand.java @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Watcher.WatcherType; + +/** + * Remove watches command for cli + */ +public class RemoveWatchesCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + private CommandLine cl; + + { + options.addOption("c", false, "child watcher type"); + options.addOption("d", false, "data watcher type"); + options.addOption("a", false, "any watcher type"); + options.addOption("l", false, + "remove locally when there is no server connection"); + } + + public RemoveWatchesCommand() { + super("removewatches", "path [-c|-d|-a] [-l]"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + return this; + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + String path = args[1]; + WatcherType wtype = WatcherType.Any; + // if no matching option -c or -d or -a is specified, we remove + // the watches of the given node by choosing WatcherType.Any + if (cl.hasOption("c")) { + wtype = WatcherType.Children; + } else if (cl.hasOption("d")) { + wtype = WatcherType.Data; + } else if (cl.hasOption("a")) { + wtype = WatcherType.Any; + } + // whether to remove the watches locally + boolean local = cl.hasOption("l"); + + try { + zk.removeAllWatches(path, wtype, local); + } catch (KeeperException.NoWatcherException ex) { + err.println(ex.getMessage()); + return false; + } + return true; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/SetAclCommand.java b/src/java/main/org/apache/zookeeper/cli/SetAclCommand.java new file mode 100644 index 00000000000..142392996d6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/SetAclCommand.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; + +import java.util.List; + +/** + * setAcl command for cli + */ +public class SetAclCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + private CommandLine cl; + + { + options.addOption("s", false, "stats"); + options.addOption("v", true, "version"); + } + + public SetAclCommand() { + super("setAcl", "[-s] [-v version] path acl"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 3) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, + InterruptedException { + String path = args[1]; + String aclStr = args[2]; + List acl = AclParser.parse(aclStr); + int version; + if (cl.hasOption("v")) { + version = Integer.parseInt(cl.getOptionValue("v")); + } else { + version = -1; + } + try { + Stat stat = zk.setACL(path, acl, version); + if (cl.hasOption("s")) { + new StatPrinter(out).print(stat); + } + } catch (KeeperException.InvalidACLException ex) { + err.println(ex.getMessage()); + } catch (KeeperException.NoAuthException ex) { + err.println(ex.getMessage()); + } + + return false; + + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/SetCommand.java b/src/java/main/org/apache/zookeeper/cli/SetCommand.java new file mode 100644 index 00000000000..5445994c0d6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/SetCommand.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; + +/** + * set command for cli + */ +public class SetCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + private CommandLine cl; + + { + options.addOption("s", false, "stats"); + options.addOption("v", true, "version"); + } + + public SetCommand() { + super("set", "[-s] [-v version] path data"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 3) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, InterruptedException { + String path = args[1]; + byte[] data = args[2].getBytes(); + int version; + if (cl.hasOption("v")) { + version = Integer.parseInt(cl.getOptionValue("v")); + } else { + version = -1; + } + + try { + Stat stat = zk.setData(path, data, version); + if (cl.hasOption("s")) { + new StatPrinter(out).print(stat); + } + } catch (KeeperException.BadVersionException ex) { + err.println(ex.getMessage()); + } + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/SetQuotaCommand.java b/src/java/main/org/apache/zookeeper/cli/SetQuotaCommand.java new file mode 100644 index 00000000000..d078013d536 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/SetQuotaCommand.java @@ -0,0 +1,205 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionGroup; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Quotas; +import org.apache.zookeeper.StatsTrack; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; + +/** + * setQuota command for cli + */ +public class SetQuotaCommand extends CliCommand { + + private static final Logger LOG = LoggerFactory.getLogger(SetQuotaCommand.class); + private Options options = new Options(); + private String[] args; + private CommandLine cl; + + public SetQuotaCommand() { + super("setquota", "-n|-b val path"); + + OptionGroup og1 = new OptionGroup(); + og1.addOption(new Option("b", true, "bytes quota")); + og1.addOption(new Option("n", true, "num quota")); + og1.setRequired(true); + options.addOptionGroup(og1); + } + + public static boolean createQuota(ZooKeeper zk, String path, + long bytes, int numNodes) + throws KeeperException, IOException, InterruptedException { + // check if the path exists. We cannot create + // quota for a path that already exists in zookeeper + // for now. + Stat initStat = zk.exists(path, false); + if (initStat == null) { + throw new IllegalArgumentException(path + " does not exist."); + } + // now check if their is already existing + // parent or child that has quota + + String quotaPath = Quotas.quotaZookeeper; + // check for more than 2 children -- + // if zookeeper_stats and zookeeper_qutoas + // are not the children then this path + // is an ancestor of some path that + // already has quota + String realPath = Quotas.quotaZookeeper + path; + try { + List children = zk.getChildren(realPath, false); + for (String child : children) { + if (!child.startsWith("zookeeper_")) { + throw new IllegalArgumentException(path + " has child " + + child + " which has a quota"); + } + } + } catch (KeeperException.NoNodeException ne) { + // this is fine + } + + //check for any parent that has been quota + checkIfParentQuota(zk, path); + + // this is valid node for quota + // start creating all the parents + if (zk.exists(quotaPath, false) == null) { + try { + zk.create(Quotas.procZookeeper, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.create(Quotas.quotaZookeeper, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ne) { + // do nothing + } + } + + // now create the direct children + // and the stat and quota nodes + String[] splits = path.split("/"); + StringBuilder sb = new StringBuilder(); + sb.append(quotaPath); + for (int i = 1; i < splits.length; i++) { + sb.append("/" + splits[i]); + quotaPath = sb.toString(); + try { + zk.create(quotaPath, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ne) { + //do nothing + } + } + String statPath = quotaPath + "/" + Quotas.statNode; + quotaPath = quotaPath + "/" + Quotas.limitNode; + StatsTrack strack = new StatsTrack(null); + strack.setBytes(bytes); + strack.setCount(numNodes); + try { + zk.create(quotaPath, strack.toString().getBytes(), + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + StatsTrack stats = new StatsTrack(null); + stats.setBytes(0L); + stats.setCount(0); + zk.create(statPath, stats.toString().getBytes(), + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ne) { + byte[] data = zk.getData(quotaPath, false, new Stat()); + StatsTrack strackC = new StatsTrack(new String(data)); + if (bytes != -1L) { + strackC.setBytes(bytes); + } + if (numNodes != -1) { + strackC.setCount(numNodes); + } + zk.setData(quotaPath, strackC.toString().getBytes(), -1); + } + return true; + } + + private static void checkIfParentQuota(ZooKeeper zk, String path) + throws InterruptedException, KeeperException { + final String[] splits = path.split("/"); + String quotaPath = Quotas.quotaZookeeper; + for (String str : splits) { + if (str.length() == 0) { + // this should only be for the beginning of the path + // i.e. "/..." - split(path)[0] is empty string before first '/' + continue; + } + quotaPath += "/" + str; + List children = null; + try { + children = zk.getChildren(quotaPath, false); + } catch (KeeperException.NoNodeException ne) { + LOG.debug("child removed during quota check", ne); + return; + } + if (children.size() == 0) { + return; + } + for (String child : children) { + if (Quotas.limitNode.equals(child)) { + throw new IllegalArgumentException(path + " has a parent " + + quotaPath + " which has a quota"); + } + } + } + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, IOException, + InterruptedException { + // get the args + String path = args[1]; + + if (cl.hasOption("b")) { + // we are setting the bytes quota + long bytes = Long.parseLong(cl.getOptionValue("b")); + createQuota(zk, path, bytes, -1); + } else if (cl.hasOption("n")) { + // we are setting the num quota + int numNodes = Integer.parseInt(cl.getOptionValue("n")); + createQuota(zk, path, -1L, numNodes); + } else { + err.println(getUsageStr()); + } + + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/StatCommand.java b/src/java/main/org/apache/zookeeper/cli/StatCommand.java new file mode 100644 index 00000000000..258894ccad7 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/StatCommand.java @@ -0,0 +1,79 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; + +/** + * stat command for cli + */ +public class StatCommand extends CliCommand { + + private static final Options options = new Options(); + + static { + options.addOption("w", false, "watch"); + } + + private String[] args; + private CommandLine cl; + + public StatCommand() { + super("stat", "[-w] path"); + } + + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + retainCompatibility(cmdArgs); + + return this; + } + + private void retainCompatibility(String[] cmdArgs) throws ParseException { + // stat path [watch] + if (args.length > 2) { + // rewrite to option + cmdArgs[2] = "-w"; + err.println("'stat path [watch]' has been deprecated. " + + "Please use 'stat [-w] path' instead."); + Parser parser = new PosixParser(); + cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + } + } + + @Override + public boolean exec() throws KeeperException, + InterruptedException { + String path = args[1]; + boolean watch = cl.hasOption("w"); + Stat stat = zk.exists(path, watch); + if (stat == null) { + throw new KeeperException.NoNodeException(path); + } + new StatPrinter(out).print(stat); + return watch; + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/StatPrinter.java b/src/java/main/org/apache/zookeeper/cli/StatPrinter.java new file mode 100644 index 00000000000..bb36ae8c9cf --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/StatPrinter.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.zookeeper.data.Stat; + +import java.io.PrintStream; +import java.util.Date; + +/** + * utility for printing stat values s + */ +public class StatPrinter { + + protected PrintStream out; + + public StatPrinter(PrintStream out) { + this.out = out; + } + + public void print(Stat stat) { + out.println("cZxid = 0x" + Long.toHexString(stat.getCzxid())); + out.println("ctime = " + new Date(stat.getCtime()).toString()); + out.println("mZxid = 0x" + Long.toHexString(stat.getMzxid())); + out.println("mtime = " + new Date(stat.getMtime()).toString()); + out.println("pZxid = 0x" + Long.toHexString(stat.getPzxid())); + out.println("cversion = " + stat.getCversion()); + out.println("dataVersion = " + stat.getVersion()); + out.println("aclVersion = " + stat.getAversion()); + out.println("ephemeralOwner = 0x" + + Long.toHexString(stat.getEphemeralOwner())); + out.println("dataLength = " + stat.getDataLength()); + out.println("numChildren = " + stat.getNumChildren()); + } +} diff --git a/src/java/main/org/apache/zookeeper/cli/SyncCommand.java b/src/java/main/org/apache/zookeeper/cli/SyncCommand.java new file mode 100644 index 00000000000..3c9fda69f54 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/cli/SyncCommand.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.Parser; +import org.apache.commons.cli.PosixParser; +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.KeeperException; + +import java.io.IOException; + +/** + * sync command for cli + */ +public class SyncCommand extends CliCommand { + + private static Options options = new Options(); + private String[] args; + + public SyncCommand() { + super("sync", "path"); + } + + @Override + public CliCommand parse(String[] cmdArgs) throws ParseException { + Parser parser = new PosixParser(); + CommandLine cl = parser.parse(options, cmdArgs); + args = cl.getArgs(); + if (args.length < 2) { + throw new ParseException(getUsageStr()); + } + + return this; + } + + @Override + public boolean exec() throws KeeperException, IOException, InterruptedException { + String path = args[1]; + zk.sync(path, new AsyncCallback.VoidCallback() { + + public void processResult(int rc, String path, Object ctx) { + out.println("Sync returned " + rc); + } + }, null); + + return false; + } +} diff --git a/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java b/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java new file mode 100644 index 00000000000..79e40f1b483 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.client; + +import org.apache.zookeeper.common.PathUtils; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.zookeeper.common.StringUtils.split; + +/** + * A parser for ZooKeeper Client connect strings. + * + * This class is not meant to be seen or used outside of ZooKeeper itself. + * + * The chrootPath member should be replaced by a Path object in issue + * ZOOKEEPER-849. + * + * @see org.apache.zookeeper.ZooKeeper + */ +public final class ConnectStringParser { + private static final int DEFAULT_PORT = 2181; + + private final String chrootPath; + + private final ArrayList serverAddresses = new ArrayList(); + + /** + * + * @throws IllegalArgumentException + * for an invalid chroot path. + */ + public ConnectStringParser(String connectString) { + // parse out chroot, if any + int off = connectString.indexOf('/'); + if (off >= 0) { + String chrootPath = connectString.substring(off); + // ignore "/" chroot spec, same as null + if (chrootPath.length() == 1) { + this.chrootPath = null; + } else { + PathUtils.validatePath(chrootPath); + this.chrootPath = chrootPath; + } + connectString = connectString.substring(0, off); + } else { + this.chrootPath = null; + } + + List hostsList = split(connectString, ","); + for (String host : hostsList) { + int port = DEFAULT_PORT; + int pidx = host.lastIndexOf(':'); + if (pidx >= 0) { + // otherwise : is at the end of the string, ignore + if (pidx < host.length() - 1) { + port = Integer.parseInt(host.substring(pidx + 1)); + } + host = host.substring(0, pidx); + } + serverAddresses.add(InetSocketAddress.createUnresolved(host, port)); + } + } + + public String getChrootPath() { + return chrootPath; + } + + public ArrayList getServerAddresses() { + return serverAddresses; + } +} diff --git a/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java b/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java new file mode 100644 index 00000000000..3a06d65218f --- /dev/null +++ b/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java @@ -0,0 +1,137 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.client; + +import org.apache.zookeeper.common.X509Exception.SSLContextException; +import org.apache.zookeeper.common.X509Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketTimeoutException; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; + +public class FourLetterWordMain { + protected static final Logger LOG = LoggerFactory.getLogger(FourLetterWordMain.class); + //in milliseconds, socket should connect/read within this period otherwise SocketTimeoutException + private static final int DEFAULT_SOCKET_TIMEOUT = 5000; + + /** + * Send the 4letterword + * @param host the destination host + * @param port the destination port + * @param cmd the 4letterword + * @return server response + * @throws java.io.IOException + * @throws SSLContextException + */ + public static String send4LetterWord(String host, int port, String cmd) + throws IOException, SSLContextException { + return send4LetterWord(host, port, cmd, false, DEFAULT_SOCKET_TIMEOUT); + } + + /** + * Send the 4letterword + * @param host the destination host + * @param port the destination port + * @param cmd the 4letterword + * @param secure whether to use SSL + * @return server response + * @throws java.io.IOException + * @throws SSLContextException + */ + public static String send4LetterWord(String host, int port, String cmd, boolean secure) + throws IOException, SSLContextException { + return send4LetterWord(host, port, cmd, secure, DEFAULT_SOCKET_TIMEOUT); + } + + /** + * Send the 4letterword + * @param host the destination host + * @param port the destination port + * @param cmd the 4letterword + * @param secure whether to use SSL + * @param timeout in milliseconds, maximum time to wait while connecting/reading data + * @return server response + * @throws java.io.IOException + * @throws SSLContextException + */ + public static String send4LetterWord(String host, int port, String cmd, boolean secure, int timeout) + throws IOException, SSLContextException { + LOG.info("connecting to {} {}", host, port); + Socket sock; + InetSocketAddress hostaddress = host != null ? new InetSocketAddress(host, port) : + new InetSocketAddress(InetAddress.getByName(null), port); + if (secure) { + LOG.info("using secure socket"); + SSLContext sslContext = X509Util.createSSLContext(); + SSLSocketFactory socketFactory = sslContext.getSocketFactory(); + SSLSocket sslSock = (SSLSocket) socketFactory.createSocket(); + sslSock.connect(hostaddress, timeout); + sslSock.startHandshake(); + sock = sslSock; + } else { + sock = new Socket(); + sock.connect(hostaddress, timeout); + } + sock.setSoTimeout(timeout); + BufferedReader reader = null; + try { + OutputStream outstream = sock.getOutputStream(); + outstream.write(cmd.getBytes()); + outstream.flush(); + + // this replicates NC - close the output stream before reading + if (!secure) { + // SSL prohibits unilateral half-close + sock.shutdownOutput(); + } + + reader = + new BufferedReader( + new InputStreamReader(sock.getInputStream())); + StringBuilder sb = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + sb.append(line + "\n"); + } + return sb.toString(); + } catch (SocketTimeoutException e) { + throw new IOException("Exception while executing four letter word: " + cmd, e); + } finally { + sock.close(); + if (reader != null) { + reader.close(); + } + } + } + + public static void main(String[] args) + throws IOException, SSLContextException { + if (args.length == 3) { + System.out.println(send4LetterWord(args[0], Integer.parseInt(args[1]), args[2])); + } else if (args.length == 4) { + System.out.println(send4LetterWord(args[0], Integer.parseInt(args[1]), args[2], Boolean.parseBoolean(args[3]))); + } else { + System.out.println("Usage: FourLetterWordMain "); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/client/HostProvider.java b/src/java/main/org/apache/zookeeper/client/HostProvider.java new file mode 100644 index 00000000000..8e09235f4dd --- /dev/null +++ b/src/java/main/org/apache/zookeeper/client/HostProvider.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.client; + +import java.net.InetSocketAddress; +import java.util.Collection; + +/** + * A set of hosts a ZooKeeper client should connect to. + * + * Classes implementing this interface must guarantee the following: + * + * * Every call to next() returns an InetSocketAddress. So the iterator never + * ends. + * + * * The size() of a HostProvider may never be zero. + * + * A HostProvider must return resolved InetSocketAddress instances on next(), + * but it's up to the HostProvider, when it wants to do the resolving. + * + * Different HostProvider could be imagined: + * + * * A HostProvider that loads the list of Hosts from an URL or from DNS + * * A HostProvider that re-resolves the InetSocketAddress after a timeout. + * * A HostProvider that prefers nearby hosts. + */ +public interface HostProvider { + public int size(); + + /** + * The next host to try to connect to. + * + * For a spinDelay of 0 there should be no wait. + * + * @param spinDelay + * Milliseconds to wait if all hosts have been tried once. + */ + public InetSocketAddress next(long spinDelay); + + /** + * Notify the HostProvider of a successful connection. + * + * The HostProvider may use this notification to reset it's inner state. + */ + public void onConnected(); + + /** + * Update the list of servers. This returns true if changing connections is necessary for load-balancing, false otherwise. + * @param serverAddresses new host list + * @param currentHost the host to which this client is currently connected + * @return true if changing connections is necessary for load-balancing, false otherwise + */ + boolean updateServerList(Collection serverAddresses, + InetSocketAddress currentHost); +} diff --git a/src/java/main/org/apache/zookeeper/client/StaticHostProvider.java b/src/java/main/org/apache/zookeeper/client/StaticHostProvider.java new file mode 100644 index 00000000000..ed74875ea34 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/client/StaticHostProvider.java @@ -0,0 +1,332 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.client; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +/** + * Most simple HostProvider, resolves only on instantiation. + * + */ +public final class StaticHostProvider implements HostProvider { + private static final Logger LOG = LoggerFactory + .getLogger(StaticHostProvider.class); + private final List oldServers = new ArrayList( + 5); + private final List newServers = new ArrayList( + 5); + private List serverAddresses = new ArrayList( + 5); + private Random sourceOfRandomness; + private int lastIndex = -1; + private int currentIndex = -1; + /** + * The following fields are used to migrate clients during reconfiguration + */ + private boolean reconfigMode = false; + private int currentIndexOld = -1; + private int currentIndexNew = -1; + + private float pOld, pNew; + + /** + * Constructs a SimpleHostSet. + * + * @param serverAddresses + * possibly unresolved ZooKeeper server addresses + * @throws IllegalArgumentException + * if serverAddresses is empty or resolves to an empty list + */ + public StaticHostProvider(Collection serverAddresses) { + sourceOfRandomness = new Random(System.currentTimeMillis() ^ this.hashCode()); + + this.serverAddresses = resolveAndShuffle(serverAddresses); + if (this.serverAddresses.isEmpty()) { + throw new IllegalArgumentException( + "A HostProvider may not be empty!"); + } + currentIndex = -1; + lastIndex = -1; + } + + /** + * Constructs a SimpleHostSet. This constructor is used from StaticHostProviderTest to produce deterministic test results + * by initializing sourceOfRandomness with the same seed + * + * @param serverAddresses + * possibly unresolved ZooKeeper server addresses + * @param randomnessSeed a seed used to initialize sourceOfRandomnes + * @throws IllegalArgumentException + * if serverAddresses is empty or resolves to an empty list + */ + public StaticHostProvider(Collection serverAddresses, + long randomnessSeed) { + sourceOfRandomness = new Random(randomnessSeed); + + this.serverAddresses = resolveAndShuffle(serverAddresses); + if (this.serverAddresses.isEmpty()) { + throw new IllegalArgumentException( + "A HostProvider may not be empty!"); + } + currentIndex = -1; + lastIndex = -1; + } + + private List resolveAndShuffle(Collection serverAddresses) { + List tmpList = new ArrayList(serverAddresses.size()); + for (InetSocketAddress address : serverAddresses) { + try { + InetAddress ia = address.getAddress(); + String addr = (ia != null) ? ia.getHostAddress() : address.getHostString(); + InetAddress resolvedAddresses[] = InetAddress.getAllByName(addr); + for (InetAddress resolvedAddress : resolvedAddresses) { + InetAddress taddr = InetAddress.getByAddress(address.getHostString(), resolvedAddress.getAddress()); + tmpList.add(new InetSocketAddress(taddr, address.getPort())); + } + } catch (UnknownHostException ex) { + LOG.warn("No IP address found for server: {}", address, ex); + } + } + Collections.shuffle(tmpList, sourceOfRandomness); + return tmpList; + } + + + /** + * Update the list of servers. This returns true if changing connections is necessary for load-balancing, false + * otherwise. Changing connections is necessary if one of the following holds: + * a) the host to which this client is currently connected is not in serverAddresses. + * Otherwise (if currentHost is in the new list serverAddresses): + * b) the number of servers in the cluster is increasing - in this case the load on currentHost should decrease, + * which means that SOME of the clients connected to it will migrate to the new servers. The decision whether + * this client migrates or not (i.e., whether true or false is returned) is probabilistic so that the expected + * number of clients connected to each server is the same. + * + * If true is returned, the function sets pOld and pNew that correspond to the probability to migrate to ones of the + * new servers in serverAddresses or one of the old servers (migrating to one of the old servers is done only + * if our client's currentHost is not in serverAddresses). See nextHostInReconfigMode for the selection logic. + * + * See {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1355} for the protocol and its evaluation, and + * StaticHostProviderTest for the tests that illustrate how load balancing works with this policy. + * @param serverAddresses new host list + * @param currentHost the host to which this client is currently connected + * @return true if changing connections is necessary for load-balancing, false otherwise + */ + + + @Override + public synchronized boolean updateServerList( + Collection serverAddresses, + InetSocketAddress currentHost) { + // Resolve server addresses and shuffle them + List resolvedList = resolveAndShuffle(serverAddresses); + if (resolvedList.isEmpty()) { + throw new IllegalArgumentException( + "A HostProvider may not be empty!"); + } + // Check if client's current server is in the new list of servers + boolean myServerInNewConfig = false; + + InetSocketAddress myServer = currentHost; + + // choose "current" server according to the client rebalancing algorithm + if (reconfigMode) { + myServer = next(0); + } + + // if the client is not currently connected to any server + if (myServer == null) { + // reconfigMode = false (next shouldn't return null). + if (lastIndex >= 0) { + // take the last server to which we were connected + myServer = this.serverAddresses.get(lastIndex); + } else { + // take the first server on the list + myServer = this.serverAddresses.get(0); + } + } + + for (InetSocketAddress addr : resolvedList) { + if (addr.getPort() == myServer.getPort() + && ((addr.getAddress() != null + && myServer.getAddress() != null && addr + .getAddress().equals(myServer.getAddress())) || addr + .getHostString().equals(myServer.getHostString()))) { + myServerInNewConfig = true; + break; + } + } + + reconfigMode = true; + + newServers.clear(); + oldServers.clear(); + // Divide the new servers into oldServers that were in the previous list + // and newServers that were not in the previous list + for (InetSocketAddress resolvedAddress : resolvedList) { + if (this.serverAddresses.contains(resolvedAddress)) { + oldServers.add(resolvedAddress); + } else { + newServers.add(resolvedAddress); + } + } + + int numOld = oldServers.size(); + int numNew = newServers.size(); + + // number of servers increased + if (numOld + numNew > this.serverAddresses.size()) { + if (myServerInNewConfig) { + // my server is in new config, but load should be decreased. + // Need to decide if this client + // is moving to one of the new servers + if (sourceOfRandomness.nextFloat() <= (1 - ((float) this.serverAddresses + .size()) / (numOld + numNew))) { + pNew = 1; + pOld = 0; + } else { + // do nothing special - stay with the current server + reconfigMode = false; + } + } else { + // my server is not in new config, and load on old servers must + // be decreased, so connect to + // one of the new servers + pNew = 1; + pOld = 0; + } + } else { // number of servers stayed the same or decreased + if (myServerInNewConfig) { + // my server is in new config, and load should be increased, so + // stay with this server and do nothing special + reconfigMode = false; + } else { + pOld = ((float) (numOld * (this.serverAddresses.size() - (numOld + numNew)))) + / ((numOld + numNew) * (this.serverAddresses.size() - numOld)); + pNew = 1 - pOld; + } + } + + if (!reconfigMode) { + currentIndex = resolvedList.indexOf(getServerAtCurrentIndex()); + } else { + currentIndex = -1; + } + this.serverAddresses = resolvedList; + currentIndexOld = -1; + currentIndexNew = -1; + lastIndex = currentIndex; + return reconfigMode; + } + + public synchronized InetSocketAddress getServerAtIndex(int i) { + if (i < 0 || i >= serverAddresses.size()) return null; + return serverAddresses.get(i); + } + + public synchronized InetSocketAddress getServerAtCurrentIndex() { + return getServerAtIndex(currentIndex); + } + + public synchronized int size() { + return serverAddresses.size(); + } + + /** + * Get the next server to connect to, when in "reconfigMode", which means that + * you've just updated the server list, and now trying to find some server to connect to. + * Once onConnected() is called, reconfigMode is set to false. Similarly, if we tried to connect + * to all servers in new config and failed, reconfigMode is set to false. + * + * While in reconfigMode, we should connect to a server in newServers with probability pNew and to servers in + * oldServers with probability pOld (which is just 1-pNew). If we tried out all servers in either oldServers + * or newServers we continue to try servers from the other set, regardless of pNew or pOld. If we tried all servers + * we give up and go back to the normal round robin mode + * + * When called, this should be protected by synchronized(this) + */ + private InetSocketAddress nextHostInReconfigMode() { + boolean takeNew = (sourceOfRandomness.nextFloat() <= pNew); + + // take one of the new servers if it is possible (there are still such + // servers we didn't try), + // and either the probability tells us to connect to one of the new + // servers or if we already + // tried all the old servers + if (((currentIndexNew + 1) < newServers.size()) + && (takeNew || (currentIndexOld + 1) >= oldServers.size())) { + ++currentIndexNew; + return newServers.get(currentIndexNew); + } + + // start taking old servers + if ((currentIndexOld + 1) < oldServers.size()) { + ++currentIndexOld; + return oldServers.get(currentIndexOld); + } + + return null; + } + + public InetSocketAddress next(long spinDelay) { + boolean needToSleep = false; + InetSocketAddress addr; + + synchronized (this) { + if (reconfigMode) { + addr = nextHostInReconfigMode(); + if (addr != null) { + currentIndex = serverAddresses.indexOf(addr); + return addr; + } + //tried all servers and couldn't connect + reconfigMode = false; + needToSleep = (spinDelay > 0); + } + ++currentIndex; + if (currentIndex == serverAddresses.size()) { + currentIndex = 0; + } + addr = serverAddresses.get(currentIndex); + needToSleep = needToSleep || (currentIndex == lastIndex && spinDelay > 0); + if (lastIndex == -1) { + // We don't want to sleep on the first ever connect attempt. + lastIndex = 0; + } + } + if (needToSleep) { + try { + Thread.sleep(spinDelay); + } catch (InterruptedException e) { + LOG.warn("Unexpected exception", e); + } + } + + return addr; + } + + public synchronized void onConnected() { + lastIndex = currentIndex; + reconfigMode = false; + } + +} diff --git a/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java b/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java new file mode 100644 index 00000000000..4da614d5fdf --- /dev/null +++ b/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java @@ -0,0 +1,571 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.client; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.ClientCnxn; +import org.apache.zookeeper.Environment; +import org.apache.zookeeper.Login; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.proto.GetSASLRequest; +import org.apache.zookeeper.proto.SetSASLResponse; +import org.apache.zookeeper.server.auth.KerberosName; +import org.ietf.jgss.GSSContext; +import org.ietf.jgss.GSSCredential; +import org.ietf.jgss.GSSException; +import org.ietf.jgss.GSSManager; +import org.ietf.jgss.Oid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.security.Principal; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.AppConfigurationEntry; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.LoginException; +import javax.security.sasl.AuthorizeCallback; +import javax.security.sasl.RealmCallback; +import javax.security.sasl.Sasl; +import javax.security.sasl.SaslClient; +import javax.security.sasl.SaslException; + +/** + * This class manages SASL authentication for the client. It + * allows ClientCnxn to authenticate using SASL with a Zookeeper server. + */ +public class ZooKeeperSaslClient { + public static final String LOGIN_CONTEXT_NAME_KEY = "zookeeper.sasl.clientconfig"; + public static final String ENABLE_CLIENT_SASL_KEY = "zookeeper.sasl.client"; + public static final String ENABLE_CLIENT_SASL_DEFAULT = "true"; + private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperSaslClient.class); + private static Login login = null; + /** informational message indicating the current configuration status */ + private final String configStatus; + private SaslClient saslClient; + private boolean isSASLConfigured = true; + + private byte[] saslToken = new byte[0]; + private SaslState saslState = SaslState.INITIAL; + private boolean gotLastPacket = false; + + public ZooKeeperSaslClient(final String serverPrincipal) + throws LoginException { + /** + * ZOOKEEPER-1373: allow system property to specify the JAAS + * configuration section that the zookeeper client should use. + * Default to "Client". + */ + String clientSection = System.getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client"); + // Note that 'Configuration' here refers to javax.security.auth.login.Configuration. + AppConfigurationEntry entries[] = null; + RuntimeException runtimeException = null; + try { + entries = Configuration.getConfiguration().getAppConfigurationEntry(clientSection); + } catch (SecurityException e) { + // handle below: might be harmless if the user doesn't intend to use JAAS authentication. + runtimeException = e; + } catch (IllegalArgumentException e) { + // third party customized getAppConfigurationEntry could throw IllegalArgumentException when JAAS + // configuration isn't set. We can reevaluate whether to catch RuntimeException instead when more + // different types of RuntimeException found + runtimeException = e; + } + if (entries != null) { + this.configStatus = "Will attempt to SASL-authenticate using Login Context section '" + clientSection + "'"; + this.saslClient = createSaslClient(serverPrincipal, clientSection); + } else { + // Handle situation of clientSection's being null: it might simply because the client does not intend to + // use SASL, so not necessarily an error. + saslState = SaslState.FAILED; + String explicitClientSection = System.getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY); + if (explicitClientSection != null) { + // If the user explicitly overrides the default Login Context, they probably expected SASL to + // succeed. But if we got here, SASL failed. + if (runtimeException != null) { + throw new LoginException("Zookeeper client cannot authenticate using the " + explicitClientSection + + " section of the supplied JAAS configuration: '" + + System.getProperty(Environment.JAAS_CONF_KEY) + "' because of a " + + "RuntimeException: " + runtimeException); + } else { + throw new LoginException("Client cannot SASL-authenticate because the specified JAAS configuration " + + "section '" + explicitClientSection + "' could not be found."); + } + } else { + // The user did not override the default context. It might be that they just don't intend to use SASL, + // so log at INFO, not WARN, since they don't expect any SASL-related information. + String msg = "Will not attempt to authenticate using SASL "; + if (runtimeException != null) { + msg += "(" + runtimeException + ")"; + } else { + msg += "(unknown error)"; + } + this.configStatus = msg; + this.isSASLConfigured = false; + } + if (System.getProperty(Environment.JAAS_CONF_KEY) != null) { + // Again, the user explicitly set something SASL-related, so they probably expected SASL to succeed. + if (runtimeException != null) { + throw new LoginException("Zookeeper client cannot authenticate using the '" + + System.getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client") + + "' section of the supplied JAAS configuration: '" + + System.getProperty(Environment.JAAS_CONF_KEY) + "' because of a " + + "RuntimeException: " + runtimeException); + } else { + throw new LoginException("No JAAS configuration section named '" + + System.getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client") + + "' was found in specified JAAS configuration file: '" + + System.getProperty(Environment.JAAS_CONF_KEY) + "'."); + } + } + } + } + + /** + * Returns true if the SASL client is enabled. By default, the client + * is enabled but can be disabled by setting the system property + * zookeeper.sasl.client to false. See + * ZOOKEEPER-1657 for more information. + * + * @return If the SASL client is enabled. + */ + public static boolean isEnabled() { + return Boolean.valueOf(System.getProperty(ENABLE_CLIENT_SASL_KEY, ENABLE_CLIENT_SASL_DEFAULT)); + } + + public SaslState getSaslState() { + return saslState; + } + + public String getLoginContext() { + if (login != null) + return login.getLoginContextName(); + return null; + } + + /** + * @return informational message indicating the current configuration status. + */ + public String getConfigStatus() { + return configStatus; + } + + public boolean isComplete() { + return (saslState == SaslState.COMPLETE); + } + + public boolean isFailed() { + return (saslState == SaslState.FAILED); + } + + synchronized private SaslClient createSaslClient(final String servicePrincipal, + final String loginContext) throws LoginException { + try { + if (login == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("JAAS loginContext is: " + loginContext); + } + // note that the login object is static: it's shared amongst all zookeeper-related connections. + // createSaslClient() must be declared synchronized so that login is initialized only once. + login = new Login(loginContext, new ClientCallbackHandler(null)); + login.startThreadIfNeeded(); + } + Subject subject = login.getSubject(); + SaslClient saslClient; + // Use subject.getPrincipals().isEmpty() as an indication of which SASL mechanism to use: + // if empty, use DIGEST-MD5; otherwise, use GSSAPI. + if (subject.getPrincipals().isEmpty()) { + // no principals: must not be GSSAPI: use DIGEST-MD5 mechanism instead. + LOG.info("Client will use DIGEST-MD5 as SASL mechanism."); + String[] mechs = {"DIGEST-MD5"}; + String username = (String) (subject.getPublicCredentials().toArray()[0]); + String password = (String) (subject.getPrivateCredentials().toArray()[0]); + // "zk-sasl-md5" is a hard-wired 'domain' parameter shared with zookeeper server code (see ServerCnxnFactory.java) + saslClient = Sasl.createSaslClient(mechs, username, "zookeeper", "zk-sasl-md5", null, new ClientCallbackHandler(password)); + return saslClient; + } else { // GSSAPI. + boolean usingNativeJgss = + Boolean.getBoolean("sun.security.jgss.native"); + if (usingNativeJgss) { + // http://docs.oracle.com/javase/6/docs/technotes/guides/security/jgss/jgss-features.html + // """ + // In addition, when performing operations as a particular + // Subject, e.g. Subject.doAs(...) or Subject.doAsPrivileged(...), + // the to-be-used GSSCredential should be added to Subject's + // private credential set. Otherwise, the GSS operations will + // fail since no credential is found. + // """ + try { + GSSManager manager = GSSManager.getInstance(); + Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2"); + GSSCredential cred = manager.createCredential(null, + GSSContext.DEFAULT_LIFETIME, + krb5Mechanism, + GSSCredential.INITIATE_ONLY); + subject.getPrivateCredentials().add(cred); + if (LOG.isDebugEnabled()) { + LOG.debug("Added private credential to subject: " + cred); + } + } catch (GSSException ex) { + LOG.warn("Cannot add private credential to subject; " + + "authentication at the server may fail", ex); + } + } + final Object[] principals = subject.getPrincipals().toArray(); + // determine client principal from subject. + final Principal clientPrincipal = (Principal) principals[0]; + final KerberosName clientKerberosName = new KerberosName(clientPrincipal.getName()); + // assume that server and client are in the same realm (by default; unless the system property + // "zookeeper.server.realm" is set). + String serverRealm = System.getProperty("zookeeper.server.realm", clientKerberosName.getRealm()); + KerberosName serviceKerberosName = new KerberosName(servicePrincipal + "@" + serverRealm); + final String serviceName = serviceKerberosName.getServiceName(); + final String serviceHostname = serviceKerberosName.getHostName(); + final String clientPrincipalName = clientKerberosName.toString(); + try { + saslClient = Subject.doAs(subject, new PrivilegedExceptionAction() { + public SaslClient run() throws SaslException { + LOG.info("Client will use GSSAPI as SASL mechanism."); + String[] mechs = {"GSSAPI"}; + LOG.debug("creating sasl client: client=" + clientPrincipalName + ";service=" + serviceName + ";serviceHostname=" + serviceHostname); + SaslClient saslClient = Sasl.createSaslClient(mechs, clientPrincipalName, serviceName, serviceHostname, null, new ClientCallbackHandler(null)); + return saslClient; + } + }); + return saslClient; + } catch (Exception e) { + LOG.error("Exception while trying to create SASL client", e); + e.printStackTrace(); + return null; + } + } + } catch (LoginException e) { + // We throw LoginExceptions... + throw e; + } catch (Exception e) { + // ..but consume (with a log message) all other types of exceptions. + LOG.error("Exception while trying to create SASL client: " + e); + return null; + } + } + + public void respondToServer(byte[] serverToken, ClientCnxn cnxn) { + if (saslClient == null) { + LOG.error("saslClient is unexpectedly null. Cannot respond to server's SASL message; ignoring."); + return; + } + + if (!(saslClient.isComplete())) { + try { + saslToken = createSaslToken(serverToken); + if (saslToken != null) { + sendSaslPacket(saslToken, cnxn); + } + } catch (SaslException e) { + LOG.error("SASL authentication failed using login context '" + + this.getLoginContext() + "'."); + saslState = SaslState.FAILED; + gotLastPacket = true; + } + } + + if (saslClient.isComplete()) { + // GSSAPI: server sends a final packet after authentication succeeds + // or fails. + if ((serverToken == null) && (saslClient.getMechanismName().equals("GSSAPI"))) + gotLastPacket = true; + // non-GSSAPI: no final packet from server. + if (!saslClient.getMechanismName().equals("GSSAPI")) { + gotLastPacket = true; + } + // SASL authentication is completed, successfully or not: + // enable the socket's writable flag so that any packets waiting for authentication to complete in + // the outgoing queue will be sent to the Zookeeper server. + cnxn.saslCompleted(); + } + } + + private byte[] createSaslToken() throws SaslException { + saslState = SaslState.INTERMEDIATE; + return createSaslToken(saslToken); + } + + private byte[] createSaslToken(final byte[] saslToken) throws SaslException { + if (saslToken == null) { + // TODO: introspect about runtime environment (such as jaas.conf) + saslState = SaslState.FAILED; + throw new SaslException("Error in authenticating with a Zookeeper Quorum member: the quorum member's saslToken is null."); + } + + Subject subject = login.getSubject(); + if (subject != null) { + synchronized (login) { + try { + final byte[] retval = + Subject.doAs(subject, new PrivilegedExceptionAction() { + public byte[] run() throws SaslException { + LOG.debug("saslClient.evaluateChallenge(len=" + saslToken.length + ")"); + return saslClient.evaluateChallenge(saslToken); + } + }); + return retval; + } catch (PrivilegedActionException e) { + String error = "An error: (" + e + ") occurred when evaluating Zookeeper Quorum Member's " + + " received SASL token."; + // Try to provide hints to use about what went wrong so they can fix their configuration. + // TODO: introspect about e: look for GSS information. + final String UNKNOWN_SERVER_ERROR_TEXT = + "(Mechanism level: Server not found in Kerberos database (7) - UNKNOWN_SERVER)"; + if (e.toString().indexOf(UNKNOWN_SERVER_ERROR_TEXT) > -1) { + error += " This may be caused by Java's being unable to resolve the Zookeeper Quorum Member's" + + " hostname correctly. You may want to try to adding" + + " '-Dsun.net.spi.nameservice.provider.1=dns,sun' to your client's JVMFLAGS environment."; + } + error += " Zookeeper Client will go to AUTH_FAILED state."; + LOG.error(error); + saslState = SaslState.FAILED; + throw new SaslException(error); + } + } + } else { + throw new SaslException("Cannot make SASL token without subject defined. " + + "For diagnosis, please look for WARNs and ERRORs in your log related to the Login class."); + } + } + + private void sendSaslPacket(byte[] saslToken, ClientCnxn cnxn) + throws SaslException { + if (LOG.isDebugEnabled()) { + LOG.debug("ClientCnxn:sendSaslPacket:length=" + saslToken.length); + } + + GetSASLRequest request = new GetSASLRequest(); + request.setToken(saslToken); + SetSASLResponse response = new SetSASLResponse(); + ServerSaslResponseCallback cb = new ServerSaslResponseCallback(); + + try { + cnxn.sendPacket(request, response, cb, ZooDefs.OpCode.sasl); + } catch (IOException e) { + throw new SaslException("Failed to send SASL packet to server.", + e); + } + } + + private void sendSaslPacket(ClientCnxn cnxn) throws SaslException { + if (LOG.isDebugEnabled()) { + LOG.debug("ClientCnxn:sendSaslPacket:length=" + saslToken.length); + } + GetSASLRequest request = new GetSASLRequest(); + request.setToken(createSaslToken()); + SetSASLResponse response = new SetSASLResponse(); + ServerSaslResponseCallback cb = new ServerSaslResponseCallback(); + try { + cnxn.sendPacket(request, response, cb, ZooDefs.OpCode.sasl); + } catch (IOException e) { + throw new SaslException("Failed to send SASL packet to server due " + + "to IOException:", e); + } + } + + // used by ClientCnxn to know whether to emit a SASL-related event: either AuthFailed or SaslAuthenticated, + // or none, if not ready yet. Sets saslState to COMPLETE as a side-effect. + public KeeperState getKeeperState() { + if (saslClient != null) { + if (saslState == SaslState.FAILED) { + return KeeperState.AuthFailed; + } + if (saslClient.isComplete()) { + if (saslState == SaslState.INTERMEDIATE) { + saslState = SaslState.COMPLETE; + return KeeperState.SaslAuthenticated; + } + } + } + // No event ready to emit yet. + return null; + } + + // Initialize the client's communications with the Zookeeper server by sending the server the first + // authentication packet. + public void initialize(ClientCnxn cnxn) throws SaslException { + if (saslClient == null) { + saslState = SaslState.FAILED; + throw new SaslException("saslClient failed to initialize properly: it's null."); + } + if (saslState == SaslState.INITIAL) { + if (saslClient.hasInitialResponse()) { + sendSaslPacket(cnxn); + } else { + byte[] emptyToken = new byte[0]; + sendSaslPacket(emptyToken, cnxn); + } + saslState = SaslState.INTERMEDIATE; + } + } + + public boolean clientTunneledAuthenticationInProgress() { + if (!isSASLConfigured) { + return false; + } + // TODO: Rather than checking a disjunction here, should be a single member + // variable or method in this class to determine whether the client is + // configured to use SASL. (see also ZOOKEEPER-1455). + try { + if ((System.getProperty(Environment.JAAS_CONF_KEY) != null) || + ((javax.security.auth.login.Configuration.getConfiguration() != null) && + (javax.security.auth.login.Configuration.getConfiguration(). + getAppConfigurationEntry(System. + getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client")) + != null))) { + // Client is configured to use a valid login Configuration, so + // authentication is either in progress, successful, or failed. + + // 1. Authentication hasn't finished yet: we must wait for it to do so. + if ((isComplete() == false) && + (isFailed() == false)) { + return true; + } + + // 2. SASL authentication has succeeded or failed.. + if (isComplete() || isFailed()) { + if (gotLastPacket == false) { + // ..but still in progress, because there is a final SASL + // message from server which must be received. + return true; + } + } + } + // Either client is not configured to use a tunnelled authentication + // scheme, or tunnelled authentication has completed (successfully or + // not), and all server SASL messages have been received. + return false; + } catch (SecurityException e) { + // Thrown if the caller does not have permission to retrieve the Configuration. + // In this case, simply returning false is correct. + if (LOG.isDebugEnabled() == true) { + LOG.debug("Could not retrieve login configuration: " + e); + } + return false; + } + } + + /** + * close login thread if running + */ + public void shutdown() { + if (null != login) { + login.shutdown(); + } + } + + public enum SaslState { + INITIAL, INTERMEDIATE, COMPLETE, FAILED + } + + public static class ServerSaslResponseCallback implements AsyncCallback.DataCallback { + public void processResult(int rc, String path, Object ctx, byte data[], Stat stat) { + // processResult() is used by ClientCnxn's sendThread to respond to + // data[] contains the Zookeeper Server's SASL token. + // ctx is the ZooKeeperSaslClient object. We use this object's respondToServer() method + // to reply to the Zookeeper Server's SASL token + ZooKeeperSaslClient client = ((ClientCnxn) ctx).zooKeeperSaslClient; + if (client == null) { + LOG.warn("sasl client was unexpectedly null: cannot respond to Zookeeper server."); + return; + } + byte[] usedata = data; + if (data != null) { + LOG.debug("ServerSaslResponseCallback(): saslToken server response: (length=" + usedata.length + ")"); + } else { + usedata = new byte[0]; + LOG.debug("ServerSaslResponseCallback(): using empty data[] as server response (length=" + usedata.length + ")"); + } + client.respondToServer(usedata, (ClientCnxn) ctx); + } + } + + // The CallbackHandler interface here refers to + // javax.security.auth.callback.CallbackHandler. + // It should not be confused with Zookeeper packet callbacks like + // org.apache.zookeeper.server.auth.SaslServerCallbackHandler. + public static class ClientCallbackHandler implements CallbackHandler { + private String password = null; + + public ClientCallbackHandler(String password) { + this.password = password; + } + + public void handle(Callback[] callbacks) throws + UnsupportedCallbackException { + for (Callback callback : callbacks) { + if (callback instanceof NameCallback) { + NameCallback nc = (NameCallback) callback; + nc.setName(nc.getDefaultName()); + } else { + if (callback instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback) callback; + if (password != null) { + pc.setPassword(this.password.toCharArray()); + } else { + LOG.warn("Could not login: the client is being asked for a password, but the Zookeeper" + + " client code does not currently support obtaining a password from the user." + + " Make sure that the client is configured to use a ticket cache (using" + + " the JAAS configuration setting 'useTicketCache=true)' and restart the client. If" + + " you still get this message after that, the TGT in the ticket cache has expired and must" + + " be manually refreshed. To do so, first determine if you are using a password or a" + + " keytab. If the former, run kinit in a Unix shell in the environment of the user who" + + " is running this Zookeeper client using the command" + + " 'kinit ' (where is the name of the client's Kerberos principal)." + + " If the latter, do" + + " 'kinit -k -t ' (where is the name of the Kerberos principal, and" + + " is the location of the keytab file). After manually refreshing your cache," + + " restart this client. If you continue to see this message after manually refreshing" + + " your cache, ensure that your KDC host's clock is in sync with this host's clock."); + } + } else { + if (callback instanceof RealmCallback) { + RealmCallback rc = (RealmCallback) callback; + rc.setText(rc.getDefaultText()); + } else { + if (callback instanceof AuthorizeCallback) { + AuthorizeCallback ac = (AuthorizeCallback) callback; + String authid = ac.getAuthenticationID(); + String authzid = ac.getAuthorizationID(); + if (authid.equals(authzid)) { + ac.setAuthorized(true); + } else { + ac.setAuthorized(false); + } + if (ac.isAuthorized()) { + ac.setAuthorizedID(authzid); + } + } else { + throw new UnsupportedCallbackException(callback, "Unrecognized SASL ClientCallback"); + } + } + } + } + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java b/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java new file mode 100644 index 00000000000..9ae2a613086 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/AtomicFileOutputStream.java @@ -0,0 +1,108 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.common; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FilterOutputStream; +import java.io.IOException; + +/* + * This code is originally from HDFS, see the similarly named files there + * in case of bug fixing, history, etc... + */ + +/** + * A FileOutputStream that has the property that it will only show up at its + * destination once it has been entirely written and flushed to disk. While + * being written, it will use a .tmp suffix. + * + * When the output stream is closed, it is flushed, fsynced, and will be moved + * into place, overwriting any file that already exists at that location. + * + * NOTE: on Windows platforms, it will not atomically replace the target + * file - instead the target file is deleted before this one is moved into + * place. + */ +public class AtomicFileOutputStream extends FilterOutputStream { + private static final String TMP_EXTENSION = ".tmp"; + + private final static Logger LOG = LoggerFactory + .getLogger(AtomicFileOutputStream.class); + + private final File origFile; + private final File tmpFile; + + public AtomicFileOutputStream(File f) throws FileNotFoundException { + // Code unfortunately must be duplicated below since we can't assign + // anything + // before calling super + super(new FileOutputStream(new File(f.getParentFile(), f.getName() + + TMP_EXTENSION))); + origFile = f.getAbsoluteFile(); + tmpFile = new File(f.getParentFile(), f.getName() + TMP_EXTENSION) + .getAbsoluteFile(); + } + + @Override + public void close() throws IOException { + boolean triedToClose = false, success = false; + try { + flush(); + ((FileOutputStream) out).getFD().sync(); + + triedToClose = true; + super.close(); + success = true; + } finally { + if (success) { + boolean renamed = tmpFile.renameTo(origFile); + if (!renamed) { + // On windows, renameTo does not replace. + if (!origFile.delete() || !tmpFile.renameTo(origFile)) { + throw new IOException( + "Could not rename temporary file " + tmpFile + + " to " + origFile); + } + } + } else { + if (!triedToClose) { + // If we failed when flushing, try to close it to not leak + // an FD + IOUtils.closeStream(out); + } + // close wasn't successful, try to delete the tmp file + if (!tmpFile.delete()) { + LOG.warn("Unable to delete tmp file " + tmpFile); + } + } + } + } + + /** + * Close the atomic file, but do not "commit" the temporary file on top of + * the destination. This should be used if there is a failure in writing. + */ + public void abort() { + try { + super.close(); + } catch (IOException ioe) { + LOG.warn("Unable to abort file " + tmpFile, ioe); + } + if (!tmpFile.delete()) { + LOG.warn("Unable to delete tmp file during abort " + tmpFile); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/common/AtomicFileWritingIdiom.java b/src/java/main/org/apache/zookeeper/common/AtomicFileWritingIdiom.java new file mode 100644 index 00000000000..77f1461deed --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/AtomicFileWritingIdiom.java @@ -0,0 +1,82 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.common; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +/* + * Used to perform an atomic write into a file. + * If there is a failure in the middle of the writing operation, + * the original file (if it exists) is left intact. + * Based on the org.apache.zookeeper.server.quorum.QuorumPeer.writeLongToFile(...) idiom + * using the HDFS AtomicFileOutputStream class. + */ +public class AtomicFileWritingIdiom { + + public AtomicFileWritingIdiom(File targetFile, OutputStreamStatement osStmt) throws IOException { + this(targetFile, osStmt, null); + } + + public AtomicFileWritingIdiom(File targetFile, WriterStatement wStmt) throws IOException { + this(targetFile, null, wStmt); + } + + private AtomicFileWritingIdiom(File targetFile, OutputStreamStatement osStmt, WriterStatement wStmt) throws IOException { + AtomicFileOutputStream out = null; + boolean error = true; + try { + out = new AtomicFileOutputStream(targetFile); + if (wStmt == null) { + // execute output stream operation + osStmt.write(out); + } else { + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); + // execute writer operation and flush + wStmt.write(bw); + bw.flush(); + } + out.flush(); + // everything went ok + error = false; + } finally { + // nothing interesting to do if out == null + if (out != null) { + if (error) { + // worst case here the tmp file/resources(fd) are not cleaned up + // and the caller will be notified (IOException) + out.abort(); + } else { + // if the close operation (rename) fails we'll get notified. + // worst case the tmp file may still exist + IOUtils.closeStream(out); + } + } + } + } + + public static interface OutputStreamStatement { + + public void write(OutputStream os) throws IOException; + + } + + public static interface WriterStatement { + + public void write(Writer os) throws IOException; + + } + +} diff --git a/src/java/main/org/apache/zookeeper/common/IOUtils.java b/src/java/main/org/apache/zookeeper/common/IOUtils.java new file mode 100644 index 00000000000..242c354056e --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/IOUtils.java @@ -0,0 +1,116 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.common; + +import org.slf4j.Logger; + +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +/* + * This code is originally from HDFS, see the similarly named files there + * in case of bug fixing, history, etc... + */ + +public class IOUtils { + /** + * Closes the stream ignoring {@link IOException}. Must only be called in + * cleaning up from exception handlers. + * + * @param stream + * the Stream to close + */ + public static void closeStream(Closeable stream) { + cleanup(null, stream); + } + + /** + * Close the Closeable objects and ignore any {@link IOException} or + * null pointers. Must only be used for cleanup in exception handlers. + * + * @param log + * the log to record problems to at debug level. Can be null. + * @param closeables + * the objects to close + */ + public static void cleanup(Logger log, Closeable... closeables) { + for (Closeable c : closeables) { + if (c != null) { + try { + c.close(); + } catch (IOException e) { + if (log != null) { + log.warn("Exception in closing " + c, e); + } + } + } + } + } + + /** + * Copies from one stream to another. + * + * @param in + * InputStrem to read from + * @param out + * OutputStream to write to + * @param buffSize + * the size of the buffer + * @param close + * whether or not close the InputStream and OutputStream at the + * end. The streams are closed in the finally clause. + */ + public static void copyBytes(InputStream in, OutputStream out, + int buffSize, boolean close) throws IOException { + try { + copyBytes(in, out, buffSize); + if (close) { + out.close(); + out = null; + in.close(); + in = null; + } + } finally { + if (close) { + closeStream(out); + closeStream(in); + } + } + } + + /** + * Copies from one stream to another. + * + * @param in + * InputStrem to read from + * @param out + * OutputStream to write to + * @param buffSize + * the size of the buffer + */ + public static void copyBytes(InputStream in, OutputStream out, int buffSize) + throws IOException { + PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null; + byte buf[] = new byte[buffSize]; + int bytesRead = in.read(buf); + while (bytesRead >= 0) { + out.write(buf, 0, bytesRead); + if ((ps != null) && ps.checkError()) { + throw new IOException("Unable to write to output stream."); + } + bytesRead = in.read(buf); + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/common/PathTrie.java b/src/java/main/org/apache/zookeeper/common/PathTrie.java new file mode 100644 index 00000000000..7032780ce80 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/PathTrie.java @@ -0,0 +1,285 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.common; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * a class that implements prefix matching for + * components of a filesystem path. the trie + * looks like a tree with edges mapping to + * the component of a path. + * example /ab/bc/cf would map to a trie + * / + * ab/ + * (ab) + * bc/ + * / + * (bc) + * cf/ + * (cf) + */ +public class PathTrie { + /** + * the logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(PathTrie.class); + + /** + * the root node of PathTrie + */ + private final TrieNode rootNode; + + /** + * construct a new PathTrie with + * a root node of / + */ + public PathTrie() { + this.rootNode = new TrieNode(null); + } + + /** + * add a path to the path trie + * @param path + */ + public void addPath(String path) { + if (path == null) { + return; + } + String[] pathComponents = path.split("/"); + TrieNode parent = rootNode; + String part = null; + if (pathComponents.length <= 1) { + throw new IllegalArgumentException("Invalid path " + path); + } + for (int i = 1; i < pathComponents.length; i++) { + part = pathComponents[i]; + if (parent.getChild(part) == null) { + parent.addChild(part, new TrieNode(parent)); + } + parent = parent.getChild(part); + } + parent.setProperty(true); + } + + /** + * delete a path from the trie + * @param path the path to be deleted + */ + public void deletePath(String path) { + if (path == null) { + return; + } + String[] pathComponents = path.split("/"); + TrieNode parent = rootNode; + String part = null; + if (pathComponents.length <= 1) { + throw new IllegalArgumentException("Invalid path " + path); + } + for (int i = 1; i < pathComponents.length; i++) { + part = pathComponents[i]; + if (parent.getChild(part) == null) { + //the path does not exist + return; + } + parent = parent.getChild(part); + LOG.info("{}", parent); + } + TrieNode realParent = parent.getParent(); + realParent.deleteChild(part); + } + + /** + * return the largest prefix for the input path. + * @param path the input path + * @return the largest prefix for the input path. + */ + public String findMaxPrefix(String path) { + if (path == null) { + return null; + } + if ("/".equals(path)) { + return path; + } + String[] pathComponents = path.split("/"); + TrieNode parent = rootNode; + List components = new ArrayList(); + if (pathComponents.length <= 1) { + throw new IllegalArgumentException("Invalid path " + path); + } + int i = 1; + String part = null; + StringBuilder sb = new StringBuilder(); + int lastindex = -1; + while ((i < pathComponents.length)) { + if (parent.getChild(pathComponents[i]) != null) { + part = pathComponents[i]; + parent = parent.getChild(part); + components.add(part); + if (parent.getProperty()) { + lastindex = i - 1; + } + } else { + break; + } + i++; + } + for (int j = 0; j < (lastindex + 1); j++) { + sb.append("/" + components.get(j)); + } + return sb.toString(); + } + + /** + * clear all nodes + */ + public void clear() { + for (String child : rootNode.getChildren()) { + rootNode.deleteChild(child); + } + } + + static class TrieNode { + final HashMap children; + boolean property = false; + TrieNode parent = null; + + /** + * create a trienode with parent + * as parameter + * @param parent the parent of this trienode + */ + private TrieNode(TrieNode parent) { + children = new HashMap(); + this.parent = parent; + } + + /** + * get the parent of this node + * @return the parent node + */ + TrieNode getParent() { + return this.parent; + } + + /** + * set the parent of this node + * @param parent the parent to set to + */ + void setParent(TrieNode parent) { + this.parent = parent; + } + + /** the property of this + * node + * @return the property for this + * node + */ + boolean getProperty() { + return this.property; + } + + /** + * a property that is set + * for a node - making it + * special. + */ + void setProperty(boolean prop) { + this.property = prop; + } + + /** + * add a child to the existing node + * @param childName the string name of the child + * @param node the node that is the child + */ + void addChild(String childName, TrieNode node) { + synchronized (children) { + if (children.containsKey(childName)) { + return; + } + children.put(childName, node); + } + } + + /** + * delete child from this node + * @param childName the string name of the child to + * be deleted + */ + void deleteChild(String childName) { + synchronized (children) { + if (!children.containsKey(childName)) { + return; + } + TrieNode childNode = children.get(childName); + // this is the only child node. + if (childNode.getChildren().length == 1) { + childNode.setParent(null); + children.remove(childName); + } else { + // their are more child nodes + // so just reset property. + childNode.setProperty(false); + } + } + } + + /** + * return the child of a node mapping + * to the input childname + * @param childName the name of the child + * @return the child of a node + */ + TrieNode getChild(String childName) { + synchronized (children) { + if (!children.containsKey(childName)) { + return null; + } else { + return children.get(childName); + } + } + } + + /** + * get the list of children of this + * trienode. + * @param node to get its children + * @return the string list of its children + */ + String[] getChildren() { + synchronized (children) { + return children.keySet().toArray(new String[0]); + } + } + + /** + * get the string representation + * for this node + */ + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Children of trienode: "); + synchronized (children) { + for (String str : children.keySet()) { + sb.append(" " + str); + } + } + return sb.toString(); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/common/PathUtils.java b/src/java/main/org/apache/zookeeper/common/PathUtils.java new file mode 100644 index 00000000000..ded197daa82 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/PathUtils.java @@ -0,0 +1,113 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.common; + + +/** + * Path related utilities + */ +public class PathUtils { + + /** validate the provided znode path string + * @param path znode path string + * @param isSequential if the path is being created + * with a sequential flag + * @throws IllegalArgumentException if the path is invalid + */ + public static void validatePath(String path, boolean isSequential) + throws IllegalArgumentException { + validatePath(isSequential ? path + "1" : path); + } + + /** + * Validate the provided znode path string + * @param path znode path string + * @throws IllegalArgumentException if the path is invalid + */ + public static void validatePath(String path) throws IllegalArgumentException { + if (path == null) { + throw new IllegalArgumentException("Path cannot be null"); + } + if (path.length() == 0) { + throw new IllegalArgumentException("Path length must be > 0"); + } + if (path.charAt(0) != '/') { + throw new IllegalArgumentException( + "Path must start with / character"); + } + if (path.length() == 1) { // done checking - it's the root + return; + } + if (path.charAt(path.length() - 1) == '/') { + throw new IllegalArgumentException( + "Path must not end with / character"); + } + + String reason = null; + char lastc = '/'; + char chars[] = path.toCharArray(); + char c; + for (int i = 1; i < chars.length; lastc = chars[i], i++) { + c = chars[i]; + + if (c == 0) { + reason = "null character not allowed @" + i; + break; + } else if (c == '/' && lastc == '/') { + reason = "empty node name specified @" + i; + break; + } else if (c == '.' && lastc == '.') { + if (chars[i - 2] == '/' && + ((i + 1 == chars.length) + || chars[i + 1] == '/')) { + reason = "relative paths not allowed @" + i; + break; + } + } else if (c == '.') { + if (chars[i - 1] == '/' && + ((i + 1 == chars.length) + || chars[i + 1] == '/')) { + reason = "relative paths not allowed @" + i; + break; + } + } else if (c > '\u0000' && c <= '\u001f' + || c >= '\u007f' && c <= '\u009F' + || c >= '\ud800' && c <= '\uf8ff' + || c >= '\ufff0' && c <= '\uffff') { + reason = "invalid charater @" + i; + break; + } + } + + if (reason != null) { + throw new IllegalArgumentException( + "Invalid path string \"" + path + "\" caused by " + reason); + } + } + + /** + * Convert Windows path to Unix + * + * @param path + * file path + * @return converted file path + */ + public static String normalizeFileSystemPath(String path) { + if (path != null) { + String osname = java.lang.System.getProperty("os.name"); + if (osname.toLowerCase().contains("windows")) { + return path.replace('\\', '/'); + } + } + return path; + } +} diff --git a/src/java/main/org/apache/zookeeper/common/StringUtils.java b/src/java/main/org/apache/zookeeper/common/StringUtils.java new file mode 100644 index 00000000000..6fa58fe2c9b --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/StringUtils.java @@ -0,0 +1,57 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.common; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class StringUtils { + + private StringUtils() {/** non instantiable and non inheritable **/} + + /** + * This method returns an immutable List, but different from String's split() it trims the results in the input String, and removes any empty string from the resulting List. + */ + public static List split(String value, String separator) { + String[] splits = value.split(separator); + List results = new ArrayList(); + for (int i = 0; i < splits.length; i++) { + splits[i] = splits[i].trim(); + if (splits[i].length() > 0) { + results.add(splits[i]); + } + } + return Collections.unmodifiableList(results); + } + + /** + * This method takes a List and a delimiter and joins the strings into a single string, where the original strings are separated using the given delimiter. + */ + public static String joinStrings(List list, String delim) { + if (list == null) + return null; + + StringBuilder builder = new StringBuilder(list.get(0)); + for (String s : list.subList(1, list.size())) { + builder.append(delim).append(s); + } + + return builder.toString(); + } +} diff --git a/src/java/main/org/apache/zookeeper/common/Time.java b/src/java/main/org/apache/zookeeper/common/Time.java new file mode 100644 index 00000000000..89c67b27e60 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/Time.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.common; + +import java.util.Date; + +public class Time { + /** + * Returns time in milliseconds as does System.currentTimeMillis(), + * but uses elapsed time from an arbitrary epoch more like System.nanoTime(). + * The difference is that if somebody changes the system clock, + * Time.currentElapsedTime will change but nanoTime won't. On the other hand, + * all of ZK assumes that time is measured in milliseconds. + * @return The time in milliseconds from some arbitrary point in time. + */ + public static long currentElapsedTime() { + return System.nanoTime() / 1000000; + } + + /** + * Explicitly returns system dependent current wall time. + * @return Current time in msec. + */ + public static long currentWallTime() { + return System.currentTimeMillis(); + } + + /** + * This is to convert the elapsedTime to a Date. + * @return A date object indicated by the elapsedTime. + */ + public static Date elapsedTimeToDate(long elapsedTime) { + long wallTime = currentWallTime() + elapsedTime - currentElapsedTime(); + return new Date(wallTime); + } +} \ No newline at end of file diff --git a/src/java/main/org/apache/zookeeper/common/X509Exception.java b/src/java/main/org/apache/zookeeper/common/X509Exception.java new file mode 100644 index 00000000000..4fe4c345b25 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/X509Exception.java @@ -0,0 +1,60 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.common; + +@SuppressWarnings("serial") +public class X509Exception extends Exception { + public X509Exception(String message) { + super(message); + } + + public X509Exception(Throwable cause) { + super(cause); + } + + public X509Exception(String message, Throwable cause) { + super(message, cause); + } + + public static class KeyManagerException extends X509Exception { + public KeyManagerException(String message) { + super(message); + } + + public KeyManagerException(Throwable cause) { + super(cause); + } + } + + public static class TrustManagerException extends X509Exception { + public TrustManagerException(String message) { + super(message); + } + + public TrustManagerException(Throwable cause) { + super(cause); + } + } + + public static class SSLContextException extends X509Exception { + public SSLContextException(String message) { + super(message); + } + + public SSLContextException(Throwable cause) { + super(cause); + } + + public SSLContextException(String message, Throwable cause) { + super(message, cause); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/common/X509Util.java b/src/java/main/org/apache/zookeeper/common/X509Util.java new file mode 100644 index 00000000000..0207d551570 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/common/X509Util.java @@ -0,0 +1,162 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.common; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.KeyStore; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509KeyManager; +import javax.net.ssl.X509TrustManager; + +import static org.apache.zookeeper.common.X509Exception.KeyManagerException; +import static org.apache.zookeeper.common.X509Exception.SSLContextException; +import static org.apache.zookeeper.common.X509Exception.TrustManagerException; + +/** + * Utility code for X509 handling + */ +public class X509Util { + public static final String SSL_KEYSTORE_LOCATION = "zookeeper.ssl.keyStore.location"; + public static final String SSL_KEYSTORE_PASSWD = "zookeeper.ssl.keyStore.password"; + public static final String SSL_TRUSTSTORE_LOCATION = "zookeeper.ssl.trustStore.location"; + public static final String SSL_TRUSTSTORE_PASSWD = "zookeeper.ssl.trustStore.password"; + public static final String SSL_AUTHPROVIDER = "zookeeper.ssl.authProvider"; + private static final Logger LOG = LoggerFactory.getLogger(X509Util.class); + + public static SSLContext createSSLContext() throws SSLContextException { + KeyManager[] keyManagers = null; + TrustManager[] trustManagers = null; + + String keyStoreLocationProp = System.getProperty(SSL_KEYSTORE_LOCATION); + String keyStorePasswordProp = System.getProperty(SSL_KEYSTORE_PASSWD); + + // There are legal states in some use cases for null KeyManager or TrustManager. + // But if a user wanna specify one, location and password are required. + + if (keyStoreLocationProp == null && keyStorePasswordProp == null) { + LOG.warn("keystore not specified for client connection"); + } else { + if (keyStoreLocationProp == null) { + throw new SSLContextException("keystore location not specified for client connection"); + } + if (keyStorePasswordProp == null) { + throw new SSLContextException("keystore password not specified for client connection"); + } + try { + keyManagers = new KeyManager[]{ + createKeyManager(keyStoreLocationProp, keyStorePasswordProp)}; + } catch (KeyManagerException e) { + throw new SSLContextException("Failed to create KeyManager", e); + } + } + + String trustStoreLocationProp = System.getProperty(SSL_TRUSTSTORE_LOCATION); + String trustStorePasswordProp = System.getProperty(SSL_TRUSTSTORE_PASSWD); + + if (trustStoreLocationProp == null && trustStorePasswordProp == null) { + LOG.warn("keystore not specified for client connection"); + } else { + if (trustStoreLocationProp == null) { + throw new SSLContextException("keystore location not specified for client connection"); + } + if (trustStorePasswordProp == null) { + throw new SSLContextException("keystore password not specified for client connection"); + } + try { + trustManagers = new TrustManager[]{ + createTrustManager(trustStoreLocationProp, trustStorePasswordProp)}; + } catch (TrustManagerException e) { + throw new SSLContextException("Failed to create KeyManager", e); + } + } + + SSLContext sslContext = null; + try { + sslContext = SSLContext.getInstance("TLSv1"); + sslContext.init(keyManagers, trustManagers, null); + } catch (Exception e) { + throw new SSLContextException(e); + } + return sslContext; + } + + public static X509KeyManager createKeyManager(String keyStoreLocation, String keyStorePassword) + throws KeyManagerException { + FileInputStream inputStream = null; + try { + char[] keyStorePasswordChars = keyStorePassword.toCharArray(); + File keyStoreFile = new File(keyStoreLocation); + KeyStore ks = KeyStore.getInstance("JKS"); + inputStream = new FileInputStream(keyStoreFile); + ks.load(inputStream, keyStorePasswordChars); + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(ks, keyStorePasswordChars); + + for (KeyManager km : kmf.getKeyManagers()) { + if (km instanceof X509KeyManager) { + return (X509KeyManager) km; + } + } + throw new KeyManagerException("Couldn't find X509KeyManager"); + + } catch (Exception e) { + throw new KeyManagerException(e); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + } + } + } + } + + public static X509TrustManager createTrustManager(String trustStoreLocation, String trustStorePassword) + throws TrustManagerException { + FileInputStream inputStream = null; + try { + char[] trustStorePasswordChars = trustStorePassword.toCharArray(); + File trustStoreFile = new File(trustStoreLocation); + KeyStore ts = KeyStore.getInstance("JKS"); + inputStream = new FileInputStream(trustStoreFile); + ts.load(inputStream, trustStorePasswordChars); + TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); + tmf.init(ts); + + for (TrustManager tm : tmf.getTrustManagers()) { + if (tm instanceof X509TrustManager) { + return (X509TrustManager) tm; + } + } + throw new TrustManagerException("Couldn't find X509TrustManager"); + } catch (Exception e) { + throw new TrustManagerException(e); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + } + } + } + } +} \ No newline at end of file diff --git a/src/java/main/org/apache/zookeeper/jmx/CommonNames.java b/src/java/main/org/apache/zookeeper/jmx/CommonNames.java new file mode 100644 index 00000000000..ceeac53d600 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/jmx/CommonNames.java @@ -0,0 +1,22 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.jmx; + +/** + * A bunch of constants. + * TODO: will get rid of it eventually. + */ +public class CommonNames { + public static final String DOMAIN = "org.apache.ZooKeeperService"; + public static final String DATA_TREE_KEY = "DataTree"; + public static final String STANDALONE_SERVER_KEY = "StandaloneServer"; +} diff --git a/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java b/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java new file mode 100644 index 00000000000..820a074bf58 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java @@ -0,0 +1,215 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.jmx; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.management.ManagementFactory; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import javax.management.JMException; +import javax.management.MBeanServer; +import javax.management.MBeanServerFactory; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +/** + * This class provides a unified interface for registering/unregistering of + * zookeeper MBeans with the platform MBean server. It builds a hierarchy of MBeans + * where each MBean represented by a filesystem-like path. Eventually, this hierarchy + * will be stored in the zookeeper data tree instance as a virtual data tree. + */ +public class MBeanRegistry { + private static final Logger LOG = LoggerFactory.getLogger(MBeanRegistry.class); + + private static volatile MBeanRegistry instance = new MBeanRegistry(); + + private final Object LOCK = new Object(); + + private Map mapBean2Path = + new ConcurrentHashMap(); + + private MBeanServer mBeanServer; + + public MBeanRegistry() { + try { + mBeanServer = ManagementFactory.getPlatformMBeanServer(); + } catch (Error e) { + // Account for running within IKVM and create a new MBeanServer + // if the PlatformMBeanServer does not exist. + mBeanServer = MBeanServerFactory.createMBeanServer(); + } + } + + public static MBeanRegistry getInstance() { + return instance; + } + + /** + * Useful for unit tests. Change the MBeanRegistry instance + * + * @param instance new instance + */ + public static void setInstance(MBeanRegistry instance) { + MBeanRegistry.instance = instance; + } + + /** + * Return the underlying MBeanServer that is being + * used to register MBean's. The returned MBeanServer + * may be a new empty MBeanServer if running through IKVM. + */ + public MBeanServer getPlatformMBeanServer() { + return mBeanServer; + } + + /** + * Registers a new MBean with the platform MBean server. + * @param bean the bean being registered + * @param parent if not null, the new bean will be registered as a child + * node of this parent. + */ + public void register(ZKMBeanInfo bean, ZKMBeanInfo parent) + throws JMException { + assert bean != null; + String path = null; + if (parent != null) { + path = mapBean2Path.get(parent); + assert path != null; + } + path = makeFullPath(path, parent); + if (bean.isHidden()) + return; + ObjectName oname = makeObjectName(path, bean); + try { + synchronized (LOCK) { + mBeanServer.registerMBean(bean, oname); + mapBean2Path.put(bean, path); + } + } catch (JMException e) { + LOG.warn("Failed to register MBean " + bean.getName()); + throw e; + } + } + + /** + * Unregister the MBean identified by the path. + * @param path + * @param bean + */ + private void unregister(String path, ZKMBeanInfo bean) throws JMException { + if (path == null) + return; + if (!bean.isHidden()) { + final ObjectName objName = makeObjectName(path, bean); + if (LOG.isInfoEnabled()) { + LOG.info("Unregister MBean [{}]", objName); + } + synchronized (LOCK) { + mBeanServer.unregisterMBean(objName); + } + } + } + + /** + * @return a {@link Collection} with the {@link ZKMBeanInfo} instances not + * unregistered. Mainly for testing purposes. + */ + public Set getRegisteredBeans() { + return new HashSet(mapBean2Path.keySet()); + } + + /** + * Unregister MBean. + * @param bean + */ + public void unregister(ZKMBeanInfo bean) { + if (bean == null) + return; + String path = mapBean2Path.remove(bean); + try { + unregister(path, bean); + } catch (JMException e) { + LOG.warn("Error during unregister of [{}]", bean.getName(), e); + } catch (Throwable t) { + LOG.error("Unexpected exception during unregister of [{}]. It should be reviewed and fixed.", bean.getName(), t); + } + } + + /** + * Generate a filesystem-like path. + * @param prefix path prefix + * @param name path elements + * @return absolute path + */ + public String makeFullPath(String prefix, String... name) { + StringBuilder sb = new StringBuilder(prefix == null ? "/" : (prefix.equals("/") ? prefix : prefix + "/")); + boolean first = true; + for (String s : name) { + if (s == null) continue; + if (!first) { + sb.append("/"); + } else + first = false; + sb.append(s); + } + return sb.toString(); + } + + protected String makeFullPath(String prefix, ZKMBeanInfo bean) { + return makeFullPath(prefix, bean == null ? null : bean.getName()); + } + + /** + * This takes a path, such as /a/b/c, and converts it to + * name0=a,name1=b,name2=c + */ + private int tokenize(StringBuilder sb, String path, int index) { + String[] tokens = path.split("/"); + for (String s : tokens) { + if (s.length() == 0) + continue; + sb.append("name").append(index++) + .append("=").append(s).append(","); + } + return index; + } + + /** + * Builds an MBean path and creates an ObjectName instance using the path. + * @param path MBean path + * @param bean the MBean instance + * @return ObjectName to be registered with the platform MBean server + */ + protected ObjectName makeObjectName(String path, ZKMBeanInfo bean) + throws MalformedObjectNameException { + if (path == null) + return null; + StringBuilder beanName = new StringBuilder(CommonNames.DOMAIN + ":"); + int counter = 0; + counter = tokenize(beanName, path, counter); + tokenize(beanName, bean.getName(), counter); + beanName.deleteCharAt(beanName.length() - 1); + try { + return new ObjectName(beanName.toString()); + } catch (MalformedObjectNameException e) { + LOG.warn("Invalid name \"" + beanName.toString() + "\" for class " + + bean.getClass().toString()); + throw e; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java b/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java new file mode 100644 index 00000000000..c6de6df36c3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java @@ -0,0 +1,113 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.jmx; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Enumeration; + +import javax.management.JMException; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +/** + * Shared utilities + */ +public class ManagedUtil { + private static final Logger LOG = LoggerFactory.getLogger(ManagedUtil.class); + + private static final boolean isLog4jJmxEnabled() { + boolean enabled = false; + + try { + Class.forName("org.apache.log4j.spi.LoggerRepository"); + + if (Boolean.getBoolean("zookeeper.jmx.log4j.disable") == true) { + LOG.info("Log4j found but jmx support is disabled."); + } else { + enabled = true; + LOG.info("Log4j found with jmx enabled."); + } + + } catch (ClassNotFoundException e) { + LOG.info("Log4j not found."); + } + + return enabled; + } + + + /** + * Register the log4j JMX mbeans. Set environment variable + * "zookeeper.jmx.log4j.disable" to true to disable registration. + * @see http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html + * @throws JMException if registration fails + */ + @SuppressWarnings("rawtypes") + public static void registerLog4jMBeans() throws JMException { + if (isLog4jJmxEnabled()) { + LOG.debug("registerLog4jMBeans()"); + MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer(); + + try { + // Create and Register the top level Log4J MBean + // org.apache.log4j.jmx.HierarchyDynamicMBean hdm = new org.apache.log4j.jmx.HierarchyDynamicMBean(); + Object hdm = Class.forName("org.apache.log4j.jmx.HierarchyDynamicMBean").newInstance(); + + ObjectName mbo = new ObjectName("log4j:hiearchy=default"); + mbs.registerMBean(hdm, mbo); + + // Add the root logger to the Hierarchy MBean + // org.apache.log4j.Logger rootLogger = + // org.apache.log4j.Logger.getRootLogger(); + Object rootLogger = Class.forName("org.apache.log4j.Logger") + .getMethod("getRootLogger", (Class[]) null) + .invoke(null, (Object[]) null); + + // hdm.addLoggerMBean(rootLogger.getName()); + Object rootLoggerName = rootLogger.getClass() + .getMethod("getName", (Class[]) null) + .invoke(rootLogger, (Object[]) null); + hdm.getClass().getMethod("addLoggerMBean", String.class) + .invoke(hdm, rootLoggerName); + + // Get each logger from the Log4J Repository and add it to the + // Hierarchy MBean created above. + // org.apache.log4j.spi.LoggerRepository r = + // org.apache.log4j.LogManager.getLoggerRepository(); + Object r = Class.forName("org.apache.log4j.LogManager") + .getMethod("getLoggerRepository", (Class[]) null) + .invoke(null, (Object[]) null); + + // Enumeration enumer = r.getCurrentLoggers(); + Enumeration enumer = (Enumeration) r.getClass() + .getMethod("getCurrentLoggers", (Class[]) null) + .invoke(r, (Object[]) null); + + while (enumer.hasMoreElements()) { + Object logger = enumer.nextElement(); + // hdm.addLoggerMBean(logger.getName()); + Object loggerName = logger.getClass() + .getMethod("getName", (Class[]) null) + .invoke(logger, (Object[]) null); + hdm.getClass().getMethod("addLoggerMBean", String.class) + .invoke(hdm, loggerName); + } + } catch (Exception e) { + LOG.error("Problems while registering log4j jmx beans!", e); + throw new JMException(e.toString()); + } + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java b/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java new file mode 100644 index 00000000000..3412b46d83c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.jmx; + +/** + * Zookeeper MBean info interface. MBeanRegistry uses the interface to generate + * JMX object name. + */ +public interface ZKMBeanInfo { + /** + * @return a string identifying the MBean + */ + public String getName(); + + /** + * If isHidden returns true, the MBean won't be registered with MBean server, + * and thus won't be available for management tools. Used for grouping MBeans. + * @return true if the MBean is hidden. + */ + public boolean isHidden(); +} diff --git a/src/java/main/org/apache/zookeeper/server/ByteBufferInputStream.java b/src/java/main/org/apache/zookeeper/server/ByteBufferInputStream.java new file mode 100644 index 00000000000..564bba5f8cc --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ByteBufferInputStream.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.Record; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; + +public class ByteBufferInputStream extends InputStream { + ByteBuffer bb; + + public ByteBufferInputStream(ByteBuffer bb) { + this.bb = bb; + } + + static public void byteBuffer2Record(ByteBuffer bb, Record record) + throws IOException { + BinaryInputArchive ia; + ia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); + record.deserialize(ia, "request"); + } + + @Override + public int read() throws IOException { + if (bb.remaining() == 0) { + return -1; + } + return bb.get() & 0xff; + } + + @Override + public int available() throws IOException { + return bb.remaining(); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (bb.remaining() == 0) { + return -1; + } + if (len > bb.remaining()) { + len = bb.remaining(); + } + bb.get(b, off, len); + return len; + } + + @Override + public int read(byte[] b) throws IOException { + return read(b, 0, b.length); + } + + @Override + public long skip(long n) throws IOException { + if (n < 0L) { + return 0; + } + n = Math.min(n, bb.remaining()); + bb.position(bb.position() + (int) n); + return n; + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/ByteBufferOutputStream.java b/src/java/main/org/apache/zookeeper/server/ByteBufferOutputStream.java new file mode 100644 index 00000000000..b2cd9b0dd5d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ByteBufferOutputStream.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +public class ByteBufferOutputStream extends OutputStream { + ByteBuffer bb; + + public ByteBufferOutputStream(ByteBuffer bb) { + this.bb = bb; + } + + static public void record2ByteBuffer(Record record, ByteBuffer bb) + throws IOException { + BinaryOutputArchive oa; + oa = BinaryOutputArchive.getArchive(new ByteBufferOutputStream(bb)); + record.serialize(oa, "request"); + } + + @Override + public void write(int b) throws IOException { + bb.put((byte) b); + } + + @Override + public void write(byte[] b) throws IOException { + bb.put(b); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + bb.put(b, off, len); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ConnectionBean.java b/src/java/main/org/apache/zookeeper/server/ConnectionBean.java new file mode 100644 index 00000000000..ddbf6873693 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ConnectionBean.java @@ -0,0 +1,166 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.jmx.ZKMBeanInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Arrays; + +import javax.management.ObjectName; + +/** + * Implementation of connection MBean interface. + */ +public class ConnectionBean implements ConnectionMXBean, ZKMBeanInfo { + private static final Logger LOG = LoggerFactory.getLogger(ConnectionBean.class); + + private final ServerCnxn connection; + private final Stats stats; + + private final ZooKeeperServer zk; + + private final String remoteIP; + private final long sessionId; + + public ConnectionBean(ServerCnxn connection, ZooKeeperServer zk) { + this.connection = connection; + this.stats = connection; + this.zk = zk; + + InetSocketAddress sockAddr = connection.getRemoteSocketAddress(); + if (sockAddr == null) { + remoteIP = "Unknown"; + } else { + InetAddress addr = sockAddr.getAddress(); + if (addr instanceof Inet6Address) { + remoteIP = ObjectName.quote(addr.getHostAddress()); + } else { + remoteIP = addr.getHostAddress(); + } + } + sessionId = connection.getSessionId(); + } + + public String getSessionId() { + return "0x" + Long.toHexString(sessionId); + } + + public String getSourceIP() { + InetSocketAddress sockAddr = connection.getRemoteSocketAddress(); + if (sockAddr == null) { + return null; + } + return sockAddr.getAddress().getHostAddress() + + ":" + sockAddr.getPort(); + } + + public String getName() { + return MBeanRegistry.getInstance().makeFullPath("Connections", remoteIP, + getSessionId()); + } + + public boolean isHidden() { + return false; + } + + public String[] getEphemeralNodes() { + if (zk.getZKDatabase() != null) { + String[] res = zk.getZKDatabase().getEphemerals(sessionId) + .toArray(new String[0]); + Arrays.sort(res); + return res; + } + return null; + } + + public String getStartedTime() { + return stats.getEstablished().toString(); + } + + public void terminateSession() { + try { + zk.closeSession(sessionId); + } catch (Exception e) { + LOG.warn("Unable to closeSession() for session: 0x" + + getSessionId(), e); + } + } + + public void terminateConnection() { + connection.sendCloseSession(); + } + + public void resetCounters() { + stats.resetStats(); + } + + @Override + public String toString() { + return "ConnectionBean{ClientIP=" + ObjectName.quote(getSourceIP()) + + ",SessionId=0x" + getSessionId() + "}"; + } + + public long getOutstandingRequests() { + return stats.getOutstandingRequests(); + } + + public long getPacketsReceived() { + return stats.getPacketsReceived(); + } + + public long getPacketsSent() { + return stats.getPacketsSent(); + } + + public int getSessionTimeout() { + return connection.getSessionTimeout(); + } + + public long getMinLatency() { + return stats.getMinLatency(); + } + + public long getAvgLatency() { + return stats.getAvgLatency(); + } + + public long getMaxLatency() { + return stats.getMaxLatency(); + } + + public String getLastOperation() { + return stats.getLastOperation(); + } + + public String getLastCxid() { + return "0x" + Long.toHexString(stats.getLastCxid()); + } + + public String getLastZxid() { + return "0x" + Long.toHexString(stats.getLastZxid()); + } + + public String getLastResponseTime() { + return Time.elapsedTimeToDate(stats.getLastResponseTime()).toString(); + } + + public long getLastLatency() { + return stats.getLastLatency(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java b/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java new file mode 100644 index 00000000000..97eee6bcdc2 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java @@ -0,0 +1,106 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +/** + * This MBean represents a client connection. + */ +public interface ConnectionMXBean { + /** + * @return source (client) IP address + */ + public String getSourceIP(); + + /** + * @return client's session id + */ + public String getSessionId(); + + /** + * @return time the connection was started + */ + public String getStartedTime(); + + /** + * @return number of ephemeral nodes owned by this connection + */ + public String[] getEphemeralNodes(); + + /** + * @return packets received from this client + */ + public long getPacketsReceived(); + + /** + * @return number of packets sent to this client + */ + public long getPacketsSent(); + + /** + * @return number of requets being processed + */ + public long getOutstandingRequests(); + + /** + * @return session timeout in ms + */ + public int getSessionTimeout(); + + /** + * Terminate this client session. The client will reconnect with a different + * session id. + */ + public void terminateSession(); + + /** + * Terminate thei client connection. The client will immediately attempt to + * reconnect with the same session id. + */ + public void terminateConnection(); + + + /** Min latency in ms + * @since 3.3.0 */ + long getMinLatency(); + + /** Average latency in ms + * @since 3.3.0 */ + long getAvgLatency(); + + /** Max latency in ms + * @since 3.3.0 */ + long getMaxLatency(); + + /** Last operation performed by this connection + * @since 3.3.0 */ + String getLastOperation(); + + /** Last cxid of this connection + * @since 3.3.0 */ + String getLastCxid(); + + /** Last zxid of this connection + * @since 3.3.0 */ + String getLastZxid(); + + /** Last time server sent a response to client on this connection + * @since 3.3.0 */ + String getLastResponseTime(); + + /** Latency of last response to client on this connection in ms + * @since 3.3.0 */ + long getLastLatency(); + + /** Reset counters + * @since 3.3.0 */ + void resetCounters(); +} diff --git a/src/java/main/org/apache/zookeeper/server/ContainerManager.java b/src/java/main/org/apache/zookeeper/server/ContainerManager.java new file mode 100644 index 00000000000..3ed43341c72 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ContainerManager.java @@ -0,0 +1,154 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.common.Time; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Manages cleanup of container ZNodes. This class is meant to only + * be run from the leader. There's no harm in running from followers/observers + * but that will be extra work that's not needed. Once started, it periodically + * checks container nodes that have a cversion > 0 and have no children. A + * delete is attempted on the node. The result of the delete is unimportant. + * If the proposal fails or the container node is not empty there's no harm. + */ +public class ContainerManager { + private static final Logger LOG = LoggerFactory.getLogger(ContainerManager.class); + private final ZKDatabase zkDb; + private final RequestProcessor requestProcessor; + private final int checkIntervalMs; + private final int maxPerMinute; + private final Timer timer; + private final AtomicReference task = new AtomicReference(null); + + /** + * @param zkDb the ZK database + * @param requestProcessor request processer - used to inject delete + * container requests + * @param checkIntervalMs how often to check containers in milliseconds + * @param maxPerMinute the max containers to delete per second - avoids + * herding of container deletions + */ + public ContainerManager(ZKDatabase zkDb, RequestProcessor requestProcessor, + int checkIntervalMs, int maxPerMinute) { + this.zkDb = zkDb; + this.requestProcessor = requestProcessor; + this.checkIntervalMs = checkIntervalMs; + this.maxPerMinute = maxPerMinute; + timer = new Timer("ContainerManagerTask", true); + + LOG.info(String.format("Using checkIntervalMs=%d maxPerMinute=%d", + checkIntervalMs, maxPerMinute)); + } + + /** + * start/restart the timer the runs the check. Can safely be called + * multiple times. + */ + public void start() { + if (task.get() == null) { + TimerTask timerTask = new TimerTask() { + @Override + public void run() { + try { + checkContainers(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LOG.info("interrupted"); + cancel(); + } catch (Throwable e) { + LOG.error("Error checking containers", e); + } + } + }; + if (task.compareAndSet(null, timerTask)) { + timer.scheduleAtFixedRate(timerTask, checkIntervalMs, + checkIntervalMs); + } + } + } + + /** + * stop the timer if necessary. Can safely be called multiple times. + */ + public void stop() { + TimerTask timerTask = task.getAndSet(null); + if (timerTask != null) { + timerTask.cancel(); + } + } + + /** + * Manually check the containers. Not normally used directly + */ + public void checkContainers() + throws InterruptedException { + long minIntervalMs = getMinIntervalMs(); + for (String containerPath : getCandidates()) { + long startMs = Time.currentElapsedTime(); + + ByteBuffer path = ByteBuffer.wrap(containerPath.getBytes()); + Request request = new Request(null, 0, 0, + ZooDefs.OpCode.deleteContainer, path, null); + try { + LOG.info("Attempting to delete candidate container: %s", + containerPath); + requestProcessor.processRequest(request); + } catch (Exception e) { + LOG.error(String.format("Could not delete container: %s", + containerPath), e); + } + + long elapsedMs = Time.currentElapsedTime() - startMs; + long waitMs = minIntervalMs - elapsedMs; + if (waitMs > 0) { + Thread.sleep(waitMs); + } + } + } + + // VisibleForTesting + protected long getMinIntervalMs() { + return TimeUnit.MINUTES.toMillis(1) / maxPerMinute; + } + + // VisibleForTesting + protected Collection getCandidates() { + Set candidates = new HashSet(); + for (String containerPath : zkDb.getDataTree().getContainers()) { + DataNode node = zkDb.getDataTree().getNode(containerPath); + /* + cversion > 0: keep newly created containers from being deleted + before any children have been added. If you were to create the + container just before a container cleaning period the container + would be immediately be deleted. + */ + if ((node != null) && (node.stat.getCversion() > 0) && + (node.getChildren().size() == 0)) { + candidates.add(containerPath); + } + } + return candidates; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/DataNode.java b/src/java/main/org/apache/zookeeper/server/DataNode.java new file mode 100644 index 00000000000..c46e9226a2a --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/DataNode.java @@ -0,0 +1,183 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.data.StatPersisted; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * This class contains the data for a node in the data tree. + *

        + * A data node contains a reference to its parent, a byte array as its data, an + * array of ACLs, a stat object, and a set of its children's paths. + * + */ +public class DataNode implements Record { + private static final Logger LOG = LoggerFactory.getLogger(DataNode.class); + /** + * the stat for this node that is persisted to disk. + */ + public StatPersisted stat; + /** the data for this datanode */ + byte data[]; + /** + * the acl map long for this datanode. the datatree has the map + */ + Long acl; + /** + * the list of children for this node. note that the list of children string + * does not contain the parent path -- just the last part of the path. This + * should be synchronized on except deserializing (for speed up issues). + */ + private Set children = null; + + /** + * default constructor for the datanode + */ + DataNode() { + // default constructor + } + + /** + * create a DataNode with parent, data, acls and stat + * + * @param parent + * the parent of this DataNode + * @param data + * the data to be set + * @param acl + * the acls for this node + * @param stat + * the stat for this node. + */ + public DataNode(byte data[], Long acl, StatPersisted stat) { + this.data = data; + this.acl = acl; + this.stat = stat; + try { + LOG.info("DataNode->data:{}", new String(data, "utf-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + + private static long getClientEphemeralOwner(StatPersisted stat) { + return (stat.getEphemeralOwner() == DataTree.CONTAINER_EPHEMERAL_OWNER) + ? 0 : stat.getEphemeralOwner(); + } + + /** + * Method that inserts a child into the children set + * + * @param child + * to be inserted + * @return true if this set did not already contain the specified element + */ + public synchronized boolean addChild(String child) { + if (children == null) { + // let's be conservative on the typical number of children + children = new HashSet(8); + } + return children.add(child); + } + + /** + * Method that removes a child from the children set + * + * @param child + * @return true if this set contained the specified element + */ + public synchronized boolean removeChild(String child) { + if (children == null) { + return false; + } + return children.remove(child); + } + + /** + * convenience methods to get the children + * + * @return the children of this datanode + */ + public synchronized Set getChildren() { + if (children == null) { + return children; + } + + return Collections.unmodifiableSet(children); + } + + /** + * convenience method for setting the children for this datanode + * + * @param children + */ + public synchronized void setChildren(HashSet children) { + this.children = children; + } + + public synchronized long getApproximateDataSize() { + if (null == data) return 0; + return data.length; + } + + synchronized public void copyStat(Stat to) { + to.setAversion(stat.getAversion()); + to.setCtime(stat.getCtime()); + to.setCzxid(stat.getCzxid()); + to.setMtime(stat.getMtime()); + to.setMzxid(stat.getMzxid()); + to.setPzxid(stat.getPzxid()); + to.setVersion(stat.getVersion()); + to.setEphemeralOwner(getClientEphemeralOwner(stat)); + to.setDataLength(data == null ? 0 : data.length); + int numChildren = 0; + if (this.children != null) { + numChildren = children.size(); + } + // when we do the Cversion we need to translate from the count of the creates + // to the count of the changes (v3 semantics) + // for every create there is a delete except for the children still present + to.setCversion(stat.getCversion() * 2 - numChildren); + to.setNumChildren(numChildren); + } + + synchronized public void deserialize(InputArchive archive, String tag) + throws IOException { + archive.startRecord("node"); + data = archive.readBuffer("data"); + acl = archive.readLong("acl"); + stat = new StatPersisted(); + stat.deserialize(archive, "statpersisted"); + archive.endRecord("node"); + } + + synchronized public void serialize(OutputArchive archive, String tag) + throws IOException { + archive.startRecord(this, "node"); + archive.writeBuffer(data, "data"); + archive.writeLong(acl, "acl"); + stat.serialize(archive, "statpersisted"); + archive.endRecord(this, "node"); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/DataTree.java b/src/java/main/org/apache/zookeeper/server/DataTree.java new file mode 100644 index 00000000000..c43fb515e9f --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/DataTree.java @@ -0,0 +1,1455 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.Index; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.KeeperException.NodeExistsException; +import org.apache.zookeeper.Quotas; +import org.apache.zookeeper.StatsTrack; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.common.PathTrie; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.data.StatPersisted; +import org.apache.zookeeper.txn.CheckVersionTxn; +import org.apache.zookeeper.txn.CreateContainerTxn; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.DeleteTxn; +import org.apache.zookeeper.txn.ErrorTxn; +import org.apache.zookeeper.txn.MultiTxn; +import org.apache.zookeeper.txn.SetACLTxn; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.Txn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * This class maintains the tree data structure. It doesn't have any networking + * or client connection code in it so that it can be tested in a stand alone + * way. + *

        + * The tree maintains two parallel data structures: a hashtable that maps from + * full paths to DataNodes and a tree of DataNodes. All accesses to a path is + * through the hashtable. The tree is traversed only when serializing to disk. + */ +public class DataTree { + public static final long CONTAINER_EPHEMERAL_OWNER = Long.MIN_VALUE; + private static final Logger LOG = LoggerFactory.getLogger(DataTree.class); + /** the root of zookeeper tree */ + private static final String rootZookeeper = "/"; + /** the zookeeper nodes that acts as the management and status node **/ + private static final String procZookeeper = Quotas.procZookeeper; + /** this will be the string thats stored as a child of root */ + private static final String procChildZookeeper = procZookeeper.substring(1); + /** + * the zookeeper quota node that acts as the quota management node for + * zookeeper + */ + private static final String quotaZookeeper = Quotas.quotaZookeeper; + /** this will be the string thats stored as a child of /zookeeper */ + private static final String quotaChildZookeeper = quotaZookeeper + .substring(procZookeeper.length() + 1); + /** + * the zookeeper config node that acts as the config management node for + * zookeeper + */ + private static final String configZookeeper = ZooDefs.CONFIG_NODE; + /** this will be the string thats stored as a child of /zookeeper */ + private static final String configChildZookeeper = configZookeeper + .substring(procZookeeper.length() + 1); + /** + * This hashtable provides a fast lookup to the datanodes. The tree is the + * source of truth and is where all the locking occurs + */ + private final ConcurrentHashMap nodes = + new ConcurrentHashMap(); + private final WatchManager dataWatches = new WatchManager(); + private final WatchManager childWatches = new WatchManager(); + /** + * the path trie that keeps track fo the quota nodes in this datatree + */ + private final PathTrie pTrie = new PathTrie(); + + /** + * This hashtable lists the paths of the ephemeral nodes of a session. + */ + private final Map> ephemerals = + new ConcurrentHashMap>(); + + /** + * This set contains the paths of all container nodes + */ + private final Set containers = + Collections.newSetFromMap(new ConcurrentHashMap()); + + /** + * this is map from longs to acl's. It saves acl's being stored for each + * datanode. + */ + private final Map> longKeyMap = + new HashMap>(); + + /** + * this a map from acls to long. + */ + private final Map, Long> aclKeyMap = + new HashMap, Long>(); + /** + * create a /zookeeper filesystem that is the proc filesystem of zookeeper + */ + private final DataNode procDataNode = new DataNode(new byte[0], -1L, new StatPersisted()); + /** + * create a /zookeeper/quota node for maintaining quota properties for + * zookeeper + */ + private final DataNode quotaDataNode = new DataNode(new byte[0], -1L, new StatPersisted()); + public volatile long lastProcessedZxid = 0; + /** + * these are the number of acls that we have in the datatree + */ + private long aclIndex = 0; + /** + * This is a pointer to the root of the DataTree. It is the source of truth, + * but we usually use the nodes hashmap to find nodes in the tree. + */ + private DataNode root = new DataNode(new byte[0], -1L, new StatPersisted()); + /** + * create a /zookeeper/config node for maintaining the configuration (membership and quorum system) info for + * zookeeper + */ + private DataNode configDataNode = new DataNode(new byte[0], -1L, new StatPersisted()); + + public DataTree() { + /* Rather than fight it, let root have an alias */ + nodes.put("", root); + nodes.put(rootZookeeper, root); + + /** add the proc node and quota node */ + root.addChild(procChildZookeeper); + nodes.put(procZookeeper, procDataNode); + + procDataNode.addChild(quotaChildZookeeper); + nodes.put(quotaZookeeper, quotaDataNode); + + addConfigNode(); + } + + static public void copyStatPersisted(StatPersisted from, StatPersisted to) { + to.setAversion(from.getAversion()); + to.setCtime(from.getCtime()); + to.setCversion(from.getCversion()); + to.setCzxid(from.getCzxid()); + to.setMtime(from.getMtime()); + to.setMzxid(from.getMzxid()); + to.setPzxid(from.getPzxid()); + to.setVersion(from.getVersion()); + to.setEphemeralOwner(from.getEphemeralOwner()); + } + + static public void copyStat(Stat from, Stat to) { + to.setAversion(from.getAversion()); + to.setCtime(from.getCtime()); + to.setCversion(from.getCversion()); + to.setCzxid(from.getCzxid()); + to.setMtime(from.getMtime()); + to.setMzxid(from.getMzxid()); + to.setPzxid(from.getPzxid()); + to.setVersion(from.getVersion()); + to.setEphemeralOwner(from.getEphemeralOwner()); + to.setDataLength(from.getDataLength()); + to.setNumChildren(from.getNumChildren()); + } + + @SuppressWarnings("unchecked") + public Set getEphemerals(long sessionId) { + HashSet retv = ephemerals.get(sessionId); + if (retv == null) { + return new HashSet(); + } + HashSet cloned = null; + synchronized (retv) { + cloned = (HashSet) retv.clone(); + } + return cloned; + } + + public Set getContainers() { + return new HashSet(containers); + } + + int getAclSize() { + return longKeyMap.size(); + } + + private long incrementIndex() { + return ++aclIndex; + } + + /** + * converts the list of acls to a list of longs. + * + * @param acls + * @return a list of longs that map to the acls + */ + public synchronized Long convertAcls(List acls) { + if (acls == null) + return -1L; + // get the value from the map + Long ret = aclKeyMap.get(acls); + // could not find the map + if (ret != null) + return ret; + long val = incrementIndex(); + longKeyMap.put(val, acls); + aclKeyMap.put(acls, val); + return val; + } + + /** + * converts a list of longs to a list of acls. + * + * @param longVal + * the list of longs + * @return a list of ACLs that map to longs + */ + public synchronized List convertLong(Long longVal) { + if (longVal == null) + return null; + if (longVal == -1L) + return Ids.OPEN_ACL_UNSAFE; + List acls = longKeyMap.get(longVal); + if (acls == null) { + LOG.error("ERROR: ACL not available for long " + longVal); + throw new RuntimeException("Failed to fetch acls for " + longVal); + } + return acls; + } + + public Collection getSessions() { + return ephemerals.keySet(); + } + + public DataNode getNode(String path) { + return nodes.get(path); + } + + public int getNodeCount() { + return nodes.size(); + } + + public int getWatchCount() { + return dataWatches.size() + childWatches.size(); + } + + public int getEphemeralsCount() { + int result = 0; + for (HashSet set : ephemerals.values()) { + result += set.size(); + } + return result; + } + + /** + * Get the size of the nodes based on path and data length. + * + * @return size of the data + */ + public long approximateDataSize() { + long result = 0; + for (Map.Entry entry : nodes.entrySet()) { + DataNode value = entry.getValue(); + synchronized (value) { + result += entry.getKey().length(); + result += value.getApproximateDataSize(); + } + } + return result; + } + + public void addConfigNode() { + DataNode zookeeperZnode = nodes.get(procZookeeper); + if (zookeeperZnode != null) { // should always be the case + zookeeperZnode.addChild(configChildZookeeper); + } else { + LOG.error("There's no /zookeeper znode - this should never happen"); + } + nodes.put(configZookeeper, configDataNode); + } + + /** + * is the path one of the special paths owned by zookeeper. + * + * @param path + * the path to be checked + * @return true if a special path. false if not. + */ + boolean isSpecialPath(String path) { + if (rootZookeeper.equals(path) || procZookeeper.equals(path) + || quotaZookeeper.equals(path) || configZookeeper.equals(path)) { + return true; + } + return false; + } + + /** + * update the count of this stat datanode + * + * @param lastPrefix + * the path of the node that is quotaed. + * @param diff + * the diff to be added to the count + */ + public void updateCount(String lastPrefix, int diff) { + String statNode = Quotas.statPath(lastPrefix); + DataNode node = nodes.get(statNode); + StatsTrack updatedStat = null; + if (node == null) { + // should not happen + LOG.error("Missing count node for stat " + statNode); + return; + } + synchronized (node) { + updatedStat = new StatsTrack(new String(node.data)); + updatedStat.setCount(updatedStat.getCount() + diff); + node.data = updatedStat.toString().getBytes(); + } + // now check if the counts match the quota + String quotaNode = Quotas.quotaPath(lastPrefix); + node = nodes.get(quotaNode); + StatsTrack thisStats = null; + if (node == null) { + // should not happen + LOG.error("Missing count node for quota " + quotaNode); + return; + } + synchronized (node) { + thisStats = new StatsTrack(new String(node.data)); + } + if (thisStats.getCount() > -1 && (thisStats.getCount() < updatedStat.getCount())) { + LOG + .warn("Quota exceeded: " + lastPrefix + " count=" + + updatedStat.getCount() + " limit=" + + thisStats.getCount()); + } + } + + /** + * update the count of bytes of this stat datanode + * + * @param lastPrefix + * the path of the node that is quotaed + * @param diff + * the diff to added to number of bytes + * @throws IOException + * if path is not found + */ + public void updateBytes(String lastPrefix, long diff) { + String statNode = Quotas.statPath(lastPrefix); + DataNode node = nodes.get(statNode); + if (node == null) { + // should never be null but just to make + // findbugs happy + LOG.error("Missing stat node for bytes " + statNode); + return; + } + StatsTrack updatedStat = null; + synchronized (node) { + updatedStat = new StatsTrack(new String(node.data)); + updatedStat.setBytes(updatedStat.getBytes() + diff); + node.data = updatedStat.toString().getBytes(); + } + // now check if the bytes match the quota + String quotaNode = Quotas.quotaPath(lastPrefix); + node = nodes.get(quotaNode); + if (node == null) { + // should never be null but just to make + // findbugs happy + LOG.error("Missing quota node for bytes " + quotaNode); + return; + } + StatsTrack thisStats = null; + synchronized (node) { + thisStats = new StatsTrack(new String(node.data)); + } + if (thisStats.getBytes() > -1 && (thisStats.getBytes() < updatedStat.getBytes())) { + LOG + .warn("Quota exceeded: " + lastPrefix + " bytes=" + + updatedStat.getBytes() + " limit=" + + thisStats.getBytes()); + } + } + + /** + * Add a new node to the DataTree. + * @param path + * Path for the new node. + * @param data + * Data to store in the node. + * @param acl + * Node acls + * @param ephemeralOwner + * the session id that owns this node. -1 indicates this is not + * an ephemeral node. + * @param zxid + * Transaction ID + * @param time + * @throws NodeExistsException + * @throws NoNodeException + * @throws KeeperException + */ + public void createNode(final String path, byte data[], List acl, + long ephemeralOwner, int parentCVersion, long zxid, long time) + throws NoNodeException, NodeExistsException { + createNode(path, data, acl, ephemeralOwner, parentCVersion, zxid, time, null); + } + + /** + * Add a new node to the DataTree. + * @param path + * Path for the new node. + * @param data + * Data to store in the node. + * @param acl + * Node acls + * @param ephemeralOwner + * the session id that owns this node. -1 indicates this is not + * an ephemeral node. + * @param zxid + * Transaction ID + * @param time + * @param outputStat + * A Stat object to store Stat output results into. + * @throws NodeExistsException + * @throws NoNodeException + * @throws KeeperException + */ + public void createNode(final String path, byte data[], List acl, + long ephemeralOwner, int parentCVersion, long zxid, long time, Stat outputStat) + throws KeeperException.NoNodeException, + KeeperException.NodeExistsException { + int lastSlash = path.lastIndexOf('/'); + String parentName = path.substring(0, lastSlash); + String childName = path.substring(lastSlash + 1); + StatPersisted stat = new StatPersisted(); + stat.setCtime(time); + stat.setMtime(time); + stat.setCzxid(zxid); + stat.setMzxid(zxid); + stat.setPzxid(zxid); + stat.setVersion(0); + stat.setAversion(0); + stat.setEphemeralOwner(ephemeralOwner); + DataNode parent = nodes.get(parentName); + if (parent == null) { + throw new KeeperException.NoNodeException(); + } + synchronized (parent) { + Set children = parent.getChildren(); + if (children != null && children.contains(childName)) { + throw new KeeperException.NodeExistsException(); + } + + if (parentCVersion == -1) { + parentCVersion = parent.stat.getCversion(); + parentCVersion++; + } + parent.stat.setCversion(parentCVersion); + parent.stat.setPzxid(zxid); + Long longval = convertAcls(acl); + DataNode child = new DataNode(data, longval, stat); + parent.addChild(childName); + nodes.put(path, child); + if (ephemeralOwner == CONTAINER_EPHEMERAL_OWNER) { + containers.add(path); + } else if (ephemeralOwner != 0) { + HashSet list = ephemerals.get(ephemeralOwner); + if (list == null) { + list = new HashSet(); + ephemerals.put(ephemeralOwner, list); + } + synchronized (list) { + list.add(path); + } + } + if (outputStat != null) { + child.copyStat(outputStat); + } + } + // now check if its one of the zookeeper node child + if (parentName.startsWith(quotaZookeeper)) { + // now check if its the limit node + if (Quotas.limitNode.equals(childName)) { + // this is the limit node + // get the parent and add it to the trie + pTrie.addPath(parentName.substring(quotaZookeeper.length())); + } + if (Quotas.statNode.equals(childName)) { + updateQuotaForPath(parentName + .substring(quotaZookeeper.length())); + } + } + // also check to update the quotas for this node + String lastPrefix = getMaxPrefixWithQuota(path); + if (lastPrefix != null) { + // ok we have some match and need to update + updateCount(lastPrefix, 1); + updateBytes(lastPrefix, data == null ? 0 : data.length); + } + dataWatches.triggerWatch(path, Event.EventType.NodeCreated); + childWatches.triggerWatch(parentName.equals("") ? "/" : parentName, + Event.EventType.NodeChildrenChanged); + } + + /** + * remove the path from the datatree + * + * @param path + * the path to of the node to be deleted + * @param zxid + * the current zxid + * @throws KeeperException.NoNodeException + */ + public void deleteNode(String path, long zxid) throws KeeperException.NoNodeException { + int lastSlash = path.lastIndexOf('/'); + String parentName = path.substring(0, lastSlash); + String childName = path.substring(lastSlash + 1); + DataNode node = nodes.get(path); + if (node == null) { + throw new KeeperException.NoNodeException(); + } + nodes.remove(path); + DataNode parent = nodes.get(parentName); + if (parent == null) { + throw new KeeperException.NoNodeException(); + } + synchronized (parent) { + parent.removeChild(childName); + parent.stat.setPzxid(zxid); + long eowner = node.stat.getEphemeralOwner(); + if (eowner == CONTAINER_EPHEMERAL_OWNER) { + containers.remove(path); + } else if (eowner != 0) { + HashSet nodes = ephemerals.get(eowner); + if (nodes != null) { + synchronized (nodes) { + nodes.remove(path); + } + } + } + } + if (parentName.startsWith(procZookeeper) && Quotas.limitNode.equals(childName)) { + // delete the node in the trie. + // we need to update the trie as well + pTrie.deletePath(parentName.substring(quotaZookeeper.length())); + } + + // also check to update the quotas for this node + String lastPrefix = getMaxPrefixWithQuota(path); + if (lastPrefix != null) { + // ok we have some match and need to update + updateCount(lastPrefix, -1); + int bytes = 0; + synchronized (node) { + bytes = (node.data == null ? 0 : -(node.data.length)); + } + updateBytes(lastPrefix, bytes); + } + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, + "dataWatches.triggerWatch " + path); + ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, + "childWatches.triggerWatch " + parentName); + } + Set processed = dataWatches.triggerWatch(path, EventType.NodeDeleted); + childWatches.triggerWatch(path, EventType.NodeDeleted, processed); + childWatches.triggerWatch("".equals(parentName) ? "/" : parentName, EventType.NodeChildrenChanged); + } + + public Stat setData(String path, byte data[], int version, long zxid, + long time) throws KeeperException.NoNodeException { + Stat s = new Stat(); + DataNode n = nodes.get(path); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + byte lastdata[] = null; + synchronized (n) { + lastdata = n.data; + n.data = data; + n.stat.setMtime(time); + n.stat.setMzxid(zxid); + n.stat.setVersion(version); + n.copyStat(s); + } + // now update if the path is in a quota subtree. + String lastPrefix = getMaxPrefixWithQuota(path); + if (lastPrefix != null) { + this.updateBytes(lastPrefix, (data == null ? 0 : data.length) + - (lastdata == null ? 0 : lastdata.length)); + } + dataWatches.triggerWatch(path, EventType.NodeDataChanged); + return s; + } + + /** + * If there is a quota set, return the appropriate prefix for that quota + * Else return null + * @param path The ZK path to check for quota + * @return Max quota prefix, or null if none + */ + public String getMaxPrefixWithQuota(String path) { + // do nothing for the root. + // we are not keeping a quota on the zookeeper + // root node for now. + String lastPrefix = pTrie.findMaxPrefix(path); + + if (rootZookeeper.equals(lastPrefix) || "".equals(lastPrefix)) { + return null; + } else { + return lastPrefix; + } + } + + public byte[] getData(String path, Stat stat, Watcher watcher) + throws KeeperException.NoNodeException { + DataNode n = nodes.get(path); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + synchronized (n) { + n.copyStat(stat); + if (watcher != null) { + dataWatches.addWatch(path, watcher); + } + return n.data; + } + } + + public Stat statNode(String path, Watcher watcher) + throws KeeperException.NoNodeException { + Stat stat = new Stat(); + DataNode n = nodes.get(path); + if (watcher != null) { + dataWatches.addWatch(path, watcher); + } + if (n == null) { + throw new KeeperException.NoNodeException(); + } + synchronized (n) { + n.copyStat(stat); + return stat; + } + } + + public List getChildren(String path, Stat stat, Watcher watcher) + throws KeeperException.NoNodeException { + DataNode n = nodes.get(path); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + synchronized (n) { + if (stat != null) { + n.copyStat(stat); + } + ArrayList children; + Set childs = n.getChildren(); + if (childs == null) { + children = new ArrayList(0); + } else { + children = new ArrayList(childs); + } + + if (watcher != null) { + childWatches.addWatch(path, watcher); + } + return children; + } + } + + public Stat setACL(String path, List acl, int version) + throws KeeperException.NoNodeException { + Stat stat = new Stat(); + DataNode n = nodes.get(path); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + synchronized (n) { + n.stat.setAversion(version); + n.acl = convertAcls(acl); + n.copyStat(stat); + return stat; + } + } + + public List getACL(String path, Stat stat) + throws KeeperException.NoNodeException { + DataNode n = nodes.get(path); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + synchronized (n) { + n.copyStat(stat); + return new ArrayList(convertLong(n.acl)); + } + } + + public ProcessTxnResult processTxn(TxnHeader header, Record txn) { + ProcessTxnResult rc = new ProcessTxnResult(); + + try { + rc.clientId = header.getClientId(); + rc.cxid = header.getCxid(); + rc.zxid = header.getZxid(); + rc.type = header.getType(); + rc.err = 0; + rc.multiResult = null; + switch (header.getType()) { + case OpCode.create: + CreateTxn createTxn = (CreateTxn) txn; + rc.path = createTxn.getPath(); + createNode( + createTxn.getPath(), + createTxn.getData(), + createTxn.getAcl(), + createTxn.getEphemeral() ? header.getClientId() : 0, + createTxn.getParentCVersion(), + header.getZxid(), header.getTime(), null); + break; + case OpCode.create2: + CreateTxn create2Txn = (CreateTxn) txn; + rc.path = create2Txn.getPath(); + Stat stat = new Stat(); + createNode( + create2Txn.getPath(), + create2Txn.getData(), + create2Txn.getAcl(), + create2Txn.getEphemeral() ? header.getClientId() : 0, + create2Txn.getParentCVersion(), + header.getZxid(), header.getTime(), stat); + rc.stat = stat; + break; + case OpCode.createContainer: + CreateContainerTxn createContainerTxn = (CreateContainerTxn) txn; + rc.path = createContainerTxn.getPath(); + stat = new Stat(); + createNode( + createContainerTxn.getPath(), + createContainerTxn.getData(), + createContainerTxn.getAcl(), + CONTAINER_EPHEMERAL_OWNER, + createContainerTxn.getParentCVersion(), + header.getZxid(), header.getTime(), stat); + rc.stat = stat; + break; + case OpCode.delete: + case OpCode.deleteContainer: + DeleteTxn deleteTxn = (DeleteTxn) txn; + rc.path = deleteTxn.getPath(); + deleteNode(deleteTxn.getPath(), header.getZxid()); + break; + case OpCode.reconfig: + case OpCode.setData: + SetDataTxn setDataTxn = (SetDataTxn) txn; + rc.path = setDataTxn.getPath(); + rc.stat = setData(setDataTxn.getPath(), setDataTxn + .getData(), setDataTxn.getVersion(), header + .getZxid(), header.getTime()); + break; + case OpCode.setACL: + SetACLTxn setACLTxn = (SetACLTxn) txn; + rc.path = setACLTxn.getPath(); + rc.stat = setACL(setACLTxn.getPath(), setACLTxn.getAcl(), + setACLTxn.getVersion()); + break; + case OpCode.closeSession: + killSession(header.getClientId(), header.getZxid()); + break; + case OpCode.error: + ErrorTxn errTxn = (ErrorTxn) txn; + rc.err = errTxn.getErr(); + break; + case OpCode.check: + CheckVersionTxn checkTxn = (CheckVersionTxn) txn; + rc.path = checkTxn.getPath(); + break; + case OpCode.multi: + MultiTxn multiTxn = (MultiTxn) txn; + List txns = multiTxn.getTxns(); + rc.multiResult = new ArrayList(); + boolean failed = false; + for (Txn subtxn : txns) { + if (subtxn.getType() == OpCode.error) { + failed = true; + break; + } + } + + boolean post_failed = false; + for (Txn subtxn : txns) { + ByteBuffer bb = ByteBuffer.wrap(subtxn.getData()); + Record record = null; + switch (subtxn.getType()) { + case OpCode.create: + record = new CreateTxn(); + break; + case OpCode.createContainer: + record = new CreateContainerTxn(); + break; + case OpCode.delete: + case OpCode.deleteContainer: + record = new DeleteTxn(); + break; + case OpCode.setData: + record = new SetDataTxn(); + break; + case OpCode.error: + record = new ErrorTxn(); + post_failed = true; + break; + case OpCode.check: + record = new CheckVersionTxn(); + break; + default: + throw new IOException("Invalid type of op: " + subtxn.getType()); + } + assert (record != null); + + ByteBufferInputStream.byteBuffer2Record(bb, record); + + if (failed && subtxn.getType() != OpCode.error) { + int ec = post_failed ? Code.RUNTIMEINCONSISTENCY.intValue() + : Code.OK.intValue(); + + subtxn.setType(OpCode.error); + record = new ErrorTxn(ec); + } + + if (failed) { + assert (subtxn.getType() == OpCode.error); + } + TxnHeader subHdr = new TxnHeader(header.getClientId(), header.getCxid(), header.getZxid(), header.getTime(), subtxn.getType()); + ProcessTxnResult subRc = processTxn(subHdr, record); + rc.multiResult.add(subRc); + if (subRc.err != 0 && rc.err == 0) { + rc.err = subRc.err; + } + } + break; + } + } catch (KeeperException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Failed: " + header + ":" + txn, e); + } + rc.err = e.code().intValue(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Failed: " + header + ":" + txn, e); + } + } + /* + * A snapshot might be in progress while we are modifying the data + * tree. If we set lastProcessedZxid prior to making corresponding + * change to the tree, then the zxid associated with the snapshot + * file will be ahead of its contents. Thus, while restoring from + * the snapshot, the restore method will not apply the transaction + * for zxid associated with the snapshot file, since the restore + * method assumes that transaction to be present in the snapshot. + * + * To avoid this, we first apply the transaction and then modify + * lastProcessedZxid. During restore, we correctly handle the + * case where the snapshot contains data ahead of the zxid associated + * with the file. + */ + if (rc.zxid > lastProcessedZxid) { + lastProcessedZxid = rc.zxid; + } + + /* + * Snapshots are taken lazily. It can happen that the child + * znodes of a parent are created after the parent + * is serialized. Therefore, while replaying logs during restore, a + * create might fail because the node was already + * created. + * + * After seeing this failure, we should increment + * the cversion of the parent znode since the parent was serialized + * before its children. + * + * Note, such failures on DT should be seen only during + * restore. + */ + if (header.getType() == OpCode.create && rc.err == Code.NODEEXISTS.intValue()) { + LOG.debug("Adjusting parent cversion for Txn: " + header.getType() + " path:" + rc.path + " err: " + rc.err); + int lastSlash = rc.path.lastIndexOf('/'); + String parentName = rc.path.substring(0, lastSlash); + CreateTxn cTxn = (CreateTxn) txn; + try { + setCversionPzxid(parentName, cTxn.getParentCVersion(), header.getZxid()); + } catch (KeeperException.NoNodeException e) { + LOG.error("Failed to set parent cversion for: " + parentName, e); + rc.err = e.code().intValue(); + } + } else if (rc.err != Code.OK.intValue()) { + LOG.debug("Ignoring processTxn failure hdr: " + header.getType() + " : error: " + rc.err); + } + return rc; + } + + void killSession(long session, long zxid) { + // the list is already removed from the ephemerals + // so we do not have to worry about synchronizing on + // the list. This is only called from FinalRequestProcessor + // so there is no need for synchronization. The list is not + // changed here. Only create and delete change the list which + // are again called from FinalRequestProcessor in sequence. + HashSet list = ephemerals.remove(session); + if (list != null) { + for (String path : list) { + try { + deleteNode(path, zxid); + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting ephemeral node " + path + " for session 0x" + Long.toHexString(session)); + } + } catch (NoNodeException e) { + LOG.warn("Ignoring NoNodeException for path " + path + " while removing ephemeral for dead session 0x" + Long.toHexString(session)); + } + } + } + } + + /** + * this method gets the count of nodes and the bytes under a subtree + * + * @param path + * the path to be used + * @param counts + * the int count + */ + private void getCounts(String path, Counts counts) { + DataNode node = getNode(path); + if (node == null) { + return; + } + String[] children = null; + int len = 0; + synchronized (node) { + Set childs = node.getChildren(); + if (childs != null) { + children = childs.toArray(new String[childs.size()]); + } + len = (node.data == null ? 0 : node.data.length); + } + // add itself + counts.count += 1; + counts.bytes += len; + if (children == null || children.length == 0) { + return; + } + for (String child : children) { + getCounts(path + "/" + child, counts); + } + } + + /** + * update the quota for the given path + * + * @param path + * the path to be used + */ + private void updateQuotaForPath(String path) { + Counts c = new Counts(); + getCounts(path, c); + StatsTrack strack = new StatsTrack(); + strack.setBytes(c.bytes); + strack.setCount(c.count); + String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode; + DataNode node = getNode(statPath); + // it should exist + if (node == null) { + LOG.warn("Missing quota stat node " + statPath); + return; + } + synchronized (node) { + node.data = strack.toString().getBytes(); + } + } + + /** + * this method traverses the quota path and update the path trie and sets + * + * @param path + */ + private void traverseNode(String path) { + DataNode node = getNode(path); + String children[] = null; + synchronized (node) { + Set childs = node.getChildren(); + if (childs != null) { + children = childs.toArray(new String[childs.size()]); + } + } + if (children == null || children.length == 0) { + // this node does not have a child + // is the leaf node + // check if its the leaf node + String endString = "/" + Quotas.limitNode; + if (path.endsWith(endString)) { + // ok this is the limit node + // get the real node and update + // the count and the bytes + String realPath = path.substring(Quotas.quotaZookeeper + .length(), path.indexOf(endString)); + updateQuotaForPath(realPath); + this.pTrie.addPath(realPath); + } + return; + } + for (String child : children) { + traverseNode(path + "/" + child); + } + } + + /** + * this method sets up the path trie and sets up stats for quota nodes + */ + private void setupQuota() { + String quotaPath = Quotas.quotaZookeeper; + DataNode node = getNode(quotaPath); + if (node == null) { + return; + } + traverseNode(quotaPath); + } + + /** + * this method uses a stringbuilder to create a new path for children. This + * is faster than string appends ( str1 + str2). + * + * @param oa + * OutputArchive to write to. + * @param path + * a string builder. + * @throws IOException + * @throws InterruptedException + */ + void serializeNode(OutputArchive oa, StringBuilder path) throws IOException { + String pathString = path.toString(); + DataNode node = getNode(pathString); + if (node == null) { + return; + } + String children[] = null; + DataNode nodeCopy; + synchronized (node) { + StatPersisted statCopy = new StatPersisted(); + copyStatPersisted(node.stat, statCopy); + //we do not need to make a copy of node.data because the contents + //are never changed + nodeCopy = new DataNode(node.data, node.acl, statCopy); + Set childs = node.getChildren(); + if (childs != null) { + children = childs.toArray(new String[childs.size()]); + } + } + oa.writeString(pathString, "path"); + oa.writeRecord(nodeCopy, "node"); + path.append('/'); + int off = path.length(); + if (children != null) { + for (String child : children) { + // since this is single buffer being resused + // we need + // to truncate the previous bytes of string. + path.delete(off, Integer.MAX_VALUE); + path.append(child); + serializeNode(oa, path); + } + } + } + + private void deserializeList(Map> longKeyMap, + InputArchive ia) throws IOException { + int i = ia.readInt("map"); + while (i > 0) { + Long val = ia.readLong("long"); + if (aclIndex < val) { + aclIndex = val; + } + List aclList = new ArrayList(); + Index j = ia.startVector("acls"); + while (!j.done()) { + ACL acl = new ACL(); + acl.deserialize(ia, "acl"); + aclList.add(acl); + j.incr(); + } + longKeyMap.put(val, aclList); + aclKeyMap.put(aclList, val); + i--; + } + } + + private synchronized void serializeList(Map> longKeyMap, + OutputArchive oa) throws IOException { + oa.writeInt(longKeyMap.size(), "map"); + Set>> set = longKeyMap.entrySet(); + for (Map.Entry> val : set) { + oa.writeLong(val.getKey(), "long"); + List aclList = val.getValue(); + oa.startVector(aclList, "acls"); + for (ACL acl : aclList) { + acl.serialize(oa, "acl"); + } + oa.endVector(aclList, "acls"); + } + } + + public void serialize(OutputArchive oa, String tag) throws IOException { + serializeList(longKeyMap, oa); + serializeNode(oa, new StringBuilder("")); + // / marks end of stream + // we need to check if clear had been called in between the snapshot. + if (root != null) { + oa.writeString("/", "path"); + } + } + + public void deserialize(InputArchive ia, String tag) throws IOException { + deserializeList(longKeyMap, ia); + nodes.clear(); + pTrie.clear(); + String path = ia.readString("path"); + while (!"/".equals(path)) { + DataNode node = new DataNode(); + ia.readRecord(node, "node"); + nodes.put(path, node); + int lastSlash = path.lastIndexOf('/'); + if (lastSlash == -1) { + root = node; + } else { + String parentPath = path.substring(0, lastSlash); + DataNode parent = nodes.get(parentPath); + if (parent == null) { + throw new IOException("Invalid Datatree, unable to find " + + "parent " + parentPath + " of path " + path); + } + parent.addChild(path.substring(lastSlash + 1)); + long eowner = node.stat.getEphemeralOwner(); + if (eowner == CONTAINER_EPHEMERAL_OWNER) { + containers.add(path); + } else if (eowner != 0) { + HashSet list = ephemerals.get(eowner); + if (list == null) { + list = new HashSet(); + ephemerals.put(eowner, list); + } + list.add(path); + } + } + path = ia.readString("path"); + } + nodes.put("/", root); + // we are done with deserializing the + // the datatree + // update the quotas - create path trie + // and also update the stat nodes + setupQuota(); + } + + /** + * Summary of the watches on the datatree. + * @param pwriter the output to write to + */ + public synchronized void dumpWatchesSummary(PrintWriter pwriter) { + pwriter.print(dataWatches.toString()); + } + + /** + * Write a text dump of all the watches on the datatree. + * Warning, this is expensive, use sparingly! + * @param pwriter the output to write to + */ + public synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) { + dataWatches.dumpWatches(pwriter, byPath); + } + + /** + * Returns a watch report. + * + * @return watch report + * @see WatchesReport + */ + public synchronized WatchesReport getWatches() { + return dataWatches.getWatches(); + } + + /** + * Returns a watch report by path. + * + * @return watch report + * @see WatchesPathReport + */ + public synchronized WatchesPathReport getWatchesByPath() { + return dataWatches.getWatchesByPath(); + } + + /** + * Returns a watch summary. + * + * @return watch summary + * @see WatchesSummary + */ + public synchronized WatchesSummary getWatchesSummary() { + return dataWatches.getWatchesSummary(); + } + + /** + * Write a text dump of all the ephemerals in the datatree. + * @param pwriter the output to write to + */ + public void dumpEphemerals(PrintWriter pwriter) { + Set keys = ephemerals.keySet(); + pwriter.println("Sessions with Ephemerals (" + + keys.size() + "):"); + for (long k : keys) { + pwriter.print("0x" + Long.toHexString(k)); + pwriter.println(":"); + HashSet tmp = ephemerals.get(k); + if (tmp != null) { + synchronized (tmp) { + for (String path : tmp) { + pwriter.println("\t" + path); + } + } + } + } + } + + /** + * Returns a mapping of session ID to ephemeral znodes. + * + * @return map of session ID to sets of ephemeral znodes + */ + public Map> getEphemerals() { + HashMap> ephemeralsCopy = new HashMap>(); + for (Entry> e : ephemerals.entrySet()) { + synchronized (e.getValue()) { + ephemeralsCopy.put(e.getKey(), new HashSet(e.getValue())); + } + } + return ephemeralsCopy; + } + + public void removeCnxn(Watcher watcher) { + dataWatches.removeWatcher(watcher); + childWatches.removeWatcher(watcher); + } + + public void setWatches(long relativeZxid, List dataWatches, + List existWatches, List childWatches, + Watcher watcher) { + for (String path : dataWatches) { + DataNode node = getNode(path); + WatchedEvent e = null; + if (node == null) { + watcher.process(new WatchedEvent(EventType.NodeDeleted, + KeeperState.SyncConnected, path)); + } else if (node.stat.getMzxid() > relativeZxid) { + watcher.process(new WatchedEvent(EventType.NodeDataChanged, + KeeperState.SyncConnected, path)); + } else { + this.dataWatches.addWatch(path, watcher); + } + } + for (String path : existWatches) { + DataNode node = getNode(path); + if (node != null) { + watcher.process(new WatchedEvent(EventType.NodeCreated, + KeeperState.SyncConnected, path)); + } else { + this.dataWatches.addWatch(path, watcher); + } + } + for (String path : childWatches) { + DataNode node = getNode(path); + if (node == null) { + watcher.process(new WatchedEvent(EventType.NodeDeleted, + KeeperState.SyncConnected, path)); + } else if (node.stat.getPzxid() > relativeZxid) { + watcher.process(new WatchedEvent(EventType.NodeChildrenChanged, + KeeperState.SyncConnected, path)); + } else { + this.childWatches.addWatch(path, watcher); + } + } + } + + /** + * This method sets the Cversion and Pzxid for the specified node to the + * values passed as arguments. The values are modified only if newCversion + * is greater than the current Cversion. A NoNodeException is thrown if + * a znode for the specified path is not found. + * + * @param path + * Full path to the znode whose Cversion needs to be modified. + * A "/" at the end of the path is ignored. + * @param newCversion + * Value to be assigned to Cversion + * @param zxid + * Value to be assigned to Pzxid + * @throws KeeperException.NoNodeException + * If znode not found. + **/ + public void setCversionPzxid(String path, int newCversion, long zxid) + throws KeeperException.NoNodeException { + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + DataNode node = nodes.get(path); + if (node == null) { + throw new KeeperException.NoNodeException(path); + } + synchronized (node) { + if (newCversion == -1) { + newCversion = node.stat.getCversion() + 1; + } + if (newCversion > node.stat.getCversion()) { + node.stat.setCversion(newCversion); + node.stat.setPzxid(zxid); + } + } + } + + public boolean containsWatcher(String path, WatcherType type, Watcher watcher) { + boolean containsWatcher = false; + switch (type) { + case Children: + containsWatcher = this.childWatches.containsWatcher(path, watcher); + break; + case Data: + containsWatcher = this.dataWatches.containsWatcher(path, watcher); + break; + case Any: + if (this.childWatches.containsWatcher(path, watcher)) { + containsWatcher = true; + } + if (this.dataWatches.containsWatcher(path, watcher)) { + containsWatcher = true; + } + break; + } + return containsWatcher; + } + + public boolean removeWatch(String path, WatcherType type, Watcher watcher) { + boolean removed = false; + switch (type) { + case Children: + removed = this.childWatches.removeWatcher(path, watcher); + break; + case Data: + removed = this.dataWatches.removeWatcher(path, watcher); + break; + case Any: + if (this.childWatches.removeWatcher(path, watcher)) { + removed = true; + } + if (this.dataWatches.removeWatcher(path, watcher)) { + removed = true; + } + break; + } + return removed; + } + + static public class ProcessTxnResult { + public long clientId; + + public int cxid; + + public long zxid; + + public int err; + + public int type; + + public String path; + + public Stat stat; + + public List multiResult; + + /** + * Equality is defined as the clientId and the cxid being the same. This + * allows us to use hash tables to track completion of transactions. + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object o) { + if (o instanceof ProcessTxnResult) { + ProcessTxnResult other = (ProcessTxnResult) o; + return other.clientId == clientId && other.cxid == cxid; + } + return false; + } + + /** + * See equals() to find the rational for how this hashcode is generated. + * + * @see ProcessTxnResult#equals(Object) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return (int) ((clientId ^ cxid) % Integer.MAX_VALUE); + } + + } + + /** + * a encapsultaing class for return value + */ + private static class Counts { + long bytes; + int count; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/DataTreeBean.java b/src/java/main/org/apache/zookeeper/server/DataTreeBean.java new file mode 100644 index 00000000000..c153e31d454 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/DataTreeBean.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.jmx.ZKMBeanInfo; + +/** + * This class implements the data tree MBean. + */ +public class DataTreeBean implements DataTreeMXBean, ZKMBeanInfo { + DataTree dataTree; + + public DataTreeBean(org.apache.zookeeper.server.DataTree dataTree) { + this.dataTree = dataTree; + } + + public int getNodeCount() { + return dataTree.getNodeCount(); + } + + public long approximateDataSize() { + return dataTree.approximateDataSize(); + } + + public int countEphemerals() { + return dataTree.getEphemeralsCount(); + } + + public int getWatchCount() { + return dataTree.getWatchCount(); + } + + public String getName() { + return "InMemoryDataTree"; + } + + public boolean isHidden() { + return false; + } + + public String getLastZxid() { + return "0x" + Long.toHexString(dataTree.lastProcessedZxid); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java b/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java new file mode 100644 index 00000000000..14d0dea93f9 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +/** + * Zookeeper data tree MBean. + */ +public interface DataTreeMXBean { + /** + * @return number of znodes in the data tree. + */ + public int getNodeCount(); + + /** + * @return the most recent zxid processed by the data tree. + */ + public String getLastZxid(); + + /** + * @return number of watches set. + */ + public int getWatchCount(); + + /** + * @return data tree size in bytes. The size includes the znode path and + * its value. + */ + public long approximateDataSize(); + + /** + * @return number of ephemeral nodes in the data tree + */ + public int countEphemerals(); +} diff --git a/src/java/main/org/apache/zookeeper/server/DatadirCleanupManager.java b/src/java/main/org/apache/zookeeper/server/DatadirCleanupManager.java new file mode 100644 index 00000000000..603889b5bd3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/DatadirCleanupManager.java @@ -0,0 +1,179 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.TimeUnit; + +/** + * This class manages the cleanup of snapshots and corresponding transaction + * logs by scheduling the auto purge task with the specified + * 'autopurge.purgeInterval'. It keeps the most recent + * 'autopurge.snapRetainCount' number of snapshots and corresponding transaction + * logs. + */ +public class DatadirCleanupManager { + + private static final Logger LOG = LoggerFactory.getLogger(DatadirCleanupManager.class); + private final File snapDir; + private final File dataLogDir; + private final int snapRetainCount; + private final int purgeInterval; + private PurgeTaskStatus purgeTaskStatus = PurgeTaskStatus.NOT_STARTED; + private Timer timer; + + /** + * Constructor of DatadirCleanupManager. It takes the parameters to schedule + * the purge task. + * + * @param snapDir + * snapshot directory + * @param dataLogDir + * transaction log directory + * @param snapRetainCount + * number of snapshots to be retained after purge + * @param purgeInterval + * purge interval in hours + */ + public DatadirCleanupManager(File snapDir, File dataLogDir, int snapRetainCount, + int purgeInterval) { + this.snapDir = snapDir; + this.dataLogDir = dataLogDir; + this.snapRetainCount = snapRetainCount; + this.purgeInterval = purgeInterval; + LOG.info("autopurge.snapRetainCount set to " + snapRetainCount); + LOG.info("autopurge.purgeInterval set to " + purgeInterval); + } + + /** + * Validates the purge configuration and schedules the purge task. Purge + * task keeps the most recent snapRetainCount number of + * snapshots and deletes the remaining for every purgeInterval + * hour(s). + *

        + * purgeInterval of 0 or + * negative integer will not schedule the purge task. + *

        + * + * @see PurgeTxnLog#purge(File, File, int) + */ + public void start() { + if (PurgeTaskStatus.STARTED == purgeTaskStatus) { + LOG.warn("Purge task is already running."); + return; + } + // Don't schedule the purge task with zero or negative purge interval. + if (purgeInterval <= 0) { + LOG.info("Purge task is not scheduled."); + return; + } + + timer = new Timer("PurgeTask", true); + TimerTask task = new PurgeTask(dataLogDir, snapDir, snapRetainCount); + timer.scheduleAtFixedRate(task, 0, TimeUnit.HOURS.toMillis(purgeInterval)); + + purgeTaskStatus = PurgeTaskStatus.STARTED; + } + + /** + * Shutdown the purge task. + */ + public void shutdown() { + if (PurgeTaskStatus.STARTED == purgeTaskStatus) { + LOG.info("Shutting down purge task."); + timer.cancel(); + purgeTaskStatus = PurgeTaskStatus.COMPLETED; + } else { + LOG.warn("Purge task not started. Ignoring shutdown!"); + } + } + + /** + * Returns the status of the purge task. + * + * @return the status of the purge task + */ + public PurgeTaskStatus getPurgeTaskStatus() { + return purgeTaskStatus; + } + + /** + * Returns the snapshot directory. + * + * @return the snapshot directory. + */ + public File getSnapDir() { + return snapDir; + } + + /** + * Returns transaction log directory. + * + * @return the transaction log directory. + */ + public File getDataLogDir() { + return dataLogDir; + } + + /** + * Returns purge interval in hours. + * + * @return the purge interval in hours. + */ + public int getPurgeInterval() { + return purgeInterval; + } + + /** + * Returns the number of snapshots to be retained after purge. + * + * @return the number of snapshots to be retained after purge. + */ + public int getSnapRetainCount() { + return snapRetainCount; + } + + /** + * Status of the dataDir purge task + */ + public enum PurgeTaskStatus { + NOT_STARTED, STARTED, COMPLETED; + } + + static class PurgeTask extends TimerTask { + private File logsDir; + private File snapsDir; + private int snapRetainCount; + + public PurgeTask(File dataDir, File snapDir, int count) { + logsDir = dataDir; + snapsDir = snapDir; + snapRetainCount = count; + } + + @Override + public void run() { + LOG.info("Purge task started."); + try { + PurgeTxnLog.purge(logsDir, snapsDir, snapRetainCount); + } catch (Exception e) { + LOG.error("Error occured while purging.", e); + } + LOG.info("Purge task completed."); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ExitCode.java b/src/java/main/org/apache/zookeeper/server/ExitCode.java new file mode 100644 index 00000000000..50230bdca7a --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ExitCode.java @@ -0,0 +1,20 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +/** + * Exit code used to exit server + */ +public class ExitCode { + + /* Represents unexpected error */ + public final static int UNEXPECTED_ERROR = 1; +} diff --git a/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java b/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java new file mode 100644 index 00000000000..1522dac06fb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ExpiryQueue.java @@ -0,0 +1,182 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.common.Time; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; + +/** + * ExpiryQueue tracks elements in time sorted fixed duration buckets. + * It's used by SessionTrackerImpl to expire sessions and NIOServerCnxnFactory + * to expire connections. + */ +public class ExpiryQueue { + private final ConcurrentHashMap elemMap = + new ConcurrentHashMap(); + /** + * The maximum number of buckets is equal to max timeout/expirationInterval, + * so the expirationInterval should not be too small compared to the + * max timeout that this expiry queue needs to maintain. + */ + private final ConcurrentHashMap> expiryMap = + new ConcurrentHashMap>(); + + private final AtomicLong nextExpirationTime = new AtomicLong(); + private final int expirationInterval; + + public ExpiryQueue(int expirationInterval) { + this.expirationInterval = expirationInterval; + nextExpirationTime.set(roundToNextInterval(Time.currentElapsedTime())); + } + + private long roundToNextInterval(long time) { + return (time / expirationInterval + 1) * expirationInterval; + } + + /** + * Removes element from the queue. + * @param elem element to remove + * @return time at which the element was set to expire, or null if + * it wasn't present + */ + public Long remove(E elem) { + Long expiryTime = elemMap.remove(elem); + if (expiryTime != null) { + Set set = expiryMap.get(expiryTime); + if (set != null) { + set.remove(elem); + // We don't need to worry about removing empty sets, + // they'll eventually be removed when they expire. + } + } + return expiryTime; + } + + /** + * Adds or updates expiration time for element in queue, rounding the + * timeout to the expiry interval bucketed used by this queue. + * @param elem element to add/update + * @param timeout timout in milliseconds + * @return time at which the element is now set to expire if + * changed, or null if unchanged + */ + public Long update(E elem, int timeout) { + Long prevExpiryTime = elemMap.get(elem); + long now = Time.currentElapsedTime(); + Long newExpiryTime = roundToNextInterval(now + timeout); + + if (newExpiryTime.equals(prevExpiryTime)) { + // No change, so nothing to update + return null; + } + + // First add the elem to the new expiry time bucket in expiryMap. + Set set = expiryMap.get(newExpiryTime); + if (set == null) { + // Construct a ConcurrentHashSet using a ConcurrentHashMap + set = Collections.newSetFromMap( + new ConcurrentHashMap()); + // Put the new set in the map, but only if another thread + // hasn't beaten us to it + Set existingSet = expiryMap.putIfAbsent(newExpiryTime, set); + if (existingSet != null) { + set = existingSet; + } + } + set.add(elem); + + // Map the elem to the new expiry time. If a different previous + // mapping was present, clean up the previous expiry bucket. + prevExpiryTime = elemMap.put(elem, newExpiryTime); + if (prevExpiryTime != null && !newExpiryTime.equals(prevExpiryTime)) { + Set prevSet = expiryMap.get(prevExpiryTime); + if (prevSet != null) { + prevSet.remove(elem); + } + } + return newExpiryTime; + } + + /** + * @return milliseconds until next expiration time, or 0 if has already past + */ + public long getWaitTime() { + long now = Time.currentElapsedTime(); + long expirationTime = nextExpirationTime.get(); + return now < expirationTime ? (expirationTime - now) : 0L; + } + + /** + * Remove the next expired set of elements from expireMap. This method needs + * to be called frequently enough by checking getWaitTime(), otherwise there + * will be a backlog of empty sets queued up in expiryMap. + * + * @return next set of expired elements, or an empty set if none are + * ready + */ + public Set poll() { + long now = Time.currentElapsedTime(); + long expirationTime = nextExpirationTime.get(); + if (now < expirationTime) { + return Collections.emptySet(); + } + + Set set = null; + long newExpirationTime = expirationTime + expirationInterval; + if (nextExpirationTime.compareAndSet( + expirationTime, newExpirationTime)) { + set = expiryMap.remove(expirationTime); + } + if (set == null) { + return Collections.emptySet(); + } + return set; + } + + public void dump(PrintWriter pwriter) { + pwriter.print("Sets ("); + pwriter.print(expiryMap.size()); + pwriter.print(")/("); + pwriter.print(elemMap.size()); + pwriter.println("):"); + ArrayList keys = new ArrayList(expiryMap.keySet()); + Collections.sort(keys); + for (long time : keys) { + Set set = expiryMap.get(time); + if (set != null) { + pwriter.print(set.size()); + pwriter.print(" expire at "); + pwriter.print(Time.elapsedTimeToDate(time)); + pwriter.println(":"); + for (E elem : set) { + pwriter.print("\t"); + pwriter.println(elem.toString()); + } + } + } + } + + /** + * Returns an unmodifiable view of the expiration time -> elements mapping. + */ + public Map> getExpiryMap() { + return Collections.unmodifiableMap(expiryMap); + } +} + diff --git a/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java new file mode 100644 index 00000000000..def943790f0 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java @@ -0,0 +1,469 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.Record; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.KeeperException.SessionMovedException; +import org.apache.zookeeper.MultiResponse; +import org.apache.zookeeper.OpResult; +import org.apache.zookeeper.OpResult.CheckResult; +import org.apache.zookeeper.OpResult.CreateResult; +import org.apache.zookeeper.OpResult.DeleteResult; +import org.apache.zookeeper.OpResult.ErrorResult; +import org.apache.zookeeper.OpResult.SetDataResult; +import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.proto.CheckWatchesRequest; +import org.apache.zookeeper.proto.Create2Response; +import org.apache.zookeeper.proto.CreateResponse; +import org.apache.zookeeper.proto.ExistsRequest; +import org.apache.zookeeper.proto.ExistsResponse; +import org.apache.zookeeper.proto.GetACLRequest; +import org.apache.zookeeper.proto.GetACLResponse; +import org.apache.zookeeper.proto.GetChildren2Request; +import org.apache.zookeeper.proto.GetChildren2Response; +import org.apache.zookeeper.proto.GetChildrenRequest; +import org.apache.zookeeper.proto.GetChildrenResponse; +import org.apache.zookeeper.proto.GetDataRequest; +import org.apache.zookeeper.proto.GetDataResponse; +import org.apache.zookeeper.proto.RemoveWatchesRequest; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.SetACLResponse; +import org.apache.zookeeper.proto.SetDataResponse; +import org.apache.zookeeper.proto.SetWatches; +import org.apache.zookeeper.proto.SyncRequest; +import org.apache.zookeeper.proto.SyncResponse; +import org.apache.zookeeper.server.DataTree.ProcessTxnResult; +import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; +import org.apache.zookeeper.server.quorum.QuorumZooKeeperServer; +import org.apache.zookeeper.txn.ErrorTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Locale; + +/** + * This Request processor actually applies any transaction associated with a request and services any queries. It is always at the end of a RequestProcessor chain (hence the name), so it does not have + * a nextProcessor member. + * + * This RequestProcessor counts on ZooKeeperServer to populate the outstandingRequests member of ZooKeeperServer. + */ +public class FinalRequestProcessor implements RequestProcessor { + private static final Logger LOG = LoggerFactory.getLogger(FinalRequestProcessor.class); + + ZooKeeperServer zks; + + public FinalRequestProcessor(ZooKeeperServer zks) { + this.zks = zks; + } + + public void processRequest(Request request) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing request:: " + request); + } + // request.addRQRec(">final"); + long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; + if (request.type == OpCode.ping) { + traceMask = ZooTrace.SERVER_PING_TRACE_MASK; + } + if (LOG.isTraceEnabled()) { + ZooTrace.logRequest(LOG, traceMask, 'E', request, ""); + } + ProcessTxnResult rc = null; + synchronized (zks.outstandingChanges) { + // Need to process local session requests + rc = zks.processTxn(request); + + // request.hdr is set for write requests, which are the only ones + // that add to outstandingChanges. + if (request.getHdr() != null) { + TxnHeader hdr = request.getHdr(); + Record txn = request.getTxn(); + long zxid = hdr.getZxid(); + while (!zks.outstandingChanges.isEmpty() && zks.outstandingChanges.get(0).zxid <= zxid) { + ChangeRecord cr = zks.outstandingChanges.remove(0); + if (cr.zxid < zxid) { + LOG.warn("Zxid outstanding " + cr.zxid + " is less than current " + zxid); + } + if (zks.outstandingChangesForPath.get(cr.path) == cr) { + zks.outstandingChangesForPath.remove(cr.path); + } + } + } + + // do not add non quorum packets to the queue. + if (request.isQuorum()) { + zks.getZKDatabase().addCommittedProposal(request); + } + } + + // ZOOKEEPER-558: + // In some cases the server does not close the connection (e.g., closeconn buffer + // was not being queued — ZOOKEEPER-558) properly. This happens, for example, + // when the client closes the connection. The server should still close the session, though. + // Calling closeSession() after losing the cnxn, results in the client close session response being dropped. + if (request.type == OpCode.closeSession && connClosedByClient(request)) { + // We need to check if we can close the session id. + // Sometimes the corresponding ServerCnxnFactory could be null because + // we are just playing diffs from the leader. + if (closeSession(zks.serverCnxnFactory, request.sessionId) || + closeSession(zks.secureServerCnxnFactory, request.sessionId)) { + return; + } + } + + if (request.cnxn == null) { + return; + } + ServerCnxn cnxn = request.cnxn; + + String lastOp = "NA"; + zks.decInProcess(); + Code err = Code.OK; + Record rsp = null; + try { + if (request.getHdr() != null && request.getHdr().getType() == OpCode.error) { + /* + * When local session upgrading is disabled, leader will + * reject the ephemeral node creation due to session expire. + * However, if this is the follower that issue the request, + * it will have the correct error code, so we should use that + * and report to user + */ + if (request.getException() != null) { + throw request.getException(); + } else { + throw KeeperException.create(KeeperException.Code + .get(((ErrorTxn) request.getTxn()).getErr())); + } + } + + KeeperException ke = request.getException(); + if (ke != null && request.type != OpCode.multi) { + throw ke; + } + + if (LOG.isDebugEnabled()) { + LOG.debug("{}", request); + } + switch (request.type) { + case OpCode.ping: { + zks.serverStats().updateLatency(request.createTime); + lastOp = "PING"; + cnxn.updateStatsForResponse(request.cxid, request.zxid, lastOp, request.createTime, Time.currentElapsedTime()); + cnxn.sendResponse(new ReplyHeader(-2, zks.getZKDatabase().getDataTreeLastProcessedZxid(), 0), null, "response"); + return; + } + case OpCode.createSession: { + zks.serverStats().updateLatency(request.createTime); + lastOp = "SESS"; + cnxn.updateStatsForResponse(request.cxid, request.zxid, lastOp, request.createTime, Time.currentElapsedTime()); + zks.finishSessionInit(request.cnxn, true); + return; + } + case OpCode.multi: { + lastOp = "MULT"; + rsp = new MultiResponse(); + + for (ProcessTxnResult subTxnResult : rc.multiResult) { + + OpResult subResult; + + switch (subTxnResult.type) { + case OpCode.check: + subResult = new CheckResult(); + break; + case OpCode.create: + subResult = new CreateResult(subTxnResult.path); + break; + case OpCode.create2: + case OpCode.createContainer: + subResult = new CreateResult(subTxnResult.path, subTxnResult.stat); + break; + case OpCode.delete: + case OpCode.deleteContainer: + subResult = new DeleteResult(); + break; + case OpCode.setData: + subResult = new SetDataResult(subTxnResult.stat); + break; + case OpCode.error: + subResult = new ErrorResult(subTxnResult.err); + break; + default: + throw new IOException("Invalid type of op"); + } + + ((MultiResponse) rsp).add(subResult); + } + + break; + } + case OpCode.create: { + lastOp = "CREA"; + rsp = new CreateResponse(rc.path); + err = Code.get(rc.err); + break; + } + case OpCode.create2: + case OpCode.createContainer: { + lastOp = "CREA"; + rsp = new Create2Response(rc.path, rc.stat); + err = Code.get(rc.err); + break; + } + case OpCode.delete: + case OpCode.deleteContainer: { + lastOp = "DELE"; + err = Code.get(rc.err); + break; + } + case OpCode.setData: { + lastOp = "SETD"; + rsp = new SetDataResponse(rc.stat); + err = Code.get(rc.err); + break; + } + case OpCode.reconfig: { + lastOp = "RECO"; + rsp = new GetDataResponse(((QuorumZooKeeperServer) zks).self.getQuorumVerifier().toString().getBytes(), rc.stat); + err = Code.get(rc.err); + break; + } + case OpCode.setACL: { + lastOp = "SETA"; + rsp = new SetACLResponse(rc.stat); + err = Code.get(rc.err); + break; + } + case OpCode.closeSession: { + lastOp = "CLOS"; + err = Code.get(rc.err); + break; + } + case OpCode.sync: { + lastOp = "SYNC"; + SyncRequest syncRequest = new SyncRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, + syncRequest); + rsp = new SyncResponse(syncRequest.getPath()); + break; + } + case OpCode.check: { + lastOp = "CHEC"; + rsp = new SetDataResponse(rc.stat); + err = Code.get(rc.err); + break; + } + case OpCode.exists: { + lastOp = "EXIS"; + // TODO we need to figure out the security requirement for this! + ExistsRequest existsRequest = new ExistsRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, + existsRequest); + String path = existsRequest.getPath(); + if (path.indexOf('\0') != -1) { + throw new KeeperException.BadArgumentsException(); + } + Stat stat = zks.getZKDatabase().statNode(path, existsRequest + .getWatch() ? cnxn : null); + rsp = new ExistsResponse(stat); + break; + } + case OpCode.getData: { + lastOp = "GETD"; + GetDataRequest getDataRequest = new GetDataRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, getDataRequest); + DataNode n = zks.getZKDatabase().getNode(getDataRequest.getPath()); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + Long aclL; + synchronized (n) { + aclL = n.acl; + } + PrepRequestProcessor.checkACL(zks, zks.getZKDatabase().convertLong(aclL), ZooDefs.Perms.READ, request.authInfo); + Stat stat = new Stat(); + byte b[] = zks.getZKDatabase().getData(getDataRequest.getPath(), stat, + getDataRequest.getWatch() ? cnxn : null); + rsp = new GetDataResponse(b, stat); + break; + } + case OpCode.setWatches: { + lastOp = "SETW"; + SetWatches setWatches = new SetWatches(); + // XXX We really should NOT need this!!!! + request.request.rewind(); + ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); + long relativeZxid = setWatches.getRelativeZxid(); + zks.getZKDatabase().setWatches(relativeZxid, + setWatches.getDataWatches(), + setWatches.getExistWatches(), + setWatches.getChildWatches(), cnxn); + break; + } + case OpCode.getACL: { + lastOp = "GETA"; + GetACLRequest getACLRequest = new GetACLRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, + getACLRequest); + Stat stat = new Stat(); + List acl = + zks.getZKDatabase().getACL(getACLRequest.getPath(), stat); + rsp = new GetACLResponse(acl, stat); + break; + } + case OpCode.getChildren: { + lastOp = "GETC"; + GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, + getChildrenRequest); + DataNode n = zks.getZKDatabase().getNode(getChildrenRequest.getPath()); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + Long aclG; + synchronized (n) { + aclG = n.acl; + + } + PrepRequestProcessor.checkACL(zks, zks.getZKDatabase().convertLong(aclG), + ZooDefs.Perms.READ, + request.authInfo); + List children = zks.getZKDatabase().getChildren( + getChildrenRequest.getPath(), null, getChildrenRequest + .getWatch() ? cnxn : null); + rsp = new GetChildrenResponse(children); + break; + } + case OpCode.getChildren2: { + lastOp = "GETC"; + GetChildren2Request getChildren2Request = new GetChildren2Request(); + ByteBufferInputStream.byteBuffer2Record(request.request, + getChildren2Request); + Stat stat = new Stat(); + DataNode n = zks.getZKDatabase().getNode(getChildren2Request.getPath()); + if (n == null) { + throw new KeeperException.NoNodeException(); + } + Long aclG; + synchronized (n) { + aclG = n.acl; + } + PrepRequestProcessor.checkACL(zks, zks.getZKDatabase().convertLong(aclG), + ZooDefs.Perms.READ, + request.authInfo); + List children = zks.getZKDatabase().getChildren( + getChildren2Request.getPath(), stat, getChildren2Request + .getWatch() ? cnxn : null); + rsp = new GetChildren2Response(children, stat); + break; + } + case OpCode.checkWatches: { + lastOp = "CHKW"; + CheckWatchesRequest checkWatches = new CheckWatchesRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, + checkWatches); + WatcherType type = WatcherType.fromInt(checkWatches.getType()); + boolean containsWatcher = zks.getZKDatabase().containsWatcher( + checkWatches.getPath(), type, cnxn); + if (!containsWatcher) { + String msg = String.format(Locale.ENGLISH, "%s (type: %s)", + new Object[]{checkWatches.getPath(), type}); + throw new KeeperException.NoWatcherException(msg); + } + break; + } + case OpCode.removeWatches: { + lastOp = "REMW"; + RemoveWatchesRequest removeWatches = new RemoveWatchesRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, + removeWatches); + WatcherType type = WatcherType.fromInt(removeWatches.getType()); + boolean removed = zks.getZKDatabase().removeWatch( + removeWatches.getPath(), type, cnxn); + if (!removed) { + String msg = String.format(Locale.ENGLISH, "%s (type: %s)", + new Object[]{removeWatches.getPath(), type}); + throw new KeeperException.NoWatcherException(msg); + } + break; + } + } + } catch (SessionMovedException e) { + // session moved is a connection level error, we need to tear + // down the connection otw ZOOKEEPER-710 might happen + // ie client on slow follower starts to renew session, fails + // before this completes, then tries the fast follower (leader) + // and is successful, however the initial renew is then + // successfully fwd/processed by the leader and as a result + // the client and leader disagree on where the client is most + // recently attached (and therefore invalid SESSION MOVED generated) + cnxn.sendCloseSession(); + return; + } catch (KeeperException e) { + err = e.code(); + } catch (Exception e) { + // log at error level as we are returning a marshalling + // error to the user + LOG.error("Failed to process " + request, e); + StringBuilder sb = new StringBuilder(); + ByteBuffer bb = request.request; + bb.rewind(); + while (bb.hasRemaining()) { + sb.append(Integer.toHexString(bb.get() & 0xff)); + } + LOG.error("Dumping request buffer: 0x" + sb.toString()); + err = Code.MARSHALLINGERROR; + } + + long lastZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); + ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue()); + zks.serverStats().updateLatency(request.createTime); + cnxn.updateStatsForResponse(request.cxid, lastZxid, lastOp, request.createTime, Time.currentElapsedTime()); + try { + cnxn.sendResponse(hdr, rsp, "response"); + if (request.type == OpCode.closeSession) { + cnxn.sendCloseSession(); + } + } catch (IOException e) { + LOG.error("FIXMSG", e); + } + } + + private boolean closeSession(ServerCnxnFactory serverCnxnFactory, long sessionId) { + if (serverCnxnFactory == null) { + return false; + } + return serverCnxnFactory.closeSession(sessionId); + } + + private boolean connClosedByClient(Request request) { + return request.cnxn == null; + } + + public void shutdown() { + // we are the final link in the chain + LOG.info("shutdown of request processor complete"); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/LogFormatter.java b/src/java/main/org/apache/zookeeper/server/LogFormatter.java new file mode 100644 index 00000000000..79ce5497321 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/LogFormatter.java @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.server.persistence.FileHeader; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.EOFException; +import java.io.FileInputStream; +import java.io.IOException; +import java.text.DateFormat; +import java.util.Date; +import java.util.zip.Adler32; +import java.util.zip.Checksum; + +public class LogFormatter { + private static final Logger LOG = LoggerFactory.getLogger(LogFormatter.class); + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + + args=new String[]{"/tmp/zookeeper/version-2/log.10"}; + + if (args.length != 1) { + System.err.println("USAGE: LogFormatter log_file"); + System.exit(2); + } + FileInputStream fis = new FileInputStream(args[0]); + BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis); + FileHeader fhdr = new FileHeader(); + fhdr.deserialize(logStream, "fileheader"); + + if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) { + System.err.println("Invalid magic number for " + args[0]); + System.exit(2); + } + System.out.println("ZooKeeper Transactional Log File with dbid " + + fhdr.getDbid() + " txnlog format version " + + fhdr.getVersion()); + + int count = 0; + while (true) { + long crcValue; + byte[] bytes; + try { + crcValue = logStream.readLong("crcvalue"); + + bytes = logStream.readBuffer("txnEntry"); + } catch (EOFException e) { + System.out.println("EOF reached after " + count + " txns."); + return; + } + if (bytes.length == 0) { + // Since we preallocate, we define EOF to be an + // empty transaction + System.out.println("EOF reached after " + count + " txns."); + return; + } + Checksum crc = new Adler32(); + crc.update(bytes, 0, bytes.length); + if (crcValue != crc.getValue()) { + throw new IOException("CRC doesn't match " + crcValue + + " vs " + crc.getValue()); + } + TxnHeader hdr = new TxnHeader(); + Record txn = SerializeUtils.deserializeTxn(bytes, hdr); + System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT, + DateFormat.LONG).format(new Date(hdr.getTime())) + + " session 0x" + + Long.toHexString(hdr.getClientId()) + + " cxid 0x" + + Long.toHexString(hdr.getCxid()) + + " zxid 0x" + + Long.toHexString(hdr.getZxid()) + + " " + TraceFormatter.op2String(hdr.getType()) + " " + txn); + if (logStream.readByte("EOR") != 'B') { + LOG.error("Last transaction was partial."); + throw new EOFException("Last transaction was partial."); + } + count++; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java b/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java new file mode 100644 index 00000000000..0edc9f893cf --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java @@ -0,0 +1,775 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; +import org.apache.zookeeper.proto.WatcherEvent; +import org.apache.zookeeper.server.NIOServerCnxnFactory.SelectorThread; +import org.apache.zookeeper.server.command.CommandExecutor; +import org.apache.zookeeper.server.command.FourLetterCommands; +import org.apache.zookeeper.server.command.SetTraceMaskCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Writer; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.CancelledKeyException; +import java.nio.channels.SelectionKey; +import java.nio.channels.SocketChannel; +import java.security.cert.Certificate; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * This class handles communication with clients using NIO. There is one per + * client, but only one thread doing the communication. + */ +public class NIOServerCnxn extends ServerCnxn { + private static final Logger LOG = LoggerFactory.getLogger(NIOServerCnxn.class); + private final static byte fourBytes[] = new byte[4]; + private final NIOServerCnxnFactory factory; + private final SocketChannel sock; + private final SelectorThread selectorThread; + private final SelectionKey sk; + private final ByteBuffer lenBuffer = ByteBuffer.allocate(4); + private final Queue outgoingBuffers = + new LinkedBlockingQueue(); + private final ZooKeeperServer zkServer; + /** + * The number of requests that have been submitted but not yet responded to. + */ + private final AtomicInteger outstandingRequests = new AtomicInteger(0); + private final int outstandingLimit; + /** + * This boolean tracks whether the connection is ready for selection or + * not. A connection is marked as not ready for selection while it is + * processing an IO request. The flag is used to gatekeep pushing interest + * op updates onto the selector. + */ + private final AtomicBoolean selectable = new AtomicBoolean(true); + private final AtomicBoolean throttled = new AtomicBoolean(false); + private boolean initialized; + private ByteBuffer incomingBuffer = lenBuffer; + private int sessionTimeout; + /** + * This is the id that uniquely identifies the session of a client. Once + * this session is no longer active, the ephemeral nodes will go away. + */ + private long sessionId; + + public NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, + SelectionKey sk, NIOServerCnxnFactory factory, + SelectorThread selectorThread) throws IOException { + this.zkServer = zk; + this.sock = sock; + this.sk = sk; + this.factory = factory; + this.selectorThread = selectorThread; + if (this.factory.login != null) { + this.zooKeeperSaslServer = new ZooKeeperSaslServer(factory.login); + } + if (zk != null) { + outstandingLimit = zk.getGlobalOutstandingLimit(); + } else { + outstandingLimit = 1; + } + sock.socket().setTcpNoDelay(true); + /* set socket linger to false, so that socket close does not block */ + sock.socket().setSoLinger(false, -1); + InetAddress addr = ((InetSocketAddress) sock.socket() + .getRemoteSocketAddress()).getAddress(); + authInfo.add(new Id("ip", addr.getHostAddress())); + this.sessionTimeout = factory.sessionlessCnxnTimeout; + } + + /** + * Close resources associated with a sock. + */ + public static void closeSock(SocketChannel sock) { + if (sock.isOpen() == false) { + return; + } + + try { + /* + * The following sequence of code is stupid! You would think that + * only sock.close() is needed, but alas, it doesn't work that way. + * If you just do sock.close() there are cases where the socket + * doesn't actually close... + */ + sock.socket().shutdownOutput(); + } catch (IOException e) { + // This is a relatively common exception that we can't avoid + if (LOG.isDebugEnabled()) { + LOG.debug("ignoring exception during output shutdown", e); + } + } + try { + sock.socket().shutdownInput(); + } catch (IOException e) { + // This is a relatively common exception that we can't avoid + if (LOG.isDebugEnabled()) { + LOG.debug("ignoring exception during input shutdown", e); + } + } + try { + sock.socket().close(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("ignoring exception during socket close", e); + } + } + try { + sock.close(); + } catch (IOException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("ignoring exception during socketchannel close", e); + } + } + } + + /* Send close connection packet to the client, doIO will eventually + * close the underlying machinery (like socket, selectorkey, etc...) + */ + public void sendCloseSession() { + sendBuffer(ServerCnxnFactory.closeConn); + } + + /** + * send buffer without using the asynchronous + * calls to selector and then close the socket + * @param bb + */ + void sendBufferSync(ByteBuffer bb) { + try { + /* configure socket to be blocking + * so that we dont have to do write in + * a tight while loop + */ + if (bb != ServerCnxnFactory.closeConn) { + if (sock.isOpen()) { + sock.configureBlocking(true); + sock.write(bb); + } + packetSent(); + } + } catch (IOException ie) { + LOG.error("Error sending data synchronously ", ie); + } + } + + /** + * sendBuffer pushes a byte buffer onto the outgoing buffer queue for + * asynchronous writes. + */ + public void sendBuffer(ByteBuffer bb) { + if (LOG.isTraceEnabled()) { + LOG.trace("Add a buffer to outgoingBuffers, sk " + sk + + " is valid: " + sk.isValid()); + } + outgoingBuffers.add(bb); + requestInterestOpsUpdate(); + } + + /** Read the request payload (everything following the length prefix) */ + private void readPayload() throws IOException, InterruptedException { + if (incomingBuffer.remaining() != 0) { // have we read length bytes? + int rc = sock.read(incomingBuffer); // sock is non-blocking, so ok + if (rc < 0) { + throw new EndOfStreamException( + "Unable to read additional data from client sessionid 0x" + + Long.toHexString(sessionId) + + ", likely client has closed socket"); + } + } + + if (incomingBuffer.remaining() == 0) { // have we read length bytes? + packetReceived(); + incomingBuffer.flip(); + if (!initialized) { + readConnectRequest(); + } else { + readRequest(); + } + lenBuffer.clear(); + incomingBuffer = lenBuffer; + } + } + + public boolean isSelectable() { + return sk.isValid() && selectable.get(); + } + + public void disableSelectable() { + selectable.set(false); + } + + public void enableSelectable() { + selectable.set(true); + } + + private void requestInterestOpsUpdate() { + if (isSelectable()) { + selectorThread.addInterestOpsUpdateRequest(sk); + } + } + + void handleWrite(SelectionKey k) throws IOException, CloseRequestException { + if (outgoingBuffers.isEmpty()) { + return; + } + + /* + * This is going to reset the buffer position to 0 and the + * limit to the size of the buffer, so that we can fill it + * with data from the non-direct buffers that we need to + * send. + */ + ByteBuffer directBuffer = NIOServerCnxnFactory.getDirectBuffer(); + if (directBuffer == null) { + ByteBuffer[] bufferList = new ByteBuffer[outgoingBuffers.size()]; + // Use gathered write call. This updates the positions of the + // byte buffers to reflect the bytes that were written out. + sock.write(outgoingBuffers.toArray(bufferList)); + + // Remove the buffers that we have sent + ByteBuffer bb; + while ((bb = outgoingBuffers.peek()) != null) { + if (bb == ServerCnxnFactory.closeConn) { + throw new CloseRequestException("close requested"); + } + if (bb.remaining() > 0) { + break; + } + packetSent(); + outgoingBuffers.remove(); + } + } else { + directBuffer.clear(); + + for (ByteBuffer b : outgoingBuffers) { + if (directBuffer.remaining() < b.remaining()) { + /* + * When we call put later, if the directBuffer is to + * small to hold everything, nothing will be copied, + * so we've got to slice the buffer if it's too big. + */ + b = (ByteBuffer) b.slice().limit( + directBuffer.remaining()); + } + /* + * put() is going to modify the positions of both + * buffers, put we don't want to change the position of + * the source buffers (we'll do that after the send, if + * needed), so we save and reset the position after the + * copy + */ + int p = b.position(); + directBuffer.put(b); + b.position(p); + if (directBuffer.remaining() == 0) { + break; + } + } + /* + * Do the flip: limit becomes position, position gets set to + * 0. This sets us up for the write. + */ + directBuffer.flip(); + + int sent = sock.write(directBuffer); + + ByteBuffer bb; + + // Remove the buffers that we have sent + while ((bb = outgoingBuffers.peek()) != null) { + if (bb == ServerCnxnFactory.closeConn) { + throw new CloseRequestException("close requested"); + } + if (sent < bb.remaining()) { + /* + * We only partially sent this buffer, so we update + * the position and exit the loop. + */ + bb.position(bb.position() + sent); + break; + } + packetSent(); + /* We've sent the whole buffer, so drop the buffer */ + sent -= bb.remaining(); + outgoingBuffers.remove(); + } + } + } + + /** + * Only used in order to allow testing + */ + protected boolean isSocketOpen() { + return sock.isOpen(); + } + + /** + * Handles read/write IO on connection. + */ + void doIO(SelectionKey k) throws InterruptedException { + try { + if (isSocketOpen() == false) { + LOG.warn("trying to do i/o on a null socket for session:0x" + + Long.toHexString(sessionId)); + + return; + } + if (k.isReadable()) { + int rc = sock.read(incomingBuffer); + if (rc < 0) { + throw new EndOfStreamException( + "Unable to read additional data from client sessionid 0x" + + Long.toHexString(sessionId) + + ", likely client has closed socket"); + } + if (incomingBuffer.remaining() == 0) { + boolean isPayload; + if (incomingBuffer == lenBuffer) { // start of next request + incomingBuffer.flip(); + isPayload = readLength(k); + incomingBuffer.clear(); + } else { + // continuation + isPayload = true; + } + if (isPayload) { // not the case for 4letterword + readPayload(); + } else { + // four letter words take care + // need not do anything else + return; + } + } + } + if (k.isWritable()) { + handleWrite(k); + + if (!initialized && !getReadInterest() && !getWriteInterest()) { + throw new CloseRequestException("responded to info probe"); + } + } + } catch (CancelledKeyException e) { + LOG.warn("CancelledKeyException causing close of session 0x" + + Long.toHexString(sessionId)); + if (LOG.isDebugEnabled()) { + LOG.debug("CancelledKeyException stack trace", e); + } + close(); + } catch (CloseRequestException e) { + // expecting close to log session closure + close(); + } catch (EndOfStreamException e) { + LOG.warn(e.getMessage()); + // expecting close to log session closure + close(); + } catch (IOException e) { + LOG.warn("Exception causing close of session 0x" + + Long.toHexString(sessionId) + ": " + e.getMessage()); + if (LOG.isDebugEnabled()) { + LOG.debug("IOException stack trace", e); + } + close(); + } + } + + private void readRequest() throws IOException { + zkServer.processPacket(this, incomingBuffer); + } + + // Only called as callback from zkServer.processPacket() + protected void incrOutstandingRequests(RequestHeader h) { + if (h.getXid() >= 0) { + outstandingRequests.incrementAndGet(); + // check throttling + int inProcess = zkServer.getInProcess(); + if (inProcess > outstandingLimit) { + if (LOG.isDebugEnabled()) { + LOG.debug("Throttling recv " + inProcess); + } + disableRecv(); + } + } + } + + // returns whether we are interested in writing, which is determined + // by whether we have any pending buffers on the output queue or not + private boolean getWriteInterest() { + return !outgoingBuffers.isEmpty(); + } + + // returns whether we are interested in taking new requests, which is + // determined by whether we are currently throttled or not + private boolean getReadInterest() { + return !throttled.get(); + } + + // Throttle acceptance of new requests. If this entailed a state change, + // register an interest op update request with the selector. + public void disableRecv() { + if (throttled.compareAndSet(false, true)) { + requestInterestOpsUpdate(); + } + } + + // Disable throttling and resume acceptance of new requests. If this + // entailed a state change, register an interest op update request with + // the selector. + public void enableRecv() { + if (throttled.compareAndSet(true, false)) { + requestInterestOpsUpdate(); + } + } + + private void readConnectRequest() throws IOException, InterruptedException { + if (zkServer == null) { + throw new IOException("ZooKeeperServer not running"); + } + zkServer.processConnectRequest(this, incomingBuffer); + initialized = true; + } + + /** Return if four letter word found and responded to, otw false **/ + private boolean checkFourLetterWord(final SelectionKey k, final int len) + throws IOException { + // We take advantage of the limited size of the length to look + // for cmds. They are all 4-bytes which fits inside of an int + String cmd = FourLetterCommands.cmd2String.get(len); + if (cmd == null) { + return false; + } + LOG.info("Processing " + cmd + " command from " + + sock.socket().getRemoteSocketAddress()); + packetReceived(); + + /** cancel the selection key to remove the socket handling + * from selector. This is to prevent netcat problem wherein + * netcat immediately closes the sending side after sending the + * commands and still keeps the receiving channel open. + * The idea is to remove the selectionkey from the selector + * so that the selector does not notice the closed read on the + * socket channel and keep the socket alive to write the data to + * and makes sure to close the socket after its done writing the data + */ + if (k != null) { + try { + k.cancel(); + } catch (Exception e) { + LOG.error("Error cancelling command selection key ", e); + } + } + + final PrintWriter pwriter = new PrintWriter( + new BufferedWriter(new SendBufferWriter())); + if (len == FourLetterCommands.setTraceMaskCmd) { + incomingBuffer = ByteBuffer.allocate(8); + int rc = sock.read(incomingBuffer); + if (rc < 0) { + throw new IOException("Read error"); + } + incomingBuffer.flip(); + long traceMask = incomingBuffer.getLong(); + ZooTrace.setTextTraceLevel(traceMask); + SetTraceMaskCommand setMask = new SetTraceMaskCommand(pwriter, this, traceMask); + setMask.start(); + return true; + } else { + CommandExecutor commandExecutor = new CommandExecutor(); + return commandExecutor.execute(this, pwriter, len, zkServer, factory); + } + } + + /** Reads the first 4 bytes of lenBuffer, which could be true length or + * four letter word. + * + * @param k selection key + * @return true if length read, otw false (wasn't really the length) + * @throws IOException if buffer size exceeds maxBuffer size + */ + private boolean readLength(SelectionKey k) throws IOException { + // Read the length, now get the buffer + int len = lenBuffer.getInt(); + if (!initialized && checkFourLetterWord(sk, len)) { + return false; + } + if (len < 0 || len > BinaryInputArchive.maxBuffer) { + throw new IOException("Len error " + len); + } + if (zkServer == null) { + throw new IOException("ZooKeeperServer not running"); + } + incomingBuffer = ByteBuffer.allocate(len); + return true; + } + + public long getOutstandingRequests() { + return outstandingRequests.get(); + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.server.ServerCnxnIface#getSessionTimeout() + */ + public int getSessionTimeout() { + return sessionTimeout; + } + + @Override + public void setSessionTimeout(int sessionTimeout) { + this.sessionTimeout = sessionTimeout; + factory.touchCnxn(this); + } + + /** + * Used by "dump" 4-letter command to list all connection in + * cnxnExpiryMap + */ + @Override + public String toString() { + return "ip: " + sock.socket().getRemoteSocketAddress() + + " sessionId: 0x" + Long.toHexString(sessionId); + } + + /** + * Close the cnxn and remove it from the factory cnxns list. + */ + @Override + public void close() { + if (!factory.removeCnxn(this)) { + return; + } + + if (zkServer != null) { + zkServer.removeCnxn(this); + } + + if (sk != null) { + try { + // need to cancel this selection key from the selector + sk.cancel(); + } catch (Exception e) { + if (LOG.isDebugEnabled()) { + LOG.debug("ignoring exception during selectionkey cancel", e); + } + } + } + + closeSock(); + } + + /** + * Close resources associated with the sock of this cnxn. + */ + private void closeSock() { + if (sock.isOpen() == false) { + return; + } + + LOG.info("Closed socket connection for client " + + sock.socket().getRemoteSocketAddress() + + (sessionId != 0 ? + " which had sessionid 0x" + Long.toHexString(sessionId) : + " (no session established for client)")); + closeSock(sock); + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.server.ServerCnxnIface#sendResponse(org.apache.zookeeper.proto.ReplyHeader, + * org.apache.jute.Record, java.lang.String) + */ + @Override + public void sendResponse(ReplyHeader h, Record r, String tag) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // Make space for length + BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos); + try { + baos.write(fourBytes); + bos.writeRecord(h, "header"); + if (r != null) { + bos.writeRecord(r, tag); + } + baos.close(); + } catch (IOException e) { + LOG.error("Error serializing response"); + } + byte b[] = baos.toByteArray(); + ByteBuffer bb = ByteBuffer.wrap(b); + bb.putInt(b.length - 4).rewind(); + sendBuffer(bb); + if (h.getXid() > 0) { + // check throttling + if (outstandingRequests.decrementAndGet() < 1 || + zkServer.getInProcess() < outstandingLimit) { + enableRecv(); + } + } + } catch (Exception e) { + LOG.warn("Unexpected exception. Destruction averted.", e); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.server.ServerCnxnIface#process(org.apache.zookeeper.proto.WatcherEvent) + */ + @Override + public void process(WatchedEvent event) { + ReplyHeader h = new ReplyHeader(-1, -1L, 0); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, + "Deliver event " + event + " to 0x" + + Long.toHexString(this.sessionId) + + " through " + this); + } + + // Convert WatchedEvent to a type that can be sent over the wire + WatcherEvent e = event.getWrapper(); + + sendResponse(h, e, "notification"); + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.server.ServerCnxnIface#getSessionId() + */ + @Override + public long getSessionId() { + return sessionId; + } + + @Override + public void setSessionId(long sessionId) { + this.sessionId = sessionId; + factory.addSession(sessionId, this); + } + + @Override + public int getInterestOps() { + if (!isSelectable()) { + return 0; + } + int interestOps = 0; + if (getReadInterest()) { + interestOps |= SelectionKey.OP_READ; + } + if (getWriteInterest()) { + interestOps |= SelectionKey.OP_WRITE; + } + return interestOps; + } + + @Override + public InetSocketAddress getRemoteSocketAddress() { + if (sock.isOpen() == false) { + return null; + } + return (InetSocketAddress) sock.socket().getRemoteSocketAddress(); + } + + public InetAddress getSocketAddress() { + if (sock.isOpen() == false) { + return null; + } + return sock.socket().getInetAddress(); + } + + @Override + protected ServerStats serverStats() { + if (zkServer == null) { + return null; + } + return zkServer.serverStats(); + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public Certificate[] getClientCertificateChain() { + throw new UnsupportedOperationException( + "SSL is unsupported in NIOServerCnxn"); + } + + @Override + public void setClientCertificateChain(Certificate[] chain) { + throw new UnsupportedOperationException( + "SSL is unsupported in NIOServerCnxn"); + } + + /** + * This class wraps the sendBuffer method of NIOServerCnxn. It is + * responsible for chunking up the response to a client. Rather + * than cons'ing up a response fully in memory, which may be large + * for some commands, this class chunks up the result. + */ + private class SendBufferWriter extends Writer { + private StringBuffer sb = new StringBuffer(); + + /** + * Check if we are ready to send another chunk. + * @param force force sending, even if not a full chunk + */ + private void checkFlush(boolean force) { + if ((force && sb.length() > 0) || sb.length() > 2048) { + sendBufferSync(ByteBuffer.wrap(sb.toString().getBytes())); + // clear our internal buffer + sb.setLength(0); + } + } + + @Override + public void close() throws IOException { + if (sb == null) return; + checkFlush(true); + sb = null; // clear out the ref to ensure no reuse + } + + @Override + public void flush() throws IOException { + checkFlush(true); + } + + @Override + public void write(char[] cbuf, int off, int len) throws IOException { + sb.append(cbuf, off, len); + checkFlush(false); + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java b/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java new file mode 100644 index 00000000000..63bbfb4f306 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java @@ -0,0 +1,949 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.nio.ByteBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * NIOServerCnxnFactory implements a multi-threaded ServerCnxnFactory using + * NIO non-blocking socket calls. Communication between threads is handled via + * queues. + * + * - 1 accept thread, which accepts new connections and assigns to a + * selector thread + * - 1-N selector threads, each of which selects on 1/N of the connections. + * The reason the factory supports more than one selector thread is that + * with large numbers of connections, select() itself can become a + * performance bottleneck. + * - 0-M socket I/O worker threads, which perform basic socket reads and + * writes. If configured with 0 worker threads, the selector threads + * do the socket I/O directly. + * - 1 connection expiration thread, which closes idle connections; this is + * necessary to expire connections on which no session is established. + * + * Typical (default) thread counts are: on a 32 core machine, 1 accept thread, + * 1 connection expiration thread, 4 selector threads, and 64 worker threads. + */ +public class NIOServerCnxnFactory extends ServerCnxnFactory { + /** Default sessionless connection timeout in ms: 10000 (10s) */ + public static final String ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT = + "zookeeper.nio.sessionlessCnxnTimeout"; + /** + * With 500 connections to an observer with watchers firing on each, is + * unable to exceed 1GigE rates with only 1 selector. + * Defaults to using 2 selector threads with 8 cores and 4 with 32 cores. + * Expressed as sqrt(numCores/2). Must have at least 1 selector thread. + */ + public static final String ZOOKEEPER_NIO_NUM_SELECTOR_THREADS = + "zookeeper.nio.numSelectorThreads"; + /** Default: 2 * numCores */ + public static final String ZOOKEEPER_NIO_NUM_WORKER_THREADS = + "zookeeper.nio.numWorkerThreads"; + /** Default: 64kB */ + public static final String ZOOKEEPER_NIO_DIRECT_BUFFER_BYTES = + "zookeeper.nio.directBufferBytes"; + /** Default worker pool shutdown timeout in ms: 5000 (5s) */ + public static final String ZOOKEEPER_NIO_SHUTDOWN_TIMEOUT = + "zookeeper.nio.shutdownTimeout"; + private static final Logger LOG = LoggerFactory.getLogger(NIOServerCnxnFactory.class); + private static int directBufferBytes; + /** + * We use this buffer to do efficient socket I/O. Because I/O is handled + * by the worker threads (or the selector threads directly, if no worker + * thread pool is created), we can create a fixed set of these to be + * shared by connections. + */ + private static final ThreadLocal directBuffer = + new ThreadLocal() { + @Override + protected ByteBuffer initialValue() { + return ByteBuffer.allocateDirect(directBufferBytes); + } + }; + + static { + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + LOG.error("Thread " + t + " died", e); + } + }); + /** + * this is to avoid the jvm bug: + * NullPointerException in Selector.open() + * http://bugs.sun.com/view_bug.do?bug_id=6427854 + */ + try { + Selector.open().close(); + } catch (IOException ie) { + LOG.error("Selector failed to open", ie); + } + + /** + * Value of 0 disables use of direct buffers and instead uses + * gathered write call. + * + * Default to using 64k direct buffers. + */ + directBufferBytes = Integer.getInteger( + ZOOKEEPER_NIO_DIRECT_BUFFER_BYTES, 64 * 1024); + } + + // sessionMap is used by closeSession() + private final ConcurrentHashMap sessionMap = + new ConcurrentHashMap(); + // ipMap is used to limit connections per IP + private final ConcurrentHashMap> ipMap = + new ConcurrentHashMap>(); + private final Set selectorThreads = + new HashSet(); + protected int maxClientCnxns = 60; + protected WorkerService workerPool; + ServerSocketChannel ss; + int sessionlessCnxnTimeout; + private ExpiryQueue cnxnExpiryQueue; + private int numSelectorThreads; + private int numWorkerThreads; + private long workerShutdownTimeoutMS; + private volatile boolean stopped = true; + private ConnectionExpirerThread expirerThread; + private AcceptThread acceptThread; + /** + * Construct a new server connection factory which will accept an unlimited number + * of concurrent connections from each client (up to the file descriptor + * limits of the operating system). startup(zks) must be called subsequently. + */ + public NIOServerCnxnFactory() { + } + + public static ByteBuffer getDirectBuffer() { + return directBufferBytes > 0 ? directBuffer.get() : null; + } + + @Override + public void configure(InetSocketAddress addr, int maxcc, boolean secure) throws IOException { + if (secure) { + throw new UnsupportedOperationException("SSL isn't supported in NIOServerCnxn"); + } + configureSaslLogin(); + + maxClientCnxns = maxcc; + sessionlessCnxnTimeout = Integer.getInteger( + ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT, 10000); + // We also use the sessionlessCnxnTimeout as expiring interval for + // cnxnExpiryQueue. These don't need to be the same, but the expiring + // interval passed into the ExpiryQueue() constructor below should be + // less than or equal to the timeout. + cnxnExpiryQueue = + new ExpiryQueue(sessionlessCnxnTimeout); + expirerThread = new ConnectionExpirerThread(); + + int numCores = Runtime.getRuntime().availableProcessors(); + // 32 cores sweet spot seems to be 4 selector threads + numSelectorThreads = Integer.getInteger( + ZOOKEEPER_NIO_NUM_SELECTOR_THREADS, + Math.max((int) Math.sqrt((float) numCores / 2), 1)); + if (numSelectorThreads < 1) { + throw new IOException("numSelectorThreads must be at least 1"); + } + + numWorkerThreads = Integer.getInteger( + ZOOKEEPER_NIO_NUM_WORKER_THREADS, 2 * numCores); + workerShutdownTimeoutMS = Long.getLong( + ZOOKEEPER_NIO_SHUTDOWN_TIMEOUT, 5000); + + LOG.info("Configuring NIO connection handler with " + + (sessionlessCnxnTimeout / 1000) + "s sessionless connection" + + " timeout, " + numSelectorThreads + " selector thread(s), " + + (numWorkerThreads > 0 ? numWorkerThreads : "no") + + " worker threads, and " + + (directBufferBytes == 0 ? "gathered writes." : + ("" + (directBufferBytes / 1024) + " kB direct buffers."))); + for (int i = 0; i < numSelectorThreads; ++i) { + selectorThreads.add(new SelectorThread(i)); + } + + this.ss = ServerSocketChannel.open(); + ss.socket().setReuseAddress(true); + LOG.info("binding to port " + addr); + ss.socket().bind(addr); + ss.configureBlocking(false); + acceptThread = new AcceptThread(ss, addr, selectorThreads); + } + + @Override + public void reconfigure(InetSocketAddress addr) { + ServerSocketChannel oldSS = ss; + try { + this.ss = ServerSocketChannel.open(); + ss.socket().setReuseAddress(true); + LOG.info("binding to port " + addr); + ss.socket().bind(addr); + ss.configureBlocking(false); + acceptThread.setReconfiguring(); + oldSS.close(); + acceptThread.wakeupSelector(); + try { + acceptThread.join(); + } catch (InterruptedException e) { + LOG.error("Error joining old acceptThread when reconfiguring client port " + e.getMessage()); + } + acceptThread = new AcceptThread(ss, addr, selectorThreads); + acceptThread.start(); + } catch (IOException e) { + LOG.error("Error reconfiguring client port to " + addr + " " + e.getMessage()); + } + } + + /** {@inheritDoc} */ + public int getMaxClientCnxnsPerHost() { + return maxClientCnxns; + } + + /** {@inheritDoc} */ + public void setMaxClientCnxnsPerHost(int max) { + maxClientCnxns = max; + } + + @Override + public void start() { + stopped = false; + if (workerPool == null) { + workerPool = new WorkerService( + "NIOWorker", numWorkerThreads, false); + } + for (SelectorThread thread : selectorThreads) { + if (thread.getState() == Thread.State.NEW) { + thread.start(); + } + } + // ensure thread is started once and only once + if (acceptThread.getState() == Thread.State.NEW) { + acceptThread.start(); + } + if (expirerThread.getState() == Thread.State.NEW) { + expirerThread.start(); + } + } + + @Override + public void startup(ZooKeeperServer zks, boolean startServer) + throws IOException, InterruptedException { + start(); + setZooKeeperServer(zks); + if (startServer) { + zks.startdata(); + zks.startup(); + } + } + + @Override + public InetSocketAddress getLocalAddress() { + return (InetSocketAddress) ss.socket().getLocalSocketAddress(); + } + + @Override + public int getLocalPort() { + return ss.socket().getLocalPort(); + } + + /** + * De-registers the connection from the various mappings maintained + * by the factory. + */ + public boolean removeCnxn(NIOServerCnxn cnxn) { + // If the connection is not in the master list it's already been closed + if (!cnxns.remove(cnxn)) { + return false; + } + cnxnExpiryQueue.remove(cnxn); + + long sessionId = cnxn.getSessionId(); + if (sessionId != 0) { + sessionMap.remove(sessionId); + } + + InetAddress addr = cnxn.getSocketAddress(); + if (addr != null) { + Set set = ipMap.get(addr); + if (set != null) { + set.remove(cnxn); + // Note that we make no effort here to remove empty mappings + // from ipMap. + } + } + + // unregister from JMX + unregisterConnection(cnxn); + return true; + } + + /** + * Add or update cnxn in our cnxnExpiryQueue + * @param cnxn + */ + public void touchCnxn(NIOServerCnxn cnxn) { + cnxnExpiryQueue.update(cnxn, cnxn.getSessionTimeout()); + } + + private void addCnxn(NIOServerCnxn cnxn) { + InetAddress addr = cnxn.getSocketAddress(); + Set set = ipMap.get(addr); + if (set == null) { + // in general we will see 1 connection from each + // host, setting the initial cap to 2 allows us + // to minimize mem usage in the common case + // of 1 entry -- we need to set the initial cap + // to 2 to avoid rehash when the first entry is added + // Construct a ConcurrentHashSet using a ConcurrentHashMap + set = Collections.newSetFromMap( + new ConcurrentHashMap(2)); + // Put the new set in the map, but only if another thread + // hasn't beaten us to it + Set existingSet = ipMap.putIfAbsent(addr, set); + if (existingSet != null) { + set = existingSet; + } + } + set.add(cnxn); + + cnxns.add(cnxn); + touchCnxn(cnxn); + } + + protected NIOServerCnxn createConnection(SocketChannel sock, + SelectionKey sk, SelectorThread selectorThread) throws IOException { + return new NIOServerCnxn(zkServer, sock, sk, this, selectorThread); + } + + private int getClientCnxnCount(InetAddress cl) { + Set s = ipMap.get(cl); + if (s == null) return 0; + return s.size(); + } + + /** + * clear all the connections in the selector + * + */ + @Override + @SuppressWarnings("unchecked") + public void closeAll() { + // clear all the connections on which we are selecting + for (ServerCnxn cnxn : cnxns) { + try { + // This will remove the cnxn from cnxns + cnxn.close(); + } catch (Exception e) { + LOG.warn("Ignoring exception closing cnxn sessionid 0x" + + Long.toHexString(cnxn.getSessionId()), e); + } + } + } + + public void stop() { + stopped = true; + + // Stop queuing connection attempts + try { + ss.close(); + } catch (IOException e) { + LOG.warn("Error closing listen socket", e); + } + + if (acceptThread != null) { + acceptThread.wakeupSelector(); + } + if (expirerThread != null) { + expirerThread.interrupt(); + } + for (SelectorThread thread : selectorThreads) { + thread.wakeupSelector(); + } + if (workerPool != null) { + workerPool.stop(); + } + } + + public void shutdown() { + try { + // close listen socket and signal selector threads to stop + stop(); + + // wait for selector and worker threads to shutdown + join(); + + // close all open connections + closeAll(); + + if (login != null) { + login.shutdown(); + } + } catch (InterruptedException e) { + LOG.warn("Ignoring interrupted exception during shutdown", e); + } catch (Exception e) { + LOG.warn("Ignoring unexpected exception during shutdown", e); + } + + if (zkServer != null) { + zkServer.shutdown(); + } + } + + public void addSession(long sessionId, NIOServerCnxn cnxn) { + sessionMap.put(sessionId, cnxn); + } + + @Override + public boolean closeSession(long sessionId) { + NIOServerCnxn cnxn = sessionMap.remove(sessionId); + if (cnxn != null) { + cnxn.close(); + return true; + } + return false; + } + + @Override + public void join() throws InterruptedException { + if (acceptThread != null) { + acceptThread.join(); + } + for (SelectorThread thread : selectorThreads) { + thread.join(); + } + if (workerPool != null) { + workerPool.join(workerShutdownTimeoutMS); + } + } + + @Override + public Iterable getConnections() { + return cnxns; + } + + public void dumpConnections(PrintWriter pwriter) { + pwriter.print("Connections "); + cnxnExpiryQueue.dump(pwriter); + } + + @Override + public void resetAllConnectionStats() { + // No need to synchronize since cnxns is backed by a ConcurrentHashMap + for (ServerCnxn c : cnxns) { + c.resetStats(); + } + } + + @Override + public Iterable> getAllConnectionInfo(boolean brief) { + HashSet> info = new HashSet>(); + // No need to synchronize since cnxns is backed by a ConcurrentHashMap + for (ServerCnxn c : cnxns) { + info.add(c.getConnectionInfo(brief)); + } + return info; + } + + /** + * AbstractSelectThread is an abstract base class containing a few bits + * of code shared by the AcceptThread (which selects on the listen socket) + * and SelectorThread (which selects on client connections) classes. + */ + private abstract class AbstractSelectThread extends ZooKeeperThread { + protected final Selector selector; + + public AbstractSelectThread(String name) throws IOException { + super(name); + // Allows the JVM to shutdown even if this thread is still running. + setDaemon(true); + this.selector = Selector.open(); + } + + public void wakeupSelector() { + selector.wakeup(); + } + + /** + * Close the selector. This should be called when the thread is about to + * exit and no operation is going to be performed on the Selector or + * SelectionKey + */ + protected void closeSelector() { + try { + selector.close(); + } catch (IOException e) { + LOG.warn("ignored exception during selector close " + + e.getMessage()); + } + } + + protected void cleanupSelectionKey(SelectionKey key) { + if (key != null) { + try { + key.cancel(); + } catch (Exception ex) { + if (LOG.isDebugEnabled()) { + LOG.debug("ignoring exception during selectionkey cancel", ex); + } + } + } + } + + protected void fastCloseSock(SocketChannel sc) { + if (sc != null) { + try { + // Hard close immediately, discarding buffers + sc.socket().setSoLinger(true, 0); + } catch (SocketException e) { + LOG.warn("Unable to set socket linger to 0, socket close" + + " may stall in CLOSE_WAIT", e); + } + NIOServerCnxn.closeSock(sc); + } + } + } + + /** + * There is a single AcceptThread which accepts new connections and assigns + * them to a SelectorThread using a simple round-robin scheme to spread + * them across the SelectorThreads. It enforces maximum number of + * connections per IP and attempts to cope with running out of file + * descriptors by briefly sleeping before retrying. + */ + private class AcceptThread extends AbstractSelectThread { + private final ServerSocketChannel acceptSocket; + private final SelectionKey acceptKey; + private final RateLogger acceptErrorLogger = new RateLogger(LOG); + private final Collection selectorThreads; + private Iterator selectorIterator; + private volatile boolean reconfiguring = false; + + public AcceptThread(ServerSocketChannel ss, InetSocketAddress addr, + Set selectorThreads) throws IOException { + super("NIOServerCxnFactory.AcceptThread:" + addr); + this.acceptSocket = ss; + this.acceptKey = + acceptSocket.register(selector, SelectionKey.OP_ACCEPT); + this.selectorThreads = Collections.unmodifiableList( + new ArrayList(selectorThreads)); + selectorIterator = this.selectorThreads.iterator(); + } + + public void run() { + try { + while (!stopped && !acceptSocket.socket().isClosed()) { + try { + select(); + } catch (RuntimeException e) { + LOG.warn("Ignoring unexpected runtime exception", e); + } catch (Exception e) { + LOG.warn("Ignoring unexpected exception", e); + } + } + } finally { + closeSelector(); + // This will wake up the selector threads, and tell the + // worker thread pool to begin shutdown. + if (!reconfiguring) { + NIOServerCnxnFactory.this.stop(); + } + LOG.info("accept thread exitted run method"); + } + } + + public void setReconfiguring() { + reconfiguring = true; + } + + private void select() { + try { + selector.select(); + + Iterator selectedKeys = + selector.selectedKeys().iterator(); + while (!stopped && selectedKeys.hasNext()) { + SelectionKey key = selectedKeys.next(); + selectedKeys.remove(); + + if (!key.isValid()) { + continue; + } + if (key.isAcceptable()) { + if (!doAccept()) { + // If unable to pull a new connection off the accept + // queue, pause accepting to give us time to free + // up file descriptors and so the accept thread + // doesn't spin in a tight loop. + pauseAccept(10); + } + } else { + LOG.warn("Unexpected ops in accept select " + + key.readyOps()); + } + } + } catch (IOException e) { + LOG.warn("Ignoring IOException while selecting", e); + } + } + + /** + * Mask off the listen socket interest ops and use select() to sleep + * so that other threads can wake us up by calling wakeup() on the + * selector. + */ + private void pauseAccept(long millisecs) { + acceptKey.interestOps(0); + try { + selector.select(millisecs); + } catch (IOException e) { + // ignore + } finally { + acceptKey.interestOps(SelectionKey.OP_ACCEPT); + } + } + + /** + * Accept new socket connections. Enforces maximum number of connections + * per client IP address. Round-robin assigns to selector thread for + * handling. Returns whether pulled a connection off the accept queue + * or not. If encounters an error attempts to fast close the socket. + * + * @return whether was able to accept a connection or not + */ + private boolean doAccept() { + boolean accepted = false; + SocketChannel sc = null; + try { + sc = acceptSocket.accept(); + accepted = true; + InetAddress ia = sc.socket().getInetAddress(); + int cnxncount = getClientCnxnCount(ia); + + if (maxClientCnxns > 0 && cnxncount >= maxClientCnxns) { + throw new IOException("Too many connections from " + ia + + " - max is " + maxClientCnxns); + } + + LOG.info("Accepted socket connection from " + + sc.socket().getRemoteSocketAddress()); + sc.configureBlocking(false); + + // Round-robin assign this connection to a selector thread + if (!selectorIterator.hasNext()) { + selectorIterator = selectorThreads.iterator(); + } + SelectorThread selectorThread = selectorIterator.next(); + if (!selectorThread.addAcceptedConnection(sc)) { + throw new IOException( + "Unable to add connection to selector queue" + + (stopped ? " (shutdown in progress)" : "")); + } + acceptErrorLogger.flush(); + } catch (IOException e) { + // accept, maxClientCnxns, configureBlocking + acceptErrorLogger.rateLimitLog( + "Error accepting new connection: " + e.getMessage()); + fastCloseSock(sc); + } + return accepted; + } + } + + /** + * The SelectorThread receives newly accepted connections from the + * AcceptThread and is responsible for selecting for I/O readiness + * across the connections. This thread is the only thread that performs + * any non-threadsafe or potentially blocking calls on the selector + * (registering new connections and reading/writing interest ops). + * + * Assignment of a connection to a SelectorThread is permanent and only + * one SelectorThread will ever interact with the connection. There are + * 1-N SelectorThreads, with connections evenly apportioned between the + * SelectorThreads. + * + * If there is a worker thread pool, when a connection has I/O to perform + * the SelectorThread removes it from selection by clearing its interest + * ops and schedules the I/O for processing by a worker thread. When the + * work is complete, the connection is placed on the ready queue to have + * its interest ops restored and resume selection. + * + * If there is no worker thread pool, the SelectorThread performs the I/O + * directly. + */ + class SelectorThread extends AbstractSelectThread { + private final int id; + private final Queue acceptedQueue; + private final Queue updateQueue; + + public SelectorThread(int id) throws IOException { + super("NIOServerCxnFactory.SelectorThread-" + id); + this.id = id; + acceptedQueue = new LinkedBlockingQueue(); + updateQueue = new LinkedBlockingQueue(); + } + + /** + * Place new accepted connection onto a queue for adding. Do this + * so only the selector thread modifies what keys are registered + * with the selector. + */ + public boolean addAcceptedConnection(SocketChannel accepted) { + if (stopped || !acceptedQueue.offer(accepted)) { + return false; + } + wakeupSelector(); + return true; + } + + /** + * Place interest op update requests onto a queue so that only the + * selector thread modifies interest ops, because interest ops + * reads/sets are potentially blocking operations if other select + * operations are happening. + */ + public boolean addInterestOpsUpdateRequest(SelectionKey sk) { + if (stopped || !updateQueue.offer(sk)) { + return false; + } + wakeupSelector(); + return true; + } + + /** + * The main loop for the thread selects() on the connections and + * dispatches ready I/O work requests, then registers all pending + * newly accepted connections and updates any interest ops on the + * queue. + */ + public void run() { + try { + while (!stopped) { + try { + select(); + processAcceptedConnections(); + processInterestOpsUpdateRequests(); + } catch (RuntimeException e) { + LOG.warn("Ignoring unexpected runtime exception", e); + } catch (Exception e) { + LOG.warn("Ignoring unexpected exception", e); + } + } + + // Close connections still pending on the selector. Any others + // with in-flight work, let drain out of the work queue. + for (SelectionKey key : selector.keys()) { + NIOServerCnxn cnxn = (NIOServerCnxn) key.attachment(); + if (cnxn.isSelectable()) { + cnxn.close(); + } + cleanupSelectionKey(key); + } + SocketChannel accepted; + while ((accepted = acceptedQueue.poll()) != null) { + fastCloseSock(accepted); + } + updateQueue.clear(); + } finally { + closeSelector(); + // This will wake up the accept thread and the other selector + // threads, and tell the worker thread pool to begin shutdown. + NIOServerCnxnFactory.this.stop(); + LOG.info("selector thread exitted run method"); + } + } + + private void select() { + try { + selector.select(); + + Set selected = selector.selectedKeys(); + ArrayList selectedList = + new ArrayList(selected); + Collections.shuffle(selectedList); + Iterator selectedKeys = selectedList.iterator(); + while (!stopped && selectedKeys.hasNext()) { + SelectionKey key = selectedKeys.next(); + selected.remove(key); + + if (!key.isValid()) { + cleanupSelectionKey(key); + continue; + } + if (key.isReadable() || key.isWritable()) { + handleIO(key); + } else { + LOG.warn("Unexpected ops in select " + key.readyOps()); + } + } + } catch (IOException e) { + LOG.warn("Ignoring IOException while selecting", e); + } + } + + /** + * Schedule I/O for processing on the connection associated with + * the given SelectionKey. If a worker thread pool is not being used, + * I/O is run directly by this thread. + */ + private void handleIO(SelectionKey key) { + IOWorkRequest workRequest = new IOWorkRequest(this, key); + NIOServerCnxn cnxn = (NIOServerCnxn) key.attachment(); + + // Stop selecting this key while processing on its + // connection + cnxn.disableSelectable(); + key.interestOps(0); + touchCnxn(cnxn); + workerPool.schedule(workRequest); + } + + /** + * Iterate over the queue of accepted connections that have been + * assigned to this thread but not yet placed on the selector. + */ + private void processAcceptedConnections() { + SocketChannel accepted; + while (!stopped && (accepted = acceptedQueue.poll()) != null) { + SelectionKey key = null; + try { + key = accepted.register(selector, SelectionKey.OP_READ); + NIOServerCnxn cnxn = createConnection(accepted, key, this); + key.attach(cnxn); + addCnxn(cnxn); + } catch (IOException e) { + // register, createConnection + cleanupSelectionKey(key); + fastCloseSock(accepted); + } + } + } + + /** + * Iterate over the queue of connections ready to resume selection, + * and restore their interest ops selection mask. + */ + private void processInterestOpsUpdateRequests() { + SelectionKey key; + while (!stopped && (key = updateQueue.poll()) != null) { + if (!key.isValid()) { + cleanupSelectionKey(key); + } + NIOServerCnxn cnxn = (NIOServerCnxn) key.attachment(); + if (cnxn.isSelectable()) { + key.interestOps(cnxn.getInterestOps()); + } + } + } + } + + /** + * IOWorkRequest is a small wrapper class to allow doIO() calls to be + * run on a connection using a WorkerService. + */ + private class IOWorkRequest extends WorkerService.WorkRequest { + private final SelectorThread selectorThread; + private final SelectionKey key; + private final NIOServerCnxn cnxn; + + IOWorkRequest(SelectorThread selectorThread, SelectionKey key) { + this.selectorThread = selectorThread; + this.key = key; + this.cnxn = (NIOServerCnxn) key.attachment(); + } + + public void doWork() throws InterruptedException { + if (!key.isValid()) { + selectorThread.cleanupSelectionKey(key); + return; + } + + if (key.isReadable() || key.isWritable()) { + cnxn.doIO(key); + + // Check if we shutdown or doIO() closed this connection + if (stopped) { + cnxn.close(); + return; + } + if (!key.isValid()) { + selectorThread.cleanupSelectionKey(key); + return; + } + touchCnxn(cnxn); + } + + // Mark this connection as once again ready for selection + cnxn.enableSelectable(); + // Push an update request on the queue to resume selecting + // on the current set of interest ops, which may have changed + // as a result of the I/O operations we just performed. + if (!selectorThread.addInterestOpsUpdateRequest(key)) { + cnxn.close(); + } + } + + @Override + public void cleanup() { + cnxn.close(); + } + } + + /** + * This thread is responsible for closing stale connections so that + * connections on which no session is established are properly expired. + */ + private class ConnectionExpirerThread extends ZooKeeperThread { + ConnectionExpirerThread() { + super("ConnnectionExpirer"); + } + + public void run() { + try { + while (!stopped) { + long waitTime = cnxnExpiryQueue.getWaitTime(); + if (waitTime > 0) { + Thread.sleep(waitTime); + continue; + } + for (NIOServerCnxn conn : cnxnExpiryQueue.poll()) { + conn.close(); + } + } + + } catch (InterruptedException e) { + LOG.info("ConnnectionExpirerThread interrupted"); + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java b/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java new file mode 100644 index 00000000000..a8a8fc75a10 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java @@ -0,0 +1,476 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.WatcherEvent; +import org.apache.zookeeper.server.command.CommandExecutor; +import org.apache.zookeeper.server.command.FourLetterCommands; +import org.apache.zookeeper.server.command.SetTraceMaskCommand; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.MessageEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Writer; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.security.cert.Certificate; +import java.util.Arrays; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; + +import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer; + +public class NettyServerCnxn extends ServerCnxn { + private static final Logger LOG = LoggerFactory.getLogger(NettyServerCnxn.class); + private static final byte[] fourBytes = new byte[4]; + Channel channel; + ChannelBuffer queuedBuffer; + volatile boolean throttled; + ByteBuffer bb; + ByteBuffer bbLen = ByteBuffer.allocate(4); + long sessionId; + int sessionTimeout; + AtomicLong outstandingCount = new AtomicLong(); + Certificate[] clientChain; + NettyServerCnxnFactory factory; + boolean initialized; + /** The ZooKeeperServer for this connection. May be null if the server + * is not currently serving requests (for example if the server is not + * an active quorum participant. + */ + private volatile ZooKeeperServer zkServer; + + NettyServerCnxn(Channel channel, ZooKeeperServer zks, NettyServerCnxnFactory factory) { + this.channel = channel; + this.zkServer = zks; + this.factory = factory; + if (this.factory.login != null) { + this.zooKeeperSaslServer = new ZooKeeperSaslServer(factory.login); + } + } + + @Override + public void close() { + if (LOG.isDebugEnabled()) { + LOG.debug("close called for sessionid:0x" + + Long.toHexString(sessionId)); + } + synchronized (factory.cnxns) { + // if this is not in cnxns then it's already closed + if (!factory.cnxns.remove(this)) { + if (LOG.isDebugEnabled()) { + LOG.debug("cnxns size:" + factory.cnxns.size()); + } + return; + } + if (LOG.isDebugEnabled()) { + LOG.debug("close in progress for sessionid:0x" + + Long.toHexString(sessionId)); + } + + synchronized (factory.ipMap) { + Set s = + factory.ipMap.get(((InetSocketAddress) channel + .getRemoteAddress()).getAddress()); + s.remove(this); + } + } + + if (channel.isOpen()) { + channel.close(); + } + factory.unregisterConnection(this); + } + + @Override + public long getSessionId() { + return sessionId; + } + + @Override + public void setSessionId(long sessionId) { + this.sessionId = sessionId; + } + + @Override + public int getSessionTimeout() { + return sessionTimeout; + } + + @Override + public void setSessionTimeout(int sessionTimeout) { + this.sessionTimeout = sessionTimeout; + } + + ; + + @Override + public void process(WatchedEvent event) { + ReplyHeader h = new ReplyHeader(-1, -1L, 0); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, + "Deliver event " + event + " to 0x" + + Long.toHexString(this.sessionId) + + " through " + this); + } + + // Convert WatchedEvent to a type that can be sent over the wire + WatcherEvent e = event.getWrapper(); + + try { + sendResponse(h, e, "notification"); + } catch (IOException e1) { + if (LOG.isDebugEnabled()) { + LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1); + } + close(); + } + } + + @Override + public void sendResponse(ReplyHeader h, Record r, String tag) + throws IOException { + if (!channel.isOpen()) { + return; + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // Make space for length + BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos); + try { + baos.write(fourBytes); + bos.writeRecord(h, "header"); + if (r != null) { + bos.writeRecord(r, tag); + } + baos.close(); + } catch (IOException e) { + LOG.error("Error serializing response"); + } + byte b[] = baos.toByteArray(); + ByteBuffer bb = ByteBuffer.wrap(b); + bb.putInt(b.length - 4).rewind(); + sendBuffer(bb); + if (h.getXid() > 0) { + // zks cannot be null otherwise we would not have gotten here! + if (!zkServer.shouldThrottle(outstandingCount.decrementAndGet())) { + enableRecv(); + } + } + } + + @Override + public void enableRecv() { + if (throttled) { + throttled = false; + if (LOG.isDebugEnabled()) { + LOG.debug("Sending unthrottle event " + this); + } + channel.getPipeline().sendUpstream(new ResumeMessageEvent(channel)); + } + } + + @Override + public void sendBuffer(ByteBuffer sendBuffer) { + if (sendBuffer == ServerCnxnFactory.closeConn) { + close(); + return; + } + channel.write(wrappedBuffer(sendBuffer)); + packetSent(); + } + + /** Return if four letter word found and responded to, otw false **/ + private boolean checkFourLetterWord(final Channel channel, + ChannelBuffer message, final int len) throws IOException { + // We take advantage of the limited size of the length to look + // for cmds. They are all 4-bytes which fits inside of an int + String cmd = FourLetterCommands.cmd2String.get(len); + if (cmd == null) { + return false; + } + channel.setInterestOps(0).awaitUninterruptibly(); + LOG.info("Processing " + cmd + " command from " + + channel.getRemoteAddress()); + packetReceived(); + + final PrintWriter pwriter = new PrintWriter( + new BufferedWriter(new SendBufferWriter())); + if (len == FourLetterCommands.setTraceMaskCmd) { + ByteBuffer mask = ByteBuffer.allocate(8); + message.readBytes(mask); + mask.flip(); + long traceMask = mask.getLong(); + ZooTrace.setTextTraceLevel(traceMask); + SetTraceMaskCommand setMask = new SetTraceMaskCommand(pwriter, this, traceMask); + setMask.start(); + return true; + } else { + CommandExecutor commandExecutor = new CommandExecutor(); + return commandExecutor.execute(this, pwriter, len, zkServer, factory); + } + } + + public void receiveMessage(ChannelBuffer message) { + try { + while (message.readable() && !throttled) { + if (bb != null) { + if (LOG.isTraceEnabled()) { + LOG.trace("message readable " + message.readableBytes() + + " bb len " + bb.remaining() + " " + bb); + ByteBuffer dat = bb.duplicate(); + dat.flip(); + LOG.trace(Long.toHexString(sessionId) + + " bb 0x" + + ChannelBuffers.hexDump( + ChannelBuffers.copiedBuffer(dat))); + } + + if (bb.remaining() > message.readableBytes()) { + int newLimit = bb.position() + message.readableBytes(); + bb.limit(newLimit); + } + message.readBytes(bb); + bb.limit(bb.capacity()); + + if (LOG.isTraceEnabled()) { + LOG.trace("after readBytes message readable " + + message.readableBytes() + + " bb len " + bb.remaining() + " " + bb); + ByteBuffer dat = bb.duplicate(); + dat.flip(); + LOG.trace("after readbytes " + + Long.toHexString(sessionId) + + " bb 0x" + + ChannelBuffers.hexDump( + ChannelBuffers.copiedBuffer(dat))); + } + if (bb.remaining() == 0) { + packetReceived(); + bb.flip(); + + ZooKeeperServer zks = this.zkServer; + if (zks == null) { + throw new IOException("ZK down"); + } + if (initialized) { + zks.processPacket(this, bb); + + if (zks.shouldThrottle(outstandingCount.incrementAndGet())) { + disableRecvNoWait(); + } + } else { + LOG.debug("got conn req request from " + + getRemoteSocketAddress()); + zks.processConnectRequest(this, bb); + initialized = true; + } + bb = null; + } + } else { + if (LOG.isTraceEnabled()) { + LOG.trace("message readable " + + message.readableBytes() + + " bblenrem " + bbLen.remaining()); + ByteBuffer dat = bbLen.duplicate(); + dat.flip(); + LOG.trace(Long.toHexString(sessionId) + + " bbLen 0x" + + ChannelBuffers.hexDump( + ChannelBuffers.copiedBuffer(dat))); + } + + if (message.readableBytes() < bbLen.remaining()) { + bbLen.limit(bbLen.position() + message.readableBytes()); + } + message.readBytes(bbLen); + bbLen.limit(bbLen.capacity()); + if (bbLen.remaining() == 0) { + bbLen.flip(); + + if (LOG.isTraceEnabled()) { + LOG.trace(Long.toHexString(sessionId) + + " bbLen 0x" + + ChannelBuffers.hexDump( + ChannelBuffers.copiedBuffer(bbLen))); + } + int len = bbLen.getInt(); + if (LOG.isTraceEnabled()) { + LOG.trace(Long.toHexString(sessionId) + + " bbLen len is " + len); + } + + bbLen.clear(); + if (!initialized) { + if (checkFourLetterWord(channel, message, len)) { + return; + } + } + if (len < 0 || len > BinaryInputArchive.maxBuffer) { + throw new IOException("Len error " + len); + } + bb = ByteBuffer.allocate(len); + } + } + } + } catch (IOException e) { + LOG.warn("Closing connection to " + getRemoteSocketAddress(), e); + close(); + } + } + + @Override + public void disableRecv() { + disableRecvNoWait().awaitUninterruptibly(); + } + + private ChannelFuture disableRecvNoWait() { + throttled = true; + if (LOG.isDebugEnabled()) { + LOG.debug("Throttling - disabling recv " + this); + } + return channel.setReadable(false); + } + + @Override + public long getOutstandingRequests() { + return outstandingCount.longValue(); + } + + @Override + public int getInterestOps() { + return channel.getInterestOps(); + } + + @Override + public InetSocketAddress getRemoteSocketAddress() { + return (InetSocketAddress) channel.getRemoteAddress(); + } + + /** Send close connection packet to the client. + */ + @Override + public void sendCloseSession() { + sendBuffer(ServerCnxnFactory.closeConn); + } + + @Override + protected ServerStats serverStats() { + if (zkServer == null) { + return null; + } + return zkServer.serverStats(); + } + + @Override + public boolean isSecure() { + return factory.secure; + } + + @Override + public Certificate[] getClientCertificateChain() { + if (clientChain == null) { + return null; + } + return Arrays.copyOf(clientChain, clientChain.length); + } + + @Override + public void setClientCertificateChain(Certificate[] chain) { + if (chain == null) { + clientChain = null; + } else { + clientChain = Arrays.copyOf(chain, chain.length); + } + } + + static class ResumeMessageEvent implements MessageEvent { + Channel channel; + + ResumeMessageEvent(Channel channel) { + this.channel = channel; + } + + @Override + public Object getMessage() { + return null; + } + + @Override + public SocketAddress getRemoteAddress() { + return null; + } + + @Override + public Channel getChannel() { + return channel; + } + + @Override + public ChannelFuture getFuture() { + return null; + } + } + + /** + * This class wraps the sendBuffer method of NIOServerCnxn. It is + * responsible for chunking up the response to a client. Rather + * than cons'ing up a response fully in memory, which may be large + * for some commands, this class chunks up the result. + */ + private class SendBufferWriter extends Writer { + private StringBuffer sb = new StringBuffer(); + + /** + * Check if we are ready to send another chunk. + * @param force force sending, even if not a full chunk + */ + private void checkFlush(boolean force) { + if ((force && sb.length() > 0) || sb.length() > 2048) { + sendBuffer(ByteBuffer.wrap(sb.toString().getBytes())); + // clear our internal buffer + sb.setLength(0); + } + } + + @Override + public void close() throws IOException { + if (sb == null) return; + checkFlush(true); + sb = null; // clear out the ref to ensure no reuse + } + + @Override + public void flush() throws IOException { + checkFlush(true); + } + + @Override + public void write(char[] cbuf, int off, int len) throws IOException { + sb.append(cbuf, off, len); + checkFlush(false); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java b/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java new file mode 100644 index 00000000000..f81d0b8f5b5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java @@ -0,0 +1,536 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.common.X509Exception; +import org.apache.zookeeper.common.X509Exception.SSLContextException; +import org.apache.zookeeper.common.X509Util; +import org.apache.zookeeper.server.auth.ProviderRegistry; +import org.apache.zookeeper.server.auth.X509AuthenticationProvider; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelFutureListener; +import org.jboss.netty.channel.ChannelHandler.Sharable; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.channel.ChannelPipelineFactory; +import org.jboss.netty.channel.ChannelStateEvent; +import org.jboss.netty.channel.Channels; +import org.jboss.netty.channel.ExceptionEvent; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.channel.WriteCompletionEvent; +import org.jboss.netty.channel.group.ChannelGroup; +import org.jboss.netty.channel.group.DefaultChannelGroup; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +import org.jboss.netty.handler.ssl.SslHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Executors; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLSession; +import javax.net.ssl.X509KeyManager; +import javax.net.ssl.X509TrustManager; + +import static org.jboss.netty.buffer.ChannelBuffers.dynamicBuffer; + +public class NettyServerCnxnFactory extends ServerCnxnFactory { + private static final Logger LOG = LoggerFactory.getLogger(NettyServerCnxnFactory.class); + + ServerBootstrap bootstrap; + Channel parentChannel; + ChannelGroup allChannels = new DefaultChannelGroup("zkServerCnxns"); + HashMap> ipMap = + new HashMap>(); + InetSocketAddress localAddress; + int maxClientCnxns = 60; + CnxnChannelHandler channelHandler = new CnxnChannelHandler(); + boolean killed; + + NettyServerCnxnFactory() { + bootstrap = new ServerBootstrap( + new NioServerSocketChannelFactory( + Executors.newCachedThreadPool(), + Executors.newCachedThreadPool())); + // parent channel + bootstrap.setOption("reuseAddress", true); + // child channels + bootstrap.setOption("child.tcpNoDelay", true); + /* set socket linger to off, so that socket close does not block */ + bootstrap.setOption("child.soLinger", -1); + bootstrap.setPipelineFactory(new ChannelPipelineFactory() { + @Override + public ChannelPipeline getPipeline() throws Exception { + ChannelPipeline p = Channels.pipeline(); + if (secure) { + initSSL(p); + } + p.addLast("servercnxnfactory", channelHandler); + + return p; + } + }); + } + + private synchronized void initSSL(ChannelPipeline p) + throws X509Exception, KeyManagementException, NoSuchAlgorithmException { + String authProviderProp = System.getProperty(X509Util.SSL_AUTHPROVIDER); + SSLContext sslContext; + if (authProviderProp == null) { + sslContext = X509Util.createSSLContext(); + } else { + sslContext = SSLContext.getInstance("TLSv1"); + X509AuthenticationProvider authProvider = + (X509AuthenticationProvider) ProviderRegistry.getProvider( + System.getProperty(X509Util.SSL_AUTHPROVIDER, + "x509")); + + if (authProvider == null) { + LOG.error("Auth provider not found: {}", authProviderProp); + throw new SSLContextException( + "Could not create SSLContext with specified auth provider: " + + authProviderProp); + } + + sslContext.init(new X509KeyManager[]{authProvider.getKeyManager()}, + new X509TrustManager[]{authProvider.getTrustManager()}, + null); + } + + SSLEngine sslEngine = sslContext.createSSLEngine(); + sslEngine.setUseClientMode(false); + sslEngine.setNeedClientAuth(true); + + p.addLast("ssl", new SslHandler(sslEngine)); + LOG.info("SSL handler added for channel: {}", p.getChannel()); + } + + @Override + public void closeAll() { + if (LOG.isDebugEnabled()) { + LOG.debug("closeAll()"); + } + // clear all the connections on which we are selecting + int length = cnxns.size(); + for (ServerCnxn cnxn : cnxns) { + try { + // This will remove the cnxn from cnxns + cnxn.close(); + } catch (Exception e) { + LOG.warn("Ignoring exception closing cnxn sessionid 0x" + + Long.toHexString(cnxn.getSessionId()), e); + } + } + if (LOG.isDebugEnabled()) { + LOG.debug("allChannels size:" + allChannels.size() + " cnxns size:" + + length); + } + } + + @Override + public boolean closeSession(long sessionId) { + if (LOG.isDebugEnabled()) { + LOG.debug("closeSession sessionid:0x" + sessionId); + } + for (ServerCnxn cnxn : cnxns) { + if (cnxn.getSessionId() == sessionId) { + try { + cnxn.close(); + } catch (Exception e) { + LOG.warn("exception during session close", e); + } + return true; + } + } + return false; + } + + @Override + public void configure(InetSocketAddress addr, int maxClientCnxns, boolean secure) + throws IOException { + configureSaslLogin(); + localAddress = addr; + this.maxClientCnxns = maxClientCnxns; + this.secure = secure; + } + + /** {@inheritDoc} */ + public int getMaxClientCnxnsPerHost() { + return maxClientCnxns; + } + + /** {@inheritDoc} */ + public void setMaxClientCnxnsPerHost(int max) { + maxClientCnxns = max; + } + + @Override + public int getLocalPort() { + return localAddress.getPort(); + } + + @Override + public void join() throws InterruptedException { + synchronized (this) { + while (!killed) { + wait(); + } + } + } + + @Override + public void shutdown() { + LOG.info("shutdown called " + localAddress); + if (login != null) { + login.shutdown(); + } + // null if factory never started + if (parentChannel != null) { + parentChannel.close().awaitUninterruptibly(); + closeAll(); + allChannels.close().awaitUninterruptibly(); + bootstrap.releaseExternalResources(); + } + + if (zkServer != null) { + zkServer.shutdown(); + } + synchronized (this) { + killed = true; + notifyAll(); + } + } + + @Override + public void start() { + LOG.info("binding to port " + localAddress); + parentChannel = bootstrap.bind(localAddress); + } + + public void reconfigure(InetSocketAddress addr) { + Channel oldChannel = parentChannel; + LOG.info("binding to port " + addr); + parentChannel = bootstrap.bind(addr); + localAddress = addr; + oldChannel.close(); + } + + @Override + public void startup(ZooKeeperServer zks, boolean startServer) + throws IOException, InterruptedException { + start(); + setZooKeeperServer(zks); + if (startServer) { + zks.startdata(); + zks.startup(); + } + } + + @Override + public Iterable getConnections() { + return cnxns; + } + + @Override + public InetSocketAddress getLocalAddress() { + return localAddress; + } + + private void addCnxn(NettyServerCnxn cnxn) { + cnxns.add(cnxn); + synchronized (ipMap) { + InetAddress addr = + ((InetSocketAddress) cnxn.channel.getRemoteAddress()) + .getAddress(); + Set s = ipMap.get(addr); + if (s == null) { + s = new HashSet(); + } + s.add(cnxn); + ipMap.put(addr, s); + } + } + + @Override + public void resetAllConnectionStats() { + // No need to synchronize since cnxns is backed by a ConcurrentHashMap + for (ServerCnxn c : cnxns) { + c.resetStats(); + } + } + + @Override + public Iterable> getAllConnectionInfo(boolean brief) { + HashSet> info = new HashSet>(); + // No need to synchronize since cnxns is backed by a ConcurrentHashMap + for (ServerCnxn c : cnxns) { + info.add(c.getConnectionInfo(brief)); + } + return info; + } + + /** + * This is an inner class since we need to extend SimpleChannelHandler, but + * NettyServerCnxnFactory already extends ServerCnxnFactory. By making it inner + * this class gets access to the member variables and methods. + */ + @Sharable + class CnxnChannelHandler extends SimpleChannelHandler { + + @Override + public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) + throws Exception { + if (LOG.isTraceEnabled()) { + LOG.trace("Channel closed " + e); + } + allChannels.remove(ctx.getChannel()); + } + + @Override + public void channelConnected(ChannelHandlerContext ctx, + ChannelStateEvent e) throws Exception { + if (LOG.isTraceEnabled()) { + LOG.trace("Channel connected " + e); + } + + NettyServerCnxn cnxn = new NettyServerCnxn(ctx.getChannel(), + zkServer, NettyServerCnxnFactory.this); + ctx.setAttachment(cnxn); + + if (secure) { + SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class); + ChannelFuture handshakeFuture = sslHandler.handshake(); + handshakeFuture.addListener(new CertificateVerifier(sslHandler, cnxn)); + } else { + allChannels.add(ctx.getChannel()); + addCnxn(cnxn); + } + } + + @Override + public void channelDisconnected(ChannelHandlerContext ctx, + ChannelStateEvent e) throws Exception { + if (LOG.isTraceEnabled()) { + LOG.trace("Channel disconnected " + e); + } + NettyServerCnxn cnxn = (NettyServerCnxn) ctx.getAttachment(); + if (cnxn != null) { + if (LOG.isTraceEnabled()) { + LOG.trace("Channel disconnect caused close " + e); + } + cnxn.close(); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) + throws Exception { + LOG.warn("Exception caught " + e, e.getCause()); + NettyServerCnxn cnxn = (NettyServerCnxn) ctx.getAttachment(); + if (cnxn != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Closing " + cnxn); + cnxn.close(); + } + } + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) + throws Exception { + if (LOG.isTraceEnabled()) { + LOG.trace("message received called " + e.getMessage()); + } + try { + if (LOG.isDebugEnabled()) { + LOG.debug("New message " + e.toString() + + " from " + ctx.getChannel()); + } + NettyServerCnxn cnxn = (NettyServerCnxn) ctx.getAttachment(); + synchronized (cnxn) { + processMessage(e, cnxn); + } + } catch (Exception ex) { + LOG.error("Unexpected exception in receive", ex); + throw ex; + } + } + + private void processMessage(MessageEvent e, NettyServerCnxn cnxn) { + if (LOG.isDebugEnabled()) { + LOG.debug(Long.toHexString(cnxn.sessionId) + " queuedBuffer: " + + cnxn.queuedBuffer); + } + + if (e instanceof NettyServerCnxn.ResumeMessageEvent) { + LOG.debug("Received ResumeMessageEvent"); + if (cnxn.queuedBuffer != null) { + if (LOG.isTraceEnabled()) { + LOG.trace("processing queue " + + Long.toHexString(cnxn.sessionId) + + " queuedBuffer 0x" + + ChannelBuffers.hexDump(cnxn.queuedBuffer)); + } + cnxn.receiveMessage(cnxn.queuedBuffer); + if (!cnxn.queuedBuffer.readable()) { + LOG.debug("Processed queue - no bytes remaining"); + cnxn.queuedBuffer = null; + } else { + LOG.debug("Processed queue - bytes remaining"); + } + } else { + LOG.debug("queue empty"); + } + cnxn.channel.setReadable(true); + } else { + ChannelBuffer buf = (ChannelBuffer) e.getMessage(); + if (LOG.isTraceEnabled()) { + LOG.trace(Long.toHexString(cnxn.sessionId) + + " buf 0x" + + ChannelBuffers.hexDump(buf)); + } + + if (cnxn.throttled) { + LOG.debug("Received message while throttled"); + // we are throttled, so we need to queue + if (cnxn.queuedBuffer == null) { + LOG.debug("allocating queue"); + cnxn.queuedBuffer = dynamicBuffer(buf.readableBytes()); + } + cnxn.queuedBuffer.writeBytes(buf); + if (LOG.isTraceEnabled()) { + LOG.trace(Long.toHexString(cnxn.sessionId) + + " queuedBuffer 0x" + + ChannelBuffers.hexDump(cnxn.queuedBuffer)); + } + } else { + LOG.debug("not throttled"); + if (cnxn.queuedBuffer != null) { + if (LOG.isTraceEnabled()) { + LOG.trace(Long.toHexString(cnxn.sessionId) + + " queuedBuffer 0x" + + ChannelBuffers.hexDump(cnxn.queuedBuffer)); + } + cnxn.queuedBuffer.writeBytes(buf); + if (LOG.isTraceEnabled()) { + LOG.trace(Long.toHexString(cnxn.sessionId) + + " queuedBuffer 0x" + + ChannelBuffers.hexDump(cnxn.queuedBuffer)); + } + + cnxn.receiveMessage(cnxn.queuedBuffer); + if (!cnxn.queuedBuffer.readable()) { + LOG.debug("Processed queue - no bytes remaining"); + cnxn.queuedBuffer = null; + } else { + LOG.debug("Processed queue - bytes remaining"); + } + } else { + cnxn.receiveMessage(buf); + if (buf.readable()) { + if (LOG.isTraceEnabled()) { + LOG.trace("Before copy " + buf); + } + cnxn.queuedBuffer = dynamicBuffer(buf.readableBytes()); + cnxn.queuedBuffer.writeBytes(buf); + if (LOG.isTraceEnabled()) { + LOG.trace("Copy is " + cnxn.queuedBuffer); + LOG.trace(Long.toHexString(cnxn.sessionId) + + " queuedBuffer 0x" + + ChannelBuffers.hexDump(cnxn.queuedBuffer)); + } + } + } + } + } + } + + @Override + public void writeComplete(ChannelHandlerContext ctx, + WriteCompletionEvent e) throws Exception { + if (LOG.isTraceEnabled()) { + LOG.trace("write complete " + e); + } + } + + private final class CertificateVerifier + implements ChannelFutureListener { + private final SslHandler sslHandler; + private final NettyServerCnxn cnxn; + + CertificateVerifier(SslHandler sslHandler, NettyServerCnxn cnxn) { + this.sslHandler = sslHandler; + this.cnxn = cnxn; + } + + /** + * Only allow the connection to stay open if certificate passes auth + */ + public void operationComplete(ChannelFuture future) + throws SSLPeerUnverifiedException { + if (future.isSuccess()) { + LOG.debug("Successful handshake with session 0x{}", + Long.toHexString(cnxn.sessionId)); + SSLEngine eng = sslHandler.getEngine(); + SSLSession session = eng.getSession(); + cnxn.setClientCertificateChain(session.getPeerCertificates()); + + String authProviderProp + = System.getProperty(X509Util.SSL_AUTHPROVIDER, "x509"); + + X509AuthenticationProvider authProvider = + (X509AuthenticationProvider) + ProviderRegistry.getProvider(authProviderProp); + + if (authProvider == null) { + LOG.error("Auth provider not found: {}", authProviderProp); + cnxn.close(); + return; + } + + if (KeeperException.Code.OK != + authProvider.handleAuthentication(cnxn, null)) { + LOG.error("Authentication failed for session 0x{}", + Long.toHexString(cnxn.sessionId)); + cnxn.close(); + return; + } + + allChannels.add(future.getChannel()); + addCnxn(cnxn); + } else { + LOG.error("Unsuccessful handshake with session 0x{}", + Long.toHexString(cnxn.sessionId)); + cnxn.close(); + } + } + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/ObserverBean.java b/src/java/main/org/apache/zookeeper/server/ObserverBean.java new file mode 100644 index 00000000000..d8084042fca --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ObserverBean.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.server.quorum.Observer; +import org.apache.zookeeper.server.quorum.ObserverMXBean; + +/** + * ObserverBean + * + */ +public class ObserverBean extends ZooKeeperServerBean implements ObserverMXBean { + + private Observer observer; + + public ObserverBean(Observer observer, ZooKeeperServer zks) { + super(zks); + this.observer = observer; + } + + public String getName() { + return "Observer"; + } + + public int getPendingRevalidationCount() { + return this.observer.getPendingRevalidationsCount(); + } + + public String getQuorumAddress() { + return observer.getSocket().toString(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java new file mode 100644 index 00000000000..b053f4fe380 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java @@ -0,0 +1,960 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.BadArgumentsException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.MultiTransactionRecord; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.common.StringUtils; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.data.StatPersisted; +import org.apache.zookeeper.proto.CheckVersionRequest; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.proto.DeleteRequest; +import org.apache.zookeeper.proto.ReconfigRequest; +import org.apache.zookeeper.proto.SetACLRequest; +import org.apache.zookeeper.proto.SetDataRequest; +import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; +import org.apache.zookeeper.server.auth.AuthenticationProvider; +import org.apache.zookeeper.server.auth.ProviderRegistry; +import org.apache.zookeeper.server.quorum.Leader.XidRolloverException; +import org.apache.zookeeper.server.quorum.LeaderZooKeeperServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.apache.zookeeper.server.quorum.flexible.QuorumMaj; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.txn.CheckVersionTxn; +import org.apache.zookeeper.txn.CreateContainerTxn; +import org.apache.zookeeper.txn.CreateSessionTxn; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.DeleteTxn; +import org.apache.zookeeper.txn.ErrorTxn; +import org.apache.zookeeper.txn.MultiTxn; +import org.apache.zookeeper.txn.SetACLTxn; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.Txn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.StringReader; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * This request processor is generally at the start of a RequestProcessor + * change. It sets up any transactions associated with requests that change the + * state of the system. It counts on ZooKeeperServer to update + * outstandingRequests, so that it can take into account transactions that are + * in the queue to be applied when generating a transaction. + */ +public class PrepRequestProcessor extends ZooKeeperCriticalThread implements + RequestProcessor { + private static final Logger LOG = LoggerFactory.getLogger(PrepRequestProcessor.class); + + static boolean skipACL; + /** + * this is only for testing purposes. + * should never be useed otherwise + */ + private static boolean failCreate = false; + + static { + skipACL = System.getProperty("zookeeper.skipACL", "no").equals("yes"); + if (skipACL) { + LOG.info("zookeeper.skipACL==\"yes\", ACL checks will be skipped"); + } + } + + private final RequestProcessor nextProcessor; + LinkedBlockingQueue submittedRequests = new LinkedBlockingQueue(); + ZooKeeperServer zks; + + public PrepRequestProcessor(ZooKeeperServer zks, + RequestProcessor nextProcessor) { + super("ProcessThread(sid:" + zks.getServerId() + " cport:" + + zks.getClientPort() + "):", zks.getZooKeeperServerListener()); + this.nextProcessor = nextProcessor; + this.zks = zks; + } + + /** + * method for tests to set failCreate + * @param b + */ + public static void setFailCreate(boolean b) { + failCreate = b; + } + + /** + * Grant or deny authorization to an operation on a node as a function of: + * + * @param zks: not used. + * @param acl: set of ACLs for the node + * @param perm: the permission that the client is requesting + * @param ids: the credentials supplied by the client + */ + static void checkACL(ZooKeeperServer zks, List acl, int perm, + List ids) throws KeeperException.NoAuthException { + if (skipACL) { + return; + } + if (LOG.isDebugEnabled()) { + LOG.debug("Permission requested: {} ", perm); + LOG.debug("ACLs for node: {}", acl); + LOG.debug("Client credentials: {}", ids); + } + if (acl == null || acl.size() == 0) { + return; + } + for (Id authId : ids) { + if (authId.getScheme().equals("super")) { + return; + } + } + for (ACL a : acl) { + Id id = a.getId(); + if ((a.getPerms() & perm) != 0) { + if (id.getScheme().equals("world") + && id.getId().equals("anyone")) { + return; + } + AuthenticationProvider ap = ProviderRegistry.getProvider(id + .getScheme()); + if (ap != null) { + for (Id authId : ids) { + if (authId.getScheme().equals(id.getScheme()) + && ap.matches(authId.getId(), id.getId())) { + return; + } + } + } + } + } + throw new KeeperException.NoAuthException(); + } + + private static int checkAndIncVersion(int currentVersion, int expectedVersion, String path) + throws KeeperException.BadVersionException { + if (expectedVersion != -1 && expectedVersion != currentVersion) { + throw new KeeperException.BadVersionException(path); + } + return currentVersion + 1; + } + + @Override + public void run() { + try { + while (true) { + Request request = submittedRequests.take(); + long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; + if (request.type == OpCode.ping) { + traceMask = ZooTrace.CLIENT_PING_TRACE_MASK; + } + if (LOG.isTraceEnabled()) { + ZooTrace.logRequest(LOG, traceMask, 'P', request, ""); + } + if (Request.requestOfDeath == request) { + break; + } + pRequest(request); + } + } catch (RequestProcessorException e) { + if (e.getCause() instanceof XidRolloverException) { + LOG.info(e.getCause().getMessage()); + } + handleException(this.getName(), e); + } catch (Exception e) { + handleException(this.getName(), e); + } + LOG.info("PrepRequestProcessor exited loop!"); + } + + private ChangeRecord getRecordForPath(String path) throws KeeperException.NoNodeException { + ChangeRecord lastChange = null; + synchronized (zks.outstandingChanges) { + lastChange = zks.outstandingChangesForPath.get(path); + if (lastChange == null) { + DataNode n = zks.getZKDatabase().getNode(path); + if (n != null) { + Long acl; + Set children; + synchronized (n) { + acl = n.acl; + children = n.getChildren(); + } + lastChange = new ChangeRecord(-1, path, n.stat, + children != null ? children.size() : 0, + zks.getZKDatabase().convertLong(acl)); + } + } + } + if (lastChange == null || lastChange.stat == null) { + throw new KeeperException.NoNodeException(path); + } + return lastChange; + } + + private ChangeRecord getOutstandingChange(String path) { + synchronized (zks.outstandingChanges) { + return zks.outstandingChangesForPath.get(path); + } + } + + private void addChangeRecord(ChangeRecord c) { + synchronized (zks.outstandingChanges) { + zks.outstandingChanges.add(c); + zks.outstandingChangesForPath.put(c.path, c); + } + } + + /** + * Grab current pending change records for each op in a multi-op. + * + * This is used inside MultiOp error code path to rollback in the event + * of a failed multi-op. + * + * @param multiRequest + * @return a map that contains previously existed records that probably need to be + * rolled back in any failure. + */ + private Map getPendingChanges(MultiTransactionRecord multiRequest) { + HashMap pendingChangeRecords = new HashMap(); + + for (Op op : multiRequest) { + String path = op.getPath(); + ChangeRecord cr = getOutstandingChange(path); + // only previously existing records need to be rolled back. + if (cr != null) { + pendingChangeRecords.put(path, cr); + } + + /* + * ZOOKEEPER-1624 - We need to store for parent's ChangeRecord + * of the parent node of a request. So that if this is a + * sequential node creation request, rollbackPendingChanges() + * can restore previous parent's ChangeRecord correctly. + * + * Otherwise, sequential node name generation will be incorrect + * for a subsequent request. + */ + int lastSlash = path.lastIndexOf('/'); + if (lastSlash == -1 || path.indexOf('\0') != -1) { + continue; + } + String parentPath = path.substring(0, lastSlash); + ChangeRecord parentCr = getOutstandingChange(parentPath); + if (parentCr != null) { + pendingChangeRecords.put(parentPath, parentCr); + } + } + + return pendingChangeRecords; + } + + /** + * Rollback pending changes records from a failed multi-op. + * + * If a multi-op fails, we can't leave any invalid change records we created + * around. We also need to restore their prior value (if any) if their prior + * value is still valid. + * + * @param zxid + * @param pendingChangeRecords + */ + void rollbackPendingChanges(long zxid, Map pendingChangeRecords) { + synchronized (zks.outstandingChanges) { + // Grab a list iterator starting at the END of the list so we can iterate in reverse + ListIterator iter = zks.outstandingChanges.listIterator(zks.outstandingChanges.size()); + while (iter.hasPrevious()) { + ChangeRecord c = iter.previous(); + if (c.zxid == zxid) { + iter.remove(); + // Remove all outstanding changes for paths of this multi. + // Previous records will be added back later. + zks.outstandingChangesForPath.remove(c.path); + } else { + break; + } + } + + // we don't need to roll back any records because there is nothing left. + if (zks.outstandingChanges.isEmpty()) { + return; + } + + long firstZxid = zks.outstandingChanges.get(0).zxid; + + for (ChangeRecord c : pendingChangeRecords.values()) { + // Don't apply any prior change records less than firstZxid. + // Note that previous outstanding requests might have been removed + // once they are completed. + if (c.zxid < firstZxid) { + continue; + } + + // add previously existing records back. + zks.outstandingChangesForPath.put(c.path, c); + } + } + } + + /** + * Performs basic validation of a path for a create request. + * Throws if the path is not valid and returns the parent path. + * @throws BadArgumentsException + */ + private String validatePathForCreate(String path, long sessionId) + throws BadArgumentsException { + int lastSlash = path.lastIndexOf('/'); + if (lastSlash == -1 || path.indexOf('\0') != -1 || failCreate) { + LOG.info("Invalid path %s with session 0x%s", + path, Long.toHexString(sessionId)); + throw new KeeperException.BadArgumentsException(path); + } + return path.substring(0, lastSlash); + } + + /** + * This method will be called inside the ProcessRequestThread, which is a + * singleton, so there will be a single thread calling this code. + * + * @param type + * @param zxid + * @param request + * @param record + */ + protected void pRequest2Txn(int type, long zxid, Request request, + Record record, boolean deserialize) + throws KeeperException, IOException, RequestProcessorException { + request.setHdr(new TxnHeader(request.sessionId, request.cxid, zxid, + Time.currentWallTime(), type)); + + switch (type) { + case OpCode.create: + case OpCode.create2: + case OpCode.createContainer: { + CreateRequest createRequest = (CreateRequest) record; + if (deserialize) { + ByteBufferInputStream.byteBuffer2Record(request.request, createRequest); + } + CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); + validateCreateRequest(createMode, request); + String path = createRequest.getPath(); + String parentPath = validatePathForCreate(path, request.sessionId); + + List listACL = fixupACL(path, request.authInfo, createRequest.getAcl()); + ChangeRecord parentRecord = getRecordForPath(parentPath); + + checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE, request.authInfo); + int parentCVersion = parentRecord.stat.getCversion(); + if (createMode.isSequential()) { + path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion); + } + validatePath(path, request.sessionId); + try { + if (getRecordForPath(path) != null) { + throw new KeeperException.NodeExistsException(path); + } + } catch (KeeperException.NoNodeException e) { + // ignore this one + } + boolean ephemeralParent = (parentRecord.stat.getEphemeralOwner() != 0) && + (parentRecord.stat.getEphemeralOwner() != DataTree.CONTAINER_EPHEMERAL_OWNER); + if (ephemeralParent) { + throw new KeeperException.NoChildrenForEphemeralsException(path); + } + int newCversion = parentRecord.stat.getCversion() + 1; + if (type == OpCode.createContainer) { + request.setTxn(new CreateContainerTxn(path, createRequest.getData(), listACL, newCversion)); + } else { + request.setTxn(new CreateTxn(path, createRequest.getData(), listACL, createMode.isEphemeral(), + newCversion)); + } + StatPersisted s = new StatPersisted(); + if (createMode.isEphemeral()) { + s.setEphemeralOwner(request.sessionId); + } + parentRecord = parentRecord.duplicate(request.getHdr().getZxid()); + parentRecord.childCount++; + parentRecord.stat.setCversion(newCversion); + addChangeRecord(parentRecord); + addChangeRecord(new ChangeRecord(request.getHdr().getZxid(), path, s, 0, listACL)); + break; + } + case OpCode.deleteContainer: { + String path = new String(request.request.array()); + String parentPath = getParentPathAndValidate(path); + ChangeRecord parentRecord = getRecordForPath(parentPath); + ChangeRecord nodeRecord = getRecordForPath(path); + if (nodeRecord.childCount > 0) { + throw new KeeperException.NotEmptyException(path); + } + if (nodeRecord.stat.getEphemeralOwner() != DataTree.CONTAINER_EPHEMERAL_OWNER) { + throw new KeeperException.BadVersionException(path); + } + request.setTxn(new DeleteTxn(path)); + parentRecord = parentRecord.duplicate(request.getHdr().getZxid()); + parentRecord.childCount--; + addChangeRecord(parentRecord); + addChangeRecord(new ChangeRecord(request.getHdr().getZxid(), path, null, -1, null)); + break; + } + case OpCode.delete: + zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); + DeleteRequest deleteRequest = (DeleteRequest) record; + if (deserialize) + ByteBufferInputStream.byteBuffer2Record(request.request, deleteRequest); + String path = deleteRequest.getPath(); + String parentPath = getParentPathAndValidate(path); + ChangeRecord parentRecord = getRecordForPath(parentPath); + ChangeRecord nodeRecord = getRecordForPath(path); + checkACL(zks, parentRecord.acl, ZooDefs.Perms.DELETE, request.authInfo); + checkAndIncVersion(nodeRecord.stat.getVersion(), deleteRequest.getVersion(), path); + if (nodeRecord.childCount > 0) { + throw new KeeperException.NotEmptyException(path); + } + request.setTxn(new DeleteTxn(path)); + parentRecord = parentRecord.duplicate(request.getHdr().getZxid()); + parentRecord.childCount--; + addChangeRecord(parentRecord); + addChangeRecord(new ChangeRecord(request.getHdr().getZxid(), path, null, -1, null)); + break; + case OpCode.setData: + zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); + SetDataRequest setDataRequest = (SetDataRequest) record; + if (deserialize) + ByteBufferInputStream.byteBuffer2Record(request.request, setDataRequest); + path = setDataRequest.getPath(); + validatePath(path, request.sessionId); + nodeRecord = getRecordForPath(path); + checkACL(zks, nodeRecord.acl, ZooDefs.Perms.WRITE, request.authInfo); + int newVersion = checkAndIncVersion(nodeRecord.stat.getVersion(), setDataRequest.getVersion(), path); + request.setTxn(new SetDataTxn(path, setDataRequest.getData(), newVersion)); + nodeRecord = nodeRecord.duplicate(request.getHdr().getZxid()); + nodeRecord.stat.setVersion(newVersion); + addChangeRecord(nodeRecord); + break; + case OpCode.reconfig: + zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); + ReconfigRequest reconfigRequest = (ReconfigRequest) record; + LeaderZooKeeperServer lzks; + try { + lzks = (LeaderZooKeeperServer) zks; + } catch (ClassCastException e) { + // standalone mode - reconfiguration currently not supported + throw new KeeperException.UnimplementedException(); + } + QuorumVerifier lastSeenQV = lzks.self.getLastSeenQuorumVerifier(); + // check that there's no reconfig in progress + if (lastSeenQV.getVersion() != lzks.self.getQuorumVerifier().getVersion()) { + throw new KeeperException.ReconfigInProgress(); + } + long configId = reconfigRequest.getCurConfigId(); + + if (configId != -1 && configId != lzks.self.getLastSeenQuorumVerifier().getVersion()) { + String msg = "Reconfiguration from version " + configId + " failed -- last seen version is " + lzks.self.getLastSeenQuorumVerifier().getVersion(); + throw new KeeperException.BadVersionException(msg); + } + + String newMembers = reconfigRequest.getNewMembers(); + + if (newMembers != null) { //non-incremental membership change + LOG.info("Non-incremental reconfig"); + + // Input may be delimited by either commas or newlines so convert to common newline separated format + newMembers = newMembers.replaceAll(",", "\n"); + + try { + Properties props = new Properties(); + props.load(new StringReader(newMembers)); + request.qv = QuorumPeerConfig.parseDynamicConfig(props, lzks.self.getElectionType(), true, false); + request.qv.setVersion(request.getHdr().getZxid()); + } catch (IOException e) { + throw new KeeperException.BadArgumentsException(e.getMessage()); + } catch (ConfigException e) { + throw new KeeperException.BadArgumentsException(e.getMessage()); + } + } else { //incremental change - must be a majority quorum system + LOG.info("Incremental reconfig"); + + List joiningServers = null; + String joiningServersString = reconfigRequest.getJoiningServers(); + if (joiningServersString != null) { + joiningServers = StringUtils.split(joiningServersString, ","); + } + + List leavingServers = null; + String leavingServersString = reconfigRequest.getLeavingServers(); + if (leavingServersString != null) { + leavingServers = StringUtils.split(leavingServersString, ","); + } + + if (!(lastSeenQV instanceof QuorumMaj)) { + String msg = "Incremental reconfiguration requested but last configuration seen has a non-majority quorum system"; + LOG.warn(msg); + throw new KeeperException.BadArgumentsException(msg); + } + Map nextServers = new HashMap(lastSeenQV.getAllMembers()); + try { + if (leavingServers != null) { + for (String leaving : leavingServers) { + long sid = Long.parseLong(leaving); + nextServers.remove(sid); + } + } + if (joiningServers != null) { + for (String joiner : joiningServers) { + // joiner should have the following format: server.x = server_spec;client_spec + String[] parts = StringUtils.split(joiner, "=").toArray(new String[0]); + if (parts.length != 2) { + throw new KeeperException.BadArgumentsException("Wrong format of server string"); + } + // extract server id x from first part of joiner: server.x + Long sid = Long.parseLong(parts[0].substring(parts[0].lastIndexOf('.') + 1)); + QuorumServer qs = new QuorumServer(sid, parts[1]); + if (qs.clientAddr == null || qs.electionAddr == null || qs.addr == null) { + throw new KeeperException.BadArgumentsException("Wrong format of server string - each server should have 3 ports specified"); + } + + // check duplication of addresses and ports + for (QuorumServer nqs : nextServers.values()) { + if (qs.id == nqs.id) { + continue; + } + qs.checkAddressDuplicate(nqs); + } + + nextServers.remove(qs.id); + nextServers.put(Long.valueOf(qs.id), qs); + } + } + } catch (ConfigException e) { + throw new KeeperException.BadArgumentsException("Reconfiguration failed"); + } + request.qv = new QuorumMaj(nextServers); + request.qv.setVersion(request.getHdr().getZxid()); + } + if (QuorumPeerConfig.isStandaloneEnabled() && request.qv.getVotingMembers().size() < 2) { + String msg = "Reconfig failed - new configuration must include at least 2 followers"; + LOG.warn(msg); + throw new KeeperException.BadArgumentsException(msg); + } else if (request.qv.getVotingMembers().size() < 1) { + String msg = "Reconfig failed - new configuration must include at least 1 follower"; + LOG.warn(msg); + throw new KeeperException.BadArgumentsException(msg); + } + + if (!lzks.getLeader().isQuorumSynced(request.qv)) { + String msg2 = "Reconfig failed - there must be a connected and synced quorum in new configuration"; + LOG.warn(msg2); + throw new KeeperException.NewConfigNoQuorum(); + } + + nodeRecord = getRecordForPath(ZooDefs.CONFIG_NODE); + checkACL(zks, nodeRecord.acl, ZooDefs.Perms.WRITE, request.authInfo); + request.setTxn(new SetDataTxn(ZooDefs.CONFIG_NODE, request.qv.toString().getBytes(), -1)); + nodeRecord = nodeRecord.duplicate(request.getHdr().getZxid()); + nodeRecord.stat.setVersion(-1); + addChangeRecord(nodeRecord); + break; + case OpCode.setACL: + zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); + SetACLRequest setAclRequest = (SetACLRequest) record; + if (deserialize) + ByteBufferInputStream.byteBuffer2Record(request.request, setAclRequest); + path = setAclRequest.getPath(); + validatePath(path, request.sessionId); + List listACL = fixupACL(path, request.authInfo, setAclRequest.getAcl()); + nodeRecord = getRecordForPath(path); + checkACL(zks, nodeRecord.acl, ZooDefs.Perms.ADMIN, request.authInfo); + newVersion = checkAndIncVersion(nodeRecord.stat.getAversion(), setAclRequest.getVersion(), path); + request.setTxn(new SetACLTxn(path, listACL, newVersion)); + nodeRecord = nodeRecord.duplicate(request.getHdr().getZxid()); + nodeRecord.stat.setAversion(newVersion); + addChangeRecord(nodeRecord); + break; + case OpCode.createSession: + request.request.rewind(); + int to = request.request.getInt(); + request.setTxn(new CreateSessionTxn(to)); + request.request.rewind(); + if (request.isLocalSession()) { + // This will add to local session tracker if it is enabled + zks.sessionTracker.addSession(request.sessionId, to); + } else { + // Explicitly add to global session if the flag is not set + zks.sessionTracker.addGlobalSession(request.sessionId, to); + } + zks.setOwner(request.sessionId, request.getOwner()); + break; + case OpCode.closeSession: + // We don't want to do this check since the session expiration thread + // queues up this operation without being the session owner. + // this request is the last of the session so it should be ok + //zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); + Set es = zks.getZKDatabase() + .getEphemerals(request.sessionId); + synchronized (zks.outstandingChanges) { + for (ChangeRecord c : zks.outstandingChanges) { + if (c.stat == null) { + // Doing a delete + es.remove(c.path); + } else if (c.stat.getEphemeralOwner() == request.sessionId) { + es.add(c.path); + } + } + for (String path2Delete : es) { + addChangeRecord(new ChangeRecord(request.getHdr().getZxid(), path2Delete, null, 0, null)); + } + + zks.sessionTracker.setSessionClosing(request.sessionId); + } + + LOG.info("Processed session termination for sessionid: 0x" + + Long.toHexString(request.sessionId)); + break; + case OpCode.check: + zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); + CheckVersionRequest checkVersionRequest = (CheckVersionRequest) record; + if (deserialize) + ByteBufferInputStream.byteBuffer2Record(request.request, checkVersionRequest); + path = checkVersionRequest.getPath(); + validatePath(path, request.sessionId); + nodeRecord = getRecordForPath(path); + checkACL(zks, nodeRecord.acl, ZooDefs.Perms.READ, request.authInfo); + request.setTxn(new CheckVersionTxn(path, checkAndIncVersion(nodeRecord.stat.getVersion(), + checkVersionRequest.getVersion(), path))); + break; + default: + LOG.warn("unknown type " + type); + break; + } + } + + private void validatePath(String path, long sessionId) throws BadArgumentsException { + try { + PathUtils.validatePath(path); + } catch (IllegalArgumentException ie) { + LOG.info("Invalid path {} with session 0x{}, reason: {}", + path, Long.toHexString(sessionId), ie.getMessage()); + throw new BadArgumentsException(path); + } + } + + private String getParentPathAndValidate(String path) + throws BadArgumentsException { + int lastSlash = path.lastIndexOf('/'); + if (lastSlash == -1 || path.indexOf('\0') != -1 + || zks.getZKDatabase().isSpecialPath(path)) { + throw new BadArgumentsException(path); + } + return path.substring(0, lastSlash); + } + + /** + * This method will be called inside the ProcessRequestThread, which is a + * singleton, so there will be a single thread calling this code. + * + * @param request + */ + protected void pRequest(Request request) throws RequestProcessorException { + // LOG.info("Prep>>> cxid = " + request.cxid + " type = " + + // request.type + " id = 0x" + Long.toHexString(request.sessionId)); + request.setHdr(null); + request.setTxn(null); + + try { + switch (request.type) { + case OpCode.createContainer: + case OpCode.create: + case OpCode.create2: + CreateRequest create2Request = new CreateRequest(); + pRequest2Txn(request.type, zks.getNextZxid(), request, create2Request, true); + break; + case OpCode.deleteContainer: + case OpCode.delete: + DeleteRequest deleteRequest = new DeleteRequest(); + pRequest2Txn(request.type, zks.getNextZxid(), request, deleteRequest, true); + break; + case OpCode.setData: + SetDataRequest setDataRequest = new SetDataRequest(); + pRequest2Txn(request.type, zks.getNextZxid(), request, setDataRequest, true); + break; + case OpCode.reconfig: + ReconfigRequest reconfigRequest = new ReconfigRequest(); + ByteBufferInputStream.byteBuffer2Record(request.request, reconfigRequest); + pRequest2Txn(request.type, zks.getNextZxid(), request, reconfigRequest, true); + break; + case OpCode.setACL: + SetACLRequest setAclRequest = new SetACLRequest(); + pRequest2Txn(request.type, zks.getNextZxid(), request, setAclRequest, true); + break; + case OpCode.check: + CheckVersionRequest checkRequest = new CheckVersionRequest(); + pRequest2Txn(request.type, zks.getNextZxid(), request, checkRequest, true); + break; + case OpCode.multi: + MultiTransactionRecord multiRequest = new MultiTransactionRecord(); + try { + ByteBufferInputStream.byteBuffer2Record(request.request, multiRequest); + } catch (IOException e) { + request.setHdr(new TxnHeader(request.sessionId, request.cxid, zks.getNextZxid(), + Time.currentWallTime(), OpCode.multi)); + throw e; + } + List txns = new ArrayList(); + //Each op in a multi-op must have the same zxid! + long zxid = zks.getNextZxid(); + KeeperException ke = null; + + //Store off current pending change records in case we need to rollback + Map pendingChanges = getPendingChanges(multiRequest); + + for (Op op : multiRequest) { + Record subrequest = op.toRequestRecord(); + int type; + Record txn; + + /* If we've already failed one of the ops, don't bother + * trying the rest as we know it's going to fail and it + * would be confusing in the logfiles. + */ + if (ke != null) { + type = OpCode.error; + txn = new ErrorTxn(Code.RUNTIMEINCONSISTENCY.intValue()); + } + + /* Prep the request and convert to a Txn */ + else { + try { + pRequest2Txn(op.getType(), zxid, request, subrequest, false); + type = request.getHdr().getType(); + txn = request.getTxn(); + } catch (KeeperException e) { + ke = e; + type = OpCode.error; + txn = new ErrorTxn(e.code().intValue()); + + LOG.info("Got user-level KeeperException when processing " + + request.toString() + " aborting remaining multi ops." + + " Error Path:" + e.getPath() + + " Error:" + e.getMessage()); + + request.setException(e); + + /* Rollback change records from failed multi-op */ + rollbackPendingChanges(zxid, pendingChanges); + } + } + + //FIXME: I don't want to have to serialize it here and then + // immediately deserialize in next processor. But I'm + // not sure how else to get the txn stored into our list. + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + txn.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + + txns.add(new Txn(type, bb.array())); + } + + request.setHdr(new TxnHeader(request.sessionId, request.cxid, zxid, + Time.currentWallTime(), request.type)); + request.setTxn(new MultiTxn(txns)); + + break; + + //create/close session don't require request record + case OpCode.createSession: + case OpCode.closeSession: + if (!request.isLocalSession()) { + pRequest2Txn(request.type, zks.getNextZxid(), request, + null, true); + } + break; + + //All the rest don't need to create a Txn - just verify session + case OpCode.sync: + case OpCode.exists: + case OpCode.getData: + case OpCode.getACL: + case OpCode.getChildren: + case OpCode.getChildren2: + case OpCode.ping: + case OpCode.setWatches: + case OpCode.checkWatches: + case OpCode.removeWatches: + zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); + break; + default: + LOG.warn("unknown type " + request.type); + break; + } + } catch (KeeperException e) { + if (request.getHdr() != null) { + request.getHdr().setType(OpCode.error); + request.setTxn(new ErrorTxn(e.code().intValue())); + } + LOG.info("Got user-level KeeperException when processing " + + request.toString() + + " Error Path:" + e.getPath() + + " Error:" + e.getMessage()); + request.setException(e); + } catch (Exception e) { + // log at error level as we are returning a marshalling + // error to the user + LOG.error("Failed to process " + request, e); + + StringBuilder sb = new StringBuilder(); + ByteBuffer bb = request.request; + if (bb != null) { + bb.rewind(); + while (bb.hasRemaining()) { + sb.append(Integer.toHexString(bb.get() & 0xff)); + } + } else { + sb.append("request buffer is null"); + } + + LOG.error("Dumping request buffer: 0x" + sb.toString()); + if (request.getHdr() != null) { + request.getHdr().setType(OpCode.error); + request.setTxn(new ErrorTxn(Code.MARSHALLINGERROR.intValue())); + } + } + request.zxid = zks.getZxid(); + nextProcessor.processRequest(request); + } + + private List removeDuplicates(List acl) { + + ArrayList retval = new ArrayList(); + Iterator it = acl.iterator(); + while (it.hasNext()) { + ACL a = it.next(); + if (retval.contains(a) == false) { + retval.add(a); + } + } + return retval; + } + + private void validateCreateRequest(CreateMode createMode, Request request) + throws KeeperException { + if (createMode.isEphemeral()) { + // Exception is set when local session failed to upgrade + // so we just need to report the error + if (request.getException() != null) { + throw request.getException(); + } + zks.sessionTracker.checkGlobalSession(request.sessionId, + request.getOwner()); + } else { + zks.sessionTracker.checkSession(request.sessionId, + request.getOwner()); + } + } + + /** + * This method checks out the acl making sure it isn't null or empty, + * it has valid schemes and ids, and expanding any relative ids that + * depend on the requestor's authentication information. + * + * @param authInfo list of ACL IDs associated with the client connection + * @param acls list of ACLs being assigned to the node (create or setACL operation) + * @return verified and expanded ACLs + * @throws KeeperException.InvalidACLException + */ + private List fixupACL(String path, List authInfo, List acls) + throws KeeperException.InvalidACLException { + // check for well formed ACLs + // This resolves https://issues.apache.org/jira/browse/ZOOKEEPER-1877 + List uniqacls = removeDuplicates(acls); + LinkedList rv = new LinkedList(); + if (uniqacls == null || uniqacls.size() == 0) { + throw new KeeperException.InvalidACLException(path); + } + for (ACL a : uniqacls) { + LOG.debug("Processing ACL: {}", a); + if (a == null) { + throw new KeeperException.InvalidACLException(path); + } + Id id = a.getId(); + if (id == null || id.getScheme() == null) { + throw new KeeperException.InvalidACLException(path); + } + if (id.getScheme().equals("world") && id.getId().equals("anyone")) { + rv.add(a); + } else if (id.getScheme().equals("auth")) { + // This is the "auth" id, so we have to expand it to the + // authenticated ids of the requestor + boolean authIdValid = false; + for (Id cid : authInfo) { + AuthenticationProvider ap = + ProviderRegistry.getProvider(cid.getScheme()); + if (ap == null) { + LOG.error("Missing AuthenticationProvider for " + + cid.getScheme()); + } else if (ap.isAuthenticated()) { + authIdValid = true; + rv.add(new ACL(a.getPerms(), cid)); + } + } + if (!authIdValid) { + throw new KeeperException.InvalidACLException(path); + } + } else { + AuthenticationProvider ap = ProviderRegistry.getProvider(id.getScheme()); + if (ap == null || !ap.isValid(id.getId())) { + throw new KeeperException.InvalidACLException(path); + } + rv.add(a); + } + } + return rv; + } + + public void processRequest(Request request) { + submittedRequests.add(request); + } + + public void shutdown() { + LOG.info("Shutting down"); + submittedRequests.clear(); + submittedRequests.add(Request.requestOfDeath); + nextProcessor.shutdown(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/PurgeTxnLog.java b/src/java/main/org/apache/zookeeper/server/PurgeTxnLog.java new file mode 100644 index 00000000000..05cb69d45b5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/PurgeTxnLog.java @@ -0,0 +1,185 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.persistence.Util; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * this class is used to clean up the + * snapshot and data log dir's. This is usually + * run as a cronjob on the zookeeper server machine. + * Invocation of this class will clean up the datalogdir + * files and snapdir files keeping the last "-n" snapshot files + * and the corresponding logs. + */ +public class PurgeTxnLog { + + private static final String COUNT_ERR_MSG = "count should be greater than or equal to 3"; + private static final String PREFIX_SNAPSHOT = "snapshot"; + private static final String PREFIX_LOG = "log"; + + static void printUsage() { + System.out.println("Usage:"); + System.out.println("PurgeTxnLog dataLogDir [snapDir] -n count"); + System.out.println("\tdataLogDir -- path to the txn log directory"); + System.out.println("\tsnapDir -- path to the snapshot directory"); + System.out.println("\tcount -- the number of old snaps/logs you want " + + "to keep, value should be greater than or equal to 3"); + } + + /** + * Purges the snapshot and logs keeping the last num snapshots and the + * corresponding logs. If logs are rolling or a new snapshot is created + * during this process, these newest N snapshots or any data logs will be + * excluded from current purging cycle. + * + * @param dataDir the dir that has the logs + * @param snapDir the dir that has the snapshots + * @param num the number of snapshots to keep + * @throws IOException + */ + public static void purge(File dataDir, File snapDir, int num) throws IOException { + if (num < 3) { + throw new IllegalArgumentException(COUNT_ERR_MSG); + } + + FileTxnSnapLog txnLog = new FileTxnSnapLog(dataDir, snapDir); + + List snaps = txnLog.findNRecentSnapshots(num); + retainNRecentSnapshots(txnLog, snaps); + } + + // VisibleForTesting + static void retainNRecentSnapshots(FileTxnSnapLog txnLog, List snaps) { + // found any valid recent snapshots? + if (snaps.size() == 0) + return; + File snapShot = snaps.get(snaps.size() - 1); + final long leastZxidToBeRetain = Util.getZxidFromName( + snapShot.getName(), PREFIX_SNAPSHOT); + + class MyFileFilter implements FileFilter { + private final String prefix; + + MyFileFilter(String prefix) { + this.prefix = prefix; + } + + public boolean accept(File f) { + if (!f.getName().startsWith(prefix + ".")) + return false; + long fZxid = Util.getZxidFromName(f.getName(), prefix); + if (fZxid >= leastZxidToBeRetain) { + return false; + } + return true; + } + } + // add all non-excluded log files + List files = new ArrayList(Arrays.asList(txnLog + .getDataDir().listFiles(new MyFileFilter(PREFIX_LOG)))); + // add all non-excluded snapshot files to the deletion list + files.addAll(Arrays.asList(txnLog.getSnapDir().listFiles( + new MyFileFilter(PREFIX_SNAPSHOT)))); + // remove the old files + for (File f : files) { + System.out.println("Removing file: " + + DateFormat.getDateTimeInstance().format(f.lastModified()) + + "\t" + f.getPath()); + if (!f.delete()) { + System.err.println("Failed to remove " + f.getPath()); + } + } + + } + + /** + * @param args dataLogDir [snapDir] -n count + * dataLogDir -- path to the txn log directory + * snapDir -- path to the snapshot directory + * count -- the number of old snaps/logs you want to keep, value should be greater than or equal to 3
        + */ + public static void main(String[] args) throws IOException { + if (args.length < 3 || args.length > 4) { + printUsageThenExit(); + } + File dataDir = validateAndGetFile(args[0]); + File snapDir = dataDir; + int num = -1; + String countOption = ""; + if (args.length == 3) { + countOption = args[1]; + num = validateAndGetCount(args[2]); + } else { + snapDir = validateAndGetFile(args[1]); + countOption = args[2]; + num = validateAndGetCount(args[3]); + } + if (!"-n".equals(countOption)) { + printUsageThenExit(); + } + purge(dataDir, snapDir, num); + } + + /** + * validates file existence and returns the file + * + * @param path + * @return File + */ + private static File validateAndGetFile(String path) { + File file = new File(path); + if (!file.exists()) { + System.err.println("Path '" + file.getAbsolutePath() + + "' does not exist. "); + printUsageThenExit(); + } + return file; + } + + /** + * Returns integer if parsed successfully and it is valid otherwise prints + * error and usage and then exits + * + * @param number + * @return count + */ + private static int validateAndGetCount(String number) { + int result = 0; + try { + result = Integer.parseInt(number); + if (result < 3) { + System.err.println(COUNT_ERR_MSG); + printUsageThenExit(); + } + } catch (NumberFormatException e) { + System.err + .println("'" + number + "' can not be parsed to integer."); + printUsageThenExit(); + } + return result; + } + + private static void printUsageThenExit() { + printUsage(); + System.exit(1); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/RateLogger.java b/src/java/main/org/apache/zookeeper/server/RateLogger.java new file mode 100644 index 00000000000..67d4f01a0ad --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/RateLogger.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.common.Time; +import org.slf4j.Logger; + +public class RateLogger { + private final Logger LOG; + private String msg = null; + private long timestamp; + private int count = 0; + public RateLogger(Logger log) { + LOG = log; + } + + public void flush() { + if (msg != null) { + if (count > 1) { + LOG.warn("[" + count + " times] " + msg); + } else if (count == 1) { + LOG.warn(msg); + } + } + msg = null; + count = 0; + } + + public void rateLimitLog(String newMsg) { + long now = Time.currentElapsedTime(); + if (newMsg.equals(msg)) { + ++count; + if (now - timestamp >= 100) { + flush(); + msg = newMsg; + timestamp = now; + } + } else { + flush(); + msg = newMsg; + timestamp = now; + LOG.warn(msg); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/Request.java b/src/java/main/org/apache/zookeeper/server/Request.java new file mode 100644 index 00000000000..f5c925f3c84 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/Request.java @@ -0,0 +1,272 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 uuuuu Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "/RequuuAS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.Record; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.txn.TxnHeader; + +import java.nio.ByteBuffer; +import java.util.List; + +/** + * This is the structure that represents a request moving through a chain of + * RequestProcessors. There are various pieces of information that is tacked + * onto the request as it is processed. + */ +public class Request { + //停止整个正在运行的等待执行任务的线程 + public final static Request requestOfDeath = new Request(null, 0, 0, 0, null, null); + public final long sessionId; + public final int cxid; + public final int type; + public final ByteBuffer request; + public final ServerCnxn cnxn; + public final List authInfo; + public final long createTime = Time.currentElapsedTime(); + public long zxid = -1; + public QuorumVerifier qv = null; + private TxnHeader hdr; + private Record txn; + private Object owner; + private KeeperException e; + /** + * If this is a create or close request for a local-only session. + */ + private boolean isLocalSession = false; + + public Request(ServerCnxn cnxn, long sessionId, int xid, int type, ByteBuffer bb, List authInfo) { + this.cnxn = cnxn; + this.sessionId = sessionId; + this.cxid = xid; + this.type = type; + this.request = bb; + this.authInfo = authInfo; + } + + public Request(long sessionId, int xid, int type, TxnHeader hdr, Record txn, long zxid) { + this.sessionId = sessionId; + this.cxid = xid; + this.type = type; + this.hdr = hdr; + this.txn = txn; + this.zxid = zxid; + this.request = null; + this.cnxn = null; + this.authInfo = null; + } + + /** + * is the packet type a valid packet in zookeeper + * + * @param type + * the type of the packet + * @return true if a valid packet, false if not + */ + static boolean isValid(int type) { + // make sure this is always synchronized with Zoodefs!! + switch (type) { + case OpCode.notification: + return false; + case OpCode.check: + case OpCode.closeSession: + case OpCode.create: + case OpCode.create2: + case OpCode.createContainer: + case OpCode.createSession: + case OpCode.delete: + case OpCode.deleteContainer: + case OpCode.exists: + case OpCode.getACL: + case OpCode.getChildren: + case OpCode.getChildren2: + case OpCode.getData: + case OpCode.multi: + case OpCode.ping: + case OpCode.reconfig: + case OpCode.setACL: + case OpCode.setData: + case OpCode.setWatches: + case OpCode.sync: + case OpCode.checkWatches: + case OpCode.removeWatches: + return true; + default: + return false; + } + } + + static String op2String(int op) { + switch (op) { + case OpCode.notification: + return "notification"; + case OpCode.create: + return "create"; + case OpCode.create2: + return "create2"; + case OpCode.createContainer: + return "createContainer"; + case OpCode.setWatches: + return "setWatches"; + case OpCode.delete: + return "delete"; + case OpCode.deleteContainer: + return "deleteContainer"; + case OpCode.exists: + return "exists"; + case OpCode.getData: + return "getData"; + case OpCode.check: + return "check"; + case OpCode.multi: + return "multi"; + case OpCode.setData: + return "setData"; + case OpCode.sync: + return "sync:"; + case OpCode.getACL: + return "getACL"; + case OpCode.setACL: + return "setACL"; + case OpCode.getChildren: + return "getChildren"; + case OpCode.getChildren2: + return "getChildren2"; + case OpCode.ping: + return "ping"; + case OpCode.createSession: + return "createSession"; + case OpCode.closeSession: + return "closeSession"; + case OpCode.error: + return "error"; + case OpCode.reconfig: + return "reconfig"; + case OpCode.checkWatches: + return "checkWatches"; + case OpCode.removeWatches: + return "removeWatches"; + default: + return "unknown " + op; + } + } + + public boolean isLocalSession() { + return isLocalSession; + } + + public void setLocalSession(boolean isLocalSession) { + this.isLocalSession = isLocalSession; + } + + public Object getOwner() { + return owner; + } + + public void setOwner(Object owner) { + this.owner = owner; + } + + public TxnHeader getHdr() { + return hdr; + } + + public void setHdr(TxnHeader hdr) { + this.hdr = hdr; + } + + public Record getTxn() { + return txn; + } + + public void setTxn(Record txn) { + this.txn = txn; + } + + public boolean isQuorum() { + switch (this.type) { + case OpCode.exists: + case OpCode.getACL: + case OpCode.getChildren: + case OpCode.getChildren2: + case OpCode.getData: + return false; + case OpCode.create: + case OpCode.create2: + case OpCode.createContainer: + case OpCode.error: + case OpCode.delete: + case OpCode.deleteContainer: + case OpCode.setACL: + case OpCode.setData: + case OpCode.check: + case OpCode.multi: + case OpCode.reconfig: + return true; + case OpCode.closeSession: + case OpCode.createSession: + return !this.isLocalSession; + default: + return false; + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("sessionid:0x").append(Long.toHexString(sessionId)) + .append(" type:").append(op2String(type)) + .append(" cxid:0x").append(Long.toHexString(cxid)) + .append(" zxid:0x").append(Long.toHexString(hdr == null ? + -2 : hdr.getZxid())) + .append(" txntype:").append(hdr == null ? + "unknown" : "" + hdr.getType()); + + // best effort to print the path assoc with this request + String path = "n/a"; + if (type != OpCode.createSession + && type != OpCode.setWatches + && type != OpCode.closeSession + && request != null + && request.remaining() >= 4) { + try { + // make sure we don't mess with request itself + ByteBuffer rbuf = request.asReadOnlyBuffer(); + rbuf.clear(); + int pathLen = rbuf.getInt(); + // sanity check + if (pathLen >= 0 + && pathLen < 4096 + && rbuf.remaining() >= pathLen) { + byte b[] = new byte[pathLen]; + rbuf.get(b); + path = new String(b); + } + } catch (Exception e) { + // ignore - can't find the path, will output "n/a" instead + } + } + sb.append(" reqpath:").append(path); + + return sb.toString(); + } + + public KeeperException getException() { + return e; + } + + public void setException(KeeperException e) { + this.e = e; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/RequestProcessor.java b/src/java/main/org/apache/zookeeper/server/RequestProcessor.java new file mode 100644 index 00000000000..23ccc48b6b2 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/RequestProcessor.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +/** + * RequestProcessors are chained together to process transactions. Requests are + * always processed in order. The standalone server, follower, and leader all + * have slightly different RequestProcessors chained together. + * + * Requests always move forward through the chain of RequestProcessors. Requests + * are passed to a RequestProcessor through processRequest(). Generally method + * will always be invoked by a single thread. + * + * When shutdown is called, the request RequestProcessor should also shutdown + * any RequestProcessors that it is connected to. + */ +public interface RequestProcessor { + void processRequest(Request request) throws RequestProcessorException; + + void shutdown(); + + @SuppressWarnings("serial") + public static class RequestProcessorException extends Exception { + public RequestProcessorException(String msg, Throwable t) { + super(msg, t); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ServerCnxn.java b/src/java/main/org/apache/zookeeper/server/ServerCnxn.java new file mode 100644 index 00000000000..5ad076f7076 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ServerCnxn.java @@ -0,0 +1,361 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.Record; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.security.cert.Certificate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +/** + * Interface to a Server connection - represents a connection from a client + * to the server. + */ +public abstract class ServerCnxn implements Stats, Watcher { + // This is just an arbitrary object to represent requests issued by + // (aka owned by) this class + final public static Object me = new Object(); + private static final Logger LOG = LoggerFactory.getLogger(ServerCnxn.class); + protected final Date established = new Date(); + protected final AtomicLong packetsReceived = new AtomicLong(); + protected final AtomicLong packetsSent = new AtomicLong(); + protected ArrayList authInfo = new ArrayList(); + protected ZooKeeperSaslServer zooKeeperSaslServer = null; + protected long minLatency; + protected long maxLatency; + protected String lastOp; + protected long lastCxid; + protected long lastZxid; + protected long lastResponseTime; + protected long lastLatency; + protected long count; + protected long totalLatency; + /** + * If the client is of old version, we don't send r-o mode info to it. + * The reason is that if we would, old C client doesn't read it, which + * results in TCP RST packet, i.e. "connection reset by peer". + */ + boolean isOldClient = true; + + abstract int getSessionTimeout(); + + abstract void setSessionTimeout(int sessionTimeout); + + abstract void close(); + + public abstract void sendResponse(ReplyHeader h, Record r, String tag) + throws IOException; + + /* notify the client the session is closing and close/cleanup socket */ + abstract void sendCloseSession(); + + public abstract void process(WatchedEvent event); + + public abstract long getSessionId(); + + abstract void setSessionId(long sessionId); + + /** auth info for the cnxn, returns an unmodifyable list */ + public List getAuthInfo() { + return Collections.unmodifiableList(authInfo); + } + + public void addAuthInfo(Id id) { + if (authInfo.contains(id) == false) { + authInfo.add(id); + } + } + + public boolean removeAuthInfo(Id id) { + return authInfo.remove(id); + } + + abstract void sendBuffer(ByteBuffer closeConn); + + abstract void enableRecv(); + + abstract void disableRecv(); + + protected void packetReceived() { + incrPacketsReceived(); + ServerStats serverStats = serverStats(); + if (serverStats != null) { + serverStats().incrementPacketsReceived(); + } + } + + protected void packetSent() { + incrPacketsSent(); + ServerStats serverStats = serverStats(); + if (serverStats != null) { + serverStats().incrementPacketsSent(); + } + } + + protected abstract ServerStats serverStats(); + + public synchronized void resetStats() { + packetsReceived.set(0); + packetsSent.set(0); + minLatency = Long.MAX_VALUE; + maxLatency = 0; + lastOp = "NA"; + lastCxid = -1; + lastZxid = -1; + lastResponseTime = 0; + lastLatency = 0; + + count = 0; + totalLatency = 0; + } + + protected long incrPacketsReceived() { + return packetsReceived.incrementAndGet(); + } + + protected void incrOutstandingRequests(RequestHeader h) { + } + + protected long incrPacketsSent() { + return packetsSent.incrementAndGet(); + } + + protected synchronized void updateStatsForResponse(long cxid, long zxid, + String op, long start, long end) { + // don't overwrite with "special" xids - we're interested + // in the clients last real operation + if (cxid >= 0) { + lastCxid = cxid; + } + lastZxid = zxid; + lastOp = op; + lastResponseTime = end; + long elapsed = end - start; + lastLatency = elapsed; + if (elapsed < minLatency) { + minLatency = elapsed; + } + if (elapsed > maxLatency) { + maxLatency = elapsed; + } + count++; + totalLatency += elapsed; + } + + public Date getEstablished() { + return (Date) established.clone(); + } + + public abstract long getOutstandingRequests(); + + public long getPacketsReceived() { + return packetsReceived.longValue(); + } + + public long getPacketsSent() { + return packetsSent.longValue(); + } + + public synchronized long getMinLatency() { + return minLatency == Long.MAX_VALUE ? 0 : minLatency; + } + + public synchronized long getAvgLatency() { + return count == 0 ? 0 : totalLatency / count; + } + + public synchronized long getMaxLatency() { + return maxLatency; + } + + public synchronized String getLastOperation() { + return lastOp; + } + + public synchronized long getLastCxid() { + return lastCxid; + } + + public synchronized long getLastZxid() { + return lastZxid; + } + + public synchronized long getLastResponseTime() { + return lastResponseTime; + } + + public synchronized long getLastLatency() { + return lastLatency; + } + + /** + * Prints detailed stats information for the connection. + * + * @see dumpConnectionInfo(PrintWriter, boolean) for brief stats + */ + @Override + public String toString() { + StringWriter sw = new StringWriter(); + PrintWriter pwriter = new PrintWriter(sw); + dumpConnectionInfo(pwriter, false); + pwriter.flush(); + pwriter.close(); + return sw.toString(); + } + + public abstract InetSocketAddress getRemoteSocketAddress(); + + public abstract int getInterestOps(); + + public abstract boolean isSecure(); + + public abstract Certificate[] getClientCertificateChain(); + + public abstract void setClientCertificateChain(Certificate[] chain); + + /** + * Print information about the connection. + * @param brief iff true prints brief details, otw full detail + * @return information about this connection + */ + public synchronized void + dumpConnectionInfo(PrintWriter pwriter, boolean brief) { + pwriter.print(" "); + pwriter.print(getRemoteSocketAddress()); + pwriter.print("["); + int interestOps = getInterestOps(); + pwriter.print(interestOps == 0 ? "0" : Integer.toHexString(interestOps)); + pwriter.print("](queued="); + pwriter.print(getOutstandingRequests()); + pwriter.print(",recved="); + pwriter.print(getPacketsReceived()); + pwriter.print(",sent="); + pwriter.print(getPacketsSent()); + + if (!brief) { + long sessionId = getSessionId(); + if (sessionId != 0) { + pwriter.print(",sid=0x"); + pwriter.print(Long.toHexString(sessionId)); + pwriter.print(",lop="); + pwriter.print(getLastOperation()); + pwriter.print(",est="); + pwriter.print(getEstablished().getTime()); + pwriter.print(",to="); + pwriter.print(getSessionTimeout()); + long lastCxid = getLastCxid(); + if (lastCxid >= 0) { + pwriter.print(",lcxid=0x"); + pwriter.print(Long.toHexString(lastCxid)); + } + pwriter.print(",lzxid=0x"); + pwriter.print(Long.toHexString(getLastZxid())); + pwriter.print(",lresp="); + pwriter.print(getLastResponseTime()); + pwriter.print(",llat="); + pwriter.print(getLastLatency()); + pwriter.print(",minlat="); + pwriter.print(getMinLatency()); + pwriter.print(",avglat="); + pwriter.print(getAvgLatency()); + pwriter.print(",maxlat="); + pwriter.print(getMaxLatency()); + } + } + pwriter.print(")"); + } + + public synchronized Map getConnectionInfo(boolean brief) { + Map info = new LinkedHashMap(); + info.put("remote_socket_address", getRemoteSocketAddress()); + info.put("interest_ops", getInterestOps()); + info.put("outstanding_requests", getOutstandingRequests()); + info.put("packets_received", getPacketsReceived()); + info.put("packets_sent", getPacketsSent()); + if (!brief) { + info.put("session_id", getSessionId()); + info.put("last_operation", getLastOperation()); + info.put("established", getEstablished()); + info.put("session_timeout", getSessionTimeout()); + info.put("last_cxid", getLastCxid()); + info.put("last_zxid", getLastZxid()); + info.put("last_response_time", getLastResponseTime()); + info.put("last_latency", getLastLatency()); + info.put("min_latency", getMinLatency()); + info.put("avg_latency", getAvgLatency()); + info.put("max_latency", getMaxLatency()); + } + return info; + } + + /** + * clean up the socket related to a command and also make sure we flush the + * data before we do that + * + * @param pwriter + * the pwriter for a command socket + */ + public void cleanupWriterSocket(PrintWriter pwriter) { + try { + if (pwriter != null) { + pwriter.flush(); + pwriter.close(); + } + } catch (Exception e) { + LOG.info("Error closing PrintWriter ", e); + } finally { + try { + close(); + } catch (Exception e) { + LOG.error("Error closing a command socket ", e); + } + } + } + + protected static class CloseRequestException extends IOException { + private static final long serialVersionUID = -7854505709816442681L; + + public CloseRequestException(String msg) { + super(msg); + } + } + + protected static class EndOfStreamException extends IOException { + private static final long serialVersionUID = -8255690282104294178L; + + public EndOfStreamException(String msg) { + super(msg); + } + + public String toString() { + return "EndOfStreamException: " + getMessage(); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java b/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java new file mode 100644 index 00000000000..bbeb4e8b656 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java @@ -0,0 +1,230 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.Environment; +import org.apache.zookeeper.Login; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.server.auth.SaslServerCallbackHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import javax.management.JMException; +import javax.security.auth.login.AppConfigurationEntry; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.LoginException; + + +public abstract class ServerCnxnFactory { + + public static final String ZOOKEEPER_SERVER_CNXN_FACTORY = "zookeeper.serverCnxnFactory"; + /** + * The buffer will cause the connection to be close when we do a send. + */ + static final ByteBuffer closeConn = ByteBuffer.allocate(0); + private static final Logger LOG = LoggerFactory.getLogger(ServerCnxnFactory.class); + // Connection set is relied on heavily by four letter commands + // Construct a ConcurrentHashSet using a ConcurrentHashMap + protected final Set cnxns = Collections.newSetFromMap( + new ConcurrentHashMap()); + private final ConcurrentHashMap connectionBeans = + new ConcurrentHashMap(); + public Login login; + // Tells whether SSL is enabled on this ServerCnxnFactory + protected boolean secure; + protected SaslServerCallbackHandler saslServerCallbackHandler; + protected ZooKeeperServer zkServer; + + static public ServerCnxnFactory createFactory() throws IOException { + String serverCnxnFactoryName = + System.getProperty(ZOOKEEPER_SERVER_CNXN_FACTORY); + if (serverCnxnFactoryName == null) { + serverCnxnFactoryName = NIOServerCnxnFactory.class.getName(); + } + try { + return (ServerCnxnFactory) Class.forName(serverCnxnFactoryName) + .newInstance(); + } catch (Exception e) { + IOException ioe = new IOException("Couldn't instantiate " + + serverCnxnFactoryName); + ioe.initCause(e); + throw ioe; + } + } + + static public ServerCnxnFactory createFactory(int clientPort, + int maxClientCnxns) throws IOException { + return createFactory(new InetSocketAddress(clientPort), maxClientCnxns); + } + + static public ServerCnxnFactory createFactory(InetSocketAddress addr, + int maxClientCnxns) throws IOException { + ServerCnxnFactory factory = createFactory(); + factory.configure(addr, maxClientCnxns); + return factory; + } + + public abstract int getLocalPort(); + + public abstract Iterable getConnections(); + + public int getNumAliveConnections() { + return cnxns.size(); + } + + public ZooKeeperServer getZooKeeperServer() { + return zkServer; + } + + final public void setZooKeeperServer(ZooKeeperServer zks) { + this.zkServer = zks; + if (zks != null) { + if (secure) { + zks.setSecureServerCnxnFactory(this); + } else { + zks.setServerCnxnFactory(this); + } + } + } + + /** + * @return true if the cnxn that contains the sessionId exists in this ServerCnxnFactory + * and it's closed. Otherwise false. + */ + public abstract boolean closeSession(long sessionId); + + public void configure(InetSocketAddress addr, int maxcc) throws IOException { + configure(addr, maxcc, false); + } + + public abstract void configure(InetSocketAddress addr, int maxcc, boolean secure) + throws IOException; + + public abstract void reconfigure(InetSocketAddress addr); + + /** Maximum number of connections allowed from particular host (ip) */ + public abstract int getMaxClientCnxnsPerHost(); + + /** Maximum number of connections allowed from particular host (ip) */ + public abstract void setMaxClientCnxnsPerHost(int max); + + public boolean isSecure() { + return secure; + } + + public void startup(ZooKeeperServer zkServer) throws IOException, InterruptedException { + startup(zkServer, true); + } + + // This method is to maintain compatiblity of startup(zks) and enable sharing of zks + // when we add secureCnxnFactory. + public abstract void startup(ZooKeeperServer zkServer, boolean startServer) + throws IOException, InterruptedException; + + public abstract void join() throws InterruptedException; + + public abstract void shutdown(); + + public abstract void start(); + + public abstract void closeAll(); + + public abstract InetSocketAddress getLocalAddress(); + + public abstract void resetAllConnectionStats(); + + public abstract Iterable> getAllConnectionInfo(boolean brief); + + public void unregisterConnection(ServerCnxn serverCnxn) { + ConnectionBean jmxConnectionBean = connectionBeans.remove(serverCnxn); + if (jmxConnectionBean != null) { + MBeanRegistry.getInstance().unregister(jmxConnectionBean); + } + } + + public void registerConnection(ServerCnxn serverCnxn) { + if (zkServer != null) { + ConnectionBean jmxConnectionBean = new ConnectionBean(serverCnxn, zkServer); + try { + MBeanRegistry.getInstance().register(jmxConnectionBean, zkServer.jmxServerBean); + connectionBeans.put(serverCnxn, jmxConnectionBean); + } catch (JMException e) { + LOG.warn("Could not register connection", e); + } + } + + } + + /** + * Initialize the server SASL if specified. + * + * If the user has specified a "ZooKeeperServer.LOGIN_CONTEXT_NAME_KEY" + * or a jaas.conf using "java.security.auth.login.config" + * the authentication is required and an exception is raised. + * Otherwise no authentication is configured and no exception is raised. + * + * @throws IOException if jaas.conf is missing or there's an error in it. + */ + protected void configureSaslLogin() throws IOException { + String serverSection = System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY, + ZooKeeperSaslServer.DEFAULT_LOGIN_CONTEXT_NAME); + + // Note that 'Configuration' here refers to javax.security.auth.login.Configuration. + AppConfigurationEntry entries[] = null; + SecurityException securityException = null; + try { + entries = Configuration.getConfiguration().getAppConfigurationEntry(serverSection); + } catch (SecurityException e) { + // handle below: might be harmless if the user doesn't intend to use JAAS authentication. + securityException = e; + } + + // No entries in jaas.conf + // If there's a configuration exception fetching the jaas section and + // the user has required sasl by specifying a LOGIN_CONTEXT_NAME_KEY or a jaas file + // we throw an exception otherwise we continue without authentication. + if (entries == null) { + String jaasFile = System.getProperty(Environment.JAAS_CONF_KEY); + String loginContextName = System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY); + if (securityException != null && (loginContextName != null || jaasFile != null)) { + String errorMessage = "No JAAS configuration section named '" + serverSection + "' was found"; + if (jaasFile != null) { + errorMessage += "in '" + jaasFile + "'."; + } + if (loginContextName != null) { + errorMessage += " But " + ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY + " was set."; + } + LOG.error(errorMessage); + throw new IOException(errorMessage); + } + return; + } + + // jaas.conf entry available + try { + saslServerCallbackHandler = new SaslServerCallbackHandler(Configuration.getConfiguration()); + login = new Login(serverSection, saslServerCallbackHandler); + login.startThreadIfNeeded(); + } catch (LoginException e) { + throw new IOException("Could not configure server because SASL configuration did not allow the " + + " ZooKeeper server to authenticate itself properly: " + e); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ServerConfig.java b/src/java/main/org/apache/zookeeper/server/ServerConfig.java new file mode 100644 index 00000000000..e2a0cd8cfd8 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ServerConfig.java @@ -0,0 +1,129 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; + +import java.io.File; +import java.net.InetSocketAddress; +import java.util.Arrays; + +/** + * Server configuration storage. + * + * We use this instead of Properties as it's typed. + * + */ +public class ServerConfig { + //// + //// If you update the configuration parameters be sure + //// to update the "conf" 4letter word + //// + protected InetSocketAddress clientPortAddress; + protected InetSocketAddress secureClientPortAddress; + protected File dataDir; + protected File dataLogDir; + protected int tickTime = ZooKeeperServer.DEFAULT_TICK_TIME; + protected int maxClientCnxns; + /** defaults to -1 if not set explicitly */ + protected int minSessionTimeout = -1; + /** defaults to -1 if not set explicitly */ + protected int maxSessionTimeout = -1; + + /** + * Parse arguments for server configuration + * @param args clientPort dataDir and optional tickTime + * @return ServerConfig configured wrt arguments + * @throws IllegalArgumentException on invalid usage + */ + public void parse(String[] args) { + if (args.length < 2 || args.length > 4) { + throw new IllegalArgumentException("Invalid args:" + + Arrays.toString(args)); + } + + clientPortAddress = new InetSocketAddress(Integer.parseInt(args[0])); + dataDir = new File(args[1]); + dataLogDir = dataDir; + if (args.length == 3) { + tickTime = Integer.parseInt(args[2]); + } + if (args.length == 4) { + maxClientCnxns = Integer.parseInt(args[3]); + } + } + + /** + * Parse a ZooKeeper configuration file + * @param path the patch of the configuration file + * @return ServerConfig configured wrt arguments + * @throws ConfigException error processing configuration + */ + public void parse(String path) throws ConfigException { + QuorumPeerConfig config = new QuorumPeerConfig(); + config.parse(path); + + // let qpconfig parse the file and then pull the stuff we are + // interested in + readFrom(config); + } + + /** + * Read attributes from a QuorumPeerConfig. + * @param config + */ + public void readFrom(QuorumPeerConfig config) { + clientPortAddress = config.getClientPortAddress(); + secureClientPortAddress = config.getSecureClientPortAddress(); + dataDir = config.getDataDir(); + dataLogDir = config.getDataLogDir(); + tickTime = config.getTickTime(); + maxClientCnxns = config.getMaxClientCnxns(); + minSessionTimeout = config.getMinSessionTimeout(); + maxSessionTimeout = config.getMaxSessionTimeout(); + } + + public InetSocketAddress getClientPortAddress() { + return clientPortAddress; + } + + public InetSocketAddress getSecureClientPortAddress() { + return secureClientPortAddress; + } + + public File getDataDir() { + return dataDir; + } + + public File getDataLogDir() { + return dataLogDir; + } + + public int getTickTime() { + return tickTime; + } + + public int getMaxClientCnxns() { + return maxClientCnxns; + } + + /** minimum session timeout in milliseconds, -1 if unset */ + public int getMinSessionTimeout() { + return minSessionTimeout; + } + + /** maximum session timeout in milliseconds, -1 if unset */ + public int getMaxSessionTimeout() { + return maxSessionTimeout; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ServerStats.java b/src/java/main/org/apache/zookeeper/server/ServerStats.java new file mode 100644 index 00000000000..e395c239695 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ServerStats.java @@ -0,0 +1,159 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + + +import org.apache.zookeeper.common.Time; + +/** + * Basic Server Statistics + */ +public class ServerStats { + private final Provider provider; + private long packetsSent; + private long packetsReceived; + private long maxLatency; + private long minLatency = Long.MAX_VALUE; + private long totalLatency = 0; + private long count = 0; + + public ServerStats(Provider provider) { + this.provider = provider; + } + + // getters + synchronized public long getMinLatency() { + return minLatency == Long.MAX_VALUE ? 0 : minLatency; + } + + synchronized public long getAvgLatency() { + if (count != 0) { + return totalLatency / count; + } + return 0; + } + + synchronized public long getMaxLatency() { + return maxLatency; + } + + public long getOutstandingRequests() { + return provider.getOutstandingRequests(); + } + + public long getLastProcessedZxid() { + return provider.getLastProcessedZxid(); + } + + public long getDataDirSize() { + return provider.getDataDirSize(); + } + + public long getLogDirSize() { + return provider.getLogDirSize(); + } + + synchronized public long getPacketsReceived() { + return packetsReceived; + } + + synchronized public long getPacketsSent() { + return packetsSent; + } + + public String getServerState() { + return provider.getState(); + } + + /** The number of client connections alive to this server */ + public int getNumAliveClientConnections() { + return provider.getNumAliveConnections(); + } + + public boolean isProviderNull() { + return provider == null; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Latency min/avg/max: " + getMinLatency() + "/" + + getAvgLatency() + "/" + getMaxLatency() + "\n"); + sb.append("Received: " + getPacketsReceived() + "\n"); + sb.append("Sent: " + getPacketsSent() + "\n"); + sb.append("Connections: " + getNumAliveClientConnections() + "\n"); + + if (provider != null) { + sb.append("Outstanding: " + getOutstandingRequests() + "\n"); + sb.append("Zxid: 0x" + Long.toHexString(getLastProcessedZxid()) + "\n"); + } + sb.append("Mode: " + getServerState() + "\n"); + return sb.toString(); + } + + // mutators + synchronized void updateLatency(long requestCreateTime) { + long latency = Time.currentElapsedTime() - requestCreateTime; + totalLatency += latency; + count++; + if (latency < minLatency) { + minLatency = latency; + } + if (latency > maxLatency) { + maxLatency = latency; + } + } + + synchronized public void resetLatency() { + totalLatency = 0; + count = 0; + maxLatency = 0; + minLatency = Long.MAX_VALUE; + } + + synchronized public void resetMaxLatency() { + maxLatency = getMinLatency(); + } + + synchronized public void incrementPacketsReceived() { + packetsReceived++; + } + + synchronized public void incrementPacketsSent() { + packetsSent++; + } + + synchronized public void resetRequestCounters() { + packetsReceived = 0; + packetsSent = 0; + } + + synchronized public void reset() { + resetLatency(); + resetRequestCounters(); + } + + public interface Provider { + public long getOutstandingRequests(); + + public long getLastProcessedZxid(); + + public String getState(); + + public int getNumAliveConnections(); + + public long getDataDirSize(); + + public long getLogDirSize(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/SessionTracker.java b/src/java/main/org/apache/zookeeper/server/SessionTracker.java new file mode 100644 index 00000000000..de33e01e871 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/SessionTracker.java @@ -0,0 +1,130 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.SessionExpiredException; + +import java.io.PrintWriter; +import java.util.Map; +import java.util.Set; + +/** + * This is the basic interface that ZooKeeperServer uses to track sessions. The + * standalone and leader ZooKeeperServer use the same SessionTracker. The + * FollowerZooKeeperServer uses a SessionTracker which is basically a simple + * shell to track information to be forwarded to the leader. + */ +public interface SessionTracker { + long createSession(int sessionTimeout); + + /** + * Add a global session to those being tracked. + * @param id sessionId + * @param to sessionTimeout + * @return whether the session was newly added (if false, already existed) + */ + boolean addGlobalSession(long id, int to); + + /** + * Add a session to those being tracked. The session is added as a local + * session if they are enabled, otherwise as global. + * @param id sessionId + * @param to sessionTimeout + * @return whether the session was newly added (if false, already existed) + */ + boolean addSession(long id, int to); + + /** + * @param sessionId + * @param sessionTimeout + * @return false if session is no longer active + */ + boolean touchSession(long sessionId, int sessionTimeout); + + /** + * Mark that the session is in the process of closing. + * @param sessionId + */ + void setSessionClosing(long sessionId); + + /** + * + */ + void shutdown(); + + /** + * @param sessionId + */ + void removeSession(long sessionId); + + /** + * @param sessionId + * @return whether or not the SessionTracker is aware of this session + */ + boolean isTrackingSession(long sessionId); + + /** + * Checks whether the SessionTracker is aware of this session, the session + * is still active, and the owner matches. If the owner wasn't previously + * set, this sets the owner of the session. + * + * UnknownSessionException should never been thrown to the client. It is + * only used internally to deal with possible local session from other + * machine + * + * @param sessionId + * @param owner + */ + public void checkSession(long sessionId, Object owner) + throws KeeperException.SessionExpiredException, + KeeperException.SessionMovedException, + KeeperException.UnknownSessionException; + + /** + * Strictly check that a given session is a global session or not + * @param sessionId + * @param owner + * @throws KeeperException.SessionExpiredException + * @throws KeeperException.SessionMovedException + */ + public void checkGlobalSession(long sessionId, Object owner) + throws KeeperException.SessionExpiredException, + KeeperException.SessionMovedException; + + void setOwner(long id, Object owner) throws SessionExpiredException; + + /** + * Text dump of session information, suitable for debugging. + * @param pwriter the output writer + */ + void dumpSessions(PrintWriter pwriter); + + /** + * Returns a mapping of time to session IDs that expire at that time. + */ + Map> getSessionExpiryMap(); + + public static interface Session { + long getSessionId(); + + int getTimeout(); + + boolean isClosing(); + } + + public static interface SessionExpirer { + void expire(Session session); + + long getServerId(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java b/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java new file mode 100644 index 00000000000..3fb4dc99d6e --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java @@ -0,0 +1,323 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.common.Time; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.MessageFormat; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; + +/** + * This is a full featured SessionTracker. It tracks session in grouped by tick + * interval. It always rounds up the tick interval to provide a sort of grace + * period. Sessions are thus expired in batches made up of sessions that expire + * in a given interval. + */ +public class SessionTrackerImpl extends ZooKeeperCriticalThread implements + SessionTracker { + private static final Logger LOG = LoggerFactory.getLogger(SessionTrackerImpl.class); + + protected final ConcurrentHashMap sessionsById = + new ConcurrentHashMap(); + + private final ExpiryQueue sessionExpiryQueue; + + private final ConcurrentMap sessionsWithTimeout; + private final AtomicLong nextSessionId = new AtomicLong(); + private final SessionExpirer expirer; + volatile boolean running = true; + + public SessionTrackerImpl(SessionExpirer expirer, + ConcurrentMap sessionsWithTimeout, int tickTime, + long serverId, ZooKeeperServerListener listener) { + super("SessionTracker", listener); + this.expirer = expirer; + this.sessionExpiryQueue = new ExpiryQueue(tickTime); + this.sessionsWithTimeout = sessionsWithTimeout; + this.nextSessionId.set(initializeNextSession(serverId)); + for (Entry e : sessionsWithTimeout.entrySet()) { + addSession(e.getKey(), e.getValue()); + } + } + + /** + * Generates an initial sessionId. High order byte is serverId, next 5 + * 5 bytes are from timestamp, and low order 2 bytes are 0s. + */ + public static long initializeNextSession(long id) { + long nextSid; + nextSid = (Time.currentElapsedTime() << 24) >>> 8; + nextSid = nextSid | (id << 56); + return nextSid; + } + + public void dumpSessions(PrintWriter pwriter) { + pwriter.print("Session "); + sessionExpiryQueue.dump(pwriter); + } + + /** + * Returns a mapping from time to session IDs of sessions expiring at that time. + */ + synchronized public Map> getSessionExpiryMap() { + // Convert time -> sessions map to time -> session IDs map + Map> expiryMap = sessionExpiryQueue.getExpiryMap(); + Map> sessionExpiryMap = new TreeMap>(); + for (Entry> e : expiryMap.entrySet()) { + Set ids = new HashSet(); + sessionExpiryMap.put(e.getKey(), ids); + for (SessionImpl s : e.getValue()) { + ids.add(s.sessionId); + } + } + return sessionExpiryMap; + } + + @Override + public String toString() { + StringWriter sw = new StringWriter(); + PrintWriter pwriter = new PrintWriter(sw); + dumpSessions(pwriter); + pwriter.flush(); + pwriter.close(); + return sw.toString(); + } + + @Override + public void run() { + try { + while (running) { + long waitTime = sessionExpiryQueue.getWaitTime(); + if (waitTime > 0) { + Thread.sleep(waitTime); + continue; + } + + for (SessionImpl s : sessionExpiryQueue.poll()) { + setSessionClosing(s.sessionId); + expirer.expire(s); + } + } + } catch (InterruptedException e) { + handleException(this.getName(), e); + } + LOG.info("SessionTrackerImpl exited loop!"); + } + + synchronized public boolean touchSession(long sessionId, int timeout) { + SessionImpl s = sessionsById.get(sessionId); + + if (s == null) { + logTraceTouchInvalidSession(sessionId, timeout); + return false; + } + + if (s.isClosing()) { + logTraceTouchClosingSession(sessionId, timeout); + return false; + } + + updateSessionExpiry(s, timeout); + return true; + } + + private void updateSessionExpiry(SessionImpl s, int timeout) { + logTraceTouchSession(s.sessionId, timeout, ""); + sessionExpiryQueue.update(s, timeout); + } + + private void logTraceTouchSession(long sessionId, int timeout, String sessionStatus) { + if (!LOG.isTraceEnabled()) + return; + + String msg = MessageFormat.format( + "SessionTrackerImpl --- Touch {0}session: 0x{1} with timeout {2}", + sessionStatus, Long.toHexString(sessionId), Integer.toString(timeout)); + + ZooTrace.logTraceMessage(LOG, ZooTrace.CLIENT_PING_TRACE_MASK, msg); + } + + private void logTraceTouchInvalidSession(long sessionId, int timeout) { + logTraceTouchSession(sessionId, timeout, "invalid "); + } + + private void logTraceTouchClosingSession(long sessionId, int timeout) { + logTraceTouchSession(sessionId, timeout, "closing "); + } + + public int getSessionTimeout(long sessionId) { + return sessionsWithTimeout.get(sessionId); + } + + synchronized public void setSessionClosing(long sessionId) { + if (LOG.isTraceEnabled()) { + LOG.trace("Session closing: 0x" + Long.toHexString(sessionId)); + } + SessionImpl s = sessionsById.get(sessionId); + if (s == null) { + return; + } + s.isClosing = true; + } + + synchronized public void removeSession(long sessionId) { + LOG.debug("Removing session 0x" + Long.toHexString(sessionId)); + SessionImpl s = sessionsById.remove(sessionId); + sessionsWithTimeout.remove(sessionId); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, + "SessionTrackerImpl --- Removing session 0x" + + Long.toHexString(sessionId)); + } + if (s != null) { + sessionExpiryQueue.remove(s); + } + } + + public void shutdown() { + LOG.info("Shutting down"); + + running = false; + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.getTextTraceLevel(), + "Shutdown SessionTrackerImpl!"); + } + } + + public long createSession(int sessionTimeout) { + long sessionId = nextSessionId.getAndIncrement(); + addSession(sessionId, sessionTimeout); + return sessionId; + } + + public boolean addGlobalSession(long id, int sessionTimeout) { + return addSession(id, sessionTimeout); + } + + public synchronized boolean addSession(long id, int sessionTimeout) { + sessionsWithTimeout.put(id, sessionTimeout); + + boolean added = false; + + SessionImpl session = sessionsById.get(id); + if (session == null) { + session = new SessionImpl(id, sessionTimeout); + } + + // findbugs2.0.3 complains about get after put. + // long term strategy would be use computeIfAbsent after JDK 1.8 + SessionImpl existedSession = sessionsById.putIfAbsent(id, session); + + if (existedSession != null) { + session = existedSession; + } else { + added = true; + LOG.debug("Adding session 0x" + Long.toHexString(id)); + } + + if (LOG.isTraceEnabled()) { + String actionStr = added ? "Adding" : "Existing"; + ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, + "SessionTrackerImpl --- " + actionStr + " session 0x" + + Long.toHexString(id) + " " + sessionTimeout); + } + + updateSessionExpiry(session, sessionTimeout); + return added; + } + + public boolean isTrackingSession(long sessionId) { + return sessionsById.containsKey(sessionId); + } + + public synchronized void checkSession(long sessionId, Object owner) + throws KeeperException.SessionExpiredException, + KeeperException.SessionMovedException, + KeeperException.UnknownSessionException { + LOG.debug("Checking session 0x" + Long.toHexString(sessionId)); + SessionImpl session = sessionsById.get(sessionId); + + if (session == null) { + throw new KeeperException.UnknownSessionException(); + } + + if (session.isClosing()) { + throw new KeeperException.SessionExpiredException(); + } + + if (session.owner == null) { + session.owner = owner; + } else if (session.owner != owner) { + throw new KeeperException.SessionMovedException(); + } + } + + synchronized public void setOwner(long id, Object owner) throws SessionExpiredException { + SessionImpl session = sessionsById.get(id); + if (session == null || session.isClosing()) { + throw new KeeperException.SessionExpiredException(); + } + session.owner = owner; + } + + public void checkGlobalSession(long sessionId, Object owner) + throws KeeperException.SessionExpiredException, + KeeperException.SessionMovedException { + try { + checkSession(sessionId, owner); + } catch (KeeperException.UnknownSessionException e) { + throw new KeeperException.SessionExpiredException(); + } + } + + public static class SessionImpl implements Session { + final long sessionId; + final int timeout; + boolean isClosing; + Object owner; + + SessionImpl(long sessionId, int timeout) { + this.sessionId = sessionId; + this.timeout = timeout; + isClosing = false; + } + + public long getSessionId() { + return sessionId; + } + + public int getTimeout() { + return timeout; + } + + public boolean isClosing() { + return isClosing; + } + + public String toString() { + return "0x" + Long.toHexString(sessionId); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java b/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java new file mode 100644 index 00000000000..27a972f3442 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java @@ -0,0 +1,121 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.InputArchive; +import org.apache.zookeeper.data.StatPersisted; +import org.apache.zookeeper.server.persistence.FileSnap; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.zip.Adler32; +import java.util.zip.CheckedInputStream; + +/** + * Dump a snapshot file to stdout. + */ +public class SnapshotFormatter { + + /** + * USAGE: SnapshotFormatter snapshot_file + */ + public static void main(String[] args) throws Exception { + if (args.length != 1) { + System.err.println("USAGE: SnapshotFormatter snapshot_file"); + System.exit(2); + } + + new SnapshotFormatter().run(args[0]); + } + + public void run(String snapshotFileName) throws IOException { + InputStream is = new CheckedInputStream( + new BufferedInputStream(new FileInputStream(snapshotFileName)), + new Adler32()); + InputArchive ia = BinaryInputArchive.getArchive(is); + + FileSnap fileSnap = new FileSnap(null); + + DataTree dataTree = new DataTree(); + Map sessions = new HashMap(); + + fileSnap.deserialize(dataTree, sessions, ia); + + printDetails(dataTree, sessions); + } + + private void printDetails(DataTree dataTree, Map sessions) { + printZnodeDetails(dataTree); + printSessionDetails(dataTree, sessions); + } + + private void printZnodeDetails(DataTree dataTree) { + System.out.println(String.format("ZNode Details (count=%d):", + dataTree.getNodeCount())); + + printZnode(dataTree, "/"); + System.out.println("----"); + } + + private void printZnode(DataTree dataTree, String name) { + System.out.println("----"); + DataNode n = dataTree.getNode(name); + Set children; + synchronized (n) { // keep findbugs happy + System.out.println(name); + printStat(n.stat); + if (n.data != null) { + System.out.println(" dataLength = " + n.data.length); + } else { + System.out.println(" no data"); + } + children = n.getChildren(); + } + if (children != null) { + for (String child : children) { + printZnode(dataTree, name + (name.equals("/") ? "" : "/") + child); + } + } + } + + private void printSessionDetails(DataTree dataTree, Map sessions) { + System.out.println("Session Details (sid, timeout, ephemeralCount):"); + for (Map.Entry e : sessions.entrySet()) { + long sid = e.getKey(); + System.out.println(String.format("%#016x, %d, %d", + sid, e.getValue(), dataTree.getEphemerals(sid).size())); + } + } + + private void printStat(StatPersisted stat) { + printHex("cZxid", stat.getCzxid()); + System.out.println(" ctime = " + new Date(stat.getCtime()).toString()); + printHex("mZxid", stat.getMzxid()); + System.out.println(" mtime = " + new Date(stat.getMtime()).toString()); + printHex("pZxid", stat.getPzxid()); + System.out.println(" cversion = " + stat.getCversion()); + System.out.println(" dataVersion = " + stat.getVersion()); + System.out.println(" aclVersion = " + stat.getAversion()); + printHex("ephemeralOwner", stat.getEphemeralOwner()); + } + + private void printHex(String prefix, long value) { + System.out.println(String.format(" %s = %#016x", prefix, value)); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/Stats.java b/src/java/main/org/apache/zookeeper/server/Stats.java new file mode 100644 index 00000000000..e6f4390140f --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/Stats.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import java.util.Date; + +/** + * Statistics on the ServerCnxn + */ +interface Stats { + /** Date/time the connection was established + * @since 3.3.0 */ + Date getEstablished(); + + /** + * The number of requests that have been submitted but not yet + * responded to. + */ + long getOutstandingRequests(); + + /** Number of packets received */ + long getPacketsReceived(); + + /** Number of packets sent (incl notifications) */ + long getPacketsSent(); + + /** Min latency in ms + * @since 3.3.0 */ + long getMinLatency(); + + /** Average latency in ms + * @since 3.3.0 */ + long getAvgLatency(); + + /** Max latency in ms + * @since 3.3.0 */ + long getMaxLatency(); + + /** Last operation performed by this connection + * @since 3.3.0 */ + String getLastOperation(); + + /** Last cxid of this connection + * @since 3.3.0 */ + long getLastCxid(); + + /** Last zxid of this connection + * @since 3.3.0 */ + long getLastZxid(); + + /** Last time server sent a response to client on this connection + * @since 3.3.0 */ + long getLastResponseTime(); + + /** Latency of last response to client on this connection in ms + * @since 3.3.0 */ + long getLastLatency(); + + /** Reset counters + * @since 3.3.0 */ + void resetStats(); +} diff --git a/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java new file mode 100644 index 00000000000..ed99be248c5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java @@ -0,0 +1,198 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Flushable; +import java.io.IOException; +import java.util.LinkedList; +import java.util.Random; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * This RequestProcessor logs requests to disk. It batches the requests to do the io efficiently. The request is not passed to the next RequestProcessor until its log has been synced to disk. + * + * SyncRequestProcessor is used in 3 different cases 1. Leader - Sync request to disk and forward it to AckRequestProcessor which send ack back to itself. 2. Follower - Sync request to disk and + * forward request to SendAckRequestProcessor which send the packets to leader. SendAckRequestProcessor is flushable which allow us to force push packets to leader. 3. Observer - Sync committed + * request to disk (received as INFORM packet). It never send ack back to the leader, so the nextProcessor will be null. This change the semantic of txnlog on the observer since it only contains + * committed txns. + */ +public class SyncRequestProcessor extends ZooKeeperCriticalThread implements RequestProcessor { + private static final Logger LOG = LoggerFactory.getLogger(SyncRequestProcessor.class); + /** + * The number of log entries to log before starting a snapshot + */ + private static int snapCount = ZooKeeperServer.getSnapCount(); + private final ZooKeeperServer zks; + private final LinkedBlockingQueue queuedRequests = new LinkedBlockingQueue(); + private final RequestProcessor nextProcessor; + /** + * Transactions that have been written and are waiting to be flushed to disk. Basically this is the list of SyncItems whose callbacks will be invoked after flush returns successfully. + */ + private final LinkedList toFlush = new LinkedList(); + private final Random r = new Random(System.nanoTime()); + private final Request requestOfDeath = Request.requestOfDeath; + private Thread snapInProcess = null; + volatile private boolean running; + + public SyncRequestProcessor(ZooKeeperServer zks, + RequestProcessor nextProcessor) { + super("SyncThread:" + zks.getServerId(), zks + .getZooKeeperServerListener()); + this.zks = zks; + this.nextProcessor = nextProcessor; + running = true; + } + + /** + * used by tests to get the snapcount + * + * @return the snapcount + */ + public static int getSnapCount() { + return snapCount; + } + + /** + * used by tests to check for changing snapcounts + */ + public static void setSnapCount(int count) { + snapCount = count; + } + + @Override + public void run() { + try { + int logCount = 0; + // we do this in an attempt to ensure that not all of the servers + // in the ensemble take a snapshot at the same time + //防止同一时刻多个节点同时保存快照 + int randRoll = r.nextInt(snapCount / 2); + while (true) { + Request si = null; + if (toFlush.isEmpty()) { + si = queuedRequests.take(); + } else { + si = queuedRequests.poll(); + if (si == null) { + + flush(toFlush); + continue; + } + } + if (si == requestOfDeath) { + break; + } + if (si != null) { + // track the number of records written to the log + if (zks.getZKDatabase().append(si)) { + logCount++; + if (logCount > (snapCount / 2 + randRoll)) { + randRoll = r.nextInt(snapCount / 2); + // roll the log + zks.getZKDatabase().rollLog(); + // take a snapshot + if (snapInProcess != null && snapInProcess.isAlive()) { + LOG.warn("Too busy to snap, skipping"); + } else { + snapInProcess = new ZooKeeperThread("Snapshot Thread") { + public void run() { + try { + zks.takeSnapshot(); + } catch (Exception e) { + LOG.warn("Unexpected exception", e); + } + } + }; + snapInProcess.start(); + } + logCount = 0; + } + } else if (toFlush.isEmpty()) { + // optimization for read heavy workloads + // iff this is a read, and there are no pending + // flushes (writes), then just pass this to the next + // processor + if (nextProcessor != null) { + nextProcessor.processRequest(si); + if (nextProcessor instanceof Flushable) { + ((Flushable) nextProcessor).flush(); + } + } + continue; + } + toFlush.add(si); + if (toFlush.size() > 1000) { + flush(toFlush); + } + } + } + } catch (Throwable t) { + handleException(this.getName(), t); + } finally { + running = false; + } + LOG.info("SyncRequestProcessor exited!"); + } + + /** + * 1.将所有没有刷新到磁盘的数据刷新到磁盘。 + * 2.将所有缓存在和leader连接的数据刷新到socket中。 + * @param toFlush + * @throws IOException + * @throws RequestProcessorException + */ + private void flush(LinkedList toFlush) throws IOException, RequestProcessorException { + if (toFlush.isEmpty()) + return; + + zks.getZKDatabase().commit(); + while (!toFlush.isEmpty()) { + Request i = toFlush.remove(); + if (nextProcessor != null) { + nextProcessor.processRequest(i); + } + } + if (nextProcessor != null && nextProcessor instanceof Flushable) { + ((Flushable) nextProcessor).flush(); + } + } + + public void shutdown() { + LOG.info("Shutting down"); + queuedRequests.add(requestOfDeath); + try { + if (running) { + this.join(); + } + if (!toFlush.isEmpty()) { + flush(toFlush); + } + } catch (InterruptedException e) { + LOG.warn("Interrupted while wating for " + this + " to finish"); + } catch (IOException e) { + LOG.warn("Got IO exception during shutdown"); + } catch (RequestProcessorException e) { + LOG.warn("Got request processor exception during shutdown"); + } + if (nextProcessor != null) { + nextProcessor.shutdown(); + } + } + + public void processRequest(Request request) { + queuedRequests.add(request); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/TraceFormatter.java b/src/java/main/org/apache/zookeeper/server/TraceFormatter.java new file mode 100644 index 00000000000..f64519f3306 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/TraceFormatter.java @@ -0,0 +1,124 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZooDefs.OpCode; + +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.text.DateFormat; +import java.util.Date; + +public class TraceFormatter { + + public static String op2String(int op) { + switch (op) { + case OpCode.notification: + return "notification"; + case OpCode.create: + return "create"; + case OpCode.create2: + return "create2"; + case OpCode.createContainer: + return "createContainer"; + case OpCode.delete: + return "delete"; + case OpCode.deleteContainer: + return "deleteContainer"; + case OpCode.exists: + return "exists"; + case OpCode.getData: + return "getDate"; + case OpCode.setData: + return "setData"; + case OpCode.multi: + return "multi"; + case OpCode.getACL: + return "getACL"; + case OpCode.setACL: + return "setACL"; + case OpCode.getChildren: + return "getChildren"; + case OpCode.getChildren2: + return "getChildren2"; + case OpCode.ping: + return "ping"; + case OpCode.createSession: + return "createSession"; + case OpCode.closeSession: + return "closeSession"; + case OpCode.error: + return "error"; + case OpCode.reconfig: + return "reconfig"; + default: + return "unknown " + op; + } + } + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + if (args.length != 1) { + System.err.println("USAGE: TraceFormatter trace_file"); + System.exit(2); + } + FileChannel fc = new FileInputStream(args[0]).getChannel(); + while (true) { + ByteBuffer bb = ByteBuffer.allocate(41); + fc.read(bb); + bb.flip(); + + byte app = bb.get(); + long time = bb.getLong(); + long id = bb.getLong(); + int cxid = bb.getInt(); + long zxid = bb.getLong(); + int txnType = bb.getInt(); + int type = bb.getInt(); + int len = bb.getInt(); + bb = ByteBuffer.allocate(len); + fc.read(bb); + bb.flip(); + String path = "n/a"; + if (bb.remaining() > 0) { + if (type != OpCode.createSession) { + int pathLen = bb.getInt(); + byte b[] = new byte[pathLen]; + bb.get(b); + path = new String(b); + } + } + System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT, + DateFormat.LONG).format(new Date(time)) + + ": " + + (char) app + + " id=0x" + + Long.toHexString(id) + + " cxid=" + + cxid + + " op=" + + op2String(type) + + " zxid=0x" + + Long.toHexString(zxid) + + " txnType=" + + txnType + + " len=" + + len + " path=" + path); + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/TxnLogProposalIterator.java b/src/java/main/org/apache/zookeeper/server/TxnLogProposalIterator.java new file mode 100644 index 00000000000..c9c41c94a42 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/TxnLogProposalIterator.java @@ -0,0 +1,113 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; +import org.apache.zookeeper.server.quorum.Leader; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.server.quorum.QuorumPacket; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Iterator; + +/** + * This class provides an iterator interface to access Proposal deserialized + * from on-disk txnlog. The iterator deserializes one proposal at a time + * to reduce memory footprint. Note that the request part of the proposal + * is not initialized and set to null since we don't need it during + * follower sync-up. + * + */ +public class TxnLogProposalIterator implements Iterator { + public static final TxnLogProposalIterator EMPTY_ITERATOR = new TxnLogProposalIterator(); + private static final Logger LOG = LoggerFactory + .getLogger(TxnLogProposalIterator.class); + private boolean hasNext = false; + + private TxnIterator itr; + + private TxnLogProposalIterator() { + } + + public TxnLogProposalIterator(TxnIterator itr) { + if (itr != null) { + this.itr = itr; + hasNext = (itr.getHeader() != null); + } + } + + @Override + public boolean hasNext() { + return hasNext; + } + + /** + * Proposal returned by this iterator has request part set to null, since + * it is not used for follower sync-up. + */ + @Override + public Proposal next() { + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + Proposal p = new Proposal(); + try { + TxnHeader hdr = itr.getHeader(); + Record txn = itr.getTxn(); + hdr.serialize(boa, "hdr"); + if (txn != null) { + txn.serialize(boa, "txn"); + } + baos.close(); + + QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, itr.getHeader() + .getZxid(), baos.toByteArray(), null); + p.packet = pp; + p.request = null; + + // This is the only place that can throw IO exception + hasNext = itr.next(); + + } catch (IOException e) { + LOG.error("Unable to read txnlog from disk", e); + hasNext = false; + } + + return p; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + /** + * Close the files and release the resources which are used for iterating + * transaction records + */ + public void close() { + if (itr != null) { + try { + itr.close(); + } catch (IOException ioe) { + LOG.warn("Error closing file iterator", ioe); + } + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/UnimplementedRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/UnimplementedRequestProcessor.java new file mode 100644 index 00000000000..9472f9905bb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/UnimplementedRequestProcessor.java @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.proto.ReplyHeader; + +import java.io.IOException; + +/** + * Manages the unknown requests (i.e. unknown OpCode), by: + * - sending back the KeeperException.UnimplementedException() error code to the client + * - closing the connection. + */ +public class UnimplementedRequestProcessor implements RequestProcessor { + + public void processRequest(Request request) throws RequestProcessorException { + KeeperException ke = new KeeperException.UnimplementedException(); + request.setException(ke); + ReplyHeader rh = new ReplyHeader(request.cxid, request.zxid, ke.code().intValue()); + try { + request.cnxn.sendResponse(rh, null, "response"); + } catch (IOException e) { + throw new RequestProcessorException("Can't send the response", e); + } + + request.cnxn.sendCloseSession(); + } + + public void shutdown() { + } +} diff --git a/src/java/main/org/apache/zookeeper/server/WatchManager.java b/src/java/main/org/apache/zookeeper/server/WatchManager.java new file mode 100644 index 00000000000..42ca50b6984 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/WatchManager.java @@ -0,0 +1,258 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +/** + * This class manages watches. It allows watches to be associated with a string + * and removes watchers and their watches in addition to managing triggers. + */ +class WatchManager { + private static final Logger LOG = LoggerFactory.getLogger(WatchManager.class); + + private final HashMap> watchTable = + new HashMap>(); + + private final HashMap> watch2Paths = + new HashMap>(); + + synchronized int size() { + int result = 0; + for (Set watches : watchTable.values()) { + result += watches.size(); + } + return result; + } + + synchronized void addWatch(String path, Watcher watcher) { + HashSet list = watchTable.get(path); + if (list == null) { + // don't waste memory if there are few watches on a node + // rehash when the 4th entry is added, doubling size thereafter + // seems like a good compromise + list = new HashSet(4); + watchTable.put(path, list); + } + list.add(watcher); + + HashSet paths = watch2Paths.get(watcher); + if (paths == null) { + // cnxns typically have many watches, so use default cap here + paths = new HashSet(); + watch2Paths.put(watcher, paths); + } + paths.add(path); + } + + synchronized void removeWatcher(Watcher watcher) { + HashSet paths = watch2Paths.remove(watcher); + if (paths == null) { + return; + } + for (String p : paths) { + HashSet list = watchTable.get(p); + if (list != null) { + list.remove(watcher); + if (list.size() == 0) { + watchTable.remove(p); + } + } + } + } + + Set triggerWatch(String path, EventType type) { + return triggerWatch(path, type, null); + } + + Set triggerWatch(String path, EventType type, Set supress) { + WatchedEvent e = new WatchedEvent(type, + KeeperState.SyncConnected, path); + HashSet watchers; + synchronized (this) { + watchers = watchTable.remove(path); + if (watchers == null || watchers.isEmpty()) { + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, + ZooTrace.EVENT_DELIVERY_TRACE_MASK, + "No watchers for " + path); + } + return null; + } + for (Watcher w : watchers) { + HashSet paths = watch2Paths.get(w); + if (paths != null) { + paths.remove(path); + } + } + } + for (Watcher w : watchers) { + if (supress != null && supress.contains(w)) { + continue; + } + w.process(e); + } + return watchers; + } + + /** + * Brief description of this object. + */ + @Override + public synchronized String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append(watch2Paths.size()).append(" connections watching ") + .append(watchTable.size()).append(" paths\n"); + + int total = 0; + for (HashSet paths : watch2Paths.values()) { + total += paths.size(); + } + sb.append("Total watches:").append(total); + + return sb.toString(); + } + + /** + * String representation of watches. Warning, may be large! + * @param byPath iff true output watches by paths, otw output + * watches by connection + * @return string representation of watches + */ + synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) { + if (byPath) { + for (Entry> e : watchTable.entrySet()) { + pwriter.println(e.getKey()); + for (Watcher w : e.getValue()) { + pwriter.print("\t0x"); + pwriter.print(Long.toHexString(((ServerCnxn) w).getSessionId())); + pwriter.print("\n"); + } + } + } else { + for (Entry> e : watch2Paths.entrySet()) { + pwriter.print("0x"); + pwriter.println(Long.toHexString(((ServerCnxn) e.getKey()).getSessionId())); + for (String path : e.getValue()) { + pwriter.print("\t"); + pwriter.println(path); + } + } + } + } + + /** + * Checks the specified watcher exists for the given path + * + * @param path + * znode path + * @param watcher + * watcher object reference + * @return true if the watcher exists, false otherwise + */ + synchronized boolean containsWatcher(String path, Watcher watcher) { + HashSet paths = watch2Paths.get(watcher); + if (paths == null || !paths.contains(path)) { + return false; + } + return true; + } + + /** + * Removes the specified watcher for the given path + * + * @param path + * znode path + * @param watcher + * watcher object reference + * @return true if the watcher successfully removed, false otherwise + */ + synchronized boolean removeWatcher(String path, Watcher watcher) { + HashSet paths = watch2Paths.get(watcher); + if (paths == null || !paths.remove(path)) { + return false; + } + + HashSet list = watchTable.get(path); + if (list == null || !list.remove(watcher)) { + return false; + } + + if (list.size() == 0) { + watchTable.remove(path); + } + + return true; + } + + /** + * Returns a watch report. + * + * @return watch report + * @see WatchesReport + */ + synchronized WatchesReport getWatches() { + Map> id2paths = new HashMap>(); + for (Entry> e : watch2Paths.entrySet()) { + Long id = ((ServerCnxn) e.getKey()).getSessionId(); + HashSet paths = new HashSet(e.getValue()); + id2paths.put(id, paths); + } + return new WatchesReport(id2paths); + } + + /** + * Returns a watch report by path. + * + * @return watch report + * @see WatchesPathReport + */ + synchronized WatchesPathReport getWatchesByPath() { + Map> path2ids = new HashMap>(); + for (Entry> e : watchTable.entrySet()) { + Set ids = new HashSet(e.getValue().size()); + path2ids.put(e.getKey(), ids); + for (Watcher watcher : e.getValue()) { + ids.add(((ServerCnxn) watcher).getSessionId()); + } + } + return new WatchesPathReport(path2ids); + } + + /** + * Returns a watch summary. + * + * @return watch summary + * @see WatchesSummary + */ + synchronized WatchesSummary getWatchesSummary() { + int totalWatches = 0; + for (HashSet paths : watch2Paths.values()) { + totalWatches += paths.size(); + } + return new WatchesSummary(watch2Paths.size(), watchTable.size(), + totalWatches); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java b/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java new file mode 100644 index 00000000000..824c463ccc8 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/WatchesPathReport.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * A watch report, essentially a mapping of path to session IDs of sessions that have set a watch on that path. This class is immutable. + */ +public class WatchesPathReport { + + private final Map> path2Ids; + + /** + * Creates a new report. + * + * @param path2Ids map of paths to session IDs of sessions that have set a watch on that path + */ + WatchesPathReport(Map> path2Ids) { + this.path2Ids = Collections.unmodifiableMap(deepCopy(path2Ids)); + } + + private static Map> deepCopy(Map> m) { + Map> m2 = new HashMap>(); + for (Map.Entry> e : m.entrySet()) { + m2.put(e.getKey(), new HashSet(e.getValue())); + } + return m2; + } + + /** + * Checks if the given path has watches set. + * + * @param path path + * @return true if path has watch set + */ + public boolean hasSessions(String path) { + return path2Ids.containsKey(path); + } + + /** + * Gets the session IDs of sessions that have set watches on the given path. The returned set is immutable. + * + * @param path session ID + * @return session IDs of sessions that have set watches on the path, or null if none + */ + public Set getSessions(String path) { + Set s = path2Ids.get(path); + return s != null ? Collections.unmodifiableSet(s) : null; + } + + /** + * Converts this report to a map. The returned map is mutable, and changes to it do not reflect back into this report. + * + * @return map representation of report + */ + public Map> toMap() { + return deepCopy(path2Ids); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/WatchesReport.java b/src/java/main/org/apache/zookeeper/server/WatchesReport.java new file mode 100644 index 00000000000..d2c55c894dc --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/WatchesReport.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * A watch report, essentially a mapping of session ID to paths that the session has set a watch on. This class is immutable. + */ +public class WatchesReport { + + private final Map> id2paths; + + /** + * Creates a new report. + * + * @param id2paths map of session IDs to paths that each session has set a watch on + */ + WatchesReport(Map> id2paths) { + this.id2paths = Collections.unmodifiableMap(deepCopy(id2paths)); + } + + private static Map> deepCopy(Map> m) { + Map> m2 = new HashMap>(); + for (Map.Entry> e : m.entrySet()) { + m2.put(e.getKey(), new HashSet(e.getValue())); + } + return m2; + } + + /** + * Checks if the given session has watches set. + * + * @param sessionId session ID + * @return true if session has paths with watches set + */ + public boolean hasPaths(long sessionId) { + return id2paths.containsKey(sessionId); + } + + /** + * Gets the paths that the given session has set watches on. The returned set is immutable. + * + * @param sessionId session ID + * @return paths that have watches set by the session, or null if none + */ + public Set getPaths(long sessionId) { + Set s = id2paths.get(sessionId); + return s != null ? Collections.unmodifiableSet(s) : null; + } + + /** + * Converts this report to a map. The returned map is mutable, and changes to it do not reflect back into this report. + * + * @return map representation of report + */ + public Map> toMap() { + return deepCopy(id2paths); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/WatchesSummary.java b/src/java/main/org/apache/zookeeper/server/WatchesSummary.java new file mode 100644 index 00000000000..8e8e1c71d21 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/WatchesSummary.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A summary of watch information. This class is immutable. + */ +public class WatchesSummary { + + /** + * The key in the map returned by {@link #toMap()} for the number of connections. + */ + public static final String KEY_NUM_CONNECTIONS = "num_connections"; + /** + * The key in the map returned by {@link #toMap()} for the number of paths. + */ + public static final String KEY_NUM_PATHS = "num_paths"; + /** + * The key in the map returned by {@link #toMap()} for the total number of watches. + */ + public static final String KEY_NUM_TOTAL_WATCHES = "num_total_watches"; + + private final int numConnections; + private final int numPaths; + private final int totalWatches; + + /** + * Creates a new summary. + * + * @param numConnections the number of sessions that have set watches + * @param numPaths the number of paths that have watches set on them + * @param totalWatches the total number of watches set + */ + WatchesSummary(int numConnections, int numPaths, int totalWatches) { + this.numConnections = numConnections; + this.numPaths = numPaths; + this.totalWatches = totalWatches; + } + + /** + * Gets the number of connections (sessions) that have set watches. + * + * @return number of connections + */ + public int getNumConnections() { + return numConnections; + } + + /** + * Gets the number of paths that have watches set on them. + * + * @return number of paths + */ + public int getNumPaths() { + return numPaths; + } + + /** + * Gets the total number of watches set. + * + * @return total watches + */ + public int getTotalWatches() { + return totalWatches; + } + + /** + * Converts this summary to a map. The returned map is mutable, and changes to it do not reflect back into this summary. + * + * @return map representation of summary + */ + public Map toMap() { + Map summary = new LinkedHashMap(); + summary.put(KEY_NUM_CONNECTIONS, numConnections); + summary.put(KEY_NUM_PATHS, numPaths); + summary.put(KEY_NUM_TOTAL_WATCHES, totalWatches); + return summary; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/WorkerService.java b/src/java/main/org/apache/zookeeper/server/WorkerService.java new file mode 100644 index 00000000000..96a5e3d8c90 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/WorkerService.java @@ -0,0 +1,243 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.common.Time; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * WorkerService is a worker thread pool for running tasks and is implemented + * using one or more ExecutorServices. A WorkerService can support assignable + * threads, which it does by creating N separate single thread ExecutorServices, + * or non-assignable threads, which it does by creating a single N-thread + * ExecutorService. + * - NIOServerCnxnFactory uses a non-assignable WorkerService because the + * socket IO requests are order independent and allowing the + * ExecutorService to handle thread assignment gives optimal performance. + * - CommitProcessor uses an assignable WorkerService because requests for + * a given session must be processed in order. + * ExecutorService provides queue management and thread restarting, so it's + * useful even with a single thread. + */ +public class WorkerService { + private static final Logger LOG = + LoggerFactory.getLogger(WorkerService.class); + + private final ArrayList workers = + new ArrayList(); + + private final String threadNamePrefix; + private int numWorkerThreads; + private boolean threadsAreAssignable; + private long shutdownTimeoutMS = 5000; + + private volatile boolean stopped = true; + + /** + * @param name worker threads are named Thread-## + * @param numThreads number of worker threads (0 - N) + * If 0, scheduled work is run immediately by + * the calling thread. + * @param useAssignableThreads whether the worker threads should be + * individually assignable or not + */ + public WorkerService(String name, int numThreads, + boolean useAssignableThreads) { + this.threadNamePrefix = (name == null ? "" : name) + "Thread"; + this.numWorkerThreads = numThreads; + this.threadsAreAssignable = useAssignableThreads; + start(); + } + + /** + * Schedule work to be done. If a worker thread pool is not being + * used, work is done directly by this thread. This schedule API is + * for use with non-assignable WorkerServices. For assignable + * WorkerServices, will always run on the first thread. + */ + public void schedule(WorkRequest workRequest) { + schedule(workRequest, 0); + } + + /** + * Schedule work to be done by the thread assigned to this id. Thread + * assignment is a single mod operation on the number of threads. If a + * worker thread pool is not being used, work is done directly by + * this thread. + */ + public void schedule(WorkRequest workRequest, long id) { + if (stopped) { + workRequest.cleanup(); + return; + } + + ScheduledWorkRequest scheduledWorkRequest = + new ScheduledWorkRequest(workRequest); + + // If we have a worker thread pool, use that; otherwise, do the work + // directly. + int size = workers.size(); + if (size > 0) { + try { + // make sure to map negative ids as well to [0, size-1] + int workerNum = ((int) (id % size) + size) % size; + ExecutorService worker = workers.get(workerNum); + worker.execute(scheduledWorkRequest); + } catch (RejectedExecutionException e) { + LOG.warn("ExecutorService rejected execution", e); + workRequest.cleanup(); + } + } else { + // When there is no worker thread pool, do the work directly + // and wait for its completion + scheduledWorkRequest.start(); + try { + scheduledWorkRequest.join(); + } catch (InterruptedException e) { + LOG.warn("Unexpected exception", e); + Thread.currentThread().interrupt(); + } + } + } + + public void start() { + if (numWorkerThreads > 0) { + if (threadsAreAssignable) { + for (int i = 1; i <= numWorkerThreads; ++i) { + workers.add(Executors.newFixedThreadPool( + 1, new DaemonThreadFactory(threadNamePrefix, i))); + } + } else { + workers.add(Executors.newFixedThreadPool( + numWorkerThreads, new DaemonThreadFactory(threadNamePrefix))); + } + } + stopped = false; + } + + public void stop() { + stopped = true; + + // Signal for graceful shutdown + for (ExecutorService worker : workers) { + worker.shutdown(); + } + } + + public void join(long shutdownTimeoutMS) { + // Give the worker threads time to finish executing + long now = Time.currentElapsedTime(); + long endTime = now + shutdownTimeoutMS; + for (ExecutorService worker : workers) { + boolean terminated = false; + while ((now = Time.currentElapsedTime()) <= endTime) { + try { + terminated = worker.awaitTermination( + endTime - now, TimeUnit.MILLISECONDS); + break; + } catch (InterruptedException e) { + // ignore + } + } + if (!terminated) { + // If we've timed out, do a hard shutdown + worker.shutdownNow(); + } + } + } + + /** + * Callers should implement a class extending WorkRequest in order to + * schedule work with the service. + */ + public static abstract class WorkRequest { + /** + * Must be implemented. Is called when the work request is run. + */ + public abstract void doWork() throws Exception; + + /** + * (Optional) If implemented, is called if the service is stopped + * or unable to schedule the request. + */ + public void cleanup() { + } + } + + /** + * ThreadFactory for the worker thread pool. We don't use the default + * thread factory because (1) we want to give the worker threads easier + * to identify names; and (2) we want to make the worker threads daemon + * threads so they don't block the server from shutting down. + */ + private static class DaemonThreadFactory implements ThreadFactory { + final ThreadGroup group; + final AtomicInteger threadNumber = new AtomicInteger(1); + final String namePrefix; + + DaemonThreadFactory(String name) { + this(name, 1); + } + + DaemonThreadFactory(String name, int firstThreadNum) { + threadNumber.set(firstThreadNum); + SecurityManager s = System.getSecurityManager(); + group = (s != null) ? s.getThreadGroup() : + Thread.currentThread().getThreadGroup(); + namePrefix = name + "-"; + } + + public Thread newThread(Runnable r) { + Thread t = new Thread(group, r, + namePrefix + threadNumber.getAndIncrement(), + 0); + if (!t.isDaemon()) + t.setDaemon(true); + if (t.getPriority() != Thread.NORM_PRIORITY) + t.setPriority(Thread.NORM_PRIORITY); + return t; + } + } + + private class ScheduledWorkRequest extends ZooKeeperThread { + private final WorkRequest workRequest; + + ScheduledWorkRequest(WorkRequest workRequest) { + super("ScheduledWorkRequest"); + this.workRequest = workRequest; + } + + @Override + public void run() { + try { + // Check if stopped while request was on queue + if (stopped) { + workRequest.cleanup(); + return; + } + workRequest.doWork(); + } catch (Exception e) { + LOG.warn("Unexpected exception", e); + workRequest.cleanup(); + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ZKDatabase.java b/src/java/main/org/apache/zookeeper/server/ZKDatabase.java new file mode 100644 index 00000000000..ea4934c5fe6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZKDatabase.java @@ -0,0 +1,614 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.DataTree.ProcessTxnResult; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog.PlayBackListener; +import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; +import org.apache.zookeeper.server.quorum.Leader; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.server.quorum.QuorumPacket; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; +import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; + +/** + * This class maintains the in memory database of zookeeper + * server states that includes the sessions, datatree and the + * committed logs. It is booted up after reading the logs + * and snapshots from the disk. + */ +public class ZKDatabase { + + /** + * Default value is to use snapshot if txnlog size exceeds 1/3 the size of snapshot + */ + public static final String SNAPSHOT_SIZE_FACTOR = "zookeeper.snapshotSizeFactor"; + public static final int commitLogCount = 500; + private static final Logger LOG = LoggerFactory.getLogger(ZKDatabase.class); + protected static int commitLogBuffer = 700; + /** + * make sure on a clear you take care of + * all these members. + */ + protected DataTree dataTree; + protected ConcurrentHashMap sessionsWithTimeouts; + protected FileTxnSnapLog snapLog; + protected long minCommittedLog, maxCommittedLog; + protected LinkedList committedLog = new LinkedList(); + protected ReentrantReadWriteLock logLock = new ReentrantReadWriteLock(); + private double snapshotSizeFactor = 0.33; + volatile private boolean initialized = false; + + /** + * the filetxnsnaplog that this zk database + * maps to. There is a one to one relationship + * between a filetxnsnaplog and zkdatabase. + * @param snapLog the FileTxnSnapLog mapping this zkdatabase + */ + public ZKDatabase(FileTxnSnapLog snapLog) { + dataTree = new DataTree(); + sessionsWithTimeouts = new ConcurrentHashMap(); + this.snapLog = snapLog; + } + + /** + * checks to see if the zk database has been + * initialized or not. + * @return true if zk database is initialized and false if not + */ + public boolean isInitialized() { + return initialized; + } + + /** + * clear the zkdatabase. + * Note to developers - be careful to see that + * the clear method does clear out all the + * data structures in zkdatabase. + */ + public void clear() { + minCommittedLog = 0; + maxCommittedLog = 0; + /* to be safe we just create a new + * datatree. + */ + dataTree = new DataTree(); + sessionsWithTimeouts.clear(); + WriteLock lock = logLock.writeLock(); + try { + lock.lock(); + committedLog.clear(); + } finally { + lock.unlock(); + } + initialized = false; + } + + /** + * the datatree for this zkdatabase + * @return the datatree for this zkdatabase + */ + public DataTree getDataTree() { + return this.dataTree; + } + + /** + * the committed log for this zk database + * @return the committed log for this zkdatabase + */ + public long getmaxCommittedLog() { + return maxCommittedLog; + } + + + /** + * the minimum committed transaction log + * available in memory + * @return the minimum committed transaction + * log available in memory + */ + public long getminCommittedLog() { + return minCommittedLog; + } + + /** + * Get the lock that controls the committedLog. If you want to get the pointer to the committedLog, you need + * to use this lock to acquire a read lock before calling getCommittedLog() + * @return the lock that controls the committed log + */ + public ReentrantReadWriteLock getLogLock() { + return logLock; + } + + + public synchronized List getCommittedLog() { + ReadLock rl = logLock.readLock(); + // only make a copy if this thread isn't already holding a lock + if (logLock.getReadHoldCount() <= 0) { + try { + rl.lock(); + return new LinkedList(this.committedLog); + } finally { + rl.unlock(); + } + } + return this.committedLog; + } + + /** + * get the last processed zxid from a datatree + * @return the last processed zxid of a datatree + */ + public long getDataTreeLastProcessedZxid() { + return dataTree.lastProcessedZxid; + } + + /** + * return the sessions in the datatree + * @return the data tree sessions + */ + public Collection getSessions() { + return dataTree.getSessions(); + } + + /** + * get sessions with timeouts + * @return the hashmap of sessions with timeouts + */ + public ConcurrentHashMap getSessionWithTimeOuts() { + return sessionsWithTimeouts; + } + + + /** + * load the database from the disk onto memory and also add + * the transactions to the committedlog in memory. + * @return the last valid zxid on disk + * @throws IOException + */ + public long loadDataBase() throws IOException { + PlayBackListener listener = new PlayBackListener() { + public void onTxnLoaded(TxnHeader hdr, Record txn) { + Request r = new Request(0, hdr.getCxid(), hdr.getType(), hdr, txn, hdr.getZxid()); + addCommittedProposal(r); + } + }; + + long zxid = snapLog.restore(dataTree, sessionsWithTimeouts, listener); + initialized = true; + return zxid; + } + + /** + * maintains a list of last committedLog + * or so committed requests. This is used for + * fast follower synchronization. + * @param request committed request + */ + public void addCommittedProposal(Request request) { + WriteLock wl = logLock.writeLock(); + try { + wl.lock(); + if (committedLog.size() > commitLogCount) { + committedLog.removeFirst(); + minCommittedLog = committedLog.getFirst().packet.getZxid(); + } + if (committedLog.isEmpty()) { + minCommittedLog = request.zxid; + maxCommittedLog = request.zxid; + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + try { + request.getHdr().serialize(boa, "hdr"); + if (request.getTxn() != null) { + request.getTxn().serialize(boa, "txn"); + } + baos.close(); + } catch (IOException e) { + LOG.error("This really should be impossible", e); + } + QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid, + baos.toByteArray(), null); + Proposal p = new Proposal(); + p.packet = pp; + p.request = request; + committedLog.add(p); + maxCommittedLog = p.packet.getZxid(); + } finally { + wl.unlock(); + } + } + + public double getSnapshotSizeFactor() { + return snapshotSizeFactor; + } + + /** + * Use for unit testing, so we can turn this feature on/off + * @param snapshotSizeFactor Set to minus value to turn this off. + */ + public void setSnapshotSizeFactor(double snapshotSizeFactor) { + this.snapshotSizeFactor = snapshotSizeFactor; + } + + public long calculateTxnLogSizeLimit() { + long snapSize = 0; + try { + snapSize = snapLog.findMostRecentSnapshot().length(); + } catch (IOException e) { + LOG.error("Unable to get size of most recent snapshot"); + } + return (long) (snapSize * snapshotSizeFactor); + } + + /** + * Get proposals from txnlog. Only packet part of proposal is populated. + * + * @param startZxid the starting zxid of the proposal + * @param sizeLimit maximum on-disk size of txnlog to fetch + * 0 is unlimited, negative value means disable. + * @return list of proposal (request part of each proposal is null) + */ + public Iterator getProposalsFromTxnLog(long startZxid, + long sizeLimit) { + if (sizeLimit < 0) { + LOG.debug("Negative size limit - retrieving proposal via txnlog is disabled"); + return TxnLogProposalIterator.EMPTY_ITERATOR; + } + + TxnIterator itr = null; + try { + + itr = snapLog.readTxnLog(startZxid, false); + + // If we cannot guarantee that this is strictly the starting txn + // after a given zxid, we should fail. + if ((itr.getHeader() != null) + && (itr.getHeader().getZxid() > startZxid)) { + LOG.warn("Unable to find proposals from txnlog for zxid: " + + startZxid); + itr.close(); + return TxnLogProposalIterator.EMPTY_ITERATOR; + } + + if (sizeLimit > 0) { + long txnSize = itr.getStorageSize(); + if (txnSize > sizeLimit) { + LOG.info("Txnlog size: " + txnSize + " exceeds sizeLimit: " + + sizeLimit); + itr.close(); + return TxnLogProposalIterator.EMPTY_ITERATOR; + } + } + } catch (IOException e) { + LOG.error("Unable to read txnlog from disk", e); + try { + if (itr != null) { + itr.close(); + } + } catch (IOException ioe) { + LOG.warn("Error closing file iterator", ioe); + } + return TxnLogProposalIterator.EMPTY_ITERATOR; + } + return new TxnLogProposalIterator(itr); + } + + /** + * remove a cnxn from the datatree + * @param cnxn the cnxn to remove from the datatree + */ + public void removeCnxn(ServerCnxn cnxn) { + dataTree.removeCnxn(cnxn); + } + + /** + * kill a given session in the datatree + * @param sessionId the session id to be killed + * @param zxid the zxid of kill session transaction + */ + public void killSession(long sessionId, long zxid) { + dataTree.killSession(sessionId, zxid); + } + + /** + * write a text dump of all the ephemerals in the datatree + * @param pwriter the output to write to + */ + public void dumpEphemerals(PrintWriter pwriter) { + dataTree.dumpEphemerals(pwriter); + } + + public Map> getEphemerals() { + return dataTree.getEphemerals(); + } + + /** + * the node count of the datatree + * @return the node count of datatree + */ + public int getNodeCount() { + return dataTree.getNodeCount(); + } + + /** + * the paths for ephemeral session id + * @param sessionId the session id for which paths match to + * @return the paths for a session id + */ + public Set getEphemerals(long sessionId) { + return dataTree.getEphemerals(sessionId); + } + + /** + * the last processed zxid in the datatree + * @param zxid the last processed zxid in the datatree + */ + public void setlastProcessedZxid(long zxid) { + dataTree.lastProcessedZxid = zxid; + } + + /** + * the process txn on the data + * @param hdr the txnheader for the txn + * @param txn the transaction that needs to be processed + * @return the result of processing the transaction on this + * datatree/zkdatabase + */ + public ProcessTxnResult processTxn(TxnHeader hdr, Record txn) { + return dataTree.processTxn(hdr, txn); + } + + /** + * stat the path + * @param path the path for which stat is to be done + * @param serverCnxn the servercnxn attached to this request + * @return the stat of this node + * @throws KeeperException.NoNodeException + */ + public Stat statNode(String path, ServerCnxn serverCnxn) throws KeeperException.NoNodeException { + return dataTree.statNode(path, serverCnxn); + } + + /** + * get the datanode for this path + * @param path the path to lookup + * @return the datanode for getting the path + */ + public DataNode getNode(String path) { + return dataTree.getNode(path); + } + + /** + * convert from long to the acl entry + * @param aclL the long for which to get the acl + * @return the acl corresponding to this long entry + */ + public List convertLong(Long aclL) { + return dataTree.convertLong(aclL); + } + + /** + * get data and stat for a path + * @param path the path being queried + * @param stat the stat for this path + * @param watcher the watcher function + * @return + * @throws KeeperException.NoNodeException + */ + public byte[] getData(String path, Stat stat, Watcher watcher) + throws KeeperException.NoNodeException { + return dataTree.getData(path, stat, watcher); + } + + /** + * set watches on the datatree + * @param relativeZxid the relative zxid that client has seen + * @param dataWatches the data watches the client wants to reset + * @param existWatches the exists watches the client wants to reset + * @param childWatches the child watches the client wants to reset + * @param watcher the watcher function + */ + public void setWatches(long relativeZxid, List dataWatches, + List existWatches, List childWatches, Watcher watcher) { + dataTree.setWatches(relativeZxid, dataWatches, existWatches, childWatches, watcher); + } + + /** + * get acl for a path + * @param path the path to query for acl + * @param stat the stat for the node + * @return the acl list for this path + * @throws NoNodeException + */ + public List getACL(String path, Stat stat) throws NoNodeException { + return dataTree.getACL(path, stat); + } + + /** + * get children list for this path + * @param path the path of the node + * @param stat the stat of the node + * @param watcher the watcher function for this path + * @return the list of children for this path + * @throws KeeperException.NoNodeException + */ + public List getChildren(String path, Stat stat, Watcher watcher) + throws KeeperException.NoNodeException { + return dataTree.getChildren(path, stat, watcher); + } + + /** + * check if the path is special or not + * @param path the input path + * @return true if path is special and false if not + */ + public boolean isSpecialPath(String path) { + return dataTree.isSpecialPath(path); + } + + /** + * get the acl size of the datatree + * @return the acl size of the datatree + */ + public int getAclSize() { + return dataTree.getAclSize(); + } + + /** + * Truncate the ZKDatabase to the specified zxid + * @param zxid the zxid to truncate zk database to + * @return true if the truncate is successful and false if not + * @throws IOException + */ + public boolean truncateLog(long zxid) throws IOException { + clear(); + + // truncate the log + boolean truncated = snapLog.truncateLog(zxid); + + if (!truncated) { + return false; + } + + loadDataBase(); + return true; + } + + /** + * deserialize a snapshot from an input archive + * @param ia the input archive you want to deserialize from + * @throws IOException + */ + public void deserializeSnapshot(InputArchive ia) throws IOException { + clear(); + SerializeUtils.deserializeSnapshot(getDataTree(), ia, getSessionWithTimeOuts()); + initialized = true; + } + + /** + * serialize the snapshot + * @param oa the output archive to which the snapshot needs to be serialized + * @throws IOException + * @throws InterruptedException + */ + public void serializeSnapshot(OutputArchive oa) throws IOException, + InterruptedException { + SerializeUtils.serializeSnapshot(getDataTree(), oa, getSessionWithTimeOuts()); + } + + /** + * append to the underlying transaction log + * @param si the request to append + * @return true if the append was succesfull and false if not + */ + public boolean append(Request si) throws IOException { + return this.snapLog.append(si); + } + + /** + * roll the underlying log + */ + public void rollLog() throws IOException { + this.snapLog.rollLog(); + } + + /** + * commit to the underlying transaction log + * @throws IOException + */ + public void commit() throws IOException { + this.snapLog.commit(); + } + + /** + * close this database. free the resources + * @throws IOException + */ + public void close() throws IOException { + this.snapLog.close(); + } + + public synchronized void initConfigInZKDatabase(QuorumVerifier qv) { + if (qv == null) return; // only happens during tests + try { + if (this.dataTree.getNode(ZooDefs.CONFIG_NODE) == null) { + // should only happen during upgrade + LOG.warn("configuration znode missing (hould only happen during upgrade), creating the node"); + this.dataTree.addConfigNode(); + } + this.dataTree.setData(ZooDefs.CONFIG_NODE, qv.toString().getBytes(), -1, qv.getVersion(), Time.currentWallTime()); + } catch (NoNodeException e) { + System.out.println("configuration node missing - should not happen"); + } + } + + /** + * Check whether the given watcher exists in datatree + * + * @param path + * node to check watcher existence + * @param type + * type of watcher + * @param watcher + * watcher function + */ + public boolean containsWatcher(String path, WatcherType type, Watcher watcher) { + return dataTree.containsWatcher(path, type, watcher); + } + + /** + * Remove watch from the datatree + * + * @param path + * node to remove watches from + * @param type + * type of watcher to remove + * @param watcher + * watcher function to remove + */ + public boolean removeWatch(String path, WatcherType type, Watcher watcher) { + return dataTree.removeWatch(path, type, watcher); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java new file mode 100644 index 00000000000..5a61ec3bed5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperCriticalThread.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Represents critical thread. When there is an uncaught exception thrown by the + * thread this will exit the system. + */ +public class ZooKeeperCriticalThread extends ZooKeeperThread { + private static final Logger LOG = LoggerFactory + .getLogger(ZooKeeperCriticalThread.class); + private final ZooKeeperServerListener listener; + + public ZooKeeperCriticalThread(String threadName, ZooKeeperServerListener listener) { + super(threadName); + this.listener = listener; + } + + /** + * This will be used by the uncaught exception handler and make the system + * exit. + * + * @param threadName + * - thread name + * @param e + * - exception object + */ + @Override + protected void handleException(String threadName, Throwable e) { + LOG.error("Severe unrecoverable error, from thread : {}", threadName, e); + listener.notifyStopping(threadName, ExitCode.UNEXPECTED_ERROR); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperSaslServer.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperSaslServer.java new file mode 100644 index 00000000000..4ed5bdb1963 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperSaslServer.java @@ -0,0 +1,161 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.Login; +import org.ietf.jgss.GSSContext; +import org.ietf.jgss.GSSCredential; +import org.ietf.jgss.GSSException; +import org.ietf.jgss.GSSManager; +import org.ietf.jgss.GSSName; +import org.ietf.jgss.Oid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.security.Principal; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +import javax.security.auth.Subject; +import javax.security.sasl.Sasl; +import javax.security.sasl.SaslException; +import javax.security.sasl.SaslServer; + +public class ZooKeeperSaslServer { + public static final String LOGIN_CONTEXT_NAME_KEY = "zookeeper.sasl.serverconfig"; + public static final String DEFAULT_LOGIN_CONTEXT_NAME = "Server"; + + private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperSaslServer.class); + private SaslServer saslServer; + + ZooKeeperSaslServer(final Login login) { + saslServer = createSaslServer(login); + } + + private SaslServer createSaslServer(final Login login) { + synchronized (login) { + Subject subject = login.getSubject(); + if (subject != null) { + // server is using a JAAS-authenticated subject: determine service principal name and hostname from zk server's subject. + if (subject.getPrincipals().size() > 0) { + try { + final Object[] principals = subject.getPrincipals().toArray(); + final Principal servicePrincipal = (Principal) principals[0]; + + // e.g. servicePrincipalNameAndHostname := "zookeeper/myhost.foo.com@FOO.COM" + final String servicePrincipalNameAndHostname = servicePrincipal.getName(); + + int indexOf = servicePrincipalNameAndHostname.indexOf("/"); + + // e.g. servicePrincipalName := "zookeeper" + final String servicePrincipalName = servicePrincipalNameAndHostname.substring(0, indexOf); + + // e.g. serviceHostnameAndKerbDomain := "myhost.foo.com@FOO.COM" + final String serviceHostnameAndKerbDomain = servicePrincipalNameAndHostname.substring(indexOf + 1, servicePrincipalNameAndHostname.length()); + + indexOf = serviceHostnameAndKerbDomain.indexOf("@"); + // e.g. serviceHostname := "myhost.foo.com" + final String serviceHostname = serviceHostnameAndKerbDomain.substring(0, indexOf); + + final String mech = "GSSAPI"; // TODO: should depend on zoo.cfg specified mechs, but if subject is non-null, it can be assumed to be GSSAPI. + + LOG.debug("serviceHostname is '" + serviceHostname + "'"); + LOG.debug("servicePrincipalName is '" + servicePrincipalName + "'"); + LOG.debug("SASL mechanism(mech) is '" + mech + "'"); + + boolean usingNativeJgss = + Boolean.getBoolean("sun.security.jgss.native"); + if (usingNativeJgss) { + // http://docs.oracle.com/javase/6/docs/technotes/guides/security/jgss/jgss-features.html + // """ + // In addition, when performing operations as a particular + // Subject, e.g. Subject.doAs(...) or + // Subject.doAsPrivileged(...), the to-be-used + // GSSCredential should be added to Subject's + // private credential set. Otherwise, the GSS operations + // will fail since no credential is found. + // """ + try { + GSSManager manager = GSSManager.getInstance(); + Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2"); + GSSName gssName = manager.createName( + servicePrincipalName + "@" + serviceHostname, + GSSName.NT_HOSTBASED_SERVICE); + GSSCredential cred = manager.createCredential(gssName, + GSSContext.DEFAULT_LIFETIME, + krb5Mechanism, + GSSCredential.ACCEPT_ONLY); + subject.getPrivateCredentials().add(cred); + if (LOG.isDebugEnabled()) { + LOG.debug("Added private credential to subject: " + cred); + } + } catch (GSSException ex) { + LOG.warn("Cannot add private credential to subject; " + + "clients authentication may fail", ex); + } + } + try { + return Subject.doAs(subject, new PrivilegedExceptionAction() { + public SaslServer run() { + try { + SaslServer saslServer; + saslServer = Sasl.createSaslServer(mech, servicePrincipalName, serviceHostname, null, login.callbackHandler); + return saslServer; + } catch (SaslException e) { + LOG.error("Zookeeper Server failed to create a SaslServer to interact with a client during session initiation: " + e); + e.printStackTrace(); + return null; + } + } + } + ); + } catch (PrivilegedActionException e) { + // TODO: exit server at this point(?) + LOG.error("Zookeeper Quorum member experienced a PrivilegedActionException exception while creating a SaslServer using a JAAS principal context:" + e); + e.printStackTrace(); + } + } catch (IndexOutOfBoundsException e) { + LOG.error("server principal name/hostname determination error: ", e); + } + } else { + // JAAS non-GSSAPI authentication: assuming and supporting only DIGEST-MD5 mechanism for now. + // TODO: use 'authMech=' value in zoo.cfg. + try { + SaslServer saslServer = Sasl.createSaslServer("DIGEST-MD5", "zookeeper", "zk-sasl-md5", null, login.callbackHandler); + return saslServer; + } catch (SaslException e) { + LOG.error("Zookeeper Quorum member failed to create a SaslServer to interact with a client during session initiation", e); + } + } + } + } + LOG.error("failed to create saslServer object."); + return null; + } + + public byte[] evaluateResponse(byte[] response) throws SaslException { + return saslServer.evaluateResponse(response); + } + + public boolean isComplete() { + return saslServer.isComplete(); + } + + public String getAuthorizationID() { + return saslServer.getAuthorizationID(); + } + +} + + + + diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java new file mode 100644 index 00000000000..abb8ff72cfb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java @@ -0,0 +1,1103 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.Environment; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.data.StatPersisted; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.proto.AuthPacket; +import org.apache.zookeeper.proto.ConnectRequest; +import org.apache.zookeeper.proto.ConnectResponse; +import org.apache.zookeeper.proto.GetSASLRequest; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; +import org.apache.zookeeper.proto.SetSASLResponse; +import org.apache.zookeeper.server.DataTree.ProcessTxnResult; +import org.apache.zookeeper.server.RequestProcessor.RequestProcessorException; +import org.apache.zookeeper.server.ServerCnxn.CloseRequestException; +import org.apache.zookeeper.server.SessionTracker.Session; +import org.apache.zookeeper.server.SessionTracker.SessionExpirer; +import org.apache.zookeeper.server.auth.AuthenticationProvider; +import org.apache.zookeeper.server.auth.ProviderRegistry; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer; +import org.apache.zookeeper.txn.CreateSessionTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +import javax.security.sasl.SaslException; + + +/** + * This class implements a simple standalone ZooKeeperServer. It sets up the following chain of RequestProcessors to process requests: PrepRequestProcessor -> SyncRequestProcessor -> + * FinalRequestProcessor + */ +public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider { + public static final int DEFAULT_TICK_TIME = 3000; + public final static Exception ok = new Exception("No prob"); + protected static final Logger LOG; + /** + * This is the secret that we use to generate passwords, for the moment it is more of a sanity check. + */ + static final private long superSecret = 0XB3415C00L; + + static { + LOG = LoggerFactory.getLogger(ZooKeeperServer.class); + + Environment.logEnv("Server environment:", LOG); + } + + final List outstandingChanges = new ArrayList(); + // this data structure must be accessed under the outstandingChanges lock + final HashMap outstandingChangesForPath = new HashMap(); + + private final AtomicLong hzxid = new AtomicLong(0); + private final AtomicInteger requestsInProcess = new AtomicInteger(0); + private final ServerStats serverStats; + private final ZooKeeperServerListener listener = new ZooKeeperServerListenerImpl(); + protected ZooKeeperServerBean jmxServerBean; + protected DataTreeBean jmxDataTreeBean; + protected int tickTime = DEFAULT_TICK_TIME; + /** + * value of -1 indicates unset, use default + */ + protected int minSessionTimeout = -1; + /** + * value of -1 indicates unset, use default + */ + protected int maxSessionTimeout = -1; + protected SessionTracker sessionTracker; + protected RequestProcessor firstProcessor; + protected volatile State state = State.INITIAL; + protected ServerCnxnFactory serverCnxnFactory; + protected ServerCnxnFactory secureServerCnxnFactory; + private FileTxnSnapLog txnLogFactory = null; + private ZKDatabase zkDb; + /** + * Creates a ZooKeeperServer instance. Nothing is setup, use the setX methods to prepare the instance (eg datadir, datalogdir, ticktime, builder, etc...) + */ + public ZooKeeperServer() { + serverStats = new ServerStats(this); + } + + /** + * Creates a ZooKeeperServer instance. It sets everything up, but doesn't actually start listening for clients until run() is invoked. + * + * @param dataDir the directory to put the data + */ + public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, + int minSessionTimeout, int maxSessionTimeout, ZKDatabase zkDb) { + serverStats = new ServerStats(this); + this.txnLogFactory = txnLogFactory; + this.zkDb = zkDb; + this.tickTime = tickTime; + setMinSessionTimeout(minSessionTimeout); + setMaxSessionTimeout(maxSessionTimeout); + + LOG.info("Created server with tickTime " + tickTime + + " minSessionTimeout " + getMinSessionTimeout() + + " maxSessionTimeout " + getMaxSessionTimeout() + + " datadir " + txnLogFactory.getDataDir() + + " snapdir " + txnLogFactory.getSnapDir()); + } + + /** + * creates a zookeeperserver instance. + * + * @param txnLogFactory the file transaction snapshot logging class + * @param tickTime the ticktime for the server + */ + public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime) throws IOException { + this(txnLogFactory, tickTime, -1, -1, new ZKDatabase(txnLogFactory)); + } + + /** + * This constructor is for backward compatibility with the existing unit test code. It defaults to FileLogProvider persistence provider. + */ + public ZooKeeperServer(File snapDir, File logDir, int tickTime) + throws IOException { + this(new FileTxnSnapLog(snapDir, logDir), + tickTime); + } + + /** + * Default constructor, relies on the config for its agrument values + */ + public ZooKeeperServer(FileTxnSnapLog txnLogFactory) + throws IOException { + this(txnLogFactory, DEFAULT_TICK_TIME, -1, -1, new ZKDatabase(txnLogFactory)); + } + + public static int getSnapCount() { + String sc = System.getProperty("zookeeper.snapCount"); + try { + int snapCount = Integer.parseInt(sc); + + // snapCount must be 2 or more. See org.apache.zookeeper.server.SyncRequestProcessor + if (snapCount < 2) { + LOG.warn("SnapCount should be 2 or more. Now, snapCount is reset to 2"); + snapCount = 2; + } + return snapCount; + } catch (Exception e) { + return 100000; + } + } + + void removeCnxn(ServerCnxn cnxn) { + zkDb.removeCnxn(cnxn); + } + + public ServerStats serverStats() { + return serverStats; + } + + public void dumpConf(PrintWriter pwriter) { + pwriter.print("clientPort="); + pwriter.println(getClientPort()); + pwriter.print("secureClientPort="); + pwriter.println(getSecureClientPort()); + pwriter.print("dataDir="); + pwriter.println(zkDb.snapLog.getDataDir().getAbsolutePath()); + pwriter.print("dataDirSize="); + pwriter.println(getDataDirSize()); + pwriter.print("dataLogDir="); + pwriter.println(zkDb.snapLog.getSnapDir().getAbsolutePath()); + pwriter.print("dataLogSize="); + pwriter.println(getLogDirSize()); + pwriter.print("tickTime="); + pwriter.println(getTickTime()); + pwriter.print("maxClientCnxns="); + pwriter.println(getMaxClientCnxnsPerHost()); + pwriter.print("minSessionTimeout="); + pwriter.println(getMinSessionTimeout()); + pwriter.print("maxSessionTimeout="); + pwriter.println(getMaxSessionTimeout()); + + pwriter.print("serverId="); + pwriter.println(getServerId()); + } + + public ZooKeeperServerConf getConf() { + return new ZooKeeperServerConf + (getClientPort(), + zkDb.snapLog.getSnapDir().getAbsolutePath(), + zkDb.snapLog.getDataDir().getAbsolutePath(), + getTickTime(), + serverCnxnFactory.getMaxClientCnxnsPerHost(), + getMinSessionTimeout(), + getMaxSessionTimeout(), + getServerId()); + } + + /** + * get the zookeeper database for this server + * + * @return the zookeeper database for this server + */ + public ZKDatabase getZKDatabase() { + return this.zkDb; + } + + /** + * set the zkdatabase for this zookeeper server + */ + public void setZKDatabase(ZKDatabase zkDb) { + this.zkDb = zkDb; + } + + /** + * Restore sessions and data + */ + public void loadData() throws IOException, InterruptedException { + /* + * When a new leader starts executing Leader#lead, it + * invokes this method. The database, however, has been + * initialized before running leader election so that + * the server could pick its zxid for its initial vote. + * It does it by invoking QuorumPeer#getLastLoggedZxid. + * Consequently, we don't need to initialize it once more + * and avoid the penalty of loading it a second time. Not + * reloading it is particularly important for applications + * that host a large database. + * + * The following if block checks whether the database has + * been initialized or not. Note that this method is + * invoked by at least one other method: + * ZooKeeperServer#startdata. + * + * See ZOOKEEPER-1642 for more detail. + */ + if (zkDb.isInitialized()) { + setZxid(zkDb.getDataTreeLastProcessedZxid()); + } else { + setZxid(zkDb.loadDataBase()); + } + + // Clean up dead sessions + LinkedList deadSessions = new LinkedList(); + for (Long session : zkDb.getSessions()) { + if (zkDb.getSessionWithTimeOuts().get(session) == null) { + deadSessions.add(session); + } + } + + for (long session : deadSessions) { + // XXX: Is lastProcessedZxid really the best thing to use? + killSession(session, zkDb.getDataTreeLastProcessedZxid()); + } + + // Make a clean snapshot + takeSnapshot(); + } + + public void takeSnapshot() { + try { + txnLogFactory.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts()); + } catch (IOException e) { + LOG.error("Severe unrecoverable error, exiting", e); + // This is a severe error that we cannot recover from, + // so we need to exit + System.exit(10); + } + } + + @Override + public long getDataDirSize() { + if (zkDb == null) { + return 0L; + } + File path = zkDb.snapLog.getDataDir(); + return getDirSize(path); + } + + @Override + public long getLogDirSize() { + if (zkDb == null) { + return 0L; + } + File path = zkDb.snapLog.getSnapDir(); + return getDirSize(path); + } + + private long getDirSize(File file) { + long size = 0L; + if (file.isDirectory()) { + for (File f : file.listFiles()) { + size += getDirSize(f); + } + } else { + size = file.length(); + } + return size; + } + + public long getZxid() { + return hzxid.get(); + } + + public void setZxid(long zxid) { + hzxid.set(zxid); + } + + public SessionTracker getSessionTracker() { + return sessionTracker; + } + + long getNextZxid() { + return hzxid.incrementAndGet(); + } + + private void close(long sessionId) { + Request si = new Request(null, sessionId, 0, OpCode.closeSession, null, null); + setLocalSessionFlag(si); + submitRequest(si); + } + + public void closeSession(long sessionId) { + LOG.info("Closing session 0x" + Long.toHexString(sessionId)); + + // we do not want to wait for a session close. send it as soon as we + // detect it! + close(sessionId); + } + + protected void killSession(long sessionId, long zxid) { + zkDb.killSession(sessionId, zxid); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, + "ZooKeeperServer --- killSession: 0x" + + Long.toHexString(sessionId)); + } + if (sessionTracker != null) { + sessionTracker.removeSession(sessionId); + } + } + + public void expire(Session session) { + long sessionId = session.getSessionId(); + LOG.info("Expiring session 0x" + Long.toHexString(sessionId) + + ", timeout of " + session.getTimeout() + "ms exceeded"); + close(sessionId); + } + + void touch(ServerCnxn cnxn) throws MissingSessionException { + if (cnxn == null) { + return; + } + long id = cnxn.getSessionId(); + int to = cnxn.getSessionTimeout(); + if (!sessionTracker.touchSession(id, to)) { + throw new MissingSessionException( + "No session with sessionid 0x" + Long.toHexString(id) + + " exists, probably expired and removed"); + } + } + + protected void registerJMX() { + // register with JMX + try { + jmxServerBean = new ZooKeeperServerBean(this); + MBeanRegistry.getInstance().register(jmxServerBean, null); + + try { + jmxDataTreeBean = new DataTreeBean(zkDb.getDataTree()); + MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxDataTreeBean = null; + } + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxServerBean = null; + } + } + + public void startdata() + throws IOException, InterruptedException { + //check to see if zkDb is not null + if (zkDb == null) { + zkDb = new ZKDatabase(this.txnLogFactory); + } + if (!zkDb.isInitialized()) { + loadData(); + } + } + + public synchronized void startup() { + if (sessionTracker == null) { + createSessionTracker(); + } + startSessionTracker(); + setupRequestProcessors(); + + registerJMX(); + + state = State.RUNNING; + notifyAll(); + } + + protected void setupRequestProcessors() { + RequestProcessor finalProcessor = new FinalRequestProcessor(this); + RequestProcessor syncProcessor = new SyncRequestProcessor(this, finalProcessor); + ((SyncRequestProcessor) syncProcessor).start(); + firstProcessor = new PrepRequestProcessor(this, syncProcessor); + ((PrepRequestProcessor) firstProcessor).start(); + } + + public ZooKeeperServerListener getZooKeeperServerListener() { + return listener; + } + + protected void createSessionTracker() { + sessionTracker = new SessionTrackerImpl(this, zkDb.getSessionWithTimeOuts(), + tickTime, 1, getZooKeeperServerListener()); + } + + protected void startSessionTracker() { + ((SessionTrackerImpl) sessionTracker).start(); + } + + public boolean isRunning() { + return state == State.RUNNING; + } + + public synchronized void shutdown() { + if (!isRunning()) { + LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); + return; + } + LOG.info("shutting down"); + + // new RuntimeException("Calling shutdown").printStackTrace(); + state = State.SHUTDOWN; + // Since sessionTracker and syncThreads poll we just have to + // set running to false and they will detect it during the poll + // interval. + if (sessionTracker != null) { + sessionTracker.shutdown(); + } + if (firstProcessor != null) { + firstProcessor.shutdown(); + } + if (zkDb != null) { + zkDb.clear(); + } + + unregisterJMX(); + } + + protected void unregisterJMX() { + // unregister from JMX + try { + if (jmxDataTreeBean != null) { + MBeanRegistry.getInstance().unregister(jmxDataTreeBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + try { + if (jmxServerBean != null) { + MBeanRegistry.getInstance().unregister(jmxServerBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + jmxServerBean = null; + jmxDataTreeBean = null; + } + + public void incInProcess() { + requestsInProcess.incrementAndGet(); + } + + public void decInProcess() { + requestsInProcess.decrementAndGet(); + } + + public int getInProcess() { + return requestsInProcess.get(); + } + + byte[] generatePasswd(long id) { + Random r = new Random(id ^ superSecret); + byte p[] = new byte[16]; + r.nextBytes(p); + return p; + } + + protected boolean checkPasswd(long sessionId, byte[] passwd) { + return sessionId != 0 + && Arrays.equals(passwd, generatePasswd(sessionId)); + } + + long createSession(ServerCnxn cnxn, byte passwd[], int timeout) { + if (passwd == null) { + // Possible since it's just deserialized from a packet on the wire. + passwd = new byte[0]; + } + long sessionId = sessionTracker.createSession(timeout); + Random r = new Random(sessionId ^ superSecret); + r.nextBytes(passwd); + ByteBuffer to = ByteBuffer.allocate(4); + to.putInt(timeout); + cnxn.setSessionId(sessionId); + Request si = new Request(cnxn, sessionId, 0, OpCode.createSession, to, null); + setLocalSessionFlag(si); + submitRequest(si); + return sessionId; + } + + /** + * set the owner of this session as owner + * + * @param id the session id + * @param owner the owner of the session + */ + public void setOwner(long id, Object owner) throws SessionExpiredException { + sessionTracker.setOwner(id, owner); + } + + protected void revalidateSession(ServerCnxn cnxn, long sessionId, + int sessionTimeout) throws IOException { + boolean rc = sessionTracker.touchSession(sessionId, sessionTimeout); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, + "Session 0x" + Long.toHexString(sessionId) + + " is valid: " + rc); + } + finishSessionInit(cnxn, rc); + } + + public void reopenSession(ServerCnxn cnxn, long sessionId, byte[] passwd, + int sessionTimeout) throws IOException { + if (checkPasswd(sessionId, passwd)) { + revalidateSession(cnxn, sessionId, sessionTimeout); + } else { + LOG.warn("Incorrect password from " + cnxn.getRemoteSocketAddress() + + " for session 0x" + Long.toHexString(sessionId)); + finishSessionInit(cnxn, false); + } + } + + public void finishSessionInit(ServerCnxn cnxn, boolean valid) { + // register with JMX + try { + if (valid) { + if (serverCnxnFactory != null && serverCnxnFactory.cnxns.contains(cnxn)) { + serverCnxnFactory.registerConnection(cnxn); + } else if (secureServerCnxnFactory != null && secureServerCnxnFactory.cnxns.contains(cnxn)) { + secureServerCnxnFactory.registerConnection(cnxn); + } + } + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + } + + try { + ConnectResponse rsp = new ConnectResponse(0, valid ? cnxn.getSessionTimeout() + : 0, valid ? cnxn.getSessionId() : 0, // send 0 if session is no + // longer valid + valid ? generatePasswd(cnxn.getSessionId()) : new byte[16]); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos); + bos.writeInt(-1, "len"); + rsp.serialize(bos, "connect"); + if (!cnxn.isOldClient) { + bos.writeBool( + this instanceof ReadOnlyZooKeeperServer, "readOnly"); + } + baos.close(); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + bb.putInt(bb.remaining() - 4).rewind(); + cnxn.sendBuffer(bb); + + if (valid) { + LOG.info("Established session 0x" + + Long.toHexString(cnxn.getSessionId()) + + " with negotiated timeout " + cnxn.getSessionTimeout() + + " for client " + + cnxn.getRemoteSocketAddress()); + cnxn.enableRecv(); + } else { + + LOG.info("Invalid session 0x" + + Long.toHexString(cnxn.getSessionId()) + + " for client " + + cnxn.getRemoteSocketAddress() + + ", probably expired"); + cnxn.sendBuffer(ServerCnxnFactory.closeConn); + } + + } catch (Exception e) { + LOG.warn("Exception while establishing session, closing", e); + cnxn.close(); + } + } + + public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader) { + closeSession(cnxn.getSessionId()); + } + + public long getServerId() { + return 0; + } + + /** + * If the underlying Zookeeper server support local session, this method will set a isLocalSession to true if a request is associated with a local session. + */ + protected void setLocalSessionFlag(Request si) { + } + + public void submitRequest(Request si) { + if (firstProcessor == null) { + synchronized (this) { + try { + // Since all requests are passed to the request + // processor it should wait for setting up the request + // processor chain. The state will be updated to RUNNING + // after the setup. + while (state == State.INITIAL) { + wait(1000); + } + } catch (InterruptedException e) { + LOG.warn("Unexpected interruption", e); + } + if (firstProcessor == null || state != State.RUNNING) { + throw new RuntimeException("Not started"); + } + } + } + try { + touch(si.cnxn); + boolean validpacket = Request.isValid(si.type); + if (validpacket) { + firstProcessor.processRequest(si); + if (si.cnxn != null) { + incInProcess(); + } + } else { + LOG.warn("Received packet at server of unknown type " + si.type); + new UnimplementedRequestProcessor().processRequest(si); + } + } catch (MissingSessionException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Dropping request: " + e.getMessage()); + } + } catch (RequestProcessorException e) { + LOG.error("Unable to process request:" + e.getMessage(), e); + } + } + + public int getGlobalOutstandingLimit() { + String sc = System.getProperty("zookeeper.globalOutstandingLimit"); + int limit; + try { + limit = Integer.parseInt(sc); + } catch (Exception e) { + limit = 1000; + } + return limit; + } + + public ServerCnxnFactory getServerCnxnFactory() { + return serverCnxnFactory; + } + + public void setServerCnxnFactory(ServerCnxnFactory factory) { + serverCnxnFactory = factory; + } + + public void setSecureServerCnxnFactory(ServerCnxnFactory factory) { + secureServerCnxnFactory = factory; + } + + /** + * return the last proceesed id from the datatree + */ + public long getLastProcessedZxid() { + return zkDb.getDataTreeLastProcessedZxid(); + } + + /** + * return the outstanding requests in the queue, which havent been processed yet + */ + public long getOutstandingRequests() { + return getInProcess(); + } + + /** + * return the total number of client connections that are alive to this server + */ + public int getNumAliveConnections() { + int numAliveConnections = 0; + + if (serverCnxnFactory != null) { + numAliveConnections += serverCnxnFactory.getNumAliveConnections(); + } + + if (secureServerCnxnFactory != null) { + numAliveConnections += secureServerCnxnFactory.getNumAliveConnections(); + } + + return numAliveConnections; + } + + /** + * trunccate the log to get in sync with others if in a quorum + * + * @param zxid the zxid that it needs to get in sync with others + */ + public void truncateLog(long zxid) throws IOException { + this.zkDb.truncateLog(zxid); + } + + public int getTickTime() { + return tickTime; + } + + public void setTickTime(int tickTime) { + LOG.info("tickTime set to " + tickTime); + this.tickTime = tickTime; + } + + public int getMinSessionTimeout() { + return minSessionTimeout; + } + + public void setMinSessionTimeout(int min) { + this.minSessionTimeout = min == -1 ? tickTime * 2 : min; + LOG.info("minSessionTimeout set to {}", this.minSessionTimeout); + } + + public int getMaxSessionTimeout() { + return maxSessionTimeout; + } + + public void setMaxSessionTimeout(int max) { + this.maxSessionTimeout = max == -1 ? tickTime * 20 : max; + LOG.info("maxSessionTimeout set to {}", this.maxSessionTimeout); + } + + public int getClientPort() { + return serverCnxnFactory != null ? serverCnxnFactory.getLocalPort() : -1; + } + + public int getSecureClientPort() { + return secureServerCnxnFactory != null ? secureServerCnxnFactory.getLocalPort() : -1; + } + + /** + * Maximum number of connections allowed from particular host (ip) + */ + public int getMaxClientCnxnsPerHost() { + if (serverCnxnFactory != null) { + return serverCnxnFactory.getMaxClientCnxnsPerHost(); + } + if (secureServerCnxnFactory != null) { + return secureServerCnxnFactory.getMaxClientCnxnsPerHost(); + } + return -1; + } + + public FileTxnSnapLog getTxnLogFactory() { + return this.txnLogFactory; + } + + public void setTxnLogFactory(FileTxnSnapLog txnLog) { + this.txnLogFactory = txnLog; + } + + public String getState() { + return "standalone"; + } + + public void dumpEphemerals(PrintWriter pwriter) { + zkDb.dumpEphemerals(pwriter); + } + + public Map> getEphemerals() { + return zkDb.getEphemerals(); + } + + public void processConnectRequest(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException { + BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(incomingBuffer)); + ConnectRequest connReq = new ConnectRequest(); + connReq.deserialize(bia, "connect"); + if (LOG.isDebugEnabled()) { + LOG.debug("Session establishment request from client " + + cnxn.getRemoteSocketAddress() + + " client's lastZxid is 0x" + + Long.toHexString(connReq.getLastZxidSeen())); + } + boolean readOnly = false; + try { + readOnly = bia.readBool("readOnly"); + cnxn.isOldClient = false; + } catch (IOException e) { + // this is ok -- just a packet from an old client which + // doesn't contain readOnly field + LOG.warn("Connection request from old client " + + cnxn.getRemoteSocketAddress() + + "; will be dropped if server is in r-o mode"); + } + if (!readOnly && this instanceof ReadOnlyZooKeeperServer) { + String msg = "Refusing session request for not-read-only client " + + cnxn.getRemoteSocketAddress(); + LOG.info(msg); + throw new CloseRequestException(msg); + } + if (connReq.getLastZxidSeen() > zkDb.dataTree.lastProcessedZxid) { + String msg = "Refusing session request for client " + + cnxn.getRemoteSocketAddress() + + " as it has seen zxid 0x" + + Long.toHexString(connReq.getLastZxidSeen()) + + " our last zxid is 0x" + + Long.toHexString(getZKDatabase().getDataTreeLastProcessedZxid()) + + " client must try another server"; + + LOG.info(msg); + throw new CloseRequestException(msg); + } + int sessionTimeout = connReq.getTimeOut(); + byte passwd[] = connReq.getPasswd(); + int minSessionTimeout = getMinSessionTimeout(); + if (sessionTimeout < minSessionTimeout) { + sessionTimeout = minSessionTimeout; + } + int maxSessionTimeout = getMaxSessionTimeout(); + if (sessionTimeout > maxSessionTimeout) { + sessionTimeout = maxSessionTimeout; + } + cnxn.setSessionTimeout(sessionTimeout); + // We don't want to receive any packets until we are sure that the + // session is setup + cnxn.disableRecv(); + long sessionId = connReq.getSessionId(); + if (sessionId == 0) { + LOG.info("Client attempting to establish new session at " + + cnxn.getRemoteSocketAddress()); + createSession(cnxn, passwd, sessionTimeout); + } else { + long clientSessionId = connReq.getSessionId(); + LOG.info("Client attempting to renew session 0x" + + Long.toHexString(clientSessionId) + + " at " + cnxn.getRemoteSocketAddress()); + if (serverCnxnFactory != null) { + serverCnxnFactory.closeSession(sessionId); + } + if (secureServerCnxnFactory != null) { + secureServerCnxnFactory.closeSession(sessionId); + } + cnxn.setSessionId(sessionId); + reopenSession(cnxn, sessionId, passwd, sessionTimeout); + } + } + + public boolean shouldThrottle(long outStandingCount) { + if (getGlobalOutstandingLimit() < getInProcess()) { + return outStandingCount > 0; + } + return false; + } + + public void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException { + // We have the request, now process and setup for next + InputStream bais = new ByteBufferInputStream(incomingBuffer); + BinaryInputArchive bia = BinaryInputArchive.getArchive(bais); + RequestHeader h = new RequestHeader(); + h.deserialize(bia, "header"); + // Through the magic of byte buffers, txn will not be + // pointing + // to the start of the txn + incomingBuffer = incomingBuffer.slice(); + if (h.getType() == OpCode.auth) { + LOG.info("got auth packet " + cnxn.getRemoteSocketAddress()); + AuthPacket authPacket = new AuthPacket(); + ByteBufferInputStream.byteBuffer2Record(incomingBuffer, authPacket); + String scheme = authPacket.getScheme(); + AuthenticationProvider ap = ProviderRegistry.getProvider(scheme); + Code authReturn = KeeperException.Code.AUTHFAILED; + if (ap != null) { + try { + authReturn = ap.handleAuthentication(cnxn, authPacket.getAuth()); + } catch (RuntimeException e) { + LOG.warn("Caught runtime exception from AuthenticationProvider: " + scheme + " due to " + e); + authReturn = KeeperException.Code.AUTHFAILED; + } + } + if (authReturn == KeeperException.Code.OK) { + if (LOG.isDebugEnabled()) { + LOG.debug("Authentication succeeded for scheme: " + scheme); + } + LOG.info("auth success " + cnxn.getRemoteSocketAddress()); + ReplyHeader rh = new ReplyHeader(h.getXid(), 0, + KeeperException.Code.OK.intValue()); + cnxn.sendResponse(rh, null, null); + } else { + if (ap == null) { + LOG.warn("No authentication provider for scheme: " + + scheme + " has " + + ProviderRegistry.listProviders()); + } else { + LOG.warn("Authentication failed for scheme: " + scheme); + } + // send a response... + ReplyHeader rh = new ReplyHeader(h.getXid(), 0, + KeeperException.Code.AUTHFAILED.intValue()); + cnxn.sendResponse(rh, null, null); + // ... and close connection + cnxn.sendBuffer(ServerCnxnFactory.closeConn); + cnxn.disableRecv(); + } + return; + } else { + if (h.getType() == OpCode.sasl) { + Record rsp = processSasl(incomingBuffer, cnxn); + ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue()); + cnxn.sendResponse(rh, rsp, "response"); // not sure about 3rd arg..what is it? + } else { + Request si = new Request(cnxn, cnxn.getSessionId(), h.getXid(), + h.getType(), incomingBuffer, cnxn.getAuthInfo()); + si.setOwner(ServerCnxn.me); + // Always treat packet from the client as a possible + // local request. + setLocalSessionFlag(si); + submitRequest(si); + } + } + cnxn.incrOutstandingRequests(h); + } + + private Record processSasl(ByteBuffer incomingBuffer, ServerCnxn cnxn) throws IOException { + LOG.debug("Responding to client SASL token."); + GetSASLRequest clientTokenRecord = new GetSASLRequest(); + ByteBufferInputStream.byteBuffer2Record(incomingBuffer, clientTokenRecord); + byte[] clientToken = clientTokenRecord.getToken(); + LOG.debug("Size of client SASL token: " + clientToken.length); + byte[] responseToken = null; + try { + ZooKeeperSaslServer saslServer = cnxn.zooKeeperSaslServer; + try { + // note that clientToken might be empty (clientToken.length == 0): + // if using the DIGEST-MD5 mechanism, clientToken will be empty at the beginning of the + // SASL negotiation process. + responseToken = saslServer.evaluateResponse(clientToken); + if (saslServer.isComplete()) { + String authorizationID = saslServer.getAuthorizationID(); + LOG.info("adding SASL authorization for authorizationID: " + authorizationID); + cnxn.addAuthInfo(new Id("sasl", authorizationID)); + } + } catch (SaslException e) { + LOG.warn("Client failed to SASL authenticate: " + e, e); + if ((System.getProperty("zookeeper.allowSaslFailedClients") != null) + && + (System.getProperty("zookeeper.allowSaslFailedClients").equals("true"))) { + LOG.warn("Maintaining client connection despite SASL authentication failure."); + } else { + LOG.warn("Closing client connection due to SASL authentication failure."); + cnxn.close(); + } + } + } catch (NullPointerException e) { + LOG.error("cnxn.saslServer is null: cnxn object did not initialize its saslServer properly."); + } + if (responseToken != null) { + LOG.debug("Size of server SASL response: " + responseToken.length); + } + // wrap SASL response token to client inside a Response object. + return new SetSASLResponse(responseToken); + } + + // entry point for quorum/Learner.java + public ProcessTxnResult processTxn(TxnHeader hdr, Record txn) { + return processTxn(null, hdr, txn); + } + + // entry point for FinalRequestProcessor.java + public ProcessTxnResult processTxn(Request request) { + return processTxn(request, request.getHdr(), request.getTxn()); + } + + private ProcessTxnResult processTxn(Request request, TxnHeader hdr, Record txn) { + ProcessTxnResult rc; + int opCode = request != null ? request.type : hdr.getType(); + long sessionId = request != null ? request.sessionId : hdr.getClientId(); + if (hdr != null) { + rc = getZKDatabase().processTxn(hdr, txn); + } else { + rc = new ProcessTxnResult(); + } + if (opCode == OpCode.createSession) { + if (hdr != null && txn instanceof CreateSessionTxn) { + CreateSessionTxn cst = (CreateSessionTxn) txn; + sessionTracker.addGlobalSession(sessionId, cst.getTimeOut()); + } else if (request != null && request.isLocalSession()) { + request.request.rewind(); + int timeout = request.request.getInt(); + request.request.rewind(); + sessionTracker.addSession(request.sessionId, timeout); + } else { + LOG.warn("*****>>>>> Got " + txn.getClass() + " " + txn.toString()); + } + } else if (opCode == OpCode.closeSession) { + sessionTracker.removeSession(sessionId); + } + return rc; + } + + public Map> getSessionExpiryMap() { + return sessionTracker.getSessionExpiryMap(); + } + + enum State { + INITIAL, RUNNING, SHUTDOWN; + } + + public static class MissingSessionException extends IOException { + private static final long serialVersionUID = 7467414635467261007L; + + public MissingSessionException(String msg) { + super(msg); + } + } + + /** + * This structure is used to facilitate information sharing between PrepRP and FinalRP. + */ + static class ChangeRecord { + long zxid; + String path; + StatPersisted stat; /* Make sure to create a new object when changing */ + int childCount; + List acl; /* Make sure to create a new object when changing */ + + ChangeRecord(long zxid, String path, StatPersisted stat, int childCount, + List acl) { + this.zxid = zxid; + this.path = path; + this.stat = stat; + this.childCount = childCount; + this.acl = acl; + } + + ChangeRecord duplicate(long zxid) { + StatPersisted stat = new StatPersisted(); + if (this.stat != null) { + DataTree.copyStatPersisted(this.stat, stat); + } + return new ChangeRecord(zxid, path, stat, childCount, + acl == null ? new ArrayList() : new ArrayList(acl)); + } + } + + /** + * Default listener implementation, which will do a graceful shutdown on notification + */ + private class ZooKeeperServerListenerImpl implements + ZooKeeperServerListener { + + @Override + public void notifyStopping(String threadName, int exitCode) { + LOG.info("Thread {} exits, error code {}", threadName, exitCode); + shutdown(); + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java new file mode 100644 index 00000000000..cef7c98978c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java @@ -0,0 +1,157 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.Version; +import org.apache.zookeeper.jmx.ZKMBeanInfo; + +import java.util.Date; + +/** + * This class implements the ZooKeeper server MBean interface. + */ +public class ZooKeeperServerBean implements ZooKeeperServerMXBean, ZKMBeanInfo { + protected final ZooKeeperServer zks; + private final Date startTime; + private final String name; + + public ZooKeeperServerBean(ZooKeeperServer zks) { + startTime = new Date(); + this.zks = zks; + name = "StandaloneServer_port" + zks.getClientPort(); + } + + public String getClientPort() { + return Integer.toString(zks.getClientPort()); + } + + public String getName() { + return name; + } + + public boolean isHidden() { + return false; + } + + public String getStartTime() { + return startTime.toString(); + } + + public String getVersion() { + return Version.getFullVersion(); + } + + public long getAvgRequestLatency() { + return zks.serverStats().getAvgLatency(); + } + + public long getMaxRequestLatency() { + return zks.serverStats().getMaxLatency(); + } + + public long getMinRequestLatency() { + return zks.serverStats().getMinLatency(); + } + + public long getOutstandingRequests() { + return zks.serverStats().getOutstandingRequests(); + } + + public int getTickTime() { + return zks.getTickTime(); + } + + public void setTickTime(int tickTime) { + zks.setTickTime(tickTime); + } + + public int getMaxClientCnxnsPerHost() { + return zks.getMaxClientCnxnsPerHost(); + } + + public void setMaxClientCnxnsPerHost(int max) { + if (zks.serverCnxnFactory != null) { + zks.serverCnxnFactory.setMaxClientCnxnsPerHost(max); + } + if (zks.secureServerCnxnFactory != null) { + zks.secureServerCnxnFactory.setMaxClientCnxnsPerHost(max); + } + } + + public int getMinSessionTimeout() { + return zks.getMinSessionTimeout(); + } + + public void setMinSessionTimeout(int min) { + zks.setMinSessionTimeout(min); + } + + public int getMaxSessionTimeout() { + return zks.getMaxSessionTimeout(); + } + + public void setMaxSessionTimeout(int max) { + zks.setMaxSessionTimeout(max); + } + + public long getDataDirSize() { + return zks.getDataDirSize(); + } + + public long getLogDirSize() { + return zks.getLogDirSize(); + } + + public long getPacketsReceived() { + return zks.serverStats().getPacketsReceived(); + } + + public long getPacketsSent() { + return zks.serverStats().getPacketsSent(); + } + + public void resetLatency() { + zks.serverStats().resetLatency(); + } + + public void resetMaxLatency() { + zks.serverStats().resetMaxLatency(); + } + + public void resetStatistics() { + ServerStats serverStats = zks.serverStats(); + serverStats.resetRequestCounters(); + serverStats.resetLatency(); + } + + public long getNumAliveConnections() { + return zks.getNumAliveConnections(); + } + + @Override + public String getSecureClientPort() { + if (zks.secureServerCnxnFactory != null) { + return Integer.toString(zks.secureServerCnxnFactory.getLocalPort()); + } + return ""; + } + + @Override + public String getSecureClientAddress() { + if (zks.secureServerCnxnFactory != null) { + return String.format("%s:%d", zks.secureServerCnxnFactory + .getLocalAddress().getHostString(), + zks.secureServerCnxnFactory.getLocalPort()); + } + return ""; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java new file mode 100644 index 00000000000..de699c028fe --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerConf.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Configuration data for a {@link ZooKeeperServer}. This class is immutable. + */ +public class ZooKeeperServerConf { + /** + * The key in the map returned by {@link #toMap()} for the client port. + */ + public static final String KEY_CLIENT_PORT = "client_port"; + /** + * The key in the map returned by {@link #toMap()} for the data directory. + */ + public static final String KEY_DATA_DIR = "data_dir"; + /** + * The key in the map returned by {@link #toMap()} for the data log directory. + */ + public static final String KEY_DATA_LOG_DIR = "data_log_dir"; + /** + * The key in the map returned by {@link #toMap()} for the tick time. + */ + public static final String KEY_TICK_TIME = "tick_time"; + /** + * The key in the map returned by {@link #toMap()} for the maximum client connections per host. + */ + public static final String KEY_MAX_CLIENT_CNXNS = "max_client_cnxns"; + /** + * The key in the map returned by {@link #toMap()} for the minimum session timeout. + */ + public static final String KEY_MIN_SESSION_TIMEOUT = "min_session_timeout"; + /** + * The key in the map returned by {@link #toMap()} for the maximum session timeout. + */ + public static final String KEY_MAX_SESSION_TIMEOUT = "max_session_timeout"; + /** + * The key in the map returned by {@link #toMap()} for the server ID. + */ + public static final String KEY_SERVER_ID = "server_id"; + + private final int clientPort; + private final String dataDir; + private final String dataLogDir; + private final int tickTime; + private final int maxClientCnxnsPerHost; + private final int minSessionTimeout; + private final int maxSessionTimeout; + private final long serverId; + + /** + * Creates a new configuration. + * + * @param clientPort client port + * @param dataDir absolute path to data directory + * @param dataLogDir absolute path to data log directory + * @param tickTime tick time + * @param maxClientCnxnsPerHost maximum number of client connections + * @param minSessionTimeout minimum session timeout + * @param maxSessionTimeout maximum session timeout + * @param serverId server ID + */ + ZooKeeperServerConf(int clientPort, String dataDir, String dataLogDir, + int tickTime, int maxClientCnxnsPerHost, + int minSessionTimeout, int maxSessionTimeout, + long serverId) { + this.clientPort = clientPort; + this.dataDir = dataDir; + this.dataLogDir = dataLogDir; + this.tickTime = tickTime; + this.maxClientCnxnsPerHost = maxClientCnxnsPerHost; + this.minSessionTimeout = minSessionTimeout; + this.maxSessionTimeout = maxSessionTimeout; + this.serverId = serverId; + } + + /** + * Gets the client port. + * + * @return client port + */ + public int getClientPort() { + return clientPort; + } + + /** + * Gets the data directory. + * + * @return data directory + */ + public String getDataDir() { + return dataDir; + } + + /** + * Gets the data log directory. + * + * @return data log directory + */ + public String getDataLogDir() { + return dataLogDir; + } + + /** + * Gets the tick time. + * + * @return tick time + */ + public int getTickTime() { + return tickTime; + } + + /** + * Gets the maximum client connections per host. + * + * @return maximum client connections per host + */ + public int getMaxClientCnxnsPerHost() { + return maxClientCnxnsPerHost; + } + + /** + * Gets the minimum session timeout. + * + * @return minimum session timeout + */ + public int getMinSessionTimeout() { + return minSessionTimeout; + } + + /** + * Gets the maximum session timeout. + * + * @return maximum session timeout + */ + public int getMaxSessionTimeout() { + return maxSessionTimeout; + } + + /** + * Gets the server ID. + * + * @return server ID + */ + public long getServerId() { + return serverId; + } + + /** + * Converts this configuration to a map. The returned map is mutable, and changes to it do not reflect back into this configuration. + * + * @return map representation of configuration + */ + public Map toMap() { + Map conf = new LinkedHashMap(); + conf.put(KEY_CLIENT_PORT, clientPort); + conf.put(KEY_DATA_DIR, dataDir); + conf.put(KEY_DATA_LOG_DIR, dataLogDir); + conf.put(KEY_TICK_TIME, tickTime); + conf.put(KEY_MAX_CLIENT_CNXNS, maxClientCnxnsPerHost); + conf.put(KEY_MIN_SESSION_TIMEOUT, minSessionTimeout); + conf.put(KEY_MAX_SESSION_TIMEOUT, maxSessionTimeout); + conf.put(KEY_SERVER_ID, serverId); + return conf; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerListener.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerListener.java new file mode 100644 index 00000000000..bbf4bccb965 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerListener.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +/** + * Listener for the critical resource events. + */ +public interface ZooKeeperServerListener { + + /** + * This will notify the server that some critical thread has stopped. + * It usually takes place when fatal error occurred. + * + * @param threadName + * - name of the thread + * @param errorCode + * - error code + */ + void notifyStopping(String threadName, int errorCode); +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java new file mode 100644 index 00000000000..a7437927b4a --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java @@ -0,0 +1,138 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +/** + * ZooKeeper server MBean. + */ +public interface ZooKeeperServerMXBean { + /** + * @return the server socket port number + */ + public String getClientPort(); + + /** + * @return the zookeeper server version + */ + public String getVersion(); + + /** + * @return time the server was started + */ + public String getStartTime(); + + /** + * @return min request latency in ms + */ + public long getMinRequestLatency(); + + /** + * @return average request latency in ms + */ + public long getAvgRequestLatency(); + + /** + * @return max request latency in ms + */ + public long getMaxRequestLatency(); + + /** + * @return number of packets received so far + */ + public long getPacketsReceived(); + + /** + * @return number of packets sent so far + */ + public long getPacketsSent(); + + /** + * @return number of outstanding requests. + */ + public long getOutstandingRequests(); + + /** + * Current TickTime of server in milliseconds + */ + public int getTickTime(); + + /** + * Set TickTime of server in milliseconds + */ + public void setTickTime(int tickTime); + + /** Current maxClientCnxns allowed from a particular host */ + public int getMaxClientCnxnsPerHost(); + + /** Set maxClientCnxns allowed from a particular host */ + public void setMaxClientCnxnsPerHost(int max); + + /** + * Current minSessionTimeout of the server in milliseconds + */ + public int getMinSessionTimeout(); + + /** + * Set minSessionTimeout of server in milliseconds + */ + public void setMinSessionTimeout(int min); + + /** + * Current maxSessionTimeout of the server in milliseconds + */ + public int getMaxSessionTimeout(); + + /** + * Set maxSessionTimeout of server in milliseconds + */ + public void setMaxSessionTimeout(int max); + + /** + * Reset packet and latency statistics + */ + public void resetStatistics(); + + /** + * Reset min/avg/max latency statistics + */ + public void resetLatency(); + + /** + * Reset max latency statistics only. + */ + public void resetMaxLatency(); + + /** + * @return number of alive client connections + */ + public long getNumAliveConnections(); + + /** + * @return estimated size of data directory in bytes + */ + public long getDataDirSize(); + + /** + * @return estimated size of log directory in bytes + */ + public long getLogDirSize(); + + /** + * @return secure client port + */ + public String getSecureClientPort(); + + /** + * @return secure client address + */ + public String getSecureClientAddress(); +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java new file mode 100644 index 00000000000..4163656b715 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java @@ -0,0 +1,180 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.jmx.ManagedUtil; +import org.apache.zookeeper.server.admin.AdminServer; +import org.apache.zookeeper.server.admin.AdminServer.AdminServerException; +import org.apache.zookeeper.server.admin.AdminServerFactory; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog.DatadirException; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import javax.management.JMException; + +/** + * This class starts and runs a standalone ZooKeeperServer. + */ +public class ZooKeeperServerMain { + private static final Logger LOG = + LoggerFactory.getLogger(ZooKeeperServerMain.class); + + private static final String USAGE = + "Usage: ZooKeeperServerMain configfile | port datadir [ticktime] [maxcnxns]"; + + // ZooKeeper server supports two kinds of connection: unencrypted and encrypted. + private ServerCnxnFactory cnxnFactory; + private ServerCnxnFactory secureCnxnFactory; + private ContainerManager containerManager; + + private AdminServer adminServer; + + /* + * Start up the ZooKeeper server. + * + * @param args the configfile or the port datadir [ticktime] + */ + public static void main(String[] args) { + ZooKeeperServerMain main = new ZooKeeperServerMain(); + try { + main.initializeAndRun(args); + } catch (IllegalArgumentException e) { + LOG.error("Invalid arguments, exiting abnormally", e); + LOG.info(USAGE); + System.err.println(USAGE); + System.exit(2); + } catch (ConfigException e) { + LOG.error("Invalid config, exiting abnormally", e); + System.err.println("Invalid config, exiting abnormally"); + System.exit(2); + } catch (DatadirException e) { + LOG.error("Unable to access datadir, exiting abnormally", e); + System.err.println("Unable to access datadir, exiting abnormally"); + System.exit(3); + } catch (AdminServerException e) { + LOG.error("Unable to start AdminServer, exiting abnormally", e); + System.err.println("Unable to start AdminServer, exiting abnormally"); + System.exit(4); + } catch (Exception e) { + LOG.error("Unexpected exception, exiting abnormally", e); + System.exit(1); + } + LOG.info("Exiting normally"); + System.exit(0); + } + + protected void initializeAndRun(String[] args) + throws ConfigException, IOException, AdminServerException { + try { + ManagedUtil.registerLog4jMBeans(); + } catch (JMException e) { + LOG.warn("Unable to register log4j JMX control", e); + } + + ServerConfig config = new ServerConfig(); + if (args.length == 1) { + config.parse(args[0]); + } else { + config.parse(args); + } + + runFromConfig(config); + } + + /** + * Run from a ServerConfig. + * @param config ServerConfig to use. + * @throws IOException + * @throws AdminServerException + */ + public void runFromConfig(ServerConfig config) throws IOException, AdminServerException { + LOG.info("Starting server"); + FileTxnSnapLog txnLog = null; + try { + // Note that this thread isn't going to be doing anything else, + // so rather than spawning another thread, we will just call + // run() in this thread. + // create a file logger url from the command line args + txnLog = new FileTxnSnapLog(config.dataLogDir, config.dataDir); + ZooKeeperServer zkServer = new ZooKeeperServer(txnLog, + config.tickTime, config.minSessionTimeout, config.maxSessionTimeout, null); + + // Start Admin server + adminServer = AdminServerFactory.createAdminServer(); + adminServer.setZooKeeperServer(zkServer); + adminServer.start(); + + boolean needStartZKServer = true; + if (config.getClientPortAddress() != null) { + cnxnFactory = ServerCnxnFactory.createFactory(); + cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns(), false); + cnxnFactory.startup(zkServer); + // zkServer has been started. So we don't need to start it again in secureCnxnFactory. + needStartZKServer = false; + } + if (config.getSecureClientPortAddress() != null) { + secureCnxnFactory = ServerCnxnFactory.createFactory(); + secureCnxnFactory.configure(config.getSecureClientPortAddress(), config.getMaxClientCnxns(), true); + secureCnxnFactory.startup(zkServer, needStartZKServer); + } + + containerManager = new ContainerManager(zkServer.getZKDatabase(), zkServer.firstProcessor, + Integer.getInteger("znode.container.checkIntervalMs", (int) TimeUnit.MINUTES.toMillis(1)), + Integer.getInteger("znode.container.maxPerMinute", 10000) + ); + containerManager.start(); + + if (cnxnFactory != null) { + cnxnFactory.join(); + } + if (secureCnxnFactory != null) { + secureCnxnFactory.join(); + } + + if (zkServer.isRunning()) { + zkServer.shutdown(); + } + } catch (InterruptedException e) { + // warn, but generally this is ok + LOG.warn("Server interrupted", e); + } finally { + if (txnLog != null) { + txnLog.close(); + } + } + } + + /** + * Shutdown the serving instance + */ + protected void shutdown() { + if (containerManager != null) { + containerManager.stop(); + } + if (cnxnFactory != null) { + cnxnFactory.shutdown(); + } + if (secureCnxnFactory != null) { + secureCnxnFactory.shutdown(); + } + try { + adminServer.shutdown(); + } catch (AdminServerException e) { + LOG.warn("Problem stopping AdminServer", e); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java new file mode 100644 index 00000000000..3a7a13ae366 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperThread.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is the main class for catching all the uncaught exceptions thrown by the + * threads. + */ +public class ZooKeeperThread extends Thread { + + private static final Logger LOG = LoggerFactory + .getLogger(ZooKeeperThread.class); + + private UncaughtExceptionHandler uncaughtExceptionalHandler = new UncaughtExceptionHandler() { + + @Override + public void uncaughtException(Thread t, Throwable e) { + handleException(t.getName(), e); + } + }; + + public ZooKeeperThread(String threadName) { + super(threadName); + setUncaughtExceptionHandler(uncaughtExceptionalHandler); + } + + /** + * This will be used by the uncaught exception handler and just log a + * warning message and return. + * + * @param thName + * - thread name + * @param e + * - exception object + */ + protected void handleException(String thName, Throwable e) { + LOG.warn("Exception occured from thread {}", thName, e); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/ZooTrace.java b/src/java/main/org/apache/zookeeper/server/ZooTrace.java new file mode 100644 index 00000000000..83eec9c2096 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/ZooTrace.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.server.quorum.QuorumPacket; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class encapsulates and centralizes tracing for the ZooKeeper server. + * Trace messages go to the log with TRACE level. + *

        + * Log4j must be correctly configured to capture the TRACE messages. + */ +public class ZooTrace { + final static public long CLIENT_REQUEST_TRACE_MASK = 1 << 1; + + final static public long CLIENT_DATA_PACKET_TRACE_MASK = 1 << 2; + + final static public long CLIENT_PING_TRACE_MASK = 1 << 3; + + final static public long SERVER_PACKET_TRACE_MASK = 1 << 4; + + final static public long SESSION_TRACE_MASK = 1 << 5; + + final static public long EVENT_DELIVERY_TRACE_MASK = 1 << 6; + + final static public long SERVER_PING_TRACE_MASK = 1 << 7; + + final static public long WARNING_TRACE_MASK = 1 << 8; + + final static public long JMX_TRACE_MASK = 1 << 9; + + private static long traceMask = CLIENT_REQUEST_TRACE_MASK + | SERVER_PACKET_TRACE_MASK | SESSION_TRACE_MASK + | WARNING_TRACE_MASK; + + public static synchronized long getTextTraceLevel() { + return traceMask; + } + + public static synchronized void setTextTraceLevel(long mask) { + traceMask = mask; + final Logger LOG = LoggerFactory.getLogger(ZooTrace.class); + LOG.info("Set text trace mask to 0x" + Long.toHexString(mask)); + } + + public static synchronized boolean isTraceEnabled(Logger log, long mask) { + return log.isTraceEnabled() && (mask & traceMask) != 0; + } + + public static void logTraceMessage(Logger log, long mask, String msg) { + if (isTraceEnabled(log, mask)) { + log.trace(msg); + } + } + + static public void logQuorumPacket(Logger log, long mask, + char direction, QuorumPacket qp) { + return; + + // if (isTraceEnabled(log, mask)) { + // logTraceMessage(LOG, mask, direction + " " + // + FollowerHandler.packetToString(qp)); + // } + } + + static public void logRequest(Logger log, long mask, + char rp, Request request, String header) { + if (isTraceEnabled(log, mask)) { + log.trace(header + ":" + rp + request.toString()); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java b/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java new file mode 100644 index 00000000000..6a7e2cb8a1c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/AdminServer.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.server.ZooKeeperServer; + +/** + * Interface for an embedded admin server that runs Commands. There is only one + * functional implementation, JettyAdminServer. DummyAdminServer, which does + * nothing, is used when we do not wish to run a server. + */ +public interface AdminServer { + public void start() throws AdminServerException; + + public void shutdown() throws AdminServerException; + + public void setZooKeeperServer(ZooKeeperServer zkServer); + + public class AdminServerException extends Exception { + private static final long serialVersionUID = 1L; + + public AdminServerException(String message, Throwable cause) { + super(message, cause); + } + + public AdminServerException(Throwable cause) { + super(cause); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/AdminServerFactory.java b/src/java/main/org/apache/zookeeper/server/admin/AdminServerFactory.java new file mode 100644 index 00000000000..272ff649def --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/AdminServerFactory.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; + +/** + * Factory class for creating an AdminServer. + */ +public class AdminServerFactory { + private static final Logger LOG = LoggerFactory.getLogger(AdminServerFactory.class); + + /** + * This method encapsulates the logic for whether we should use a + * JettyAdminServer (i.e., the AdminServer is enabled) or a DummyAdminServer + * (i.e., the AdminServer is disabled). It uses reflection when attempting + * to create a JettyAdminServer, rather than referencing the class directly, + * so that it's ok to omit Jetty from the classpath if a user doesn't wish + * to pull in Jetty with ZooKeeper. + */ + public static AdminServer createAdminServer() { + if (!"false".equals(System.getProperty("zookeeper.admin.enableServer"))) { + try { + Class jettyAdminServerC = Class.forName("org.apache.zookeeper.server.admin.JettyAdminServer"); + Object adminServer = jettyAdminServerC.getConstructor().newInstance(); + return (AdminServer) adminServer; + + } catch (ClassNotFoundException e) { + LOG.warn("Unable to start JettyAdminServer", e); + } catch (InstantiationException e) { + LOG.warn("Unable to start JettyAdminServer", e); + } catch (IllegalAccessException e) { + LOG.warn("Unable to start JettyAdminServer", e); + } catch (InvocationTargetException e) { + LOG.warn("Unable to start JettyAdminServer", e); + } catch (NoSuchMethodException e) { + LOG.warn("Unable to start JettyAdminServer", e); + } catch (NoClassDefFoundError e) { + LOG.warn("Unable to load jetty, not starting JettyAdminServer", e); + } + } + return new DummyAdminServer(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/Command.java b/src/java/main/org/apache/zookeeper/server/admin/Command.java new file mode 100644 index 00000000000..e0f3ba342b1 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/Command.java @@ -0,0 +1,61 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.server.ZooKeeperServer; + +import java.util.Map; +import java.util.Set; + +/** + * Interface implemented by all commands runnable by JettyAdminServer. + * + * @see CommandBase + * @see Commands + * @see JettyAdminServer + */ +public interface Command { + /** + * The set of all names that can be used to refer to this command (e.g., + * "configuration", "config", and "conf"). + */ + Set getNames(); + + /** + * The name that is returned with the command response and that appears in + * the list of all commands. This should be a member of the set returned by + * getNames(). + */ + String getPrimaryName(); + + /** + * A string documentating this command (e.g., what it does, any arguments it + * takes). + */ + String getDoc(); + + /** + * Run this command. Commands take a ZooKeeperServer and String-valued + * keyword arguments and return a map containing any information + * constituting the response to the command. Commands are responsible for + * parsing keyword arguments and performing any error handling if necessary. + * Errors should be reported by setting the "error" entry of the returned + * map with an appropriate message rather than throwing an exception. + * + * @param zkServer + * @param kwargs keyword -> argument value mapping + * @return Map representing response to command containing at minimum: + * - "command" key containing the command's primary name + * - "error" key containing a String error message or null if no error + */ + CommandResponse run(ZooKeeperServer zkServer, Map kwargs); +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/CommandBase.java b/src/java/main/org/apache/zookeeper/server/admin/CommandBase.java new file mode 100644 index 00000000000..f0127512df3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/CommandBase.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public abstract class CommandBase implements Command { + private final String primaryName; + private final Set names; + private final String doc; + + /** + * @param names The possible names of this command, with the primary name first. + */ + protected CommandBase(List names) { + this(names, null); + } + + protected CommandBase(List names, String doc) { + this.primaryName = names.get(0); + this.names = new HashSet(names); + this.doc = doc; + } + + @Override + public String getPrimaryName() { + return primaryName; + } + + @Override + public Set getNames() { + return names; + } + + @Override + public String getDoc() { + return doc; + } + + /** + * @return A response with the command set to the primary name and the + * error set to null (these are the two entries that all command + * responses are required to include). + */ + protected CommandResponse initializeResponse() { + return new CommandResponse(primaryName); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/CommandOutputter.java b/src/java/main/org/apache/zookeeper/server/admin/CommandOutputter.java new file mode 100644 index 00000000000..16a94f62579 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/CommandOutputter.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import java.io.PrintWriter; + +/** + * CommandOutputters are used to format the responses from Commands. + * + * @see Command + * @see JettyAdminServer + */ +public interface CommandOutputter { + /** The MIME type of this output (e.g., "application/json") */ + String getContentType(); + + void output(CommandResponse response, PrintWriter pw); +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/CommandResponse.java b/src/java/main/org/apache/zookeeper/server/admin/CommandResponse.java new file mode 100644 index 00000000000..cd5d7ded9ac --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/CommandResponse.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A response from running a {@link Command}. + */ +public class CommandResponse { + + /** + * The key in the map returned by {@link #toMap()} for the command name. + */ + public static final String KEY_COMMAND = "command"; + /** + * The key in the map returned by {@link #toMap()} for the error string. + */ + public static final String KEY_ERROR = "error"; + + private final String command; + private final String error; + private final Map data; + + /** + * Creates a new response with no error string. + * + * @param command command name + */ + public CommandResponse(String command) { + this(command, null); + } + + /** + * Creates a new response. + * + * @param command command name + * @param error error string (may be null) + */ + public CommandResponse(String command, String error) { + this.command = command; + this.error = error; + data = new LinkedHashMap(); + } + + /** + * Gets the command name. + * + * @return command name + */ + public String getCommand() { + return command; + } + + /** + * Gets the error string (may be null). + * + * @return error string + */ + public String getError() { + return error; + } + + /** + * Adds a key/value pair to this response. + * + * @param key key + * @param value value + * @return prior value for key, or null if none + */ + public Object put(String key, Object value) { + return data.put(key, value); + } + + /** + * Adds all key/value pairs in the given map to this response. + * + * @param m map of key/value pairs + */ + public void putAll(Map m) { + data.putAll(m); + } + + /** + * Converts this response to a map. The returned map is mutable, and changes to it do not reflect back into this response. + * + * @return map representation of response + */ + public Map toMap() { + Map m = new LinkedHashMap(data); + m.put(KEY_COMMAND, command); + m.put(KEY_ERROR, error); + m.putAll(data); + return m; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/Commands.java b/src/java/main/org/apache/zookeeper/server/admin/Commands.java new file mode 100644 index 00000000000..7a2ea71205e --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/Commands.java @@ -0,0 +1,507 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.Environment; +import org.apache.zookeeper.Environment.Entry; +import org.apache.zookeeper.Version; +import org.apache.zookeeper.server.DataTree; +import org.apache.zookeeper.server.ServerStats; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.server.quorum.Leader; +import org.apache.zookeeper.server.quorum.LeaderZooKeeperServer; +import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer; +import org.apache.zookeeper.server.util.OSMXBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Class containing static methods for registering and running Commands, as well + * as default Command definitions. + * + * @see Command + * @see JettyAdminServer + */ +public class Commands { + static final Logger LOG = LoggerFactory.getLogger(Commands.class); + + /** Maps command names to Command instances */ + private static Map commands = new HashMap(); + private static Set primaryNames = new HashSet(); + + static { + registerCommand(new CnxnStatResetCommand()); + registerCommand(new ConfCommand()); + registerCommand(new ConsCommand()); + registerCommand(new DirsCommand()); + registerCommand(new DumpCommand()); + registerCommand(new EnvCommand()); + registerCommand(new GetTraceMaskCommand()); + registerCommand(new IsroCommand()); + registerCommand(new MonitorCommand()); + registerCommand(new RuokCommand()); + registerCommand(new SetTraceMaskCommand()); + registerCommand(new SrvrCommand()); + registerCommand(new StatCommand()); + registerCommand(new StatResetCommand()); + registerCommand(new WatchCommand()); + registerCommand(new WatchesByPathCommand()); + registerCommand(new WatchSummaryCommand()); + } + + private Commands() { + } + + /** + * Registers the given command. Registered commands can be run by passing + * any of their names to runCommand. + */ + public static void registerCommand(Command command) { + for (String name : command.getNames()) { + Command prev = commands.put(name, command); + if (prev != null) { + LOG.warn("Re-registering command %s (primary name = %s)", name, command.getPrimaryName()); + } + } + primaryNames.add(command.getPrimaryName()); + } + + /** + * Run the registered command with name cmdName. Commands should not produce + * any exceptions; any (anticipated) errors should be reported in the + * "error" entry of the returned map. Likewise, if no command with the given + * name is registered, this will be noted in the "error" entry. + * + * @param cmdName + * @param zkServer + * @param kwargs String-valued keyword arguments to the command + * (may be null if command requires no additional arguments) + * @return Map representing response to command containing at minimum: + * - "command" key containing the command's primary name + * - "error" key containing a String error message or null if no error + */ + public static CommandResponse runCommand(String cmdName, ZooKeeperServer zkServer, Map kwargs) { + if (!commands.containsKey(cmdName)) { + return new CommandResponse(cmdName, "Unknown command: " + cmdName); + } + if (zkServer == null) { + return new CommandResponse(cmdName, "This ZooKeeper instance is not currently serving requests"); + } + return commands.get(cmdName).run(zkServer, kwargs); + } + + /** + * Returns the primary names of all registered commands. + */ + public static Set getPrimaryNames() { + return primaryNames; + } + + /** + * Returns the commands registered under cmdName with registerCommand, or + * null if no command is registered with that name. + */ + public static Command getCommand(String cmdName) { + return commands.get(cmdName); + } + + /** + * Reset all connection statistics. + */ + public static class CnxnStatResetCommand extends CommandBase { + public CnxnStatResetCommand() { + super(Arrays.asList("connection_stat_reset", "crst")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + zkServer.getServerCnxnFactory().resetAllConnectionStats(); + return response; + + } + } + + /** + * Server configuration parameters. + * @see ZooKeeperServer#getConf() + */ + public static class ConfCommand extends CommandBase { + public ConfCommand() { + super(Arrays.asList("configuration", "conf", "config")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + response.putAll(zkServer.getConf().toMap()); + return response; + } + } + + /** + * Information on client connections to server. Returned Map contains: + * - "connections": list of connection info objects + * @see org.apache.zookeeper.server.ServerCnxn#getConnectionInfo(boolean) + */ + public static class ConsCommand extends CommandBase { + public ConsCommand() { + super(Arrays.asList("connections", "cons")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + response.put("connections", zkServer.getServerCnxnFactory().getAllConnectionInfo(false)); + return response; + } + } + + /** + * Information on ZK datadir and snapdir size in bytes + */ + public static class DirsCommand extends CommandBase { + public DirsCommand() { + super(Arrays.asList("dirs")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + response.put("datadir_size", zkServer.getDataDirSize()); + response.put("logdir_size", zkServer.getLogDirSize()); + return response; + } + } + + /** + * Information on session expirations and ephemerals. Returned map contains: + * - "expiry_time_to_session_ids": Map> + * time -> sessions IDs of sessions that expire at time + * - "sesssion_id_to_ephemeral_paths": Map> + * session ID -> ephemeral paths created by that session + * @see ZooKeeperServer#getSessionExpiryMap() + * @see ZooKeeperServer#getEphemerals() + */ + public static class DumpCommand extends CommandBase { + public DumpCommand() { + super(Arrays.asList("dump")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + response.put("expiry_time_to_session_ids", zkServer.getSessionExpiryMap()); + response.put("session_id_to_ephemeral_paths", zkServer.getEphemerals()); + return response; + } + } + + /** + * All defined environment variables. + */ + public static class EnvCommand extends CommandBase { + public EnvCommand() { + super(Arrays.asList("environment", "env", "envi")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + for (Entry e : Environment.list()) { + response.put(e.getKey(), e.getValue()); + } + return response; + } + } + + /** + * The current trace mask. Returned map contains: + * - "tracemask": Long + */ + public static class GetTraceMaskCommand extends CommandBase { + public GetTraceMaskCommand() { + super(Arrays.asList("get_trace_mask", "gtmk")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + response.put("tracemask", ZooTrace.getTextTraceLevel()); + return response; + } + } + + /** + * Is this server in read-only mode. Returned map contains: + * - "is_read_only": Boolean + */ + public static class IsroCommand extends CommandBase { + public IsroCommand() { + super(Arrays.asList("is_read_only", "isro")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + response.put("read_only", zkServer instanceof ReadOnlyZooKeeperServer); + return response; + } + } + + /** + * Some useful info for monitoring. Returned map contains: + * - "version": String + * server version + * - "avg_latency": Long + * - "max_latency": Long + * - "min_latency": Long + * - "packets_received": Long + * - "packets_sents": Long + * - "num_alive_connections": Integer + * - "outstanding_requests": Long + * number of unprocessed requests + * - "server_state": "leader", "follower", or "standalone" + * - "znode_count": Integer + * - "watch_count": Integer + * - "ephemerals_count": Integer + * - "approximate_data_size": Long + * - "open_file_descriptor_count": Long (unix only) + * - "max_file_descritpor_count": Long (unix only) + * - "followers": Integer (leader only) + * - "synced_followers": Integer (leader only) + * - "pending_syncs": Integer (leader only) + */ + public static class MonitorCommand extends CommandBase { + public MonitorCommand() { + super(Arrays.asList("monitor", "mntr")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + ZKDatabase zkdb = zkServer.getZKDatabase(); + ServerStats stats = zkServer.serverStats(); + + CommandResponse response = initializeResponse(); + + response.put("version", Version.getFullVersion()); + + response.put("avg_latency", stats.getAvgLatency()); + response.put("max_latency", stats.getMaxLatency()); + response.put("min_latency", stats.getMinLatency()); + + response.put("packets_received", stats.getPacketsReceived()); + response.put("packets_sent", stats.getPacketsSent()); + response.put("num_alive_connections", stats.getNumAliveClientConnections()); + + response.put("outstanding_requests", stats.getOutstandingRequests()); + + response.put("server_state", stats.getServerState()); + response.put("znode_count", zkdb.getNodeCount()); + + response.put("watch_count", zkdb.getDataTree().getWatchCount()); + response.put("ephemerals_count", zkdb.getDataTree().getEphemeralsCount()); + response.put("approximate_data_size", zkdb.getDataTree().approximateDataSize()); + + OSMXBean osMbean = new OSMXBean(); + response.put("open_file_descriptor_count", osMbean.getOpenFileDescriptorCount()); + response.put("max_file_descriptor_count", osMbean.getMaxFileDescriptorCount()); + + if (zkServer instanceof LeaderZooKeeperServer) { + Leader leader = ((LeaderZooKeeperServer) zkServer).getLeader(); + + response.put("followers", leader.getLearners().size()); + response.put("synced_followers", leader.getForwardingFollowers().size()); + response.put("pending_syncs", leader.getNumPendingSyncs()); + } + + return response; + + } + } + + /** + * No-op command, check if the server is running + */ + public static class RuokCommand extends CommandBase { + public RuokCommand() { + super(Arrays.asList("ruok")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + return initializeResponse(); + } + } + + /** + * Sets the trace mask. Required arguments: + * - "traceMask": Long + * Returned Map contains: + * - "tracemask": Long + */ + public static class SetTraceMaskCommand extends CommandBase { + public SetTraceMaskCommand() { + super(Arrays.asList("set_trace_mask", "stmk")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + long traceMask; + if (!kwargs.containsKey("traceMask")) { + response.put("error", "setTraceMask requires long traceMask argument"); + return response; + } + try { + traceMask = Long.parseLong(kwargs.get("traceMask")); + } catch (NumberFormatException e) { + response.put("error", "setTraceMask requires long traceMask argument, got " + + kwargs.get("traceMask")); + return response; + } + + ZooTrace.setTextTraceLevel(traceMask); + response.put("tracemask", traceMask); + return response; + } + } + + /** + * Server information. Returned map contains: + * - "version": String + * version of server + * - "read_only": Boolean + * is server in read-only mode + * - "server_stats": ServerStats object + * - "node_count": Integer + */ + public static class SrvrCommand extends CommandBase { + public SrvrCommand() { + super(Arrays.asList("server_stats", "srvr")); + } + + // Allow subclasses (e.g. StatCommand) to specify their own names + protected SrvrCommand(List names) { + super(names); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + LOG.info("running stat"); + response.put("version", Version.getFullVersion()); + response.put("read_only", zkServer instanceof ReadOnlyZooKeeperServer); + response.put("server_stats", zkServer.serverStats()); + response.put("node_count", zkServer.getZKDatabase().getNodeCount()); + return response; + + } + } + + /** + * Same as SrvrCommand but has extra "connections" entry. + */ + public static class StatCommand extends SrvrCommand { + public StatCommand() { + super(Arrays.asList("stats", "stat")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = super.run(zkServer, kwargs); + response.put("connections", zkServer.getServerCnxnFactory().getAllConnectionInfo(true)); + return response; + } + } + + /** + * Resets server statistics. + */ + public static class StatResetCommand extends CommandBase { + public StatResetCommand() { + super(Arrays.asList("stat_reset", "srst")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + CommandResponse response = initializeResponse(); + zkServer.serverStats().reset(); + return response; + } + } + + /** + * Watch information aggregated by session. Returned Map contains: + * - "session_id_to_watched_paths": Map> session ID -> watched paths + * @see DataTree#getWatches() + */ + public static class WatchCommand extends CommandBase { + public WatchCommand() { + super(Arrays.asList("watches", "wchc")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + DataTree dt = zkServer.getZKDatabase().getDataTree(); + CommandResponse response = initializeResponse(); + response.put("session_id_to_watched_paths", dt.getWatches().toMap()); + return response; + } + } + + /** + * Watch information aggregated by path. Returned Map contains: + * - "path_to_session_ids": Map> path -> session IDs of sessions watching path + * @see DataTree#getWatchesByPath() + */ + public static class WatchesByPathCommand extends CommandBase { + public WatchesByPathCommand() { + super(Arrays.asList("watches_by_path", "wchp")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + DataTree dt = zkServer.getZKDatabase().getDataTree(); + CommandResponse response = initializeResponse(); + response.put("path_to_session_ids", dt.getWatchesByPath().toMap()); + return response; + } + } + + /** + * Summarized watch information. + * @see DataTree#getWatchesSummary() + */ + public static class WatchSummaryCommand extends CommandBase { + public WatchSummaryCommand() { + super(Arrays.asList("watch_summary", "wchs")); + } + + @Override + public CommandResponse run(ZooKeeperServer zkServer, Map kwargs) { + DataTree dt = zkServer.getZKDatabase().getDataTree(); + CommandResponse response = initializeResponse(); + response.putAll(dt.getWatchesSummary().toMap()); + return response; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/DummyAdminServer.java b/src/java/main/org/apache/zookeeper/server/admin/DummyAdminServer.java new file mode 100644 index 00000000000..aba4d56a3c7 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/DummyAdminServer.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.server.ZooKeeperServer; + +/** + * An AdminServer that does nothing. + * + * We use this class when we wish to disable the AdminServer. (This way we only + * have to consider whether the server is enabled when we create the + * AdminServer, which is handled by AdminServerFactory.) + */ +public class DummyAdminServer implements AdminServer { + @Override + public void start() throws AdminServerException { + } + + @Override + public void shutdown() throws AdminServerException { + } + + @Override + public void setZooKeeperServer(ZooKeeperServer zkServer) { + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java b/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java new file mode 100644 index 00000000000..74b8bbe0274 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java @@ -0,0 +1,182 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.server.ZooKeeperServer; +import org.mortbay.jetty.Server; +import org.mortbay.jetty.nio.SelectChannelConnector; +import org.mortbay.jetty.servlet.Context; +import org.mortbay.jetty.servlet.ServletHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * This class encapsulates a Jetty server for running Commands. + * + * Given the default settings, start a ZooKeeper server and visit + * http://:8080/commands for links to all registered commands. Visiting + * http://:8080/commands/ will execute the associated + * Command and return the result in the body of the response. Any keyword + * arguments to the command are specified with URL parameters (e.g., + * http://localhost:8080/commands/set_trace_mask?traceMask=306). + * + * @see Commands + * @see CommandOutputter + */ +public class JettyAdminServer implements AdminServer { + public static final int DEFAULT_PORT = 8080; + public static final String DEFAULT_COMMAND_URL = "/commands"; + static final Logger LOG = LoggerFactory.getLogger(JettyAdminServer.class); + private static final String DEFAULT_ADDRESS = "0.0.0.0"; + private final Server server; + private final int port; + private final String commandUrl; + private ZooKeeperServer zkServer; + private String address; + + public JettyAdminServer() throws AdminServerException { + this(System.getProperty("zookeeper.admin.serverAddress", + DEFAULT_ADDRESS), Integer.getInteger( + "zookeeper.admin.serverPort", DEFAULT_PORT), System + .getProperty("zookeeper.admin.commandURL", DEFAULT_COMMAND_URL)); + } + + public JettyAdminServer(String address, int port, String commandUrl) { + this.port = port; + this.commandUrl = commandUrl; + this.address = address; + + server = new Server(); + SelectChannelConnector connector = new SelectChannelConnector(); + connector.setHost(address); + connector.setPort(port); + server.addConnector(connector); + Context context = new Context(server, "/"); + server.setHandler(context); + context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + + "/*"); + } + + /** + * Start the embedded Jetty server. + */ + @Override + public void start() throws AdminServerException { + try { + server.start(); + } catch (Exception e) { + // Server.start() only throws Exception, so let's at least wrap it + // in an identifiable subclass + throw new AdminServerException(String.format( + "Problem starting AdminServer on address %s," + + " port %d and command URL %s", address, port, + commandUrl), e); + } + LOG.info(String.format("Started AdminServer on address %s, port %d" + + " and command URL %s", address, port, commandUrl)); + } + + /** + * Stop the embedded Jetty server. + * + * This is not very important except for tests where multiple + * JettyAdminServers are started and may try to bind to the same ports if + * previous servers aren't shut down. + */ + @Override + public void shutdown() throws AdminServerException { + try { + server.stop(); + } catch (Exception e) { + throw new AdminServerException(String.format( + "Problem stopping AdminServer on address %s," + + " port %d and command URL %s", address, port, commandUrl), + e); + } + } + + /** + * Set the ZooKeeperServer that will be used to run Commands. + * + * It is not necessary to set the ZK server before calling + * AdminServer.start(), and the ZK server can be set to null when, e.g., + * that server is being shut down. If the ZK server is not set or set to + * null, the AdminServer will still be able to issue Commands, but they will + * return an error until a ZK server is set. + */ + @Override + public void setZooKeeperServer(ZooKeeperServer zkServer) { + this.zkServer = zkServer; + } + + /** + * Returns a list of URLs to each registered Command. + */ + private List commandLinks() { + List links = new ArrayList(); + List commands = new ArrayList(Commands.getPrimaryNames()); + Collections.sort(commands); + for (String command : commands) { + String url = commandUrl + "/" + command; + links.add(String.format("%s", url, command)); + } + return links; + } + + private class CommandServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Capture the command name from the URL + String cmd = request.getPathInfo(); + if (cmd == null || cmd.equals("/")) { + // No command specified, print links to all commands instead + for (String link : commandLinks()) { + response.getWriter().println(link); + response.getWriter().println("
        "); + } + return; + } + // Strip leading "/" + cmd = cmd.substring(1); + + // Extract keyword arguments to command from request parameters + @SuppressWarnings("unchecked") + Map parameterMap = request.getParameterMap(); + Map kwargs = new HashMap(); + for (Map.Entry entry : parameterMap.entrySet()) { + kwargs.put(entry.getKey(), entry.getValue()[0]); + } + + // Run the command + CommandResponse cmdResponse = Commands.runCommand(cmd, zkServer, kwargs); + + // Format and print the output of the command + CommandOutputter outputter = new JsonOutputter(); + response.setStatus(HttpServletResponse.SC_OK); + response.setContentType(outputter.getContentType()); + outputter.output(cmdResponse, response.getWriter()); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java b/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java new file mode 100644 index 00000000000..22bbf2fcba8 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.PropertyNamingStrategy; +import org.codehaus.jackson.map.SerializationConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.PrintWriter; + +public class JsonOutputter implements CommandOutputter { + public static final String ERROR_RESPONSE = "{\"error\": \"Exception writing command response to JSON\"}"; + static final Logger LOG = LoggerFactory.getLogger(JsonOutputter.class); + private ObjectMapper mapper; + + public JsonOutputter() { + mapper = new ObjectMapper(); + mapper.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true); + mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); + mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); + } + + @Override + public String getContentType() { + return "application/json"; + } + + @Override + public void output(CommandResponse response, PrintWriter pw) { + try { + mapper.writeValue(pw, response.toMap()); + } catch (JsonGenerationException e) { + LOG.warn("Exception writing command response to JSON:", e); + pw.write(ERROR_RESPONSE); + } catch (JsonMappingException e) { + LOG.warn("Exception writing command response to JSON:", e); + pw.write(ERROR_RESPONSE); + } catch (IOException e) { + LOG.warn("Exception writing command response to JSON:", e); + pw.write(ERROR_RESPONSE); + } + } + +} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/AuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java similarity index 67% rename from zookeeper/java/src/com/yahoo/zookeeper/server/auth/AuthenticationProvider.java rename to src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java index f518d7f439d..e08dc115ef4 100644 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/AuthenticationProvider.java +++ b/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java @@ -1,22 +1,18 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.zookeeper.server.auth; +package org.apache.zookeeper.server.auth; -import com.yahoo.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.server.ServerCnxn; /** * This interface is implemented by authentication providers to add new kinds of @@ -26,7 +22,7 @@ public interface AuthenticationProvider { /** * The String used to represent this provider. This will correspond to the * scheme field of an Id. - * + * * @return the scheme of this provider. */ String getScheme(); @@ -36,20 +32,20 @@ public interface AuthenticationProvider { * scheme. The authData is directly from the authentication packet. The * implementor may attach new ids to the authInfo field of cnxn or may use * cnxn to send packets back to the client. - * + * * @param cnxn * the cnxn that received the authentication information. * @param authData * the authentication data received. * @return TODO */ - int handleAuthentication(ServerCnxn cnxn, byte authData[]); + KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte authData[]); /** * This method is called to see if the given id matches the given id * expression in the ACL. This allows schemes to use application specific * wild cards. - * + * * @param id * the id to check. * @param aclExpr @@ -63,14 +59,14 @@ public interface AuthenticationProvider { * should be used to identify the creator of a node. Some ids such as hosts * and ip addresses are rather transient and in general don't really * identify a client even though sometimes they do. - * + * * @return true if this provider identifies creators. */ boolean isAuthenticated(); /** * Validates the syntax of an id. - * + * * @param id * the id to validate. * @return true if id is well formed. diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/DigestAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java similarity index 52% rename from zookeeper/java/src/com/yahoo/zookeeper/server/auth/DigestAuthenticationProvider.java rename to src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java index dd45aecfec0..94e163319e9 100644 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/DigestAuthenticationProvider.java +++ b/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java @@ -1,40 +1,40 @@ -/* - * Copyright 2008, Yahoo! Inc. +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.zookeeper.server.auth; +package org.apache.zookeeper.server.auth; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.server.ServerCnxn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.server.ServerCnxn; -import com.yahoo.zookeeper.server.ZooLog; - public class DigestAuthenticationProvider implements AuthenticationProvider { - public static String superDigest = "super:1wZ8qIvQBMTq0KPxMc6RQ/PCXKM="; + private static final Logger LOG = + LoggerFactory.getLogger(DigestAuthenticationProvider.class); - public String getScheme() { - return "digest"; - } + /** specify a command line property with key of + * "zookeeper.DigestAuthenticationProvider.superDigest" + * and value of "super:" to enable + * super user access (i.e. acls disabled) + */ + private final static String superDigest = System.getProperty( + "zookeeper.DigestAuthenticationProvider.superDigest"); static final private String base64Encode(byte b[]) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < b.length;) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < b.length; ) { int pad = 0; int v = (b[i++] & 0xff) << 16; if (i < b.length) { @@ -85,19 +85,35 @@ static public String generateDigest(String idPassword) return parts[0] + ":" + base64Encode(digest); } - public int handleAuthentication(ServerCnxn cnxn, byte[] authData) { + /** Call with a single argument of user:pass to generate authdata. + * Authdata output can be used when setting superDigest for example. + * @param args single argument of user:pass + * @throws NoSuchAlgorithmException + */ + public static void main(String args[]) throws NoSuchAlgorithmException { + for (int i = 0; i < args.length; i++) { + System.out.println(args[i] + "->" + generateDigest(args[i])); + } + } + + public String getScheme() { + return "digest"; + } + + public KeeperException.Code + handleAuthentication(ServerCnxn cnxn, byte[] authData) { String id = new String(authData); try { String digest = generateDigest(id); if (digest.equals(superDigest)) { - cnxn.getAuthInfo().add(new Id("super", "")); + cnxn.addAuthInfo(new Id("super", "")); } - cnxn.getAuthInfo().add(new Id(getScheme(), digest)); - return KeeperException.Code.Ok; + cnxn.addAuthInfo(new Id(getScheme(), digest)); + return KeeperException.Code.OK; } catch (NoSuchAlgorithmException e) { - ZooLog.logException(e); + LOG.error("Missing algorithm", e); } - return KeeperException.Code.AuthFailed; + return KeeperException.Code.AUTHFAILED; } public boolean isAuthenticated() { @@ -112,11 +128,4 @@ public boolean isValid(String id) { public boolean matches(String id, String aclExpr) { return id.equals(aclExpr); } - - public static void main(String args[]) throws IOException, - NoSuchAlgorithmException { - for (int i = 0; i < args.length; i++) { - System.out.println(args[i] + "->" + generateDigest(args[i])); - } - } } diff --git a/src/java/main/org/apache/zookeeper/server/auth/DigestLoginModule.java b/src/java/main/org/apache/zookeeper/server/auth/DigestLoginModule.java new file mode 100644 index 00000000000..8f90b6ab8a3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/auth/DigestLoginModule.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.auth; + +import java.util.Map; + +import javax.security.auth.Subject; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.spi.LoginModule; + +public class DigestLoginModule implements LoginModule { + private Subject subject; + + public boolean abort() { + return false; + } + + public boolean commit() { + return true; + } + + public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { + if (options.containsKey("username")) { + // Zookeeper client: get username and password from JAAS conf (only used if using DIGEST-MD5). + this.subject = subject; + String username = (String) options.get("username"); + this.subject.getPublicCredentials().add((Object) username); + String password = (String) options.get("password"); + this.subject.getPrivateCredentials().add((Object) password); + } + return; + } + + public boolean logout() { + return true; + } + + public boolean login() { + // Unlike with Krb5LoginModule, we don't do any actual login or credential passing here: authentication to Zookeeper + // is done later, through the SASLClient object. + return true; + } + +} + + diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/IPAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java similarity index 59% rename from zookeeper/java/src/com/yahoo/zookeeper/server/auth/IPAuthenticationProvider.java rename to src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java index 28b6ccc7e30..4bad45fd86c 100644 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/IPAuthenticationProvider.java +++ b/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java @@ -1,24 +1,19 @@ -/* - * Copyright 2008, Yahoo! Inc. +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.yahoo.zookeeper.server.auth; +package org.apache.zookeeper.server.auth; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.server.ServerCnxn; public class IPAuthenticationProvider implements AuthenticationProvider { @@ -26,10 +21,11 @@ public String getScheme() { return "ip"; } - public int handleAuthentication(ServerCnxn cnxn, byte[] authData) { - String id = cnxn.getRemoteAddress().getAddress().getHostAddress(); - cnxn.getAuthInfo().add(new Id(getScheme(), id)); - return KeeperException.Code.Ok; + public KeeperException.Code + handleAuthentication(ServerCnxn cnxn, byte[] authData) { + String id = cnxn.getRemoteSocketAddress().getAddress().getHostAddress(); + cnxn.addAuthInfo(new Id(getScheme(), id)); + return KeeperException.Code.OK; } // This is a bit weird but we need to return the address and the number of @@ -108,6 +104,21 @@ public boolean isAuthenticated() { } public boolean isValid(String id) { - return addr2Bytes(id) != null; + String parts[] = id.split("/", 2); + byte aclAddr[] = addr2Bytes(parts[0]); + if (aclAddr == null) { + return false; + } + if (parts.length == 2) { + try { + int bits = Integer.parseInt(parts[1]); + if (bits < 0 || bits > aclAddr.length * 8) { + return false; + } + } catch (NumberFormatException e) { + return false; + } + } + return true; } } diff --git a/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java b/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java new file mode 100644 index 00000000000..bb9a5b581a6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java @@ -0,0 +1,405 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + + /* This file copied from Hadoop's security branch, + * with the following changes: + * 1. package changed from org.apache.hadoop.security to + * org.apache.zookeeper.server.auth. + * 2. Usage of Hadoop's Configuration class removed since + * it is not available in Zookeeper: instead, system property + * "zookeeper.security.auth_to_local" is used. + */ + +package org.apache.zookeeper.server.auth; + +import org.apache.zookeeper.server.util.KerberosUtil; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * This class implements parsing and handling of Kerberos principal names. In + * particular, it splits them apart and translates them down into local + * operating system names. + */ +public class KerberosName { + /** + * A pattern that matches a Kerberos name with at most 2 components. + */ + private static final Pattern nameParser = + Pattern.compile("([^/@]*)(/([^/@]*))?@([^/@]*)"); + /** + * A pattern for parsing a auth_to_local rule. + */ + private static final Pattern ruleParser = + Pattern.compile("\\s*((DEFAULT)|(RULE:\\[(\\d*):([^\\]]*)](\\(([^)]*)\\))?" + + "(s/([^/]*)/([^/]*)/(g)?)?))"); + /** + * A pattern that recognizes simple/non-simple names. + */ + private static final Pattern nonSimplePattern = Pattern.compile("[/@]"); + /** + * A pattern that matches a string with out '$' and then a single + * parameter with $n. + */ + private static Pattern parameterPattern = + Pattern.compile("([^$]*)(\\$(\\d*))?"); + /** + * The list of translation rules. + */ + private static List rules; + private static String defaultRealm; + + static { + try { + defaultRealm = KerberosUtil.getDefaultRealm(); + } catch (Exception ke) { + if ((System.getProperty("zookeeper.requireKerberosConfig") != null) && + (System.getProperty("zookeeper.requireKerberosConfig").equals("true"))) { + throw new IllegalArgumentException("Can't get Kerberos configuration", ke); + } else + defaultRealm = ""; + } + try { + // setConfiguration() will work even if the above try() fails due + // to a missing Kerberos configuration (unless zookeeper.requireKerberosConfig + // is set to true, which would not allow execution to reach here due to the + // throwing of an IllegalArgumentException above). + setConfiguration(); + } catch (IOException e) { + throw new IllegalArgumentException("Could not configure Kerberos principal name mapping."); + } + } + + /** The first component of the name */ + private final String serviceName; + /** The second component of the name. It may be null. */ + private final String hostName; + /** The realm of the name. */ + private final String realm; + + /** + * Create a name from the full Kerberos principal name. + * @param name + */ + public KerberosName(String name) { + Matcher match = nameParser.matcher(name); + if (!match.matches()) { + if (name.contains("@")) { + throw new IllegalArgumentException("Malformed Kerberos name: " + name); + } else { + serviceName = name; + hostName = null; + realm = null; + } + } else { + serviceName = match.group(1); + hostName = match.group(3); + realm = match.group(4); + } + } + + static List parseRules(String rules) { + List result = new ArrayList(); + String remaining = rules.trim(); + while (remaining.length() > 0) { + Matcher matcher = ruleParser.matcher(remaining); + if (!matcher.lookingAt()) { + throw new IllegalArgumentException("Invalid rule: " + remaining); + } + if (matcher.group(2) != null) { + result.add(new Rule()); + } else { + result.add(new Rule(Integer.parseInt(matcher.group(4)), + matcher.group(5), + matcher.group(7), + matcher.group(9), + matcher.group(10), + "g".equals(matcher.group(11)))); + } + remaining = remaining.substring(matcher.end()); + } + return result; + } + + /** + * Set the static configuration to get the rules. + * @param conf the new configuration + * @throws IOException + */ + public static void setConfiguration() throws IOException { + String ruleString = System.getProperty("zookeeper.security.auth_to_local", "DEFAULT"); + rules = parseRules(ruleString); + } + + static void printRules() throws IOException { + int i = 0; + for (Rule r : rules) { + System.out.println(++i + " " + r); + } + } + + public static void main(String[] args) throws Exception { + for (String arg : args) { + KerberosName name = new KerberosName(arg); + System.out.println("Name: " + name + " to " + name.getShortName()); + } + } + + /** + * Get the configured default realm. + * @return the default realm from the krb5.conf + */ + public String getDefaultRealm() { + return defaultRealm; + } + + /** + * Put the name back together from the parts. + */ + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + result.append(serviceName); + if (hostName != null) { + result.append('/'); + result.append(hostName); + } + if (realm != null) { + result.append('@'); + result.append(realm); + } + return result.toString(); + } + + /** + * Get the first component of the name. + * @return the first section of the Kerberos principal name + */ + public String getServiceName() { + return serviceName; + } + + /** + * Get the second component of the name. + * @return the second section of the Kerberos principal name, and may be null + */ + public String getHostName() { + return hostName; + } + + /** + * Get the realm of the name. + * @return the realm of the name, may be null + */ + public String getRealm() { + return realm; + } + + /** + * Get the translation of the principal name into an operating system + * user name. + * @return the short name + * @throws IOException + */ + public String getShortName() throws IOException { + String[] params; + if (hostName == null) { + // if it is already simple, just return it + if (realm == null) { + return serviceName; + } + params = new String[]{realm, serviceName}; + } else { + params = new String[]{realm, serviceName, hostName}; + } + for (Rule r : rules) { + String result = r.apply(params); + if (result != null) { + return result; + } + } + throw new NoMatchingRule("No rules applied to " + toString()); + } + + /** + * An encoding of a rule for translating kerberos names. + */ + private static class Rule { + private final boolean isDefault; + private final int numOfComponents; + private final String format; + private final Pattern match; + private final Pattern fromPattern; + private final String toPattern; + private final boolean repeat; + + Rule() { + isDefault = true; + numOfComponents = 0; + format = null; + match = null; + fromPattern = null; + toPattern = null; + repeat = false; + } + + Rule(int numOfComponents, String format, String match, String fromPattern, + String toPattern, boolean repeat) { + isDefault = false; + this.numOfComponents = numOfComponents; + this.format = format; + this.match = match == null ? null : Pattern.compile(match); + this.fromPattern = + fromPattern == null ? null : Pattern.compile(fromPattern); + this.toPattern = toPattern; + this.repeat = repeat; + } + + /** + * Replace the numbered parameters of the form $n where n is from 1 to + * the length of params. Normal text is copied directly and $n is replaced + * by the corresponding parameter. + * @param format the string to replace parameters again + * @param params the list of parameters + * @return the generated string with the parameter references replaced. + * @throws BadFormatString + */ + static String replaceParameters(String format, + String[] params) throws BadFormatString { + Matcher match = parameterPattern.matcher(format); + int start = 0; + StringBuilder result = new StringBuilder(); + while (start < format.length() && match.find(start)) { + result.append(match.group(1)); + String paramNum = match.group(3); + if (paramNum != null) { + try { + int num = Integer.parseInt(paramNum); + if (num < 0 || num > params.length) { + throw new BadFormatString("index " + num + " from " + format + + " is outside of the valid range 0 to " + + (params.length - 1)); + } + result.append(params[num]); + } catch (NumberFormatException nfe) { + throw new BadFormatString("bad format in username mapping in " + + paramNum, nfe); + } + + } + start = match.end(); + } + return result.toString(); + } + + /** + * Replace the matches of the from pattern in the base string with the value + * of the to string. + * @param base the string to transform + * @param from the pattern to look for in the base string + * @param to the string to replace matches of the pattern with + * @param repeat whether the substitution should be repeated + * @return + */ + static String replaceSubstitution(String base, Pattern from, String to, + boolean repeat) { + Matcher match = from.matcher(base); + if (repeat) { + return match.replaceAll(to); + } else { + return match.replaceFirst(to); + } + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder(); + if (isDefault) { + buf.append("DEFAULT"); + } else { + buf.append("RULE:["); + buf.append(numOfComponents); + buf.append(':'); + buf.append(format); + buf.append(']'); + if (match != null) { + buf.append('('); + buf.append(match); + buf.append(')'); + } + if (fromPattern != null) { + buf.append("s/"); + buf.append(fromPattern); + buf.append('/'); + buf.append(toPattern); + buf.append('/'); + if (repeat) { + buf.append('g'); + } + } + } + return buf.toString(); + } + + /** + * Try to apply this rule to the given name represented as a parameter + * array. + * @param params first element is the realm, second and later elements are + * are the components of the name "a/b@FOO" -> {"FOO", "a", "b"} + * @return the short name if this rule applies or null + * @throws IOException throws if something is wrong with the rules + */ + String apply(String[] params) throws IOException { + String result = null; + if (isDefault) { + if (defaultRealm.equals(params[0])) { + result = params[1]; + } + } else if (params.length - 1 == numOfComponents) { + String base = replaceParameters(format, params); + if (match == null || match.matcher(base).matches()) { + if (fromPattern == null) { + result = base; + } else { + result = replaceSubstitution(base, fromPattern, toPattern, repeat); + } + } + } + if (result != null && nonSimplePattern.matcher(result).find()) { + throw new NoMatchingRule("Non-simple name " + result + + " after auth_to_local rule " + this); + } + return result; + } + } + + @SuppressWarnings("serial") + public static class BadFormatString extends IOException { + BadFormatString(String msg) { + super(msg); + } + + BadFormatString(String msg, Throwable err) { + super(msg, err); + } + } + + @SuppressWarnings("serial") + public static class NoMatchingRule extends IOException { + NoMatchingRule(String msg) { + super(msg); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java b/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java new file mode 100644 index 00000000000..d939f05cbae --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.auth; + +import org.apache.zookeeper.server.ZooKeeperServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Enumeration; +import java.util.HashMap; + +public class ProviderRegistry { + private static final Logger LOG = LoggerFactory.getLogger(ProviderRegistry.class); + + private static boolean initialized = false; + private static HashMap authenticationProviders = + new HashMap(); + + public static void initialize() { + synchronized (ProviderRegistry.class) { + if (initialized) + return; + IPAuthenticationProvider ipp = new IPAuthenticationProvider(); + DigestAuthenticationProvider digp = new DigestAuthenticationProvider(); + X509AuthenticationProvider x509p = new X509AuthenticationProvider(); + authenticationProviders.put(ipp.getScheme(), ipp); + authenticationProviders.put(digp.getScheme(), digp); + authenticationProviders.put(x509p.getScheme(), x509p); + Enumeration en = System.getProperties().keys(); + while (en.hasMoreElements()) { + String k = (String) en.nextElement(); + if (k.startsWith("zookeeper.authProvider.")) { + String className = System.getProperty(k); + try { + Class c = ZooKeeperServer.class.getClassLoader() + .loadClass(className); + AuthenticationProvider ap = (AuthenticationProvider) c + .newInstance(); + authenticationProviders.put(ap.getScheme(), ap); + } catch (Exception e) { + LOG.warn("Problems loading " + className, e); + } + } + } + initialized = true; + } + } + + public static AuthenticationProvider getProvider(String scheme) { + if (!initialized) + initialize(); + return authenticationProviders.get(scheme); + } + + public static String listProviders() { + StringBuilder sb = new StringBuilder(); + for (String s : authenticationProviders.keySet()) { + sb.append(s + " "); + } + return sb.toString(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/auth/SASLAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/SASLAuthenticationProvider.java new file mode 100644 index 00000000000..d61393642df --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/auth/SASLAuthenticationProvider.java @@ -0,0 +1,70 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.auth; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.server.ServerCnxn; + +public class SASLAuthenticationProvider implements AuthenticationProvider { + + public String getScheme() { + return "sasl"; + } + + public KeeperException.Code + handleAuthentication(ServerCnxn cnxn, byte[] authData) { + // Should never call this: SASL authentication is negotiated at session initiation. + // TODO: consider substituting current implementation of direct ClientCnxn manipulation with + // a call to this method (SASLAuthenticationProvider:handleAuthentication()) at session initiation. + return KeeperException.Code.AUTHFAILED; + + } + + public boolean matches(String id, String aclExpr) { + if (System.getProperty("zookeeper.superUser") != null) { + if (id.equals(System.getProperty("zookeeper.superUser")) || id.equals(aclExpr)) { + return true; + } + } + if ((id.equals("super") || id.equals(aclExpr))) { + return true; + } + String readAccessUser = System.getProperty("zookeeper.letAnySaslUserDoX"); + if (readAccessUser != null && aclExpr.equals(readAccessUser)) { + return true; + } + return false; + } + + public boolean isAuthenticated() { + return true; + } + + public boolean isValid(String id) { + // Since the SASL authenticator will usually be used with Kerberos authentication, + // it should enforce that these names are valid according to Kerberos's + // syntax for principals. + // + // Use the KerberosName(id) constructor to define validity: + // if KerberosName(id) throws IllegalArgumentException, then id is invalid. + // otherwise, it is valid. + // + try { + new KerberosName(id); + return true; + } catch (IllegalArgumentException e) { + return false; + } + } + + +} diff --git a/src/java/main/org/apache/zookeeper/server/auth/SaslServerCallbackHandler.java b/src/java/main/org/apache/zookeeper/server/auth/SaslServerCallbackHandler.java new file mode 100644 index 00000000000..81e26eee2c1 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/auth/SaslServerCallbackHandler.java @@ -0,0 +1,144 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.auth; + +import org.apache.zookeeper.server.ZooKeeperSaslServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.AppConfigurationEntry; +import javax.security.auth.login.Configuration; +import javax.security.sasl.AuthorizeCallback; +import javax.security.sasl.RealmCallback; + +public class SaslServerCallbackHandler implements CallbackHandler { + private static final String USER_PREFIX = "user_"; + private static final Logger LOG = LoggerFactory.getLogger(SaslServerCallbackHandler.class); + private static final String SYSPROP_SUPER_PASSWORD = "zookeeper.SASLAuthenticationProvider.superPassword"; + private static final String SYSPROP_REMOVE_HOST = "zookeeper.kerberos.removeHostFromPrincipal"; + private static final String SYSPROP_REMOVE_REALM = "zookeeper.kerberos.removeRealmFromPrincipal"; + private final Map credentials = new HashMap(); + private String userName; + + public SaslServerCallbackHandler(Configuration configuration) throws IOException { + String serverSection = System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY, + ZooKeeperSaslServer.DEFAULT_LOGIN_CONTEXT_NAME); + AppConfigurationEntry configurationEntries[] = configuration.getAppConfigurationEntry(serverSection); + + if (configurationEntries == null) { + String errorMessage = "Could not find a 'Server' entry in this configuration: Server cannot start."; + LOG.error(errorMessage); + throw new IOException(errorMessage); + } + credentials.clear(); + for (AppConfigurationEntry entry : configurationEntries) { + Map options = entry.getOptions(); + // Populate DIGEST-MD5 user -> password map with JAAS configuration entries from the "Server" section. + // Usernames are distinguished from other options by prefixing the username with a "user_" prefix. + for (Map.Entry pair : options.entrySet()) { + String key = pair.getKey(); + if (key.startsWith(USER_PREFIX)) { + String userName = key.substring(USER_PREFIX.length()); + credentials.put(userName, (String) pair.getValue()); + } + } + } + } + + public void handle(Callback[] callbacks) throws UnsupportedCallbackException { + for (Callback callback : callbacks) { + if (callback instanceof NameCallback) { + handleNameCallback((NameCallback) callback); + } else if (callback instanceof PasswordCallback) { + handlePasswordCallback((PasswordCallback) callback); + } else if (callback instanceof RealmCallback) { + handleRealmCallback((RealmCallback) callback); + } else if (callback instanceof AuthorizeCallback) { + handleAuthorizeCallback((AuthorizeCallback) callback); + } + } + } + + private void handleNameCallback(NameCallback nc) { + // check to see if this user is in the user password database. + if (credentials.get(nc.getDefaultName()) == null) { + LOG.warn("User '" + nc.getDefaultName() + "' not found in list of DIGEST-MD5 authenticateable users."); + return; + } + nc.setName(nc.getDefaultName()); + userName = nc.getDefaultName(); + } + + private void handlePasswordCallback(PasswordCallback pc) { + if ("super".equals(this.userName) && System.getProperty(SYSPROP_SUPER_PASSWORD) != null) { + // superuser: use Java system property for password, if available. + pc.setPassword(System.getProperty(SYSPROP_SUPER_PASSWORD).toCharArray()); + } else if (credentials.containsKey(userName)) { + pc.setPassword(credentials.get(userName).toCharArray()); + } else { + LOG.warn("No password found for user: " + userName); + } + } + + private void handleRealmCallback(RealmCallback rc) { + LOG.debug("client supplied realm: " + rc.getDefaultText()); + rc.setText(rc.getDefaultText()); + } + + private void handleAuthorizeCallback(AuthorizeCallback ac) { + String authenticationID = ac.getAuthenticationID(); + String authorizationID = ac.getAuthorizationID(); + + LOG.info("Successfully authenticated client: authenticationID=" + authenticationID + + "; authorizationID=" + authorizationID + "."); + ac.setAuthorized(true); + + // canonicalize authorization id according to system properties: + // zookeeper.kerberos.removeRealmFromPrincipal(={true,false}) + // zookeeper.kerberos.removeHostFromPrincipal(={true,false}) + KerberosName kerberosName = new KerberosName(authenticationID); + try { + StringBuilder userNameBuilder = new StringBuilder(kerberosName.getShortName()); + if (shouldAppendHost(kerberosName)) { + userNameBuilder.append("/").append(kerberosName.getHostName()); + } + if (shouldAppendRealm(kerberosName)) { + userNameBuilder.append("@").append(kerberosName.getRealm()); + } + LOG.info("Setting authorizedID: " + userNameBuilder); + ac.setAuthorizedID(userNameBuilder.toString()); + } catch (IOException e) { + LOG.error("Failed to set name based on Kerberos authentication rules."); + } + } + + private boolean shouldAppendRealm(KerberosName kerberosName) { + return !isSystemPropertyTrue(SYSPROP_REMOVE_REALM) && kerberosName.getRealm() != null; + } + + private boolean shouldAppendHost(KerberosName kerberosName) { + return !isSystemPropertyTrue(SYSPROP_REMOVE_HOST) && kerberosName.getHostName() != null; + } + + private boolean isSystemPropertyTrue(String propertyName) { + return "true".equals(System.getProperty(propertyName)); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/auth/X509AuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/X509AuthenticationProvider.java new file mode 100644 index 00000000000..d86236cf233 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/auth/X509AuthenticationProvider.java @@ -0,0 +1,219 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.auth; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.common.X509Exception.KeyManagerException; +import org.apache.zookeeper.common.X509Exception.TrustManagerException; +import org.apache.zookeeper.common.X509Util; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.server.ServerCnxn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.X509KeyManager; +import javax.net.ssl.X509TrustManager; +import javax.security.auth.x500.X500Principal; + +/** + * An AuthenticationProvider backed by an X509TrustManager and an X509KeyManager + * to perform remote host certificate authentication. The default algorithm is + * SunX509 and a JKS KeyStore. To specify the locations of the key store and + * trust store, set the following system properties: + *
        zookeeper.ssl.keyStore.location + *
        zookeeper.ssl.trustStore.location + *
        To specify store passwords, set the following system properties: + *
        zookeeper.ssl.keyStore.password + *
        zookeeper.ssl.trustStore.password + *
        Alternatively, this can be plugged with any X509TrustManager and + * X509KeyManager implementation. + */ +public class X509AuthenticationProvider implements AuthenticationProvider { + static final String ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER + = "zookeeper.X509AuthenticationProvider.superUser"; + private static final Logger LOG + = LoggerFactory.getLogger(X509AuthenticationProvider.class); + private final X509TrustManager trustManager; + private final X509KeyManager keyManager; + + /** + * Initialize the X509AuthenticationProvider with a JKS KeyStore and JKS + * TrustStore according to the following system properties: + *
        zookeeper.ssl.keyStore.location + *
        zookeeper.ssl.trustStore.location + *
        zookeeper.ssl.keyStore.password + *
        zookeeper.ssl.trustStore.password + */ + public X509AuthenticationProvider() { + String keyStoreLocationProp = System.getProperty( + X509Util.SSL_KEYSTORE_LOCATION); + String keyStorePasswordProp = System.getProperty( + X509Util.SSL_KEYSTORE_PASSWD); + + X509KeyManager km = null; + X509TrustManager tm = null; + try { + km = X509Util.createKeyManager( + keyStoreLocationProp, keyStorePasswordProp); + } catch (KeyManagerException e) { + LOG.error("Failed to create key manager", e); + } + + String trustStoreLocationProp = System.getProperty( + X509Util.SSL_TRUSTSTORE_LOCATION); + String trustStorePasswordProp = System.getProperty( + X509Util.SSL_TRUSTSTORE_PASSWD); + + try { + tm = X509Util.createTrustManager( + trustStoreLocationProp, trustStorePasswordProp); + } catch (TrustManagerException e) { + LOG.error("Failed to create trust manager", e); + } + + this.keyManager = km; + this.trustManager = tm; + } + + /** + * Initialize the X509AuthenticationProvider with the provided + * X509TrustManager and X509KeyManager. + * + * @param trustManager X509TrustManager implementation to use for remote + * host authentication. + * @param keyManager X509KeyManager implementation to use for certificate + * management. + */ + public X509AuthenticationProvider(X509TrustManager trustManager, + X509KeyManager keyManager) { + this.trustManager = trustManager; + this.keyManager = keyManager; + } + + @Override + public String getScheme() { + return "x509"; + } + + @Override + public KeeperException.Code handleAuthentication(ServerCnxn cnxn, + byte[] authData) { + X509Certificate[] certChain + = (X509Certificate[]) cnxn.getClientCertificateChain(); + + if (certChain == null || certChain.length == 0) { + return KeeperException.Code.AUTHFAILED; + } + + if (trustManager == null) { + LOG.error("No trust manager available to authenticate session 0x{}", + Long.toHexString(cnxn.getSessionId())); + return KeeperException.Code.AUTHFAILED; + } + + X509Certificate clientCert = certChain[0]; + + try { + // Authenticate client certificate + trustManager.checkClientTrusted(certChain, + clientCert.getPublicKey().getAlgorithm()); + } catch (CertificateException ce) { + LOG.error("Failed to trust certificate for session 0x" + + Long.toHexString(cnxn.getSessionId()), ce); + return KeeperException.Code.AUTHFAILED; + } + + String clientId = getClientId(clientCert); + + if (clientId.equals(System.getProperty( + ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER))) { + cnxn.addAuthInfo(new Id("super", clientId)); + LOG.info("Authenticated Id '{}' as super user", clientId); + } + + Id authInfo = new Id(getScheme(), clientId); + cnxn.addAuthInfo(authInfo); + + LOG.info("Authenticated Id '{}' for Scheme '{}'", + authInfo.getId(), authInfo.getScheme()); + return KeeperException.Code.OK; + } + + /** + * Determine the string to be used as the remote host session Id for + * authorization purposes. Associate this client identifier with a + * ServerCnxn that has been authenticated over SSL, and any ACLs that refer + * to the authenticated client. + * + * @param clientCert Authenticated X509Certificate associated with the + * remote host. + * @return Identifier string to be associated with the client. + */ + protected String getClientId(X509Certificate clientCert) { + return clientCert.getSubjectX500Principal().getName(); + } + + @Override + public boolean matches(String id, String aclExpr) { + if (System.getProperty(ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER) != null) { + return (id.equals(System.getProperty(ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER)) + || id.equals(aclExpr)); + } + + return (id.equals(aclExpr)); + } + + @Override + public boolean isAuthenticated() { + return true; + } + + @Override + public boolean isValid(String id) { + try { + new X500Principal(id); + return true; + } catch (IllegalArgumentException e) { + return false; + } + } + + /** + * Get the X509TrustManager implementation used for remote host + * authentication. + * + * @return The X509TrustManager. + * @throws TrustManagerException When there is no trust manager available. + */ + public X509TrustManager getTrustManager() throws TrustManagerException { + if (trustManager == null) { + throw new TrustManagerException("No trust manager available"); + } + return trustManager; + } + + /** + * Get the X509KeyManager implementation used for certificate management. + * + * @return The X509KeyManager. + * @throws KeyManagerException When there is no key manager available. + */ + public X509KeyManager getKeyManager() throws KeyManagerException { + if (keyManager == null) { + throw new KeyManagerException("No key manager available"); + } + return keyManager; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/AbstractFourLetterCommand.java b/src/java/main/org/apache/zookeeper/server/command/AbstractFourLetterCommand.java new file mode 100644 index 00000000000..ad1b3ceb873 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/AbstractFourLetterCommand.java @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Set of threads for command ports. All the 4 letter commands are run via a + * thread. Each class maps to a correspoding 4 letter command. CommandThread is + * the abstract class from which all the others inherit. + */ +public abstract class AbstractFourLetterCommand { + protected static final String ZK_NOT_SERVING = "This ZooKeeper instance is not currently serving requests"; + private static final Logger LOG = LoggerFactory + .getLogger(AbstractFourLetterCommand.class); + protected PrintWriter pw; + protected ServerCnxn serverCnxn; + protected ZooKeeperServer zkServer; + protected ServerCnxnFactory factory; + + public AbstractFourLetterCommand(PrintWriter pw, ServerCnxn serverCnxn) { + this.pw = pw; + this.serverCnxn = serverCnxn; + } + + public void start() { + run(); + } + + public void run() { + try { + commandRun(); + } catch (IOException ie) { + LOG.error("Error in running command ", ie); + } finally { + serverCnxn.cleanupWriterSocket(pw); + } + } + + public void setZkServer(ZooKeeperServer zkServer) { + this.zkServer = zkServer; + } + + public void setFactory(ServerCnxnFactory factory) { + this.factory = factory; + } + + public abstract void commandRun() throws IOException; +} diff --git a/src/java/main/org/apache/zookeeper/server/command/CnxnStatResetCommand.java b/src/java/main/org/apache/zookeeper/server/command/CnxnStatResetCommand.java new file mode 100644 index 00000000000..47741990ad1 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/CnxnStatResetCommand.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class CnxnStatResetCommand extends AbstractFourLetterCommand { + public CnxnStatResetCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + } else { + factory.resetAllConnectionStats(); + pw.println("Connection stats reset."); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/CommandExecutor.java b/src/java/main/org/apache/zookeeper/server/command/CommandExecutor.java new file mode 100644 index 00000000000..672db41251c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/CommandExecutor.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZooKeeperServer; + +import java.io.PrintWriter; + +public class CommandExecutor { + /** + * This class decides which command to be executed and then executes + */ + public boolean execute(ServerCnxn serverCnxn, PrintWriter pwriter, + final int commandCode, ZooKeeperServer zkServer, ServerCnxnFactory factory) { + AbstractFourLetterCommand command = getCommand(serverCnxn, pwriter, commandCode); + + if (command == null) { + return false; + } + + command.setZkServer(zkServer); + command.setFactory(factory); + command.start(); + return true; + } + + private AbstractFourLetterCommand getCommand(ServerCnxn serverCnxn, + PrintWriter pwriter, final int commandCode) { + AbstractFourLetterCommand command = null; + if (commandCode == FourLetterCommands.ruokCmd) { + command = new RuokCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.getTraceMaskCmd) { + command = new TraceMaskCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.enviCmd) { + command = new EnvCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.confCmd) { + command = new ConfCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.srstCmd) { + command = new StatResetCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.crstCmd) { + command = new CnxnStatResetCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.dirsCmd) { + command = new DirsCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.dumpCmd) { + command = new DumpCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.statCmd + || commandCode == FourLetterCommands.srvrCmd) { + command = new StatCommand(pwriter, serverCnxn, commandCode); + } else if (commandCode == FourLetterCommands.consCmd) { + command = new ConsCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.wchpCmd + || commandCode == FourLetterCommands.wchcCmd + || commandCode == FourLetterCommands.wchsCmd) { + command = new WatchCommand(pwriter, serverCnxn, commandCode); + } else if (commandCode == FourLetterCommands.mntrCmd) { + command = new MonitorCommand(pwriter, serverCnxn); + } else if (commandCode == FourLetterCommands.isroCmd) { + command = new IsroCommand(pwriter, serverCnxn); + } + return command; + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/command/ConfCommand.java b/src/java/main/org/apache/zookeeper/server/command/ConfCommand.java new file mode 100644 index 00000000000..149c5bf23da --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/ConfCommand.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class ConfCommand extends AbstractFourLetterCommand { + ConfCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + } else { + zkServer.dumpConf(pw); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/ConsCommand.java b/src/java/main/org/apache/zookeeper/server/command/ConsCommand.java new file mode 100644 index 00000000000..97c54b00248 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/ConsCommand.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class ConsCommand extends AbstractFourLetterCommand { + public ConsCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + } else { + for (ServerCnxn c : factory.getConnections()) { + c.dumpConnectionInfo(pw, false); + pw.println(); + } + pw.println(); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/DirsCommand.java b/src/java/main/org/apache/zookeeper/server/command/DirsCommand.java new file mode 100644 index 00000000000..cd61d426b04 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/DirsCommand.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.IOException; +import java.io.PrintWriter; + +public class DirsCommand extends AbstractFourLetterCommand { + + public DirsCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() throws IOException { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + return; + } + pw.println("datadir_size: " + zkServer.getDataDirSize()); + pw.println("logdir_size: " + zkServer.getLogDirSize()); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/DumpCommand.java b/src/java/main/org/apache/zookeeper/server/command/DumpCommand.java new file mode 100644 index 00000000000..7a15f107c09 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/DumpCommand.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.NIOServerCnxnFactory; +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class DumpCommand extends AbstractFourLetterCommand { + public DumpCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + } else { + pw.println("SessionTracker dump:"); + zkServer.getSessionTracker().dumpSessions(pw); + pw.println("ephemeral nodes dump:"); + zkServer.dumpEphemerals(pw); + pw.println("Connections dump:"); + //dumpConnections connection is implemented only in NIOServerCnxnFactory + if (factory instanceof NIOServerCnxnFactory) { + ((NIOServerCnxnFactory) factory).dumpConnections(pw); + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/EnvCommand.java b/src/java/main/org/apache/zookeeper/server/command/EnvCommand.java new file mode 100644 index 00000000000..e67f06551af --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/EnvCommand.java @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.Environment; +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; +import java.util.List; + +public class EnvCommand extends AbstractFourLetterCommand { + EnvCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + List env = Environment.list(); + + pw.println("Environment:"); + for (Environment.Entry e : env) { + pw.print(e.getKey()); + pw.print("="); + pw.println(e.getValue()); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java b/src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java new file mode 100644 index 00000000000..0f704d6f1e6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java @@ -0,0 +1,171 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import java.nio.ByteBuffer; +import java.util.HashMap; + +/** + * This class contains constants for all the four letter commands + */ +public class FourLetterCommands { + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int confCmd = + ByteBuffer.wrap("conf".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int consCmd = + ByteBuffer.wrap("cons".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int crstCmd = + ByteBuffer.wrap("crst".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int dirsCmd = + ByteBuffer.wrap("dirs".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int dumpCmd = + ByteBuffer.wrap("dump".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int enviCmd = + ByteBuffer.wrap("envi".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int getTraceMaskCmd = + ByteBuffer.wrap("gtmk".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int ruokCmd = + ByteBuffer.wrap("ruok".getBytes()).getInt(); + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int setTraceMaskCmd = + ByteBuffer.wrap("stmk".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int srvrCmd = + ByteBuffer.wrap("srvr".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int srstCmd = + ByteBuffer.wrap("srst".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int statCmd = + ByteBuffer.wrap("stat".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int wchcCmd = + ByteBuffer.wrap("wchc".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int wchpCmd = + ByteBuffer.wrap("wchp".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int wchsCmd = + ByteBuffer.wrap("wchs".getBytes()).getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int mntrCmd = ByteBuffer.wrap("mntr".getBytes()) + .getInt(); + + /* + * See + * Zk Admin. this link is for all the commands. + */ + public final static int isroCmd = ByteBuffer.wrap("isro".getBytes()) + .getInt(); + + /* + * The control sequence sent by the telnet program when it closes a + * connection. Include simply to keep the logs cleaner (the server would + * close the connection anyway because it would parse this as a negative + * length). + */ + public final static int telnetCloseCmd = 0xfff4fffd; + + public final static HashMap cmd2String = + new HashMap(); + + // specify all of the commands that are available + static { + cmd2String.put(confCmd, "conf"); + cmd2String.put(consCmd, "cons"); + cmd2String.put(crstCmd, "crst"); + cmd2String.put(dirsCmd, "dirs"); + cmd2String.put(dumpCmd, "dump"); + cmd2String.put(enviCmd, "envi"); + cmd2String.put(getTraceMaskCmd, "gtmk"); + cmd2String.put(ruokCmd, "ruok"); + cmd2String.put(setTraceMaskCmd, "stmk"); + cmd2String.put(srstCmd, "srst"); + cmd2String.put(srvrCmd, "srvr"); + cmd2String.put(statCmd, "stat"); + cmd2String.put(wchcCmd, "wchc"); + cmd2String.put(wchpCmd, "wchp"); + cmd2String.put(wchsCmd, "wchs"); + cmd2String.put(mntrCmd, "mntr"); + cmd2String.put(isroCmd, "isro"); + cmd2String.put(telnetCloseCmd, "telnet close"); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/IsroCommand.java b/src/java/main/org/apache/zookeeper/server/command/IsroCommand.java new file mode 100644 index 00000000000..dfc8490c04d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/IsroCommand.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer; + +import java.io.PrintWriter; + +public class IsroCommand extends AbstractFourLetterCommand { + + public IsroCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.print("null"); + } else if (zkServer instanceof ReadOnlyZooKeeperServer) { + pw.print("ro"); + } else { + pw.print("rw"); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java b/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java new file mode 100644 index 00000000000..aeb5a402013 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.Version; +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.ServerStats; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.quorum.Leader; +import org.apache.zookeeper.server.quorum.LeaderZooKeeperServer; +import org.apache.zookeeper.server.util.OSMXBean; + +import java.io.PrintWriter; + +public class MonitorCommand extends AbstractFourLetterCommand { + + MonitorCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + return; + } + ZKDatabase zkdb = zkServer.getZKDatabase(); + ServerStats stats = zkServer.serverStats(); + + print("version", Version.getFullVersion()); + + print("avg_latency", stats.getAvgLatency()); + print("max_latency", stats.getMaxLatency()); + print("min_latency", stats.getMinLatency()); + + print("packets_received", stats.getPacketsReceived()); + print("packets_sent", stats.getPacketsSent()); + print("num_alive_connections", stats.getNumAliveClientConnections()); + + print("outstanding_requests", stats.getOutstandingRequests()); + + print("server_state", stats.getServerState()); + print("znode_count", zkdb.getNodeCount()); + + print("watch_count", zkdb.getDataTree().getWatchCount()); + print("ephemerals_count", zkdb.getDataTree().getEphemeralsCount()); + print("approximate_data_size", zkdb.getDataTree().approximateDataSize()); + + OSMXBean osMbean = new OSMXBean(); + if (osMbean != null && osMbean.getUnix() == true) { + print("open_file_descriptor_count", osMbean.getOpenFileDescriptorCount()); + print("max_file_descriptor_count", osMbean.getMaxFileDescriptorCount()); + } + + if (stats.getServerState().equals("leader")) { + Leader leader = ((LeaderZooKeeperServer) zkServer).getLeader(); + + print("followers", leader.getLearners().size()); + print("synced_followers", leader.getForwardingFollowers().size()); + print("pending_syncs", leader.getNumPendingSyncs()); + } + } + + private void print(String key, long number) { + print(key, "" + number); + } + + private void print(String key, String value) { + pw.print("zk_"); + pw.print(key); + pw.print("\t"); + pw.println(value); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/command/RuokCommand.java b/src/java/main/org/apache/zookeeper/server/command/RuokCommand.java new file mode 100644 index 00000000000..03246748c4c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/RuokCommand.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class RuokCommand extends AbstractFourLetterCommand { + public RuokCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + pw.print("imok"); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/SetTraceMaskCommand.java b/src/java/main/org/apache/zookeeper/server/command/SetTraceMaskCommand.java new file mode 100644 index 00000000000..ebee7ada5bb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/SetTraceMaskCommand.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class SetTraceMaskCommand extends AbstractFourLetterCommand { + long trace = 0; + + public SetTraceMaskCommand(PrintWriter pw, ServerCnxn serverCnxn, long trace) { + super(pw, serverCnxn); + this.trace = trace; + } + + @Override + public void commandRun() { + pw.print(trace); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/StatCommand.java b/src/java/main/org/apache/zookeeper/server/command/StatCommand.java new file mode 100644 index 00000000000..140966e2172 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/StatCommand.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.Version; +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.PrintWriter; + +public class StatCommand extends AbstractFourLetterCommand { + private static final Logger LOG = LoggerFactory + .getLogger(AbstractFourLetterCommand.class); + private int len; + + public StatCommand(PrintWriter pw, ServerCnxn serverCnxn, int len) { + super(pw, serverCnxn); + this.len = len; + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + } else { + pw.print("Zookeeper version: "); + pw.println(Version.getFullVersion()); + if (zkServer instanceof ReadOnlyZooKeeperServer) { + pw.println("READ-ONLY mode; serving only read-only clients"); + } + if (len == FourLetterCommands.statCmd) { + LOG.info("Stat command output"); + pw.println("Clients:"); + for (ServerCnxn c : factory.getConnections()) { + c.dumpConnectionInfo(pw, true); + pw.println(); + } + pw.println(); + } + pw.print(zkServer.serverStats().toString()); + pw.print("Node count: "); + pw.println(zkServer.getZKDatabase().getNodeCount()); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/StatResetCommand.java b/src/java/main/org/apache/zookeeper/server/command/StatResetCommand.java new file mode 100644 index 00000000000..527d563be5b --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/StatResetCommand.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class StatResetCommand extends AbstractFourLetterCommand { + public StatResetCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + } else { + zkServer.serverStats().reset(); + pw.println("Server stats reset."); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/TraceMaskCommand.java b/src/java/main/org/apache/zookeeper/server/command/TraceMaskCommand.java new file mode 100644 index 00000000000..d1002d849b3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/TraceMaskCommand.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.ZooTrace; + +import java.io.PrintWriter; + +public class TraceMaskCommand extends AbstractFourLetterCommand { + TraceMaskCommand(PrintWriter pw, ServerCnxn serverCnxn) { + super(pw, serverCnxn); + } + + @Override + public void commandRun() { + long traceMask = ZooTrace.getTextTraceLevel(); + pw.print(traceMask); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/command/WatchCommand.java b/src/java/main/org/apache/zookeeper/server/command/WatchCommand.java new file mode 100644 index 00000000000..ef53cca8233 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/command/WatchCommand.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.command; + +import org.apache.zookeeper.server.DataTree; +import org.apache.zookeeper.server.ServerCnxn; + +import java.io.PrintWriter; + +public class WatchCommand extends AbstractFourLetterCommand { + int len = 0; + + public WatchCommand(PrintWriter pw, ServerCnxn serverCnxn, int len) { + super(pw, serverCnxn); + this.len = len; + } + + @Override + public void commandRun() { + if (zkServer == null) { + pw.println(ZK_NOT_SERVING); + } else { + DataTree dt = zkServer.getZKDatabase().getDataTree(); + if (len == FourLetterCommands.wchsCmd) { + dt.dumpWatchesSummary(pw); + } else if (len == FourLetterCommands.wchpCmd) { + dt.dumpWatches(pw, true); + } else { + dt.dumpWatches(pw, false); + } + pw.println(); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/package.html b/src/java/main/org/apache/zookeeper/server/package.html new file mode 100644 index 00000000000..0b150dc47ec --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/package.html @@ -0,0 +1,101 @@ + + + + +

        ZooKeeper server theory of operation

        +ZooKeeperServer is designed to work in standalone mode and also +be extensible so that it can be used to implement the quorum based +version of ZooKeeper. +

        + ZooKeeper maintains a order when processing requests: +

          +
        • All requests will be processed in order. +
        • All responses will return in order. +
        • All watches will be sent in the order that the update takes place. +
        +

        + We will explain the three aspects of ZooKeeperServer: request processing, data + structure maintenance, and session tracking. + +

        Request processing

        + +Requests are received by the ServerCnxn. Demarshalling of a request is +done by ClientRequestHandler. After a request has been demarshalled, +ClientRequestHandler invokes the relevant method in ZooKeeper and marshals +the result. +

        + If the request is just a query, it will be processed by ZooKeeper and returned. + Otherwise, the request will be validated and a transaction will be generated + and logged. This the request will then wait until the request has been logged + before continuing processing. +

        + Requests are logged as a group. Transactions are queued up and the SyncThread + will process them at predefined intervals. (Currently 20ms) The SyncThread + interacts with ZooKeeperServer the txnQueue. Transactions are added to the + txnQueue of SyncThread via queueItem. When the transaction has been synced to + disk, its callback will be invoked which will cause the request processing to + be completed. + +

        Data structure maintenance

        + +ZooKeeper data is stored in-memory. Each znode is stored in a DataNode object. +This object is accessed through a hash table that maps paths to DataNodes. +DataNodes also organize themselves into a tree. This tree is only used for +serializing nodes. +

        + We guarantee that changes to nodes are stored to non-volatile media before + responding to a client. We do this quickly by writing changes as a sequence + of transactions in a log file. Even though we flush transactions as a group, + we need to avoid seeks as much as possible. Also, since the server can fail + at any point, we need to be careful of partial records. +

        + We address the above problems by +

          +
        • Pre-allocating 1M chunks of file space. This allows us to append to the + file without causing seeks to update file size. It also means that we need + to check for the end of the log by looking for a zero length transaction + rather than simply end of file. +
        • Writing a signature at the end of each transaction. When processing + transactions, we only use transactions that have a valid signature at the end. +
        +

        + As the server runs, the log file will grow quite large. To avoid long startup + times we periodically take a snapshot of the tree of DataNodes. We cannot + take the snapshot synchronously as the data takes a while to write out, so + instead we asynchronously write out the tree. This means that we end up + with a "corrupt" snapshot of the data tree. More formally if we define T + to be the real snapshot of the tree at the time we begin taking the snapshot + and l as the sequence of transactions that are applied to the tree between + the time the snapshot begins and the time the snapshot completes, we write + to disk T+l' where l' is a subset of the transactions in l. While we do not + have a way of figuring out which transactions make up l', it doesn't really + matter. T+l'+l = T+l since the transactions we log are idempotent (applying + the transaction multiple times has the same result as applying the transaction + once). So when we restore the snapshot we also play all transactions in the log + that occur after the snapshot was begun. We can easily figure out where to + start the replay because we start a new logfile when we start a snapshot. Both + the snapshot file and log file have a numeric suffix that represent the + transaction id that created the respective files. + +

        Session tracking

        +Rather than tracking sessions exactly, we track them in batches. That are +processed at fixed intervals. This is easier to implement than exact +session tracking and it is more efficient in terms of performance. It also +provides a small grace period for session renewal. + + \ No newline at end of file diff --git a/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java b/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java new file mode 100644 index 00000000000..1a27aa9ba55 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java @@ -0,0 +1,245 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.persistence; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.zookeeper.server.DataTree; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.zip.Adler32; +import java.util.zip.CheckedInputStream; +import java.util.zip.CheckedOutputStream; + +/** + * This class implements the snapshot interface. + * it is responsible for storing, serializing + * and deserializing the right snapshot. + * and provides access to the snapshots. + */ +public class FileSnap implements SnapShot { + public final static int SNAP_MAGIC + = ByteBuffer.wrap("ZKSN".getBytes()).getInt(); + private static final int VERSION = 2; + private static final long dbId = -1; + private static final Logger LOG = LoggerFactory.getLogger(FileSnap.class); + File snapDir; + private volatile boolean close = false; + + public FileSnap(File snapDir) { + this.snapDir = snapDir; + } + + /** + * deserialize a data tree from the most recent snapshot + * @return the zxid of the snapshot + */ + public long deserialize(DataTree dt, Map sessions) + throws IOException { + // we run through 100 snapshots (not all of them) + // if we cannot get it running within 100 snapshots + // we should give up + List snapList = findNValidSnapshots(100); + if (snapList.size() == 0) { + return -1L; + } + File snap = null; + boolean foundValid = false; + for (int i = 0; i < snapList.size(); i++) { + snap = snapList.get(i); + InputStream snapIS = null; + CheckedInputStream crcIn = null; + try { + LOG.info("Reading snapshot " + snap); + snapIS = new BufferedInputStream(new FileInputStream(snap)); + crcIn = new CheckedInputStream(snapIS, new Adler32()); + InputArchive ia = BinaryInputArchive.getArchive(crcIn); + deserialize(dt, sessions, ia); + long checkSum = crcIn.getChecksum().getValue(); + long val = ia.readLong("val"); + if (val != checkSum) { + throw new IOException("CRC corruption in snapshot : " + snap); + } + foundValid = true; + break; + } catch (IOException e) { + LOG.warn("problem reading snap file " + snap, e); + } finally { + if (snapIS != null) + snapIS.close(); + if (crcIn != null) + crcIn.close(); + } + } + if (!foundValid) { + throw new IOException("Not able to find valid snapshots in " + snapDir); + } + dt.lastProcessedZxid = Util.getZxidFromName(snap.getName(), "snapshot"); + return dt.lastProcessedZxid; + } + + /** + * deserialize the datatree from an inputarchive + * @param dt the datatree to be serialized into + * @param sessions the sessions to be filled up + * @param ia the input archive to restore from + * @throws IOException + */ + public void deserialize(DataTree dt, Map sessions, + InputArchive ia) throws IOException { + FileHeader header = new FileHeader(); + header.deserialize(ia, "fileheader"); + if (header.getMagic() != SNAP_MAGIC) { + throw new IOException("mismatching magic headers " + + header.getMagic() + + " != " + FileSnap.SNAP_MAGIC); + } + SerializeUtils.deserializeSnapshot(dt, ia, sessions); + } + + /** + * find the most recent snapshot in the database. + * @return the file containing the most recent snapshot + */ + public File findMostRecentSnapshot() throws IOException { + List files = findNValidSnapshots(1); + if (files.size() == 0) { + return null; + } + return files.get(0); + } + + /** + * find the last (maybe) valid n snapshots. this does some + * minor checks on the validity of the snapshots. It just + * checks for / at the end of the snapshot. This does + * not mean that the snapshot is truly valid but is + * valid with a high probability. also, the most recent + * will be first on the list. + * @param n the number of most recent snapshots + * @return the last n snapshots (the number might be + * less than n in case enough snapshots are not available). + * @throws IOException + */ + private List findNValidSnapshots(int n) throws IOException { + List files = Util.sortDataDir(snapDir.listFiles(), "snapshot", false); + int count = 0; + List list = new ArrayList(); + for (File f : files) { + // we should catch the exceptions + // from the valid snapshot and continue + // until we find a valid one + try { + if (Util.isValidSnapshot(f)) { + list.add(f); + count++; + if (count == n) { + break; + } + } + } catch (IOException e) { + LOG.info("invalid snapshot " + f, e); + } + } + return list; + } + + /** + * find the last n snapshots. this does not have + * any checks if the snapshot might be valid or not + * @param the number of most recent snapshots + * @return the last n snapshots + * @throws IOException + */ + public List findNRecentSnapshots(int n) throws IOException { + List files = Util.sortDataDir(snapDir.listFiles(), "snapshot", false); + int i = 0; + List list = new ArrayList(); + for (File f : files) { + if (i == n) + break; + i++; + list.add(f); + } + return list; + } + + /** + * serialize the datatree and sessions + * @param dt the datatree to be serialized + * @param sessions the sessions to be serialized + * @param oa the output archive to serialize into + * @param header the header of this snapshot + * @throws IOException + */ + protected void serialize(DataTree dt, Map sessions, + OutputArchive oa, FileHeader header) throws IOException { + // this is really a programmatic error and not something that can + // happen at runtime + if (header == null) + throw new IllegalStateException( + "Snapshot's not open for writing: uninitialized header"); + header.serialize(oa, "fileheader"); + SerializeUtils.serializeSnapshot(dt, oa, sessions); + } + + /** + * serialize the datatree and session into the file snapshot + * @param dt the datatree to be serialized + * @param sessions the sessions to be serialized + * @param snapShot the file to store snapshot into + */ + public synchronized void serialize(DataTree dt, Map sessions, File snapShot) + throws IOException { + if (!close) { + OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot)); + CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32()); + //CheckedOutputStream cout = new CheckedOutputStream() + OutputArchive oa = BinaryOutputArchive.getArchive(crcOut); + FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId); + serialize(dt, sessions, oa, header); + long val = crcOut.getChecksum().getValue(); + oa.writeLong(val, "val"); + oa.writeString("/", "path"); + sessOS.flush(); + crcOut.close(); + sessOS.close(); + } + } + + /** + * synchronized close just so that if serialize is in place + * the close operation will block and will wait till serialize + * is done and will set the close flag + */ + @Override + public synchronized void close() throws IOException { + close = true; + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java new file mode 100644 index 00000000000..f33347d13af --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java @@ -0,0 +1,693 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.persistence; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.zip.Adler32; +import java.util.zip.Checksum; + +/** + * This class implements the TxnLog interface. It provides api's to access the txnlogs and add entries to it.

        The format of a Transactional log is as follows: + *

        + * LogFile:
        + *     FileHeader TxnList ZeroPad
        + *
        + * FileHeader: {
        + *     magic 4bytes (ZKLG)
        + *     version 4bytes
        + *     dbid 8bytes
        + *   }
        + *
        + * TxnList:
        + *     Txn || Txn TxnList
        + *
        + * Txn:
        + *     checksum Txnlen TxnHeader Record 0x42
        + *
        + * checksum: 8bytes Adler32 is currently used
        + *   calculated across payload -- Txnlen, TxnHeader, Record and 0x42
        + *
        + * Txnlen:
        + *     len 4bytes
        + *
        + * TxnHeader: {
        + *     sessionid 8bytes
        + *     cxid 4bytes
        + *     zxid 8bytes
        + *     time 8bytes
        + *     type 4bytes
        + *   }
        + *
        + * Record:
        + *     See Jute definition file for details on the various record types
        + *
        + * ZeroPad:
        + *     0 padded to EOF (filled during preallocation stage)
        + * 
        + */ +public class FileTxnLog implements TxnLog { + public final static int TXNLOG_MAGIC = + ByteBuffer.wrap("ZKLG".getBytes()).getInt(); + public final static int VERSION = 2; + private static final Logger LOG; + /** + * Maximum time we allow for elapsed fsync before WARNing + */ + private final static long fsyncWarningThresholdMS; + static long preAllocSize = 65536 * 1024; + + static { + LOG = LoggerFactory.getLogger(FileTxnLog.class); + + String size = System.getProperty("zookeeper.preAllocSize"); + if (size != null) { + try { + preAllocSize = Long.parseLong(size) * 1024; + } catch (NumberFormatException e) { + LOG.warn(size + " is not a valid value for preAllocSize"); + } + } + fsyncWarningThresholdMS = Long.getLong("fsync.warningthresholdms", 1000); + } + + private final boolean forceSync = !System.getProperty("zookeeper.forceSync", "yes").equals("no"); + long lastZxidSeen; + volatile BufferedOutputStream logStream = null; + volatile OutputArchive oa; + volatile FileOutputStream fos = null; + File logDir; + ; + long dbId; + long currentSize; + File logFileWrite = null; + private LinkedList streamsToFlush = new LinkedList(); + + /** + * constructor for FileTxnLog. Take the directory where the txnlogs are stored + * + * @param logDir the directory where the txnlogs are stored + */ + public FileTxnLog(File logDir) { + this.logDir = logDir; + } + + /** + * method to allow setting preallocate size of log file to pad the file. + * + * @param size the size to set to in bytes + */ + public static void setPreallocSize(long size) { + preAllocSize = size; + } + + /** + * Find the log file that starts at, or just before, the snapshot. Return this and all subsequent logs. Results are ordered by zxid of file, ascending order. + * + * @param logDirList array of files + * @param snapshotZxid return files at, or before this zxid + */ + public static File[] getLogFiles(File[] logDirList, long snapshotZxid) { + List files = Util.sortDataDir(logDirList, "log", true); + long logZxid = 0; + // Find the log file that starts before or at the same time as the + // zxid of the snapshot + for (File f : files) { + long fzxid = Util.getZxidFromName(f.getName(), "log"); + if (fzxid > snapshotZxid) { + continue; + } + // the files + // are sorted with zxid's + if (fzxid > logZxid) { + logZxid = fzxid; + } + } + List v = new ArrayList(5); + for (File f : files) { + long fzxid = Util.getZxidFromName(f.getName(), "log"); + if (fzxid < logZxid) { + continue; + } + v.add(f); + } + return v.toArray(new File[0]); + + } + + /** + * read the header of the transaction file + * + * @param file the transaction file to read + * @return header that was read fomr the file + */ + private static FileHeader readHeader(File file) throws IOException { + InputStream is = null; + try { + is = new BufferedInputStream(new FileInputStream(file)); + InputArchive ia = BinaryInputArchive.getArchive(is); + FileHeader hdr = new FileHeader(); + hdr.deserialize(ia, "fileheader"); + return hdr; + } finally { + try { + if (is != null) is.close(); + } catch (IOException e) { + LOG.warn("Ignoring exception during close", e); + } + } + } + + /** + * creates a checksum alogrithm to be used + * + * @return the checksum used for this txnlog + */ + protected Checksum makeChecksumAlgorithm() { + return new Adler32(); + } + + /** + * rollover the current log file to a new one. + */ + public synchronized void rollLog() throws IOException { + if (logStream != null) { + this.logStream.flush(); + this.logStream = null; + oa = null; + } + } + + /** + * close all the open file handles + */ + public synchronized void close() throws IOException { + if (logStream != null) { + logStream.close(); + } + for (FileOutputStream log : streamsToFlush) { + log.close(); + } + } + + /** + * append an entry to the transaction log + * + * @param hdr the header of the transaction + * @param txn the transaction part of the entry returns true iff something appended, otw false + */ + public synchronized boolean append(TxnHeader hdr, Record txn) + throws IOException { + if (hdr != null) { + if (hdr.getZxid() <= lastZxidSeen) { + LOG.warn("Current zxid " + hdr.getZxid() + " is <= " + lastZxidSeen + " for " + hdr.getType()); + } + if (logStream == null) { + if (LOG.isInfoEnabled()) { + LOG.info("Creating new log file: log." + Long.toHexString(hdr.getZxid())); + } + logFileWrite = new File(logDir, ("log." + Long.toHexString(hdr.getZxid()))); + fos = new FileOutputStream(logFileWrite); + logStream = new BufferedOutputStream(fos); + oa = BinaryOutputArchive.getArchive(logStream); + FileHeader fhdr = new FileHeader(TXNLOG_MAGIC, VERSION, dbId); + fhdr.serialize(oa, "fileheader"); + // Make sure that the magic number is written before padding. + logStream.flush(); + currentSize = fos.getChannel().position(); + + //加入待flush列表,等待this.commit()将数据刷新到磁盘上。 + streamsToFlush.add(fos); + } + padFile(fos); + byte[] buf = Util.marshallTxnEntry(hdr, txn); + if (buf == null || buf.length == 0) { + throw new IOException("Faulty serialization for header " + "and txn"); + } + Checksum crc = makeChecksumAlgorithm(); + crc.update(buf, 0, buf.length); + oa.writeLong(crc.getValue(), "txnEntryCRC"); + Util.writeTxnBytes(oa, buf); + return true; + } + return false; + } + + /** + * pad the current file to increase its size + * + * @param out the outputstream to be padded + */ + private void padFile(FileOutputStream out) throws IOException { + currentSize = Util.padLogFile(out, currentSize, preAllocSize); + } + + /** + * get the last zxid that was logged in the transaction logs + * + * @return the last zxid logged in the transaction logs + */ + public long getLastLoggedZxid() { + File[] files = getLogFiles(logDir.listFiles(), 0); + long maxLog = files.length > 0 ? + Util.getZxidFromName(files[files.length - 1].getName(), "log") : -1; + + // if a log file is more recent we must scan it to find + // the highest zxid + long zxid = maxLog; + TxnIterator itr = null; + try { + FileTxnLog txn = new FileTxnLog(logDir); + itr = txn.read(maxLog); + while (true) { + if (!itr.next()) + break; + TxnHeader hdr = itr.getHeader(); + zxid = hdr.getZxid(); + } + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } finally { + close(itr); + } + return zxid; + } + + private void close(TxnIterator itr) { + if (itr != null) { + try { + itr.close(); + } catch (IOException ioe) { + LOG.warn("Error closing file iterator", ioe); + } + } + } + + /** + * commit the logs. make sure that evertyhing hits the disk + */ + public synchronized void commit() throws IOException { + if (logStream != null) { + logStream.flush(); + } + for (FileOutputStream log : streamsToFlush) { + log.flush(); + if (forceSync) { + long startSyncNS = System.nanoTime(); + log.getChannel().force(false); + long syncElapsedMS = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startSyncNS); + if (syncElapsedMS > fsyncWarningThresholdMS) { + LOG.warn("fsync-ing the write ahead log in " + Thread.currentThread().getName() + " took " + syncElapsedMS + "ms which will adversely effect operation latency. " + "See the ZooKeeper troubleshooting guide"); + } + } + } + while (streamsToFlush.size() > 1) { + streamsToFlush.removeFirst().close(); + } + } + + /** + * start reading all the transactions from the given zxid + * + * @param zxid the zxid to start reading transactions from + * @return returns an iterator to iterate through the transaction logs + */ + public TxnIterator read(long zxid) throws IOException { + return read(zxid, true); + } + + /** + * start reading all the transactions from the given zxid. + * + * @param zxid the zxid to start reading transactions from + * @param fastForward true if the iterator should be fast forwarded to point to the txn of a given zxid, else the iterator will point to the starting txn of a txnlog that may contain txn of a + * given zxid + * @return returns an iterator to iterate through the transaction logs + */ + public TxnIterator read(long zxid, boolean fastForward) throws IOException { + return new FileTxnIterator(logDir, zxid, fastForward); + } + + /** + * truncate the current transaction logs + * + * @param zxid the zxid to truncate the logs to + * @return true if successful false if not + */ + public boolean truncate(long zxid) throws IOException { + FileTxnIterator itr = null; + try { + itr = new FileTxnIterator(this.logDir, zxid); + PositionInputStream input = itr.inputStream; + if (input == null) { + throw new IOException("No log files found to truncate! This could " + + "happen if you still have snapshots from an old setup or " + + "log files were deleted accidentally or dataLogDir was changed in zoo.cfg."); + } + long pos = input.getPosition(); + // now, truncate at the current position + RandomAccessFile raf = new RandomAccessFile(itr.logFile, "rw"); + raf.setLength(pos); + raf.close(); + while (itr.goToNextLog()) { + if (!itr.logFile.delete()) { + LOG.warn("Unable to truncate {}", itr.logFile); + } + } + } finally { + close(itr); + } + return true; + } + + /** + * the dbid of this transaction database + * + * @return the dbid of this database + */ + public long getDbId() throws IOException { + FileTxnIterator itr = new FileTxnIterator(logDir, 0); + FileHeader fh = readHeader(itr.logFile); + itr.close(); + if (fh == null) + throw new IOException("Unsupported Format."); + return fh.getDbid(); + } + + /** + * the forceSync value. true if forceSync is enabled, false otherwise. + * + * @return the forceSync value + */ + public boolean isForceSync() { + return forceSync; + } + + /** + * a class that keeps track of the position in the input stream. The position points to offset that has been consumed by the applications. It can wrap buffered input streams to provide the right + * offset for the application. + */ + static class PositionInputStream extends FilterInputStream { + long position; + + protected PositionInputStream(InputStream in) { + super(in); + position = 0; + } + + @Override + public int read() throws IOException { + int rc = super.read(); + if (rc > -1) { + position++; + } + return rc; + } + + public int read(byte[] b) throws IOException { + int rc = super.read(b); + if (rc > 0) { + position += rc; + } + return rc; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int rc = super.read(b, off, len); + if (rc > 0) { + position += rc; + } + return rc; + } + + @Override + public long skip(long n) throws IOException { + long rc = super.skip(n); + if (rc > 0) { + position += rc; + } + return rc; + } + + public long getPosition() { + return position; + } + + @Override + public boolean markSupported() { + return false; + } + + @Override + public void mark(int readLimit) { + throw new UnsupportedOperationException("mark"); + } + + @Override + public void reset() { + throw new UnsupportedOperationException("reset"); + } + } + + /** + * this class implements the txnlog iterator interface which is used for reading the transaction logs + */ + public static class FileTxnIterator implements TxnLog.TxnIterator { + static final String CRC_ERROR = "CRC check failed"; + File logDir; + long zxid; + TxnHeader hdr; + Record record; + File logFile; + InputArchive ia; + PositionInputStream inputStream = null; + //stored files is the list of files greater than + //the zxid we are looking for. + private ArrayList storedFiles; + + /** + * create an iterator over a transaction database directory + * + * @param logDir the transaction database directory + * @param zxid the zxid to start reading from + * @param fastForward true if the iterator should be fast forwarded to point to the txn of a given zxid, else the iterator will point to the starting txn of a txnlog that may contain txn of a + * given zxid + */ + public FileTxnIterator(File logDir, long zxid, boolean fastForward) + throws IOException { + this.logDir = logDir; + this.zxid = zxid; + init(); + + if (fastForward && hdr != null) { + while (hdr.getZxid() < zxid) { + if (!next()) + break; + } + } + } + + /** + * create an iterator over a transaction database directory + * + * @param logDir the transaction database directory + * @param zxid the zxid to start reading from + */ + public FileTxnIterator(File logDir, long zxid) throws IOException { + this(logDir, zxid, true); + } + + /** + * initialize to the zxid specified this is inclusive of the zxid + */ + void init() throws IOException { + storedFiles = new ArrayList(); + List files = Util.sortDataDir(FileTxnLog.getLogFiles(logDir.listFiles(), 0), "log", false); + for (File f : files) { + if (Util.getZxidFromName(f.getName(), "log") >= zxid) { + storedFiles.add(f); + } + // add the last logfile that is less than the zxid + else if (Util.getZxidFromName(f.getName(), "log") < zxid) { + storedFiles.add(f); + break; + } + } + goToNextLog(); + if (!next()) + return; + } + + /** + * Return total storage size of txnlog that will return by this iterator. + */ + public long getStorageSize() { + long sum = 0; + for (File f : storedFiles) { + sum += f.length(); + } + return sum; + } + + /** + * go to the next logfile + * + * @return true if there is one and false if there is no new file to be read + */ + private boolean goToNextLog() throws IOException { + if (storedFiles.size() > 0) { + this.logFile = storedFiles.remove(storedFiles.size() - 1); + ia = createInputArchive(this.logFile); + return true; + } + return false; + } + + /** + * read the header from the inputarchive + * + * @param ia the inputarchive to be read from + * @param is the inputstream + */ + protected void inStreamCreated(InputArchive ia, InputStream is) + throws IOException { + FileHeader header = new FileHeader(); + header.deserialize(ia, "fileheader"); + if (header.getMagic() != FileTxnLog.TXNLOG_MAGIC) { + throw new IOException("Transaction log: " + this.logFile + " has invalid magic number " + + header.getMagic() + + " != " + FileTxnLog.TXNLOG_MAGIC); + } + } + + /** + * Invoked to indicate that the input stream has been created. + * + * @param ia input archive + * @param is file input stream associated with the input archive. + **/ + protected InputArchive createInputArchive(File logFile) throws IOException { + if (inputStream == null) { + inputStream = new PositionInputStream(new BufferedInputStream(new FileInputStream(logFile))); + LOG.debug("Created new input stream " + logFile); + ia = BinaryInputArchive.getArchive(inputStream); + inStreamCreated(ia, inputStream); + LOG.debug("Created new input archive " + logFile); + } + return ia; + } + + /** + * create a checksum algorithm + * + * @return the checksum algorithm + */ + protected Checksum makeChecksumAlgorithm() { + return new Adler32(); + } + + /** + * the iterator that moves to the next transaction + * + * @return true if there is more transactions to be read false if not. + */ + public boolean next() throws IOException { + if (ia == null) { + return false; + } + try { + long crcValue = ia.readLong("crcvalue"); + byte[] bytes = Util.readTxnBytes(ia); + // Since we preallocate, we define EOF to be an + if (bytes == null || bytes.length == 0) { + throw new EOFException("Failed to read " + logFile); + } + // EOF or corrupted record + // validate CRC + Checksum crc = makeChecksumAlgorithm(); + crc.update(bytes, 0, bytes.length); + if (crcValue != crc.getValue()) + throw new IOException(CRC_ERROR); + hdr = new TxnHeader(); + record = SerializeUtils.deserializeTxn(bytes, hdr); + } catch (EOFException e) { + LOG.debug("EOF excepton " + e); + inputStream.close(); + inputStream = null; + ia = null; + hdr = null; + // this means that the file has ended + // we should go to the next file + if (!goToNextLog()) { + return false; + } + // if we went to the next log file, we should call next() again + return next(); + } catch (IOException e) { + inputStream.close(); + throw e; + } + return true; + } + + /** + * reutrn the current header + * + * @return the current header that is read + */ + public TxnHeader getHeader() { + return hdr; + } + + /** + * return the current transaction + * + * @return the current transaction that is read + */ + public Record getTxn() { + return record; + } + + /** + * close the iterator and release the resources. + */ + public void close() throws IOException { + if (inputStream != null) { + inputStream.close(); + } + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java new file mode 100644 index 00000000000..2a6add96fd2 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java @@ -0,0 +1,400 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.persistence; + +import org.apache.jute.Record; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.DataTree; +import org.apache.zookeeper.server.DataTree.ProcessTxnResult; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; +import org.apache.zookeeper.txn.CreateSessionTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * This is a helper class + * above the implementations + * of txnlog and snapshot + * classes + */ +public class FileTxnSnapLog { + public final static int VERSION = 2; + public final static String version = "version-"; + public static final String ZOOKEEPER_DATADIR_AUTOCREATE = + "zookeeper.datadir.autocreate"; + public static final String ZOOKEEPER_DATADIR_AUTOCREATE_DEFAULT = "true"; + private static final Logger LOG = LoggerFactory.getLogger(FileTxnSnapLog.class); + //the direcotry containing the + //the transaction logs + private final File dataDir; + //the directory containing the + //the snapshot directory + private final File snapDir; + private TxnLog txnLog; + private SnapShot snapLog; + + /** + * the constructor which takes the datadir and + * snapdir. + * @param dataDir the trasaction directory + * @param snapDir the snapshot directory + */ + public FileTxnSnapLog(File dataDir, File snapDir) throws IOException { + LOG.debug("Opening datadir:{} snapDir:{}", dataDir, snapDir); + + this.dataDir = new File(dataDir, version + VERSION); + this.snapDir = new File(snapDir, version + VERSION); + + // by default create snap/log dirs, but otherwise complain instead + // See ZOOKEEPER-1161 for more details + boolean enableAutocreate = Boolean.valueOf( + System.getProperty(ZOOKEEPER_DATADIR_AUTOCREATE, + ZOOKEEPER_DATADIR_AUTOCREATE_DEFAULT)); + + if (!this.dataDir.exists()) { + if (!enableAutocreate) { + throw new DatadirException("Missing data directory " + + this.dataDir + + ", automatic data directory creation is disabled (" + + ZOOKEEPER_DATADIR_AUTOCREATE + + " is false). Please create this directory manually."); + } + + if (!this.dataDir.mkdirs()) { + throw new DatadirException("Unable to create data directory " + + this.dataDir); + } + } + if (!this.snapDir.exists()) { + // by default create this directory, but otherwise complain instead + // See ZOOKEEPER-1161 for more details + if (!enableAutocreate) { + throw new DatadirException("Missing snap directory " + + this.snapDir + + ", automatic data directory creation is disabled (" + + ZOOKEEPER_DATADIR_AUTOCREATE + + " is false). Please create this directory manually."); + } + + if (!this.snapDir.mkdirs()) { + throw new DatadirException("Unable to create snap directory " + + this.snapDir); + } + } + txnLog = new FileTxnLog(this.dataDir); + snapLog = new FileSnap(this.snapDir); + } + + /** + * get the datadir used by this filetxn + * snap log + * @return the data dir + */ + public File getDataDir() { + return this.dataDir; + } + + /** + * get the snap dir used by this + * filetxn snap log + * @return the snap dir + */ + public File getSnapDir() { + return this.snapDir; + } + + /** + * this function restores the server + * database after reading from the + * snapshots and transaction logs + * @param dt the datatree to be restored + * @param sessions the sessions to be restored + * @param listener the playback listener to run on the + * database restoration + * @return the highest zxid restored + * @throws IOException + */ + public long restore(DataTree dt, Map sessions, + PlayBackListener listener) throws IOException { + snapLog.deserialize(dt, sessions); + FileTxnLog txnLog = new FileTxnLog(dataDir); + TxnIterator itr = txnLog.read(dt.lastProcessedZxid + 1); + long highestZxid = dt.lastProcessedZxid; + TxnHeader hdr; + try { + while (true) { + // iterator points to + // the first valid txn when initialized + hdr = itr.getHeader(); + if (hdr == null) { + //empty logs + return dt.lastProcessedZxid; + } + if (hdr.getZxid() < highestZxid && highestZxid != 0) { + LOG.error("{}(higestZxid) > {}(next log) for type {}", + new Object[]{highestZxid, hdr.getZxid(), + hdr.getType()}); + } else { + highestZxid = hdr.getZxid(); + } + try { + processTransaction(hdr, dt, sessions, itr.getTxn()); + } catch (KeeperException.NoNodeException e) { + throw new IOException("Failed to process transaction type: " + + hdr.getType() + " error: " + e.getMessage(), e); + } + listener.onTxnLoaded(hdr, itr.getTxn()); + if (!itr.next()) + break; + } + } finally { + if (itr != null) { + itr.close(); + } + } + return highestZxid; + } + + /** + * Get TxnIterator for iterating through txnlog starting at a given zxid + * + * @param zxid starting zxid + * @return TxnIterator + * @throws IOException + */ + public TxnIterator readTxnLog(long zxid) throws IOException { + return readTxnLog(zxid, true); + } + + /** + * Get TxnIterator for iterating through txnlog starting at a given zxid + * + * @param zxid starting zxid + * @param fastForward true if the iterator should be fast forwarded to point + * to the txn of a given zxid, else the iterator will point to the + * starting txn of a txnlog that may contain txn of a given zxid + * @return TxnIterator + * @throws IOException + */ + public TxnIterator readTxnLog(long zxid, boolean fastForward) + throws IOException { + FileTxnLog txnLog = new FileTxnLog(dataDir); + return txnLog.read(zxid, fastForward); + } + + /** + * process the transaction on the datatree + * @param hdr the hdr of the transaction + * @param dt the datatree to apply transaction to + * @param sessions the sessions to be restored + * @param txn the transaction to be applied + */ + public void processTransaction(TxnHeader hdr, DataTree dt, + Map sessions, Record txn) + throws KeeperException.NoNodeException { + ProcessTxnResult rc; + switch (hdr.getType()) { + case OpCode.createSession: + sessions.put(hdr.getClientId(), + ((CreateSessionTxn) txn).getTimeOut()); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, + "playLog --- create session in log: 0x" + + Long.toHexString(hdr.getClientId()) + + " with timeout: " + + ((CreateSessionTxn) txn).getTimeOut()); + } + // give dataTree a chance to sync its lastProcessedZxid + rc = dt.processTxn(hdr, txn); + break; + case OpCode.closeSession: + sessions.remove(hdr.getClientId()); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, + "playLog --- close session in log: 0x" + + Long.toHexString(hdr.getClientId())); + } + rc = dt.processTxn(hdr, txn); + break; + default: + rc = dt.processTxn(hdr, txn); + } + + /** + * Snapshots are lazily created. So when a snapshot is in progress, + * there is a chance for later transactions to make into the + * snapshot. Then when the snapshot is restored, NONODE/NODEEXISTS + * errors could occur. It should be safe to ignore these. + */ + if (rc.err != Code.OK.intValue()) { + LOG.debug( + "Ignoring processTxn failure hdr: {}, error: {}, path: {}", + hdr.getType(), rc.err, rc.path); + } + } + + /** + * the last logged zxid on the transaction logs + * @return the last logged zxid + */ + public long getLastLoggedZxid() { + FileTxnLog txnLog = new FileTxnLog(dataDir); + return txnLog.getLastLoggedZxid(); + } + + /** + * save the datatree and the sessions into a snapshot + * @param dataTree the datatree to be serialized onto disk + * @param sessionsWithTimeouts the sesssion timeouts to be + * serialized onto disk + * @throws IOException + */ + public void save(DataTree dataTree, + ConcurrentHashMap sessionsWithTimeouts) + throws IOException { + long lastZxid = dataTree.lastProcessedZxid; + File snapshotFile = new File(snapDir, Util.makeSnapshotName(lastZxid)); + LOG.info("Snapshotting: 0x{} to {}", Long.toHexString(lastZxid), + snapshotFile); + snapLog.serialize(dataTree, sessionsWithTimeouts, snapshotFile); + + } + + /** + * truncate the transaction logs the zxid + * specified + * @param zxid the zxid to truncate the logs to + * @return true if able to truncate the log, false if not + * @throws IOException + */ + public boolean truncateLog(long zxid) throws IOException { + // close the existing txnLog and snapLog + close(); + + // truncate it + FileTxnLog truncLog = new FileTxnLog(dataDir); + boolean truncated = truncLog.truncate(zxid); + truncLog.close(); + + // re-open the txnLog and snapLog + // I'd rather just close/reopen this object itself, however that + // would have a big impact outside ZKDatabase as there are other + // objects holding a reference to this object. + txnLog = new FileTxnLog(dataDir); + snapLog = new FileSnap(snapDir); + + return truncated; + } + + /** + * the most recent snapshot in the snapshot + * directory + * @return the file that contains the most + * recent snapshot + * @throws IOException + */ + public File findMostRecentSnapshot() throws IOException { + FileSnap snaplog = new FileSnap(snapDir); + return snaplog.findMostRecentSnapshot(); + } + + /** + * the n most recent snapshots + * @param n the number of recent snapshots + * @return the list of n most recent snapshots, with + * the most recent in front + * @throws IOException + */ + public List findNRecentSnapshots(int n) throws IOException { + FileSnap snaplog = new FileSnap(snapDir); + return snaplog.findNRecentSnapshots(n); + } + + /** + * get the snapshot logs that are greater than + * the given zxid + * @param zxid the zxid that contains logs greater than + * zxid + * @return + */ + public File[] getSnapshotLogs(long zxid) { + return FileTxnLog.getLogFiles(dataDir.listFiles(), zxid); + } + + /** + * append the request to the transaction logs + * @param si the request to be appended + * returns true iff something appended, otw false + * @throws IOException + */ + public boolean append(Request si) throws IOException { + return txnLog.append(si.getHdr(), si.getTxn()); + } + + /** + * commit the transaction of logs + * @throws IOException + */ + public void commit() throws IOException { + txnLog.commit(); + } + + /** + * roll the transaction logs + * @throws IOException + */ + public void rollLog() throws IOException { + txnLog.rollLog(); + } + + /** + * close the transaction log files + * @throws IOException + */ + public void close() throws IOException { + txnLog.close(); + snapLog.close(); + } + + /** + * This listener helps + * the external apis calling + * restore to gather information + * while the data is being + * restored. + */ + public interface PlayBackListener { + void onTxnLoaded(TxnHeader hdr, Record rec); + } + + @SuppressWarnings("serial") + public static class DatadirException extends IOException { + public DatadirException(String msg) { + super(msg); + } + + public DatadirException(String msg, Exception e) { + super(msg, e); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java b/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java new file mode 100644 index 00000000000..4ab4f70649d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java @@ -0,0 +1,60 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.persistence; + +import org.apache.zookeeper.server.DataTree; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +/** + * snapshot interface for the persistence layer. + * implement this interface for implementing + * snapshots. + */ +public interface SnapShot { + + /** + * deserialize a data tree from the last valid snapshot and + * return the last zxid that was deserialized + * @param dt the datatree to be deserialized into + * @param sessions the sessions to be deserialized into + * @return the last zxid that was deserialized from the snapshot + * @throws IOException + */ + long deserialize(DataTree dt, Map sessions) + throws IOException; + + /** + * persist the datatree and the sessions into a persistence storage + * @param dt the datatree to be serialized + * @param sessions + * @throws IOException + */ + void serialize(DataTree dt, Map sessions, + File name) + throws IOException; + + /** + * find the most recent snapshot file + * @return the most recent snapshot file + * @throws IOException + */ + File findMostRecentSnapshot() throws IOException; + + /** + * free resources from this snapshot immediately + * @throws IOException + */ + void close() throws IOException; +} diff --git a/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java b/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java new file mode 100644 index 00000000000..f7ed3d70bfe --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.persistence; + +import org.apache.jute.Record; +import org.apache.zookeeper.txn.TxnHeader; + +import java.io.IOException; + +/** + * Interface for reading transaction logs. + * + */ +public interface TxnLog { + + /** + * roll the current + * log being appended to + * @throws IOException + */ + void rollLog() throws IOException; + + /** + * Append a request to the transaction log + * @param hdr the transaction header + * @param r the transaction itself + * returns true iff something appended, otw false + * @throws IOException + */ + boolean append(TxnHeader hdr, Record r) throws IOException; + + /** + * Start reading the transaction logs + * from a given zxid + * @param zxid + * @return returns an iterator to read the + * next transaction in the logs. + * @throws IOException + */ + TxnIterator read(long zxid) throws IOException; + + /** + * the last zxid of the logged transactions. + * @return the last zxid of the logged transactions. + * @throws IOException + */ + long getLastLoggedZxid() throws IOException; + + /** + * truncate the log to get in sync with the + * leader. + * @param zxid the zxid to truncate at. + * @throws IOException + */ + boolean truncate(long zxid) throws IOException; + + /** + * the dbid for this transaction log. + * @return the dbid for this transaction log. + * @throws IOException + */ + long getDbId() throws IOException; + + /** + * commmit the trasaction and make sure + * they are persisted + * @throws IOException + */ + void commit() throws IOException; + + /** + * close the transactions logs + */ + void close() throws IOException; + + /** + * an iterating interface for reading + * transaction logs. + */ + public interface TxnIterator { + /** + * return the transaction header. + * @return return the transaction header. + */ + TxnHeader getHeader(); + + /** + * return the transaction record. + * @return return the transaction record. + */ + Record getTxn(); + + /** + * go to the next transaction record. + * @throws IOException + */ + boolean next() throws IOException; + + /** + * close files and release the + * resources + * @throws IOException + */ + void close() throws IOException; + + /** + * Get an estimated storage space used to store transaction records + * that will return by this iterator + * @throws IOException + */ + long getStorageSize() throws IOException; + } +} + diff --git a/src/java/main/org/apache/zookeeper/server/persistence/Util.java b/src/java/main/org/apache/zookeeper/server/persistence/Util.java new file mode 100644 index 00000000000..17e37a9d24e --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/persistence/Util.java @@ -0,0 +1,319 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.persistence; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.io.Serializable; +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Properties; + +/** + * A collection of utility methods for dealing with file name parsing, + * low level I/O file operations and marshalling/unmarshalling. + */ +public class Util { + private static final Logger LOG = LoggerFactory.getLogger(Util.class); + private static final String SNAP_DIR = "snapDir"; + private static final String LOG_DIR = "logDir"; + private static final String DB_FORMAT_CONV = "dbFormatConversion"; + private static final ByteBuffer fill = ByteBuffer.allocateDirect(1); + + public static String makeURIString(String dataDir, String dataLogDir, + String convPolicy) { + String uri = "file:" + SNAP_DIR + "=" + dataDir + ";" + LOG_DIR + "=" + dataLogDir; + if (convPolicy != null) + uri += ";" + DB_FORMAT_CONV + "=" + convPolicy; + return uri.replace('\\', '/'); + } + + /** + * Given two directory files the method returns a well-formed + * logfile provider URI. This method is for backward compatibility with the + * existing code that only supports logfile persistence and expects these two + * parameters passed either on the command-line or in the configuration file. + * + * @param dataDir snapshot directory + * @param dataLogDir transaction log directory + * @return logfile provider URI + */ + public static URI makeFileLoggerURL(File dataDir, File dataLogDir) { + return URI.create(makeURIString(dataDir.getPath(), dataLogDir.getPath(), null)); + } + + public static URI makeFileLoggerURL(File dataDir, File dataLogDir, String convPolicy) { + return URI.create(makeURIString(dataDir.getPath(), dataLogDir.getPath(), convPolicy)); + } + + /** + * Creates a valid transaction log file name. + * + * @param zxid used as a file name suffix (extention) + * @return file name + */ + public static String makeLogName(long zxid) { + return "log." + Long.toHexString(zxid); + } + + /** + * Creates a snapshot file name. + * + * @param zxid used as a suffix + * @return file name + */ + public static String makeSnapshotName(long zxid) { + return "snapshot." + Long.toHexString(zxid); + } + + /** + * Extracts snapshot directory property value from the container. + * + * @param props properties container + * @return file representing the snapshot directory + */ + public static File getSnapDir(Properties props) { + return new File(props.getProperty(SNAP_DIR)); + } + + /** + * Extracts transaction log directory property value from the container. + * + * @param props properties container + * @return file representing the txn log directory + */ + public static File getLogDir(Properties props) { + return new File(props.getProperty(LOG_DIR)); + } + + /** + * Extracts the value of the dbFormatConversion attribute. + * + * @param props properties container + * @return value of the dbFormatConversion attribute + */ + public static String getFormatConversionPolicy(Properties props) { + return props.getProperty(DB_FORMAT_CONV); + } + + /** + * Extracts zxid from the file name. The file name should have been created + * using one of the {@link makeLogName} or {@link makeSnapshotName}. + * + * @param name the file name to parse + * @param prefix the file name prefix (snapshot or log) + * @return zxid + */ + public static long getZxidFromName(String name, String prefix) { + long zxid = -1; + String nameParts[] = name.split("\\."); + if (nameParts.length == 2 && nameParts[0].equals(prefix)) { + try { + zxid = Long.parseLong(nameParts[1], 16); + } catch (NumberFormatException e) { + } + } + return zxid; + } + + /** + * Verifies that the file is a valid snapshot. Snapshot may be invalid if + * it's incomplete as in a situation when the server dies while in the process + * of storing a snapshot. Any file that is not a snapshot is also + * an invalid snapshot. + * + * @param f file to verify + * @return true if the snapshot is valid + * @throws IOException + */ + public static boolean isValidSnapshot(File f) throws IOException { + if (f == null || Util.getZxidFromName(f.getName(), "snapshot") == -1) + return false; + + // Check for a valid snapshot + RandomAccessFile raf = new RandomAccessFile(f, "r"); + try { + // including the header and the last / bytes + // the snapshot should be atleast 10 bytes + if (raf.length() < 10) { + return false; + } + raf.seek(raf.length() - 5); + byte bytes[] = new byte[5]; + int readlen = 0; + int l; + while (readlen < 5 && + (l = raf.read(bytes, readlen, bytes.length - readlen)) >= 0) { + readlen += l; + } + if (readlen != bytes.length) { + LOG.info("Invalid snapshot " + f + + " too short, len = " + readlen); + return false; + } + ByteBuffer bb = ByteBuffer.wrap(bytes); + int len = bb.getInt(); + byte b = bb.get(); + if (len != 1 || b != '/') { + LOG.info("Invalid snapshot " + f + " len = " + len + + " byte = " + (b & 0xff)); + return false; + } + } finally { + raf.close(); + } + + return true; + } + + /** + * Grows the file to the specified number of bytes. This only happenes if + * the current file position is sufficiently close (less than 4K) to end of + * file. + * + * @param f output stream to pad + * @param currentSize application keeps track of the cuurent file size + * @param preAllocSize how many bytes to pad + * @return the new file size. It can be the same as currentSize if no + * padding was done. + * @throws IOException + */ + public static long padLogFile(FileOutputStream f, long currentSize, + long preAllocSize) throws IOException { + long position = f.getChannel().position(); + if (position + 4096 >= currentSize) { + currentSize = currentSize + preAllocSize; + fill.position(0); + f.getChannel().write(fill, currentSize - fill.remaining()); + } + return currentSize; + } + + /** + * Reads a transaction entry from the input archive. + * @param ia archive to read from + * @return null if the entry is corrupted or EOF has been reached; a buffer + * (possible empty) containing serialized transaction record. + * @throws IOException + */ + public static byte[] readTxnBytes(InputArchive ia) throws IOException { + try { + byte[] bytes = ia.readBuffer("txtEntry"); + // Since we preallocate, we define EOF to be an + // empty transaction + if (bytes.length == 0) + return bytes; + if (ia.readByte("EOF") != 'B') { + LOG.error("Last transaction was partial."); + return null; + } + return bytes; + } catch (EOFException e) { + } + return null; + } + + + /** + * Serializes transaction header and transaction data into a byte buffer. + * + * @param hdr transaction header + * @param txn transaction data + * @return serialized transaction record + * @throws IOException + */ + public static byte[] marshallTxnEntry(TxnHeader hdr, Record txn) + throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputArchive boa = BinaryOutputArchive.getArchive(baos); + + hdr.serialize(boa, "hdr"); + if (txn != null) { + txn.serialize(boa, "txn"); + } + return baos.toByteArray(); + } + + /** + * Write the serialized transaction record to the output archive. + * + * @param oa output archive + * @param bytes serialized trasnaction record + * @throws IOException + */ + public static void writeTxnBytes(OutputArchive oa, byte[] bytes) + throws IOException { + oa.writeBuffer(bytes, "txnEntry"); + oa.writeByte((byte) 0x42, "EOR"); // 'B' + } + + /** + * Sort the list of files. Recency as determined by the version component + * of the file name. + * + * @param files array of files + * @param prefix files not matching this prefix are assumed to have a + * version = -1) + * @param ascending true sorted in ascending order, false results in + * descending order + * @return sorted input files + */ + public static List sortDataDir(File[] files, String prefix, boolean ascending) { + if (files == null) + return new ArrayList(0); + List filelist = Arrays.asList(files); + Collections.sort(filelist, new DataDirFileComparator(prefix, ascending)); + return filelist; + } + + /** + * Compare file file names of form "prefix.version". Sort order result + * returned in order of version. + */ + private static class DataDirFileComparator + implements Comparator, Serializable { + private static final long serialVersionUID = -2648639884525140318L; + + private String prefix; + private boolean ascending; + + public DataDirFileComparator(String prefix, boolean ascending) { + this.prefix = prefix; + this.ascending = ascending; + } + + public int compare(File o1, File o2) { + long z1 = Util.getZxidFromName(o1.getName(), prefix); + long z2 = Util.getZxidFromName(o2.getName(), prefix); + int result = z1 < z2 ? -1 : (z1 > z2 ? 1 : 0); + return ascending ? result : -result; + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/AckRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/AckRequestProcessor.java new file mode 100644 index 00000000000..fbe77cee20b --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/AckRequestProcessor.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This is a very simple RequestProcessor that simply forwards a request from a + * previous stage to the leader as an ACK. + */ +class AckRequestProcessor implements RequestProcessor { + private static final Logger LOG = LoggerFactory.getLogger(AckRequestProcessor.class); + Leader leader; + + AckRequestProcessor(Leader leader) { + this.leader = leader; + } + + /** + * Forward the request as an ACK to the leader + */ + public void processRequest(Request request) { + QuorumPeer self = leader.self; + if (self != null) + leader.processAck(self.getId(), request.zxid, null); + else + LOG.error("Null QuorumPeer"); + } + + public void shutdown() { + // XXX No need to do anything + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java b/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java new file mode 100644 index 00000000000..f376f1d5357 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java @@ -0,0 +1,961 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.server.ZooKeeperThread; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +/** + * @deprecated This class has been deprecated as of release 3.4.0. + */ +@Deprecated +public class AuthFastLeaderElection implements Election { + private static final Logger LOG = LoggerFactory.getLogger(AuthFastLeaderElection.class); + + /* Sequence numbers for messages */ + static int sequencer = 0; + static int maxTag = 0; + + /* + * Determine how much time a process has to wait once it believes that it + * has reached the end of leader election. + */ + static int finalizeWait = 100; + + /* + * Challenge counter to avoid replay attacks + */ + + static int challengeCounter = 0; + + /* + * Flag to determine whether to authenticate or not + */ + LinkedBlockingQueue sendqueue; + LinkedBlockingQueue recvqueue; + QuorumPeer self; + int port; + AtomicLong logicalclock = new AtomicLong(); /* Election instance */ + DatagramSocket mySocket; + long proposedLeader; + long proposedZxid; + private boolean authEnabled = false; + public AuthFastLeaderElection(QuorumPeer self, + boolean auth) { + this.authEnabled = auth; + starter(self); + } + public AuthFastLeaderElection(QuorumPeer self) { + starter(self); + } + + private void starter(QuorumPeer self) { + this.self = self; + port = self.getVotingView().get(self.getId()).electionAddr.getPort(); + proposedLeader = -1; + proposedZxid = -1; + + try { + mySocket = new DatagramSocket(port); + // mySocket.setSoTimeout(20000); + } catch (SocketException e1) { + e1.printStackTrace(); + throw new RuntimeException(); + } + sendqueue = new LinkedBlockingQueue(2 * self.getVotingView().size()); + recvqueue = new LinkedBlockingQueue(2 * self.getVotingView() + .size()); + new Messenger(self.getVotingView().size() * 2, mySocket); + } + + private void leaveInstance() { + logicalclock.incrementAndGet(); + } + + private void sendNotifications() { + for (QuorumServer server : self.getView().values()) { + + ToSend notmsg = new ToSend(ToSend.mType.notification, + AuthFastLeaderElection.sequencer++, proposedLeader, + proposedZxid, logicalclock.get(), QuorumPeer.ServerState.LOOKING, + self.getView().get(server.id).electionAddr); + + sendqueue.offer(notmsg); + } + } + + private boolean totalOrderPredicate(long id, long zxid) { + if ((zxid > proposedZxid) + || ((zxid == proposedZxid) && (id > proposedLeader))) + return true; + else + return false; + + } + + private boolean termPredicate(HashMap votes, + long l, long zxid) { + + + Collection votesCast = votes.values(); + int count = 0; + /* + * First make the views consistent. Sometimes peers will have different + * zxids for a server depending on timing. + */ + for (Vote v : votesCast) { + if ((v.getId() == l) && (v.getZxid() == zxid)) + count++; + } + + if (count > (self.getVotingView().size() / 2)) + return true; + else + return false; + + } + + /** + * There is nothing to shutdown in this implementation of + * leader election, so we simply have an empty method. + */ + public void shutdown() { + } + + /** + * Invoked in QuorumPeer to find or elect a new leader. + * + * @throws InterruptedException + */ + public Vote lookForLeader() throws InterruptedException { + try { + self.jmxLeaderElectionBean = new LeaderElectionBean(); + MBeanRegistry.getInstance().register( + self.jmxLeaderElectionBean, self.jmxLocalPeerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + self.jmxLeaderElectionBean = null; + } + + try { + HashMap recvset = + new HashMap(); + + HashMap outofelection = + new HashMap(); + + logicalclock.incrementAndGet(); + + proposedLeader = self.getId(); + proposedZxid = self.getLastLoggedZxid(); + + LOG.info("Election tally"); + sendNotifications(); + + /* + * Loop in which we exchange notifications until we find a leader + */ + + while (self.getPeerState() == ServerState.LOOKING) { + /* + * Remove next notification from queue, times out after 2 times + * the termination time + */ + Notification n = recvqueue.poll(2 * finalizeWait, + TimeUnit.MILLISECONDS); + + /* + * Sends more notifications if haven't received enough. + * Otherwise processes new notification. + */ + if (n == null) { + if (((!outofelection.isEmpty()) || (recvset.size() > 1))) + sendNotifications(); + } else + switch (n.state) { + case LOOKING: + if (n.epoch > logicalclock.get()) { + logicalclock.set(n.epoch); + recvset.clear(); + if (totalOrderPredicate(n.leader, n.zxid)) { + proposedLeader = n.leader; + proposedZxid = n.zxid; + } + sendNotifications(); + } else if (n.epoch < logicalclock.get()) { + break; + } else if (totalOrderPredicate(n.leader, n.zxid)) { + proposedLeader = n.leader; + proposedZxid = n.zxid; + + sendNotifications(); + } + + recvset.put(n.addr, new Vote(n.leader, n.zxid)); + + // If have received from all nodes, then terminate + if (self.getVotingView().size() == recvset.size()) { + self.setPeerState((proposedLeader == self.getId()) ? + ServerState.LEADING : ServerState.FOLLOWING); + // if (self.state == ServerState.FOLLOWING) { + // Thread.sleep(100); + // } + leaveInstance(); + return new Vote(proposedLeader, proposedZxid); + + } else if (termPredicate(recvset, proposedLeader, + proposedZxid)) { + // Otherwise, wait for a fixed amount of time + LOG.info("Passed predicate"); + Thread.sleep(finalizeWait); + + // Notification probe = recvqueue.peek(); + + // Verify if there is any change in the proposed leader + while ((!recvqueue.isEmpty()) + && !totalOrderPredicate( + recvqueue.peek().leader, recvqueue + .peek().zxid)) { + recvqueue.poll(); + } + if (recvqueue.isEmpty()) { + // LOG.warn("Proposed leader: " + + // proposedLeader); + self.setPeerState( + (proposedLeader == self.getId()) ? + ServerState.LEADING : + ServerState.FOLLOWING); + + leaveInstance(); + return new Vote(proposedLeader, proposedZxid); + } + } + break; + case LEADING: + outofelection.put(n.addr, new Vote(n.leader, n.zxid)); + + if (termPredicate(outofelection, n.leader, n.zxid)) { + + self.setPeerState((n.leader == self.getId()) ? + ServerState.LEADING : ServerState.FOLLOWING); + + leaveInstance(); + return new Vote(n.leader, n.zxid); + } + break; + case FOLLOWING: + outofelection.put(n.addr, new Vote(n.leader, n.zxid)); + + if (termPredicate(outofelection, n.leader, n.zxid)) { + + self.setPeerState((n.leader == self.getId()) ? + ServerState.LEADING : ServerState.FOLLOWING); + + leaveInstance(); + return new Vote(n.leader, n.zxid); + } + break; + default: + break; + } + } + + return null; + } finally { + try { + if (self.jmxLeaderElectionBean != null) { + MBeanRegistry.getInstance().unregister( + self.jmxLeaderElectionBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + self.jmxLeaderElectionBean = null; + } + } + + static public class Notification { + /* + * Proposed leader + */ + long leader; + + /* + * zxid of the proposed leader + */ + long zxid; + + /* + * Epoch + */ + long epoch; + + /* + * current state of sender + */ + QuorumPeer.ServerState state; + + /* + * Address of the sender + */ + InetSocketAddress addr; + } + + /* + * Messages to send, both Notifications and Acks + */ + static public class ToSend { + /* + * Message type: 0 notification, 1 acknowledgement + */ + int type; + /* + * Proposed leader in the case of notification + */ + long leader; + /* + * id contains the tag for acks, and zxid for notifications + */ + long zxid; + /* + * Epoch + */ + long epoch; + /* + * Current state; + */ + QuorumPeer.ServerState state; + /* + * Message tag + */ + long tag; + InetSocketAddress addr; + + ToSend(mType type, long tag, long leader, long zxid, long epoch, + ServerState state, InetSocketAddress addr) { + + switch (type) { + case crequest: + this.type = 0; + this.tag = tag; + this.leader = leader; + this.zxid = zxid; + this.epoch = epoch; + this.state = state; + this.addr = addr; + + break; + case challenge: + this.type = 1; + this.tag = tag; + this.leader = leader; + this.zxid = zxid; + this.epoch = epoch; + this.state = state; + this.addr = addr; + + break; + case notification: + this.type = 2; + this.leader = leader; + this.zxid = zxid; + this.epoch = epoch; + this.state = QuorumPeer.ServerState.LOOKING; + this.tag = tag; + this.addr = addr; + + break; + case ack: + this.type = 3; + this.tag = tag; + this.leader = leader; + this.zxid = zxid; + this.epoch = epoch; + this.state = state; + this.addr = addr; + + break; + default: + break; + } + } + + static enum mType { + crequest, challenge, notification, ack + } + } + + private class Messenger { + + final DatagramSocket mySocket; + final Set ackset; + final ConcurrentHashMap challengeMap; + final ConcurrentHashMap challengeMutex; + final ConcurrentHashMap ackMutex; + final ConcurrentHashMap> addrChallengeMap; + long lastProposedLeader; + long lastProposedZxid; + long lastEpoch; + + Messenger(int threads, DatagramSocket s) { + mySocket = s; + ackset = Collections.newSetFromMap(new ConcurrentHashMap()); + challengeMap = new ConcurrentHashMap(); + challengeMutex = new ConcurrentHashMap(); + ackMutex = new ConcurrentHashMap(); + addrChallengeMap = new ConcurrentHashMap>(); + lastProposedLeader = 0; + lastProposedZxid = 0; + lastEpoch = 0; + + for (int i = 0; i < threads; ++i) { + Thread t = new Thread(new WorkerSender(3), + "WorkerSender Thread: " + (i + 1)); + t.setDaemon(true); + t.start(); + } + + for (QuorumServer server : self.getVotingView().values()) { + InetSocketAddress saddr = new InetSocketAddress(server.addr + .getAddress(), port); + addrChallengeMap.put(saddr, new ConcurrentHashMap()); + } + + Thread t = new Thread(new WorkerReceiver(s, this), + "WorkerReceiver Thread"); + t.start(); + } + + class WorkerReceiver extends ZooKeeperThread { + + DatagramSocket mySocket; + Messenger myMsg; + + WorkerReceiver(DatagramSocket s, Messenger msg) { + super("WorkerReceiver-" + s.getRemoteSocketAddress()); + mySocket = s; + myMsg = msg; + } + + boolean saveChallenge(long tag, long challenge) { + Semaphore s = challengeMutex.get(tag); + if (s != null) { + synchronized (Messenger.this) { + challengeMap.put(tag, challenge); + challengeMutex.remove(tag); + } + + + s.release(); + } else { + LOG.error("No challenge mutex object"); + } + + + return true; + } + + public void run() { + byte responseBytes[] = new byte[48]; + ByteBuffer responseBuffer = ByteBuffer.wrap(responseBytes); + DatagramPacket responsePacket = new DatagramPacket( + responseBytes, responseBytes.length); + while (true) { + // Sleeps on receive + try { + responseBuffer.clear(); + mySocket.receive(responsePacket); + } catch (IOException e) { + LOG.warn("Ignoring exception receiving", e); + } + // Receive new message + if (responsePacket.getLength() != responseBytes.length) { + LOG.warn("Got a short response: " + + responsePacket.getLength() + " " + + responsePacket.toString()); + continue; + } + responseBuffer.clear(); + int type = responseBuffer.getInt(); + if ((type > 3) || (type < 0)) { + LOG.warn("Got bad Msg type: " + type); + continue; + } + long tag = responseBuffer.getLong(); + + QuorumPeer.ServerState ackstate = QuorumPeer.ServerState.LOOKING; + switch (responseBuffer.getInt()) { + case 0: + ackstate = QuorumPeer.ServerState.LOOKING; + break; + case 1: + ackstate = QuorumPeer.ServerState.LEADING; + break; + case 2: + ackstate = QuorumPeer.ServerState.FOLLOWING; + break; + default: + LOG.warn("unknown type " + responseBuffer.getInt()); + break; + } + + Vote current = self.getCurrentVote(); + + switch (type) { + case 0: + // Receive challenge request + ToSend c = new ToSend(ToSend.mType.challenge, tag, + current.getId(), current.getZxid(), + logicalclock.get(), self.getPeerState(), + (InetSocketAddress) responsePacket + .getSocketAddress()); + sendqueue.offer(c); + break; + case 1: + // Receive challenge and store somewhere else + long challenge = responseBuffer.getLong(); + saveChallenge(tag, challenge); + + break; + case 2: + Notification n = new Notification(); + n.leader = responseBuffer.getLong(); + n.zxid = responseBuffer.getLong(); + n.epoch = responseBuffer.getLong(); + n.state = ackstate; + n.addr = (InetSocketAddress) responsePacket + .getSocketAddress(); + + if ((myMsg.lastEpoch <= n.epoch) + && ((n.zxid > myMsg.lastProposedZxid) + || ((n.zxid == myMsg.lastProposedZxid) + && (n.leader > myMsg.lastProposedLeader)))) { + myMsg.lastProposedZxid = n.zxid; + myMsg.lastProposedLeader = n.leader; + myMsg.lastEpoch = n.epoch; + } + + long recChallenge; + InetSocketAddress addr = (InetSocketAddress) responsePacket + .getSocketAddress(); + if (authEnabled) { + ConcurrentHashMap tmpMap = addrChallengeMap.get(addr); + if (tmpMap != null) { + if (tmpMap.get(tag) != null) { + recChallenge = responseBuffer.getLong(); + + if (tmpMap.get(tag) == recChallenge) { + recvqueue.offer(n); + + ToSend a = new ToSend(ToSend.mType.ack, + tag, current.getId(), + current.getZxid(), + logicalclock.get(), self.getPeerState(), + addr); + + sendqueue.offer(a); + } else { + LOG.warn("Incorrect challenge: " + + recChallenge + ", " + + addrChallengeMap.toString()); + } + } else { + LOG.warn("No challenge for host: " + addr + + " " + tag); + } + } + } else { + recvqueue.offer(n); + + ToSend a = new ToSend(ToSend.mType.ack, tag, + current.getId(), current.getZxid(), + logicalclock.get(), self.getPeerState(), + (InetSocketAddress) responsePacket + .getSocketAddress()); + + sendqueue.offer(a); + } + break; + + // Upon reception of an ack message, remove it from the + // queue + case 3: + Semaphore s = ackMutex.get(tag); + + if (s != null) + s.release(); + else LOG.error("Empty ack semaphore"); + + ackset.add(tag); + + if (authEnabled) { + ConcurrentHashMap tmpMap = addrChallengeMap.get(responsePacket + .getSocketAddress()); + if (tmpMap != null) { + tmpMap.remove(tag); + } else { + LOG.warn("No such address in the ensemble configuration " + responsePacket + .getSocketAddress()); + } + } + + if (ackstate != QuorumPeer.ServerState.LOOKING) { + Notification outofsync = new Notification(); + outofsync.leader = responseBuffer.getLong(); + outofsync.zxid = responseBuffer.getLong(); + outofsync.epoch = responseBuffer.getLong(); + outofsync.state = ackstate; + outofsync.addr = (InetSocketAddress) responsePacket + .getSocketAddress(); + + recvqueue.offer(outofsync); + } + + break; + // Default case + default: + LOG.warn("Received message of incorrect type " + type); + break; + } + } + } + } + + class WorkerSender extends ZooKeeperThread { + + Random rand; + int maxAttempts; + int ackWait = finalizeWait; + + /* + * Receives a socket and max number of attempts as input + */ + + WorkerSender(int attempts) { + super("WorkerSender"); + maxAttempts = attempts; + rand = new Random(java.lang.Thread.currentThread().getId() + + Time.currentElapsedTime()); + } + + long genChallenge() { + byte buf[] = new byte[8]; + + buf[0] = (byte) ((challengeCounter & 0xff000000) >>> 24); + buf[1] = (byte) ((challengeCounter & 0x00ff0000) >>> 16); + buf[2] = (byte) ((challengeCounter & 0x0000ff00) >>> 8); + buf[3] = (byte) ((challengeCounter & 0x000000ff)); + + challengeCounter++; + int secret = rand.nextInt(java.lang.Integer.MAX_VALUE); + + buf[4] = (byte) ((secret & 0xff000000) >>> 24); + buf[5] = (byte) ((secret & 0x00ff0000) >>> 16); + buf[6] = (byte) ((secret & 0x0000ff00) >>> 8); + buf[7] = (byte) ((secret & 0x000000ff)); + + return (((long) (buf[0] & 0xFF)) << 56) + + (((long) (buf[1] & 0xFF)) << 48) + + (((long) (buf[2] & 0xFF)) << 40) + + (((long) (buf[3] & 0xFF)) << 32) + + (((long) (buf[4] & 0xFF)) << 24) + + (((long) (buf[5] & 0xFF)) << 16) + + (((long) (buf[6] & 0xFF)) << 8) + + ((long) (buf[7] & 0xFF)); + } + + public void run() { + while (true) { + try { + ToSend m = sendqueue.take(); + process(m); + } catch (InterruptedException e) { + break; + } + + } + } + + private void process(ToSend m) { + int attempts = 0; + byte zeroes[]; + byte requestBytes[] = new byte[48]; + DatagramPacket requestPacket = new DatagramPacket(requestBytes, + requestBytes.length); + ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); + + switch (m.type) { + case 0: + /* + * Building challenge request packet to send + */ + requestBuffer.clear(); + requestBuffer.putInt(ToSend.mType.crequest.ordinal()); + requestBuffer.putLong(m.tag); + requestBuffer.putInt(m.state.ordinal()); + zeroes = new byte[32]; + requestBuffer.put(zeroes); + + requestPacket.setLength(48); + try { + requestPacket.setSocketAddress(m.addr); + } catch (IllegalArgumentException e) { + // Sun doesn't include the address that causes this + // exception to be thrown, so we wrap the exception + // in order to capture this critical detail. + throw new IllegalArgumentException( + "Unable to set socket address on packet, msg:" + + e.getMessage() + " with addr:" + m.addr, + e); + } + + try { + if (challengeMap.get(m.tag) == null) { + mySocket.send(requestPacket); + } + } catch (IOException e) { + LOG.warn("Exception while sending challenge: ", e); + } + + break; + case 1: + /* + * Building challenge packet to send + */ + + long newChallenge; + ConcurrentHashMap tmpMap = addrChallengeMap.get(m.addr); + if (tmpMap != null) { + Long tmpLong = tmpMap.get(m.tag); + if (tmpLong != null) { + newChallenge = tmpLong; + } else { + newChallenge = genChallenge(); + } + + tmpMap.put(m.tag, newChallenge); + + requestBuffer.clear(); + requestBuffer.putInt(ToSend.mType.challenge.ordinal()); + requestBuffer.putLong(m.tag); + requestBuffer.putInt(m.state.ordinal()); + requestBuffer.putLong(newChallenge); + zeroes = new byte[24]; + requestBuffer.put(zeroes); + + requestPacket.setLength(48); + try { + requestPacket.setSocketAddress(m.addr); + } catch (IllegalArgumentException e) { + // Sun doesn't include the address that causes this + // exception to be thrown, so we wrap the exception + // in order to capture this critical detail. + throw new IllegalArgumentException( + "Unable to set socket address on packet, msg:" + + e.getMessage() + " with addr:" + m.addr, + e); + } + + + try { + mySocket.send(requestPacket); + } catch (IOException e) { + LOG.warn("Exception while sending challenge: ", e); + } + } else { + LOG.error("Address is not in the configuration: " + m.addr); + } + + break; + case 2: + + /* + * Building notification packet to send + */ + + requestBuffer.clear(); + requestBuffer.putInt(m.type); + requestBuffer.putLong(m.tag); + requestBuffer.putInt(m.state.ordinal()); + requestBuffer.putLong(m.leader); + requestBuffer.putLong(m.zxid); + requestBuffer.putLong(m.epoch); + zeroes = new byte[8]; + requestBuffer.put(zeroes); + + requestPacket.setLength(48); + try { + requestPacket.setSocketAddress(m.addr); + } catch (IllegalArgumentException e) { + // Sun doesn't include the address that causes this + // exception to be thrown, so we wrap the exception + // in order to capture this critical detail. + throw new IllegalArgumentException( + "Unable to set socket address on packet, msg:" + + e.getMessage() + " with addr:" + m.addr, + e); + } + + + boolean myChallenge = false; + boolean myAck = false; + + while (attempts < maxAttempts) { + try { + /* + * Try to obtain a challenge only if does not have + * one yet + */ + + if (!myChallenge && authEnabled) { + ToSend crequest = new ToSend( + ToSend.mType.crequest, m.tag, m.leader, + m.zxid, m.epoch, + QuorumPeer.ServerState.LOOKING, m.addr); + sendqueue.offer(crequest); + + try { + double timeout = ackWait + * java.lang.Math.pow(2, attempts); + + Semaphore s = new Semaphore(0); + synchronized (Messenger.this) { + challengeMutex.put(m.tag, s); + s.tryAcquire((long) timeout, TimeUnit.MILLISECONDS); + myChallenge = challengeMap + .containsKey(m.tag); + } + } catch (InterruptedException e) { + LOG.warn("Challenge request exception: ", e); + } + } + + /* + * If don't have challenge yet, skip sending + * notification + */ + + if (authEnabled && !myChallenge) { + attempts++; + continue; + } + + if (authEnabled) { + requestBuffer.position(40); + Long tmpLong = challengeMap.get(m.tag); + if (tmpLong != null) { + requestBuffer.putLong(tmpLong); + } else { + LOG.warn("No challenge with tag: " + m.tag); + } + } + mySocket.send(requestPacket); + try { + Semaphore s = new Semaphore(0); + double timeout = ackWait + * java.lang.Math.pow(10, attempts); + ackMutex.put(m.tag, s); + s.tryAcquire((int) timeout, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + LOG.warn("Ack exception: ", e); + } + + if (ackset.remove(m.tag)) { + myAck = true; + } + + } catch (IOException e) { + LOG.warn("Sending exception: ", e); + /* + * Do nothing, just try again + */ + } + if (myAck) { + /* + * Received ack successfully, so return + */ + challengeMap.remove(m.tag); + + return; + } else + attempts++; + } + /* + * Return message to queue for another attempt later if + * epoch hasn't changed. + */ + if (m.epoch == logicalclock.get()) { + challengeMap.remove(m.tag); + sendqueue.offer(m); + } + break; + case 3: + + requestBuffer.clear(); + requestBuffer.putInt(m.type); + requestBuffer.putLong(m.tag); + requestBuffer.putInt(m.state.ordinal()); + requestBuffer.putLong(m.leader); + requestBuffer.putLong(m.zxid); + requestBuffer.putLong(m.epoch); + + requestPacket.setLength(48); + try { + requestPacket.setSocketAddress(m.addr); + } catch (IllegalArgumentException e) { + // Sun doesn't include the address that causes this + // exception to be thrown, so we wrap the exception + // in order to capture this critical detail. + throw new IllegalArgumentException( + "Unable to set socket address on packet, msg:" + + e.getMessage() + " with addr:" + m.addr, + e); + } + + + try { + mySocket.send(requestPacket); + } catch (IOException e) { + LOG.warn("Exception while sending ack: ", e); + } + break; + default: + LOG.warn("unknown type " + m.type); + break; + } + } + } + + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java new file mode 100644 index 00000000000..2fbd7b91d7d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java @@ -0,0 +1,346 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.WorkerService; +import org.apache.zookeeper.server.ZooKeeperCriticalThread; +import org.apache.zookeeper.server.ZooKeeperServerListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +/** + * This RequestProcessor matches the incoming committed requests with the locally submitted requests. The trick is that locally submitted requests that change the state of the system will come back as + * incoming committed requests, so we need to match them up. + * + * The CommitProcessor is multi-threaded. Communication between threads is handled via queues, atomics, and wait/notifyAll synchronized on the processor. The CommitProcessor acts as a gateway for + * allowing requests to continue with the remainder of the processing pipeline. It will allow many read requests but only a single write request to be in flight simultaneously, thus ensuring that + * write requests are processed in transaction id order. + * + * - 1 commit processor main thread, which watches the request queues and assigns requests to worker threads based on their sessionId so that read and write requests for a particular session are + * always assigned to the same thread (and hence are guaranteed to run in order). - 0-N worker threads, which run the rest of the request processor pipeline on the requests. If configured with 0 + * worker threads, the primary commit processor thread runs the pipeline directly. + * + * Typical (default) thread counts are: on a 32 core machine, 1 commit processor thread and 32 worker threads. + * + * Multi-threading constraints: - Each session's requests must be processed in order. - Write requests must be processed in zxid order - Must ensure no race condition between writes in one session + * that would trigger a watch being set by a read request in another session + * + * The current implementation solves the third constraint by simply allowing no read requests to be processed in parallel with write requests. + */ +public class CommitProcessor extends ZooKeeperCriticalThread implements + RequestProcessor { + /** + * Default: numCores + */ + public static final String ZOOKEEPER_COMMIT_PROC_NUM_WORKER_THREADS = + "zookeeper.commitProcessor.numWorkerThreads"; + /** + * Default worker pool shutdown timeout in ms: 5000 (5s) + */ + public static final String ZOOKEEPER_COMMIT_PROC_SHUTDOWN_TIMEOUT = + "zookeeper.commitProcessor.shutdownTimeout"; + private static final Logger LOG = LoggerFactory.getLogger(CommitProcessor.class); + /** + * Requests that we are holding until the commit comes in. + */ + protected final LinkedBlockingQueue queuedRequests = + new LinkedBlockingQueue(); + + /** + * Requests that have been committed. + */ + protected final LinkedBlockingQueue committedRequests = new LinkedBlockingQueue(); + + /** + * Request for which we are currently awaiting a commit + */ + protected final AtomicReference nextPending = + new AtomicReference(); + /** + * Request currently being committed (ie, sent off to next processor) + */ + private final AtomicReference currentlyCommitting = + new AtomicReference(); + + /** + * The number of requests currently being processed + */ + protected AtomicInteger numRequestsProcessing = new AtomicInteger(0); + protected volatile boolean stopped = true; + protected WorkerService workerPool; + RequestProcessor nextProcessor; + /** + * This flag indicates whether we need to wait for a response to come back from the leader or we just let the sync operation flow through like a read. The flag will be true if the CommitProcessor + * is in a Leader pipeline. + */ + boolean matchSyncs; + private long workerShutdownTimeoutMS; + + public CommitProcessor(RequestProcessor nextProcessor, String id, + boolean matchSyncs, ZooKeeperServerListener listener) { + super("CommitProcessor:" + id, listener); + this.nextProcessor = nextProcessor; + this.matchSyncs = matchSyncs; + } + + private boolean isProcessingRequest() { + return numRequestsProcessing.get() != 0; + } + + private boolean isWaitingForCommit() { + return nextPending.get() != null; + } + + private boolean isProcessingCommit() { + return currentlyCommitting.get() != null; + } + + protected boolean needCommit(Request request) { + switch (request.type) { + case OpCode.create: + case OpCode.create2: + case OpCode.createContainer: + case OpCode.delete: + case OpCode.deleteContainer: + case OpCode.setData: + case OpCode.reconfig: + case OpCode.multi: + case OpCode.setACL: + return true; + case OpCode.sync: + return matchSyncs; + case OpCode.createSession: + case OpCode.closeSession: + return !request.isLocalSession(); + default: + return false; + } + } + + @Override + public void run() { + Request request; + try { + while (!stopped) { + synchronized (this) { + while (!stopped && + ((queuedRequests.isEmpty() || isWaitingForCommit() || isProcessingCommit()) && (committedRequests.isEmpty() || isProcessingRequest()))) + { + wait(); + } + } + + /* + * Processing queuedRequests: Process the next requests until we + * find one for which we need to wait for a commit. We cannot + * process a read request while we are processing write request. + */ + while (!stopped && !isWaitingForCommit() && !isProcessingCommit() && (request = queuedRequests.poll()) != null) { + if (needCommit(request)) { + nextPending.set(request); + } else { + sendToNextProcessor(request); + } + } + + /* + * Processing committedRequests: check and see if the commit + * came in for the pending request. We can only commit a + * request when there is no other request being processed. + */ + processCommitted(); + } + } catch (Throwable e) { + handleException(this.getName(), e); + } + LOG.info("CommitProcessor exited loop!"); + } + + /* + * Separated this method from the main run loop + * for test purposes (ZOOKEEPER-1863) + */ + protected void processCommitted() { + Request request; + if (!stopped && !isProcessingRequest() && (committedRequests.peek() != null)) { + + //后面的processor当前没有正在处理的请求。 + /* + * ZOOKEEPER-1863: continue only if there is no new request + * waiting in queuedRequests or it is waiting for a + * commit. + */ + if (!isWaitingForCommit() && !queuedRequests.isEmpty()) { + return; + } + + request = committedRequests.poll(); + + /* + * We match with nextPending so that we can move to the + * next request when it is committed. We also want to + * use nextPending because it has the cnxn member set + * properly. + */ + Request pending = nextPending.get(); + if (pending != null && pending.sessionId == request.sessionId && pending.cxid == request.cxid) { + // we want to send our version of the request. + // the pointer to the connection in the request + pending.setHdr(request.getHdr()); + pending.setTxn(request.getTxn()); + pending.zxid = request.zxid; + // Set currentlyCommitting so we will block until this + // completes. Cleared by CommitWorkRequest after + // nextProcessor returns. + currentlyCommitting.set(pending); + nextPending.set(null); + sendToNextProcessor(pending); + } else { + // this request came from someone else so just + // send the commit packet + currentlyCommitting.set(request); + sendToNextProcessor(request); + } + } + } + + @Override + public void start() { + int numCores = Runtime.getRuntime().availableProcessors(); + int numWorkerThreads = Integer.getInteger( + ZOOKEEPER_COMMIT_PROC_NUM_WORKER_THREADS, numCores); + workerShutdownTimeoutMS = Long.getLong( + ZOOKEEPER_COMMIT_PROC_SHUTDOWN_TIMEOUT, 5000); + + LOG.info("Configuring CommitProcessor with " + + (numWorkerThreads > 0 ? numWorkerThreads : "no") + + " worker threads."); + if (workerPool == null) { + workerPool = new WorkerService( + "CommitProcWork", numWorkerThreads, true); + } + stopped = false; + super.start(); + } + + /** + * Schedule final request processing; if a worker thread pool is not being used, processing is done directly by this thread. + */ + private void sendToNextProcessor(Request request) { + numRequestsProcessing.incrementAndGet(); + workerPool.schedule(new CommitWorkRequest(request), request.sessionId); + } + + synchronized private void wakeup() { + notifyAll(); + } + + public void commit(Request request) { + if (stopped || request == null) { + return; + } + if (LOG.isDebugEnabled()) { + LOG.debug("Committing request:: " + request); + } + committedRequests.add(request); + if (!isProcessingCommit()) { + wakeup(); + } + } + + public void processRequest(Request request) { + if (stopped) { + return; + } + if (LOG.isDebugEnabled()) { + LOG.debug("Processing request:: " + request); + } + queuedRequests.add(request); + if (!isWaitingForCommit()) { + wakeup(); + } + } + + private void halt() { + stopped = true; + wakeup(); + queuedRequests.clear(); + if (workerPool != null) { + workerPool.stop(); + } + } + + public void shutdown() { + LOG.info("Shutting down"); + + halt(); + + if (workerPool != null) { + workerPool.join(workerShutdownTimeoutMS); + } + + if (nextProcessor != null) { + nextProcessor.shutdown(); + } + } + + /** + * CommitWorkRequest is a small wrapper class to allow downstream processing to be run using the WorkerService + */ + private class CommitWorkRequest extends WorkerService.WorkRequest { + private final Request request; + + CommitWorkRequest(Request request) { + this.request = request; + } + + @Override + public void cleanup() { + if (!stopped) { + LOG.error("Exception thrown by downstream processor," + + " unable to continue."); + CommitProcessor.this.halt(); + } + } + + public void doWork() throws RequestProcessorException { + try { + nextProcessor.processRequest(request); + } finally { + // If this request is the commit request that was blocking + // the processor, clear. + currentlyCommitting.compareAndSet(request, null); + + /* + * Decrement outstanding request count. The processor may be + * blocked at the moment because it is waiting for the pipeline + * to drain. In that case, wake it up if there are pending + * requests. + */ + if (numRequestsProcessing.decrementAndGet() == 0) { + if (!queuedRequests.isEmpty() || + !committedRequests.isEmpty()) { + wakeup(); + } + } + } + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Election.java b/src/java/main/org/apache/zookeeper/server/quorum/Election.java new file mode 100644 index 00000000000..76dfe14ae2a --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/Election.java @@ -0,0 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + + +public interface Election { + public Vote lookForLeader() throws InterruptedException; + + public void shutdown(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java b/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java new file mode 100644 index 00000000000..f239a8be9a8 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java @@ -0,0 +1,981 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.server.ZooKeeperThread; +import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + + +/** + * Implementation of leader election using TCP. It uses an object of the class QuorumCnxManager to manage connections. Otherwise, the algorithm is push-based as with the other UDP implementations. + * + * There are a few parameters that can be tuned to change its behavior. First, finalizeWait determines the amount of time to wait until deciding upon a leader. This is part of the leader election + * algorithm. + */ + + +public class FastLeaderElection implements Election { + /** + * Determine how much time a process has to wait once it believes that it has reached the end of leader election. + */ + final static int finalizeWait = 200; + /** + * Upper bound on the amount of time between two consecutive notification checks. This impacts the amount of time to get the system up again after long partitions. Currently 60 seconds. + */ + + final static int maxNotificationInterval = 60000; + /** + * This value is passed to the methods that check the quorum majority of an established ensemble for those values that should not be taken into account in the comparison (electionEpoch and zxid). + */ + final static int IGNOREVALUE = -1; + private static final Logger LOG = LoggerFactory.getLogger(FastLeaderElection.class); + static byte[] dummyData = new byte[0]; + /** + * Connection manager. Fast leader election uses TCP for communication between peers, and QuorumCnxManager manages such connections. + */ + + QuorumCnxManager manager; + LinkedBlockingQueue sendqueue; + LinkedBlockingQueue recvqueue; + QuorumPeer self; + Messenger messenger; + AtomicLong logicalclock = new AtomicLong(); /* Election instance */ + long proposedLeader; + long proposedZxid; + long proposedEpoch; + volatile boolean stop; + /** + * Constructor of FastLeaderElection. It takes two parameters, one is the QuorumPeer object that instantiated this object, and the other is the connection manager. Such an object should be created + * only once by each peer during an instance of the ZooKeeper service. + * + * @param self QuorumPeer that created this object + * @param manager Connection manager + */ + public FastLeaderElection(QuorumPeer self, QuorumCnxManager manager) { + this.stop = false; + this.manager = manager; + starter(self, manager); + } + + static ByteBuffer buildMsg(int state, + long leader, + long zxid, + long electionEpoch, + long epoch) { + byte requestBytes[] = new byte[40]; + ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); + + /* + * Building notification packet to send, this is called directly only in tests + */ + + requestBuffer.clear(); + requestBuffer.putInt(state); + requestBuffer.putLong(leader); + requestBuffer.putLong(zxid); + requestBuffer.putLong(electionEpoch); + requestBuffer.putLong(epoch); + requestBuffer.putInt(0x1); + + return requestBuffer; + } + + static ByteBuffer buildMsg(int state, + long leader, + long zxid, + long electionEpoch, + long epoch, + byte[] configData) { + byte requestBytes[] = new byte[44 + configData.length]; + ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); + + /* + * Building notification packet to send + */ + + requestBuffer.clear(); + requestBuffer.putInt(state); + requestBuffer.putLong(leader); + requestBuffer.putLong(zxid); + requestBuffer.putLong(electionEpoch); + requestBuffer.putLong(epoch); + requestBuffer.putInt(Notification.CURRENTVERSION); + requestBuffer.putInt(configData.length); + requestBuffer.put(configData); + + return requestBuffer; + } + + /** + * Returns the current vlue of the logical clock counter + */ + public long getLogicalClock() { + return logicalclock.get(); + } + + /** + * This method is invoked by the constructor. Because it is a part of the starting procedure of the object that must be on any constructor of this class, it is probably best to keep as a separate + * method. As we have a single constructor currently, it is not strictly necessary to have it separate. + * + * @param self QuorumPeer that created this object + * @param manager Connection manager + */ + private void starter(QuorumPeer self, QuorumCnxManager manager) { + this.self = self; + proposedLeader = -1; + proposedZxid = -1; + + sendqueue = new LinkedBlockingQueue(); + recvqueue = new LinkedBlockingQueue(); + this.messenger = new Messenger(manager); + } + + /** + * This method starts the sender and receiver threads. + */ + public void start() { + this.messenger.start(); + } + + private void leaveInstance(Vote v) { + if (LOG.isDebugEnabled()) { + LOG.debug("About to leave FLE instance: leader={}, zxid=0x{}, my id={}, my state={}", v.getId(), Long.toHexString(v.getZxid()), self.getId(), self.getPeerState()); + } + recvqueue.clear(); + } + + public QuorumCnxManager getCnxManager() { + return manager; + } + + public void shutdown() { + stop = true; + proposedLeader = -1; + proposedZxid = -1; + LOG.debug("Shutting down connection manager"); + manager.halt(); + LOG.debug("Shutting down messenger"); + messenger.halt(); + LOG.debug("FLE is down"); + } + + /** + * Send notifications to all peers upon a change in our vote + */ + private void sendNotifications() { + for (long sid : self.getCurrentAndNextConfigVoters()) { + QuorumVerifier qv = self.getQuorumVerifier(); + ToSend notmsg = new ToSend(ToSend.mType.notification, proposedLeader, proposedZxid, logicalclock.get(), QuorumPeer.ServerState.LOOKING, sid, proposedEpoch, qv.toString().getBytes()); + if (LOG.isDebugEnabled()) { + LOG.debug("Sending Notification: " + proposedLeader + " (n.leader), 0x" + + Long.toHexString(proposedZxid) + " (n.zxid), 0x" + Long.toHexString(logicalclock.get()) + + " (n.round), " + sid + " (recipient), " + self.getId() + + " (myid), 0x" + Long.toHexString(proposedEpoch) + " (n.peerEpoch)"); + } + sendqueue.offer(notmsg); + } + } + + private void printNotification(Notification n) { + LOG.info("Notification: " + + Long.toHexString(n.version) + " (message format version), " + + n.leader + " (n.leader), 0x" + + Long.toHexString(n.zxid) + " (n.zxid), 0x" + + Long.toHexString(n.electionEpoch) + " (n.round), " + n.state + + " (n.state), " + n.sid + " (n.sid), 0x" + + Long.toHexString(n.peerEpoch) + " (n.peerEPoch), " + + self.getPeerState() + " (my state)" + + (n.qv != null ? (Long.toHexString(n.qv.getVersion()) + " (n.config version)") : "")); + } + + /** + * Check if a pair (server id, zxid) succeeds our current vote. + * + * @param id Server identifier + * @param zxid Last zxid observed by the issuer of this vote + */ + protected boolean totalOrderPredicate(long newId, long newZxid, long newEpoch, long curId, long curZxid, long curEpoch) { + LOG.debug("id: " + newId + ", proposed id: " + curId + ", zxid: 0x" + + Long.toHexString(newZxid) + ", proposed zxid: 0x" + Long.toHexString(curZxid)); + if (self.getQuorumVerifier().getWeight(newId) == 0) { + return false; + } + + /* + * We return true if one of the following three cases hold: + * 1- New epoch is higher + * 2- New epoch is the same as current epoch, but new zxid is higher + * 3- New epoch is the same as current epoch, new zxid is the same + * as current zxid, but server id is higher. + */ + + return ((newEpoch > curEpoch) || + ((newEpoch == curEpoch) && + ((newZxid > curZxid) || ((newZxid == curZxid) && (newId > curId))))); + } + + /** + * Termination predicate. Given a set of votes, determines if have sufficient to declare the end of the election round. 分析:http://www.cnblogs.com/leesf456/p/6508185.html + * + * @param votes Set of votes + * @param vote Identifier of the vote received last + */ + private boolean termPredicate(HashMap votes, Vote vote) { + SyncedLearnerTracker voteSet = new SyncedLearnerTracker(); + voteSet.addQuorumVerifier(self.getQuorumVerifier()); + if (self.getLastSeenQuorumVerifier() != null && self.getLastSeenQuorumVerifier().getVersion() > self.getQuorumVerifier().getVersion()) { + voteSet.addQuorumVerifier(self.getLastSeenQuorumVerifier()); + } + + /* + * First make the views consistent. Sometimes peers will have different + * zxids for a server depending on timing. + */ + for (Map.Entry entry : votes.entrySet()) { + if (vote.equals(entry.getValue())) { + voteSet.addAck(entry.getKey()); + } + } + + return voteSet.hasAllQuorums(); + } + + /** + * In the case there is a leader elected, and a quorum supporting this leader, we have to check if the leader has voted and acked that it is leading. We need this check to avoid that peers keep + * electing over and over a peer that has crashed and it is no longer leading. + * + * @param votes set of votes + * @param leader leader id + * @param electionEpoch epoch id + */ + private boolean checkLeader( + HashMap votes, + long leader, + long electionEpoch) { + + boolean predicate = true; + + /* + * If everyone else thinks I'm the leader, I must be the leader. + * The other two checks are just for the case in which I'm not the + * leader. If I'm not the leader and I haven't received a message + * from leader stating that it is leading, then predicate is false. + */ + + if (leader != self.getId()) { + if (votes.get(leader) == null) predicate = false; + else if (votes.get(leader).getState() != ServerState.LEADING) predicate = false; + } else if (logicalclock.get() != electionEpoch) { + predicate = false; + } + + return predicate; + } + + synchronized void updateProposal(long leader, long zxid, long epoch) { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating proposal: " + leader + " (newleader), 0x" + + Long.toHexString(zxid) + " (newzxid), " + proposedLeader + + " (oldleader), 0x" + Long.toHexString(proposedZxid) + " (oldzxid)"); + } + proposedLeader = leader; + proposedZxid = zxid; + proposedEpoch = epoch; + } + + synchronized public Vote getVote() { + return new Vote(proposedLeader, proposedZxid, proposedEpoch); + } + + /** + * A learning state can be either FOLLOWING or OBSERVING. This method simply decides which one depending on the role of the server. + * + * @return ServerState + */ + private ServerState learningState() { + if (self.getLearnerType() == LearnerType.PARTICIPANT) { + LOG.debug("I'm a participant: " + self.getId()); + return ServerState.FOLLOWING; + } else { + LOG.debug("I'm an observer: " + self.getId()); + return ServerState.OBSERVING; + } + } + + /** + * Returns the initial vote value of server identifier. + * + * @return long + */ + private long getInitId() { + if (self.getQuorumVerifier().getVotingMembers().containsKey(self.getId())) + return self.getId(); + else return Long.MIN_VALUE; + } + + /** + * Returns initial last logged zxid. + * + * @return long + */ + private long getInitLastLoggedZxid() { + if (self.getLearnerType() == LearnerType.PARTICIPANT) + return self.getLastLoggedZxid(); + else return Long.MIN_VALUE; + } + + /** + * Returns the initial vote value of the peer epoch. + * + * @return long + */ + private long getPeerEpoch() { + if (self.getLearnerType() == LearnerType.PARTICIPANT) + try { + return self.getCurrentEpoch(); + } catch (IOException e) { + RuntimeException re = new RuntimeException(e.getMessage()); + re.setStackTrace(e.getStackTrace()); + throw re; + } + else return Long.MIN_VALUE; + } + + /** + * Starts a new round of leader election. Whenever our QuorumPeer changes its state to LOOKING, this method is invoked, and it sends notifications to all other peers. + */ + public Vote lookForLeader() throws InterruptedException { + try { + self.jmxLeaderElectionBean = new LeaderElectionBean(); + MBeanRegistry.getInstance().register(self.jmxLeaderElectionBean, self.jmxLocalPeerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + self.jmxLeaderElectionBean = null; + } + if (self.start_fle == 0) { + self.start_fle = Time.currentElapsedTime(); + } + try { + HashMap recv_set = new HashMap(); + + HashMap out_of_election = new HashMap(); + + int notTimeout = finalizeWait; + + synchronized (this) { + logicalclock.incrementAndGet(); + updateProposal(getInitId(), getInitLastLoggedZxid(), getPeerEpoch()); + } + + LOG.info("New election. My id = " + self.getId() + ", proposed zxid=0x" + Long.toHexString(proposedZxid)); + + sendNotifications(); + + /* + * Loop in which we exchange notifications until we find a leader + */ + + while ((self.getPeerState() == ServerState.LOOKING) && (!stop)) { + /* + * Remove next notification from queue, times out after 2 times + * the termination time + */ + Notification n = recvqueue.poll(notTimeout, TimeUnit.MILLISECONDS); + + /* + * Sends more notifications if haven't received enough. + * Otherwise processes new notification. + */ + if (n == null) { + if (manager.haveDelivered()) { + sendNotifications(); + } else { + manager.connectAll(); + } + + /* + * Exponential backoff + */ + int tmpTimeOut = notTimeout * 2; + notTimeout = (tmpTimeOut < maxNotificationInterval ? tmpTimeOut : maxNotificationInterval); + LOG.info("Notification time out: " + notTimeout); + } else if (self.getCurrentAndNextConfigVoters().contains(n.sid)) { + /* + * Only proceed if the vote comes from a replica in the current or next voting view. + */ + switch (n.state) { + case LOOKING: + /** + * 1.接收到别的节点发过来的投票之后,和本地的投票做比较,如果比本地的大就更新本地投票。 + * 2.如果recv_set中的节点的投票结果和本地的投票结果一样就往SyncedLearnerTracker中QuorumVerifierAcksetPair的ackset增加一个值。 + * 3.如果ackset过半,就说明选举结束。 + */ + // If notification > current, replace and send messages out + if (n.electionEpoch > logicalclock.get()) { + logicalclock.set(n.electionEpoch); + recv_set.clear(); + if (totalOrderPredicate(n.leader, n.zxid, n.peerEpoch, getInitId(), getInitLastLoggedZxid(), getPeerEpoch())) { + updateProposal(n.leader, n.zxid, n.peerEpoch); + } else { + updateProposal(getInitId(), getInitLastLoggedZxid(), getPeerEpoch()); + } + sendNotifications(); + } else if (n.electionEpoch < logicalclock.get()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Notification election epoch is smaller than logicalclock. n.electionEpoch = 0x" + + Long.toHexString(n.electionEpoch) + + ", logicalclock=0x" + Long.toHexString(logicalclock.get())); + } + break; + } else if (totalOrderPredicate(n.leader, n.zxid, n.peerEpoch, proposedLeader, proposedZxid, proposedEpoch)) { + updateProposal(n.leader, n.zxid, n.peerEpoch); + sendNotifications(); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding vote: from=" + n.sid + ", proposed leader=" + n.leader + ", proposed zxid=0x" + Long.toHexString(n.zxid) + ", proposed election epoch=0x" + Long.toHexString(n.electionEpoch)); + } + + recv_set.put(n.sid, new Vote(n.leader, n.zxid, n.electionEpoch, n.peerEpoch)); + + if (termPredicate(recv_set, new Vote(proposedLeader, proposedZxid, logicalclock.get(), proposedEpoch))) { + /** + * 1.Verify if there is any change in the proposed leader + * 2.类似于2MSL吧,并不能完全避免没有收到主节点更新 + * 3.最长等待200ms + */ + while ((n = recvqueue.poll(finalizeWait, TimeUnit.MILLISECONDS)) != null) { + if (totalOrderPredicate(n.leader, n.zxid, n.peerEpoch, proposedLeader, proposedZxid, proposedEpoch)) { + recvqueue.put(n); + break; + } + } + + /* + * This predicate is true once we don't read any new + * relevant message from the reception queue + */ + if (n == null) { + self.setPeerState((proposedLeader == self.getId()) ? ServerState.LEADING : learningState()); + Vote endVote = new Vote(proposedLeader, proposedZxid, proposedEpoch); + leaveInstance(endVote); + return endVote; + } + } + break; + case OBSERVING: + LOG.debug("Notification from observer: " + n.sid); + break; + case FOLLOWING: + case LEADING: + /* + * Consider all notifications from the same epoch + * together. + */ + if (n.electionEpoch == logicalclock.get()) { + recv_set.put(n.sid, new Vote(n.leader, n.zxid, n.electionEpoch, n.peerEpoch)); + if (termPredicate(recv_set, new Vote(n.leader, n.zxid, n.electionEpoch, n.peerEpoch, n.state)) && checkLeader(out_of_election, n.leader, n.electionEpoch)) { + self.setPeerState((n.leader == self.getId()) ? ServerState.LEADING : learningState()); + Vote endVote = new Vote(n.leader, n.zxid, n.peerEpoch); + leaveInstance(endVote); + return endVote; + } + } + + /* + * Before joining an established ensemble, verify that + * a majority are following the same leader. + * Only peer epoch is used to check that the votes come + * from the same ensemble. This is because there is at + * least one corner case in which the ensemble can be + * created with inconsistent zxid and election epoch + * info. However, given that only one ensemble can be + * running at a single point in time and that each + * epoch is used only once, using only the epoch to + * compare the votes is sufficient. + * + * @see https://issues.apache.org/jira/browse/ZOOKEEPER-1732 + */ + out_of_election.put(n.sid, new Vote(n.leader, IGNOREVALUE, IGNOREVALUE, n.peerEpoch, n.state)); + if (termPredicate(out_of_election, new Vote(n.leader, IGNOREVALUE, IGNOREVALUE, n.peerEpoch, n.state)) && + checkLeader(out_of_election, n.leader, IGNOREVALUE)) { + synchronized (this) { + logicalclock.set(n.electionEpoch); + self.setPeerState((n.leader == self.getId()) ? ServerState.LEADING : learningState()); + } + Vote endVote = new Vote(n.leader, n.zxid, n.peerEpoch); + leaveInstance(endVote); + return endVote; + } + break; + default: + LOG.warn("Notification state unrecoginized: " + n.state + " (n.state), " + n.sid + " (n.sid)"); + break; + } + } else { + LOG.warn("Ignoring notification from non-cluster member " + n.sid); + } + } + return null; + } finally { + try { + if (self.jmxLeaderElectionBean != null) { + MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + self.jmxLeaderElectionBean = null; + } + } + + /** + * Notifications are messages that let other peers know that a given peer has changed its vote, either because it has joined leader election or because it learned of another peer with higher zxid + * or same zxid and higher server id + */ + + static public class Notification { + /* + * Format version, introduced in 3.4.6 + */ + + public final static int CURRENTVERSION = 0x2; + int version; + + /* + * Proposed leader + */ + long leader; + + /* + * zxid of the proposed leader + */ + long zxid; + + /* + * Epoch + */ + long electionEpoch; + + /* + * current state of sender + */ + QuorumPeer.ServerState state; + + /* + * Address of sender + */ + long sid; + + QuorumVerifier qv; + /* + * epoch of the proposed leader + */ + long peerEpoch; + } + + /** + * Messages that a peer wants to send to other peers. These messages can be both Notifications and Acks of reception of notification. + */ + static public class ToSend { + /* + * Proposed leader in the case of notification + */ + long leader; + /* + * id contains the tag for acks, and zxid for notifications + */ + long zxid; + /* + * Epoch + */ + long electionEpoch; + /* + * Current state; + */ + QuorumPeer.ServerState state; + /* + * Address of recipient + */ + long sid; + /* + * Used to send a QuorumVerifier (configuration info) + */ + byte[] configData = dummyData; + /* + * Leader epoch + */ + long peerEpoch; + + ToSend(mType type, + long leader, + long zxid, + long electionEpoch, + ServerState state, + long sid, + long peerEpoch, + byte[] configData) { + + this.leader = leader; + this.zxid = zxid; + this.electionEpoch = electionEpoch; + this.state = state; + this.sid = sid; + this.peerEpoch = peerEpoch; + this.configData = configData; + } + + static enum mType {crequest, challenge, notification, ack} + } + + /** + * Multi-threaded implementation of message handler. Messenger implements two sub-classes: WorkReceiver and WorkSender. The functionality of each is obvious from the name. Each of these spawns a + * new thread. + */ + + protected class Messenger { + + WorkerSender ws; + WorkerReceiver wr; + Thread wsThread = null; + Thread wrThread = null; + /** + * Constructor of class Messenger. + * + * @param manager Connection manager + */ + Messenger(QuorumCnxManager manager) { + + this.ws = new WorkerSender(manager); + + this.wsThread = new Thread(this.ws, + "WorkerSender[myid=" + self.getId() + "]"); + this.wsThread.setDaemon(true); + + this.wr = new WorkerReceiver(manager); + + this.wrThread = new Thread(this.wr, + "WorkerReceiver[myid=" + self.getId() + "]"); + this.wrThread.setDaemon(true); + } + + /** + * Starts instances of WorkerSender and WorkerReceiver + */ + void start() { + this.wsThread.start(); + this.wrThread.start(); + } + + /** + * Stops instances of WorkerSender and WorkerReceiver + */ + void halt() { + this.ws.stop = true; + this.wr.stop = true; + } + + /** + * Receives messages from instance of QuorumCnxManager on method run(), and processes such messages. + */ + + class WorkerReceiver extends ZooKeeperThread { + volatile boolean stop; + QuorumCnxManager manager; + + WorkerReceiver(QuorumCnxManager manager) { + super("WorkerReceiver"); + this.stop = false; + this.manager = manager; + } + + public void run() { + + Message response; + while (!stop) { + // Sleeps on receive + try { + response = manager.pollRecvQueue(3000, TimeUnit.MILLISECONDS); + if (response == null) continue; + + // The current protocol and two previous generations all send at least 28 bytes + if (response.buffer.capacity() < 28) { + LOG.error("Got a short response: " + response.buffer.capacity()); + continue; + } + + // this is the backwardCompatibility mode in place before ZK-107 + // It is for a version of the protocol in which we didn't send peer epoch + // With peer epoch and version the message became 40 bytes + boolean backCompatibility28 = (response.buffer.capacity() == 28); + + // this is the backwardCompatibility mode for no version information + boolean backCompatibility40 = (response.buffer.capacity() == 40); + + response.buffer.clear(); + + // Instantiate Notification and set its attributes + Notification n = new Notification(); + + int rstate = response.buffer.getInt(); + long rleader = response.buffer.getLong(); + long rzxid = response.buffer.getLong(); + long relectionEpoch = response.buffer.getLong(); + long rpeerepoch; + + int version = 0x0; + if (!backCompatibility28) { + rpeerepoch = response.buffer.getLong(); + if (!backCompatibility40) { + /* + * Version added in 3.4.6 + */ + + version = response.buffer.getInt(); + } else { + LOG.info("Backward compatibility mode (36 bits), server id: {}", response.sid); + } + } else { + LOG.info("Backward compatibility mode (28 bits), server id: {}", response.sid); + rpeerepoch = ZxidUtils.getEpochFromZxid(rzxid); + } + + QuorumVerifier rqv = null; + + // check if we have a version that includes config. If so extract config info from message. + if (version > 0x1) { + int configLength = response.buffer.getInt(); + byte b[] = new byte[configLength]; + + response.buffer.get(b); + + synchronized (self) { + try { + rqv = self.configFromString(new String(b)); + QuorumVerifier curQV = self.getQuorumVerifier(); + if (rqv.getVersion() > curQV.getVersion()) { + LOG.info("{} Received version: {} my version: {}", self.getId(), + Long.toHexString(rqv.getVersion()), + Long.toHexString(self.getQuorumVerifier().getVersion())); + if (self.getPeerState() == ServerState.LOOKING) { + LOG.debug("Invoking processReconfig(), state: {}", self.getServerState()); + self.processReconfig(rqv, null, null, false); + if (!rqv.equals(curQV)) { + LOG.info("restarting leader election"); + self.shuttingDownLE = true; + self.getElectionAlg().shutdown(); + + break; + } + } else { + LOG.debug("Skip processReconfig(), state: {}", self.getServerState()); + } + } + } catch (IOException e) { + LOG.error("Something went wrong while processing config received from {}", response.sid); + } catch (ConfigException e) { + LOG.error("Something went wrong while processing config received from {}", response.sid); + } + } + } else { + LOG.info("Backward compatibility mode (before reconfig), server id: {}", response.sid); + } + + /* + * If it is from a non-voting server (such as an observer or + * a non-voting follower), respond right away. + */ + if (!self.getCurrentAndNextConfigVoters().contains(response.sid)) { + Vote current = self.getCurrentVote(); + QuorumVerifier qv = self.getQuorumVerifier(); + ToSend notmsg = new ToSend(ToSend.mType.notification, + current.getId(), + current.getZxid(), + logicalclock.get(), + self.getPeerState(), + response.sid, + current.getPeerEpoch(), + qv.toString().getBytes()); + + sendqueue.offer(notmsg); + } else { + // Receive new message + if (LOG.isDebugEnabled()) { + LOG.debug("Receive new notification message. My id = " + + self.getId()); + } + + // State of peer that sent this message + QuorumPeer.ServerState ackstate = QuorumPeer.ServerState.LOOKING; + switch (rstate) { + case 0: + ackstate = QuorumPeer.ServerState.LOOKING; + break; + case 1: + ackstate = QuorumPeer.ServerState.FOLLOWING; + break; + case 2: + ackstate = QuorumPeer.ServerState.LEADING; + break; + case 3: + ackstate = QuorumPeer.ServerState.OBSERVING; + break; + default: + continue; + } + + n.leader = rleader; + n.zxid = rzxid; + n.electionEpoch = relectionEpoch; + n.state = ackstate; + n.sid = response.sid; + n.peerEpoch = rpeerepoch; + n.version = version; + n.qv = rqv; + /* + * Print notification info + */ + if (LOG.isInfoEnabled()) { + printNotification(n); + } + + /* + * If this server is looking, then send proposed leader + */ + + if (self.getPeerState() == QuorumPeer.ServerState.LOOKING) { + recvqueue.offer(n); + + /* + * Send a notification back if the peer that sent this + * message is also looking and its logical clock is + * lagging behind. + */ + if ((ackstate == QuorumPeer.ServerState.LOOKING) + && (n.electionEpoch < logicalclock.get())) { + Vote v = getVote(); + QuorumVerifier qv = self.getQuorumVerifier(); + ToSend notmsg = new ToSend(ToSend.mType.notification, + v.getId(), + v.getZxid(), + logicalclock.get(), + self.getPeerState(), + response.sid, + v.getPeerEpoch(), + qv.toString().getBytes()); + sendqueue.offer(notmsg); + } + } else { + /* + * If this server is not looking, but the one that sent the ack + * is looking, then send back what it believes to be the leader. + */ + Vote current = self.getCurrentVote(); + if (ackstate == QuorumPeer.ServerState.LOOKING) { + if (LOG.isDebugEnabled()) { + LOG.debug("Sending new notification. My id ={} recipient={} zxid=0x{} leader={} config version = {}", + self.getId(), + response.sid, + Long.toHexString(current.getZxid()), + current.getId(), + Long.toHexString(self.getQuorumVerifier().getVersion())); + } + + QuorumVerifier qv = self.getQuorumVerifier(); + ToSend notmsg = new ToSend( + ToSend.mType.notification, + current.getId(), + current.getZxid(), + current.getElectionEpoch(), + self.getPeerState(), + response.sid, + current.getPeerEpoch(), + qv.toString().getBytes()); + sendqueue.offer(notmsg); + } + } + } + } catch (InterruptedException e) { + LOG.warn("Interrupted Exception while waiting for new message" + + e.toString()); + } + } + LOG.info("WorkerReceiver is down"); + } + } + + /** + * This worker simply dequeues a message to send and and queues it on the manager's queue. + */ + + class WorkerSender extends ZooKeeperThread { + volatile boolean stop; + QuorumCnxManager manager; + + WorkerSender(QuorumCnxManager manager) { + super("WorkerSender"); + this.stop = false; + this.manager = manager; + } + + public void run() { + while (!stop) { + try { + ToSend m = sendqueue.poll(3000, TimeUnit.MILLISECONDS); + if (m == null) continue; + + process(m); + } catch (InterruptedException e) { + break; + } + } + LOG.info("WorkerSender is down"); + } + + /** + * Called by run() once there is a new message to send. + * + * @param m message to send + */ + void process(ToSend m) { + ByteBuffer requestBuffer = buildMsg(m.state.ordinal(), + m.leader, + m.zxid, + m.electionEpoch, + m.peerEpoch, + m.configData); + + manager.toSend(m.sid, requestBuffer); + + } + } + + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Follower.java b/src/java/main/org/apache/zookeeper/server/quorum/Follower.java new file mode 100644 index 00000000000..70febc9f67d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/Follower.java @@ -0,0 +1,192 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.Record; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.TxnHeader; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; + +/** + * This class has the control logic for the Follower. + */ +public class Follower extends Learner { + + //上次处理的事务id + private long lastQueued; + // This is the same object as this.zk, but we cache the downcast op + final FollowerZooKeeperServer fzk; + + Follower(QuorumPeer self, FollowerZooKeeperServer zk) { + this.self = self; + this.zk = zk; + this.fzk = zk; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Follower ").append(sock); + sb.append(" lastQueuedZxid:").append(lastQueued); + sb.append(" pendingRevalidationCount:") + .append(pendingRevalidations.size()); + return sb.toString(); + } + + /** + * the main method called by the follower to follow the leader + */ + void followLeader() throws InterruptedException { + self.end_fle = Time.currentElapsedTime(); + LOG.info("FOLLOWING - LEADER ELECTION TOOK - " + (self.end_fle - self.start_fle)); + self.start_fle = 0; + self.end_fle = 0; + fzk.registerJMX(new FollowerBean(this, zk), self.jmxLocalPeerBean); + try { + InetSocketAddress addr = findLeader(); + try { + //连接到主节点 + connectToLeader(addr); + long newEpochZxid = registerWithLeader(Leader.FOLLOWERINFO); + if (self.isReconfigStateChange()) + throw new Exception("learned about role change"); + //check to see if the leader zxid is lower than ours + //this should never happen but is just a safety check + long newEpoch = ZxidUtils.getEpochFromZxid(newEpochZxid); + if (newEpoch < self.getAcceptedEpoch()) { + LOG.error("Proposed leader epoch " + ZxidUtils.zxidToString(newEpochZxid) + + " is less than our accepted epoch " + ZxidUtils.zxidToString(self.getAcceptedEpoch())); + throw new IOException("Error: Epoch of leader is lower"); + } + /** + * 与Leader数据同步 + */ + syncWithLeader(newEpochZxid); + QuorumPacket qp = new QuorumPacket(); + while (self.isRunning()) { + readPacket(qp); + processPacket(qp); + } + } catch (Exception e) { + LOG.warn("Exception when following the leader", e); + try { + sock.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + + // clear pending revalidations + pendingRevalidations.clear(); + } + } finally { + zk.unregisterJMX((Learner) this); + } + } + + /** + * Examine the packet received in qp and dispatch based on its contents. + */ + protected void processPacket(QuorumPacket qp) throws Exception { + switch (qp.getType()) { + case Leader.PING: + ping(qp); + break; + case Leader.PROPOSAL: + TxnHeader hdr = new TxnHeader(); + Record txn = SerializeUtils.deserializeTxn(qp.getData(), hdr); + if (hdr.getZxid() != lastQueued + 1) { + LOG.warn("Got zxid 0x" + Long.toHexString(hdr.getZxid()) + " expected 0x" + Long.toHexString(lastQueued + 1)); + } + lastQueued = hdr.getZxid(); + if (hdr.getType() == OpCode.reconfig) { + SetDataTxn setDataTxn = (SetDataTxn) txn; + QuorumVerifier qv = self.configFromString(new String(setDataTxn.getData())); + self.setLastSeenQuorumVerifier(qv, true); + } + fzk.logRequest(hdr, txn); + break; + case Leader.COMMIT: + fzk.commit(qp.getZxid()); + break; + + case Leader.COMMITANDACTIVATE: + // get the new configuration from the request + Request request = fzk.pendingTxns.element(); + SetDataTxn setDataTxn = (SetDataTxn) request.getTxn(); + QuorumVerifier qv = self.configFromString(new String(setDataTxn.getData())); + + // get new designated leader from (current) leader's message + ByteBuffer buffer = ByteBuffer.wrap(qp.getData()); + long suggestedLeaderId = buffer.getLong(); + boolean majorChange = + self.processReconfig(qv, suggestedLeaderId, qp.getZxid(), true); + // commit (writes the new config to ZK tree (/zookeeper/config) + fzk.commit(qp.getZxid()); + if (majorChange) { + throw new Exception("changes proposed in reconfig"); + } + break; + case Leader.UPTODATE: + LOG.error("Received an UPTODATE message after Follower started"); + break; + case Leader.REVALIDATE: + revalidate(qp); + break; + case Leader.SYNC: + fzk.sync(); + break; + default: + LOG.warn("Unknown packet type: {}", LearnerHandler.packetToString(qp)); + break; + } + } + + /** + * The zxid of the last operation seen + * + * @return zxid + */ + public long getZxid() { + try { + synchronized (fzk) { + return fzk.getZxid(); + } + } catch (NullPointerException e) { + LOG.warn("error getting zxid", e); + } + return -1; + } + + /** + * The zxid of the last operation queued + * + * @return zxid + */ + protected long getLastQueued() { + return lastQueued; + } + + @Override + public void shutdown() { + LOG.info("shutdown called", new Exception("shutdown Follower")); + super.shutdown(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java b/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java new file mode 100644 index 00000000000..8a3dcc5e64f --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.ZooKeeperServerBean; + +/** + * Follower MBean inteface implementation + */ +public class FollowerBean extends ZooKeeperServerBean implements FollowerMXBean { + private final Follower follower; + + public FollowerBean(Follower follower, ZooKeeperServer zks) { + super(zks); + this.follower = follower; + } + + public String getName() { + return "Follower"; + } + + public String getQuorumAddress() { + return follower.sock.toString(); + } + + public String getLastQueuedZxid() { + return "0x" + Long.toHexString(follower.getLastQueued()); + } + + public int getPendingRevalidationCount() { + return follower.getPendingRevalidationsCount(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java new file mode 100644 index 00000000000..e9d590dc730 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ZooKeeperServerMXBean; + +/** + * Follower MBean + */ +public interface FollowerMXBean extends ZooKeeperServerMXBean { + /** + * @return socket address + */ + public String getQuorumAddress(); + + /** + * @return last queued zxid + */ + public String getLastQueuedZxid(); + + /** + * @return count of pending revalidations + */ + public int getPendingRevalidationCount(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java new file mode 100644 index 00000000000..a9d75b6139d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java @@ -0,0 +1,144 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.ZooKeeperCriticalThread; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.txn.ErrorTxn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * This RequestProcessor forwards any requests that modify the state of the + * system to the Leader. + */ +public class FollowerRequestProcessor extends ZooKeeperCriticalThread implements + RequestProcessor { + private static final Logger LOG = LoggerFactory.getLogger(FollowerRequestProcessor.class); + + FollowerZooKeeperServer zks; + + RequestProcessor nextProcessor; + + LinkedBlockingQueue queuedRequests = new LinkedBlockingQueue(); + + boolean finished = false; + + public FollowerRequestProcessor(FollowerZooKeeperServer zks, + RequestProcessor nextProcessor) { + super("FollowerRequestProcessor:" + zks.getServerId(), zks + .getZooKeeperServerListener()); + this.zks = zks; + this.nextProcessor = nextProcessor; + } + + @Override + public void run() { + try { + while (!finished) { + Request request = queuedRequests.take(); + if (LOG.isTraceEnabled()) { + ZooTrace.logRequest(LOG, ZooTrace.CLIENT_REQUEST_TRACE_MASK, + 'F', request, ""); + } + if (request == Request.requestOfDeath) { + break; + } + // We want to queue the request to be processed before we submit + // the request to the leader so that we are ready to receive + // the response + + //如果是读请求直接返回。 + nextProcessor.processRequest(request); + + + + //如果是写请求,直接转发到Leader节点 + + // We now ship the request to the leader. As with all + // other quorum operations, sync also follows this code + // path, but different from others, we need to keep track + // of the sync operations this follower has pending, so we + // add it to pendingSyncs. + switch (request.type) { + case OpCode.sync: + zks.pendingSyncs.add(request); + zks.getFollower().request(request); + break; + case OpCode.create: + case OpCode.create2: + case OpCode.createContainer: + case OpCode.delete: + case OpCode.deleteContainer: + case OpCode.setData: + case OpCode.reconfig: + case OpCode.setACL: + case OpCode.multi: + case OpCode.check: + zks.getFollower().request(request); + break; + case OpCode.createSession: + case OpCode.closeSession: + // Don't forward local sessions to the leader. + if (!request.isLocalSession()) { + zks.getFollower().request(request); + } + break; + } + } + } catch (Exception e) { + handleException(this.getName(), e); + } + LOG.info("FollowerRequestProcessor exited loop!"); + } + + public void processRequest(Request request) { + if (!finished) { + // Before sending the request, check if the request requires a + // global session and what we have is a local session. If so do + // an upgrade. + Request upgradeRequest = null; + try { + upgradeRequest = zks.checkUpgradeSession(request); + } catch (KeeperException ke) { + if (request.getHdr() != null) { + request.getHdr().setType(OpCode.error); + request.setTxn(new ErrorTxn(ke.code().intValue())); + } + request.setException(ke); + LOG.info("Error creating upgrade request", ke); + } catch (IOException ie) { + LOG.error("Unexpected error in upgrade", ie); + } + if (upgradeRequest != null) { + queuedRequests.add(upgradeRequest); + } + queuedRequests.add(request); + } + } + + public void shutdown() { + LOG.info("Shutting down"); + finished = true; + queuedRequests.clear(); + queuedRequests.add(Request.requestOfDeath); + nextProcessor.shutdown(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java new file mode 100644 index 00000000000..6fa2a07ac43 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java @@ -0,0 +1,143 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.Record; +import org.apache.zookeeper.server.FinalRequestProcessor; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * Just like the standard ZooKeeperServer. We just replace the request + * processors: FollowerRequestProcessor -> CommitProcessor -> + * FinalRequestProcessor + * + * A SyncRequestProcessor is also spawned off to log proposals from the leader. + */ +public class FollowerZooKeeperServer extends LearnerZooKeeperServer { + private static final Logger LOG = LoggerFactory.getLogger(FollowerZooKeeperServer.class); + /* + * Pending sync requests + */ + ConcurrentLinkedQueue pendingSyncs; + LinkedBlockingQueue pendingTxns = new LinkedBlockingQueue(); + + /** + * @param port + * @param dataDir + * @throws IOException + */ + FollowerZooKeeperServer(FileTxnSnapLog logFactory, QuorumPeer self, + ZKDatabase zkDb) throws IOException { + super(logFactory, self.tickTime, self.minSessionTimeout, + self.maxSessionTimeout, zkDb, self); + this.pendingSyncs = new ConcurrentLinkedQueue(); + } + + public Follower getFollower() { + return self.follower; + } + + @Override + protected void setupRequestProcessors() { + //PROPOSAL和COMMIT是通过pendingTxns连接起来的 + + //COMMIT--处理leader发来的数据(Leader连接hander) + RequestProcessor finalProcessor = new FinalRequestProcessor(this); + commitProcessor = new CommitProcessor(finalProcessor, Long.toString(getServerId()), true, getZooKeeperServerListener()); + commitProcessor.start(); + + //处理和客户端的数据(客户端连接hander),如果有写消息,会将消息转发给leader + firstProcessor = new FollowerRequestProcessor(this, commitProcessor); + ((FollowerRequestProcessor) firstProcessor).start(); + + + //PROPOSAL--处理leader发来的数据(Leader连接hander) + syncProcessor = new SyncRequestProcessor(this, new SendAckRequestProcessor((Learner) getFollower())); + syncProcessor.start(); + } + + /** + * 将操作记录到事务日志中 + * @param hdr 消息头 + * @param txn 消息体 + */ + public void logRequest(TxnHeader hdr, Record txn) { + Request request = new Request(hdr.getClientId(), hdr.getCxid(), hdr.getType(), hdr, txn, hdr.getZxid()); + if ((request.zxid & 0xffffffffL) != 0) { + /** + * 加入到等待commit的队列中,等待leader发送commit消息过来 + */ + pendingTxns.add(request); + } + /** + * 加入到syncProcessor线程处理队列中 + */ + syncProcessor.processRequest(request); + } + + /** + * When a COMMIT message is received, eventually this method is called, + * which matches up the zxid from the COMMIT with (hopefully) the head of + * the pendingTxns queue and hands it to the commitProcessor to commit. + * @param zxid - must correspond to the head of pendingTxns if it exists + */ + public void commit(long zxid) { + if (pendingTxns.size() == 0) { + LOG.warn("Committing " + Long.toHexString(zxid) + " without seeing txn"); + return; + } + long firstElementZxid = pendingTxns.element().zxid; + if (firstElementZxid != zxid) { + LOG.error("Committing zxid 0x" + Long.toHexString(zxid) + " but next pending txn 0x" + Long.toHexString(firstElementZxid)); + System.exit(12); + } + Request request = pendingTxns.remove(); + commitProcessor.commit(request); + } + + synchronized public void sync() { + if (pendingSyncs.size() == 0) { + LOG.warn("Not expecting a sync."); + return; + } + + Request r = pendingSyncs.remove(); + commitProcessor.commit(r); + } + + @Override + public int getGlobalOutstandingLimit() { + int divisor = self.getQuorumSize() > 2 ? self.getQuorumSize() - 1 : 1; + return super.getGlobalOutstandingLimit() / divisor; + } + + @Override + public String getState() { + return "follower"; + } + + @Override + public Learner getLearner() { + return getFollower(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Leader.java b/src/java/main/org/apache/zookeeper/server/quorum/Leader.java new file mode 100644 index 00000000000..4fe581a0a18 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/Leader.java @@ -0,0 +1,1284 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.server.FinalRequestProcessor; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.ZooKeeperCriticalThread; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.BindException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketAddress; +import java.net.SocketException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; + + +/** + * This class has the control logic for the Leader. + */ +public class Leader { + /** + * This message is the first that a follower receives from the leader. It has the protocol version and the epoch of the leader. + */ + public static final int LEADERINFO = 17; + /** + * This message is used by the follow to ack a proposed epoch. + */ + public static final int ACKEPOCH = 18; + /** + * This message type is sent by a leader to propose a mutation. + */ + public final static int PROPOSAL = 2; + /** + * This message is for follower to expect diff + */ + final static int DIFF = 13; + /** + * This is for follower to truncate its logs + */ + final static int TRUNC = 14; + /** + * This is for follower to download the snapshots + */ + final static int SNAP = 15; + /** + * This tells the leader that the connecting peer is actually an observer + */ + final static int OBSERVERINFO = 16; + /** + * This message type is sent by the leader to indicate it's zxid and if needed, its database. + */ + final static int NEWLEADER = 10; + /** + * This message type is sent by a follower to pass the last zxid. This is here for backward compatibility purposes. + */ + final static int FOLLOWERINFO = 11; + /** + * This message type is sent by the leader to indicate that the follower is now uptodate andt can start responding to clients. + */ + final static int UPTODATE = 12; + /** + * This message type is sent to a leader to request and mutation operation. The payload will consist of a request header followed by a request. + */ + final static int REQUEST = 1; + /** + * This message type is sent by a follower after it has synced a proposal. + */ + final static int ACK = 3; + /** + * This message type is sent by a leader to commit a proposal and cause followers to start serving the corresponding data. + */ + final static int COMMIT = 4; + /** + * This message type is enchanged between follower and leader (initiated by follower) to determine liveliness. + */ + final static int PING = 5; + /** + * This message type is to validate a session that should be active. + */ + final static int REVALIDATE = 6; + /** + * This message is a reply to a synchronize command flushing the pipe between the leader and the follower. + */ + final static int SYNC = 7; + /** + * This message type informs observers of a committed proposal. + */ + final static int INFORM = 8; + /** + * Similar to COMMIT, only for a reconfig operation. + */ + final static int COMMITANDACTIVATE = 9; + /** + * Similar to INFORM, only for a reconfig operation. + */ + final static int INFORMANDACTIVATE = 19; + private static final Logger LOG = LoggerFactory.getLogger(Leader.class); + static final private boolean nodelay = System.getProperty("leader.nodelay", "true").equals("true"); + // Throttle when there are too many concurrent snapshots being sent to observers + private static final String MAX_CONCURRENT_SNAPSHOTS = "zookeeper.leader.maxConcurrentSnapshots"; + private static final int maxConcurrentSnapshots; + private static final String MAX_CONCURRENT_SNAPSHOT_TIMEOUT = "zookeeper.leader.maxConcurrentSnapshotTimeout"; + private static final long maxConcurrentSnapshotTimeout; + + static { + LOG.info("TCP NoDelay set to: " + nodelay); + } + + static { + maxConcurrentSnapshots = Integer.getInteger(MAX_CONCURRENT_SNAPSHOTS, 10); + LOG.info(MAX_CONCURRENT_SNAPSHOTS + " = " + maxConcurrentSnapshots); + maxConcurrentSnapshotTimeout = Long.getLong(MAX_CONCURRENT_SNAPSHOT_TIMEOUT, 5); + LOG.info(MAX_CONCURRENT_SNAPSHOT_TIMEOUT + " = " + maxConcurrentSnapshotTimeout); + } + + final LeaderZooKeeperServer zk; + final QuorumPeer self; + //Follower counter + final AtomicLong followerCounter = new AtomicLong(-1); + final ConcurrentMap outstandingProposals = new ConcurrentHashMap(); + private final LearnerSnapshotThrottler learnerSnapshotThrottler = + new LearnerSnapshotThrottler(maxConcurrentSnapshots, maxConcurrentSnapshotTimeout); + // list of all the followers + private final HashSet learners = + new HashSet(); + // list of followers that are ready to follow (i.e synced with the leader) + private final HashSet forwardingFollowers = + new HashSet(); + private final HashSet observingLearners = + new HashSet(); + // Pending sync requests. Must access under 'this' lock. + private final HashMap> pendingSyncs = + new HashMap>(); + private final ServerSocket ss; + private final ConcurrentLinkedQueue toBeApplied = new ConcurrentLinkedQueue(); + private final Proposal newLeaderProposal = new Proposal(); + private final HashSet connectingFollowers = new HashSet(); + private final HashSet electingFollowers = new HashSet(); + // the follower acceptor thread + volatile LearnerCnxAcceptor cnxAcceptor = null; + StateSummary leaderStateSummary; + long epoch = -1; + boolean waitingForNewEpoch = true; + // when a reconfig occurs where the leader is removed or becomes an observer, + // it does not commit ops after committing the reconfig + boolean allowedToCommit = true; + boolean isShutdown; + long lastCommitted = -1; + long lastProposed; + private boolean quorumFormed = false; + private boolean electionFinished = false; + + Leader(QuorumPeer self, LeaderZooKeeperServer zk) throws IOException { + this.self = self; + try { + if (self.getQuorumListenOnAllIPs()) { + ss = new ServerSocket(self.getQuorumAddress().getPort()); + } else { + ss = new ServerSocket(); + } + ss.setReuseAddress(true); + if (!self.getQuorumListenOnAllIPs()) { + ss.bind(self.getQuorumAddress()); + } + } catch (BindException e) { + if (self.getQuorumListenOnAllIPs()) { + LOG.error("Couldn't bind to port " + self.getQuorumAddress().getPort(), e); + } else { + LOG.error("Couldn't bind to " + self.getQuorumAddress(), e); + } + throw e; + } + this.zk = zk; + } + + /** + * Get string representation of a given packet type + * + * @return string representing the packet type + */ + public static String getPacketType(int packetType) { + switch (packetType) { + case DIFF: + return "DIFF"; + case TRUNC: + return "TRUNC"; + case SNAP: + return "SNAP"; + case OBSERVERINFO: + return "OBSERVERINFO"; + case NEWLEADER: + return "NEWLEADER"; + case FOLLOWERINFO: + return "FOLLOWERINFO"; + case UPTODATE: + return "UPTODATE"; + case LEADERINFO: + return "LEADERINFO"; + case ACKEPOCH: + return "ACKEPOCH"; + case REQUEST: + return "REQUEST"; + case PROPOSAL: + return "PROPOSAL"; + case ACK: + return "ACK"; + case COMMIT: + return "COMMIT"; + case COMMITANDACTIVATE: + return "COMMITANDACTIVATE"; + case PING: + return "PING"; + case REVALIDATE: + return "REVALIDATE"; + case SYNC: + return "SYNC"; + case INFORM: + return "INFORM"; + case INFORMANDACTIVATE: + return "INFORMANDACTIVATE"; + default: + return "UNKNOWN"; + } + } + + /** + * Returns a copy of the current learner snapshot + */ + public List getLearners() { + synchronized (learners) { + return new ArrayList(learners); + } + } + + /** + * Returns a copy of the current forwarding follower snapshot + */ + public List getForwardingFollowers() { + synchronized (forwardingFollowers) { + return new ArrayList(forwardingFollowers); + } + } + + private void addForwardingFollower(LearnerHandler lh) { + synchronized (forwardingFollowers) { + forwardingFollowers.add(lh); + } + } + + /** + * Returns a copy of the current observer snapshot + */ + public List getObservingLearners() { + synchronized (observingLearners) { + return new ArrayList(observingLearners); + } + } + + private void addObserverLearnerHandler(LearnerHandler lh) { + synchronized (observingLearners) { + observingLearners.add(lh); + } + } + + synchronized public int getNumPendingSyncs() { + return pendingSyncs.size(); + } + + /** + * Adds peer to the leader. + * + * @param learner instance of learner handle + */ + void addLearnerHandler(LearnerHandler learner) { + synchronized (learners) { + learners.add(learner); + } + } + + /** + * Remove the learner from the learner list + */ + void removeLearnerHandler(LearnerHandler peer) { + synchronized (forwardingFollowers) { + forwardingFollowers.remove(peer); + } + synchronized (learners) { + learners.remove(peer); + } + synchronized (observingLearners) { + observingLearners.remove(peer); + } + } + + boolean isLearnerSynced(LearnerHandler peer) { + synchronized (forwardingFollowers) { + return forwardingFollowers.contains(peer); + } + } + + /** + * Returns true if a quorum in qv is connected and synced with the leader and false otherwise + * + * @param qv, a QuorumVerifier + */ + public boolean isQuorumSynced(QuorumVerifier qv) { + HashSet ids = new HashSet(); + if (qv.getVotingMembers().containsKey(self.getId())) + ids.add(self.getId()); + synchronized (forwardingFollowers) { + for (LearnerHandler learnerHandler : forwardingFollowers) { + if (learnerHandler.synced() && qv.getVotingMembers().containsKey(learnerHandler.getSid())) { + ids.add(learnerHandler.getSid()); + } + } + } + return qv.containsQuorum(ids); + } + + /** + * This method is main function that is called to lead + */ + void lead() throws IOException, InterruptedException { + self.end_fle = Time.currentElapsedTime(); + LOG.info("LEADING - LEADER ELECTION TOOK - " + + (self.end_fle - self.start_fle)); + self.start_fle = 0; + self.end_fle = 0; + + zk.registerJMX(new LeaderBean(this, zk), self.jmxLocalPeerBean); + + try { + self.tick.set(0); + zk.loadData(); + + leaderStateSummary = new StateSummary(self.getCurrentEpoch(), zk.getLastProcessedZxid()); + + // Start thread that waits for connection requests from + // new followers. + cnxAcceptor = new LearnerCnxAcceptor(); + cnxAcceptor.start(); + + long epoch = getEpochToPropose(self.getId(), self.getAcceptedEpoch()); + + zk.setZxid(ZxidUtils.makeZxid(epoch, 0)); + + synchronized (this) { + lastProposed = zk.getZxid(); + } + + newLeaderProposal.packet = new QuorumPacket(NEWLEADER, zk.getZxid(), + null, null); + + + if ((newLeaderProposal.packet.getZxid() & 0xffffffffL) != 0) { + LOG.info("NEWLEADER proposal has Zxid of " + + Long.toHexString(newLeaderProposal.packet.getZxid())); + } + + QuorumVerifier lastSeenQV = self.getLastSeenQuorumVerifier(); + QuorumVerifier curQV = self.getQuorumVerifier(); + if (curQV.getVersion() == 0 && curQV.getVersion() == lastSeenQV.getVersion()) { + // This was added in ZOOKEEPER-1783. The initial config has version 0 (not explicitly + // specified by the user; the lack of version in a config file is interpreted as version=0). + // As soon as a config is established we would like to increase its version so that it + // takes presedence over other initial configs that were not established (such as a config + // of a server trying to join the ensemble, which may be a partial view of the system, not the full config). + // We chose to set the new version to the one of the NEWLEADER message. However, before we can do that + // there must be agreement on the new version, so we can only change the version when sending/receiving UPTODATE, + // not when sending/receiving NEWLEADER. In other words, we can't change curQV here since its the committed quorum verifier, + // and there's still no agreement on the new version that we'd like to use. Instead, we use + // lastSeenQuorumVerifier which is being sent with NEWLEADER message + // so its a good way to let followers know about the new version. (The original reason for sending + // lastSeenQuorumVerifier with NEWLEADER is so that the leader completes any potentially uncommitted reconfigs + // that it finds before starting to propose operations. Here we're reusing the same code path for + // reaching consensus on the new version number.) + + // It is important that this is done before the leader executes waitForEpochAck, + // so before LearnerHandlers return from their waitForEpochAck + // hence before they construct the NEWLEADER message containing + // the last-seen-quorumverifier of the leader, which we change below + try { + QuorumVerifier newQV = self.configFromString(curQV.toString()); + newQV.setVersion(zk.getZxid()); + self.setLastSeenQuorumVerifier(newQV, true); + } catch (Exception e) { + throw new IOException(e); + } + } + + newLeaderProposal.addQuorumVerifier(self.getQuorumVerifier()); + if (self.getLastSeenQuorumVerifier().getVersion() > self.getQuorumVerifier().getVersion()) { + newLeaderProposal.addQuorumVerifier(self.getLastSeenQuorumVerifier()); + } + + // We have to get at least a majority of servers in sync with + // us. We do this by waiting for the NEWLEADER packet to get + // acknowledged + + waitForEpochAck(self.getId(), leaderStateSummary); + self.setCurrentEpoch(epoch); + + try { + waitForNewLeaderAck(self.getId(), zk.getZxid(), LearnerType.PARTICIPANT); + } catch (InterruptedException e) { + shutdown("Waiting for a quorum of followers, only synced with sids: [ " + newLeaderProposal.ackSetsToString() + " ]"); + HashSet followerSet = new HashSet(); + + for (LearnerHandler f : getLearners()) { + if (self.getQuorumVerifier().getVotingMembers().containsKey(f.getSid())) { + followerSet.add(f.getSid()); + } + } + boolean initTicksShouldBeIncreased = true; + for (Proposal.QuorumVerifierAcksetPair qvAckset : newLeaderProposal.qvAcksetPairs) { + if (!qvAckset.getQuorumVerifier().containsQuorum(followerSet)) { + initTicksShouldBeIncreased = false; + break; + } + } + if (initTicksShouldBeIncreased) { + LOG.warn("Enough followers present. " + + "Perhaps the initTicks need to be increased."); + } + return; + } + + startZkServer(); + + /** + * WARNING: do not use this for anything other than QA testing + * on a real cluster. Specifically to enable verification that quorum + * can handle the lower 32bit roll-over issue identified in + * ZOOKEEPER-1277. Without this option it would take a very long + * time (on order of a month say) to see the 4 billion writes + * necessary to cause the roll-over to occur. + * + * This field allows you to override the zxid of the server. Typically + * you'll want to set it to something like 0xfffffff0 and then + * start the quorum, run some operations and see the re-election. + */ + String initialZxid = System.getProperty("zookeeper.testingonly.initialZxid"); + if (initialZxid != null) { + long zxid = Long.parseLong(initialZxid); + zk.setZxid((zk.getZxid() & 0xffffffff00000000L) | zxid); + } + + if (!System.getProperty("zookeeper.leaderServes", "yes").equals("no")) { + self.setZooKeeperServer(zk); + } + + self.adminServer.setZooKeeperServer(zk); + + // Everything is a go, simply start counting the ticks + // WARNING: I couldn't find any wait statement on a synchronized + // block that would be notified by this notifyAll() call, so + // I commented it out + //synchronized (this) { + // notifyAll(); + //} + // We ping twice a tick, so we only update the tick every other + // iteration + boolean tickSkip = true; + + while (true) { + synchronized (this) { + long start = Time.currentElapsedTime(); + long cur = start; + long end = start + self.tickTime / 2; + while (cur < end) { + wait(end - cur); + cur = Time.currentElapsedTime(); + } + + if (!tickSkip) { + self.tick.incrementAndGet(); + } + + // We use an instance of SyncedLearnerTracker to + // track synced learners to make sure we still have a + // quorum of current (and potentially next pending) view. + SyncedLearnerTracker syncedAckSet = new SyncedLearnerTracker(); + syncedAckSet.addQuorumVerifier(self.getQuorumVerifier()); + if (self.getLastSeenQuorumVerifier() != null && self.getLastSeenQuorumVerifier().getVersion() > self.getQuorumVerifier().getVersion()) { + syncedAckSet.addQuorumVerifier(self.getLastSeenQuorumVerifier()); + } + + syncedAckSet.addAck(self.getId()); + + for (LearnerHandler f : getLearners()) { + if (f.synced()) { + syncedAckSet.addAck(f.getSid()); + } + } + + if (!tickSkip && !syncedAckSet.hasAllQuorums()) { + // Lost quorum of last committed and/or last proposed + // config, shutdown + shutdown("Not sufficient followers synced, only synced with sids: [ " + syncedAckSet.ackSetsToString() + " ]"); + // make sure the order is the same! + // the leader goes to looking + return; + } + tickSkip = !tickSkip; + } + for (LearnerHandler f : getLearners()) { + f.ping(); + } + } + } finally { + zk.unregisterJMX(this); + } + } + + /** + * Close down all the LearnerHandlers + */ + void shutdown(String reason) { + LOG.info("Shutting down"); + + if (isShutdown) { + return; + } + + LOG.info("Shutdown called", + new Exception("shutdown Leader! reason: " + reason)); + + if (cnxAcceptor != null) { + cnxAcceptor.halt(); + } + + // NIO should not accept conenctions + self.setZooKeeperServer(null); + self.adminServer.setZooKeeperServer(null); + try { + ss.close(); + } catch (IOException e) { + LOG.warn("Ignoring unexpected exception during close", e); + } + self.closeAllConnections(); + // shutdown the previous zk + if (zk != null) { + zk.shutdown(); + } + synchronized (learners) { + for (Iterator it = learners.iterator(); it + .hasNext(); ) { + LearnerHandler f = it.next(); + it.remove(); + f.shutdown(); + } + } + isShutdown = true; + } + + /** + * In a reconfig operation, this method attempts to find the best leader for next configuration. If the current leader is a voter in the next configuartion, then it remains the leader. Otherwise, + * choose one of the new voters that acked the reconfiguartion, such that it is as up-to-date as possible, i.e., acked as many outstanding proposals as possible. + * + * @param zxid of the reconfigProposal + * @return server if of the designated leader + */ + + private long getDesignatedLeader(Proposal reconfigProposal, long zxid) { + //new configuration + Proposal.QuorumVerifierAcksetPair newQVAcksetPair = reconfigProposal.qvAcksetPairs.get(reconfigProposal.qvAcksetPairs.size() - 1); + + //check if I'm in the new configuration with the same quorum address - + // if so, I'll remain the leader + if (newQVAcksetPair.getQuorumVerifier().getVotingMembers().containsKey(self.getId()) && + newQVAcksetPair.getQuorumVerifier().getVotingMembers().get(self.getId()).addr.equals(self.getQuorumAddress())) { + return self.getId(); + } + // start with an initial set of candidates that are voters from new config that + // acknowledged the reconfig op (there must be a quorum). Choose one of them as + // current leader candidate + HashSet candidates = new HashSet(newQVAcksetPair.getAckset()); + candidates.remove(self.getId()); // if we're here, I shouldn't be the leader + long curCandidate = candidates.iterator().next(); + + //go over outstanding ops in order, and try to find a candidate that acked the most ops. + //this way it will be the most up-to-date and we'll minimize the number of ops that get dropped + + long curZxid = zxid + 1; + Proposal p = outstandingProposals.get(curZxid); + + while (p != null && !candidates.isEmpty()) { + for (Proposal.QuorumVerifierAcksetPair qvAckset : p.qvAcksetPairs) { + //reduce the set of candidates to those that acknowledged p + candidates.retainAll(qvAckset.getAckset()); + //no candidate acked p, return the best candidate found so far + if (candidates.isEmpty()) return curCandidate; + //update the current candidate, and if it is the only one remaining, return it + curCandidate = candidates.iterator().next(); + if (candidates.size() == 1) return curCandidate; + } + curZxid++; + p = outstandingProposals.get(curZxid); + } + + return curCandidate; + } + + /** + * @param a proposal p + * @return True if committed, otherwise false. + **/ + synchronized public boolean tryToCommit(Proposal p, long zxid, SocketAddress followerAddr) { + // make sure that ops are committed in order. With reconfigurations it is now possible + // that different operations wait for different sets of acks, and we still want to enforce + // that they are committed in order. Currently we only permit one outstanding reconfiguration + // such that the reconfiguration and subsequent outstanding ops proposed while the reconfig is + // pending all wait for a quorum of old and new config, so its not possible to get enough acks + // for an operation without getting enough acks for preceding ops. But in the future if multiple + // concurrent reconfigs are allowed, this can happen. + if (outstandingProposals.containsKey(zxid - 1)) return false; + + // getting a quorum from all necessary configurations + if (!p.hasAllQuorums()) { + return false; + } + + // commit proposals in order + if (zxid != lastCommitted + 1) { + LOG.warn("Commiting zxid 0x" + Long.toHexString(zxid) + + " from " + followerAddr + " not first!"); + LOG.warn("First is " + + (lastCommitted + 1)); + } + + // in order to be committed, a proposal must be accepted by a quorum + + outstandingProposals.remove(zxid); + + if (p.request != null) { + toBeApplied.add(p); + } + + if (p.request == null) { + LOG.warn("Going to commmit null: " + p); + } else if (p.request.getHdr().getType() == OpCode.reconfig) { + LOG.debug("Committing a reconfiguration! " + outstandingProposals.size()); + + //if this server is voter in new config with the same quorum address, + //then it will remain the leader + //otherwise an up-to-date follower will be designated as leader. This saves + //leader election time, unless the designated leader fails + Long designatedLeader = getDesignatedLeader(p, zxid); + //LOG.warn("designated leader is: " + designatedLeader); + + QuorumVerifier newQV = p.qvAcksetPairs.get(p.qvAcksetPairs.size() - 1).getQuorumVerifier(); + + self.processReconfig(newQV, designatedLeader, zk.getZxid(), true); + + if (designatedLeader != self.getId()) { + allowedToCommit = false; + } + + // we're sending the designated leader, and if the leader is changing the followers are + // responsible for closing the connection - this way we are sure that at least a majority of them + // receive the commit message. + commitAndActivate(zxid, designatedLeader); + informAndActivate(p, designatedLeader); + //turnOffFollowers(); + } else { + commit(zxid); + inform(p); + } + zk.commitProcessor.commit(p.request); + if (pendingSyncs.containsKey(zxid)) { + for (LearnerSyncRequest r : pendingSyncs.remove(zxid)) { + sendSync(r); + } + } + + return true; + } + + /** + * Keep a count of acks that are received by the leader for a particular proposal + * + * @param zxid, the zxid of the proposal sent out + * @param sid, the id of the server that sent the ack + */ + synchronized public void processAck(long sid, long zxid, SocketAddress followerAddr) { + if (!allowedToCommit) return; // last op committed was a leader change - from now on + // the new leader should commit + if (LOG.isTraceEnabled()) { + LOG.trace("Ack zxid: 0x{}", Long.toHexString(zxid)); + for (Proposal p : outstandingProposals.values()) { + long packetZxid = p.packet.getZxid(); + LOG.trace("outstanding proposal: 0x{}", Long.toHexString(packetZxid)); + } + LOG.trace("outstanding proposals all"); + } + + if ((zxid & 0xffffffffL) == 0) { + /* + * We no longer process NEWLEADER ack with this method. However, + * the learner sends an ack back to the leader after it gets + * UPTODATE, so we just ignore the message. + */ + return; + } + + + if (outstandingProposals.size() == 0) { + if (LOG.isDebugEnabled()) { + LOG.debug("outstanding is 0"); + } + return; + } + if (lastCommitted >= zxid) { + if (LOG.isDebugEnabled()) { + LOG.debug("proposal has already been committed, pzxid: 0x{} zxid: 0x{}", + Long.toHexString(lastCommitted), Long.toHexString(zxid)); + } + // The proposal has already been committed + return; + } + Proposal p = outstandingProposals.get(zxid); + if (p == null) { + LOG.warn("Trying to commit future proposal: zxid 0x{} from {}", Long.toHexString(zxid), followerAddr); + return; + } + + p.addAck(sid); + /*if (LOG.isDebugEnabled()) { + LOG.debug("Count for zxid: 0x{} is {}", + Long.toHexString(zxid), p.ackSet.size()); + }*/ + + boolean hasCommitted = tryToCommit(p, zxid, followerAddr); + + // If p is a reconfiguration, multiple other operations may be ready to be committed, + // since operations wait for different sets of acks. + // Currently we only permit one outstanding reconfiguration at a time + // such that the reconfiguration and subsequent outstanding ops proposed while the reconfig is + // pending all wait for a quorum of old and new config, so its not possible to get enough acks + // for an operation without getting enough acks for preceding ops. But in the future if multiple + // concurrent reconfigs are allowed, this can happen and then we need to check whether some pending + // ops may already have enough acks and can be committed, which is what this code does. + + if (hasCommitted && p.request != null && p.request.getHdr().getType() == OpCode.reconfig) { + long curZxid = zxid; + while (allowedToCommit && hasCommitted && p != null) { + curZxid++; + p = outstandingProposals.get(curZxid); + if (p != null) hasCommitted = tryToCommit(p, curZxid, null); + } + } + } + + /** + * send a packet to all the followers ready to follow + * + * @param qp the packet to be sent + */ + void sendPacket(QuorumPacket qp) { + synchronized (forwardingFollowers) { + for (LearnerHandler f : forwardingFollowers) { + f.queuePacket(qp); + } + } + } + + /** + * send a packet to all observers + */ + void sendObserverPacket(QuorumPacket qp) { + for (LearnerHandler f : getObservingLearners()) { + f.queuePacket(qp); + } + } + + /** + * Create a commit packet and send it to all the members of the quorum + */ + public void commit(long zxid) { + synchronized (this) { + lastCommitted = zxid; + } + QuorumPacket qp = new QuorumPacket(Leader.COMMIT, zxid, null, null); + sendPacket(qp); + } + + //commit and send some info + public void commitAndActivate(long zxid, long designatedLeader) { + synchronized (this) { + lastCommitted = zxid; + } + + byte data[] = new byte[8]; + ByteBuffer buffer = ByteBuffer.wrap(data); + buffer.putLong(designatedLeader); + + QuorumPacket qp = new QuorumPacket(Leader.COMMITANDACTIVATE, zxid, data, null); + sendPacket(qp); + } + + /** + * Create an inform packet and send it to all observers. + */ + public void inform(Proposal proposal) { + QuorumPacket qp = new QuorumPacket(Leader.INFORM, proposal.request.zxid, + proposal.packet.getData(), null); + sendObserverPacket(qp); + } + + /** + * Create an inform&activate packet and send it to all observers. + */ + public void informAndActivate(Proposal proposal, long designatedLeader) { + byte[] proposalData = proposal.packet.getData(); + byte[] data = new byte[proposalData.length + 8]; + ByteBuffer buffer = ByteBuffer.wrap(data); + buffer.putLong(designatedLeader); + buffer.put(proposalData); + + QuorumPacket qp = new QuorumPacket(Leader.INFORMANDACTIVATE, proposal.request.zxid, data, null); + sendObserverPacket(qp); + } + + /** + * Returns the current epoch of the leader. + */ + public long getEpoch() { + return ZxidUtils.getEpochFromZxid(lastProposed); + } + + /** + * create a proposal and send it out to all the members + * + * @return the proposal that is queued to send to all the members + */ + public Proposal propose(Request request) throws XidRolloverException { + /** + * Address the rollover issue. All lower 32bits set indicate a new leader + * election. Force a re-election instead. See ZOOKEEPER-1277 + */ + if ((request.zxid & 0xffffffffL) == 0xffffffffL) { + String msg = + "zxid lower 32 bits have rolled over, forcing re-election, and therefore new epoch start"; + shutdown(msg); + throw new XidRolloverException(msg); + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + try { + request.getHdr().serialize(boa, "hdr"); + if (request.getTxn() != null) { + request.getTxn().serialize(boa, "txn"); + } + baos.close(); + } catch (IOException e) { + LOG.warn("This really should be impossible", e); + } + QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid, + baos.toByteArray(), null); + + Proposal p = new Proposal(); + p.packet = pp; + p.request = request; + + synchronized (this) { + p.addQuorumVerifier(self.getQuorumVerifier()); + + if (request.getHdr().getType() == OpCode.reconfig) { + self.setLastSeenQuorumVerifier(request.qv, true); + } + + if (self.getQuorumVerifier().getVersion() < self.getLastSeenQuorumVerifier().getVersion()) { + p.addQuorumVerifier(self.getLastSeenQuorumVerifier()); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Proposing:: " + request); + } + + lastProposed = p.packet.getZxid(); + outstandingProposals.put(lastProposed, p); + sendPacket(pp); + } + return p; + } + + public LearnerSnapshotThrottler getLearnerSnapshotThrottler() { + return learnerSnapshotThrottler; + } + + /** + * Process sync requests + * + * @param r the request + */ + + synchronized public void processSync(LearnerSyncRequest r) { + if (outstandingProposals.isEmpty()) { + sendSync(r); + } else { + List l = pendingSyncs.get(lastProposed); + if (l == null) { + l = new ArrayList(); + } + l.add(r); + pendingSyncs.put(lastProposed, l); + } + } + + /** + * Sends a sync message to the appropriate server + */ + + public void sendSync(LearnerSyncRequest r) { + QuorumPacket qp = new QuorumPacket(Leader.SYNC, 0, null, null); + r.fh.queuePacket(qp); + } + + /** + * lets the leader know that a follower is capable of following and is done syncing + * + * @param handler handler of the follower + * @return last proposed zxid + */ + synchronized public long startForwarding(LearnerHandler handler, + long lastSeenZxid) { + // Queue up any outstanding requests enabling the receipt of + // new requests + if (lastProposed > lastSeenZxid) { + for (Proposal p : toBeApplied) { + if (p.packet.getZxid() <= lastSeenZxid) { + continue; + } + handler.queuePacket(p.packet); + // Since the proposal has been committed we need to send the + // commit message also + QuorumPacket qp = new QuorumPacket(Leader.COMMIT, p.packet + .getZxid(), null, null); + handler.queuePacket(qp); + } + // Only participant need to get outstanding proposals + if (handler.getLearnerType() == LearnerType.PARTICIPANT) { + List zxids = new ArrayList(outstandingProposals.keySet()); + Collections.sort(zxids); + for (Long zxid : zxids) { + if (zxid <= lastSeenZxid) { + continue; + } + handler.queuePacket(outstandingProposals.get(zxid).packet); + } + } + } + if (handler.getLearnerType() == LearnerType.PARTICIPANT) { + addForwardingFollower(handler); + } else { + addObserverLearnerHandler(handler); + } + + return lastProposed; + } + + public long getEpochToPropose(long sid, long lastAcceptedEpoch) throws InterruptedException, IOException { + synchronized (connectingFollowers) { + if (!waitingForNewEpoch) { + return epoch; + } + if (lastAcceptedEpoch >= epoch) { + epoch = lastAcceptedEpoch + 1; + } + connectingFollowers.add(sid); + QuorumVerifier verifier = self.getQuorumVerifier(); + if (connectingFollowers.contains(self.getId()) && + verifier.containsQuorum(connectingFollowers)) { + waitingForNewEpoch = false; + self.setAcceptedEpoch(epoch); + connectingFollowers.notifyAll(); + } else { + long start = Time.currentElapsedTime(); + long cur = start; + long end = start + self.getInitLimit() * self.getTickTime(); + while (waitingForNewEpoch && cur < end) { + connectingFollowers.wait(end - cur); + cur = Time.currentElapsedTime(); + } + if (waitingForNewEpoch) { + throw new InterruptedException("Timeout while waiting for epoch from quorum"); + } + } + return epoch; + } + } + + public void waitForEpochAck(long id, StateSummary ss) throws IOException, InterruptedException { + synchronized (electingFollowers) { + if (electionFinished) { + return; + } + if (ss.getCurrentEpoch() != -1) { + if (ss.isMoreRecentThan(leaderStateSummary)) { + throw new IOException("Follower is ahead of the leader, leader summary: " + + leaderStateSummary.getCurrentEpoch() + + " (current epoch), " + + leaderStateSummary.getLastZxid() + + " (last zxid)"); + } + electingFollowers.add(id); + } + QuorumVerifier verifier = self.getQuorumVerifier(); + if (electingFollowers.contains(self.getId()) && verifier.containsQuorum(electingFollowers)) { + electionFinished = true; + electingFollowers.notifyAll(); + } else { + long start = Time.currentElapsedTime(); + long cur = start; + long end = start + self.getInitLimit() * self.getTickTime(); + while (!electionFinished && cur < end) { + electingFollowers.wait(end - cur); + cur = Time.currentElapsedTime(); + } + if (!electionFinished) { + throw new InterruptedException("Timeout while waiting for epoch to be acked by quorum"); + } + } + } + } + + /** + * Return a list of sid in set as string + */ + private String getSidSetString(Set sidSet) { + StringBuilder sids = new StringBuilder(); + Iterator iter = sidSet.iterator(); + while (iter.hasNext()) { + sids.append(iter.next()); + if (!iter.hasNext()) { + break; + } + sids.append(","); + } + return sids.toString(); + } + + /** + * Start up Leader ZooKeeper server and initialize zxid to the new epoch + */ + private synchronized void startZkServer() { + // Update lastCommitted and Db's zxid to a value representing the new epoch + lastCommitted = zk.getZxid(); + LOG.info("Have quorum of supporters, sids: [ " + + newLeaderProposal.ackSetsToString() + + " ]; starting up and setting last processed zxid: 0x{}", + Long.toHexString(zk.getZxid())); + + /* + * ZOOKEEPER-1324. the leader sends the new config it must complete + * to others inside a NEWLEADER message (see LearnerHandler where + * the NEWLEADER message is constructed), and once it has enough + * acks we must execute the following code so that it applies the + * config to itself. + */ + QuorumVerifier newQV = self.getLastSeenQuorumVerifier(); + + Long designatedLeader = getDesignatedLeader(newLeaderProposal, zk.getZxid()); + + self.processReconfig(newQV, designatedLeader, zk.getZxid(), true); + if (designatedLeader != self.getId()) { + allowedToCommit = false; + } + + zk.startup(); + /* + * Update the election vote here to ensure that all members of the + * ensemble report the same vote to new servers that start up and + * send leader election notifications to the ensemble. + * + * @see https://issues.apache.org/jira/browse/ZOOKEEPER-1732 + */ + self.updateElectionVote(getEpoch()); + + zk.getZKDatabase().setlastProcessedZxid(zk.getZxid()); + } + + /** + * Process NEWLEADER ack of a given sid and wait until the leader receives sufficient acks. + */ + public void waitForNewLeaderAck(long sid, long zxid, LearnerType learnerType) + throws InterruptedException { + + synchronized (newLeaderProposal.qvAcksetPairs) { + + if (quorumFormed) { + return; + } + + long currentZxid = newLeaderProposal.packet.getZxid(); + if (zxid != currentZxid) { + LOG.error("NEWLEADER ACK from sid: " + sid + + " is from a different epoch - current 0x" + + Long.toHexString(currentZxid) + " receieved 0x" + + Long.toHexString(zxid)); + return; + } + + /* + * Note that addAck already checks that the learner + * is a PARTICIPANT. + */ + newLeaderProposal.addAck(sid); + + if (newLeaderProposal.hasAllQuorums()) { + quorumFormed = true; + newLeaderProposal.qvAcksetPairs.notifyAll(); + } else { + long start = Time.currentElapsedTime(); + long cur = start; + long end = start + self.getInitLimit() * self.getTickTime(); + while (!quorumFormed && cur < end) { + newLeaderProposal.qvAcksetPairs.wait(end - cur); + cur = Time.currentElapsedTime(); + } + if (!quorumFormed) { + throw new InterruptedException( + "Timeout while waiting for NEWLEADER to be acked by quorum"); + } + } + } + } + + static public class Proposal extends SyncedLearnerTracker { + public QuorumPacket packet; + public Request request; + + @Override + public String toString() { + return packet.getType() + ", " + packet.getZxid() + ", " + request; + } + } + + static class ToBeAppliedRequestProcessor implements RequestProcessor { + private final RequestProcessor next; + + private final Leader leader; + + /** + * This request processor simply maintains the toBeApplied list. For this to work next must be a FinalRequestProcessor and FinalRequestProcessor.processRequest MUST process the request + * synchronously! + * + * @param next a reference to the FinalRequestProcessor + */ + ToBeAppliedRequestProcessor(RequestProcessor next, Leader leader) { + if (!(next instanceof FinalRequestProcessor)) { + throw new RuntimeException(ToBeAppliedRequestProcessor.class + .getName() + + " must be connected to " + + FinalRequestProcessor.class.getName() + + " not " + + next.getClass().getName()); + } + this.leader = leader; + this.next = next; + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.server.RequestProcessor#processRequest(org.apache.zookeeper.server.Request) + */ + public void processRequest(Request request) throws RequestProcessorException { + next.processRequest(request); + + // The only requests that should be on toBeApplied are write + // requests, for which we will have a hdr. We can't simply use + // request.zxid here because that is set on read requests to equal + // the zxid of the last write op. + if (request.getHdr() != null) { + long zxid = request.getHdr().getZxid(); + Iterator iter = leader.toBeApplied.iterator(); + if (iter.hasNext()) { + Proposal p = iter.next(); + if (p.request != null && p.request.zxid == zxid) { + iter.remove(); + return; + } + } + LOG.error("Committed request not found on toBeApplied: " + + request); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.server.RequestProcessor#shutdown() + */ + public void shutdown() { + LOG.info("Shutting down"); + next.shutdown(); + } + } + + @SuppressWarnings("serial") + public static class XidRolloverException extends Exception { + public XidRolloverException(String message) { + super(message); + } + } + + class LearnerCnxAcceptor extends ZooKeeperCriticalThread { + private volatile boolean stop = false; + + public LearnerCnxAcceptor() { + super("LearnerCnxAcceptor-" + ss.getLocalSocketAddress(), zk + .getZooKeeperServerListener()); + } + + @Override + public void run() { + try { + while (!stop) { + try { + Socket s = ss.accept(); + // start with the initLimit, once the ack is processed + // in LearnerHandler switch to the syncLimit + s.setSoTimeout(self.tickTime * self.initLimit); + s.setTcpNoDelay(nodelay); + LearnerHandler fh = new LearnerHandler(s, Leader.this); + fh.start(); + } catch (SocketException e) { + if (stop) { + LOG.info("exception while shutting down acceptor: " + + e); + + // When Leader.shutdown() calls ss.close(), + // the call to accept throws an exception. + // We catch and set stop to true. + stop = true; + } else { + throw e; + } + } + } + } catch (Exception e) { + LOG.warn("Exception while accepting follower", e.getMessage()); + handleException(this.getName(), e); + } + } + + public void halt() { + stop = true; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java new file mode 100644 index 00000000000..b258a89419c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.ZooKeeperServerBean; + +/** + * Leader MBean interface implementation. + */ +public class LeaderBean extends ZooKeeperServerBean implements LeaderMXBean { + private final Leader leader; + + public LeaderBean(Leader leader, ZooKeeperServer zks) { + super(zks); + this.leader = leader; + } + + public String getName() { + return "Leader"; + } + + public String getCurrentZxid() { + return "0x" + Long.toHexString(zks.getZxid()); + } + + public String followerInfo() { + StringBuilder sb = new StringBuilder(); + for (LearnerHandler handler : leader.getLearners()) { + sb.append(handler.toString()).append("\n"); + } + return sb.toString(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java new file mode 100644 index 00000000000..a28325702c7 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java @@ -0,0 +1,283 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + +/** + * @deprecated This class has been deprecated as of release 3.4.0. + */ +@Deprecated +public class LeaderElection implements Election { + protected static final Random epochGen = new Random(); + private static final Logger LOG = LoggerFactory.getLogger(LeaderElection.class); + protected QuorumPeer self; + + public LeaderElection(QuorumPeer self) { + this.self = self; + } + + protected ElectionResult countVotes(HashMap votes, HashSet heardFrom) { + final ElectionResult result = new ElectionResult(); + // Initialize with null vote + result.vote = new Vote(Long.MIN_VALUE, Long.MIN_VALUE); + result.winner = new Vote(Long.MIN_VALUE, Long.MIN_VALUE); + + // First, filter out votes from unheard-from machines. Then + // make the views consistent. Sometimes peers will have + // different zxids for a server depending on timing. + final HashMap validVotes = new HashMap(); + final Map maxZxids = new HashMap(); + for (Map.Entry e : votes.entrySet()) { + // Only include votes from machines that we heard from + final Vote v = e.getValue(); + if (heardFrom.contains(v.getId())) { + validVotes.put(e.getKey(), v); + Long val = maxZxids.get(v.getId()); + if (val == null || val < v.getZxid()) { + maxZxids.put(v.getId(), v.getZxid()); + } + } + } + + // Make all zxids for a given vote id equal to the largest zxid seen for + // that id + for (Map.Entry e : validVotes.entrySet()) { + final Vote v = e.getValue(); + Long zxid = maxZxids.get(v.getId()); + if (v.getZxid() < zxid) { + // This is safe inside an iterator as per + // http://download.oracle.com/javase/1.5.0/docs/api/java/util/Map.Entry.html + e.setValue(new Vote(v.getId(), zxid, v.getElectionEpoch(), v.getPeerEpoch(), v.getState())); + } + } + + result.numValidVotes = validVotes.size(); + + final HashMap countTable = new HashMap(); + // Now do the tally + for (Vote v : validVotes.values()) { + Integer count = countTable.get(v); + if (count == null) { + count = 0; + } + countTable.put(v, count + 1); + if (v.getId() == result.vote.getId()) { + result.count++; + } else if (v.getZxid() > result.vote.getZxid() + || (v.getZxid() == result.vote.getZxid() && v.getId() > result.vote.getId())) { + result.vote = v; + result.count = 1; + } + } + result.winningCount = 0; + LOG.info("Election tally: "); + for (Entry entry : countTable.entrySet()) { + if (entry.getValue() > result.winningCount) { + result.winningCount = entry.getValue(); + result.winner = entry.getKey(); + } + LOG.info(entry.getKey().getId() + "\t-> " + entry.getValue()); + } + return result; + } + + /** + * There is nothing to shutdown in this implementation of + * leader election, so we simply have an empty method. + */ + public void shutdown() { + } + + /** + * Invoked in QuorumPeer to find or elect a new leader. + * + * @throws InterruptedException + */ + public Vote lookForLeader() throws InterruptedException { + try { + self.jmxLeaderElectionBean = new LeaderElectionBean(); + MBeanRegistry.getInstance().register( + self.jmxLeaderElectionBean, self.jmxLocalPeerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + self.jmxLeaderElectionBean = null; + } + + try { + self.setCurrentVote(new Vote(self.getId(), + self.getLastLoggedZxid())); + // We are going to look for a leader by casting a vote for ourself + byte requestBytes[] = new byte[4]; + ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); + byte responseBytes[] = new byte[28]; + ByteBuffer responseBuffer = ByteBuffer.wrap(responseBytes); + /* The current vote for the leader. Initially me! */ + DatagramSocket s = null; + try { + s = new DatagramSocket(); + s.setSoTimeout(200); + } catch (SocketException e1) { + LOG.error("Socket exception when creating socket for leader election", e1); + System.exit(4); + } + DatagramPacket requestPacket = new DatagramPacket(requestBytes, + requestBytes.length); + DatagramPacket responsePacket = new DatagramPacket(responseBytes, + responseBytes.length); + int xid = epochGen.nextInt(); + while (self.isRunning()) { + HashMap votes = + new HashMap(self.getVotingView().size()); + + requestBuffer.clear(); + requestBuffer.putInt(xid); + requestPacket.setLength(4); + HashSet heardFrom = new HashSet(); + for (QuorumServer server : self.getVotingView().values()) { + LOG.info("Server address: " + server.addr); + try { + requestPacket.setSocketAddress(server.addr); + } catch (IllegalArgumentException e) { + // Sun doesn't include the address that causes this + // exception to be thrown, so we wrap the exception + // in order to capture this critical detail. + throw new IllegalArgumentException( + "Unable to set socket address on packet, msg:" + + e.getMessage() + " with addr:" + server.addr, + e); + } + + try { + s.send(requestPacket); + responsePacket.setLength(responseBytes.length); + s.receive(responsePacket); + if (responsePacket.getLength() != responseBytes.length) { + LOG.error("Got a short response: " + + responsePacket.getLength()); + continue; + } + responseBuffer.clear(); + int recvedXid = responseBuffer.getInt(); + if (recvedXid != xid) { + LOG.error("Got bad xid: expected " + xid + + " got " + recvedXid); + continue; + } + long peerId = responseBuffer.getLong(); + heardFrom.add(peerId); + //if(server.id != peerId){ + Vote vote = new Vote(responseBuffer.getLong(), + responseBuffer.getLong()); + InetSocketAddress addr = + (InetSocketAddress) responsePacket + .getSocketAddress(); + votes.put(addr, vote); + //} + } catch (IOException e) { + LOG.warn("Ignoring exception while looking for leader", + e); + // Errors are okay, since hosts may be + // down + } + } + + ElectionResult result = countVotes(votes, heardFrom); + // ZOOKEEPER-569: + // If no votes are received for live peers, reset to voting + // for ourselves as otherwise we may hang on to a vote + // for a dead peer + if (result.numValidVotes == 0) { + self.setCurrentVote(new Vote(self.getId(), + self.getLastLoggedZxid())); + } else { + if (result.winner.getId() >= 0) { + self.setCurrentVote(result.vote); + // To do: this doesn't use a quorum verifier + if (result.winningCount > (self.getVotingView().size() / 2)) { + self.setCurrentVote(result.winner); + s.close(); + Vote current = self.getCurrentVote(); + LOG.info("Found leader: my type is: " + self.getLearnerType()); + /* + * We want to make sure we implement the state machine + * correctly. If we are a PARTICIPANT, once a leader + * is elected we can move either to LEADING or + * FOLLOWING. However if we are an OBSERVER, it is an + * error to be elected as a Leader. + */ + if (self.getLearnerType() == LearnerType.OBSERVER) { + if (current.getId() == self.getId()) { + // This should never happen! + LOG.error("OBSERVER elected as leader!"); + Thread.sleep(100); + } else { + self.setPeerState(ServerState.OBSERVING); + Thread.sleep(100); + return current; + } + } else { + self.setPeerState((current.getId() == self.getId()) + ? ServerState.LEADING : ServerState.FOLLOWING); + if (self.getPeerState() == ServerState.FOLLOWING) { + Thread.sleep(100); + } + return current; + } + } + } + } + Thread.sleep(1000); + } + return null; + } finally { + try { + if (self.jmxLeaderElectionBean != null) { + MBeanRegistry.getInstance().unregister( + self.jmxLeaderElectionBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + self.jmxLeaderElectionBean = null; + } + } + + protected static class ElectionResult { + public Vote vote; + + public int count; + + public Vote winner; + + public int winningCount; + + public int numValidVotes; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionBean.java new file mode 100644 index 00000000000..5744c0c587f --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionBean.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.ZKMBeanInfo; + +import java.util.Date; + +/** + * Leader election MBean interface implementation + */ +public class LeaderElectionBean implements LeaderElectionMXBean, ZKMBeanInfo { + private final Date startTime = new Date(); + + public String getName() { + return "LeaderElection"; + } + + public boolean isHidden() { + return false; + } + + public String getStartTime() { + return startTime.toString(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionMXBean.java new file mode 100644 index 00000000000..cbe4087da75 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionMXBean.java @@ -0,0 +1,24 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + + +/** + * Leader election protocol MBean. + */ +public interface LeaderElectionMXBean { + /** + * + * @return the time when the leader election started + */ + public String getStartTime(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java new file mode 100644 index 00000000000..79ee43d20e3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ZooKeeperServerMXBean; + +/** + * Leader MBean. + */ +public interface LeaderMXBean extends ZooKeeperServerMXBean { + /** + * Current zxid of cluster. + */ + public String getCurrentZxid(); + + /** + * @return information on current followers + */ + public String followerInfo(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderRequestProcessor.java new file mode 100644 index 00000000000..e2f0085dd73 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderRequestProcessor.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.txn.ErrorTxn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * Responsible for performing local session upgrade. Only request submitted + * directly to the leader should go through this processor. + */ +public class LeaderRequestProcessor implements RequestProcessor { + private static final Logger LOG = LoggerFactory + .getLogger(LeaderRequestProcessor.class); + + private final LeaderZooKeeperServer lzks; + + private final RequestProcessor nextProcessor; + + public LeaderRequestProcessor(LeaderZooKeeperServer zks, + RequestProcessor nextProcessor) { + this.lzks = zks; + this.nextProcessor = nextProcessor; + } + + @Override + public void processRequest(Request request) + throws RequestProcessorException { + // Check if this is a local session and we are trying to create + // an ephemeral node, in which case we upgrade the session + Request upgradeRequest = null; + try { + upgradeRequest = lzks.checkUpgradeSession(request); + } catch (KeeperException ke) { + if (request.getHdr() != null) { + LOG.debug("Updating header"); + request.getHdr().setType(OpCode.error); + request.setTxn(new ErrorTxn(ke.code().intValue())); + } + request.setException(ke); + LOG.info("Error creating upgrade request " + ke.getMessage()); + } catch (IOException ie) { + LOG.error("Unexpected error in upgrade", ie); + } + if (upgradeRequest != null) { + nextProcessor.processRequest(upgradeRequest); + } + + nextProcessor.processRequest(request); + } + + @Override + public void shutdown() { + LOG.info("Shutting down"); + nextProcessor.shutdown(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderSessionTracker.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderSessionTracker.java new file mode 100644 index 00000000000..f20338af20e --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderSessionTracker.java @@ -0,0 +1,213 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.KeeperException.SessionMovedException; +import org.apache.zookeeper.KeeperException.UnknownSessionException; +import org.apache.zookeeper.server.SessionTrackerImpl; +import org.apache.zookeeper.server.ZooKeeperServerListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.PrintWriter; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentMap; + +/** + * The leader session tracker tracks local and global sessions on the leader. + */ +public class LeaderSessionTracker extends UpgradeableSessionTracker { + private static final Logger LOG = LoggerFactory.getLogger(LeaderSessionTracker.class); + + private final boolean localSessionsEnabled; + private final SessionTrackerImpl globalSessionTracker; + + /** + * Server id of the leader + */ + private final long serverId; + + public LeaderSessionTracker(SessionExpirer expirer, + ConcurrentMap sessionsWithTimeouts, + int tickTime, long id, boolean localSessionsEnabled, + ZooKeeperServerListener listener) { + + this.globalSessionTracker = new SessionTrackerImpl( + expirer, sessionsWithTimeouts, tickTime, id, listener); + + this.localSessionsEnabled = localSessionsEnabled; + if (this.localSessionsEnabled) { + createLocalSessionTracker(expirer, tickTime, id, listener); + } + serverId = id; + } + + // Returns the serverId from the sessionId (the high order byte) + public static long getServerIdFromSessionId(long sessionId) { + return sessionId >> 56; + } + + public void removeSession(long sessionId) { + if (localSessionTracker != null) { + localSessionTracker.removeSession(sessionId); + } + globalSessionTracker.removeSession(sessionId); + } + + public void start() { + globalSessionTracker.start(); + if (localSessionTracker != null) { + localSessionTracker.start(); + } + } + + public void shutdown() { + if (localSessionTracker != null) { + localSessionTracker.shutdown(); + } + globalSessionTracker.shutdown(); + } + + public boolean isGlobalSession(long sessionId) { + return globalSessionTracker.isTrackingSession(sessionId); + } + + public boolean addGlobalSession(long sessionId, int sessionTimeout) { + boolean added = + globalSessionTracker.addSession(sessionId, sessionTimeout); + if (localSessionsEnabled && added) { + // Only do extra logging so we know what kind of session this is + // if we're supporting both kinds of sessions + LOG.info("Adding global session 0x" + Long.toHexString(sessionId)); + } + return added; + } + + public boolean addSession(long sessionId, int sessionTimeout) { + boolean added; + if (localSessionsEnabled && !isGlobalSession(sessionId)) { + added = localSessionTracker.addSession(sessionId, sessionTimeout); + // Check for race condition with session upgrading + if (isGlobalSession(sessionId)) { + added = false; + localSessionTracker.removeSession(sessionId); + } else if (added) { + LOG.info("Adding local session 0x" + Long.toHexString(sessionId)); + } + } else { + added = addGlobalSession(sessionId, sessionTimeout); + } + return added; + } + + public boolean touchSession(long sessionId, int sessionTimeout) { + if (localSessionTracker != null && + localSessionTracker.touchSession(sessionId, sessionTimeout)) { + return true; + } + return globalSessionTracker.touchSession(sessionId, sessionTimeout); + } + + public long createSession(int sessionTimeout) { + if (localSessionsEnabled) { + return localSessionTracker.createSession(sessionTimeout); + } + return globalSessionTracker.createSession(sessionTimeout); + } + + public void checkSession(long sessionId, Object owner) + throws SessionExpiredException, SessionMovedException, + UnknownSessionException { + if (localSessionTracker != null) { + try { + localSessionTracker.checkSession(sessionId, owner); + // A session can both be a local and global session during + // upgrade + if (!isGlobalSession(sessionId)) { + return; + } + } catch (UnknownSessionException e) { + // Ignore. We'll check instead whether it's a global session + } + } + try { + globalSessionTracker.checkSession(sessionId, owner); + // if we can get here, it is a valid global session + return; + } catch (UnknownSessionException e) { + // Ignore. This may be local session from other servers. + } + + /* + * if local session is not enabled or it used to be our local session + * throw sessions expires + */ + if (!localSessionsEnabled || (getServerIdFromSessionId(sessionId) == serverId)) { + throw new SessionExpiredException(); + } + } + + public void checkGlobalSession(long sessionId, Object owner) + throws SessionExpiredException, SessionMovedException { + try { + globalSessionTracker.checkSession(sessionId, owner); + } catch (UnknownSessionException e) { + // For global session, if we don't know it, it is already expired + throw new SessionExpiredException(); + } + } + + public void setOwner(long sessionId, Object owner) + throws SessionExpiredException { + if (localSessionTracker != null) { + try { + localSessionTracker.setOwner(sessionId, owner); + return; + } catch (SessionExpiredException e) { + // Ignore. We'll check instead whether it's a global session + } + } + globalSessionTracker.setOwner(sessionId, owner); + } + + public void dumpSessions(PrintWriter pwriter) { + if (localSessionTracker != null) { + pwriter.print("Local "); + localSessionTracker.dumpSessions(pwriter); + pwriter.print("Global "); + } + globalSessionTracker.dumpSessions(pwriter); + } + + public void setSessionClosing(long sessionId) { + // call is no-op if session isn't tracked so safe to call both + if (localSessionTracker != null) { + localSessionTracker.setSessionClosing(sessionId); + } + globalSessionTracker.setSessionClosing(sessionId); + } + + public Map> getSessionExpiryMap() { + Map> sessionExpiryMap; + // combine local and global sessions, getting local first so upgrades + // to global are caught + if (localSessionTracker != null) { + sessionExpiryMap = localSessionTracker.getSessionExpiryMap(); + } else { + sessionExpiryMap = new TreeMap>(); + } + sessionExpiryMap.putAll(globalSessionTracker.getSessionExpiryMap()); + return sessionExpiryMap; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java new file mode 100644 index 00000000000..b325568a8d8 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java @@ -0,0 +1,227 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.server.ContainerManager; +import org.apache.zookeeper.server.DataTreeBean; +import org.apache.zookeeper.server.FinalRequestProcessor; +import org.apache.zookeeper.server.PrepRequestProcessor; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * + * Just like the standard ZooKeeperServer. We just replace the request + * processors: PrepRequestProcessor -> ProposalRequestProcessor -> + * CommitProcessor -> Leader.ToBeAppliedRequestProcessor -> + * FinalRequestProcessor + */ +public class LeaderZooKeeperServer extends QuorumZooKeeperServer { + CommitProcessor commitProcessor; + PrepRequestProcessor prepRequestProcessor; + private ContainerManager containerManager; // guarded by sync + + /** + * @param port + * @param dataDir + * @throws IOException + */ + LeaderZooKeeperServer(FileTxnSnapLog logFactory, QuorumPeer self, ZKDatabase zkDb) throws IOException { + super(logFactory, self.tickTime, self.minSessionTimeout, self.maxSessionTimeout, zkDb, self); + } + + public Leader getLeader() { + return self.leader; + } + + @Override + protected void setupRequestProcessors() { + RequestProcessor finalProcessor = new FinalRequestProcessor(this); + RequestProcessor toBeAppliedProcessor = new Leader.ToBeAppliedRequestProcessor(finalProcessor, getLeader()); + commitProcessor = new CommitProcessor(toBeAppliedProcessor, + Long.toString(getServerId()), false, + getZooKeeperServerListener()); + commitProcessor.start(); + ProposalRequestProcessor proposalProcessor = new ProposalRequestProcessor(this, + commitProcessor); + proposalProcessor.initialize(); + prepRequestProcessor = new PrepRequestProcessor(this, proposalProcessor); + prepRequestProcessor.start(); + firstProcessor = new LeaderRequestProcessor(this, prepRequestProcessor); + + setupContainerManager(); + } + + private synchronized void setupContainerManager() { + containerManager = new ContainerManager(getZKDatabase(), prepRequestProcessor, + Integer.getInteger("znode.container.checkIntervalMs", (int) TimeUnit.MINUTES.toMillis(1)), + Integer.getInteger("znode.container.maxPerMinute", 10000) + ); + } + + @Override + public synchronized void startup() { + super.startup(); + if (containerManager != null) { + containerManager.start(); + } + } + + @Override + public synchronized void shutdown() { + if (containerManager != null) { + containerManager.stop(); + } + super.shutdown(); + } + + @Override + public int getGlobalOutstandingLimit() { + int divisor = self.getQuorumSize() > 2 ? self.getQuorumSize() - 1 : 1; + return super.getGlobalOutstandingLimit() / divisor; + } + + @Override + public void createSessionTracker() { + sessionTracker = new LeaderSessionTracker( + this, getZKDatabase().getSessionWithTimeOuts(), + tickTime, self.getId(), self.areLocalSessionsEnabled(), + getZooKeeperServerListener()); + } + + public boolean touch(long sess, int to) { + return sessionTracker.touchSession(sess, to); + } + + public boolean checkIfValidGlobalSession(long sess, int to) { + if (self.areLocalSessionsEnabled() && + !upgradeableSessionTracker.isGlobalSession(sess)) { + return false; + } + return sessionTracker.touchSession(sess, to); + } + + /** + * Requests coming from the learner should go directly to + * PrepRequestProcessor + * + * @param request + */ + public void submitLearnerRequest(Request request) { + /* + * Requests coming from the learner should have gone through + * submitRequest() on each server which already perform some request + * validation, so we don't need to do it again. + * + * Additionally, LearnerHandler should start submitting requests into + * the leader's pipeline only when the leader's server is started, so we + * can submit the request directly into PrepRequestProcessor. + * + * This is done so that requests from learners won't go through + * LeaderRequestProcessor which perform local session upgrade. + */ + prepRequestProcessor.processRequest(request); + } + + @Override + protected void registerJMX() { + // register with JMX + try { + jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); + MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxDataTreeBean = null; + } + } + + public void registerJMX(LeaderBean leaderBean, + LocalPeerBean localPeerBean) { + // register with JMX + if (self.jmxLeaderElectionBean != null) { + try { + MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + } + self.jmxLeaderElectionBean = null; + } + + try { + jmxServerBean = leaderBean; + MBeanRegistry.getInstance().register(leaderBean, localPeerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxServerBean = null; + } + } + + @Override + protected void unregisterJMX() { + // unregister from JMX + try { + if (jmxDataTreeBean != null) { + MBeanRegistry.getInstance().unregister(jmxDataTreeBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + jmxDataTreeBean = null; + } + + protected void unregisterJMX(Leader leader) { + // unregister from JMX + try { + if (jmxServerBean != null) { + MBeanRegistry.getInstance().unregister(jmxServerBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + jmxServerBean = null; + } + + @Override + public String getState() { + return "leader"; + } + + /** + * Returns the id of the associated QuorumPeer, which will do for a unique + * id of this server. + */ + @Override + public long getServerId() { + return self.getId(); + } + + @Override + protected void revalidateSession(ServerCnxn cnxn, long sessionId, + int sessionTimeout) throws IOException { + super.revalidateSession(cnxn, sessionId, sessionTimeout); + try { + // setowner as the leader itself, unless updated + // via the follower handlers + setOwner(sessionId, ServerCnxn.me); + } catch (SessionExpiredException e) { + // this is ok, it just means that the session revalidation failed. + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Learner.java b/src/java/main/org/apache/zookeeper/server/quorum/Learner.java new file mode 100644 index 00000000000..0edb92058fd --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/Learner.java @@ -0,0 +1,584 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.ConnectException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.util.LinkedList; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +/** + * This class is the superclass of two of the three main actors in a ZK ensemble: Followers and Observers. Both Followers and Observers share a good deal of code which is moved into Peer to avoid + * duplication. + */ +public class Learner { + protected static final Logger LOG = LoggerFactory.getLogger(Learner.class); + static final private boolean nodelay = System.getProperty("follower.nodelay", "true").equals("true"); + + static { + LOG.info("TCP NoDelay set to: " + nodelay); + } + + final ConcurrentHashMap pendingRevalidations = + new ConcurrentHashMap(); + protected BufferedOutputStream bufferedOutput; + protected Socket sock; + protected InputArchive leaderIs; + protected OutputArchive leaderOs; + /** + * the protocol version of the leader + */ + protected int leaderProtocolVersion = 0x01; + QuorumPeer self; + LearnerZooKeeperServer zk; + + /** + * Socket getter + */ + public Socket getSocket() { + return sock; + } + + public int getPendingRevalidationsCount() { + return pendingRevalidations.size(); + } + + /** + * validate a session for a client + * + * @param clientId the client to be revalidated + * @param timeout the timeout for which the session is valid + */ + void validateSession(ServerCnxn cnxn, long clientId, int timeout) + throws IOException { + LOG.info("Revalidating client: 0x" + Long.toHexString(clientId)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeLong(clientId); + dos.writeInt(timeout); + dos.close(); + QuorumPacket qp = new QuorumPacket(Leader.REVALIDATE, -1, baos + .toByteArray(), null); + pendingRevalidations.put(clientId, cnxn); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, + ZooTrace.SESSION_TRACE_MASK, + "To validate session 0x" + + Long.toHexString(clientId)); + } + writePacket(qp, true); + } + + /** + * write a packet to the leader + * + * @param pp the proposal packet to be sent to the leader + */ + void writePacket(QuorumPacket pp, boolean flush) throws IOException { + synchronized (leaderOs) { + if (pp != null) { + leaderOs.writeRecord(pp, "packet"); + } + if (flush) { + bufferedOutput.flush(); + } + } + } + + /** + * read a packet from the leader + * + * @param pp the packet to be instantiated + */ + void readPacket(QuorumPacket pp) throws IOException { + synchronized (leaderIs) { + leaderIs.readRecord(pp, "packet"); + } + long traceMask = ZooTrace.SERVER_PACKET_TRACE_MASK; + if (pp.getType() == Leader.PING) { + traceMask = ZooTrace.SERVER_PING_TRACE_MASK; + } + if (LOG.isTraceEnabled()) { + ZooTrace.logQuorumPacket(LOG, traceMask, 'i', pp); + } + } + + /** + * send a request packet to the leader + * + * @param request the request from the client + */ + void request(Request request) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream oa = new DataOutputStream(baos); + oa.writeLong(request.sessionId); + oa.writeInt(request.cxid); + oa.writeInt(request.type); + if (request.request != null) { + request.request.rewind(); + int len = request.request.remaining(); + byte b[] = new byte[len]; + request.request.get(b); + request.request.rewind(); + oa.write(b); + } + oa.close(); + QuorumPacket qp = new QuorumPacket(Leader.REQUEST, -1, baos.toByteArray(), request.authInfo); + writePacket(qp, true); + } + + /** + * Returns the address of the node we think is the leader. + */ + protected InetSocketAddress findLeader() { + InetSocketAddress addr = null; + // Find the leader by id + Vote current = self.getCurrentVote(); + for (QuorumServer s : self.getView().values()) { + if (s.id == current.getId()) { + addr = s.addr; + break; + } + } + if (addr == null) { + LOG.warn("Couldn't find the leader with id = " + + current.getId()); + } + return addr; + } + + /** + * Overridable helper method to return the System.nanoTime(). This method behaves identical to System.nanoTime(). + */ + protected long nanoTime() { + return System.nanoTime(); + } + + /** + * Overridable helper method to simply call sock.connect(). This can be overriden in tests to fake connection success/failure for connectToLeader. + */ + protected void sockConnect(Socket sock, InetSocketAddress addr, int timeout) + throws IOException { + sock.connect(addr, timeout); + } + + /** + * Establish a connection with the Leader found by findLeader. Retries until either initLimit time has elapsed or 5 tries have happened. + * + * @param addr - the address of the Leader to connect to. + * @throws IOException - if the socket connection fails on the 5th attempt + */ + protected void connectToLeader(InetSocketAddress addr) + throws IOException, ConnectException, InterruptedException { + sock = new Socket(); + sock.setSoTimeout(self.tickTime * self.initLimit); + + int initLimitTime = self.tickTime * self.initLimit; + int remainingInitLimitTime = initLimitTime; + long startNanoTime = nanoTime(); + + for (int tries = 0; tries < 5; tries++) { + try { + // recalculate the init limit time because retries sleep for 1000 milliseconds + remainingInitLimitTime = initLimitTime - (int) ((nanoTime() - startNanoTime) / 1000000); + if (remainingInitLimitTime <= 0) { + LOG.error("initLimit exceeded on retries."); + throw new IOException("initLimit exceeded on retries."); + } + + sockConnect(sock, addr, Math.min(self.tickTime * self.syncLimit, remainingInitLimitTime)); + sock.setTcpNoDelay(nodelay); + break; + } catch (IOException e) { + remainingInitLimitTime = initLimitTime - (int) ((nanoTime() - startNanoTime) / 1000000); + + if (remainingInitLimitTime <= 1000) { + LOG.error("Unexpected exception, initLimit exceeded. tries=" + tries + + ", remaining init limit=" + remainingInitLimitTime + + ", connecting to " + addr, e); + throw e; + } else if (tries >= 4) { + LOG.error("Unexpected exception, retries exceeded. tries=" + tries + + ", remaining init limit=" + remainingInitLimitTime + + ", connecting to " + addr, e); + throw e; + } else { + LOG.warn("Unexpected exception, tries=" + tries + + ", remaining init limit=" + remainingInitLimitTime + + ", connecting to " + addr, e); + sock = new Socket(); + sock.setSoTimeout(self.tickTime * self.initLimit); + } + } + Thread.sleep(1000); + } + leaderIs = BinaryInputArchive.getArchive(new BufferedInputStream(sock.getInputStream())); + bufferedOutput = new BufferedOutputStream(sock.getOutputStream()); + leaderOs = BinaryOutputArchive.getArchive(bufferedOutput); + } + + /** + * Once connected to the leader, perform the handshake protocol to establish a following / observing connection. + * + * @return the zxid the Leader sends for synchronization purposes. + */ + protected long registerWithLeader(int pktType) throws IOException { + /* + * Send follower info, including last zxid and sid + */ + + QuorumPacket qp = new QuorumPacket(); + qp.setType(pktType); + qp.setZxid(ZxidUtils.makeZxid(self.getAcceptedEpoch(), 0)); + + /* + * Add sid to payload + */ + LearnerInfo li = new LearnerInfo(self.getId(), 0x10000, self.getQuorumVerifier().getVersion()); + ByteArrayOutputStream bsid = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(bsid); + boa.writeRecord(li, "LearnerInfo"); + qp.setData(bsid.toByteArray()); + writePacket(qp, true); + readPacket(qp); + final long newEpoch = ZxidUtils.getEpochFromZxid(qp.getZxid()); + if (qp.getType() == Leader.LEADERINFO) { + // we are connected to a 1.0 server so accept the new epoch and read the next packet + leaderProtocolVersion = ByteBuffer.wrap(qp.getData()).getInt(); + byte epochBytes[] = new byte[4]; + final ByteBuffer wrappedEpochBytes = ByteBuffer.wrap(epochBytes); + if (newEpoch > self.getAcceptedEpoch()) { + wrappedEpochBytes.putInt((int) self.getCurrentEpoch()); + self.setAcceptedEpoch(newEpoch); + } else if (newEpoch == self.getAcceptedEpoch()) { + // since we have already acked an epoch equal to the leaders, we cannot ack + // again, but we still need to send our lastZxid to the leader so that we can + // sync with it if it does assume leadership of the epoch. + // the -1 indicates that this reply should not count as an ack for the new epoch + wrappedEpochBytes.putInt(-1); + } else { + throw new IOException("Leaders epoch, " + newEpoch + " is less than accepted epoch, " + self.getAcceptedEpoch()); + } + QuorumPacket ackNewEpoch = new QuorumPacket(Leader.ACKEPOCH, self.getLastLoggedZxid(), epochBytes, null); + writePacket(ackNewEpoch, true); + return ZxidUtils.makeZxid(newEpoch, 0); + } else { + if (newEpoch > self.getAcceptedEpoch()) { + self.setAcceptedEpoch(newEpoch); + } + if (qp.getType() != Leader.NEWLEADER) { + LOG.error("First packet should have been NEWLEADER"); + throw new IOException("First packet should have been NEWLEADER"); + } + return qp.getZxid(); + } + } + + /** + * Finally, synchronize our history with the Leader. + */ + protected void syncWithLeader(long newLeaderZxid) throws Exception { + QuorumPacket ack = new QuorumPacket(Leader.ACK, 0, null, null); + QuorumPacket qp = new QuorumPacket(); + long newEpoch = ZxidUtils.getEpochFromZxid(newLeaderZxid); + + QuorumVerifier newLeaderQV = null; + /** + * 从leader收到的第二个包 + */ + readPacket(qp); + LinkedList packetsCommitted = new LinkedList(); + LinkedList packetsNotCommitted = new LinkedList(); + synchronized (zk) { + if (qp.getType() == Leader.DIFF) { + LOG.info("Getting a diff from the leader 0x" + Long.toHexString(qp.getZxid())); + } else if (qp.getType() == Leader.SNAP) { + LOG.info("Getting a snapshot from leader"); + // The leader is going to dump the database + // db is clear as part of deserializeSnapshot() + zk.getZKDatabase().deserializeSnapshot(leaderIs); + String signature = leaderIs.readString("signature"); + if (!signature.equals("BenWasHere")) { + LOG.error("Missing signature. Got " + signature); + throw new IOException("Missing signature"); + } + } else if (qp.getType() == Leader.TRUNC) { + //we need to truncate the log to the lastzxid of the leader + LOG.warn("Truncating log to get in sync with the leader 0x" + Long.toHexString(qp.getZxid())); + boolean truncated = zk.getZKDatabase().truncateLog(qp.getZxid()); + if (!truncated) { + // not able to truncate the log + LOG.error("Not able to truncate the log " + Long.toHexString(qp.getZxid())); + System.exit(13); + } + } else { + LOG.error("Got unexpected packet from leader: {}, exiting ... ", LearnerHandler.packetToString(qp)); + System.exit(13); + } + zk.getZKDatabase().initConfigInZKDatabase(self.getQuorumVerifier()); + zk.getZKDatabase().setlastProcessedZxid(qp.getZxid()); + zk.createSessionTracker(); + long lastQueued = 0; + // in V1.0 we take a snapshot when we get the NEWLEADER message, but in pre V1.0 + // we take the snapshot at the UPDATE, since V1.0 also gets the UPDATE (after the NEWLEADER) + // we need to make sure that we don't take the snapshot twice. + boolean snapshotTaken = false; + // we are now going to start getting transactions to apply followed by an UPTODATE + outerLoop: + while (self.isRunning()) { + readPacket(qp); + switch (qp.getType()) { + case Leader.PROPOSAL: + PacketInFlight pif = new PacketInFlight(); + pif.hdr = new TxnHeader(); + pif.rec = SerializeUtils.deserializeTxn(qp.getData(), pif.hdr); + if (pif.hdr.getZxid() != lastQueued + 1) { + LOG.warn("Got zxid 0x" + + Long.toHexString(pif.hdr.getZxid()) + + " expected 0x" + + Long.toHexString(lastQueued + 1)); + } + lastQueued = pif.hdr.getZxid(); + + if (pif.hdr.getType() == OpCode.reconfig) { + SetDataTxn setDataTxn = (SetDataTxn) pif.rec; + QuorumVerifier qv = self.configFromString(new String(setDataTxn.getData())); + self.setLastSeenQuorumVerifier(qv, true); + } + + packetsNotCommitted.add(pif); + break; + case Leader.COMMIT: + case Leader.COMMITANDACTIVATE: + if (!snapshotTaken) { + pif = packetsNotCommitted.peekFirst(); + if (pif.hdr.getZxid() != qp.getZxid()) { + LOG.warn("Committing " + qp.getZxid() + ", but next proposal is " + pif.hdr.getZxid()); + } else { + if (qp.getType() == Leader.COMMITANDACTIVATE) { + QuorumVerifier qv = self.configFromString(new String(((SetDataTxn) pif.rec).getData())); + boolean majorChange = + self.processReconfig(qv, ByteBuffer.wrap(qp.getData()).getLong(), qp.getZxid(), true); + if (majorChange) { + throw new Exception("changes proposed in reconfig"); + } + } + zk.processTxn(pif.hdr, pif.rec); + packetsNotCommitted.remove(); + } + } else { + packetsCommitted.add(qp.getZxid()); + } + break; + case Leader.INFORM: + case Leader.INFORMANDACTIVATE: + PacketInFlight packet = new PacketInFlight(); + packet.hdr = new TxnHeader(); + + if (qp.getType() == Leader.INFORMANDACTIVATE) { + ByteBuffer buffer = ByteBuffer.wrap(qp.getData()); + long suggestedLeaderId = buffer.getLong(); + byte[] remainingdata = new byte[buffer.remaining()]; + buffer.get(remainingdata); + packet.rec = SerializeUtils.deserializeTxn(remainingdata, packet.hdr); + QuorumVerifier qv = self.configFromString(new String(((SetDataTxn) packet.rec).getData())); + boolean majorChange = + self.processReconfig(qv, suggestedLeaderId, qp.getZxid(), true); + if (majorChange) { + throw new Exception("changes proposed in reconfig"); + } + } else { + packet.rec = SerializeUtils.deserializeTxn(qp.getData(), packet.hdr); + // Log warning message if txn comes out-of-order + if (packet.hdr.getZxid() != lastQueued + 1) { + LOG.warn("Got zxid 0x" + + Long.toHexString(packet.hdr.getZxid()) + + " expected 0x" + + Long.toHexString(lastQueued + 1)); + } + lastQueued = packet.hdr.getZxid(); + } + + if (!snapshotTaken) { + // Apply to db directly if we haven't taken the snapshot + zk.processTxn(packet.hdr, packet.rec); + } else { + packetsNotCommitted.add(packet); + packetsCommitted.add(qp.getZxid()); + } + break; + case Leader.UPTODATE: + LOG.info("Learner received UPTODATE message"); + if (newLeaderQV != null) { + boolean majorChange = self.processReconfig(newLeaderQV, null, null, true); + if (majorChange) { + throw new Exception("changes proposed in reconfig"); + } + } + if (!snapshotTaken) { // true for the pre v1.0 case + zk.takeSnapshot(); + self.setCurrentEpoch(newEpoch); + } + self.setZooKeeperServer(zk); + self.adminServer.setZooKeeperServer(zk); + break outerLoop; + case Leader.NEWLEADER: // it will be NEWLEADER in v1.0 + LOG.info("Learner received NEWLEADER message"); + if (qp.getData() != null && qp.getData().length > 1) { + try { + QuorumVerifier qv = self.configFromString(new String(qp.getData())); + self.setLastSeenQuorumVerifier(qv, true); + newLeaderQV = qv; + } catch (Exception e) { + e.printStackTrace(); + } + } + + zk.takeSnapshot(); + self.setCurrentEpoch(newEpoch); + snapshotTaken = true; + writePacket(new QuorumPacket(Leader.ACK, newLeaderZxid, null, null), true); + break; + } + } + } + ack.setZxid(ZxidUtils.makeZxid(newEpoch, 0)); + writePacket(ack, true); + sock.setSoTimeout(self.tickTime * self.syncLimit); + //与leader同步完成后,启动服务器,接收客户端请求。 + zk.startup(); + /* + * Update the election vote here to ensure that all members of the + * ensemble report the same vote to new servers that start up and + * send leader election notifications to the ensemble. + * + * @see https://issues.apache.org/jira/browse/ZOOKEEPER-1732 + */ + self.updateElectionVote(newEpoch); + + // We need to log the stuff that came in between the snapshot and the uptodate + if (zk instanceof FollowerZooKeeperServer) { + FollowerZooKeeperServer fzk = (FollowerZooKeeperServer) zk; + for (PacketInFlight p : packetsNotCommitted) { + fzk.logRequest(p.hdr, p.rec); + } + for (Long zxid : packetsCommitted) { + fzk.commit(zxid); + } + } else if (zk instanceof ObserverZooKeeperServer) { + // Similar to follower, we need to log requests between the snapshot + // and UPTODATE + ObserverZooKeeperServer ozk = (ObserverZooKeeperServer) zk; + for (PacketInFlight p : packetsNotCommitted) { + Long zxid = packetsCommitted.peekFirst(); + if (p.hdr.getZxid() != zxid) { + // log warning message if there is no matching commit + // old leader send outstanding proposal to observer + LOG.warn("Committing " + Long.toHexString(zxid) + + ", but next proposal is " + + Long.toHexString(p.hdr.getZxid())); + continue; + } + packetsCommitted.remove(); + Request request = new Request(null, p.hdr.getClientId(), + p.hdr.getCxid(), p.hdr.getType(), null, null); + request.setTxn(p.rec); + request.setHdr(p.hdr); + ozk.commitRequest(request); + } + } else { + // New server type need to handle in-flight packets + throw new UnsupportedOperationException("Unknown server type"); + } + } + + protected void revalidate(QuorumPacket qp) throws IOException { + ByteArrayInputStream bis = new ByteArrayInputStream(qp + .getData()); + DataInputStream dis = new DataInputStream(bis); + long sessionId = dis.readLong(); + boolean valid = dis.readBoolean(); + ServerCnxn cnxn = pendingRevalidations.remove(sessionId); + if (cnxn == null) { + LOG.warn("Missing session 0x" + + Long.toHexString(sessionId) + + " for validation"); + } else { + zk.finishSessionInit(cnxn, valid); + } + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, + ZooTrace.SESSION_TRACE_MASK, + "Session 0x" + Long.toHexString(sessionId) + + " is valid: " + valid); + } + } + + protected void ping(QuorumPacket qp) throws IOException { + // Send back the ping with our session data + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + Map touchTable = zk.getTouchSnapshot(); + for (Entry entry : touchTable.entrySet()) { + dos.writeLong(entry.getKey()); + dos.writeInt(entry.getValue()); + } + qp.setData(bos.toByteArray()); + writePacket(qp, true); + } + + /** + * Shutdown the Peer + */ + public void shutdown() { + self.setZooKeeperServer(null); + self.closeAllConnections(); + self.adminServer.setZooKeeperServer(null); + // shutdown previous zookeeper + if (zk != null) { + zk.shutdown(); + } + } + + static class PacketInFlight { + TxnHeader hdr; + Record rec; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java b/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java new file mode 100644 index 00000000000..3eb9cccf6b3 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java @@ -0,0 +1,954 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.TxnLogProposalIterator; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperThread; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; + +/** + * There will be an instance of this class created by the Leader for each + * learner. All communication with a learner is handled by this + * class. + */ +public class LearnerHandler extends ZooKeeperThread { + /** + * For testing purpose, force leader to use snapshot to sync with followers + */ + public static final String FORCE_SNAP_SYNC = "zookeeper.forceSnapshotSync"; + private static final Logger LOG = LoggerFactory.getLogger(LearnerHandler.class); + protected final Socket sock; + final Leader leader; + /** + * The packets to be sent to the learner + */ + final LinkedBlockingQueue queuedPackets = + new LinkedBlockingQueue(); + /** + * If this packet is queued, the sender thread will exit + */ + final QuorumPacket proposalOfDeath = new QuorumPacket(); + /** + * ZooKeeper server identifier of this learner + */ + protected long sid = 0; + protected int version = 0x1; + /** Deadline for receiving the next ack. If we are bootstrapping then + * it's based on the initLimit, if we are done bootstrapping it's based + * on the syncLimit. Once the deadline is past this learner should + * be considered no longer "sync'd" with the leader. */ + volatile long tickOfNextAckDeadline; + private SyncLimitCheck syncLimitCheck = new SyncLimitCheck(); + private BinaryInputArchive ia; + + ; + private BinaryOutputArchive oa; + private BufferedOutputStream bufferedOutput; + /** + * Keep track of whether we have started send packets thread + */ + private volatile boolean sendingThreadStarted = false; + private boolean forceSnapSync = false; + /** + * Keep track of whether we need to queue TRUNC or DIFF into packet queue + * that we are going to blast it to the learner + */ + private boolean needOpPacket = true; + /** + * Last zxid sent to the learner as part of synchronization + */ + private long leaderLastZxid; + private LearnerType learnerType = LearnerType.PARTICIPANT; + + LearnerHandler(Socket sock, Leader leader) throws IOException { + super("LearnerHandler-" + sock.getRemoteSocketAddress()); + this.sock = sock; + this.leader = leader; + leader.addLearnerHandler(this); + } + + static public String packetToString(QuorumPacket p) { + String type; + String mess = null; + + switch (p.getType()) { + case Leader.ACK: + type = "ACK"; + break; + case Leader.COMMIT: + type = "COMMIT"; + break; + case Leader.FOLLOWERINFO: + type = "FOLLOWERINFO"; + break; + case Leader.NEWLEADER: + type = "NEWLEADER"; + break; + case Leader.PING: + type = "PING"; + break; + case Leader.PROPOSAL: + type = "PROPOSAL"; + TxnHeader hdr = new TxnHeader(); + try { + SerializeUtils.deserializeTxn(p.getData(), hdr); + // mess = "transaction: " + txn.toString(); + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + break; + case Leader.REQUEST: + type = "REQUEST"; + break; + case Leader.REVALIDATE: + type = "REVALIDATE"; + ByteArrayInputStream bis = new ByteArrayInputStream(p.getData()); + DataInputStream dis = new DataInputStream(bis); + try { + long id = dis.readLong(); + mess = " sessionid = " + id; + } catch (IOException e) { + LOG.warn("Unexpected exception", e); + } + + break; + case Leader.UPTODATE: + type = "UPTODATE"; + break; + case Leader.DIFF: + type = "DIFF"; + break; + case Leader.TRUNC: + type = "TRUNC"; + break; + case Leader.SNAP: + type = "SNAP"; + break; + case Leader.ACKEPOCH: + type = "ACKEPOCH"; + break; + case Leader.SYNC: + type = "SYNC"; + break; + case Leader.INFORM: + type = "INFORM"; + break; + case Leader.COMMITANDACTIVATE: + type = "COMMITANDACTIVATE"; + break; + case Leader.INFORMANDACTIVATE: + type = "INFORMANDACTIVATE"; + break; + default: + type = "UNKNOWN" + p.getType(); + } + String entry = null; + if (type != null) { + entry = type + " " + Long.toHexString(p.getZxid()) + " " + mess; + } + return entry; + } + + public Socket getSocket() { + return sock; + } + + long getSid() { + return sid; + } + + int getVersion() { + return version; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("LearnerHandler ").append(sock); + sb.append(" tickOfNextAckDeadline:").append(tickOfNextAckDeadline()); + sb.append(" synced?:").append(synced()); + sb.append(" queuedPacketLength:").append(queuedPackets.size()); + return sb.toString(); + } + + public LearnerType getLearnerType() { + return learnerType; + } + + /** + * This method will use the thread to send packets added to the + * queuedPackets list + * + * @throws InterruptedException + */ + private void sendPackets() throws InterruptedException { + long traceMask = ZooTrace.SERVER_PACKET_TRACE_MASK; + while (true) { + try { + QuorumPacket p; + p = queuedPackets.poll(); + if (p == null) { + bufferedOutput.flush(); + p = queuedPackets.take(); + } + + if (p == proposalOfDeath) { + // Packet of death! + break; + } + if (p.getType() == Leader.PING) { + traceMask = ZooTrace.SERVER_PING_TRACE_MASK; + } + if (p.getType() == Leader.PROPOSAL) { + syncLimitCheck.updateProposal(p.getZxid(), System.nanoTime()); + } + if (LOG.isTraceEnabled()) { + ZooTrace.logQuorumPacket(LOG, traceMask, 'o', p); + } + oa.writeRecord(p, "packet"); + } catch (IOException e) { + if (!sock.isClosed()) { + LOG.warn("Unexpected exception at " + this, e); + try { + // this will cause everything to shutdown on + // this learner handler and will help notify + // the learner/observer instantaneously + sock.close(); + } catch (IOException ie) { + LOG.warn("Error closing socket for handler " + this, ie); + } + } + break; + } + } + } + + /** + * This thread will receive packets from the peer and process them and + * also listen to new connections from new peers. + */ + @Override + public void run() { + try { + tickOfNextAckDeadline = leader.self.tick.get() + + leader.self.initLimit + leader.self.syncLimit; + + ia = BinaryInputArchive.getArchive(new BufferedInputStream(sock + .getInputStream())); + bufferedOutput = new BufferedOutputStream(sock.getOutputStream()); + oa = BinaryOutputArchive.getArchive(bufferedOutput); + + QuorumPacket qp = new QuorumPacket(); + ia.readRecord(qp, "packet"); + if (qp.getType() != Leader.FOLLOWERINFO && qp.getType() != Leader.OBSERVERINFO) { + LOG.error("First packet " + qp.toString() + + " is not FOLLOWERINFO or OBSERVERINFO!"); + return; + } + + byte learnerInfoData[] = qp.getData(); + if (learnerInfoData != null) { + ByteBuffer bbsid = ByteBuffer.wrap(learnerInfoData); + if (learnerInfoData.length >= 8) { + this.sid = bbsid.getLong(); + } + if (learnerInfoData.length >= 12) { + this.version = bbsid.getInt(); // protocolVersion + } + if (learnerInfoData.length >= 20) { + long configVersion = bbsid.getLong(); + if (configVersion > leader.self.getQuorumVerifier().getVersion()) { + throw new IOException("Follower is ahead of the leader (has a later activated configuration)"); + } + } + } else { + this.sid = leader.followerCounter.getAndDecrement(); + } + + if (leader.self.getView().containsKey(this.sid)) { + LOG.info("Follower sid: " + this.sid + " : info : " + + leader.self.getView().get(this.sid).toString()); + } else { + LOG.info("Follower sid: " + this.sid + " not in the current config " + Long.toHexString(leader.self.getQuorumVerifier().getVersion())); + } + + if (qp.getType() == Leader.OBSERVERINFO) { + learnerType = LearnerType.OBSERVER; + } + + long lastAcceptedEpoch = ZxidUtils.getEpochFromZxid(qp.getZxid()); + + long peerLastZxid; + StateSummary ss = null; + long zxid = qp.getZxid(); + long newEpoch = leader.getEpochToPropose(this.getSid(), lastAcceptedEpoch); + long newLeaderZxid = ZxidUtils.makeZxid(newEpoch, 0); + + if (this.getVersion() < 0x10000) { + // we are going to have to extrapolate the epoch information + long epoch = ZxidUtils.getEpochFromZxid(zxid); + ss = new StateSummary(epoch, zxid); + // fake the message + leader.waitForEpochAck(this.getSid(), ss); + } else { + byte ver[] = new byte[4]; + ByteBuffer.wrap(ver).putInt(0x10000); + QuorumPacket newEpochPacket = new QuorumPacket(Leader.LEADERINFO, newLeaderZxid, ver, null); + oa.writeRecord(newEpochPacket, "packet"); + bufferedOutput.flush(); + QuorumPacket ackEpochPacket = new QuorumPacket(); + ia.readRecord(ackEpochPacket, "packet"); + if (ackEpochPacket.getType() != Leader.ACKEPOCH) { + LOG.error(ackEpochPacket.toString() + + " is not ACKEPOCH"); + return; + } + ByteBuffer bbepoch = ByteBuffer.wrap(ackEpochPacket.getData()); + ss = new StateSummary(bbepoch.getInt(), ackEpochPacket.getZxid()); + leader.waitForEpochAck(this.getSid(), ss); + } + peerLastZxid = ss.getLastZxid(); + + // Take any necessary action if we need to send TRUNC or DIFF + // startForwarding() will be called in all cases + boolean needSnap = syncFollower(peerLastZxid, leader.zk.getZKDatabase(), leader); + + LOG.debug("Sending NEWLEADER message to " + sid); + // the version of this quorumVerifier will be set by leader.lead() in case + // the leader is just being established. waitForEpochAck makes sure that readyToStart is true if + // we got here, so the version was set + if (getVersion() < 0x10000) { + QuorumPacket newLeaderQP = new QuorumPacket(Leader.NEWLEADER, + newLeaderZxid, null, null); + oa.writeRecord(newLeaderQP, "packet"); + } else { + QuorumPacket newLeaderQP = new QuorumPacket(Leader.NEWLEADER, + newLeaderZxid, leader.self.getLastSeenQuorumVerifier() + .toString().getBytes(), null); + queuedPackets.add(newLeaderQP); + } + bufferedOutput.flush(); + + /* if we are not truncating or sending a diff just send a snapshot */ + if (needSnap) { + boolean exemptFromThrottle = getLearnerType() != LearnerType.OBSERVER; + LearnerSnapshot snapshot = + leader.getLearnerSnapshotThrottler().beginSnapshot(exemptFromThrottle); + try { + long zxidToSend = leader.zk.getZKDatabase().getDataTreeLastProcessedZxid(); + oa.writeRecord(new QuorumPacket(Leader.SNAP, zxidToSend, null, null), "packet"); + bufferedOutput.flush(); + + LOG.info("Sending snapshot last zxid of peer is 0x{}, zxid of leader is 0x{}, " + + "send zxid of db as 0x{}, {} concurrent snapshots, " + + "snapshot was {} from throttle", + Long.toHexString(peerLastZxid), + Long.toHexString(leaderLastZxid), + Long.toHexString(zxidToSend), + snapshot.getConcurrentSnapshotNumber(), + snapshot.isEssential() ? "exempt" : "not exempt"); + // Dump data to peer + leader.zk.getZKDatabase().serializeSnapshot(oa); + oa.writeString("BenWasHere", "signature"); + bufferedOutput.flush(); + } finally { + snapshot.close(); + } + } + + // Start thread that blast packets in the queue to learner + startSendingPackets(); + + /* + * Have to wait for the first ACK, wait until + * the leader is ready, and only then we can + * start processing messages. + */ + qp = new QuorumPacket(); + ia.readRecord(qp, "packet"); + if (qp.getType() != Leader.ACK) { + LOG.error("Next packet was supposed to be an ACK," + + " but received packet: {}", packetToString(qp)); + return; + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Received NEWLEADER-ACK message from " + sid); + } + leader.waitForNewLeaderAck(getSid(), qp.getZxid(), getLearnerType()); + + syncLimitCheck.start(); + + // now that the ack has been processed expect the syncLimit + sock.setSoTimeout(leader.self.tickTime * leader.self.syncLimit); + + /* + * Wait until leader starts up + */ + synchronized (leader.zk) { + while (!leader.zk.isRunning() && !this.isInterrupted()) { + leader.zk.wait(20); + } + } + // Mutation packets will be queued during the serialize, + // so we need to mark when the peer can actually start + // using the data + // + LOG.debug("Sending UPTODATE message to " + sid); + queuedPackets.add(new QuorumPacket(Leader.UPTODATE, -1, null, null)); + + while (true) { + qp = new QuorumPacket(); + ia.readRecord(qp, "packet"); + + long traceMask = ZooTrace.SERVER_PACKET_TRACE_MASK; + if (qp.getType() == Leader.PING) { + traceMask = ZooTrace.SERVER_PING_TRACE_MASK; + } + if (LOG.isTraceEnabled()) { + ZooTrace.logQuorumPacket(LOG, traceMask, 'i', qp); + } + tickOfNextAckDeadline = leader.self.tick.get() + leader.self.syncLimit; + + + ByteBuffer bb; + long sessionId; + int cxid; + int type; + + switch (qp.getType()) { + case Leader.ACK: + if (this.learnerType == LearnerType.OBSERVER) { + if (LOG.isDebugEnabled()) { + LOG.debug("Received ACK from Observer " + this.sid); + } + } + syncLimitCheck.updateAck(qp.getZxid()); + leader.processAck(this.sid, qp.getZxid(), sock.getLocalSocketAddress()); + break; + case Leader.PING: + // Process the touches + ByteArrayInputStream bis = new ByteArrayInputStream(qp + .getData()); + DataInputStream dis = new DataInputStream(bis); + while (dis.available() > 0) { + long sess = dis.readLong(); + int to = dis.readInt(); + leader.zk.touch(sess, to); + } + break; + case Leader.REVALIDATE: + bis = new ByteArrayInputStream(qp.getData()); + dis = new DataInputStream(bis); + long id = dis.readLong(); + int to = dis.readInt(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeLong(id); + boolean valid = leader.zk.checkIfValidGlobalSession(id, to); + if (valid) { + try { + //set the session owner + // as the follower that + // owns the session + leader.zk.setOwner(id, this); + } catch (SessionExpiredException e) { + LOG.error("Somehow session " + Long.toHexString(id) + " expired right after being renewed! (impossible)", e); + } + } + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, + ZooTrace.SESSION_TRACE_MASK, + "Session 0x" + Long.toHexString(id) + + " is valid: " + valid); + } + dos.writeBoolean(valid); + qp.setData(bos.toByteArray()); + queuedPackets.add(qp); + break; + case Leader.REQUEST: + bb = ByteBuffer.wrap(qp.getData()); + sessionId = bb.getLong(); + cxid = bb.getInt(); + type = bb.getInt(); + bb = bb.slice(); + Request si; + if (type == OpCode.sync) { + si = new LearnerSyncRequest(this, sessionId, cxid, type, bb, qp.getAuthinfo()); + } else { + si = new Request(null, sessionId, cxid, type, bb, qp.getAuthinfo()); + } + si.setOwner(this); + leader.zk.submitLearnerRequest(si); + break; + default: + LOG.warn("unexpected quorum packet, type: {}", packetToString(qp)); + break; + } + } + } catch (IOException e) { + if (sock != null && !sock.isClosed()) { + LOG.error("Unexpected exception causing shutdown while sock " + + "still open", e); + //close the socket to make sure the + //other side can see it being close + try { + sock.close(); + } catch (IOException ie) { + // do nothing + } + } + } catch (InterruptedException e) { + LOG.error("Unexpected exception causing shutdown", e); + } catch (SnapshotThrottleException e) { + LOG.error("too many concurrent snapshots: " + e); + } finally { + LOG.warn("******* GOODBYE " + + (sock != null ? sock.getRemoteSocketAddress() : "") + + " ********"); + shutdown(); + } + } + + /** + * Start thread that will forward any packet in the queue to the follower + */ + protected void startSendingPackets() { + if (!sendingThreadStarted) { + // Start sending packets + new Thread() { + public void run() { + Thread.currentThread().setName( + "Sender-" + sock.getRemoteSocketAddress()); + try { + sendPackets(); + } catch (InterruptedException e) { + LOG.warn("Unexpected interruption " + e.getMessage()); + } + } + }.start(); + sendingThreadStarted = true; + } else { + LOG.error("Attempting to start sending thread after it already started"); + } + } + + /** + * Determine if we need to sync with follower using DIFF/TRUNC/SNAP + * and setup follower to receive packets from commit processor + * + * @param peerLastZxid + * @param db + * @param leader + * @return true if snapshot transfer is needed. + */ + public boolean syncFollower(long peerLastZxid, ZKDatabase db, Leader leader) { + /* + * When leader election is completed, the leader will set its + * lastProcessedZxid to be (epoch < 32). There will be no txn associated + * with this zxid. + * + * The learner will set its lastProcessedZxid to the same value if + * it get DIFF or SNAP from the leader. If the same learner come + * back to sync with leader using this zxid, we will never find this + * zxid in our history. In this case, we will ignore TRUNC logic and + * always send DIFF if we have old enough history + */ + boolean isPeerNewEpochZxid = (peerLastZxid & 0xffffffffL) == 0; + // Keep track of the latest zxid which already queued + long currentZxid = peerLastZxid; + boolean needSnap = true; + boolean txnLogSyncEnabled = (db.getSnapshotSizeFactor() >= 0); + ReentrantReadWriteLock lock = db.getLogLock(); + ReadLock rl = lock.readLock(); + try { + rl.lock(); + long maxCommittedLog = db.getmaxCommittedLog(); + long minCommittedLog = db.getminCommittedLog(); + long lastProcessedZxid = db.getDataTreeLastProcessedZxid(); + + LOG.info("Synchronizing with Follower sid: {} maxCommittedLog=0x{}" + + " minCommittedLog=0x{} lastProcessedZxid=0x{}" + + " peerLastZxid=0x{}", getSid(), + Long.toHexString(maxCommittedLog), + Long.toHexString(minCommittedLog), + Long.toHexString(lastProcessedZxid), + Long.toHexString(peerLastZxid)); + + if (db.getCommittedLog().isEmpty()) { + /* + * It is possible that commitedLog is empty. In that case + * setting these value to the latest txn in leader db + * will reduce the case that we need to handle + * + * Here is how each case handle by the if block below + * 1. lastProcessZxid == peerZxid -> Handle by (2) + * 2. lastProcessZxid < peerZxid -> Handle by (3) + * 3. lastProcessZxid > peerZxid -> Handle by (5) + */ + minCommittedLog = lastProcessedZxid; + maxCommittedLog = lastProcessedZxid; + } + + /* + * Here are the cases that we want to handle + * + * 1. Force sending snapshot (for testing purpose) + * 2. Peer and leader is already sync, send empty diff + * 3. Follower has txn that we haven't seen. This may be old leader + * so we need to send TRUNC. However, if peer has newEpochZxid, + * we cannot send TRUC since the follower has no txnlog + * 4. Follower is within committedLog range or already in-sync. + * We may need to send DIFF or TRUNC depending on follower's zxid + * We always send empty DIFF if follower is already in-sync + * 5. Follower missed the committedLog. We will try to use on-disk + * txnlog + committedLog to sync with follower. If that fail, + * we will send snapshot + */ + + if (forceSnapSync) { + // Force leader to use snapshot to sync with follower + LOG.warn("Forcing snapshot sync - should not see this in production"); + } else if (lastProcessedZxid == peerLastZxid) { + // Follower is already sync with us, send empty diff + LOG.info("Sending DIFF zxid=0x" + Long.toHexString(peerLastZxid) + + " for peer sid: " + getSid()); + queueOpPacket(Leader.DIFF, peerLastZxid); + needOpPacket = false; + needSnap = false; + } else if (peerLastZxid > maxCommittedLog && !isPeerNewEpochZxid) { + // Newer than commitedLog, send trunc and done + LOG.debug("Sending TRUNC to follower zxidToSend=0x" + + Long.toHexString(maxCommittedLog) + + " for peer sid:" + getSid()); + queueOpPacket(Leader.TRUNC, maxCommittedLog); + currentZxid = maxCommittedLog; + needOpPacket = false; + needSnap = false; + } else if ((maxCommittedLog >= peerLastZxid) + && (minCommittedLog <= peerLastZxid)) { + // Follower is within commitLog range + LOG.info("Using committedLog for peer sid: " + getSid()); + Iterator itr = db.getCommittedLog().iterator(); + currentZxid = queueCommittedProposals(itr, peerLastZxid, + null, maxCommittedLog); + needSnap = false; + } else if (peerLastZxid < minCommittedLog && txnLogSyncEnabled) { + // Use txnlog and committedLog to sync + + // Calculate sizeLimit that we allow to retrieve txnlog from disk + long sizeLimit = db.calculateTxnLogSizeLimit(); + // This method can return empty iterator if the requested zxid + // is older than on-disk txnlog + Iterator txnLogItr = db.getProposalsFromTxnLog( + peerLastZxid, sizeLimit); + if (txnLogItr.hasNext()) { + LOG.info("Use txnlog and committedLog for peer sid: " + getSid()); + currentZxid = queueCommittedProposals(txnLogItr, peerLastZxid, + minCommittedLog, maxCommittedLog); + + LOG.debug("Queueing committedLog 0x" + Long.toHexString(currentZxid)); + Iterator committedLogItr = db.getCommittedLog().iterator(); + currentZxid = queueCommittedProposals(committedLogItr, currentZxid, + null, maxCommittedLog); + needSnap = false; + } + // closing the resources + if (txnLogItr instanceof TxnLogProposalIterator) { + TxnLogProposalIterator txnProposalItr = (TxnLogProposalIterator) txnLogItr; + txnProposalItr.close(); + } + } else { + LOG.warn("Unhandled scenario for peer sid: " + getSid()); + } + LOG.debug("Start forwarding 0x" + Long.toHexString(currentZxid) + + " for peer sid: " + getSid()); + leaderLastZxid = leader.startForwarding(this, currentZxid); + } finally { + rl.unlock(); + } + + if (needOpPacket && !needSnap) { + // This should never happen, but we should fall back to sending + // snapshot just in case. + LOG.error("Unhandled scenario for peer sid: " + getSid() + + " fall back to use snapshot"); + needSnap = true; + } + + return needSnap; + } + + /** + * Queue committed proposals into packet queue. The range of packets which + * is going to be queued are (peerLaxtZxid, maxZxid] + * + * @param itr iterator point to the proposals + * @param peerLastZxid last zxid seen by the follower + * @param maxZxid max zxid of the proposal to queue, null if no limit + * @param lastCommitedZxid when sending diff, we need to send lastCommitedZxid + * on the leader to follow Zab 1.0 protocol. + * @return last zxid of the queued proposal + */ + protected long queueCommittedProposals(Iterator itr, + long peerLastZxid, Long maxZxid, Long lastCommitedZxid) { + boolean isPeerNewEpochZxid = (peerLastZxid & 0xffffffffL) == 0; + long queuedZxid = peerLastZxid; + // as we look through proposals, this variable keeps track of previous + // proposal Id. + long prevProposalZxid = -1; + while (itr.hasNext()) { + Proposal propose = itr.next(); + + long packetZxid = propose.packet.getZxid(); + // abort if we hit the limit + if ((maxZxid != null) && (packetZxid > maxZxid)) { + break; + } + + // skip the proposals the peer already has + if (packetZxid < peerLastZxid) { + prevProposalZxid = packetZxid; + continue; + } + + // If we are sending the first packet, figure out whether to trunc + // or diff + if (needOpPacket) { + + // Send diff when we see the follower's zxid in our history + if (packetZxid == peerLastZxid) { + LOG.info("Sending DIFF zxid=0x" + + Long.toHexString(lastCommitedZxid) + + " for peer sid: " + getSid()); + queueOpPacket(Leader.DIFF, lastCommitedZxid); + needOpPacket = false; + continue; + } + + if (isPeerNewEpochZxid) { + // Send diff and fall through if zxid is of a new-epoch + LOG.info("Sending DIFF zxid=0x" + + Long.toHexString(lastCommitedZxid) + + " for peer sid: " + getSid()); + queueOpPacket(Leader.DIFF, lastCommitedZxid); + needOpPacket = false; + } else if (packetZxid > peerLastZxid) { + // Peer have some proposals that the leader hasn't seen yet + // it may used to be a leader + if (ZxidUtils.getEpochFromZxid(packetZxid) != + ZxidUtils.getEpochFromZxid(peerLastZxid)) { + // We cannot send TRUNC that cross epoch boundary. + // The learner will crash if it is asked to do so. + // We will send snapshot this those cases. + LOG.warn("Cannot send TRUNC to peer sid: " + getSid() + + " peer zxid is from different epoch"); + return queuedZxid; + } + + LOG.info("Sending TRUNC zxid=0x" + + Long.toHexString(prevProposalZxid) + + " for peer sid: " + getSid()); + queueOpPacket(Leader.TRUNC, prevProposalZxid); + needOpPacket = false; + } + } + + if (packetZxid <= queuedZxid) { + // We can get here, if we don't have op packet to queue + // or there is a duplicate txn in a given iterator + continue; + } + + // Since this is already a committed proposal, we need to follow + // it by a commit packet + queuePacket(propose.packet); + queueOpPacket(Leader.COMMIT, packetZxid); + queuedZxid = packetZxid; + + } + + if (needOpPacket && isPeerNewEpochZxid) { + // We will send DIFF for this kind of zxid in any case. This if-block + // is the catch when our history older than learner and there is + // no new txn since then. So we need an empty diff + LOG.info("Sending DIFF zxid=0x" + + Long.toHexString(lastCommitedZxid) + + " for peer sid: " + getSid()); + queueOpPacket(Leader.DIFF, lastCommitedZxid); + needOpPacket = false; + } + + return queuedZxid; + } + + public void shutdown() { + // Send the packet of death + try { + queuedPackets.put(proposalOfDeath); + } catch (InterruptedException e) { + LOG.warn("Ignoring unexpected exception", e); + } + try { + if (sock != null && !sock.isClosed()) { + sock.close(); + } + } catch (IOException e) { + LOG.warn("Ignoring unexpected exception during socket close", e); + } + this.interrupt(); + leader.removeLearnerHandler(this); + } + + public long tickOfNextAckDeadline() { + return tickOfNextAckDeadline; + } + + /** + * ping calls from the leader to the peers + */ + public void ping() { + // If learner hasn't sync properly yet, don't send ping packet + // otherwise, the learner will crash + if (!sendingThreadStarted) { + return; + } + long id; + if (syncLimitCheck.check(System.nanoTime())) { + synchronized (leader) { + id = leader.lastProposed; + } + QuorumPacket ping = new QuorumPacket(Leader.PING, id, null, null); + queuePacket(ping); + } else { + LOG.warn("Closing connection to peer due to transaction timeout."); + shutdown(); + } + } + + /** + * Queue leader packet of a given type + * @param type + * @param zxid + */ + private void queueOpPacket(int type, long zxid) { + QuorumPacket packet = new QuorumPacket(type, zxid, null, null); + queuePacket(packet); + } + + void queuePacket(QuorumPacket p) { + queuedPackets.add(p); + } + + public boolean synced() { + return isAlive() + && leader.self.tick.get() <= tickOfNextAckDeadline; + } + + /** + * For testing, return packet queue + * @return + */ + public Queue getQueuedPackets() { + return queuedPackets; + } + + /** + * For testing, we need to reset this value + */ + public void setFirstPacket(boolean value) { + needOpPacket = value; + } + + /** + * This class controls the time that the Leader has been + * waiting for acknowledgement of a proposal from this Learner. + * If the time is above syncLimit, the connection will be closed. + * It keeps track of only one proposal at a time, when the ACK for + * that proposal arrives, it switches to the last proposal received + * or clears the value if there is no pending proposal. + */ + private class SyncLimitCheck { + private boolean started = false; + private long currentZxid = 0; + private long currentTime = 0; + private long nextZxid = 0; + private long nextTime = 0; + + public synchronized void start() { + started = true; + } + + public synchronized void updateProposal(long zxid, long time) { + if (!started) { + return; + } + if (currentTime == 0) { + currentTime = time; + currentZxid = zxid; + } else { + nextTime = time; + nextZxid = zxid; + } + } + + public synchronized void updateAck(long zxid) { + if (currentZxid == zxid) { + currentTime = nextTime; + currentZxid = nextZxid; + nextTime = 0; + nextZxid = 0; + } else if (nextZxid == zxid) { + LOG.warn("ACK for " + zxid + " received before ACK for " + currentZxid + "!!!!"); + nextTime = 0; + nextZxid = 0; + } + } + + public synchronized boolean check(long time) { + if (currentTime == 0) { + return true; + } else { + long msDelay = (time - currentTime) / 1000000; + return (msDelay < (leader.self.tickTime * leader.self.syncLimit)); + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java new file mode 100644 index 00000000000..279d8c1f6e5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java @@ -0,0 +1,218 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.KeeperException.SessionMovedException; +import org.apache.zookeeper.KeeperException.UnknownSessionException; +import org.apache.zookeeper.server.SessionTrackerImpl; +import org.apache.zookeeper.server.ZooKeeperServerListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + +/** + * The learner session tracker is used by learners (followers and observers) to + * track zookeeper sessions which may or may not be echoed to the leader. When + * a new session is created it is saved locally in a wrapped + * LocalSessionTracker. It can subsequently be upgraded to a global session + * as required. If an upgrade is requested the session is removed from local + * collections while keeping the same session ID. It is up to the caller to + * queue a session creation request for the leader. + * A secondary function of the learner session tracker is to remember sessions + * which have been touched in this service. This information is passed along + * to the leader with a ping. + */ +public class LearnerSessionTracker extends UpgradeableSessionTracker { + private static final Logger LOG = LoggerFactory.getLogger(LearnerSessionTracker.class); + + private final SessionExpirer expirer; + // Touch table for the global sessions + private final AtomicReference> touchTable = + new AtomicReference>(); + private final long serverId; + private final AtomicLong nextSessionId = new AtomicLong(); + + private final boolean localSessionsEnabled; + private final ConcurrentMap globalSessionsWithTimeouts; + + public LearnerSessionTracker(SessionExpirer expirer, + ConcurrentMap sessionsWithTimeouts, + int tickTime, long id, boolean localSessionsEnabled, + ZooKeeperServerListener listener) { + this.expirer = expirer; + this.touchTable.set(new ConcurrentHashMap()); + this.globalSessionsWithTimeouts = sessionsWithTimeouts; + this.serverId = id; + nextSessionId.set(SessionTrackerImpl.initializeNextSession(serverId)); + + this.localSessionsEnabled = localSessionsEnabled; + if (this.localSessionsEnabled) { + createLocalSessionTracker(expirer, tickTime, id, listener); + } + } + + public void removeSession(long sessionId) { + if (localSessionTracker != null) { + localSessionTracker.removeSession(sessionId); + } + globalSessionsWithTimeouts.remove(sessionId); + touchTable.get().remove(sessionId); + } + + public void start() { + if (localSessionTracker != null) { + localSessionTracker.start(); + } + } + + public void shutdown() { + if (localSessionTracker != null) { + localSessionTracker.shutdown(); + } + } + + public boolean isGlobalSession(long sessionId) { + return globalSessionsWithTimeouts.containsKey(sessionId); + } + + public boolean addGlobalSession(long sessionId, int sessionTimeout) { + boolean added = + globalSessionsWithTimeouts.put(sessionId, sessionTimeout) == null; + if (localSessionsEnabled && added) { + // Only do extra logging so we know what kind of session this is + // if we're supporting both kinds of sessions + LOG.info("Adding global session 0x" + Long.toHexString(sessionId)); + } + touchTable.get().put(sessionId, sessionTimeout); + return added; + } + + public boolean addSession(long sessionId, int sessionTimeout) { + boolean added; + if (localSessionsEnabled && !isGlobalSession(sessionId)) { + added = localSessionTracker.addSession(sessionId, sessionTimeout); + // Check for race condition with session upgrading + if (isGlobalSession(sessionId)) { + added = false; + localSessionTracker.removeSession(sessionId); + } else if (added) { + LOG.info("Adding local session 0x" + + Long.toHexString(sessionId)); + } + } else { + added = addGlobalSession(sessionId, sessionTimeout); + } + return added; + } + + public boolean touchSession(long sessionId, int sessionTimeout) { + if (localSessionsEnabled) { + if (localSessionTracker.touchSession(sessionId, sessionTimeout)) { + return true; + } + if (!isGlobalSession(sessionId)) { + return false; + } + } + touchTable.get().put(sessionId, sessionTimeout); + return true; + } + + public Map snapshot() { + return touchTable.getAndSet(new ConcurrentHashMap()); + } + + public long createSession(int sessionTimeout) { + if (localSessionsEnabled) { + return localSessionTracker.createSession(sessionTimeout); + } + return nextSessionId.getAndIncrement(); + } + + public void checkSession(long sessionId, Object owner) + throws SessionExpiredException, SessionMovedException { + if (localSessionTracker != null) { + try { + localSessionTracker.checkSession(sessionId, owner); + return; + } catch (UnknownSessionException e) { + // Check whether it's a global session. We can ignore those + // because they are handled at the leader, but if not, rethrow. + // We check local session status first to avoid race condition + // with session upgrading. + if (!isGlobalSession(sessionId)) { + throw new SessionExpiredException(); + } + } + } + } + + public void setOwner(long sessionId, Object owner) + throws SessionExpiredException { + if (localSessionTracker != null) { + try { + localSessionTracker.setOwner(sessionId, owner); + return; + } catch (SessionExpiredException e) { + // Check whether it's a global session. We can ignore those + // because they are handled at the leader, but if not, rethrow. + // We check local session status first to avoid race condition + // with session upgrading. + if (!isGlobalSession(sessionId)) { + throw e; + } + } + } + } + + public void dumpSessions(PrintWriter pwriter) { + if (localSessionTracker != null) { + pwriter.print("Local "); + localSessionTracker.dumpSessions(pwriter); + } + pwriter.print("Global Sessions("); + pwriter.print(globalSessionsWithTimeouts.size()); + pwriter.println("):"); + SortedSet sessionIds = new TreeSet( + globalSessionsWithTimeouts.keySet()); + for (long sessionId : sessionIds) { + pwriter.print("0x"); + pwriter.print(Long.toHexString(sessionId)); + pwriter.print("\t"); + pwriter.print(globalSessionsWithTimeouts.get(sessionId)); + pwriter.println("ms"); + } + } + + public void setSessionClosing(long sessionId) { + // Global sessions handled on the leader; this call is a no-op if + // not tracked as a local session so safe to call in both cases. + if (localSessionTracker != null) { + localSessionTracker.setSessionClosing(sessionId); + } + } + + @Override + public Map> getSessionExpiryMap() { + return new HashMap>(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LearnerSnapshot.java b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSnapshot.java new file mode 100644 index 00000000000..31647538130 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSnapshot.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +public class LearnerSnapshot { + private final LearnerSnapshotThrottler throttler; + private final int concurrentSnapshotNumber; + private final boolean essential; + + LearnerSnapshot(LearnerSnapshotThrottler throttler, + int concurrentSnapshotNumber, boolean essential) { + this.throttler = throttler; + this.concurrentSnapshotNumber = concurrentSnapshotNumber; + this.essential = essential; + } + + public void close() { + throttler.endSnapshot(); + } + + public int getConcurrentSnapshotNumber() { + return concurrentSnapshotNumber; + } + + public boolean isEssential() { + return essential; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LearnerSnapshotThrottler.java b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSnapshotThrottler.java new file mode 100644 index 00000000000..ebcfe39509b --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSnapshotThrottler.java @@ -0,0 +1,128 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.common.Time; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility class to limit the number of concurrent snapshots from a leader to + * observers and followers. {@link LearnerHandler} objects should call + * {@link #beginSnapshot(boolean)} before sending a snapshot and + * {@link #endSnapshot()} after finishing, successfully or not. + * + */ +public class LearnerSnapshotThrottler { + private static final Logger LOG = + LoggerFactory.getLogger(LearnerSnapshotThrottler.class); + + private final Object snapCountSyncObject = new Object(); + private final int maxConcurrentSnapshots; + private final long timeoutMillis; + private int snapsInProgress; + + /** + * Constructs a new instance limiting the concurrent number of snapshots to + * maxConcurrentSnapshots. + * @param maxConcurrentSnapshots maximum concurrent number of snapshots + * @param timeoutMillis milliseconds to attempt to wait when attempting to + * begin a snapshot that would otherwise be throttled; + * a value of zero means no waiting will be attempted + * @throws java.lang.IllegalArgumentException when timeoutMillis + * is negative or + * maxConcurrentSnaphots + * is less than 1 + */ + public LearnerSnapshotThrottler(int maxConcurrentSnapshots, + long timeoutMillis) { + if (timeoutMillis < 0) { + String errorMsg = "timeout cannot be negative, was " + timeoutMillis; + throw new IllegalArgumentException(errorMsg); + } + if (maxConcurrentSnapshots <= 0) { + String errorMsg = "maxConcurrentSnapshots must be positive, was " + + maxConcurrentSnapshots; + throw new IllegalArgumentException(errorMsg); + } + + this.maxConcurrentSnapshots = maxConcurrentSnapshots; + this.timeoutMillis = timeoutMillis; + + synchronized (snapCountSyncObject) { + snapsInProgress = 0; + } + } + + public LearnerSnapshotThrottler(int maxConcurrentSnapshots) { + this(maxConcurrentSnapshots, 0); + } + + /** + * Indicates that a new snapshot is about to be sent. + * + * @param essential if true, do not throw an exception even + * if throttling limit is reached + * @throws SnapshotThrottleException if throttling limit has been exceeded + * and essential == false, + * even after waiting for the timeout + * period, if any + * @throws InterruptedException if thread is interrupted while trying + * to start a snapshot; cannot happen if + * timeout is zero + */ + public LearnerSnapshot beginSnapshot(boolean essential) + throws SnapshotThrottleException, InterruptedException { + int snapshotNumber; + + synchronized (snapCountSyncObject) { + if (!essential + && timeoutMillis > 0 + && snapsInProgress >= maxConcurrentSnapshots) { + long timestamp = Time.currentElapsedTime(); + do { + snapCountSyncObject.wait(timeoutMillis); + } while (snapsInProgress >= maxConcurrentSnapshots + && timestamp + timeoutMillis < Time.currentElapsedTime()); + } + + if (essential || snapsInProgress < maxConcurrentSnapshots) { + snapsInProgress++; + snapshotNumber = snapsInProgress; + } else { + throw new SnapshotThrottleException(snapsInProgress + 1, + maxConcurrentSnapshots); + } + } + + return new LearnerSnapshot(this, snapshotNumber, essential); + } + + /** + * Indicates that a snapshot has been completed. + */ + public void endSnapshot() { + int newCount; + synchronized (snapCountSyncObject) { + snapsInProgress--; + newCount = snapsInProgress; + snapCountSyncObject.notify(); + } + + if (newCount < 0) { + String errorMsg = + "endSnapshot() called incorrectly; current snapshot count is " + + newCount; + LOG.error(errorMsg); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LearnerSyncRequest.java b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSyncRequest.java new file mode 100644 index 00000000000..88c7d3fa09a --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LearnerSyncRequest.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.server.Request; + +import java.nio.ByteBuffer; +import java.util.List; + +public class LearnerSyncRequest extends Request { + LearnerHandler fh; + + public LearnerSyncRequest(LearnerHandler fh, long sessionId, int xid, int type, + ByteBuffer bb, List authInfo) { + super(null, sessionId, xid, type, bb, authInfo); + this.fh = fh; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java new file mode 100644 index 00000000000..c700f8b2dcb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java @@ -0,0 +1,167 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.server.DataTreeBean; +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServerBean; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; + +import java.io.IOException; +import java.util.Collections; +import java.util.Map; + +/** + * Parent class for all ZooKeeperServers for Learners + */ +public abstract class LearnerZooKeeperServer extends QuorumZooKeeperServer { + + /* + * Request processors + */ + protected CommitProcessor commitProcessor; + protected SyncRequestProcessor syncProcessor; + + public LearnerZooKeeperServer(FileTxnSnapLog logFactory, int tickTime, + int minSessionTimeout, int maxSessionTimeout, + ZKDatabase zkDb, QuorumPeer self) + throws IOException { + super(logFactory, tickTime, minSessionTimeout, maxSessionTimeout, zkDb, self); + } + + /** + * Abstract method to return the learner associated with this server. + * Since the Learner may change under our feet (when QuorumPeer reassigns + * it) we can't simply take a reference here. Instead, we need the + * subclasses to implement this. + */ + abstract public Learner getLearner(); + + /** + * Returns the current state of the session tracker. This is only currently + * used by a Learner to build a ping response packet. + * + */ + protected Map getTouchSnapshot() { + if (sessionTracker != null) { + return ((LearnerSessionTracker) sessionTracker).snapshot(); + } + Map map = Collections.emptyMap(); + return map; + } + + /** + * Returns the id of the associated QuorumPeer, which will do for a unique + * id of this server. + */ + @Override + public long getServerId() { + return self.getId(); + } + + @Override + public void createSessionTracker() { + sessionTracker = new LearnerSessionTracker(this, getZKDatabase().getSessionWithTimeOuts(), this.tickTime, self.getId(), self.areLocalSessionsEnabled(), getZooKeeperServerListener()); + } + + @Override + protected void revalidateSession(ServerCnxn cnxn, long sessionId, + int sessionTimeout) throws IOException { + if (upgradeableSessionTracker.isLocalSession(sessionId)) { + super.revalidateSession(cnxn, sessionId, sessionTimeout); + } else { + getLearner().validateSession(cnxn, sessionId, sessionTimeout); + } + } + + @Override + protected void registerJMX() { + // register with JMX + try { + jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); + MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxDataTreeBean = null; + } + } + + public void registerJMX(ZooKeeperServerBean serverBean, + LocalPeerBean localPeerBean) { + // register with JMX + if (self.jmxLeaderElectionBean != null) { + try { + MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + } + self.jmxLeaderElectionBean = null; + } + + try { + jmxServerBean = serverBean; + MBeanRegistry.getInstance().register(serverBean, localPeerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxServerBean = null; + } + } + + @Override + protected void unregisterJMX() { + // unregister from JMX + try { + if (jmxDataTreeBean != null) { + MBeanRegistry.getInstance().unregister(jmxDataTreeBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + jmxDataTreeBean = null; + } + + protected void unregisterJMX(Learner peer) { + // unregister from JMX + try { + if (jmxServerBean != null) { + MBeanRegistry.getInstance().unregister(jmxServerBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + jmxServerBean = null; + } + + @Override + public synchronized void shutdown() { + if (!isRunning()) { + LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); + return; + } + LOG.info("Shutting down"); + try { + super.shutdown(); + } catch (Exception e) { + LOG.warn("Ignoring unexpected exception during shutdown", e); + } + try { + if (syncProcessor != null) { + syncProcessor.shutdown(); + } + } catch (Exception e) { + LOG.warn("Ignoring unexpected exception in syncprocessor shutdown", + e); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java new file mode 100644 index 00000000000..d733ed8ef8d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + + +/** + * Implementation of the local peer MBean interface. + */ +public class LocalPeerBean extends ServerBean implements LocalPeerMXBean { + private final QuorumPeer peer; + + public LocalPeerBean(QuorumPeer peer) { + this.peer = peer; + } + + public String getName() { + return "replica." + peer.getId(); + } + + public boolean isHidden() { + return false; + } + + public int getTickTime() { + return peer.getTickTime(); + } + + public int getMaxClientCnxnsPerHost() { + return peer.getMaxClientCnxnsPerHost(); + } + + public int getMinSessionTimeout() { + return peer.getMinSessionTimeout(); + } + + public int getMaxSessionTimeout() { + return peer.getMaxSessionTimeout(); + } + + public int getInitLimit() { + return peer.getInitLimit(); + } + + public int getSyncLimit() { + return peer.getSyncLimit(); + } + + public int getTick() { + return peer.getTick(); + } + + public String getState() { + return peer.getServerState(); + } + + public String getQuorumAddress() { + return peer.getQuorumAddress().toString(); + } + + public int getElectionType() { + return peer.getElectionType(); + } + + public String getElectionAddress() { + return peer.getElectionAddress().getHostString() + ":" + + peer.getElectionAddress().getPort(); + } + + public String getClientAddress() { + if (null != peer.cnxnFactory) { + return String.format("%s:%d", peer.cnxnFactory.getLocalAddress() + .getHostString(), peer.getClientPort()); + } else { + return ""; + } + } + + public String getLearnerType() { + return peer.getLearnerType().toString(); + } + + public long getConfigVersion() { + return peer.getQuorumVerifier().getVersion(); + } + + @Override + public String getQuorumSystemInfo() { + return peer.getQuorumVerifier().toString(); + } + + @Override + public boolean isPartOfEnsemble() { + return peer.getView().containsKey(peer.getId()); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java new file mode 100644 index 00000000000..0b1b8d8ccf9 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + + +/** + * A local zookeeper server MBean interface. Unlike the remote peer, the local + * peer provides complete state/statistics at runtime and can be managed (just + * like a standalone zookeeper server). + */ +public interface LocalPeerMXBean extends ServerMXBean { + + /** + * @return the number of milliseconds of each tick + */ + public int getTickTime(); + + /** Current maxClientCnxns allowed from a particular host */ + public int getMaxClientCnxnsPerHost(); + + /** + * @return the minimum number of milliseconds allowed for a session timeout + */ + public int getMinSessionTimeout(); + + /** + * @return the maximum number of milliseconds allowed for a session timeout + */ + public int getMaxSessionTimeout(); + + /** + * @return the number of ticks that the initial sync phase can take + */ + public int getInitLimit(); + + /** + * @return the number of ticks that can pass between sending a request + * and getting a acknowledgment + */ + public int getSyncLimit(); + + /** + * @return the current tick + */ + public int getTick(); + + /** + * @return the current server state + */ + public String getState(); + + /** + * @return the quorum address + */ + public String getQuorumAddress(); + + /** + * @return the election type + */ + public int getElectionType(); + + /** + * @return the election address + */ + public String getElectionAddress(); + + /** + * @return the client address + */ + public String getClientAddress(); + + /** + * @return the learner type + */ + public String getLearnerType(); + + /** + * @return the config version + */ + public long getConfigVersion(); + + /** + * @return the quorum system information + */ + public String getQuorumSystemInfo(); + + /** + * @return true if quorum peer is part of the ensemble, false otherwise + */ + public boolean isPartOfEnsemble(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LocalSessionTracker.java b/src/java/main/org/apache/zookeeper/server/quorum/LocalSessionTracker.java new file mode 100644 index 00000000000..3f7b6bc25bb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/LocalSessionTracker.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.SessionTrackerImpl; +import org.apache.zookeeper.server.ZooKeeperServerListener; + +import java.util.concurrent.ConcurrentMap; + +/** + * Local session tracker. + */ +public class LocalSessionTracker extends SessionTrackerImpl { + public LocalSessionTracker(SessionExpirer expirer, + ConcurrentMap sessionsWithTimeouts, + int tickTime, long id, ZooKeeperServerListener listener) { + super(expirer, sessionsWithTimeouts, tickTime, id, listener); + } + + public boolean isLocalSession(long sessionId) { + return isTrackingSession(sessionId); + } + + public boolean isGlobalSession(long sessionId) { + return false; + } + + public boolean addGlobalSession(long sessionId, int sessionTimeout) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Observer.java b/src/java/main/org/apache/zookeeper/server/quorum/Observer.java new file mode 100644 index 00000000000..4cafadd989c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/Observer.java @@ -0,0 +1,159 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.Record; +import org.apache.zookeeper.server.ObserverBean; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.TxnHeader; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; + +/** + * Observers are peers that do not take part in the atomic broadcast protocol. + * Instead, they are informed of successful proposals by the Leader. Observers + * therefore naturally act as a relay point for publishing the proposal stream + * and can relieve Followers of some of the connection load. Observers may + * submit proposals, but do not vote in their acceptance. + * + * See ZOOKEEPER-368 for a discussion of this feature. + */ +public class Observer extends Learner { + + Observer(QuorumPeer self, ObserverZooKeeperServer observerZooKeeperServer) { + this.self = self; + this.zk = observerZooKeeperServer; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Observer ").append(sock); + sb.append(" pendingRevalidationCount:") + .append(pendingRevalidations.size()); + return sb.toString(); + } + + /** + * the main method called by the observer to observe the leader + * @throws Exception + */ + void observeLeader() throws Exception { + zk.registerJMX(new ObserverBean(this, zk), self.jmxLocalPeerBean); + + try { + InetSocketAddress addr = findLeader(); + LOG.info("Observing " + addr); + try { + connectToLeader(addr); + long newLeaderZxid = registerWithLeader(Leader.OBSERVERINFO); + if (self.isReconfigStateChange()) + throw new Exception("learned about role change"); + + syncWithLeader(newLeaderZxid); + QuorumPacket qp = new QuorumPacket(); + while (self.isRunning()) { + readPacket(qp); + processPacket(qp); + } + } catch (Exception e) { + LOG.warn("Exception when observing the leader", e); + try { + sock.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + + // clear pending revalidations + pendingRevalidations.clear(); + } + } finally { + zk.unregisterJMX(this); + } + } + + /** + * Controls the response of an observer to the receipt of a quorumpacket + * @param qp + * @throws Exception + */ + protected void processPacket(QuorumPacket qp) throws Exception { + switch (qp.getType()) { + case Leader.PING: + ping(qp); + break; + case Leader.PROPOSAL: + LOG.warn("Ignoring proposal"); + break; + case Leader.COMMIT: + LOG.warn("Ignoring commit"); + break; + case Leader.UPTODATE: + LOG.error("Received an UPTODATE message after Observer started"); + break; + case Leader.REVALIDATE: + revalidate(qp); + break; + case Leader.SYNC: + ((ObserverZooKeeperServer) zk).sync(); + break; + case Leader.INFORM: + TxnHeader hdr = new TxnHeader(); + Record txn = SerializeUtils.deserializeTxn(qp.getData(), hdr); + Request request = new Request(hdr.getClientId(), hdr.getCxid(), hdr.getType(), hdr, txn, 0); + ObserverZooKeeperServer obs = (ObserverZooKeeperServer) zk; + obs.commitRequest(request); + break; + case Leader.INFORMANDACTIVATE: + hdr = new TxnHeader(); + + // get new designated leader from (current) leader's message + ByteBuffer buffer = ByteBuffer.wrap(qp.getData()); + long suggestedLeaderId = buffer.getLong(); + + byte[] remainingdata = new byte[buffer.remaining()]; + buffer.get(remainingdata); + txn = SerializeUtils.deserializeTxn(remainingdata, hdr); + QuorumVerifier qv = self.configFromString(new String(((SetDataTxn) txn).getData())); + + request = new Request(hdr.getClientId(), hdr.getCxid(), hdr.getType(), hdr, txn, 0); + obs = (ObserverZooKeeperServer) zk; + + boolean majorChange = + self.processReconfig(qv, suggestedLeaderId, qp.getZxid(), true); + + obs.commitRequest(request); + + if (majorChange) { + throw new Exception("changes proposed in reconfig"); + } + break; + default: + LOG.warn("Unknown packet type: {}", LearnerHandler.packetToString(qp)); + break; + } + } + + /** + * Shutdown the Observer. + */ + public void shutdown() { + LOG.info("shutdown called", new Exception("shutdown Observer")); + super.shutdown(); + } +} + diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ObserverMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/ObserverMXBean.java new file mode 100644 index 00000000000..e7d70c4de59 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ObserverMXBean.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ZooKeeperServerMXBean; + +/** + * Observer MX Bean interface, implemented by ObserverBean + * + */ +public interface ObserverMXBean extends ZooKeeperServerMXBean { + /** + * @return count of pending revalidations + */ + public int getPendingRevalidationCount(); + + /** + * @return socket address + */ + public String getQuorumAddress(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java new file mode 100644 index 00000000000..c22741f3d33 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java @@ -0,0 +1,149 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.ZooKeeperCriticalThread; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.txn.ErrorTxn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * This RequestProcessor forwards any requests that modify the state of the + * system to the Leader. + */ +public class ObserverRequestProcessor extends ZooKeeperCriticalThread implements + RequestProcessor { + private static final Logger LOG = LoggerFactory.getLogger(ObserverRequestProcessor.class); + + ObserverZooKeeperServer zks; + + RequestProcessor nextProcessor; + + // We keep a queue of requests. As requests get submitted they are + // stored here. The queue is drained in the run() method. + LinkedBlockingQueue queuedRequests = new LinkedBlockingQueue(); + + boolean finished = false; + + /** + * Constructor - takes an ObserverZooKeeperServer to associate with + * and the next processor to pass requests to after we're finished. + * @param zks + * @param nextProcessor + */ + public ObserverRequestProcessor(ObserverZooKeeperServer zks, + RequestProcessor nextProcessor) { + super("ObserverRequestProcessor:" + zks.getServerId(), zks + .getZooKeeperServerListener()); + this.zks = zks; + this.nextProcessor = nextProcessor; + } + + @Override + public void run() { + try { + while (!finished) { + Request request = queuedRequests.take(); + if (LOG.isTraceEnabled()) { + ZooTrace.logRequest(LOG, ZooTrace.CLIENT_REQUEST_TRACE_MASK, + 'F', request, ""); + } + if (request == Request.requestOfDeath) { + break; + } + // We want to queue the request to be processed before we submit + // the request to the leader so that we are ready to receive + // the response + nextProcessor.processRequest(request); + + // We now ship the request to the leader. As with all + // other quorum operations, sync also follows this code + // path, but different from others, we need to keep track + // of the sync operations this Observer has pending, so we + // add it to pendingSyncs. + switch (request.type) { + case OpCode.sync: + zks.pendingSyncs.add(request); + zks.getObserver().request(request); + break; + case OpCode.create: + case OpCode.create2: + case OpCode.createContainer: + case OpCode.delete: + case OpCode.deleteContainer: + case OpCode.setData: + case OpCode.reconfig: + case OpCode.setACL: + case OpCode.multi: + case OpCode.check: + zks.getObserver().request(request); + break; + case OpCode.createSession: + case OpCode.closeSession: + // Don't forward local sessions to the leader. + if (!request.isLocalSession()) { + zks.getObserver().request(request); + } + break; + } + } + } catch (Exception e) { + handleException(this.getName(), e); + } + LOG.info("ObserverRequestProcessor exited loop!"); + } + + /** + * Simply queue the request, which will be processed in FIFO order. + */ + public void processRequest(Request request) { + if (!finished) { + Request upgradeRequest = null; + try { + upgradeRequest = zks.checkUpgradeSession(request); + } catch (KeeperException ke) { + if (request.getHdr() != null) { + request.getHdr().setType(OpCode.error); + request.setTxn(new ErrorTxn(ke.code().intValue())); + } + request.setException(ke); + LOG.info("Error creating upgrade request", ke); + } catch (IOException ie) { + LOG.error("Unexpected error in upgrade", ie); + } + if (upgradeRequest != null) { + queuedRequests.add(upgradeRequest); + } + queuedRequests.add(request); + } + } + + /** + * Shutdown the processor. + */ + public void shutdown() { + LOG.info("Shutting down"); + finished = true; + queuedRequests.clear(); + queuedRequests.add(Request.requestOfDeath); + nextProcessor.shutdown(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java new file mode 100644 index 00000000000..11b8eb81f69 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ObserverZooKeeperServer.java @@ -0,0 +1,137 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.FinalRequestProcessor; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * A ZooKeeperServer for the Observer node type. Not much is different, but + * we anticipate specializing the request processors in the future. + * + */ +public class ObserverZooKeeperServer extends LearnerZooKeeperServer { + private static final Logger LOG = + LoggerFactory.getLogger(ObserverZooKeeperServer.class); + /* + * Pending sync requests + */ + ConcurrentLinkedQueue pendingSyncs = + new ConcurrentLinkedQueue(); + /** + * Enable since request processor for writing txnlog to disk and + * take periodic snapshot. Default is ON. + */ + + private boolean syncRequestProcessorEnabled = this.self.getSyncEnabled(); + + ObserverZooKeeperServer(FileTxnSnapLog logFactory, QuorumPeer self, ZKDatabase zkDb) throws IOException { + super(logFactory, self.tickTime, self.minSessionTimeout, self.maxSessionTimeout, zkDb, self); + LOG.info("syncEnabled =" + syncRequestProcessorEnabled); + } + + public Observer getObserver() { + return self.observer; + } + + @Override + public Learner getLearner() { + return self.observer; + } + + /** + * Unlike a Follower, which sees a full request only during the PROPOSAL + * phase, Observers get all the data required with the INFORM packet. + * This method commits a request that has been unpacked by from an INFORM + * received from the Leader. + * + * @param request + */ + public void commitRequest(Request request) { + if (syncRequestProcessorEnabled) { + // Write to txnlog and take periodic snapshot + syncProcessor.processRequest(request); + } + commitProcessor.commit(request); + } + + /** + * Set up the request processors for an Observer: + * firstProcesor->commitProcessor->finalProcessor + */ + @Override + protected void setupRequestProcessors() { + // We might consider changing the processor behaviour of + // Observers to, for example, remove the disk sync requirements. + // Currently, they behave almost exactly the same as followers. + RequestProcessor finalProcessor = new FinalRequestProcessor(this); + commitProcessor = new CommitProcessor(finalProcessor, + Long.toString(getServerId()), true, + getZooKeeperServerListener()); + commitProcessor.start(); + firstProcessor = new ObserverRequestProcessor(this, commitProcessor); + ((ObserverRequestProcessor) firstProcessor).start(); + + /* + * Observer should write to disk, so that the it won't request + * too old txn from the leader which may lead to getting an entire + * snapshot. + * + * However, this may degrade performance as it has to write to disk + * and do periodic snapshot which may double the memory requirements + */ + if (syncRequestProcessorEnabled) { + syncProcessor = new SyncRequestProcessor(this, null); + syncProcessor.start(); + } + } + + /* + * Process a sync request + */ + synchronized public void sync() { + if (pendingSyncs.size() == 0) { + LOG.warn("Not expecting a sync."); + return; + } + + Request r = pendingSyncs.remove(); + commitProcessor.commit(r); + } + + @Override + public String getState() { + return "observer"; + } + + ; + + @Override + public synchronized void shutdown() { + if (!isRunning()) { + LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); + return; + } + super.shutdown(); + if (syncRequestProcessorEnabled && syncProcessor != null) { + syncProcessor.shutdown(); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ProposalRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/ProposalRequestProcessor.java new file mode 100644 index 00000000000..080e3e7ccd9 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ProposalRequestProcessor.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.quorum.Leader.XidRolloverException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This RequestProcessor simply forwards requests to an AckRequestProcessor and + * SyncRequestProcessor. + */ +public class ProposalRequestProcessor implements RequestProcessor { + private static final Logger LOG = + LoggerFactory.getLogger(ProposalRequestProcessor.class); + + LeaderZooKeeperServer zks; + + RequestProcessor nextProcessor; + + SyncRequestProcessor syncProcessor; + + public ProposalRequestProcessor(LeaderZooKeeperServer zks, + RequestProcessor nextProcessor) { + this.zks = zks; + this.nextProcessor = nextProcessor; + AckRequestProcessor ackProcessor = new AckRequestProcessor(zks.getLeader()); + syncProcessor = new SyncRequestProcessor(zks, ackProcessor); + } + + /** + * initialize this processor + */ + public void initialize() { + syncProcessor.start(); + } + + public void processRequest(Request request) throws RequestProcessorException { + // LOG.warn("Ack>>> cxid = " + request.cxid + " type = " + + // request.type + " id = " + request.sessionId); + // request.addRQRec(">prop"); + + + /* In the following IF-THEN-ELSE block, we process syncs on the leader. + * If the sync is coming from a follower, then the follower + * handler adds it to syncHandler. Otherwise, if it is a client of + * the leader that issued the sync command, then syncHandler won't + * contain the handler. In this case, we add it to syncHandler, and + * call processRequest on the next processor. + */ + + if (request instanceof LearnerSyncRequest) { + zks.getLeader().processSync((LearnerSyncRequest) request); + } else { + //对于第一个写请求,这个时候会放在pending里,等待后续操作 + nextProcessor.processRequest(request); + if (request.getHdr() != null) { + // We need to sync and get consensus on any transactions + try { + zks.getLeader().propose(request); + } catch (XidRolloverException e) { + throw new RequestProcessorException(e.getMessage(), e); + } + syncProcessor.processRequest(request); + } + } + } + + public void shutdown() { + LOG.info("Shutting down"); + nextProcessor.shutdown(); + syncProcessor.shutdown(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumBean.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumBean.java new file mode 100644 index 00000000000..b23cf90ec6a --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumBean.java @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.ZKMBeanInfo; + +public class QuorumBean implements QuorumMXBean, ZKMBeanInfo { + private final QuorumPeer peer; + private final String name; + + public QuorumBean(QuorumPeer peer) { + this.peer = peer; + name = "ReplicatedServer_id" + peer.getId(); + } + + public String getName() { + return name; + } + + public boolean isHidden() { + return false; + } + + public int getQuorumSize() { + return peer.getQuorumSize(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java new file mode 100644 index 00000000000..440420ca5b9 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java @@ -0,0 +1,1018 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ZooKeeperThread; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.nio.channels.UnresolvedAddressException; +import java.util.Enumeration; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * This class implements a connection manager for leader election using TCP. It + * maintains one connection for every pair of servers. The tricky part is to + * guarantee that there is exactly one connection for every pair of servers that + * are operating correctly and that can communicate over the network. + * + * If two servers try to start a connection concurrently, then the connection + * manager uses a very simple tie-breaking mechanism to decide which connection + * to drop based on the IP addressed of the two parties. + * + * For every peer, the manager maintains a queue of messages to send. If the + * connection to any particular peer drops, then the sender thread puts the + * message back on the list. As this implementation currently uses a queue + * implementation to maintain messages to send to another peer, we add the + * message to the tail of the queue, thus changing the order of messages. + * Although this is not a problem for the leader election, it could be a problem + * when consolidating peer communication. This is to be verified, though. + * + */ + +public class QuorumCnxManager { + /* + * Protocol identifier used among peers + */ + public static final long PROTOCOL_VERSION = -65536L; + /* + * Max buffer size to be read from the network. + */ + static public final int maxBuffer = 2048; + /* + * Maximum capacity of thread queues + */ + static final int RECV_CAPACITY = 100; + // Initialized to 1 to prevent sending + // stale notifications to peers + static final int SEND_CAPACITY = 1; + /* + * Maximum number of attempts to connect to a peer + */ + static final int PACKETMAXSIZE = 1024 * 512; + + /* + * Negative counter for observer server ids. + */ + static final int MAX_CONNECTION_ATTEMPTS = 2; + private static final Logger LOG = LoggerFactory.getLogger(QuorumCnxManager.class); + /* + * Reception queue + */ + public final ArrayBlockingQueue recvQueue; + + /* + * Connection time out value in milliseconds + */ + /* + * Listener thread + */ + public final Listener listener; + /* + * Local IP address + */ + final QuorumPeer self; + + /* + * Mapping from Peer to Thread number + */ + final ConcurrentHashMap senderWorkerMap; + final ConcurrentHashMap> queueSendMap; + final ConcurrentHashMap lastMessageSent; + /* + * Object to synchronize access to recvQueue + */ + private final Object recvQLock = new Object(); + volatile boolean shutdown = false; + + /* + * Shutdown flag + */ + private long observerCounter = -1; + private int cnxTO = 5000; + /* + * Counter to count worker threads + */ + private AtomicInteger threadCnt = new AtomicInteger(0); + + public QuorumCnxManager(QuorumPeer self) { + this.recvQueue = new ArrayBlockingQueue(RECV_CAPACITY); + this.queueSendMap = new ConcurrentHashMap>(); + this.senderWorkerMap = new ConcurrentHashMap(); + this.lastMessageSent = new ConcurrentHashMap(); + + String cnxToValue = System.getProperty("zookeeper.cnxTimeout"); + if (cnxToValue != null) { + this.cnxTO = Integer.parseInt(cnxToValue); + } + + this.self = self; + + // Starts listener thread that waits for connection requests + listener = new Listener(); + listener.setName("QuorumPeerListener"); + } + + /** + * Invokes initiateConnection for testing purposes + * + * @param sid + */ + public void testInitiateConnection(long sid) throws Exception { + if (LOG.isDebugEnabled()) { + LOG.debug("Opening channel to server " + sid); + } + Socket sock = new Socket(); + setSockOpts(sock); + sock.connect(self.getVotingView().get(sid).electionAddr, cnxTO); + initiateConnection(sock, sid); + } + + /** + * If this server has initiated the connection, then it gives up on the + * connection if it loses challenge. Otherwise, it keeps the connection. + */ + public boolean initiateConnection(Socket sock, Long sid) { + try { + // Use BufferedOutputStream to reduce the number of IP packets. This is + // important for x-DC scenarios. + BufferedOutputStream buf = new BufferedOutputStream(sock.getOutputStream()); + DataOutputStream dout = new DataOutputStream(buf); + + // Sending id and challenge + + // represents protocol version (in other words - message type) + dout.writeLong(PROTOCOL_VERSION); + dout.writeLong(self.getId()); + String addr = self.getElectionAddress().getHostString() + ":" + self.getElectionAddress().getPort(); + byte[] addr_bytes = addr.getBytes(); + dout.writeInt(addr_bytes.length); + dout.write(addr_bytes); + dout.flush(); + } catch (IOException e) { + LOG.warn("Ignoring exception reading or writing challenge: ", e); + closeSocket(sock); + return false; + } + + // If lost the challenge, then drop the new connection + if (sid > self.getId()) { + LOG.info("Have smaller server identifier, so dropping the " + + "connection: (" + sid + ", " + self.getId() + ")"); + closeSocket(sock); + // Otherwise proceed with the connection + } else { + SendWorker sw = new SendWorker(sock, sid); + RecvWorker rw = new RecvWorker(sock, sid, sw); + sw.setRecv(rw); + + SendWorker vsw = senderWorkerMap.get(sid); + + if (vsw != null) + vsw.finish(); + + senderWorkerMap.put(sid, sw); + queueSendMap.putIfAbsent(sid, new ArrayBlockingQueue( + SEND_CAPACITY)); + + sw.start(); + rw.start(); + + return true; + + } + return false; + } + + /** + * If this server receives a connection request, then it gives up on the new + * connection if it wins. Notice that it checks whether it has a connection + * to this server already or not. If it does, then it sends the smallest + * possible long value to lose the challenge. + * + */ + public void receiveConnection(Socket sock) { + Long sid = null, protocolVersion = null; + InetSocketAddress electionAddr = null; + + try { + DataInputStream din = new DataInputStream(sock.getInputStream()); + + protocolVersion = din.readLong(); + if (protocolVersion >= 0) { // this is a server id and not a protocol version + sid = protocolVersion; + } else { + try { + InitialMessage init = InitialMessage.parse(protocolVersion, din); + sid = init.sid; + electionAddr = init.electionAddr; + } catch (InitialMessage.InitialMessageException ex) { + LOG.error(ex.toString()); + closeSocket(sock); + return; + } + } + + if (sid == QuorumPeer.OBSERVER_ID) { + /* + * Choose identifier at random. We need a value to identify + * the connection. + */ + + sid = observerCounter--; + LOG.info("Setting arbitrary identifier to observer: {}", sid); + } + } catch (IOException e) { + closeSocket(sock); + LOG.warn("Exception reading or writing challenge: {}", e.toString()); + return; + } + + //If wins the challenge, then close the new connection. + if (sid < self.getId()) { + /* + * This replica might still believe that the connection to sid is + * up, so we have to shut down the workers before trying to open a + * new connection. + */ + SendWorker sw = senderWorkerMap.get(sid); + if (sw != null) { + sw.finish(); + } + + /* + * Now we start a new connection + */ + LOG.debug("Create new connection to server: {}", sid); + closeSocket(sock); + + if (electionAddr != null) { + connectOne(sid, electionAddr); + } else { + connectOne(sid); + } + + } else { // Otherwise start worker threads to receive data. + SendWorker sw = new SendWorker(sock, sid); + RecvWorker rw = new RecvWorker(sock, sid, sw); + sw.setRecv(rw); + + SendWorker vsw = senderWorkerMap.get(sid); + + if (vsw != null) { + vsw.finish(); + } + + senderWorkerMap.put(sid, sw); + + queueSendMap.putIfAbsent(sid, + new ArrayBlockingQueue(SEND_CAPACITY)); + + sw.start(); + rw.start(); + } + } + + /** + * Processes invoke this message to queue a message to send. Currently, + * only leader election uses it. + */ + public void toSend(Long sid, ByteBuffer b) { + /* + * If sending message to myself, then simply enqueue it (loopback). + */ + if (self.getId() == sid) { + b.position(0); + addToRecvQueue(new Message(b.duplicate(), sid)); + /* + * Otherwise send to the corresponding thread to send. + */ + } else { + /* + * Start a new connection if doesn't have one already. + */ + ArrayBlockingQueue bq = new ArrayBlockingQueue( + SEND_CAPACITY); + ArrayBlockingQueue oldq = queueSendMap.putIfAbsent(sid, bq); + if (oldq != null) { + addToSendQueue(oldq, b); + } else { + addToSendQueue(bq, b); + } + connectOne(sid); + + } + } + + /** + * Try to establish a connection to server with id sid using its electionAddr. + * + * @param sid server id + * @return boolean success indication + */ + synchronized private boolean connectOne(long sid, InetSocketAddress electionAddr) { + if (senderWorkerMap.get(sid) != null) { + LOG.debug("There is a connection already for server " + sid); + return true; + } + try { + + if (LOG.isDebugEnabled()) { + LOG.debug("Opening channel to server " + sid); + } + Socket sock = new Socket(); + setSockOpts(sock); + sock.connect(electionAddr, cnxTO); + if (LOG.isDebugEnabled()) { + LOG.debug("Connected to server " + sid); + } + initiateConnection(sock, sid); + return true; + } catch (UnresolvedAddressException e) { + // Sun doesn't include the address that causes this + // exception to be thrown, also UAE cannot be wrapped cleanly + // so we log the exception in order to capture this critical + // detail. + LOG.warn("Cannot open channel to " + sid + + " at election address " + electionAddr, e); + throw e; + } catch (IOException e) { + LOG.warn("Cannot open channel to " + sid + + " at election address " + electionAddr, + e); + return false; + } + + } + + /** + * Try to establish a connection to server with id sid. + * + * @param sid server id + */ + + synchronized void connectOne(long sid) { + if (senderWorkerMap.get(sid) != null) { + LOG.debug("There is a connection already for server " + sid); + return; + } + synchronized (self) { + boolean knownId = false; + // Resolve hostname for the remote server before attempting to + // connect in case the underlying ip address has changed. + self.recreateSocketAddresses(sid); + if (self.getView().containsKey(sid)) { + knownId = true; + if (connectOne(sid, self.getView().get(sid).electionAddr)) + return; + } + if (self.getLastSeenQuorumVerifier() != null && self.getLastSeenQuorumVerifier().getAllMembers().containsKey(sid) + && (!knownId || (self.getLastSeenQuorumVerifier().getAllMembers().get(sid).electionAddr != + self.getView().get(sid).electionAddr))) { + knownId = true; + if (connectOne(sid, self.getLastSeenQuorumVerifier().getAllMembers().get(sid).electionAddr)) + return; + } + if (!knownId) { + LOG.warn("Invalid server id: " + sid); + return; + } + } + } + + /** + * Try to establish a connection with each server if one + * doesn't exist. + */ + + public void connectAll() { + long sid; + for (Enumeration en = queueSendMap.keys(); + en.hasMoreElements(); ) { + sid = en.nextElement(); + connectOne(sid); + } + } + + /** + * Check if all queues are empty, indicating that all messages have been delivered. + */ + boolean haveDelivered() { + for (ArrayBlockingQueue queue : queueSendMap.values()) { + LOG.debug("Queue size: " + queue.size()); + if (queue.size() == 0) { + return true; + } + } + + return false; + } + + /** + * Flag that it is time to wrap up all activities and interrupt the listener. + */ + public void halt() { + shutdown = true; + LOG.debug("Halting listener"); + listener.halt(); + + // Wait for the listener to terminate. + try { + listener.join(); + } catch (InterruptedException ex) { + LOG.warn("Got interrupted before joining the listener", ex); + } + softHalt(); + } + + /** + * A soft halt simply finishes workers. + */ + public void softHalt() { + for (SendWorker sw : senderWorkerMap.values()) { + LOG.debug("Halting sender: " + sw); + sw.finish(); + } + } + + /** + * Helper method to set socket options. + * + * @param sock + * Reference to socket + */ + private void setSockOpts(Socket sock) throws SocketException { + sock.setTcpNoDelay(true); + sock.setSoTimeout(self.tickTime * self.syncLimit); + } + + /** + * Helper method to close a socket. + * + * @param sock + * Reference to socket + */ + private void closeSocket(Socket sock) { + try { + sock.close(); + } catch (IOException ie) { + LOG.error("Exception while closing", ie); + } + } + + /** + * Return number of worker threads + */ + public long getThreadCount() { + return threadCnt.get(); + } + + /** + * Return reference to QuorumPeer + */ + public QuorumPeer getQuorumPeer() { + return self; + } + + /** + * Inserts an element in the specified queue. If the Queue is full, this + * method removes an element from the head of the Queue and then inserts + * the element at the tail. It can happen that the an element is removed + * by another thread in {@link SendWorker#processMessage() processMessage} + * method before this method attempts to remove an element from the queue. + * This will cause {@link ArrayBlockingQueue#remove() remove} to throw an + * exception, which is safe to ignore. + * + * Unlike {@link #addToRecvQueue(Message) addToRecvQueue} this method does + * not need to be synchronized since there is only one thread that inserts + * an element in the queue and another thread that reads from the queue. + * + * @param queue + * Reference to the Queue + * @param buffer + * Reference to the buffer to be inserted in the queue + */ + private void addToSendQueue(ArrayBlockingQueue queue, + ByteBuffer buffer) { + if (queue.remainingCapacity() == 0) { + try { + queue.remove(); + } catch (NoSuchElementException ne) { + // element could be removed by poll() + LOG.debug("Trying to remove from an empty " + + "Queue. Ignoring exception " + ne); + } + } + try { + queue.add(buffer); + } catch (IllegalStateException ie) { + // This should never happen + LOG.error("Unable to insert an element in the queue " + ie); + } + } + + /** + * Returns true if queue is empty. + * @param queue + * Reference to the queue + * @return + * true if the specified queue is empty + */ + private boolean isSendQueueEmpty(ArrayBlockingQueue queue) { + return queue.isEmpty(); + } + + /** + * Retrieves and removes buffer at the head of this queue, + * waiting up to the specified wait time if necessary for an element to + * become available. + * + * {@link ArrayBlockingQueue#poll(long, java.util.concurrent.TimeUnit)} + */ + private ByteBuffer pollSendQueue(ArrayBlockingQueue queue, + long timeout, TimeUnit unit) throws InterruptedException { + return queue.poll(timeout, unit); + } + + /** + * Inserts an element in the {@link #recvQueue}. If the Queue is full, this + * methods removes an element from the head of the Queue and then inserts + * the element at the tail of the queue. + * + * This method is synchronized to achieve fairness between two threads that + * are trying to insert an element in the queue. Each thread checks if the + * queue is full, then removes the element at the head of the queue, and + * then inserts an element at the tail. This three-step process is done to + * prevent a thread from blocking while inserting an element in the queue. + * If we do not synchronize the call to this method, then a thread can grab + * a slot in the queue created by the second thread. This can cause the call + * to insert by the second thread to fail. + * Note that synchronizing this method does not block another thread + * from polling the queue since that synchronization is provided by the + * queue itself. + * + * @param msg + * Reference to the message to be inserted in the queue + */ + public void addToRecvQueue(Message msg) { + synchronized (recvQLock) { + if (recvQueue.remainingCapacity() == 0) { + try { + recvQueue.remove(); + } catch (NoSuchElementException ne) { + // element could be removed by poll() + LOG.debug("Trying to remove from an empty " + + "recvQueue. Ignoring exception " + ne); + } + } + try { + recvQueue.add(msg); + } catch (IllegalStateException ie) { + // This should never happen + LOG.error("Unable to insert element in the recvQueue " + ie); + } + } + } + + /** + * Retrieves and removes a message at the head of this queue, + * waiting up to the specified wait time if necessary for an element to + * become available. + * + * {@link ArrayBlockingQueue#poll(long, java.util.concurrent.TimeUnit)} + */ + public Message pollRecvQueue(long timeout, TimeUnit unit) + throws InterruptedException { + return recvQueue.poll(timeout, unit); + } + + static public class Message { + ByteBuffer buffer; + long sid; + Message(ByteBuffer buffer, long sid) { + this.buffer = buffer; + this.sid = sid; + } + } + + /* + * This class parses the initial identification sent out by peers with their + * sid & hostname. + */ + static public class InitialMessage { + public Long sid; + public InetSocketAddress electionAddr; + + InitialMessage(Long sid, InetSocketAddress address) { + this.sid = sid; + this.electionAddr = address; + } + + static public InitialMessage parse(Long protocolVersion, DataInputStream din) + throws InitialMessageException, IOException { + Long sid; + + if (protocolVersion != PROTOCOL_VERSION) { + throw new InitialMessageException( + "Got unrecognized protocol version %s", protocolVersion); + } + + sid = din.readLong(); + + int remaining = din.readInt(); + if (remaining <= 0 || remaining > maxBuffer) { + throw new InitialMessageException( + "Unreasonable buffer length: %s", remaining); + } + + byte[] b = new byte[remaining]; + int num_read = din.read(b); + + if (num_read != remaining) { + throw new InitialMessageException( + "Read only %s bytes out of %s sent by server %s", + num_read, remaining, sid); + } + + // FIXME: IPv6 is not supported. Using something like Guava's HostAndPort + // parser would be good. + String addr = new String(b); + String[] host_port = addr.split(":"); + + if (host_port.length != 2) { + throw new InitialMessageException("Badly formed address: %s", addr); + } + + int port; + try { + port = Integer.parseInt(host_port[1]); + } catch (NumberFormatException e) { + throw new InitialMessageException("Bad port number: %s", host_port[1]); + } + + return new InitialMessage(sid, new InetSocketAddress(host_port[0], port)); + } + + @SuppressWarnings("serial") + public static class InitialMessageException extends Exception { + InitialMessageException(String message, Object... args) { + super(String.format(message, args)); + } + } + } + + /** + * Thread to listen on some port + */ + public class Listener extends ZooKeeperThread { + + volatile ServerSocket ss = null; + + public Listener() { + // During startup of thread, thread name will be overridden to + // specific election address + super("ListenerThread"); + } + + /** + * Sleeps on accept(). + */ + @Override + public void run() { + int numRetries = 0; + InetSocketAddress addr; + + while ((!shutdown) && (numRetries < 3)) { + try { + ss = new ServerSocket(); + ss.setReuseAddress(true); + if (self.getQuorumListenOnAllIPs()) { + int port = self.getElectionAddress().getPort(); + addr = new InetSocketAddress(port); + } else { + // Resolve hostname for this server in case the + // underlying ip address has changed. + self.recreateSocketAddresses(self.getId()); + addr = self.getElectionAddress(); + } + LOG.info("My election bind port: " + addr.toString()); + setName(addr.toString()); + ss.bind(addr); + while (!shutdown) { + Socket client = ss.accept(); + setSockOpts(client); + LOG.info("Received connection request " + + client.getRemoteSocketAddress()); + receiveConnection(client); + numRetries = 0; + } + } catch (IOException e) { + if (shutdown) { + break; + } + LOG.error("Exception while listening", e); + numRetries++; + try { + ss.close(); + Thread.sleep(1000); + } catch (IOException ie) { + LOG.error("Error closing server socket", ie); + } catch (InterruptedException ie) { + LOG.error("Interrupted while sleeping. " + + "Ignoring exception", ie); + } + } + } + LOG.info("Leaving listener"); + if (!shutdown) { + LOG.error("As I'm leaving the listener thread, " + + "I won't be able to participate in leader " + + "election any longer: " + + self.getElectionAddress()); + } else if (ss != null) { + // Clean up for shutdown. + try { + ss.close(); + } catch (IOException ie) { + // Don't log an error for shutdown. + LOG.debug("Error closing server socket", ie); + } + } + } + + /** + * Halts this listener thread. + */ + void halt() { + try { + LOG.debug("Trying to close listener: " + ss); + if (ss != null) { + LOG.debug("Closing listener: " + self.getId()); + ss.close(); + } + } catch (IOException e) { + LOG.warn("Exception when shutting down listener: " + e); + } + } + } + + /** + * Thread to send messages. Instance waits on a queue, and send a message as + * soon as there is one available. If connection breaks, then opens a new + * one. + */ + class SendWorker extends ZooKeeperThread { + Long sid; + Socket sock; + RecvWorker recvWorker; + volatile boolean running = true; + DataOutputStream dout; + + /** + * An instance of this thread receives messages to send + * through a queue and sends them to the server sid. + * + * @param sock + * Socket to remote peer + * @param sid + * Server identifier of remote peer + */ + SendWorker(Socket sock, Long sid) { + super("SendWorker:" + sid); + this.sid = sid; + this.sock = sock; + recvWorker = null; + try { + dout = new DataOutputStream(sock.getOutputStream()); + } catch (IOException e) { + LOG.error("Unable to access socket output stream", e); + closeSocket(sock); + running = false; + } + LOG.debug("Address of remote peer: " + this.sid); + } + + synchronized void setRecv(RecvWorker recvWorker) { + this.recvWorker = recvWorker; + } + + /** + * Returns RecvWorker that pairs up with this SendWorker. + * + * @return RecvWorker + */ + synchronized RecvWorker getRecvWorker() { + return recvWorker; + } + + synchronized boolean finish() { + if (LOG.isDebugEnabled()) { + LOG.debug("Calling finish for " + sid); + } + + if (!running) { + /* + * Avoids running finish() twice. + */ + return running; + } + + running = false; + closeSocket(sock); + // channel = null; + + this.interrupt(); + if (recvWorker != null) { + recvWorker.finish(); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Removing entry from senderWorkerMap sid=" + sid); + } + senderWorkerMap.remove(sid, this); + threadCnt.decrementAndGet(); + return running; + } + + synchronized void send(ByteBuffer b) throws IOException { + byte[] msgBytes = new byte[b.capacity()]; + try { + b.position(0); + b.get(msgBytes); + } catch (BufferUnderflowException be) { + LOG.error("BufferUnderflowException ", be); + return; + } + dout.writeInt(b.capacity()); + dout.write(b.array()); + dout.flush(); + } + + @Override + public void run() { + threadCnt.incrementAndGet(); + try { + /** + * If there is nothing in the queue to send, then we + * send the lastMessage to ensure that the last message + * was received by the peer. The message could be dropped + * in case self or the peer shutdown their connection + * (and exit the thread) prior to reading/processing + * the last message. Duplicate messages are handled correctly + * by the peer. + * + * If the send queue is non-empty, then we have a recent + * message than that stored in lastMessage. To avoid sending + * stale message, we should send the message in the send queue. + */ + ArrayBlockingQueue bq = queueSendMap.get(sid); + if (bq == null || isSendQueueEmpty(bq)) { + ByteBuffer b = lastMessageSent.get(sid); + if (b != null) { + LOG.debug("Attempting to send lastMessage to sid=" + sid); + send(b); + } + } + } catch (IOException e) { + LOG.error("Failed to send last message. Shutting down thread.", e); + this.finish(); + } + + try { + while (running && !shutdown && sock != null) { + + ByteBuffer b = null; + try { + ArrayBlockingQueue bq = queueSendMap + .get(sid); + if (bq != null) { + b = pollSendQueue(bq, 1000, TimeUnit.MILLISECONDS); + } else { + LOG.error("No queue of incoming messages for " + + "server " + sid); + break; + } + + if (b != null) { + lastMessageSent.put(sid, b); + send(b); + } + } catch (InterruptedException e) { + LOG.warn("Interrupted while waiting for message on queue", + e); + } + } + } catch (Exception e) { + LOG.warn("Exception when using channel: for id " + sid + " my id = " + + self.getId() + " error = " + e); + } + this.finish(); + LOG.warn("Send worker leaving thread " + " id " + sid + " my id = " + self.getId()); + } + } + + /** + * Thread to receive messages. Instance waits on a socket read. If the + * channel breaks, then removes itself from the pool of receivers. + */ + class RecvWorker extends ZooKeeperThread { + final SendWorker sw; + Long sid; + Socket sock; + volatile boolean running = true; + DataInputStream din; + + RecvWorker(Socket sock, Long sid, SendWorker sw) { + super("RecvWorker:" + sid); + this.sid = sid; + this.sock = sock; + this.sw = sw; + try { + din = new DataInputStream(sock.getInputStream()); + // OK to wait until socket disconnects while reading. + sock.setSoTimeout(0); + } catch (IOException e) { + LOG.error("Error while accessing socket for " + sid, e); + closeSocket(sock); + running = false; + } + } + + /** + * Shuts down this worker + * + * @return boolean Value of variable running + */ + synchronized boolean finish() { + if (!running) { + /* + * Avoids running finish() twice. + */ + return running; + } + running = false; + + this.interrupt(); + threadCnt.decrementAndGet(); + return running; + } + + @Override + public void run() { + threadCnt.incrementAndGet(); + try { + while (running && !shutdown && sock != null) { + /** + * Reads the first int to determine the length of the + * message + */ + int length = din.readInt(); + if (length <= 0 || length > PACKETMAXSIZE) { + throw new IOException( + "Received packet with invalid packet: " + + length); + } + /** + * Allocates a new ByteBuffer to receive the message + */ + byte[] msgArray = new byte[length]; + din.readFully(msgArray, 0, length); + ByteBuffer message = ByteBuffer.wrap(msgArray); + addToRecvQueue(new Message(message.duplicate(), sid)); + } + } catch (Exception e) { + LOG.warn("Connection broken for id " + sid + ", my id = " + + self.getId() + ", error = ", e); + } finally { + LOG.warn("Interrupting SendWorker"); + sw.finish(); + if (sock != null) { + closeSocket(sock); + } + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumMXBean.java new file mode 100644 index 00000000000..a3cc30c2e9c --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumMXBean.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +/** + * An MBean representing a zookeeper cluster nodes (aka quorum peers) + */ +public interface QuorumMXBean { + /** + * @return the name of the quorum + */ + public String getName(); + + /** + * @return configured number of peers in the quorum + */ + public int getQuorumSize(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java new file mode 100644 index 00000000000..30e9d5de9fe --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java @@ -0,0 +1,1799 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException.BadArgumentsException; +import org.apache.zookeeper.common.AtomicFileWritingIdiom; +import org.apache.zookeeper.common.AtomicFileWritingIdiom.WriterStatement; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.jmx.ZKMBeanInfo; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.ZooKeeperThread; +import org.apache.zookeeper.server.admin.AdminServer; +import org.apache.zookeeper.server.admin.AdminServer.AdminServerException; +import org.apache.zookeeper.server.admin.AdminServerFactory; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.apache.zookeeper.server.quorum.flexible.QuorumMaj; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * This class manages the quorum protocol. There are three states this server can be in:
        1. Leader election - each server will elect a leader (proposing itself as a leader initially).
        2. + *
        3. Follower - the server will synchronize with the leader and replicate any transactions.
        4. Leader - the server will process requests and forward them to followers. A majority of followers + * must log the request before it can be accepted.
        + * + * This class will setup a datagram socket that will always respond with its view of the current leader. The response will take the form of: + * + *
        + * int xid;
        + *
        + * long myid;
        + *
        + * long leader_id;
        + *
        + * long leader_zxid;
        + * 
        + * + * The request for the current leader will consist solely of an xid: int xid; + */ +public class QuorumPeer extends ZooKeeperThread implements QuorumStats.Provider { + /** + * The syncEnabled can also be set via a system property. + */ + public static final String SYNC_ENABLED = "zookeeper.observer.syncEnabled"; + public static final String CURRENT_EPOCH_FILENAME = "currentEpoch"; + public static final String ACCEPTED_EPOCH_FILENAME = "acceptedEpoch"; + static final long OBSERVER_ID = Long.MAX_VALUE; + private static final Logger LOG = LoggerFactory.getLogger(QuorumPeer.class); + private final QuorumStats quorumStats; + /* + * Record leader election time + */ + public long start_fle, end_fle; + /** + * QuorumVerifier implementation; default (majority). + */ + + //last committed quorum verifier + public QuorumVerifier quorumVerifier; + //last proposed quorum verifier + public QuorumVerifier lastSeenQuorumVerifier = null; + + + public Follower follower; + + /* + * To enable observers to have no identifier, we need a generic identifier + * at least for QuorumCnxManager. We use the following constant to as the + * value of such a generic identifier. + */ + public Leader leader; + public Observer observer; + /** + * The number of milliseconds of each tick + */ + protected int tickTime; + /** + * Whether learners in this quorum should create new sessions as local. False by default to preserve existing behavior. + */ + protected boolean localSessionsEnabled = false; + /** + * Whether learners in this quorum should upgrade local sessions to global. Only matters if local sessions are enabled. + */ + protected boolean localSessionsUpgradingEnabled = true; + /** + * Minimum number of milliseconds to allow for session timeout. A value of -1 indicates unset, use default. + */ + protected int minSessionTimeout = -1; + /** + * Maximum number of milliseconds to allow for session timeout. A value of -1 indicates unset, use default. + */ + protected int maxSessionTimeout = -1; + /** + * The number of ticks that the initial synchronization phase can take + */ + protected int initLimit; + /** + * The number of ticks that can pass between sending a request and getting an acknowledgment + */ + protected int syncLimit; + /** + * Enables/Disables sync request processor. This option is enabled by default and is to be used with observers. + */ + protected boolean syncEnabled = true; + /** + * The current tick + */ + protected AtomicInteger tick = new AtomicInteger(); + /** + * Whether or not to listen on all IPs for the two quorum ports (broadcast and fast leader election). + */ + protected boolean quorumListenOnAllIPs = false; + LocalPeerBean jmxLocalPeerBean; + LeaderElectionBean jmxLeaderElectionBean; + volatile boolean running = true; + DatagramSocket udpSocket; + Election electionAlg; + ServerCnxnFactory cnxnFactory; + ServerCnxnFactory secureCnxnFactory; + AdminServer adminServer; + ResponderThread responder; + boolean shuttingDownLE = false; + private QuorumBean jmxQuorumBean; + private Map jmxRemotePeerBean; + private QuorumCnxManager qcm; + /** + * ZKDatabase is a top level member of quorumpeer which will be used in all the zookeeperservers instantiated later. Also, it is created once on bootup and only thrown away in case of a truncate + * message from the leader + */ + private ZKDatabase zkDb; + /* + * Default value of peer is participant + */ + private LearnerType learnerType = LearnerType.PARTICIPANT; + private String configFilename = null; + /** + * My id + */ + private long myid; + /** + * This is who I think the leader currently is. + */ + volatile private Vote currentVote; + private ServerState state = ServerState.LOOKING; + private boolean reconfigFlag = false; // indicates that a reconfig just committed + private InetSocketAddress myQuorumAddr; + private InetSocketAddress myElectionAddr = null; + private InetSocketAddress myClientAddr = null; + private int electionType; + private FileTxnSnapLog logFactory = null; + private long acceptedEpoch = -1; + private long currentEpoch = -1; + + public QuorumPeer() { + super("QuorumPeer"); + quorumStats = new QuorumStats(this); + jmxRemotePeerBean = new HashMap(); + adminServer = AdminServerFactory.createAdminServer(); + } + + /** + * For backward compatibility purposes, we instantiate QuorumMaj by default. + */ + + public QuorumPeer(Map quorumPeers, File dataDir, + File dataLogDir, int electionType, + long myid, int tickTime, int initLimit, int syncLimit, + ServerCnxnFactory cnxnFactory) throws IOException { + this(quorumPeers, dataDir, dataLogDir, electionType, myid, tickTime, + initLimit, syncLimit, false, cnxnFactory, + new QuorumMaj(quorumPeers)); + } + + public QuorumPeer(Map quorumPeers, File dataDir, + File dataLogDir, int electionType, + long myid, int tickTime, int initLimit, int syncLimit, + boolean quorumListenOnAllIPs, + ServerCnxnFactory cnxnFactory, + QuorumVerifier quorumConfig) throws IOException { + this(); + this.cnxnFactory = cnxnFactory; + this.electionType = electionType; + this.myid = myid; + this.tickTime = tickTime; + this.initLimit = initLimit; + this.syncLimit = syncLimit; + this.quorumListenOnAllIPs = quorumListenOnAllIPs; + this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir); + this.zkDb = new ZKDatabase(this.logFactory); + if (quorumConfig == null) quorumConfig = new QuorumMaj(quorumPeers); + setQuorumVerifier(quorumConfig, false); + adminServer = AdminServerFactory.createAdminServer(); + } + + /** + * This constructor is only used by the existing unit test code. It defaults to FileLogProvider persistence provider. + */ + public QuorumPeer(Map quorumPeers, File snapDir, + File logDir, int clientPort, int electionAlg, + long myid, int tickTime, int initLimit, int syncLimit) + throws IOException { + this(quorumPeers, snapDir, logDir, electionAlg, myid, tickTime, initLimit, syncLimit, false, + ServerCnxnFactory.createFactory(getClientAddress(quorumPeers, myid, clientPort), -1), + new QuorumMaj(quorumPeers)); + } + + /** + * This constructor is only used by the existing unit test code. It defaults to FileLogProvider persistence provider. + */ + public QuorumPeer(Map quorumPeers, File snapDir, + File logDir, int clientPort, int electionAlg, + long myid, int tickTime, int initLimit, int syncLimit, + QuorumVerifier quorumConfig) + throws IOException { + this(quorumPeers, snapDir, logDir, electionAlg, + myid, tickTime, initLimit, syncLimit, false, + ServerCnxnFactory.createFactory(getClientAddress(quorumPeers, myid, clientPort), -1), + quorumConfig); + } + + /** + * Count the number of nodes in the map that could be followers. + * + * @return The number of followers in the map + */ + protected static int countParticipants(Map peers) { + int count = 0; + for (QuorumServer q : peers.values()) { + if (q.type == LearnerType.PARTICIPANT) { + count++; + } + } + return count; + } + + private static InetSocketAddress getClientAddress(Map quorumPeers, long myid, int clientPort) + throws IOException { + QuorumServer quorumServer = quorumPeers.get(myid); + if (null == quorumServer) { + throw new IOException("No QuorumServer correspoding to myid " + myid); + } + if (null == quorumServer.clientAddr) { + return new InetSocketAddress(clientPort); + } + if (quorumServer.clientAddr.getPort() != clientPort) { + throw new IOException("QuorumServer port " + quorumServer.clientAddr.getPort() + + " does not match with given port " + clientPort); + } + return quorumServer.clientAddr; + } + + public LearnerType getLearnerType() { + return learnerType; + } + + /** + * Sets the LearnerType + */ + public void setLearnerType(LearnerType p) { + learnerType = p; + } + + protected synchronized void setConfigFileName(String s) { + configFilename = s; + } + + public int getQuorumSize() { + return getVotingView().size(); + } + + /** + * get the id of this quorum peer. + */ + public long getId() { + return myid; + } + + public synchronized Vote getCurrentVote() { + return currentVote; + } + + public synchronized void setCurrentVote(Vote v) { + currentVote = v; + } + + public synchronized void reconfigFlagSet() { + reconfigFlag = true; + } + + public synchronized void reconfigFlagClear() { + reconfigFlag = false; + } + + public synchronized boolean isReconfigStateChange() { + return reconfigFlag; + } + + public synchronized ServerState getPeerState() { + return state; + } + + public synchronized void setPeerState(ServerState newState) { + state = newState; + } + + /** + * Resolves hostname for a given server ID. + * + * This method resolves hostname for a given server ID in both quorumVerifer and lastSeenQuorumVerifier. If the server ID matches the local server ID, it also updates myQuorumAddr and + * myElectionAddr. + */ + public void recreateSocketAddresses(long id) { + QuorumVerifier qv = getQuorumVerifier(); + if (qv != null) { + QuorumServer qs = qv.getAllMembers().get(id); + if (qs != null) { + qs.recreateSocketAddresses(); + if (id == getId()) { + setQuorumAddress(qs.addr); + setElectionAddress(qs.electionAddr); + } + } + } + qv = getLastSeenQuorumVerifier(); + if (qv != null) { + QuorumServer qs = qv.getAllMembers().get(id); + if (qs != null) { + qs.recreateSocketAddresses(); + } + } + } + + public synchronized InetSocketAddress getQuorumAddress() { + return myQuorumAddr; + } + + public synchronized void setQuorumAddress(InetSocketAddress addr) { + myQuorumAddr = addr; + } + + public InetSocketAddress getElectionAddress() { + return myElectionAddr; + } + + public void setElectionAddress(InetSocketAddress addr) { + myElectionAddr = addr; + } + + public InetSocketAddress getClientAddress() { + return myClientAddr; + } + + public void setClientAddress(InetSocketAddress addr) { + myClientAddr = addr; + } + + QuorumStats quorumStats() { + return quorumStats; + } + + @Override + public synchronized void start() { + if (!getView().containsKey(myid)) { + throw new RuntimeException("My id " + myid + " not in the peer list"); + } + loadDataBase(); + startServerCnxnFactory(); + try { + adminServer.start(); + } catch (AdminServerException e) { + LOG.warn("Problem starting AdminServer", e); + System.out.println(e); + } + startLeaderElection(); + super.start(); + } + + private void loadDataBase() { + try { + zkDb.loadDataBase(); + + // load the epochs + long lastProcessedZxid = zkDb.getDataTree().lastProcessedZxid; + long epochOfZxid = ZxidUtils.getEpochFromZxid(lastProcessedZxid); + try { + currentEpoch = readLongFromFile(CURRENT_EPOCH_FILENAME); + } catch (FileNotFoundException e) { + // pick a reasonable epoch number + // this should only happen once when moving to a + // new code version + currentEpoch = epochOfZxid; + LOG.info(CURRENT_EPOCH_FILENAME + + " not found! Creating with a reasonable default of {}. This should only happen when you are upgrading your installation", + currentEpoch); + writeLongToFile(CURRENT_EPOCH_FILENAME, currentEpoch); + } + if (epochOfZxid > currentEpoch) { + throw new IOException("The current epoch, " + ZxidUtils.zxidToString(currentEpoch) + ", is older than the last zxid, " + lastProcessedZxid); + } + try { + acceptedEpoch = readLongFromFile(ACCEPTED_EPOCH_FILENAME); + } catch (FileNotFoundException e) { + // pick a reasonable epoch number + // this should only happen once when moving to a + // new code version + acceptedEpoch = epochOfZxid; + LOG.info(ACCEPTED_EPOCH_FILENAME + + " not found! Creating with a reasonable default of {}. This should only happen when you are upgrading your installation", + acceptedEpoch); + writeLongToFile(ACCEPTED_EPOCH_FILENAME, acceptedEpoch); + } + if (acceptedEpoch < currentEpoch) { + throw new IOException("The accepted epoch, " + ZxidUtils.zxidToString(acceptedEpoch) + " is less than the current epoch, " + ZxidUtils.zxidToString(currentEpoch)); + } + } catch (IOException ie) { + LOG.error("Unable to load database on disk", ie); + throw new RuntimeException("Unable to run quorum server ", ie); + } + } + + synchronized public void stopLeaderElection() { + responder.running = false; + responder.interrupt(); + } + + synchronized public void startLeaderElection() { + try { + if (getPeerState() == ServerState.LOOKING) { + currentVote = new Vote(myid, getLastLoggedZxid(), getCurrentEpoch()); + } + } catch (IOException e) { + RuntimeException re = new RuntimeException(e.getMessage()); + re.setStackTrace(e.getStackTrace()); + throw re; + } + + // if (!getView().containsKey(myid)) { + // throw new RuntimeException("My id " + myid + " not in the peer list"); + //} + if (electionType == 0) { + try { + udpSocket = new DatagramSocket(myQuorumAddr.getPort()); + responder = new ResponderThread(); + responder.start(); + } catch (SocketException e) { + throw new RuntimeException(e); + } + } + this.electionAlg = createElectionAlgorithm(electionType); + } + + /** + * returns the highest zxid that this host has seen + * + * @return the highest zxid for this host + */ + public long getLastLoggedZxid() { + if (!zkDb.isInitialized()) { + loadDataBase(); + } + return zkDb.getDataTreeLastProcessedZxid(); + } + + protected Follower makeFollower(FileTxnSnapLog logFactory) throws IOException { + return new Follower(this, new FollowerZooKeeperServer(logFactory, this, this.zkDb)); + } + + protected Leader makeLeader(FileTxnSnapLog logFactory) throws IOException { + return new Leader(this, new LeaderZooKeeperServer(logFactory, this, this.zkDb)); + } + + protected Observer makeObserver(FileTxnSnapLog logFactory) throws IOException { + return new Observer(this, new ObserverZooKeeperServer(logFactory, this, this.zkDb)); + } + + @SuppressWarnings("deprecation") + protected Election createElectionAlgorithm(int electionAlgorithm) { + Election le = null; + + //TODO: use a factory rather than a switch + switch (electionAlgorithm) { + case 0: + le = new LeaderElection(this); + break; + case 1: + le = new AuthFastLeaderElection(this); + break; + case 2: + le = new AuthFastLeaderElection(this, true); + break; + case 3: + qcm = new QuorumCnxManager(this); + QuorumCnxManager.Listener listener = qcm.listener; + if (listener != null) { + listener.start(); + FastLeaderElection fle = new FastLeaderElection(this, qcm); + fle.start(); + le = fle; + } else { + LOG.error("Null listener when initializing cnx manager"); + } + break; + default: + assert false; + } + return le; + } + + @SuppressWarnings("deprecation") + protected Election makeLEStrategy() { + LOG.debug("Initializing leader election protocol..."); + if (getElectionType() == 0) { + electionAlg = new LeaderElection(this); + } + return electionAlg; + } + + synchronized protected void setLeader(Leader newLeader) { + leader = newLeader; + } + + synchronized protected void setFollower(Follower newFollower) { + follower = newFollower; + } + + synchronized protected void setObserver(Observer newObserver) { + observer = newObserver; + } + + synchronized public ZooKeeperServer getActiveServer() { + if (leader != null) + return leader.zk; + else if (follower != null) + return follower.zk; + else if (observer != null) + return observer.zk; + return null; + } + + @Override + public void run() { + updateThreadName(); + + LOG.debug("Starting quorum peer"); + try { + jmxQuorumBean = new QuorumBean(this); + MBeanRegistry.getInstance().register(jmxQuorumBean, null); + for (QuorumServer s : getView().values()) { + ZKMBeanInfo p; + if (getId() == s.id) { + p = jmxLocalPeerBean = new LocalPeerBean(this); + try { + MBeanRegistry.getInstance().register(p, jmxQuorumBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxLocalPeerBean = null; + } + } else { + RemotePeerBean rBean = new RemotePeerBean(s); + try { + MBeanRegistry.getInstance().register(rBean, jmxQuorumBean); + jmxRemotePeerBean.put(s.id, rBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + } + } + } + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxQuorumBean = null; + } + + try { + /* + * Main loop + */ + while (running) { + switch (getPeerState()) { + case LOOKING: + LOG.info("LOOKING"); + + if (Boolean.getBoolean("readonlymode.enabled")) { + LOG.info("Attempting to start ReadOnlyZooKeeperServer"); + + // Create read-only server but don't start it immediately + final ReadOnlyZooKeeperServer roZk = + new ReadOnlyZooKeeperServer(logFactory, this, this.zkDb); + + // Instead of starting roZk immediately, wait some grace + // period before we decide we're partitioned. + // + // Thread is used here because otherwise it would require + // changes in each of election strategy classes which is + // unnecessary code coupling. + Thread roZkMgr = new Thread() { + public void run() { + try { + // lower-bound grace period to 2 secs + sleep(Math.max(2000, tickTime)); + if (ServerState.LOOKING.equals(getPeerState())) { + roZk.startup(); + } + } catch (InterruptedException e) { + LOG.info("Interrupted while attempting to start ReadOnlyZooKeeperServer, not started"); + } catch (Exception e) { + LOG.error("FAILED to start ReadOnlyZooKeeperServer", e); + } + } + }; + try { + roZkMgr.start(); + reconfigFlagClear(); + if (shuttingDownLE) { + shuttingDownLE = false; + startLeaderElection(); + } + setCurrentVote(makeLEStrategy().lookForLeader()); + } catch (Exception e) { + LOG.warn("Unexpected exception", e); + setPeerState(ServerState.LOOKING); + } finally { + // If the thread is in the the grace period, interrupt + // to come out of waiting. + roZkMgr.interrupt(); + roZk.shutdown(); + } + } else { + try { + reconfigFlagClear(); + if (shuttingDownLE) { + shuttingDownLE = false; + startLeaderElection(); + } + setCurrentVote(makeLEStrategy().lookForLeader()); + } catch (Exception e) { + LOG.warn("Unexpected exception", e); + setPeerState(ServerState.LOOKING); + } + } + break; + case OBSERVING: + try { + LOG.info("OBSERVING"); + setObserver(makeObserver(logFactory)); + observer.observeLeader(); + } catch (Exception e) { + LOG.warn("Unexpected exception", e); + } finally { + observer.shutdown(); + setObserver(null); + updateServerState(); + } + break; + case FOLLOWING: + try { + LOG.info("FOLLOWING"); + setFollower(makeFollower(logFactory)); + follower.followLeader(); + } catch (Exception e) { + LOG.warn("Unexpected exception", e); + } finally { + follower.shutdown(); + setFollower(null); + updateServerState(); + } + break; + case LEADING: + LOG.info("LEADING"); + try { + setLeader(makeLeader(logFactory)); + leader.lead(); + setLeader(null); + } catch (Exception e) { + LOG.warn("Unexpected exception", e); + } finally { + if (leader != null) { + leader.shutdown("Forcing shutdown"); + setLeader(null); + } + updateServerState(); + } + break; + } + start_fle = Time.currentElapsedTime(); + } + } finally { + LOG.warn("QuorumPeer main thread exited"); + MBeanRegistry instance = MBeanRegistry.getInstance(); + instance.unregister(jmxQuorumBean); + instance.unregister(jmxLocalPeerBean); + + for (RemotePeerBean remotePeerBean : jmxRemotePeerBean.values()) { + instance.unregister(remotePeerBean); + } + + jmxQuorumBean = null; + jmxLocalPeerBean = null; + jmxRemotePeerBean = null; + } + } + + private synchronized void updateServerState() { + if (!reconfigFlag) { + setPeerState(ServerState.LOOKING); + LOG.warn("PeerState set to LOOKING"); + return; + } + + if (getId() == getCurrentVote().getId()) { + setPeerState(ServerState.LEADING); + LOG.debug("PeerState set to LEADING"); + } else if (getLearnerType() == LearnerType.PARTICIPANT) { + setPeerState(ServerState.FOLLOWING); + LOG.debug("PeerState set to FOLLOWING"); + } else if (getLearnerType() == LearnerType.OBSERVER) { + setPeerState(ServerState.OBSERVING); + LOG.debug("PeerState set to OBSERVER"); + } else { // currently shouldn't happen since there are only 2 learner types + setPeerState(ServerState.LOOKING); + LOG.debug("Shouldn't be here"); + } + reconfigFlag = false; + } + + public void shutdown() { + running = false; + if (leader != null) { + leader.shutdown("quorum Peer shutdown"); + } + if (follower != null) { + follower.shutdown(); + } + shutdownServerCnxnFactory(); + if (udpSocket != null) { + udpSocket.close(); + } + + try { + adminServer.shutdown(); + } catch (AdminServerException e) { + LOG.warn("Problem stopping AdminServer", e); + } + + if (getElectionAlg() != null) { + this.interrupt(); + getElectionAlg().shutdown(); + } + try { + zkDb.close(); + } catch (IOException ie) { + LOG.warn("Error closing logs ", ie); + } + } + + /** + * A 'view' is a node's current opinion of the membership of the entire ensemble. + */ + public Map getView() { + return Collections.unmodifiableMap(getQuorumVerifier().getAllMembers()); + } + + /** + * Observers are not contained in this view, only nodes with PeerType=PARTICIPANT. + */ + public Map getVotingView() { + return getQuorumVerifier().getVotingMembers(); + } + + /** + * Returns only observers, no followers. + */ + public Map getObservingView() { + return getQuorumVerifier().getObservingMembers(); + } + + public synchronized Set getCurrentAndNextConfigVoters() { + Set voterIds = new HashSet(getQuorumVerifier().getVotingMembers().keySet()); + if (getLastSeenQuorumVerifier() != null) { + voterIds.addAll(getLastSeenQuorumVerifier().getVotingMembers().keySet()); + } + return voterIds; + } + + /** + * Check if a node is in the current view. With static membership, the result of this check will never change; only when dynamic membership is introduced will this be more useful. + */ + public boolean viewContains(Long sid) { + return this.getView().containsKey(sid); + } + + /** + * Only used by QuorumStats at the moment + */ + public String[] getQuorumPeers() { + List l = new ArrayList(); + synchronized (this) { + if (leader != null) { + for (LearnerHandler fh : leader.getLearners()) { + if (fh.getSocket() != null) { + String s = fh.getSocket().getRemoteSocketAddress().toString(); + if (leader.isLearnerSynced(fh)) + s += "*"; + l.add(s); + } + } + } else if (follower != null) { + l.add(follower.sock.getRemoteSocketAddress().toString()); + } + } + return l.toArray(new String[0]); + } + + public String getServerState() { + switch (getPeerState()) { + case LOOKING: + return QuorumStats.Provider.LOOKING_STATE; + case LEADING: + return QuorumStats.Provider.LEADING_STATE; + case FOLLOWING: + return QuorumStats.Provider.FOLLOWING_STATE; + case OBSERVING: + return QuorumStats.Provider.OBSERVING_STATE; + } + return QuorumStats.Provider.UNKNOWN_STATE; + } + + /** + * set the id of this quorum peer. + */ + public void setMyid(long myid) { + this.myid = myid; + } + + /** + * Get the number of milliseconds of each tick + */ + public int getTickTime() { + return tickTime; + } + + /** + * Set the number of milliseconds of each tick + */ + public void setTickTime(int tickTime) { + LOG.info("tickTime set to " + tickTime); + this.tickTime = tickTime; + } + + /** + * Maximum number of connections allowed from particular host (ip) + */ + public int getMaxClientCnxnsPerHost() { + if (cnxnFactory != null) { + return cnxnFactory.getMaxClientCnxnsPerHost(); + } + if (secureCnxnFactory != null) { + return secureCnxnFactory.getMaxClientCnxnsPerHost(); + } + return -1; + } + + /** + * Whether local sessions are enabled + */ + public boolean areLocalSessionsEnabled() { + return localSessionsEnabled; + } + + /** + * Whether to enable local sessions + */ + public void enableLocalSessions(boolean flag) { + LOG.info("Local sessions " + (flag ? "enabled" : "disabled")); + localSessionsEnabled = flag; + } + + /** + * Whether local sessions are allowed to upgrade to global sessions + */ + public boolean isLocalSessionsUpgradingEnabled() { + return localSessionsUpgradingEnabled; + } + + /** + * Whether to allow local sessions to upgrade to global sessions + */ + public void enableLocalSessionsUpgrading(boolean flag) { + LOG.info("Local session upgrading " + (flag ? "enabled" : "disabled")); + localSessionsUpgradingEnabled = flag; + } + + /** + * minimum session timeout in milliseconds + */ + public int getMinSessionTimeout() { + return minSessionTimeout; + } + + /** + * minimum session timeout in milliseconds + */ + public void setMinSessionTimeout(int min) { + LOG.info("minSessionTimeout set to " + min); + this.minSessionTimeout = min; + } + + /** + * maximum session timeout in milliseconds + */ + public int getMaxSessionTimeout() { + return maxSessionTimeout; + } + + /** + * maximum session timeout in milliseconds + */ + public void setMaxSessionTimeout(int max) { + LOG.info("maxSessionTimeout set to " + max); + this.maxSessionTimeout = max; + } + + /** + * Get the number of ticks that the initial synchronization phase can take + */ + public int getInitLimit() { + return initLimit; + } + + /** + * Set the number of ticks that the initial synchronization phase can take + */ + public void setInitLimit(int initLimit) { + LOG.info("initLimit set to " + initLimit); + this.initLimit = initLimit; + } + + /** + * Get the current tick + */ + public int getTick() { + return tick.get(); + } + + public QuorumVerifier configFromString(String s) throws IOException, ConfigException { + Properties props = new Properties(); + props.load(new StringReader(s)); + return QuorumPeerConfig.parseDynamicConfig(props, electionType, false, false); + } + + /** + * Return QuorumVerifier object for the last committed configuration + */ + + public synchronized QuorumVerifier getQuorumVerifier() { + return quorumVerifier; + + } + + public synchronized QuorumVerifier getLastSeenQuorumVerifier() { + return lastSeenQuorumVerifier; + } + + public synchronized void connectNewPeers() { + if (qcm != null && getQuorumVerifier() != null && getLastSeenQuorumVerifier() != null) { + Map committedView = getQuorumVerifier().getAllMembers(); + for (Entry e : getLastSeenQuorumVerifier().getAllMembers().entrySet()) { + if (e.getKey() != getId() && !committedView.containsKey(e.getKey())) + qcm.connectOne(e.getKey()); + } + } + } + + public synchronized void restartLeaderElection(QuorumVerifier qvOLD, QuorumVerifier qvNEW) { + if (qvOLD == null || !qvOLD.equals(qvNEW)) { + LOG.warn("Restarting Leader Election"); + getElectionAlg().shutdown(); + shuttingDownLE = false; + startLeaderElection(); + } + } + + public String getNextDynamicConfigFilename() { + return configFilename + QuorumPeerConfig.nextDynamicConfigFileSuffix; + } + + public synchronized void setLastSeenQuorumVerifier(QuorumVerifier qv, boolean writeToDisk) { + if (lastSeenQuorumVerifier != null && lastSeenQuorumVerifier.getVersion() > qv.getVersion()) { + LOG.error("setLastSeenQuorumVerifier called with stale config " + qv.getVersion() + + ". Current version: " + quorumVerifier.getVersion()); + + } + // assuming that a version uniquely identifies a configuration, so if + // version is the same, nothing to do here. + if (lastSeenQuorumVerifier != null && + lastSeenQuorumVerifier.getVersion() == qv.getVersion()) { + return; + } + lastSeenQuorumVerifier = qv; + connectNewPeers(); + if (writeToDisk) { + try { + QuorumPeerConfig.writeDynamicConfig( + getNextDynamicConfigFilename(), qv, true); + } catch (IOException e) { + LOG.error("Error writing next dynamic config file to disk: ", e.getMessage()); + } + } + + } + + public synchronized QuorumVerifier setQuorumVerifier(QuorumVerifier qv, boolean writeToDisk) { + if ((quorumVerifier != null) && (quorumVerifier.getVersion() >= qv.getVersion())) { + // this is normal. For example - server found out about new config through FastLeaderElection gossiping + // and then got the same config in UPTODATE message so its already known + LOG.debug(getId() + " setQuorumVerifier called with known or old config " + qv.getVersion() + + ". Current version: " + quorumVerifier.getVersion()); + return quorumVerifier; + } + QuorumVerifier prevQV = quorumVerifier; + quorumVerifier = qv; + if (lastSeenQuorumVerifier == null || (qv.getVersion() > lastSeenQuorumVerifier.getVersion())) + lastSeenQuorumVerifier = qv; + + if (writeToDisk) { + // some tests initialize QuorumPeer without a static config file + if (configFilename != null) { + try { + String dynamicConfigFilename = makeDynamicConfigFilename( + qv.getVersion()); + QuorumPeerConfig.writeDynamicConfig( + dynamicConfigFilename, qv, false); + QuorumPeerConfig.editStaticConfig(configFilename, + dynamicConfigFilename, + needEraseClientInfoFromStaticConfig()); + } catch (IOException e) { + LOG.error("Error closing file: ", e.getMessage()); + } + } else { + LOG.info("writeToDisk == true but configFilename == null"); + } + } + + if (qv.getVersion() == lastSeenQuorumVerifier.getVersion()) { + QuorumPeerConfig.deleteFile(getNextDynamicConfigFilename()); + } + QuorumServer qs = qv.getAllMembers().get(getId()); + if (qs != null) { + setQuorumAddress(qs.addr); + setElectionAddress(qs.electionAddr); + setClientAddress(qs.clientAddr); + } + return prevQV; + } + + private String makeDynamicConfigFilename(long version) { + return configFilename + ".dynamic." + Long.toHexString(version); + } + + private boolean needEraseClientInfoFromStaticConfig() { + QuorumServer server = quorumVerifier.getAllMembers().get(getId()); + return (server != null && server.clientAddr != null); + } + + /** + * Get an instance of LeaderElection + */ + public Election getElectionAlg() { + return electionAlg; + } + + /** + * Get the synclimit + */ + public int getSyncLimit() { + return syncLimit; + } + + /** + * Set the synclimit + */ + public void setSyncLimit(int syncLimit) { + this.syncLimit = syncLimit; + } + + /** + * Return syncEnabled. + */ + public boolean getSyncEnabled() { + if (System.getProperty(SYNC_ENABLED) != null) { + LOG.info(SYNC_ENABLED + "=" + Boolean.getBoolean(SYNC_ENABLED)); + return Boolean.getBoolean(SYNC_ENABLED); + } else { + return syncEnabled; + } + } + + /** + * Set syncEnabled. + */ + public void setSyncEnabled(boolean syncEnabled) { + this.syncEnabled = syncEnabled; + } + + /** + * Gets the election type + */ + public int getElectionType() { + return electionType; + } + + /** + * Sets the election type + */ + public void setElectionType(int electionType) { + this.electionType = electionType; + } + + public boolean getQuorumListenOnAllIPs() { + return quorumListenOnAllIPs; + } + + public void setQuorumListenOnAllIPs(boolean quorumListenOnAllIPs) { + this.quorumListenOnAllIPs = quorumListenOnAllIPs; + } + + public void setCnxnFactory(ServerCnxnFactory cnxnFactory) { + this.cnxnFactory = cnxnFactory; + } + + public void setSecureCnxnFactory(ServerCnxnFactory secureCnxnFactory) { + this.secureCnxnFactory = secureCnxnFactory; + } + + private void startServerCnxnFactory() { + if (cnxnFactory != null) { + cnxnFactory.start(); + } + if (secureCnxnFactory != null) { + secureCnxnFactory.start(); + } + } + + private void shutdownServerCnxnFactory() { + if (cnxnFactory != null) { + cnxnFactory.shutdown(); + } + if (secureCnxnFactory != null) { + secureCnxnFactory.shutdown(); + } + } + + // Leader and learner will control the zookeeper server and pass it into QuorumPeer. + public void setZooKeeperServer(ZooKeeperServer zks) { + if (cnxnFactory != null) { + cnxnFactory.setZooKeeperServer(zks); + } + if (secureCnxnFactory != null) { + secureCnxnFactory.setZooKeeperServer(zks); + } + } + + public void closeAllConnections() { + if (cnxnFactory != null) { + cnxnFactory.closeAll(); + } + if (secureCnxnFactory != null) { + secureCnxnFactory.closeAll(); + } + } + + public int getClientPort() { + if (cnxnFactory != null) { + return cnxnFactory.getLocalPort(); + } + return -1; + } + + public FileTxnSnapLog getTxnFactory() { + return this.logFactory; + } + + public void setTxnFactory(FileTxnSnapLog factory) { + this.logFactory = factory; + } + + /** + * set zk database for this node + */ + public void setZKDatabase(ZKDatabase database) { + this.zkDb = database; + } + + public synchronized void initConfigInZKDatabase() { + if (zkDb != null) zkDb.initConfigInZKDatabase(getQuorumVerifier()); + } + + public boolean isRunning() { + return running; + } + + public void setRunning(boolean running) { + this.running = running; + } + + /** + * get reference to QuorumCnxManager + */ + public QuorumCnxManager getQuorumCnxManager() { + return qcm; + } + + private long readLongFromFile(String name) throws IOException { + File file = new File(logFactory.getSnapDir(), name); + BufferedReader br = new BufferedReader(new FileReader(file)); + String line = ""; + try { + line = br.readLine(); + return Long.parseLong(line); + } catch (NumberFormatException e) { + throw new IOException("Found " + line + " in " + file); + } finally { + br.close(); + } + } + + /** + * Write a long value to disk atomically. Either succeeds or an exception is thrown. + * + * @param name file name to write the long to + * @param value the long value to write to the named file + * @throws IOException if the file cannot be written atomically + */ + private void writeLongToFile(String name, final long value) throws IOException { + File file = new File(logFactory.getSnapDir(), name); + new AtomicFileWritingIdiom(file, new WriterStatement() { + @Override + public void write(Writer bw) throws IOException { + bw.write(Long.toString(value)); + } + }); + } + + public long getCurrentEpoch() throws IOException { + if (currentEpoch == -1) { + currentEpoch = readLongFromFile(CURRENT_EPOCH_FILENAME); + } + return currentEpoch; + } + + public void setCurrentEpoch(long e) throws IOException { + currentEpoch = e; + writeLongToFile(CURRENT_EPOCH_FILENAME, e); + + } + + public long getAcceptedEpoch() throws IOException { + if (acceptedEpoch == -1) { + acceptedEpoch = readLongFromFile(ACCEPTED_EPOCH_FILENAME); + } + return acceptedEpoch; + } + + public void setAcceptedEpoch(long e) throws IOException { + acceptedEpoch = e; + writeLongToFile(ACCEPTED_EPOCH_FILENAME, e); + } + + public boolean processReconfig(QuorumVerifier qv, Long suggestedLeaderId, Long zxid, boolean restartLE) { + InetSocketAddress oldClientAddr = getClientAddress(); + + // update last committed quorum verifier, write the new config to disk + // and restart leader election if config changed + QuorumVerifier prevQV = setQuorumVerifier(qv, true); + + // There is no log record for the initial config, thus after syncing + // with leader + // /zookeeper/config is empty! it is also possible that last committed + // config is propagated during leader election + // without the propagation the corresponding log records. + // so we should explicitly do this (this is not necessary when we're + // already a Follower/Observer, only + // for Learner): + initConfigInZKDatabase(); + + if (prevQV.getVersion() < qv.getVersion() && !prevQV.equals(qv)) { + Map newMembers = qv.getAllMembers(); + updateRemotePeerMXBeans(newMembers); + if (restartLE) restartLeaderElection(prevQV, qv); + + QuorumServer myNewQS = newMembers.get(getId()); + if (myNewQS != null && myNewQS.clientAddr != null + && !myNewQS.clientAddr.equals(oldClientAddr)) { + cnxnFactory.reconfigure(myNewQS.clientAddr); + updateThreadName(); + } + + boolean roleChange = updateLearnerType(qv); + boolean leaderChange = false; + if (suggestedLeaderId != null) { + // zxid should be non-null too + leaderChange = updateVote(suggestedLeaderId, zxid); + } else { + long currentLeaderId = getCurrentVote().getId(); + QuorumServer myleaderInCurQV = prevQV.getVotingMembers().get(currentLeaderId); + QuorumServer myleaderInNewQV = qv.getVotingMembers().get(currentLeaderId); + leaderChange = (myleaderInCurQV == null || myleaderInCurQV.addr == null || + myleaderInNewQV == null || !myleaderInCurQV.addr.equals(myleaderInNewQV.addr)); + // we don't have a designated leader - need to go into leader + // election + reconfigFlagClear(); + } + + if (roleChange || leaderChange) { + return true; + } + } + return false; + + } + + private void updateRemotePeerMXBeans(Map newMembers) { + Set existingMembers = new HashSet(newMembers.keySet()); + existingMembers.retainAll(jmxRemotePeerBean.keySet()); + for (Long id : existingMembers) { + RemotePeerBean rBean = jmxRemotePeerBean.get(id); + rBean.setQuorumServer(newMembers.get(id)); + } + + Set joiningMembers = new HashSet(newMembers.keySet()); + joiningMembers.removeAll(jmxRemotePeerBean.keySet()); + joiningMembers.remove(getId()); // remove self as it is local bean + for (Long id : joiningMembers) { + QuorumServer qs = newMembers.get(id); + RemotePeerBean rBean = new RemotePeerBean(qs); + try { + MBeanRegistry.getInstance().register(rBean, jmxQuorumBean); + jmxRemotePeerBean.put(qs.id, rBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + } + } + + Set leavingMembers = new HashSet(jmxRemotePeerBean.keySet()); + leavingMembers.removeAll(newMembers.keySet()); + for (Long id : leavingMembers) { + RemotePeerBean rBean = jmxRemotePeerBean.remove(id); + try { + MBeanRegistry.getInstance().unregister(rBean); + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + } + } + + private boolean updateLearnerType(QuorumVerifier newQV) { + //check if I'm an observer in new config + if (newQV.getObservingMembers().containsKey(getId())) { + if (getLearnerType() != LearnerType.OBSERVER) { + setLearnerType(LearnerType.OBSERVER); + LOG.info("Becoming an observer"); + reconfigFlagSet(); + return true; + } else { + return false; + } + } else if (newQV.getVotingMembers().containsKey(getId())) { + if (getLearnerType() != LearnerType.PARTICIPANT) { + setLearnerType(LearnerType.PARTICIPANT); + LOG.info("Becoming a voting participant"); + reconfigFlagSet(); + return true; + } else { + return false; + } + } + // I'm not in the view + if (getLearnerType() != LearnerType.PARTICIPANT) { + setLearnerType(LearnerType.PARTICIPANT); + LOG.info("Becoming a non-voting participant"); + reconfigFlagSet(); + return true; + } + return false; + } + + private boolean updateVote(long designatedLeader, long zxid) { + Vote currentVote = getCurrentVote(); + if (currentVote != null && designatedLeader != currentVote.getId()) { + setCurrentVote(new Vote(designatedLeader, zxid)); + reconfigFlagSet(); + LOG.warn("Suggested leader: " + designatedLeader); + return true; + } + return false; + } + + /** + * Updates leader election info to avoid inconsistencies when a new server tries to join the ensemble. + * + * @see https://issues.apache.org/jira/browse/ZOOKEEPER-1732 + */ + protected void updateElectionVote(long newEpoch) { + Vote currentVote = getCurrentVote(); + if (currentVote != null) { + setCurrentVote(new Vote(currentVote.getId(), + currentVote.getZxid(), + currentVote.getElectionEpoch(), + newEpoch, + currentVote.getState())); + } + } + + private void updateThreadName() { + String plain = cnxnFactory != null ? cnxnFactory.getLocalAddress().toString() : "disabled"; + String secure = secureCnxnFactory != null ? secureCnxnFactory.getLocalAddress().toString() : "disabled"; + setName(String.format("QuorumPeer[myid=%d](plain=%s)(secure=%s)", getId(), plain, secure)); + } + + public enum ServerState { + LOOKING, FOLLOWING, LEADING, OBSERVING; + } + + /* + * A peer can either be participating, which implies that it is willing to + * both vote in instances of consensus and to elect or become a Leader, or + * it may be observing in which case it isn't. + * + * We need this distinction to decide which ServerState to move to when + * conditions change (e.g. which state to become after LOOKING). + */ + public enum LearnerType { + PARTICIPANT, OBSERVER; + } + + public static class QuorumServer { + private static final String wrongFormat = " does not have the form server_config or server_config;client_config" + + " where server_config is host:port:port or host:port:port:type and client_config is port or host:port"; + public InetSocketAddress addr = null; + public InetSocketAddress electionAddr = null; + public InetSocketAddress clientAddr = null; + public long id; + public LearnerType type = LearnerType.PARTICIPANT; + private List myAddrs; + + public QuorumServer(long id, InetSocketAddress addr, + InetSocketAddress electionAddr, InetSocketAddress clientAddr) { + this(id, addr, electionAddr, clientAddr, LearnerType.PARTICIPANT); + } + + public QuorumServer(long id, InetSocketAddress addr, + InetSocketAddress electionAddr) { + this(id, addr, electionAddr, (InetSocketAddress) null, LearnerType.PARTICIPANT); + } + + public QuorumServer(long id, InetSocketAddress addr) { + this(id, addr, (InetSocketAddress) null, (InetSocketAddress) null, LearnerType.PARTICIPANT); + } + + public QuorumServer(long sid, String addressStr) throws ConfigException { + // LOG.warn("sid = " + sid + " addressStr = " + addressStr); + this.id = sid; + String serverClientParts[] = addressStr.split(";"); + String serverParts[] = splitWithLeadingHostname(serverClientParts[0]); + if ((serverClientParts.length > 2) || (serverParts.length < 3) + || (serverParts.length > 4)) { + throw new ConfigException(addressStr + wrongFormat); + } + + if (serverClientParts.length == 2) { + //LOG.warn("ClientParts: " + serverClientParts[1]); + String clientParts[] = splitWithLeadingHostname(serverClientParts[1]); + if (clientParts.length > 2) { + throw new ConfigException(addressStr + wrongFormat); + } + + // is client_config a host:port or just a port + String hostname = (clientParts.length == 2) ? clientParts[0] : "0.0.0.0"; + try { + clientAddr = new InetSocketAddress(hostname, + Integer.parseInt(clientParts[clientParts.length - 1])); + //LOG.warn("Set clientAddr to " + clientAddr); + } catch (NumberFormatException e) { + throw new ConfigException("Address unresolved: " + hostname + ":" + clientParts[clientParts.length - 1]); + } + } + + // server_config should be either host:port:port or host:port:port:type + try { + addr = new InetSocketAddress(serverParts[0], + Integer.parseInt(serverParts[1])); + } catch (NumberFormatException e) { + throw new ConfigException("Address unresolved: " + serverParts[0] + ":" + serverParts[1]); + } + try { + electionAddr = new InetSocketAddress(serverParts[0], + Integer.parseInt(serverParts[2])); + } catch (NumberFormatException e) { + throw new ConfigException("Address unresolved: " + serverParts[0] + ":" + serverParts[2]); + } + + if (serverParts.length == 4) { + setType(serverParts[3]); + } + + setMyAddrs(); + } + + public QuorumServer(long id, InetSocketAddress addr, + InetSocketAddress electionAddr, LearnerType type) { + this(id, addr, electionAddr, (InetSocketAddress) null, type); + } + + public QuorumServer(long id, InetSocketAddress addr, + InetSocketAddress electionAddr, InetSocketAddress clientAddr, LearnerType type) { + this.id = id; + this.addr = addr; + this.electionAddr = electionAddr; + this.type = type; + this.clientAddr = clientAddr; + + setMyAddrs(); + } + + private static String[] splitWithLeadingHostname(String s) + throws ConfigException { + /* Does it start with an IPv6 literal? */ + if (s.startsWith("[")) { + int i = s.indexOf("]:"); + if (i < 0) { + throw new ConfigException(s + " starts with '[' but has no matching ']:'"); + } + + String[] sa = s.substring(i + 2).split(":"); + String[] nsa = new String[sa.length + 1]; + nsa[0] = s.substring(1, i); + System.arraycopy(sa, 0, nsa, 1, sa.length); + + return nsa; + } else { + return s.split(":"); + } + } + + private static String delimitedHostString(InetSocketAddress addr) { + String host = addr.getHostString(); + if (host.contains(":")) { + return "[" + host + "]"; + } else { + return host; + } + } + + /** + * Performs a DNS lookup for server address and election address. + * + * If the DNS lookup fails, this.addr and electionAddr remain unmodified. + */ + public void recreateSocketAddresses() { + if (this.addr == null) { + LOG.warn("Server address has not been initialized"); + return; + } + if (this.electionAddr == null) { + LOG.warn("Election address has not been initialized"); + return; + } + String host = this.addr.getHostString(); + InetAddress address = null; + try { + address = InetAddress.getByName(host); + } catch (UnknownHostException ex) { + LOG.warn("Failed to resolve address: {}", host, ex); + return; + } + LOG.debug("Resolved address for {}: {}", host, address); + int port = this.addr.getPort(); + this.addr = new InetSocketAddress(address, port); + port = this.electionAddr.getPort(); + this.electionAddr = new InetSocketAddress(address, port); + } + + private void setType(String s) throws ConfigException { + if (s.toLowerCase().equals("observer")) { + type = LearnerType.OBSERVER; + } else if (s.toLowerCase().equals("participant")) { + type = LearnerType.PARTICIPANT; + } else { + throw new ConfigException("Unrecognised peertype: " + s); + } + } + + private void setMyAddrs() { + this.myAddrs = new ArrayList(); + this.myAddrs.add(this.addr); + this.myAddrs.add(this.clientAddr); + this.myAddrs.add(this.electionAddr); + this.myAddrs = excludedSpecialAddresses(this.myAddrs); + } + + public String toString() { + StringWriter sw = new StringWriter(); + //addr should never be null, but just to make sure + if (addr != null) { + sw.append(delimitedHostString(addr)); + sw.append(":"); + sw.append(String.valueOf(addr.getPort())); + } + if (electionAddr != null) { + sw.append(":"); + sw.append(String.valueOf(electionAddr.getPort())); + } + if (type == LearnerType.OBSERVER) sw.append(":observer"); + else if (type == LearnerType.PARTICIPANT) sw.append(":participant"); + if (clientAddr != null) { + sw.append(";"); + sw.append(delimitedHostString(clientAddr)); + sw.append(":"); + sw.append(String.valueOf(clientAddr.getPort())); + } + return sw.toString(); + } + + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + + private boolean checkAddressesEqual(InetSocketAddress addr1, InetSocketAddress addr2) { + if ((addr1 == null && addr2 != null) || + (addr1 != null && addr2 == null) || + (addr1 != null && addr2 != null && !addr1.equals(addr2))) return false; + return true; + } + + public boolean equals(Object o) { + if (!(o instanceof QuorumServer)) return false; + QuorumServer qs = (QuorumServer) o; + if ((qs.id != id) || (qs.type != type)) return false; + if (!checkAddressesEqual(addr, qs.addr)) return false; + if (!checkAddressesEqual(electionAddr, qs.electionAddr)) return false; + if (!checkAddressesEqual(clientAddr, qs.clientAddr)) return false; + return true; + } + + public void checkAddressDuplicate(QuorumServer s) throws BadArgumentsException { + List otherAddrs = new ArrayList(); + otherAddrs.add(s.addr); + otherAddrs.add(s.clientAddr); + otherAddrs.add(s.electionAddr); + otherAddrs = excludedSpecialAddresses(otherAddrs); + + for (InetSocketAddress my : this.myAddrs) { + + for (InetSocketAddress other : otherAddrs) { + if (my.equals(other)) { + String error = String.format("%s of server.%d conflicts %s of server.%d", my, this.id, other, s.id); + throw new BadArgumentsException(error); + } + } + } + } + + private List excludedSpecialAddresses(List addrs) { + List included = new ArrayList(); + InetAddress wcAddr = new InetSocketAddress(0).getAddress(); + + for (InetSocketAddress addr : addrs) { + if (addr == null) { + continue; + } + InetAddress inetaddr = addr.getAddress(); + + if (inetaddr == null || + inetaddr.equals(wcAddr) || // wildCard address(0.0.0.0) + inetaddr.isLoopbackAddress()) { // loopback address(localhost/127.0.0.1) + continue; + } + included.add(addr); + } + return included; + } + } + + /** + * @deprecated As of release 3.4.0, this class has been deprecated, since it is used with one of the udp-based versions of leader election, which we are also deprecating. + * + * This class simply responds to requests for the current leader of this node.

        The request contains just an xid generated by the requestor.

        The response has the xid, the id of this server, + * the id of the leader, and the zxid of the leader. + */ + @Deprecated + class ResponderThread extends ZooKeeperThread { + volatile boolean running = true; + + ResponderThread() { + super("ResponderThread"); + } + + @Override + public void run() { + try { + byte b[] = new byte[36]; + ByteBuffer responseBuffer = ByteBuffer.wrap(b); + DatagramPacket packet = new DatagramPacket(b, b.length); + while (running) { + udpSocket.receive(packet); + if (packet.getLength() != 4) { + LOG.warn("Got more than just an xid! Len = " + + packet.getLength()); + } else { + responseBuffer.clear(); + responseBuffer.getInt(); // Skip the xid + responseBuffer.putLong(myid); + Vote current = getCurrentVote(); + switch (getPeerState()) { + case LOOKING: + responseBuffer.putLong(current.getId()); + responseBuffer.putLong(current.getZxid()); + break; + case LEADING: + responseBuffer.putLong(myid); + try { + long proposed; + synchronized (leader) { + proposed = leader.lastProposed; + } + responseBuffer.putLong(proposed); + } catch (NullPointerException npe) { + // This can happen in state transitions, + // just ignore the request + } + break; + case FOLLOWING: + responseBuffer.putLong(current.getId()); + try { + responseBuffer.putLong(follower.getZxid()); + } catch (NullPointerException npe) { + // This can happen in state transitions, + // just ignore the request + } + break; + case OBSERVING: + // Do nothing, Observers keep themselves to + // themselves. + break; + } + packet.setData(b); + udpSocket.send(packet); + } + packet.setLength(b.length); + } + } catch (RuntimeException e) { + LOG.warn("Unexpected runtime exception in ResponderThread", e); + } catch (IOException e) { + LOG.warn("Unexpected IO exception in ResponderThread", e); + } finally { + LOG.warn("QuorumPeer responder thread exited"); + } + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java new file mode 100644 index 00000000000..05e10ce45a9 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java @@ -0,0 +1,737 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.common.AtomicFileWritingIdiom; +import org.apache.zookeeper.common.AtomicFileWritingIdiom.OutputStreamStatement; +import org.apache.zookeeper.common.AtomicFileWritingIdiom.WriterStatement; +import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.common.StringUtils; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; +import org.apache.zookeeper.server.quorum.flexible.QuorumMaj; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.apache.zookeeper.server.util.VerifyingFileFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringReader; +import java.io.Writer; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; + + +public class QuorumPeerConfig { + public static final String nextDynamicConfigFileSuffix = ".dynamic.next"; + private static final Logger LOG = LoggerFactory.getLogger(QuorumPeerConfig.class); + private static final int UNSET_SERVERID = -1; + private static boolean standaloneEnabled = true; + /** + * Minimum snapshot retain count. + * @see org.apache.zookeeper.server.PurgeTxnLog#purge(File, File, int) + */ + private final int MIN_SNAP_RETAIN_COUNT = 3; + protected InetSocketAddress clientPortAddress; + protected InetSocketAddress secureClientPortAddress; + protected File dataDir; + protected File dataLogDir; + protected String dynamicConfigFileStr = null; + protected String configFileStr = null; + protected int tickTime = ZooKeeperServer.DEFAULT_TICK_TIME; + protected int maxClientCnxns = 60; + /** defaults to -1 if not set explicitly */ + protected int minSessionTimeout = -1; + /** defaults to -1 if not set explicitly */ + protected int maxSessionTimeout = -1; + protected boolean localSessionsEnabled = false; + protected boolean localSessionsUpgradingEnabled = false; + protected int initLimit; + protected int syncLimit; + protected int electionAlg = 3; + protected int electionPort = 2182; + protected boolean quorumListenOnAllIPs = false; + protected long serverId = UNSET_SERVERID; + protected QuorumVerifier quorumVerifier = null, lastSeenQuorumVerifier = null; + protected int snapRetainCount = 3; + protected int purgeInterval = 0; + protected boolean syncEnabled = true; + protected LearnerType peerType = LearnerType.PARTICIPANT; + + // This method gets the version from the end of dynamic file name. + // For example, "zoo.cfg.dynamic.0" returns initial version "0". + // "zoo.cfg.dynamic.1001" returns version of hex number "0x1001". + // If a dynamic file name doesn't have any version at the end of file, + // e.g. "zoo.cfg.dynamic", it returns null. + public static String getVersionFromFilename(String filename) { + int i = filename.lastIndexOf('.'); + if (i < 0 || i >= filename.length()) + return null; + + String hexVersion = filename.substring(i + 1); + try { + long version = Long.parseLong(hexVersion, 16); + return Long.toHexString(version); + } catch (NumberFormatException e) { + return null; + } + } + + /** + * Writes dynamic configuration file + */ + public static void writeDynamicConfig(final String dynamicConfigFilename, + final QuorumVerifier qv, + final boolean needKeepVersion) + throws IOException { + + new AtomicFileWritingIdiom(new File(dynamicConfigFilename), new WriterStatement() { + @Override + public void write(Writer out) throws IOException { + Properties cfg = new Properties(); + cfg.load(new StringReader( + qv.toString())); + + List servers = new ArrayList(); + for (Entry entry : cfg.entrySet()) { + String key = entry.getKey().toString().trim(); + if (!needKeepVersion && key.startsWith("version")) + continue; + + String value = entry.getValue().toString().trim(); + servers.add(key + .concat("=") + .concat(value)); + } + + Collections.sort(servers); + out.write(StringUtils.joinStrings(servers, "\n")); + } + }); + } + + /** + * Edit static config file. + * If there are quorum information in static file, e.g. "server.X", "group", + * it will remove them. + * If it needs to erase client port information left by the old config, + * "eraseClientPortAddress" should be set true. + * It should also updates dynamic file pointer on reconfig. + */ + public static void editStaticConfig(final String configFileStr, + final String dynamicFileStr, + final boolean eraseClientPortAddress) + throws IOException { + // Some tests may not have a static config file. + if (configFileStr == null) + return; + + File configFile = (new VerifyingFileFactory.Builder(LOG) + .warnForRelativePath() + .failForNonExistingPath() + .build()).create(configFileStr); + + final File dynamicFile = (new VerifyingFileFactory.Builder(LOG) + .warnForRelativePath() + .failForNonExistingPath() + .build()).create(dynamicFileStr); + + final Properties cfg = new Properties(); + FileInputStream in = new FileInputStream(configFile); + try { + cfg.load(in); + } finally { + in.close(); + } + + new AtomicFileWritingIdiom(new File(configFileStr), new WriterStatement() { + @Override + public void write(Writer out) throws IOException { + for (Entry entry : cfg.entrySet()) { + String key = entry.getKey().toString().trim(); + + if (key.startsWith("server.") + || key.startsWith("group") + || key.startsWith("weight") + || key.startsWith("dynamicConfigFile") + || (eraseClientPortAddress + && (key.startsWith("clientPort") + || key.startsWith("clientPortAddress")))) { + // not writing them back to static file + continue; + } + + String value = entry.getValue().toString().trim(); + out.write(key.concat("=").concat(value).concat("\n")); + } + + // updates the dynamic file pointer + String dynamicConfigFilePath = PathUtils.normalizeFileSystemPath(dynamicFile.getCanonicalPath()); + out.write("dynamicConfigFile=" + .concat(dynamicConfigFilePath) + .concat("\n")); + } + }); + } + + public static void deleteFile(String filename) { + File f = new File(filename); + if (f.exists()) { + try { + f.delete(); + } catch (Exception e) { + LOG.warn("deleting " + filename + " failed"); + } + } + } + + private static QuorumVerifier createQuorumVerifier(Properties dynamicConfigProp, boolean isHierarchical) throws ConfigException { + if (isHierarchical) { + return new QuorumHierarchical(dynamicConfigProp); + } else { + /* + * The default QuorumVerifier is QuorumMaj + */ + //LOG.info("Defaulting to majority quorums"); + return new QuorumMaj(dynamicConfigProp); + } + } + + /** + * Parse dynamic configuration file and return + * quorumVerifier for new configuration. + * @param dynamicConfigProp Properties to parse from. + * @throws IOException + * @throws ConfigException + */ + public static QuorumVerifier parseDynamicConfig(Properties dynamicConfigProp, int eAlg, boolean warnings, + boolean configBackwardCompatibilityMode) throws IOException, ConfigException { + boolean isHierarchical = false; + for (Entry entry : dynamicConfigProp.entrySet()) { + String key = entry.getKey().toString().trim(); + if (key.startsWith("group") || key.startsWith("weight")) { + isHierarchical = true; + } else if (!configBackwardCompatibilityMode && !key.startsWith("server.") && !key.equals("version")) { + LOG.info(dynamicConfigProp.toString()); + throw new ConfigException("Unrecognised parameter: " + key); + } + } + + QuorumVerifier qv = createQuorumVerifier(dynamicConfigProp, isHierarchical); + + int numParticipators = qv.getVotingMembers().size(); + int numObservers = qv.getObservingMembers().size(); + if (numParticipators == 0) { + if (!standaloneEnabled) { + throw new IllegalArgumentException("standaloneEnabled = false then " + + "number of participants should be >0"); + } + if (numObservers > 0) { + throw new IllegalArgumentException("Observers w/o participants is an invalid configuration"); + } + } else if (numParticipators == 1 && standaloneEnabled) { + // HBase currently adds a single server line to the config, for + // b/w compatibility reasons we need to keep this here. If standaloneEnabled + // is true, the QuorumPeerMain script will create a standalone server instead + // of a quorum configuration + LOG.error("Invalid configuration, only one server specified (ignoring)"); + if (numObservers > 0) { + throw new IllegalArgumentException("Observers w/o quorum is an invalid configuration"); + } + } else { + if (warnings) { + if (numParticipators <= 2) { + LOG.warn("No server failure will be tolerated. " + + "You need at least 3 servers."); + } else if (numParticipators % 2 == 0) { + LOG.warn("Non-optimial configuration, consider an odd number of servers."); + } + } + /* + * If using FLE, then every server requires a separate election + * port. + */ + if (eAlg != 0) { + for (QuorumServer s : qv.getVotingMembers().values()) { + if (s.electionAddr == null) + throw new IllegalArgumentException( + "Missing election port for server: " + s.id); + } + } + } + return qv; + } + + public static boolean isStandaloneEnabled() { + return standaloneEnabled; + } + + public static void setStandaloneEnabled(boolean enabled) { + standaloneEnabled = enabled; + } + + /** + * Parse a ZooKeeper configuration file + * @param path the patch of the configuration file + * @throws ConfigException error processing configuration + */ + public void parse(String path) throws ConfigException { + LOG.info("Reading configuration from: " + path); + + try { + File configFile = (new VerifyingFileFactory.Builder(LOG) + .warnForRelativePath() + .failForNonExistingPath() + .build()).create(path); + + Properties cfg = new Properties(); + FileInputStream in = new FileInputStream(configFile); + try { + cfg.load(in); + configFileStr = path; + } finally { + in.close(); + } + + parseProperties(cfg); + } catch (IOException e) { + throw new ConfigException("Error processing " + path, e); + } catch (IllegalArgumentException e) { + throw new ConfigException("Error processing " + path, e); + } + + if (dynamicConfigFileStr != null) { + try { + Properties dynamicCfg = new Properties(); + FileInputStream inConfig = new FileInputStream(dynamicConfigFileStr); + try { + dynamicCfg.load(inConfig); + if (dynamicCfg.getProperty("version") != null) { + throw new ConfigException("dynamic file shouldn't have version inside"); + } + + String version = getVersionFromFilename(dynamicConfigFileStr); + // If there isn't any version associated with the filename, + // the default version is 0. + if (version != null) { + dynamicCfg.setProperty("version", version); + } + } finally { + inConfig.close(); + } + setupQuorumPeerConfig(dynamicCfg, false); + + } catch (IOException e) { + throw new ConfigException("Error processing " + dynamicConfigFileStr, e); + } catch (IllegalArgumentException e) { + throw new ConfigException("Error processing " + dynamicConfigFileStr, e); + } + File nextDynamicConfigFile = new File(configFileStr + nextDynamicConfigFileSuffix); + if (nextDynamicConfigFile.exists()) { + try { + Properties dynamicConfigNextCfg = new Properties(); + FileInputStream inConfigNext = new FileInputStream(nextDynamicConfigFile); + try { + dynamicConfigNextCfg.load(inConfigNext); + } finally { + inConfigNext.close(); + } + boolean isHierarchical = false; + for (Entry entry : dynamicConfigNextCfg.entrySet()) { + String key = entry.getKey().toString().trim(); + if (key.startsWith("group") || key.startsWith("weight")) { + isHierarchical = true; + break; + } + } + lastSeenQuorumVerifier = createQuorumVerifier(dynamicConfigNextCfg, isHierarchical); + } catch (IOException e) { + LOG.warn("NextQuorumVerifier is initiated to null"); + } + } + } + } + + /** + * Parse config from a Properties. + * @param zkProp Properties to parse from. + * @throws IOException + * @throws ConfigException + */ + public void parseProperties(Properties zkProp) + throws IOException, ConfigException { + int clientPort = 0; + int secureClientPort = 0; + String clientPortAddress = null; + String secureClientPortAddress = null; + VerifyingFileFactory vff = new VerifyingFileFactory.Builder(LOG).warnForRelativePath().build(); + for (Entry entry : zkProp.entrySet()) { + String key = entry.getKey().toString().trim(); + String value = entry.getValue().toString().trim(); + if (key.equals("dataDir")) { + dataDir = vff.create(value); + } else if (key.equals("dataLogDir")) { + dataLogDir = vff.create(value); + } else if (key.equals("clientPort")) { + clientPort = Integer.parseInt(value); + } else if (key.equals("localSessionsEnabled")) { + localSessionsEnabled = Boolean.parseBoolean(value); + } else if (key.equals("localSessionsUpgradingEnabled")) { + localSessionsUpgradingEnabled = Boolean.parseBoolean(value); + } else if (key.equals("clientPortAddress")) { + clientPortAddress = value.trim(); + } else if (key.equals("secureClientPort")) { + secureClientPort = Integer.parseInt(value); + } else if (key.equals("secureClientPortAddress")) { + secureClientPortAddress = value.trim(); + } else if (key.equals("tickTime")) { + tickTime = Integer.parseInt(value); + } else if (key.equals("maxClientCnxns")) { + maxClientCnxns = Integer.parseInt(value); + } else if (key.equals("minSessionTimeout")) { + minSessionTimeout = Integer.parseInt(value); + } else if (key.equals("maxSessionTimeout")) { + maxSessionTimeout = Integer.parseInt(value); + } else if (key.equals("initLimit")) { + initLimit = Integer.parseInt(value); + } else if (key.equals("syncLimit")) { + syncLimit = Integer.parseInt(value); + } else if (key.equals("electionAlg")) { + electionAlg = Integer.parseInt(value); + } else if (key.equals("quorumListenOnAllIPs")) { + quorumListenOnAllIPs = Boolean.parseBoolean(value); + } else if (key.equals("peerType")) { + if (value.toLowerCase().equals("observer")) { + peerType = LearnerType.OBSERVER; + } else if (value.toLowerCase().equals("participant")) { + peerType = LearnerType.PARTICIPANT; + } else { + throw new ConfigException("Unrecognised peertype: " + value); + } + } else if (key.equals("syncEnabled")) { + syncEnabled = Boolean.parseBoolean(value); + } else if (key.equals("dynamicConfigFile")) { + dynamicConfigFileStr = value; + } else if (key.equals("autopurge.snapRetainCount")) { + snapRetainCount = Integer.parseInt(value); + } else if (key.equals("autopurge.purgeInterval")) { + purgeInterval = Integer.parseInt(value); + } else if (key.equals("standaloneEnabled")) { + if (value.toLowerCase().equals("true")) { + setStandaloneEnabled(true); + } else if (value.toLowerCase().equals("false")) { + setStandaloneEnabled(false); + } else { + throw new ConfigException("Invalid option for standalone mode. Choose 'true' or 'false.'"); + } + } else if ((key.startsWith("server.") || key.startsWith("group") || key.startsWith("weight")) && zkProp.containsKey("dynamicConfigFile")) { + throw new ConfigException("parameter: " + key + " must be in a separate dynamic config file"); + } else { + System.setProperty("zookeeper." + key, value); + } + } + + // Reset to MIN_SNAP_RETAIN_COUNT if invalid (less than 3) + // PurgeTxnLog.purge(File, File, int) will not allow to purge less + // than 3. + if (snapRetainCount < MIN_SNAP_RETAIN_COUNT) { + LOG.warn("Invalid autopurge.snapRetainCount: " + snapRetainCount + + ". Defaulting to " + MIN_SNAP_RETAIN_COUNT); + snapRetainCount = MIN_SNAP_RETAIN_COUNT; + } + + if (dataDir == null) { + throw new IllegalArgumentException("dataDir is not set"); + } + if (dataLogDir == null) { + dataLogDir = dataDir; + } + + if (clientPort == 0) { + LOG.info("clientPort is not set"); + if (clientPortAddress != null) { + throw new IllegalArgumentException("clientPortAddress is set but clientPort is not set"); + } + } else if (clientPortAddress != null) { + this.clientPortAddress = new InetSocketAddress( + InetAddress.getByName(clientPortAddress), clientPort); + LOG.info("clientPortAddress is {}", this.clientPortAddress.toString()); + } else { + this.clientPortAddress = new InetSocketAddress(clientPort); + LOG.info("clientPortAddress is {}", this.clientPortAddress.toString()); + } + + if (secureClientPort == 0) { + LOG.info("secureClientPort is not set"); + if (secureClientPortAddress != null) { + throw new IllegalArgumentException("secureClientPortAddress is set but secureClientPort is not set"); + } + } else if (secureClientPortAddress != null) { + this.secureClientPortAddress = new InetSocketAddress( + InetAddress.getByName(secureClientPortAddress), secureClientPort); + LOG.info("secureClientPortAddress is {}", this.secureClientPortAddress.toString()); + } else { + this.secureClientPortAddress = new InetSocketAddress(secureClientPort); + LOG.info("secureClientPortAddress is {}", this.secureClientPortAddress.toString()); + } + + if (tickTime == 0) { + throw new IllegalArgumentException("tickTime is not set"); + } + + minSessionTimeout = minSessionTimeout == -1 ? tickTime * 2 : minSessionTimeout; + maxSessionTimeout = maxSessionTimeout == -1 ? tickTime * 20 : maxSessionTimeout; + + if (minSessionTimeout > maxSessionTimeout) { + throw new IllegalArgumentException( + "minSessionTimeout must not be larger than maxSessionTimeout"); + } + + // backward compatibility - dynamic configuration in the same file as + // static configuration params see writeDynamicConfig() + if (dynamicConfigFileStr == null) { + setupQuorumPeerConfig(zkProp, true); + if (isDistributed()) { + // we don't backup static config for standalone mode. + backupOldConfig(); + } + } + } + + /** + * Backward compatibility -- It would backup static config file on bootup + * if users write dynamic configuration in "zoo.cfg". + */ + private void backupOldConfig() throws IOException { + new AtomicFileWritingIdiom(new File(configFileStr + ".bak"), new OutputStreamStatement() { + @Override + public void write(OutputStream output) throws IOException { + InputStream input = null; + try { + input = new FileInputStream(new File(configFileStr)); + byte[] buf = new byte[1024]; + int bytesRead; + while ((bytesRead = input.read(buf)) > 0) { + output.write(buf, 0, bytesRead); + } + } finally { + if (input != null) { + input.close(); + } + } + } + }); + } + + void setupQuorumPeerConfig(Properties prop, boolean configBackwardCompatibilityMode) + throws IOException, ConfigException { + quorumVerifier = parseDynamicConfig(prop, electionAlg, true, configBackwardCompatibilityMode); + setupMyId(); + setupClientPort(); + setupPeerType(); + checkValidity(); + } + + private void setupMyId() throws IOException { + File myIdFile = new File(dataDir, "myid"); + // standalone server doesn't need myid file. + if (!myIdFile.isFile()) { + return; + } + BufferedReader br = new BufferedReader(new FileReader(myIdFile)); + String myIdString; + try { + myIdString = br.readLine(); + } finally { + br.close(); + } + try { + serverId = Long.parseLong(myIdString); + MDC.put("myid", myIdString); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("serverid " + myIdString + + " is not a number"); + } + } + + private void setupClientPort() throws ConfigException { + if (serverId == UNSET_SERVERID) { + return; + } + QuorumServer qs = quorumVerifier.getAllMembers().get(serverId); + if (clientPortAddress != null && qs != null && qs.clientAddr != null) { + if ((!clientPortAddress.getAddress().isAnyLocalAddress() + && !clientPortAddress.equals(qs.clientAddr)) || + (clientPortAddress.getAddress().isAnyLocalAddress() + && clientPortAddress.getPort() != qs.clientAddr.getPort())) + throw new ConfigException("client address for this server (id = " + serverId + + ") in static config file is " + clientPortAddress + + " is different from client address found in dynamic file: " + qs.clientAddr); + } + if (qs != null && qs.clientAddr != null) clientPortAddress = qs.clientAddr; + } + + private void setupPeerType() { + // Warn about inconsistent peer type + LearnerType roleByServersList = quorumVerifier.getObservingMembers().containsKey(serverId) ? LearnerType.OBSERVER + : LearnerType.PARTICIPANT; + if (roleByServersList != peerType) { + LOG.warn("Peer type from servers list (" + roleByServersList + + ") doesn't match peerType (" + peerType + + "). Defaulting to servers list."); + + peerType = roleByServersList; + } + } + + public void checkValidity() throws IOException, ConfigException { + if (isDistributed()) { + if (initLimit == 0) { + throw new IllegalArgumentException("initLimit is not set"); + } + if (syncLimit == 0) { + throw new IllegalArgumentException("syncLimit is not set"); + } + if (serverId == UNSET_SERVERID) { + throw new IllegalArgumentException("myid file is missing"); + } + } + } + + public InetSocketAddress getClientPortAddress() { + return clientPortAddress; + } + + public InetSocketAddress getSecureClientPortAddress() { + return secureClientPortAddress; + } + + public File getDataDir() { + return dataDir; + } + + public File getDataLogDir() { + return dataLogDir; + } + + public int getTickTime() { + return tickTime; + } + + public int getMaxClientCnxns() { + return maxClientCnxns; + } + + public int getMinSessionTimeout() { + return minSessionTimeout; + } + + public int getMaxSessionTimeout() { + return maxSessionTimeout; + } + + public boolean areLocalSessionsEnabled() { + return localSessionsEnabled; + } + + public boolean isLocalSessionsUpgradingEnabled() { + return localSessionsUpgradingEnabled; + } + + public int getInitLimit() { + return initLimit; + } + + public int getSyncLimit() { + return syncLimit; + } + + public int getElectionAlg() { + return electionAlg; + } + + public int getElectionPort() { + return electionPort; + } + + public int getSnapRetainCount() { + return snapRetainCount; + } + + public int getPurgeInterval() { + return purgeInterval; + } + + public boolean getSyncEnabled() { + return syncEnabled; + } + + public QuorumVerifier getQuorumVerifier() { + return quorumVerifier; + } + + public QuorumVerifier getLastSeenQuorumVerifier() { + return lastSeenQuorumVerifier; + } + + public Map getServers() { + // returns all configuration servers -- participants and observers + return Collections.unmodifiableMap(quorumVerifier.getAllMembers()); + } + + public long getServerId() { + return serverId; + } + + public boolean isDistributed() { + return quorumVerifier != null && (!standaloneEnabled || quorumVerifier.getVotingMembers().size() > 1); + } + + public LearnerType getPeerType() { + return peerType; + } + + public String getConfigFilename() { + return configFileStr; + } + + public Boolean getQuorumListenOnAllIPs() { + return quorumListenOnAllIPs; + } + + @SuppressWarnings("serial") + public static class ConfigException extends Exception { + public ConfigException(String msg) { + super(msg); + } + + public ConfigException(String msg, Exception e) { + super(msg, e); + } + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java new file mode 100644 index 00000000000..0ab018b8ff0 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java @@ -0,0 +1,182 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.ManagedUtil; +import org.apache.zookeeper.server.DatadirCleanupManager; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServerMain; +import org.apache.zookeeper.server.admin.AdminServer.AdminServerException; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog.DatadirException; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +import javax.management.JMException; + +/** + * + *

        Configuration file

        + * + * When the main() method of this class is used to start the program, the first + * argument is used as a path to the config file, which will be used to obtain + * configuration information. This file is a Properties file, so keys and + * values are separated by equals (=) and the key/value pairs are separated + * by new lines. The following is a general summary of keys used in the + * configuration file. For full details on this see the documentation in + * docs/index.html + *
          + *
        1. dataDir - The directory where the ZooKeeper data is stored.
        2. + *
        3. dataLogDir - The directory where the ZooKeeper transaction log is stored.
        4. + *
        5. clientPort - The port used to communicate with clients.
        6. + *
        7. tickTime - The duration of a tick in milliseconds. This is the basic + * unit of time in ZooKeeper.
        8. + *
        9. initLimit - The maximum number of ticks that a follower will wait to + * initially synchronize with a leader.
        10. + *
        11. syncLimit - The maximum number of ticks that a follower will wait for a + * message (including heartbeats) from the leader.
        12. + *
        13. server.id - This is the host:port[:port] that the server with the + * given id will use for the quorum protocol.
        14. + *
        + * In addition to the config file. There is a file in the data directory called + * "myid" that contains the server id as an ASCII decimal value. + * + */ +public class QuorumPeerMain { + private static final Logger LOG = LoggerFactory.getLogger(QuorumPeerMain.class); + + private static final String USAGE = "Usage: QuorumPeerMain configfile"; + + protected QuorumPeer quorumPeer; + + /** + * To start the replicated server specify the configuration file name on + * the command line. + * @param args path to the configfile + */ + public static void main(String[] args) { + QuorumPeerMain main = new QuorumPeerMain(); + try { + main.initializeAndRun(args); + } catch (IllegalArgumentException e) { + LOG.error("Invalid arguments, exiting abnormally", e); + LOG.info(USAGE); + System.err.println(USAGE); + System.exit(2); + } catch (ConfigException e) { + LOG.error("Invalid config, exiting abnormally", e); + System.err.println("Invalid config, exiting abnormally"); + System.exit(2); + } catch (DatadirException e) { + LOG.error("Unable to access datadir, exiting abnormally", e); + System.err.println("Unable to access datadir, exiting abnormally"); + System.exit(3); + } catch (AdminServerException e) { + LOG.error("Unable to start AdminServer, exiting abnormally", e); + System.err.println("Unable to start AdminServer, exiting abnormally"); + System.exit(4); + } catch (Exception e) { + LOG.error("Unexpected exception, exiting abnormally", e); + System.exit(1); + } + LOG.info("Exiting normally"); + System.exit(0); + } + + protected void initializeAndRun(String[] args) + throws ConfigException, IOException, AdminServerException { + QuorumPeerConfig config = new QuorumPeerConfig(); + if (args.length == 1) { + config.parse(args[0]); + } + + // Start and schedule the the purge task + DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config + .getDataDir(), config.getDataLogDir(), config + .getSnapRetainCount(), config.getPurgeInterval()); + purgeMgr.start(); + + if (args.length == 1 && config.isDistributed()) { + runFromConfig(config); + } else { + LOG.warn("Either no config or no quorum defined in config, running " + + " in standalone mode"); + // there is only server in the quorum -- run as standalone + ZooKeeperServerMain.main(args); + } + } + + public void runFromConfig(QuorumPeerConfig config) throws IOException, AdminServerException { + try { + ManagedUtil.registerLog4jMBeans(); + } catch (JMException e) { + LOG.warn("Unable to register log4j JMX control", e); + } + + LOG.info("Starting quorum peer"); + try { + ServerCnxnFactory cnxnFactory = null; + ServerCnxnFactory secureCnxnFactory = null; + + if (config.getClientPortAddress() != null) { + cnxnFactory = ServerCnxnFactory.createFactory(); + cnxnFactory.configure(config.getClientPortAddress(), + config.getMaxClientCnxns(), + false); + } + + if (config.getSecureClientPortAddress() != null) { + secureCnxnFactory = ServerCnxnFactory.createFactory(); + secureCnxnFactory.configure(config.getSecureClientPortAddress(), + config.getMaxClientCnxns(), + true); + } + + quorumPeer = new QuorumPeer(); + quorumPeer.setTxnFactory(new FileTxnSnapLog( + config.getDataLogDir(), + config.getDataDir())); + quorumPeer.enableLocalSessions(config.areLocalSessionsEnabled()); + quorumPeer.enableLocalSessionsUpgrading( + config.isLocalSessionsUpgradingEnabled()); + //quorumPeer.setQuorumPeers(config.getAllMembers()); + quorumPeer.setElectionType(config.getElectionAlg()); + quorumPeer.setMyid(config.getServerId()); + quorumPeer.setTickTime(config.getTickTime()); + quorumPeer.setMinSessionTimeout(config.getMinSessionTimeout()); + quorumPeer.setMaxSessionTimeout(config.getMaxSessionTimeout()); + quorumPeer.setInitLimit(config.getInitLimit()); + quorumPeer.setSyncLimit(config.getSyncLimit()); + quorumPeer.setConfigFileName(config.getConfigFilename()); + quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory())); + quorumPeer.setQuorumVerifier(config.getQuorumVerifier(), false); + if (config.getLastSeenQuorumVerifier() != null) { + quorumPeer.setLastSeenQuorumVerifier(config.getLastSeenQuorumVerifier(), false); + } + quorumPeer.initConfigInZKDatabase(); + quorumPeer.setCnxnFactory(cnxnFactory); + quorumPeer.setSecureCnxnFactory(secureCnxnFactory); + quorumPeer.setLearnerType(config.getPeerType()); + quorumPeer.setSyncEnabled(config.getSyncEnabled()); + quorumPeer.setQuorumListenOnAllIPs(config.getQuorumListenOnAllIPs()); + + quorumPeer.start(); + quorumPeer.join();//main线程等待quorumPeer线程退出 + } catch (InterruptedException e) { + // warn, but generally this is ok + LOG.warn("Quorum Peer interrupted", e); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumStats.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumStats.java new file mode 100644 index 00000000000..95995269adb --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumStats.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +public class QuorumStats { + private final Provider provider; + + protected QuorumStats(Provider provider) { + this.provider = provider; + } + + public String getServerState() { + return provider.getServerState(); + } + + public String[] getQuorumPeers() { + return provider.getQuorumPeers(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()); + String state = getServerState(); + if (state.equals(Provider.LEADING_STATE)) { + sb.append("Followers:"); + for (String f : getQuorumPeers()) { + sb.append(" ").append(f); + } + sb.append("\n"); + } else if (state.equals(Provider.FOLLOWING_STATE) + || state.equals(Provider.OBSERVING_STATE)) { + sb.append("Leader: "); + String[] ldr = getQuorumPeers(); + if (ldr.length > 0) + sb.append(ldr[0]); + else + sb.append("not connected"); + sb.append("\n"); + } + return sb.toString(); + } + + public interface Provider { + static public final String UNKNOWN_STATE = "unknown"; + static public final String LOOKING_STATE = "leaderelection"; + static public final String LEADING_STATE = "leading"; + static public final String FOLLOWING_STATE = "following"; + static public final String OBSERVING_STATE = "observing"; + + public String[] getQuorumPeers(); + + public String getServerState(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java new file mode 100644 index 00000000000..52ed9f0c511 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java @@ -0,0 +1,151 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.server.ByteBufferInputStream; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; + +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.ByteBuffer; + +/** + * Abstract base class for all ZooKeeperServers that participate in + * a quorum. + */ +public abstract class QuorumZooKeeperServer extends ZooKeeperServer { + + public final QuorumPeer self; + protected UpgradeableSessionTracker upgradeableSessionTracker; + + protected QuorumZooKeeperServer(FileTxnSnapLog logFactory, int tickTime, + int minSessionTimeout, int maxSessionTimeout, + ZKDatabase zkDb, QuorumPeer self) { + super(logFactory, tickTime, minSessionTimeout, maxSessionTimeout, zkDb); + this.self = self; + } + + @Override + protected void startSessionTracker() { + upgradeableSessionTracker = (UpgradeableSessionTracker) sessionTracker; + upgradeableSessionTracker.start(); + } + + public Request checkUpgradeSession(Request request) + throws IOException, KeeperException { + // If this is a request for a local session and it is to + // create an ephemeral node, then upgrade the session and return + // a new session request for the leader. + // This is called by the request processor thread (either follower + // or observer request processor), which is unique to a learner. + // So will not be called concurrently by two threads. + if (request.type != OpCode.create || + !upgradeableSessionTracker.isLocalSession(request.sessionId)) { + return null; + } + CreateRequest createRequest = new CreateRequest(); + request.request.rewind(); + ByteBufferInputStream.byteBuffer2Record(request.request, createRequest); + request.request.rewind(); + CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); + if (!createMode.isEphemeral()) { + return null; + } + // Uh oh. We need to upgrade before we can proceed. + if (!self.isLocalSessionsUpgradingEnabled()) { + throw new KeeperException.EphemeralOnLocalSessionException(); + } + + return makeUpgradeRequest(request.sessionId); + } + + private Request makeUpgradeRequest(long sessionId) { + // Make sure to atomically check local session status, upgrade + // session, and make the session creation request. This is to + // avoid another thread upgrading the session in parallel. + synchronized (upgradeableSessionTracker) { + if (upgradeableSessionTracker.isLocalSession(sessionId)) { + int timeout = upgradeableSessionTracker.upgradeSession(sessionId); + ByteBuffer to = ByteBuffer.allocate(4); + to.putInt(timeout); + return new Request( + null, sessionId, 0, OpCode.createSession, to, null); + } + } + return null; + } + + /** + * Implements the SessionUpgrader interface, + * + * @param sessionId + */ + public void upgrade(long sessionId) { + Request request = makeUpgradeRequest(sessionId); + if (request != null) { + LOG.info("Upgrading session 0x" + Long.toHexString(sessionId)); + // This must be a global request + submitRequest(request); + } + } + + @Override + protected void setLocalSessionFlag(Request si) { + // We need to set isLocalSession to tree for these type of request + // so that the request processor can process them correctly. + switch (si.type) { + case OpCode.createSession: + if (self.areLocalSessionsEnabled()) { + // All new sessions local by default. + si.setLocalSession(true); + } + break; + case OpCode.closeSession: + String reqType = "global"; + if (upgradeableSessionTracker.isLocalSession(si.sessionId)) { + si.setLocalSession(true); + reqType = "local"; + } + LOG.info("Submitting " + reqType + " closeSession request" + + " for session 0x" + Long.toHexString(si.sessionId)); + break; + default: + break; + } + } + + @Override + public void dumpConf(PrintWriter pwriter) { + super.dumpConf(pwriter); + + pwriter.print("initLimit="); + pwriter.println(self.getInitLimit()); + pwriter.print("syncLimit="); + pwriter.println(self.getSyncLimit()); + pwriter.print("electionAlg="); + pwriter.println(self.getElectionType()); + pwriter.print("electionPort="); + pwriter.println(self.getElectionAddress().getPort()); + pwriter.print("quorumPort="); + pwriter.println(self.getQuorumAddress().getPort()); + pwriter.print("peerType="); + pwriter.println(self.getLearnerType().ordinal()); + pwriter.println("membership: "); + pwriter.print(new String(self.getQuorumVerifier().toString().getBytes())); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyBean.java b/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyBean.java new file mode 100644 index 00000000000..a0b3087d6ea --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyBean.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.ZooKeeperServerBean; + +/** + * ReadOnly MX Bean interface, implemented by ReadOnlyBean + * + */ +public class ReadOnlyBean extends ZooKeeperServerBean { + + public ReadOnlyBean(ZooKeeperServer zks) { + super(zks); + } + + public String getName() { + return "ReadOnlyServer"; + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java new file mode 100644 index 00000000000..32c6077a8b8 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java @@ -0,0 +1,124 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.ZooKeeperCriticalThread; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.server.quorum.Leader.XidRolloverException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * This processor is at the beginning of the ReadOnlyZooKeeperServer's + * processors chain. All it does is, it passes read-only operations (e.g. + * OpCode.getData, OpCode.exists) through to the next processor, but drops + * state-changing operations (e.g. OpCode.create, OpCode.setData). + */ +public class ReadOnlyRequestProcessor extends ZooKeeperCriticalThread implements + RequestProcessor { + + private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyRequestProcessor.class); + + private final LinkedBlockingQueue queuedRequests = new LinkedBlockingQueue(); + private final RequestProcessor nextProcessor; + private final ZooKeeperServer zks; + private boolean finished = false; + + public ReadOnlyRequestProcessor(ZooKeeperServer zks, + RequestProcessor nextProcessor) { + super("ReadOnlyRequestProcessor:" + zks.getServerId(), zks + .getZooKeeperServerListener()); + this.zks = zks; + this.nextProcessor = nextProcessor; + } + + public void run() { + try { + while (!finished) { + Request request = queuedRequests.take(); + + // log request + long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; + if (request.type == OpCode.ping) { + traceMask = ZooTrace.CLIENT_PING_TRACE_MASK; + } + if (LOG.isTraceEnabled()) { + ZooTrace.logRequest(LOG, traceMask, 'R', request, ""); + } + if (Request.requestOfDeath == request) { + break; + } + + // filter read requests + switch (request.type) { + case OpCode.sync: + case OpCode.create: + case OpCode.create2: + case OpCode.createContainer: + case OpCode.delete: + case OpCode.deleteContainer: + case OpCode.setData: + case OpCode.reconfig: + case OpCode.setACL: + case OpCode.multi: + case OpCode.check: + ReplyHeader hdr = new ReplyHeader(request.cxid, zks.getZKDatabase() + .getDataTreeLastProcessedZxid(), Code.NOTREADONLY.intValue()); + try { + request.cnxn.sendResponse(hdr, null, null); + } catch (IOException e) { + LOG.error("IO exception while sending response", e); + } + continue; + } + + // proceed to the next processor + if (nextProcessor != null) { + nextProcessor.processRequest(request); + } + } + } catch (RequestProcessorException e) { + if (e.getCause() instanceof XidRolloverException) { + LOG.info(e.getCause().getMessage()); + } + handleException(this.getName(), e); + } catch (Exception e) { + handleException(this.getName(), e); + } + LOG.info("ReadOnlyRequestProcessor exited loop!"); + } + + @Override + public void processRequest(Request request) { + if (!finished) { + queuedRequests.add(request); + } + } + + @Override + public void shutdown() { + finished = true; + queuedRequests.clear(); + queuedRequests.add(Request.requestOfDeath); + nextProcessor.shutdown(); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServer.java new file mode 100644 index 00000000000..a88b03ee20f --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServer.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.server.DataTreeBean; +import org.apache.zookeeper.server.FinalRequestProcessor; +import org.apache.zookeeper.server.PrepRequestProcessor; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.ZooKeeperServerBean; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; + +import java.io.PrintWriter; + +/** + * A ZooKeeperServer which comes into play when peer is partitioned from the + * majority. Handles read-only clients, but drops connections from not-read-only + * ones. + *

        + * The very first processor in the chain of request processors is a + * ReadOnlyRequestProcessor which drops state-changing requests. + */ +public class ReadOnlyZooKeeperServer extends ZooKeeperServer { + + protected final QuorumPeer self; + private volatile boolean shutdown = false; + + ReadOnlyZooKeeperServer(FileTxnSnapLog logFactory, QuorumPeer self, + ZKDatabase zkDb) { + super(logFactory, self.tickTime, self.minSessionTimeout, + self.maxSessionTimeout, zkDb); + this.self = self; + } + + @Override + protected void setupRequestProcessors() { + RequestProcessor finalProcessor = new FinalRequestProcessor(this); + RequestProcessor prepProcessor = new PrepRequestProcessor(this, finalProcessor); + ((PrepRequestProcessor) prepProcessor).start(); + firstProcessor = new ReadOnlyRequestProcessor(this, prepProcessor); + ((ReadOnlyRequestProcessor) firstProcessor).start(); + } + + @Override + public synchronized void startup() { + // check to avoid startup follows shutdown + if (shutdown) { + LOG.warn("Not starting Read-only server as startup follows shutdown!"); + return; + } + registerJMX(new ReadOnlyBean(this), self.jmxLocalPeerBean); + super.startup(); + self.setZooKeeperServer(this); + self.adminServer.setZooKeeperServer(this); + LOG.info("Read-only server started"); + } + + @Override + protected void registerJMX() { + // register with JMX + try { + jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); + MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxDataTreeBean = null; + } + } + + public void registerJMX(ZooKeeperServerBean serverBean, LocalPeerBean localPeerBean) { + // register with JMX + try { + jmxServerBean = serverBean; + MBeanRegistry.getInstance().register(serverBean, localPeerBean); + } catch (Exception e) { + LOG.warn("Failed to register with JMX", e); + jmxServerBean = null; + } + } + + @Override + protected void unregisterJMX() { + // unregister from JMX + try { + if (jmxDataTreeBean != null) { + MBeanRegistry.getInstance().unregister(jmxDataTreeBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + jmxDataTreeBean = null; + } + + protected void unregisterJMX(ZooKeeperServer zks) { + // unregister from JMX + try { + if (jmxServerBean != null) { + MBeanRegistry.getInstance().unregister(jmxServerBean); + } + } catch (Exception e) { + LOG.warn("Failed to unregister with JMX", e); + } + jmxServerBean = null; + } + + @Override + public String getState() { + return "read-only"; + } + + /** + * Returns the id of the associated QuorumPeer, which will do for a unique + * id of this server. + */ + @Override + public long getServerId() { + return self.getId(); + } + + @Override + public synchronized void shutdown() { + if (!isRunning()) { + LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); + return; + } + shutdown = true; + unregisterJMX(this); + + // set peer's server to null + self.setZooKeeperServer(null); + // clear all the connections + self.closeAllConnections(); + + self.adminServer.setZooKeeperServer(null); + + // shutdown the server itself + super.shutdown(); + } + + @Override + public void dumpConf(PrintWriter pwriter) { + super.dumpConf(pwriter); + + pwriter.print("initLimit="); + pwriter.println(self.getInitLimit()); + pwriter.print("syncLimit="); + pwriter.println(self.getSyncLimit()); + pwriter.print("electionAlg="); + pwriter.println(self.getElectionType()); + pwriter.print("electionPort="); + pwriter.println(self.getElectionAddress().getPort()); + pwriter.print("quorumPort="); + pwriter.println(self.getQuorumAddress().getPort()); + pwriter.print("peerType="); + pwriter.println(self.getLearnerType().ordinal()); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerBean.java b/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerBean.java new file mode 100644 index 00000000000..74a0b559126 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerBean.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.ZKMBeanInfo; + +/** + * A remote peer bean only provides limited information about the remote peer, + * and the peer cannot be managed remotely. + */ +public class RemotePeerBean implements RemotePeerMXBean, ZKMBeanInfo { + private QuorumPeer.QuorumServer peer; + + public RemotePeerBean(QuorumPeer.QuorumServer peer) { + this.peer = peer; + } + + public void setQuorumServer(QuorumPeer.QuorumServer peer) { + this.peer = peer; + } + + public String getName() { + return "replica." + peer.id; + } + + public boolean isHidden() { + return false; + } + + public String getQuorumAddress() { + return peer.addr.getHostString() + ":" + peer.addr.getPort(); + } + + public String getElectionAddress() { + return peer.electionAddr.getHostString() + ":" + peer.electionAddr.getPort(); + } + + public String getClientAddress() { + if (null == peer.clientAddr) { + return ""; + } + return peer.clientAddr.getHostString() + ":" + + peer.clientAddr.getPort(); + } + + public String getLearnerType() { + return peer.type.toString(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerMXBean.java new file mode 100644 index 00000000000..e132a19a3f5 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerMXBean.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +/** + * A proxy for a remote quorum peer. + */ +public interface RemotePeerMXBean { + /** + * @return name of the peer + */ + public String getName(); + + /** + * @return IP address of the quorum peer + */ + public String getQuorumAddress(); + + /** + * @return the election address + */ + public String getElectionAddress(); + + /** + * @return the client address + */ + public String getClientAddress(); + + /** + * @return the learner type + */ + public String getLearnerType(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/SendAckRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/quorum/SendAckRequestProcessor.java new file mode 100644 index 00000000000..dd04514af50 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/SendAckRequestProcessor.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Flushable; +import java.io.IOException; + +public class SendAckRequestProcessor implements RequestProcessor, Flushable { + private static final Logger LOG = LoggerFactory.getLogger(SendAckRequestProcessor.class); + + Learner learner; + + SendAckRequestProcessor(Learner peer) { + this.learner = peer; + } + + public void processRequest(Request si) { + if (si.type != OpCode.sync) { + QuorumPacket qp = new QuorumPacket(Leader.ACK, si.getHdr().getZxid(), null, null); + try { + learner.writePacket(qp, false); + } catch (IOException e) { + LOG.warn("Closing connection to leader, exception during packet send", e); + try { + if (!learner.sock.isClosed()) { + learner.sock.close(); + } + } catch (IOException e1) { + // Nothing to do, we are shutting things down, so an exception here is irrelevant + LOG.debug("Ignoring error closing the connection", e1); + } + } + } + } + + public void flush() throws IOException { + try { + learner.writePacket(null, true); + } catch (IOException e) { + LOG.warn("Closing connection to leader, exception during packet send", e); + try { + if (!learner.sock.isClosed()) { + learner.sock.close(); + } + } catch (IOException e1) { + // Nothing to do, we are shutting things down, so an exception here is irrelevant + LOG.debug("Ignoring error closing the connection", e1); + } + } + } + + public void shutdown() { + // Nothing needed + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ServerBean.java b/src/java/main/org/apache/zookeeper/server/quorum/ServerBean.java new file mode 100644 index 00000000000..679e6226cba --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ServerBean.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.jmx.ZKMBeanInfo; + +import java.util.Date; + +/** + * An abstract base class for the leader and follower MBeans. + */ +public abstract class ServerBean implements ServerMXBean, ZKMBeanInfo { + private final Date startTime = new Date(); + + public boolean isHidden() { + return false; + } + + public String getStartTime() { + return startTime.toString(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/ServerMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/ServerMXBean.java new file mode 100644 index 00000000000..1a089defe9d --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/ServerMXBean.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +/** + * A quorum server MBean. + */ +public interface ServerMXBean { + /** + * @return name of the server MBean + */ + public String getName(); + + /** + * @return the start time the server + */ + public String getStartTime(); +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/SnapshotThrottleException.java b/src/java/main/org/apache/zookeeper/server/quorum/SnapshotThrottleException.java new file mode 100644 index 00000000000..8923ed7d843 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/SnapshotThrottleException.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +/** + * Thrown when a {@link Leader} has too many concurrent snapshots being sent + * to observers. + * + * @see LearnerSnapshotThrottler + * + */ +public class SnapshotThrottleException extends Exception { + private static final long serialVersionUID = 1L; + + public SnapshotThrottleException(int concurrentSnapshotNumber, int throttleThreshold) { + super(getMessage(concurrentSnapshotNumber, throttleThreshold)); + } + + private static String getMessage(int concurrentSnapshotNumber, int throttleThreshold) { + return String.format("new snapshot would make %d concurrently in progress; " + + "maximum is %d", concurrentSnapshotNumber, throttleThreshold); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/StateSummary.java b/src/java/main/org/apache/zookeeper/server/quorum/StateSummary.java new file mode 100644 index 00000000000..db831fa8155 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/StateSummary.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +/** + * This class encapsulates the state comparison logic. Specifically, + * how two different states are compared. + */ +public class StateSummary { + private long currentEpoch; + private long lastZxid; + + public StateSummary(long currentEpoch, long lastZxid) { + this.currentEpoch = currentEpoch; + this.lastZxid = lastZxid; + } + + public long getCurrentEpoch() { + return currentEpoch; + } + + public long getLastZxid() { + return lastZxid; + } + + public boolean isMoreRecentThan(StateSummary ss) { + return (currentEpoch > ss.currentEpoch) || (currentEpoch == ss.currentEpoch && lastZxid > ss.lastZxid); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof StateSummary)) { + return false; + } + StateSummary ss = (StateSummary) obj; + return currentEpoch == ss.currentEpoch && lastZxid == ss.lastZxid; + } + + @Override + public int hashCode() { + return (int) (currentEpoch ^ lastZxid); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/SyncedLearnerTracker.java b/src/java/main/org/apache/zookeeper/server/quorum/SyncedLearnerTracker.java new file mode 100644 index 00000000000..783c620ed71 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/SyncedLearnerTracker.java @@ -0,0 +1,73 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; + +import java.util.ArrayList; +import java.util.HashSet; + +public class SyncedLearnerTracker { + + protected ArrayList qvAcksetPairs = new ArrayList(); + + public void addQuorumVerifier(QuorumVerifier qv) { + qvAcksetPairs.add(new QuorumVerifierAcksetPair(qv, new HashSet(qv.getVotingMembers().size()))); + } + + public boolean addAck(Long sid) { + boolean change = false; + for (QuorumVerifierAcksetPair qvAckset : qvAcksetPairs) { + if (qvAckset.getQuorumVerifier().getVotingMembers().containsKey(sid)) { + qvAckset.getAckset().add(sid); + change = true; + } + } + return change; + } + + public boolean hasAllQuorums() { + for (QuorumVerifierAcksetPair qvAckset : qvAcksetPairs) { + if (!qvAckset.getQuorumVerifier().containsQuorum(qvAckset.getAckset())) + return false; + } + return true; + } + + public String ackSetsToString() { + StringBuilder sb = new StringBuilder(); + + for (QuorumVerifierAcksetPair qvAckset : qvAcksetPairs) { + sb.append(qvAckset.getAckset().toString()).append(","); + } + + return sb.substring(0, sb.length() - 1); + } + + public static class QuorumVerifierAcksetPair { + private final QuorumVerifier qv; + private final HashSet ackset; + + public QuorumVerifierAcksetPair(QuorumVerifier qv, HashSet ackset) { + this.qv = qv; + this.ackset = ackset; + } + + public QuorumVerifier getQuorumVerifier() { + return this.qv; + } + + public HashSet getAckset() { + return this.ackset; + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/UpgradeableSessionTracker.java b/src/java/main/org/apache/zookeeper/server/quorum/UpgradeableSessionTracker.java new file mode 100644 index 00000000000..110d7e7f1d6 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/UpgradeableSessionTracker.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.server.SessionTracker; +import org.apache.zookeeper.server.ZooKeeperServerListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * A session tracker that supports upgradeable local sessions. + */ +public abstract class UpgradeableSessionTracker implements SessionTracker { + private static final Logger LOG = LoggerFactory.getLogger(UpgradeableSessionTracker.class); + protected LocalSessionTracker localSessionTracker; + private ConcurrentMap localSessionsWithTimeouts; + + public void start() { + } + + public void createLocalSessionTracker(SessionExpirer expirer, + int tickTime, long id, ZooKeeperServerListener listener) { + this.localSessionsWithTimeouts = + new ConcurrentHashMap(); + this.localSessionTracker = new LocalSessionTracker( + expirer, this.localSessionsWithTimeouts, tickTime, id, listener); + } + + public boolean isTrackingSession(long sessionId) { + return isLocalSession(sessionId) || isGlobalSession(sessionId); + } + + public boolean isLocalSession(long sessionId) { + return localSessionTracker != null && + localSessionTracker.isTrackingSession(sessionId); + } + + abstract public boolean isGlobalSession(long sessionId); + + /** + * Upgrades the session to a global session. + * This simply removes the session from the local tracker and marks + * it as global. It is up to the caller to actually + * queue up a transaction for the session. + * + * @param sessionId + * @return session timeout (-1 if not a local session) + */ + public int upgradeSession(long sessionId) { + if (localSessionsWithTimeouts == null) { + return -1; + } + // We won't race another upgrade attempt because only one thread + // will get the timeout from the map + Integer timeout = localSessionsWithTimeouts.remove(sessionId); + if (timeout != null) { + LOG.info("Upgrading session 0x" + Long.toHexString(sessionId)); + // Add as global before removing as local + addGlobalSession(sessionId, timeout); + localSessionTracker.removeSession(sessionId); + return timeout; + } + return -1; + } + + public void checkGlobalSession(long sessionId, Object owner) + throws KeeperException.SessionExpiredException, + KeeperException.SessionMovedException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Vote.java b/src/java/main/org/apache/zookeeper/server/quorum/Vote.java new file mode 100644 index 00000000000..025e7f1e1f1 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/Vote.java @@ -0,0 +1,131 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; + + +public class Vote { + + final private int version; + final private long id; + final private long zxid; + final private long electionEpoch; + final private long peerEpoch; + final private ServerState state; + + public Vote(long id, + long zxid) { + this.version = 0x0; + this.id = id; + this.zxid = zxid; + this.electionEpoch = -1; + this.peerEpoch = -1; + this.state = ServerState.LOOKING; + } + + public Vote(long id, + long zxid, + long peerEpoch) { + this.version = 0x0; + this.id = id; + this.zxid = zxid; + this.electionEpoch = -1; + this.peerEpoch = peerEpoch; + this.state = ServerState.LOOKING; + } + + public Vote(long id, + long zxid, + long electionEpoch, + long peerEpoch) { + this.version = 0x0; + this.id = id; + this.zxid = zxid; + this.electionEpoch = electionEpoch; + this.peerEpoch = peerEpoch; + this.state = ServerState.LOOKING; + } + + public Vote(int version, + long id, + long zxid, + long electionEpoch, + long peerEpoch, + ServerState state) { + this.version = version; + this.id = id; + this.zxid = zxid; + this.electionEpoch = electionEpoch; + this.state = state; + this.peerEpoch = peerEpoch; + } + + public Vote(long id, + long zxid, + long electionEpoch, + long peerEpoch, + ServerState state) { + this.id = id; + this.zxid = zxid; + this.electionEpoch = electionEpoch; + this.state = state; + this.peerEpoch = peerEpoch; + this.version = 0x0; + } + + public int getVersion() { + return version; + } + + public long getId() { + return id; + } + + public long getZxid() { + return zxid; + } + + public long getElectionEpoch() { + return electionEpoch; + } + + public long getPeerEpoch() { + return peerEpoch; + } + + public ServerState getState() { + return state; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Vote)) { + return false; + } + Vote other = (Vote) o; + return (id == other.id + && zxid == other.zxid + && electionEpoch == other.electionEpoch + && peerEpoch == other.peerEpoch); + + } + + @Override + public int hashCode() { + return (int) (id & zxid); + } + + public String toString() { + return "(" + id + ", " + Long.toHexString(zxid) + ", " + Long.toHexString(peerEpoch) + ")"; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java b/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java new file mode 100644 index 00000000000..ef930fe773b --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java @@ -0,0 +1,372 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum.flexible; + +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; + + +/** + * This class implements a validator for hierarchical quorums. With this + * construction, zookeeper servers are split into disjoint groups, and + * each server has a weight. We obtain a quorum if we get more than half + * of the total weight of a group for a majority of groups. + * + * The configuration of quorums uses two parameters: group and weight. + * Groups are sets of ZooKeeper servers, and we set a group by passing + * a colon-separated list of server ids. It is also necessary to assign + * weights to server. Here is an example of a configuration that creates + * three groups and assigns a weight of 1 to each server: + * + * group.1=1:2:3 + * group.2=4:5:6 + * group.3=7:8:9 + * + * weight.1=1 + * weight.2=1 + * weight.3=1 + * weight.4=1 + * weight.5=1 + * weight.6=1 + * weight.7=1 + * weight.8=1 + * weight.9=1 + * + * Note that it is still necessary to define peers using the server keyword. + */ + +public class QuorumHierarchical implements QuorumVerifier { + private static final Logger LOG = LoggerFactory.getLogger(QuorumHierarchical.class); + + private HashMap serverWeight = new HashMap(); + private HashMap serverGroup = new HashMap(); + private HashMap groupWeight = new HashMap(); + + private int numGroups = 0; + + private Map allMembers = new HashMap(); + private Map participatingMembers = new HashMap(); + private Map observingMembers = new HashMap(); + + private long version = 0; + + /** + * This contructor requires the quorum configuration + * to be declared in a separate file, and it takes the + * file as an input parameter. + */ + public QuorumHierarchical(String filename) + throws ConfigException { + readConfigFile(filename); + } + + /** + * This constructor takes a set of properties. We use + * it in the unit test for this feature. + */ + + public QuorumHierarchical(Properties qp) throws ConfigException { + parse(qp); + LOG.info(serverWeight.size() + ", " + serverGroup.size() + ", " + groupWeight.size()); + } + + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + + public boolean equals(Object o) { + if (!(o instanceof QuorumHierarchical)) { + return false; + } + QuorumHierarchical qm = (QuorumHierarchical) o; + if (qm.getVersion() == version) return true; + if ((allMembers.size() != qm.getAllMembers().size()) || + (serverWeight.size() != qm.serverWeight.size()) || + (groupWeight.size() != qm.groupWeight.size()) || + (serverGroup.size() != qm.serverGroup.size())) { + return false; + } + for (QuorumServer qs : allMembers.values()) { + QuorumServer qso = qm.getAllMembers().get(qs.id); + if (qso == null || !qs.equals(qso)) return false; + } + for (Long sid : serverWeight.keySet()) { + if (!serverWeight.get(sid).equals(qm.serverWeight.get(sid))) + return false; + } + for (Long sid : groupWeight.keySet()) { + if (!groupWeight.get(sid).equals(qm.groupWeight.get(sid))) + return false; + } + for (Long sid : serverGroup.keySet()) { + if (!serverGroup.get(sid).equals(qm.serverGroup.get(sid))) + return false; + } + return true; + } + + /** + * Returns the weight of a server. + * + * @param id + */ + public long getWeight(long id) { + return serverWeight.get(id); + } + + /** + * Reads a configration file. Called from the constructor + * that takes a file as an input. + */ + private void readConfigFile(String filename) + throws ConfigException { + File configFile = new File(filename); + + LOG.info("Reading configuration from: " + configFile); + + try { + if (!configFile.exists()) { + throw new IllegalArgumentException(configFile.toString() + + " file is missing"); + } + + Properties cfg = new Properties(); + FileInputStream in = new FileInputStream(configFile); + try { + cfg.load(in); + } finally { + in.close(); + } + + parse(cfg); + } catch (IOException e) { + throw new ConfigException("Error processing " + filename, e); + } catch (IllegalArgumentException e) { + throw new ConfigException("Error processing " + filename, e); + } + + } + + + /** + * Parse properties if configuration given in a separate file. + * Assumes that allMembers has been already assigned + * @throws ConfigException + */ + private void parse(Properties quorumProp) throws ConfigException { + for (Entry entry : quorumProp.entrySet()) { + String key = entry.getKey().toString(); + String value = entry.getValue().toString(); + + if (key.startsWith("server.")) { + int dot = key.indexOf('.'); + long sid = Long.parseLong(key.substring(dot + 1)); + QuorumServer qs = new QuorumServer(sid, value); + allMembers.put(Long.valueOf(sid), qs); + if (qs.type == LearnerType.PARTICIPANT) + participatingMembers.put(Long.valueOf(sid), qs); + else { + observingMembers.put(Long.valueOf(sid), qs); + } + } else if (key.startsWith("group")) { + int dot = key.indexOf('.'); + long gid = Long.parseLong(key.substring(dot + 1)); + + numGroups++; + + String parts[] = value.split(":"); + for (String s : parts) { + long sid = Long.parseLong(s); + if (serverGroup.containsKey(sid)) + throw new ConfigException("Server " + sid + "is in multiple groups"); + else + serverGroup.put(sid, gid); + } + + + } else if (key.startsWith("weight")) { + int dot = key.indexOf('.'); + long sid = Long.parseLong(key.substring(dot + 1)); + serverWeight.put(sid, Long.parseLong(value)); + } else if (key.equals("version")) { + version = Long.parseLong(value, 16); + } + } + + for (QuorumServer qs : allMembers.values()) { + Long id = qs.id; + if (qs.type == LearnerType.PARTICIPANT) { + if (!serverGroup.containsKey(id)) + throw new ConfigException("Server " + id + "is not in a group"); + if (!serverWeight.containsKey(id)) + serverWeight.put(id, (long) 1); + } + } + + + computeGroupWeight(); + } + + public Map getAllMembers() { + return allMembers; + } + + public String toString() { + StringWriter sw = new StringWriter(); + + for (QuorumServer member : getAllMembers().values()) { + String key = "server." + member.id; + String value = member.toString(); + sw.append(key); + sw.append('='); + sw.append(value); + sw.append('\n'); + } + + Map groups = new HashMap(); + for (Entry pair : serverGroup.entrySet()) { + Long sid = pair.getKey(); + Long gid = pair.getValue(); + String str = groups.get(gid); + if (str == null) str = sid.toString(); + else str = str.concat(":").concat(sid.toString()); + groups.put(gid, str); + } + + for (Entry pair : groups.entrySet()) { + Long gid = pair.getKey(); + String key = "group." + gid.toString(); + String value = pair.getValue(); + sw.append(key); + sw.append('='); + sw.append(value); + sw.append('\n'); + } + + + for (Entry pair : serverWeight.entrySet()) { + Long sid = pair.getKey(); + String key = "weight." + sid.toString(); + String value = pair.getValue().toString(); + sw.append(key); + sw.append('='); + sw.append(value); + sw.append('\n'); + } + + sw.append("version=" + Long.toHexString(version)); + + return sw.toString(); + } + + /** + * This method pre-computes the weights of groups to speed up processing + * when validating a given set. We compute the weights of groups in + * different places, so we have a separate method. + */ + private void computeGroupWeight() { + for (long sid : serverGroup.keySet()) { + Long gid = serverGroup.get(sid); + if (!groupWeight.containsKey(gid)) + groupWeight.put(gid, serverWeight.get(sid)); + else { + long totalWeight = serverWeight.get(sid) + groupWeight.get(gid); + groupWeight.put(gid, totalWeight); + } + } + + /* + * Do not consider groups with weight zero + */ + for (long weight : groupWeight.values()) { + LOG.debug("Group weight: " + weight); + if (weight == ((long) 0)) { + numGroups--; + LOG.debug("One zero-weight group: " + 1 + ", " + numGroups); + } + } + } + + /** + * Verifies if a given set is a quorum. + */ + public boolean containsQuorum(Set set) { + HashMap expansion = new HashMap(); + + /* + * Adds up weights per group + */ + if (set.size() == 0) return false; + else LOG.debug("Set size: " + set.size()); + + for (long sid : set) { + Long gid = serverGroup.get(sid); + if (gid == null) continue; + if (!expansion.containsKey(gid)) + expansion.put(gid, serverWeight.get(sid)); + else { + long totalWeight = serverWeight.get(sid) + expansion.get(gid); + expansion.put(gid, totalWeight); + } + } + + /* + * Check if all groups have majority + */ + int majGroupCounter = 0; + for (long gid : expansion.keySet()) { + LOG.debug("Group info: " + expansion.get(gid) + ", " + gid + ", " + groupWeight.get(gid)); + if (expansion.get(gid) > (groupWeight.get(gid) / 2)) + majGroupCounter++; + } + + LOG.debug("Majority group counter: " + majGroupCounter + ", " + numGroups); + if ((majGroupCounter > (numGroups / 2))) { + LOG.debug("Positive set size: " + set.size()); + return true; + } else { + LOG.debug("Negative set size: " + set.size()); + return false; + } + } + + public Map getVotingMembers() { + return participatingMembers; + } + + public Map getObservingMembers() { + return observingMembers; + } + + public long getVersion() { + return version; + } + + public void setVersion(long ver) { + version = ver; + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java b/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java new file mode 100644 index 00000000000..75e5e3cb312 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java @@ -0,0 +1,149 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum.flexible; + +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; + +/** + * This class implements a validator for majority quorums. The implementation is + * straightforward. + * + */ +public class QuorumMaj implements QuorumVerifier { + private Map allMembers = new HashMap(); + private HashMap votingMembers = new HashMap(); + private HashMap observingMembers = new HashMap(); + private long version = 0; + private int half; + + /** + * Defines a majority to avoid computing it every time. + * + */ + public QuorumMaj(Map allMembers) { + this.allMembers = allMembers; + for (QuorumServer qs : allMembers.values()) { + if (qs.type == LearnerType.PARTICIPANT) { + votingMembers.put(Long.valueOf(qs.id), qs); + } else { + observingMembers.put(Long.valueOf(qs.id), qs); + } + } + half = votingMembers.size() / 2; + } + + public QuorumMaj(Properties props) throws ConfigException { + for (Entry entry : props.entrySet()) { + String key = entry.getKey().toString(); + String value = entry.getValue().toString(); + + if (key.startsWith("server.")) { + int dot = key.indexOf('.'); + long sid = Long.parseLong(key.substring(dot + 1)); + QuorumServer qs = new QuorumServer(sid, value); + allMembers.put(Long.valueOf(sid), qs); + if (qs.type == LearnerType.PARTICIPANT) + votingMembers.put(Long.valueOf(sid), qs); + else { + observingMembers.put(Long.valueOf(sid), qs); + } + } else if (key.equals("version")) { + version = Long.parseLong(value, 16); + } + } + half = votingMembers.size() / 2; + } + + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + + public boolean equals(Object o) { + if (!(o instanceof QuorumMaj)) { + return false; + } + QuorumMaj qm = (QuorumMaj) o; + if (qm.getVersion() == version) + return true; + if (allMembers.size() != qm.getAllMembers().size()) + return false; + for (QuorumServer qs : allMembers.values()) { + QuorumServer qso = qm.getAllMembers().get(qs.id); + if (qso == null || !qs.equals(qso)) + return false; + } + return true; + } + + /** + * Returns weight of 1 by default. + * + * @param id + */ + public long getWeight(long id) { + return (long) 1; + } + + public String toString() { + StringBuilder sw = new StringBuilder(); + + for (QuorumServer member : getAllMembers().values()) { + String key = "server." + member.id; + String value = member.toString(); + sw.append(key); + sw.append('='); + sw.append(value); + sw.append('\n'); + } + String hexVersion = Long.toHexString(version); + sw.append("version="); + sw.append(hexVersion); + return sw.toString(); + } + + /** + * Verifies if a set is a majority. Assumes that ackSet contains acks only + * from votingMembers + */ + public boolean containsQuorum(Set ackSet) { + return (ackSet.size() > half); + } + + public Map getAllMembers() { + return allMembers; + } + + public Map getVotingMembers() { + return votingMembers; + } + + public Map getObservingMembers() { + return observingMembers; + } + + public long getVersion() { + return version; + } + + public void setVersion(long ver) { + version = ver; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java b/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java new file mode 100644 index 00000000000..5a65ccdf215 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum.flexible; + +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; + +import java.util.Map; +import java.util.Set; + +/** + * All quorum validators have to implement a method called + * containsQuorum, which verifies if a HashSet of server + * identifiers constitutes a quorum. + * + */ + +public interface QuorumVerifier { + long getWeight(long id); + + boolean containsQuorum(Set set); + + long getVersion(); + + void setVersion(long ver); + + Map getAllMembers(); + + Map getVotingMembers(); + + Map getObservingMembers(); + + boolean equals(Object o); + + String toString(); +} diff --git a/src/java/main/org/apache/zookeeper/server/util/ConfigUtils.java b/src/java/main/org/apache/zookeeper/server/util/ConfigUtils.java new file mode 100644 index 00000000000..e511a13cab9 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/util/ConfigUtils.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.util; + +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; + +import java.io.IOException; +import java.io.StringReader; +import java.util.Map.Entry; +import java.util.Properties; + + +public class ConfigUtils { + static public String getClientConfigStr(String configData) { + Properties props = new Properties(); + try { + props.load(new StringReader(configData)); + } catch (IOException e) { + e.printStackTrace(); + return ""; + } + StringBuffer sb = new StringBuffer(); + boolean first = true; + String version = ""; + for (Entry entry : props.entrySet()) { + String key = entry.getKey().toString().trim(); + String value = entry.getValue().toString().trim(); + if (key.equals("version")) version = value; + if (!key.startsWith("server.")) continue; + QuorumPeer.QuorumServer qs; + try { + qs = new QuorumPeer.QuorumServer(-1, value); + } catch (ConfigException e) { + e.printStackTrace(); + continue; + } + if (!first) sb.append(","); + else first = false; + sb.append(qs.clientAddr.getHostString() + ":" + qs.clientAddr.getPort()); + } + return version + " " + sb.toString(); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java b/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java new file mode 100644 index 00000000000..34f629e5f3f --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class KerberosUtil { + + public static String getDefaultRealm() + throws ClassNotFoundException, NoSuchMethodException, + IllegalArgumentException, IllegalAccessException, + InvocationTargetException { + Object kerbConf; + Class classRef; + Method getInstanceMethod; + Method getDefaultRealmMethod; + if (System.getProperty("java.vendor").contains("IBM")) { + classRef = Class.forName("com.ibm.security.krb5.internal.Config"); + } else { + classRef = Class.forName("sun.security.krb5.Config"); + } + getInstanceMethod = classRef.getMethod("getInstance", new Class[0]); + kerbConf = getInstanceMethod.invoke(classRef, new Object[0]); + getDefaultRealmMethod = classRef.getDeclaredMethod("getDefaultRealm", + new Class[0]); + return (String) getDefaultRealmMethod.invoke(kerbConf, new Object[0]); + } +} diff --git a/src/java/main/org/apache/zookeeper/server/util/OSMXBean.java b/src/java/main/org/apache/zookeeper/server/util/OSMXBean.java new file mode 100644 index 00000000000..1b9e6d01d07 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/util/OSMXBean.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; +import java.lang.management.RuntimeMXBean; +import java.lang.reflect.Method; + +/** + * This class is a wrapper for the implementation of + * com.sun.management.UnixOperatingSystemMXBean + * It will decide to use the sun api or its own implementation + * depending on the runtime (vendor) used. + */ +public class OSMXBean { + private static final Logger LOG = LoggerFactory.getLogger(OSMXBean.class); + private static final boolean ibmvendor = + System.getProperty("java.vendor").contains("IBM"); + private static final boolean windows = + System.getProperty("os.name").startsWith("Windows"); + private static final boolean linux = + System.getProperty("os.name").startsWith("Linux"); + private OperatingSystemMXBean osMbean; + + /** + * Constructor. Get the running Operating System instance + */ + public OSMXBean() { + this.osMbean = ManagementFactory.getOperatingSystemMXBean(); + } + + /** + * Check if the OS is unix. If using the IBM java runtime, this + * will only work for linux. + * + * @return whether this is unix or not. + */ + public boolean getUnix() { + if (windows) { + return false; + } + return (ibmvendor ? linux : true); + } + + /** + * Load the implementation of UnixOperatingSystemMXBean for sun jvm + * and runs the desired method. + * @param mBeanMethodName : method to run from the interface UnixOperatingSystemMXBean + * @return the method result + */ + private Long getOSUnixMXBeanMethod(String mBeanMethodName) { + Object unixos; + Class classRef; + Method mBeanMethod; + + try { + classRef = Class.forName("com.sun.management.UnixOperatingSystemMXBean"); + if (classRef.isInstance(osMbean)) { + mBeanMethod = classRef.getDeclaredMethod(mBeanMethodName, + new Class[0]); + unixos = classRef.cast(osMbean); + return (Long) mBeanMethod.invoke(unixos); + } + } catch (Exception e) { + LOG.warn("Not able to load class or method for com.sun.managment.UnixOperatingSystemMXBean.", e); + } + return null; + } + + /** + * Get the number of opened filed descriptor for the runtime jvm. + * If sun java, it will use the com.sun.management interfaces. + * Otherwise, this methods implements it (linux only). + * @return number of open file descriptors for the jvm + */ + public long getOpenFileDescriptorCount() { + Long ofdc; + + if (!ibmvendor) { + ofdc = getOSUnixMXBeanMethod("getOpenFileDescriptorCount"); + return (ofdc != null ? ofdc.longValue() : -1); + } + + try { + //need to get the PID number of the process first + RuntimeMXBean rtmbean = ManagementFactory.getRuntimeMXBean(); + String rtname = rtmbean.getName(); + String[] pidhost = rtname.split("@"); + + //using linux bash commands to retrieve info + Process p = Runtime.getRuntime().exec( + new String[]{"bash", "-c", + "ls /proc/" + pidhost[0] + "/fdinfo | wc -l"}); + InputStream in = p.getInputStream(); + BufferedReader output = new BufferedReader( + new InputStreamReader(in)); + + try { + String openFileDesCount; + if ((openFileDesCount = output.readLine()) != null) { + return Long.parseLong(openFileDesCount); + } + } finally { + if (output != null) { + output.close(); + } + } + } catch (IOException ie) { + LOG.warn("Not able to get the number of open file descriptors", ie); + } + return -1; + } + + /** + * Get the number of the maximum file descriptors the system can use. + * If sun java, it will use the com.sun.management interfaces. + * Otherwise, this methods implements it (linux only). + * @return max number of file descriptors the operating system can use. + */ + public long getMaxFileDescriptorCount() { + Long mfdc; + + if (!ibmvendor) { + mfdc = getOSUnixMXBeanMethod("getMaxFileDescriptorCount"); + return (mfdc != null ? mfdc.longValue() : -1); + } + + try { + //using linux bash commands to retrieve info + Process p = Runtime.getRuntime().exec( + new String[]{"bash", "-c", "ulimit -n"}); + InputStream in = p.getInputStream(); + BufferedReader output = new BufferedReader( + new InputStreamReader(in)); + + try { + String maxFileDesCount; + if ((maxFileDesCount = output.readLine()) != null) { + return Long.parseLong(maxFileDesCount); + } + } finally { + if (output != null) { + output.close(); + } + } + } catch (IOException ie) { + LOG.warn("Not able to get the max number of file descriptors", ie); + } + return -1; + } +} diff --git a/src/java/main/org/apache/zookeeper/server/util/SerializeUtils.java b/src/java/main/org/apache/zookeeper/server/util/SerializeUtils.java new file mode 100644 index 00000000000..d6c7626ecce --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/util/SerializeUtils.java @@ -0,0 +1,140 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.util; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.DataTree; +import org.apache.zookeeper.server.ZooTrace; +import org.apache.zookeeper.txn.CreateContainerTxn; +import org.apache.zookeeper.txn.CreateSessionTxn; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.CreateTxnV0; +import org.apache.zookeeper.txn.DeleteTxn; +import org.apache.zookeeper.txn.ErrorTxn; +import org.apache.zookeeper.txn.MultiTxn; +import org.apache.zookeeper.txn.SetACLTxn; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class SerializeUtils { + private static final Logger LOG = LoggerFactory.getLogger(SerializeUtils.class); + + public static Record deserializeTxn(byte txnBytes[], TxnHeader hdr) + throws IOException { + final ByteArrayInputStream bais = new ByteArrayInputStream(txnBytes); + InputArchive ia = BinaryInputArchive.getArchive(bais); + + hdr.deserialize(ia, "hdr"); + bais.mark(bais.available()); + Record txn = null; + switch (hdr.getType()) { + case OpCode.createSession: + // This isn't really an error txn; it just has the same + // format. The error represents the timeout + txn = new CreateSessionTxn(); + break; + case OpCode.closeSession: + return null; + case OpCode.create: + case OpCode.create2: + txn = new CreateTxn(); + break; + case OpCode.createContainer: + txn = new CreateContainerTxn(); + break; + case OpCode.delete: + case OpCode.deleteContainer: + txn = new DeleteTxn(); + break; + case OpCode.reconfig: + case OpCode.setData: + txn = new SetDataTxn(); + break; + case OpCode.setACL: + txn = new SetACLTxn(); + break; + case OpCode.error: + txn = new ErrorTxn(); + break; + case OpCode.multi: + txn = new MultiTxn(); + break; + default: + throw new IOException("Unsupported Txn with type=%d" + hdr.getType()); + } + if (txn != null) { + try { + txn.deserialize(ia, "txn"); + } catch (EOFException e) { + // perhaps this is a V0 Create + if (hdr.getType() == OpCode.create) { + CreateTxn create = (CreateTxn) txn; + bais.reset(); + CreateTxnV0 createv0 = new CreateTxnV0(); + createv0.deserialize(ia, "txn"); + // cool now make it V1. a -1 parentCVersion will + // trigger fixup processing in processTxn + create.setPath(createv0.getPath()); + create.setData(createv0.getData()); + create.setAcl(createv0.getAcl()); + create.setEphemeral(createv0.getEphemeral()); + create.setParentCVersion(-1); + } else { + throw e; + } + } + } + return txn; + } + + public static void deserializeSnapshot(DataTree dt, InputArchive ia, + Map sessions) throws IOException { + int count = ia.readInt("count"); + while (count > 0) { + long id = ia.readLong("id"); + int to = ia.readInt("timeout"); + sessions.put(id, to); + if (LOG.isTraceEnabled()) { + ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, + "loadData --- session in archive: " + id + + " with timeout: " + to); + } + count--; + } + dt.deserialize(ia, "tree"); + } + + public static void serializeSnapshot(DataTree dt, OutputArchive oa, + Map sessions) throws IOException { + HashMap sessSnap = new HashMap(sessions); + oa.writeInt(sessSnap.size(), "count"); + for (Entry entry : sessSnap.entrySet()) { + oa.writeLong(entry.getKey().longValue(), "id"); + oa.writeInt(entry.getValue().intValue(), "timeout"); + } + dt.serialize(oa, "tree"); + } + +} diff --git a/src/java/main/org/apache/zookeeper/server/util/VerifyingFileFactory.java b/src/java/main/org/apache/zookeeper/server/util/VerifyingFileFactory.java new file mode 100644 index 00000000000..2821ca88101 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/util/VerifyingFileFactory.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.util; + +import org.slf4j.Logger; + +import java.io.File; + +public final class VerifyingFileFactory { + + private final boolean warnForRelativePath; + private final boolean failForNonExistingPath; + private final Logger log; + + public VerifyingFileFactory(Builder builder) { + warnForRelativePath = builder.warnForRelativePathOption; + failForNonExistingPath = builder.failForNonExistingPathOption; + log = builder.log; + assert (log != null); + } + + public File create(String path) { + File file = new File(path); + if (warnForRelativePath) doWarnForRelativePath(file); + if (failForNonExistingPath) doFailForNonExistingPath(file); + return file; + } + + private void doFailForNonExistingPath(File file) { + if (!file.exists()) { + throw new IllegalArgumentException(file.toString() + + " file is missing"); + } + } + + private void doWarnForRelativePath(File file) { + if (file.isAbsolute()) return; + if (file.getPath().substring(0, 2).equals("." + File.separator)) return; + log.warn(file.getPath() + " is relative. Prepend ." + + File.separator + " to indicate that you're sure!"); + } + + public static class Builder { + private final Logger log; + private boolean warnForRelativePathOption = false; + private boolean failForNonExistingPathOption = false; + + public Builder(Logger log) { + this.log = log; + } + + public Builder warnForRelativePath() { + warnForRelativePathOption = true; + return this; + } + + public Builder failForNonExistingPath() { + failForNonExistingPathOption = true; + return this; + } + + public VerifyingFileFactory build() { + return new VerifyingFileFactory(this); + } + } +} diff --git a/src/java/main/org/apache/zookeeper/server/util/ZxidUtils.java b/src/java/main/org/apache/zookeeper/server/util/ZxidUtils.java new file mode 100644 index 00000000000..63bd9d0e6a0 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/server/util/ZxidUtils.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.util; + +public class ZxidUtils { + static public long getEpochFromZxid(long zxid) { + return zxid >> 32L; + } + + static public long getCounterFromZxid(long zxid) { + return zxid & 0xffffffffL; + } + + static public long makeZxid(long epoch, long counter) { + return (epoch << 32L) | (counter & 0xffffffffL); + } + + static public String zxidToString(long zxid) { + return Long.toHexString(zxid); + } +} diff --git a/src/java/main/org/apache/zookeeper/version/util/VerGen.java b/src/java/main/org/apache/zookeeper/version/util/VerGen.java new file mode 100644 index 00000000000..8273b7f98c0 --- /dev/null +++ b/src/java/main/org/apache/zookeeper/version/util/VerGen.java @@ -0,0 +1,169 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.version.util; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class VerGen { + private static final String PACKAGE_NAME = "org.apache.zookeeper.version"; + private static final String TYPE_NAME = "Info"; + + static void printUsage() { + System.out.print("Usage:\tjava -cp org.apache.zookeeper." + + "version.util.VerGen maj.min.micro[-qualifier] rev buildDate"); + System.exit(1); + } + + public static void generateFile(File outputDir, Version version, int rev, String buildDate) { + String path = PACKAGE_NAME.replaceAll("\\.", "/"); + File pkgdir = new File(outputDir, path); + if (!pkgdir.exists()) { + // create the pkg directory + boolean ret = pkgdir.mkdirs(); + if (!ret) { + System.out.println("Cannnot create directory: " + path); + System.exit(1); + } + } else if (!pkgdir.isDirectory()) { + // not a directory + System.out.println(path + " is not a directory."); + System.exit(1); + } + File file = new File(pkgdir, TYPE_NAME + ".java"); + FileWriter w = null; + try { + w = new FileWriter(file); + w.write("// Do not edit!\n// File generated by org.apache.zookeeper" + + ".version.util.VerGen.\n"); + w.write("/**\n"); + w.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + w.write("* or more contributor license agreements. See the NOTICE file\n"); + w.write("* distributed with this work for additional information\n"); + w.write("* regarding copyright ownership. The ASF licenses this file\n"); + w.write("* to you under the Apache License, Version 2.0 (the\n"); + w.write("* \"License\"); you may not use this file except in compliance\n"); + w.write("* with the License. You may obtain a copy of the License at\n"); + w.write("*\n"); + w.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + w.write("*\n"); + w.write("* Unless required by applicable law or agreed to in writing, software\n"); + w.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + w.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + w.write("* See the License for the specific language governing permissions and\n"); + w.write("* limitations under the License.\n"); + w.write("*/\n"); + w.write("\n"); + w.write("package " + PACKAGE_NAME + ";\n\n"); + w.write("public interface " + TYPE_NAME + " {\n"); + w.write(" public static final int MAJOR=" + version.maj + ";\n"); + w.write(" public static final int MINOR=" + version.min + ";\n"); + w.write(" public static final int MICRO=" + version.micro + ";\n"); + w.write(" public static final String QUALIFIER=" + + (version.qualifier == null ? null : + "\"" + version.qualifier + "\"") + + ";\n"); + if (rev < 0) { + System.out.println("Unknown REVISION number, using " + rev); + } + w.write(" public static final int REVISION=" + rev + ";\n"); + w.write(" public static final String BUILD_DATE=\"" + buildDate + + "\";\n"); + w.write("}\n"); + } catch (IOException e) { + System.out.println("Unable to generate version.Info file: " + + e.getMessage()); + System.exit(1); + } finally { + if (w != null) { + try { + w.close(); + } catch (IOException e) { + System.out.println("Unable to close file writer" + + e.getMessage()); + } + } + } + } + + public static Version parseVersionString(String input) { + Version result = new Version(); + + Pattern p = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)((\\.\\d+)*)(-(.+))?$"); + Matcher m = p.matcher(input); + + if (!m.matches()) { + return null; + } + result.maj = Integer.parseInt(m.group(1)); + result.min = Integer.parseInt(m.group(2)); + result.micro = Integer.parseInt(m.group(3)); + if (m.groupCount() == 7) { + result.qualifier = m.group(7); + } else { + result.qualifier = null; + } + return result; + } + + /** + * Emits a org.apache.zookeeper.version.Info interface file with version and + * revision information constants set to the values passed in as command + * line parameters. The file is created in the current directory.
        + * Usage: java org.apache.zookeeper.version.util.VerGen maj.min.micro[-qualifier] + * rev buildDate + * + * @param args + *

          + *
        • maj - major version number + *
        • min - minor version number + *
        • micro - minor minor version number + *
        • qualifier - optional qualifier (dash followed by qualifier text) + *
        • rev - current SVN revision number + *
        • buildDate - date the build + *
        + */ + public static void main(String[] args) { + if (args.length != 3) + printUsage(); + try { + Version version = parseVersionString(args[0]); + if (version == null) { + System.err.println( + "Invalid version number format, must be \"x.y.z(-.*)?\""); + System.exit(1); + } + int rev; + try { + rev = Integer.parseInt(args[1]); + } catch (NumberFormatException e) { + rev = -1; + } + generateFile(new File("."), version, rev, args[2]); + } catch (NumberFormatException e) { + System.err.println( + "All version-related parameters must be valid integers!"); + throw e; + } + } + + public static class Version { + public int maj; + public int min; + public int micro; + public String qualifier; + } + +} diff --git a/src/java/systest/README.txt b/src/java/systest/README.txt new file mode 100644 index 00000000000..8a2985c2eda --- /dev/null +++ b/src/java/systest/README.txt @@ -0,0 +1,62 @@ +To run the system test we need to create processing containers that we can +spawn tasks, called Instances, in. (how is that for a dangling preposition!?!) +Start up InstanceContainers first. Then run the system test. The system test +finds the InstanceContainers and directs them through ZooKeeper, so you are +going to need an instance of ZooKeeper running that they can all access. +The easiest way to do all of this is to use the zookeeper fat jar. + +Steps to run system test +------------------------ +1) transfer the fatjar from the release directory to all systems + participating in the test. fatjar is in contrib/fatjar directory. + + (developers can generate by running "ant jar compile-test" + targets in trunk, then compiling using "ant jar" in src/contrib/jarjar) + +2) run a zookeeper standalone instance (cluster is ok too) + +e.g. java -jar zookeeper--fatjar.jar server + +Note: you must provide zoo.cfg, see sample in conf directory + +3) on each host start the system test container + +e.g. java -jar zookeeper--fatjar.jar ic /sysTest + +name : name of the test container - must be unique + typically it's a good idea to name after the host to aid debugging + +zkHostPort : the host:port of the server from step 2) + +4) initiate the system test using the fatjar: + +java -jar build/contrib/fatjar/zookeeper--fatjar.jar systest org.apache.zookeeper.test.system.SimpleSysTest + +by default it will access the zk server started in 2) on localhost:2181 + +or you can specify a remote host:port using + -DsysTest.zkHostPort=:,:,... + +java -DsysTest.zkHostPort=hostA:2181 -jar build/contrib/fatjar/zookeeper--fatjar.jar systest org.apache.zookeeper.test.system.SimpleSysTest + +where hostA is running the zk server started in step 2) above + +InstanceContainers can also be used to run a the saturation benchmark. The +first two steps are the same as the system test. Step 3 is almost the same: + +3) start the InstanceContainer on each host: + +e.g. java -jar zookeeper--fatjar.jar ic + +note prefix can be /sysTest or any other path. If you do use /sysTest, make +sure the system test isn't running when you run the benchmark. + +4) run GenerateLoad using the following + +java -jar build/contrib/fatjar/zookeeper--fatjar.jar generateLoad #servers #clients + +Once GenerateLoad is started, it will read commands from stdin. Usually +the only command you need to know is "percentage" which sets the percentage +of writes to use in the requests. Once a percentage is set, the benchmark +will start. "percentage 0" will cause only reads to be issued and +"percentage 100" will cause only writes to be issued. diff --git a/src/java/systest/org/apache/zookeeper/test/system/BaseSysTest.java b/src/java/systest/org/apache/zookeeper/test/system/BaseSysTest.java new file mode 100644 index 00000000000..28c241165eb --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/BaseSysTest.java @@ -0,0 +1,290 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.runner.JUnitCore; + +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.HashMap; + +@Ignore("No tests in this class.") +public class BaseSysTest { + final static int tickTime = 2000; + final static int initLimit = 3; + final static int syncLimit = 3; + private static final File testData = new File( + System.getProperty("test.data.dir", "build/test/data")); + static int defaultServerCount = 5; + static int defaultClientCount = 7; + private static int fakeBasePort = 33222; + private static String zkHostPort; + private static boolean fakeMachines = System.getProperty("baseSysTest.fakeMachines", "no").equals("yes"); + + static { + try { + zkHostPort = System.getProperty("sysTest.zkHostPort", InetAddress.getLocalHost().getCanonicalHostName() + ":2181"); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + } + + static { + defaultServerCount = Integer.parseInt(System.getProperty("simpleSysTest.defaultServerCount", Integer.toString(defaultServerCount))); + defaultClientCount = Integer.parseInt(System.getProperty("simpleSysTest.defaultClientCount", Integer.toString(defaultClientCount))); + } + + protected String prefix = "/sysTest"; + ZooKeeper zk; + InstanceManager im; + int serverCount = defaultServerCount; + int clientCount = defaultClientCount; + String serverHostPort; + String quorumHostPort; + HashMap peers; + String params; + private QuorumPeer qps[]; + private File qpsDirs[]; + private Class clazz; + private Instance fakeBaseClients[]; + + static public void main(String args[]) { + JUnitCore.main(args); + } + + @Before + public void setUp() throws Exception { + if (!fakeMachines) { + zk = new ZooKeeper(zkHostPort, 15000, new Watcher() { + public void process(WatchedEvent e) { + } + }); + im = new InstanceManager(zk, prefix); + } + } + + @After + public void tearDown() throws Exception { + if (null != im) { + im.close(); + } + } + + public String getHostPort() { + return serverHostPort; + } + + public int getServerCount() { + return serverCount; + } + + public int getClientCount() { + return clientCount; + } + + public void startServers() throws IOException { + for (int i = 0; i < serverCount; i++) { + startServer(i); + } + } + + public void stopServers() throws IOException { + for (int i = 0; i < serverCount; i++) { + stopServer(i); + } + } + + public void startClients() throws IOException { + for (int i = 0; i < clientCount; i++) { + startClient(i); + } + } + + public void stopClients() throws IOException { + for (int i = 0; i < clientCount; i++) { + stopClient(i); + } + } + + public void configureServers(int count) throws Exception { + serverCount = count; + if (fakeMachines) { + fakeConfigureServers(count); + } else { + distributedConfigureServers(count); + } + } + + private void distributedConfigureServers(int count) throws IOException { + StringBuilder sbClient = new StringBuilder(); + StringBuilder sbServer = new StringBuilder(); + try { + for (int i = 0; i < count; i++) { + String r[] = QuorumPeerInstance.createServer(im, i); + if (i > 0) { + sbClient.append(','); + sbServer.append(','); + } + sbClient.append(r[0]); // r[0] == "host:clientPort" + sbServer.append(r[1]); // r[1] == "host:leaderPort:leaderElectionPort" + sbServer.append(";" + (r[0].split(":"))[1]); // Appending ";clientPort" + } + serverHostPort = sbClient.toString(); + quorumHostPort = sbServer.toString(); + } catch (Exception e) { + IOException ioe = new IOException(e.getMessage()); + ioe.setStackTrace(e.getStackTrace()); + throw ioe; + } + } + + private void fakeConfigureServers(int count) throws IOException { + peers = new HashMap(); + qps = new QuorumPeer[count]; + qpsDirs = new File[count]; + for (int i = 1; i <= count; i++) { + InetSocketAddress peerAddress = new InetSocketAddress("127.0.0.1", + fakeBasePort + i); + InetSocketAddress electionAddr = new InetSocketAddress("127.0.0.1", + serverCount + fakeBasePort + i); + peers.put(Long.valueOf(i), new QuorumServer(i, peerAddress, + electionAddr)); + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < count; i++) { + //make that testData exists otherwise it fails on windows + testData.mkdirs(); + qpsDirs[i] = File.createTempFile("sysTest", ".tmp", testData); + qpsDirs[i].delete(); + qpsDirs[i].mkdir(); + int port = fakeBasePort + 10 + i; + if (sb.length() > 0) { + sb.append(','); + } + sb.append("localhost:"); + sb.append(port); + } + serverHostPort = sb.toString(); + } + + public void startServer(int index) throws IOException { + int port = fakeBasePort + 10 + index; + if (fakeMachines) { + qps[index] = new QuorumPeer(peers, qpsDirs[index], qpsDirs[index], port, 0, index + 1, tickTime, initLimit, syncLimit); + qps[index].start(); + } else { + try { + QuorumPeerInstance.startInstance(im, quorumHostPort, index); + } catch (Exception e) { + IOException ioe = new IOException(e.getClass().getName() + ": " + e.getMessage()); + ioe.setStackTrace(e.getStackTrace()); + throw ioe; + } + } + } + + public void stopServer(int index) throws IOException { + if (fakeMachines) { + qps[index].shutdown(); + } else { + try { + QuorumPeerInstance.stopInstance(im, index); + } catch (Exception e) { + IOException ioe = new IOException(e.getMessage()); + ioe.setStackTrace(e.getStackTrace()); + throw ioe; + } + } + } + + public void configureClients(int count, Class clazz, String params) throws Exception { + clientCount = count; + if (fakeMachines) { + fakeConfigureClients(count, clazz, params); + } else { + distributedConfigureClients(count, clazz, params); + } + } + + private void distributedConfigureClients(int count, Class clazz, String params) throws IOException { + this.clazz = clazz; + this.params = params; + + } + + private void fakeConfigureClients(int count, Class clazz, String params) throws IOException, ClassNotFoundException { + fakeBaseClients = new Instance[count]; + for (int i = 0; i < count; i++) { + try { + fakeBaseClients[i] = clazz.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + return; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return; + } + fakeBaseClients[i].configure(i + " " + params); + } + } + + public void startClient(int index) throws IOException { + if (fakeMachines) { + fakeStartClient(index); + } else { + distributedStartClient(index); + } + } + + private void distributedStartClient(int index) throws IOException { + try { + im.assignInstance("client" + index, clazz, index + " " + params, 1); + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + private void fakeStartClient(int index) { + fakeBaseClients[index].start(); + } + + public void stopClient(int index) throws IOException { + if (fakeMachines) { + fakeStopClient(index); + } else { + distributedStopClient(index); + } + } + + private void distributedStopClient(int index) throws IOException { + try { + im.removeInstance("client" + index); + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + private void fakeStopClient(int index) { + fakeBaseClients[index].stop(); + } +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/DuplicateNameException.java b/src/java/systest/org/apache/zookeeper/test/system/DuplicateNameException.java new file mode 100644 index 00000000000..c402fe78ed6 --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/DuplicateNameException.java @@ -0,0 +1,20 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +public class DuplicateNameException extends Exception { + private static final long serialVersionUID = 1L; + + public DuplicateNameException(String mess) { + super(mess); + } +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java b/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java new file mode 100644 index 00000000000..3f5d4494d28 --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java @@ -0,0 +1,694 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Random; +import java.util.Set; + + +public class GenerateLoad { + protected static final Logger LOG = LoggerFactory.getLogger(GenerateLoad.class); + static final int INTERVAL = 6000; + static ServerSocket ss; + static Set slaves = Collections + .synchronizedSet(new HashSet()); + static Map totalByTime = new HashMap(); + volatile static long currentInterval; + static long lastChange; + static PrintStream sf; + static PrintStream tf; + private static boolean leaderOnly; + private static boolean leaderServes; + + static { + try { + tf = new PrintStream(new FileOutputStream("trace")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + synchronized static void add(long time, int count, Socket s) { + long interval = time / INTERVAL; + if (currentInterval == 0 || currentInterval > interval) { + System.out.println("Dropping " + count + " for " + new Date(time) + + " " + currentInterval + ">" + interval); + return; + } + // We track totals by seconds + Long total = totalByTime.get(interval); + if (total == null) { + totalByTime.put(interval, (long) count); + } else { + totalByTime.put(interval, total.longValue() + count); + } + tf.println(interval + " " + count + " " + s); + } + + synchronized static long remove(long interval) { + Long total = totalByTime.remove(interval); + return total == null ? -1 : total; + } + + synchronized static void sendChange(int percentage) { + long now = Time.currentElapsedTime(); + long start = now; + ReporterThread.percentage = percentage; + for (SlaveThread st : slaves.toArray(new SlaveThread[0])) { + st.send(percentage); + } + now = Time.currentElapsedTime(); + long delay = now - start; + if (delay > 1000) { + System.out.println("Delay of " + delay + " to send new percentage"); + } + lastChange = now; + } + + private static String[] processOptions(String args[]) { + ArrayList newArgs = new ArrayList(); + for (String a : args) { + if (a.equals("--leaderOnly")) { + leaderOnly = true; + leaderServes = true; + } else if (a.equals("--leaderServes")) { + leaderServes = true; + } else { + newArgs.add(a); + } + } + return newArgs.toArray(new String[0]); + } + + /** + * @param args + * @throws InterruptedException + * @throws KeeperException + * @throws DuplicateNameException + * @throws NoAvailableContainers + * @throws NoAssignmentException + */ + public static void main(String[] args) throws InterruptedException, + KeeperException, NoAvailableContainers, DuplicateNameException, + NoAssignmentException { + + args = processOptions(args); + if (args.length == 5) { + try { + StatusWatcher statusWatcher = new StatusWatcher(); + ZooKeeper zk = new ZooKeeper(args[0], 15000, statusWatcher); + if (!statusWatcher.waitConnected(5000)) { + System.err.println("Could not connect to " + args[0]); + return; + } + InstanceManager im = new InstanceManager(zk, args[1]); + ss = new ServerSocket(0); + int port = ss.getLocalPort(); + int serverCount = Integer.parseInt(args[2]); + int clientCount = Integer.parseInt(args[3]); + StringBuilder quorumHostPort = new StringBuilder(); + StringBuilder zkHostPort = new StringBuilder(); + for (int i = 0; i < serverCount; i++) { + String r[] = QuorumPeerInstance.createServer(im, i, leaderServes); + if (i > 0) { + quorumHostPort.append(','); + zkHostPort.append(','); + } + zkHostPort.append(r[0]); // r[0] == "host:clientPort" + quorumHostPort.append(r[1]); // r[1] == "host:leaderPort:leaderElectionPort" + quorumHostPort.append(";" + (r[0].split(":"))[1]); // Appending ";clientPort" + } + for (int i = 0; i < serverCount; i++) { + QuorumPeerInstance.startInstance(im, quorumHostPort + .toString(), i); + } + if (leaderOnly) { + int tries = 0; + outer: + while (true) { + Thread.sleep(1000); + IOException lastException = null; + String parts[] = zkHostPort.toString().split(","); + for (int i = 0; i < parts.length; i++) { + try { + String mode = getMode(parts[i]); + if (mode.equals("leader")) { + zkHostPort = new StringBuilder(parts[i]); + System.out.println("Connecting exclusively to " + zkHostPort.toString()); + break outer; + } + } catch (IOException e) { + lastException = e; + } + } + if (tries++ > 3) { + throw lastException; + } + } + } + for (int i = 0; i < clientCount; i++) { + im.assignInstance("client" + i, GeneratorInstance.class, + zkHostPort.toString() + + ' ' + + InetAddress.getLocalHost() + .getCanonicalHostName() + ':' + + port, 1); + } + new AcceptorThread(); + new ReporterThread(); + BufferedReader is = new BufferedReader(new InputStreamReader( + System.in)); + String line; + while ((line = is.readLine()) != null) { + try { + String cmdNumber[] = line.split(" "); + if (cmdNumber[0].equals("percentage") + && cmdNumber.length > 1) { + int number = Integer.parseInt(cmdNumber[1]); + if (number < 0 || number > 100) { + throw new NumberFormatException( + "must be between 0 and 100"); + } + sendChange(number); + } else if (cmdNumber[0].equals("sleep") + && cmdNumber.length > 1) { + int number = Integer.parseInt(cmdNumber[1]); + Thread.sleep(number * 1000); + } else if (cmdNumber[0].equals("save") + && cmdNumber.length > 1) { + sf = new PrintStream(cmdNumber[1]); + } else { + System.err.println("Commands must be:"); + System.err + .println("\tpercentage new_write_percentage"); + System.err.println("\tsleep seconds_to_sleep"); + System.err.println("\tsave file_to_save_output"); + } + } catch (NumberFormatException e) { + System.out.println("Not a valid number: " + + e.getMessage()); + } + } + } catch (NumberFormatException e) { + doUsage(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(2); + } + } else { + doUsage(); + } + + } + + private static String getMode(String hostPort) throws NumberFormatException, UnknownHostException, IOException { + String parts[] = hostPort.split(":"); + Socket s = new Socket(parts[0], Integer.parseInt(parts[1])); + s.getOutputStream().write("stat".getBytes()); + BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); + String line; + try { + while ((line = br.readLine()) != null) { + if (line.startsWith("Mode: ")) { + return line.substring(6); + } + } + return "unknown"; + } finally { + s.close(); + } + } + + private static void doUsage() { + System.err.println("USAGE: " + GenerateLoad.class.getName() + + " [--leaderOnly] [--leaderServes] zookeeper_host:port containerPrefix #ofServers #ofClients requestSize"); + System.exit(2); + } + + static class SlaveThread extends Thread { + Socket s; + + SlaveThread(Socket s) { + setDaemon(true); + this.s = s; + start(); + } + + public void run() { + try { + System.out.println("Connected to " + s); + BufferedReader is = new BufferedReader(new InputStreamReader(s + .getInputStream())); + String result; + while ((result = is.readLine()) != null) { + String timePercentCount[] = result.split(" "); + if (timePercentCount.length != 5) { + System.err.println("Got " + result + " from " + s + + " exitng."); + throw new IOException(result); + } + long time = Long.parseLong(timePercentCount[0]); + // int percent = Integer.parseInt(timePercentCount[1]); + int count = Integer.parseInt(timePercentCount[2]); + int errs = Integer.parseInt(timePercentCount[3]); + if (errs > 0) { + System.out.println(s + " Got an error! " + errs); + } + add(time, count, s); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + close(); + } + } + + void send(int percentage) { + try { + s.getOutputStream().write((percentage + "\n").getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + void close() { + try { + System.err.println("Closing " + s); + slaves.remove(this); + s.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + static class AcceptorThread extends Thread { + AcceptorThread() { + setDaemon(true); + start(); + } + + public void run() { + try { + while (true) { + Socket s = ss.accept(); + System.err.println("Accepted connection from " + s); + slaves.add(new SlaveThread(s)); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + for (Iterator it = slaves.iterator(); it.hasNext(); ) { + SlaveThread st = it.next(); + it.remove(); + st.close(); + } + } + } + } + + static class ReporterThread extends Thread { + static int percentage; + + ReporterThread() { + setDaemon(true); + start(); + } + + public void run() { + try { + currentInterval = Time.currentElapsedTime() / INTERVAL; + // Give things time to report; + Thread.sleep(INTERVAL * 2); + long min = 99999; + long max = 0; + long total = 0; + int number = 0; + while (true) { + long now = Time.currentElapsedTime(); + long lastInterval = currentInterval; + currentInterval += 1; + long count = remove(lastInterval); + count = count * 1000 / INTERVAL; // Multiply by 1000 to get + // reqs/sec + if (lastChange != 0 + && (lastChange + INTERVAL * 3) < now) { + // We only want to print anything if things have had a + // chance to change + + if (count < min) { + min = count; + } + if (count > max) { + max = count; + } + total += count; + number++; + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(lastInterval * INTERVAL); + String report = lastInterval + " " + + calendar.get(Calendar.HOUR_OF_DAY) + ":" + + calendar.get(Calendar.MINUTE) + ":" + + calendar.get(Calendar.SECOND) + " " + + percentage + "% " + count + " " + min + " " + + ((double) total / (double) number) + " " + + max; + System.err.println(report); + if (sf != null) { + sf.println(report); + } + } else { + max = total = 0; + min = 999999999; + number = 0; + } + Thread.sleep(INTERVAL); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + } + + static public class GeneratorInstance implements Instance { + + final Object statSync = new Object(); + byte bytes[]; + int percentage = -1; + int errors; + int finished; + + int reads; + + int writes; + + int rlatency; + + int wlatency; + + int outstanding; + + volatile boolean alive; + Socket s; + ZooKeeperThread zkThread; + SenderThread sendThread; + Reporter r; + + public void configure(final String params) { + System.err.println("Got " + params); + new Thread() { + public void run() { + try { + String parts[] = params.split(" "); + String hostPort[] = parts[1].split(":"); + int bytesSize = 1024; + if (parts.length == 3) { + try { + bytesSize = Integer.parseInt(parts[2]); + } catch (Exception e) { + System.err.println("Not an integer: " + parts[2]); + } + } + bytes = new byte[bytesSize]; + s = new Socket(hostPort[0], Integer.parseInt(hostPort[1])); + zkThread = new ZooKeeperThread(parts[0]); + sendThread = new SenderThread(s); + BufferedReader is = new BufferedReader(new InputStreamReader(s + .getInputStream())); + String line; + while ((line = is.readLine()) != null) { + percentage = Integer.parseInt(line); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }.start(); + + } + + public void setReporter(Reporter r) { + this.r = r; + } + + public void start() { + try { + r.report("started"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void stop() { + alive = false; + zkThread.interrupt(); + sendThread.interrupt(); + try { + zkThread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + sendThread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + r.report("stopped"); + } catch (Exception e) { + e.printStackTrace(); + } + try { + s.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + class ZooKeeperThread extends Thread implements Watcher, DataCallback, + StatCallback { + static final int outstandingLimit = 100; + String host; + Random r = new Random(); + String path; + ZooKeeper zk; + boolean connected; + + ZooKeeperThread(String host) { + setDaemon(true); + alive = true; + this.host = host; + start(); + } + + synchronized void incOutstanding() throws InterruptedException { + outstanding++; + while (outstanding > outstandingLimit) { + wait(); + } + } + + synchronized void decOutstanding() { + outstanding--; + notifyAll(); + } + + public void run() { + try { + zk = new ZooKeeper(host, 60000, this); + synchronized (this) { + if (!connected) { + wait(20000); + } + } + for (int i = 0; i < 300; i++) { + try { + Thread.sleep(100); + path = zk.create("/client", new byte[16], + Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL_SEQUENTIAL); + break; + } catch (KeeperException e) { + LOG.error("keeper exception thrown", e); + } + } + if (path == null) { + System.err.println("Couldn't create a node in /!"); + return; + } + while (alive) { + if (r.nextInt(100) < percentage) { + zk.setData(path, bytes, -1, this, System + .currentTimeMillis()); + } else { + zk.getData(path, false, this, System + .currentTimeMillis()); + } + incOutstanding(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + alive = false; + try { + zk.close(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + public void process(WatchedEvent event) { + System.err.println(event); + synchronized (this) { + if (event.getType() == EventType.None) { + connected = (event.getState() == KeeperState.SyncConnected); + notifyAll(); + } + } + } + + public void processResult(int rc, String path, Object ctx, byte[] data, + Stat stat) { + decOutstanding(); + synchronized (statSync) { + if (!alive) { + return; + } + if (rc != 0) { + System.err.println("Got rc = " + rc); + errors++; + } else { + finished++; + rlatency += Time.currentElapsedTime() - (Long) ctx; + reads++; + } + } + } + + public void processResult(int rc, String path, Object ctx, Stat stat) { + decOutstanding(); + synchronized (statSync) { + if (rc != 0) { + System.err.println("Got rc = " + rc); + errors++; + } else { + finished++; + wlatency += Time.currentElapsedTime() - (Long) ctx; + writes++; + } + } + } + } + + class SenderThread extends Thread { + Socket s; + + SenderThread(Socket s) { + this.s = s; + setDaemon(true); + start(); + } + + public void run() { + try { + OutputStream os = s.getOutputStream(); + finished = 0; + errors = 0; + while (alive) { + Thread.sleep(300); + if (percentage == -1 || (finished == 0 && errors == 0)) { + continue; + } + String report = Time.currentElapsedTime() + " " + + percentage + " " + finished + " " + errors + " " + + outstanding + "\n"; + /* String subreport = reads + " " + + (((double) rlatency) / reads) + " " + writes + + " " + (((double) wlatency / writes)); */ + synchronized (statSync) { + finished = 0; + errors = 0; + reads = 0; + writes = 0; + rlatency = 0; + wlatency = 0; + } + os.write(report.getBytes()); + //System.out.println("Reporting " + report + "+" + subreport); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + } + + } + + private static class StatusWatcher implements Watcher { + volatile boolean connected; + + public void process(WatchedEvent event) { + if (event.getType() == Watcher.Event.EventType.None) { + synchronized (this) { + connected = event.getState() == Watcher.Event.KeeperState.SyncConnected; + notifyAll(); + } + } + } + + synchronized public boolean waitConnected(long timeout) + throws InterruptedException { + long endTime = Time.currentElapsedTime() + timeout; + while (!connected && Time.currentElapsedTime() < endTime) { + wait(endTime - Time.currentElapsedTime()); + } + return connected; + } + } +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/Instance.java b/src/java/systest/org/apache/zookeeper/test/system/Instance.java new file mode 100644 index 00000000000..f3d80e53240 --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/Instance.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.KeeperException; + +/** + * This interface is implemented by a class that can be run in an + * instance container. + * + */ +public interface Instance { + /** + * This will be the first method invoked by the InstanceContainer after + * an instance of this interface has been constructed. It will only be + * invoked once. + * + * @param r a handle to use to report on status changes. + */ + void setReporter(Reporter r); + + /** + * This will be the second method invoked by the InstanceContainer. It + * may be invoked again if the configuration changes. + * + * @param params parameters that were passed to the InstanceManager when + * this instance was scheduled. + */ + void configure(String params); + + /** + * Starts this instance. + */ + void start(); + + /** + * Stops this instance. + */ + void stop(); + + /** + * This object is used to report back changes in status. + */ + interface Reporter { + void report(String report) throws KeeperException, InterruptedException; + } +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/InstanceContainer.java b/src/java/systest/org/apache/zookeeper/test/system/InstanceContainer.java new file mode 100644 index 00000000000..f93999fc16d --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/InstanceContainer.java @@ -0,0 +1,311 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.ConnectionLossException; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.KeeperException.NodeExistsException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.test.system.Instance.Reporter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This class starts up, + */ +public class InstanceContainer implements Watcher, AsyncCallback.ChildrenCallback { + static final int sessTimeout = 5000; + static final int maxTries = 3; + private static final Logger LOG = LoggerFactory.getLogger(InstanceContainer.class); + String name; + String zkHostPort; + // We only run if the readyNode exists + String prefixNode; + String statusNode = "available"; + String reportsNode = "reports"; + String assignmentsNode = "assignments"; + ZooKeeper zk; + HashMap instances = new HashMap(); + public InstanceContainer(String name, String zkHostPort, String prefix) throws UnknownHostException { + if (name.length() == 0 || name.equals("hostname")) { + name = InetAddress.getLocalHost().getCanonicalHostName(); + } + this.name = name; + this.zkHostPort = zkHostPort; + this.prefixNode = prefix; + this.statusNode = prefix + '/' + this.statusNode + '/' + name; + this.reportsNode = prefix + '/' + this.reportsNode; + this.assignmentsNode = prefix + '/' + this.assignmentsNode + '/' + name; + } + + /** + * @param args the first parameter is the instance name, the second + * is the ZooKeeper spec. if the instance name is the empty string + * or "hostname", the hostname will be used. + * @throws InterruptedException + * @throws IOException + * @throws UnknownHostException + * @throws KeeperException + */ + public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException, KeeperException { + if (args.length != 3) { + System.err.println("USAGE: " + InstanceContainer.class.getName() + " name zkHostPort znodePrefix"); + System.exit(2); + } + new InstanceContainer(args[0], args[1], args[2]).run(); + while (true) { + Thread.sleep(1000); + } + } + + private void rmnod(String path) throws InterruptedException, KeeperException { + KeeperException lastException = null; + for (int i = 0; i < maxTries; i++) { + try { + zk.delete(path, -1); + lastException = null; + break; + } catch (KeeperException.NoNodeException e) { + // cool this is what we want + break; + } catch (KeeperException e) { + lastException = e; + } + } + if (lastException != null) { + throw lastException; + } + } + + private void mknod_inner(String path, CreateMode mode) throws KeeperException, InterruptedException { + for (int i = 0; i < maxTries; i++) { + try { + zk.create(path, null, Ids.OPEN_ACL_UNSAFE, mode); + break; + } catch (NodeExistsException e) { + if (mode != CreateMode.EPHEMERAL) { + return; + } + Stat stat = zk.exists(path, false); + if (stat == null) { + continue; + } + if (stat.getEphemeralOwner() != zk.getSessionId()) { + throw e; + } + break; + } catch (ConnectionLossException e) { + e.printStackTrace(); + } + } + } + + private void mknod(String path, CreateMode mode) throws KeeperException, InterruptedException { + String subpath[] = path.split("/"); + StringBuilder sb = new StringBuilder(); + // We start at 1 because / will create an empty part first + for (int i = 1; i < subpath.length; i++) { + sb.append("/"); + sb.append(subpath[i]); + CreateMode m = CreateMode.PERSISTENT; + if (i == subpath.length - 1) { + m = mode; + } + mknod_inner(sb.toString(), m); + } + } + + public void run() throws IOException, InterruptedException, KeeperException { + zk = new ZooKeeper(zkHostPort, sessTimeout, this); + mknod(assignmentsNode, CreateMode.PERSISTENT); + mknod(statusNode, CreateMode.EPHEMERAL); + mknod(reportsNode, CreateMode.PERSISTENT); + // Now we just start watching the assignments directory + zk.getChildren(assignmentsNode, true, this, null); + } + + public void process(WatchedEvent event) { + if (KeeperState.Expired == event.getState()) { + // It's all over + LOG.error("Lost session"); + System.exit(4); + } + if (event.getPath() != null && event.getPath().equals(assignmentsNode)) { + // children have changed, so read in the new list + zk.getChildren(assignmentsNode, true, this, null); + } + } + + @Override + public void processResult(int rc, String path, Object ctx, List children) { + if (rc != KeeperException.Code.OK.intValue()) { + // try it again + zk.getChildren(assignmentsNode, true, this, null); + return; + } + HashMap newList = new HashMap(); + // check for differences + Stat stat = new Stat(); + for (String child : children) { + Instance i = instances.remove(child); + if (i == null) { + // Start up a new instance + byte data[] = null; + String myNode = assignmentsNode + '/' + child; + while (true) { + try { + data = zk.getData(myNode, true, stat); + break; + } catch (NoNodeException e) { + // The node doesn't exist anymore, so skip it + break; + } catch (KeeperException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + return; + } + } + if (data != null) { + String instanceSpec = new String(data); + int spaceIndex = instanceSpec.indexOf(' '); + String clazz; + String conf; + if (spaceIndex == -1) { + clazz = instanceSpec; + conf = null; + } else { + clazz = instanceSpec.substring(0, spaceIndex); + conf = instanceSpec.substring(spaceIndex + 1); + } + try { + Class c = Class.forName(clazz); + i = (Instance) c.newInstance(); + Reporter reporter = new MyReporter(child); + i.setReporter(reporter); + i.configure(conf); + i.start(); + newList.put(child, i); + int ver = stat.getVersion(); + Instance myInstance = i; + DataCallback dc = new MyDataCallback(myNode, myInstance, ver); + Watcher watcher = new MyWatcher(myNode, dc); + zk.getData(myNode, watcher, dc, watcher); + } catch (Exception e) { + LOG.warn("Skipping " + child, e); + if (e.getCause() != null) { + LOG.warn("Caused by", e.getCause()); + } + } + + } + } else { + // just move it to the new list + newList.put(child, i); + } + } + // kill anything that was removed for the children + for (Map.Entry i : instances.entrySet()) { + i.getValue().stop(); + try { + rmnod(reportsNode + '/' + i.getKey()); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } catch (KeeperException e) { + e.printStackTrace(); + } + } + instances = newList; + } + + private final class MyWatcher implements Watcher { + String myNode; + DataCallback dc; + + MyWatcher(String myNode, DataCallback dc) { + this.myNode = myNode; + this.dc = dc; + } + + public void process(WatchedEvent event) { + if (event.getPath() != null && event.getPath().equals(myNode)) { + zk.getData(myNode, this, dc, this); + } + } + } + + private final class MyDataCallback implements DataCallback { + int lastVer; + String myNode; + Instance myInstance; + + MyDataCallback(String myNode, Instance myInstance, int ver) { + this.myNode = myNode; + this.myInstance = myInstance; + lastVer = ver; + } + + public void processResult(int rc, String path, + Object ctx, byte[] data, Stat stat) { + if (rc == KeeperException.Code.NONODE.intValue()) { + // we can just ignore because the child watcher takes care of this + return; + } + if (rc != KeeperException.Code.OK.intValue()) { + zk.getData(myNode, (Watcher) ctx, this, ctx); + } + int currVer = stat.getVersion(); + if (currVer != lastVer) { + String parts[] = new String(data).split(" ", 2); + myInstance.configure(parts[1]); + lastVer = currVer; + } + } + } + + private final class MyReporter implements Reporter { + String myReportNode; + + public MyReporter(String child) { + myReportNode = reportsNode + '/' + child; + } + + public void report(String report) throws KeeperException, InterruptedException { + for (int j = 0; j < maxTries; j++) { + try { + try { + zk.setData(myReportNode, report.getBytes(), -1); + } catch (NoNodeException e) { + zk.create(myReportNode, report.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + } + break; + } catch (ConnectionLossException e) { + } + } + } + } + +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java b/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java new file mode 100644 index 00000000000..779da5c958b --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/InstanceManager.java @@ -0,0 +1,349 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.ConnectionLossException; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.KeeperException.NodeExistsException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; + +/** + * This class doles out assignments to InstanceContainers that are registered to + * a ZooKeeper znode. The znode will have four child nodes: + * * ready: this znode indicates that the InstanceManager is running + * * available: the children of this znode are ephemeral nodes representing + * running InstanceContainers + * * assignments: there will be a child under this znode for each available + * InstanceContainer. those znodes will have a child for each + * assigned instance + * * reports: there will be a child under this znode for each instance that is + * running. it will have the report string from the instance. + */ +public class InstanceManager implements AsyncCallback.ChildrenCallback, Watcher { + final private static Logger LOG = LoggerFactory.getLogger(InstanceManager.class); + private static final int maxTries = 3; + private static List preferredList = new ArrayList(); + + static { + String list = System.getProperty("ic.preferredList"); + if (list != null) { + preferredList = Arrays.asList(list.split(",")); + System.err.println("Preferred List: " + preferredList); + } else { + System.err.println("Preferred List is empty"); + } + } + + private ZooKeeper zk; + private String prefixNode; + private String reportsNode = "reports"; + private String readyNode = "ready"; + private String assignmentsNode = "assignments"; + private String statusNode = "available"; + private HashMap> assignments = new HashMap>(); + private HashMap instanceToAssignment = new HashMap(); + public InstanceManager(ZooKeeper zk, String prefix) throws KeeperException, InterruptedException { + this.zk = zk; + this.prefixNode = prefix; + this.readyNode = prefix + '/' + this.readyNode; + this.assignmentsNode = prefix + '/' + this.assignmentsNode; + this.reportsNode = prefix + '/' + this.reportsNode; + this.statusNode = prefix + '/' + this.statusNode; + for (int i = 0; i < maxTries; i++) { + try { + setupNodes(zk); + break; + } catch (ConnectionLossException e) { + } + } + ConnectionLossException lastException = null; + for (int i = 0; i < maxTries; i++) { + try { + List children = zk.getChildren(statusNode, this); + processResult(0, statusNode, null, children); + lastException = null; + break; + } catch (ConnectionLossException e) { + lastException = e; + } + } + if (lastException != null) { + throw lastException; + } + } + + private void setupNodes(ZooKeeper zk) throws KeeperException, + InterruptedException { + try { + zk.create(prefixNode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (NodeExistsException e) { /* this is ok */ } + try { + zk.create(assignmentsNode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (NodeExistsException e) { /* this is ok */ } + try { + zk.create(statusNode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (NodeExistsException e) { /* this is ok */ } + try { + zk.create(reportsNode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (NodeExistsException e) { /* this is ok */ } + try { + zk.create(readyNode, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (NodeExistsException e) { /* this is ok */ } + } + + synchronized public void processResult(int rc, String path, Object ctx, + List children) { + if (rc != KeeperException.Code.OK.intValue()) { + zk.getChildren(statusNode, this, this, null); + return; + } + if (LOG.isDebugEnabled()) { + LOG.debug("Got " + children + " children from " + path); + } + HashMap> newAssignments = new HashMap>(); + for (String c : children) { + HashSet a = assignments.remove(c); + if (a != null) { + newAssignments.put(c, a); + } else { + newAssignments.put(c, new HashSet()); + } + } + // Clean up the dead machines + for (String dead : assignments.keySet()) { + try { + removeInstance(dead); + } catch (KeeperException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + assignments = newAssignments; + } + + public void process(WatchedEvent event) { + if (event.getPath().equals(statusNode)) { + zk.getChildren(statusNode, this, this, null); + } + } + + synchronized public String assignInstance(String name, Class clazz, String params, int weight) throws NoAvailableContainers, DuplicateNameException, InterruptedException, KeeperException { + if (weight < 1) { + // if the weights are not above zero, things will get messed up + weight = 1; + } + String instanceSpec = clazz.getName() + ' ' + params; + if (instanceToAssignment.get(name) != null) { + throw new DuplicateNameException(name + " already exists"); + } + // find most idle node + String mostIdle = null; + int mostIdleWeight = Integer.MAX_VALUE; + for (String preferred : preferredList) { + HashSet assignmentList = assignments.get(preferred); + int w = 0; + if (assignmentList != null) { + for (Assigned a : assignmentList) { + w += a.weight; + } + if (w < mostIdleWeight) { + mostIdleWeight = w; + mostIdle = preferred; + } + } + } + for (Entry> e : assignments.entrySet()) { + int w = 0; + for (Assigned a : e.getValue()) { + w += a.weight; + } + if (w < mostIdleWeight) { + mostIdleWeight = w; + mostIdle = e.getKey(); + } + } + if (mostIdle == null) { + throw new NoAvailableContainers("No available containers"); + } + Assigned a = new Assigned(mostIdle, weight); + instanceToAssignment.put(name, a); + HashSet as = assignments.get(mostIdle); + if (as == null) { + as = new HashSet(); + assignments.put(mostIdle, as); + } + as.add(a); + KeeperException lastException = null; + for (int i = 0; i < maxTries; i++) { + try { + zk.create(assignmentsNode + '/' + mostIdle + '/' + name, instanceSpec.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + return mostIdle; + } catch (NodeExistsException e) { + return mostIdle; + } catch (KeeperException e) { + lastException = e; + } + } + throw lastException; + } + + public void reconfigureInstance(String name, String params) throws NoAssignmentException, InterruptedException, KeeperException { + if (LOG.isDebugEnabled()) { + LOG.debug("Reconfiguring " + name + " with " + params); + } + Assigned assigned = instanceToAssignment.get(name); + if (assigned == null) { + throw new NoAssignmentException(); + } + KeeperException lastException = null; + for (int i = 0; i < maxTries; i++) { + try { + zk.setData(assignmentsNode + '/' + assigned.container + '/' + name, ("update " + params).getBytes(), -1); + break; + } catch (ConnectionLossException e) { + lastException = e; + } + } + if (lastException != null) { + throw lastException; + } + } + + private void doDelete(String path) throws InterruptedException, KeeperException { + KeeperException lastException = null; + for (int i = 0; i < maxTries; i++) { + try { + zk.delete(path, -1); + return; + } catch (NoNodeException e) { + return; + } catch (KeeperException e) { + lastException = e; + } + } + throw lastException; + } + + synchronized public void removeInstance(String name) throws InterruptedException, KeeperException { + Assigned assigned = instanceToAssignment.remove(name); + if (assigned == null) { + return; + } + assignments.get(assigned.container).remove(name); + doDelete(assignmentsNode + '/' + assigned.container + '/' + name); + doDelete(reportsNode + '/' + name); + } + + synchronized boolean isAlive(String name) { + return instanceToAssignment.get(name) != null; + } + + public void resetStatus(String name) throws InterruptedException, KeeperException { + KeeperException lastException = null; + for (int i = 0; i < maxTries; i++) { + try { + zk.delete(reportsNode + '/' + name, -1); + lastException = null; + break; + } catch (ConnectionLossException e) { + lastException = e; + } catch (NoNodeException e) { + // great this is what we want! + } + } + if (lastException != null) { + throw lastException; + } + } + + public String getStatus(String name, long timeout) throws KeeperException, InterruptedException { + Stat stat = new Stat(); + byte data[] = null; + long endTime = Time.currentElapsedTime() + timeout; + KeeperException lastException = null; + for (int i = 0; i < maxTries && endTime > Time.currentElapsedTime(); i++) { + try { + data = zk.getData(reportsNode + '/' + name, false, stat); + if (LOG.isDebugEnabled()) { + LOG.debug("Got Data: " + ((data == null) ? "null" : new String(data))); + } + lastException = null; + break; + } catch (ConnectionLossException e) { + lastException = e; + } catch (NoNodeException e) { + final Object eventObj = new Object(); + synchronized (eventObj) { + // wait for the node to appear + Stat eStat = zk.exists(reportsNode + '/' + name, new Watcher() { + public void process(WatchedEvent event) { + synchronized (eventObj) { + eventObj.notifyAll(); + } + } + }); + if (eStat == null) { + eventObj.wait(endTime - Time.currentElapsedTime()); + } + } + lastException = e; + } + } + if (lastException != null) { + throw lastException; + } + return new String(data); + } + + synchronized public void close() throws InterruptedException { + for (String name : instanceToAssignment.keySet().toArray(new String[0])) { + try { + removeInstance(name); + } catch (KeeperException e) { + e.printStackTrace(); + } + } + try { + doDelete(readyNode); + } catch (KeeperException e) { + e.printStackTrace(); + } + } + + private static final class Assigned { + String container; + int weight; + + Assigned(String container, int weight) { + this.container = container; + this.weight = weight; + } + } +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/NoAssignmentException.java b/src/java/systest/org/apache/zookeeper/test/system/NoAssignmentException.java new file mode 100644 index 00000000000..3931cdf3907 --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/NoAssignmentException.java @@ -0,0 +1,17 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +public class NoAssignmentException extends Exception { + private static final long serialVersionUID = 1L; + +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/NoAvailableContainers.java b/src/java/systest/org/apache/zookeeper/test/system/NoAvailableContainers.java new file mode 100644 index 00000000000..8266160d098 --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/NoAvailableContainers.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +public class NoAvailableContainers extends Exception { + private static final long serialVersionUID = 1L; + + public NoAvailableContainers(String string) { + super(string); + } + +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java b/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java new file mode 100644 index 00000000000..ea224acc35f --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java @@ -0,0 +1,283 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.test.TestUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.HashMap; +import java.util.Properties; + +class QuorumPeerInstance implements Instance { + final private static Logger LOG = LoggerFactory.getLogger(QuorumPeerInstance.class); + private static final File testData = new File( + System.getProperty("test.data.dir", "build/test/data")); + + private static final int syncLimit = 3; + private static final int initLimit = 3; + private static final int tickTime = 2000; + String serverHostPort; + int serverId; + Reporter r; + QuorumPeer peer; + InetSocketAddress clientAddr; + InetSocketAddress quorumLeaderAddr; + InetSocketAddress quorumLeaderElectionAddr; + HashMap peers; + File snapDir, logDir; + public QuorumPeerInstance() { + try { + File tmpFile = File.createTempFile("test", ".dir", testData); + File tmpDir = tmpFile.getParentFile(); + tmpFile.delete(); + File zkDirs = new File(tmpDir, "zktmp.cfg"); + logDir = tmpDir; + snapDir = tmpDir; + Properties p; + if (zkDirs.exists()) { + p = new Properties(); + FileInputStream input = new FileInputStream(zkDirs); + try { + p.load(input); + } finally { + input.close(); + } + } else { + p = System.getProperties(); + } + logDir = new File(p.getProperty("logDir", tmpDir.getAbsolutePath())); + snapDir = new File(p.getProperty("snapDir", tmpDir.getAbsolutePath())); + logDir = File.createTempFile("zktst", ".dir", logDir); + logDir.delete(); + logDir.mkdirs(); + snapDir = File.createTempFile("zktst", ".dir", snapDir); + snapDir.delete(); + snapDir.mkdirs(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * This method is used to configure a QuorumPeerInstance + * + * @param im the InstanceManager that will be managing the new instance + * @param i the server number to configure (should be zero based) + * @throws NoAvailableContainers + * @throws DuplicateNameException + * @throws InterruptedException + * @throws KeeperException + */ + public static String[] createServer(InstanceManager im, int i) throws NoAvailableContainers, DuplicateNameException, InterruptedException, KeeperException { + return createServer(im, i, true); + } + + /** + * This method is used to configure a QuorumPeerInstance + * + * @param im the InstanceManager that will be managing the new instance + * @param i the server number to configure (should be zero based) + * @param leaderServes if false, the leader will not accept client connections + * @throws NoAvailableContainers + * @throws DuplicateNameException + * @throws InterruptedException + * @throws KeeperException + */ + public static String[] createServer(InstanceManager im, int i, boolean leaderServes) throws NoAvailableContainers, DuplicateNameException, InterruptedException, KeeperException { + im.assignInstance("server" + i, QuorumPeerInstance.class, Integer.toString(i) + " " + leaderServes, 50); + return im.getStatus("server" + i, 3000).split(","); + + } + + /** + * Start an instance of the quorumPeer. + * @param im the manager of the instance + * @param quorumHostPort the comma-separated list of host:port pairs of quorum peers + * @param index the zero based index of the server to start. + * @throws InterruptedException + * @throws KeeperException + * @throws NoAssignmentException + */ + public static void startInstance(InstanceManager im, String quorumHostPort, int index) throws InterruptedException, KeeperException, NoAssignmentException { + im.resetStatus("server" + index); + im.reconfigureInstance("server" + index, quorumHostPort + " start"); + im.getStatus("server" + index, 5000); + } + + /** + * Stop an instance of the quorumPeer + * @param im the manager of the instance + * @param index the zero based index fo the server to stop + * @throws InterruptedException + * @throws KeeperException + * @throws NoAssignmentException + */ + public static void stopInstance(InstanceManager im, int index) throws InterruptedException, KeeperException, NoAssignmentException { + im.resetStatus("server" + index); + im.reconfigureInstance("server" + index, Integer.toString(index) + " stop"); + im.getStatus("server" + index, 3000); + + } + + public void setReporter(Reporter r) { + this.r = r; + } + + public void configure(String params) { + if (clientAddr == null) { + String parts[] = params.split(" "); + // The first time we are configured, it is just to tell + // us which machine we are + serverId = Integer.parseInt(parts[0]); + if (LOG.isDebugEnabled()) { + LOG.debug("Setting up server " + serverId); + } + if (parts.length > 1 && parts[1].equals("false")) { + System.setProperty("zookeeper.leaderServes", "no"); + } else { + System.setProperty("zookeeper.leaderServes", "yes"); + } + // Let's grab two ports + try { + ServerSocket ss = new ServerSocket(0, 1, InetAddress.getLocalHost()); + clientAddr = (InetSocketAddress) ss.getLocalSocketAddress(); + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + ServerSocket ss = new ServerSocket(0, 1, InetAddress.getLocalHost()); + quorumLeaderAddr = (InetSocketAddress) ss.getLocalSocketAddress(); + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + ServerSocket ss = new ServerSocket(0, 1, InetAddress.getLocalHost()); + quorumLeaderElectionAddr = (InetSocketAddress) ss.getLocalSocketAddress(); + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } + String report = clientAddr.getHostString() + ':' + clientAddr.getPort() + + ',' + quorumLeaderAddr.getHostString() + ':' + quorumLeaderAddr.getPort() + ':' + quorumLeaderElectionAddr.getPort(); + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Reporting " + report); + } + r.report(report); + } catch (Exception e) { + e.printStackTrace(); + } + return; + } else { + int spaceIndex = params.indexOf(' '); + if (spaceIndex == -1) { + LOG.warn("looking for host:port,... start|stop, but found " + params); + return; + } + String quorumSpecs = params.substring(0, spaceIndex); + String cmd = params.substring(spaceIndex + 1); + if (LOG.isDebugEnabled()) { + LOG.debug("Running command: " + cmd); + } + if (!cmd.equals("start")) { + if (peer != null) { + peer.shutdown(); + } + peer = null; + try { + for (int i = 0; i < 5; i++) { + Thread.sleep(500); + try { + // Wait until we can't connect + new Socket("127.0.0.1", clientAddr.getPort()).close(); + } catch (IOException e) { + break; + } + } + r.report("stopped"); + } catch (Exception e) { + LOG.error("Unhandled error", e); + } + return; + } + String parts[] = quorumSpecs.split(","); + peers = new HashMap(); + for (int i = 0; i < parts.length; i++) { + // parts[i] == "host:leaderPort:leaderElectionPort;clientPort" + String subparts[] = ((parts[i].split(";"))[0]).split(":"); + String clientPort = (parts[i].split(";"))[1]; + peers.put(Long.valueOf(i), + new QuorumServer( + i, + new InetSocketAddress(subparts[0], Integer.parseInt(subparts[1])), + new InetSocketAddress(subparts[0], Integer.parseInt(subparts[2])), + new InetSocketAddress(subparts[0], Integer.parseInt(clientPort)))); + } + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Starting quorumPeer " + serverId + " on port " + clientAddr.getPort()); + } + if (peer != null) { + LOG.warn("Peer " + serverId + " already started"); + return; + } + System.err.println("SnapDir = " + snapDir + " LogDir = " + logDir); + peer = new QuorumPeer(peers, snapDir, logDir, clientAddr.getPort(), 0, serverId, tickTime, initLimit, syncLimit); + peer.start(); + for (int i = 0; i < 5; i++) { + Thread.sleep(500); + try { + // Wait until we can connect + new Socket("127.0.0.1", clientAddr.getPort()).close(); + break; + } catch (IOException e) { + } + } + r.report("started"); + } catch (Exception e) { + LOG.error("Unhandled exception", e); + } + } + } + + public void start() { + } + + public void stop() { + if (LOG.isDebugEnabled()) { + LOG.debug("Stopping peer " + serverId); + } + if (peer != null) { + peer.shutdown(); + } + if (logDir != null) { + TestUtils.deleteFileRecursively(logDir); + } + if (snapDir != null) { + TestUtils.deleteFileRecursively(snapDir); + } + } + +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/SimpleClient.java b/src/java/systest/org/apache/zookeeper/test/system/SimpleClient.java new file mode 100644 index 00000000000..ed4b84fe0b4 --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/SimpleClient.java @@ -0,0 +1,113 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.AsyncCallback.StringCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; + +/** + * The client that gets spawned for the SimpleSysTest + * + */ +public class SimpleClient implements Instance, Watcher, AsyncCallback.DataCallback, StringCallback, StatCallback { + private static final long serialVersionUID = 1L; + String hostPort; + ZooKeeper zk; + transient int index; + transient String myPath; + byte data[]; + boolean createdEphemeral; + Reporter r; + + public void configure(String params) { + String parts[] = params.split(" "); + hostPort = parts[1]; + this.index = Integer.parseInt(parts[0]); + myPath = "/simpleCase/" + index; + } + + public void start() { + try { + zk = new ZooKeeper(hostPort, 15000, this); + zk.getData("/simpleCase", true, this, null); + if (null != r) { + r.report("Client " + index + " connecting to " + hostPort); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void stop() { + try { + if (zk != null) { + zk.close(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void process(WatchedEvent event) { + if (event.getPath() != null && event.getPath().equals("/simpleCase")) { + zk.getData("/simpleCase", true, this, null); + } + } + + public void processResult(int rc, String path, Object ctx, byte[] data, + Stat stat) { + if (rc != 0) { + zk.getData("/simpleCase", true, this, null); + } else { + this.data = data; + String content = new String(data); + if (content.equals("die")) { + this.stop(); + return; + } + if (!createdEphemeral) { + zk.create(myPath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, this, null); + createdEphemeral = true; + } else { + zk.setData(myPath, data, -1, this, null); + } + } + } + + public void processResult(int rc, String path, Object ctx, String name) { + if (rc != 0) { + zk.create(myPath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, this, null); + } + } + + public void processResult(int rc, String path, Object ctx, Stat stat) { + if (rc != 0) { + zk.setData(myPath, data, -1, this, null); + } + } + + @Override + public String toString() { + return SimpleClient.class.getName() + "[" + index + "] using " + hostPort; + } + + public void setReporter(Reporter r) { + this.r = r; + } +} diff --git a/src/java/systest/org/apache/zookeeper/test/system/SimpleSysTest.java b/src/java/systest/org/apache/zookeeper/test/system/SimpleSysTest.java new file mode 100644 index 00000000000..fd04126eb42 --- /dev/null +++ b/src/java/systest/org/apache/zookeeper/test/system/SimpleSysTest.java @@ -0,0 +1,166 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test.system; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException.ConnectionLossException; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeper.States; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This does a basic system test. It starts up an ensemble of servers and a set of clients. + * It makes sure that all the clients come up. It kills off servers while making a change and + * then ensures that all clients see the change. And then signals the clients to die and + * watches them disappear. + * + */ +public class SimpleSysTest extends BaseSysTest implements Watcher { + final private static Logger LOG = LoggerFactory.getLogger(SimpleSysTest.class); + int maxTries = 10; + boolean connected; + + synchronized private boolean waitForConnect(ZooKeeper zk, long timeout) throws InterruptedException { + connected = (zk.getState() == States.CONNECTED); + long end = Time.currentElapsedTime() + timeout; + while (!connected && end > Time.currentElapsedTime()) { + wait(timeout); + connected = (zk.getState() == States.CONNECTED); + } + return connected; + } + + /** + * This test checks the following: + * 1) All clients connect successfully + * 2) Half of the servers die (assuming odd number) and a write succeeds + * 3) All servers are restarted and cluster stays alive + * 4) Clients see a change by the server + * 5) Clients' ephemeral nodes are cleaned up + * + * @throws Exception + */ + @Test + public void testSimpleCase() throws Exception { + configureServers(serverCount); + configureClients(clientCount, SimpleClient.class, getHostPort()); + Stat stat = new Stat(); + startServers(); + LOG.debug("Connecting to " + getHostPort()); + ZooKeeper zk = new ZooKeeper(getHostPort(), 15000, this); + waitForConnect(zk, 10000); + zk.create("/simpleCase", "orig".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + startClients(); + + // Check that all clients connect properly + for (int i = 0; i < getClientCount(); i++) { + for (int j = 0; j < maxTries; j++) { + try { + byte b[] = zk.getData("/simpleCase/" + i, false, stat); + Assert.assertEquals("orig", new String(b)); + } catch (NoNodeException e) { + if (j + 1 == maxTries) { + Assert.fail("Max tries exceeded on client " + i); + } + Thread.sleep(1000); + } + } + } + + // Kill half the servers, make a change, restart the dead + // servers, and then bounce the other servers one by one + for (int i = 0; i < getServerCount(); i++) { + stopServer(i); + if (i + 1 > getServerCount() / 2) { + startServer(i); + } else if (i + 1 == getServerCount() / 2) { + Assert.assertTrue("Connection didn't recover", waitForConnect(zk, 10000)); + try { + zk.setData("/simpleCase", "new".getBytes(), -1); + } catch (ConnectionLossException e) { + Assert.assertTrue("Connection didn't recover", waitForConnect(zk, 10000)); + zk.setData("/simpleCase", "new".getBytes(), -1); + } + for (int j = 0; j < i; j++) { + LOG.info("Starting server " + j); + startServer(i); + } + } + } + Thread.sleep(100); // wait for things to stabilize + Assert.assertTrue("Servers didn't bounce", waitForConnect(zk, 15000)); + try { + zk.getData("/simpleCase", false, stat); + } catch (ConnectionLossException e) { + Assert.assertTrue("Servers didn't bounce", waitForConnect(zk, 15000)); + } + + // check that the change has propagated to everyone + for (int i = 0; i < getClientCount(); i++) { + for (int j = 0; j < maxTries; j++) { + byte data[] = zk.getData("/simpleCase/" + i, false, stat); + if (new String(data).equals("new")) { + break; + } + if (j + 1 == maxTries) { + Assert.fail("max tries exceeded for " + i); + } + Thread.sleep(1000); + } + } + + // send out the kill signal + zk.setData("/simpleCase", "die".getBytes(), -1); + + // watch for everyone to die + for (int i = 0; i < getClientCount(); i++) { + try { + for (int j = 0; j < maxTries; j++) { + zk.getData("/simpleCase/" + i, false, stat); + if (j + 1 == maxTries) { + Assert.fail("max tries exceeded waiting for child " + i + " to die"); + } + Thread.sleep(200); + } + } catch (NoNodeException e) { + // Great this is what we were hoping for! + } + } + + stopClients(); + stopServers(); + } + + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.SyncConnected) { + synchronized (this) { + connected = true; + notifyAll(); + } + } else if (event.getState() == KeeperState.Disconnected) { + synchronized (this) { + connected = false; + notifyAll(); + } + } + } +} diff --git a/src/java/test/bin/test-patch.properties b/src/java/test/bin/test-patch.properties new file mode 100644 index 00000000000..ce19e47e43f --- /dev/null +++ b/src/java/test/bin/test-patch.properties @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +OK_RELEASEAUDIT_WARNINGS=0 +OK_FINDBUGS_WARNINGS=0 +OK_JAVADOC_WARNINGS=0 diff --git a/src/java/test/bin/test-patch.sh b/src/java/test/bin/test-patch.sh new file mode 100755 index 00000000000..41e827be50d --- /dev/null +++ b/src/java/test/bin/test-patch.sh @@ -0,0 +1,637 @@ +#!/usr/bin/env bash +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +#set -x + +### Setup some variables. +### SVN_REVISION and BUILD_URL are set by Hudson if it is run by patch process +### Read variables from properties file +. `dirname $0`/test-patch.properties + +############################################################################### +parseArgs() { + case "$1" in + HUDSON) + ### Set HUDSON to true to indicate that this script is being run by Hudson + HUDSON=true + if [[ $# != 15 ]] ; then + echo "ERROR: usage $0 HUDSON " + cleanupAndExit 0 + fi + PATCH_DIR=$2 + PS=$3 + WGET=$4 + JIRACLI=$5 + SVN=$6 + GREP=$7 + PATCH=$8 + FINDBUGS_HOME=$9 + FORREST_HOME=${10} + BASEDIR=${11} + JIRA_PASSWD=${12} + JAVA5_HOME=${13} + CURL=${14} + defect=${15} + + ### Retrieve the defect number + if [ -z "$defect" ] ; then + echo "Could not determine the patch to test. Exiting." + cleanupAndExit 0 + fi + + if [ ! -e "$PATCH_DIR" ] ; then + mkdir -p $PATCH_DIR + fi + + ;; + DEVELOPER) + ### Set HUDSON to false to indicate that this script is being run by a developer + HUDSON=false + if [[ $# != 10 ]] ; then + echo "ERROR: usage $0 DEVELOPER " + cleanupAndExit 0 + fi + ### PATCH_FILE contains the location of the patchfile + PATCH_FILE=$2 + if [[ ! -e "$PATCH_FILE" ]] ; then + echo "Unable to locate the patch file $PATCH_FILE" + cleanupAndExit 0 + fi + PATCH_DIR=$3 + ### Check if $PATCH_DIR exists. If it does not exist, create a new directory + if [[ ! -e "$PATCH_DIR" ]] ; then + mkdir "$PATCH_DIR" + if [[ $? == 0 ]] ; then + echo "$PATCH_DIR has been created" + else + echo "Unable to create $PATCH_DIR" + cleanupAndExit 0 + fi + fi + SVN=$4 + GREP=$5 + PATCH=$6 + FINDBUGS_HOME=$7 + FORREST_HOME=$8 + BASEDIR=$9 + JAVA5_HOME=${10} + ### Obtain the patch filename to append it to the version number + defect=`basename $PATCH_FILE` + ;; + *) + echo "ERROR: usage $0 HUDSON [args] | DEVELOPER [args]" + cleanupAndExit 0 + ;; + esac +} + +############################################################################### +checkout () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Testing patch for ${defect}." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + ### When run by a developer, if the workspace contains modifications, do not continue + status=`$SVN stat --ignore-externals | sed -e '/^X[ ]*/D'` + if [[ $HUDSON == "false" ]] ; then + if [[ "$status" != "" ]] ; then + echo "ERROR: can't run in a workspace that contains the following modifications" + echo "$status" + cleanupAndExit 1 + fi + else + cd $BASEDIR + $SVN revert -R . + rm -rf `$SVN status --no-ignore` + $SVN upgrade + $SVN update + fi + return $? +} + +############################################################################### +setup () { + ### Download latest patch file (ignoring .htm and .html) when run from patch process + if [[ $HUDSON == "true" ]] ; then + $WGET -q -O $PATCH_DIR/jira http://issues.apache.org/jira/browse/$defect + if [[ `$GREP -c 'Patch Available' $PATCH_DIR/jira` == 0 ]] ; then + echo "$defect is not \"Patch Available\". Exiting." + cleanupAndExit 0 + fi + relativePatchURL=`$GREP -o '"/jira/secure/attachment/[0-9]*/[^"]*' $PATCH_DIR/jira | $GREP -v -e 'htm[l]*$' | sort | tail -1 | $GREP -o '/jira/secure/attachment/[0-9]*/[^"]*'` + patchURL="http://issues.apache.org${relativePatchURL}" + patchNum=`echo $patchURL | $GREP -o '[0-9]*/' | $GREP -o '[0-9]*'` + echo "$defect patch is being downloaded at `date` from" + echo "$patchURL" + $WGET -q -O $PATCH_DIR/patch $patchURL + JIRA_COMMENT="Here are the results of testing the latest attachment + $patchURL + against trunk revision ${SVN_REVISION}." + + ### Copy the patch file to $PATCH_DIR + else + cp $PATCH_FILE $PATCH_DIR/patch + if [[ $? == 0 ]] ; then + echo "Patch file $PATCH_FILE copied to $PATCH_DIR" + else + echo "Could not copy $PATCH_FILE to $PATCH_DIR" + cleanupAndExit 0 + fi + fi + ### exit if warnings are NOT defined in the properties file + if [ -z "$OK_FINDBUGS_WARNINGS" ] || [[ -z "$OK_JAVADOC_WARNINGS" ]] || [[ -z $OK_RELEASEAUDIT_WARNINGS ]]; then + echo "Please define the following properties in test-patch.properties file" + echo "OK_FINDBUGS_WARNINGS" + echo "OK_RELEASEAUDIT_WARNINGS" + echo "OK_JAVADOC_WARNINGS" + cleanupAndExit 1 + fi + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Pre-build trunk to verify trunk stability and javac warnings" + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + echo "$ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1" + $ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1 + if [[ $? != 0 ]] ; then + echo "Trunk compilation is broken?" + cleanupAndExit 1 + fi +} + +############################################################################### +### Check for @author tags in the patch +checkAuthor () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Checking there are no @author tags in the patch." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + authorTags=`$GREP -c -i '@author' $PATCH_DIR/patch` + echo "There appear to be $authorTags @author tags in the patch." + if [[ $authorTags != 0 ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 @author. The patch appears to contain $authorTags @author tags which the Zookeeper community has agreed to not allow in code contributions." + return 1 + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 @author. The patch does not contain any @author tags." + return 0 +} + +############################################################################### +### Check for tests in the patch +checkTests () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Checking there are new or changed tests in the patch." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + testReferences=`$GREP -c -i '/test' $PATCH_DIR/patch` + echo "There appear to be $testReferences test files referenced in the patch." + if [[ $testReferences == 0 ]] ; then + if [[ $HUDSON == "true" ]] ; then + patchIsDoc=`$GREP -c -i 'title="documentation' $PATCH_DIR/jira` + if [[ $patchIsDoc != 0 ]] ; then + echo "The patch appears to be a documentation patch that doesn't require tests." + JIRA_COMMENT="$JIRA_COMMENT + + +0 tests included. The patch appears to be a documentation patch that doesn't require tests." + return 0 + fi + fi + JIRA_COMMENT="$JIRA_COMMENT + + -1 tests included. The patch doesn't appear to include any new or modified tests. + Please justify why no new tests are needed for this patch. + Also please list what manual steps were performed to verify this patch." + return 1 + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 tests included. The patch appears to include $testReferences new or modified tests." + return 0 +} + +############################################################################### +### Attempt to apply the patch +applyPatch () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Applying patch." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + $PATCH -E -p0 < $PATCH_DIR/patch + if [[ $? != 0 ]] ; then + echo "PATCH APPLICATION FAILED" + JIRA_COMMENT="$JIRA_COMMENT + + -1 patch. The patch command could not apply the patch." + return 1 + fi + return 0 +} + +############################################################################### +### Check there are no javadoc warnings +checkJavadocWarnings () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Determining number of patched javadoc warnings." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt" + $ANT_HOME/bin/ant -DZookeeperPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt + javadocWarnings=`$GREP -o '\[javadoc\] [0-9]* warning' $PATCH_DIR/patchJavadocWarnings.txt | awk '{total += $2} END {print total}'` + echo "" + echo "" + echo "There appear to be $javadocWarnings javadoc warnings generated by the patched build." + + ### if current warnings greater than OK_JAVADOC_WARNINGS + if [[ $javadocWarnings > $OK_JAVADOC_WARNINGS ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 javadoc. The javadoc tool appears to have generated `expr $(($javadocWarnings-$OK_JAVADOC_WARNINGS))` warning messages." + return 1 + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 javadoc. The javadoc tool did not generate any warning messages." + return 0 +} + +############################################################################### +### Check there are no changes in the number of Javac warnings +checkJavacWarnings () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Determining number of patched javac warnings." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + echo "$ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1" + $ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1 + if [[ $? != 0 ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 javac. The patch appears to cause tar ant target to fail." + return 1 + fi + ### Compare trunk and patch javac warning numbers + if [[ -f $PATCH_DIR/patchJavacWarnings.txt ]] ; then + trunkJavacWarnings=`$GREP -o '\[javac\] [0-9]* warning' $PATCH_DIR/trunkJavacWarnings.txt | awk '{total += $2} END {print total}'` + patchJavacWarnings=`$GREP -o '\[javac\] [0-9]* warning' $PATCH_DIR/patchJavacWarnings.txt | awk '{total += $2} END {print total}'` + echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch." + if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then + if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 javac. The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)." + return 1 + fi + fi + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 javac. The applied patch does not increase the total number of javac compiler warnings." + return 0 +} + +############################################################################### +### Check there are no changes in the number of release audit (RAT) warnings +checkReleaseAuditWarnings () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Determining number of patched release audit warnings." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + echo "$ANT_HOME/bin/ant -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1" + $ANT_HOME/bin/ant -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1 + + ### Compare trunk and patch release audit warning numbers + if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then + patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt` + echo "" + echo "" + echo "There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch." + if [[ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ]] ; then + if [[ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 release audit. The applied patch generated $patchReleaseAuditWarnings release audit warnings (more than the trunk's current $OK_RELEASEAUDIT_WARNINGS warnings)." + $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt + echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt + JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt +$JIRA_COMMENT_FOOTER" + return 1 + fi + fi + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 release audit. The applied patch does not increase the total number of release audit warnings." + return 0 +} + +############################################################################### +### Check there are no changes in the number of Checkstyle warnings +checkStyle () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Determining number of patched checkstyle warnings." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + echo "THIS IS NOT IMPLEMENTED YET" + echo "" + echo "" + echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= checkstyle" + $ANT_HOME/bin/ant -DZookeeperPatchProcess= checkstyle + JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html +$JIRA_COMMENT_FOOTER" + ### TODO: calculate actual patchStyleErrors +# patchStyleErrors=0 +# if [[ $patchStyleErrors != 0 ]] ; then +# JIRA_COMMENT="$JIRA_COMMENT +# +# -1 checkstyle. The patch generated $patchStyleErrors code style errors." +# return 1 +# fi +# JIRA_COMMENT="$JIRA_COMMENT +# +# +1 checkstyle. The patch generated 0 code style errors." + return 0 +} + +############################################################################### +### Check there are no changes in the number of Findbugs warnings +checkFindbugsWarnings () { + findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version` + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Determining number of patched Findbugs warnings." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + echo "$ANT_HOME/bin/ant -Dfindbugs.home=$FINDBUGS_HOME -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= findbugs" + $ANT_HOME/bin/ant -Dfindbugs.home=$FINDBUGS_HOME -Djava5.home=${JAVA5_HOME} -Dforrest.home=${FORREST_HOME} -DZookeeperPatchProcess= findbugs + if [ $? != 0 ] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 findbugs. The patch appears to cause Findbugs (version ${findbugs_version}) to fail." + return 1 + fi +JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html +$JIRA_COMMENT_FOOTER" + cp $BASEDIR/build/test/findbugs/*.xml $PATCH_DIR/patchFindbugsWarnings.xml + $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \ + $PATCH_DIR/patchFindbugsWarnings.xml \ + $PATCH_DIR/patchFindbugsWarnings.xml + findbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings.xml \ + $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml | /usr/bin/awk '{print $1}'` + $FINDBUGS_HOME/bin/convertXmlToText -html \ + $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml \ + $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.html + cp $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.html $PATCH_DIR/newPatchFindbugsWarnings.html + cp $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml $PATCH_DIR/newPatchFindbugsWarnings.xml + + ### if current warnings greater than OK_FINDBUGS_WARNINGS + if [[ $findbugsWarnings > $OK_FINDBUGS_WARNINGS ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 findbugs. The patch appears to introduce `expr $(($findbugsWarnings-$OK_FINDBUGS_WARNINGS))` new Findbugs (version ${findbugs_version}) warnings." + return 1 + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 findbugs. The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings." + return 0 +} + +############################################################################### +### Run the test-core target +runCoreTests () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Running core tests." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + + ### Kill any rogue build processes from the last attempt + $PS auxwww | $GREP ZookeeperPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null + + echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes -Dtest.junit.threads=8 -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME -Djava5.home=$JAVA5_HOME test-core" + $ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes -Dtest.junit.threads=8 -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME -Djava5.home=$JAVA5_HOME test-core + if [[ $? != 0 ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 core tests. The patch failed core unit tests." + return 1 + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 core tests. The patch passed core unit tests." + return 0 +} + +############################################################################### +### Run the test-contrib target +runContribTests () { + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Running contrib tests." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + + ### Kill any rogue build processes from the last attempt + $PS auxwww | $GREP ZookeeperPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null + + echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes test-contrib" + $ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes test-contrib + if [[ $? != 0 ]] ; then + JIRA_COMMENT="$JIRA_COMMENT + + -1 contrib tests. The patch failed contrib unit tests." + return 1 + fi + JIRA_COMMENT="$JIRA_COMMENT + + +1 contrib tests. The patch passed contrib unit tests." + return 0 +} + +############################################################################### +### Submit a comment to the defect's Jira +submitJiraComment () { + local result=$1 + ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer + if [[ $HUDSON == "false" ]] ; then + JIRA_COMMENT_FOOTER="" + fi + if [[ $result == 0 ]] ; then + comment="+1 overall. $JIRA_COMMENT + +$JIRA_COMMENT_FOOTER" + else + comment="-1 overall. $JIRA_COMMENT + +$JIRA_COMMENT_FOOTER" + fi + ### Output the test result to the console + echo " + + + +$comment" + + if [[ $HUDSON == "true" ]] ; then + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Adding comment to Jira." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + ### Update Jira with a comment + export USER=hudson + $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect + $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD + fi +} + +############################################################################### +### Cleanup files +cleanupAndExit () { + local result=$1 + if [[ $HUDSON == "true" ]] ; then + if [ -e "$PATCH_DIR" ] ; then + mv $PATCH_DIR $BASEDIR + fi + fi + echo "" + echo "" + echo "======================================================================" + echo "======================================================================" + echo " Finished build." + echo "======================================================================" + echo "======================================================================" + echo "" + echo "" + exit $result +} + +############################################################################### +############################################################################### +############################################################################### + +JIRA_COMMENT="" +JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console + +This message is automatically generated." + +### Check if arguments to the script have been specified properly or not +parseArgs $@ +cd $BASEDIR + +checkout +RESULT=$? +if [[ $HUDSON == "true" ]] ; then + if [[ $RESULT != 0 ]] ; then + exit 100 + fi +fi +setup +checkAuthor +RESULT=$? + +checkTests +(( RESULT = RESULT + $? )) +applyPatch +if [[ $? != 0 ]] ; then + submitJiraComment 1 + cleanupAndExit 1 +fi +checkJavadocWarnings +(( RESULT = RESULT + $? )) +checkJavacWarnings +(( RESULT = RESULT + $? )) +### Checkstyle not implemented yet +#checkStyle +#(( RESULT = RESULT + $? )) +checkFindbugsWarnings +(( RESULT = RESULT + $? )) +checkReleaseAuditWarnings +(( RESULT = RESULT + $? )) +### Do not call these when run by a developer +if [[ $HUDSON == "true" ]] ; then + runCoreTests + (( RESULT = RESULT + $? )) + runContribTests + (( RESULT = RESULT + $? )) +fi +JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/ +$JIRA_COMMENT_FOOTER" + +submitJiraComment $RESULT +cleanupAndExit $RESULT diff --git a/src/java/test/bin/test-scripts.sh b/src/java/test/bin/test-scripts.sh new file mode 100755 index 00000000000..ad175badb00 --- /dev/null +++ b/src/java/test/bin/test-scripts.sh @@ -0,0 +1,223 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ZKS=bin/zkServer.sh +ZKSI=bin/zkServer-initialize.sh + +if [ ! -d "conf" ]; then + echo "run this from the toplevel directory" + exit 1 +fi + +if [ ! `ls build/zookeeper*.jar` ]; then + echo "first compile the zk jar file" + exit 1 +fi + +DATADIR=test-scripts_datadir +DATALOGDIR=test-scripts_datalogdir + +case "`uname`" in + CYGWIN*) cygwin=true ;; + *) cygwin=false ;; +esac + +if $cygwin +then + ZOOCFG=`cygpath -wp "$ZOOCFG"` + # cygwin has a "kill" in the shell itself, gets confused + KILL=/bin/kill +else + KILL=kill +fi + +fail() { + # don't run clear_tmp to allow debugging + echo "FAIL $1" + $KILL -9 $(cat "$ZOOPIDFILE") + $KILL -9 $$ +} + +#generate a minimal config +genconfig1() { + cat > test-scripts.cfg <> test-scripts.cfg < + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        + + +

        CheckStyle Audit

        +
        Designed for use with CheckStyle and Ant. +
        +
        + + + +
        + + + +
        + + + + +
        + + + + +
        + + + +

        Files

        + + + + + + + + + + + + + + +
        NameErrors
        + + + + + +
        +
        + + + + +

        File + +

        + + + + + + + + + + + + + + +
        Error DescriptionLine
        + + + +
        + Back to top +
        + + + +

        Summary

        + + + + + + + + + + + + +
        FilesErrors
        + + + +
        +
        + + + + a + b + + + + + diff --git a/src/java/test/checkstyle.xml b/src/java/test/checkstyle.xml new file mode 100644 index 00000000000..3b24ede6787 --- /dev/null +++ b/src/java/test/checkstyle.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/test/config/findbugsExcludeFile.xml b/src/java/test/config/findbugsExcludeFile.xml new file mode 100644 index 00000000000..226f570fcf1 --- /dev/null +++ b/src/java/test/config/findbugsExcludeFile.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/test/data/buffersize/create/version-2/log.1 b/src/java/test/data/buffersize/create/version-2/log.1 new file mode 100644 index 00000000000..4f05bc1cb45 Binary files /dev/null and b/src/java/test/data/buffersize/create/version-2/log.1 differ diff --git a/src/java/test/data/buffersize/create/version-2/snapshot.0 b/src/java/test/data/buffersize/create/version-2/snapshot.0 new file mode 100644 index 00000000000..49b512e65af Binary files /dev/null and b/src/java/test/data/buffersize/create/version-2/snapshot.0 differ diff --git a/src/java/test/data/buffersize/set/version-2/log.1 b/src/java/test/data/buffersize/set/version-2/log.1 new file mode 100644 index 00000000000..8586f16bf73 Binary files /dev/null and b/src/java/test/data/buffersize/set/version-2/log.1 differ diff --git a/src/java/test/data/buffersize/set/version-2/snapshot.0 b/src/java/test/data/buffersize/set/version-2/snapshot.0 new file mode 100644 index 00000000000..49b512e65af Binary files /dev/null and b/src/java/test/data/buffersize/set/version-2/snapshot.0 differ diff --git a/src/java/test/data/buffersize/snapshot/version-2/log.1 b/src/java/test/data/buffersize/snapshot/version-2/log.1 new file mode 100644 index 00000000000..2f145a68386 Binary files /dev/null and b/src/java/test/data/buffersize/snapshot/version-2/log.1 differ diff --git a/src/java/test/data/buffersize/snapshot/version-2/snapshot.0 b/src/java/test/data/buffersize/snapshot/version-2/snapshot.0 new file mode 100644 index 00000000000..49b512e65af Binary files /dev/null and b/src/java/test/data/buffersize/snapshot/version-2/snapshot.0 differ diff --git a/src/java/test/data/buffersize/snapshot/version-2/snapshot.2 b/src/java/test/data/buffersize/snapshot/version-2/snapshot.2 new file mode 100644 index 00000000000..59dfa701a83 Binary files /dev/null and b/src/java/test/data/buffersize/snapshot/version-2/snapshot.2 differ diff --git a/src/java/test/data/invalidsnap/version-2/log.1 b/src/java/test/data/invalidsnap/version-2/log.1 new file mode 100644 index 00000000000..9dc15ae8d84 Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/log.1 differ diff --git a/src/java/test/data/invalidsnap/version-2/log.274 b/src/java/test/data/invalidsnap/version-2/log.274 new file mode 100644 index 00000000000..3bb868e2694 Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/log.274 differ diff --git a/src/java/test/data/invalidsnap/version-2/log.63b b/src/java/test/data/invalidsnap/version-2/log.63b new file mode 100644 index 00000000000..4ee0a98a42b Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/log.63b differ diff --git a/src/java/test/data/invalidsnap/version-2/snapshot.0 b/src/java/test/data/invalidsnap/version-2/snapshot.0 new file mode 100644 index 00000000000..49b512e65af Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/snapshot.0 differ diff --git a/src/java/test/data/invalidsnap/version-2/snapshot.272 b/src/java/test/data/invalidsnap/version-2/snapshot.272 new file mode 100644 index 00000000000..71f32a5dc02 Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/snapshot.272 differ diff --git a/src/java/test/data/invalidsnap/version-2/snapshot.273 b/src/java/test/data/invalidsnap/version-2/snapshot.273 new file mode 100644 index 00000000000..3146f565663 Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/snapshot.273 differ diff --git a/src/java/test/data/invalidsnap/version-2/snapshot.639 b/src/java/test/data/invalidsnap/version-2/snapshot.639 new file mode 100644 index 00000000000..cf9e38985ee Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/snapshot.639 differ diff --git a/src/java/test/data/invalidsnap/version-2/snapshot.83f b/src/java/test/data/invalidsnap/version-2/snapshot.83f new file mode 100644 index 00000000000..26dc5f66521 Binary files /dev/null and b/src/java/test/data/invalidsnap/version-2/snapshot.83f differ diff --git a/src/java/test/data/ssl/README.md b/src/java/test/data/ssl/README.md new file mode 100644 index 00000000000..b8823d8a3de --- /dev/null +++ b/src/java/test/data/ssl/README.md @@ -0,0 +1,10 @@ +SSL test data +=================== + +testKeyStore.jks +--- +Testing keystore, password is "testpass". + +testTrustStore.jks +--- +Testing truststore, password is "testpass". diff --git a/src/java/test/data/ssl/testKeyStore.jks b/src/java/test/data/ssl/testKeyStore.jks new file mode 100644 index 00000000000..40a7d0b7eae Binary files /dev/null and b/src/java/test/data/ssl/testKeyStore.jks differ diff --git a/src/java/test/data/ssl/testTrustStore.jks b/src/java/test/data/ssl/testTrustStore.jks new file mode 100644 index 00000000000..33f09c11dfa Binary files /dev/null and b/src/java/test/data/ssl/testTrustStore.jks differ diff --git a/src/java/test/data/upgrade/log.100000001 b/src/java/test/data/upgrade/log.100000001 new file mode 100644 index 00000000000..00655f15fab Binary files /dev/null and b/src/java/test/data/upgrade/log.100000001 differ diff --git a/src/java/test/data/upgrade/log.100001bf0 b/src/java/test/data/upgrade/log.100001bf0 new file mode 100644 index 00000000000..83fa6973e50 Binary files /dev/null and b/src/java/test/data/upgrade/log.100001bf0 differ diff --git a/src/java/test/data/upgrade/snapshot.100000000 b/src/java/test/data/upgrade/snapshot.100000000 new file mode 100644 index 00000000000..56f90157fbc Binary files /dev/null and b/src/java/test/data/upgrade/snapshot.100000000 differ diff --git a/src/java/test/data/upgrade/snapshot.100001bec b/src/java/test/data/upgrade/snapshot.100001bec new file mode 100644 index 00000000000..0010d1eb8c6 Binary files /dev/null and b/src/java/test/data/upgrade/snapshot.100001bec differ diff --git a/src/java/test/org/apache/jute/BinaryInputArchiveTest.java b/src/java/test/org/apache/jute/BinaryInputArchiveTest.java new file mode 100644 index 00000000000..3b959fa2930 --- /dev/null +++ b/src/java/test/org/apache/jute/BinaryInputArchiveTest.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.jute; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + + +// TODO: introduce JuteTestCase as in ZKTestCase +public class BinaryInputArchiveTest { + + @Test + public void testReadStringCheckLength() { + byte[] buf = new byte[]{ + Byte.MAX_VALUE, Byte.MAX_VALUE, Byte.MAX_VALUE, Byte.MAX_VALUE}; + ByteArrayInputStream is = new ByteArrayInputStream(buf); + BinaryInputArchive ia = BinaryInputArchive.getArchive(is); + try { + ia.readString(""); + Assert.fail("Should have thrown an IOException"); + } catch (IOException e) { + Assert.assertTrue("Not 'Unreasonable length' exception: " + e, + e.getMessage().startsWith(BinaryInputArchive.UNREASONBLE_LENGTH)); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/ClientReconnectTest.java b/src/java/test/org/apache/zookeeper/ClientReconnectTest.java new file mode 100644 index 00000000000..83cdb67c75c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/ClientReconnectTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + + +import org.apache.zookeeper.client.HostProvider; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.SocketChannel; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.mockito.Matchers.anyLong; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClientReconnectTest extends ZKTestCase { + private SocketChannel sc; + private CountDownLatch countDownLatch = new CountDownLatch(3); + + @Test + public void testClientReconnect() throws IOException, InterruptedException { + HostProvider hostProvider = mock(HostProvider.class); + when(hostProvider.size()).thenReturn(1); + InetSocketAddress inaddr = new InetSocketAddress("127.0.0.1", 1111); + when(hostProvider.next(anyLong())).thenReturn(inaddr); + ZooKeeper zk = mock(ZooKeeper.class); + sc = SocketChannel.open(); + + ClientCnxnSocketNIO nioCnxn = new MockCnxn(); + ClientWatchManager watcher = mock(ClientWatchManager.class); + ClientCnxn clientCnxn = new ClientCnxn( + "tmp", hostProvider, 5000, + zk, watcher, nioCnxn, false); + clientCnxn.start(); + countDownLatch.await(5000, TimeUnit.MILLISECONDS); + Assert.assertTrue(countDownLatch.getCount() == 0); + clientCnxn.close(); + } + + class MockCnxn extends ClientCnxnSocketNIO { + MockCnxn() throws IOException { + super(); + } + + @Override + void registerAndConnect(SocketChannel sock, InetSocketAddress addr) throws + IOException { + countDownLatch.countDown(); + throw new IOException("failed to register"); + } + + @Override + SocketChannel createSock() { + return sc; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/CustomHostProviderTest.java b/src/java/test/org/apache/zookeeper/CustomHostProviderTest.java new file mode 100644 index 00000000000..8bdbc2c9740 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/CustomHostProviderTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + +import org.apache.zookeeper.client.HostProvider; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicInteger; + +public class CustomHostProviderTest extends ZKTestCase implements Watcher { + private AtomicInteger counter = new AtomicInteger(3); + + @Override + public void process(WatchedEvent event) { + } + + @Test + public void testZooKeeperWithCustomHostProvider() throws IOException, + InterruptedException { + final int CLIENT_PORT = PortAssignment.unique(); + final HostProvider specialHostProvider = new SpecialHostProvider(); + int expectedCounter = 3; + counter.set(expectedCounter); + + ZooKeeper zkDefaults = new ZooKeeper("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT, this, false); + + ZooKeeper zkSpecial = new ZooKeeper("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT, this, false, specialHostProvider); + + Assert.assertTrue(counter.get() == expectedCounter); + zkDefaults.updateServerList("127.0.0.1:" + PortAssignment.unique()); + Assert.assertTrue(counter.get() == expectedCounter); + + zkSpecial.updateServerList("127.0.0.1:" + PortAssignment.unique()); + expectedCounter--; + Assert.assertTrue(counter.get() == expectedCounter); + } + + private class SpecialHostProvider implements HostProvider { + // ignores its connectstring, and next() always returns localhost:2181 + // it will count down when updateServerList() is called + @Override + public int size() { + return 1; + } + + @Override + public InetSocketAddress next(long spinDelay) { + return new InetSocketAddress("127.0.0.1", 2181); + } + + @Override + public void onConnected() { + } + + @Override + public boolean updateServerList(Collection + serverAddresses, InetSocketAddress currentHost) { + counter.decrementAndGet(); + return false; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java b/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java new file mode 100644 index 00000000000..ee880f90c89 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.junit.Test; +import org.junit.internal.runners.statements.InvokeMethod; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.List; + +/** + * The sole responsibility of this class is to print to the log when a test + * starts and when it finishes. + */ +public class JUnit4ZKTestRunner extends BlockJUnit4ClassRunner { + private static final Logger LOG = LoggerFactory.getLogger(JUnit4ZKTestRunner.class); + + public JUnit4ZKTestRunner(Class klass) throws InitializationError { + super(klass); + } + + public static List computeTestMethodsForClass(final Class klass, final List defaultMethods) { + List list = defaultMethods; + String methodName = System.getProperty("test.method"); + if (methodName == null) { + LOG.info("No test.method specified. using default methods."); + } else { + LOG.info("Picked up test.method={}", methodName); + try { + list = Arrays.asList(new FrameworkMethod(klass.getMethod(methodName))); + } catch (NoSuchMethodException nsme) { + LOG.warn("{} does not have test.method={}. failing to default methods.", klass.getName(), methodName); + } + } + return list; + } + + + @Override + protected List computeTestMethods() { + return computeTestMethodsForClass(getTestClass().getJavaClass(), super.computeTestMethods()); + } + + @Override + protected Statement methodInvoker(FrameworkMethod method, Object test) { + return new LoggedInvokeMethod(method, test); + } + + public static class LoggedInvokeMethod extends InvokeMethod { + private final FrameworkMethod method; + private final String name; + + public LoggedInvokeMethod(FrameworkMethod method, Object target) { + super(method, target); + this.method = method; + name = method.getName(); + } + + @Override + public void evaluate() throws Throwable { + LOG.info("RUNNING TEST METHOD {}", name); + try { + super.evaluate(); + Runtime rt = Runtime.getRuntime(); + long usedKB = (rt.totalMemory() - rt.freeMemory()) / 1024; + LOG.info("Memory used {}", usedKB); + ThreadGroup tg = Thread.currentThread().getThreadGroup(); + while (tg.getParent() != null) { + tg = tg.getParent(); + } + LOG.info("Number of threads {}", tg.activeCount()); + } catch (Throwable t) { + // The test method threw an exception, but it might be an + // expected exception as defined in the @Test annotation. + // Check the annotation and log an appropriate message. + Test annotation = this.method.getAnnotation(Test.class); + if (annotation != null && annotation.expected() != null && + annotation.expected().isAssignableFrom(t.getClass())) { + LOG.info("TEST METHOD {} THREW EXPECTED EXCEPTION {}", name, + annotation.expected()); + } else { + LOG.info("TEST METHOD FAILED {}", name, t); + } + throw t; + } + LOG.info("FINISHED TEST METHOD {}", name); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/JaasConfiguration.java b/src/java/test/org/apache/zookeeper/JaasConfiguration.java new file mode 100644 index 00000000000..7ba10a29729 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/JaasConfiguration.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.login.AppConfigurationEntry; +import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag; + +/** + * This helper class allows to programmatically create a JAAS configuration. + * Each section must have a name and a login module, and a set of key/values + * to describe login options. + * + * Example: + * jaas = new JaasConfiguration(); + * jaas.addSection("Server", "org.apache.zookeeper.server.auth.DigestLoginModule", + * "username", "passowrd"); + */ +public class JaasConfiguration extends javax.security.auth.login.Configuration { + private final Map sections = + new HashMap(); + + public JaasConfiguration() { + } + + /** + * Add a section to the jaas.conf + * @param name Section name + * @param loginModuleName Login module name + * @param args login key/value args + */ + public void addSection(String name, String loginModuleName, String... args) { + Map conf = new HashMap(); + // loop through the args (must be key/value sequence) + for (int i = 0; i < args.length - 1; i += 2) { + conf.put(args[i], args[i + 1]); + } + addSection(name, loginModuleName, conf); + } + + /** + * Add a section to the jaas.conf + * @param name Section name + * @param loginModuleName Login module name + * @param conf login key/value args + */ + public void addSection(String name, String loginModuleName, final Map conf) { + AppConfigurationEntry[] entries = new AppConfigurationEntry[1]; + entries[0] = new AppConfigurationEntry(loginModuleName, LoginModuleControlFlag.REQUIRED, conf); + this.sections.put(name, entries); + } + + @Override + public AppConfigurationEntry[] getAppConfigurationEntry(String appName) { + return sections.get(appName); + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/MockPacket.java b/src/java/test/org/apache/zookeeper/MockPacket.java new file mode 100644 index 00000000000..7af80832cf3 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/MockPacket.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.Record; +import org.apache.zookeeper.ZooKeeper.WatchRegistration; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; + +import java.nio.ByteBuffer; + +public class MockPacket extends ClientCnxn.Packet { + + public MockPacket(RequestHeader requestHeader, ReplyHeader replyHeader, + Record request, Record response, + WatchRegistration watchRegistration) { + super(requestHeader, replyHeader, request, response, watchRegistration); + } + + public MockPacket(RequestHeader requestHeader, ReplyHeader replyHeader, + Record request, Record response, + WatchRegistration watchRegistration, boolean readOnly) { + super(requestHeader, replyHeader, request, response, watchRegistration, readOnly); + } + + public ByteBuffer createAndReturnBB() { + createBB(); + return this.bb; + } + +} diff --git a/src/java/test/org/apache/zookeeper/MultiResponseTest.java b/src/java/test/org/apache/zookeeper/MultiResponseTest.java new file mode 100644 index 00000000000..75d9a1207a1 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/MultiResponseTest.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ByteBufferInputStream; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +public class MultiResponseTest extends ZKTestCase { + public void testRoundTrip() throws IOException { + MultiResponse response = new MultiResponse(); + + response.add(new OpResult.CheckResult()); + response.add(new OpResult.CreateResult("foo-bar")); + response.add(new OpResult.DeleteResult()); + + Stat s = new Stat(); + s.setCzxid(546); + response.add(new OpResult.SetDataResult(s)); + + MultiResponse decodedResponse = codeDecode(response); + + Assert.assertEquals(response, decodedResponse); + Assert.assertEquals(response.hashCode(), decodedResponse.hashCode()); + } + + @Test + public void testEmptyRoundTrip() throws IOException { + MultiResponse result = new MultiResponse(); + MultiResponse decodedResult = codeDecode(result); + + Assert.assertEquals(result, decodedResult); + Assert.assertEquals(result.hashCode(), decodedResult.hashCode()); + } + + private MultiResponse codeDecode(MultiResponse request) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + request.serialize(boa, "result"); + baos.close(); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + bb.rewind(); + + BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); + MultiResponse decodedRequest = new MultiResponse(); + decodedRequest.deserialize(bia, "result"); + return decodedRequest; + } + +} diff --git a/src/java/test/org/apache/zookeeper/MultiTransactionRecordTest.java b/src/java/test/org/apache/zookeeper/MultiTransactionRecordTest.java new file mode 100644 index 00000000000..4b850d76551 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/MultiTransactionRecordTest.java @@ -0,0 +1,61 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.server.ByteBufferInputStream; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +public class MultiTransactionRecordTest extends ZKTestCase { + @Test + public void testRoundTrip() throws IOException { + MultiTransactionRecord request = new MultiTransactionRecord(); + request.add(Op.check("check", 1)); + request.add(Op.create("create", "create data".getBytes(), ZooDefs.Ids.CREATOR_ALL_ACL, ZooDefs.Perms.ALL)); + request.add(Op.delete("delete", 17)); + request.add(Op.setData("setData", "set data".getBytes(), 19)); + + MultiTransactionRecord decodedRequest = codeDecode(request); + + Assert.assertEquals(request, decodedRequest); + Assert.assertEquals(request.hashCode(), decodedRequest.hashCode()); + } + + @Test + public void testEmptyRoundTrip() throws IOException { + MultiTransactionRecord request = new MultiTransactionRecord(); + MultiTransactionRecord decodedRequest = codeDecode(request); + + Assert.assertEquals(request, decodedRequest); + Assert.assertEquals(request.hashCode(), decodedRequest.hashCode()); + } + + private MultiTransactionRecord codeDecode(MultiTransactionRecord request) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + request.serialize(boa, "request"); + baos.close(); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + bb.rewind(); + + BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); + MultiTransactionRecord decodedRequest = new MultiTransactionRecord(); + decodedRequest.deserialize(bia, "request"); + return decodedRequest; + } +} diff --git a/src/java/test/org/apache/zookeeper/PortAssignment.java b/src/java/test/org/apache/zookeeper/PortAssignment.java new file mode 100644 index 00000000000..a7c81a6beda --- /dev/null +++ b/src/java/test/org/apache/zookeeper/PortAssignment.java @@ -0,0 +1,203 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** Assign ports to tests */ +public final class PortAssignment { + private static final Logger LOG = LoggerFactory.getLogger(PortAssignment.class); + + // The available port range that we use stays away from the ephemeral port + // range, which the OS will assign to client socket connections. We can't + // coordinate with the OS on the assignment of those ports, so it's best to + // stay out of that range to avoid conflicts. Typical ranges for ephemeral + // ports are: + // - IANA suggests 49152 - 65535 + // - Linux typically uses 32768 - 61000 + // - FreeBSD modern versions typically use the IANA suggested range + // - Windows modern versions typically use the IANA suggested range + private static final int GLOBAL_BASE_PORT = 11221; + private static final int GLOBAL_MAX_PORT = 32767; + + private static PortRange portRange = null; + private static int nextPort; + + /** + * There is no reason to instantiate this class. + */ + private PortAssignment() { + } + + /** + * Assign a new, unique port to the test. This method works by assigning + * ports from a valid port range as identified by the total number of + * concurrent test processes and the ID of this test process. Each + * concurrent test process uses an isolated range, so it's not possible for + * multiple test processes to collide on the same port. Within the port + * range, ports are assigned in monotonic increasing order, wrapping around + * to the beginning of the range if needed. As an extra precaution, the + * method attempts to bind to the port and immediately close it before + * returning it to the caller. If the port cannot be bound, then it tries + * the next one in the range. This provides some resiliency in case the port + * is otherwise occupied, such as a developer running other servers on the + * machine running the tests. + * + * @return port + */ + public synchronized static int unique() { + if (portRange == null) { + portRange = setupPortRange(System.getProperty("test.junit.threads"), + System.getProperty("sun.java.command")); + nextPort = portRange.getMinimum(); + } + int candidatePort = nextPort; + for (; ; ) { + ++candidatePort; + if (candidatePort > portRange.getMaximum()) { + candidatePort = portRange.getMinimum(); + } + if (candidatePort == nextPort) { + throw new IllegalStateException(String.format( + "Could not assign port from range %s. The entire " + + "range has been exhausted.", portRange)); + } + try { + ServerSocket s = new ServerSocket(candidatePort); + s.close(); + nextPort = candidatePort; + LOG.info("Assigned port {} from range {}.", nextPort, portRange); + return nextPort; + } catch (IOException e) { + LOG.debug("Could not bind to port {} from range {}. " + + "Attempting next port.", candidatePort, portRange, e); + } + } + } + + /** + * Sets up the port range to be used. In typical usage, Ant invokes JUnit, + * possibly using multiple JUnit processes to execute multiple test suites + * concurrently. The count of JUnit processes is passed from Ant as a system + * property named "test.junit.threads". Ant's JUnit runner receives the + * thread ID as a command line argument of the form threadid=N, where N is an + * integer in the range [1, ${test.junit.threads}]. It's not otherwise + * accessible, so we need to parse it from the command line. This method + * uses these 2 pieces of information to split the available ports into + * disjoint ranges. Each JUnit process only assigns ports from its own range + * in order to prevent bind errors during concurrent test runs. If any of + * this information is unavailable or unparseable, then the default behavior + * is for this process to use the entire available port range. This is + * expected when running tests outside of Ant. + * + * @param strProcessCount string representation of integer process count, + * typically taken from system property test.junit.threads + * @param cmdLine command line containing threadid=N argument, typically + * taken from system property sun.java.command + * @return port range to use + */ + static PortRange setupPortRange(String strProcessCount, String cmdLine) { + Integer processCount = null; + if (strProcessCount != null && !strProcessCount.isEmpty()) { + try { + processCount = Integer.valueOf(strProcessCount); + } catch (NumberFormatException e) { + LOG.warn("Error parsing test.junit.threads = {}.", + strProcessCount, e); + } + } + + Integer threadId = null; + if (processCount != null) { + if (cmdLine != null && !cmdLine.isEmpty()) { + Matcher m = Pattern.compile("threadid=(\\d+)").matcher(cmdLine); + if (m.find()) { + try { + threadId = Integer.valueOf(m.group(1)); + } catch (NumberFormatException e) { + LOG.warn("Error parsing threadid from {}.", cmdLine, e); + } + } + } + } + + final PortRange newPortRange; + if (processCount != null && processCount > 1 && threadId != null) { + // We know the total JUnit process count and this test process's ID. + // Use these values to calculate the valid range for port assignments + // within this test process. We lose a few possible ports to the + // remainder, but that's acceptable. + int portRangeSize = (GLOBAL_MAX_PORT - GLOBAL_BASE_PORT) / + processCount; + int minPort = GLOBAL_BASE_PORT + ((threadId - 1) * portRangeSize); + int maxPort = minPort + portRangeSize - 1; + newPortRange = new PortRange(minPort, maxPort); + LOG.info("Test process {}/{} using ports from {}.", threadId, + processCount, newPortRange); + } else { + // If running outside the context of Ant or Ant is using a single + // test process, then use all valid ports. + newPortRange = new PortRange(GLOBAL_BASE_PORT, GLOBAL_MAX_PORT); + LOG.info("Single test process using ports from {}.", newPortRange); + } + + return newPortRange; + } + + /** + * Contains the minimum and maximum (both inclusive) in a range of ports. + */ + static final class PortRange { + private final int minimum; + private final int maximum; + + /** + * Creates a new PortRange. + * + * @param minimum lower bound port number + * @param maximum upper bound port number + */ + PortRange(int minimum, int maximum) { + this.minimum = minimum; + this.maximum = maximum; + } + + /** + * Returns maximum port in the range. + * + * @return maximum + */ + int getMaximum() { + return maximum; + } + + /** + * Returns minimum port in the range. + * + * @return minimum + */ + int getMinimum() { + return minimum; + } + + @Override + public String toString() { + return String.format("%d - %d", minimum, maximum); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/PortAssignmentTest.java b/src/java/test/org/apache/zookeeper/PortAssignmentTest.java new file mode 100644 index 00000000000..aa5208cddf6 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/PortAssignmentTest.java @@ -0,0 +1,73 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +@Parameterized.UseParametersRunnerFactory(ZKParameterized.RunnerFactory.class) +public class PortAssignmentTest { + + private final String strProcessCount; + private final String cmdLine; + private final int expectedMinimumPort; + private final int expectedMaximumPort; + + public PortAssignmentTest(String strProcessCount, String cmdLine, + int expectedMinimumPort, int expectedMaximumPort) { + this.strProcessCount = strProcessCount; + this.cmdLine = cmdLine; + this.expectedMinimumPort = expectedMinimumPort; + this.expectedMaximumPort = expectedMaximumPort; + } + + @Parameters + public static Collection data() { + return Arrays.asList( + new Object[]{"8", "threadid=1", 11221, 13913}, + new Object[]{"8", "threadid=2", 13914, 16606}, + new Object[]{"8", "threadid=3", 16607, 19299}, + new Object[]{"8", "threadid=4", 19300, 21992}, + new Object[]{"8", "threadid=5", 21993, 24685}, + new Object[]{"8", "threadid=6", 24686, 27378}, + new Object[]{"8", "threadid=7", 27379, 30071}, + new Object[]{"8", "threadid=8", 30072, 32764}, + new Object[]{"1", "threadid=1", 11221, 32767}, + new Object[]{"2", "threadid=1", 11221, 21993}, + new Object[]{"2", "threadid=2", 21994, 32766}, + new Object[]{null, null, 11221, 32767}, + new Object[]{"", "", 11221, 32767}); + } + + @Test + public void testSetupPortRange() { + PortAssignment.PortRange portRange = PortAssignment.setupPortRange( + strProcessCount, cmdLine); + assertEquals(buildAssertionMessage("minimum"), expectedMinimumPort, + portRange.getMinimum()); + assertEquals(buildAssertionMessage("maximum"), expectedMaximumPort, + portRange.getMaximum()); + } + + private String buildAssertionMessage(String checkType) { + return String.format("strProcessCount = %s, cmdLine = %s, checking %s", + strProcessCount, cmdLine, checkType); + } +} diff --git a/src/java/test/org/apache/zookeeper/RemoveWatchesCmdTest.java b/src/java/test/org/apache/zookeeper/RemoveWatchesCmdTest.java new file mode 100644 index 00000000000..95aa9f31215 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/RemoveWatchesCmdTest.java @@ -0,0 +1,338 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Testing remove watches using command line + */ +public class RemoveWatchesCmdTest extends ClientBase { + private static final Logger LOG = LoggerFactory + .getLogger(RemoveWatchesCmdTest.class); + private ZooKeeper zk; + private ZooKeeperMain zkMain; + + @Override + public void setUp() throws Exception { + super.setUp(); + zk = createClient(); + zkMain = new ZooKeeperMain(zk); + } + + @Override + public void tearDown() throws Exception { + if (zk != null) { + zk.close(); + } + super.tearDown(); + } + + /** + * Test verifies default options. When there is no passed options, + * removewatches command will use default options - WatcherType.ANY and + * local=false + */ + @Test(timeout = 30000) + public void testRemoveWatchesWithNoPassedOptions() throws Exception { + List expectedEvents = new ArrayList(); + expectedEvents.add(EventType.ChildWatchRemoved); + expectedEvents.add(EventType.DataWatchRemoved); + MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 2); + + zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.create("/testnode2", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + LOG.info("Adding childwatcher to /testnode1 and /testnode2"); + zk.getChildren("/testnode1", myWatcher); + zk.getChildren("/testnode2", myWatcher); + + LOG.info("Adding datawatcher to /testnode1 and /testnode2"); + zk.getData("/testnode1", myWatcher, null); + zk.getData("/testnode2", myWatcher, null); + + String cmdstring = "removewatches /testnode1"; + LOG.info("Remove watchers using shell command : {}", cmdstring); + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Removewatches cmd fails to remove child watches", + zkMain.processZKCmd(zkMain.cl)); + LOG.info("Waiting for the DataWatchRemoved event"); + myWatcher.matches(); + + // verifying that other path child watches are not affected + Assert.assertTrue( + "Failed to find child watches for the path testnode2", zk + .getChildWatches().contains("/testnode2")); + Assert.assertTrue("Failed to find data watches for the path testnode2", + zk.getDataWatches().contains("/testnode2")); + } + + /** + * Test verifies deletion of NodeDataChanged watches + */ + @Test(timeout = 30000) + public void testRemoveNodeDataChangedWatches() throws Exception { + LOG.info("Adding data watcher using getData()"); + List expectedEvents = new ArrayList(); + expectedEvents.add(EventType.DataWatchRemoved); + MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1); + + zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.getData("/testnode1", myWatcher, null); + + String cmdstring = "removewatches /testnode1 -d"; + LOG.info("Remove watchers using shell command : {}", cmdstring); + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Removewatches cmd fails to remove data watches", + zkMain.processZKCmd(zkMain.cl)); + + LOG.info("Waiting for the DataWatchRemoved event"); + myWatcher.matches(); + + // verifying that other path data watches are removed + Assert.assertEquals( + "Data watches are not removed : " + zk.getDataWatches(), 0, zk + .getDataWatches().size()); + } + + /** + * Test verifies deletion of NodeCreated data watches + */ + @Test(timeout = 30000) + public void testRemoveNodeCreatedWatches() throws Exception { + List expectedEvents = new ArrayList(); + expectedEvents.add(EventType.DataWatchRemoved); + MyWatcher myWatcher1 = new MyWatcher("/testnode1", expectedEvents, 1); + MyWatcher myWatcher2 = new MyWatcher("/testnode1/testnode2", + expectedEvents, 1); + // Adding pre-created watcher + LOG.info("Adding NodeCreated watcher"); + zk.exists("/testnode1", myWatcher1); + zk.exists("/testnode1/testnode2", myWatcher2); + + String cmdstring1 = "removewatches /testnode1 -d"; + LOG.info("Remove watchers using shell command : {}", cmdstring1); + zkMain.cl.parseCommand(cmdstring1); + Assert.assertTrue( + "Removewatches cmd fails to remove pre-create watches", + zkMain.processZKCmd(zkMain.cl)); + myWatcher1.matches(); + Assert.assertEquals( + "Failed to remove pre-create watches :" + zk.getExistWatches(), + 1, zk.getExistWatches().size()); + Assert.assertTrue( + "Failed to remove pre-create watches :" + zk.getExistWatches(), + zk.getExistWatches().contains("/testnode1/testnode2")); + + String cmdstring2 = "removewatches /testnode1/testnode2 -d"; + LOG.info("Remove watchers using shell command : {}", cmdstring2); + zkMain.cl.parseCommand(cmdstring2); + Assert.assertTrue("Removewatches cmd fails to remove data watches", + zkMain.processZKCmd(zkMain.cl)); + + myWatcher2.matches(); + Assert.assertEquals( + "Failed to remove pre-create watches : " + zk.getExistWatches(), + 0, zk.getExistWatches().size()); + } + + /** + * Test verifies deletion of NodeChildrenChanged watches + */ + @Test(timeout = 30000) + public void testRemoveNodeChildrenChangedWatches() throws Exception { + List expectedEvents = new ArrayList(); + expectedEvents.add(EventType.ChildWatchRemoved); + MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1); + + zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + LOG.info("Adding child changed watcher"); + zk.getChildren("/testnode1", myWatcher); + + String cmdstring = "removewatches /testnode1 -c"; + LOG.info("Remove watchers using shell command : {}", cmdstring); + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Removewatches cmd fails to remove child watches", + zkMain.processZKCmd(zkMain.cl)); + myWatcher.matches(); + Assert.assertEquals( + "Failed to remove child watches : " + zk.getChildWatches(), 0, + zk.getChildWatches().size()); + } + + /** + * Test verifies deletion of NodeDeleted watches + */ + @Test(timeout = 30000) + public void testRemoveNodeDeletedWatches() throws Exception { + LOG.info("Adding NodeDeleted watcher"); + List expectedEvents = new ArrayList(); + expectedEvents.add(EventType.ChildWatchRemoved); + expectedEvents.add(EventType.NodeDeleted); + MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1); + + zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.create("/testnode1/testnode2", "data".getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.getChildren("/testnode1/testnode2", myWatcher); + zk.getChildren("/testnode1", myWatcher); + + String cmdstring = "removewatches /testnode1 -c"; + LOG.info("Remove watchers using shell command : {}", cmdstring); + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Removewatches cmd fails to remove child watches", + zkMain.processZKCmd(zkMain.cl)); + LOG.info("Waiting for the ChildWatchRemoved event"); + myWatcher.matches(); + Assert.assertEquals( + "Failed to remove child watches : " + zk.getChildWatches(), 1, + zk.getChildWatches().size()); + + Assert.assertTrue( + "Failed to remove child watches :" + zk.getChildWatches(), zk + .getChildWatches().contains("/testnode1/testnode2")); + + // verify node delete watcher + zk.delete("/testnode1/testnode2", -1); + myWatcher.matches(); + } + + /** + * Test verifies deletion of any watches + */ + @Test(timeout = 30000) + public void testRemoveAnyWatches() throws Exception { + verifyRemoveAnyWatches(false); + } + + /** + * Test verifies deletion of watches locally when there is no server + * connection + */ + @Test(timeout = 30000) + public void testRemoveWatchesLocallyWhenNoServerConnection() + throws Exception { + verifyRemoveAnyWatches(true); + } + + private void verifyRemoveAnyWatches(boolean local) throws Exception { + final Map> pathVsEvent = new HashMap>(); + LOG.info("Adding NodeChildrenChanged, NodeDataChanged watchers"); + final CountDownLatch watcherLatch = new CountDownLatch(2); + Watcher watcher = new Watcher() { + + @Override + public void process(WatchedEvent event) { + switch (event.getType()) { + case ChildWatchRemoved: + case DataWatchRemoved: { + addWatchNotifications(pathVsEvent, event); + watcherLatch.countDown(); + break; + } + case NodeChildrenChanged: + case NodeDataChanged: { + addWatchNotifications(pathVsEvent, event); + break; + } + } + } + + private void addWatchNotifications( + final Map> pathVsEvent, + WatchedEvent event) { + List events = pathVsEvent.get(event.getPath()); + if (null == events) { + events = new ArrayList(); + pathVsEvent.put(event.getPath(), events); + } + events.add(event.getType()); + } + }; + zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.getChildren("/testnode1", watcher); + zk.getData("/testnode1", watcher, null); + String cmdstring = "removewatches /testnode1 -a"; + if (local) { + LOG.info("Stopping ZK server to verify deletion of watches locally"); + stopServer(); + cmdstring = "removewatches /testnode1 -a -l"; + } + + LOG.info("Remove watchers using shell command : {}", cmdstring); + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue( + "Removewatches cmd fails to remove child/data watches", + zkMain.processZKCmd(zkMain.cl)); + LOG.info("Waiting for the WatchRemoved events"); + watcherLatch.await(10, TimeUnit.SECONDS); + Assert.assertEquals("Didn't receives WatchRemoved events!", 1, + pathVsEvent.size()); + Assert.assertTrue( + "Didn't receives DataWatchRemoved!", + pathVsEvent.get("/testnode1").contains( + EventType.DataWatchRemoved)); + Assert.assertTrue("Didn't receives ChildWatchRemoved!", pathVsEvent + .get("/testnode1").contains(EventType.ChildWatchRemoved)); + } + + private class MyWatcher implements Watcher { + private final String path; + private final CountDownLatch latch; + private final List expectedEvents = new ArrayList(); + private String eventPath; + + public MyWatcher(String path, List expectedEvents, int count) { + this.path = path; + this.latch = new CountDownLatch(count); + this.expectedEvents.addAll(expectedEvents); + } + + public void process(WatchedEvent event) { + LOG.debug("Event path : {}, eventPath : {}" + + new Object[]{path, event.getPath()}); + this.eventPath = event.getPath(); + if (expectedEvents.contains(event.getType())) { + latch.countDown(); + } + } + + public boolean matches() throws InterruptedException { + if (!latch.await(CONNECTION_TIMEOUT / 3, TimeUnit.MILLISECONDS)) { + LOG.error("Failed to get watch notifications!"); + return false; + } + LOG.debug("Client path : {} eventPath : {}", new Object[]{path, + eventPath}); + return path.equals(eventPath); + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/RemoveWatchesTest.java b/src/java/test/org/apache/zookeeper/RemoveWatchesTest.java new file mode 100644 index 00000000000..b4224ef8267 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/RemoveWatchesTest.java @@ -0,0 +1,1246 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.KeeperException.NoWatcherException; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Verifies removing watches using ZooKeeper client apis + */ +@RunWith(Parameterized.class) +@Parameterized.UseParametersRunnerFactory(ZKParameterized.RunnerFactory.class) +public class RemoveWatchesTest extends ClientBase { + private static final Logger LOG = LoggerFactory + .getLogger(RemoveWatchesTest.class); + private final boolean useAsync; + private ZooKeeper zk1 = null; + private ZooKeeper zk2 = null; + + public RemoveWatchesTest(boolean useAsync) { + this.useAsync = useAsync; + } + + @Parameters + public static Collection configs() { + return Arrays.asList(new Object[][]{{false}, {true},}); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + zk1 = createClient(); + zk2 = createClient(); + } + + @Override + public void tearDown() throws Exception { + if (zk1 != null) + zk1.close(); + if (zk2 != null) + zk2.close(); + super.tearDown(); + } + + private void removeWatches(ZooKeeper zk, String path, Watcher watcher, + WatcherType watcherType, boolean local, KeeperException.Code rc) + throws InterruptedException, KeeperException { + LOG.info( + "Sending removeWatches req using zk {} path: {} type: {} watcher: {} ", + new Object[]{zk, path, watcherType, watcher}); + if (useAsync) { + MyCallback c1 = new MyCallback(rc.intValue(), path); + zk.removeWatches(path, watcher, watcherType, local, c1, null); + Assert.assertTrue("Didn't succeeds removeWatch operation", + c1.matches()); + if (KeeperException.Code.OK.intValue() != c1.rc) { + KeeperException ke = KeeperException + .create(KeeperException.Code.get(c1.rc)); + throw ke; + } + } else { + zk.removeWatches(path, watcher, watcherType, local); + } + } + + private void removeAllWatches(ZooKeeper zk, String path, + WatcherType watcherType, boolean local, KeeperException.Code rc) + throws InterruptedException, KeeperException { + LOG.info("Sending removeWatches req using zk {} path: {} type: {} ", + new Object[]{zk, path, watcherType}); + if (useAsync) { + MyCallback c1 = new MyCallback(rc.intValue(), path); + zk.removeAllWatches(path, watcherType, local, c1, null); + Assert.assertTrue("Didn't succeeds removeWatch operation", + c1.matches()); + if (KeeperException.Code.OK.intValue() != c1.rc) { + KeeperException ke = KeeperException + .create(KeeperException.Code.get(c1.rc)); + throw ke; + } + } else { + zk.removeAllWatches(path, watcherType, local); + } + } + + /** + * Test verifies removal of single watcher when there is server connection + */ + @Test(timeout = 90000) + public void testRemoveSingleWatcher() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + zk1.create("/node2", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + MyWatcher w1 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + MyWatcher w2 = new MyWatcher("/node2", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node2", w2)); + removeWatches(zk2, "/node1", w1, WatcherType.Data, false, Code.OK); + Assert.assertEquals("Didn't find data watcher", 1, + zk2.getDataWatches().size()); + Assert.assertEquals("Didn't find data watcher", "/node2", + zk2.getDataWatches().get(0)); + removeWatches(zk2, "/node2", w2, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove data watcher", w2.matches()); + // closing session should remove ephemeral nodes and trigger data + // watches if any + if (zk1 != null) { + zk1.close(); + zk1 = null; + } + + List events = w1.getEventsAfterWatchRemoval(); + Assert.assertFalse( + "Shouldn't get NodeDeletedEvent after watch removal", + events.contains(EventType.NodeDeleted)); + Assert.assertEquals( + "Shouldn't get NodeDeletedEvent after watch removal", 0, + events.size()); + } + + /** + * Test verifies removal of multiple data watchers when there is server + * connection + */ + @Test(timeout = 90000) + public void testMultipleDataWatchers() throws IOException, + InterruptedException, KeeperException { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + MyWatcher w1 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + MyWatcher w2 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + removeWatches(zk2, "/node1", w2, WatcherType.Data, false, Code.OK); + Assert.assertEquals("Didn't find data watcher", 1, + zk2.getDataWatches().size()); + Assert.assertEquals("Didn't find data watcher", "/node1", + zk2.getDataWatches().get(0)); + removeWatches(zk2, "/node1", w1, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove data watcher", w2.matches()); + // closing session should remove ephemeral nodes and trigger data + // watches if any + if (zk1 != null) { + zk1.close(); + zk1 = null; + } + + List events = w2.getEventsAfterWatchRemoval(); + Assert.assertEquals( + "Shouldn't get NodeDeletedEvent after watch removal", 0, + events.size()); + } + + /** + * Test verifies removal of multiple child watchers when there is server + * connection + */ + @Test(timeout = 90000) + public void testMultipleChildWatchers() throws IOException, + InterruptedException, KeeperException { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 1); + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w1); + MyWatcher w2 = new MyWatcher("/node1", 1); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w2); + removeWatches(zk2, "/node1", w2, WatcherType.Children, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", w2.matches()); + Assert.assertEquals("Didn't find child watcher", 1, zk2 + .getChildWatches().size()); + removeWatches(zk2, "/node1", w1, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", w1.matches()); + // create child to see NodeChildren notification + zk1.create("/node1/node2", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + // waiting for child watchers to be notified + int count = 30; + while (count > 0) { + if (w1.getEventsAfterWatchRemoval().size() > 0) { + break; + } + count--; + Thread.sleep(100); + } + // watcher2 + List events = w2.getEventsAfterWatchRemoval(); + Assert.assertEquals("Shouldn't get NodeChildrenChanged event", 0, + events.size()); + } + + /** + * Test verifies null watcher with WatcherType.Any - remove all the watchers + * data, child, exists + */ + @Test(timeout = 90000) + public void testRemoveAllWatchers() throws IOException, + InterruptedException, KeeperException { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 2); + MyWatcher w2 = new MyWatcher("/node1", 2); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w1); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w2); + removeWatches(zk2, "/node1", w1, WatcherType.Any, false, Code.OK); + removeWatches(zk2, "/node1", w2, WatcherType.Any, false, Code.OK); + zk1.create("/node1/child", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + Assert.assertTrue("Didn't remove data watcher", w1.matches()); + Assert.assertTrue("Didn't remove child watcher", w2.matches()); + } + + /** + * Test verifies null watcher with WatcherType.Data - remove all data + * watchers. Child watchers shouldn't be removed + */ + @Test(timeout = 90000) + public void testRemoveAllDataWatchers() throws IOException, + InterruptedException, KeeperException { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 1); + MyWatcher w2 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w1); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w2); + removeWatches(zk2, "/node1", w1, WatcherType.Data, false, Code.OK); + removeWatches(zk2, "/node1", w2, WatcherType.Data, false, Code.OK); + zk1.create("/node1/child", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + Assert.assertTrue("Didn't remove data watcher", w1.matches()); + Assert.assertTrue("Didn't remove data watcher", w2.matches()); + // waiting for child watchers to be notified + int count = 10; + while (count > 0) { + if (w1.getEventsAfterWatchRemoval().size() > 0 + && w2.getEventsAfterWatchRemoval().size() > 0) { + break; + } + count--; + Thread.sleep(1000); + } + // watcher1 + List events = w1.getEventsAfterWatchRemoval(); + Assert.assertEquals("Didn't get NodeChildrenChanged event", 1, + events.size()); + Assert.assertTrue("Didn't get NodeChildrenChanged event", + events.contains(EventType.NodeChildrenChanged)); + // watcher2 + events = w2.getEventsAfterWatchRemoval(); + Assert.assertEquals("Didn't get NodeChildrenChanged event", 1, + events.size()); + Assert.assertTrue("Didn't get NodeChildrenChanged event", + events.contains(EventType.NodeChildrenChanged)); + } + + /** + * Test verifies null watcher with WatcherType.Children - remove all child + * watchers. Data watchers shouldn't be removed + */ + @Test(timeout = 90000) + public void testRemoveAllChildWatchers() throws IOException, + InterruptedException, KeeperException { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 1); + MyWatcher w2 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w1); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w2); + removeWatches(zk2, "/node1", w1, WatcherType.Children, false, Code.OK); + removeWatches(zk2, "/node1", w2, WatcherType.Children, false, Code.OK); + zk1.setData("/node1", "test".getBytes(), -1); + Assert.assertTrue("Didn't remove child watcher", w1.matches()); + Assert.assertTrue("Didn't remove child watcher", w2.matches()); + // waiting for child watchers to be notified + int count = 10; + while (count > 0) { + if (w1.getEventsAfterWatchRemoval().size() > 0 + && w2.getEventsAfterWatchRemoval().size() > 0) { + break; + } + count--; + Thread.sleep(1000); + } + // watcher1 + List events = w1.getEventsAfterWatchRemoval(); + Assert.assertEquals("Didn't get NodeDataChanged event", 1, + events.size()); + Assert.assertTrue("Didn't get NodeDataChanged event", + events.contains(EventType.NodeDataChanged)); + // watcher2 + events = w2.getEventsAfterWatchRemoval(); + Assert.assertEquals("Didn't get NodeDataChanged event", 1, + events.size()); + Assert.assertTrue("Didn't get NodeDataChanged event", + events.contains(EventType.NodeDataChanged)); + } + + /** + * Test verifies given watcher doesn't exists! + */ + @Test(timeout = 90000) + public void testNoWatcherException() throws IOException, + InterruptedException, KeeperException { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 2); + MyWatcher w2 = new MyWatcher("/node1", 2); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNull("Didn't set data watches", zk2.exists("/node2", w2)); + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w1); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w2); + + // New Watcher which will be used for removal + MyWatcher w3 = new MyWatcher("/node1", 2); + + try { + removeWatches(zk2, "/node1", w3, WatcherType.Any, false, + Code.NOWATCHER); + Assert.fail("Should throw exception as given watcher doesn't exists"); + } catch (KeeperException.NoWatcherException nwe) { + // expected + } + try { + removeWatches(zk2, "/node1", w3, WatcherType.Children, false, + Code.NOWATCHER); + Assert.fail("Should throw exception as given watcher doesn't exists"); + } catch (KeeperException.NoWatcherException nwe) { + // expected + } + try { + removeWatches(zk2, "/node1", w3, WatcherType.Data, false, + Code.NOWATCHER); + Assert.fail("Should throw exception as given watcher doesn't exists"); + } catch (KeeperException.NoWatcherException nwe) { + // expected + } + try { + removeWatches(zk2, "/nonexists", w3, WatcherType.Data, false, + Code.NOWATCHER); + Assert.fail("Should throw exception as given watcher doesn't exists"); + } catch (KeeperException.NoWatcherException nwe) { + // expected + } + } + + /** + * Test verifies WatcherType.Any - removes only the configured data watcher + * function + */ + @Test(timeout = 90000) + public void testRemoveAnyDataWatcher() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 1); + MyWatcher w2 = new MyWatcher("/node1", 2); + // Add multiple data watches + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + // Add child watch + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w2); + removeWatches(zk2, "/node1", w1, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove data watcher", w1.matches()); + Assert.assertEquals("Didn't find child watcher", 1, zk2 + .getChildWatches().size()); + Assert.assertEquals("Didn't find data watcher", 1, zk2 + .getDataWatches().size()); + removeWatches(zk2, "/node1", w2, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", w2.matches()); + } + + /** + * Test verifies WatcherType.Any - removes only the configured child watcher + * function + */ + @Test(timeout = 90000) + public void testRemoveAnyChildWatcher() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 2); + MyWatcher w2 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + // Add multiple child watches + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w2); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w1); + removeWatches(zk2, "/node1", w2, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", w2.matches()); + Assert.assertEquals("Didn't find child watcher", 1, zk2 + .getChildWatches().size()); + Assert.assertEquals("Didn't find data watcher", 1, zk2 + .getDataWatches().size()); + removeWatches(zk2, "/node1", w1, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove watchers", w1.matches()); + } + + /** + * Test verifies when there is no server connection. Remove watches when + * local=true, otw should retain it + */ + @Test(timeout = 90000) + public void testRemoveWatcherWhenNoConnection() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 2); + MyWatcher w2 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + // Add multiple child watches + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w1); + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w2); + stopServer(); + removeWatches(zk2, "/node1", w2, WatcherType.Any, true, Code.OK); + Assert.assertTrue("Didn't remove child watcher", w2.matches()); + Assert.assertFalse("Shouldn't remove data watcher", w1.matches()); + try { + removeWatches(zk2, "/node1", w1, WatcherType.Any, false, + Code.CONNECTIONLOSS); + Assert.fail("Should throw exception as last watch removal requires server connection"); + } catch (KeeperException.ConnectionLossException nwe) { + // expected + } + Assert.assertFalse("Shouldn't remove data watcher", w1.matches()); + + // when local=true, here if connection not available, simply removes + // from local session + removeWatches(zk2, "/node1", w1, WatcherType.Any, true, Code.OK); + Assert.assertTrue("Didn't remove data watcher", w1.matches()); + } + + /** + * Test verifies many pre-node watchers. Also, verifies internal + * datastructure 'watchManager.existWatches' + */ + @Test(timeout = 90000) + public void testManyPreNodeWatchers() throws Exception { + int count = 50; + List wList = new ArrayList(count); + MyWatcher w; + String path = "/node"; + // Exists watcher + for (int i = 0; i < count; i++) { + final String nodePath = path + i; + w = new MyWatcher(nodePath, 1); + wList.add(w); + LOG.info("Adding pre node watcher {} on path {}", new Object[]{w, + nodePath}); + zk1.exists(nodePath, w); + } + Assert.assertEquals("Failed to add watchers!", count, zk1 + .getExistWatches().size()); + for (int i = 0; i < count; i++) { + final MyWatcher watcher = wList.get(i); + removeWatches(zk1, path + i, watcher, WatcherType.Data, false, + Code.OK); + Assert.assertTrue("Didn't remove data watcher", watcher.matches()); + } + Assert.assertEquals("Didn't remove watch references!", 0, zk1 + .getExistWatches().size()); + } + + /** + * Test verifies many child watchers. Also, verifies internal datastructure + * 'watchManager.childWatches' + */ + @Test(timeout = 90000) + public void testManyChildWatchers() throws Exception { + int count = 50; + List wList = new ArrayList(count); + MyWatcher w; + String path = "/node"; + + // Child watcher + for (int i = 0; i < count; i++) { + String nodePath = path + i; + zk1.create(nodePath, null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + nodePath += "/"; + } + for (int i = 0; i < count; i++) { + String nodePath = path + i; + w = new MyWatcher(path + i, 1); + wList.add(w); + LOG.info("Adding child watcher {} on path {}", new Object[]{w, + nodePath}); + zk1.getChildren(nodePath, w); + nodePath += "/"; + } + Assert.assertEquals("Failed to add watchers!", count, zk1 + .getChildWatches().size()); + for (int i = 0; i < count; i++) { + final MyWatcher watcher = wList.get(i); + removeWatches(zk1, path + i, watcher, WatcherType.Children, false, + Code.OK); + Assert.assertTrue("Didn't remove child watcher", watcher.matches()); + } + Assert.assertEquals("Didn't remove watch references!", 0, zk1 + .getChildWatches().size()); + } + + /** + * Test verifies many data watchers. Also, verifies internal datastructure + * 'watchManager.dataWatches' + */ + @Test(timeout = 90000) + public void testManyDataWatchers() throws Exception { + int count = 50; + List wList = new ArrayList(count); + MyWatcher w; + String path = "/node"; + + // Data watcher + for (int i = 0; i < count; i++) { + String nodePath = path + i; + w = new MyWatcher(path + i, 1); + wList.add(w); + zk1.create(nodePath, null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + LOG.info("Adding data watcher {} on path {}", new Object[]{w, + nodePath}); + zk1.getData(nodePath, w, null); + nodePath += "/"; + } + Assert.assertEquals("Failed to add watchers!", count, zk1 + .getDataWatches().size()); + for (int i = 0; i < count; i++) { + final MyWatcher watcher = wList.get(i); + removeWatches(zk1, path + i, watcher, WatcherType.Data, false, + Code.OK); + Assert.assertTrue("Didn't remove data watcher", watcher.matches()); + } + Assert.assertEquals("Didn't remove watch references!", 0, zk1 + .getDataWatches().size()); + } + + /** + * Test verifies removal of many watchers locally when no connection and + * WatcherType#Any. Also, verifies internal watchManager datastructures + */ + @Test(timeout = 90000) + public void testManyWatchersWhenNoConnection() throws Exception { + int count = 3; + List wList = new ArrayList(count); + MyWatcher w; + String path = "/node"; + + // Child watcher + for (int i = 0; i < count; i++) { + String nodePath = path + i; + zk1.create(nodePath, null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + nodePath += "/"; + } + for (int i = 0; i < count; i++) { + String nodePath = path + i; + w = new MyWatcher(path + i, 2); + wList.add(w); + LOG.info("Adding child watcher {} on path {}", new Object[]{w, + nodePath}); + zk1.getChildren(nodePath, w); + nodePath += "/"; + } + Assert.assertEquals("Failed to add watchers!", count, zk1 + .getChildWatches().size()); + + // Data watcher + for (int i = 0; i < count; i++) { + String nodePath = path + i; + w = wList.get(i); + LOG.info("Adding data watcher {} on path {}", new Object[]{w, + nodePath}); + zk1.getData(nodePath, w, null); + nodePath += "/"; + } + Assert.assertEquals("Failed to add watchers!", count, zk1 + .getDataWatches().size()); + stopServer(); + for (int i = 0; i < count; i++) { + final MyWatcher watcher = wList.get(i); + removeWatches(zk1, path + i, watcher, WatcherType.Any, true, + Code.OK); + Assert.assertTrue("Didn't remove watcher", watcher.matches()); + } + Assert.assertEquals("Didn't remove watch references!", 0, zk1 + .getChildWatches().size()); + Assert.assertEquals("Didn't remove watch references!", 0, zk1 + .getDataWatches().size()); + } + + /** + * Test verifies removing watcher having namespace + */ + @Test(timeout = 90000) + public void testChRootRemoveWatcher() throws Exception { + // creating the subtree for chRoot clients. + String chRoot = "/appsX"; + zk1.create("/appsX", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + if (zk1 != null) { + zk1.close(); + } + if (zk2 != null) { + zk2.close(); + } + // Creating chRoot client. + zk1 = createClient(this.hostPort + chRoot); + zk2 = createClient(this.hostPort + chRoot); + + LOG.info("Creating child znode /node1 using chRoot client"); + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + MyWatcher w1 = new MyWatcher("/node1", 2); + MyWatcher w2 = new MyWatcher("/node1", 1); + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + // Add multiple child watches + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + zk2.getChildren("/node1", w2); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + zk2.getChildren("/node1", w1); + removeWatches(zk2, "/node1", w1, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", w1.matches()); + Assert.assertEquals("Didn't find child watcher", 1, zk2 + .getChildWatches().size()); + removeWatches(zk2, "/node1", w2, WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", w2.matches()); + } + + /** + * Verify that if a given watcher doesn't exist, the server properly + * returns an error code for it. + * + * In our Java client implementation, we check that a given watch exists at + * two points: + * + * 1) before submitting the RemoveWatches request + * 2) after a successful server response, when the watcher needs to be + * removed + * + * Since this can be racy (i.e. a watch can fire while a RemoveWatches + * request is in-flight), we need to verify that the watch was actually + * removed (i.e. from ZKDatabase and DataTree) and return NOWATCHER if + * needed. + * + * Also, other implementations might not do a client side check before + * submitting a RemoveWatches request. If we don't do a server side check, + * we would just return ZOK even if no watch was removed. + * + */ + @Test(timeout = 90000) + public void testNoWatcherServerException() + throws InterruptedException, IOException, TimeoutException { + CountdownWatcher watcher = new CountdownWatcher(); + MyZooKeeper zk = new MyZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher); + boolean nw = false; + + watcher.waitForConnected(CONNECTION_TIMEOUT); + + try { + zk.removeWatches("/nowatchhere", watcher, WatcherType.Data, false); + } catch (KeeperException nwe) { + if (nwe.code().intValue() == Code.NOWATCHER.intValue()) { + nw = true; + } + } + + Assert.assertTrue("Server didn't return NOWATCHER", + zk.getRemoveWatchesRC() == Code.NOWATCHER.intValue()); + Assert.assertTrue("NoWatcherException didn't happen", nw); + } + + /** + * Test verifies given watcher doesn't exists! + */ + @Test(timeout = 90000) + public void testRemoveAllNoWatcherException() throws IOException, + InterruptedException, KeeperException { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + try { + removeAllWatches(zk2, "/node1", WatcherType.Any, false, + Code.NOWATCHER); + Assert.fail("Should throw exception as given watcher doesn't exists"); + } catch (KeeperException.NoWatcherException nwe) { + // expected + } + } + + /** + * Test verifies null watcher + */ + @Test(timeout = 30000) + public void testNullWatcherReference() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + try { + if (useAsync) { + zk1.removeWatches("/node1", null, WatcherType.Data, false, + null, null); + } else { + zk1.removeWatches("/node1", null, WatcherType.Data, false); + } + Assert.fail("Must throw IllegalArgumentException as watcher is null!"); + } catch (IllegalArgumentException iae) { + // expected + } + } + + /** + * Test verifies WatcherType.Data - removes only the configured data watcher + * function + */ + @Test(timeout = 90000) + public void testRemoveWhenMultipleDataWatchesOnAPath() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + final CountDownLatch dataWatchCount = new CountDownLatch(1); + final CountDownLatch rmWatchCount = new CountDownLatch(1); + Watcher w1 = new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getType() == EventType.DataWatchRemoved) { + rmWatchCount.countDown(); + } + } + }; + Watcher w2 = new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getType() == EventType.NodeDataChanged) { + dataWatchCount.countDown(); + } + } + }; + // Add multiple data watches + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + + removeWatches(zk2, "/node1", w1, WatcherType.Data, false, Code.OK); + Assert.assertTrue("Didn't remove data watcher", + rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + + zk1.setData("/node1", "test".getBytes(), -1); + LOG.info("Waiting for data watchers to be notified"); + Assert.assertTrue("Didn't get data watch notification!", + dataWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + } + + /** + * Test verifies WatcherType.Children - removes only the configured child + * watcher function + */ + @Test(timeout = 90000) + public void testRemoveWhenMultipleChildWatchesOnAPath() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + final CountDownLatch childWatchCount = new CountDownLatch(1); + final CountDownLatch rmWatchCount = new CountDownLatch(1); + Watcher w1 = new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getType() == EventType.ChildWatchRemoved) { + rmWatchCount.countDown(); + } + } + }; + Watcher w2 = new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getType() == EventType.NodeChildrenChanged) { + childWatchCount.countDown(); + } + } + }; + // Add multiple child watches + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertEquals("Didn't set child watches", 0, + zk2.getChildren("/node1", w1).size()); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertEquals("Didn't set child watches", 0, + zk2.getChildren("/node1", w2).size()); + + removeWatches(zk2, "/node1", w1, WatcherType.Children, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", + rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + + zk1.create("/node1/node2", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + LOG.info("Waiting for child watchers to be notified"); + Assert.assertTrue("Didn't get child watch notification!", + childWatchCount + .await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + } + + /** + * Test verifies WatcherType.Data - removes only the configured data watcher + * function + */ + @Test(timeout = 90000) + public void testRemoveAllDataWatchesOnAPath() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + final CountDownLatch dWatchCount = new CountDownLatch(2); + final CountDownLatch rmWatchCount = new CountDownLatch(2); + Watcher w1 = new Watcher() { + @Override + public void process(WatchedEvent event) { + switch (event.getType()) { + case DataWatchRemoved: + rmWatchCount.countDown(); + break; + case NodeDataChanged: + dWatchCount.countDown(); + break; + default: + break; + } + } + }; + Watcher w2 = new Watcher() { + @Override + public void process(WatchedEvent event) { + switch (event.getType()) { + case DataWatchRemoved: + rmWatchCount.countDown(); + break; + case NodeDataChanged: + dWatchCount.countDown(); + break; + default: + break; + } + } + }; + // Add multiple data watches + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + + Assert.assertTrue("Server session is not a watcher", + isServerSessionWatcher(zk2.getSessionId(), "/node1", + WatcherType.Data)); + removeAllWatches(zk2, "/node1", WatcherType.Data, false, Code.OK); + Assert.assertTrue("Didn't remove data watcher", + rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + + Assert.assertFalse("Server session is still a watcher after removal", + isServerSessionWatcher(zk2.getSessionId(), "/node1", + WatcherType.Data)); + } + + /** + * Test verifies WatcherType.Children - removes only the configured child + * watcher function + */ + @Test(timeout = 90000) + public void testRemoveAllChildWatchesOnAPath() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + final CountDownLatch cWatchCount = new CountDownLatch(2); + final CountDownLatch rmWatchCount = new CountDownLatch(2); + Watcher w1 = new Watcher() { + @Override + public void process(WatchedEvent event) { + switch (event.getType()) { + case ChildWatchRemoved: + rmWatchCount.countDown(); + break; + case NodeChildrenChanged: + cWatchCount.countDown(); + break; + default: + break; + } + } + }; + Watcher w2 = new Watcher() { + @Override + public void process(WatchedEvent event) { + switch (event.getType()) { + case ChildWatchRemoved: + rmWatchCount.countDown(); + break; + case NodeChildrenChanged: + cWatchCount.countDown(); + break; + default: + break; + } + } + }; + // Add multiple child watches + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertEquals("Didn't set child watches", 0, + zk2.getChildren("/node1", w1).size()); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertEquals("Didn't set child watches", 0, + zk2.getChildren("/node1", w2).size()); + + Assert.assertTrue("Server session is not a watcher", + isServerSessionWatcher(zk2.getSessionId(), "/node1", + WatcherType.Children)); + removeAllWatches(zk2, "/node1", WatcherType.Children, false, Code.OK); + Assert.assertTrue("Didn't remove child watcher", + rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + + Assert.assertFalse("Server session is still a watcher after removal", + isServerSessionWatcher(zk2.getSessionId(), "/node1", + WatcherType.Children)); + } + + /** + * Test verifies WatcherType.Any - removes all the configured child,data + * watcher functions + */ + @Test(timeout = 90000) + public void testRemoveAllWatchesOnAPath() throws Exception { + zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + final CountDownLatch watchCount = new CountDownLatch(2); + final CountDownLatch rmWatchCount = new CountDownLatch(4); + Watcher w1 = new Watcher() { + @Override + public void process(WatchedEvent event) { + switch (event.getType()) { + case ChildWatchRemoved: + case DataWatchRemoved: + rmWatchCount.countDown(); + break; + case NodeChildrenChanged: + case NodeDataChanged: + watchCount.countDown(); + break; + default: + break; + } + } + }; + Watcher w2 = new Watcher() { + @Override + public void process(WatchedEvent event) { + switch (event.getType()) { + case ChildWatchRemoved: + case DataWatchRemoved: + rmWatchCount.countDown(); + break; + case NodeChildrenChanged: + case NodeDataChanged: + watchCount.countDown(); + break; + default: + break; + } + } + }; + // Add multiple child watches + LOG.info("Adding child watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertEquals("Didn't set child watches", 0, + zk2.getChildren("/node1", w1).size()); + LOG.info("Adding child watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertEquals("Didn't set child watches", 0, + zk2.getChildren("/node1", w2).size()); + + // Add multiple data watches + LOG.info("Adding data watcher {} on path {}", new Object[]{w1, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w1)); + LOG.info("Adding data watcher {} on path {}", new Object[]{w2, + "/node1"}); + Assert.assertNotNull("Didn't set data watches", + zk2.exists("/node1", w2)); + + Assert.assertTrue("Server session is not a watcher", + isServerSessionWatcher(zk2.getSessionId(), "/node1", + WatcherType.Data)); + removeAllWatches(zk2, "/node1", WatcherType.Any, false, Code.OK); + Assert.assertTrue("Didn't remove data watcher", + rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + Assert.assertFalse("Server session is still a watcher after removal", + isServerSessionWatcher(zk2.getSessionId(), "/node1", + WatcherType.Data)); + Assert.assertEquals("Received watch notification after removal!", 2, + watchCount.getCount()); + } + + /** + * Checks if a session is registered with the server as a watcher. + * + * @param long sessionId the session ID to check + * @param path the path to check for watchers + * @param type the type of watcher + * @return true if the client session is a watcher on path for the type + */ + private boolean isServerSessionWatcher(long sessionId, String path, + WatcherType type) { + Set cnxns = new HashSet<>(); + CollectionUtils.addAll(cnxns, serverFactory.getConnections().iterator()); + for (ServerCnxn cnxn : cnxns) { + if (cnxn.getSessionId() == sessionId) { + return getServer(serverFactory).getZKDatabase().getDataTree() + .containsWatcher(path, type, cnxn); + } + } + return false; + } + + /* a mocked ZK class that doesn't do client-side verification + * before/after calling removeWatches */ + private class MyZooKeeper extends ZooKeeper { + private MyWatchManager myWatchManager; + + public MyZooKeeper(String hp, int timeout, Watcher watcher) + throws IOException { + super(hp, timeout, watcher, false); + } + + protected ZKWatchManager defaultWatchManager() { + myWatchManager = new MyWatchManager(); + return myWatchManager; + } + + public int getRemoveWatchesRC() { + return myWatchManager.lastrc; + } + + class MyWatchManager extends ZKWatchManager { + public int lastrc; + + /* Pretend that any watcher exists */ + void containsWatcher(String path, Watcher watcher, + WatcherType watcherType) throws NoWatcherException { + } + + /* save the return error code by the server */ + protected boolean removeWatches( + Map> pathVsWatcher, + Watcher watcher, String path, boolean local, int rc, + Set removedWatchers) throws KeeperException { + lastrc = rc; + return false; + } + } + } + + private class MyWatcher implements Watcher { + private final String path; + private String eventPath; + private CountDownLatch latch; + private List eventsAfterWatchRemoval = new ArrayList(); + + public MyWatcher(String path, int count) { + this.path = path; + latch = new CountDownLatch(count); + } + + public void process(WatchedEvent event) { + LOG.debug("Event path : {}, eventPath : {}" + + new Object[]{path, event.getPath()}); + this.eventPath = event.getPath(); + // notifies watcher removal + if (latch.getCount() == 0) { + if (event.getType() != EventType.None) { + eventsAfterWatchRemoval.add(event.getType()); + } + } + if (event.getType() == EventType.ChildWatchRemoved + || event.getType() == EventType.DataWatchRemoved) { + latch.countDown(); + } + } + + /** + * Returns true if the watcher was triggered. Try to avoid using this + * method with assertFalse statements. A false return depends on a timed + * out wait on a latch, which makes tests run long. + * + * @return true if the watcher was triggered, false otherwise + * @throws InterruptedException if interrupted while waiting on latch + */ + public boolean matches() throws InterruptedException { + if (!latch.await(CONNECTION_TIMEOUT / 5, TimeUnit.MILLISECONDS)) { + LOG.error("Failed waiting to remove the watches"); + return false; + } + LOG.debug("Client path : {} eventPath : {}", new Object[]{path, + eventPath}); + return path.equals(eventPath); + } + + public List getEventsAfterWatchRemoval() { + return eventsAfterWatchRemoval; + } + } + + private class MyCallback implements AsyncCallback.VoidCallback { + private final String path; + private final int rc; + int eventRc; + private String eventPath; + private CountDownLatch latch = new CountDownLatch(1); + + public MyCallback(int rc, String path) { + this.rc = rc; + this.path = path; + } + + @Override + public void processResult(int rc, String eventPath, Object ctx) { + System.out.println("latch:" + path + " " + eventPath); + this.eventPath = eventPath; + this.eventRc = rc; + this.latch.countDown(); + } + + /** + * Returns true if the callback was triggered. Try to avoid using this + * method with assertFalse statements. A false return depends on a timed + * out wait on a latch, which makes tests run long. + * + * @return true if the watcher was triggered, false otherwise + * @throws InterruptedException if interrupted while waiting on latch + */ + public boolean matches() throws InterruptedException { + if (!latch.await(CONNECTION_TIMEOUT / 5, TimeUnit.MILLISECONDS)) { + return false; + } + return path.equals(eventPath) && rc == eventRc; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/TestableZooKeeper.java b/src/java/test/org/apache/zookeeper/TestableZooKeeper.java new file mode 100644 index 00000000000..62264b43513 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/TestableZooKeeper.java @@ -0,0 +1,116 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.jute.Record; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; + +import java.io.IOException; +import java.net.SocketAddress; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class TestableZooKeeper extends ZooKeeper { + + public TestableZooKeeper(String host, int sessionTimeout, + Watcher watcher) throws IOException { + super(host, sessionTimeout, watcher); + } + + @Override + public List getChildWatches() { + return super.getChildWatches(); + } + + + @Override + public List getDataWatches() { + return super.getDataWatches(); + } + + + @Override + public List getExistWatches() { + return super.getExistWatches(); + } + + /** + * Cause this ZooKeeper object to disconnect from the server. It will then + * later attempt to reconnect. + */ + public void testableConnloss() throws IOException { + synchronized (cnxn) { + cnxn.sendThread.testableCloseSocket(); + } + } + + /** + * Cause this ZooKeeper object to stop receiving from the ZooKeeperServer + * for the given number of milliseconds. + * @param ms the number of milliseconds to pause. + * @return true if the connection is paused, otherwise false + */ + public boolean pauseCnxn(final long ms) { + final CountDownLatch initiatedPause = new CountDownLatch(1); + new Thread() { + public void run() { + synchronized (cnxn) { + try { + try { + cnxn.sendThread.testableCloseSocket(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + initiatedPause.countDown(); + } + Thread.sleep(ms); + } catch (InterruptedException e) { + } + } + } + }.start(); + + try { + return initiatedPause.await(ms, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + return false; + } + } + + public boolean testableWaitForShutdown(int wait) + throws InterruptedException { + return super.testableWaitForShutdown(wait); + } + + public SocketAddress testableLocalSocketAddress() { + return super.testableLocalSocketAddress(); + } + + public SocketAddress testableRemoteSocketAddress() { + return super.testableRemoteSocketAddress(); + } + + /** + * @return the last zxid as seen by the client session + */ + public long testableLastZxid() { + return cnxn.getLastZxid(); + } + + public ReplyHeader submitRequest(RequestHeader h, Record request, + Record response, WatchRegistration watchRegistration) throws InterruptedException { + return cnxn.submitRequest(h, request, response, watchRegistration); + } +} diff --git a/src/java/test/org/apache/zookeeper/VerGenTest.java b/src/java/test/org/apache/zookeeper/VerGenTest.java new file mode 100644 index 00000000000..875abc01057 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/VerGenTest.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.version.util.VerGen; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; + + +/** + * Test VerGen, used during the build. + * + */ +@RunWith(Parameterized.class) +@Parameterized.UseParametersRunnerFactory(ZKParameterized.RunnerFactory.class) +public class VerGenTest extends ZKTestCase { + private String input; + private Object[] expected; + + public VerGenTest(String input, Object[] expected) { + this.input = input; + this.expected = expected; + } + + @Parameters + public static Collection data() { + return Arrays.asList(new Object[][]{ + {"1.2.3", new Object[]{1, 2, 3, null}}, + {"1.2.3-dev", new Object[]{1, 2, 3, "dev"}}, + {"1.2.3-SNAPSHOT", new Object[]{1, 2, 3, "SNAPSHOT"}}, + {"1.2.3-SNAPSHOT", new Object[]{1, 2, 3, "SNAPSHOT"}}, + {"1.2.3-foo-bar+123", new Object[]{1, 2, 3, "foo-bar+123"}}, + {"1.2.3.4.5-SNAPSHOT", new Object[]{1, 2, 3, "SNAPSHOT"}}, + {"1.2.3.4.5-foo-bar+123", new Object[]{1, 2, 3, "foo-bar+123"}} + }); + } + + @Test + public void testParser() { + VerGen.Version v = VerGen.parseVersionString(input); + Assert.assertEquals(expected[0], v.maj); + Assert.assertEquals(expected[1], v.min); + Assert.assertEquals(expected[2], v.micro); + Assert.assertEquals(expected[3], v.qualifier); + } + + @Test + public void testGenFile() throws Exception { + VerGen.Version v = VerGen.parseVersionString(input); + File outputDir = ClientBase.createTmpDir(); + VerGen.generateFile(outputDir, v, 1, "Nov1"); + ClientBase.recursiveDelete(outputDir); + } +} diff --git a/src/java/test/org/apache/zookeeper/ZKParameterized.java b/src/java/test/org/apache/zookeeper/ZKParameterized.java new file mode 100644 index 00000000000..c2fe2d1a0d0 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/ZKParameterized.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; +import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters; +import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory; +import org.junit.runners.parameterized.TestWithParameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +public class ZKParameterized { + private static final Logger LOG = LoggerFactory.getLogger(ZKParameterized.class); + + public static class RunnerFactory extends BlockJUnit4ClassRunnerWithParametersFactory { + @Override + public org.junit.runner.Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError { + return new ZKParameterized.Runner(test); + } + } + + public static class Runner extends BlockJUnit4ClassRunnerWithParameters { + public Runner(TestWithParameters test) throws InitializationError { + super(test); + } + + + @Override + protected List computeTestMethods() { + return JUnit4ZKTestRunner.computeTestMethodsForClass(getTestClass().getJavaClass(), super.computeTestMethods()); + } + + + @Override + protected Statement methodInvoker(FrameworkMethod method, Object test) { + return new JUnit4ZKTestRunner.LoggedInvokeMethod(method, test); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/ZKTestCase.java b/src/java/test/org/apache/zookeeper/ZKTestCase.java new file mode 100644 index 00000000000..2d701249331 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/ZKTestCase.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.junit.Rule; +import org.junit.rules.MethodRule; +import org.junit.rules.TestWatchman; +import org.junit.runner.RunWith; +import org.junit.runners.model.FrameworkMethod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Base class for a non-parameterized ZK test. + * + * Basic utilities shared by all tests. Also logging of various events during + * the test execution (start/stop/success/failure/etc...) + */ +@SuppressWarnings("deprecation") +@RunWith(JUnit4ZKTestRunner.class) +public class ZKTestCase { + private static final Logger LOG = LoggerFactory.getLogger(ZKTestCase.class); + + private String testName; + @Rule + public MethodRule watchman = new TestWatchman() { + @Override + public void starting(FrameworkMethod method) { + // By default, disable starting a JettyAdminServer in tests to avoid + // accidentally attempting to start multiple admin servers on the + // same port. + System.setProperty("zookeeper.admin.enableServer", "false"); + testName = method.getName(); + LOG.info("STARTING " + testName); + } + + @Override + public void finished(FrameworkMethod method) { + LOG.info("FINISHED " + testName); + } + + @Override + public void succeeded(FrameworkMethod method) { + LOG.info("SUCCEEDED " + testName); + } + + @Override + public void failed(Throwable e, FrameworkMethod method) { + LOG.info("FAILED " + testName, e); + } + + }; + + protected String getTestName() { + return testName; + } + +} diff --git a/src/java/test/org/apache/zookeeper/ZooKeeperTest.java b/src/java/test/org/apache/zookeeper/ZooKeeperTest.java new file mode 100644 index 00000000000..ec5916ef796 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/ZooKeeperTest.java @@ -0,0 +1,443 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper; + +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.cli.LsCommand; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.*; + +/** + * + * Testing Zookeeper public methods + * + */ +public class ZooKeeperTest extends ClientBase { + + @Test + public void testDeleteRecursive() throws IOException, InterruptedException, + KeeperException { + final ZooKeeper zk = createClient(); + // making sure setdata works on / + zk.setData("/", "some".getBytes(), -1); + zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b/v/1", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/c", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/c/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + List children = zk.getChildren("/a", false); + + Assert.assertEquals("2 children - b & c should be present ", children + .size(), 2); + Assert.assertTrue(children.contains("b")); + Assert.assertTrue(children.contains("c")); + + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + // 'rmr' is deprecated, so the test here is just for backwards + // compatibility. + String cmdstring0 = "rmr /a/b/v"; + String cmdstring1 = "deleteall /a"; + zkMain.cl.parseCommand(cmdstring0); + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + Assert.assertEquals(null, zk.exists("/a/b/v", null)); + zkMain.cl.parseCommand(cmdstring1); + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + Assert.assertNull(zk.exists("/a", null)); + } + + @Test + public void testDeleteRecursiveAsync() throws IOException, + InterruptedException, KeeperException { + final ZooKeeper zk = createClient(); + // making sure setdata works on / + zk.setData("/", "some".getBytes(), -1); + zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b/v/1", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/c", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/c/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + for (int i = 0; i < 50; ++i) { + zk.create("/a/c/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + List children = zk.getChildren("/a", false); + + Assert.assertEquals("2 children - b & c should be present ", children + .size(), 2); + Assert.assertTrue(children.contains("b")); + Assert.assertTrue(children.contains("c")); + + VoidCallback cb = new VoidCallback() { + + @Override + public void processResult(int rc, String path, Object ctx) { + synchronized (ctx) { + ((AtomicInteger) ctx).set(4); + ctx.notify(); + } + } + + }; + final AtomicInteger ctx = new AtomicInteger(3); + ZKUtil.deleteRecursive(zk, "/a", cb, ctx); + synchronized (ctx) { + ctx.wait(); + } + Assert.assertEquals(4, ((AtomicInteger) ctx).get()); + } + + @Test + public void testStatWhenPathDoesNotExist() throws IOException, + InterruptedException { + final ZooKeeper zk = createClient(); + ZooKeeperMain main = new ZooKeeperMain(zk); + String cmdstring = "stat /invalidPath"; + main.cl.parseCommand(cmdstring); + try { + main.processZKCmd(main.cl); + Assert.fail("As Node does not exist, command should fail by throwing No Node Exception."); + } catch (KeeperException e) { + Assert.assertEquals("KeeperErrorCode = NoNode for /invalidPath", e.getMessage()); + } + } + + @Test + public void testParseWithExtraSpaces() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = " ls / "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertEquals("Spaces also considered as characters", zkMain.cl.getNumArguments(), 2); + Assert.assertEquals("ls is not taken as first argument", zkMain.cl.getCmdArgument(0), "ls"); + Assert.assertEquals("/ is not taken as second argument", zkMain.cl.getCmdArgument(1), "/"); + } + + @Test + public void testParseWithQuotes() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + for (String quoteChar : new String[]{"'", "\""}) { + String cmdstring = String.format("create /node %1$squoted data%1$s", quoteChar); + zkMain.cl.parseCommand(cmdstring); + Assert.assertEquals("quotes combine arguments", zkMain.cl.getNumArguments(), 3); + Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create"); + Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node"); + Assert.assertEquals("quoted data is not taken as third argument", zkMain.cl.getCmdArgument(2), "quoted data"); + } + } + + @Test + public void testParseWithMixedQuotes() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + for (String[] quoteChars : new String[][]{{"'", "\""}, {"\"", "'"}}) { + String outerQuotes = quoteChars[0]; + String innerQuotes = quoteChars[1]; + String cmdstring = String.format("create /node %1$s%2$squoted data%2$s%1$s", outerQuotes, innerQuotes); + zkMain.cl.parseCommand(cmdstring); + Assert.assertEquals("quotes combine arguments", zkMain.cl.getNumArguments(), 3); + Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create"); + Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node"); + Assert.assertEquals("quoted data is not taken as third argument", zkMain.cl.getCmdArgument(2), innerQuotes + "quoted data" + innerQuotes); + } + } + + @Test + public void testParseWithEmptyQuotes() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = "create /node ''"; + zkMain.cl.parseCommand(cmdstring); + Assert.assertEquals("empty quotes should produce arguments", zkMain.cl.getNumArguments(), 3); + Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create"); + Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node"); + Assert.assertEquals("empty string is not taken as third argument", zkMain.cl.getCmdArgument(2), ""); + } + + @Test + public void testParseWithMultipleQuotes() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = "create /node '' ''"; + zkMain.cl.parseCommand(cmdstring); + Assert.assertEquals("expected 5 arguments", zkMain.cl.getNumArguments(), 4); + Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create"); + Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node"); + Assert.assertEquals("empty string is not taken as third argument", zkMain.cl.getCmdArgument(2), ""); + Assert.assertEquals("empty string is not taken as fourth argument", zkMain.cl.getCmdArgument(3), ""); + } + + @Test + public void testInvalidCommand() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = "cret -s /node1"; + zkMain.cl.parseCommand(cmdstring); + Assert.assertFalse("Doesn't validate the command", zkMain + .processZKCmd(zkMain.cl)); + } + + @Test + public void testCreateCommandWithoutPath() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = "create "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertFalse("Path is not validated.", zkMain + .processZKCmd(zkMain.cl)); + // create ephemeral + cmdstring = "create -e "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertFalse("Path is not validated.", zkMain + .processZKCmd(zkMain.cl)); + // create sequential + cmdstring = "create -s "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertFalse("Path is not validated.", zkMain + .processZKCmd(zkMain.cl)); + // create ephemeral sequential + cmdstring = "create -s -e "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertFalse("Path is not validated.", zkMain + .processZKCmd(zkMain.cl)); + } + + @Test + public void testCreateNodeWithoutData() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + // create persistent sequential node + String cmdstring = "create -s /node "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Doesn't create node without data", zkMain + .processZKCmd(zkMain.cl)); + // create ephemeral node + cmdstring = "create -e /node "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Doesn't create node without data", zkMain + .processZKCmd(zkMain.cl)); + // create ephemeral sequential node + cmdstring = "create -s -e /node "; + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Doesn't create node without data", zkMain + .processZKCmd(zkMain.cl)); + // creating ephemeral with wrong option. + cmdstring = "create -s y /node"; + zkMain.cl.parseCommand(cmdstring); + try { + Assert.assertTrue("Created node with wrong option", zkMain + .processZKCmd(zkMain.cl)); + Assert.fail("Created the node with wrong option should " + + "throw Exception."); + } catch (IllegalArgumentException e) { + Assert.assertEquals("Path must start with / character", e + .getMessage()); + } + } + + @Test + public void testACLWithExtraAgruments() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + // create persistent sequential node + String cmdstring = "create -s /l data ip:10.18.52.144:cdrwa f g h"; + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue( + "Not considering the extra arguments after the acls.", zkMain + .processZKCmd(zkMain.cl)); + } + + @Test + public void testCreatePersistentNode() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = "create /node2"; + zkMain.cl.parseCommand(cmdstring); + Assert.assertTrue("Not creating Persistent node.", zkMain + .processZKCmd(zkMain.cl)); + } + + @Test + public void testDelete() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring1 = "create -e /node2 data"; + String cmdstring2 = "delete /node2"; + String cmdstring3 = "ls /node2"; + zkMain.cl.parseCommand(cmdstring1); + Assert.assertTrue(zkMain.processZKCmd(zkMain.cl)); + zkMain.cl.parseCommand(cmdstring2); + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + zkMain.cl.parseCommand(cmdstring3); + Assert.assertFalse("", zkMain.processCmd(zkMain.cl)); + } + + @Test + public void testStatCommand() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring1 = "create -e /node3 data"; + String cmdstring2 = "stat /node3"; + String cmdstring3 = "delete /node3"; + zkMain.cl.parseCommand(cmdstring1); + Assert.assertTrue(zkMain.processZKCmd(zkMain.cl)); + zkMain.cl.parseCommand(cmdstring2); + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + zkMain.cl.parseCommand(cmdstring3); + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + } + + @Test + public void testInvalidStatCommand() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + // node doesn't exists + String cmdstring1 = "stat /node123"; + zkMain.cl.parseCommand(cmdstring1); + try { + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + Assert.fail("Path doesn't exists so, command should fail."); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + } + } + + @Test + public void testSetData() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring1 = "create -e /node4 data"; + String cmdstring2 = "set /node4 " + "data"; + String cmdstring3 = "delete /node4"; + Stat stat = new Stat(); + int version = 0; + zkMain.cl.parseCommand(cmdstring1); + Assert.assertTrue(zkMain.processZKCmd(zkMain.cl)); + stat = zk.exists("/node4", true); + version = stat.getVersion(); + zkMain.cl.parseCommand(cmdstring2); + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + stat = zk.exists("/node4", true); + Assert.assertEquals(version + 1, stat.getVersion()); + zkMain.cl.parseCommand(cmdstring3); + Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); + } + + @Test + public void testCheckInvalidAcls() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = "create -s -e /node data ip:scheme:gggsd"; //invalid acl's + try { + zkMain.executeLine(cmdstring); + } catch (KeeperException.InvalidACLException e) { + fail("For Invalid ACls should not throw exception"); + } + } + + @Test + public void testDeleteWithInvalidVersionNo() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmdstring = "create -s -e /node1 data "; + String cmdstring1 = "delete /node1 2";//invalid dataversion no + zkMain.executeLine(cmdstring); + try { + zkMain.executeLine(cmdstring1); + + } catch (KeeperException.BadVersionException e) { + fail("For Invalid dataversion number should not throw exception"); + } + } + + @Test + public void testCliCommandsNotEchoingUsage() throws Exception { + // setup redirect out/err streams to get System.in/err, use this judiciously! + final PrintStream systemErr = System.err; // get current err + final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errContent)); + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + String cmd1 = "printwatches"; + zkMain.executeLine(cmd1); + String cmd2 = "history"; + zkMain.executeLine(cmd2); + String cmd3 = "redo"; + zkMain.executeLine(cmd3); + // revert redirect of out/err streams - important step! + System.setErr(systemErr); + if (errContent.toString().contains("ZooKeeper -server host:port cmd args")) { + fail("CLI commands (history, redo, connect, printwatches) display usage info!"); + } + } + + @Test + public void testSortedLs() throws Exception { + final ZooKeeper zk = createClient(); + ZooKeeperMain zkMain = new ZooKeeperMain(zk); + + zkMain.executeLine("create /aa1"); + zkMain.executeLine("create /aa2"); + zkMain.executeLine("create /aa3"); + zkMain.executeLine("create /test1"); + zkMain.executeLine("create /zk1"); + + // call ls and put result in byteStream + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(byteStream); + String lsCmd = "ls /"; + LsCommand entity = new LsCommand(); + entity.setZk(zk); + entity.setOut(out); + entity.parse(lsCmd.split(" ")).exec(); + + String result = byteStream.toString(); + assertTrue(result, result.contains("[aa1, aa2, aa3, test1, zk1, zookeeper]")); + } + +} diff --git a/src/java/test/org/apache/zookeeper/ZooKeeperTestableTest.java b/src/java/test/org/apache/zookeeper/ZooKeeperTestableTest.java new file mode 100644 index 00000000000..a099ad7bb30 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/ZooKeeperTestableTest.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper; + +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class ZooKeeperTestableTest extends ClientBase { + @Test + public void testSessionExpiration() throws IOException, InterruptedException, + KeeperException { + ZooKeeper zk = createClient(); + + final CountDownLatch expirationLatch = new CountDownLatch(1); + Watcher watcher = new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getState() == Event.KeeperState.Expired) { + expirationLatch.countDown(); + } + } + }; + zk.exists("/foo", watcher); + + zk.getTestable().injectSessionExpiration(); + Assert.assertTrue(expirationLatch.await(5, TimeUnit.SECONDS)); + + boolean gotException = false; + try { + zk.exists("/foo", false); + Assert.fail("Should have thrown a SessionExpiredException"); + } catch (KeeperException.SessionExpiredException e) { + // correct + gotException = true; + } + Assert.assertTrue(gotException); + } +} diff --git a/src/java/test/org/apache/zookeeper/common/AtomicFileWritingIdiomTest.java b/src/java/test/org/apache/zookeeper/common/AtomicFileWritingIdiomTest.java new file mode 100644 index 00000000000..bd94ea03414 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/common/AtomicFileWritingIdiomTest.java @@ -0,0 +1,353 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.common; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.common.AtomicFileWritingIdiom.OutputStreamStatement; +import org.apache.zookeeper.common.AtomicFileWritingIdiom.WriterStatement; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class AtomicFileWritingIdiomTest extends ZKTestCase { + + private static File tmpdir; + + @BeforeClass + public static void createTmpDir() { + tmpdir = new File("build/test/tmp"); + tmpdir.mkdirs(); + } + + @Test + public void testOutputStreamSuccess() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + new AtomicFileWritingIdiom(target, new OutputStreamStatement() { + @Override + public void write(OutputStream os) throws IOException { + os.write("after".getBytes("ASCII")); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + } + }); + assertFalse("tmp file should have been deleted", tmp.exists()); + // content changed + assertEquals("after", getContent(target)); + target.delete(); + } + + @Test + public void testWriterSuccess() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + new AtomicFileWritingIdiom(target, new WriterStatement() { + @Override + public void write(Writer os) throws IOException { + os.write("after"); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + } + }); + assertFalse("tmp file should have been deleted", tmp.exists()); + // content changed + assertEquals("after", getContent(target)); + target.delete(); + } + + @Test + public void testOutputStreamFailure() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new OutputStreamStatement() { + @Override + public void write(OutputStream os) throws IOException { + os.write("after".getBytes("ASCII")); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new RuntimeException(); + } + }); + } catch (RuntimeException ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // content preserved + assertEquals("before", getContent(target)); + target.delete(); + } + + @Test + public void testWriterFailure() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new WriterStatement() { + @Override + public void write(Writer os) throws IOException { + os.write("after"); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new RuntimeException(); + } + }); + } catch (RuntimeException ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // content preserved + assertEquals("before", getContent(target)); + target.delete(); + } + + @Test + public void testOutputStreamFailureIOException() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new OutputStreamStatement() { + @Override + public void write(OutputStream os) throws IOException { + os.write("after".getBytes("ASCII")); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new IOException(); + } + }); + } catch (IOException ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // content preserved + assertEquals("before", getContent(target)); + target.delete(); + } + + @Test + public void testWriterFailureIOException() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new WriterStatement() { + @Override + public void write(Writer os) throws IOException { + os.write("after"); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new IOException(); + } + }); + } catch (IOException ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // content preserved + assertEquals("before", getContent(target)); + target.delete(); + } + + @Test + public void testOutputStreamFailureError() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new OutputStreamStatement() { + @Override + public void write(OutputStream os) throws IOException { + os.write("after".getBytes("ASCII")); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new Error(); + } + }); + } catch (Error ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // content preserved + assertEquals("before", getContent(target)); + target.delete(); + } + + @Test + public void testWriterFailureError() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + createFile(target, "before"); + assertEquals("before", getContent(target)); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new WriterStatement() { + @Override + public void write(Writer os) throws IOException { + os.write("after"); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new Error(); + } + }); + } catch (Error ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // content preserved + assertEquals("before", getContent(target)); + target.delete(); + } + + // ************** target file does not exist + + @Test + public void testOutputStreamSuccessNE() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + target.delete(); + assertFalse("file should not exist", target.exists()); + new AtomicFileWritingIdiom(target, new OutputStreamStatement() { + @Override + public void write(OutputStream os) throws IOException { + os.write("after".getBytes("ASCII")); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + } + }); + // content changed + assertEquals("after", getContent(target)); + target.delete(); + } + + @Test + public void testWriterSuccessNE() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + target.delete(); + assertFalse("file should not exist", target.exists()); + new AtomicFileWritingIdiom(target, new WriterStatement() { + @Override + public void write(Writer os) throws IOException { + os.write("after"); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + } + }); + assertFalse("tmp file should have been deleted", tmp.exists()); + // content changed + assertEquals("after", getContent(target)); + target.delete(); + } + + @Test + public void testOutputStreamFailureNE() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + target.delete(); + assertFalse("file should not exist", target.exists()); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new OutputStreamStatement() { + @Override + public void write(OutputStream os) throws IOException { + os.write("after".getBytes("ASCII")); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new RuntimeException(); + } + }); + } catch (RuntimeException ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // file should not exist + assertFalse("file should not exist", target.exists()); + } + + @Test + public void testWriterFailureNE() throws IOException { + File target = new File(tmpdir, "target.txt"); + final File tmp = new File(tmpdir, "target.txt.tmp"); + target.delete(); + assertFalse("file should not exist", target.exists()); + boolean exception = false; + try { + new AtomicFileWritingIdiom(target, new WriterStatement() { + @Override + public void write(Writer os) throws IOException { + os.write("after"); + os.flush(); + assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists()); + throw new RuntimeException(); + } + }); + } catch (RuntimeException ex) { + exception = true; + } + assertFalse("tmp file should have been deleted", tmp.exists()); + assertTrue("should have raised an exception", exception); + // file should not exist + assertFalse("file should not exist", target.exists()); + } + + private String getContent(File file, String encoding) throws IOException { + StringBuilder result = new StringBuilder(); + FileInputStream fis = new FileInputStream(file); + byte[] b = new byte[20]; + int nb; + while ((nb = fis.read(b)) != -1) { + result.append(new String(b, 0, nb, encoding)); + } + fis.close(); + return result.toString(); + } + + private String getContent(File file) throws IOException { + return getContent(file, "ASCII"); + } + + private void createFile(File file, String content) throws IOException { + FileOutputStream fos = new FileOutputStream(file); + fos.write(content.getBytes("ASCII")); + fos.close(); + } + +} diff --git a/src/java/test/org/apache/zookeeper/common/PathUtilsTest.java b/src/java/test/org/apache/zookeeper/common/PathUtilsTest.java new file mode 100644 index 00000000000..4502421b025 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/common/PathUtilsTest.java @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.common; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Test; + +public class PathUtilsTest extends ZKTestCase { + + @Test + public void testValidatePath_ValidPath() { + PathUtils.validatePath("/this is / a valid/path"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_Null() { + PathUtils.validatePath(null); + } + + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_EmptyString() { + PathUtils.validatePath(""); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_NotAbsolutePath() { + PathUtils.validatePath("not/valid"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_EndsWithSlash() { + PathUtils.validatePath("/ends/with/slash/"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_ContainsNullCharacter() { + PathUtils.validatePath("/test\u0000"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_DoubleSlash() { + PathUtils.validatePath("/double//slash"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_SinglePeriod() { + PathUtils.validatePath("/single/./period"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_DoublePeriod() { + PathUtils.validatePath("/double/../period"); + } + + @Test + public void testValidatePath_NameContainingPeriod() { + // A period that isn't on its own is ok + PathUtils.validatePath("/name/with.period."); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_0x01() { + PathUtils.validatePath("/test\u0001"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_0x1F() { + PathUtils.validatePath("/test\u001F"); + } + + @Test // The first allowable character + public void testValidatePath_0x20() { + PathUtils.validatePath("/test\u0020"); + } + + @Test + public void testValidatePath_0x7e() { + // The last valid ASCII character + PathUtils.validatePath("/test\u007e"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_0x7f() { + PathUtils.validatePath("/test\u007f"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_0x9f() { + PathUtils.validatePath("/test\u009f"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_ud800() { + PathUtils.validatePath("/test\ud800"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_uf8ff() { + PathUtils.validatePath("/test\uf8ff"); + } + + @Test + public void testValidatePath_HighestAllowableChar() { + PathUtils.validatePath("/test\uffef"); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidatePath_SupplementaryChar() { + PathUtils.validatePath("/test\ufff0"); + } + +} diff --git a/src/java/test/org/apache/zookeeper/common/TimeTest.java b/src/java/test/org/apache/zookeeper/common/TimeTest.java new file mode 100644 index 00000000000..651ea8eab69 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/common/TimeTest.java @@ -0,0 +1,102 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.common; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Calendar; +import java.util.Date; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Command line program for demonstrating robustness to clock + * changes. + *

        + * How to run: + * ant clean compile-test + * echo build/test/lib/*.jar build/lib/*.jar build/classes build/test/classes | sed -e 's/ /:/g' > cp + * java -cp $(cat cp) org.apache.zookeeper.common.TimeTest | tee log-without-patch + *

        + * After test program starts, in another window, do commands: + * date -s '+1hour' + * date -s '-1hour' + *

        + * As long as there isn't any expired event, the experiment is successful. + */ +public class TimeTest extends ClientBase { + private static final long mt0 = System.currentTimeMillis(); + private static final long nt0 = Time.currentElapsedTime(); + + private static AtomicInteger watchCount = new AtomicInteger(0); + + + public static void main(String[] args) throws Exception { + System.out.printf("Starting\n"); + final TimeTest test = new TimeTest(); + System.out.printf("After construct\n"); + test.setUp(); + ZooKeeper zk = test.createClient(); + zk.create("/ephemeral", new byte[]{1, 2, 3}, + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + while (Time.currentElapsedTime() - nt0 < 100000) { + System.out.printf("%d\t%s\n", discrepancy(), + zk.exists("/ephemeral", + watchCount.get() == 0 ? createWatcher() : null) != null); + waitByYielding(500); + } + } + + private static Watcher createWatcher() { + watchCount.incrementAndGet(); + return new Watcher() { + @Override + public void process(WatchedEvent event) { + watchCount.decrementAndGet(); + System.out.printf("%d event = %s\n", discrepancy(), event); + } + }; + + } + + private static void waitByYielding(long delay) { + long t0 = Time.currentElapsedTime(); + while (Time.currentElapsedTime() < t0 + delay) { + Thread.yield(); + } + } + + private static long discrepancy() { + return (System.currentTimeMillis() - mt0) - (Time.currentElapsedTime() - nt0); + } + + @Test + public void testElapsedTimeToDate() throws Exception { + long walltime = Time.currentWallTime(); + long elapsedTime = Time.currentElapsedTime(); + Thread.sleep(200); + + Calendar cal = Calendar.getInstance(); + cal.setTime(Time.elapsedTimeToDate(elapsedTime)); + int calculatedDate = cal.get(Calendar.HOUR_OF_DAY); + cal.setTime(new Date(walltime)); + int realDate = cal.get(Calendar.HOUR_OF_DAY); + + Assert.assertEquals(calculatedDate, realDate); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ByteBufferInputStreamTest.java b/src/java/test/org/apache/zookeeper/server/ByteBufferInputStreamTest.java new file mode 100644 index 00000000000..6c216c7d4a5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ByteBufferInputStreamTest.java @@ -0,0 +1,163 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.Arrays; + +import static org.junit.Assert.*; + +public class ByteBufferInputStreamTest extends ZKTestCase { + private static final byte[] DATA_BYTES_0 = + "Apache ZooKeeper".getBytes(Charset.forName("UTF-8")); + + private static byte[] DATA_BYTES; + private ByteBuffer bb; + private ByteBufferInputStream in; + private byte[] bs; + + @BeforeClass + public static void setUpClass() { + int len = DATA_BYTES_0.length + 2; + DATA_BYTES = new byte[len]; + System.arraycopy(DATA_BYTES_0, 0, DATA_BYTES, 0, DATA_BYTES_0.length); + DATA_BYTES[len - 2] = (byte) 0x0; + DATA_BYTES[len - 1] = (byte) 0xff; + } + + @Before + public void setUp() throws Exception { + bb = ByteBuffer.wrap(DATA_BYTES); + in = new ByteBufferInputStream(bb); + bs = new byte[]{(byte) 1, (byte) 2, (byte) 3, (byte) 4}; + } + + @Test + public void testRead() throws Exception { + for (int i = 0; i < DATA_BYTES.length; i++) { + int b = in.read(); + assertEquals(DATA_BYTES[i], (byte) b); + } + assertEquals(-1, in.read()); + } + + @Test + public void testReadArrayOffsetLength() throws Exception { + assertEquals(1, in.read(bs, 2, 1)); + byte[] expected = + new byte[]{(byte) 1, (byte) 2, DATA_BYTES[0], (byte) 4}; + assertArrayEquals(expected, bs); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void testReadArrayOffsetLength_LengthTooLarge() throws Exception { + in.read(bs, 2, 3); + } + + @Test + public void testReadArrayOffsetLength_HitEndOfStream() + throws Exception { + for (int i = 0; i < DATA_BYTES.length - 1; i++) { + in.read(); + } + assertEquals(1, in.read(bs, 2, 2)); + byte[] expected = + new byte[]{(byte) 1, (byte) 2, DATA_BYTES[DATA_BYTES.length - 1], + (byte) 4}; + assertArrayEquals(expected, bs); + } + + @Test + public void testReadArrayOffsetLength_AtEndOfStream() + throws Exception { + for (int i = 0; i < DATA_BYTES.length; i++) { + in.read(); + } + byte[] expected = Arrays.copyOf(bs, bs.length); + assertEquals(-1, in.read(bs, 2, 2)); + assertArrayEquals(expected, bs); + } + + @Test + public void testReadArrayOffsetLength_0Length() throws Exception { + byte[] expected = Arrays.copyOf(bs, bs.length); + assertEquals(0, in.read(bs, 2, 0)); + assertArrayEquals(expected, bs); + } + + @Test + public void testReadArray() throws Exception { + byte[] expected = Arrays.copyOf(DATA_BYTES, 4); + assertEquals(4, in.read(bs)); + assertArrayEquals(expected, bs); + } + + @Test + public void testSkip() throws Exception { + in.read(); + assertEquals(2L, in.skip(2L)); + assertEquals(DATA_BYTES[3], in.read()); + assertEquals(DATA_BYTES[4], in.read()); + } + + @Test + public void testSkip2() throws Exception { + for (int i = 0; i < DATA_BYTES.length / 2; i++) { + in.read(); + } + long skipAmount = DATA_BYTES.length / 4; + assertEquals(skipAmount, in.skip(skipAmount)); + int idx = DATA_BYTES.length / 2 + (int) skipAmount; + assertEquals(DATA_BYTES[idx++], in.read()); + assertEquals(DATA_BYTES[idx++], in.read()); + } + + @Test + public void testNegativeSkip() throws Exception { + in.read(); + assertEquals(0L, in.skip(-2L)); + assertEquals(DATA_BYTES[1], in.read()); + assertEquals(DATA_BYTES[2], in.read()); + } + + @Test + public void testSkip_HitEnd() throws Exception { + for (int i = 0; i < DATA_BYTES.length - 1; i++) { + in.read(); + } + assertEquals(1L, in.skip(2L)); + assertEquals(-1, in.read()); + } + + @Test + public void testSkip_AtEnd() throws Exception { + for (int i = 0; i < DATA_BYTES.length; i++) { + in.read(); + } + assertEquals(0L, in.skip(2L)); + assertEquals(-1, in.read()); + } + + @Test + public void testAvailable() throws Exception { + for (int i = DATA_BYTES.length; i > 0; i--) { + assertEquals(i, in.available()); + in.read(); + } + assertEquals(0, in.available()); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/CRCTest.java b/src/java/test/org/apache/zookeeper/server/CRCTest.java new file mode 100644 index 00000000000..ec2d1308a16 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/CRCTest.java @@ -0,0 +1,182 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.InputArchive; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.persistence.FileSnap; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; +import java.util.zip.Adler32; +import java.util.zip.CheckedInputStream; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class CRCTest extends ZKTestCase implements Watcher { + private static final Logger LOG = LoggerFactory.getLogger(CRCTest.class); + + private static final String HOSTPORT = + "127.0.0.1:" + PortAssignment.unique(); + private volatile CountDownLatch startSignal; + + /** + * corrupt a file by writing m at 500 b + * offset + * @param file the file to be corrupted + * @throws IOException + */ + private void corruptFile(File file) throws IOException { + // corrupt the logfile + RandomAccessFile raf = new RandomAccessFile(file, "rw"); + byte[] b = "mahadev".getBytes(); + long writeLen = 500L; + raf.seek(writeLen); + //corrupting the data + raf.write(b); + raf.close(); + } + + /** return if checksum matches for a snapshot **/ + private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException { + DataTree dt = new DataTree(); + Map sessions = new ConcurrentHashMap(); + InputStream snapIS = new BufferedInputStream(new FileInputStream( + snapFile)); + CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32()); + InputArchive ia = BinaryInputArchive.getArchive(crcIn); + try { + snap.deserialize(dt, sessions, ia); + } catch (IOException ie) { + // we failed on the most recent snapshot + // must be incomplete + // try reading the next one + // after corrupting + snapIS.close(); + crcIn.close(); + throw ie; + } + + long checksum = crcIn.getChecksum().getValue(); + long val = ia.readLong("val"); + snapIS.close(); + crcIn.close(); + return (val != checksum); + } + + /** test checksums for the logs and snapshots. + * the reader should fail on reading + * a corrupt snapshot and a corrupt log + * file + * @throws Exception + */ + @Test + public void testChecksums() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(150); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + LOG.info("starting up the zookeeper server .. waiting"); + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + try { + for (int i = 0; i < 2000; i++) { + zk.create("/crctest- " + i, ("/crctest- " + i).getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + } finally { + zk.close(); + } + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + ClientBase.CONNECTION_TIMEOUT)); + + File versionDir = new File(tmpDir, "version-2"); + File[] list = versionDir.listFiles(); + //there should be only two files + // one the snapshot and the other logFile + File snapFile = null; + File logFile = null; + for (File file : list) { + LOG.info("file is " + file); + if (file.getName().startsWith("log")) { + logFile = file; + corruptFile(logFile); + } + } + FileTxnLog flog = new FileTxnLog(versionDir); + TxnIterator itr = flog.read(1); + //we will get a checksum failure + try { + while (itr.next()) { + } + Assert.assertTrue(false); + } catch (IOException ie) { + LOG.info("crc corruption", ie); + } + itr.close(); + // find the last snapshot + FileSnap snap = new FileSnap(versionDir); + List snapFiles = snap.findNRecentSnapshots(2); + snapFile = snapFiles.get(0); + corruptFile(snapFile); + boolean cfile = false; + try { + cfile = getCheckSum(snap, snapFile); + } catch (IOException ie) { + //the last snapshot seems incompelte + // corrupt the last but one + // and use that + snapFile = snapFiles.get(1); + corruptFile(snapFile); + cfile = getCheckSum(snap, snapFile); + } + Assert.assertTrue(cfile); + } + + public void process(WatchedEvent event) { + LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath()); + if (event.getState() == KeeperState.SyncConnected + && startSignal != null && startSignal.getCount() > 0) { + startSignal.countDown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/CreateContainerTest.java b/src/java/test/org/apache/zookeeper/server/CreateContainerTest.java new file mode 100644 index 00000000000..8a02aaa874b --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/CreateContainerTest.java @@ -0,0 +1,273 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public class CreateContainerTest extends ClientBase { + private ZooKeeper zk; + + @Override + public void setUp() throws Exception { + super.setUp(); + zk = createClient(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + zk.close(); + } + + @Test(timeout = 30000) + public void testCreate() + throws IOException, KeeperException, InterruptedException { + createNoStatVerifyResult("/foo"); + createNoStatVerifyResult("/foo/child"); + } + + @Test(timeout = 30000) + public void testCreateWithStat() + throws IOException, KeeperException, InterruptedException { + Stat stat = createWithStatVerifyResult("/foo"); + Stat childStat = createWithStatVerifyResult("/foo/child"); + // Don't expect to get the same stats for different creates. + Assert.assertFalse(stat.equals(childStat)); + } + + @SuppressWarnings("ConstantConditions") + @Test(timeout = 30000) + public void testCreateWithNullStat() + throws IOException, KeeperException, InterruptedException { + final String name = "/foo"; + Assert.assertNull(zk.exists(name, false)); + + Stat stat = null; + // If a null Stat object is passed the create should still + // succeed, but no Stat info will be returned. + zk.create(name, name.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, stat); + Assert.assertNull(stat); + Assert.assertNotNull(zk.exists(name, false)); + } + + @Test(timeout = 30000) + public void testSimpleDeletion() + throws IOException, KeeperException, InterruptedException { + zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.delete("/foo/bar", -1); // should cause "/foo" to get deleted when checkContainers() is called + + ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() + .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100); + containerManager.checkContainers(); + + Thread.sleep(1000); + + Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); + } + + @Test(timeout = 30000) + public void testMultiWithContainerSimple() + throws IOException, KeeperException, InterruptedException { + Op createContainer = Op.create("/foo", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + zk.multi(Collections.singletonList(createContainer)); + + DataTree dataTree = serverFactory.getZooKeeperServer().getZKDatabase().getDataTree(); + Assert.assertEquals(dataTree.getContainers().size(), 1); + } + + @Test(timeout = 30000) + public void testMultiWithContainer() + throws IOException, KeeperException, InterruptedException { + Op createContainer = Op.create("/foo", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + Op createChild = Op.create("/foo/bar", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.multi(Arrays.asList(createContainer, createChild)); + + DataTree dataTree = serverFactory.getZooKeeperServer().getZKDatabase().getDataTree(); + Assert.assertEquals(dataTree.getContainers().size(), 1); + + zk.delete("/foo/bar", -1); // should cause "/foo" to get deleted when checkContainers() is called + + ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() + .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100); + containerManager.checkContainers(); + + Thread.sleep(1000); + + Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); + + createContainer = Op.create("/foo", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + createChild = Op.create("/foo/bar", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Op deleteChild = Op.delete("/foo/bar", -1); + zk.multi(Arrays.asList(createContainer, createChild, deleteChild)); + + containerManager.checkContainers(); + + Thread.sleep(1000); + + Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); + } + + @Test(timeout = 30000) + public void testSimpleDeletionAsync() + throws IOException, KeeperException, InterruptedException { + final CountDownLatch latch = new CountDownLatch(1); + AsyncCallback.Create2Callback cb = new AsyncCallback.Create2Callback() { + @Override + public void processResult(int rc, String path, Object ctx, String name, Stat stat) { + Assert.assertEquals(ctx, "context"); + latch.countDown(); + } + }; + zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, cb, "context"); + Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); + zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.delete("/foo/bar", -1); // should cause "/foo" to get deleted when checkContainers() is called + + ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() + .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100); + containerManager.checkContainers(); + + Thread.sleep(1000); + + Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); + } + + @Test(timeout = 30000) + public void testCascadingDeletion() + throws IOException, KeeperException, InterruptedException { + zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + zk.create("/foo/bar/one", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.delete("/foo/bar/one", -1); // should cause "/foo/bar" and "/foo" to get deleted when checkContainers() is called + + ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() + .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100); + containerManager.checkContainers(); + Thread.sleep(1000); + containerManager + .checkContainers(); + Thread.sleep(1000); + + Assert.assertNull("Container should have been deleted", zk.exists("/foo/bar", false)); + Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); + } + + @Test(timeout = 30000) + public void testFalseEmpty() + throws IOException, KeeperException, InterruptedException { + zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() + .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100) { + @Override + protected Collection getCandidates() { + return Collections.singletonList("/foo"); + } + }; + containerManager.checkContainers(); + Thread.sleep(1000); + + Assert.assertNotNull("Container should have not been deleted", zk.exists("/foo", false)); + } + + @Test(timeout = 30000) + public void testMaxPerMinute() + throws IOException, KeeperException, InterruptedException { + final BlockingQueue queue = new LinkedBlockingQueue(); + RequestProcessor processor = new RequestProcessor() { + @Override + public void processRequest(Request request) throws RequestProcessorException { + queue.add(new String(request.request.array())); + } + + @Override + public void shutdown() { + } + }; + final ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() + .getZKDatabase(), processor, 1, 2) { + @Override + protected long getMinIntervalMs() { + return 1000; + } + + @Override + protected Collection getCandidates() { + return Arrays.asList("/one", "/two", "/three", "/four"); + } + }; + Executors.newSingleThreadExecutor().submit(new Callable() { + @Override + public Void call() throws Exception { + containerManager.checkContainers(); + return null; + } + }); + Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/one"); + Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/two"); + Assert.assertEquals(queue.size(), 0); + Thread.sleep(500); + Assert.assertEquals(queue.size(), 0); + + Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/three"); + Assert.assertEquals(queue.poll(5, TimeUnit.SECONDS), "/four"); + } + + private void createNoStatVerifyResult(String newName) + throws KeeperException, InterruptedException { + Assert.assertNull("Node existed before created", zk.exists(newName, false)); + zk.create(newName, newName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); + Assert.assertNotNull("Node was not created as expected", + zk.exists(newName, false)); + } + + private Stat createWithStatVerifyResult(String newName) + throws KeeperException, InterruptedException { + Assert.assertNull("Node existed before created", zk.exists(newName, false)); + Stat stat = new Stat(); + zk.create(newName, newName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, stat); + validateCreateStat(stat, newName); + + Stat referenceStat = zk.exists(newName, false); + Assert.assertNotNull("Node was not created as expected", referenceStat); + Assert.assertEquals(referenceStat, stat); + + return stat; + } + + private void validateCreateStat(Stat stat, String name) { + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(0, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(0, stat.getNumChildren()); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/DataTreeTest.java b/src/java/test/org/apache/zookeeper/server/DataTreeTest.java new file mode 100644 index 00000000000..b5c6e3fe85e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/DataTreeTest.java @@ -0,0 +1,230 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.KeeperException.NodeExistsException; +import org.apache.zookeeper.Quotas; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.common.PathTrie; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.DataNode; +import org.apache.zookeeper.server.DataTree; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +public class DataTreeTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(DataTreeTest.class); + + private DataTree dt; + + @Before + public void setUp() throws Exception { + dt = new DataTree(); + } + + @After + public void tearDown() throws Exception { + dt = null; + } + + /** + * For ZOOKEEPER-1755 - Test race condition when taking dumpEphemerals and + * removing the session related ephemerals from DataTree structure + */ + @Test(timeout = 60000) + public void testDumpEphemerals() throws Exception { + int count = 1000; + long session = 1000; + long zxid = 2000; + final DataTree dataTree = new DataTree(); + LOG.info("Create {} zkclient sessions and its ephemeral nodes", count); + createEphemeralNode(session, dataTree, count); + final AtomicBoolean exceptionDuringDumpEphemerals = new AtomicBoolean( + false); + final AtomicBoolean running = new AtomicBoolean(true); + Thread thread = new Thread() { + public void run() { + PrintWriter pwriter = new PrintWriter(new StringWriter()); + try { + while (running.get()) { + dataTree.dumpEphemerals(pwriter); + } + } catch (Exception e) { + LOG.error("Received exception while dumpEphemerals!", e); + exceptionDuringDumpEphemerals.set(true); + } + } + + ; + }; + thread.start(); + LOG.debug("Killing {} zkclient sessions and its ephemeral nodes", count); + killZkClientSession(session, zxid, dataTree, count); + running.set(false); + thread.join(); + Assert.assertFalse("Should have got exception while dumpEphemerals!", + exceptionDuringDumpEphemerals.get()); + } + + private void killZkClientSession(long session, long zxid, + final DataTree dataTree, int count) { + for (int i = 0; i < count; i++) { + dataTree.killSession(session + i, zxid); + } + } + + private void createEphemeralNode(long session, final DataTree dataTree, + int count) throws NoNodeException, NodeExistsException { + for (int i = 0; i < count; i++) { + dataTree.createNode("/test" + i, new byte[0], null, session + i, + dataTree.getNode("/").stat.getCversion() + 1, 1, 1); + } + } + + @Test(timeout = 60000) + public void testRootWatchTriggered() throws Exception { + class MyWatcher implements Watcher { + boolean fired = false; + + public void process(WatchedEvent event) { + if (event.getPath().equals("/")) + fired = true; + } + } + MyWatcher watcher = new MyWatcher(); + // set a watch on the root node + dt.getChildren("/", new Stat(), watcher); + // add a new node, should trigger a watch + dt.createNode("/xyz", new byte[0], null, 0, dt.getNode("/").stat.getCversion() + 1, 1, 1); + Assert.assertFalse("Root node watch not triggered", !watcher.fired); + } + + /** + * For ZOOKEEPER-1046 test if cversion is getting incremented correctly. + */ + @Test(timeout = 60000) + public void testIncrementCversion() throws Exception { + dt.createNode("/test", new byte[0], null, 0, dt.getNode("/").stat.getCversion() + 1, 1, 1); + DataNode zk = dt.getNode("/test"); + int prevCversion = zk.stat.getCversion(); + long prevPzxid = zk.stat.getPzxid(); + dt.setCversionPzxid("/test/", prevCversion + 1, prevPzxid + 1); + int newCversion = zk.stat.getCversion(); + long newPzxid = zk.stat.getPzxid(); + Assert.assertTrue(" verification failed. Expected: <" + + (prevCversion + 1) + ", " + (prevPzxid + 1) + ">, found: <" + + newCversion + ", " + newPzxid + ">", + (newCversion == prevCversion + 1 && newPzxid == prevPzxid + 1)); + } + + @Test(timeout = 60000) + public void testPathTrieClearOnDeserialize() throws Exception { + + //Create a DataTree with quota nodes so PathTrie get updated + DataTree dserTree = new DataTree(); + + dserTree.createNode("/bug", new byte[20], null, -1, 1, 1, 1); + dserTree.createNode(Quotas.quotaZookeeper + "/bug", null, null, -1, 1, 1, 1); + dserTree.createNode(Quotas.quotaPath("/bug"), new byte[20], null, -1, 1, 1, 1); + dserTree.createNode(Quotas.statPath("/bug"), new byte[20], null, -1, 1, 1, 1); + + //deserialize a DataTree; this should clear the old /bug nodes and pathTrie + DataTree tree = new DataTree(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos); + tree.serialize(oa, "test"); + baos.flush(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + BinaryInputArchive ia = BinaryInputArchive.getArchive(bais); + dserTree.deserialize(ia, "test"); + + Field pfield = DataTree.class.getDeclaredField("pTrie"); + pfield.setAccessible(true); + PathTrie pTrie = (PathTrie) pfield.get(dserTree); + + //Check that the node path is removed from pTrie + Assert.assertEquals("/bug is still in pTrie", "", pTrie.findMaxPrefix("/bug")); + } + + /* + * ZOOKEEPER-2201 - OutputArchive.writeRecord can block for long periods of + * time, we must call it outside of the node lock. + * We call tree.serialize, which calls our modified writeRecord method that + * blocks until it can verify that a separate thread can lock the DataNode + * currently being written, i.e. that DataTree.serializeNode does not hold + * the DataNode lock while calling OutputArchive.writeRecord. + */ + @Test(timeout = 60000) + public void testSerializeDoesntLockDataNodeWhileWriting() throws Exception { + DataTree tree = new DataTree(); + tree.createNode("/marker", new byte[]{42}, null, -1, 1, 1, 1); + final DataNode markerNode = tree.getNode("/marker"); + final AtomicBoolean ranTestCase = new AtomicBoolean(); + DataOutputStream out = new DataOutputStream(new ByteArrayOutputStream()); + BinaryOutputArchive oa = new BinaryOutputArchive(out) { + @Override + public void writeRecord(Record r, String tag) throws IOException { + DataNode node = (DataNode) r; + if (node.data.length == 1 && node.data[0] == 42) { + final Semaphore semaphore = new Semaphore(0); + new Thread(new Runnable() { + @Override + public void run() { + synchronized (markerNode) { + //When we lock markerNode, allow writeRecord to continue + semaphore.release(); + } + } + }).start(); + + try { + boolean acquired = semaphore.tryAcquire(30, TimeUnit.SECONDS); + //This is the real assertion - could another thread lock + //the DataNode we're currently writing + Assert.assertTrue("Couldn't acquire a lock on the DataNode while we were calling tree.serialize", acquired); + } catch (InterruptedException e1) { + throw new RuntimeException(e1); + } + ranTestCase.set(true); + } + super.writeRecord(r, tag); + } + }; + + tree.serialize(oa, "test"); + + //Let's make sure that we hit the code that ran the real assertion above + Assert.assertTrue("Didn't find the expected node", ranTestCase.get()); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/DatadirCleanupManagerTest.java b/src/java/test/org/apache/zookeeper/server/DatadirCleanupManagerTest.java new file mode 100644 index 00000000000..9a818d1f4fc --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/DatadirCleanupManagerTest.java @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static org.apache.zookeeper.server.DatadirCleanupManager.PurgeTaskStatus.COMPLETED; +import static org.apache.zookeeper.server.DatadirCleanupManager.PurgeTaskStatus.NOT_STARTED; +import static org.apache.zookeeper.server.DatadirCleanupManager.PurgeTaskStatus.STARTED; + +public class DatadirCleanupManagerTest extends ZKTestCase { + + private DatadirCleanupManager purgeMgr; + private File snapDir; + private File dataLogDir; + + @Before + public void setUp() throws Exception { + File dataDir = ClientBase.createTmpDir(); + snapDir = dataDir; + dataLogDir = dataDir; + } + + @Test + public void testPurgeTask() throws Exception { + purgeMgr = new DatadirCleanupManager(snapDir, dataLogDir, 3, 1); + purgeMgr.start(); + Assert.assertEquals("Data log directory is not set as configured", + dataLogDir, purgeMgr.getDataLogDir()); + Assert.assertEquals("Snapshot directory is not set as configured", + snapDir, purgeMgr.getSnapDir()); + Assert.assertEquals("Snapshot retain count is not set as configured", + 3, purgeMgr.getSnapRetainCount()); + Assert.assertEquals("Purge task is not started", STARTED, purgeMgr.getPurgeTaskStatus()); + purgeMgr.shutdown(); + Assert.assertEquals("Purge task is still running after shutdown", COMPLETED, + purgeMgr.getPurgeTaskStatus()); + } + + @Test + public void testWithZeroPurgeInterval() throws Exception { + purgeMgr = new DatadirCleanupManager(snapDir, dataLogDir, 3, 0); + purgeMgr.start(); + Assert.assertEquals("Purge task is scheduled with zero purge interval", NOT_STARTED, + purgeMgr.getPurgeTaskStatus()); + purgeMgr.shutdown(); + Assert.assertEquals("Purge task is scheduled with zero purge interval", NOT_STARTED, + purgeMgr.getPurgeTaskStatus()); + } + + @Test + public void testWithNegativePurgeInterval() throws Exception { + purgeMgr = new DatadirCleanupManager(snapDir, dataLogDir, 3, -1); + purgeMgr.start(); + Assert.assertEquals("Purge task is scheduled with negative purge interval", + NOT_STARTED, purgeMgr.getPurgeTaskStatus()); + purgeMgr.shutdown(); + Assert.assertEquals("Purge task is scheduled with negative purge interval", NOT_STARTED, + purgeMgr.getPurgeTaskStatus()); + } + + @After + public void tearDown() throws Exception { + if (purgeMgr != null) { + purgeMgr.shutdown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java b/src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java new file mode 100644 index 00000000000..bf710449146 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/DeserializationPerfTest.java @@ -0,0 +1,112 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZKTestCase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class DeserializationPerfTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(DeserializationPerfTest.class); + + private static void deserializeTree(int depth, int width, int len) + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + BinaryInputArchive ia; + int count; + { + DataTree tree = new DataTree(); + SerializationPerfTest.createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]); + count = tree.getNodeCount(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos); + tree.serialize(oa, "test"); + baos.flush(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ia = BinaryInputArchive.getArchive(bais); + } + + DataTree dserTree = new DataTree(); + + System.gc(); + long start = System.nanoTime(); + dserTree.deserialize(ia, "test"); + long end = System.nanoTime(); + long durationms = (end - start) / 1000000L; + long pernodeus = ((end - start) / 1000L) / count; + + Assert.assertEquals(count, dserTree.getNodeCount()); + + LOG.info("Deserialized " + count + " nodes in " + durationms + + " ms (" + pernodeus + "us/node), depth=" + depth + " width=" + + width + " datalen=" + len); + } + + @Test + public void testSingleDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(1, 0, 20); + } + + @Test + public void testWideDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(2, 10000, 20); + } + + @Test + public void testDeepDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(400, 1, 20); + } + + @Test + public void test10Wide5DeepDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(5, 10, 20); + } + + @Test + public void test15Wide5DeepDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(5, 15, 20); + } + + @Test + public void test25Wide4DeepDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(4, 25, 20); + } + + @Test + public void test40Wide4DeepDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(4, 40, 20); + } + + @Test + public void test300Wide3DeepDeserialize() throws + InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + deserializeTree(3, 300, 20); + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java b/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java new file mode 100644 index 00000000000..fe7dce776b5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java @@ -0,0 +1,115 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +/** + * Test stand-alone server. + * + */ +public class InvalidSnapCountTest extends ZKTestCase implements Watcher { + protected static final Logger LOG = + LoggerFactory.getLogger(InvalidSnapCountTest.class); + + /** + * Verify the ability to start a standalone server instance. + */ + @Test + public void testInvalidSnapCount() throws Exception { + + final int CLIENT_PORT = 3181; + + MainThread main = new MainThread(CLIENT_PORT); + main.start(); + + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT, + CONNECTION_TIMEOUT)); + + Assert.assertEquals(SyncRequestProcessor.getSnapCount(), 2); + + main.shutdown(); + + } + + public void process(WatchedEvent event) { + // ignore for this test + } + + public static class MainThread extends Thread { + final File confFile; + final TestMain main; + + public MainThread(int clientPort) throws IOException { + super("Standalone server with clientPort:" + clientPort); + File tmpDir = ClientBase.createTmpDir(); + confFile = new File(tmpDir, "zoo.cfg"); + + FileWriter fwriter = new FileWriter(confFile); + fwriter.write("tickTime=2000\n"); + fwriter.write("initLimit=10\n"); + fwriter.write("syncLimit=5\n"); + fwriter.write("snapCount=1\n"); + + File dataDir = new File(tmpDir, "data"); + if (!dataDir.mkdir()) { + throw new IOException("unable to mkdir " + dataDir); + } + + // Convert windows path to UNIX to avoid problems with "\" + String dir = PathUtils.normalizeFileSystemPath(dataDir.toString()); + fwriter.write("dataDir=" + dir + "\n"); + + fwriter.write("clientPort=" + clientPort + "\n"); + fwriter.flush(); + fwriter.close(); + + main = new TestMain(); + } + + public void run() { + String args[] = new String[1]; + args[0] = confFile.toString(); + try { + main.initializeAndRun(args); + } catch (Exception e) { + // test will still fail even though we just log/ignore + LOG.error("unexpected exception in run", e); + } + } + + public void shutdown() { + main.shutdown(); + } + } + + public static class TestMain extends ZooKeeperServerMain { + public void shutdown() { + super.shutdown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java b/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java new file mode 100644 index 00000000000..547ab829183 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.RandomAccessFile; + +import static org.junit.Assert.assertTrue; + +/** + * This test checks that the server works even if the last snapshot is + * invalidated by corruption or if the server crashes while generating the + * snapshot. + */ +public class InvalidSnapshotTest extends ClientBase { + private static final Logger LOG = + LoggerFactory.getLogger(InvalidSnapshotTest.class); + + public InvalidSnapshotTest() { + SyncRequestProcessor.setSnapCount(100); + } + + /** + * Validate that the server can come up on an invalid snapshot - by + * reverting to a prior snapshot + associated logs. + */ + @Test + public void testInvalidSnapshot() throws Exception { + ZooKeeper zk = createClient(); + try { + for (int i = 0; i < 2000; i++) { + zk.create("/invalidsnap-" + i, new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + } finally { + zk.close(); + } + NIOServerCnxnFactory factory = (NIOServerCnxnFactory) serverFactory; + stopServer(); + + // now corrupt the snapshot + File snapFile = factory.zkServer.getTxnLogFactory().findMostRecentSnapshot(); + LOG.info("Corrupting " + snapFile); + RandomAccessFile raf = new RandomAccessFile(snapFile, "rws"); + raf.setLength(3); + raf.close(); + + // now restart the server + startServer(); + + // verify that the expected data exists and wasn't lost + zk = createClient(); + try { + assertTrue("the node should exist", + (zk.exists("/invalidsnap-1999", false) != null)); + } finally { + zk.close(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/MockNIOServerCnxn.java b/src/java/test/org/apache/zookeeper/server/MockNIOServerCnxn.java new file mode 100644 index 00000000000..94475eb4c2c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/MockNIOServerCnxn.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.server.NIOServerCnxnFactory.SelectorThread; + +import java.io.IOException; +import java.nio.channels.SelectionKey; +import java.nio.channels.SocketChannel; + +public class MockNIOServerCnxn extends NIOServerCnxn { + + public MockNIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, + SelectionKey sk, NIOServerCnxnFactory factory, + SelectorThread selectorThread) throws IOException { + super(zk, sock, sk, factory, selectorThread); + } + + /** + * Handles read/write IO on connection. + */ + public void doIO(SelectionKey k) throws InterruptedException { + super.doIO(k); + } + + @Override + protected boolean isSocketOpen() { + return true; + } +} diff --git a/src/java/test/org/apache/zookeeper/server/MockSelectorThread.java b/src/java/test/org/apache/zookeeper/server/MockSelectorThread.java new file mode 100644 index 00000000000..4b27b9e2288 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/MockSelectorThread.java @@ -0,0 +1,25 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import java.io.IOException; +import java.nio.channels.SelectionKey; + +public class MockSelectorThread extends NIOServerCnxnFactory.SelectorThread { + public MockSelectorThread(NIOServerCnxnFactory fact) throws IOException { + fact.super(0); + } + + public boolean addInterestOpsUpdateRequest(SelectionKey sk) { + return super.addInterestOpsUpdateRequest(sk); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/MockServerCnxn.java b/src/java/test/org/apache/zookeeper/server/MockServerCnxn.java new file mode 100644 index 00000000000..5a2147ee6ea --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/MockServerCnxn.java @@ -0,0 +1,107 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.jute.Record; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.proto.ReplyHeader; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.security.cert.Certificate; + +public class MockServerCnxn extends ServerCnxn { + public Certificate[] clientChain; + public boolean secure; + + @Override + int getSessionTimeout() { + return 0; + } + + @Override + void setSessionTimeout(int sessionTimeout) { + } + + @Override + void close() { + } + + @Override + public void sendResponse(ReplyHeader h, Record r, String tag) + throws IOException { + } + + @Override + void sendCloseSession() { + } + + @Override + public void process(WatchedEvent event) { + } + + @Override + public long getSessionId() { + return 0; + } + + @Override + void setSessionId(long sessionId) { + } + + @Override + public boolean isSecure() { + return secure; + } + + @Override + public Certificate[] getClientCertificateChain() { + return clientChain; + } + + @Override + public void setClientCertificateChain(Certificate[] chain) { + clientChain = chain; + } + + @Override + void sendBuffer(ByteBuffer closeConn) { + } + + @Override + void enableRecv() { + } + + @Override + void disableRecv() { + } + + @Override + protected ServerStats serverStats() { + return null; + } + + @Override + public long getOutstandingRequests() { + return 0; + } + + @Override + public InetSocketAddress getRemoteSocketAddress() { + return null; + } + + @Override + public int getInterestOps() { + return 0; + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java b/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java new file mode 100644 index 00000000000..45a81d607c4 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +public class NIOServerCnxnTest extends ClientBase { + private static final Logger LOG = LoggerFactory + .getLogger(NIOServerCnxnTest.class); + + /** + * Test operations on ServerCnxn after socket closure. + */ + @Test(timeout = 60000) + public void testOperationsAfterCnxnClose() throws IOException, + InterruptedException, KeeperException { + final ZooKeeper zk = createClient(); + + final String path = "/a"; + try { + // make sure zkclient works + zk.create(path, "test".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertNotNull("Didn't create znode:" + path, + zk.exists(path, false)); + // Defaults ServerCnxnFactory would be instantiated with + // NIOServerCnxnFactory + Assert.assertTrue( + "Didn't instantiate ServerCnxnFactory with NIOServerCnxnFactory!", + serverFactory instanceof NIOServerCnxnFactory); + Iterable connections = serverFactory.getConnections(); + for (ServerCnxn serverCnxn : connections) { + serverCnxn.close(); + try { + serverCnxn.toString(); + } catch (Exception e) { + LOG.error("Exception while getting connection details!", e); + Assert.fail("Shouldn't throw exception while " + + "getting connection details!"); + } + } + } finally { + zk.close(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/NettyServerCnxnTest.java b/src/java/test/org/apache/zookeeper/server/NettyServerCnxnTest.java new file mode 100644 index 00000000000..99516962346 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/NettyServerCnxnTest.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test verifies the behavior of NettyServerCnxn which represents a connection + * from a client to the server. + */ +public class NettyServerCnxnTest extends ClientBase { + private static final Logger LOG = LoggerFactory + .getLogger(NettyServerCnxnTest.class); + + @Override + public void setUp() throws Exception { + System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, + "org.apache.zookeeper.server.NettyServerCnxnFactory"); + super.setUp(); + } + + /** + * Test verifies the channel closure - while closing the channel + * servercnxnfactory should remove all channel references to avoid + * duplicate channel closure. Duplicate closure may result in indefinite + * hanging due to netty open issue. + * + * @see NETTY-412 + */ + @Test(timeout = 40000) + public void testSendCloseSession() throws Exception { + Assert.assertTrue( + "Didn't instantiate ServerCnxnFactory with NettyServerCnxnFactory!", + serverFactory instanceof NettyServerCnxnFactory); + + final ZooKeeper zk = createClient(); + final String path = "/a"; + try { + // make sure zkclient works + zk.create(path, "test".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertNotNull("Didn't create znode:" + path, + zk.exists(path, false)); + Iterable connections = serverFactory.getConnections(); + Assert.assertEquals("Mismatch in number of live connections!", 1, + serverFactory.getNumAliveConnections()); + for (ServerCnxn serverCnxn : connections) { + serverCnxn.sendCloseSession(); + } + LOG.info("Waiting for the channel disconnected event"); + int timeout = 0; + while (serverFactory.getNumAliveConnections() != 0) { + Thread.sleep(1000); + timeout += 1000; + if (timeout > CONNECTION_TIMEOUT) { + Assert.fail("The number of live connections should be 0"); + } + } + } finally { + zk.close(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java b/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java new file mode 100644 index 00000000000..861a090a53f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java @@ -0,0 +1,292 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.KeeperException.SessionMovedException; +import org.apache.zookeeper.MultiTransactionRecord; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.proto.SetDataRequest; +import org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.txn.ErrorTxn; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class PrepRequestProcessorTest extends ClientBase { + private static final Logger LOG = LoggerFactory.getLogger(PrepRequestProcessorTest.class); + private static final int CONNECTION_TIMEOUT = 3000; + private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique(); + private CountDownLatch pLatch; + + private ZooKeeperServer zks; + private ServerCnxnFactory servcnxnf; + private PrepRequestProcessor processor; + private Request outcome; + + @Before + public void setup() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(100); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + + servcnxnf = ServerCnxnFactory.createFactory(PORT, -1); + servcnxnf.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + zks.sessionTracker = new MySessionTracker(); + } + + @After + public void teardown() throws Exception { + if (servcnxnf != null) { + servcnxnf.shutdown(); + } + if (zks != null) { + zks.shutdown(); + } + } + + @Test + public void testPRequest() throws Exception { + pLatch = new CountDownLatch(1); + processor = new PrepRequestProcessor(zks, new MyRequestProcessor()); + Request foo = new Request(null, 1l, 1, OpCode.create, ByteBuffer.allocate(3), null); + processor.pRequest(foo); + + Assert.assertEquals("Request should have marshalling error", new ErrorTxn(KeeperException.Code.MARSHALLINGERROR.intValue()), + outcome.getTxn()); + Assert.assertTrue("request hasn't been processed in chain", pLatch.await(5, TimeUnit.SECONDS)); + } + + private Request createRequest(Record record, int opCode) throws IOException { + // encoding + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + record.serialize(boa, "request"); + baos.close(); + // Id + List ids = Arrays.asList(Ids.ANYONE_ID_UNSAFE); + return new Request(null, 1l, 0, opCode, ByteBuffer.wrap(baos.toByteArray()), ids); + } + + private void process(List ops) throws Exception { + pLatch = new CountDownLatch(1); + processor = new PrepRequestProcessor(zks, new MyRequestProcessor()); + + Record record = new MultiTransactionRecord(ops); + Request req = createRequest(record, OpCode.multi); + + processor.pRequest(req); + Assert.assertTrue("request hasn't been processed in chain", pLatch.await(5, TimeUnit.SECONDS)); + } + + /** + * This test checks that a successful multi will change outstanding record + * and failed multi shouldn't change outstanding record. + */ + @Test + public void testMultiOutstandingChange() throws Exception { + zks.getZKDatabase().dataTree.createNode("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, 0, 0, 0, 0); + + Assert.assertNull(zks.outstandingChangesForPath.get("/foo")); + + process(Arrays.asList( + Op.setData("/foo", new byte[0], -1))); + + ChangeRecord cr = zks.outstandingChangesForPath.get("/foo"); + Assert.assertNotNull("Change record wasn't set", cr); + Assert.assertEquals("Record zxid wasn't set correctly", + 1, cr.zxid); + + process(Arrays.asList( + Op.delete("/foo", -1))); + cr = zks.outstandingChangesForPath.get("/foo"); + Assert.assertEquals("Record zxid wasn't set correctly", + 2, cr.zxid); + + + // It should fail and shouldn't change outstanding record. + process(Arrays.asList( + Op.delete("/foo", -1))); + cr = zks.outstandingChangesForPath.get("/foo"); + // zxid should still be previous result because record's not changed. + Assert.assertEquals("Record zxid wasn't set correctly", + 2, cr.zxid); + } + + /** + * ZOOKEEPER-2052: + * This test checks that if a multi operation aborted, and during the multi there is side effect + * that changed outstandingChangesForPath, after aborted the side effect should be removed and + * everything should be restored correctly. + */ + @Test + public void testMultiRollbackNoLastChange() throws Exception { + zks.getZKDatabase().dataTree.createNode("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, 0, 0, 0, 0); + zks.getZKDatabase().dataTree.createNode("/foo/bar", new byte[0], Ids.OPEN_ACL_UNSAFE, 0, 0, 0, 0); + + Assert.assertNull(zks.outstandingChangesForPath.get("/foo")); + + // multi record: + // set "/foo" => succeed, leave a outstanding change + // delete "/foo" => fail, roll back change + process(Arrays.asList( + Op.setData("/foo", new byte[0], -1), + Op.delete("/foo", -1))); + + // aborting multi shouldn't leave any record. + Assert.assertNull(zks.outstandingChangesForPath.get("/foo")); + } + + /** + * It tests that PrepRequestProcessor will return BadArgument KeeperException + * if the request path (if it exists) is not valid, e.g. empty string. + */ + @Test + public void testInvalidPath() throws Exception { + pLatch = new CountDownLatch(1); + processor = new PrepRequestProcessor(zks, new MyRequestProcessor()); + + SetDataRequest record = new SetDataRequest("", new byte[0], -1); + Request req = createRequest(record, OpCode.setData); + processor.pRequest(req); + pLatch.await(); + Assert.assertEquals(outcome.getHdr().getType(), OpCode.error); + Assert.assertEquals(outcome.getException().code(), KeeperException.Code.BADARGUMENTS); + } + + private class MyRequestProcessor implements RequestProcessor { + @Override + public void processRequest(Request request) { + // getting called by PrepRequestProcessor + outcome = request; + pLatch.countDown(); + } + + @Override + public void shutdown() { + // TODO Auto-generated method stub + + } + } + + private class MySessionTracker implements SessionTracker { + @Override + public boolean addGlobalSession(long id, int to) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean addSession(long id, int to) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void checkSession(long sessionId, Object owner) + throws SessionExpiredException, SessionMovedException { + // TODO Auto-generated method stub + } + + @Override + public long createSession(int sessionTimeout) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void dumpSessions(PrintWriter pwriter) { + // TODO Auto-generated method stub + + } + + @Override + public void removeSession(long sessionId) { + // TODO Auto-generated method stub + + } + + public int upgradeSession(long sessionId) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setOwner(long id, Object owner) + throws SessionExpiredException { + // TODO Auto-generated method stub + + } + + @Override + public void shutdown() { + // TODO Auto-generated method stub + + } + + @Override + public boolean touchSession(long sessionId, int sessionTimeout) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setSessionClosing(long sessionId) { + // TODO Auto-generated method stub + } + + @Override + public boolean isTrackingSession(long sessionId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void checkGlobalSession(long sessionId, Object owner) + throws SessionExpiredException, SessionMovedException { + // TODO Auto-generated method stub + } + + @Override + public Map> getSessionExpiryMap() { + return new HashMap>(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java b/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java new file mode 100644 index 00000000000..5a7f69e8b7a --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/PurgeTxnTest.java @@ -0,0 +1,457 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.PurgeTxnLog; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; + +public class PurgeTxnTest extends ZKTestCase implements Watcher { + private static final Logger LOG = LoggerFactory.getLogger(PurgeTxnTest.class); + private static final int CONNECTION_TIMEOUT = 3000; + private static final long OP_TIMEOUT_IN_MILLIS = 90000; + private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique(); + private File tmpDir; + + @After + public void teardown() { + if (null != tmpDir) { + ClientBase.recursiveDelete(tmpDir); + } + } + + /** + * test the purge + * @throws Exception an exception might be thrown here + */ + @Test + public void testPurge() throws Exception { + tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(100); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + try { + for (int i = 0; i < 2000; i++) { + zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + } finally { + zk.close(); + } + f.shutdown(); + zks.getTxnLogFactory().close(); + Assert.assertTrue("waiting for server to shutdown", + ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + // now corrupt the snapshot + PurgeTxnLog.purge(tmpDir, tmpDir, 3); + FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir); + List listLogs = snaplog.findNRecentSnapshots(4); + int numSnaps = 0; + for (File ff : listLogs) { + if (ff.getName().startsWith("snapshot")) { + numSnaps++; + } + } + Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3)); + snaplog.close(); + zks.shutdown(); + } + + /** + * Tests purge when logs are rolling or a new snapshot is created, then + * these newer files should alse be excluded in the current cycle. + * + * For frequent snapshotting, configured SnapCount to 30. There are three + * threads which will create 1000 znodes each and simultaneously do purge + * call + */ + @Test + public void testPurgeWhenLogRollingInProgress() throws Exception { + tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(30); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + final ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + final CountDownLatch doPurge = new CountDownLatch(1); + final CountDownLatch purgeFinished = new CountDownLatch(1); + final AtomicBoolean opFailed = new AtomicBoolean(false); + new Thread() { + public void run() { + try { + doPurge.await(OP_TIMEOUT_IN_MILLIS / 2, + TimeUnit.MILLISECONDS); + PurgeTxnLog.purge(tmpDir, tmpDir, 3); + } catch (IOException ioe) { + LOG.error("Exception when purge", ioe); + opFailed.set(true); + } catch (InterruptedException ie) { + LOG.error("Exception when purge", ie); + opFailed.set(true); + } finally { + purgeFinished.countDown(); + } + } + + ; + }.start(); + final int thCount = 3; + List znodes = manyClientOps(zk, doPurge, thCount, + "/invalidsnap"); + Assert.assertTrue("Purging is not finished!", purgeFinished.await( + OP_TIMEOUT_IN_MILLIS, TimeUnit.MILLISECONDS)); + Assert.assertFalse("Purging failed!", opFailed.get()); + for (String znode : znodes) { + try { + zk.getData(znode, false, null); + } catch (Exception ke) { + LOG.error("Unexpected exception when visiting znode!", ke); + Assert.fail("Unexpected exception when visiting znode!"); + } + } + zk.close(); + f.shutdown(); + zks.shutdown(); + zks.getTxnLogFactory().close(); + } + + /** + * Tests finding n recent snapshots from set of snapshots and data logs + */ + @Test + public void testFindNRecentSnapshots() throws Exception { + int nRecentSnap = 4; // n recent snap shots + int nRecentCount = 30; + int offset = 0; + tmpDir = ClientBase.createTmpDir(); + File version2 = new File(tmpDir.toString(), "version-2"); + Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(), + version2.mkdir()); + List expectedNRecentSnapFiles = new ArrayList(); + int counter = offset + (2 * nRecentCount); + for (int i = 0; i < nRecentCount; i++) { + // simulate log file + File logFile = new File(version2 + "/log." + Long.toHexString(--counter)); + Assert.assertTrue("Failed to create log File:" + logFile.toString(), + logFile.createNewFile()); + // simulate snapshot file + File snapFile = new File(version2 + "/snapshot." + + Long.toHexString(--counter)); + Assert.assertTrue("Failed to create snap File:" + snapFile.toString(), + snapFile.createNewFile()); + // add the n recent snap files for assertion + if (i < nRecentSnap) { + expectedNRecentSnapFiles.add(snapFile); + } + } + + FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir); + List nRecentSnapFiles = txnLog.findNRecentSnapshots(nRecentSnap); + txnLog.close(); + Assert.assertEquals("exactly 4 snapshots ", 4, + nRecentSnapFiles.size()); + expectedNRecentSnapFiles.removeAll(nRecentSnapFiles); + Assert.assertEquals("Didn't get the recent snap files", 0, + expectedNRecentSnapFiles.size()); + } + + /** + * Tests purge where the data directory contains old snapshots and data + * logs, newest snapshots and data logs, (newest + n) snapshots and data + * logs + */ + @Test + public void testSnapFilesGreaterThanToRetain() throws Exception { + int nRecentCount = 4; + int fileAboveRecentCount = 4; + int fileToPurgeCount = 2; + AtomicInteger offset = new AtomicInteger(0); + tmpDir = ClientBase.createTmpDir(); + File version2 = new File(tmpDir.toString(), "version-2"); + Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(), + version2.mkdir()); + List snapsToPurge = new ArrayList(); + List logsToPurge = new ArrayList(); + List snaps = new ArrayList(); + List logs = new ArrayList(); + List snapsAboveRecentFiles = new ArrayList(); + List logsAboveRecentFiles = new ArrayList(); + createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge, + logsToPurge); + createDataDirFiles(offset, nRecentCount, version2, snaps, logs); + createDataDirFiles(offset, fileAboveRecentCount, version2, + snapsAboveRecentFiles, logsAboveRecentFiles); + + FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir); + PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps); + txnLog.close(); + verifyFilesAfterPurge(snapsToPurge, false); + verifyFilesAfterPurge(logsToPurge, false); + verifyFilesAfterPurge(snaps, true); + verifyFilesAfterPurge(logs, true); + verifyFilesAfterPurge(snapsAboveRecentFiles, true); + verifyFilesAfterPurge(logsAboveRecentFiles, true); + } + + /** + * Tests purge where the data directory contains snap files equals to the + * number of files to be retained + */ + @Test + public void testSnapFilesEqualsToRetain() throws Exception { + int nRecentCount = 3; + AtomicInteger offset = new AtomicInteger(0); + tmpDir = ClientBase.createTmpDir(); + File version2 = new File(tmpDir.toString(), "version-2"); + Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(), + version2.mkdir()); + List snaps = new ArrayList(); + List logs = new ArrayList(); + createDataDirFiles(offset, nRecentCount, version2, snaps, logs); + + FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir); + PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps); + txnLog.close(); + verifyFilesAfterPurge(snaps, true); + verifyFilesAfterPurge(logs, true); + } + + /** + * Tests purge where the data directory contains old snapshots and data + * logs, newest snapshots and data logs + */ + @Test + public void testSnapFilesLessThanToRetain() throws Exception { + int nRecentCount = 4; + int fileToPurgeCount = 2; + AtomicInteger offset = new AtomicInteger(0); + tmpDir = ClientBase.createTmpDir(); + File version2 = new File(tmpDir.toString(), "version-2"); + Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(), + version2.mkdir()); + List snapsToPurge = new ArrayList(); + List logsToPurge = new ArrayList(); + List snaps = new ArrayList(); + List logs = new ArrayList(); + createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge, + logsToPurge); + createDataDirFiles(offset, nRecentCount, version2, snaps, logs); + + FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir); + PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps); + txnLog.close(); + verifyFilesAfterPurge(snapsToPurge, false); + verifyFilesAfterPurge(logsToPurge, false); + verifyFilesAfterPurge(snaps, true); + verifyFilesAfterPurge(logs, true); + } + + /** + * PurgeTxnLog is called with dataLogDir snapDir -n count This test case + * verify these values are parsed properly and functionality works fine + */ + @Test + public void testPurgeTxnLogWithDataDir() + throws Exception { + tmpDir = ClientBase.createTmpDir(); + File dataDir = new File(tmpDir, "dataDir"); + File dataLogDir = new File(tmpDir, "dataLogDir"); + + File dataDirVersion2 = new File(dataDir, "version-2"); + dataDirVersion2.mkdirs(); + File dataLogDirVersion2 = new File(dataLogDir, "version-2"); + dataLogDirVersion2.mkdirs(); + + // create dummy log and transaction file + int totalFiles = 20; + + // create transaction and snapshot files in different-different + // directories + for (int i = 0; i < totalFiles; i++) { + // simulate log file + File logFile = new File(dataLogDirVersion2, "log." + + Long.toHexString(i)); + logFile.createNewFile(); + // simulate snapshot file + File snapFile = new File(dataDirVersion2, "snapshot." + + Long.toHexString(i)); + snapFile.createNewFile(); + } + + int numberOfFilesToKeep = 10; + // scenario where four parameter are passed + String[] args = new String[]{dataLogDir.getAbsolutePath(), + dataDir.getAbsolutePath(), "-n", + Integer.toString(numberOfFilesToKeep)}; + PurgeTxnLog.main(args); + + assertEquals(numberOfFilesToKeep, dataDirVersion2.listFiles().length); + assertEquals(numberOfFilesToKeep, dataLogDirVersion2.listFiles().length); + ClientBase.recursiveDelete(tmpDir); + + } + + /** + * PurgeTxnLog is called with dataLogDir -n count This test case verify + * these values are parsed properly and functionality works fine + */ + @Test + public void testPurgeTxnLogWithoutDataDir() + throws Exception { + tmpDir = ClientBase.createTmpDir(); + File dataDir = new File(tmpDir, "dataDir"); + File dataLogDir = new File(tmpDir, "dataLogDir"); + + File dataDirVersion2 = new File(dataDir, "version-2"); + dataDirVersion2.mkdirs(); + File dataLogDirVersion2 = new File(dataLogDir, "version-2"); + dataLogDirVersion2.mkdirs(); + + // create dummy log and transaction file + int totalFiles = 20; + + // create transaction and snapshot files in data directory + for (int i = 0; i < totalFiles; i++) { + // simulate log file + File logFile = new File(dataLogDirVersion2, "log." + + Long.toHexString(i)); + logFile.createNewFile(); + // simulate snapshot file + File snapFile = new File(dataLogDirVersion2, "snapshot." + + Long.toHexString(i)); + snapFile.createNewFile(); + } + + int numberOfFilesToKeep = 10; + // scenario where only three parameter are passed + String[] args = new String[]{dataLogDir.getAbsolutePath(), "-n", + Integer.toString(numberOfFilesToKeep)}; + PurgeTxnLog.main(args); + assertEquals(numberOfFilesToKeep + numberOfFilesToKeep, + dataLogDirVersion2.listFiles().length); + ClientBase.recursiveDelete(tmpDir); + + } + + private void createDataDirFiles(AtomicInteger offset, int limit, + File version_2, List snaps, List logs) + throws IOException { + int counter = offset.get() + (2 * limit); + offset.set(counter); + for (int i = 0; i < limit; i++) { + // simulate log file + File logFile = new File(version_2 + "/log." + Long.toHexString(--counter)); + Assert.assertTrue("Failed to create log File:" + logFile.toString(), + logFile.createNewFile()); + logs.add(logFile); + // simulate snapshot file + File snapFile = new File(version_2 + "/snapshot." + + Long.toHexString(--counter)); + Assert.assertTrue("Failed to create snap File:" + snapFile.toString(), + snapFile.createNewFile()); + snaps.add(snapFile); + } + } + + private void verifyFilesAfterPurge(List logs, boolean exists) { + for (File file : logs) { + Assert.assertEquals("After purging, file " + file, exists, + file.exists()); + } + } + + private List manyClientOps(final ZooKeeper zk, + final CountDownLatch doPurge, int thCount, final String prefix) { + Thread[] ths = new Thread[thCount]; + final List znodes = Collections + .synchronizedList(new ArrayList()); + final CountDownLatch finished = new CountDownLatch(thCount); + for (int indx = 0; indx < thCount; indx++) { + final String myprefix = prefix + "-" + indx; + Thread th = new Thread() { + public void run() { + for (int i = 0; i < 1000; i++) { + try { + String mynode = myprefix + "-" + i; + znodes.add(mynode); + zk.create(mynode, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (Exception e) { + LOG.error("Unexpected exception occured!", e); + } + if (i == 200) { + doPurge.countDown(); + } + } + finished.countDown(); + } + + ; + }; + ths[indx] = th; + } + + for (Thread thread : ths) { + thread.start(); + } + try { + Assert.assertTrue("ZkClient ops is not finished!", + finished.await(OP_TIMEOUT_IN_MILLIS, TimeUnit.MILLISECONDS)); + } catch (InterruptedException ie) { + LOG.error("Unexpected exception occured!", ie); + Assert.fail("Unexpected exception occured!"); + } + return znodes; + } + + public void process(WatchedEvent event) { + // do nothing + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/SerializationPerfTest.java b/src/java/test/org/apache/zookeeper/server/SerializationPerfTest.java new file mode 100644 index 00000000000..00158552c0f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/SerializationPerfTest.java @@ -0,0 +1,118 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZKTestCase; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.OutputStream; + +public class SerializationPerfTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(SerializationPerfTest.class); + + static int createNodes(DataTree tree, String path, int depth, + int childcount, int parentCVersion, byte[] data) throws KeeperException.NodeExistsException, KeeperException.NoNodeException { + path += "node" + depth; + tree.createNode(path, data, null, -1, ++parentCVersion, 1, 1); + + if (--depth == 0) { + return 1; + } + + path += "/"; + + int count = 1; + for (int i = 0; i < childcount; i++) { + count += createNodes(tree, path + i, depth, childcount, 1, data); + } + + return count; + } + + private static void serializeTree(int depth, int width, int len) + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + DataTree tree = new DataTree(); + createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]); + int count = tree.getNodeCount(); + + BinaryOutputArchive oa = + BinaryOutputArchive.getArchive(new NullOutputStream()); + System.gc(); + long start = System.nanoTime(); + tree.serialize(oa, "test"); + long end = System.nanoTime(); + long durationms = (end - start) / 1000000L; + long pernodeus = ((end - start) / 1000L) / count; + LOG.info("Serialized " + count + " nodes in " + + durationms + " ms (" + pernodeus + "us/node), depth=" + + depth + " width=" + width + " datalen=" + len); + } + + @Test + public void testSingleSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(1, 0, 20); + } + + @Test + public void testWideSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(2, 10000, 20); + } + + @Test + public void testDeepSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(400, 1, 20); + } + + @Test + public void test10Wide5DeepSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(5, 10, 20); + } + + @Test + public void test15Wide5DeepSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(5, 15, 20); + } + + @Test + public void test25Wide4DeepSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(4, 25, 20); + } + + @Test + public void test40Wide4DeepSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(4, 40, 20); + } + + @Test + public void test300Wide3DeepSerialize() + throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { + serializeTree(3, 300, 20); + } + + private static class NullOutputStream extends OutputStream { + public void write(int b) { + // do nothing - exclude persistence from perf + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ServerCnxnFactoryAccessor.java b/src/java/test/org/apache/zookeeper/server/ServerCnxnFactoryAccessor.java new file mode 100644 index 00000000000..1110c546407 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ServerCnxnFactoryAccessor.java @@ -0,0 +1,17 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +public class ServerCnxnFactoryAccessor { + public static ZooKeeperServer getZkServer(ServerCnxnFactory fac) { + return fac.zkServer; + } +} diff --git a/src/java/test/org/apache/zookeeper/server/SessionTrackerTest.java b/src/java/test/org/apache/zookeeper/server/SessionTrackerTest.java new file mode 100644 index 00000000000..7e91a4ce257 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/SessionTrackerTest.java @@ -0,0 +1,148 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.server.SessionTrackerImpl.SessionImpl; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Testing zk client session logic in sessiontracker + */ +public class SessionTrackerTest extends ZKTestCase { + + private final long sessionId = 339900; + private final int sessionTimeout = 3000; + private FirstProcessor firstProcessor; + private CountDownLatch latch; + + /** + * Verify the create session call in the Leader.FinalRequestProcessor after + * the session expiration. + */ + @Test(timeout = 20000) + public void testAddSessionAfterSessionExpiry() throws Exception { + ZooKeeperServer zks = setupSessionTracker(); + + latch = new CountDownLatch(1); + zks.sessionTracker.addSession(sessionId, sessionTimeout); + SessionTrackerImpl sessionTrackerImpl = (SessionTrackerImpl) zks.sessionTracker; + SessionImpl sessionImpl = sessionTrackerImpl.sessionsById + .get(sessionId); + Assert.assertNotNull("Sessionid:" + sessionId + + " doesn't exists in sessiontracker", sessionImpl); + + // verify the session existence + Object sessionOwner = new Object(); + sessionTrackerImpl.checkSession(sessionId, sessionOwner); + + // waiting for the session expiry + latch.await(sessionTimeout * 2, TimeUnit.MILLISECONDS); + + // Simulating FinalRequestProcessor logic: create session request has + // delayed and now reaches FinalRequestProcessor. Here the leader zk + // will do sessionTracker.addSession(id, timeout) + sessionTrackerImpl.addSession(sessionId, sessionTimeout); + try { + sessionTrackerImpl.checkSession(sessionId, sessionOwner); + Assert.fail("Should throw session expiry exception " + + "as the session has expired and closed"); + } catch (KeeperException.SessionExpiredException e) { + // expected behaviour + } + Assert.assertTrue("Session didn't expired", sessionImpl.isClosing()); + Assert.assertFalse("Session didn't expired", sessionTrackerImpl + .touchSession(sessionId, sessionTimeout)); + Assert.assertEquals( + "Duplicate session expiry request has been generated", 1, + firstProcessor.getCountOfCloseSessionReq()); + } + + /** + * Verify the session closure request has reached PrepRequestProcessor soon + * after session expiration by the session tracker + */ + @Test(timeout = 20000) + public void testCloseSessionRequestAfterSessionExpiry() throws Exception { + ZooKeeperServer zks = setupSessionTracker(); + + latch = new CountDownLatch(1); + zks.sessionTracker.addSession(sessionId, sessionTimeout); + SessionTrackerImpl sessionTrackerImpl = (SessionTrackerImpl) zks.sessionTracker; + SessionImpl sessionImpl = sessionTrackerImpl.sessionsById + .get(sessionId); + Assert.assertNotNull("Sessionid:" + sessionId + + " doesn't exists in sessiontracker", sessionImpl); + + // verify the session existence + Object sessionOwner = new Object(); + sessionTrackerImpl.checkSession(sessionId, sessionOwner); + + // waiting for the session expiry + latch.await(sessionTimeout * 2, TimeUnit.MILLISECONDS); + + // Simulating close session request: removeSession() will be executed + // while OpCode.closeSession + sessionTrackerImpl.removeSession(sessionId); + SessionImpl actualSession = sessionTrackerImpl.sessionsById + .get(sessionId); + Assert.assertNull("Session:" + sessionId + + " still exists after removal", actualSession); + } + + private ZooKeeperServer setupSessionTracker() throws IOException { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + zks.setupRequestProcessors(); + firstProcessor = new FirstProcessor(zks, null); + zks.firstProcessor = firstProcessor; + + // setup session tracker + zks.createSessionTracker(); + zks.startSessionTracker(); + return zks; + } + + // Mock processor used in zookeeper server + private class FirstProcessor extends PrepRequestProcessor { + private volatile int countOfCloseSessionReq = 0; + + public FirstProcessor(ZooKeeperServer zks, + RequestProcessor nextProcessor) { + super(zks, nextProcessor); + } + + @Override + public void processRequest(Request request) { + // check session close request + if (request.type == OpCode.closeSession) { + latch.countDown(); + countOfCloseSessionReq++; + } + } + + // return number of session expiry calls + int getCountOfCloseSessionReq() { + return countOfCloseSessionReq; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ToStringTest.java b/src/java/test/org/apache/zookeeper/server/ToStringTest.java new file mode 100644 index 00000000000..ab4ff84134e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ToStringTest.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.proto.SetDataRequest; +import org.junit.Assert; +import org.junit.Test; + +/** + * A misc place to verify toString methods - mainly to make sure they don't + * fail. + */ +public class ToStringTest extends ZKTestCase { + /** Verify jute - which we've had particular problems with in the past + * wrt null fields */ + @Test + public void testJuteToString() { + SetDataRequest req = new SetDataRequest(null, null, 0); + Assert.assertNotSame("ERROR", req.toString()); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/WatchesPathReportTest.java b/src/java/test/org/apache/zookeeper/server/WatchesPathReportTest.java new file mode 100644 index 00000000000..f3a959859f3 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/WatchesPathReportTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.*; + +public class WatchesPathReportTest extends ZKTestCase { + private Map> m; + private WatchesPathReport r; + + @Before + public void setUp() { + m = new HashMap>(); + Set s = new HashSet(); + s.add(101L); + s.add(102L); + m.put("path1", s); + s = new HashSet(); + s.add(201L); + m.put("path2", s); + r = new WatchesPathReport(m); + } + + @Test + public void testHasSessions() { + assertTrue(r.hasSessions("path1")); + assertTrue(r.hasSessions("path2")); + assertFalse(r.hasSessions("path3")); + } + + @Test + public void testGetSessions() { + Set s = r.getSessions("path1"); + assertEquals(2, s.size()); + assertTrue(s.contains(101L)); + assertTrue(s.contains(102L)); + s = r.getSessions("path2"); + assertEquals(1, s.size()); + assertTrue(s.contains(201L)); + assertNull(r.getSessions("path3")); + } + + @Test + public void testToMap() { + assertEquals(m, r.toMap()); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/WatchesReportTest.java b/src/java/test/org/apache/zookeeper/server/WatchesReportTest.java new file mode 100644 index 00000000000..cb173f34919 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/WatchesReportTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.*; + +public class WatchesReportTest extends ZKTestCase { + private Map> m; + private WatchesReport r; + + @Before + public void setUp() { + m = new HashMap>(); + Set s = new HashSet(); + s.add("path1a"); + s.add("path1b"); + m.put(1L, s); + s = new HashSet(); + s.add("path2a"); + m.put(2L, s); + r = new WatchesReport(m); + } + + @Test + public void testHasPaths() { + assertTrue(r.hasPaths(1L)); + assertTrue(r.hasPaths(2L)); + assertFalse(r.hasPaths(3L)); + } + + @Test + public void testGetPaths() { + Set s = r.getPaths(1L); + assertEquals(2, s.size()); + assertTrue(s.contains("path1a")); + assertTrue(s.contains("path1b")); + s = r.getPaths(2L); + assertEquals(1, s.size()); + assertTrue(s.contains("path2a")); + assertNull(r.getPaths(3L)); + } + + @Test + public void testToMap() { + assertEquals(m, r.toMap()); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/WatchesSummaryTest.java b/src/java/test/org/apache/zookeeper/server/WatchesSummaryTest.java new file mode 100644 index 00000000000..8eed0dd48c5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/WatchesSummaryTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Before; +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.*; + +public class WatchesSummaryTest extends ZKTestCase { + private WatchesSummary s; + + @Before + public void setUp() { + s = new WatchesSummary(1, 2, 3); + } + + @Test + public void testGetters() { + assertEquals(1, s.getNumConnections()); + assertEquals(2, s.getNumPaths()); + assertEquals(3, s.getTotalWatches()); + } + + @Test + public void testToMap() { + Map m = s.toMap(); + assertEquals(3, m.size()); + assertEquals(Integer.valueOf(1), m.get(WatchesSummary.KEY_NUM_CONNECTIONS)); + assertEquals(Integer.valueOf(2), m.get(WatchesSummary.KEY_NUM_PATHS)); + assertEquals(Integer.valueOf(3), m.get(WatchesSummary.KEY_NUM_TOTAL_WATCHES)); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java new file mode 100644 index 00000000000..9dc6395aef8 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ZooKeeperServerBeanTest { + @Before + public void setup() { + System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, + "org.apache.zookeeper.server.NettyServerCnxnFactory"); + } + + @After + public void teardown() throws Exception { + System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); + } + + @Test + public void testGetSecureClientPort() throws IOException { + ZooKeeperServer zks = new ZooKeeperServer(); + /** + * case 1: When secure client is not configured GetSecureClientPort + * should return empty string + */ + ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks); + String result = serverBean.getSecureClientPort(); + assertEquals("", result); + + /** + * case 2: When secure client is configured GetSecureClientPort should + * return configured port + */ + + ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); + int secureClientPort = 8443; + InetSocketAddress address = new InetSocketAddress(secureClientPort); + cnxnFactory.configure(address, 5, true); + zks.setSecureServerCnxnFactory(cnxnFactory); + + result = serverBean.getSecureClientPort(); + assertEquals(Integer.toString(secureClientPort), result); + + // cleanup + cnxnFactory.shutdown(); + + } + + @Test + public void testGetSecureClientAddress() throws IOException { + ZooKeeperServer zks = new ZooKeeperServer(); + /** + * case 1: When secure client is not configured getSecureClientAddress + * should return empty string + */ + ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks); + String result = serverBean.getSecureClientPort(); + assertEquals("", result); + + /** + * case 2: When secure client is configured getSecureClientAddress + * should return configured SecureClientAddress + */ + + ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); + int secureClientPort = 8443; + InetSocketAddress address = new InetSocketAddress(secureClientPort); + cnxnFactory.configure(address, 5, true); + zks.setSecureServerCnxnFactory(cnxnFactory); + + result = serverBean.getSecureClientAddress(); + String ipv4 = "0.0.0.0:" + secureClientPort; + String ipv6 = "0:0:0:0:0:0:0:0:" + secureClientPort; + assertTrue(result.equals(ipv4) || result.equals(ipv6)); + + // cleanup + cnxnFactory.shutdown(); + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/ZooKeeperServerConfTest.java b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerConfTest.java new file mode 100644 index 00000000000..d43d9b3b5ba --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerConfTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Before; +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.*; + +public class ZooKeeperServerConfTest extends ZKTestCase { + private ZooKeeperServerConf c; + + @Before + public void setUp() { + c = new ZooKeeperServerConf(1, "a", "b", 2, 3, 4, 5, 6L); + } + + @Test + public void testGetters() { + assertEquals(1, c.getClientPort()); + assertEquals("a", c.getDataDir()); + assertEquals("b", c.getDataLogDir()); + assertEquals(2, c.getTickTime()); + assertEquals(3, c.getMaxClientCnxnsPerHost()); + assertEquals(4, c.getMinSessionTimeout()); + assertEquals(5, c.getMaxSessionTimeout()); + assertEquals(6L, c.getServerId()); + } + + @Test + public void testToMap() { + Map m = c.toMap(); + assertEquals(8, m.size()); + assertEquals(Integer.valueOf(1), m.get(ZooKeeperServerConf.KEY_CLIENT_PORT)); + assertEquals("a", m.get(ZooKeeperServerConf.KEY_DATA_DIR)); + assertEquals("b", m.get(ZooKeeperServerConf.KEY_DATA_LOG_DIR)); + assertEquals(Integer.valueOf(2), m.get(ZooKeeperServerConf.KEY_TICK_TIME)); + assertEquals(Integer.valueOf(3), m.get(ZooKeeperServerConf.KEY_MAX_CLIENT_CNXNS)); + assertEquals(Integer.valueOf(4), m.get(ZooKeeperServerConf.KEY_MIN_SESSION_TIMEOUT)); + assertEquals(Integer.valueOf(5), m.get(ZooKeeperServerConf.KEY_MAX_SESSION_TIMEOUT)); + assertEquals(Long.valueOf(6L), m.get(ZooKeeperServerConf.KEY_SERVER_ID)); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java new file mode 100644 index 00000000000..df1d0e65303 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java @@ -0,0 +1,406 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +/** + * Test stand-alone server. + * + */ +public class ZooKeeperServerMainTest extends ZKTestCase implements Watcher { + protected static final Logger LOG = + LoggerFactory.getLogger(ZooKeeperServerMainTest.class); + + private CountDownLatch clientConnected = new CountDownLatch(1); + + /** + * Verify the ability to start a standalone server instance. + */ + @Test + public void testStandalone() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT = PortAssignment.unique(); + + MainThread main = new MainThread(CLIENT_PORT, true, null); + main.start(); + + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT, + CONNECTION_TIMEOUT)); + + + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT, this); + + zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertEquals(new String(zk.getData("/foo", null, null)), "foobar"); + zk.close(); + + main.shutdown(); + main.join(); + main.deleteDirs(); + + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT)); + } + + /** + * Test verifies server should fail when data dir or data log dir doesn't + * exists. Sets "zookeeper.datadir.autocreate" to false. + */ + @Test(timeout = 30000) + public void testWithoutAutoCreateDataLogDir() throws Exception { + ClientBase.setupTestEnv(); + System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, "false"); + try { + final int CLIENT_PORT = PortAssignment.unique(); + + MainThread main = new MainThread(CLIENT_PORT, false, null); + String args[] = new String[1]; + args[0] = main.confFile.toString(); + main.start(); + + Assert.assertFalse("waiting for server being up", ClientBase + .waitForServerUp("127.0.0.1:" + CLIENT_PORT, + CONNECTION_TIMEOUT / 2)); + } finally { + // resets "zookeeper.datadir.autocreate" flag + System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, + FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE_DEFAULT); + } + } + + /** + * Test verifies the auto creation of data dir and data log dir. + * Sets "zookeeper.datadir.autocreate" to true. + */ + @Test(timeout = 30000) + public void testWithAutoCreateDataLogDir() throws Exception { + ClientBase.setupTestEnv(); + System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, "true"); + final int CLIENT_PORT = PortAssignment.unique(); + + MainThread main = new MainThread(CLIENT_PORT, false, null); + String args[] = new String[1]; + args[0] = main.confFile.toString(); + main.start(); + + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT, + CONNECTION_TIMEOUT)); + + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT, this); + + zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertEquals(new String(zk.getData("/foo", null, null)), + "foobar"); + zk.close(); + + main.shutdown(); + main.join(); + main.deleteDirs(); + + Assert.assertTrue("waiting for server down", ClientBase + .waitForServerDown("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT)); + } + + /** + * Test verifies that the server shouldn't allow minsessiontimeout > + * maxsessiontimeout + */ + @Test + public void testWithMinSessionTimeoutGreaterThanMaxSessionTimeout() + throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT = PortAssignment.unique(); + final int tickTime = 2000; + final int minSessionTimeout = 20 * tickTime + 1000; // min is higher + final int maxSessionTimeout = tickTime * 2 - 100; // max is lower + final String configs = "maxSessionTimeout=" + maxSessionTimeout + "\n" + + "minSessionTimeout=" + minSessionTimeout + "\n"; + MainThread main = new MainThread(CLIENT_PORT, false, configs); + String args[] = new String[1]; + args[0] = main.confFile.toString(); + try { + main.main.initializeAndRun(args); + Assert.fail("Must throw exception as " + + "minsessiontimeout > maxsessiontimeout"); + } catch (ConfigException iae) { + // expected + } + } + + /** + * Test verifies that the server is able to redefine if user configured only + * minSessionTimeout limit + */ + @Test + public void testWithOnlyMinSessionTimeout() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT = PortAssignment.unique(); + final int tickTime = 2000; + final int minSessionTimeout = tickTime * 2 - 100; + int maxSessionTimeout = 20 * tickTime; + final String configs = "minSessionTimeout=" + minSessionTimeout + "\n"; + MainThread main = new MainThread(CLIENT_PORT, false, configs); + main.start(); + + String HOSTPORT = "127.0.0.1:" + CLIENT_PORT; + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + // create session with min value + verifySessionTimeOut(minSessionTimeout, minSessionTimeout, HOSTPORT); + verifySessionTimeOut(minSessionTimeout - 2000, minSessionTimeout, + HOSTPORT); + // create session with max value + verifySessionTimeOut(maxSessionTimeout, maxSessionTimeout, HOSTPORT); + verifySessionTimeOut(maxSessionTimeout + 2000, maxSessionTimeout, + HOSTPORT); + main.shutdown(); + Assert.assertTrue("waiting for server down", ClientBase + .waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT)); + } + + /** + * Test verifies that the server is able to redefine the min/max session + * timeouts + */ + @Test + public void testMinMaxSessionTimeOut() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT = PortAssignment.unique(); + final int tickTime = 2000; + final int minSessionTimeout = tickTime * 2 - 100; + final int maxSessionTimeout = 20 * tickTime + 1000; + final String configs = "maxSessionTimeout=" + maxSessionTimeout + "\n" + + "minSessionTimeout=" + minSessionTimeout + "\n"; + MainThread main = new MainThread(CLIENT_PORT, false, configs); + main.start(); + + String HOSTPORT = "127.0.0.1:" + CLIENT_PORT; + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + // create session with min value + verifySessionTimeOut(minSessionTimeout, minSessionTimeout, HOSTPORT); + verifySessionTimeOut(minSessionTimeout - 2000, minSessionTimeout, + HOSTPORT); + // create session with max value + verifySessionTimeOut(maxSessionTimeout, maxSessionTimeout, HOSTPORT); + verifySessionTimeOut(maxSessionTimeout + 2000, maxSessionTimeout, + HOSTPORT); + main.shutdown(); + + Assert.assertTrue("waiting for server down", ClientBase + .waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT)); + } + + private void verifySessionTimeOut(int sessionTimeout, + int expectedSessionTimeout, String HOSTPORT) throws IOException, + KeeperException, InterruptedException { + clientConnected = new CountDownLatch(1); + ZooKeeper zk = new ZooKeeper(HOSTPORT, sessionTimeout, this); + Assert.assertTrue("Failed to establish zkclient connection!", + clientConnected.await(sessionTimeout, TimeUnit.MILLISECONDS)); + Assert.assertEquals("Not able to configure the sessionTimeout values", + expectedSessionTimeout, zk.getSessionTimeout()); + zk.close(); + } + + @Test + public void testJMXRegistrationWithNIO() throws Exception { + ClientBase.setupTestEnv(); + File tmpDir_1 = ClientBase.createTmpDir(); + ServerCnxnFactory server_1 = startServer(tmpDir_1); + File tmpDir_2 = ClientBase.createTmpDir(); + ServerCnxnFactory server_2 = startServer(tmpDir_2); + + server_1.shutdown(); + server_2.shutdown(); + + deleteFile(tmpDir_1); + deleteFile(tmpDir_2); + } + + @Test + public void testJMXRegistrationWithNetty() throws Exception { + String originalServerCnxnFactory = System + .getProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); + System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, + NettyServerCnxnFactory.class.getName()); + try { + ClientBase.setupTestEnv(); + File tmpDir_1 = ClientBase.createTmpDir(); + ServerCnxnFactory server_1 = startServer(tmpDir_1); + File tmpDir_2 = ClientBase.createTmpDir(); + ServerCnxnFactory server_2 = startServer(tmpDir_2); + + server_1.shutdown(); + server_2.shutdown(); + + deleteFile(tmpDir_1); + deleteFile(tmpDir_2); + } finally { + // setting back + if (originalServerCnxnFactory == null + || originalServerCnxnFactory.isEmpty()) { + System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); + } else { + System.setProperty( + ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, + originalServerCnxnFactory); + } + } + } + + private void deleteFile(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) + deleteFile(c); + } + if (!f.delete()) + // double check for the file existence + if (f.exists()) { + throw new IOException("Failed to delete file: " + f); + } + } + + private ServerCnxnFactory startServer(File tmpDir) throws IOException, + InterruptedException { + final int CLIENT_PORT = PortAssignment.unique(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1); + f.startup(zks); + Assert.assertNotNull("JMX initialization failed!", zks.jmxServerBean); + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT, + CONNECTION_TIMEOUT)); + return f; + } + + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.SyncConnected) { + clientConnected.countDown(); + } + } + + public static class MainThread extends Thread { + final File confFile; + final TestZKSMain main; + final File tmpDir; + + public MainThread(int clientPort, boolean preCreateDirs, String configs) + throws IOException { + super("Standalone server with clientPort:" + clientPort); + tmpDir = ClientBase.createTmpDir(); + confFile = new File(tmpDir, "zoo.cfg"); + + FileWriter fwriter = new FileWriter(confFile); + fwriter.write("tickTime=2000\n"); + fwriter.write("initLimit=10\n"); + fwriter.write("syncLimit=5\n"); + if (configs != null) { + fwriter.write(configs); + } + + File dataDir = new File(tmpDir, "data"); + String dir = dataDir.toString(); + String dirLog = dataDir.toString() + "_txnlog"; + if (preCreateDirs) { + if (!dataDir.mkdir()) { + throw new IOException("unable to mkdir " + dataDir); + } + dirLog = dataDir.toString(); + } + + dir = PathUtils.normalizeFileSystemPath(dir); + dirLog = PathUtils.normalizeFileSystemPath(dirLog); + fwriter.write("dataDir=" + dir + "\n"); + fwriter.write("dataLogDir=" + dirLog + "\n"); + fwriter.write("clientPort=" + clientPort + "\n"); + fwriter.flush(); + fwriter.close(); + + main = new TestZKSMain(); + } + + public void run() { + String args[] = new String[1]; + args[0] = confFile.toString(); + try { + main.initializeAndRun(args); + } catch (Exception e) { + // test will still fail even though we just log/ignore + LOG.error("unexpected exception in run", e); + } + } + + public void shutdown() throws IOException { + main.shutdown(); + } + + void deleteDirs() throws IOException { + delete(tmpDir); + } + + void delete(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) + delete(c); + } + if (!f.delete()) + // double check for the file existence + if (f.exists()) { + throw new IOException("Failed to delete file: " + f); + } + } + } + + public static class TestZKSMain extends ZooKeeperServerMain { + public void shutdown() { + super.shutdown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java new file mode 100644 index 00000000000..45f96df9819 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java @@ -0,0 +1,129 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.server.persistence.Util; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +public class ZooKeeperServerTest extends ZKTestCase { + @Test + public void testSortDataDirAscending() { + File[] files = new File[5]; + + files[0] = new File("foo.10027c6de"); + files[1] = new File("foo.10027c6df"); + files[2] = new File("bar.10027c6dd"); + files[3] = new File("foo.10027c6dc"); + files[4] = new File("foo.20027c6dc"); + + File[] orig = files.clone(); + + List filelist = Util.sortDataDir(files, "foo", true); + + Assert.assertEquals(orig[2], filelist.get(0)); + Assert.assertEquals(orig[3], filelist.get(1)); + Assert.assertEquals(orig[0], filelist.get(2)); + Assert.assertEquals(orig[1], filelist.get(3)); + Assert.assertEquals(orig[4], filelist.get(4)); + } + + @Test + public void testSortDataDirDescending() { + File[] files = new File[5]; + + files[0] = new File("foo.10027c6de"); + files[1] = new File("foo.10027c6df"); + files[2] = new File("bar.10027c6dd"); + files[3] = new File("foo.10027c6dc"); + files[4] = new File("foo.20027c6dc"); + + File[] orig = files.clone(); + + List filelist = Util.sortDataDir(files, "foo", false); + + Assert.assertEquals(orig[4], filelist.get(0)); + Assert.assertEquals(orig[1], filelist.get(1)); + Assert.assertEquals(orig[0], filelist.get(2)); + Assert.assertEquals(orig[3], filelist.get(3)); + Assert.assertEquals(orig[2], filelist.get(4)); + } + + @Test + public void testGetLogFiles() { + File[] files = new File[5]; + + files[0] = new File("log.10027c6de"); + files[1] = new File("log.10027c6df"); + files[2] = new File("snapshot.10027c6dd"); + files[3] = new File("log.10027c6dc"); + files[4] = new File("log.20027c6dc"); + + File[] orig = files.clone(); + + File[] filelist = + FileTxnLog.getLogFiles(files, + Long.parseLong("10027c6de", 16)); + + Assert.assertEquals(3, filelist.length); + Assert.assertEquals(orig[0], filelist[0]); + Assert.assertEquals(orig[1], filelist[1]); + Assert.assertEquals(orig[4], filelist[2]); + } + + @Test + public void testForceSyncDefaultEnabled() { + File file = new File("foo.10027c6de"); + FileTxnLog log = new FileTxnLog(file); + Assert.assertTrue(log.isForceSync()); + } + + @Test + public void testForceSyncDefaultDisabled() { + try { + File file = new File("foo.10027c6de"); + System.setProperty("zookeeper.forceSync", "no"); + FileTxnLog log = new FileTxnLog(file); + Assert.assertFalse(log.isForceSync()); + } finally { + //Reset back to default. + System.setProperty("zookeeper.forceSync", "yes"); + } + } + + @Test + public void testInvalidSnapshot() { + File f = null; + File tmpFileDir = null; + try { + tmpFileDir = ClientBase.createTmpDir(); + f = new File(tmpFileDir, "snapshot.0"); + if (!f.exists()) { + f.createNewFile(); + } + Assert.assertFalse("Snapshot file size is greater than 9 bytes", Util.isValidSnapshot(f)); + Assert.assertTrue("Can't delete file", f.delete()); + } catch (IOException e) { + } finally { + if (null != tmpFileDir) { + ClientBase.recursiveDelete(tmpFileDir); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java b/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java new file mode 100644 index 00000000000..7bd7fb1d85d --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ZooKeeperThreadTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.server; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Assert; +import org.junit.Test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class ZooKeeperThreadTest extends ZKTestCase { + private CountDownLatch runningLatch = new CountDownLatch(1); + + /** + * Test verifies uncaught exception handling of ZooKeeperThread + */ + @Test(timeout = 30000) + public void testUncaughtException() throws Exception { + MyThread t1 = new MyThread("Test-Thread"); + t1.start(); + Assert.assertTrue("Uncaught exception is not properly handled.", + runningLatch.await(10000, TimeUnit.MILLISECONDS)); + + runningLatch = new CountDownLatch(1); + MyCriticalThread t2 = new MyCriticalThread("Test-Critical-Thread"); + t2.start(); + Assert.assertTrue("Uncaught exception is not properly handled.", + runningLatch.await(10000, TimeUnit.MILLISECONDS)); + } + + public class MyThread extends ZooKeeperThread { + + public MyThread(String threadName) { + super(threadName); + } + + public void run() { + throw new Error(); + } + + @Override + protected void handleException(String thName, Throwable e) { + runningLatch.countDown(); + } + } + + public class MyCriticalThread extends ZooKeeperCriticalThread { + + public MyCriticalThread(String threadName) { + super(threadName, new ZooKeeperServerListener() { + + @Override + public void notifyStopping(String threadName, int erroCode) { + + } + }); + } + + public void run() { + throw new Error(); + } + + @Override + protected void handleException(String thName, Throwable e) { + runningLatch.countDown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java b/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java new file mode 100644 index 00000000000..1a8fb10dbd8 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java @@ -0,0 +1,441 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server; + + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.ConnectionLossException; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.apache.zookeeper.test.ClientTest; +import org.apache.zookeeper.test.QuorumUtil; +import org.apache.zookeeper.test.QuorumUtil.PeerStruct; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Verify ZOOKEEPER-1277 - ensure that we handle epoch rollover correctly. + */ +public class ZxidRolloverTest extends ZKTestCase { + private static final Logger LOG = LoggerFactory.getLogger(ZxidRolloverTest.class); + + private QuorumUtil qu; + private ZooKeeperServer zksLeader; + private ZooKeeper[] zkClients = new ZooKeeper[3]; + private CountdownWatcher[] zkClientWatchers = new CountdownWatcher[3]; + private int idxLeader; + private int idxFollower; + + private ZooKeeper getClient(int idx) { + return zkClients[idx - 1]; + } + + @Before + public void setUp() throws Exception { + System.setProperty("zookeeper.admin.enableServer", "false"); + + // set the snap count to something low so that we force log rollover + // and verify that is working as part of the epoch rollover. + SyncRequestProcessor.setSnapCount(7); + + qu = new QuorumUtil(1); + startAll(); + + for (int i = 0; i < zkClients.length; i++) { + zkClientWatchers[i] = new CountdownWatcher(); + PeerStruct peer = qu.getPeer(i + 1); + zkClients[i] = new ZooKeeper( + "127.0.0.1:" + peer.clientPort, + ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]); + } + waitForClientsConnected(); + } + + private void waitForClientsConnected() throws Exception { + for (int i = 0; i < zkClients.length; i++) { + zkClientWatchers[i].waitForConnected(ClientTest.CONNECTION_TIMEOUT); + zkClientWatchers[i].reset(); + } + } + + /** + * Ensure all clients are able to talk to the service. + */ + private void checkClientsConnected() throws Exception { + for (int i = 0; i < zkClients.length; i++) { + checkClientConnected(i + 1); + } + } + + /** + * Ensure the client is able to talk to the server. + * + * @param idx the idx of the server the client is talking to + */ + private void checkClientConnected(int idx) throws Exception { + ZooKeeper zk = getClient(idx); + if (zk == null) { + return; + } + try { + Assert.assertNull(zk.exists("/foofoofoo-connected", false)); + } catch (ConnectionLossException e) { + // second chance... + // in some cases, leader change in particular, the timing is + // very tricky to get right in order to assure that the client has + // disconnected and reconnected. In some cases the client will + // disconnect, then attempt to reconnect before the server is + // back, in which case we'll see another connloss on the operation + // in the try, this catches that case and waits for the server + // to come back + PeerStruct peer = qu.getPeer(idx); + Assert.assertTrue("Waiting for server down", ClientBase.waitForServerUp( + "127.0.0.1:" + peer.clientPort, ClientBase.CONNECTION_TIMEOUT)); + + Assert.assertNull(zk.exists("/foofoofoo-connected", false)); + } + } + + /** + * Ensure all clients are disconnected from the service. + */ + private void checkClientsDisconnected() throws Exception { + for (int i = 0; i < zkClients.length; i++) { + checkClientDisconnected(i + 1); + } + } + + /** + * Ensure the client is able to talk to the server + * + * @param idx the idx of the server the client is talking to + */ + private void checkClientDisconnected(int idx) throws Exception { + ZooKeeper zk = getClient(idx); + if (zk == null) { + return; + } + try { + Assert.assertNull(zk.exists("/foofoofoo-disconnected", false)); + Assert.fail("expected client to be disconnected"); + } catch (KeeperException e) { + // success + } + } + + private void startAll() throws Exception { + qu.startAll(); + checkLeader(); + // all clients should be connected + checkClientsConnected(); + } + + private void start(int idx) throws Exception { + qu.start(idx); + for (String hp : qu.getConnString().split(",")) { + Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(hp, + ClientTest.CONNECTION_TIMEOUT)); + } + + checkLeader(); + // all clients should be connected + checkClientsConnected(); + } + + private void checkLeader() { + idxLeader = 1; + while (qu.getPeer(idxLeader).peer.leader == null) { + idxLeader++; + } + idxFollower = (idxLeader == 1 ? 2 : 1); + + zksLeader = qu.getPeer(idxLeader).peer.getActiveServer(); + } + + private void shutdownAll() throws Exception { + qu.shutdownAll(); + // all clients should be disconnected + checkClientsDisconnected(); + } + + private void shutdown(int idx) throws Exception { + qu.shutdown(idx); + + // leader will shutdown, remaining followers will elect a new leader + PeerStruct peer = qu.getPeer(idx); + Assert.assertTrue("Waiting for server down", ClientBase.waitForServerDown( + "127.0.0.1:" + peer.clientPort, ClientBase.CONNECTION_TIMEOUT)); + + // if idx is the the leader then everyone will get disconnected, + // otherwise if idx is a follower then just that client will get + // disconnected + if (idx == idxLeader) { + checkClientDisconnected(idx); + try { + checkClientsDisconnected(); + } catch (AssertionError e) { + // the clients may or may not have already reconnected + // to the recovered cluster, force a check, but ignore + } + } else { + checkClientDisconnected(idx); + } + } + + /** Reset the next zxid to be near epoch end */ + private void adjustEpochNearEnd() { + zksLeader.setZxid((zksLeader.getZxid() & 0xffffffff00000000L) | 0xfffffffcL); + } + + @After + public void tearDown() throws Exception { + LOG.info("tearDown starting"); + for (int i = 0; i < zkClients.length; i++) { + zkClients[i].close(); + } + qu.shutdownAll(); + } + + /** + * Create the znodes, this may fail if the lower 32 roll over, if so + * wait for the clients to be re-connected after the re-election + */ + private int createNodes(ZooKeeper zk, int start, int count) throws Exception { + LOG.info("Creating nodes {} thru {}", start, (start + count)); + int j = 0; + try { + for (int i = start; i < start + count; i++) { + zk.create("/foo" + i, new byte[0], Ids.READ_ACL_UNSAFE, + CreateMode.EPHEMERAL); + j++; + } + } catch (ConnectionLossException e) { + // this is ok - the leader has dropped leadership + waitForClientsConnected(); + } + return j; + } + + /** + * Verify the expected znodes were created and that the last znode, which + * caused the roll-over, did not. + */ + private void checkNodes(ZooKeeper zk, int start, int count) throws Exception { + LOG.info("Validating nodes {} thru {}", start, (start + count)); + for (int i = start; i < start + count; i++) { + Assert.assertNotNull(zk.exists("/foo" + i, false)); + LOG.error("Exists zxid:{}", Long.toHexString(zk.exists("/foo" + i, false).getCzxid())); + } + Assert.assertNull(zk.exists("/foo" + (start + count), false)); + } + + /** + * Prior to the fix this test would hang for a while, then fail with + * connection loss. + */ + @Test + public void testSimpleRolloverFollower() throws Exception { + adjustEpochNearEnd(); + + ZooKeeper zk = getClient((idxLeader == 1 ? 2 : 1)); + int countCreated = createNodes(zk, 0, 10); + + checkNodes(zk, 0, countCreated); + } + + /** + * Similar to testSimpleRollover, but ensure the cluster comes back, + * has the right data, and is able to serve new requests. + */ + @Test + public void testRolloverThenRestart() throws Exception { + ZooKeeper zk = getClient(idxFollower); + + int countCreated = createNodes(zk, 0, 10); + + adjustEpochNearEnd(); + + countCreated += createNodes(zk, countCreated, 10); + + shutdownAll(); + startAll(); + zk = getClient(idxLeader); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + adjustEpochNearEnd(); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + shutdownAll(); + startAll(); + zk = getClient(idxFollower); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + shutdownAll(); + startAll(); + zk = getClient(idxLeader); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + // sanity check + Assert.assertTrue(countCreated > 0); + Assert.assertTrue(countCreated < 60); + } + + /** + * Similar to testRolloverThenRestart, but ensure a follower comes back, + * has the right data, and is able to serve new requests. + */ + @Test + public void testRolloverThenFollowerRestart() throws Exception { + ZooKeeper zk = getClient(idxFollower); + + int countCreated = createNodes(zk, 0, 10); + + adjustEpochNearEnd(); + + countCreated += createNodes(zk, countCreated, 10); + + shutdown(idxFollower); + start(idxFollower); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + adjustEpochNearEnd(); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + shutdown(idxFollower); + start(idxFollower); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + shutdown(idxFollower); + start(idxFollower); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + // sanity check + Assert.assertTrue(countCreated > 0); + Assert.assertTrue(countCreated < 60); + } + + /** + * Similar to testRolloverThenRestart, but ensure leadership can change, + * comes back, has the right data, and is able to serve new requests. + */ + @Test + public void testRolloverThenLeaderRestart() throws Exception { + ZooKeeper zk = getClient(idxLeader); + + int countCreated = createNodes(zk, 0, 10); + + adjustEpochNearEnd(); + + checkNodes(zk, 0, countCreated); + + shutdown(idxLeader); + start(idxLeader); + zk = getClient(idxLeader); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + adjustEpochNearEnd(); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + shutdown(idxLeader); + start(idxLeader); + zk = getClient(idxLeader); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + shutdown(idxLeader); + start(idxLeader); + zk = getClient(idxFollower); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + // sanity check + Assert.assertTrue(countCreated > 0); + Assert.assertTrue(countCreated < 50); + } + + /** + * Similar to testRolloverThenRestart, but ensure we can survive multiple + * epoch rollovers between restarts. + */ + @Test + public void testMultipleRollover() throws Exception { + ZooKeeper zk = getClient(idxFollower); + + int countCreated = createNodes(zk, 0, 10); + + adjustEpochNearEnd(); + + countCreated += createNodes(zk, countCreated, 10); + + adjustEpochNearEnd(); + + countCreated += createNodes(zk, countCreated, 10); + + adjustEpochNearEnd(); + + countCreated += createNodes(zk, countCreated, 10); + + adjustEpochNearEnd(); + + countCreated += createNodes(zk, countCreated, 10); + + shutdownAll(); + startAll(); + zk = getClient(idxFollower); + + adjustEpochNearEnd(); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + shutdown(idxLeader); + start(idxLeader); + zk = getClient(idxFollower); + + checkNodes(zk, 0, countCreated); + countCreated += createNodes(zk, countCreated, 10); + + // sanity check + Assert.assertTrue(countCreated > 0); + Assert.assertTrue(countCreated < 70); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/admin/CommandResponseTest.java b/src/java/test/org/apache/zookeeper/server/admin/CommandResponseTest.java new file mode 100644 index 00000000000..b9af98a1b57 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/admin/CommandResponseTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class CommandResponseTest extends ZKTestCase { + private CommandResponse r; + + @Before + public void setUp() throws Exception { + r = new CommandResponse("makemeasandwich", "makeityourself"); + } + + @Test + public void testGetters() { + assertEquals("makemeasandwich", r.getCommand()); + assertEquals("makeityourself", r.getError()); + } + + @Test + public void testMap() { + r.put("missing", "sudo"); + Map m = new HashMap(); + m.put("origin", "xkcd"); + m.put("url", "http://xkcd.com/149/"); + r.putAll(m); + + Map rmap = r.toMap(); + assertEquals(5, rmap.size()); + assertEquals("makemeasandwich", rmap.get(CommandResponse.KEY_COMMAND)); + assertEquals("makeityourself", rmap.get(CommandResponse.KEY_ERROR)); + assertEquals("sudo", rmap.get("missing")); + assertEquals("xkcd", rmap.get("origin")); + assertEquals("http://xkcd.com/149/", rmap.get("url")); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/admin/CommandsTest.java b/src/java/test/org/apache/zookeeper/server/admin/CommandsTest.java new file mode 100644 index 00000000000..05116b5c357 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/admin/CommandsTest.java @@ -0,0 +1,230 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.server.ServerStats; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class CommandsTest extends ClientBase { + /** + * Checks that running a given Command returns the expected Map. Asserts + * that all specified keys are present with values of the specified types + * and that there are no extra entries. + * + * @param cmdName + * - the primary name of the command + * @param kwargs + * - keyword arguments to the command + * @param keys + * - the keys that are expected in the returned Map + * @param types + * - the classes of the values in the returned Map. types[i] is + * the type of the value for keys[i]. + * @throws IOException + * @throws InterruptedException + */ + public void testCommand(String cmdName, Map kwargs, Field... fields) + throws IOException, InterruptedException { + ZooKeeperServer zks = serverFactory.getZooKeeperServer(); + Map result = Commands.runCommand(cmdName, zks, kwargs).toMap(); + + assertTrue(result.containsKey("command")); + // This is only true because we're setting cmdName to the primary name + assertEquals(cmdName, result.remove("command")); + assertTrue(result.containsKey("error")); + assertNull("error: " + result.get("error"), result.remove("error")); + + for (Field field : fields) { + String k = field.key; + assertTrue("Result from command " + cmdName + " missing field \"" + k + "\"" + + "\n" + result, + result.containsKey(k)); + Class t = field.type; + Object v = result.remove(k); + assertTrue("\"" + k + "\" field from command " + cmdName + " should be of type " + t + + ", is actually of type " + v.getClass(), + t.isAssignableFrom(v.getClass())); + } + + assertTrue("Result from command " + cmdName + " contains extra fields: " + result, + result.isEmpty()); + } + + public void testCommand(String cmdName, Field... fields) + throws IOException, InterruptedException { + testCommand(cmdName, new HashMap(), fields); + } + + @Test + public void testConfiguration() throws IOException, InterruptedException { + testCommand("configuration", + new Field("client_port", Integer.class), + new Field("data_dir", String.class), + new Field("data_log_dir", String.class), + new Field("tick_time", Integer.class), + new Field("max_client_cnxns", Integer.class), + new Field("min_session_timeout", Integer.class), + new Field("max_session_timeout", Integer.class), + new Field("server_id", Long.class)); + } + + @Test + public void testConnections() throws IOException, InterruptedException { + testCommand("connections", + new Field("connections", Iterable.class)); + } + + @Test + public void testConnectionStatReset() throws IOException, InterruptedException { + testCommand("connection_stat_reset"); + } + + @Test + public void testDump() throws IOException, InterruptedException { + testCommand("dump", + new Field("expiry_time_to_session_ids", Map.class), + new Field("session_id_to_ephemeral_paths", Map.class)); + } + + @Test + public void testEnvironment() throws IOException, InterruptedException { + testCommand("environment", + new Field("zookeeper.version", String.class), + new Field("host.name", String.class), + new Field("java.version", String.class), + new Field("java.vendor", String.class), + new Field("java.home", String.class), + new Field("java.class.path", String.class), + new Field("java.library.path", String.class), + new Field("java.io.tmpdir", String.class), + new Field("java.compiler", String.class), + new Field("os.name", String.class), + new Field("os.arch", String.class), + new Field("os.version", String.class), + new Field("user.name", String.class), + new Field("user.home", String.class), + new Field("user.dir", String.class), + new Field("os.memory.free", String.class), + new Field("os.memory.max", String.class), + new Field("os.memory.total", String.class)); + } + + @Test + public void testGetTraceMask() throws IOException, InterruptedException { + testCommand("get_trace_mask", + new Field("tracemask", Long.class)); + } + + @Test + public void testIsReadOnly() throws IOException, InterruptedException { + testCommand("is_read_only", + new Field("read_only", Boolean.class)); + } + + @Test + public void testMonitor() throws IOException, InterruptedException { + testCommand("monitor", + new Field("version", String.class), + new Field("avg_latency", Long.class), + new Field("max_latency", Long.class), + new Field("min_latency", Long.class), + new Field("packets_received", Long.class), + new Field("packets_sent", Long.class), + new Field("num_alive_connections", Integer.class), + new Field("outstanding_requests", Long.class), + new Field("server_state", String.class), + new Field("znode_count", Integer.class), + new Field("watch_count", Integer.class), + new Field("ephemerals_count", Integer.class), + new Field("approximate_data_size", Long.class), + new Field("open_file_descriptor_count", Long.class), + new Field("max_file_descriptor_count", Long.class)); + } + + @Test + public void testRuok() throws IOException, InterruptedException { + testCommand("ruok"); + } + + @Test + public void testServerStats() throws IOException, InterruptedException { + testCommand("server_stats", + new Field("version", String.class), + new Field("read_only", Boolean.class), + new Field("server_stats", ServerStats.class), + new Field("node_count", Integer.class)); + } + + @Test + public void testSetTraceMask() throws IOException, InterruptedException { + Map kwargs = new HashMap(); + kwargs.put("traceMask", "1"); + testCommand("set_trace_mask", kwargs, + new Field("tracemask", Long.class)); + } + + @Test + public void testStat() throws IOException, InterruptedException { + testCommand("stats", + new Field("version", String.class), + new Field("read_only", Boolean.class), + new Field("server_stats", ServerStats.class), + new Field("node_count", Integer.class), + new Field("connections", Iterable.class)); + } + + @Test + public void testStatReset() throws IOException, InterruptedException { + testCommand("stat_reset"); + } + + @Test + public void testWatches() throws IOException, InterruptedException { + testCommand("watches", + new Field("session_id_to_watched_paths", Map.class)); + } + + @Test + public void testWatchesByPath() throws IOException, InterruptedException { + testCommand("watches_by_path", + new Field("path_to_session_ids", Map.class)); + } + + @Test + public void testWatchSummary() throws IOException, InterruptedException { + testCommand("watch_summary", + new Field("num_connections", Integer.class), + new Field("num_paths", Integer.class), + new Field("num_total_watches", Integer.class)); + } + + private static class Field { + String key; + Class type; + + Field(String key, Class type) { + this.key = key; + this.type = type; + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/admin/JettyAdminServerTest.java b/src/java/test/org/apache/zookeeper/server/admin/JettyAdminServerTest.java new file mode 100644 index 00000000000..17d4127344a --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/admin/JettyAdminServerTest.java @@ -0,0 +1,156 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.admin; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.ZooKeeperServerMainTest; +import org.apache.zookeeper.server.admin.AdminServer.AdminServerException; +import org.apache.zookeeper.server.quorum.QuorumPeerTestBase; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; + +public class JettyAdminServerTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(JettyAdminServerTest.class); + + private static final String URL_FORMAT = "http://localhost:%d/commands"; + private static final int jettyAdminPort = PortAssignment.unique(); + + @Before + public void enableServer() { + // Override setting in ZKTestCase + System.setProperty("zookeeper.admin.enableServer", "true"); + System.setProperty("zookeeper.admin.serverPort", "" + jettyAdminPort); + } + + /** + * Tests that we can start and query a JettyAdminServer. + */ + @Test + public void testJettyAdminServer() throws AdminServerException, IOException { + JettyAdminServer server = new JettyAdminServer(); + ; + try { + server.start(); + queryAdminServer(jettyAdminPort); + } finally { + server.shutdown(); + } + } + + /** + * Starts a standalone server and tests that we can query its AdminServer. + */ + @Test + public void testStandalone() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT = PortAssignment.unique(); + + ZooKeeperServerMainTest.MainThread main = new ZooKeeperServerMainTest.MainThread(CLIENT_PORT, false, null); + main.start(); + + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT)); + + queryAdminServer(jettyAdminPort); + + main.shutdown(); + + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT, + ClientBase.CONNECTION_TIMEOUT)); + } + + /** + * Starts a quorum of two servers and tests that we can query both AdminServers. + */ + @Test + public void testQuorum() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + + final int ADMIN_SERVER_PORT1 = PortAssignment.unique(); + final int ADMIN_SERVER_PORT2 = PortAssignment.unique(); + + String quorumCfgSection = String.format + ("server.1=127.0.0.1:%d:%d;%d\nserver.2=127.0.0.1:%d:%d;%d", + PortAssignment.unique(), PortAssignment.unique(), CLIENT_PORT_QP1, + PortAssignment.unique(), PortAssignment.unique(), CLIENT_PORT_QP2 + ); + QuorumPeerTestBase.MainThread q1 = new QuorumPeerTestBase.MainThread( + 1, CLIENT_PORT_QP1, ADMIN_SERVER_PORT1, quorumCfgSection, null); + q1.start(); + + // Since JettyAdminServer reads a system property to determine its port, + // make sure it initializes itself before setting the system property + // again with the second port number + Thread.sleep(500); + + QuorumPeerTestBase.MainThread q2 = new QuorumPeerTestBase.MainThread( + 2, CLIENT_PORT_QP2, ADMIN_SERVER_PORT2, quorumCfgSection, null); + q2.start(); + + Thread.sleep(500); + + Assert.assertTrue("waiting for server 1 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT)); + + queryAdminServer(ADMIN_SERVER_PORT1); + queryAdminServer(ADMIN_SERVER_PORT2); + + q1.shutdown(); + q2.shutdown(); + + Assert.assertTrue("waiting for server 1 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT)); + } + + /** + * Check that we can load the commands page of an AdminServer running at + * localhost:port. (Note that this should work even if no zk server is set.) + */ + private void queryAdminServer(int port) throws MalformedURLException, IOException { + queryAdminServer(String.format(URL_FORMAT, port)); + } + + /** + * Check that loading urlStr results in a non-zero length response. + */ + private void queryAdminServer(String urlStr) throws MalformedURLException, IOException { + URL url = new URL(urlStr); + BufferedReader dis = new BufferedReader(new InputStreamReader((url.openStream()))); + String line = dis.readLine(); + Assert.assertTrue(line.length() > 0); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorConcurrencyTest.java b/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorConcurrencyTest.java new file mode 100644 index 00000000000..265a10adf5f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorConcurrencyTest.java @@ -0,0 +1,136 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.proto.GetDataRequest; +import org.apache.zookeeper.proto.SyncRequest; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.RequestProcessor.RequestProcessorException; +import org.apache.zookeeper.server.WorkerService; +import org.apache.zookeeper.server.ZooKeeperServerListener; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; + +public class CommitProcessorConcurrencyTest extends ZKTestCase { + protected static final Logger LOG = + LoggerFactory.getLogger(CommitProcessorConcurrencyTest.class); + + Boolean executedFlag = false; + MockCommitProcessor processor; + + @Before + public void setUp() throws Exception { + processor = new MockCommitProcessor(); + } + + @After + public void tearDown() throws Exception { + processor.shutdown(); + } + + /* + * We populate the necessary data structures in the CommitProcessor + * instance and run processCommitted + */ + @Test + public void raceTest() + throws Exception { + + ByteArrayOutputStream boas = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas); + GetDataRequest getReq = new GetDataRequest("/testrace", false); + getReq.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray()); + Request readReq = new Request(null, 0x0, 0, OpCode.getData, + bb, new ArrayList()); + + boas.reset(); + SyncRequest syncReq = new SyncRequest("/testrace"); + syncReq.serialize(boa, "request"); + bb = ByteBuffer.wrap(boas.toByteArray()); + Request writeReq = new Request(null, 0x0, 0, OpCode.sync, + bb, new ArrayList()); + + processor.addToCommittedRequests(writeReq); + processor.addToQueuedRequests(readReq); + processor.addToQueuedRequests(writeReq); + + processor.testStart(); + processor.testProcessCommitted(); + Assert.assertFalse("Next request processor executed", executedFlag); + } + + class MockCommitProcessor extends CommitProcessor { + + MockCommitProcessor() { + super( + new RequestProcessor() { + public void processRequest(Request request) + throws RequestProcessorException { + executedFlag = true; + } + + public void shutdown() { + } + }, + "0", + false, new ZooKeeperServerListener() { + + @Override + public void notifyStopping(String errMsg, int exitCode) { + + } + }); + } + + public void testStart() { + this.stopped = false; + this.workerPool = new WorkerService( + "CommitProcWork", 1, true); + } + + public void addToCommittedRequests(Request req) { + this.committedRequests.add(req); + } + + public void addToNextPending(Request req) { + this.nextPending.set(req); + } + + public void addToQueuedRequests(Request req) { + //this.numRequestsProcessing.incrementAndGet(); + this.queuedRequests.add(req); + } + + public void testProcessCommitted() { + this.processCommitted(); + } + + @Override + public void shutdown() { + this.workerPool.stop(); + } + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java b/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java new file mode 100644 index 00000000000..8cce8d26cb5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java @@ -0,0 +1,414 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.proto.GetDataRequest; +import org.apache.zookeeper.server.FinalRequestProcessor; +import org.apache.zookeeper.server.PrepRequestProcessor; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.RequestProcessor; +import org.apache.zookeeper.server.SessionTracker; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.quorum.CommitProcessor; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +/** + * The following are invariant regardless of the particular implementation + * of the CommitProcessor, and are tested for: + * + * 1. For each session, requests are processed and the client sees its + * responses in order. + * 2. Write requests are processed in zxid order across all sessions. + * + * The following are also tested for here, but are specific to this + * particular implementation. The underlying issue is that watches can be + * reset while reading the data. For reads/writes on two different sessions + * on different nodes, or with reads that do not set watches, the reads can + * happen in any order relative to the writes. For a read in one session that + * resets a watch that is triggered by a write on another session, however, + * we need to ensure that there is no race condition + * + * 3. The pipeline needs to be drained before a write request can enter. + * 4. No in-flight write requests while processing a read request. + */ +public class CommitProcessorTest extends ZKTestCase { + protected static final Logger LOG = + LoggerFactory.getLogger(CommitProcessorTest.class); + TestZooKeeperServer zks; + File tmpDir; + ArrayList testClients = + new ArrayList(); + volatile boolean fail = false; + private AtomicInteger processedReadRequests = new AtomicInteger(0); + private AtomicInteger processedWriteRequests = new AtomicInteger(0); + + public void setUp(int numCommitThreads, int numClientThreads) + throws Exception { + System.setProperty( + CommitProcessor.ZOOKEEPER_COMMIT_PROC_NUM_WORKER_THREADS, + Integer.toString(numCommitThreads)); + System.setProperty("zookeeper.admin.enableServer", "false"); + tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + zks = new TestZooKeeperServer(tmpDir, tmpDir, 4000); + zks.startup(); + for (int i = 0; i < numClientThreads; ++i) { + TestClientThread client = new TestClientThread(); + testClients.add(client); + client.start(); + } + } + + @After + public void tearDown() throws Exception { + LOG.info("tearDown starting"); + for (TestClientThread client : testClients) { + client.interrupt(); + client.join(); + } + zks.shutdown(); + + if (tmpDir != null) { + Assert.assertTrue("delete " + tmpDir.toString(), + ClientBase.recursiveDelete(tmpDir)); + } + } + + @Test + public void testNoCommitWorkers() throws Exception { + setUp(0, 10); + synchronized (this) { + wait(5000); + } + checkProcessedRequest(); + Assert.assertFalse(fail); + } + + @Test + public void testOneCommitWorker() throws Exception { + setUp(1, 10); + synchronized (this) { + wait(5000); + } + checkProcessedRequest(); + Assert.assertFalse(fail); + } + + @Test + public void testManyCommitWorkers() throws Exception { + setUp(10, 10); + synchronized (this) { + wait(5000); + } + checkProcessedRequest(); + Assert.assertFalse(fail); + + } + + private void checkProcessedRequest() { + Assert.assertTrue("No read requests processed", + processedReadRequests.get() > 0); + Assert.assertTrue("No write requests processed", + processedWriteRequests.get() > 0); + } + + synchronized private void failTest(String reason) { + fail = true; + notifyAll(); + Assert.fail(reason); + } + + private class TestClientThread extends Thread { + long sessionId; + int cxid; + int nodeId; + + public TestClientThread() { + sessionId = zks.getSessionTracker().createSession(5000); + } + + public void sendWriteRequest() throws Exception { + ByteArrayOutputStream boas = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas); + CreateRequest createReq = new CreateRequest( + "/session" + Long.toHexString(sessionId) + "-" + (++nodeId), + new byte[0], Ids.OPEN_ACL_UNSAFE, 1); + createReq.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray()); + Request req = new Request(null, sessionId, ++cxid, OpCode.create, + bb, new ArrayList()); + zks.firstProcessor.processRequest(req); + } + + public void sendReadRequest() throws Exception { + ByteArrayOutputStream boas = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas); + GetDataRequest getDataRequest = new GetDataRequest( + "/session" + Long.toHexString(sessionId) + "-" + nodeId, false); + getDataRequest.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray()); + Request req = new Request(null, sessionId, ++cxid, OpCode.getData, + bb, new ArrayList()); + zks.firstProcessor.processRequest(req); + } + + public void run() { + Random rand = new Random(Thread.currentThread().getId()); + try { + sendWriteRequest(); + for (int i = 0; i < 1000; ++i) { + // Do 25% write / 75% read request mix + if (rand.nextInt(100) < 25) { + sendWriteRequest(); + } else { + sendReadRequest(); + } + } + } catch (Exception e) { + LOG.error("Uncaught exception in test: ", e); + } + } + } + + private class TestZooKeeperServer extends ZooKeeperServer { + PrepRequestProcessor firstProcessor; + CommitProcessor commitProcessor; + + public TestZooKeeperServer(File snapDir, File logDir, int tickTime) + throws IOException { + super(snapDir, logDir, tickTime); + } + + public SessionTracker getSessionTracker() { + return sessionTracker; + } + + // Leader mock: Prep -> MockProposal -> Commit -> validate -> Final + // Have side thread call commitProc.commit() + @Override + protected void setupRequestProcessors() { + RequestProcessor finalProcessor = new FinalRequestProcessor(zks); + // ValidateProcessor is set up in a similar fashion to ToBeApplied + // processor, so it can do pre/post validating of requests + ValidateProcessor validateProcessor = + new ValidateProcessor(finalProcessor); + commitProcessor = new CommitProcessor(validateProcessor, "1", true, + getZooKeeperServerListener()); + validateProcessor.setCommitProcessor(commitProcessor); + commitProcessor.start(); + MockProposalRequestProcessor proposalProcessor = + new MockProposalRequestProcessor(commitProcessor); + proposalProcessor.start(); + firstProcessor = new PrepRequestProcessor(zks, proposalProcessor); + firstProcessor.start(); + } + } + + private class MockProposalRequestProcessor extends Thread + implements RequestProcessor { + private final CommitProcessor commitProcessor; + private final LinkedBlockingQueue proposals = + new LinkedBlockingQueue(); + + public MockProposalRequestProcessor(CommitProcessor commitProcessor) { + this.commitProcessor = commitProcessor; + } + + @Override + public void run() { + Random rand = new Random(Thread.currentThread().getId()); + try { + while (true) { + Request request = proposals.take(); + Thread.sleep(10 + rand.nextInt(190)); + commitProcessor.commit(request); + } + } catch (InterruptedException e) { + // ignore + } + } + + @Override + public void processRequest(Request request) + throws RequestProcessorException { + commitProcessor.processRequest(request); + if (request.getHdr() != null) { + // fake propose request + proposals.add(request); + } + } + + @Override + public void shutdown() { + // TODO Auto-generated method stub + + } + } + + private class ValidateProcessor implements RequestProcessor { + Random rand = new Random(Thread.currentThread().getId()); + RequestProcessor nextProcessor; + CommitProcessor commitProcessor; + AtomicLong expectedZxid = new AtomicLong(1); + ConcurrentHashMap cxidMap = + new ConcurrentHashMap(); + + AtomicInteger outstandingReadRequests = new AtomicInteger(0); + AtomicInteger outstandingWriteRequests = new AtomicInteger(0); + + public ValidateProcessor(RequestProcessor nextProcessor) { + this.nextProcessor = nextProcessor; + } + + public void setCommitProcessor(CommitProcessor commitProcessor) { + this.commitProcessor = commitProcessor; + } + + + @Override + public void processRequest(Request request) + throws RequestProcessorException { + boolean isWriteRequest = commitProcessor.needCommit(request); + if (isWriteRequest) { + outstandingWriteRequests.incrementAndGet(); + validateWriteRequestVariant(request); + LOG.debug("Starting write request zxid=" + request.zxid); + } else { + LOG.debug("Starting read request cxid=" + + request.cxid + " for session 0x" + + Long.toHexString(request.sessionId)); + outstandingReadRequests.incrementAndGet(); + validateReadRequestVariant(request); + } + + // Insert random delay to test thread race conditions + try { + Thread.sleep(10 + rand.nextInt(290)); + } catch (InterruptedException e) { + // ignore + } + nextProcessor.processRequest(request); + + /* + * The commit workers will have to execute this line before they + * wake up the commit processor. So this value is up-to-date when + * variant check is performed + */ + if (isWriteRequest) { + outstandingWriteRequests.decrementAndGet(); + LOG.debug("Done write request zxid=" + request.zxid); + processedWriteRequests.incrementAndGet(); + } else { + outstandingReadRequests.decrementAndGet(); + LOG.debug("Done read request cxid=" + + request.cxid + " for session 0x" + + Long.toHexString(request.sessionId)); + processedReadRequests.incrementAndGet(); + } + validateRequest(request); + } + + /** + * Validate that this is the only request in the pipeline + */ + private void validateWriteRequestVariant(Request request) { + long zxid = request.getHdr().getZxid(); + int readRequests = outstandingReadRequests.get(); + if (readRequests != 0) { + failTest("There are " + readRequests + " outstanding" + + " read requests while issuing a write request zxid=" + + zxid); + } + int writeRequests = outstandingWriteRequests.get(); + if (writeRequests > 1) { + failTest("There are " + writeRequests + " outstanding" + + " write requests while issuing a write request zxid=" + + zxid + " (expected one)"); + } + } + + /** + * Validate that no write request is in the pipeline while working + * on a read request + */ + private void validateReadRequestVariant(Request request) { + int writeRequests = outstandingWriteRequests.get(); + if (writeRequests != 0) { + failTest("There are " + writeRequests + " outstanding" + + " write requests while issuing a read request cxid=" + + request.cxid + " for session 0x" + + Long.toHexString(request.sessionId)); + } + } + + private void validateRequest(Request request) { + LOG.info("Got request " + request); + + // Zxids should always be in order for write requests + if (request.getHdr() != null) { + long zxid = request.getHdr().getZxid(); + if (!expectedZxid.compareAndSet(zxid, zxid + 1)) { + failTest("Write request, expected_zxid=" + + expectedZxid.get() + "; req_zxid=" + zxid); + } + } + + // Each session should see its cxids in order + AtomicInteger sessionCxid = cxidMap.get(request.sessionId); + if (sessionCxid == null) { + sessionCxid = new AtomicInteger(request.cxid + 1); + AtomicInteger existingSessionCxid = + cxidMap.putIfAbsent(request.sessionId, sessionCxid); + if (existingSessionCxid != null) { + failTest("Race condition adding cxid=" + request.cxid + + " for session 0x" + + Long.toHexString(request.sessionId) + + " with other_cxid=" + existingSessionCxid.get()); + } + } else { + if (!sessionCxid.compareAndSet( + request.cxid, request.cxid + 1)) { + failTest("Expected_cxid=" + sessionCxid.get() + + "; req_cxid=" + request.cxid); + } + } + } + + @Override + public void shutdown() { + // TODO Auto-generated method stub + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/FLEBackwardElectionRoundTest.java b/src/java/test/org/apache/zookeeper/server/quorum/FLEBackwardElectionRoundTest.java new file mode 100644 index 00000000000..ad2e9da6b70 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/FLEBackwardElectionRoundTest.java @@ -0,0 +1,137 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.QuorumCnxManager; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.util.HashMap; + +public class FLEBackwardElectionRoundTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLELostMessageTest.class); + + int count; + HashMap peers; + File tmpdir[]; + int port[]; + + QuorumCnxManager cnxManagers[]; + + @Before + public void setUp() throws Exception { + count = 3; + + peers = new HashMap(count); + tmpdir = new File[count]; + port = new int[count]; + cnxManagers = new QuorumCnxManager[count - 1]; + } + + @After + public void tearDown() throws Exception { + for (int i = 0; i < (count - 1); i++) { + if (cnxManagers[i] != null) { + cnxManagers[i].halt(); + } + } + } + + /** + * This test is checking the following case. A server S is currently LOOKING and it receives notifications from a quorum indicating they are following S. The election round E of S is higher than + * the election round E' in the notification messages, so S becomes the leader and sets its epoch back to E'. In the meanwhile, one or more followers turn to LOOKING and elect S in election round + * E. Having leader and followers with different election rounds might prevent other servers from electing a leader because they can't get a consistent set of notifications from a quorum. + * + * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1514} + */ + + @Test + public void testBackwardElectionRound() throws Exception { + LOG.info("TestLE: {}, {}", getTestName(), count); + for (int i = 0; i < count; i++) { + int clientport = PortAssignment.unique(); + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress(clientport), + new InetSocketAddress(PortAssignment.unique()))); + tmpdir[i] = ClientBase.createTmpDir(); + port[i] = clientport; + } + + ByteBuffer initialMsg = FLETestUtils.createMsg(ServerState.FOLLOWING.ordinal(), 0, 0, 1); + + /* + * Start server 0 + */ + QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2); + peer.startLeaderElection(); + FLETestUtils.LEThread thread = new FLETestUtils.LEThread(peer, 0); + thread.start(); + + /* + * Start mock server 1 + */ + QuorumPeer mockPeer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 1000, 2, 2); + cnxManagers[0] = new QuorumCnxManager(mockPeer); + cnxManagers[0].listener.start(); + + cnxManagers[0].toSend(0l, initialMsg); + + /* + * Start mock server 2 + */ + mockPeer = new QuorumPeer(peers, tmpdir[2], tmpdir[2], port[2], 3, 2, 1000, 2, 2); + cnxManagers[1] = new QuorumCnxManager(mockPeer); + cnxManagers[1].listener.start(); + + cnxManagers[1].toSend(0l, initialMsg); + + /* + * Run another instance of leader election. + */ + thread.join(5000); + thread = new FLETestUtils.LEThread(peer, 0); + thread.start(); + + /* + * Send the same messages, this time should not make 0 the leader. + */ + cnxManagers[0].toSend(0l, initialMsg); + cnxManagers[1].toSend(0l, initialMsg); + + thread.join(5000); + + if (!thread.isAlive()) { + Assert.fail("Should not have joined"); + } + + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/FLELostMessageTest.java b/src/java/test/org/apache/zookeeper/server/quorum/FLELostMessageTest.java new file mode 100644 index 00000000000..3752d277163 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/FLELostMessageTest.java @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.QuorumCnxManager; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.HashMap; + +public class FLELostMessageTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLELostMessageTest.class); + + int count; + HashMap peers; + File tmpdir[]; + int port[]; + + QuorumCnxManager cnxManager; + + @Before + public void setUp() throws Exception { + count = 3; + + peers = new HashMap(count); + tmpdir = new File[count]; + port = new int[count]; + } + + @After + public void tearDown() throws Exception { + cnxManager.halt(); + } + + @Test + public void testLostMessage() throws Exception { + LOG.info("TestLE: {}, {}", getTestName(), count); + for (int i = 0; i < count; i++) { + int clientport = PortAssignment.unique(); + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress(clientport), + new InetSocketAddress(PortAssignment.unique()))); + tmpdir[i] = ClientBase.createTmpDir(); + port[i] = clientport; + } + + /* + * Start server 0 + */ + QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 1000, 2, 2); + peer.startLeaderElection(); + FLETestUtils.LEThread thread = new FLETestUtils.LEThread(peer, 1); + thread.start(); + + /* + * Start mock server 1 + */ + mockServer(); + thread.join(5000); + if (thread.isAlive()) { + Assert.fail("Threads didn't join"); + } + } + + void mockServer() throws InterruptedException, IOException { + QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2); + cnxManager = new QuorumCnxManager(peer); + cnxManager.listener.start(); + + cnxManager.toSend(1l, FLETestUtils.createMsg(ServerState.LOOKING.ordinal(), 0, 0, 0)); + cnxManager.recvQueue.take(); + cnxManager.toSend(1L, FLETestUtils.createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 0)); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/FLETestUtils.java b/src/java/test/org/apache/zookeeper/server/quorum/FLETestUtils.java new file mode 100644 index 00000000000..328aa923b9c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/FLETestUtils.java @@ -0,0 +1,83 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.FastLeaderElection; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.Vote; +import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.ByteBuffer; + +public class FLETestUtils extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLETestUtils.class); + + /* + * Creates a leader election notification message. + */ + static ByteBuffer createMsg(int state, long leader, long zxid, long epoch) { + return FastLeaderElection.buildMsg(state, leader, zxid, 1, epoch); + } + + /* + * Thread to run an instance of leader election for + * a given quorum peer. + */ + static class LEThread extends Thread { + private int i; + private QuorumPeer peer; + + LEThread(QuorumPeer peer, int i) { + this.i = i; + this.peer = peer; + LOG.info("Constructor: {}", getName()); + + } + + public void run() { + try { + Vote v = null; + peer.setPeerState(ServerState.LOOKING); + LOG.info("Going to call leader election: {}", i); + v = peer.getElectionAlg().lookForLeader(); + + if (v == null) { + Assert.fail("Thread " + i + " got a null vote"); + } + + /* + * A real zookeeper would take care of setting the current vote. Here + * we do it manually. + */ + peer.setCurrentVote(v); + + LOG.info("Finished election: {}, {}", i, v.getId()); + + Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING); + } catch (Exception e) { + e.printStackTrace(); + } + LOG.info("Joining"); + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java b/src/java/test/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java new file mode 100644 index 00000000000..f6e4fdafd3b --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java @@ -0,0 +1,579 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.TxnLogProposalIterator; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Matchers; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.Socket; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Queue; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class LearnerHandlerTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory + .getLogger(LearnerHandlerTest.class); + private MockLearnerHandler learnerHandler; + private Socket sock; + // Member variables for mocking Leader + private Leader leader; + private long currentZxid; + // Member variables for mocking ZkDatabase + private MockZKDatabase db; + + @Before + public void setUp() throws Exception { + // Intercept when startForwarding is called + leader = mock(Leader.class); + when( + leader.startForwarding(Matchers.any(LearnerHandler.class), + Matchers.anyLong())).thenAnswer(new Answer() { + public Object answer(InvocationOnMock invocation) { + currentZxid = (Long) invocation.getArguments()[1]; + return 0; + } + }); + + sock = mock(Socket.class); + + db = new MockZKDatabase(null); + learnerHandler = new MockLearnerHandler(sock, leader); + } + + Proposal createProposal(long zxid) { + Proposal p = new Proposal(); + p.packet = new QuorumPacket(); + p.packet.setZxid(zxid); + p.packet.setType(Leader.PROPOSAL); + return p; + } + + /** + * Validate that queued packets contains proposal in the following orders as + * a given array of zxids + * + * @param zxids + */ + public void queuedPacketMatches(long[] zxids) { + int index = 0; + for (QuorumPacket qp : learnerHandler.getQueuedPackets()) { + if (qp.getType() == Leader.PROPOSAL) { + assertZxidEquals(zxids[index++], qp.getZxid()); + } + } + } + + void reset() { + learnerHandler.getQueuedPackets().clear(); + learnerHandler.threadStarted = false; + learnerHandler.setFirstPacket(true); + } + + /** + * Check if op packet (first packet in the queue) match the expected value + * @param type - type of packet + * @param zxid - zxid in the op packet + * @param currentZxid - last packet queued by syncFollower, + * before invoking startForwarding() + */ + public void assertOpType(int type, long zxid, long currentZxid) { + Queue packets = learnerHandler.getQueuedPackets(); + assertTrue(packets.size() > 0); + assertEquals(type, packets.peek().getType()); + assertZxidEquals(zxid, packets.peek().getZxid()); + assertZxidEquals(currentZxid, this.currentZxid); + } + + void assertZxidEquals(long expected, long value) { + assertEquals("Expected 0x" + Long.toHexString(expected) + " but was 0x" + + Long.toHexString(value), expected, value); + } + + /** + * Test cases when leader has empty commitedLog + */ + @Test + public void testEmptyCommittedLog() throws Exception { + long peerZxid; + + // Peer has newer zxid + peerZxid = 3; + db.lastProcessedZxid = 1; + db.committedLog.clear(); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send TRUNC and forward any packet starting lastProcessedZxid + assertOpType(Leader.TRUNC, db.lastProcessedZxid, db.lastProcessedZxid); + reset(); + + // Peer is already sync + peerZxid = 1; + db.lastProcessedZxid = 1; + db.committedLog.clear(); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF and forward any packet starting lastProcessedZxid + assertOpType(Leader.DIFF, db.lastProcessedZxid, db.lastProcessedZxid); + assertEquals(1, learnerHandler.getQueuedPackets().size()); + reset(); + + // Peer has 0 zxid (new machine turn up), txnlog + // is disabled + peerZxid = 0; + db.setSnapshotSizeFactor(-1); + db.lastProcessedZxid = 1; + db.committedLog.clear(); + // We send SNAP + assertTrue(learnerHandler.syncFollower(peerZxid, db, leader)); + assertEquals(0, learnerHandler.getQueuedPackets().size()); + reset(); + + } + + /** + * Test cases when leader has committedLog + */ + @Test + public void testCommittedLog() throws Exception { + long peerZxid; + + // Commit proposal may lag behind data tree, but it shouldn't affect + // us in any case + db.lastProcessedZxid = 6; + db.committedLog.add(createProposal(2)); + db.committedLog.add(createProposal(3)); + db.committedLog.add(createProposal(5)); + + // Peer has zxid that we have never seen + peerZxid = 4; + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send TRUNC to 3 and forward any packet starting 5 + assertOpType(Leader.TRUNC, 3, 5); + // DIFF + 1 proposals + 1 commit + assertEquals(3, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{5}); + reset(); + + // Peer is within committedLog range + peerZxid = 2; + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF and forward any packet starting lastProcessedZxid + assertOpType(Leader.DIFF, db.getmaxCommittedLog(), + db.getmaxCommittedLog()); + // DIFF + 2 proposals + 2 commit + assertEquals(5, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{3, 5}); + reset(); + + // Peer miss the committedLog and txnlog is disabled + peerZxid = 1; + db.setSnapshotSizeFactor(-1); + // We send SNAP + assertTrue(learnerHandler.syncFollower(peerZxid, db, leader)); + assertEquals(0, learnerHandler.getQueuedPackets().size()); + reset(); + } + + /** + * Test cases when txnlog is enabled + */ + @Test + public void testTxnLog() throws Exception { + long peerZxid; + db.txnLog.add(createProposal(2)); + db.txnLog.add(createProposal(3)); + db.txnLog.add(createProposal(5)); + db.txnLog.add(createProposal(6)); + db.txnLog.add(createProposal(7)); + db.txnLog.add(createProposal(8)); + db.txnLog.add(createProposal(9)); + + db.lastProcessedZxid = 9; + db.committedLog.add(createProposal(6)); + db.committedLog.add(createProposal(7)); + db.committedLog.add(createProposal(8)); + + // Peer has zxid that we have never seen + peerZxid = 4; + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send TRUNC to 3 and forward any packet starting at maxCommittedLog + assertOpType(Leader.TRUNC, 3, db.getmaxCommittedLog()); + // DIFF + 4 proposals + 4 commit + assertEquals(9, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{5, 6, 7, 8}); + reset(); + + // Peer zxid is in txnlog range + peerZxid = 3; + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF and forward any packet starting at maxCommittedLog + assertOpType(Leader.DIFF, db.getmaxCommittedLog(), + db.getmaxCommittedLog()); + // DIFF + 4 proposals + 4 commit + assertEquals(9, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{5, 6, 7, 8}); + reset(); + + } + + /** + * Test case verifying TxnLogProposalIterator closure. + */ + @Test + public void testTxnLogProposalIteratorClosure() throws Exception { + long peerZxid; + + // CommmitedLog is empty, we will use txnlog up to lastProcessZxid + db = new MockZKDatabase(null) { + @Override + public Iterator getProposalsFromTxnLog(long peerZxid, + long limit) { + return TxnLogProposalIterator.EMPTY_ITERATOR; + } + }; + db.lastProcessedZxid = 7; + db.txnLog.add(createProposal(2)); + db.txnLog.add(createProposal(3)); + + // Peer zxid + peerZxid = 4; + assertTrue("Couldn't identify snapshot transfer!", + learnerHandler.syncFollower(peerZxid, db, leader)); + reset(); + } + + /** + * Test cases when txnlog is enabled and commitedLog is empty + */ + @Test + public void testTxnLogOnly() throws Exception { + long peerZxid; + + // CommmitedLog is empty, we will use txnlog up to lastProcessZxid + db.lastProcessedZxid = 7; + db.txnLog.add(createProposal(2)); + db.txnLog.add(createProposal(3)); + db.txnLog.add(createProposal(5)); + db.txnLog.add(createProposal(6)); + db.txnLog.add(createProposal(7)); + db.txnLog.add(createProposal(8)); + + // Peer has zxid that we have never seen + peerZxid = 4; + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send TRUNC to 3 and forward any packet starting at + // lastProcessedZxid + assertOpType(Leader.TRUNC, 3, db.lastProcessedZxid); + // DIFF + 3 proposals + 3 commit + assertEquals(7, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{5, 6, 7}); + reset(); + + // Peer has zxid in txnlog range + peerZxid = 2; + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF and forward any packet starting at lastProcessedZxid + assertOpType(Leader.DIFF, db.lastProcessedZxid, db.lastProcessedZxid); + // DIFF + 4 proposals + 4 commit + assertEquals(9, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{3, 5, 6, 7}); + reset(); + + // Peer miss the txnlog + peerZxid = 1; + assertTrue(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send snap + assertEquals(0, learnerHandler.getQueuedPackets().size()); + reset(); + } + + long getZxid(long epoch, long counter) { + return ZxidUtils.makeZxid(epoch, counter); + } + + /** + * Test cases with zxids that are negative long + */ + @Test + public void testTxnLogWithNegativeZxid() throws Exception { + long peerZxid; + db.txnLog.add(createProposal(getZxid(0xf, 2))); + db.txnLog.add(createProposal(getZxid(0xf, 3))); + db.txnLog.add(createProposal(getZxid(0xf, 5))); + db.txnLog.add(createProposal(getZxid(0xf, 6))); + db.txnLog.add(createProposal(getZxid(0xf, 7))); + db.txnLog.add(createProposal(getZxid(0xf, 8))); + db.txnLog.add(createProposal(getZxid(0xf, 9))); + + db.lastProcessedZxid = getZxid(0xf, 9); + db.committedLog.add(createProposal(getZxid(0xf, 6))); + db.committedLog.add(createProposal(getZxid(0xf, 7))); + db.committedLog.add(createProposal(getZxid(0xf, 8))); + + // Peer has zxid that we have never seen + peerZxid = getZxid(0xf, 4); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send TRUNC to 3 and forward any packet starting at maxCommittedLog + assertOpType(Leader.TRUNC, getZxid(0xf, 3), db.getmaxCommittedLog()); + // DIFF + 4 proposals + 4 commit + assertEquals(9, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{getZxid(0xf, 5), + getZxid(0xf, 6), getZxid(0xf, 7), getZxid(0xf, 8)}); + reset(); + + // Peer zxid is in txnlog range + peerZxid = getZxid(0xf, 3); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF and forward any packet starting at maxCommittedLog + assertOpType(Leader.DIFF, db.getmaxCommittedLog(), + db.getmaxCommittedLog()); + // DIFF + 4 proposals + 4 commit + assertEquals(9, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{getZxid(0xf, 5), + getZxid(0xf, 6), getZxid(0xf, 7), getZxid(0xf, 8)}); + reset(); + } + + /** + * Test cases when peer has new-epoch zxid + */ + @Test + public void testNewEpochZxid() throws Exception { + long peerZxid; + db.txnLog.add(createProposal(getZxid(0, 1))); + db.txnLog.add(createProposal(getZxid(1, 1))); + db.txnLog.add(createProposal(getZxid(1, 2))); + + // After leader election, lastProcessedZxid will point to new epoch + db.lastProcessedZxid = getZxid(2, 0); + db.committedLog.add(createProposal(getZxid(1, 1))); + db.committedLog.add(createProposal(getZxid(1, 2))); + + // Peer has zxid of epoch 0 + peerZxid = getZxid(0, 0); + // We should get snap, we can do better here, but the main logic is + // that we should never send diff if we have never seen any txn older + // than peer zxid + assertTrue(learnerHandler.syncFollower(peerZxid, db, leader)); + assertEquals(0, learnerHandler.getQueuedPackets().size()); + reset(); + + // Peer has zxid of epoch 1 + peerZxid = getZxid(1, 0); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF to (1, 2) and forward any packet starting at (1, 2) + assertOpType(Leader.DIFF, getZxid(1, 2), getZxid(1, 2)); + // DIFF + 2 proposals + 2 commit + assertEquals(5, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{getZxid(1, 1), getZxid(1, 2)}); + reset(); + + // Peer has zxid of epoch 2, so it is already sync + peerZxid = getZxid(2, 0); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF to (2, 0) and forward any packet starting at (2, 0) + assertOpType(Leader.DIFF, getZxid(2, 0), getZxid(2, 0)); + // DIFF only + assertEquals(1, learnerHandler.getQueuedPackets().size()); + reset(); + + } + + /** + * Test cases when learner has new-epcoh zxid + * (zxid & 0xffffffffL) == 0; + */ + @Test + public void testNewEpochZxidWithTxnlogOnly() throws Exception { + long peerZxid; + db.txnLog.add(createProposal(getZxid(1, 1))); + db.txnLog.add(createProposal(getZxid(2, 1))); + db.txnLog.add(createProposal(getZxid(2, 2))); + db.txnLog.add(createProposal(getZxid(4, 1))); + + // After leader election, lastProcessedZxid will point to new epoch + db.lastProcessedZxid = getZxid(6, 0); + + // Peer has zxid of epoch 3 + peerZxid = getZxid(3, 0); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF to (6,0) and forward any packet starting at (4,1) + assertOpType(Leader.DIFF, getZxid(6, 0), getZxid(4, 1)); + // DIFF + 1 proposals + 1 commit + assertEquals(3, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{getZxid(4, 1)}); + reset(); + + // Peer has zxid of epoch 4 + peerZxid = getZxid(4, 0); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF to (6,0) and forward any packet starting at (4,1) + assertOpType(Leader.DIFF, getZxid(6, 0), getZxid(4, 1)); + // DIFF + 1 proposals + 1 commit + assertEquals(3, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{getZxid(4, 1)}); + reset(); + + // Peer has zxid of epoch 5 + peerZxid = getZxid(5, 0); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF to (6,0) and forward any packet starting at (5,0) + assertOpType(Leader.DIFF, getZxid(6, 0), getZxid(5, 0)); + // DIFF only + assertEquals(1, learnerHandler.getQueuedPackets().size()); + reset(); + + // Peer has zxid of epoch 6 + peerZxid = getZxid(6, 0); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF to (6,0) and forward any packet starting at (6, 0) + assertOpType(Leader.DIFF, getZxid(6, 0), getZxid(6, 0)); + // DIFF only + assertEquals(1, learnerHandler.getQueuedPackets().size()); + reset(); + } + + /** + * Test cases when there is a duplicate txn in the committedLog. This + * should never happen unless there is a bug in initialization code + * but the learner should never see duplicate packets + */ + @Test + public void testDuplicatedTxn() throws Exception { + long peerZxid; + db.txnLog.add(createProposal(getZxid(0, 1))); + db.txnLog.add(createProposal(getZxid(1, 1))); + db.txnLog.add(createProposal(getZxid(1, 2))); + db.txnLog.add(createProposal(getZxid(1, 1))); + db.txnLog.add(createProposal(getZxid(1, 2))); + + // After leader election, lastProcessedZxid will point to new epoch + db.lastProcessedZxid = getZxid(2, 0); + db.committedLog.add(createProposal(getZxid(1, 1))); + db.committedLog.add(createProposal(getZxid(1, 2))); + db.committedLog.add(createProposal(getZxid(1, 1))); + db.committedLog.add(createProposal(getZxid(1, 2))); + + // Peer has zxid of epoch 1 + peerZxid = getZxid(1, 0); + assertFalse(learnerHandler.syncFollower(peerZxid, db, leader)); + // We send DIFF to (1, 2) and forward any packet starting at (1, 2) + assertOpType(Leader.DIFF, getZxid(1, 2), getZxid(1, 2)); + // DIFF + 2 proposals + 2 commit + assertEquals(5, learnerHandler.getQueuedPackets().size()); + queuedPacketMatches(new long[]{getZxid(1, 1), getZxid(1, 2)}); + reset(); + + } + + /** + * Test cases when we have to TRUNC learner, but it may cross epoch boundary + * so we need to send snap instead + */ + @Test + public void testCrossEpochTrunc() throws Exception { + long peerZxid; + db.txnLog.add(createProposal(getZxid(1, 1))); + db.txnLog.add(createProposal(getZxid(2, 1))); + db.txnLog.add(createProposal(getZxid(2, 2))); + db.txnLog.add(createProposal(getZxid(4, 1))); + + // After leader election, lastProcessedZxid will point to new epoch + db.lastProcessedZxid = getZxid(6, 0); + + // Peer has zxid (3, 1) + peerZxid = getZxid(3, 1); + assertTrue(learnerHandler.syncFollower(peerZxid, db, leader)); + assertEquals(0, learnerHandler.getQueuedPackets().size()); + reset(); + } + + class MockLearnerHandler extends LearnerHandler { + boolean threadStarted = false; + + MockLearnerHandler(Socket sock, Leader leader) throws IOException { + super(sock, leader); + } + + protected void startSendingPackets() { + threadStarted = true; + } + } + + class MockZKDatabase extends ZKDatabase { + long lastProcessedZxid; + ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + LinkedList committedLog = new LinkedList(); + LinkedList txnLog = new LinkedList(); + + public MockZKDatabase(FileTxnSnapLog snapLog) { + super(snapLog); + } + + public long getDataTreeLastProcessedZxid() { + return lastProcessedZxid; + } + + public long getmaxCommittedLog() { + if (!committedLog.isEmpty()) { + return committedLog.getLast().packet.getZxid(); + } + return 0; + } + + public long getminCommittedLog() { + if (!committedLog.isEmpty()) { + return committedLog.getFirst().packet.getZxid(); + } + return 0; + } + + public LinkedList getCommittedLog() { + return committedLog; + } + + public ReentrantReadWriteLock getLogLock() { + return lock; + } + + public Iterator getProposalsFromTxnLog(long peerZxid, + long limit) { + if (peerZxid >= txnLog.peekFirst().packet.getZxid()) { + return txnLog.iterator(); + } else { + return (new LinkedList()).iterator(); + } + + } + + public long calculateTxnLogSizeLimit() { + return 1; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/LearnerSnapshotThrottlerTest.java b/src/java/test/org/apache/zookeeper/server/quorum/LearnerSnapshotThrottlerTest.java new file mode 100644 index 00000000000..9db578f3717 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/LearnerSnapshotThrottlerTest.java @@ -0,0 +1,207 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class LearnerSnapshotThrottlerTest extends ZKTestCase { + private static final Logger LOG = + LoggerFactory.getLogger(LearnerSnapshotThrottlerTest.class); + + @Test(expected = SnapshotThrottleException.class) + public void testTooManySnapshotsNonessential() throws Exception { + LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(5); + for (int i = 0; i < 6; i++) { + throttler.beginSnapshot(false); + } + } + + @Test(expected = SnapshotThrottleException.class) + public void testTooManySnapshotsEssential() throws Exception { + LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(5); + try { + for (int i = 0; i < 6; i++) { + throttler.beginSnapshot(true); + } + } catch (SnapshotThrottleException ex) { + Assert.fail("essential snapshots should not be throttled"); + } + throttler.endSnapshot(); + throttler.beginSnapshot(false); + } + + @Test + public void testNoThrottle() throws Exception { + LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(5); + try { + for (int i = 0; i < 6; i++) { + throttler.beginSnapshot(true); + } + } catch (SnapshotThrottleException ex) { + Assert.fail("essential snapshots should not be throttled"); + } + throttler.endSnapshot(); + for (int i = 0; i < 5; i++) { + throttler.endSnapshot(); + throttler.beginSnapshot(false); + } + } + + @Test + public void testTryWithResourceNoThrottle() throws Exception { + LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(1); + for (int i = 0; i < 3; i++) { + LearnerSnapshot snapshot = throttler.beginSnapshot(false); + try { + Assert.assertFalse(snapshot.isEssential()); + Assert.assertEquals(1, snapshot.getConcurrentSnapshotNumber()); + } finally { + snapshot.close(); + } + } + } + + @Test(expected = SnapshotThrottleException.class) + public void testTryWithResourceThrottle() throws Exception { + LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(1); + LearnerSnapshot outer = throttler.beginSnapshot(true); + try { + LearnerSnapshot inner = throttler.beginSnapshot(false); + try { + Assert.fail("shouldn't be able to have both snapshots open"); + } finally { + inner.close(); + } + } finally { + outer.close(); + } + } + + @Test + public void testParallelNoThrottle() throws Exception { + final int numThreads = 50; + + final LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(numThreads); + ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); + final CountDownLatch threadStartLatch = new CountDownLatch(numThreads); + final CountDownLatch snapshotProgressLatch = new CountDownLatch(numThreads); + + List> results = new ArrayList>(numThreads); + for (int i = 0; i < numThreads; i++) { + results.add(threadPool.submit(new Callable() { + + @Override + public Boolean call() { + threadStartLatch.countDown(); + try { + threadStartLatch.await(); + + throttler.beginSnapshot(false); + + snapshotProgressLatch.countDown(); + snapshotProgressLatch.await(); + + throttler.endSnapshot(); + } catch (Exception e) { + return false; + } + + return true; + } + })); + } + + for (Future result : results) { + Assert.assertTrue(result.get()); + } + } + + @Test + public void testPositiveTimeout() throws Exception { + final LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(1, 200); + ExecutorService threadPool = Executors.newFixedThreadPool(1); + + LearnerSnapshot first = throttler.beginSnapshot(false); + final CountDownLatch snapshotProgressLatch = new CountDownLatch(1); + + Future result = threadPool.submit(new Callable() { + @Override + public Boolean call() { + try { + snapshotProgressLatch.countDown(); + LearnerSnapshot second = throttler.beginSnapshot(false); + second.close(); + } catch (Exception e) { + return false; + } + + return true; + } + }); + + snapshotProgressLatch.await(); + + first.close(); + + Assert.assertTrue(result.get()); + } + + @Test + public void testHighContentionWithTimeout() throws Exception { + int numThreads = 20; + + final LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(2, 5000); + ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); + final CountDownLatch threadStartLatch = new CountDownLatch(numThreads); + + List> results = new ArrayList>(numThreads); + for (int i = 0; i < numThreads; i++) { + results.add(threadPool.submit(new Callable() { + + @Override + public Boolean call() { + threadStartLatch.countDown(); + try { + threadStartLatch.await(); + + LearnerSnapshot snap = throttler.beginSnapshot(false); + + int snapshotNumber = snap.getConcurrentSnapshotNumber(); + + throttler.endSnapshot(); + + return snapshotNumber <= 2; + } catch (Exception e) { + LOG.error("Exception trying to begin snapshot", e); + return false; + } + } + })); + } + + for (Future result : results) { + Assert.assertTrue(result.get()); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java b/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java new file mode 100644 index 00000000000..a3636a53b5a --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java @@ -0,0 +1,183 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.test.TestUtils; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.junit.Assert; +import org.junit.Test; + +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.util.ArrayList; + +public class LearnerTest extends ZKTestCase { + private static final File testData = new File( + System.getProperty("test.data.dir", "build/test/data")); + + @Test(expected = IOException.class) + public void connectionRetryTimeoutTest() throws Exception { + Learner learner = new TimeoutLearner(); + learner.self = new QuorumPeer(); + learner.self.setTickTime(2000); + learner.self.setInitLimit(5); + learner.self.setSyncLimit(2); + + // this addr won't even be used since we fake the Socket.connect + InetSocketAddress addr = new InetSocketAddress(1111); + + // we expect this to throw an IOException since we're faking socket connect errors every time + learner.connectToLeader(addr); + } + + @Test + public void connectionInitLimitTimeoutTest() throws Exception { + TimeoutLearner learner = new TimeoutLearner(); + learner.self = new QuorumPeer(); + learner.self.setTickTime(2000); + learner.self.setInitLimit(5); + learner.self.setSyncLimit(2); + + // this addr won't even be used since we fake the Socket.connect + InetSocketAddress addr = new InetSocketAddress(1111); + + // pretend each connect attempt takes 4000 milliseconds + learner.setTimeMultiplier((long) 4000 * 1000000); + + learner.setPassConnectAttempt(5); + + // we expect this to throw an IOException since we're faking socket connect errors every time + try { + learner.connectToLeader(addr); + Assert.fail("should have thrown IOException!"); + } catch (IOException e) { + //good, wanted to see that, let's make sure we ran out of time + Assert.assertTrue(learner.nanoTime() > 2000 * 5 * 1000000); + Assert.assertEquals(3, learner.getSockConnectAttempt()); + } + } + + @Test + public void syncTest() throws Exception { + File tmpFile = File.createTempFile("test", ".dir", testData); + tmpFile.delete(); + try { + FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile); + SimpleLearner sl = new SimpleLearner(ftsl); + long startZxid = sl.zk.getLastProcessedZxid(); + + // Set up bogus streams + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos); + sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream()); + + // make streams and socket do something innocuous + sl.bufferedOutput = new BufferedOutputStream(System.out); + sl.sock = new Socket(); + + // fake messages from the server + QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null); + oa.writeRecord(qp, null); + sl.zk.getZKDatabase().serializeSnapshot(oa); + oa.writeString("BenWasHere", "signature"); + TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create); + CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion()); + ByteArrayOutputStream tbaos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos); + hdr.serialize(boa, "hdr"); + txn.serialize(boa, "txn"); + tbaos.close(); + qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null); + oa.writeRecord(qp, null); + + // setup the messages to be streamed to follower + sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray())); + + try { + sl.syncWithLeader(3); + } catch (EOFException e) { + } + + sl.zk.shutdown(); + sl = new SimpleLearner(ftsl); + Assert.assertEquals(startZxid, sl.zk.getLastProcessedZxid()); + } finally { + TestUtils.deleteFileRecursively(tmpFile); + } + } + + static class SimpleLearnerZooKeeperServer extends LearnerZooKeeperServer { + + Learner learner; + + public SimpleLearnerZooKeeperServer(FileTxnSnapLog ftsl, QuorumPeer self) throws IOException { + super(ftsl, 2000, 2000, 2000, new ZKDatabase(ftsl), self); + } + + @Override + public Learner getLearner() { + return learner; + } + } + + static class SimpleLearner extends Learner { + SimpleLearner(FileTxnSnapLog ftsl) throws IOException { + self = new QuorumPeer(); + zk = new SimpleLearnerZooKeeperServer(ftsl, self); + ((SimpleLearnerZooKeeperServer) zk).learner = this; + } + } + + static class TimeoutLearner extends Learner { + int passSocketConnectOnAttempt = 10; + int socketConnectAttempt = 0; + long timeMultiplier = 0; + + public void setTimeMultiplier(long multiplier) { + timeMultiplier = multiplier; + } + + public void setPassConnectAttempt(int num) { + passSocketConnectOnAttempt = num; + } + + protected long nanoTime() { + return socketConnectAttempt * timeMultiplier; + } + + protected int getSockConnectAttempt() { + return socketConnectAttempt; + } + + @Override + protected void sockConnect(Socket sock, InetSocketAddress addr, int timeout) + throws IOException { + if (++socketConnectAttempt < passSocketConnectOnAttempt) { + throw new IOException("Test injected Socket.connect() error."); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java b/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java new file mode 100644 index 00000000000..4eb04c2b196 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.junit.Test; + +import java.net.InetAddress; +import java.net.InetSocketAddress; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class LocalPeerBeanTest { + + /** + * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2299 + */ + @Test + public void testClientAddress() throws Exception { + QuorumPeer quorumPeer = new QuorumPeer(); + LocalPeerBean remotePeerBean = new LocalPeerBean(quorumPeer); + + /** + * Case 1: When cnxnFactory is null + */ + String result = remotePeerBean.getClientAddress(); + assertNotNull(result); + assertEquals(0, result.length()); + + /** + * Case 2: When only client port is configured + */ + ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); + int clientPort = 2181; + InetSocketAddress address = new InetSocketAddress(clientPort); + cnxnFactory.configure(address, 5, false); + quorumPeer.setCnxnFactory(cnxnFactory); + + result = remotePeerBean.getClientAddress(); + String ipv4 = "0.0.0.0:" + clientPort; + String ipv6 = "0:0:0:0:0:0:0:0:" + clientPort; + assertTrue(result.equals(ipv4) || result.equals(ipv6)); + // cleanup + cnxnFactory.shutdown(); + + /** + * Case 3: When both client port and client address is configured + */ + InetAddress clientIP = InetAddress.getByAddress(new byte[]{127, 0, 0, + 2}); + address = new InetSocketAddress(clientIP, clientPort); + cnxnFactory = ServerCnxnFactory.createFactory(); + cnxnFactory.configure(address, 5, false); + quorumPeer.setCnxnFactory(cnxnFactory); + + result = remotePeerBean.getClientAddress(); + String expectedResult = "127.0.0.2:" + clientPort; + assertEquals(expectedResult, result); + // cleanup + cnxnFactory.shutdown(); + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java new file mode 100644 index 00000000000..68eff4f4840 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class QuorumPeerConfigTest { + + /** + * test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2264 + */ + @Test + public void testErrorMessageWhensecureClientPortNotSetButsecureClientPortAddressSet() + throws IOException, ConfigException { + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + try { + Properties zkProp = getDefaultZKProperties(); + zkProp.setProperty("secureClientPortAddress", "localhost"); + quorumPeerConfig.parseProperties(zkProp); + fail("IllegalArgumentException is expected"); + } catch (IllegalArgumentException e) { + String expectedMessage = "secureClientPortAddress is set but secureClientPort is not set"; + assertEquals(expectedMessage, e.getMessage()); + } + } + + /** + * + * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2264 + */ + @Test + public void testErrorMessageWhenclientPortNotSetButclientPortAddressSet() + throws IOException, ConfigException { + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + try { + Properties zkProp = getDefaultZKProperties(); + zkProp.setProperty("clientPortAddress", "localhost"); + quorumPeerConfig.parseProperties(zkProp); + fail("IllegalArgumentException is expected"); + } catch (IllegalArgumentException e) { + String expectedMessage = "clientPortAddress is set but clientPort is not set"; + assertEquals(expectedMessage, e.getMessage()); + } + } + + private Properties getDefaultZKProperties() { + Properties zkProp = new Properties(); + zkProp.setProperty("dataDir", new File("myDataDir").getAbsolutePath()); + return zkProp; + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java new file mode 100644 index 00000000000..98066d96c6a --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java @@ -0,0 +1,781 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.WriterAppender; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeper.States; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.test.ClientBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.LineNumberReader; +import java.io.StringReader; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.util.Map; +import java.util.regex.Pattern; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +/** + * Test stand-alone server. + * + */ +public class QuorumPeerMainTest extends QuorumPeerTestBase { + + private Servers servers; + private int numServers = 0; + + @After + public void tearDown() throws Exception { + if (servers == null || servers.mt == null) { + LOG.info("No servers to shutdown!"); + return; + } + for (int i = 0; i < numServers; i++) { + if (i < servers.mt.length) { + servers.mt[i].shutdown(); + } + } + } + + /** + * Verify the ability to start a cluster. + */ + @Test + public void testQuorum() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + + String quorumCfgSection = + "server.1=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); + q1.start(); + q2.start(); + + Assert.assertTrue("waiting for server 1 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + QuorumPeer quorumPeer = q1.main.quorumPeer; + + int tickTime = quorumPeer.getTickTime(); + Assert.assertEquals( + "Default value of minimumSessionTimeOut is not considered", + tickTime * 2, quorumPeer.getMinSessionTimeout()); + Assert.assertEquals( + "Default value of maximumSessionTimeOut is not considered", + tickTime * 20, quorumPeer.getMaxSessionTimeout()); + + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT, this); + waitForOne(zk, States.CONNECTED); + zk.create("/foo_q1", "foobar1".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertEquals(new String(zk.getData("/foo_q1", null, null)), "foobar1"); + zk.close(); + + zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT, this); + waitForOne(zk, States.CONNECTED); + zk.create("/foo_q2", "foobar2".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertEquals(new String(zk.getData("/foo_q2", null, null)), "foobar2"); + zk.close(); + + q1.shutdown(); + q2.shutdown(); + + Assert.assertTrue("waiting for server 1 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT)); + } + + /** + * Test early leader abandonment. + */ + @Test + public void testEarlyLeaderAbandonment() throws Exception { + ClientBase.setupTestEnv(); + final int SERVER_COUNT = 3; + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + sb.append("server." + i + "=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + clientPorts[i] + "\n"); + } + String quorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this); + } + + waitForAll(zk, States.CONNECTED); + + // we need to shutdown and start back up to make sure that the create session isn't the first transaction since + // that is rather innocuous. + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + } + + waitForAll(zk, States.CONNECTING); + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].start(); + // Recreate a client session since the previous session was not persisted. + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this); + } + + waitForAll(zk, States.CONNECTED); + + + // ok lets find the leader and kill everything else, we have a few + // seconds, so it should be plenty of time + int leader = -1; + Map outstanding = null; + for (int i = 0; i < SERVER_COUNT; i++) { + if (mt[i].main.quorumPeer.leader == null) { + mt[i].shutdown(); + } else { + leader = i; + outstanding = mt[leader].main.quorumPeer.leader.outstandingProposals; + } + } + + try { + zk[leader].create("/zk" + leader, "zk".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.fail("create /zk" + leader + " should have failed"); + } catch (KeeperException e) { + } + + // just make sure that we actually did get it in process at the + // leader + Assert.assertTrue(outstanding.size() == 1); + Assert.assertTrue(((Proposal) outstanding.values().iterator().next()).request.getHdr().getType() == OpCode.create); + // make sure it has a chance to write it to disk + Thread.sleep(1000); + mt[leader].shutdown(); + waitForAll(zk, States.CONNECTING); + for (int i = 0; i < SERVER_COUNT; i++) { + if (i != leader) { + mt[i].start(); + } + } + for (int i = 0; i < SERVER_COUNT; i++) { + if (i != leader) { + // Recreate a client session since the previous session was not persisted. + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this); + waitForOne(zk[i], States.CONNECTED); + zk[i].create("/zk" + i, "zk".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + } + + mt[leader].start(); + waitForAll(zk, States.CONNECTED); + // make sure everything is consistent + for (int i = 0; i < SERVER_COUNT; i++) { + for (int j = 0; j < SERVER_COUNT; j++) { + if (i == leader) { + Assert.assertTrue((j == leader ? ("Leader (" + leader + ")") : ("Follower " + j)) + " should not have /zk" + i, zk[j].exists("/zk" + i, false) == null); + } else { + Assert.assertTrue((j == leader ? ("Leader (" + leader + ")") : ("Follower " + j)) + " does not have /zk" + i, zk[j].exists("/zk" + i, false) != null); + } + } + } + for (int i = 0; i < SERVER_COUNT; i++) { + zk[i].close(); + } + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + } + } + + /** + * Test the case of server with highest zxid not present at leader election and joining later. + * This test case is for reproducing the issue and fixing the bug mentioned in ZOOKEEPER-1154 + * and ZOOKEEPER-1156. + */ + @Test + public void testHighestZxidJoinLate() throws Exception { + numServers = 3; + servers = LaunchServers(numServers); + String path = "/hzxidtest"; + int leader = -1; + + // find the leader + for (int i = 0; i < numServers; i++) { + if (servers.mt[i].main.quorumPeer.leader != null) { + leader = i; + } + } + + // make sure there is a leader + Assert.assertTrue("There should be a leader", leader >= 0); + + int nonleader = (leader + 1) % numServers; + + byte[] input = new byte[1]; + input[0] = 1; + byte[] output; + + // Create a couple of nodes + servers.zk[leader].create(path + leader, input, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + servers.zk[leader].create(path + nonleader, input, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + // make sure the updates indeed committed. If it is not + // the following statement will throw. + output = servers.zk[leader].getData(path + nonleader, false, null); + + // Shutdown every one else but the leader + for (int i = 0; i < numServers; i++) { + if (i != leader) { + servers.mt[i].shutdown(); + } + } + + input[0] = 2; + + // Update the node on the leader + servers.zk[leader].setData(path + leader, input, -1, null, null); + + // wait some time to let this get written to disk + Thread.sleep(500); + + // shut the leader down + servers.mt[leader].shutdown(); + + System.gc(); + + waitForAll(servers.zk, States.CONNECTING); + + // Start everyone but the leader + for (int i = 0; i < numServers; i++) { + if (i != leader) { + servers.mt[i].start(); + } + } + + // wait to connect to one of these + waitForOne(servers.zk[nonleader], States.CONNECTED); + + // validate that the old value is there and not the new one + output = servers.zk[nonleader].getData(path + leader, false, null); + + Assert.assertEquals( + "Expecting old value 1 since 2 isn't committed yet", + output[0], 1); + + // Do some other update, so we bump the maxCommttedZxid + // by setting the value to 2 + servers.zk[nonleader].setData(path + nonleader, input, -1); + + // start the old leader + servers.mt[leader].start(); + + // connect to it + waitForOne(servers.zk[leader], States.CONNECTED); + + // make sure it doesn't have the new value that it alone had logged + output = servers.zk[leader].getData(path + leader, false, null); + Assert.assertEquals( + "Validating that the deposed leader has rolled back that change it had written", + output[0], 1); + + // make sure the leader has the subsequent changes that were made while it was offline + output = servers.zk[leader].getData(path + nonleader, false, null); + Assert.assertEquals( + "Validating that the deposed leader caught up on changes it missed", + output[0], 2); + } + + private void waitForOne(ZooKeeper zk, States state) throws InterruptedException { + int iterations = ClientBase.CONNECTION_TIMEOUT / 500; + while (zk.getState() != state) { + if (iterations-- == 0) { + throw new RuntimeException("Waiting too long"); + } + Thread.sleep(500); + } + } + + private void waitForAll(ZooKeeper[] zks, States state) throws InterruptedException { + int iterations = ClientBase.CONNECTION_TIMEOUT / 1000; + boolean someoneNotConnected = true; + while (someoneNotConnected) { + if (iterations-- == 0) { + ClientBase.logAllStackTraces(); + throw new RuntimeException("Waiting too long"); + } + + someoneNotConnected = false; + for (ZooKeeper zk : zks) { + if (zk.getState() != state) { + someoneNotConnected = true; + break; + } + } + Thread.sleep(1000); + } + } + + /** + * This is a helper function for launching a set of servers + * + * @param numServers + * @return + * @throws IOException + * @throws InterruptedException + */ + private Servers LaunchServers(int numServers) throws IOException, InterruptedException { + int SERVER_COUNT = numServers; + Servers svrs = new Servers(); + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + sb.append("server." + i + "=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + clientPorts[i] + "\n"); + } + String quorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this); + } + + waitForAll(zk, States.CONNECTED); + + svrs.mt = mt; + svrs.zk = zk; + return svrs; + } + + /** + * Verify handling of bad quorum address + */ + @Test + public void testBadPeerAddressInQuorum() throws Exception { + ClientBase.setupTestEnv(); + + // setup the logger to capture all logs + Layout layout = + Logger.getRootLogger().getAppender("CONSOLE").getLayout(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + WriterAppender appender = new WriterAppender(layout, os); + appender.setThreshold(Level.WARN); + Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum"); + qlogger.addAppender(appender); + + try { + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + + String quorumCfgSection = + "server.1=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + q1.start(); + + boolean isup = + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + 30000); + + Assert.assertFalse("Server never came up", isup); + + q1.shutdown(); + + Assert.assertTrue("waiting for server 1 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT)); + + } finally { + qlogger.removeAppender(appender); + } + + LineNumberReader r = new LineNumberReader(new StringReader(os.toString())); + String line; + boolean found = false; + Pattern p = + Pattern.compile(".*Cannot open channel to .* at election address .*"); + while ((line = r.readLine()) != null) { + found = p.matcher(line).matches(); + if (found) { + break; + } + } + Assert.assertTrue("complains about host", found); + } + + /** + * Verify handling of inconsistent peer type + */ + @Test + public void testInconsistentPeerType() throws Exception { + ClientBase.setupTestEnv(); + + // setup the logger to capture all logs + Layout layout = + Logger.getRootLogger().getAppender("CONSOLE").getLayout(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + WriterAppender appender = new WriterAppender(layout, os); + appender.setThreshold(Level.INFO); + Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum"); + qlogger.addAppender(appender); + + // test the most likely situation only: server is stated as observer in + // servers list, but there's no "peerType=observer" token in config + try { + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + final int CLIENT_PORT_QP3 = PortAssignment.unique(); + + String quorumCfgSection = + "server.1=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2 + + "\nserver.3=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":observer" + ";" + CLIENT_PORT_QP3; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); + MainThread q3 = new MainThread(3, CLIENT_PORT_QP3, quorumCfgSection); + q1.start(); + q2.start(); + q3.start(); + + Assert.assertTrue("waiting for server 1 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 3 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP3, + CONNECTION_TIMEOUT)); + + q1.shutdown(); + q2.shutdown(); + q3.shutdown(); + + Assert.assertTrue("waiting for server 1 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 3 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP3, + ClientBase.CONNECTION_TIMEOUT)); + + } finally { + qlogger.removeAppender(appender); + } + + LineNumberReader r = new LineNumberReader(new StringReader(os.toString())); + String line; + boolean warningPresent = false; + boolean defaultedToObserver = false; + Pattern pWarn = + Pattern.compile(".*Peer type from servers list.* doesn't match peerType.*"); + Pattern pObserve = Pattern.compile(".*OBSERVING.*"); + while ((line = r.readLine()) != null) { + if (pWarn.matcher(line).matches()) { + warningPresent = true; + } + if (pObserve.matcher(line).matches()) { + defaultedToObserver = true; + } + if (warningPresent && defaultedToObserver) { + break; + } + } + Assert.assertTrue("Should warn about inconsistent peer type", + warningPresent && defaultedToObserver); + } + + /** + * verify if bad packets are being handled properly + * at the quorum port + * @throws Exception + */ + @Test + public void testBadPackets() throws Exception { + ClientBase.setupTestEnv(); + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + int electionPort1 = PortAssignment.unique(); + int electionPort2 = PortAssignment.unique(); + String quorumCfgSection = + "server.1=127.0.0.1:" + PortAssignment.unique() + + ":" + electionPort1 + ";" + CLIENT_PORT_QP1 + + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + + ":" + electionPort2 + ";" + CLIENT_PORT_QP2; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); + q1.start(); + q2.start(); + + Assert.assertTrue("waiting for server 1 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + + byte[] b = new byte[4]; + int length = 1024 * 1024 * 1024; + ByteBuffer buff = ByteBuffer.wrap(b); + buff.putInt(length); + buff.position(0); + SocketChannel s = SocketChannel.open(new InetSocketAddress("127.0.0.1", electionPort1)); + s.write(buff); + s.close(); + buff.position(0); + s = SocketChannel.open(new InetSocketAddress("127.0.0.1", electionPort2)); + s.write(buff); + s.close(); + + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT, this); + waitForOne(zk, States.CONNECTED); + zk.create("/foo_q1", "foobar1".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertEquals(new String(zk.getData("/foo_q1", null, null)), "foobar1"); + zk.close(); + q1.shutdown(); + q2.shutdown(); + } + + /** + * Verify handling of quorum defaults + * * default electionAlg is fast leader election + */ + @Test + public void testQuorumDefaults() throws Exception { + ClientBase.setupTestEnv(); + + // setup the logger to capture all logs + Layout layout = + Logger.getRootLogger().getAppender("CONSOLE").getLayout(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + WriterAppender appender = new WriterAppender(layout, os); + appender.setImmediateFlush(true); + appender.setThreshold(Level.INFO); + Logger zlogger = Logger.getLogger("org.apache.zookeeper"); + zlogger.addAppender(appender); + + try { + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + + String quorumCfgSection = + "server.1=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); + q1.start(); + q2.start(); + + Assert.assertTrue("waiting for server 1 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + + q1.shutdown(); + q2.shutdown(); + + Assert.assertTrue("waiting for server 1 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT)); + + } finally { + zlogger.removeAppender(appender); + } + os.close(); + LineNumberReader r = new LineNumberReader(new StringReader(os.toString())); + String line; + boolean found = false; + Pattern p = + Pattern.compile(".*FastLeaderElection.*"); + while ((line = r.readLine()) != null) { + found = p.matcher(line).matches(); + if (found) { + break; + } + } + Assert.assertTrue("fastleaderelection used", found); + } + + /** + * Verifies that QuorumPeer exits immediately + */ + @Test + public void testQuorumPeerExitTime() throws Exception { + long maxwait = 3000; + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + String quorumCfgSection = + "server.1=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ";" + PortAssignment.unique(); + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + q1.start(); + // Let the notifications timeout + Thread.sleep(30000); + long start = Time.currentElapsedTime(); + q1.shutdown(); + long end = Time.currentElapsedTime(); + if ((end - start) > maxwait) { + Assert.fail("QuorumPeer took " + (end - start) + + " to shutdown, expected " + maxwait); + } + } + + /** + * Test verifies that the server is able to redefine the min/max session + * timeouts + */ + @Test + public void testMinMaxSessionTimeOut() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + + String quorumCfgSection = "server.1=127.0.0.1:" + + PortAssignment.unique() + ":" + PortAssignment.unique() + + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + ":" + + PortAssignment.unique(); + + final int minSessionTimeOut = 10000; + final int maxSessionTimeOut = 15000; + final String configs = "maxSessionTimeout=" + maxSessionTimeOut + "\n" + + "minSessionTimeout=" + minSessionTimeOut + "\n"; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection, + configs); + MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection, + configs); + q1.start(); + q2.start(); + + Assert.assertTrue("waiting for server 1 being up", ClientBase + .waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", ClientBase + .waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + + QuorumPeer quorumPeer = q1.main.quorumPeer; + + Assert.assertEquals("minimumSessionTimeOut is not considered", + minSessionTimeOut, quorumPeer.getMinSessionTimeout()); + Assert.assertEquals("maximumSessionTimeOut is not considered", + maxSessionTimeOut, quorumPeer.getMaxSessionTimeout()); + } + + /** + * Test verifies that the server is able to redefine if user configured only + * minSessionTimeout limit + */ + @Test + public void testWithOnlyMinSessionTimeout() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + + String quorumCfgSection = "server.1=127.0.0.1:" + + PortAssignment.unique() + ":" + PortAssignment.unique() + + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + ":" + + PortAssignment.unique(); + + final int minSessionTimeOut = 15000; + final String configs = "minSessionTimeout=" + minSessionTimeOut + "\n"; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection, + configs); + MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection, + configs); + q1.start(); + q2.start(); + + Assert.assertTrue("waiting for server 1 being up", ClientBase + .waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", ClientBase + .waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + + QuorumPeer quorumPeer = q1.main.quorumPeer; + final int maxSessionTimeOut = quorumPeer.tickTime * 20; + + Assert.assertEquals("minimumSessionTimeOut is not considered", + minSessionTimeOut, quorumPeer.getMinSessionTimeout()); + Assert.assertEquals("maximumSessionTimeOut is wrong", + maxSessionTimeOut, quorumPeer.getMaxSessionTimeout()); + } + + // This class holds the servers and clients for those servers + private static class Servers { + MainThread mt[]; + ZooKeeper zk[]; + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTest.java b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTest.java new file mode 100644 index 00000000000..b509a2f3331 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTest.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.test.ClientBase; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +public class QuorumPeerTest { + + private int electionAlg = 3; + private int tickTime = 2000; + private int initLimit = 3; + private int syncLimit = 3; + + /** + * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2301 + */ + @Test + public void testQuorumPeerListendOnSpecifiedClientIP() throws IOException { + long myId = 1; + File dataDir = ClientBase.createTmpDir(); + int clientPort = PortAssignment.unique(); + String clientIP = "127.0.0.2"; + Map peersView = new HashMap(); + + peersView.put(Long.valueOf(myId), + new QuorumServer(myId, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT)); + + /** + * QuorumPeer constructor without QuorumVerifier + */ + QuorumPeer peer1 = new QuorumPeer(peersView, dataDir, dataDir, clientPort, electionAlg, myId, tickTime, + initLimit, syncLimit); + String hostString1 = peer1.cnxnFactory.getLocalAddress().getHostString(); + assertEquals(clientIP, hostString1); + + // cleanup + peer1.shutdown(); + + /** + * QuorumPeer constructor with QuorumVerifier + */ + peersView.clear(); + clientPort = PortAssignment.unique(); + clientIP = "127.0.0.3"; + peersView.put(Long.valueOf(myId), + new QuorumServer(myId, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT)); + QuorumPeer peer2 = new QuorumPeer(peersView, dataDir, dataDir, clientPort, electionAlg, myId, tickTime, + initLimit, syncLimit); + String hostString2 = peer2.cnxnFactory.getLocalAddress().getHostString(); + assertEquals(clientIP, hostString2); + // cleanup + peer2.shutdown(); + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTestBase.java b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTestBase.java new file mode 100644 index 00000000000..893fe6ea349 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerTestBase.java @@ -0,0 +1,274 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +/** + * + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.server.admin.JettyAdminServer; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.test.QuorumBase; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.Properties; + +/** + * Has some common functionality for tests that work with QuorumPeers. Override + * process(WatchedEvent) to implement the Watcher interface + */ +public class QuorumPeerTestBase extends ZKTestCase implements Watcher { + public static final int TIMEOUT = 3000; + protected static final Logger LOG = LoggerFactory + .getLogger(QuorumPeerTestBase.class); + + public void process(WatchedEvent event) { + // ignore for this test + } + + public static class TestQPMain extends QuorumPeerMain { + public void shutdown() { + // ensure it closes - in particular wait for thread to exit + if (quorumPeer != null) { + QuorumBase.shutdown(quorumPeer); + } + } + } + + public static class MainThread implements Runnable { + public static final int UNSET_STATIC_CLIENTPORT = -1; + // standalone mode doens't need myid + public static final int UNSET_MYID = -1; + final File confFile; + final File tmpDir; + volatile TestQPMain main; + Thread currentThread; + + public MainThread(int myid, String quorumCfgSection) throws IOException { + this(myid, quorumCfgSection, true); + } + + public MainThread(int myid, String quorumCfgSection, Integer secureClientPort, boolean writeDynamicConfigFile) + throws IOException { + this(myid, UNSET_STATIC_CLIENTPORT, JettyAdminServer.DEFAULT_PORT, secureClientPort, + quorumCfgSection, null, writeDynamicConfigFile, null); + } + + public MainThread(int myid, String quorumCfgSection, boolean writeDynamicConfigFile) + throws IOException { + this(myid, UNSET_STATIC_CLIENTPORT, quorumCfgSection, writeDynamicConfigFile); + } + + public MainThread(int myid, int clientPort, String quorumCfgSection) + throws IOException { + this(myid, clientPort, JettyAdminServer.DEFAULT_PORT, quorumCfgSection, null, true); + } + + public MainThread(int myid, int clientPort, String quorumCfgSection, boolean writeDynamicConfigFile) + throws IOException { + this(myid, clientPort, JettyAdminServer.DEFAULT_PORT, quorumCfgSection, null, writeDynamicConfigFile); + } + + public MainThread(int myid, int clientPort, String quorumCfgSection, boolean writeDynamicConfigFile, + String version) throws IOException { + this(myid, clientPort, JettyAdminServer.DEFAULT_PORT, quorumCfgSection, null, + writeDynamicConfigFile, version); + } + + public MainThread(int myid, int clientPort, String quorumCfgSection, String configs) + throws IOException { + this(myid, clientPort, JettyAdminServer.DEFAULT_PORT, quorumCfgSection, configs, true); + } + + public MainThread(int myid, int clientPort, int adminServerPort, String quorumCfgSection, + String configs) throws IOException { + this(myid, clientPort, adminServerPort, quorumCfgSection, configs, true); + } + + public MainThread(int myid, int clientPort, int adminServerPort, String quorumCfgSection, + String configs, boolean writeDynamicConfigFile) + throws IOException { + this(myid, clientPort, adminServerPort, quorumCfgSection, configs, writeDynamicConfigFile, null); + } + + public MainThread(int myid, int clientPort, int adminServerPort, String quorumCfgSection, + String configs, boolean writeDynamicConfigFile, String version) throws IOException { + this(myid, clientPort, adminServerPort, null, quorumCfgSection, configs, writeDynamicConfigFile, version); + } + + public MainThread(int myid, int clientPort, int adminServerPort, Integer secureClientPort, + String quorumCfgSection, String configs, boolean writeDynamicConfigFile, String version) + throws IOException { + tmpDir = ClientBase.createTmpDir(); + LOG.info("id = " + myid + " tmpDir = " + tmpDir + " clientPort = " + + clientPort + " adminServerPort = " + adminServerPort); + + File dataDir = new File(tmpDir, "data"); + if (!dataDir.mkdir()) { + throw new IOException("Unable to mkdir " + dataDir); + } + + confFile = new File(tmpDir, "zoo.cfg"); + + FileWriter fwriter = new FileWriter(confFile); + fwriter.write("tickTime=4000\n"); + fwriter.write("initLimit=10\n"); + fwriter.write("syncLimit=5\n"); + if (configs != null) { + fwriter.write(configs); + } + + // Convert windows path to UNIX to avoid problems with "\" + String dir = PathUtils.normalizeFileSystemPath(dataDir.toString()); + + fwriter.write("dataDir=" + dir + "\n"); + fwriter.write("admin.serverPort=" + adminServerPort + "\n"); + + // For backward compatibility test, some tests create dynamic configuration + // without setting client port. + // This could happen both in static file or dynamic file. + if (clientPort != UNSET_STATIC_CLIENTPORT) { + fwriter.write("clientPort=" + clientPort + "\n"); + } + + if (secureClientPort != null) { + fwriter.write("secureClientPort=" + secureClientPort + "\n"); + } + + if (writeDynamicConfigFile) { + String dynamicConfigFilename = createDynamicFile(quorumCfgSection, version); + fwriter.write("dynamicConfigFile=" + dynamicConfigFilename + "\n"); + } else { + fwriter.write(quorumCfgSection); + } + fwriter.flush(); + fwriter.close(); + + File myidFile = new File(dataDir, "myid"); + fwriter = new FileWriter(myidFile); + fwriter.write(Integer.toString(myid)); + fwriter.flush(); + fwriter.close(); + } + + private String createDynamicFile(String quorumCfgSection, String version) + throws IOException { + String filename = "zoo.cfg.dynamic"; + if (version != null) { + filename = filename + "." + version; + } + + File dynamicConfigFile = new File(tmpDir, filename); + String dynamicConfigFilename = PathUtils.normalizeFileSystemPath(dynamicConfigFile.toString()); + + FileWriter fDynamicConfigWriter = new FileWriter(dynamicConfigFile); + fDynamicConfigWriter.write(quorumCfgSection); + fDynamicConfigWriter.flush(); + fDynamicConfigWriter.close(); + + return dynamicConfigFilename; + } + + public File[] getDynamicFiles() { + return getFilesWithPrefix("zoo.cfg.dynamic"); + } + + public File[] getFilesWithPrefix(final String prefix) { + return tmpDir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.startsWith(prefix); + } + }); + } + + public File getFileByName(String filename) { + File f = new File(tmpDir.getPath(), filename); + return f.isFile() ? f : null; + } + + public void writeTempDynamicConfigFile(String nextQuorumCfgSection, String version) + throws IOException { + File nextDynamicConfigFile = new File(tmpDir, + "zoo.cfg" + QuorumPeerConfig.nextDynamicConfigFileSuffix); + FileWriter fwriter = new FileWriter(nextDynamicConfigFile); + fwriter.write(nextQuorumCfgSection + + "\n" + + "version=" + version); + fwriter.flush(); + fwriter.close(); + } + + synchronized public void start() { + main = new TestQPMain(); + currentThread = new Thread(this); + currentThread.start(); + } + + public void run() { + String args[] = new String[1]; + args[0] = confFile.toString(); + try { + main.initializeAndRun(args); + } catch (Exception e) { + // test will still fail even though we just log/ignore + LOG.error("unexpected exception in run", e); + } finally { + currentThread = null; + } + } + + public void shutdown() throws InterruptedException { + Thread t = currentThread; + if (t != null && t.isAlive()) { + main.shutdown(); + t.join(500); + } + } + + public void join(long timeout) throws InterruptedException { + Thread t = currentThread; + if (t != null) { + t.join(timeout); + } + } + + public boolean isAlive() { + Thread t = currentThread; + return t != null && t.isAlive(); + } + + public void clean() { + ClientBase.recursiveDelete(main.quorumPeer.getTxnFactory() + .getDataDir()); + } + + public boolean isQuorumPeerRunning() { + return main.quorumPeer != null; + } + + public String getPropFromStaticFile(String key) throws IOException { + Properties props = new Properties(); + props.load(new FileReader(confFile)); + return props.getProperty(key, ""); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/QuorumRequestPipelineTest.java b/src/java/test/org/apache/zookeeper/server/quorum/QuorumRequestPipelineTest.java new file mode 100644 index 00000000000..b7cc35eb74e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/QuorumRequestPipelineTest.java @@ -0,0 +1,183 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.ZKParameterized; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.test.QuorumBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +@RunWith(Parameterized.class) +@Parameterized.UseParametersRunnerFactory(ZKParameterized.RunnerFactory.class) +public class QuorumRequestPipelineTest extends QuorumBase { + protected final static String PARENT_PATH = "/foo"; + protected final static HashSet CHILDREN = new HashSet(Arrays.asList("1", "2", "3")); + protected final static String AUTH_PROVIDER = "digest"; + protected final static byte[] AUTH = "hello".getBytes(); + protected final static byte[] DATA = "Hint Water".getBytes(); + protected final CountDownLatch callComplete = new CountDownLatch(1); + protected ServerState serverState; + protected boolean complete = false; + protected TestableZooKeeper zkClient; + + public QuorumRequestPipelineTest(ServerState state) { + this.serverState = state; + } + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList( + new Object[][]{ + {ServerState.LEADING}, + {ServerState.FOLLOWING}, + {ServerState.OBSERVING}}); + } + + @Before + public void setUp() throws Exception { + CountdownWatcher clientWatch = new CountdownWatcher(); + super.setUp(true); + zkClient = createClient(clientWatch, getPeersMatching(serverState)); + zkClient.addAuthInfo(AUTH_PROVIDER, AUTH); + clientWatch.waitForConnected(CONNECTION_TIMEOUT); + } + + @After + public void tearDown() throws Exception { + zkClient.close(); + super.tearDown(); + } + + private Stat create2EmptyNode(TestableZooKeeper zkClient, String path) throws Exception { + Stat stat = new Stat(); + zkClient.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, stat); + return stat; + } + + @Test + public void testCreate() throws Exception { + zkClient.create(PARENT_PATH, DATA, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertArrayEquals( + String.format("%s Node created (create) with expected value", serverState), + DATA, + zkClient.getData(PARENT_PATH, false, null)); + } + + @Test + public void testCreate2() throws Exception { + zkClient.create(PARENT_PATH, DATA, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, null); + Assert.assertArrayEquals( + String.format("%s Node created (create2) with expected value", serverState), + DATA, + zkClient.getData(PARENT_PATH, false, null)); + } + + @Test + public void testDelete() throws Exception { + create2EmptyNode(zkClient, PARENT_PATH); + zkClient.delete(PARENT_PATH, -1); + Assert.assertNull( + String.format("%s Node no longer exists", serverState), + zkClient.exists(PARENT_PATH, false)); + } + + @Test + public void testExists() throws Exception { + Stat stat = create2EmptyNode(zkClient, PARENT_PATH); + Assert.assertEquals( + String.format("%s Exists returns correct node stat", serverState), + stat, + zkClient.exists(PARENT_PATH, false)); + } + + @Test + public void testSetAndGetData() throws Exception { + create2EmptyNode(zkClient, PARENT_PATH); + zkClient.setData(PARENT_PATH, DATA, -1); + Assert.assertArrayEquals( + String.format("%s Node updated with expected value", serverState), + DATA, + zkClient.getData(PARENT_PATH, false, null)); + } + + @Test + public void testSetAndGetACL() throws Exception { + create2EmptyNode(zkClient, PARENT_PATH); + Assert.assertEquals( + String.format("%s Node has open ACL", serverState), + Ids.OPEN_ACL_UNSAFE, + zkClient.getACL(PARENT_PATH, new Stat())); + zkClient.setACL(PARENT_PATH, Ids.READ_ACL_UNSAFE, -1); + Assert.assertEquals( + String.format("%s Node has world read-only ACL", serverState), + Ids.READ_ACL_UNSAFE, + zkClient.getACL(PARENT_PATH, new Stat())); + } + + @Test + public void testSetAndGetChildren() throws Exception { + create2EmptyNode(zkClient, PARENT_PATH); + for (String child : CHILDREN) { + create2EmptyNode(zkClient, PARENT_PATH + "/" + child); + } + Assert.assertEquals( + String.format("%s Parent has expected children", serverState), + CHILDREN, + new HashSet(zkClient.getChildren(PARENT_PATH, false))); + } + + @Test + public void testSetAndGetChildren2() throws Exception { + create2EmptyNode(zkClient, PARENT_PATH); + for (String child : CHILDREN) { + create2EmptyNode(zkClient, PARENT_PATH + "/" + child); + } + Assert.assertEquals( + String.format("%s Parent has expected children", serverState), + CHILDREN, + new HashSet(zkClient.getChildren(PARENT_PATH, false, null))); + } + + @Test + public void testSync() throws Exception { + complete = false; + create2EmptyNode(zkClient, PARENT_PATH); + VoidCallback onSync = new VoidCallback() { + @Override + public void processResult(int rc, String path, Object ctx) { + complete = true; + callComplete.countDown(); + } + }; + zkClient.sync(PARENT_PATH, onSync, null); + callComplete.await(30, TimeUnit.SECONDS); + Assert.assertTrue( + String.format("%s Sync completed", serverState), + complete); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java b/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java new file mode 100644 index 00000000000..d06b299ac71 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class QuorumServerTest extends ZKTestCase { + @Test + public void testToString() throws ConfigException { + String config = "127.0.0.1:1234:1236:participant;0.0.0.0:1237"; + String expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237"; + QuorumServer qs = new QuorumServer(0, config); + Assert.assertEquals("Use IP address", expected, qs.toString()); + + config = "127.0.0.1:1234:1236;0.0.0.0:1237"; + expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237"; + qs = new QuorumServer(0, config); + Assert.assertEquals("Type unspecified", expected, qs.toString()); + + config = "127.0.0.1:1234:1236:observer;0.0.0.0:1237"; + expected = "127.0.0.1:1234:1236:observer;0.0.0.0:1237"; + qs = new QuorumServer(0, config); + Assert.assertEquals("Observer type", expected, qs.toString()); + + config = "127.0.0.1:1234:1236:participant;1237"; + expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237"; + qs = new QuorumServer(0, config); + Assert.assertEquals("Client address unspecified", + expected, qs.toString()); + + config = "127.0.0.1:1234:1236:participant;1.2.3.4:1237"; + expected = "127.0.0.1:1234:1236:participant;1.2.3.4:1237"; + qs = new QuorumServer(0, config); + Assert.assertEquals("Client address specified", + expected, qs.toString()); + + config = "example.com:1234:1236:participant;1237"; + expected = "example.com:1234:1236:participant;0.0.0.0:1237"; + qs = new QuorumServer(0, config); + Assert.assertEquals("Use hostname", expected, qs.toString()); + } + + @Test + public void constructionUnderstandsIpv6LiteralsInServerConfig() throws ConfigException { + String config = "[::1]:1234:1236:participant"; + QuorumServer qs = new QuorumServer(0, config); + assertEquals("[0:0:0:0:0:0:0:1]:1234:1236:participant", qs.toString()); + } + + @Test + public void constructionUnderstandsIpv6LiteralsInClientConfig() throws ConfigException { + String config = "127.0.0.1:1234:1236:participant;[::1]:1237"; + QuorumServer qs = new QuorumServer(0, config); + assertEquals("127.0.0.1:1234:1236:participant;[0:0:0:0:0:0:0:1]:1237", qs.toString()); + } + + @Test(expected = ConfigException.class) + public void unbalancedIpv6LiteralsInServerConfigFailToBeParsed() throws ConfigException { + new QuorumServer(0, "[::1:1234:1236:participant"); + } + + @Test(expected = ConfigException.class) + public void unbalancedIpv6LiteralsInClientConfigFailToBeParsed() throws ConfigException { + new QuorumServer(0, "127.0.0.1:1234:1236:participant;[::1:1237"); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java new file mode 100644 index 00000000000..77745b67483 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigBackupTest.java @@ -0,0 +1,348 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.StringUtils; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.test.ReconfigTest; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.Scanner; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class ReconfigBackupTest extends QuorumPeerTestBase { + + public static String getVersionFromConfigStr(String config) throws IOException { + Properties props = new Properties(); + props.load(new StringReader(config)); + return props.getProperty("version", ""); + } + + // upgrade this once we have Google-Guava or Java 7+ + public static String getFileContent(File file) throws FileNotFoundException { + Scanner sc = new Scanner(file); + StringBuilder sb = new StringBuilder(); + while (sc.hasNextLine()) { + sb.append(sc.nextLine() + "\n"); + } + return sb.toString(); + } + + @Before + public void setup() { + ClientBase.setupTestEnv(); + } + + /** + * This test checks that it will backup static file on bootup. + */ + @Test + public void testBackupStatic() throws Exception { + final int SERVER_COUNT = 3; + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + String server; + + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;localhost:" + + clientPorts[i]; + sb.append(server + "\n"); + } + String currentQuorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + String[] staticFileContent = new String[SERVER_COUNT]; + String[] staticBackupContent = new String[SERVER_COUNT]; + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, false); + // check that a dynamic configuration file doesn't exist + Assert.assertNull("static file backup shouldn't exist before bootup", + mt[i].getFileByName("zoo.cfg.bak")); + staticFileContent[i] = getFileContent(mt[i].confFile); + mt[i].start(); + } + + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + File backupFile = mt[i].getFileByName("zoo.cfg.bak"); + Assert.assertNotNull("static file backup should exist", backupFile); + staticBackupContent[i] = getFileContent(backupFile); + Assert.assertEquals(staticFileContent[i], staticBackupContent[i]); + } + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + } + } + + /** + * This test checks that on reconfig, a new dynamic file will be created with + * current version appended to file name. Meanwhile, the dynamic file pointer + * in static config file should also be changed. + */ + @Test + public void testReconfigCreateNewVersionFile() throws Exception { + final int SERVER_COUNT = 3; + final int NEW_SERVER_COUNT = 5; + + final int clientPorts[] = new int[NEW_SERVER_COUNT]; + final int quorumPorts[] = new int[NEW_SERVER_COUNT]; + final int electionPorts[] = new int[NEW_SERVER_COUNT]; + final String servers[] = new String[NEW_SERVER_COUNT]; + + StringBuilder sb = new StringBuilder(); + ArrayList oldServers = new ArrayList(); + ArrayList newServers = new ArrayList(); + + for (int i = 0; i < NEW_SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + quorumPorts[i] = PortAssignment.unique(); + electionPorts[i] = PortAssignment.unique(); + servers[i] = "server." + i + "=localhost:" + quorumPorts[i] + + ":" + electionPorts[i] + ":participant;localhost:" + + clientPorts[i]; + + newServers.add(servers[i]); + + if (i >= SERVER_COUNT) { + continue; + } + oldServers.add(servers[i]); + sb.append(servers[i] + "\n"); + } + String quorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[NEW_SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[NEW_SERVER_COUNT]; + + // start old cluster + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection); + mt[i].start(); + } + + String firstVersion = null, secondVersion = null; + + // test old cluster + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + + Properties cfg = ReconfigLegacyTest.readPropertiesFromFile(mt[i].confFile); + String filename = cfg.getProperty("dynamicConfigFile", ""); + + String version = QuorumPeerConfig.getVersionFromFilename(filename); + Assert.assertNotNull(version); + + String configStr = ReconfigTest.testServerHasConfig( + zk[i], oldServers, null); + + String configVersion = getVersionFromConfigStr(configStr); + // the version appended to filename should be the same as + // the one of quorum verifier. + Assert.assertEquals(version, configVersion); + + if (i == 0) { + firstVersion = version; + } else { + Assert.assertEquals(firstVersion, version); + } + } + + ReconfigTest.reconfig(zk[1], null, null, newServers, -1); + + // start additional new servers + for (int i = SERVER_COUNT; i < NEW_SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection + servers[i]); + mt[i].start(); + } + + // wait for new servers to be up running + for (int i = SERVER_COUNT; i < NEW_SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + + // test that all servers have: + // a different, larger version dynamic file + for (int i = 0; i < NEW_SERVER_COUNT; i++) { + Properties cfg = ReconfigLegacyTest.readPropertiesFromFile(mt[i].confFile); + String filename = cfg.getProperty("dynamicConfigFile", ""); + + String version = QuorumPeerConfig.getVersionFromFilename(filename); + Assert.assertNotNull(version); + + String configStr = ReconfigTest.testServerHasConfig(zk[i], + newServers, null); + + String quorumVersion = getVersionFromConfigStr(configStr); + Assert.assertEquals(version, quorumVersion); + + if (i == 0) { + secondVersion = version; + Assert.assertTrue( + Long.parseLong(secondVersion, 16) + > Long.parseLong(firstVersion, 16)); + } else { + Assert.assertEquals(secondVersion, version); + } + } + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + zk[i].close(); + } + } + + /** + * This test checks that if a version is appended to dynamic file, + * then peer should use that version as quorum config version. + *

        + * The scenario: one server has an older version of 3 servers, and + * four others have newer version of 5 servers. Finally, the lag-off one + * should have server config of 5 servers. + */ + @Test + public void testVersionOfDynamicFilename() throws Exception { + final int SERVER_COUNT = 5; + final int oldServerCount = 3; + final int lagOffServerId = 0; + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + String server; + StringBuilder oldSb = new StringBuilder(); + ArrayList allServers = new ArrayList(); + + + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;localhost:" + + clientPorts[i]; + sb.append(server + "\n"); + allServers.add(server); + + if (i < oldServerCount) { + // only take in the first 3 servers as old quorum config. + oldSb.append(server + "\n"); + } + } + + String currentQuorumCfgSection = sb.toString(); + + String oldQuorumCfg = oldSb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + + + for (int i = 0; i < SERVER_COUNT; i++) { + if (i == lagOffServerId) { + mt[i] = new MainThread(i, clientPorts[i], oldQuorumCfg, true, "100000000"); + } else { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, + true, "200000000"); + } + + // before connecting to quorum, servers should have set up dynamic file + // version and pointer. And the lag-off server is using the older + // version dynamic file. + if (i == lagOffServerId) { + Assert.assertNotNull( + mt[i].getFileByName("zoo.cfg.dynamic.100000000")); + Assert.assertNull( + mt[i].getFileByName("zoo.cfg.dynamic.200000000")); + Assert.assertTrue( + mt[i].getPropFromStaticFile("dynamicConfigFile") + .endsWith(".100000000")); + } else { + Assert.assertNotNull( + mt[i].getFileByName("zoo.cfg.dynamic.200000000")); + Assert.assertTrue( + mt[i].getPropFromStaticFile("dynamicConfigFile") + .endsWith(".200000000")); + } + + mt[i].start(); + } + + String dynamicFileContent = null; + + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + + // we should see that now all servers have the same config of 5 servers + // including the lag-off server. + String configStr = ReconfigTest.testServerHasConfig(zk, allServers, null); + Assert.assertEquals("200000000", getVersionFromConfigStr(configStr)); + + List configLines = Arrays.asList(configStr.split("\n")); + Collections.sort(configLines); + String sortedConfigStr = StringUtils.joinStrings(configLines, "\n"); + + File dynamicConfigFile = mt[i].getFileByName("zoo.cfg.dynamic.200000000"); + Assert.assertNotNull(dynamicConfigFile); + + // All dynamic files created with the same version should have + // same configs, and they should be equal to the config we get from QuorumPeer. + if (i == 0) { + dynamicFileContent = getFileContent(dynamicConfigFile); + Assert.assertEquals(sortedConfigStr, dynamicFileContent + + "version=200000000"); + } else { + String otherDynamicFileContent = getFileContent(dynamicConfigFile); + Assert.assertEquals(dynamicFileContent, otherDynamicFileContent); + } + + zk.close(); + } + + // finally, we should also check that the lag-off server has updated + // the dynamic file pointer. + Assert.assertTrue( + mt[lagOffServerId].getPropFromStaticFile("dynamicConfigFile") + .endsWith(".200000000")); + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + } + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java new file mode 100644 index 00000000000..f5f222778d7 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java @@ -0,0 +1,261 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.NewConfigNoQuorum; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.test.QuorumUtil; +import org.apache.zookeeper.test.ReconfigTest; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class ReconfigFailureCasesTest extends QuorumPeerTestBase { + + private QuorumUtil qu; + + @After + public void tearDown() throws Exception { + if (qu != null) { + qu.tearDown(); + } + } + + /* + * Tests that an incremental reconfig fails if the current config is hiearchical. + */ + @Test + public void testIncrementalReconfigInvokedOnHiearchicalQS() throws Exception { + qu = new QuorumUtil(2); // create 5 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = ReconfigTest.createHandles(qu); + + ArrayList members = new ArrayList(); + members.add("group.1=3:4:5"); + members.add("group.2=1:2"); + members.add("weight.1=0"); + members.add("weight.2=0"); + members.add("weight.3=1"); + members.add("weight.4=1"); + members.add("weight.5=1"); + + for (int i = 1; i <= 5; i++) { + members.add("server." + i + "=127.0.0.1:" + + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":" + + qu.getPeer(i).peer.getElectionAddress().getPort() + ";" + + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort()); + } + + // Change the quorum system from majority to hierarchical. + ReconfigTest.reconfig(zkArr[1], null, null, members, -1); + ReconfigTest.testNormalOperation(zkArr[1], zkArr[2]); + + // Attempt an incremental reconfig. + List leavingServers = new ArrayList(); + leavingServers.add("3"); + try { + zkArr[1].reconfig(null, leavingServers, null, -1, null); + Assert.fail("Reconfig should have failed since the current config isn't Majority QS"); + } catch (KeeperException.BadArgumentsException e) { + // We expect this to happen. + } catch (Exception e) { + Assert.fail("Should have been BadArgumentsException!"); + } + + ReconfigTest.closeAllHandles(zkArr); + } + + /* + * Test that a reconfiguration fails if the proposed change would leave the + * cluster with less than 2 participants (StandaloneEnabled = true). + * StandaloneDisabledTest.java (startSingleServerTest) checks that if + * StandaloneEnabled = false its legal to remove all but one remaining + * server. + */ + @Test + public void testTooFewRemainingPariticipants() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = ReconfigTest.createHandles(qu); + + List leavingServers = new ArrayList(); + leavingServers.add("2"); + leavingServers.add("3"); + try { + zkArr[1].reconfig(null, leavingServers, null, -1, null); + Assert.fail("Reconfig should have failed since the current config version is not 8"); + } catch (KeeperException.BadArgumentsException e) { + // We expect this to happen. + } catch (Exception e) { + Assert.fail("Should have been BadArgumentsException!"); + } + + ReconfigTest.closeAllHandles(zkArr); + } + + /* + * Tests that a conditional reconfig fails if the specified version doesn't correspond + * to the version of the current config. + */ + @Test + public void testReconfigVersionConditionFails() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = ReconfigTest.createHandles(qu); + + List leavingServers = new ArrayList(); + leavingServers.add("3"); + try { + zkArr[1].reconfig(null, leavingServers, null, 8, null); + Assert.fail("Reconfig should have failed since the current config version is not 8"); + } catch (KeeperException.BadVersionException e) { + // We expect this to happen. + } catch (Exception e) { + Assert.fail("Should have been BadVersionException!"); + } + + ReconfigTest.closeAllHandles(zkArr); + } + + /* + * Tests that if a quorum of a new config is synced with the leader and a reconfig + * is allowed to start but then the new quorum is lost, the leader will time out and + * we go to leader election. + */ + @Test + public void testLeaderTimesoutOnNewQuorum() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = ReconfigTest.createHandles(qu); + + List leavingServers = new ArrayList(); + leavingServers.add("3"); + qu.shutdown(2); + try { + // Since we just shut down server 2, its still considered "synced" + // by the leader, which allows us to start the reconfig + // (PrepRequestProcessor checks that a quorum of the new + // config is synced before starting a reconfig). + // We try to remove server 3, which requires a quorum of {1,2,3} + // (we have that) and of {1,2}, but 2 is down so we won't get a + // quorum of new config ACKs. + zkArr[1].reconfig(null, leavingServers, null, -1, null); + Assert.fail("Reconfig should have failed since we don't have quorum of new config"); + } catch (KeeperException.ConnectionLossException e) { + // We expect leader to lose quorum of proposed config and time out + } catch (Exception e) { + Assert.fail("Should have been ConnectionLossException!"); + } + + // The leader should time out and remaining servers should go into + // LOOKING state. A new leader won't be established since that + // would require completing the reconfig, which is not possible while + // 2 is down. + Assert.assertEquals(QuorumStats.Provider.LOOKING_STATE, + qu.getPeer(1).peer.getServerState()); + Assert.assertEquals(QuorumStats.Provider.LOOKING_STATE, + qu.getPeer(3).peer.getServerState()); + ReconfigTest.closeAllHandles(zkArr); + } + + /* + * Converting an observer into a participant may sometimes fail with a + * NewConfigNoQuorum exception. This test-case demonstrates the scenario. + * Current configuration is (A, B, C, D), where A, B and C are participant + * and D is an observer. Suppose that B has crashed (or never booted). If a + * reconfiguration is submitted where D is said to become a participant, it + * will fail with NewConfigNoQuorum since in this configuration, a majority + * of voters in the new configuration (any 3 voters), must be connected and + * up-to-date with the leader. An observer cannot acknowledge the history + * prefix sent during reconfiguration, and therefore it does not count towards + * these 3 required servers and the reconfiguration will be aborted. In case + * this happens, a client can achieve the same task by two reconfig commands: + * first invoke a reconfig to remove D from the configuration and then invoke a + * second command to add it back as a participant (follower). During the + * intermediate state D is a non-voting follower and can ACK the state + * transfer performed during the second reconfig command. + */ + @Test + public void testObserverToParticipantConversionFails() throws Exception { + ClientBase.setupTestEnv(); + + final int SERVER_COUNT = 4; + int[][] ports = ReconfigRecoveryTest.generatePorts(SERVER_COUNT); + + // generate old config string + HashSet observers = new HashSet(); + observers.add(3); + StringBuilder sb = ReconfigRecoveryTest.generateConfig(SERVER_COUNT, ports, observers); + String currentQuorumCfgSection = sb.toString(); + String nextQuorumCfgSection = currentQuorumCfgSection.replace("observer", "participant"); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + + // Server 0 stays down + for (int i = 1; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, ports[i][2], currentQuorumCfgSection, + true, "100000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + ports[i][2], + ClientBase.CONNECTION_TIMEOUT, this); + } + + for (int i = 1; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + ports[i][2], + CONNECTION_TIMEOUT * 2)); + } + + try { + zk[1].reconfig("", "", nextQuorumCfgSection, -1, new Stat()); + Assert.fail("Reconfig should have failed with NewConfigNoQuorum"); + } catch (NewConfigNoQuorum e) { + // This is expected case since server 0 is down and 3 can't vote + // (observer in current role) and we need 3 votes from 0, 1, 2, 3, + } catch (Exception e) { + Assert.fail("Reconfig should have failed with NewConfigNoQuorum"); + } + // In this scenario to change 3's role to participant we need to remove it first + ArrayList leavingServers = new ArrayList(); + leavingServers.add("3"); + ReconfigTest.reconfig(zk[1], null, leavingServers, null, -1); + ReconfigTest.testNormalOperation(zk[2], zk[3]); + ReconfigTest.testServerHasConfig(zk[3], null, leavingServers); + + // Now we're adding it back as a participant and everything should work. + List newMembers = Arrays.asList(nextQuorumCfgSection.split("\n")); + ReconfigTest.reconfig(zk[1], null, null, newMembers, -1); + ReconfigTest.testNormalOperation(zk[2], zk[3]); + for (int i = 1; i < SERVER_COUNT; i++) { + ReconfigTest.testServerHasConfig(zk[i], newMembers, null); + } + for (int i = 1; i < SERVER_COUNT; i++) { + zk[i].close(); + mt[i].shutdown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java new file mode 100644 index 00000000000..2f8d0113801 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java @@ -0,0 +1,305 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.apache.zookeeper.test.ReconfigTest; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Properties; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; +import static org.junit.Assert.assertEquals; + +public class ReconfigLegacyTest extends QuorumPeerTestBase { + + private static final int SERVER_COUNT = 3; + + public static Properties readPropertiesFromFile(File file) throws IOException { + Properties cfg = new Properties(); + FileInputStream in = new FileInputStream(file); + try { + cfg.load(in); + } finally { + in.close(); + } + return cfg; + } + + @Before + public void setup() { + ClientBase.setupTestEnv(); + } + + /** + * This test checks that when started with a single static config file the + * servers will create a valid dynamic config file. Also checks that when + * the static config includes a clientPort but the dynamic definition also + * includes it, the static definition is erased. + */ + @Test + public void testConfigFileBackwardCompatibility() throws Exception { + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + String server; + ArrayList allServers = new ArrayList(); + + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;localhost:" + + clientPorts[i]; + allServers.add(server); + sb.append(server + "\n"); + } + String currentQuorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + + // Start the servers with a static config file, without a dynamic + // config file. + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, false); + // check that a dynamic configuration file doesn't exist + Assert.assertEquals(mt[i].getDynamicFiles().length, 0); + mt[i].start(); + } + // Check that the servers are up, have the right config and can process operations. + // Check that the static config was split into static and dynamic files correctly. + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + File[] dynamicFiles = mt[i].getDynamicFiles(); + + Assert.assertTrue(dynamicFiles.length == 1); + ReconfigTest.testServerHasConfig(zk[i], allServers, null); + // check that static config file doesn't include membership info + // and has a pointer to the dynamic configuration file + Properties cfg = readPropertiesFromFile(mt[i].confFile); + for (int j = 0; j < SERVER_COUNT; j++) { + Assert.assertFalse(cfg.containsKey("server." + j)); + } + Assert.assertTrue(cfg.containsKey("dynamicConfigFile")); + Assert.assertFalse(cfg.containsKey("clientPort")); + + // check that the dynamic configuration file contains the membership info + cfg = readPropertiesFromFile(dynamicFiles[0]); + for (int j = 0; j < SERVER_COUNT; j++) { + String serverLine = cfg.getProperty("server." + j, ""); + Assert.assertEquals(allServers.get(j), "server." + j + "=" + + serverLine); + } + Assert.assertFalse(cfg.containsKey("dynamicConfigFile")); + } + ReconfigTest.testNormalOperation(zk[0], zk[1]); + + // now shut down the servers and restart them + for (int i = 0; i < SERVER_COUNT; i++) { + zk[i].close(); + mt[i].shutdown(); + } + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].start(); + } + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + ReconfigTest.testServerHasConfig(zk[i], allServers, null); + } + ReconfigTest.testNormalOperation(zk[0], zk[1]); + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + zk[i].close(); + } + } + + /** + * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1992} + * 1. When a server starts from old style static config, without a client port in the server + * specification, it should keep the client port in static config file. + * 2. After port reconfig, the old port should be removed from static file + * and new port added to dynamic file. + * @throws Exception + */ + @Test + public void testReconfigRemoveClientFromStatic() throws Exception { + final int clientPorts[] = new int[SERVER_COUNT]; + final int quorumPorts[] = new int[SERVER_COUNT]; + final int electionPorts[] = new int[SERVER_COUNT]; + + final int changedServerId = 0; + final int newClientPort = PortAssignment.unique(); + + StringBuilder sb = new StringBuilder(); + ArrayList allServers = new ArrayList(); + ArrayList newServers = new ArrayList(); + + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + quorumPorts[i] = PortAssignment.unique(); + electionPorts[i] = PortAssignment.unique(); + + String server = "server." + i + "=localhost:" + quorumPorts[i] + + ":" + electionPorts[i] + ":participant"; + allServers.add(server); + sb.append(server + "\n"); + + if (i == changedServerId) { + newServers.add(server + ";0.0.0.0:" + newClientPort); + } else { + newServers.add(server); + } + } + String quorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + + // Start the servers with a static config file, without a dynamic config file. + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection, false); + mt[i].start(); + } + + // Check that when a server starts from old style config, it should keep the client + // port in static config file. + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + + ReconfigTest.testServerHasConfig(zk[i], allServers, null); + Properties cfg = readPropertiesFromFile(mt[i].confFile); + + Assert.assertTrue(cfg.containsKey("dynamicConfigFile")); + Assert.assertTrue(cfg.containsKey("clientPort")); + } + ReconfigTest.testNormalOperation(zk[0], zk[1]); + + ReconfigTest.reconfig(zk[1], null, null, newServers, -1); + ReconfigTest.testNormalOperation(zk[0], zk[1]); + + // Sleep since writing the config files may take time. + Thread.sleep(1000); + + // Check that new dynamic config includes the updated client port. + // Check that server changedServerId erased clientPort from static config. + // Check that other servers still have clientPort in static config. + + for (int i = 0; i < SERVER_COUNT; i++) { + ReconfigTest.testServerHasConfig(zk[i], newServers, null); + Properties staticCfg = readPropertiesFromFile(mt[i].confFile); + if (i == changedServerId) { + Assert.assertFalse(staticCfg.containsKey("clientPort")); + } else { + Assert.assertTrue(staticCfg.containsKey("clientPort")); + } + } + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + zk[i].close(); + } + } + + /** + * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2244 + * + * @throws Exception + */ + @Test(timeout = 120000) + public void testRestartZooKeeperServer() throws Exception { + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + String server; + + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=127.0.0.1:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;127.0.0.1:" + + clientPorts[i]; + sb.append(server + "\n"); + } + String currentQuorumCfgSection = sb.toString(); + MainThread mt[] = new MainThread[SERVER_COUNT]; + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, + false); + mt[i].start(); + } + + // ensure server started + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + } + + CountdownWatcher watch1 = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[0], + ClientBase.CONNECTION_TIMEOUT, watch1); + watch1.waitForConnected(ClientBase.CONNECTION_TIMEOUT); + + String zNodePath = "/serverRestartTest"; + String data = "originalData"; + zk.create(zNodePath, data.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.close(); + + /** + * stop two servers out of three and again start them + */ + mt[0].shutdown(); + mt[1].shutdown(); + mt[0].start(); + mt[1].start(); + // ensure server started + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + } + CountdownWatcher watch2 = new CountdownWatcher(); + zk = new ZooKeeper("127.0.0.1:" + clientPorts[0], + ClientBase.CONNECTION_TIMEOUT, watch2); + watch2.waitForConnected(ClientBase.CONNECTION_TIMEOUT); + + byte[] dataBytes = zk.getData(zNodePath, null, null); + String receivedData = new String(dataBytes); + assertEquals(data, receivedData); + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigRecoveryTest.java b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigRecoveryTest.java new file mode 100644 index 00000000000..97c5ee7467e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigRecoveryTest.java @@ -0,0 +1,571 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.test.ReconfigTest; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashSet; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class ReconfigRecoveryTest extends QuorumPeerTestBase { + /* + * Generates 3 ports per server + */ + public static int[][] generatePorts(int numServers) { + int[][] ports = new int[numServers][]; + for (int i = 0; i < numServers; i++) { + ports[i] = new int[3]; + for (int j = 0; j < 3; j++) { + ports[i][j] = PortAssignment.unique(); + } + } + return ports; + } + + /* + * Creates a configuration string for servers 0..numServers-1 Ids in + * observerIds correspond to observers, other ids are for participants. + */ + public static StringBuilder generateConfig(int numServers, int[][] ports, + HashSet observerIds) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numServers; i++) { + String server = "server." + i + "=localhost:" + ports[i][0] + ":" + + ports[i][1] + ":" + + (observerIds.contains(i) ? "observer" : "participant") + + ";localhost:" + ports[i][2]; + sb.append(server + "\n"); + } + return sb; + } + + /** + * Reconfiguration recovery - test that a reconfiguration is completed if + * leader has .next file during startup and new config is not running yet + */ + @Test + public void testNextConfigCompletion() throws Exception { + ClientBase.setupTestEnv(); + + // 2 servers in current config, 3 in next config + final int SERVER_COUNT = 3; + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + String server; + ArrayList allServers = new ArrayList(); + + String currentQuorumCfgSection = null, nextQuorumCfgSection; + + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;localhost:" + + clientPorts[i]; + allServers.add(server); + sb.append(server + "\n"); + if (i == 1) + currentQuorumCfgSection = sb.toString(); + } + nextQuorumCfgSection = sb.toString(); + + // Both servers 0 and 1 will have the .next config file, which means + // for them that a reconfiguration was in progress when they failed + // and the leader will complete it + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + for (int i = 0; i < SERVER_COUNT - 1; i++) { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, + true, "100000000"); + // note that we should run the server, shut it down and only then + // simulate a reconfig in progress by writing the temp file, but here no + // other server is competing with them in FLE, so we can skip this step + // (server 2 is booted after FLE ends) + mt[i].writeTempDynamicConfigFile(nextQuorumCfgSection, "200000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + + Assert.assertTrue("waiting for server 0 being up", ClientBase + .waitForServerUp("127.0.0.1:" + clientPorts[0], + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 1 being up", ClientBase + .waitForServerUp("127.0.0.1:" + clientPorts[1], + CONNECTION_TIMEOUT)); + + int leader = mt[0].main.quorumPeer.leader == null ? 1 : 0; + + // the new server's config is going to include itself and the current leader + sb = new StringBuilder(); + sb.append(allServers.get(leader) + "\n"); + sb.append(allServers.get(2) + "\n"); + + // suppose that this new server never heard about the reconfig proposal + String newServerInitialConfig = sb.toString(); + mt[2] = new MainThread(2, clientPorts[2], newServerInitialConfig); + mt[2].start(); + zk[2] = new ZooKeeper("127.0.0.1:" + clientPorts[2], + ClientBase.CONNECTION_TIMEOUT, this); + + Assert.assertTrue("waiting for server 2 being up", ClientBase + .waitForServerUp("127.0.0.1:" + clientPorts[2], + CONNECTION_TIMEOUT)); + + ReconfigTest.testServerHasConfig(zk[0], allServers, null); + ReconfigTest.testServerHasConfig(zk[1], allServers, null); + ReconfigTest.testServerHasConfig(zk[2], allServers, null); + + ReconfigTest.testNormalOperation(zk[0], zk[2]); + ReconfigTest.testNormalOperation(zk[2], zk[1]); + + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i].shutdown(); + zk[i].close(); + } + } + + /** + * Reconfiguration recovery - current config servers discover .next file, + * but they're both observers and their ports change in next config. Suppose + * that next config wasn't activated yet. Should complete reconfiguration. + */ + @Test + public void testCurrentServersAreObserversInNextConfig() throws Exception { + ClientBase.setupTestEnv(); + + // 2 servers in current config, 5 in next config + final int SERVER_COUNT = 5; + final int clientPorts[] = new int[SERVER_COUNT]; + final int oldClientPorts[] = new int[2]; + StringBuilder sb = new StringBuilder(); + String server; + + String currentQuorumCfg, nextQuorumCfgSection; + + ArrayList allServersNext = new ArrayList(); + + for (int i = 0; i < 2; i++) { + oldClientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;localhost:" + + oldClientPorts[i]; + sb.append(server + "\n"); + } + + currentQuorumCfg = sb.toString(); + + sb = new StringBuilder(); + String role; + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + if (i < 2) { + role = "observer"; + } else { + role = "participant"; + } + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":" + role + + ";localhost:" + clientPorts[i]; + allServersNext.add(server); + sb.append(server + "\n"); + } + nextQuorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + + // run servers 0 and 1 normally + for (int i = 0; i < 2; i++) { + mt[i] = new MainThread(i, oldClientPorts[i], currentQuorumCfg, + true, "100000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + oldClientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + + for (int i = 0; i < 2; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp( + "127.0.0.1:" + oldClientPorts[i], + CONNECTION_TIMEOUT * 2)); + } + + ReconfigTest.testNormalOperation(zk[0], zk[1]); + + // shut them down and then simulate a reboot with a reconfig in progress + for (int i = 0; i < 2; i++) { + mt[i].shutdown(); + zk[i].close(); + } + + for (int i = 0; i < 2; i++) { + Assert.assertTrue( + "waiting for server " + i + " being up", + ClientBase.waitForServerDown("127.0.0.1:" + + oldClientPorts[i], CONNECTION_TIMEOUT * 2)); + } + + for (int i = 0; i < 2; i++) { + mt[i].writeTempDynamicConfigFile(nextQuorumCfgSection, "200000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + + // new members are initialized with current config + the new server + for (int i = 2; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfg + + allServersNext.get(i)); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT * 2)); + ReconfigTest.testServerHasConfig(zk[i], allServersNext, null); + } + + ReconfigTest.testNormalOperation(zk[0], zk[2]); + ReconfigTest.testNormalOperation(zk[4], zk[1]); + + for (int i = 0; i < SERVER_COUNT; i++) { + zk[i].close(); + mt[i].shutdown(); + } + } + + /** + * Reconfiguration recovery - test that if servers in old config have a + * .next file but no quorum of new config is up then no progress should be + * possible (no progress will happen to ensure safety as the new config + * might be actually up but partitioned from old config) + */ + @Test + public void testNextConfigUnreachable() throws Exception { + ClientBase.setupTestEnv(); + + // 2 servers in current config, 5 in next config + final int SERVER_COUNT = 5; + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + String server; + + String currentQuorumCfgSection = null, nextQuorumCfgSection; + + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;localhost:" + + clientPorts[i]; + sb.append(server + "\n"); + if (i == 1) + currentQuorumCfgSection = sb.toString(); + } + nextQuorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + + // Both servers 0 and 1 will have the .next config file, which means + // for them that a reconfiguration was in progress when they failed + for (int i = 0; i < 2; i++) { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, + true, "100000000"); + // note that we should run the server, shut it down and only then + // simulate a reconfig in progress by writing the temp file, but here no + // other server is competing with them in FLE, so we can skip this step + mt[i].writeTempDynamicConfigFile(nextQuorumCfgSection, "200000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + + Thread.sleep(CONNECTION_TIMEOUT * 2); + + // make sure servers 0, 1 don't come online - this should be the case + // since they can't complete the reconfig + for (int i = 0; i < 2; i++) { + Assert.assertFalse("server " + i + " is up but shouldn't be", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT / 10)); + } + + for (int i = 0; i < 2; i++) { + zk[i].close(); + mt[i].shutdown(); + } + } + + /** + * Reconfiguration recovery - test that old config members will join the new + * config if its already active, and not try to complete the reconfiguration + */ + @Test + public void testNextConfigAlreadyActive() throws Exception { + ClientBase.setupTestEnv(); + + // 2 servers in current config, 5 in next config + final int SERVER_COUNT = 5; + final int clientPorts[] = new int[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + String server; + + String currentQuorumCfgSection = null, nextQuorumCfgSection; + + ArrayList allServers = new ArrayList(); + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;localhost:" + + clientPorts[i]; + allServers.add(server); + sb.append(server + "\n"); + if (i == 1) currentQuorumCfgSection = sb.toString(); + } + nextQuorumCfgSection = sb.toString(); + + // lets start servers 2, 3, 4 with the new config + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + for (int i = 2; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, clientPorts[i], nextQuorumCfgSection, + true, "200000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + for (int i = 2; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT)); + } + + ReconfigTest.testNormalOperation(zk[2], zk[3]); + + long epoch = mt[2].main.quorumPeer.getAcceptedEpoch(); + + // Both servers 0 and 1 will have the .next config file, which means + // for them that a reconfiguration was in progress when they failed + // and the leader will complete it. + for (int i = 0; i < 2; i++) { + mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, + true, "100000000"); + mt[i].writeTempDynamicConfigFile(nextQuorumCfgSection, "200000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], + ClientBase.CONNECTION_TIMEOUT, this); + } + + // servers 0 and 1 should connect to all servers, including the one in + // their .next file during startup, and will find the next config and join it + for (int i = 0; i < 2; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], + CONNECTION_TIMEOUT * 2)); + } + + // make sure they joined the new config without any change to it + Assert.assertEquals(epoch, mt[0].main.quorumPeer.getAcceptedEpoch()); + Assert.assertEquals(epoch, mt[1].main.quorumPeer.getAcceptedEpoch()); + Assert.assertEquals(epoch, mt[2].main.quorumPeer.getAcceptedEpoch()); + + ReconfigTest.testServerHasConfig(zk[0], allServers, null); + ReconfigTest.testServerHasConfig(zk[1], allServers, null); + + ReconfigTest.testNormalOperation(zk[0], zk[2]); + ReconfigTest.testNormalOperation(zk[4], zk[1]); + + for (int i = 0; i < SERVER_COUNT; i++) { + zk[i].close(); + mt[i].shutdown(); + } + } + + /** + * Tests conversion of observer to participant AFTER new config was already + * committed. Old config: servers 0 (participant), 1 (participant), 2 + * (observer) New config: servers 2 (participant), 3 (participant) We start + * server 2 with old config and start server 3 with new config. All other + * servers are down. In order to terminate FLE, server 3 must 'convince' + * server 2 to adopt the new config and turn into a participant. + */ + @Test + public void testObserverConvertedToParticipantDuringFLE() throws Exception { + ClientBase.setupTestEnv(); + + final int SERVER_COUNT = 4; + int[][] ports = generatePorts(SERVER_COUNT); + String currentQuorumCfgSection, nextQuorumCfgSection; + + // generate old config string + HashSet observers = new HashSet(); + observers.add(2); + StringBuilder sb = generateConfig(3, ports, observers); + currentQuorumCfgSection = sb.toString(); + + // generate new config string + ArrayList allServersNext = new ArrayList(); + sb = new StringBuilder(); + for (int i = 2; i < SERVER_COUNT; i++) { + String server = "server." + i + "=localhost:" + ports[i][0] + ":" + + ports[i][1] + ":participant;localhost:" + ports[i][2]; + allServersNext.add(server); + sb.append(server + "\n"); + } + nextQuorumCfgSection = sb.toString(); + + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + + // start server 2 with old config, where it is an observer + mt[2] = new MainThread(2, ports[2][2], currentQuorumCfgSection, + true, "100000000"); + mt[2].start(); + zk[2] = new ZooKeeper("127.0.0.1:" + ports[2][2], + ClientBase.CONNECTION_TIMEOUT, this); + + // start server 3 with new config + mt[3] = new MainThread(3, ports[3][2], nextQuorumCfgSection, + true, "200000000"); + mt[3].start(); + zk[3] = new ZooKeeper("127.0.0.1:" + ports[3][2], + ClientBase.CONNECTION_TIMEOUT, this); + + for (int i = 2; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + ports[i][2], + CONNECTION_TIMEOUT * 2)); + ReconfigTest.testServerHasConfig(zk[i], allServersNext, null); + } + + Assert.assertEquals(nextQuorumCfgSection + "version=200000000", + ReconfigTest.testServerHasConfig(zk[2], null, null)); + Assert.assertEquals(nextQuorumCfgSection + "version=200000000", + ReconfigTest.testServerHasConfig(zk[3], null, null)); + ReconfigTest.testNormalOperation(zk[2], zk[2]); + ReconfigTest.testNormalOperation(zk[3], zk[2]); + + for (int i = 2; i < SERVER_COUNT; i++) { + zk[i].close(); + mt[i].shutdown(); + } + } + + /** + * Tests conversion of observer to participant during reconfig recovery, new + * config was not committed yet. Old config: servers 0 (participant), 1 + * (participant), 2 (observer) New config: servers 2 (participant), 3 + * (participant) We start server servers 0, 1, 2 with old config and a .next + * file indicating a reconfig in progress. We start server 3 with old config + * + itself in config file. In this scenario server 2 can't be converted to + * participant during reconfig since we don't gossip about proposed + * configurations, only about committed ones. This tests that new config can + * be completed, which requires server 2's ack for the newleader message, + * even though its an observer. + */ + @Test + public void testCurrentObserverIsParticipantInNewConfig() throws Exception { + ClientBase.setupTestEnv(); + + final int SERVER_COUNT = 4; + int[][] ports = generatePorts(SERVER_COUNT); + String currentQuorumCfg, nextQuorumCfgSection; + + // generate old config string + HashSet observers = new HashSet(); + observers.add(2); + + StringBuilder sb = generateConfig(3, ports, observers); + currentQuorumCfg = sb.toString(); + + // Run servers 0..2 for a while + MainThread mt[] = new MainThread[SERVER_COUNT]; + ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT]; + for (int i = 0; i <= 2; i++) { + mt[i] = new MainThread(i, ports[i][2], currentQuorumCfg + , true, "100000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + ports[i][2], + ClientBase.CONNECTION_TIMEOUT, this); + } + + ReconfigTest.testNormalOperation(zk[0], zk[2]); + + for (int i = 0; i <= 2; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + ports[i][2], + CONNECTION_TIMEOUT * 2)); + } + + // shut servers 0..2 down + for (int i = 0; i <= 2; i++) { + mt[i].shutdown(); + zk[i].close(); + } + + // generate new config string + ArrayList allServersNext = new ArrayList(); + sb = new StringBuilder(); + for (int i = 2; i < SERVER_COUNT; i++) { + String server = "server." + i + "=localhost:" + ports[i][0] + ":" + + ports[i][1] + ":participant;localhost:" + ports[i][2]; + allServersNext.add(server); + sb.append(server + "\n"); + } + nextQuorumCfgSection = sb.toString(); + + // simulate reconfig in progress - servers 0..2 have a temp reconfig + // file when they boot + for (int i = 0; i <= 2; i++) { + mt[i].writeTempDynamicConfigFile(nextQuorumCfgSection, "200000000"); + mt[i].start(); + zk[i] = new ZooKeeper("127.0.0.1:" + ports[i][2], + ClientBase.CONNECTION_TIMEOUT, this); + } + // new server 3 has still its invalid joiner config - everyone in old + // config + itself + mt[3] = new MainThread(3, ports[3][2], currentQuorumCfg + + allServersNext.get(1)); + mt[3].start(); + zk[3] = new ZooKeeper("127.0.0.1:" + ports[3][2], + ClientBase.CONNECTION_TIMEOUT, this); + + for (int i = 2; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + ports[i][2], + CONNECTION_TIMEOUT * 3)); + ReconfigTest.testServerHasConfig(zk[i], allServersNext, null); + } + + ReconfigTest.testNormalOperation(zk[0], zk[2]); + ReconfigTest.testNormalOperation(zk[3], zk[1]); + Assert.assertEquals(nextQuorumCfgSection + "version=200000000", + ReconfigTest.testServerHasConfig(zk[2], null, null)); + Assert.assertEquals(nextQuorumCfgSection + "version=200000000", + ReconfigTest.testServerHasConfig(zk[3], null, null)); + + for (int i = 0; i < SERVER_COUNT; i++) { + zk[i].close(); + mt[i].shutdown(); + } + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/server/quorum/RemotePeerBeanTest.java b/src/java/test/org/apache/zookeeper/server/quorum/RemotePeerBeanTest.java new file mode 100644 index 00000000000..1f025922291 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/RemotePeerBeanTest.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.junit.Test; + +import java.net.InetSocketAddress; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class RemotePeerBeanTest { + + /** + * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2269 + */ + @Test + public void testGetClientAddressShouldReturnEmptyStringWhenClientAddressIsNull() { + InetSocketAddress peerCommunicationAddress = null; + // Here peerCommunicationAddress is null, also clientAddr is null + QuorumServer peer = new QuorumServer(1, peerCommunicationAddress); + RemotePeerBean remotePeerBean = new RemotePeerBean(peer); + String clientAddress = remotePeerBean.getClientAddress(); + assertNotNull(clientAddress); + assertEquals(0, clientAddress.length()); + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java b/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java new file mode 100644 index 00000000000..55e749caa7f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java @@ -0,0 +1,247 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.test.ClientBase; +import org.apache.zookeeper.test.ReconfigTest; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class StandaloneDisabledTest extends QuorumPeerTestBase { + + private final int NUM_SERVERS = 5; + private final int leaderId = 0; + private final int follower1 = 1; + private final int follower2 = 2; + private final int observer1 = 3; + private final int observer2 = 4; + private MainThread peers[]; + private ZooKeeper zkHandles[]; + private int clientPorts[]; + private ArrayList serverStrings; + private ArrayList reconfigServers; + + /** + * Test normal quorum operations work cleanly + * with just a single server. + */ + @Test + public void startSingleServerTest() throws Exception { + setUpData(); + + //start one server + startServer(leaderId, serverStrings.get(leaderId) + "\n"); + ReconfigTest.testServerHasConfig(zkHandles[leaderId], null, null); + LOG.info("Initial Configuration:\n" + + new String(zkHandles[leaderId].getConfig(this, new Stat()))); + + //start and add 2 followers + startFollowers(); + testReconfig(leaderId, true, reconfigServers); + LOG.info("Configuration after adding 2 followers:\n" + + new String(zkHandles[leaderId].getConfig(this, new Stat()))); + + //shutdown leader- quorum should still exist + shutDownServer(leaderId); + ReconfigTest.testNormalOperation(zkHandles[follower1], zkHandles[follower2]); + + //should not be able to remove follower 2 + //No quorum in new config (1/2) + reconfigServers.clear(); + reconfigServers.add(Integer.toString(follower2)); + try { + ReconfigTest.reconfig(zkHandles[follower1], null, reconfigServers, null, -1); + Assert.fail("reconfig completed successfully even though there is no quorum up in new config!"); + } catch (KeeperException.NewConfigNoQuorum e) { + } + + //reconfigure out leader and follower 1. Remaining follower + //2 should elect itself as leader and run by itself + reconfigServers.clear(); + reconfigServers.add(Integer.toString(leaderId)); + reconfigServers.add(Integer.toString(follower1)); + testReconfig(follower2, false, reconfigServers); + LOG.info("Configuration after removing leader and follower 1:\n" + + new String(zkHandles[follower2].getConfig(this, new Stat()))); + + // Try to remove follower2, which is the only remaining server. This should fail. + reconfigServers.clear(); + reconfigServers.add(Integer.toString(follower2)); + try { + zkHandles[follower2].reconfig(null, reconfigServers, null, -1, new Stat()); + Assert.fail("reconfig completed successfully even though there is no quorum up in new config!"); + } catch (KeeperException.BadArgumentsException e) { + // This is expected. + } catch (Exception e) { + Assert.fail("Should have been BadArgumentsException!"); + } + + //Add two participants and change them to observers to check + //that we can reconfigure down to one participant with observers. + ArrayList observerStrings = new ArrayList(); + startObservers(observerStrings); + testReconfig(follower2, true, reconfigServers); //add partcipants + testReconfig(follower2, true, observerStrings); //change to observers + LOG.info("Configuration after adding two observers:\n" + + new String(zkHandles[follower2].getConfig(this, new Stat()))); + + shutDownData(); + } + + /** + * Initialize private data for test. + */ + private void setUpData() throws Exception { + ClientBase.setupTestEnv(); + QuorumPeerConfig.setStandaloneEnabled(false); + peers = new MainThread[NUM_SERVERS]; + zkHandles = new ZooKeeper[NUM_SERVERS]; + clientPorts = new int[NUM_SERVERS]; + serverStrings = buildServerStrings(); + reconfigServers = new ArrayList(); + } + + /** + * Stop server threads. + */ + private void shutDownData() throws Exception { + for (int i = 0; i < NUM_SERVERS; i++) { + zkHandles[i].close(); + } + for (int i = 1; i < NUM_SERVERS; i++) { + peers[i].shutdown(); + } + } + + /** + * Create config strings that will be used for + * the test servers. + */ + private ArrayList buildServerStrings() { + ArrayList serverStrings = new ArrayList(); + + for (int i = 0; i < NUM_SERVERS; i++) { + clientPorts[i] = PortAssignment.unique(); + String server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":participant;" + + "localhost:" + clientPorts[i]; + serverStrings.add(server); + } + return serverStrings; + } + + /** + * Starts a single server in replicated mode, + * initializes its client, and waits for it + * to be connected. + */ + private void startServer(int id, String config) throws Exception { + peers[id] = new MainThread(id, clientPorts[id], config); + zkHandles[id] = new ZooKeeper("127.0.0.1:" + clientPorts[id], + CONNECTION_TIMEOUT, this); + peers[id].start(); + Assert.assertTrue("Server " + id + " is not up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[id], CONNECTION_TIMEOUT)); + Assert.assertTrue("Error- Server started in Standalone Mode!", + peers[id].isQuorumPeerRunning()); + } + + /** + * Shuts down a server, waits for it to disconnect, + * and gives enough time for the learner handler + * in its ensemble to realize it's been shut down. + */ + private void shutDownServer(int id) throws Exception { + peers[id].shutdown(); + ClientBase.waitForServerDown("127.0.0.1:" + clientPorts[id], CONNECTION_TIMEOUT); + TimeUnit.SECONDS.sleep(25); + } + + /** + * Starts servers 1 & 2 as participants and + * adds them to the list to be reconfigured + * into the ensemble. + */ + private void startFollowers() throws Exception { + reconfigServers.clear(); + for (int i = 1; i <= 2; i++) { + String config = serverStrings.get(leaderId) + "\n" + + serverStrings.get(i) + "\n" + + serverStrings.get(i % 2 + 1) + "\n"; + startServer(i, config); + reconfigServers.add(serverStrings.get(i)); + } + } + + /** + * Starts servers 1 & 2 as participants, + * adds them to the list to be reconfigured + * into the ensemble, and adds an observer + * version of their information to a list + * so they will be turned into observers later. + */ + private void startObservers(ArrayList observerStrings) throws Exception { + reconfigServers.clear(); + for (int i = observer1; i <= observer2; i++) { + String config = serverStrings.get(follower2) + "\n" + + serverStrings.get(i) + "\n"; + startServer(i, config); + reconfigServers.add(serverStrings.get(i)); + observerStrings.add(serverStrings.get(i).replace("participant", "observer")); + } + } + + /** + * Calls reconfig on the client corresponding to id to add or remove + * the given servers. Tests appropriately to make sure the + * reconfig succeeded. + */ + private void testReconfig(int id, boolean adding, + ArrayList servers) throws Exception { + if (adding) { + ReconfigTest.reconfig(zkHandles[id], servers, null, null, -1); + for (String server : servers) { + int id2 = Integer.parseInt(server.substring(7, 8)); //server.# + ReconfigTest.testNormalOperation(zkHandles[id], zkHandles[id2]); + } + ReconfigTest.testServerHasConfig(zkHandles[id], servers, null); + } else { + ReconfigTest.reconfig(zkHandles[id], null, servers, null, -1); + ReconfigTest.testServerHasConfig(zkHandles[id], null, servers); + } + + } + + /** + * Ensure observer cannot start by itself + **/ + @Test + public void startObserver() throws Exception { + int clientPort = PortAssignment.unique(); + String config = "server." + observer1 + "=localhost:" + PortAssignment.unique() + + ":" + clientPort + ":observer;" + + "localhost:" + PortAssignment.unique(); + MainThread observer = new MainThread(observer1, clientPort, config); + observer.start(); + Assert.assertFalse("Observer was able to start by itself!", + ClientBase.waitForServerUp("127.0.0.1:" + clientPort, CONNECTION_TIMEOUT)); + } +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java b/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java new file mode 100644 index 00000000000..7ee248a9373 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java @@ -0,0 +1,354 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.zookeeper.MockPacket; +import org.apache.zookeeper.ZKParameterized; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.proto.ConnectRequest; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; +import org.apache.zookeeper.proto.SetWatches; +import org.apache.zookeeper.server.MockNIOServerCnxn; +import org.apache.zookeeper.server.MockSelectorThread; +import org.apache.zookeeper.server.NIOServerCnxn; +import org.apache.zookeeper.server.NIOServerCnxnFactory; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.nio.channels.SelectableChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Demonstrate ZOOKEEPER-1382 : Watches leak on expired session + */ +@RunWith(Parameterized.class) +@Parameterized.UseParametersRunnerFactory(ZKParameterized.RunnerFactory.class) +public class WatchLeakTest { + + protected static final Logger LOG = LoggerFactory + .getLogger(WatchLeakTest.class); + /** + * This is the secret that we use to generate passwords, for the moment it + * is more of a sanity check. + */ + static final private long superSecret = 0XB3415C00L; + final long SESSION_ID = 0xBABEL; + private final boolean sessionTimedout; + + public WatchLeakTest(boolean sessionTimedout) { + this.sessionTimedout = sessionTimedout; + } + + @Parameters + public static Collection configs() { + return Arrays.asList(new Object[][]{ + {false}, {true}, + }); + } + + @Before + public void setUp() { + System.setProperty("zookeeper.admin.enableServer", "false"); + } + + /** + * Check that if session has expired then no watch can be set + */ + + @Test + public void testWatchesLeak() throws Exception { + + NIOServerCnxnFactory serverCnxnFactory = mock(NIOServerCnxnFactory.class); + final SelectionKey sk = new FakeSK(); + MockSelectorThread selectorThread = mock(MockSelectorThread.class); + when(selectorThread.addInterestOpsUpdateRequest(any(SelectionKey.class))).thenAnswer(new Answer() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + SelectionKey sk = (SelectionKey) invocation.getArguments()[0]; + NIOServerCnxn nioSrvCnx = (NIOServerCnxn) sk.attachment(); + sk.interestOps(nioSrvCnx.getInterestOps()); + return true; + } + }); + + ZKDatabase database = new ZKDatabase(null); + database.setlastProcessedZxid(2L); + QuorumPeer quorumPeer = mock(QuorumPeer.class); + FileTxnSnapLog logfactory = mock(FileTxnSnapLog.class); + // Directories are not used but we need it to avoid NPE + when(logfactory.getDataDir()).thenReturn(new File("")); + when(logfactory.getSnapDir()).thenReturn(new File("")); + FollowerZooKeeperServer fzks = null; + + try { + // Create a new follower + fzks = new FollowerZooKeeperServer(logfactory, quorumPeer, database); + fzks.startup(); + fzks.setServerCnxnFactory(serverCnxnFactory); + quorumPeer.follower = new MyFollower(quorumPeer, fzks); + LOG.info("Follower created"); + // Simulate a socket channel between a client and a follower + final SocketChannel socketChannel = createClientSocketChannel(); + // Create the NIOServerCnxn that will handle the client requests + final MockNIOServerCnxn nioCnxn = new MockNIOServerCnxn(fzks, + socketChannel, sk, serverCnxnFactory, selectorThread); + sk.attach(nioCnxn); + // Send the connection request as a client do + nioCnxn.doIO(sk); + LOG.info("Client connection sent"); + // Send the valid or invalid session packet to the follower + QuorumPacket qp = createValidateSessionPacketResponse(!sessionTimedout); + quorumPeer.follower.processPacket(qp); + LOG.info("Session validation sent"); + // OK, now the follower knows that the session is valid or invalid, let's try + // to send the watches + nioCnxn.doIO(sk); + // wait for the the request processor to do his job + Thread.sleep(1000L); + LOG.info("Watches processed"); + // If session has not been validated, there must be NO watches + int watchCount = database.getDataTree().getWatchCount(); + if (sessionTimedout) { + // Session has not been re-validated ! + LOG.info("session is not valid, watches = {}", watchCount); + assertEquals("Session is not valid so there should be no watches", 0, watchCount); + } else { + // Session has been re-validated + LOG.info("session is valid, watches = {}", watchCount); + assertEquals("Session is valid so the watch should be there", 1, watchCount); + } + } finally { + if (fzks != null) { + fzks.shutdown(); + } + } + } + + /** + * Create a watches message with a single watch on / + * + * @return a message that attempts to set 1 watch on / + */ + private ByteBuffer createWatchesMessage() { + List dataWatches = new ArrayList(1); + dataWatches.add("/"); + List existWatches = Collections.emptyList(); + List childWatches = Collections.emptyList(); + SetWatches sw = new SetWatches(1L, dataWatches, existWatches, + childWatches); + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.setWatches); + h.setXid(-8); + MockPacket p = new MockPacket(h, new ReplyHeader(), sw, null, null); + return p.createAndReturnBB(); + } + + /** + * Create a connection request + * + * @return a serialized connection request + */ + private ByteBuffer createConnRequest() { + Random r = new Random(SESSION_ID ^ superSecret); + byte p[] = new byte[16]; + r.nextBytes(p); + ConnectRequest conReq = new ConnectRequest(0, 1L, 30000, SESSION_ID, p); + MockPacket packet = new MockPacket(null, null, conReq, null, null, false); + return packet.createAndReturnBB(); + } + + /** + * Mock a client channel with a connection request and a watches message + * inside. + * + * @return a socket channel + * @throws IOException + */ + private SocketChannel createClientSocketChannel() throws IOException { + + SocketChannel socketChannel = mock(SocketChannel.class); + Socket socket = mock(Socket.class); + InetSocketAddress socketAddress = new InetSocketAddress(1234); + when(socket.getRemoteSocketAddress()).thenReturn(socketAddress); + when(socketChannel.socket()).thenReturn(socket); + + // Send watches packet to server connection + final ByteBuffer connRequest = createConnRequest(); + final ByteBuffer watchesMessage = createWatchesMessage(); + final ByteBuffer request = ByteBuffer.allocate(connRequest.limit() + + watchesMessage.limit()); + request.put(connRequest); + request.put(watchesMessage); + + Answer answer = new Answer() { + int i = 0; + + @Override + public Integer answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + ByteBuffer bb = (ByteBuffer) args[0]; + for (int k = 0; k < bb.limit(); k++) { + bb.put(request.get(i)); + i = i + 1; + } + return bb.limit(); + } + }; + when(socketChannel.read(any(ByteBuffer.class))).thenAnswer(answer); + return socketChannel; + } + + /** + * Forge an invalid session packet as a LEADER do + * + * @param valid true to create a valid session message + * + * @throws Exception + */ + private QuorumPacket createValidateSessionPacketResponse(boolean valid) throws Exception { + QuorumPacket qp = createValidateSessionPacket(); + ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData()); + DataInputStream dis = new DataInputStream(bis); + long id = dis.readLong(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeLong(id); + // false means that the session has expired + dos.writeBoolean(valid); + qp.setData(bos.toByteArray()); + return qp; + } + + /** + * Forge an validate session packet as a LEARNER do + * + * @return + * @throws Exception + */ + private QuorumPacket createValidateSessionPacket() throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeLong(SESSION_ID); + dos.writeInt(3000); + dos.close(); + QuorumPacket qp = new QuorumPacket(Leader.REVALIDATE, -1, + baos.toByteArray(), null); + return qp; + } + + /** + * A follower with no real leader connection + */ + public static class MyFollower extends Follower { + /** + * Create a follower with a mocked leader connection + * + * @param self + * @param zk + */ + MyFollower(QuorumPeer self, FollowerZooKeeperServer zk) { + super(self, zk); + leaderOs = mock(OutputArchive.class); + leaderIs = mock(InputArchive.class); + bufferedOutput = mock(BufferedOutputStream.class); + } + } + + /** + * Simulate the behavior of a real selection key + */ + private static class FakeSK extends SelectionKey { + + private int ops = OP_WRITE + OP_READ; + + @Override + public SelectableChannel channel() { + return null; + } + + @Override + public Selector selector() { + return mock(Selector.class); + } + + @Override + public boolean isValid() { + return true; + } + + @Override + public void cancel() { + } + + @Override + public int interestOps() { + return ops; + } + + @Override + public SelectionKey interestOps(int ops) { + this.ops = ops; + return this; + } + + @Override + public int readyOps() { + boolean reading = (ops & OP_READ) != 0; + boolean writing = (ops & OP_WRITE) != 0; + if (reading && writing) { + LOG.info("Channel is ready for reading and writing"); + } else if (reading) { + LOG.info("Channel is ready for reading only"); + } else if (writing) { + LOG.info("Channel is ready for writing only"); + } + return ops; + } + + } + +} diff --git a/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java b/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java new file mode 100644 index 00000000000..55d2f6be14d --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java @@ -0,0 +1,1376 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.quorum; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.InputArchive; +import org.apache.jute.OutputArchive; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ByteBufferInputStream; +import org.apache.zookeeper.server.ByteBufferOutputStream; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.ServerCnxn; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.flexible.QuorumMaj; +import org.apache.zookeeper.server.util.ZxidUtils; +import org.apache.zookeeper.test.TestUtils; +import org.apache.zookeeper.txn.CreateSessionTxn; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.ErrorTxn; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class Zab1_0Test extends ZKTestCase { + private static final int SYNC_LIMIT = 2; + + private static final Logger LOG = LoggerFactory.getLogger(Zab1_0Test.class); + + private static final File testData = new File( + System.getProperty("test.data.dir", "build/test/data")); + + static Socket[] getSocketPair() throws IOException { + ServerSocket ss = + new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1")); + InetSocketAddress endPoint = (InetSocketAddress) ss.getLocalSocketAddress(); + Socket s = new Socket(endPoint.getAddress(), endPoint.getPort()); + return new Socket[]{s, ss.accept()}; + } + + static void readPacketSkippingPing(InputArchive ia, QuorumPacket qp) throws IOException { + while (true) { + ia.readRecord(qp, null); + if (qp.getType() != Leader.PING) { + return; + } + } + } + + @Before + public void setUp() { + System.setProperty("zookeeper.admin.enableServer", "false"); + } + + @Test + public void testLeaderInConnectingFollowers() throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + Leader leader = null; + try { + QuorumPeer peer = createQuorumPeer(tmpDir); + leader = createLeader(tmpDir, peer); + peer.leader = leader; + peer.setAcceptedEpoch(5); + + FollowerMockThread f1 = new FollowerMockThread(1, leader, true); + FollowerMockThread f2 = new FollowerMockThread(2, leader, true); + f1.start(); + f2.start(); + + // wait until followers time out in getEpochToPropose - they shouldn't return + // normally because the leader didn't execute getEpochToPropose and so its epoch was not + // accounted for + f1.join(leader.self.getInitLimit() * leader.self.getTickTime() + 5000); + f2.join(leader.self.getInitLimit() * leader.self.getTickTime() + 5000); + + // even though followers timed out, their ids are in connectingFollowers, and their + // epoch were accounted for, so the leader should not block and since it started with + // accepted epoch = 5 it should now have 6 + try { + long epoch = leader.getEpochToPropose(leader.self.getId(), leader.self.getAcceptedEpoch()); + Assert.assertEquals("leader got wrong epoch from getEpochToPropose", 6, epoch); + } catch (Exception e) { + Assert.fail("leader timed out in getEpochToPropose"); + } + } finally { + if (leader != null) { + leader.shutdown("end of test"); + } + TestUtils.deleteFileRecursively(tmpDir); + } + } + + /** + * In this test, the leader sets the last accepted epoch to 5. The call + * to getEpochToPropose should set epoch to 6 and wait until another + * follower executes it. If in getEpochToPropose we don't check if + * lastAcceptedEpoch == epoch, then the call from the subsequent + * follower with lastAcceptedEpoch = 6 doesn't change the value + * of epoch, and the test fails. It passes with the fix to predicate. + * + * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1343} + * + * + * @throws Exception + */ + + @Test + public void testLastAcceptedEpoch() throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + Leader leader = null; + LeadThread leadThread = null; + try { + QuorumPeer peer = createQuorumPeer(tmpDir); + leader = createMockLeader(tmpDir, peer); + peer.leader = leader; + peer.setAcceptedEpoch(5); + leadThread = new LeadThread(leader); + leadThread.start(); + + while (((MockLeader) leader).getCurrentEpochToPropose() != 6) { + Thread.sleep(20); + } + + try { + long epoch = leader.getEpochToPropose(1, 6); + Assert.assertEquals("New proposed epoch is wrong", 7, epoch); + } catch (Exception e) { + Assert.fail("Timed out in getEpochToPropose"); + } + + } finally { + if (leader != null) { + leader.shutdown("end of test"); + } + if (leadThread != null) { + leadThread.interrupt(); + leadThread.join(); + } + TestUtils.deleteFileRecursively(tmpDir); + } + } + + @Test + public void testLeaderInElectingFollowers() throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + Leader leader = null; + try { + QuorumPeer peer = createQuorumPeer(tmpDir); + leader = createLeader(tmpDir, peer); + peer.leader = leader; + + FollowerMockThread f1 = new FollowerMockThread(1, leader, false); + FollowerMockThread f2 = new FollowerMockThread(2, leader, false); + + // things needed for waitForEpochAck to run (usually in leader.lead(), but we're not running leader here) + leader.leaderStateSummary = new StateSummary(leader.self.getCurrentEpoch(), leader.zk.getLastProcessedZxid()); + + f1.start(); + f2.start(); + + // wait until followers time out in waitForEpochAck - they shouldn't return + // normally because the leader didn't execute waitForEpochAck + f1.join(leader.self.getInitLimit() * leader.self.getTickTime() + 5000); + f2.join(leader.self.getInitLimit() * leader.self.getTickTime() + 5000); + + // make sure that they timed out and didn't return normally + Assert.assertTrue(f1.msg + " without waiting for leader", f1.msg == null); + Assert.assertTrue(f2.msg + " without waiting for leader", f2.msg == null); + } finally { + if (leader != null) { + leader.shutdown("end of test"); + } + TestUtils.deleteFileRecursively(tmpDir); + } + } + + public void testLeaderConversation(LeaderConversation conversation) throws Exception { + Socket pair[] = getSocketPair(); + Socket leaderSocket = pair[0]; + Socket followerSocket = pair[1]; + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + LeadThread leadThread = null; + Leader leader = null; + try { + QuorumPeer peer = createQuorumPeer(tmpDir); + leader = createLeader(tmpDir, peer); + peer.leader = leader; + leadThread = new LeadThread(leader); + leadThread.start(); + + while (leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) { + Thread.sleep(20); + } + + LearnerHandler lh = new LearnerHandler(leaderSocket, leader); + lh.start(); + leaderSocket.setSoTimeout(4000); + + InputArchive ia = BinaryInputArchive.getArchive(followerSocket + .getInputStream()); + OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket + .getOutputStream()); + + conversation.converseWithLeader(ia, oa, leader); + } finally { + if (leader != null) { + leader.shutdown("end of test"); + } + if (leadThread != null) { + leadThread.interrupt(); + leadThread.join(); + } + TestUtils.deleteFileRecursively(tmpDir); + } + } + + public void testPopulatedLeaderConversation(PopulatedLeaderConversation conversation, int ops) throws Exception { + Socket pair[] = getSocketPair(); + Socket leaderSocket = pair[0]; + Socket followerSocket = pair[1]; + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + LeadThread leadThread = null; + Leader leader = null; + try { + // Setup a database with two znodes + FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir); + ZKDatabase zkDb = new ZKDatabase(snapLog); + + Assert.assertTrue(ops >= 1); + long zxid = ZxidUtils.makeZxid(1, 0); + for (int i = 1; i <= ops; i++) { + zxid = ZxidUtils.makeZxid(1, i); + String path = "/foo-" + i; + zkDb.processTxn(new TxnHeader(13, 1000 + i, zxid, 30 + i, ZooDefs.OpCode.create), + new CreateTxn(path, "fpjwasalsohere".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1)); + Stat stat = new Stat(); + Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null))); + } + Assert.assertTrue(zxid > ZxidUtils.makeZxid(1, 0)); + + // Generate snapshot and close files. + snapLog.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts()); + snapLog.close(); + + QuorumPeer peer = createQuorumPeer(tmpDir); + + leader = createLeader(tmpDir, peer); + peer.leader = leader; + + // Set the last accepted epoch and current epochs to be 1 + peer.setAcceptedEpoch(1); + peer.setCurrentEpoch(1); + + + leadThread = new LeadThread(leader); + leadThread.start(); + + while (leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) { + Thread.sleep(20); + } + + LearnerHandler lh = new LearnerHandler(leaderSocket, leader); + lh.start(); + leaderSocket.setSoTimeout(4000); + + InputArchive ia = BinaryInputArchive.getArchive(followerSocket + .getInputStream()); + OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket + .getOutputStream()); + + conversation.converseWithLeader(ia, oa, leader, zxid); + } finally { + if (leader != null) { + leader.shutdown("end of test"); + } + if (leadThread != null) { + leadThread.interrupt(); + leadThread.join(); + } + TestUtils.deleteFileRecursively(tmpDir); + } + } + + public void testFollowerConversation(FollowerConversation conversation) throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + Thread followerThread = null; + ConversableFollower follower = null; + QuorumPeer peer = null; + try { + peer = createQuorumPeer(tmpDir); + follower = createFollower(tmpDir, peer); + peer.follower = follower; + + ServerSocket ss = + new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1")); + follower.setLeaderSocketAddress((InetSocketAddress) ss.getLocalSocketAddress()); + final Follower followerForThread = follower; + + followerThread = new Thread() { + public void run() { + try { + followerForThread.followLeader(); + } catch (InterruptedException e) { + LOG.info("Follower thread interrupted", e); + } catch (Exception e) { + LOG.warn("Unexpected exception in follower thread", e); + } + } + }; + followerThread.start(); + Socket leaderSocket = ss.accept(); + + InputArchive ia = BinaryInputArchive.getArchive(leaderSocket + .getInputStream()); + OutputArchive oa = BinaryOutputArchive.getArchive(leaderSocket + .getOutputStream()); + + conversation.converseWithFollower(ia, oa, follower); + } finally { + if (follower != null) { + follower.shutdown(); + } + if (followerThread != null) { + followerThread.interrupt(); + followerThread.join(); + } + if (peer != null) { + peer.shutdown(); + } + TestUtils.deleteFileRecursively(tmpDir); + } + } + + public void testObserverConversation(ObserverConversation conversation) throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + Thread observerThread = null; + ConversableObserver observer = null; + QuorumPeer peer = null; + try { + peer = createQuorumPeer(tmpDir); + peer.setSyncEnabled(true); + observer = createObserver(tmpDir, peer); + peer.observer = observer; + + ServerSocket ss = + new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1")); + observer.setLeaderSocketAddress((InetSocketAddress) ss.getLocalSocketAddress()); + final Observer observerForThread = observer; + + observerThread = new Thread() { + public void run() { + try { + observerForThread.observeLeader(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + observerThread.start(); + Socket leaderSocket = ss.accept(); + + InputArchive ia = BinaryInputArchive.getArchive(leaderSocket + .getInputStream()); + OutputArchive oa = BinaryOutputArchive.getArchive(leaderSocket + .getOutputStream()); + + conversation.converseWithObserver(ia, oa, observer); + } finally { + if (observer != null) { + observer.shutdown(); + } + if (observerThread != null) { + observerThread.interrupt(); + observerThread.join(); + } + if (peer != null) { + peer.shutdown(); + } + TestUtils.deleteFileRecursively(tmpDir); + } + } + + @Test + public void testUnnecessarySnap() throws Exception { + testPopulatedLeaderConversation(new PopulatedLeaderConversation() { + @Override + public void converseWithLeader(InputArchive ia, OutputArchive oa, + Leader l, long zxid) throws Exception { + + Assert.assertEquals(1, l.self.getAcceptedEpoch()); + Assert.assertEquals(1, l.self.getCurrentEpoch()); + + /* we test a normal run. everything should work out well. */ + LearnerInfo li = new LearnerInfo(1, 0x10000, 0); + byte liBytes[] = new byte[20]; + ByteBufferOutputStream.record2ByteBuffer(li, + ByteBuffer.wrap(liBytes)); + QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 1, + liBytes, null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.LEADERINFO, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(2, 0), qp.getZxid()); + Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(), + 0x10000); + Assert.assertEquals(2, l.self.getAcceptedEpoch()); + Assert.assertEquals(1, l.self.getCurrentEpoch()); + + byte epochBytes[] = new byte[4]; + final ByteBuffer wrappedEpochBytes = ByteBuffer.wrap(epochBytes); + wrappedEpochBytes.putInt(1); + qp = new QuorumPacket(Leader.ACKEPOCH, zxid, epochBytes, null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.DIFF, qp.getType()); + + } + }, 2); + } + + @Test + public void testNormalFollowerRun() throws Exception { + testFollowerConversation(new FollowerConversation() { + @Override + public void converseWithFollower(InputArchive ia, OutputArchive oa, + Follower f) throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + File logDir = f.fzk.getTxnLogFactory().getDataDir().getParentFile(); + File snapDir = f.fzk.getTxnLogFactory().getSnapDir().getParentFile(); + try { + Assert.assertEquals(0, f.self.getAcceptedEpoch()); + Assert.assertEquals(0, f.self.getCurrentEpoch()); + + // Setup a database with a single /foo node + ZKDatabase zkDb = new ZKDatabase(new FileTxnSnapLog(tmpDir, tmpDir)); + final long firstZxid = ZxidUtils.makeZxid(1, 1); + zkDb.processTxn(new TxnHeader(13, 1313, firstZxid, 33, ZooDefs.OpCode.create), new CreateTxn("/foo", "data1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1)); + Stat stat = new Stat(); + Assert.assertEquals("data1", new String(zkDb.getData("/foo", stat, null))); + + QuorumPacket qp = new QuorumPacket(); + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.FOLLOWERINFO, qp.getType()); + Assert.assertEquals(qp.getZxid(), 0); + LearnerInfo learnInfo = new LearnerInfo(); + ByteBufferInputStream.byteBuffer2Record(ByteBuffer.wrap(qp.getData()), learnInfo); + Assert.assertEquals(learnInfo.getProtocolVersion(), 0x10000); + Assert.assertEquals(learnInfo.getServerid(), 0); + + // We are simulating an established leader, so the epoch is 1 + qp.setType(Leader.LEADERINFO); + qp.setZxid(ZxidUtils.makeZxid(1, 0)); + byte protoBytes[] = new byte[4]; + ByteBuffer.wrap(protoBytes).putInt(0x10000); + qp.setData(protoBytes); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACKEPOCH, qp.getType()); + Assert.assertEquals(0, qp.getZxid()); + Assert.assertEquals(ZxidUtils.makeZxid(0, 0), ByteBuffer.wrap(qp.getData()).getInt()); + Assert.assertEquals(1, f.self.getAcceptedEpoch()); + Assert.assertEquals(0, f.self.getCurrentEpoch()); + + // Send the snapshot we created earlier + qp.setType(Leader.SNAP); + qp.setData(new byte[0]); + qp.setZxid(zkDb.getDataTreeLastProcessedZxid()); + oa.writeRecord(qp, null); + zkDb.serializeSnapshot(oa); + oa.writeString("BenWasHere", null); + qp.setType(Leader.NEWLEADER); + qp.setZxid(ZxidUtils.makeZxid(1, 0)); + oa.writeRecord(qp, null); + + // Get the ack of the new leader + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACK, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(1, f.self.getAcceptedEpoch()); + Assert.assertEquals(1, f.self.getCurrentEpoch()); + + Assert.assertEquals(firstZxid, f.fzk.getLastProcessedZxid()); + + // Make sure the data was recorded in the filesystem ok + ZKDatabase zkDb2 = new ZKDatabase(new FileTxnSnapLog(logDir, snapDir)); + long lastZxid = zkDb2.loadDataBase(); + Assert.assertEquals("data1", new String(zkDb2.getData("/foo", stat, null))); + Assert.assertEquals(firstZxid, lastZxid); + + // Propose an update + long proposalZxid = ZxidUtils.makeZxid(1, 1000); + proposeSetData(qp, proposalZxid, "data2", 2); + oa.writeRecord(qp, null); + + TrackerWatcher watcher = new TrackerWatcher(); + + // The change should not have happened yet, since we haven't committed + Assert.assertEquals("data1", new String(f.fzk.getZKDatabase().getData("/foo", stat, watcher))); + + // The change should happen now + qp.setType(Leader.COMMIT); + qp.setZxid(proposalZxid); + oa.writeRecord(qp, null); + + qp.setType(Leader.UPTODATE); + qp.setZxid(0); + oa.writeRecord(qp, null); + + // Read the uptodate ack + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACK, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACK, qp.getType()); + Assert.assertEquals(proposalZxid, qp.getZxid()); + + watcher.waitForChange(); + Assert.assertEquals("data2", new String(f.fzk.getZKDatabase().getData("/foo", stat, null))); + + // check and make sure the change is persisted + zkDb2 = new ZKDatabase(new FileTxnSnapLog(logDir, snapDir)); + lastZxid = zkDb2.loadDataBase(); + Assert.assertEquals("data2", new String(zkDb2.getData("/foo", stat, null))); + Assert.assertEquals(proposalZxid, lastZxid); + } finally { + TestUtils.deleteFileRecursively(tmpDir); + } + + } + + private void proposeSetData(QuorumPacket qp, long zxid, String data, int version) throws IOException { + qp.setType(Leader.PROPOSAL); + qp.setZxid(zxid); + TxnHeader hdr = new TxnHeader(4, 1414, qp.getZxid(), 55, ZooDefs.OpCode.setData); + SetDataTxn sdt = new SetDataTxn("/foo", data.getBytes(), version); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputArchive boa = BinaryOutputArchive.getArchive(baos); + boa.writeRecord(hdr, null); + boa.writeRecord(sdt, null); + qp.setData(baos.toByteArray()); + } + }); + } + + @Test + public void testNormalFollowerRunWithDiff() throws Exception { + testFollowerConversation(new FollowerConversation() { + @Override + public void converseWithFollower(InputArchive ia, OutputArchive oa, + Follower f) throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + File logDir = f.fzk.getTxnLogFactory().getDataDir().getParentFile(); + File snapDir = f.fzk.getTxnLogFactory().getSnapDir().getParentFile(); + try { + Assert.assertEquals(0, f.self.getAcceptedEpoch()); + Assert.assertEquals(0, f.self.getCurrentEpoch()); + + // Setup a database with a single /foo node + ZKDatabase zkDb = new ZKDatabase(new FileTxnSnapLog(tmpDir, tmpDir)); + final long firstZxid = ZxidUtils.makeZxid(1, 1); + zkDb.processTxn(new TxnHeader(13, 1313, firstZxid, 33, ZooDefs.OpCode.create), new CreateTxn("/foo", "data1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1)); + Stat stat = new Stat(); + Assert.assertEquals("data1", new String(zkDb.getData("/foo", stat, null))); + + QuorumPacket qp = new QuorumPacket(); + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.FOLLOWERINFO, qp.getType()); + Assert.assertEquals(qp.getZxid(), 0); + LearnerInfo learnInfo = new LearnerInfo(); + ByteBufferInputStream.byteBuffer2Record(ByteBuffer.wrap(qp.getData()), learnInfo); + Assert.assertEquals(learnInfo.getProtocolVersion(), 0x10000); + Assert.assertEquals(learnInfo.getServerid(), 0); + + // We are simulating an established leader, so the epoch is 1 + qp.setType(Leader.LEADERINFO); + qp.setZxid(ZxidUtils.makeZxid(1, 0)); + byte protoBytes[] = new byte[4]; + ByteBuffer.wrap(protoBytes).putInt(0x10000); + qp.setData(protoBytes); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACKEPOCH, qp.getType()); + Assert.assertEquals(0, qp.getZxid()); + Assert.assertEquals(ZxidUtils.makeZxid(0, 0), ByteBuffer.wrap(qp.getData()).getInt()); + Assert.assertEquals(1, f.self.getAcceptedEpoch()); + Assert.assertEquals(0, f.self.getCurrentEpoch()); + + // Send a diff + qp.setType(Leader.DIFF); + qp.setData(new byte[0]); + qp.setZxid(zkDb.getDataTreeLastProcessedZxid()); + oa.writeRecord(qp, null); + final long createSessionZxid = ZxidUtils.makeZxid(1, 2); + proposeNewSession(qp, createSessionZxid, 0x333); + oa.writeRecord(qp, null); + qp.setType(Leader.COMMIT); + qp.setZxid(createSessionZxid); + oa.writeRecord(qp, null); + qp.setType(Leader.NEWLEADER); + qp.setZxid(ZxidUtils.makeZxid(1, 0)); + qp.setData(null); + oa.writeRecord(qp, null); + qp.setType(Leader.UPTODATE); + qp.setZxid(0); + oa.writeRecord(qp, null); + + // Read the uptodate ack + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACK, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + + + // Get the ack of the new leader + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACK, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(1, f.self.getAcceptedEpoch()); + Assert.assertEquals(1, f.self.getCurrentEpoch()); + + Assert.assertEquals(createSessionZxid, f.fzk.getLastProcessedZxid()); + + // Make sure the data was recorded in the filesystem ok + ZKDatabase zkDb2 = new ZKDatabase(new FileTxnSnapLog(logDir, snapDir)); + zkDb2.loadDataBase(); + LOG.info("zkdb2 sessions:" + zkDb2.getSessions()); + Assert.assertNotNull(zkDb2.getSessionWithTimeOuts().get(4L)); + } finally { + TestUtils.deleteFileRecursively(tmpDir); + } + + } + + private void proposeNewSession(QuorumPacket qp, long zxid, long sessionId) throws IOException { + qp.setType(Leader.PROPOSAL); + qp.setZxid(zxid); + TxnHeader hdr = new TxnHeader(4, 1414, qp.getZxid(), 55, ZooDefs.OpCode.createSession); + CreateSessionTxn cst = new CreateSessionTxn(30000); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputArchive boa = BinaryOutputArchive.getArchive(baos); + boa.writeRecord(hdr, null); + boa.writeRecord(cst, null); + qp.setData(baos.toByteArray()); + } + }); + } + + @Test + public void testNormalRun() throws Exception { + testLeaderConversation(new LeaderConversation() { + public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l) + throws IOException { + Assert.assertEquals(0, l.self.getAcceptedEpoch()); + Assert.assertEquals(0, l.self.getCurrentEpoch()); + + /* we test a normal run. everything should work out well. */ + LearnerInfo li = new LearnerInfo(1, 0x10000, 0); + byte liBytes[] = new byte[20]; + ByteBufferOutputStream.record2ByteBuffer(li, + ByteBuffer.wrap(liBytes)); + QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0, + liBytes, null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.LEADERINFO, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(), + 0x10000); + Assert.assertEquals(1, l.self.getAcceptedEpoch()); + Assert.assertEquals(0, l.self.getCurrentEpoch()); + + qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.DIFF, qp.getType()); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.NEWLEADER, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(1, l.self.getAcceptedEpoch()); + Assert.assertEquals(1, l.self.getCurrentEpoch()); + + qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.UPTODATE, qp.getType()); + } + }); + } + + @Test + public void testTxnTimeout() throws Exception { + testLeaderConversation(new LeaderConversation() { + public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l) + throws IOException, InterruptedException, org.apache.zookeeper.server.quorum.Leader.XidRolloverException { + Assert.assertEquals(0, l.self.getAcceptedEpoch()); + Assert.assertEquals(0, l.self.getCurrentEpoch()); + + LearnerInfo li = new LearnerInfo(1, 0x10000, 0); + byte liBytes[] = new byte[20]; + ByteBufferOutputStream.record2ByteBuffer(li, + ByteBuffer.wrap(liBytes)); + QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0, + liBytes, null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.LEADERINFO, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(), + 0x10000); + Assert.assertEquals(1, l.self.getAcceptedEpoch()); + Assert.assertEquals(0, l.self.getCurrentEpoch()); + + qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.DIFF, qp.getType()); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.NEWLEADER, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(1, l.self.getAcceptedEpoch()); + Assert.assertEquals(1, l.self.getCurrentEpoch()); + + qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.UPTODATE, qp.getType()); + + long zxid = l.zk.getZxid(); + l.propose(new Request(1, 1, ZooDefs.OpCode.create, + new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.create), + new CreateTxn("/test", "hola".getBytes(), null, true, 0), zxid)); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.PROPOSAL, qp.getType()); + + LOG.info("Proposal sent."); + + for (int i = 0; i < (2 * SYNC_LIMIT) + 2; i++) { + try { + ia.readRecord(qp, null); + LOG.info("Ping received: " + i); + qp = new QuorumPacket(Leader.PING, qp.getZxid(), "".getBytes(), null); + oa.writeRecord(qp, null); + } catch (EOFException e) { + return; + } + } + Assert.fail("Connection hasn't been closed by leader after transaction times out."); + } + }); + } + + private void deserializeSnapshot(InputArchive ia) + throws IOException { + ZKDatabase zkdb = new ZKDatabase(null); + zkdb.deserializeSnapshot(ia); + String signature = ia.readString("signature"); + assertEquals("BenWasHere", signature); + } + + @Test + public void testNormalObserverRun() throws Exception { + testObserverConversation(new ObserverConversation() { + @Override + public void converseWithObserver(InputArchive ia, OutputArchive oa, + Observer o) throws Exception { + File tmpDir = File.createTempFile("test", "dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + File logDir = o.zk.getTxnLogFactory().getDataDir().getParentFile(); + File snapDir = o.zk.getTxnLogFactory().getSnapDir().getParentFile(); + try { + Assert.assertEquals(0, o.self.getAcceptedEpoch()); + Assert.assertEquals(0, o.self.getCurrentEpoch()); + + // Setup a database with a single /foo node + ZKDatabase zkDb = new ZKDatabase(new FileTxnSnapLog(tmpDir, tmpDir)); + final long foo1Zxid = ZxidUtils.makeZxid(1, 1); + final long foo2Zxid = ZxidUtils.makeZxid(1, 2); + zkDb.processTxn(new TxnHeader(13, 1313, foo1Zxid, 33, + ZooDefs.OpCode.create), new CreateTxn("/foo1", + "data1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + false, 1)); + zkDb.processTxn(new TxnHeader(13, 1313, foo2Zxid, 33, + ZooDefs.OpCode.create), new CreateTxn("/foo2", + "data1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + false, 1)); + Stat stat = new Stat(); + Assert.assertEquals("data1", + new String(zkDb.getData("/foo1", stat, null))); + Assert.assertEquals("data1", + new String(zkDb.getData("/foo2", stat, null))); + + QuorumPacket qp = new QuorumPacket(); + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.OBSERVERINFO, qp.getType()); + Assert.assertEquals(qp.getZxid(), 0); + LearnerInfo learnInfo = new LearnerInfo(); + ByteBufferInputStream.byteBuffer2Record( + ByteBuffer.wrap(qp.getData()), learnInfo); + Assert.assertEquals(learnInfo.getProtocolVersion(), 0x10000); + Assert.assertEquals(learnInfo.getServerid(), 0); + + // We are simulating an established leader, so the epoch is 1 + qp.setType(Leader.LEADERINFO); + qp.setZxid(ZxidUtils.makeZxid(1, 0)); + byte protoBytes[] = new byte[4]; + ByteBuffer.wrap(protoBytes).putInt(0x10000); + qp.setData(protoBytes); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACKEPOCH, qp.getType()); + Assert.assertEquals(0, qp.getZxid()); + Assert.assertEquals(ZxidUtils.makeZxid(0, 0), ByteBuffer + .wrap(qp.getData()).getInt()); + Assert.assertEquals(1, o.self.getAcceptedEpoch()); + Assert.assertEquals(0, o.self.getCurrentEpoch()); + + // Send the snapshot we created earlier + qp.setType(Leader.SNAP); + qp.setData(new byte[0]); + qp.setZxid(zkDb.getDataTreeLastProcessedZxid()); + oa.writeRecord(qp, null); + zkDb.serializeSnapshot(oa); + oa.writeString("BenWasHere", null); + qp.setType(Leader.NEWLEADER); + qp.setZxid(ZxidUtils.makeZxid(1, 0)); + oa.writeRecord(qp, null); + + // Get the ack of the new leader + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACK, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(1, o.self.getAcceptedEpoch()); + Assert.assertEquals(1, o.self.getCurrentEpoch()); + + Assert.assertEquals(foo2Zxid, o.zk.getLastProcessedZxid()); + + // Make sure the data was recorded in the filesystem ok + ZKDatabase zkDb2 = new ZKDatabase(new FileTxnSnapLog( + logDir, snapDir)); + long lastZxid = zkDb2.loadDataBase(); + Assert.assertEquals("data1", + new String(zkDb2.getData("/foo1", stat, null))); + Assert.assertEquals(foo2Zxid, lastZxid); + + // Register watch + TrackerWatcher watcher = new TrackerWatcher(); + Assert.assertEquals("data1", new String(o.zk + .getZKDatabase().getData("/foo2", stat, watcher))); + + // Propose /foo1 update + long proposalZxid = ZxidUtils.makeZxid(1, 1000); + proposeSetData(qp, "/foo1", proposalZxid, "data2", 2); + oa.writeRecord(qp, null); + + // Commit /foo1 update + qp.setType(Leader.COMMIT); + qp.setZxid(proposalZxid); + oa.writeRecord(qp, null); + + // Inform /foo2 update + long informZxid = ZxidUtils.makeZxid(1, 1001); + proposeSetData(qp, "/foo2", informZxid, "data2", 2); + qp.setType(Leader.INFORM); + oa.writeRecord(qp, null); + + qp.setType(Leader.UPTODATE); + qp.setZxid(0); + oa.writeRecord(qp, null); + + // Read the uptodate ack + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.ACK, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + + // Data should get updated + watcher.waitForChange(); + Assert.assertEquals("data2", new String(o.zk + .getZKDatabase().getData("/foo1", stat, null))); + Assert.assertEquals("data2", new String(o.zk + .getZKDatabase().getData("/foo2", stat, null))); + + // Shutdown sequence guarantee that all pending requests + // in sync request processor get flush to disk + o.zk.shutdown(); + + zkDb2 = new ZKDatabase(new FileTxnSnapLog(logDir, snapDir)); + lastZxid = zkDb2.loadDataBase(); + Assert.assertEquals("data2", new String(zkDb2.getData("/foo1", stat, null))); + Assert.assertEquals("data2", new String(zkDb2.getData("/foo2", stat, null))); + Assert.assertEquals(informZxid, lastZxid); + } finally { + TestUtils.deleteFileRecursively(tmpDir); + } + + } + + private void proposeSetData(QuorumPacket qp, String path, + long zxid, String data, int version) throws IOException { + qp.setType(Leader.PROPOSAL); + qp.setZxid(zxid); + TxnHeader hdr = new TxnHeader(4, 1414, qp.getZxid(), 55, + ZooDefs.OpCode.setData); + SetDataTxn sdt = new SetDataTxn(path, data.getBytes(), version); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputArchive boa = BinaryOutputArchive.getArchive(baos); + boa.writeRecord(hdr, null); + boa.writeRecord(sdt, null); + qp.setData(baos.toByteArray()); + } + }); + } + + @Test + public void testLeaderBehind() throws Exception { + testLeaderConversation(new LeaderConversation() { + public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l) + throws IOException { + /* we test a normal run. everything should work out well. */ + LearnerInfo li = new LearnerInfo(1, 0x10000, 0); + byte liBytes[] = new byte[20]; + ByteBufferOutputStream.record2ByteBuffer(li, + ByteBuffer.wrap(liBytes)); + /* we are going to say we last acked epoch 20 */ + QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, ZxidUtils.makeZxid(20, 0), + liBytes, null); + oa.writeRecord(qp, null); + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.LEADERINFO, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid()); + Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(), + 0x10000); + qp = new QuorumPacket(Leader.ACKEPOCH, 0, new byte[4], null); + oa.writeRecord(qp, null); + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.DIFF, qp.getType()); + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.NEWLEADER, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(21, 0), qp.getZxid()); + + qp = new QuorumPacket(Leader.ACK, qp.getZxid(), null, null); + oa.writeRecord(qp, null); + + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.UPTODATE, qp.getType()); + } + }); + } + + /** + * Tests that when a quorum of followers send LearnerInfo but do not ack the epoch (which is sent + * by the leader upon receipt of LearnerInfo from a quorum), the leader does not start using this epoch + * as it would in the normal case (when a quorum do ack the epoch). This tests ZK-1192 + * @throws Exception + */ + @Test + public void testAbandonBeforeACKEpoch() throws Exception { + testLeaderConversation(new LeaderConversation() { + public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l) + throws IOException, InterruptedException { + /* we test a normal run. everything should work out well. */ + LearnerInfo li = new LearnerInfo(1, 0x10000, 0); + byte liBytes[] = new byte[20]; + ByteBufferOutputStream.record2ByteBuffer(li, + ByteBuffer.wrap(liBytes)); + QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0, + liBytes, null); + oa.writeRecord(qp, null); + readPacketSkippingPing(ia, qp); + Assert.assertEquals(Leader.LEADERINFO, qp.getType()); + Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid()); + Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(), + 0x10000); + Thread.sleep(l.self.getInitLimit() * l.self.getTickTime() + 5000); + + // The leader didn't get a quorum of acks - make sure that leader's current epoch is not advanced + Assert.assertEquals(0, l.self.getCurrentEpoch()); + } + }); + } + + private Leader createLeader(File tmpDir, QuorumPeer peer) + throws IOException, NoSuchFieldException, IllegalAccessException { + LeaderZooKeeperServer zk = prepareLeader(tmpDir, peer); + return new Leader(peer, zk); + } + + ; + + private Leader createMockLeader(File tmpDir, QuorumPeer peer) + throws IOException, NoSuchFieldException, IllegalAccessException { + LeaderZooKeeperServer zk = prepareLeader(tmpDir, peer); + return new MockLeader(peer, zk); + } + + private LeaderZooKeeperServer prepareLeader(File tmpDir, QuorumPeer peer) + throws IOException, NoSuchFieldException, IllegalAccessException { + FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir); + peer.setTxnFactory(logFactory); + ZKDatabase zkDb = new ZKDatabase(logFactory); + LeaderZooKeeperServer zk = new LeaderZooKeeperServer(logFactory, peer, zkDb); + return zk; + } + + private ConversableFollower createFollower(File tmpDir, QuorumPeer peer) + throws IOException { + FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir); + peer.setTxnFactory(logFactory); + ZKDatabase zkDb = new ZKDatabase(logFactory); + FollowerZooKeeperServer zk = new FollowerZooKeeperServer(logFactory, peer, zkDb); + peer.setZKDatabase(zkDb); + return new ConversableFollower(peer, zk); + } + + private ConversableObserver createObserver(File tmpDir, QuorumPeer peer) + throws IOException { + FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir); + peer.setTxnFactory(logFactory); + ZKDatabase zkDb = new ZKDatabase(logFactory); + ObserverZooKeeperServer zk = new ObserverZooKeeperServer(logFactory, peer, zkDb); + peer.setZKDatabase(zkDb); + return new ConversableObserver(peer, zk); + } + + private QuorumPeer createQuorumPeer(File tmpDir) throws IOException, FileNotFoundException { + HashMap peers = new HashMap(); + QuorumPeer peer = new QuorumPeer(); + peer.syncLimit = SYNC_LIMIT; + peer.initLimit = 2; + peer.tickTime = 2000; + + peers.put(0L, new QuorumServer( + 0, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()))); + peers.put(1L, new QuorumServer( + 1, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()))); + peers.put(2L, new QuorumServer( + 2, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()))); + + peer.setQuorumVerifier(new QuorumMaj(peers), false); + peer.setCnxnFactory(new NullServerCnxnFactory()); + File version2 = new File(tmpDir, "version-2"); + version2.mkdir(); + FileOutputStream fos; + fos = new FileOutputStream(new File(version2, "currentEpoch")); + fos.write("0\n".getBytes()); + fos.close(); + fos = new FileOutputStream(new File(version2, "acceptedEpoch")); + fos.write("0\n".getBytes()); + fos.close(); + return peer; + } + + private String readContentsOfFile(File f) throws IOException { + return new BufferedReader(new FileReader(f)).readLine(); + } + + @Test + public void testInitialAcceptedCurrent() throws Exception { + File tmpDir = File.createTempFile("test", ".dir", testData); + tmpDir.delete(); + tmpDir.mkdir(); + try { + FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir); + File version2 = new File(tmpDir, "version-2"); + version2.mkdir(); + long zxid = ZxidUtils.makeZxid(3, 3); + logFactory.append(new Request(1, 1, ZooDefs.OpCode.error, + new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.error), + new ErrorTxn(1), zxid)); + logFactory.commit(); + ZKDatabase zkDb = new ZKDatabase(logFactory); + QuorumPeer peer = new QuorumPeer(); + peer.setZKDatabase(zkDb); + peer.setTxnFactory(logFactory); + peer.getLastLoggedZxid(); + Assert.assertEquals(3, peer.getAcceptedEpoch()); + Assert.assertEquals(3, peer.getCurrentEpoch()); + Assert.assertEquals(3, Integer + .parseInt(readContentsOfFile(new File(version2, + QuorumPeer.CURRENT_EPOCH_FILENAME)))); + Assert.assertEquals(3, Integer + .parseInt(readContentsOfFile(new File(version2, + QuorumPeer.ACCEPTED_EPOCH_FILENAME)))); + } finally { + TestUtils.deleteFileRecursively(tmpDir); + } + } + + static public interface LeaderConversation { + void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l) throws Exception; + } + + static public interface PopulatedLeaderConversation { + void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l, long zxid) throws Exception; + } + + static public interface FollowerConversation { + void converseWithFollower(InputArchive ia, OutputArchive oa, Follower f) throws Exception; + } + + static public interface ObserverConversation { + void converseWithObserver(InputArchive ia, OutputArchive oa, Observer o) throws Exception; + } + + private static final class LeadThread extends Thread { + private final Leader leader; + + private LeadThread(Leader leader) { + this.leader = leader; + } + + public void run() { + try { + leader.lead(); + } catch (InterruptedException e) { + LOG.info("Leader thread interrupted", e); + } catch (Exception e) { + LOG.warn("Unexpected exception in leader thread", e); + } finally { + leader.shutdown("lead ended"); + } + } + } + + private static final class MockLeader extends Leader { + + MockLeader(QuorumPeer qp, LeaderZooKeeperServer zk) + throws IOException { + super(qp, zk); + } + + /** + * This method returns the value of the variable that holds the epoch + * to be proposed and that has been proposed, depending on the point + * of the execution in which it is called. + * + * @return epoch + */ + public long getCurrentEpochToPropose() { + return epoch; + } + } + + public static final class FollowerMockThread extends Thread { + private final Leader leader; + private final long followerSid; + public long epoch = -1; + public String msg = null; + private boolean onlyGetEpochToPropose; + + private FollowerMockThread(long followerSid, Leader leader, boolean onlyGetEpochToPropose) { + this.leader = leader; + this.followerSid = followerSid; + this.onlyGetEpochToPropose = onlyGetEpochToPropose; + } + + public void run() { + if (onlyGetEpochToPropose) { + try { + epoch = leader.getEpochToPropose(followerSid, 0); + } catch (Exception e) { + } + } else { + try { + leader.waitForEpochAck(followerSid, new StateSummary(0, 0)); + msg = "FollowerMockThread (id = " + followerSid + ") returned from waitForEpochAck"; + } catch (Exception e) { + } + } + } + } + + private static final class NullServerCnxnFactory extends ServerCnxnFactory { + public void startup(ZooKeeperServer zkServer, boolean startServer) + throws IOException, InterruptedException { + } + + public void start() { + } + + public void shutdown() { + } + + public void join() throws InterruptedException { + } + + public int getMaxClientCnxnsPerHost() { + return 0; + } + + public void setMaxClientCnxnsPerHost(int max) { + } + + public int getLocalPort() { + return 0; + } + + public InetSocketAddress getLocalAddress() { + return null; + } + + public Iterable getConnections() { + return null; + } + + public void configure(InetSocketAddress addr, int maxcc, boolean secure) + throws IOException { + } + + public boolean closeSession(long sessionId) { + return false; + } + + public void closeAll() { + } + + @Override + public int getNumAliveConnections() { + return 0; + } + + @Override + public void reconfigure(InetSocketAddress addr) { + } + + @Override + public void resetAllConnectionStats() { + } + + @Override + public Iterable> getAllConnectionInfo(boolean brief) { + return null; + } + } + + static class ConversableFollower extends Follower { + + InetSocketAddress leaderAddr; + + ConversableFollower(QuorumPeer self, FollowerZooKeeperServer zk) { + super(self, zk); + } + + public void setLeaderSocketAddress(InetSocketAddress addr) { + leaderAddr = addr; + } + + @Override + protected InetSocketAddress findLeader() { + return leaderAddr; + } + } + + static class ConversableObserver extends Observer { + + InetSocketAddress leaderAddr; + + ConversableObserver(QuorumPeer self, ObserverZooKeeperServer zk) { + super(self, zk); + } + + public void setLeaderSocketAddress(InetSocketAddress addr) { + leaderAddr = addr; + } + + @Override + protected InetSocketAddress findLeader() { + return leaderAddr; + } + } + + // We want to track the change with a callback rather than depending on timing + class TrackerWatcher implements Watcher { + boolean changed; + + synchronized void waitForChange() throws InterruptedException { + while (!changed) { + wait(); + } + } + + @Override + public void process(WatchedEvent event) { + if (event.getType() == EventType.NodeDataChanged) { + synchronized (this) { + changed = true; + notifyAll(); + } + } + } + + synchronized public boolean changed() { + return changed; + } + + } +} diff --git a/src/java/test/org/apache/zookeeper/server/util/PortForwarder.java b/src/java/test/org/apache/zookeeper/server/util/PortForwarder.java new file mode 100644 index 00000000000..71f5a7b0ed5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/util/PortForwarder.java @@ -0,0 +1,247 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +/** + * + */ +package org.apache.zookeeper.server.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ConnectException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +/** + * A utility that does bi-directional forwarding between two ports. + * Useful, for example, to simulate network failures. + * Example: + * + * Server 1 config file: + * + * server.1=127.0.0.1:7301:7401;8201 + * server.2=127.0.0.1:7302:7402;8202 + * server.3=127.0.0.1:7303:7403;8203 + * + * Server 2 and 3 config files: + * + * server.1=127.0.0.1:8301:8401;8201 + * server.2=127.0.0.1:8302:8402;8202 + * server.3=127.0.0.1:8303:8403;8203 + * + * Initially forward traffic between 730x and 830x and between 740x and 830x + * This way server 1 can communicate with servers 2 and 3 + * .... + * + * List pfs = startForwarding(); + * .... + * // simulate a network interruption for server 1 + * stopForwarding(pfs); + * .... + * // restore connection + * pfs = startForwarding(); + * + * + * private List startForwarding() throws IOException { + * List res = new ArrayList(); + * res.add(new PortForwarder(8301, 7301)); + * res.add(new PortForwarder(8401, 7401)); + * res.add(new PortForwarder(7302, 8302)); + * res.add(new PortForwarder(7402, 8402)); + * res.add(new PortForwarder(7303, 8303)); + * res.add(new PortForwarder(7403, 8403)); + * return res; + * } + * + * private void stopForwarding(List pfs) throws Exception { + * for (PortForwarder pf : pfs) { + * pf.shutdown(); + * } + * } + * + * + */ +public class PortForwarder extends Thread { + private static final Logger LOG = LoggerFactory + .getLogger(PortForwarder.class); + private final int to; + private volatile boolean stopped = false; + private ExecutorService workers = Executors.newCachedThreadPool(); + private ServerSocket serverSocket; + public PortForwarder(int from, int to) throws IOException { + this.to = to; + serverSocket = new ServerSocket(from); + serverSocket.setSoTimeout(30000); + this.start(); + } + + @Override + public void run() { + try { + while (!stopped) { + Socket sock = null; + try { + LOG.info("accepting socket local:" + + serverSocket.getLocalPort() + " to:" + to); + sock = serverSocket.accept(); + LOG.info("accepted: local:" + sock.getLocalPort() + + " from:" + sock.getPort() + + " to:" + to); + Socket target = null; + int retry = 10; + while (sock.isConnected()) { + try { + target = new Socket("localhost", to); + break; + } catch (IOException e) { + if (retry == 0) { + throw e; + } + LOG.warn("connection failed, retrying(" + retry + + "): local:" + sock.getLocalPort() + + " from:" + sock.getPort() + + " to:" + to, e); + } + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); + retry--; + } + LOG.info("connected: local:" + sock.getLocalPort() + + " from:" + sock.getPort() + + " to:" + to); + sock.setSoTimeout(30000); + target.setSoTimeout(30000); + this.workers.execute(new PortForwardWorker(sock, target, + sock.getInputStream(), target.getOutputStream())); + this.workers.execute(new PortForwardWorker(target, sock, + target.getInputStream(), sock.getOutputStream())); + } catch (SocketTimeoutException e) { + LOG.warn("socket timed out local:" + + (sock != null ? sock.getLocalPort() : "") + + " from:" + (sock != null ? sock.getPort() : "") + + " to:" + to, e); + } catch (ConnectException e) { + LOG.warn("connection exception local:" + + (sock != null ? sock.getLocalPort() : "") + + " from:" + (sock != null ? sock.getPort() : "") + + " to:" + to, e); + sock.close(); + } catch (IOException e) { + if (!"Socket closed".equals(e.getMessage())) { + LOG.warn("unexpected exception local:" + + (sock != null ? sock.getLocalPort() : "") + + " from:" + (sock != null ? sock.getPort() : "") + + " to:" + to, e); + throw e; + } + } + } + } catch (IOException e) { + LOG.error("Unexpected exception to:" + to, e); + } catch (InterruptedException e) { + LOG.error("Interrupted to:" + to, e); + } + } + + public void shutdown() throws Exception { + this.stopped = true; + this.serverSocket.close(); + this.workers.shutdownNow(); + try { + if (!this.workers.awaitTermination(5, TimeUnit.SECONDS)) { + throw new Exception( + "Failed to stop forwarding within 5 seconds"); + } + } catch (InterruptedException e) { + throw new Exception("Failed to stop forwarding"); + } + this.join(); + } + + private static class PortForwardWorker implements Runnable { + + private final InputStream in; + private final OutputStream out; + private final Socket toClose; + private final Socket toClose2; + + PortForwardWorker(Socket toClose, Socket toClose2, InputStream in, + OutputStream out) throws IOException { + this.toClose = toClose; + this.toClose2 = toClose2; + this.in = in; + this.out = out; + // LOG.info("starting forward for "+toClose); + } + + public void run() { + Thread.currentThread().setName(toClose.toString() + "-->" + + toClose2.toString()); + byte[] buf = new byte[1024]; + try { + while (true) { + try { + int read = this.in.read(buf); + if (read > 0) { + try { + this.out.write(buf, 0, read); + } catch (IOException e) { + LOG.warn("exception during write", e); + try { + toClose.close(); + } catch (IOException ex) { + // ignore + } + try { + toClose2.close(); + } catch (IOException ex) { + // ignore + } + break; + } + } + } catch (SocketTimeoutException e) { + LOG.error("socket timeout", e); + } + Thread.sleep(1); + } + } catch (InterruptedException e) { + LOG.warn("Interrupted", e); + try { + toClose.close(); + } catch (IOException ex) { + // ignore + } + try { + toClose2.close(); + } catch (IOException ex) { + // ignore silently + } + } catch (SocketException e) { + if (!"Socket closed".equals(e.getMessage())) { + LOG.error("Unexpected exception", e); + } + } catch (IOException e) { + LOG.error("Unexpected exception", e); + } + LOG.info("Shutting down forward for " + toClose); + } + + } +} diff --git a/src/java/test/org/apache/zookeeper/server/util/VerifyingFileFactoryTest.java b/src/java/test/org/apache/zookeeper/server/util/VerifyingFileFactoryTest.java new file mode 100644 index 00000000000..760eef3bde8 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/server/util/VerifyingFileFactoryTest.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.server.util; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; + +import static org.junit.Assert.*; + +public class VerifyingFileFactoryTest extends ZKTestCase { + + private Logger log; + + @Before + public void setUp() { + log = LoggerFactory.getLogger("TODO: Mock Logging"); + } + + @Test + public void testForWarningOnRelativePath() { + VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) + .warnForRelativePath().build(); + vff.create("a/relative/path"); + // assertTrue(log.hasWarned); + } + + @Test + public void testForNoWarningOnIntendedRelativePath() { + VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) + .warnForRelativePath().build(); + vff.create("./an/intended/relative/path"); + // assertFalse(log.hasWarned); + } + + @Test(expected = IllegalArgumentException.class) + public void testForFailForNonExistingPath() { + VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) + .failForNonExistingPath().build(); + vff.create("/I/H0p3/this/path/d035/n0t/ex15t"); + } + + @Test + public void testFileHasCorrectPath() { + File file = new File("/some/path"); + VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log).build(); + assertEquals(file, vff.create(file.getPath())); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ACLCountTest.java b/src/java/test/org/apache/zookeeper/test/ACLCountTest.java new file mode 100644 index 00000000000..f1b3303d0f4 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ACLCountTest.java @@ -0,0 +1,129 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class ACLCountTest extends ZKTestCase implements Watcher { + private static final Logger LOG = LoggerFactory.getLogger(ACLTest.class); + private static final String HOSTPORT = + "127.0.0.1:" + PortAssignment.unique(); + private volatile CountDownLatch startSignal; + + /** + * + * Create a node and add 4 ACL values to it, but there are only 2 unique ACL values, + * and each is repeated once: + * + * ACL(ZooDefs.Perms.READ,ZooDefs.Ids.ANYONE_ID_UNSAFE); + * ACL(ZooDefs.Perms.ALL,ZooDefs.Ids.AUTH_IDS); + * ACL(ZooDefs.Perms.READ,ZooDefs.Ids.ANYONE_ID_UNSAFE); + * ACL(ZooDefs.Perms.ALL,ZooDefs.Ids.AUTH_IDS); + * + * Even though we've added 4 ACL values, there should only be 2 ACLs for that node, + * since there are only 2 *unique* ACL values. + */ + @Test + public void testAclCount() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(1000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + ZooKeeper zk; + + final ArrayList CREATOR_ALL_AND_WORLD_READABLE = + new ArrayList() { + { + add(new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE_ID_UNSAFE)); + add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.AUTH_IDS)); + add(new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE_ID_UNSAFE)); + add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.AUTH_IDS)); + } + }; + + try { + LOG.info("starting up the zookeeper server .. waiting"); + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + + zk.addAuthInfo("digest", "pat:test".getBytes()); + zk.setACL("/", Ids.CREATOR_ALL_ACL, -1); + + String path = "/path"; + + try { + Assert.assertEquals(4, CREATOR_ALL_AND_WORLD_READABLE.size()); + } catch (Exception e) { + LOG.error("Something is fundamentally wrong with ArrayList's add() method. add()ing four times to an empty ArrayList should result in an ArrayList with 4 members."); + throw e; + } + + zk.create(path, path.getBytes(), CREATOR_ALL_AND_WORLD_READABLE, CreateMode.PERSISTENT); + List acls = zk.getACL("/path", new Stat()); + Assert.assertEquals(2, acls.size()); + } catch (Exception e) { + // test failed somehow. + Assert.assertTrue(false); + } + + f.shutdown(); + zks.shutdown(); + } + + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatcherEvent) + */ + public void process(WatchedEvent event) { + LOG.info("Event:" + event.getState() + " " + event.getType() + " " + + event.getPath()); + if (event.getState() == KeeperState.SyncConnected) { + if (startSignal != null && startSignal.getCount() > 0) { + LOG.info("startsignal.countDown()"); + startSignal.countDown(); + } else { + LOG.warn("startsignal " + startSignal); + } + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/ACLRootTest.java b/src/java/test/org/apache/zookeeper/test/ACLRootTest.java new file mode 100644 index 00000000000..0ff086ae60a --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ACLRootTest.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; + +public class ACLRootTest extends ClientBase { + @Test + public void testRootAcl() throws Exception { + ZooKeeper zk = createClient(); + try { + // set auth using digest + zk.addAuthInfo("digest", "pat:test".getBytes()); + zk.setACL("/", Ids.CREATOR_ALL_ACL, -1); + zk.getData("/", false, null); + zk.close(); + // verify no access + zk = createClient(); + try { + zk.getData("/", false, null); + Assert.fail("validate auth"); + } catch (KeeperException.NoAuthException e) { + // expected + } + try { + zk.create("/apps", null, Ids.CREATOR_ALL_ACL, + CreateMode.PERSISTENT); + Assert.fail("validate auth"); + } catch (KeeperException.InvalidACLException e) { + // expected + } + zk.addAuthInfo("digest", "world:anyone".getBytes()); + try { + zk.create("/apps", null, Ids.CREATOR_ALL_ACL, + CreateMode.PERSISTENT); + Assert.fail("validate auth"); + } catch (KeeperException.NoAuthException e) { + // expected + } + zk.close(); + // verify access using original auth + zk = createClient(); + zk.addAuthInfo("digest", "pat:test".getBytes()); + zk.getData("/", false, null); + zk.create("/apps", null, Ids.CREATOR_ALL_ACL, + CreateMode.PERSISTENT); + zk.delete("/apps", -1); + // reset acl (back to open) and verify accessible again + zk.setACL("/", Ids.OPEN_ACL_UNSAFE, -1); + zk.close(); + zk = createClient(); + zk.getData("/", false, null); + zk.create("/apps", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + try { + zk.create("/apps", null, Ids.CREATOR_ALL_ACL, + CreateMode.PERSISTENT); + Assert.fail("validate auth"); + } catch (KeeperException.InvalidACLException e) { + // expected + } + zk.delete("/apps", -1); + zk.addAuthInfo("digest", "world:anyone".getBytes()); + zk.create("/apps", null, Ids.CREATOR_ALL_ACL, + CreateMode.PERSISTENT); + zk.close(); + zk = createClient(); + zk.delete("/apps", -1); + } finally { + zk.close(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ACLTest.java b/src/java/test/org/apache/zookeeper/test/ACLTest.java new file mode 100644 index 00000000000..cdc0d816258 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ACLTest.java @@ -0,0 +1,190 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.auth.IPAuthenticationProvider; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.ArrayList; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class ACLTest extends ZKTestCase implements Watcher { + private static final Logger LOG = LoggerFactory.getLogger(ACLTest.class); + private static final String HOSTPORT = + "127.0.0.1:" + PortAssignment.unique(); + private volatile CountDownLatch startSignal; + + @Test + public void testIPAuthenticationIsValidCIDR() throws Exception { + IPAuthenticationProvider prov = new IPAuthenticationProvider(); + Assert.assertTrue("testing no netmask", prov.isValid("127.0.0.1")); + Assert.assertTrue("testing single ip netmask", prov.isValid("127.0.0.1/32")); + Assert.assertTrue("testing lowest netmask possible", prov.isValid("127.0.0.1/0")); + Assert.assertFalse("testing netmask too high", prov.isValid("127.0.0.1/33")); + Assert.assertFalse("testing netmask too low", prov.isValid("10.0.0.1/-1")); + } + + @Test + public void testDisconnectedAddAuth() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(1000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + try { + LOG.info("starting up the zookeeper server .. waiting"); + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + try { + zk.addAuthInfo("digest", "pat:test".getBytes()); + zk.setACL("/", Ids.CREATOR_ALL_ACL, -1); + } finally { + zk.close(); + } + } finally { + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + ClientBase.CONNECTION_TIMEOUT)); + } + } + + /** + * Verify that acl optimization of storing just + * a few acls and there references in the data + * node is actually working. + */ + @Test + public void testAcls() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(1000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + ZooKeeper zk; + String path; + try { + LOG.info("starting up the zookeeper server .. waiting"); + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + LOG.info("starting creating acls"); + for (int i = 0; i < 100; i++) { + path = "/" + i; + zk.create(path, path.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + Assert.assertTrue("size of the acl map ", (1 == zks.getZKDatabase().getAclSize())); + for (int j = 100; j < 200; j++) { + path = "/" + j; + ACL acl = new ACL(); + acl.setPerms(0); + Id id = new Id(); + id.setId("1.1.1." + j); + id.setScheme("ip"); + acl.setId(id); + ArrayList list = new ArrayList(); + list.add(acl); + zk.create(path, path.getBytes(), list, CreateMode.PERSISTENT); + } + Assert.assertTrue("size of the acl map ", (101 == zks.getZKDatabase().getAclSize())); + } finally { + // now shutdown the server and restart it + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + } + startSignal = new CountDownLatch(1); + + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + f = ServerCnxnFactory.createFactory(PORT, -1); + + f.startup(zks); + try { + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + + startSignal.await(CONNECTION_TIMEOUT, + TimeUnit.MILLISECONDS); + Assert.assertTrue("count == 0", startSignal.getCount() == 0); + + Assert.assertTrue("acl map ", (101 == zks.getZKDatabase().getAclSize())); + for (int j = 200; j < 205; j++) { + path = "/" + j; + ACL acl = new ACL(); + acl.setPerms(0); + Id id = new Id(); + id.setId("1.1.1." + j); + id.setScheme("ip"); + acl.setId(id); + ArrayList list = new ArrayList(); + list.add(acl); + zk.create(path, path.getBytes(), list, CreateMode.PERSISTENT); + } + Assert.assertTrue("acl map ", (106 == zks.getZKDatabase().getAclSize())); + + zk.close(); + } finally { + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + ClientBase.CONNECTION_TIMEOUT)); + } + + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatcherEvent) + */ + public void process(WatchedEvent event) { + LOG.info("Event:" + event.getState() + " " + event.getType() + " " + + event.getPath()); + if (event.getState() == KeeperState.SyncConnected) { + if (startSignal != null && startSignal.getCount() > 0) { + LOG.info("startsignal.countDown()"); + startSignal.countDown(); + } else { + LOG.warn("startsignal " + startSignal); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java b/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java new file mode 100644 index 00000000000..287a4b5226c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java @@ -0,0 +1,237 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.AsyncCallback.StringCallback; +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; +import static org.apache.zookeeper.test.ClientBase.verifyThreadTerminated; + +public class AsyncHammerTest extends ZKTestCase + implements StringCallback, VoidCallback, DataCallback { + private static final Logger LOG = LoggerFactory.getLogger(AsyncHammerTest.class); + + private QuorumBase qb = new QuorumBase(); + + private volatile boolean bang; + + public void setUp(boolean withObservers) throws Exception { + qb.setUp(withObservers); + } + + protected void restart() throws Exception { + LOG.info("RESTARTING " + getTestName()); + qb.tearDown(); + + // don't call setup - we don't want to reassign ports/dirs, etc... + JMXEnv.setUp(); + qb.startServers(); + } + + public void tearDown() throws Exception { + LOG.info("Test clients shutting down"); + qb.tearDown(); + } + + @Test + public void testHammer() throws Exception { + setUp(false); + bang = true; + LOG.info("Starting hammers"); + HammerThread[] hammers = new HammerThread[100]; + for (int i = 0; i < hammers.length; i++) { + hammers[i] = new HammerThread("HammerThread-" + i); + hammers[i].start(); + } + LOG.info("Started hammers"); + Thread.sleep(5000); // allow the clients to run for max 5sec + bang = false; + LOG.info("Stopping hammers"); + for (int i = 0; i < hammers.length; i++) { + hammers[i].interrupt(); + verifyThreadTerminated(hammers[i], 60000); + Assert.assertFalse(hammers[i].failed); + } + + // before restart + LOG.info("Hammers stopped, verifying consistency"); + qb.verifyRootOfAllServersMatch(qb.hostPort); + + restart(); + + // after restart + LOG.info("Verifying hammers 2"); + qb.verifyRootOfAllServersMatch(qb.hostPort); + tearDown(); + } + + @Test + public void testObserversHammer() throws Exception { + setUp(true); + bang = true; + Thread[] hammers = new Thread[100]; + for (int i = 0; i < hammers.length; i++) { + hammers[i] = new HammerThread("HammerThread-" + i); + hammers[i].start(); + } + Thread.sleep(5000); // allow the clients to run for max 5sec + bang = false; + for (int i = 0; i < hammers.length; i++) { + hammers[i].interrupt(); + verifyThreadTerminated(hammers[i], 60000); + } + // before restart + qb.verifyRootOfAllServersMatch(qb.hostPort); + tearDown(); + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, String name) { + synchronized (ctx) { + ((LinkedList) ctx).add(rc); + ctx.notifyAll(); + } + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx) { + synchronized (ctx) { + ((LinkedList) ctx).add(rc); + ctx.notifyAll(); + } + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, byte[] data, + Stat stat) { + synchronized (ctx) { + ((LinkedList) ctx).add(rc); + ctx.notifyAll(); + } + } + + /** + * Create /test- sequence nodes asynchronously, max 30 outstanding + */ + class HammerThread extends Thread implements StringCallback, VoidCallback { + private static final int MAX_OUTSTANDING = 30; + + private TestableZooKeeper zk; + private int outstanding; + + private volatile boolean failed = false; + + public HammerThread(String name) { + super(name); + } + + public void run() { + try { + CountdownWatcher watcher = new CountdownWatcher(); + zk = new TestableZooKeeper(qb.hostPort, CONNECTION_TIMEOUT, + watcher); + watcher.waitForConnected(CONNECTION_TIMEOUT); + while (bang) { + incOutstanding(); // before create otw race + zk.create("/test-", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL, this, null); + } + } catch (InterruptedException e) { + if (bang) { + LOG.error("sanity check Assert.failed!!!"); // sanity check + return; + } + } catch (Exception e) { + LOG.error("Client create operation Assert.failed", e); + return; + } finally { + if (zk != null) { + try { + zk.close(); + if (!zk.testableWaitForShutdown(CONNECTION_TIMEOUT)) { + failed = true; + LOG.error("Client did not shutdown"); + } + } catch (InterruptedException e) { + LOG.info("Interrupted", e); + } + } + } + } + + private synchronized void incOutstanding() throws InterruptedException { + outstanding++; + while (outstanding > MAX_OUTSTANDING) { + wait(); + } + } + + private synchronized void decOutstanding() { + outstanding--; + Assert.assertTrue("outstanding >= 0", outstanding >= 0); + notifyAll(); + } + + public void process(WatchedEvent event) { + // ignore for purposes of this test + } + + public void processResult(int rc, String path, Object ctx, String name) { + if (rc != KeeperException.Code.OK.intValue()) { + if (bang) { + failed = true; + LOG.error("Create Assert.failed for 0x" + + Long.toHexString(zk.getSessionId()) + + "with rc:" + rc + " path:" + path); + } + decOutstanding(); + return; + } + try { + decOutstanding(); + zk.delete(name, -1, this, null); + } catch (Exception e) { + if (bang) { + failed = true; + LOG.error("Client delete Assert.failed", e); + } + } + } + + public void processResult(int rc, String path, Object ctx) { + if (rc != KeeperException.Code.OK.intValue()) { + if (bang) { + failed = true; + LOG.error("Delete Assert.failed for 0x" + + Long.toHexString(zk.getSessionId()) + + "with rc:" + rc + " path:" + path); + } + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/AsyncOps.java b/src/java/test/org/apache/zookeeper/test/AsyncOps.java new file mode 100644 index 00000000000..3d455c43272 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/AsyncOps.java @@ -0,0 +1,813 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.ACLCallback; +import org.apache.zookeeper.AsyncCallback.Children2Callback; +import org.apache.zookeeper.AsyncCallback.ChildrenCallback; +import org.apache.zookeeper.AsyncCallback.Create2Callback; +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.AsyncCallback.MultiCallback; +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.AsyncCallback.StringCallback; +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.OpResult; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class AsyncOps { + /** + * This is the base class for all of the async callback classes. It will + * verify the expected value against the actual value. + * + * Basic operation is that the subclasses will generate an "expected" value + * which is defined by the "toString" method of the subclass. This is + * passed through to the verify clause by specifying it as the ctx object + * of each async call (processResult methods get the ctx as part of + * the callback). Additionally the callback will also overwrite any + * instance fields with matching parameter arguments to the processResult + * method. The cb instance can then compare the expected to the + * actual value by again calling toString and comparing the two. + * + * The format of each expected value differs (is defined) by subclass. + * Generally the expected value starts with the result code (rc) and path + * of the node being operated on, followed by the fields specific to + * each operation type (cb subclass). For example ChildrenCB specifies + * a list of the expected children suffixed onto the rc and path. See + * the toString() method of each subclass for details of it's format. + */ + public static abstract class AsyncCB { + protected final ZooKeeper zk; + protected long defaultTimeoutMillis = 30000; + + /** the latch is used to await the results from the server */ + CountDownLatch latch; + + Code rc = Code.OK; + String path = "/foo"; + String expected; + + public AsyncCB(ZooKeeper zk, CountDownLatch latch) { + this.zk = zk; + this.latch = latch; + } + + public void setRC(Code rc) { + this.rc = rc; + } + + public void setPath(String path) { + this.path = path; + } + + public void processResult(Code rc, String path, Object ctx) { + this.rc = rc; + this.path = path; + this.expected = (String) ctx; + latch.countDown(); + } + + /** String format is rc:path: where is defined by each + * subclass individually. */ + @Override + public String toString() { + return rc + ":" + path + ":"; + } + + protected void verify() { + try { + latch.await(defaultTimeoutMillis, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + Assert.fail("unexpected interrupt"); + } + // on the lookout for timeout + Assert.assertSame(0L, latch.getCount()); + + String actual = toString(); + + Assert.assertEquals(expected, actual); + } + } + + public static class StringCB extends AsyncCB implements StringCallback { + byte[] data = new byte[10]; + List acl = Ids.CREATOR_ALL_ACL; + CreateMode flags = CreateMode.PERSISTENT; + String name = path; + + StringCB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + StringCB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + } + + public void setPath(String path) { + super.setPath(path); + this.name = path; + } + + public String nodeName() { + return path.substring(path.lastIndexOf('/') + 1); + } + + public void processResult(int rc, String path, Object ctx, String name) { + this.name = name; + super.processResult(Code.get(rc), path, ctx); + } + + public AsyncCB create() { + zk.create(path, data, acl, flags, this, toString()); + return this; + } + + public AsyncCB createEphemeral() { + zk.create(path, data, acl, CreateMode.EPHEMERAL, this, toString()); + return this; + } + + public void verifyCreate() { + create(); + verify(); + } + + public void verifyCreateEphemeral() { + createEphemeral(); + verify(); + } + + public void verifyCreateFailure_NodeExists() { + new StringCB(zk).verifyCreate(); + + rc = Code.NODEEXISTS; + name = null; + zk.create(path, data, acl, flags, this, toString()); + verify(); + } + + public void verifyCreateFailure_NoNode() { + + rc = Code.NONODE; + name = null; + path = path + "/bar"; + zk.create(path, data, acl, flags, this, toString()); + + verify(); + } + + public void verifyCreateFailure_NoChildForEphemeral() { + new StringCB(zk).verifyCreateEphemeral(); + + rc = Code.NOCHILDRENFOREPHEMERALS; + name = null; + path = path + "/bar"; + zk.create(path, data, acl, flags, this, toString()); + + verify(); + } + + @Override + public String toString() { + return super.toString() + name; + } + } + + public static class ACLCB extends AsyncCB implements ACLCallback { + List acl = Ids.CREATOR_ALL_ACL; + int version = 0; + Stat stat = new Stat(); + byte[] data = "testing".getBytes(); + + ACLCB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + ACLCB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + stat.setAversion(0); + stat.setCversion(0); + stat.setEphemeralOwner(0); + stat.setVersion(0); + } + + public void processResult(int rc, String path, Object ctx, + List acl, Stat stat) { + this.acl = acl; + this.stat = stat; + super.processResult(Code.get(rc), path, ctx); + } + + public void verifyGetACL() { + new StringCB(zk).verifyCreate(); + + zk.getACL(path, stat, this, toString()); + verify(); + } + + public void verifyGetACLFailure_NoNode() { + rc = Code.NONODE; + stat = null; + acl = null; + zk.getACL(path, stat, this, toString()); + + verify(); + } + + public String toString(List acls) { + if (acls == null) { + return ""; + } + + StringBuilder result = new StringBuilder(); + for (ACL acl : acls) { + result.append(acl.getPerms()).append("::"); + } + return result.toString(); + } + + @Override + public String toString() { + return super.toString() + toString(acl) + ":" + + ":" + version + ":" + new String(data) + + ":" + (stat == null ? "null" : stat.getAversion() + ":" + + stat.getCversion() + ":" + stat.getEphemeralOwner() + + ":" + stat.getVersion()); + } + } + + public static class ChildrenCB extends AsyncCB implements ChildrenCallback { + List children = new ArrayList(); + + ChildrenCB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + ChildrenCB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + } + + public void processResult(int rc, String path, Object ctx, + List children) { + this.children = + (children == null ? new ArrayList() : children); + Collections.sort(this.children); + super.processResult(Code.get(rc), path, ctx); + } + + public StringCB createNode() { + StringCB parent = new StringCB(zk); + parent.verifyCreate(); + + return parent; + } + + public StringCB createNode(StringCB parent) { + String childName = "bar"; + + return createNode(parent, childName); + } + + public StringCB createNode(StringCB parent, String childName) { + StringCB child = new StringCB(zk); + child.setPath(parent.path + "/" + childName); + child.verifyCreate(); + + return child; + } + + public void verifyGetChildrenEmpty() { + StringCB parent = createNode(); + path = parent.path; + verify(); + } + + public void verifyGetChildrenSingle() { + StringCB parent = createNode(); + StringCB child = createNode(parent); + + path = parent.path; + children.add(child.nodeName()); + + verify(); + } + + public void verifyGetChildrenTwo() { + StringCB parent = createNode(); + StringCB child1 = createNode(parent, "child1"); + StringCB child2 = createNode(parent, "child2"); + + path = parent.path; + children.add(child1.nodeName()); + children.add(child2.nodeName()); + + verify(); + } + + public void verifyGetChildrenFailure_NoNode() { + rc = KeeperException.Code.NONODE; + verify(); + } + + @Override + public void verify() { + zk.getChildren(path, false, this, toString()); + super.verify(); + } + + @Override + public String toString() { + return super.toString() + children.toString(); + } + } + + public static class Children2CB extends AsyncCB implements Children2Callback { + List children = new ArrayList(); + + Children2CB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + Children2CB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + } + + public void processResult(int rc, String path, Object ctx, + List children, Stat stat) { + this.children = + (children == null ? new ArrayList() : children); + Collections.sort(this.children); + super.processResult(Code.get(rc), path, ctx); + } + + public StringCB createNode() { + StringCB parent = new StringCB(zk); + parent.verifyCreate(); + + return parent; + } + + public StringCB createNode(StringCB parent) { + String childName = "bar"; + + return createNode(parent, childName); + } + + public StringCB createNode(StringCB parent, String childName) { + StringCB child = new StringCB(zk); + child.setPath(parent.path + "/" + childName); + child.verifyCreate(); + + return child; + } + + public void verifyGetChildrenEmpty() { + StringCB parent = createNode(); + path = parent.path; + verify(); + } + + public void verifyGetChildrenSingle() { + StringCB parent = createNode(); + StringCB child = createNode(parent); + + path = parent.path; + children.add(child.nodeName()); + + verify(); + } + + public void verifyGetChildrenTwo() { + StringCB parent = createNode(); + StringCB child1 = createNode(parent, "child1"); + StringCB child2 = createNode(parent, "child2"); + + path = parent.path; + children.add(child1.nodeName()); + children.add(child2.nodeName()); + + verify(); + } + + public void verifyGetChildrenFailure_NoNode() { + rc = KeeperException.Code.NONODE; + verify(); + } + + @Override + public void verify() { + zk.getChildren(path, false, this, toString()); + super.verify(); + } + + @Override + public String toString() { + return super.toString() + children.toString(); + } + } + + public static class Create2CB extends AsyncCB implements Create2Callback { + byte[] data = new byte[10]; + List acl = Ids.CREATOR_ALL_ACL; + CreateMode flags = CreateMode.PERSISTENT; + String name = path; + Stat stat = new Stat(); + + Create2CB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + Create2CB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + } + + public void setPath(String path) { + super.setPath(path); + this.name = path; + } + + public String nodeName() { + return path.substring(path.lastIndexOf('/') + 1); + } + + public void processResult(int rc, String path, Object ctx, + String name, Stat stat) { + this.name = name; + this.stat = stat; + super.processResult(Code.get(rc), path, ctx); + } + + public AsyncCB create() { + zk.create(path, data, acl, flags, this, toString()); + return this; + } + + public void verifyCreate() { + create(); + verify(); + } + + public void verifyCreateFailure_NodeExists() { + new Create2CB(zk).verifyCreate(); + rc = Code.NODEEXISTS; + name = null; + stat = null; + zk.create(path, data, acl, flags, this, toString()); + verify(); + } + + public void verifyCreateFailure_NoNode() { + rc = Code.NONODE; + name = null; + stat = null; + path = path + "/bar"; + zk.create(path, data, acl, flags, this, toString()); + + verify(); + } + + public void verifyCreateFailure_NoChildForEphemeral() { + new StringCB(zk).verifyCreateEphemeral(); + + rc = Code.NOCHILDRENFOREPHEMERALS; + name = null; + stat = null; + path = path + "/bar"; + zk.create(path, data, acl, flags, this, toString()); + + verify(); + } + + @Override + public String toString() { + return super.toString() + name + ":" + + (stat == null ? "null" : stat.getAversion() + ":" + + stat.getCversion() + ":" + stat.getEphemeralOwner() + + ":" + stat.getVersion()); + } + } + + public static class DataCB extends AsyncCB implements DataCallback { + byte[] data = new byte[10]; + Stat stat = new Stat(); + + DataCB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + DataCB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + stat.setAversion(0); + stat.setCversion(0); + stat.setEphemeralOwner(0); + stat.setVersion(0); + } + + public void processResult(int rc, String path, Object ctx, byte[] data, + Stat stat) { + this.data = data; + this.stat = stat; + super.processResult(Code.get(rc), path, ctx); + } + + public void verifyGetData() { + new StringCB(zk).verifyCreate(); + + zk.getData(path, false, this, toString()); + verify(); + } + + public void verifyGetDataFailure_NoNode() { + rc = KeeperException.Code.NONODE; + data = null; + stat = null; + zk.getData(path, false, this, toString()); + verify(); + } + + @Override + public String toString() { + return super.toString() + + ":" + (data == null ? "null" : new String(data)) + + ":" + (stat == null ? "null" : stat.getAversion() + ":" + + stat.getCversion() + ":" + stat.getEphemeralOwner() + + ":" + stat.getVersion()); + } + } + + public static class StatCB extends AsyncCB implements StatCallback { + List acl = Ids.CREATOR_ALL_ACL; + int version = 0; + Stat stat = new Stat(); + byte[] data = "testing".getBytes(); + + StatCB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + StatCB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + stat.setAversion(0); + stat.setCversion(0); + stat.setEphemeralOwner(0); + stat.setVersion(0); + } + + public void processResult(int rc, String path, Object ctx, Stat stat) { + this.stat = stat; + super.processResult(Code.get(rc), path, ctx); + } + + public void verifySetACL() { + stat.setAversion(1); + new StringCB(zk).verifyCreate(); + + zk.setACL(path, acl, version, this, toString()); + verify(); + } + + public void verifySetACLFailure_NoNode() { + rc = KeeperException.Code.NONODE; + stat = null; + zk.setACL(path, acl, version, this, toString()); + verify(); + } + + public void verifySetACLFailure_BadVersion() { + new StringCB(zk).verifyCreate(); + + rc = Code.BADVERSION; + stat = null; + zk.setACL(path, acl, version + 1, this, toString()); + + verify(); + } + + public void setData() { + zk.setData(path, data, version, this, toString()); + } + + public void verifySetData() { + stat.setVersion(1); + new StringCB(zk).verifyCreate(); + + setData(); + verify(); + } + + public void verifySetDataFailure_NoNode() { + rc = KeeperException.Code.NONODE; + stat = null; + zk.setData(path, data, version, this, toString()); + verify(); + } + + public void verifySetDataFailure_BadVersion() { + new StringCB(zk).verifyCreate(); + + rc = Code.BADVERSION; + stat = null; + zk.setData(path, data, version + 1, this, toString()); + + verify(); + } + + public void verifyExists() { + new StringCB(zk).verifyCreate(); + + zk.exists(path, false, this, toString()); + verify(); + } + + public void verifyExistsFailure_NoNode() { + rc = KeeperException.Code.NONODE; + stat = null; + zk.exists(path, false, this, toString()); + verify(); + } + + @Override + public String toString() { + return super.toString() + version + + ":" + new String(data) + + ":" + (stat == null ? "null" : stat.getAversion() + ":" + + stat.getCversion() + ":" + stat.getEphemeralOwner() + + ":" + stat.getVersion()); + } + } + + public static class VoidCB extends AsyncCB implements VoidCallback { + int version = 0; + + VoidCB(ZooKeeper zk) { + this(zk, new CountDownLatch(1)); + } + + VoidCB(ZooKeeper zk, CountDownLatch latch) { + super(zk, latch); + } + + public void processResult(int rc, String path, Object ctx) { + super.processResult(Code.get(rc), path, ctx); + } + + public void delete() { + zk.delete(path, version, this, toString()); + } + + public void verifyDelete() { + new StringCB(zk).verifyCreate(); + + delete(); + verify(); + } + + public void verifyDeleteFailure_NoNode() { + rc = Code.NONODE; + zk.delete(path, version, this, toString()); + verify(); + } + + public void verifyDeleteFailure_BadVersion() { + new StringCB(zk).verifyCreate(); + rc = Code.BADVERSION; + zk.delete(path, version + 1, this, toString()); + verify(); + } + + public void verifyDeleteFailure_NotEmpty() { + StringCB scb = new StringCB(zk); + scb.create(); + scb.setPath(path + "/bar"); + scb.create(); + + rc = Code.NOTEMPTY; + zk.delete(path, version, this, toString()); + verify(); + } + + public void sync() { + zk.sync(path, this, toString()); + } + + public void verifySync() { + sync(); + verify(); + } + + @Override + public String toString() { + return super.toString() + version; + } + } + + public static class MultiCB implements MultiCallback { + final CountDownLatch latch = new CountDownLatch(1); + ZooKeeper zk; + int rc; + List opResults; + + MultiCB(ZooKeeper zk) { + this.zk = zk; + } + + public void processResult(int rc, String path, Object ctx, + List opResults) { + this.rc = rc; + this.opResults = opResults; + latch.countDown(); + } + + void latch_await() { + try { + latch.await(10000, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + Assert.fail("unexpected interrupt"); + } + Assert.assertSame(0L, latch.getCount()); + } + + public void verifyMulti() { + List ops = Arrays.asList( + Op.create("/multi", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/multi", -1)); + zk.multi(ops, this, null); + latch_await(); + + Assert.assertEquals(this.rc, KeeperException.Code.OK.intValue()); + Assert.assertTrue(this.opResults.get(0) instanceof OpResult.CreateResult); + Assert.assertTrue(this.opResults.get(1) instanceof OpResult.DeleteResult); + } + + public void verifyMultiFailure_AllErrorResult() { + List ops = Arrays.asList( + Op.create("/multi", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/nonexist1", -1), + Op.setData("/multi", "test".getBytes(), -1)); + zk.multi(ops, this, null); + latch_await(); + + Assert.assertTrue(this.opResults.get(0) instanceof OpResult.ErrorResult); + Assert.assertTrue(this.opResults.get(1) instanceof OpResult.ErrorResult); + Assert.assertTrue(this.opResults.get(2) instanceof OpResult.ErrorResult); + } + + public void verifyMultiFailure_NoSideEffect() throws KeeperException, InterruptedException { + List ops = Arrays.asList( + Op.create("/multi", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/nonexist1", -1)); + zk.multi(ops, this, null); + latch_await(); + + Assert.assertTrue(this.opResults.get(0) instanceof OpResult.ErrorResult); + Assert.assertNull(zk.exists("/multi", false)); + } + + public void verifyMultiSequential_NoSideEffect() throws Exception { + StringCB scb = new StringCB(zk); + scb.verifyCreate(); + String path = scb.path + "-"; + String seqPath = path + "0000000002"; + + zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + Assert.assertNotNull(zk.exists(path + "0000000001", false)); + + List ops = Arrays.asList( + Op.create(path, new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL), + Op.delete("/nonexist", -1)); + zk.multi(ops, this, null); + latch_await(); + + Assert.assertNull(zk.exists(seqPath, false)); + zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + Assert.assertNotNull(zk.exists(seqPath, false)); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/AsyncOpsTest.java b/src/java/test/org/apache/zookeeper/test/AsyncOpsTest.java new file mode 100644 index 00000000000..93a233cddb2 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/AsyncOpsTest.java @@ -0,0 +1,263 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.AsyncOps.ACLCB; +import org.apache.zookeeper.test.AsyncOps.Children2CB; +import org.apache.zookeeper.test.AsyncOps.ChildrenCB; +import org.apache.zookeeper.test.AsyncOps.Create2CB; +import org.apache.zookeeper.test.AsyncOps.DataCB; +import org.apache.zookeeper.test.AsyncOps.MultiCB; +import org.apache.zookeeper.test.AsyncOps.StatCB; +import org.apache.zookeeper.test.AsyncOps.StringCB; +import org.apache.zookeeper.test.AsyncOps.VoidCB; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.CountDownLatch; + +public class AsyncOpsTest extends ClientBase { + private static final Logger LOG = LoggerFactory.getLogger(AsyncOpsTest.class); + + private ZooKeeper zk; + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + + LOG.info("Creating client " + getTestName()); + + zk = createClient(); + zk.addAuthInfo("digest", "ben:passwd".getBytes()); + } + + @After + @Override + public void tearDown() throws Exception { + zk.close(); + + super.tearDown(); + + LOG.info("Test clients shutting down"); + } + + @Test + public void testAsyncCreate() { + new StringCB(zk).verifyCreate(); + } + + @Test + public void testAsyncCreate2() { + new Create2CB(zk).verifyCreate(); + } + + @Test + public void testAsyncCreateThree() { + CountDownLatch latch = new CountDownLatch(3); + + StringCB op1 = new StringCB(zk, latch); + op1.setPath("/op1"); + StringCB op2 = new StringCB(zk, latch); + op2.setPath("/op2"); + StringCB op3 = new StringCB(zk, latch); + op3.setPath("/op3"); + + op1.create(); + op2.create(); + op3.create(); + + op1.verify(); + op2.verify(); + op3.verify(); + } + + @Test + public void testAsyncCreateFailure_NodeExists() { + new StringCB(zk).verifyCreateFailure_NodeExists(); + } + + @Test + public void testAsyncCreateFailure_NoNode() { + new StringCB(zk).verifyCreateFailure_NoNode(); + } + + @Test + public void testAsyncCreateFailure_NoChildForEphemeral() { + new StringCB(zk).verifyCreateFailure_NoChildForEphemeral(); + } + + @Test + public void testAsyncCreate2Failure_NodeExists() { + new Create2CB(zk).verifyCreateFailure_NodeExists(); + } + + @Test + public void testAsyncCreate2Failure_NoNode() { + new Create2CB(zk).verifyCreateFailure_NoNode(); + } + + + @Test + public void testAsyncCreate2Failure_NoChildForEphemeral() { + new Create2CB(zk).verifyCreateFailure_NoChildForEphemeral(); + } + + @Test + public void testAsyncDelete() { + new VoidCB(zk).verifyDelete(); + } + + @Test + public void testAsyncDeleteFailure_NoNode() { + new VoidCB(zk).verifyDeleteFailure_NoNode(); + } + + @Test + public void testAsyncDeleteFailure_BadVersion() { + new VoidCB(zk).verifyDeleteFailure_BadVersion(); + } + + @Test + public void testAsyncDeleteFailure_NotEmpty() { + new VoidCB(zk).verifyDeleteFailure_NotEmpty(); + } + + @Test + public void testAsyncSync() { + new VoidCB(zk).verifySync(); + } + + @Test + public void testAsyncSetACL() { + new StatCB(zk).verifySetACL(); + } + + @Test + public void testAsyncSetACLFailure_NoNode() { + new StatCB(zk).verifySetACLFailure_NoNode(); + } + + @Test + public void testAsyncSetACLFailure_BadVersion() { + new StatCB(zk).verifySetACLFailure_BadVersion(); + } + + @Test + public void testAsyncSetData() { + new StatCB(zk).verifySetData(); + } + + @Test + public void testAsyncSetDataFailure_NoNode() { + new StatCB(zk).verifySetDataFailure_NoNode(); + } + + @Test + public void testAsyncSetDataFailure_BadVersion() { + new StatCB(zk).verifySetDataFailure_BadVersion(); + } + + @Test + public void testAsyncExists() { + new StatCB(zk).verifyExists(); + } + + @Test + public void testAsyncExistsFailure_NoNode() { + new StatCB(zk).verifyExistsFailure_NoNode(); + } + + @Test + public void testAsyncGetACL() { + new ACLCB(zk).verifyGetACL(); + } + + @Test + public void testAsyncGetACLFailure_NoNode() { + new ACLCB(zk).verifyGetACLFailure_NoNode(); + } + + @Test + public void testAsyncGetChildrenEmpty() { + new ChildrenCB(zk).verifyGetChildrenEmpty(); + } + + @Test + public void testAsyncGetChildrenSingle() { + new ChildrenCB(zk).verifyGetChildrenSingle(); + } + + @Test + public void testAsyncGetChildrenTwo() { + new ChildrenCB(zk).verifyGetChildrenTwo(); + } + + @Test + public void testAsyncGetChildrenFailure_NoNode() { + new ChildrenCB(zk).verifyGetChildrenFailure_NoNode(); + } + + @Test + public void testAsyncGetChildren2Empty() { + new Children2CB(zk).verifyGetChildrenEmpty(); + } + + @Test + public void testAsyncGetChildren2Single() { + new Children2CB(zk).verifyGetChildrenSingle(); + } + + @Test + public void testAsyncGetChildren2Two() { + new Children2CB(zk).verifyGetChildrenTwo(); + } + + @Test + public void testAsyncGetChildren2Failure_NoNode() { + new Children2CB(zk).verifyGetChildrenFailure_NoNode(); + } + + @Test + public void testAsyncGetData() { + new DataCB(zk).verifyGetData(); + } + + @Test + public void testAsyncGetDataFailure_NoNode() { + new DataCB(zk).verifyGetDataFailure_NoNode(); + } + + @Test + public void testAsyncMulti() { + new MultiCB(zk).verifyMulti(); + } + + @Test + public void testAsyncMultiFailure_AllErrorResult() { + new MultiCB(zk).verifyMultiFailure_AllErrorResult(); + } + + @Test + public void testAsyncMultiFailure_NoSideEffect() throws Exception { + new MultiCB(zk).verifyMultiFailure_NoSideEffect(); + } + + @Test + public void testAsyncMultiSequential_NoSideEffect() throws Exception { + new MultiCB(zk).verifyMultiSequential_NoSideEffect(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/AsyncTest.java b/src/java/test/org/apache/zookeeper/test/AsyncTest.java new file mode 100644 index 00000000000..96e06b617a1 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/AsyncTest.java @@ -0,0 +1,155 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.AsyncCallback.StringCallback; +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class AsyncTest extends ZKTestCase + implements StringCallback, VoidCallback, DataCallback { + private static final Logger LOG = LoggerFactory.getLogger(AsyncTest.class); + LinkedList results = new LinkedList(); + private QuorumBase qb = new QuorumBase(); + + @Before + public void setUp() throws Exception { + qb.setUp(); + } + + @After + public void tearDown() throws Exception { + LOG.info("Test clients shutting down"); + qb.tearDown(); + } + + private ZooKeeper createClient() throws IOException, InterruptedException { + return createClient(qb.hostPort); + } + + private ZooKeeper createClient(String hp) + throws IOException, InterruptedException { + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper(hp, CONNECTION_TIMEOUT, watcher); + if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, + TimeUnit.MILLISECONDS)) { + Assert.fail("Unable to connect to server"); + } + return zk; + } + + @Test + public void testAsync() + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = null; + zk = createClient(); + try { + zk.addAuthInfo("digest", "ben:passwd".getBytes()); + zk.create("/ben", new byte[0], Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT, this, results); + zk.create("/ben/2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results); + zk.delete("/ben", -1, this, results); + zk.create("/ben2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results); + zk.getData("/ben2", false, this, results); + synchronized (results) { + while (results.size() < 5) { + results.wait(); + } + } + Assert.assertEquals(0, (int) results.get(0)); + Assert.assertEquals(Code.NOAUTH, Code.get(results.get(1))); + Assert.assertEquals(0, (int) results.get(2)); + Assert.assertEquals(0, (int) results.get(3)); + Assert.assertEquals(0, (int) results.get(4)); + } finally { + zk.close(); + } + + zk = createClient(); + try { + zk.addAuthInfo("digest", "ben:passwd2".getBytes()); + try { + zk.getData("/ben2", false, new Stat()); + Assert.fail("Should have received a permission error"); + } catch (KeeperException e) { + Assert.assertEquals(Code.NOAUTH, e.code()); + } + } finally { + zk.close(); + } + + zk = createClient(); + try { + zk.addAuthInfo("digest", "ben:passwd".getBytes()); + zk.getData("/ben2", false, new Stat()); + } finally { + zk.close(); + } + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, String name) { + synchronized (ctx) { + ((LinkedList) ctx).add(rc); + ctx.notifyAll(); + } + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx) { + synchronized (ctx) { + ((LinkedList) ctx).add(rc); + ctx.notifyAll(); + } + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, byte[] data, + Stat stat) { + synchronized (ctx) { + ((LinkedList) ctx).add(rc); + ctx.notifyAll(); + } + } + + private static class CountdownWatcher implements Watcher { + volatile CountDownLatch clientConnected = new CountDownLatch(1); + + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.SyncConnected) { + clientConnected.countDown(); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/AtomicFileOutputStreamTest.java b/src/java/test/org/apache/zookeeper/test/AtomicFileOutputStreamTest.java new file mode 100644 index 00000000000..a1ff3050a19 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/AtomicFileOutputStreamTest.java @@ -0,0 +1,194 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.common.AtomicFileOutputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class AtomicFileOutputStreamTest extends ZKTestCase { + private static final String TEST_STRING = "hello world"; + private static final String TEST_STRING_2 = "goodbye world"; + + private File testDir; + private File dstFile; + + @Before + public void setupTestDir() throws IOException { + testDir = ClientBase.createTmpDir(); + dstFile = new File(testDir, "test.txt"); + } + + @After + public void cleanupTestDir() throws IOException { + ClientBase.recursiveDelete(testDir); + } + + /** + * Test case where there is no existing file + */ + @Test + public void testWriteNewFile() throws IOException { + OutputStream fos = new AtomicFileOutputStream(dstFile); + assertFalse(dstFile.exists()); + fos.write(TEST_STRING.getBytes()); + fos.flush(); + assertFalse(dstFile.exists()); + fos.close(); + assertTrue(dstFile.exists()); + + String readBackData = ClientBase.readFile(dstFile); + assertEquals(TEST_STRING, readBackData); + } + + /** + * Test case where there is no existing file + */ + @Test + public void testOverwriteFile() throws IOException { + assertTrue("Creating empty dst file", dstFile.createNewFile()); + + OutputStream fos = new AtomicFileOutputStream(dstFile); + + assertTrue("Empty file still exists", dstFile.exists()); + fos.write(TEST_STRING.getBytes()); + fos.flush(); + + // Original contents still in place + assertEquals("", ClientBase.readFile(dstFile)); + + fos.close(); + + // New contents replace original file + String readBackData = ClientBase.readFile(dstFile); + assertEquals(TEST_STRING, readBackData); + } + + /** + * Test case where the flush() fails at close time - make sure that we clean + * up after ourselves and don't touch any existing file at the destination + */ + @Test + public void testFailToFlush() throws IOException { + // Create a file at destination + FileOutputStream fos = new FileOutputStream(dstFile); + fos.write(TEST_STRING_2.getBytes()); + fos.close(); + + OutputStream failingStream = createFailingStream(); + failingStream.write(TEST_STRING.getBytes()); + try { + failingStream.close(); + fail("Close didn't throw exception"); + } catch (IOException ioe) { + // expected + } + + // Should not have touched original file + assertEquals(TEST_STRING_2, ClientBase.readFile(dstFile)); + + assertEquals("Temporary file should have been cleaned up", + dstFile.getName(), ClientBase.join(",", testDir.list())); + } + + /** + * Create a stream that fails to flush at close time + */ + private OutputStream createFailingStream() throws FileNotFoundException { + return new AtomicFileOutputStream(dstFile) { + @Override + public void flush() throws IOException { + throw new IOException("injected failure"); + } + }; + } + + /** + * Ensure the tmp file is cleaned up and dstFile is not created when + * aborting a new file. + */ + @Test + public void testAbortNewFile() throws IOException { + AtomicFileOutputStream fos = new AtomicFileOutputStream(dstFile); + + fos.abort(); + + assertEquals(0, testDir.list().length); + } + + /** + * Ensure the tmp file is cleaned up and dstFile is not created when + * aborting a new file. + */ + @Test + public void testAbortNewFileAfterFlush() throws IOException { + AtomicFileOutputStream fos = new AtomicFileOutputStream(dstFile); + fos.write(TEST_STRING.getBytes()); + fos.flush(); + + fos.abort(); + + assertEquals(0, testDir.list().length); + } + + /** + * Ensure the tmp file is cleaned up and dstFile is untouched when + * aborting an existing file overwrite. + */ + @Test + public void testAbortExistingFile() throws IOException { + FileOutputStream fos1 = new FileOutputStream(dstFile); + fos1.write(TEST_STRING.getBytes()); + fos1.close(); + + AtomicFileOutputStream fos2 = new AtomicFileOutputStream(dstFile); + + fos2.abort(); + + // Should not have touched original file + assertEquals(TEST_STRING, ClientBase.readFile(dstFile)); + assertEquals(1, testDir.list().length); + } + + /** + * Ensure the tmp file is cleaned up and dstFile is untouched when + * aborting an existing file overwrite. + */ + @Test + public void testAbortExistingFileAfterFlush() throws IOException { + FileOutputStream fos1 = new FileOutputStream(dstFile); + fos1.write(TEST_STRING.getBytes()); + fos1.close(); + + AtomicFileOutputStream fos2 = new AtomicFileOutputStream(dstFile); + fos2.write(TEST_STRING_2.getBytes()); + fos2.flush(); + + fos2.abort(); + + // Should not have touched original file + assertEquals(TEST_STRING, ClientBase.readFile(dstFile)); + assertEquals(1, testDir.list().length); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/AuthTest.java b/src/java/test/org/apache/zookeeper/test/AuthTest.java new file mode 100644 index 00000000000..3106358c621 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/AuthTest.java @@ -0,0 +1,160 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class AuthTest extends ClientBase { + static { + // password is test + System.setProperty("zookeeper.DigestAuthenticationProvider.superDigest", + "super:D/InIHSb7yEEbrWz8b9l71RjZJU="); + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.test.InvalidAuthProvider"); + } + + private final CountDownLatch authFailed = new CountDownLatch(1); + + @Override + protected TestableZooKeeper createClient(String hp) + throws IOException, InterruptedException { + MyWatcher watcher = new MyWatcher(); + return createClient(watcher, hp); + } + + @Test + public void testBadAuthNotifiesWatch() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.addAuthInfo("FOO", "BAR".getBytes()); + zk.getData("/path1", false, null); + Assert.fail("Should get auth state error"); + } catch (KeeperException.AuthFailedException e) { + if (!authFailed.await(CONNECTION_TIMEOUT, + TimeUnit.MILLISECONDS)) { + Assert.fail("Should have called my watcher"); + } + } finally { + zk.close(); + } + } + + @Test + public void testBadAuthThenSendOtherCommands() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.addAuthInfo("INVALID", "BAR".getBytes()); + zk.exists("/foobar", false); + zk.getData("/path1", false, null); + Assert.fail("Should get auth state error"); + } catch (KeeperException.AuthFailedException e) { + if (!authFailed.await(CONNECTION_TIMEOUT, + TimeUnit.MILLISECONDS)) { + Assert.fail("Should have called my watcher"); + } + } finally { + zk.close(); + } + } + + @Test + public void testSuper() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.addAuthInfo("digest", "pat:pass".getBytes()); + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, + CreateMode.PERSISTENT); + zk.close(); + // verify no auth + zk = createClient(); + try { + zk.getData("/path1", false, null); + Assert.fail("auth verification"); + } catch (KeeperException.NoAuthException e) { + // expected + } + zk.close(); + // verify bad pass Assert.fails + zk = createClient(); + zk.addAuthInfo("digest", "pat:pass2".getBytes()); + try { + zk.getData("/path1", false, null); + Assert.fail("auth verification"); + } catch (KeeperException.NoAuthException e) { + // expected + } + zk.close(); + // verify super with bad pass Assert.fails + zk = createClient(); + zk.addAuthInfo("digest", "super:test2".getBytes()); + try { + zk.getData("/path1", false, null); + Assert.fail("auth verification"); + } catch (KeeperException.NoAuthException e) { + // expected + } + zk.close(); + // verify super with correct pass success + zk = createClient(); + zk.addAuthInfo("digest", "super:test".getBytes()); + zk.getData("/path1", false, null); + } finally { + zk.close(); + } + } + + @Test + public void testSuperACL() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.addAuthInfo("digest", "pat:pass".getBytes()); + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, + CreateMode.PERSISTENT); + zk.close(); + // verify super can do anything and ignores ACLs + zk = createClient(); + zk.addAuthInfo("digest", "super:test".getBytes()); + zk.getData("/path1", false, null); + + zk.setACL("/path1", Ids.READ_ACL_UNSAFE, -1); + zk.create("/path1/foo", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + + + zk.setACL("/path1", Ids.OPEN_ACL_UNSAFE, -1); + + } finally { + zk.close(); + } + } + + private class MyWatcher extends CountdownWatcher { + @Override + public synchronized void process(WatchedEvent event) { + if (event.getState() == KeeperState.AuthFailed) { + authFailed.countDown(); + } else { + super.process(event); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/BufferSizeTest.java b/src/java/test/org/apache/zookeeper/test/BufferSizeTest.java new file mode 100644 index 00000000000..e751d1e02ec --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/BufferSizeTest.java @@ -0,0 +1,127 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.jute.BinaryInputArchive; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class BufferSizeTest extends ClientBase { + public static final int TEST_MAXBUFFER = 100; + private static final File TEST_DATA = new File( + System.getProperty("test.data.dir", "build/test/data"), + "buffersize"); + + private ZooKeeper zk; + + @Before + public void setMaxBuffer() throws IOException, InterruptedException { + System.setProperty("jute.maxbuffer", "" + TEST_MAXBUFFER); + assertEquals("Can't set jute.maxbuffer!", TEST_MAXBUFFER, BinaryInputArchive.maxBuffer); + zk = createClient(); + } + + @Test + public void testCreatesReqs() throws Exception { + testRequests(new ClientOp() { + @Override + public void execute(byte[] data) throws Exception { + zk.create("/create_test", data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + } + }); + } + + @Test + public void testSetReqs() throws Exception { + final String path = "/set_test"; + zk.create(path, new byte[1], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + testRequests(new ClientOp() { + @Override + public void execute(byte[] data) throws Exception { + zk.setData(path, data, -1); + } + }); + } + + /** Issues requests containing data smaller, equal, and greater than TEST_MAXBUFFER. */ + private void testRequests(ClientOp clientOp) throws Exception { + clientOp.execute(new byte[TEST_MAXBUFFER - 60]); + try { + // This should fail since the buffer size > the data size due to extra fields + clientOp.execute(new byte[TEST_MAXBUFFER]); + fail("Request exceeding jute.maxbuffer succeeded!"); + } catch (KeeperException.ConnectionLossException e) { + } + try { + clientOp.execute(new byte[TEST_MAXBUFFER + 10]); + fail("Request exceeding jute.maxbuffer succeeded!"); + } catch (KeeperException.ConnectionLossException e) { + } + } + + @Test + public void testStartup() throws Exception { + final String path = "/test_node"; + zk.create(path, new byte[TEST_MAXBUFFER - 60], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.setData(path, new byte[TEST_MAXBUFFER - 50], -1); + + stopServer(); + startServer(); + } + + @Test + public void testStartupFailureCreate() throws Exception { + // Empty snapshot and logfile containing a 5000-byte create + testStartupFailure(new File(TEST_DATA, "create"), + "Server started despite create exceeding jute.maxbuffer!"); + } + + @Test + public void testStartupFailureSet() throws Exception { + // Empty snapshot and logfile containing a 1-byte create and 5000-byte set + testStartupFailure(new File(TEST_DATA, "set"), + "Server started despite set exceeding jute.maxbuffer!"); + } + + @Test + public void testStartupFailureSnapshot() throws Exception { + // Snapshot containing 5000-byte znode and logfile containing create txn + testStartupFailure(new File(TEST_DATA, "snapshot"), + "Server started despite znode exceeding jute.maxbuffer!"); + } + + private void testStartupFailure(File testDir, String failureMsg) throws Exception { + stopServer(); + // Point server at testDir + tmpDir = testDir; + try { + startServer(); + fail(failureMsg); + } catch (IOException e) { + LOG.info("Successfully caught IOException: " + e); + } + } + + private interface ClientOp { + void execute(byte[] data) throws Exception; + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ChrootAsyncTest.java b/src/java/test/org/apache/zookeeper/test/ChrootAsyncTest.java new file mode 100644 index 00000000000..98fa3a50665 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ChrootAsyncTest.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChrootAsyncTest extends AsyncOpsTest { + private static final Logger LOG = LoggerFactory.getLogger(ChrootAsyncTest.class); + + @Override + public void setUp() throws Exception { + String hp = hostPort; + hostPort = hostPort + "/chrootasynctest"; + + super.setUp(); + + LOG.info("Creating client " + getTestName()); + + ZooKeeper zk = createClient(hp); + try { + zk.create("/chrootasynctest", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } finally { + zk.close(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ChrootClientTest.java b/src/java/test/org/apache/zookeeper/test/ChrootClientTest.java new file mode 100644 index 00000000000..9c50e9851bb --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ChrootClientTest.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChrootClientTest extends ClientTest { + private static final Logger LOG = LoggerFactory.getLogger(ChrootClientTest.class); + + @Override + public void setUp() throws Exception { + String hp = hostPort; + hostPort = hostPort + "/chrootclienttest"; + + System.out.println(hostPort); + super.setUp(); + + LOG.info("STARTING " + getTestName()); + + ZooKeeper zk = createClient(hp); + try { + zk.create("/chrootclienttest", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } finally { + zk.close(); + } + } + + @Test + public void testPing() throws Exception { + // not necessary to repeat this, expensive and not chroot related + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ChrootTest.java b/src/java/test/org/apache/zookeeper/test/ChrootTest.java new file mode 100644 index 00000000000..f9e629ba217 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ChrootTest.java @@ -0,0 +1,130 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class ChrootTest extends ClientBase { + @Test + public void testChrootSynchronous() + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk1 = createClient(); + try { + zk1.create("/ch1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } finally { + if (zk1 != null) + zk1.close(); + } + ZooKeeper zk2 = createClient(hostPort + "/ch1"); + try { + Assert.assertEquals("/ch2", + zk2.create("/ch2", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT)); + } finally { + if (zk2 != null) + zk2.close(); + } + + zk1 = createClient(); + zk2 = createClient(hostPort + "/ch1"); + try { + // check get + MyWatcher w1 = new MyWatcher("/ch1"); + Assert.assertNotNull(zk1.exists("/ch1", w1)); + MyWatcher w2 = new MyWatcher("/ch1/ch2"); + Assert.assertNotNull(zk1.exists("/ch1/ch2", w2)); + + MyWatcher w3 = new MyWatcher("/ch2"); + Assert.assertNotNull(zk2.exists("/ch2", w3)); + + // set watches on child + MyWatcher w4 = new MyWatcher("/ch1"); + zk1.getChildren("/ch1", w4); + MyWatcher w5 = new MyWatcher("/"); + zk2.getChildren("/", w5); + + // check set + zk1.setData("/ch1", "1".getBytes(), -1); + zk2.setData("/ch2", "2".getBytes(), -1); + + // check watches + Assert.assertTrue(w1.matches()); + Assert.assertTrue(w2.matches()); + Assert.assertTrue(w3.matches()); + + // check exceptions + try { + zk2.setData("/ch3", "3".getBytes(), -1); + } catch (KeeperException.NoNodeException e) { + Assert.assertEquals("/ch3", e.getPath()); + } + + Assert.assertTrue(Arrays.equals("1".getBytes(), + zk1.getData("/ch1", false, null))); + Assert.assertTrue(Arrays.equals("2".getBytes(), + zk1.getData("/ch1/ch2", false, null))); + Assert.assertTrue(Arrays.equals("2".getBytes(), + zk2.getData("/ch2", false, null))); + + // check delete + zk2.delete("/ch2", -1); + Assert.assertTrue(w4.matches()); + Assert.assertTrue(w5.matches()); + + zk1.delete("/ch1", -1); + Assert.assertNull(zk1.exists("/ch1", false)); + Assert.assertNull(zk1.exists("/ch1/ch2", false)); + Assert.assertNull(zk2.exists("/ch2", false)); + } finally { + if (zk1 != null) + zk1.close(); + if (zk2 != null) + zk2.close(); + } + } + + private static class MyWatcher implements Watcher { + private final String path; + private String eventPath; + private CountDownLatch latch = new CountDownLatch(1); + + public MyWatcher(String path) { + this.path = path; + } + + public void process(WatchedEvent event) { + System.out.println("latch:" + path + " " + event.getPath()); + this.eventPath = event.getPath(); + latch.countDown(); + } + + public boolean matches() throws InterruptedException { + if (!latch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)) { + Assert.fail("No watch received within timeout period " + path); + } + return path.equals(eventPath); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ClientBase.java b/src/java/test/org/apache/zookeeper/test/ClientBase.java new file mode 100644 index 00000000000..920326e3ad5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ClientBase.java @@ -0,0 +1,659 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.IOUtils; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.common.X509Exception.SSLContextException; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ServerCnxnFactoryAccessor; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.util.OSMXBean; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; + +import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord; + +public abstract class ClientBase extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(ClientBase.class); + static final File BASETEST = + new File(System.getProperty("build.test.dir", "build")); + public static int CONNECTION_TIMEOUT = 30000; + protected String hostPort = "127.0.0.1:" + PortAssignment.unique(); + protected int maxCnxns = 0; + protected ServerCnxnFactory serverFactory = null; + protected File tmpDir = null; + + long initialFdCount; + private LinkedList allClients; + private boolean allClientsSetup = false; + + public ClientBase() { + super(); + } + + public static List parseHostPortList(String hplist) { + ArrayList alist = new ArrayList(); + for (String hp : hplist.split(",")) { + int idx = hp.lastIndexOf(':'); + String host = hp.substring(0, idx); + int port; + try { + port = Integer.parseInt(hp.substring(idx + 1)); + } catch (RuntimeException e) { + throw new RuntimeException("Problem parsing " + hp + e.toString()); + } + alist.add(new HostPort(host, port)); + } + return alist; + } + + public static boolean waitForServerUp(String hp, long timeout) { + return waitForServerUp(hp, timeout, false); + } + + public static boolean waitForServerUp(String hp, long timeout, boolean secure) { + long start = Time.currentElapsedTime(); + while (true) { + try { + // if there are multiple hostports, just take the first one + HostPort hpobj = parseHostPortList(hp).get(0); + String result = send4LetterWord(hpobj.host, hpobj.port, "stat", secure); + if (result.startsWith("Zookeeper version:") && + !result.contains("READ-ONLY")) { + return true; + } + } catch (IOException e) { + // ignore as this is expected + LOG.info("server {} not up", hp, e); + } catch (SSLContextException e) { + LOG.error("server {} not up", hp, e); + } + + if (Time.currentElapsedTime() > start + timeout) { + break; + } + try { + Thread.sleep(250); + } catch (InterruptedException e) { + // ignore + } + } + return false; + } + + public static boolean waitForServerDown(String hp, long timeout) { + return waitForServerDown(hp, timeout, false); + } + + public static boolean waitForServerDown(String hp, long timeout, boolean secure) { + long start = Time.currentElapsedTime(); + while (true) { + try { + HostPort hpobj = parseHostPortList(hp).get(0); + send4LetterWord(hpobj.host, hpobj.port, "stat", secure); + } catch (IOException e) { + return true; + } catch (SSLContextException e) { + return true; + } + + if (Time.currentElapsedTime() > start + timeout) { + break; + } + try { + Thread.sleep(250); + } catch (InterruptedException e) { + // ignore + } + } + return false; + } + + public static boolean waitForServerState(QuorumPeer qp, int timeout, + String serverState) { + long start = Time.currentElapsedTime(); + while (true) { + try { + Thread.sleep(250); + } catch (InterruptedException e) { + // ignore + } + if (qp.getServerState().equals(serverState)) + return true; + if (Time.currentElapsedTime() > start + timeout) { + return false; + } + } + } + + static void verifyThreadTerminated(Thread thread, long millis) + throws InterruptedException { + thread.join(millis); + if (thread.isAlive()) { + LOG.error("Thread " + thread.getName() + " : " + + Arrays.toString(thread.getStackTrace())); + Assert.assertFalse("thread " + thread.getName() + + " still alive after join", true); + } + } + + public static File createTmpDir() throws IOException { + return createTmpDir(BASETEST); + } + + static File createTmpDir(File parentDir) throws IOException { + File tmpFile = File.createTempFile("test", ".junit", parentDir); + // don't delete tmpFile - this ensures we don't attempt to create + // a tmpDir with a duplicate name + File tmpDir = new File(tmpFile + ".dir"); + Assert.assertFalse(tmpDir.exists()); // never true if tmpfile does it's job + Assert.assertTrue(tmpDir.mkdirs()); + + return tmpDir; + } + + private static int getPort(String hostPort) { + String[] split = hostPort.split(":"); + String portstr = split[split.length - 1]; + String[] pc = portstr.split("/"); + if (pc.length > 1) { + portstr = pc[0]; + } + return Integer.parseInt(portstr); + } + + /** + * Starting the given server instance + */ + public static void startServerInstance(File dataDir, + ServerCnxnFactory factory, String hostPort) throws IOException, + InterruptedException { + final int port = getPort(hostPort); + LOG.info("STARTING server instance 127.0.0.1:{}", port); + ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000); + factory.startup(zks); + Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp( + "127.0.0.1:" + port, CONNECTION_TIMEOUT, factory.isSecure())); + } + + /** + * This method instantiates a new server. Starting of the server + * instance has been moved to a separate method + * {@link ClientBase#startServerInstance(File, ServerCnxnFactory, String)}. + * Because any exception on starting the server would leave the server + * running and the caller would not be able to shutdown the instance. This + * may affect other test cases. + * + * @return newly created server instance + * + * @see ZOOKEEPER-1852 + * for more information. + */ + public static ServerCnxnFactory createNewServerInstance( + ServerCnxnFactory factory, String hostPort, int maxCnxns) + throws IOException, InterruptedException { + final int port = getPort(hostPort); + LOG.info("CREATING server instance 127.0.0.1:{}", port); + if (factory == null) { + factory = ServerCnxnFactory.createFactory(port, maxCnxns); + } + return factory; + } + + static void shutdownServerInstance(ServerCnxnFactory factory, + String hostPort) { + if (factory != null) { + ZKDatabase zkDb = null; + { + ZooKeeperServer zs = getServer(factory); + if (zs != null) { + zkDb = zs.getZKDatabase(); + } + } + factory.shutdown(); + try { + if (zkDb != null) { + zkDb.close(); + } + } catch (IOException ie) { + LOG.warn("Error closing logs ", ie); + } + final int PORT = getPort(hostPort); + + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown("127.0.0.1:" + PORT, + CONNECTION_TIMEOUT, + factory.isSecure())); + } + } + + /** + * Test specific setup + */ + public static void setupTestEnv() { + // during the tests we run with 100K prealloc in the logs. + // on windows systems prealloc of 64M was seen to take ~15seconds + // resulting in test Assert.failure (client timeout on first session). + // set env and directly in order to handle static init/gc issues + System.setProperty("zookeeper.preAllocSize", "100"); + FileTxnLog.setPreallocSize(100 * 1024); + } + + /** + * Returns a string representation of the given long value session id + * + * @param sessionId + * long value of session id + * @return string representation of session id + */ + protected static String getHexSessionId(long sessionId) { + return "0x" + Long.toHexString(sessionId); + } + + protected static ZooKeeperServer getServer(ServerCnxnFactory fac) { + ZooKeeperServer zs = ServerCnxnFactoryAccessor.getZkServer(fac); + + return zs; + } + + public static MBeanServerConnection jmxConn() throws IOException { + return JMXEnv.conn(); + } + + public static boolean recursiveDelete(File d) { + return TestUtils.deleteFileRecursively(d, true); + } + + public static void logAllStackTraces() { + StringBuilder sb = new StringBuilder(); + sb.append("Starting logAllStackTraces()\n"); + Map threads = Thread.getAllStackTraces(); + for (Entry e : threads.entrySet()) { + sb.append("Thread " + e.getKey().getName() + "\n"); + for (StackTraceElement elem : e.getValue()) { + sb.append("\tat " + elem + "\n"); + } + } + sb.append("Ending logAllStackTraces()\n"); + LOG.error(sb.toString()); + } + + public static String readFile(File file) throws IOException { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); + try { + IOUtils.copyBytes(is, os, 1024, true); + } finally { + is.close(); + } + return os.toString(); + } + + public static String join(String separator, Object[] parts) { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (Object part : parts) { + if (!first) { + sb.append(separator); + first = false; + } + sb.append(part); + } + return sb.toString(); + } + + protected TestableZooKeeper createClient() + throws IOException, InterruptedException { + return createClient(hostPort); + } + + protected TestableZooKeeper createClient(String hp) + throws IOException, InterruptedException { + CountdownWatcher watcher = new CountdownWatcher(); + return createClient(watcher, hp); + } + + protected TestableZooKeeper createClient(CountdownWatcher watcher) + throws IOException, InterruptedException { + return createClient(watcher, hostPort); + } + + protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp) + throws IOException, InterruptedException { + return createClient(watcher, hp, CONNECTION_TIMEOUT); + } + + protected TestableZooKeeper createClient(CountdownWatcher watcher, + String hp, int timeout) + throws IOException, InterruptedException { + watcher.reset(); + TestableZooKeeper zk = new TestableZooKeeper(hp, timeout, watcher); + if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS)) { + Assert.fail("Unable to connect to server"); + } + synchronized (this) { + if (!allClientsSetup) { + LOG.error("allClients never setup"); + Assert.fail("allClients never setup"); + } + if (allClients != null) { + allClients.add(zk); + JMXEnv.ensureAll(getHexSessionId(zk.getSessionId())); + } else { + // test done - close the zk, not needed + zk.close(); + } + } + + return zk; + } + + protected void setUpAll() throws Exception { + allClients = new LinkedList(); + allClientsSetup = true; + } + + @Before + public void setUp() throws Exception { + /* some useful information - log the number of fds used before + * and after a test is run. Helps to verify we are freeing resources + * correctly. Unfortunately this only works on unix systems (the + * only place sun has implemented as part of the mgmt bean api. + */ + OSMXBean osMbean = new OSMXBean(); + if (osMbean.getUnix() == true) { + initialFdCount = osMbean.getOpenFileDescriptorCount(); + LOG.info("Initial fdcount is: " + + initialFdCount); + } + + setupTestEnv(); + + JMXEnv.setUp(); + + setUpAll(); + + tmpDir = createTmpDir(BASETEST); + + startServer(); + + LOG.info("Client test setup finished"); + } + + protected void startServer() throws Exception { + LOG.info("STARTING server"); + serverFactory = createNewServerInstance(serverFactory, hostPort, + maxCnxns); + startServerInstance(tmpDir, serverFactory, hostPort); + // ensure that server and data bean are registered + Set children = JMXEnv.ensureParent("InMemoryDataTree", + "StandaloneServer_port"); + // Remove beans which are related to zk client sessions. Strong + // assertions cannot be done for these client sessions because + // registeration of these beans with server will happen only on their + // respective reconnection interval + verifyUnexpectedBeans(children); + } + + private void verifyUnexpectedBeans(Set children) { + if (allClients != null) { + for (ZooKeeper zkc : allClients) { + Iterator childItr = children.iterator(); + while (childItr.hasNext()) { + ObjectName clientBean = childItr.next(); + if (clientBean.toString().contains( + getHexSessionId(zkc.getSessionId()))) { + LOG.info("found name:" + zkc.getSessionId() + + " client bean:" + clientBean.toString()); + childItr.remove(); + } + } + } + } + for (ObjectName bean : children) { + LOG.info("unexpected:" + bean.toString()); + } + Assert.assertEquals("Unexpected bean exists!", 0, children.size()); + } + + protected void stopServer() throws Exception { + LOG.info("STOPPING server"); + shutdownServerInstance(serverFactory, hostPort); + serverFactory = null; + // ensure no beans are leftover + JMXEnv.ensureOnly(); + } + + protected void tearDownAll() throws Exception { + synchronized (this) { + if (allClients != null) for (ZooKeeper zk : allClients) { + try { + if (zk != null) + zk.close(); + } catch (InterruptedException e) { + LOG.warn("ignoring interrupt", e); + } + } + allClients = null; + } + } + + @After + public void tearDown() throws Exception { + LOG.info("tearDown starting"); + + tearDownAll(); + + stopServer(); + + if (tmpDir != null) { + Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir)); + } + + // This has to be set to null when the same instance of this class is reused between test cases + serverFactory = null; + + JMXEnv.tearDown(); + + /* some useful information - log the number of fds used before + * and after a test is run. Helps to verify we are freeing resources + * correctly. Unfortunately this only works on unix systems (the + * only place sun has implemented as part of the mgmt bean api. + */ + OSMXBean osMbean = new OSMXBean(); + if (osMbean.getUnix() == true) { + long fdCount = osMbean.getOpenFileDescriptorCount(); + String message = "fdcount after test is: " + + fdCount + " at start it was " + initialFdCount; + LOG.info(message); + if (fdCount > initialFdCount) { + LOG.info("sleeping for 20 secs"); + //Thread.sleep(60000); + //assertTrue(message, fdCount <= initialFdCount); + } + } + } + + /* + * Verify that all of the servers see the same number of nodes + * at the root + */ + void verifyRootOfAllServersMatch(String hostPort) + throws InterruptedException, KeeperException, IOException { + String parts[] = hostPort.split(","); + + // run through till the counts no longer change on each server + // max 15 tries, with 2 second sleeps, so approx 30 seconds + int[] counts = new int[parts.length]; + int failed = 0; + for (int j = 0; j < 100; j++) { + int newcounts[] = new int[parts.length]; + int i = 0; + for (String hp : parts) { + try { + ZooKeeper zk = createClient(hp); + + try { + newcounts[i++] = zk.getChildren("/", false).size(); + } finally { + zk.close(); + } + } catch (Throwable t) { + failed++; + // if session creation Assert.fails dump the thread stack + // and try the next server + logAllStackTraces(); + } + } + + if (Arrays.equals(newcounts, counts)) { + LOG.info("Found match with array:" + + Arrays.toString(newcounts)); + counts = newcounts; + break; + } else { + counts = newcounts; + Thread.sleep(10000); + } + + // don't keep this up too long, will Assert.assert false below + if (failed > 10) { + break; + } + } + + // verify all the servers reporting same number of nodes + String logmsg = "node count not consistent{} {}"; + for (int i = 1; i < parts.length; i++) { + if (counts[i - 1] != counts[i]) { + LOG.error(logmsg, Integer.valueOf(counts[i - 1]), Integer.valueOf(counts[i])); + } else { + LOG.info(logmsg, Integer.valueOf(counts[i - 1]), Integer.valueOf(counts[i])); + } + } + } + + /** + * In general don't use this. Only use in the special case that you + * want to ignore results (for whatever reason) in your test. Don't + * use empty watchers in real code! + * + */ + protected static class NullWatcher implements Watcher { + public void process(WatchedEvent event) { /* nada */ } + } + + public static class CountdownWatcher implements Watcher { + // XXX this doesn't need to be volatile! (Should probably be final) + volatile CountDownLatch clientConnected; + volatile boolean connected; + + public CountdownWatcher() { + reset(); + } + + synchronized public void reset() { + clientConnected = new CountDownLatch(1); + connected = false; + } + + synchronized public void process(WatchedEvent event) { + if (event.getState() == KeeperState.SyncConnected || + event.getState() == KeeperState.ConnectedReadOnly) { + connected = true; + notifyAll(); + clientConnected.countDown(); + } else { + connected = false; + notifyAll(); + } + } + + synchronized public boolean isConnected() { + return connected; + } + + synchronized public void waitForConnected(long timeout) + throws InterruptedException, TimeoutException { + long expire = Time.currentElapsedTime() + timeout; + long left = timeout; + while (!connected && left > 0) { + wait(left); + left = expire - Time.currentElapsedTime(); + } + if (!connected) { + throw new TimeoutException("Did not connect"); + + } + } + + synchronized public void waitForDisconnected(long timeout) + throws InterruptedException, TimeoutException { + long expire = Time.currentElapsedTime() + timeout; + long left = timeout; + while (connected && left > 0) { + wait(left); + left = expire - Time.currentElapsedTime(); + } + if (connected) { + throw new TimeoutException("Did not disconnect"); + + } + } + } + + public static class HostPort { + String host; + int port; + + public HostPort(String host, int port) { + this.host = host; + this.port = port; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java b/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java new file mode 100644 index 00000000000..dd530f28e2f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java @@ -0,0 +1,236 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.Time; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Date; +import java.util.List; + +public class ClientHammerTest extends ClientBase { + protected static final Logger LOG = LoggerFactory.getLogger(ClientHammerTest.class); + + private static final long HAMMERTHREAD_LATENCY = 5; + + /** + * Separate threads each creating a number of nodes. Each thread + * is using a non-shared (owned by thread) client for all node creations. + * @throws Throwable + */ + @Test + public void testHammerBasic() throws Throwable { + runHammer(10, 1000); + } + + public void runHammer(final int threadCount, final int childCount) + throws Throwable { + try { + HammerThread[] threads = new HammerThread[threadCount]; + long start = Time.currentElapsedTime(); + for (int i = 0; i < threads.length; i++) { + ZooKeeper zk = createClient(); + String prefix = "/test-" + i; + zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + prefix += "/"; + HammerThread thread = + new BasicHammerThread("BasicHammerThread-" + i, zk, prefix, + childCount); + thread.start(); + + threads[i] = thread; + } + + verifyHammer(start, threads, childCount); + } catch (Throwable t) { + LOG.error("test Assert.failed", t); + throw t; + } + } + + /** + * Separate threads each creating a number of nodes. Each thread + * is creating a new client for each node creation. + * @throws Throwable + */ + @Test + public void testHammerSuper() throws Throwable { + try { + final int threadCount = 5; + final int childCount = 10; + + HammerThread[] threads = new HammerThread[threadCount]; + long start = Time.currentElapsedTime(); + for (int i = 0; i < threads.length; i++) { + String prefix = "/test-" + i; + { + ZooKeeper zk = createClient(); + try { + zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } finally { + zk.close(); + } + } + prefix += "/"; + HammerThread thread = + new SuperHammerThread("SuperHammerThread-" + i, this, + prefix, childCount); + thread.start(); + + threads[i] = thread; + } + + verifyHammer(start, threads, childCount); + } catch (Throwable t) { + LOG.error("test Assert.failed", t); + throw t; + } + } + + public void verifyHammer(long start, HammerThread[] threads, int childCount) + throws IOException, InterruptedException, KeeperException { + // look for the clients to finish their create operations + LOG.info("Starting check for completed hammers"); + int workingCount = threads.length; + for (int i = 0; i < 120; i++) { + Thread.sleep(10000); + for (HammerThread h : threads) { + if (!h.isAlive() || h.current == h.count) { + workingCount--; + } + } + if (workingCount == 0) { + break; + } + workingCount = threads.length; + } + if (workingCount > 0) { + for (HammerThread h : threads) { + LOG.warn(h.getName() + " never finished creation, current:" + + h.current); + } + } else { + LOG.info("Hammer threads completed creation operations"); + } + + for (HammerThread h : threads) { + final int safetyFactor = 3; + verifyThreadTerminated(h, + (long) threads.length * (long) childCount + * HAMMERTHREAD_LATENCY * (long) safetyFactor); + } + LOG.info(new Date() + " Total time " + + (Time.currentElapsedTime() - start)); + + ZooKeeper zk = createClient(); + try { + LOG.info("******************* Connected to ZooKeeper" + new Date()); + for (int i = 0; i < threads.length; i++) { + LOG.info("Doing thread: " + i + " " + new Date()); + List children = + zk.getChildren("/test-" + i, false); + Assert.assertEquals(childCount, children.size()); + children = zk.getChildren("/test-" + i, false, null); + Assert.assertEquals(childCount, children.size()); + } + for (int i = 0; i < threads.length; i++) { + List children = + zk.getChildren("/test-" + i, false); + Assert.assertEquals(childCount, children.size()); + children = zk.getChildren("/test-" + i, false, null); + Assert.assertEquals(childCount, children.size()); + } + } finally { + zk.close(); + } + } + + private static abstract class HammerThread extends Thread { + protected final int count; + protected volatile int current = 0; + + HammerThread(String name, int count) { + super(name); + this.count = count; + } + } + + private static class BasicHammerThread extends HammerThread { + private final ZooKeeper zk; + private final String prefix; + + BasicHammerThread(String name, ZooKeeper zk, String prefix, int count) { + super(name, count); + this.zk = zk; + this.prefix = prefix; + } + + public void run() { + byte b[] = new byte[256]; + try { + for (; current < count; current++) { + // Simulate a bit of network latency... + Thread.sleep(HAMMERTHREAD_LATENCY); + zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + } catch (Throwable t) { + LOG.error("Client create operation Assert.failed", t); + } finally { + try { + zk.close(); + } catch (InterruptedException e) { + LOG.warn("Unexpected", e); + } + } + } + } + + private static class SuperHammerThread extends HammerThread { + private final ClientHammerTest parent; + private final String prefix; + + SuperHammerThread(String name, ClientHammerTest parent, String prefix, + int count) { + super(name, count); + this.parent = parent; + this.prefix = prefix; + } + + public void run() { + byte b[] = new byte[256]; + try { + for (; current < count; current++) { + ZooKeeper zk = parent.createClient(); + try { + zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } finally { + try { + zk.close(); + } catch (InterruptedException e) { + LOG.warn("Unexpected", e); + } + } + } + } catch (Throwable t) { + LOG.error("Client create operation Assert.failed", t); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java b/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java new file mode 100644 index 00000000000..b752ef20259 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ClientPortBindTest.java @@ -0,0 +1,110 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class ClientPortBindTest extends ZKTestCase implements Watcher { + protected static final Logger LOG = + LoggerFactory.getLogger(ClientPortBindTest.class); + + private volatile CountDownLatch startSignal; + + /** + * Verify that the server binds to the specified address + */ + @Test + public void testBindByAddress() throws Exception { + String bindAddress = null; + Enumeration intfs = + NetworkInterface.getNetworkInterfaces(); + // if we have a loopback and it has an address use it + while (intfs.hasMoreElements()) { + NetworkInterface i = intfs.nextElement(); + if (i.isLoopback()) { + Enumeration addrs = i.getInetAddresses(); + if (addrs.hasMoreElements()) { + bindAddress = addrs.nextElement().getHostAddress(); + } + } + } + if (bindAddress == null) { + LOG.warn("Unable to determine loop back address, skipping test"); + return; + } + final int PORT = PortAssignment.unique(); + + LOG.info("Using " + bindAddress + " as the bind address"); + final String HOSTPORT = bindAddress + ":" + PORT; + LOG.info("Using " + HOSTPORT + " as the host/port"); + + + File tmpDir = ClientBase.createTmpDir(); + + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + + ServerCnxnFactory f = ServerCnxnFactory.createFactory( + new InetSocketAddress(bindAddress, PORT), -1); + f.startup(zks); + LOG.info("starting up the the server, waiting"); + + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(HOSTPORT, + CONNECTION_TIMEOUT)); + + startSignal = new CountDownLatch(1); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + try { + startSignal.await(CONNECTION_TIMEOUT, + TimeUnit.MILLISECONDS); + Assert.assertTrue("count == 0", startSignal.getCount() == 0); + zk.close(); + } finally { + f.shutdown(); + zks.shutdown(); + + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + CONNECTION_TIMEOUT)); + } + } + + public void process(WatchedEvent event) { + LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath()); + if (event.getState() == KeeperState.SyncConnected + && startSignal != null && startSignal.getCount() > 0) { + startSignal.countDown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ClientRetryTest.java b/src/java/test/org/apache/zookeeper/test/ClientRetryTest.java new file mode 100644 index 00000000000..d89c69bb7f0 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ClientRetryTest.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeper.States; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.TimeoutException; + +public class ClientRetryTest extends ClientBase { + + @Override + public void setUp() throws Exception { + maxCnxns = 1; + super.setUp(); + } + + /* + * This is a simple test - try to connect two clients to a server + * accepting a maximum of one connection from each address. Check that + * only one is accepted. Close that connection, and check that the other + * eventually connects. + * + * There is a possibility of a false positive here, as when zk2 is tested + * for having connected it might not have been given enough time, and finish + * connecting after the test is done. Since the + * server doesn't tell the client why it hasn't connected, there's no + * obvious way to detect the difference. + */ + @Test + public void testClientRetry() throws IOException, InterruptedException, TimeoutException { + CountdownWatcher cdw1 = new CountdownWatcher(); + CountdownWatcher cdw2 = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper(hostPort, 10000, cdw1); + try { + cdw1.waitForConnected(CONNECTION_TIMEOUT); + ZooKeeper zk2 = new ZooKeeper(hostPort, 10000, cdw2); + try { + States s1 = zk.getState(); + States s2 = zk2.getState(); + Assert.assertSame(s1, States.CONNECTED); + Assert.assertSame(s2, States.CONNECTING); + cdw1.reset(); + zk.close(); + cdw1.waitForDisconnected(CONNECTION_TIMEOUT); + cdw2.waitForConnected(CONNECTION_TIMEOUT); + Assert.assertSame(zk2.getState(), States.CONNECTED); + } finally { + zk2.close(); + } + } finally { + zk.close(); + } + } +} + diff --git a/src/java/test/org/apache/zookeeper/test/ClientSkipACLTest.java b/src/java/test/org/apache/zookeeper/test/ClientSkipACLTest.java new file mode 100644 index 00000000000..489a62e2885 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ClientSkipACLTest.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class ClientSkipACLTest extends ClientTest { + @BeforeClass + static public void setup() { + System.setProperty("zookeeper.skipACL", "yes"); + } + + @AfterClass + static public void teardown() { + System.clearProperty("zookeeper.skipACL"); + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/test/ClientTest.java b/src/java/test/org/apache/zookeeper/test/ClientTest.java new file mode 100644 index 00000000000..451fc2a71b5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ClientTest.java @@ -0,0 +1,833 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.KeeperException.InvalidACLException; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.Perms; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.proto.ExistsRequest; +import org.apache.zookeeper.proto.ExistsResponse; +import org.apache.zookeeper.proto.ReplyHeader; +import org.apache.zookeeper.proto.RequestHeader; +import org.apache.zookeeper.server.PrepRequestProcessor; +import org.apache.zookeeper.server.util.OSMXBean; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.fail; + +public class ClientTest extends ClientBase { + protected static final Logger LOG = LoggerFactory.getLogger(ClientTest.class); + private boolean skipACL = System.getProperty("zookeeper.skipACL", "no").equals("yes"); + + /** Verify that pings are sent, keeping the "idle" client alive */ + @Test + public void testPing() throws Exception { + ZooKeeper zkIdle = null; + ZooKeeper zkWatchCreator = null; + try { + CountdownWatcher watcher = new CountdownWatcher(); + zkIdle = createClient(watcher, hostPort, 10000); + + zkWatchCreator = createClient(); + + for (int i = 0; i < 10; i++) { + zkWatchCreator.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + for (int i = 0; i < 10; i++) { + zkIdle.exists("/" + i, true); + } + for (int i = 0; i < 10; i++) { + Thread.sleep(1000); + zkWatchCreator.delete("/" + i, -1); + } + // The bug will manifest itself here because zkIdle will expire + zkIdle.exists("/0", false); + } finally { + if (zkIdle != null) { + zkIdle.close(); + } + if (zkWatchCreator != null) { + zkWatchCreator.close(); + } + } + } + + @Test + public void testClientwithoutWatcherObj() throws IOException, + InterruptedException, KeeperException { + performClientTest(false); + } + + @Test + public void testClientWithWatcherObj() throws IOException, + InterruptedException, KeeperException { + performClientTest(true); + } + + /** Exercise the testable functions, verify tostring, etc... */ + @Test + public void testTestability() throws Exception { + TestableZooKeeper zk = createClient(); + try { + LOG.info("{}", zk.testableLocalSocketAddress()); + LOG.info("{}", zk.testableRemoteSocketAddress()); + LOG.info("{}", zk.toString()); + } finally { + zk.close(); + zk.testableWaitForShutdown(CONNECTION_TIMEOUT); + LOG.info("{}", zk.testableLocalSocketAddress()); + LOG.info("{}", zk.testableRemoteSocketAddress()); + LOG.info("{}", zk.toString()); + } + } + + @Test + public void testACLs() throws Exception { + ZooKeeper zk = null; + try { + zk = createClient(); + try { + zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + Assert.fail("Should have received an invalid acl error"); + } catch (InvalidACLException e) { + LOG.info("Test successful, invalid acl received : " + + e.getMessage()); + } + try { + ArrayList testACL = new ArrayList(); + testACL.add(new ACL(Perms.ALL | Perms.ADMIN, Ids.AUTH_IDS)); + testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id("ip", "127.0.0.1/8"))); + zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT); + Assert.fail("Should have received an invalid acl error"); + } catch (InvalidACLException e) { + LOG.info("Test successful, invalid acl received : " + + e.getMessage()); + } + try { + ArrayList testACL = new ArrayList(); + testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id())); + zk.create("/nullidtest", new byte[0], testACL, CreateMode.PERSISTENT); + Assert.fail("Should have received an invalid acl error"); + } catch (InvalidACLException e) { + LOG.info("Test successful, invalid acl received : " + + e.getMessage()); + } + zk.addAuthInfo("digest", "ben:passwd".getBytes()); + ArrayList testACL = new ArrayList(); + testACL.add(new ACL(Perms.ALL, new Id("auth", ""))); + testACL.add(new ACL(Perms.WRITE, new Id("ip", "127.0.0.1"))); + zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT); + zk.close(); + zk = createClient(); + zk.addAuthInfo("digest", "ben:passwd2".getBytes()); + if (skipACL) { + try { + zk.getData("/acltest", false, null); + } catch (KeeperException e) { + Assert.fail("Badauth reads should succeed with skipACL."); + } + } else { + try { + zk.getData("/acltest", false, null); + Assert.fail("Should have received a permission error"); + } catch (KeeperException e) { + Assert.assertEquals(Code.NOAUTH, e.code()); + } + } + zk.addAuthInfo("digest", "ben:passwd".getBytes()); + zk.getData("/acltest", false, null); + zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1); + zk.close(); + zk = createClient(); + zk.getData("/acltest", false, null); + List acls = zk.getACL("/acltest", new Stat()); + Assert.assertEquals(1, acls.size()); + Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, acls); + + // The stat parameter should be optional. + acls = zk.getACL("/acltest", null); + Assert.assertEquals(1, acls.size()); + Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, acls); + + zk.close(); + } finally { + if (zk != null) { + zk.close(); + } + } + } + + @Test + public void testNullAuthId() throws Exception { + ZooKeeper zk = null; + try { + zk = createClient(); + zk.addAuthInfo("digest", "ben:passwd".getBytes()); + ArrayList testACL = new ArrayList(); + testACL.add(new ACL(Perms.ALL, new Id("auth", null))); + zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT); + zk.close(); + zk = createClient(); + zk.addAuthInfo("digest", "ben:passwd2".getBytes()); + if (skipACL) { + try { + zk.getData("/acltest", false, null); + } catch (KeeperException e) { + Assert.fail("Badauth reads should succeed with skipACL."); + } + } else { + try { + zk.getData("/acltest", false, null); + Assert.fail("Should have received a permission error"); + } catch (KeeperException e) { + Assert.assertEquals(Code.NOAUTH, e.code()); + } + } + zk.addAuthInfo("digest", "ben:passwd".getBytes()); + zk.getData("/acltest", false, null); + zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1); + zk.close(); + zk = createClient(); + zk.getData("/acltest", false, null); + List acls = zk.getACL("/acltest", new Stat()); + Assert.assertEquals(1, acls.size()); + Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, acls); + } finally { + if (zk != null) { + zk.close(); + } + } + } + + /** + * Register multiple watchers and verify that they all get notified and + * in the right order. + */ + @Test + public void testMutipleWatcherObjs() + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = createClient(new CountdownWatcher(), hostPort); + try { + MyWatcher watchers[] = new MyWatcher[100]; + MyWatcher watchers2[] = new MyWatcher[watchers.length]; + for (int i = 0; i < watchers.length; i++) { + watchers[i] = new MyWatcher(); + watchers2[i] = new MyWatcher(); + zk.create("/foo-" + i, ("foodata" + i).getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + Stat stat = new Stat(); + + // + // test get/exists with single set of watchers + // get all, then exists all + // + for (int i = 0; i < watchers.length; i++) { + Assert.assertNotNull(zk.getData("/foo-" + i, watchers[i], stat)); + } + for (int i = 0; i < watchers.length; i++) { + Assert.assertNotNull(zk.exists("/foo-" + i, watchers[i])); + } + // trigger the watches + for (int i = 0; i < watchers.length; i++) { + zk.setData("/foo-" + i, ("foodata2-" + i).getBytes(), -1); + zk.setData("/foo-" + i, ("foodata3-" + i).getBytes(), -1); + } + for (int i = 0; i < watchers.length; i++) { + WatchedEvent event = + watchers[i].events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals("/foo-" + i, event.getPath()); + Assert.assertEquals(EventType.NodeDataChanged, event.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event.getState()); + + // small chance that an unexpected message was delivered + // after this check, but we would catch that next time + // we check events + Assert.assertEquals(0, watchers[i].events.size()); + } + + // + // test get/exists with single set of watchers + // get/exists together + // + for (int i = 0; i < watchers.length; i++) { + Assert.assertNotNull(zk.getData("/foo-" + i, watchers[i], stat)); + Assert.assertNotNull(zk.exists("/foo-" + i, watchers[i])); + } + // trigger the watches + for (int i = 0; i < watchers.length; i++) { + zk.setData("/foo-" + i, ("foodata4-" + i).getBytes(), -1); + zk.setData("/foo-" + i, ("foodata5-" + i).getBytes(), -1); + } + for (int i = 0; i < watchers.length; i++) { + WatchedEvent event = + watchers[i].events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals("/foo-" + i, event.getPath()); + Assert.assertEquals(EventType.NodeDataChanged, event.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event.getState()); + + // small chance that an unexpected message was delivered + // after this check, but we would catch that next time + // we check events + Assert.assertEquals(0, watchers[i].events.size()); + } + + // + // test get/exists with two sets of watchers + // + for (int i = 0; i < watchers.length; i++) { + Assert.assertNotNull(zk.getData("/foo-" + i, watchers[i], stat)); + Assert.assertNotNull(zk.exists("/foo-" + i, watchers2[i])); + } + // trigger the watches + for (int i = 0; i < watchers.length; i++) { + zk.setData("/foo-" + i, ("foodata6-" + i).getBytes(), -1); + zk.setData("/foo-" + i, ("foodata7-" + i).getBytes(), -1); + } + for (int i = 0; i < watchers.length; i++) { + WatchedEvent event = + watchers[i].events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals("/foo-" + i, event.getPath()); + Assert.assertEquals(EventType.NodeDataChanged, event.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event.getState()); + + // small chance that an unexpected message was delivered + // after this check, but we would catch that next time + // we check events + Assert.assertEquals(0, watchers[i].events.size()); + + // watchers2 + WatchedEvent event2 = + watchers2[i].events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals("/foo-" + i, event2.getPath()); + Assert.assertEquals(EventType.NodeDataChanged, event2.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event2.getState()); + + // small chance that an unexpected message was delivered + // after this check, but we would catch that next time + // we check events + Assert.assertEquals(0, watchers2[i].events.size()); + } + + } finally { + if (zk != null) { + zk.close(); + } + } + } + + private void performClientTest(boolean withWatcherObj) + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = null; + try { + MyWatcher watcher = new MyWatcher(); + zk = createClient(watcher, hostPort); + LOG.info("Before create /benwashere"); + zk.create("/benwashere", "".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + LOG.info("After create /benwashere"); + try { + zk.setData("/benwashere", "hi".getBytes(), 57); + Assert.fail("Should have gotten BadVersion exception"); + } catch (KeeperException.BadVersionException e) { + // expected that + } catch (KeeperException e) { + Assert.fail("Should have gotten BadVersion exception"); + } + LOG.info("Before delete /benwashere"); + zk.delete("/benwashere", 0); + LOG.info("After delete /benwashere"); + zk.close(); + //LOG.info("Closed client: " + zk.describeCNXN()); + Thread.sleep(2000); + + zk = createClient(watcher, hostPort); + //LOG.info("Created a new client: " + zk.describeCNXN()); + LOG.info("Before delete /"); + + try { + zk.delete("/", -1); + Assert.fail("deleted root!"); + } catch (KeeperException.BadArgumentsException e) { + // good, expected that + } + Stat stat = new Stat(); + // Test basic create, ls, and getData + zk.create("/pat", "Pat was here".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + LOG.info("Before create /ben"); + zk.create("/pat/ben", "Ben was here".getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + LOG.info("Before getChildren /pat"); + List children = zk.getChildren("/pat", false); + Assert.assertEquals(1, children.size()); + Assert.assertEquals("ben", children.get(0)); + List children2 = zk.getChildren("/pat", false, null); + Assert.assertEquals(children, children2); + String value = new String(zk.getData("/pat/ben", false, stat)); + Assert.assertEquals("Ben was here", value); + // Test stat and watch of non existent node + + try { + if (withWatcherObj) { + Assert.assertEquals(null, zk.exists("/frog", watcher)); + } else { + Assert.assertEquals(null, zk.exists("/frog", true)); + } + LOG.info("Comment: asseting passed for frog setting /"); + } catch (KeeperException.NoNodeException e) { + // OK, expected that + } + zk.create("/frog", "hi".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + // the first poll is just a session delivery + LOG.info("Comment: checking for events length " + + watcher.events.size()); + WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals("/frog", event.getPath()); + Assert.assertEquals(EventType.NodeCreated, event.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event.getState()); + // Test child watch and create with sequence + zk.getChildren("/pat/ben", true); + for (int i = 0; i < 10; i++) { + zk.create("/pat/ben/" + i + "-", Integer.toString(i).getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + } + children = zk.getChildren("/pat/ben", false); + Collections.sort(children); + Assert.assertEquals(10, children.size()); + for (int i = 0; i < 10; i++) { + final String name = children.get(i); + Assert.assertTrue("starts with -", name.startsWith(i + "-")); + byte b[]; + if (withWatcherObj) { + b = zk.getData("/pat/ben/" + name, watcher, stat); + } else { + b = zk.getData("/pat/ben/" + name, true, stat); + } + Assert.assertEquals(Integer.toString(i), new String(b)); + zk.setData("/pat/ben/" + name, "new".getBytes(), + stat.getVersion()); + if (withWatcherObj) { + stat = zk.exists("/pat/ben/" + name, watcher); + } else { + stat = zk.exists("/pat/ben/" + name, true); + } + zk.delete("/pat/ben/" + name, stat.getVersion()); + } + event = watcher.events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals("/pat/ben", event.getPath()); + Assert.assertEquals(EventType.NodeChildrenChanged, event.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event.getState()); + for (int i = 0; i < 10; i++) { + event = watcher.events.poll(10, TimeUnit.SECONDS); + final String name = children.get(i); + Assert.assertEquals("/pat/ben/" + name, event.getPath()); + Assert.assertEquals(EventType.NodeDataChanged, event.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event.getState()); + event = watcher.events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals("/pat/ben/" + name, event.getPath()); + Assert.assertEquals(EventType.NodeDeleted, event.getType()); + Assert.assertEquals(KeeperState.SyncConnected, event.getState()); + } + zk.create("/good\u0040path", "".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + try { + zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.fail("duplicate create allowed"); + } catch (KeeperException.NodeExistsException e) { + // OK, expected that + } + } finally { + if (zk != null) { + zk.close(); + } + } + } + + // Test that sequential filenames are being created correctly, + // with 0-padding in the filename + @Test + public void testSequentialNodeNames() + throws IOException, InterruptedException, KeeperException { + String path = "/SEQUENCE"; + String file = "TEST"; + String filepath = path + "/" + file; + + ZooKeeper zk = null; + try { + zk = createClient(); + zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + List children = zk.getChildren(path, false); + Assert.assertEquals(1, children.size()); + Assert.assertEquals(file + "0000000000", children.get(0)); + + zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + children = zk.getChildren(path, false); + Assert.assertEquals(2, children.size()); + Assert.assertTrue("contains child 1", children.contains(file + "0000000001")); + + zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + children = zk.getChildren(path, false); + Assert.assertEquals(3, children.size()); + Assert.assertTrue("contains child 2", + children.contains(file + "0000000002")); + + // The pattern is holding so far. Let's run the counter a bit + // to be sure it continues to spit out the correct answer + for (int i = children.size(); i < 105; i++) + zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + + children = zk.getChildren(path, false); + Assert.assertTrue("contains child 104", + children.contains(file + "0000000104")); + + } finally { + if (zk != null) + zk.close(); + } + } + + // Test that data provided when + // creating sequential nodes is stored properly + @Test + public void testSequentialNodeData() throws Exception { + ZooKeeper zk = null; + String queue_handle = "/queue"; + try { + zk = createClient(); + + zk.create(queue_handle, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.create(queue_handle + "/element", "0".getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + zk.create(queue_handle + "/element", "1".getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + List children = zk.getChildren(queue_handle, true); + Assert.assertEquals(children.size(), 2); + String child1 = children.get(0); + String child2 = children.get(1); + int compareResult = child1.compareTo(child2); + Assert.assertNotSame(compareResult, 0); + if (compareResult < 0) { + } else { + String temp = child1; + child1 = child2; + child2 = temp; + } + String child1data = new String(zk.getData(queue_handle + + "/" + child1, false, null)); + String child2data = new String(zk.getData(queue_handle + + "/" + child2, false, null)); + Assert.assertEquals(child1data, "0"); + Assert.assertEquals(child2data, "1"); + } finally { + if (zk != null) { + zk.close(); + } + } + + } + + @Test + public void testLargeNodeData() throws Exception { + ZooKeeper zk = null; + String queue_handle = "/large"; + try { + zk = createClient(); + + zk.create(queue_handle, new byte[500000], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } finally { + if (zk != null) { + zk.close(); + } + } + + } + + private void verifyCreateFails(String path, ZooKeeper zk) throws Exception { + try { + zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (IllegalArgumentException e) { + // this is good + return; + } + Assert.fail("bad path \"" + path + "\" not caught"); + } + + // Test that the path string is validated + @Test + public void testPathValidation() throws Exception { + ZooKeeper zk = createClient(); + + verifyCreateFails(null, zk); + verifyCreateFails("", zk); + verifyCreateFails("//", zk); + verifyCreateFails("///", zk); + verifyCreateFails("////", zk); + verifyCreateFails("/.", zk); + verifyCreateFails("/..", zk); + verifyCreateFails("/./", zk); + verifyCreateFails("/../", zk); + verifyCreateFails("/foo/./", zk); + verifyCreateFails("/foo/../", zk); + verifyCreateFails("/foo/.", zk); + verifyCreateFails("/foo/..", zk); + verifyCreateFails("/./.", zk); + verifyCreateFails("/../..", zk); + verifyCreateFails("/\u0001foo", zk); + verifyCreateFails("/foo/bar/", zk); + verifyCreateFails("/foo//bar", zk); + verifyCreateFails("/foo/bar//", zk); + + verifyCreateFails("foo", zk); + verifyCreateFails("a", zk); + + zk.create("/createseqpar", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + // next two steps - related to sequential processing + // 1) verify that empty child name Assert.fails if not sequential + try { + zk.create("/createseqpar/", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertTrue(false); + } catch (IllegalArgumentException be) { + // catch this. + } + + // 2) verify that empty child name success if sequential + zk.create("/createseqpar/", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + zk.create("/createseqpar/.", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + zk.create("/createseqpar/..", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + try { + zk.create("/createseqpar//", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + Assert.assertTrue(false); + } catch (IllegalArgumentException be) { + // catch this. + } + try { + zk.create("/createseqpar/./", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + Assert.assertTrue(false); + } catch (IllegalArgumentException be) { + // catch this. + } + try { + zk.create("/createseqpar/../", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + Assert.assertTrue(false); + } catch (IllegalArgumentException be) { + // catch this. + } + + + //check for the code path that throws at server + PrepRequestProcessor.setFailCreate(true); + try { + zk.create("/m", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertTrue(false); + } catch (KeeperException.BadArgumentsException be) { + // catch this. + } + PrepRequestProcessor.setFailCreate(false); + zk.create("/.foo", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/.f.", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/..f", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/..f..", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f.c", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f\u0040f", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f/.f", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f/f.", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f/..f", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f/f..", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f/.f/f", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/f/f./f", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + + @Test + public void testDeleteWithChildren() throws Exception { + ZooKeeper zk = createClient(); + zk.create("/parent", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/parent/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + try { + zk.delete("/parent", -1); + Assert.fail("Should have received a not equals message"); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NOTEMPTY, e.code()); + } + zk.delete("/parent/child", -1); + zk.delete("/parent", -1); + zk.close(); + } + +// private void notestConnections() +// throws IOException, InterruptedException, KeeperException +// { +// ZooKeeper zk; +// for(int i = 0; i < 2000; i++) { +// if (i % 100 == 0) { +// LOG.info("Testing " + i + " connections"); +// } +// // We want to make sure socket descriptors are going away +// zk = new ZooKeeper(hostPort, 30000, this); +// zk.getData("/", false, new Stat()); +// zk.close(); +// } +// } + + /** + * Verify that the client is cleaning up properly. Open/close a large + * number of sessions. Essentially looking to see if sockets/selectors + * are being cleaned up properly during close. + * + * @throws Throwable + */ + @Test + public void testClientCleanup() throws Throwable { + OSMXBean osMbean = new OSMXBean(); + if (osMbean.getUnix() == false) { + LOG.warn("skipping testClientCleanup, only available on Unix"); + return; + } + + final int threadCount = 3; + final int clientCount = 10; + + /* Log the number of fds used before and after a test is run. Verifies + * we are freeing resources correctly. Unfortunately this only works + * on unix systems (the only place sun has implemented as part of the + * mgmt bean api). + */ + long initialFdCount = osMbean.getOpenFileDescriptorCount(); + + VerifyClientCleanup threads[] = new VerifyClientCleanup[threadCount]; + + for (int i = 0; i < threads.length; i++) { + threads[i] = new VerifyClientCleanup("VCC" + i, clientCount); + threads[i].start(); + } + + for (int i = 0; i < threads.length; i++) { + threads[i].join(CONNECTION_TIMEOUT); + Assert.assertTrue(threads[i].current == threads[i].count); + } + + // if this Assert.fails it means we are not cleaning up after the closed + // sessions. + long currentCount = osMbean.getOpenFileDescriptorCount(); + final String logmsg = "open fds after test ({}) are not significantly higher than before ({})"; + + if (currentCount > initialFdCount + 10) { + // consider as error + LOG.error(logmsg, Long.valueOf(currentCount), Long.valueOf(initialFdCount)); + } else { + LOG.info(logmsg, Long.valueOf(currentCount), Long.valueOf(initialFdCount)); + } + } + + /** + * We create a perfectly valid 'exists' request, except that the opcode is wrong. + * @return + * @throws Exception + */ + @Test + public void testNonExistingOpCode() throws Exception { + TestableZooKeeper zk = createClient(); + + final String path = "/m1"; + + RequestHeader h = new RequestHeader(); + h.setType(888); // This code does not exists + ExistsRequest request = new ExistsRequest(); + request.setPath(path); + request.setWatch(false); + ExistsResponse response = new ExistsResponse(); + ReplyHeader r = zk.submitRequest(h, request, response, null); + + Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue()); + zk.testableWaitForShutdown(CONNECTION_TIMEOUT); + } + + private class MyWatcher extends CountdownWatcher { + LinkedBlockingQueue events = + new LinkedBlockingQueue(); + + public void process(WatchedEvent event) { + super.process(event); + if (event.getType() != EventType.None) { + try { + events.put(event); + } catch (InterruptedException e) { + LOG.warn("ignoring interrupt during event.put"); + } + } + } + } + + private class VerifyClientCleanup extends Thread { + int count; + int current = 0; + + VerifyClientCleanup(String name, int count) { + super(name); + this.count = count; + } + + public void run() { + try { + for (; current < count; current++) { + TestableZooKeeper zk = createClient(); + zk.close(); + // we've asked to close, wait for it to finish closing + // all the sub-threads otw the selector may not be + // closed when we check (false positive on test Assert.failure + zk.testableWaitForShutdown(CONNECTION_TIMEOUT); + } + } catch (Throwable t) { + LOG.error("test Assert.failed", t); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java b/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java new file mode 100644 index 00000000000..b79f8803d47 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java @@ -0,0 +1,521 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.server.quorum.QuorumCnxManager; +import org.apache.zookeeper.server.quorum.QuorumCnxManager.InitialMessage; +import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +public class CnxManagerTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLENewEpochTest.class); + protected static final int THRESHOLD = 4; + + int count; + HashMap peers; + File peerTmpdir[]; + int peerQuorumPort[]; + int peerClientPort[]; + + @Before + public void setUp() throws Exception { + + this.count = 3; + this.peers = new HashMap(count); + peerTmpdir = new File[count]; + peerQuorumPort = new int[count]; + peerClientPort = new int[count]; + + for (int i = 0; i < count; i++) { + peerQuorumPort[i] = PortAssignment.unique(); + peerClientPort[i] = PortAssignment.unique(); + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress( + "127.0.0.1", peerQuorumPort[i]), + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", peerClientPort[i]))); + peerTmpdir[i] = ClientBase.createTmpDir(); + } + } + + ByteBuffer createMsg(int state, long leader, long zxid, long epoch) { + byte requestBytes[] = new byte[28]; + ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); + + /* + * Building notification packet to send + */ + + requestBuffer.clear(); + requestBuffer.putInt(state); + requestBuffer.putLong(leader); + requestBuffer.putLong(zxid); + requestBuffer.putLong(epoch); + + return requestBuffer; + } + + @Test + public void testCnxManager() throws Exception { + CnxManagerThread thread = new CnxManagerThread(); + + thread.start(); + + QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2); + QuorumCnxManager cnxManager = new QuorumCnxManager(peer); + QuorumCnxManager.Listener listener = cnxManager.listener; + if (listener != null) { + listener.start(); + } else { + LOG.error("Null listener when initializing cnx manager"); + } + + cnxManager.toSend(0L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1)); + + Message m = null; + int numRetries = 1; + while ((m == null) && (numRetries++ <= THRESHOLD)) { + m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS); + if (m == null) cnxManager.connectAll(); + } + + Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD); + + thread.join(5000); + if (thread.isAlive()) { + Assert.fail("Thread didn't join"); + } else { + if (thread.failed) + Assert.fail("Did not receive expected message"); + } + cnxManager.halt(); + Assert.assertFalse(cnxManager.listener.isAlive()); + } + + @Test + public void testCnxManagerTimeout() throws Exception { + Random rand = new Random(); + byte b = (byte) rand.nextInt(); + int deadPort = PortAssignment.unique(); + String deadAddress = "10.1.1." + b; + + LOG.info("This is the dead address I'm trying: " + deadAddress); + + peers.put(Long.valueOf(2), + new QuorumServer(2, + new InetSocketAddress(deadAddress, deadPort), + new InetSocketAddress(deadAddress, PortAssignment.unique()), + new InetSocketAddress(deadAddress, PortAssignment.unique()))); + peerTmpdir[2] = ClientBase.createTmpDir(); + + QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2); + QuorumCnxManager cnxManager = new QuorumCnxManager(peer); + QuorumCnxManager.Listener listener = cnxManager.listener; + if (listener != null) { + listener.start(); + } else { + LOG.error("Null listener when initializing cnx manager"); + } + + long begin = Time.currentElapsedTime(); + cnxManager.toSend(2L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1)); + long end = Time.currentElapsedTime(); + + if ((end - begin) > 6000) Assert.fail("Waited more than necessary"); + cnxManager.halt(); + Assert.assertFalse(cnxManager.listener.isAlive()); + } + + /** + * Tests a bug in QuorumCnxManager that causes a spin lock + * when a negative value is sent. This test checks if the + * connection is being closed upon a message with negative + * length. + * + * @throws Exception + */ + @Test + public void testCnxManagerSpinLock() throws Exception { + QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2); + QuorumCnxManager cnxManager = new QuorumCnxManager(peer); + QuorumCnxManager.Listener listener = cnxManager.listener; + if (listener != null) { + listener.start(); + } else { + LOG.error("Null listener when initializing cnx manager"); + } + + int port = peers.get(peer.getId()).electionAddr.getPort(); + LOG.info("Election port: " + port); + + Thread.sleep(1000); + + SocketChannel sc = SocketChannel.open(); + sc.socket().connect(peers.get(1L).electionAddr, 5000); + + InetSocketAddress otherAddr = peers.get(new Long(2)).electionAddr; + DataOutputStream dout = new DataOutputStream(sc.socket().getOutputStream()); + dout.writeLong(QuorumCnxManager.PROTOCOL_VERSION); + dout.writeLong(new Long(2)); + String addr = otherAddr.getHostString() + ":" + otherAddr.getPort(); + byte[] addr_bytes = addr.getBytes(); + dout.writeInt(addr_bytes.length); + dout.write(addr_bytes); + dout.flush(); + + + ByteBuffer msgBuffer = ByteBuffer.wrap(new byte[4]); + msgBuffer.putInt(-20); + msgBuffer.position(0); + sc.write(msgBuffer); + + Thread.sleep(1000); + + try { + /* + * Write a number of times until it + * detects that the socket is broken. + */ + for (int i = 0; i < 100; i++) { + msgBuffer.position(0); + sc.write(msgBuffer); + } + Assert.fail("Socket has not been closed"); + } catch (Exception e) { + LOG.info("Socket has been closed as expected"); + } + peer.shutdown(); + cnxManager.halt(); + Assert.assertFalse(cnxManager.listener.isAlive()); + } + + /** + * Tests a bug in QuorumCnxManager that causes a NPE when a 3.4.6 + * observer connects to a 3.5.0 server. + * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1789} + * + * @throws Exception + */ + @Test + public void testCnxManagerNPE() throws Exception { + // the connecting peer (id = 2) is a 3.4.6 observer + peers.get(2L).type = LearnerType.OBSERVER; + QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], + peerClientPort[1], 3, 1, 1000, 2, 2); + QuorumCnxManager cnxManager = new QuorumCnxManager(peer); + QuorumCnxManager.Listener listener = cnxManager.listener; + if (listener != null) { + listener.start(); + } else { + LOG.error("Null listener when initializing cnx manager"); + } + int port = peers.get(peer.getId()).electionAddr.getPort(); + LOG.info("Election port: " + port); + + Thread.sleep(1000); + + SocketChannel sc = SocketChannel.open(); + sc.socket().connect(peers.get(1L).electionAddr, 5000); + + /* + * Write id (3.4.6 protocol). This previously caused a NPE in + * QuorumCnxManager. + */ + byte[] msgBytes = new byte[8]; + ByteBuffer msgBuffer = ByteBuffer.wrap(msgBytes); + msgBuffer.putLong(2L); + msgBuffer.position(0); + sc.write(msgBuffer); + + msgBuffer = ByteBuffer.wrap(new byte[8]); + // write length of message + msgBuffer.putInt(4); + // write message + msgBuffer.putInt(5); + msgBuffer.position(0); + sc.write(msgBuffer); + + Message m = cnxManager.pollRecvQueue(1000, TimeUnit.MILLISECONDS); + Assert.assertNotNull(m); + + peer.shutdown(); + cnxManager.halt(); + Assert.assertFalse(cnxManager.listener.isAlive()); + } + + /* + * Test if a receiveConnection is able to timeout on socket errors + */ + @Test + public void testSocketTimeout() throws Exception { + QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 2, 2); + QuorumCnxManager cnxManager = new QuorumCnxManager(peer); + QuorumCnxManager.Listener listener = cnxManager.listener; + if (listener != null) { + listener.start(); + } else { + LOG.error("Null listener when initializing cnx manager"); + } + int port = peers.get(peer.getId()).electionAddr.getPort(); + LOG.info("Election port: " + port); + Thread.sleep(1000); + + Socket sock = new Socket(); + sock.connect(peers.get(1L).electionAddr, 5000); + long begin = Time.currentElapsedTime(); + // Read without sending data. Verify timeout. + cnxManager.receiveConnection(sock); + long end = Time.currentElapsedTime(); + if ((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary"); + cnxManager.halt(); + Assert.assertFalse(cnxManager.listener.isAlive()); + } + + /* + * Test if Worker threads are getting killed after connection loss + */ + @Test + public void testWorkerThreads() throws Exception { + ArrayList peerList = new ArrayList(); + try { + for (int sid = 0; sid < 3; sid++) { + QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[sid], + peerTmpdir[sid], peerClientPort[sid], 3, sid, 1000, 2, + 2); + LOG.info("Starting peer {}", peer.getId()); + peer.start(); + peerList.add(sid, peer); + } + String failure = verifyThreadCount(peerList, 4); + Assert.assertNull(failure, failure); + for (int myid = 0; myid < 3; myid++) { + for (int i = 0; i < 5; i++) { + // halt one of the listeners and verify count + QuorumPeer peer = peerList.get(myid); + LOG.info("Round {}, halting peer ", + new Object[]{i, peer.getId()}); + peer.shutdown(); + peerList.remove(myid); + failure = verifyThreadCount(peerList, 2); + Assert.assertNull(failure, failure); + // Restart halted node and verify count + peer = new QuorumPeer(peers, peerTmpdir[myid], + peerTmpdir[myid], peerClientPort[myid], 3, myid, + 1000, 2, 2); + LOG.info("Round {}, restarting peer ", + new Object[]{i, peer.getId()}); + peer.start(); + peerList.add(myid, peer); + failure = verifyThreadCount(peerList, 4); + Assert.assertNull(failure, failure); + } + } + } finally { + for (QuorumPeer quorumPeer : peerList) { + quorumPeer.shutdown(); + } + } + } + + /** + * Returns null on success, otw the message assoc with the failure + * @throws InterruptedException + */ + public String verifyThreadCount(ArrayList peerList, long ecnt) + throws InterruptedException { + String failure = null; + for (int i = 0; i < 480; i++) { + Thread.sleep(500); + + failure = _verifyThreadCount(peerList, ecnt); + if (failure == null) { + return null; + } + } + return failure; + } + + public String _verifyThreadCount(ArrayList peerList, long ecnt) { + for (int myid = 0; myid < peerList.size(); myid++) { + QuorumPeer peer = peerList.get(myid); + QuorumCnxManager cnxManager = peer.getQuorumCnxManager(); + long cnt = cnxManager.getThreadCount(); + if (cnt != ecnt) { + return new Date() + + " Incorrect number of Worker threads for sid=" + myid + + " expected " + ecnt + " found " + cnt; + } + } + return null; + } + + @Test + public void testInitialMessage() throws Exception { + InitialMessage msg; + ByteArrayOutputStream bos; + DataInputStream din; + DataOutputStream dout; + String hostport; + + // message with bad protocol version + try { + + // the initial message (without the protocol version) + hostport = "10.0.0.2:3888"; + bos = new ByteArrayOutputStream(); + dout = new DataOutputStream(bos); + dout.writeLong(5L); // sid + dout.writeInt(hostport.getBytes().length); + dout.writeBytes(hostport); + + // now parse it + din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray())); + msg = InitialMessage.parse(-65530L, din); + Assert.fail("bad protocol version accepted"); + } catch (InitialMessage.InitialMessageException ex) { + } + + // message too long + try { + + hostport = createLongString(1048576); + bos = new ByteArrayOutputStream(); + dout = new DataOutputStream(bos); + dout.writeLong(5L); // sid + dout.writeInt(hostport.getBytes().length); + dout.writeBytes(hostport); + + din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray())); + msg = InitialMessage.parse(QuorumCnxManager.PROTOCOL_VERSION, din); + Assert.fail("long message accepted"); + } catch (InitialMessage.InitialMessageException ex) { + } + + // bad hostport string + try { + + hostport = "what's going on here?"; + bos = new ByteArrayOutputStream(); + dout = new DataOutputStream(bos); + dout.writeLong(5L); // sid + dout.writeInt(hostport.getBytes().length); + dout.writeBytes(hostport); + + din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray())); + msg = InitialMessage.parse(QuorumCnxManager.PROTOCOL_VERSION, din); + Assert.fail("bad hostport accepted"); + } catch (InitialMessage.InitialMessageException ex) { + } + + // good message + try { + + hostport = "10.0.0.2:3888"; + bos = new ByteArrayOutputStream(); + dout = new DataOutputStream(bos); + dout.writeLong(5L); // sid + dout.writeInt(hostport.getBytes().length); + dout.writeBytes(hostport); + + // now parse it + din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray())); + msg = InitialMessage.parse(QuorumCnxManager.PROTOCOL_VERSION, din); + } catch (InitialMessage.InitialMessageException ex) { + Assert.fail(ex.toString()); + } + } + + private String createLongString(int size) { + StringBuilder sb = new StringBuilder(size); + for (int i = 0; i < size; i++) { + sb.append('x'); + } + return sb.toString(); + } + + class CnxManagerThread extends Thread { + + boolean failed; + + CnxManagerThread() { + failed = false; + } + + public void run() { + try { + QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2); + QuorumCnxManager cnxManager = new QuorumCnxManager(peer); + QuorumCnxManager.Listener listener = cnxManager.listener; + if (listener != null) { + listener.start(); + } else { + LOG.error("Null listener when initializing cnx manager"); + } + + long sid = 1; + cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1)); + + Message m = null; + int numRetries = 1; + while ((m == null) && (numRetries++ <= THRESHOLD)) { + m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS); + if (m == null) cnxManager.connectAll(); + } + + if (numRetries > THRESHOLD) { + failed = true; + return; + } + + cnxManager.testInitiateConnection(sid); + + m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS); + if (m == null) { + failed = true; + return; + } + } catch (Exception e) { + LOG.error("Exception while running mock thread", e); + Assert.fail("Unexpected exception"); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ConnectStringParserTest.java b/src/java/test/org/apache/zookeeper/test/ConnectStringParserTest.java new file mode 100644 index 00000000000..5fe94cabd17 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ConnectStringParserTest.java @@ -0,0 +1,61 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.client.ConnectStringParser; +import org.junit.Assert; +import org.junit.Test; + +public class ConnectStringParserTest extends ZKTestCase { + + @Test + public void testSingleServerChrootPath() { + String chrootPath = "/hallo/welt"; + String servers = "10.10.10.1"; + assertChrootPath(chrootPath, + new ConnectStringParser(servers + chrootPath)); + } + + @Test + public void testMultipleServersChrootPath() { + String chrootPath = "/hallo/welt"; + String servers = "10.10.10.1,10.10.10.2"; + assertChrootPath(chrootPath, + new ConnectStringParser(servers + chrootPath)); + } + + @Test + public void testParseServersWithoutPort() { + String servers = "10.10.10.1,10.10.10.2"; + ConnectStringParser parser = new ConnectStringParser(servers); + + Assert.assertEquals("10.10.10.1", parser.getServerAddresses().get(0).getHostString()); + Assert.assertEquals("10.10.10.2", parser.getServerAddresses().get(1).getHostString()); + } + + @Test + public void testParseServersWithPort() { + String servers = "10.10.10.1:112,10.10.10.2:110"; + ConnectStringParser parser = new ConnectStringParser(servers); + + Assert.assertEquals("10.10.10.1", parser.getServerAddresses().get(0).getHostString()); + Assert.assertEquals("10.10.10.2", parser.getServerAddresses().get(1).getHostString()); + + Assert.assertEquals(112, parser.getServerAddresses().get(0).getPort()); + Assert.assertEquals(110, parser.getServerAddresses().get(1).getPort()); + } + + private void assertChrootPath(String expected, ConnectStringParser parser) { + Assert.assertEquals(expected, parser.getChrootPath()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/CreateModeTest.java b/src/java/test/org/apache/zookeeper/test/CreateModeTest.java new file mode 100644 index 00000000000..a0c65289408 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/CreateModeTest.java @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.ZKTestCase; +import org.junit.Assert; +import org.junit.Test; + +import java.util.EnumSet; + +public class CreateModeTest extends ZKTestCase { + + @Test + public void testBasicCreateMode() { + CreateMode cm = CreateMode.PERSISTENT; + Assert.assertEquals(cm.toFlag(), 0); + Assert.assertFalse(cm.isEphemeral()); + Assert.assertFalse(cm.isSequential()); + Assert.assertFalse(cm.isContainer()); + + cm = CreateMode.EPHEMERAL; + Assert.assertEquals(cm.toFlag(), 1); + Assert.assertTrue(cm.isEphemeral()); + Assert.assertFalse(cm.isSequential()); + Assert.assertFalse(cm.isContainer()); + + cm = CreateMode.PERSISTENT_SEQUENTIAL; + Assert.assertEquals(cm.toFlag(), 2); + Assert.assertFalse(cm.isEphemeral()); + Assert.assertTrue(cm.isSequential()); + Assert.assertFalse(cm.isContainer()); + + cm = CreateMode.EPHEMERAL_SEQUENTIAL; + Assert.assertEquals(cm.toFlag(), 3); + Assert.assertTrue(cm.isEphemeral()); + Assert.assertTrue(cm.isSequential()); + Assert.assertFalse(cm.isContainer()); + + cm = CreateMode.CONTAINER; + Assert.assertEquals(cm.toFlag(), 4); + Assert.assertFalse(cm.isEphemeral()); + Assert.assertFalse(cm.isSequential()); + Assert.assertTrue(cm.isContainer()); + } + + @Test + public void testFlagConversion() throws KeeperException { + // Ensure we get the same value back after round trip conversion + EnumSet allModes = EnumSet.allOf(CreateMode.class); + + for (CreateMode cm : allModes) { + Assert.assertEquals(cm, CreateMode.fromFlag(cm.toFlag())); + } + } + + @Test + public void testInvalidFlagConversion() throws KeeperException { + try { + CreateMode.fromFlag(99); + Assert.fail("Shouldn't be able to convert 99 to a CreateMode."); + } catch (KeeperException ke) { + Assert.assertEquals(Code.BADARGUMENTS, ke.code()); + } + + try { + CreateMode.fromFlag(-1); + Assert.fail("Shouldn't be able to convert -1 to a CreateMode."); + } catch (KeeperException ke) { + Assert.assertEquals(Code.BADARGUMENTS, ke.code()); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/CreateTest.java b/src/java/test/org/apache/zookeeper/test/CreateTest.java new file mode 100644 index 00000000000..3d0a7e434e9 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/CreateTest.java @@ -0,0 +1,110 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +/** + * Test suite for validating the Create API. + */ +public class CreateTest extends ClientBase { + private ZooKeeper zk; + + @Override + public void setUp() throws Exception { + super.setUp(); + zk = createClient(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + zk.close(); + } + + @Test + public void testCreate() + throws IOException, KeeperException, InterruptedException { + createNoStatVerifyResult("/foo"); + createNoStatVerifyResult("/foo/child"); + } + + @Test + public void testCreateWithStat() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + Stat stat = createWithStatVerifyResult("/foo"); + Stat childStat = createWithStatVerifyResult("/foo/child"); + // Don't expect to get the same stats for different creates. + Assert.assertFalse(stat.equals(childStat)); + } + + @Test + public void testCreateWithNullStat() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + Assert.assertNull(zk.exists(name, false)); + + Stat stat = null; + // If a null Stat object is passed the create should still + // succeed, but no Stat info will be returned. + String path = zk.create(name, name.getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, stat); + Assert.assertNull(stat); + Assert.assertNotNull(zk.exists(name, false)); + } + + private void createNoStatVerifyResult(String newName) + throws KeeperException, InterruptedException { + Assert.assertNull("Node existed before created", zk.exists(newName, false)); + String path = zk.create(newName, newName.getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertEquals(path, newName); + Assert.assertNotNull("Node was not created as expected", + zk.exists(newName, false)); + } + + private Stat createWithStatVerifyResult(String newName) + throws KeeperException, InterruptedException { + Assert.assertNull("Node existed before created", zk.exists(newName, false)); + Stat stat = new Stat(); + String path = zk.create(newName, newName.getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, stat); + Assert.assertEquals(path, newName); + validateCreateStat(stat, newName); + + Stat referenceStat = zk.exists(newName, false); + Assert.assertNotNull("Node was not created as expected", referenceStat); + Assert.assertEquals(referenceStat, stat); + + return stat; + } + + private void validateCreateStat(Stat stat, String name) { + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(0, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(0, stat.getNumChildren()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java b/src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java new file mode 100644 index 00000000000..4dd1f4d4283 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/DisconnectableZooKeeper.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; + +import java.io.IOException; + +public class DisconnectableZooKeeper extends ZooKeeper { + public DisconnectableZooKeeper(String host, int sessionTimeout, Watcher watcher) + throws IOException { + super(host, sessionTimeout, watcher); + } + + public DisconnectableZooKeeper(String host, int sessionTimeout, Watcher watcher, + long sessionId, byte[] sessionPasswd) + throws IOException { + super(host, sessionTimeout, watcher, sessionId, sessionPasswd); + } + + /** Testing only!!! Really!!!! This is only here to test when the client + * disconnects from the server w/o sending a session disconnect (ie + * ending the session cleanly). The server will eventually notice the + * client is no longer pinging and will timeout the session. + */ + public void disconnect() throws IOException { + cnxn.disconnect(); + } + + /** + * Prevent the client from automatically reconnecting if the connection to the + * server is lost + */ + public void dontReconnect() throws Exception { + java.lang.reflect.Field f = cnxn.getClass().getDeclaredField("closing"); + f.setAccessible(true); + f.setBoolean(cnxn, true); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/DisconnectedWatcherTest.java b/src/java/test/org/apache/zookeeper/test/DisconnectedWatcherTest.java new file mode 100644 index 00000000000..4a2efdfb1d2 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/DisconnectedWatcherTest.java @@ -0,0 +1,247 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +public class DisconnectedWatcherTest extends ClientBase { + protected static final Logger LOG = LoggerFactory.getLogger(DisconnectedWatcherTest.class); + final int TIMEOUT = 5000; + + @Test + public void testChildWatcherAutoResetWithChroot() throws Exception { + ZooKeeper zk1 = createClient(); + + zk1.create("/ch1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + MyWatcher watcher = new MyWatcher(); + ZooKeeper zk2 = createClient(watcher, hostPort + "/ch1"); + zk2.getChildren("/", true); + + // this call shouldn't trigger any error or watch + zk1.create("/youdontmatter1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + // this should trigger the watch + zk1.create("/ch1/youshouldmatter1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + WatchedEvent e = watcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/", e.getPath()); + + MyWatcher childWatcher = new MyWatcher(); + zk2.getChildren("/", childWatcher); + + stopServer(); + watcher.waitForDisconnected(3000); + startServer(); + watcher.waitForConnected(3000); + + // this should trigger the watch + zk1.create("/ch1/youshouldmatter2", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + e = childWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/", e.getPath()); + } + + // @see jira issue ZOOKEEPER-961 + + @Test + public void testDefaultWatcherAutoResetWithChroot() throws Exception { + ZooKeeper zk1 = createClient(); + + zk1.create("/ch1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + MyWatcher watcher = new MyWatcher(); + ZooKeeper zk2 = createClient(watcher, hostPort + "/ch1"); + zk2.getChildren("/", true); + + // this call shouldn't trigger any error or watch + zk1.create("/youdontmatter1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + // this should trigger the watch + zk1.create("/ch1/youshouldmatter1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + WatchedEvent e = watcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/", e.getPath()); + + zk2.getChildren("/", true); + + stopServer(); + watcher.waitForDisconnected(3000); + startServer(); + watcher.waitForConnected(3000); + + // this should trigger the watch + zk1.create("/ch1/youshouldmatter2", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + e = watcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/", e.getPath()); + } + + @Test + public void testDeepChildWatcherAutoResetWithChroot() throws Exception { + ZooKeeper zk1 = createClient(); + + zk1.create("/ch1", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.create("/ch1/here", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.create("/ch1/here/we", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.create("/ch1/here/we/are", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + MyWatcher watcher = new MyWatcher(); + ZooKeeper zk2 = createClient(watcher, hostPort + "/ch1/here/we"); + zk2.getChildren("/are", true); + + // this should trigger the watch + zk1.create("/ch1/here/we/are/now", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + WatchedEvent e = watcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/are", e.getPath()); + + MyWatcher childWatcher = new MyWatcher(); + zk2.getChildren("/are", childWatcher); + + stopServer(); + watcher.waitForDisconnected(3000); + startServer(); + watcher.waitForConnected(3000); + + // this should trigger the watch + zk1.create("/ch1/here/we/are/again", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + e = childWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/are", e.getPath()); + } + + // @see jira issue ZOOKEEPER-706. Test auto reset of a large number of + // watches which require multiple SetWatches calls. + @Test + public void testManyChildWatchersAutoReset() throws Exception { + ZooKeeper zk1 = createClient(); + + MyWatcher watcher = new MyWatcher(); + ZooKeeper zk2 = createClient(watcher); + + // 110 character base path + String pathBase = "/long-path-000000000-111111111-222222222-333333333-444444444-" + + "555555555-666666666-777777777-888888888-999999999"; + + zk1.create(pathBase, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + // Create 10,000 nodes. This should ensure the length of our + // watches set below exceeds 1MB. + List paths = new ArrayList(); + for (int i = 0; i < 10000; i++) { + String path = zk1.create(pathBase + "/ch-", null, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + paths.add(path); + } + + MyWatcher childWatcher = new MyWatcher(); + + // Set a combination of child/exists/data watches + int i = 0; + for (String path : paths) { + if (i % 3 == 0) { + zk2.getChildren(path, childWatcher); + } else if (i % 3 == 1) { + zk2.exists(path + "/foo", childWatcher); + } else if (i % 3 == 2) { + zk2.getData(path, childWatcher, null); + } + + i++; + } + + stopServer(); + watcher.waitForDisconnected(30000); + startServer(); + watcher.waitForConnected(30000); + + // Trigger the watches and ensure they properly propagate to the client + i = 0; + for (String path : paths) { + if (i % 3 == 0) { + zk1.create(path + "/ch", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + WatchedEvent e = childWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals(path, e.getPath()); + } else if (i % 3 == 1) { + zk1.create(path + "/foo", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + WatchedEvent e = childWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeCreated, e.getType()); + Assert.assertEquals(path + "/foo", e.getPath()); + } else if (i % 3 == 2) { + zk1.setData(path, new byte[]{1, 2, 3}, -1); + + WatchedEvent e = childWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(EventType.NodeDataChanged, e.getType()); + Assert.assertEquals(path, e.getPath()); + } + + i++; + } + } + + private class MyWatcher extends CountdownWatcher { + LinkedBlockingQueue events = + new LinkedBlockingQueue(); + + public void process(WatchedEvent event) { + super.process(event); + if (event.getType() != Event.EventType.None) { + try { + events.put(event); + } catch (InterruptedException e) { + LOG.warn("ignoring interrupt during event.put"); + } + } + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/DuplicateLocalSessionUpgradeTest.java b/src/java/test/org/apache/zookeeper/test/DuplicateLocalSessionUpgradeTest.java new file mode 100644 index 00000000000..b6b0083dac5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/DuplicateLocalSessionUpgradeTest.java @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * When request are route incorrectly, both follower and the leader will perform + * local session upgrade. So we saw CreateSession twice in txnlog This doesn't + * affect the correctness but cause the ensemble to see more load than + * necessary. + */ +public class DuplicateLocalSessionUpgradeTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory + .getLogger(DuplicateLocalSessionUpgradeTest.class); + private static final int CONNECTION_TIMEOUT = ClientBase.CONNECTION_TIMEOUT; + private final QuorumBase qb = new QuorumBase(); + + @Before + public void setUp() throws Exception { + LOG.info("STARTING quorum " + getClass().getName()); + qb.localSessionsEnabled = true; + qb.localSessionsUpgradingEnabled = true; + qb.setUp(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + } + + @After + public void tearDown() throws Exception { + LOG.info("STOPPING quorum " + getClass().getName()); + qb.tearDown(); + } + + @Test + public void testLocalSessionUpgradeOnFollower() throws Exception { + testLocalSessionUpgrade(false); + } + + @Test + public void testLocalSessionUpgradeOnLeader() throws Exception { + testLocalSessionUpgrade(true); + } + + private void testLocalSessionUpgrade(boolean testLeader) throws Exception { + + int leaderIdx = qb.getLeaderIndex(); + Assert.assertFalse("No leader in quorum?", leaderIdx == -1); + int followerIdx = (leaderIdx + 1) % 5; + int testPeerIdx = testLeader ? leaderIdx : followerIdx; + String hostPorts[] = qb.hostPort.split(","); + + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = qb.createClient(watcher, hostPorts[testPeerIdx], + CONNECTION_TIMEOUT); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + final String firstPath = "/first"; + final String secondPath = "/ephemeral"; + + // Just create some node so that we know the current zxid + zk.create(firstPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + // Now, try an ephemeral node. This will trigger session upgrade + // so there will be createSession request inject into the pipeline + // prior to this request + zk.create(secondPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + + Stat firstStat = zk.exists(firstPath, null); + Assert.assertNotNull(firstStat); + + Stat secondStat = zk.exists(secondPath, null); + Assert.assertNotNull(secondStat); + + long zxidDiff = secondStat.getCzxid() - firstStat.getCzxid(); + + // If there is only one createSession request in between, zxid diff + // will be exactly 2. The alternative way of checking is to actually + // read txnlog but this should be sufficient + Assert.assertEquals(2L, zxidDiff); + + } +} diff --git a/src/java/test/org/apache/zookeeper/test/EventTypeTest.java b/src/java/test/org/apache/zookeeper/test/EventTypeTest.java new file mode 100644 index 00000000000..b73bf24dbce --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/EventTypeTest.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.ZKTestCase; +import org.junit.Assert; +import org.junit.Test; + +import java.util.EnumSet; + +public class EventTypeTest extends ZKTestCase { + + @Test + public void testIntConversion() { + // Ensure that we can convert all valid integers to EventTypes + EnumSet allTypes = EnumSet.allOf(EventType.class); + + for (EventType et : allTypes) { + Assert.assertEquals(et, EventType.fromInt(et.getIntValue())); + } + } + + @Test + public void testInvalidIntConversion() { + try { + EventType.fromInt(324242); + Assert.fail("Was able to create an invalid EventType via an integer"); + } catch (RuntimeException re) { + // we're good. + } + + } +} diff --git a/src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java b/src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java new file mode 100644 index 00000000000..edbd9ab5e96 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java @@ -0,0 +1,184 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.FastLeaderElection; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.Vote; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.Semaphore; + +public class FLENewEpochTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLENewEpochTest.class); + + int count; + HashMap peers; + ArrayList threads; + File tmpdir[]; + int port[]; + volatile int[] round; + + Semaphore start0; + Semaphore finish3, finish0; + + @Before + public void setUp() throws Exception { + count = 3; + + peers = new HashMap(count); + threads = new ArrayList(count); + tmpdir = new File[count]; + port = new int[count]; + + round = new int[3]; + round[0] = 0; + round[1] = 0; + round[2] = 0; + + start0 = new Semaphore(0); + finish0 = new Semaphore(0); + finish3 = new Semaphore(0); + } + + @After + public void tearDown() throws Exception { + for (int i = 0; i < threads.size(); i++) { + ((FastLeaderElection) threads.get(i).peer.getElectionAlg()).shutdown(); + } + } + + @Test + public void testLENewEpoch() throws Exception { + + LOG.info("TestLE: " + getTestName() + ", " + count); + for (int i = 0; i < count; i++) { + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()))); + tmpdir[i] = ClientBase.createTmpDir(); + port[i] = PortAssignment.unique(); + } + + for (int i = 1; i < count; i++) { + QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2); + peer.startLeaderElection(); + LEThread thread = new LEThread(peer, i); + thread.start(); + threads.add(thread); + } + if (!start0.tryAcquire(4000, java.util.concurrent.TimeUnit.MILLISECONDS)) + Assert.fail("First leader election failed"); + + QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2); + peer.startLeaderElection(); + LEThread thread = new LEThread(peer, 0); + thread.start(); + threads.add(thread); + + LOG.info("Started threads " + getTestName()); + + for (int i = 0; i < threads.size(); i++) { + threads.get(i).join(10000); + if (threads.get(i).isAlive()) { + Assert.fail("Threads didn't join"); + } + + } + } + + class LEThread extends Thread { + int i; + QuorumPeer peer; + + LEThread(QuorumPeer peer, int i) { + this.i = i; + this.peer = peer; + LOG.info("Constructor: " + getName()); + + } + + public void run() { + boolean flag = true; + try { + while (flag) { + Vote v = null; + peer.setPeerState(ServerState.LOOKING); + LOG.info("Going to call leader election again: " + i); + v = peer.getElectionAlg().lookForLeader(); + + if (v == null) { + Assert.fail("Thread " + i + " got a null vote"); + } + + /* + * A real zookeeper would take care of setting the current vote. Here + * we do it manually. + */ + peer.setCurrentVote(v); + + LOG.info("Finished election: " + i + ", " + v.getId()); + //votes[i] = v; + + switch (i) { + case 0: + LOG.info("First peer, do nothing, just join"); + if (finish0.tryAcquire(1000, java.util.concurrent.TimeUnit.MILLISECONDS)) { + //if(threads.get(0).peer.getPeerState() == ServerState.LEADING ){ + LOG.info("Setting flag to false"); + flag = false; + } + break; + case 1: + LOG.info("Second entering case"); + if (round[1] != 0) { + finish0.release(); + flag = false; + } else { + finish3.acquire(); + start0.release(); + } + LOG.info("Second is going to start second round"); + round[1]++; + break; + case 2: + LOG.info("Third peer, shutting it down"); + QuorumBase.shutdown(peer); + flag = false; + round[2] = 1; + finish3.release(); + LOG.info("Third leaving"); + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java b/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java new file mode 100644 index 00000000000..2d804cceaf0 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.FastLeaderElection; +import org.apache.zookeeper.server.quorum.QuorumCnxManager; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.HashMap; + +public class FLEPredicateTest extends ZKTestCase { + + protected static final Logger LOG = LoggerFactory.getLogger(FLEPredicateTest.class); + HashMap peers; + + @Test + public void testPredicate() throws IOException { + + peers = new HashMap(3); + + /* + * Creates list of peers. + */ + for (int i = 0; i < 3; i++) { + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()))); + } + + /* + * Creating peer. + */ + try { + File tmpDir = ClientBase.createTmpDir(); + QuorumPeer peer = new QuorumPeer(peers, tmpDir, tmpDir, + PortAssignment.unique(), 3, 0, 1000, 2, 2); + + MockFLE mock = new MockFLE(peer); + mock.start(); + + /* + * Lower epoch must return false + */ + + Assert.assertFalse(mock.predicate(4L, 0L, 0L, 3L, 0L, 2L)); + + /* + * Later epoch + */ + Assert.assertTrue(mock.predicate(0L, 0L, 1L, 1L, 0L, 0L)); + + /* + * Higher zxid + */ + Assert.assertTrue(mock.predicate(0L, 1L, 0L, 1L, 0L, 0L)); + + /* + * Higher id + */ + Assert.assertTrue(mock.predicate(1L, 1L, 0L, 0L, 1L, 0L)); + } catch (IOException e) { + LOG.error("Exception while creating quorum peer", e); + Assert.fail("Exception while creating quorum peer"); + } + } + + class MockFLE extends FastLeaderElection { + MockFLE(QuorumPeer peer) { + super(peer, new QuorumCnxManager(peer)); + } + + boolean predicate(long newId, long newZxid, long newEpoch, long curId, long curZxid, long curEpoch) { + return this.totalOrderPredicate(newId, newZxid, newEpoch, curId, curZxid, curEpoch); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/FLERestartTest.java b/src/java/test/org/apache/zookeeper/test/FLERestartTest.java new file mode 100644 index 00000000000..2ceca827043 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FLERestartTest.java @@ -0,0 +1,180 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.FastLeaderElection; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.Vote; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.concurrent.Semaphore; + +public class FLERestartTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLETest.class); + + private int count; + private HashMap peers; + private ArrayList restartThreads; + private File tmpdir[]; + private int port[]; + private Semaphore finish; + + int countVotes(HashSet hs, long id) { + int counter = 0; + for (TestVote v : hs) { + if (v.leader == id) counter++; + } + + return counter; + } + + @Before + public void setUp() throws Exception { + count = 3; + peers = new HashMap(count); + restartThreads = new ArrayList(count); + tmpdir = new File[count]; + port = new int[count]; + finish = new Semaphore(0); + } + + @After + public void tearDown() throws Exception { + for (int i = 0; i < restartThreads.size(); i++) { + ((FastLeaderElection) restartThreads.get(i).peer.getElectionAlg()).shutdown(); + } + } + + @Test + public void testLERestart() throws Exception { + + LOG.info("TestLE: " + getTestName() + ", " + count); + for (int i = 0; i < count; i++) { + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()))); + tmpdir[i] = ClientBase.createTmpDir(); + port[i] = PortAssignment.unique(); + } + + for (int i = 0; i < count; i++) { + QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2); + peer.startLeaderElection(); + FLERestartThread thread = new FLERestartThread(peer, i); + thread.start(); + restartThreads.add(thread); + } + LOG.info("Started threads " + getTestName()); + for (int i = 0; i < restartThreads.size(); i++) { + restartThreads.get(i).join(10000); + if (restartThreads.get(i).isAlive()) { + Assert.fail("Threads didn't join"); + } + + } + } + + static class TestVote { + long leader; + + TestVote(int id, long leader) { + this.leader = leader; + } + } + + class FLERestartThread extends Thread { + int i; + QuorumPeer peer; + int peerRound = 0; + + FLERestartThread(QuorumPeer peer, int i) { + this.i = i; + this.peer = peer; + LOG.info("Constructor: " + getName()); + } + + public void run() { + try { + Vote v = null; + while (true) { + peer.setPeerState(ServerState.LOOKING); + LOG.info("Going to call leader election again."); + v = peer.getElectionAlg().lookForLeader(); + if (v == null) { + LOG.info("Thread " + i + " got a null vote"); + break; + } + + /* + * A real zookeeper would take care of setting the current vote. Here + * we do it manually. + */ + peer.setCurrentVote(v); + + LOG.info("Finished election: " + i + ", " + v.getId()); + //votes[i] = v; + + switch (i) { + case 0: + if (peerRound == 0) { + LOG.info("First peer, shutting it down"); + QuorumBase.shutdown(peer); + ((FastLeaderElection) restartThreads.get(i).peer.getElectionAlg()).shutdown(); + + peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2); + peer.startLeaderElection(); + peerRound++; + } else { + finish.release(2); + return; + } + + break; + case 1: + LOG.info("Second entering case"); + finish.acquire(); + //if(threads.get(0).peer.getPeerState() == ServerState.LEADING ){ + LOG.info("Release"); + + return; + case 2: + LOG.info("First peer, do nothing, just join"); + finish.acquire(); + //if(threads.get(0).peer.getPeerState() == ServerState.LEADING ){ + LOG.info("Release"); + + return; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/FLETest.java b/src/java/test/org/apache/zookeeper/test/FLETest.java new file mode 100644 index 00000000000..8dd66e64afb --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FLETest.java @@ -0,0 +1,519 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.FastLeaderElection; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.Vote; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +public class FLETest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLETest.class); + private final int MAX_LOOP_COUNTER = 300; + int count; + HashMap peers; + ArrayList threads; + HashMap> voteMap; + HashMap quora; + File tmpdir[]; + int port[]; + int successCount; + volatile Vote votes[]; + volatile long leader = -1; + //volatile int round = 1; + Random rand = new Random(); + Set joinedThreads; + private FLETest.LEThread leThread; + + int countVotes(HashSet hs, long id) { + int counter = 0; + for (TestVote v : hs) { + if (v.leader == id) counter++; + } + + return counter; + } + + @Before + public void setUp() throws Exception { + count = 7; + + peers = new HashMap(count); + threads = new ArrayList(count); + voteMap = new HashMap>(); + votes = new Vote[count]; + tmpdir = new File[count]; + port = new int[count]; + successCount = 0; + joinedThreads = new HashSet(); + } + + @After + public void tearDown() throws Exception { + for (int i = 0; i < threads.size(); i++) { + leThread = threads.get(i); + QuorumBase.shutdown(leThread.peer); + } + } + + @Test + public void testSingleElection() throws Exception { + try { + runElection(1); + } catch (Exception e) { + Assert.fail(e.toString()); + } + } + + @Test + public void testDoubleElection() throws Exception { + try { + runElection(2); + } catch (Exception e) { + Assert.fail(e.toString()); + } + } + + @Test + public void testTripleElection() throws Exception { + try { + runElection(3); + } catch (Exception e) { + Assert.fail(e.toString()); + } + } + + /** + * Test leader election for a number of rounds. In all rounds but the last one + * we kill the leader. + * + * @param rounds + * @throws Exception + */ + private void runElection(int rounds) throws Exception { + ConcurrentHashMap> quora = + new ConcurrentHashMap>(); + + LOG.info("TestLE: " + getTestName() + ", " + count); + + /* + * Creates list of peers. + */ + for (int i = 0; i < count; i++) { + port[i] = PortAssignment.unique(); + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", port[i]))); + tmpdir[i] = ClientBase.createTmpDir(); + } + + /* + * Start one LEThread for each peer we want to run. + */ + for (int i = 0; i < count; i++) { + QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], + port[i], 3, i, 1000, 2, 2); + peer.startLeaderElection(); + LEThread thread = new LEThread(this, peer, i, rounds, quora); + thread.start(); + threads.add(thread); + } + LOG.info("Started threads " + getTestName()); + + int waitCounter = 0; + synchronized (this) { + while (((successCount <= count / 2) || (leader == -1)) + && (waitCounter < MAX_LOOP_COUNTER)) { + this.wait(200); + waitCounter++; + } + } + LOG.info("Success count: " + successCount); + + /* + * Lists what threads haven't joined. A thread doesn't join if + * it hasn't decided upon a leader yet. It can happen that a + * peer is slow or disconnected, and it can take longer to + * nominate and connect to the current leader. + */ + for (int i = 0; i < threads.size(); i++) { + if (threads.get(i).isAlive()) { + LOG.info("Threads didn't join: " + i); + } + } + + /* + * If we have a majority, then we are good to go. + */ + if (successCount <= count / 2) { + Assert.fail("Fewer than a a majority has joined"); + } + + /* + * I'm done so joining. + */ + if (!joinedThreads.contains(leader)) { + Assert.fail("Leader hasn't joined: " + leader); + } + } + + /* + * For ZOOKEEPER-975 verify that a peer joining an established cluster + * does not go in LEADING state. + */ + @Test + public void testJoin() throws Exception { + int sid; + QuorumPeer peer; + int waitTime = 10 * 1000; + ArrayList peerList = new ArrayList(); + for (sid = 0; sid < 3; sid++) { + port[sid] = PortAssignment.unique(); + peers.put(Long.valueOf(sid), + new QuorumServer(sid, + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", port[sid]))); + tmpdir[sid] = ClientBase.createTmpDir(); + } + // start 2 peers and verify if they form the cluster + for (sid = 0; sid < 2; sid++) { + peer = new QuorumPeer(peers, tmpdir[sid], tmpdir[sid], + port[sid], 3, sid, 2000, 2, 2); + LOG.info("Starting peer " + peer.getId()); + peer.start(); + peerList.add(sid, peer); + } + peer = peerList.get(0); + VerifyState v1 = new VerifyState(peerList.get(0)); + v1.start(); + v1.join(waitTime); + Assert.assertFalse("Unable to form cluster in " + + waitTime + " ms", + !v1.isSuccess()); + // Start 3rd peer and check if it goes in LEADING state + peer = new QuorumPeer(peers, tmpdir[sid], tmpdir[sid], + port[sid], 3, sid, 2000, 2, 2); + LOG.info("Starting peer " + peer.getId()); + peer.start(); + peerList.add(sid, peer); + v1 = new VerifyState(peer); + v1.start(); + v1.join(waitTime); + if (v1.isAlive()) { + Assert.fail("Peer " + peer.getId() + " failed to join the cluster " + + "within " + waitTime + " ms"); + } else if (!v1.isSuccess()) { + Assert.fail("Incorrect LEADING state for peer " + peer.getId()); + } + // cleanup + for (int id = 0; id < 3; id++) { + peer = peerList.get(id); + if (peer != null) { + peer.shutdown(); + } + } + } + + /* + * For ZOOKEEPER-1732 verify that it is possible to join an ensemble with + * inconsistent election round information. + */ + @Test + public void testJoinInconsistentEnsemble() throws Exception { + int sid; + QuorumPeer peer; + int waitTime = 10 * 1000; + ArrayList peerList = new ArrayList(); + for (sid = 0; sid < 3; sid++) { + peers.put(Long.valueOf(sid), + new QuorumServer(sid, + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()))); + tmpdir[sid] = ClientBase.createTmpDir(); + port[sid] = PortAssignment.unique(); + } + // start 2 peers and verify if they form the cluster + for (sid = 0; sid < 2; sid++) { + peer = new QuorumPeer(peers, tmpdir[sid], tmpdir[sid], + port[sid], 3, sid, 2000, 2, 2); + LOG.info("Starting peer " + peer.getId()); + peer.start(); + peerList.add(sid, peer); + } + peer = peerList.get(0); + VerifyState v1 = new VerifyState(peerList.get(0)); + v1.start(); + v1.join(waitTime); + Assert.assertFalse("Unable to form cluster in " + + waitTime + " ms", + !v1.isSuccess()); + // Change the election round for one of the members of the ensemble + long leaderSid = peer.getCurrentVote().getId(); + long zxid = peer.getCurrentVote().getZxid(); + long electionEpoch = peer.getCurrentVote().getElectionEpoch(); + ServerState state = peer.getCurrentVote().getState(); + long peerEpoch = peer.getCurrentVote().getPeerEpoch(); + Vote newVote = new Vote(leaderSid, zxid + 100, electionEpoch + 100, peerEpoch, state); + peer.setCurrentVote(newVote); + // Start 3rd peer and check if it joins the quorum + peer = new QuorumPeer(peers, tmpdir[2], tmpdir[2], + port[2], 3, 2, 2000, 2, 2); + LOG.info("Starting peer " + peer.getId()); + peer.start(); + peerList.add(sid, peer); + v1 = new VerifyState(peer); + v1.start(); + v1.join(waitTime); + if (v1.isAlive()) { + Assert.fail("Peer " + peer.getId() + " failed to join the cluster " + + "within " + waitTime + " ms"); + } + // cleanup + for (int id = 0; id < 3; id++) { + peer = peerList.get(id); + if (peer != null) { + peer.shutdown(); + } + } + } + + static class TestVote { + long leader; + + TestVote(int id, long leader) { + this.leader = leader; + } + } + + /* + * Class to verify of the thread has become a follower + */ + static class VerifyState extends Thread { + volatile private boolean success = false; + private QuorumPeer peer; + + public VerifyState(QuorumPeer peer) { + this.peer = peer; + } + + public void run() { + setName("VerifyState-" + peer.getId()); + while (true) { + if (peer.getPeerState() == ServerState.FOLLOWING) { + LOG.info("I am following"); + success = true; + break; + } else if (peer.getPeerState() == ServerState.LEADING) { + LOG.info("I am leading"); + success = false; + break; + } + try { + Thread.sleep(250); + } catch (Exception e) { + LOG.warn("Sleep failed ", e); + } + } + } + + public boolean isSuccess() { + return success; + } + } + + /** + * Implements the behavior of a peer during the leader election rounds + * of tests. + */ + class LEThread extends Thread { + FLETest self; + int i; + QuorumPeer peer; + int totalRounds; + ConcurrentHashMap> quora; + + LEThread(FLETest self, QuorumPeer peer, int i, int rounds, ConcurrentHashMap> quora) { + this.self = self; + this.i = i; + this.peer = peer; + this.totalRounds = rounds; + this.quora = quora; + + LOG.info("Constructor: " + getName()); + } + + public void run() { + try { + Vote v = null; + while (true) { + + /* + * Set the state of the peer to LOOKING and look for leader + */ + peer.setPeerState(ServerState.LOOKING); + LOG.info("Going to call leader election again."); + v = peer.getElectionAlg().lookForLeader(); + if (v == null) { + LOG.info("Thread " + i + " got a null vote"); + break; + } + + /* + * Done with the election round, so now we set the vote in + * the peer. A real zookeeper would take care of setting the + * current vote. Here we do it manually. + */ + peer.setCurrentVote(v); + + LOG.info("Finished election: " + i + ", " + v.getId()); + votes[i] = v; + + /* + * Get the current value of the logical clock for this peer + * so that we know in which round this peer has executed. + */ + int lc = (int) ((FastLeaderElection) peer.getElectionAlg()).getLogicalClock(); + + /* + * The leader executes the following block, which essentially shuts down + * the peer if it is not the last round. + */ + if (v.getId() == i) { + LOG.info("I'm the leader: " + i); + if (lc < this.totalRounds) { + LOG.info("Leader " + i + " dying"); + FastLeaderElection election = + (FastLeaderElection) peer.getElectionAlg(); + election.shutdown(); + // Make sure the vote is reset to -1 after shutdown. + Assert.assertEquals(-1, election.getVote().getId()); + LOG.info("Leader " + i + " dead"); + + break; + } + } + + /* + * If the peer has done enough rounds, then consider joining. The thread + * will only join if it is part of a quorum supporting the current + * leader. Otherwise it will try again. + */ + if (lc >= this.totalRounds) { + /* + * quora keeps the supporters of a given leader, so + * we first update it with the vote of this peer. + */ + if (quora.get(v.getId()) == null) quora.put(v.getId(), new HashSet()); + quora.get(v.getId()).add(i); + + /* + * we now wait until a quorum supports the same leader. + */ + if (waitForQuorum(v.getId())) { + synchronized (self) { + + /* + * Assert that the state of the thread is the one expected. + */ + if (v.getId() == i) { + Assert.assertTrue("Wrong state" + peer.getPeerState(), + peer.getPeerState() == ServerState.LEADING); + leader = i; + } else { + Assert.assertTrue("Wrong state" + peer.getPeerState(), + peer.getPeerState() == ServerState.FOLLOWING); + } + + /* + * Global variable keeping track of + * how many peers have successfully + * joined. + */ + successCount++; + joinedThreads.add((long) i); + self.notify(); + } + + /* + * I'm done so joining. + */ + break; + } else { + quora.get(v.getId()).remove(i); + } + } + + /* + * This sleep time represents the time a follower + * would take to declare the leader dead and start + * a new leader election. + */ + Thread.sleep(100); + + } + LOG.debug("Thread " + i + " votes " + v); + } catch (InterruptedException e) { + Assert.fail(e.toString()); + } + } + + /** + * Auxiliary method to make sure that enough followers terminated. + * + * @return boolean followers successfully joined. + */ + boolean waitForQuorum(long id) + throws InterruptedException { + int loopCounter = 0; + while ((quora.get(id).size() <= count / 2) && (loopCounter < MAX_LOOP_COUNTER)) { + Thread.sleep(100); + loopCounter++; + } + + if ((loopCounter >= MAX_LOOP_COUNTER) && (quora.get(id).size() <= count / 2)) { + return false; + } else { + return true; + } + } + + } +} diff --git a/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java b/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java new file mode 100644 index 00000000000..dfdcf320d8d --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.Vote; +import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Properties; + +public class FLEZeroWeightTest extends ZKTestCase { + private static final Logger LOG = LoggerFactory.getLogger(HierarchicalQuorumTest.class); + + Properties qp; + + int count; + HashMap peers; + ArrayList threads; + File tmpdir[]; + int port[]; + + volatile Vote votes[]; + + @Before + public void setUp() throws Exception { + count = 9; + + peers = new HashMap(count); + threads = new ArrayList(count); + votes = new Vote[count]; + tmpdir = new File[count]; + port = new int[count]; + + String config = "group.1=0:1:2\n" + + "group.2=3:4:5\n" + + "group.3=6:7:8\n" + + "weight.0=1\n" + + "weight.1=1\n" + + "weight.2=1\n" + + "weight.3=0\n" + + "weight.4=0\n" + + "weight.5=0\n" + + "weight.6=0\n" + + "weight.7=0\n" + + "weight.8=0"; + + ByteArrayInputStream is = new ByteArrayInputStream(config.getBytes()); + this.qp = new Properties(); + qp.load(is); + } + + @After + public void tearDown() throws Exception { + for (int i = 0; i < threads.size(); i++) { + LEThread leThread = threads.get(i); + // shutdown() has to be explicitly called for every thread to + // make sure that resources are freed properly and all fixed network ports + // are available for other test cases + QuorumBase.shutdown(leThread.peer); + } + } + + @Test + public void testZeroWeightQuorum() throws Exception { + LOG.info("TestZeroWeightQuorum: " + getTestName() + ", " + count); + for (int i = 0; i < count; i++) { + InetSocketAddress addr1 = new InetSocketAddress("127.0.0.1", PortAssignment.unique()); + InetSocketAddress addr2 = new InetSocketAddress("127.0.0.1", PortAssignment.unique()); + InetSocketAddress addr3 = new InetSocketAddress("127.0.0.1", PortAssignment.unique()); + port[i] = addr3.getPort(); + qp.setProperty("server." + i, "127.0.0.1:" + addr1.getPort() + ":" + addr2.getPort() + ";" + port[i]); + peers.put(Long.valueOf(i), new QuorumServer(i, addr1, addr2, addr3)); + tmpdir[i] = ClientBase.createTmpDir(); + } + + for (int i = 0; i < count; i++) { + QuorumHierarchical hq = new QuorumHierarchical(qp); + QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2, hq); + peer.startLeaderElection(); + LEThread thread = new LEThread(peer, i); + thread.start(); + threads.add(thread); + } + LOG.info("Started threads " + getTestName()); + + for (int i = 0; i < threads.size(); i++) { + threads.get(i).join(15000); + if (threads.get(i).isAlive()) { + Assert.fail("Threads didn't join"); + } else { + if (threads.get(i).fail) + Assert.fail("Elected zero-weight server"); + } + } + } + + class LEThread extends Thread { + int i; + QuorumPeer peer; + boolean fail; + + LEThread(QuorumPeer peer, int i) { + this.i = i; + this.peer = peer; + LOG.info("Constructor: " + getName()); + } + + public void run() { + try { + Vote v = null; + fail = false; + while (true) { + + //while(true) { + peer.setPeerState(ServerState.LOOKING); + LOG.info("Going to call leader election."); + v = peer.getElectionAlg().lookForLeader(); + if (v == null) { + LOG.info("Thread " + i + " got a null vote"); + return; + } + + /* + * A real zookeeper would take care of setting the current vote. Here + * we do it manually. + */ + peer.setCurrentVote(v); + + LOG.info("Finished election: " + i + ", " + v.getId()); + votes[i] = v; + + if ((peer.getPeerState() == ServerState.LEADING) && + (peer.getId() > 2)) fail = true; + + if ((peer.getPeerState() == ServerState.FOLLOWING) || + (peer.getPeerState() == ServerState.LEADING)) break; + } + LOG.debug("Thread " + i + " votes " + v); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/FollowerResyncConcurrencyTest.java b/src/java/test/org/apache/zookeeper/test/FollowerResyncConcurrencyTest.java new file mode 100644 index 00000000000..76ecf3af275 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FollowerResyncConcurrencyTest.java @@ -0,0 +1,734 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.quorum.Leader; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; +import java.util.Set; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +public class FollowerResyncConcurrencyTest extends ZKTestCase { + public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; + private static final Logger LOG = LoggerFactory.getLogger(FollowerResyncConcurrencyTest.class); + private AtomicInteger counter = new AtomicInteger(0); + private AtomicInteger errors = new AtomicInteger(0); + /** + * Keep track of pending async operations, we shouldn't start verifying + * the state until pending operation is 0 + */ + private AtomicInteger pending = new AtomicInteger(0); + + private static DisconnectableZooKeeper createClient(int port, + CountdownWatcher watcher) + throws IOException, TimeoutException, InterruptedException { + DisconnectableZooKeeper zk = new DisconnectableZooKeeper( + "127.0.0.1:" + port, ClientBase.CONNECTION_TIMEOUT, watcher); + + watcher.waitForConnected(CONNECTION_TIMEOUT); + return zk; + } + + private static TestableZooKeeper createTestableClient(String hp) + throws IOException, TimeoutException, InterruptedException { + CountdownWatcher watcher = new CountdownWatcher(); + return createTestableClient(watcher, hp); + } + + private static TestableZooKeeper createTestableClient( + CountdownWatcher watcher, String hp) + throws IOException, TimeoutException, InterruptedException { + TestableZooKeeper zk = new TestableZooKeeper( + hp, ClientBase.CONNECTION_TIMEOUT, watcher); + + watcher.waitForConnected(CONNECTION_TIMEOUT); + return zk; + } + + @Before + public void setUp() throws Exception { + pending.set(0); + errors.set(0); + counter.set(0); + } + + @After + public void tearDown() throws Exception { + LOG.info("Error count {}", errors.get()); + } + + /** + * See ZOOKEEPER-1319 - verify that a lagging follwer resyncs correctly + * + * 1) start with down quorum + * 2) start leader/follower1, add some data + * 3) restart leader/follower1 + * 4) start follower2 + * 5) verify data consistency across the ensemble + * + * @throws Exception + */ + @Test + public void testLaggingFollowerResyncsUnderNewEpoch() throws Exception { + CountdownWatcher watcher1 = new CountdownWatcher(); + CountdownWatcher watcher2 = new CountdownWatcher(); + CountdownWatcher watcher3 = new CountdownWatcher(); + + QuorumUtil qu = new QuorumUtil(1); + qu.shutdownAll(); + + qu.start(1); + qu.start(2); + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + qu.getPeer(1).clientPort, ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + qu.getPeer(2).clientPort, ClientBase.CONNECTION_TIMEOUT)); + + ZooKeeper zk1 = + createClient(qu.getPeer(1).peer.getClientPort(), watcher1); + LOG.info("zk1 has session id 0x{}", Long.toHexString(zk1.getSessionId())); + + final String resyncPath = "/resyncundernewepoch"; + zk1.create(resyncPath, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk1.close(); + + qu.shutdown(1); + qu.shutdown(2); + Assert.assertTrue("Waiting for server down", ClientBase.waitForServerDown("127.0.0.1:" + + qu.getPeer(1).clientPort, ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("Waiting for server down", ClientBase.waitForServerDown("127.0.0.1:" + + qu.getPeer(2).clientPort, ClientBase.CONNECTION_TIMEOUT)); + + qu.start(1); + qu.start(2); + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + qu.getPeer(1).clientPort, ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + qu.getPeer(2).clientPort, ClientBase.CONNECTION_TIMEOUT)); + + qu.start(3); + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + qu.getPeer(3).clientPort, ClientBase.CONNECTION_TIMEOUT)); + + zk1 = createClient(qu.getPeer(1).peer.getClientPort(), watcher1); + LOG.info("zk1 has session id 0x{}", Long.toHexString(zk1.getSessionId())); + + assertNotNull("zk1 has data", zk1.exists(resyncPath, false)); + + final ZooKeeper zk2 = + createClient(qu.getPeer(2).peer.getClientPort(), watcher2); + LOG.info("zk2 has session id 0x{}", Long.toHexString(zk2.getSessionId())); + + assertNotNull("zk2 has data", zk2.exists(resyncPath, false)); + + final ZooKeeper zk3 = + createClient(qu.getPeer(3).peer.getClientPort(), watcher3); + LOG.info("zk3 has session id 0x{}", Long.toHexString(zk3.getSessionId())); + + assertNotNull("zk3 has data", zk3.exists(resyncPath, false)); + + zk1.close(); + zk2.close(); + zk3.close(); + + qu.shutdownAll(); + } + + /** + * See ZOOKEEPER-962. This tests for one of the bugs hit while fixing this, + * setting the ZXID of the SNAP packet + * Starts up 3 ZKs. Shut down F1, write a node, restart the one that was shut down + * The non-leader ZKs are writing to cluster + * Shut down F1 again + * Restart after sessions are expired, expect to get a snap file + * Shut down, run some transactions through. + * Restart to a diff while transactions are running in leader + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void testResyncBySnapThenDiffAfterFollowerCrashes() + throws IOException, InterruptedException, KeeperException, Throwable { + followerResyncCrashTest(false); + } + + /** + * Same as testResyncBySnapThenDiffAfterFollowerCrashes() but we resync + * follower using txnlog + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void testResyncByTxnlogThenDiffAfterFollowerCrashes() + throws IOException, InterruptedException, KeeperException, Throwable { + followerResyncCrashTest(true); + } + + public void followerResyncCrashTest(boolean useTxnLogResync) + throws IOException, InterruptedException, KeeperException, Throwable { + final Semaphore sem = new Semaphore(0); + + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + CountdownWatcher watcher1 = new CountdownWatcher(); + CountdownWatcher watcher2 = new CountdownWatcher(); + CountdownWatcher watcher3 = new CountdownWatcher(); + + int index = 1; + while (qu.getPeer(index).peer.leader == null) { + index++; + } + + Leader leader = qu.getPeer(index).peer.leader; + assertNotNull(leader); + + if (useTxnLogResync) { + // Set the factor to high value so that this test case always + // resync using txnlog + qu.getPeer(index).peer.getActiveServer().getZKDatabase() + .setSnapshotSizeFactor(1000); + } else { + // Disable sending DIFF using txnlog, so that this test still + // testing the ZOOKEEPER-962 bug + qu.getPeer(index).peer.getActiveServer().getZKDatabase() + .setSnapshotSizeFactor(-1); + } + + /* Reusing the index variable to select a follower to connect to */ + index = (index == 1) ? 2 : 1; + LOG.info("Connecting to follower: {}", index); + + qu.shutdown(index); + + final ZooKeeper zk3 = + createClient(qu.getPeer(3).peer.getClientPort(), watcher3); + LOG.info("zk3 has session id 0x{}", Long.toHexString(zk3.getSessionId())); + + zk3.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL); + + qu.restart(index); + + final ZooKeeper zk1 = + createClient(qu.getPeer(index).peer.getClientPort(), watcher1); + LOG.info("zk1 has session id 0x{}", Long.toHexString(zk1.getSessionId())); + + final ZooKeeper zk2 = + createClient(qu.getPeer(index).peer.getClientPort(), watcher2); + LOG.info("zk2 has session id 0x{}", Long.toHexString(zk2.getSessionId())); + + zk1.create("/first", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + // Prepare a thread that will create znodes. + Thread mytestfooThread = new Thread(new Runnable() { + @Override + public void run() { + for (int i = 0; i < 3000; i++) { + // Here we create 3000 znodes + zk3.create("/mytestfoo", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() { + + @Override + public void processResult(int rc, String path, Object ctx, String name) { + pending.decrementAndGet(); + counter.incrementAndGet(); + if (rc != 0) { + errors.incrementAndGet(); + } + if (counter.get() == 16200) { + sem.release(); + } + } + }, null); + pending.incrementAndGet(); + if (i % 10 == 0) { + try { + Thread.sleep(100); + } catch (Exception e) { + + } + } + } + + } + }); + + // Here we start populating the server and shutdown the follower after + // initial data is written. + for (int i = 0; i < 13000; i++) { + // Here we create 13000 znodes + zk3.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() { + + @Override + public void processResult(int rc, String path, Object ctx, String name) { + pending.decrementAndGet(); + counter.incrementAndGet(); + if (rc != 0) { + errors.incrementAndGet(); + } + if (counter.get() == 16200) { + sem.release(); + } + } + }, null); + pending.incrementAndGet(); + + if (i == 5000) { + qu.shutdown(index); + LOG.info("Shutting down s1"); + } + if (i == 12000) { + // Start the prepared thread so that it is writing znodes while + // the follower is restarting. On the first restart, the follow + // should use txnlog to catchup. For subsequent restart, the + // follower should use a diff to catchup. + mytestfooThread.start(); + LOG.info("Restarting follower: {}", index); + qu.restart(index); + Thread.sleep(300); + LOG.info("Shutdown follower: {}", index); + qu.shutdown(index); + Thread.sleep(300); + LOG.info("Restarting follower: {}", index); + qu.restart(index); + LOG.info("Setting up server: {}", index); + } + if ((i % 1000) == 0) { + Thread.sleep(1000); + } + + if (i % 50 == 0) { + zk2.create("/newbaz", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() { + @Override + public void processResult(int rc, String path, Object ctx, String name) { + pending.decrementAndGet(); + counter.incrementAndGet(); + if (rc != 0) { + errors.incrementAndGet(); + } + if (counter.get() == 16200) { + sem.release(); + } + } + }, null); + pending.incrementAndGet(); + } + } + + // Wait until all updates return + if (!sem.tryAcquire(ClientBase.CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)) { + LOG.warn("Did not aquire semaphore fast enough"); + } + mytestfooThread.join(ClientBase.CONNECTION_TIMEOUT); + if (mytestfooThread.isAlive()) { + LOG.error("mytestfooThread is still alive"); + } + assertTrue(waitForPendingRequests(60)); + assertTrue(waitForSync(qu, index, 10)); + + verifyState(qu, index, leader); + + zk1.close(); + zk2.close(); + zk3.close(); + + qu.shutdownAll(); + } + + /** + * This test: + * Starts up 3 ZKs. The non-leader ZKs are writing to cluster + * Shut down one of the non-leader ZKs. + * Restart after sessions have expired but <500 txns have taken place (get a diff) + * Shut down immediately after restarting, start running separate thread with other transactions + * Restart to a diff while transactions are running in leader + * + * + * Before fixes for ZOOKEEPER-962, restarting off of diff could get an inconsistent view of data missing transactions that + * completed during diff syncing. Follower would also be considered "restarted" before all forwarded transactions + * were completely processed, so restarting would cause a snap file with a too-high zxid to be written, and transactions + * would be missed + * + * This test should pretty reliably catch the failure of restarting the server before all diff messages have been processed, + * however, due to the transient nature of the system it may not catch failures due to concurrent processing of transactions + * during the leader's diff forwarding. + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + * @throws Throwable + */ + + @Test + public void testResyncByDiffAfterFollowerCrashes() + throws IOException, InterruptedException, KeeperException, Throwable { + final Semaphore sem = new Semaphore(0); + + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + CountdownWatcher watcher1 = new CountdownWatcher(); + CountdownWatcher watcher2 = new CountdownWatcher(); + CountdownWatcher watcher3 = new CountdownWatcher(); + + int index = 1; + while (qu.getPeer(index).peer.leader == null) { + index++; + } + + Leader leader = qu.getPeer(index).peer.leader; + assertNotNull(leader); + + /* Reusing the index variable to select a follower to connect to */ + index = (index == 1) ? 2 : 1; + LOG.info("Connecting to follower: {}", index); + + final ZooKeeper zk1 = + createClient(qu.getPeer(index).peer.getClientPort(), watcher1); + LOG.info("zk1 has session id 0x{}", Long.toHexString(zk1.getSessionId())); + + final ZooKeeper zk2 = + createClient(qu.getPeer(index).peer.getClientPort(), watcher2); + LOG.info("zk2 has session id 0x{}", Long.toHexString(zk2.getSessionId())); + + final ZooKeeper zk3 = + createClient(qu.getPeer(3).peer.getClientPort(), watcher3); + LOG.info("zk3 has session id 0x{}", Long.toHexString(zk3.getSessionId())); + + zk1.create("/first", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk2.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL); + + final AtomicBoolean runNow = new AtomicBoolean(false); + Thread mytestfooThread = new Thread(new Runnable() { + + @Override + public void run() { + int inSyncCounter = 0; + while (inSyncCounter < 400) { + if (runNow.get()) { + zk3.create("/mytestfoo", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() { + + @Override + public void processResult(int rc, String path, Object ctx, String name) { + pending.decrementAndGet(); + counter.incrementAndGet(); + if (rc != 0) { + errors.incrementAndGet(); + ; + } + if (counter.get() > 7300) { + sem.release(); + } + } + }, null); + pending.incrementAndGet(); + try { + Thread.sleep(10); + } catch (Exception e) { + } + inSyncCounter++; + } else { + Thread.yield(); + } + } + + } + }); + + mytestfooThread.start(); + for (int i = 0; i < 5000; i++) { + zk2.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() { + + @Override + public void processResult(int rc, String path, Object ctx, String name) { + pending.decrementAndGet(); + counter.incrementAndGet(); + if (rc != 0) { + errors.incrementAndGet(); + ; + } + if (counter.get() > 7300) { + sem.release(); + } + } + }, null); + pending.incrementAndGet(); + if (i == 1000) { + qu.shutdown(index); + Thread.sleep(1100); + LOG.info("Shutting down s1"); + } + if (i == 1100 || i == 1150 || i == 1200) { + Thread.sleep(1000); + } + + if (i == 1200) { + qu.startThenShutdown(index); + runNow.set(true); + qu.restart(index); + LOG.info("Setting up server: {}", index); + } + + if (i >= 1000 && i % 2 == 0) { + zk3.create("/newbaz", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() { + + @Override + public void processResult(int rc, String path, Object ctx, String name) { + pending.decrementAndGet(); + counter.incrementAndGet(); + if (rc != 0) { + errors.incrementAndGet(); + } + if (counter.get() > 7300) { + sem.release(); + } + } + }, null); + pending.incrementAndGet(); + } + if (i == 1050 || i == 1100 || i == 1150) { + Thread.sleep(1000); + } + } + + // Wait until all updates return + if (!sem.tryAcquire(ClientBase.CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)) { + LOG.warn("Did not aquire semaphore fast enough"); + } + mytestfooThread.join(ClientBase.CONNECTION_TIMEOUT); + if (mytestfooThread.isAlive()) { + LOG.error("mytestfooThread is still alive"); + } + + assertTrue(waitForPendingRequests(60)); + assertTrue(waitForSync(qu, index, 10)); + // Verify that server is following and has the same epoch as the leader + + verifyState(qu, index, leader); + + zk1.close(); + zk2.close(); + zk3.close(); + + qu.shutdownAll(); + } + + /** + * Wait for all async operation to return. So we know that we can start + * verifying the state + */ + private boolean waitForPendingRequests(int timeout) throws InterruptedException { + LOG.info("Wait for pending requests: {}", pending.get()); + for (int i = 0; i < timeout; ++i) { + Thread.sleep(1000); + if (pending.get() == 0) { + return true; + } + } + LOG.info("Timeout waiting for pending requests: {}", pending.get()); + return false; + } + + /** + * Wait for all server to have the same lastProccessedZxid. Timeout in seconds + */ + private boolean waitForSync(QuorumUtil qu, int index, int timeout) throws InterruptedException { + LOG.info("Wait for server to sync"); + int leaderIndex = (index == 1) ? 2 : 1; + ZKDatabase restartedDb = qu.getPeer(index).peer.getActiveServer().getZKDatabase(); + ZKDatabase cleanDb = qu.getPeer(3).peer.getActiveServer().getZKDatabase(); + ZKDatabase leadDb = qu.getPeer(leaderIndex).peer.getActiveServer().getZKDatabase(); + long leadZxid = 0; + long cleanZxid = 0; + long restartedZxid = 0; + for (int i = 0; i < timeout; ++i) { + leadZxid = leadDb.getDataTreeLastProcessedZxid(); + cleanZxid = cleanDb.getDataTreeLastProcessedZxid(); + restartedZxid = restartedDb.getDataTreeLastProcessedZxid(); + if (leadZxid == cleanZxid && leadZxid == restartedZxid) { + return true; + } + Thread.sleep(1000); + } + LOG.info("Timeout waiting for zxid to sync: leader 0x{}" + + "clean 0x{}" + + "restarted 0x{}", Long.toHexString(leadZxid), Long.toHexString(cleanZxid), + Long.toHexString(restartedZxid)); + return false; + } + + private void verifyState(QuorumUtil qu, int index, Leader leader) { + LOG.info("Verifying state"); + assertTrue("Not following", qu.getPeer(index).peer.follower != null); + long epochF = (qu.getPeer(index).peer.getActiveServer().getZxid() >> 32L); + long epochL = (leader.getEpoch() >> 32L); + assertTrue("Zxid: " + qu.getPeer(index).peer.getActiveServer().getZKDatabase().getDataTreeLastProcessedZxid() + + "Current epoch: " + epochF, epochF == epochL); + int leaderIndex = (index == 1) ? 2 : 1; + Collection sessionsRestarted = qu.getPeer(index).peer.getActiveServer().getZKDatabase().getSessions(); + Collection sessionsNotRestarted = qu.getPeer(leaderIndex).peer.getActiveServer().getZKDatabase().getSessions(); + + for (Long l : sessionsRestarted) { + assertTrue("Should have same set of sessions in both servers, did not expect: " + l, sessionsNotRestarted.contains(l)); + } + assertEquals("Should have same number of sessions", sessionsNotRestarted.size(), sessionsRestarted.size()); + ZKDatabase restarted = qu.getPeer(index).peer.getActiveServer().getZKDatabase(); + ZKDatabase clean = qu.getPeer(3).peer.getActiveServer().getZKDatabase(); + ZKDatabase lead = qu.getPeer(leaderIndex).peer.getActiveServer().getZKDatabase(); + for (Long l : sessionsRestarted) { + LOG.info("Validating ephemeral for session id 0x{}", Long.toHexString(l)); + assertTrue("Should have same set of sessions in both servers, did not expect: " + l, sessionsNotRestarted.contains(l)); + Set ephemerals = restarted.getEphemerals(l); + Set cleanEphemerals = clean.getEphemerals(l); + for (String o : cleanEphemerals) { + if (!ephemerals.contains(o)) { + LOG.info("Restarted follower doesn't contain ephemeral {} zxid 0x{}", + o, Long.toHexString(clean.getDataTree().getNode(o).stat.getMzxid())); + } + } + for (String o : ephemerals) { + if (!cleanEphemerals.contains(o)) { + LOG.info("Restarted follower has extra ephemeral {} zxid 0x{}", + o, Long.toHexString(restarted.getDataTree().getNode(o).stat.getMzxid())); + } + } + Set leadEphemerals = lead.getEphemerals(l); + for (String o : leadEphemerals) { + if (!cleanEphemerals.contains(o)) { + LOG.info("Follower doesn't contain ephemeral from leader {} zxid 0x{}", + o, Long.toHexString(lead.getDataTree().getNode(o).stat.getMzxid())); + } + } + for (String o : cleanEphemerals) { + if (!leadEphemerals.contains(o)) { + LOG.info("Leader doesn't contain ephemeral from follower {} zxid 0x{}", + o, Long.toHexString(clean.getDataTree().getNode(o).stat.getMzxid())); + } + } + assertEquals("Should have same number of ephemerals in both followers", ephemerals.size(), cleanEphemerals.size()); + assertEquals("Leader should equal follower", lead.getEphemerals(l).size(), cleanEphemerals.size()); + } + } + + /** + * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412. + */ + @Test + public void testFollowerSendsLastZxid() throws Exception { + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + + int index = 1; + while (qu.getPeer(index).peer.follower == null) { + index++; + } + LOG.info("Connecting to follower: {}", index); + + TestableZooKeeper zk = + createTestableClient("localhost:" + qu.getPeer(index).peer.getClientPort()); + + assertEquals(0L, zk.testableLastZxid()); + zk.exists("/", false); + long lzxid = zk.testableLastZxid(); + assertTrue("lzxid:" + lzxid + " > 0", lzxid > 0); + zk.close(); + qu.shutdownAll(); + } + + /** + * Verify that the server is sending the proper zxid, and as a result + * the watch doesn't fire. See ZOOKEEPER-1412. + */ + @Test + public void testFollowerWatcherResync() throws Exception { + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + + int index = 1; + while (qu.getPeer(index).peer.follower == null) { + index++; + } + LOG.info("Connecting to follower: {}", index); + + TestableZooKeeper zk1 = createTestableClient( + "localhost:" + qu.getPeer(index).peer.getClientPort()); + zk1.create("/foo", "foo".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + MyWatcher watcher = new MyWatcher(); + TestableZooKeeper zk2 = createTestableClient(watcher, + "localhost:" + qu.getPeer(index).peer.getClientPort()); + + zk2.exists("/foo", true); + + watcher.reset(); + zk2.testableConnloss(); + if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)) { + fail("Unable to connect to server"); + } + assertArrayEquals("foo".getBytes(), zk2.getData("/foo", false, null)); + + assertNull(watcher.events.poll(5, TimeUnit.SECONDS)); + + zk1.close(); + zk2.close(); + qu.shutdownAll(); + } + + private class MyWatcher extends CountdownWatcher { + LinkedBlockingQueue events = + new LinkedBlockingQueue(); + + public void process(WatchedEvent event) { + super.process(event); + if (event.getType() != Event.EventType.None) { + try { + events.put(event); + } catch (InterruptedException e) { + LOG.warn("ignoring interrupt during event.put"); + } + } + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java b/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java new file mode 100644 index 00000000000..57c1cf34780 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java @@ -0,0 +1,110 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.common.X509Exception.SSLContextException; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord; + +public class FourLetterWordsQuorumTest extends QuorumBase { + protected static final Logger LOG = + LoggerFactory.getLogger(FourLetterWordsQuorumTest.class); + + /** Test the various four letter words */ + @Test + public void testFourLetterWords() throws Exception { + String servers[] = hostPort.split(","); + for (String hp : servers) { + verify(hp, "ruok", "imok"); + verify(hp, "envi", "java.version"); + verify(hp, "conf", "clientPort"); + verify(hp, "stat", "Outstanding"); + verify(hp, "srvr", "Outstanding"); + verify(hp, "cons", "queued"); + verify(hp, "dump", "Session"); + verify(hp, "wchs", "watches"); + verify(hp, "wchp", ""); + verify(hp, "wchc", ""); + + verify(hp, "srst", "reset"); + verify(hp, "crst", "reset"); + + verify(hp, "stat", "Outstanding"); + verify(hp, "srvr", "Outstanding"); + verify(hp, "cons", "queued"); + + TestableZooKeeper zk = createClient(hp); + String sid = getHexSessionId(zk.getSessionId()); + + verify(hp, "stat", "queued"); + verify(hp, "srvr", "Outstanding"); + verify(hp, "cons", sid); + verify(hp, "dump", sid); + verify(hp, "dirs", "size"); + + zk.getData("/", true, null); + + verify(hp, "stat", "queued"); + verify(hp, "srvr", "Outstanding"); + verify(hp, "cons", sid); + verify(hp, "dump", sid); + verify(hp, "wchs", "watching 1"); + verify(hp, "wchp", sid); + verify(hp, "wchc", sid); + verify(hp, "dirs", "size"); + + zk.close(); + + verify(hp, "ruok", "imok"); + verify(hp, "envi", "java.version"); + verify(hp, "conf", "clientPort"); + verify(hp, "stat", "Outstanding"); + verify(hp, "srvr", "Outstanding"); + verify(hp, "cons", "queued"); + verify(hp, "dump", "Session"); + verify(hp, "wchs", "watch"); + verify(hp, "wchp", ""); + verify(hp, "wchc", ""); + verify(hp, "dirs", "size"); + + verify(hp, "srst", "reset"); + verify(hp, "crst", "reset"); + + verify(hp, "stat", "Outstanding"); + verify(hp, "srvr", "Outstanding"); + verify(hp, "cons", "queued"); + + verify(hp, "mntr", "zk_version\t"); + } + } + + private void verify(String hp, String cmd, String expected) + throws IOException, SSLContextException { + for (HostPort hpobj : parseHostPortList(hp)) { + String resp = send4LetterWord(hpobj.host, hpobj.port, cmd); + LOG.info("cmd " + cmd + " expected " + expected + " got " + resp); + if (cmd.equals("dump")) { + Assert.assertTrue(resp.contains(expected) + || resp.contains("Sessions with Ephemerals")); + } else { + Assert.assertTrue(resp.contains(expected)); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java b/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java new file mode 100644 index 00000000000..12087f1e650 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java @@ -0,0 +1,238 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.IOUtils; +import org.apache.zookeeper.common.X509Exception.SSLContextException; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.StringReader; +import java.util.regex.Pattern; + +import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord; + +public class FourLetterWordsTest extends ClientBase { + protected static final Logger LOG = + LoggerFactory.getLogger(FourLetterWordsTest.class); + + @Rule + public Timeout timeout = new Timeout(30000); + + /** Test the various four letter words */ + @Test + public void testFourLetterWords() throws Exception { + verify("ruok", "imok"); + verify("envi", "java.version"); + verify("conf", "clientPort"); + verify("stat", "Outstanding"); + verify("srvr", "Outstanding"); + verify("cons", "queued"); + verify("dump", "Session"); + verify("wchs", "watches"); + verify("wchp", ""); + verify("wchc", ""); + + verify("srst", "reset"); + verify("crst", "reset"); + + verify("stat", "Outstanding"); + verify("srvr", "Outstanding"); + verify("cons", "queued"); + verify("gtmk", "306"); + verify("isro", "rw"); + + TestableZooKeeper zk = createClient(); + String sid = getHexSessionId(zk.getSessionId()); + + verify("stat", "queued"); + verify("srvr", "Outstanding"); + verify("cons", sid); + verify("dump", sid); + verify("dirs", "size"); + + zk.getData("/", true, null); + + verify("stat", "queued"); + verify("srvr", "Outstanding"); + verify("cons", sid); + verify("dump", sid); + + verify("wchs", "watching 1"); + verify("wchp", sid); + verify("wchc", sid); + verify("dirs", "size"); + zk.close(); + + verify("ruok", "imok"); + verify("envi", "java.version"); + verify("conf", "clientPort"); + verify("stat", "Outstanding"); + verify("srvr", "Outstanding"); + verify("cons", "queued"); + verify("dump", "Session"); + verify("wchs", "watch"); + verify("wchp", ""); + verify("wchc", ""); + + verify("srst", "reset"); + verify("crst", "reset"); + + verify("stat", "Outstanding"); + verify("srvr", "Outstanding"); + verify("cons", "queued"); + verify("mntr", "zk_server_state\tstandalone"); + verify("mntr", "num_alive_connections"); + verify("stat", "Connections"); + verify("srvr", "Connections"); + verify("dirs", "size"); + } + + private String sendRequest(String cmd) throws IOException, SSLContextException { + HostPort hpobj = ClientBase.parseHostPortList(hostPort).get(0); + return send4LetterWord(hpobj.host, hpobj.port, cmd); + } + + private String sendRequest(String cmd, int timeout) throws IOException, SSLContextException { + HostPort hpobj = ClientBase.parseHostPortList(hostPort).get(0); + return send4LetterWord(hpobj.host, hpobj.port, cmd, false, timeout); + } + + private void verify(String cmd, String expected) throws IOException, SSLContextException { + String resp = sendRequest(cmd); + LOG.info("cmd " + cmd + " expected " + expected + " got " + resp); + Assert.assertTrue(resp.contains(expected)); + } + + @Test + public void testValidateStatOutput() throws Exception { + ZooKeeper zk1 = createClient(); + ZooKeeper zk2 = createClient(); + + String resp = sendRequest("stat"); + BufferedReader in = new BufferedReader(new StringReader(resp)); + + String line; + // first line should be version info + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^.*\\s\\d+\\.\\d+\\.\\d+-.*$", line)); + Assert.assertTrue(Pattern.matches("^Clients:$", in.readLine())); + + int count = 0; + while ((line = in.readLine()).length() > 0) { + count++; + Assert.assertTrue(Pattern.matches("^ /.*:\\d+\\[\\d+\\]\\(queued=\\d+,recved=\\d+,sent=\\d+\\)$", line)); + } + // ensure at least the two clients we created are accounted for + Assert.assertTrue(count >= 2); + + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Latency min/avg/max: \\d+/\\d+/\\d+$", line)); + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Received: \\d+$", line)); + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Sent: \\d+$", line)); + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Connections: \\d+$", line)); + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Outstanding: \\d+$", line)); + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Zxid: 0x[\\da-fA-F]+$", line)); + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Mode: .*$", line)); + line = in.readLine(); + Assert.assertTrue(Pattern.matches("^Node count: \\d+$", line)); + + zk1.close(); + zk2.close(); + } + + @Test + public void testValidateConsOutput() throws Exception { + ZooKeeper zk1 = createClient(); + ZooKeeper zk2 = createClient(); + + String resp = sendRequest("cons"); + BufferedReader in = new BufferedReader(new StringReader(resp)); + + String line; + int count = 0; + while ((line = in.readLine()) != null && line.length() > 0) { + count++; + Assert.assertTrue(line, Pattern.matches("^ /.*:\\d+\\[\\d+\\]\\(queued=\\d+,recved=\\d+,sent=\\d+.*\\)$", line)); + } + // ensure at least the two clients we created are accounted for + Assert.assertTrue(count >= 2); + + zk1.close(); + zk2.close(); + } + + @Test(timeout = 60000) + public void testValidateSocketTimeout() throws Exception { + /** + * testing positive scenario that even with timeout parameter the + * functionality works fine + */ + String resp = sendRequest("isro", 2000); + Assert.assertTrue(resp.contains("rw")); + } + + @Test + public void testSetTraceMask() throws Exception { + String gtmkResp = sendRequest("gtmk"); + Assert.assertNotNull(gtmkResp); + gtmkResp = gtmkResp.trim(); + Assert.assertFalse(gtmkResp.isEmpty()); + long formerMask = Long.valueOf(gtmkResp); + try { + verify(buildSetTraceMaskRequest(0), "0"); + verify("gtmk", "0"); + } finally { + // Restore former value. + sendRequest(buildSetTraceMaskRequest(formerMask)); + } + } + + /** + * Builds a SetTraceMask request to be sent to the server, consisting of + * "stmk" followed by the 8-byte long representation of the trace mask. + * + * @param mask trace mask to set + * @return built request + * @throws IOException if there is an I/O error + */ + private String buildSetTraceMaskRequest(long mask) throws IOException { + ByteArrayOutputStream baos = null; + DataOutputStream dos = null; + try { + baos = new ByteArrayOutputStream(); + dos = new DataOutputStream(baos); + dos.writeBytes("stmk"); + dos.writeLong(mask); + } finally { + IOUtils.closeStream(dos); + IOUtils.closeStream(baos); + } + return new String(baos.toByteArray()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/GetChildren2Test.java b/src/java/test/org/apache/zookeeper/test/GetChildren2Test.java new file mode 100644 index 00000000000..5426a9384b8 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/GetChildren2Test.java @@ -0,0 +1,127 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class GetChildren2Test extends ClientBase { + private ZooKeeper zk; + + @Override + public void setUp() throws Exception { + super.setUp(); + + zk = createClient(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + + zk.close(); + } + + @Test + public void testChild() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + String childname = name + "/bar"; + zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + + Stat stat = new Stat(); + List s = zk.getChildren(name, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid() + 1, stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(1, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(1, stat.getNumChildren()); + Assert.assertEquals(s.size(), stat.getNumChildren()); + + s = zk.getChildren(childname, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(0, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(zk.getSessionId(), stat.getEphemeralOwner()); + Assert.assertEquals(childname.length(), stat.getDataLength()); + Assert.assertEquals(0, stat.getNumChildren()); + Assert.assertEquals(s.size(), stat.getNumChildren()); + } + + @Test + public void testChildren() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + List children = new ArrayList(); + List children_s = new ArrayList(); + + for (int i = 0; i < 10; i++) { + String childname = name + "/bar" + i; + String childname_s = "bar" + i; + children.add(childname); + children_s.add(childname_s); + } + + for (int i = 0; i < children.size(); i++) { + String childname = children.get(i); + zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + + Stat stat = new Stat(); + List s = zk.getChildren(name, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid() + i + 1, stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(i + 1, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(i + 1, stat.getNumChildren()); + Assert.assertEquals(s.size(), stat.getNumChildren()); + } + List p = zk.getChildren(name, false, null); + List c_a = children_s; + List c_b = p; + Collections.sort(c_a); + Collections.sort(c_b); + Assert.assertEquals(c_a.size(), 10); + Assert.assertEquals(c_a, c_b); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java b/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java new file mode 100644 index 00000000000..9dfd67ea5cd --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/GetProposalFromTxnTest.java @@ -0,0 +1,139 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.jute.Record; +import org.apache.log4j.Logger; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.server.util.SerializeUtils; +import org.apache.zookeeper.txn.TxnHeader; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; + +/** + * Test loading committed proposal from txnlog. Learner uses these proposals to + * catch-up with leader + */ +public class GetProposalFromTxnTest extends ZKTestCase implements Watcher { + private static final Logger LOG = Logger + .getLogger(GetProposalFromTxnTest.class); + private static final int CONNECTION_TIMEOUT = 3000; + private static final int MSG_COUNT = 2000; + private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique(); + + /** + * Test loading proposal from txnlog + * + * @throws Exception + * an exception might be thrown here + */ + @Test + public void testGetProposalFromTxn() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(100); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + + // Generate transaction so we will have some txnlog + Long[] zxids = new Long[MSG_COUNT]; + try { + String data = "data"; + byte[] bytes = data.getBytes(); + for (int i = 0; i < MSG_COUNT; i++) { + Stat stat = new Stat(); + zk.create("/invalidsnap-" + i, bytes, Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.getData("/invalidsnap-" + i, null, stat); + zxids[i] = stat.getCzxid(); + } + + } finally { + zk.close(); + } + + // shutdown and start zookeeper again + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server to shutdown", + ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + zks.startdata(); + + ZKDatabase db = zks.getZKDatabase(); + + // Set sizeLimit to be very high number, so we can pull all transactions + // from txnlog + Iterator itr = db.getProposalsFromTxnLog(zxids[0], 10000000); + + int createCount = 0; + ArrayList retrievedZxids = new ArrayList(MSG_COUNT); + + // Get zxid of create requests + while (itr.hasNext()) { + Proposal proposal = itr.next(); + TxnHeader hdr = new TxnHeader(); + Record rec = SerializeUtils.deserializeTxn( + proposal.packet.getData(), hdr); + if (hdr.getType() == OpCode.create) { + retrievedZxids.add(hdr.getZxid()); + createCount++; + } + } + + // All zxid should match what we created + Assert.assertTrue("Zxids missmatches", + Arrays.equals(zxids, retrievedZxids.toArray(new Long[0]))); + + // There should be 2000 create requests + Assert.assertTrue("create proposal count == " + MSG_COUNT, + (createCount == MSG_COUNT)); + + // We are requesting half the number of transaction from the snapshot + // this should exceed threshold (ZKDatabase.snapshotSizeFactor) + db.setSnapshotSizeFactor(0.33); + long sizeLimit = db.calculateTxnLogSizeLimit(); + + itr = db.getProposalsFromTxnLog(zxids[MSG_COUNT / 2], sizeLimit); + Assert.assertFalse("Expect empty proposal", (itr.hasNext())); + f.shutdown(); + zks.shutdown(); + } + + public void process(WatchedEvent event) { + // do nothing + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java b/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java new file mode 100644 index 00000000000..2b7ee79a71c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java @@ -0,0 +1,307 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.jmx.CommonNames; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Properties; +import java.util.Set; + +public class HierarchicalQuorumTest extends ClientBase { + private static final Logger LOG = LoggerFactory.getLogger(QuorumBase.class); + protected final ClientHammerTest cht = new ClientHammerTest(); + protected int port1; + protected int port2; + protected int port3; + protected int port4; + protected int port5; + protected int leport1; + protected int leport2; + protected int leport3; + protected int leport4; + protected int leport5; + protected int clientport1; + protected int clientport2; + protected int clientport3; + protected int clientport4; + protected int clientport5; + File s1dir, s2dir, s3dir, s4dir, s5dir; + QuorumPeer s1, s2, s3, s4, s5; + Properties qp; + + @Override + public void setUp() throws Exception { + setupTestEnv(); + + JMXEnv.setUp(); + + setUpAll(); + + port1 = PortAssignment.unique(); + port2 = PortAssignment.unique(); + port3 = PortAssignment.unique(); + port4 = PortAssignment.unique(); + port5 = PortAssignment.unique(); + leport1 = PortAssignment.unique(); + leport2 = PortAssignment.unique(); + leport3 = PortAssignment.unique(); + leport4 = PortAssignment.unique(); + leport5 = PortAssignment.unique(); + clientport1 = PortAssignment.unique(); + clientport2 = PortAssignment.unique(); + clientport3 = PortAssignment.unique(); + clientport4 = PortAssignment.unique(); + clientport5 = PortAssignment.unique(); + + hostPort = "127.0.0.1:" + clientport1 + + ",127.0.0.1:" + clientport2 + + ",127.0.0.1:" + clientport3 + + ",127.0.0.1:" + clientport4 + + ",127.0.0.1:" + clientport5; + LOG.info("Ports are: " + hostPort); + + s1dir = ClientBase.createTmpDir(); + s2dir = ClientBase.createTmpDir(); + s3dir = ClientBase.createTmpDir(); + s4dir = ClientBase.createTmpDir(); + s5dir = ClientBase.createTmpDir(); + + String config = "group.1=1:2:3\n" + + "group.2=4:5\n" + + "weight.1=1\n" + + "weight.2=1\n" + + "weight.3=1\n" + + "weight.4=0\n" + + "weight.5=0\n" + + "server.1=127.0.0.1:" + port1 + ":" + leport1 + ";" + clientport1 + "\n" + + "server.2=127.0.0.1:" + port2 + ":" + leport2 + ";" + clientport2 + "\n" + + "server.3=127.0.0.1:" + port3 + ":" + leport3 + ";" + clientport3 + "\n" + + "server.4=127.0.0.1:" + port4 + ":" + leport4 + ";" + clientport4 + "\n" + + "server.5=127.0.0.1:" + port5 + ":" + leport5 + ";" + clientport5 + "\n"; + + ByteArrayInputStream is = new ByteArrayInputStream(config.getBytes()); + this.qp = new Properties(); + + qp.load(is); + startServers(); + + cht.hostPort = hostPort; + cht.setUpAll(); + + LOG.info("Setup finished"); + } + + /** + * This method is here to keep backwards compatibility with the test code written before observers. + */ + void startServers() throws Exception { + startServers(false); + } + + /** + * Starts 5 Learners. When withObservers == false, all 5 are Followers. When withObservers == true, 3 are Followers and 2 Observers. + */ + void startServers(boolean withObservers) throws Exception { + int tickTime = 2000; + int initLimit = 3; + int syncLimit = 3; + HashMap peers = new HashMap(); + peers.put(Long.valueOf(1), new QuorumServer(1, + new InetSocketAddress("127.0.0.1", port1), + new InetSocketAddress("127.0.0.1", leport1), + new InetSocketAddress("127.0.0.1", clientport1))); + peers.put(Long.valueOf(2), new QuorumServer(2, + new InetSocketAddress("127.0.0.1", port2), + new InetSocketAddress("127.0.0.1", leport2), + new InetSocketAddress("127.0.0.1", clientport2))); + peers.put(Long.valueOf(3), new QuorumServer(3, + new InetSocketAddress("127.0.0.1", port3), + new InetSocketAddress("127.0.0.1", leport3), + new InetSocketAddress("127.0.0.1", clientport3))); + peers.put(Long.valueOf(4), new QuorumServer(4, + new InetSocketAddress("127.0.0.1", port4), + new InetSocketAddress("127.0.0.1", leport4), + new InetSocketAddress("127.0.0.1", clientport4), + withObservers ? QuorumPeer.LearnerType.OBSERVER + : QuorumPeer.LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(5), new QuorumServer(5, + new InetSocketAddress("127.0.0.1", port5), + new InetSocketAddress("127.0.0.1", leport5), + new InetSocketAddress("127.0.0.1", clientport5), + withObservers ? QuorumPeer.LearnerType.OBSERVER + : QuorumPeer.LearnerType.PARTICIPANT)); + + LOG.info("creating QuorumPeer 1 port " + clientport1); + + if (withObservers) { + qp.setProperty("server.4", "127.0.0.1:" + port4 + ":" + leport4 + ":observer" + ";" + clientport4); + qp.setProperty("server.5", "127.0.0.1:" + port5 + ":" + leport5 + ":observer" + ";" + clientport5); + } + QuorumHierarchical hq1 = new QuorumHierarchical(qp); + s1 = new QuorumPeer(peers, s1dir, s1dir, clientport1, 3, 1, tickTime, initLimit, syncLimit, hq1); + Assert.assertEquals(clientport1, s1.getClientPort()); + + LOG.info("creating QuorumPeer 2 port " + clientport2); + QuorumHierarchical hq2 = new QuorumHierarchical(qp); + s2 = new QuorumPeer(peers, s2dir, s2dir, clientport2, 3, 2, tickTime, initLimit, syncLimit, hq2); + Assert.assertEquals(clientport2, s2.getClientPort()); + + LOG.info("creating QuorumPeer 3 port " + clientport3); + QuorumHierarchical hq3 = new QuorumHierarchical(qp); + s3 = new QuorumPeer(peers, s3dir, s3dir, clientport3, 3, 3, tickTime, initLimit, syncLimit, hq3); + Assert.assertEquals(clientport3, s3.getClientPort()); + + LOG.info("creating QuorumPeer 4 port " + clientport4); + QuorumHierarchical hq4 = new QuorumHierarchical(qp); + s4 = new QuorumPeer(peers, s4dir, s4dir, clientport4, 3, 4, tickTime, initLimit, syncLimit, hq4); + if (withObservers) { + s4.setLearnerType(QuorumPeer.LearnerType.OBSERVER); + } + Assert.assertEquals(clientport4, s4.getClientPort()); + + LOG.info("creating QuorumPeer 5 port " + clientport5); + QuorumHierarchical hq5 = new QuorumHierarchical(qp); + s5 = new QuorumPeer(peers, s5dir, s5dir, clientport5, 3, 5, tickTime, initLimit, syncLimit, hq5); + if (withObservers) { + s5.setLearnerType(QuorumPeer.LearnerType.OBSERVER); + } + Assert.assertEquals(clientport5, s5.getClientPort()); + + // Observers are currently only compatible with LeaderElection + if (withObservers) { + s1.setElectionType(0); + s2.setElectionType(0); + s3.setElectionType(0); + s4.setElectionType(0); + s5.setElectionType(0); + } + + LOG.info("start QuorumPeer 1"); + s1.start(); + LOG.info("start QuorumPeer 2"); + s2.start(); + LOG.info("start QuorumPeer 3"); + s3.start(); + LOG.info("start QuorumPeer 4" + (withObservers ? "(observer)" : "")); + s4.start(); + LOG.info("start QuorumPeer 5" + (withObservers ? "(observer)" : "")); + s5.start(); + LOG.info("started QuorumPeer 5"); + + LOG.info("Closing ports " + hostPort); + for (String hp : hostPort.split(",")) { + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(hp, + CONNECTION_TIMEOUT)); + LOG.info(hp + " is accepting client connections"); + } + + // interesting to see what's there... + JMXEnv.dump(); + // make sure we have these 5 servers listed + Set ensureNames = new LinkedHashSet(); + for (int i = 1; i <= 5; i++) { + ensureNames.add("InMemoryDataTree"); + } + for (int i = 1; i <= 5; i++) { + ensureNames.add("name0=ReplicatedServer_id" + i + + ",name1=replica." + i + ",name2="); + } + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { + ensureNames.add("name0=ReplicatedServer_id" + i + + ",name1=replica." + j); + } + } + for (int i = 1; i <= 5; i++) { + ensureNames.add("name0=ReplicatedServer_id" + i); + } + JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()])); + + for (int i = 1; i <= 5; i++) { + String bean = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + i + + ",name1=replica." + i; + JMXEnv.ensureBeanAttribute(bean, "ConfigVersion"); + JMXEnv.ensureBeanAttribute(bean, "LearnerType"); + JMXEnv.ensureBeanAttribute(bean, "ClientAddress"); + JMXEnv.ensureBeanAttribute(bean, "ElectionAddress"); + JMXEnv.ensureBeanAttribute(bean, "QuorumSystemInfo"); + } + } + + @Override + public void tearDown() throws Exception { + LOG.info("TearDown started"); + cht.tearDownAll(); + + LOG.info("Shutting down server 1"); + shutdown(s1); + LOG.info("Shutting down server 2"); + shutdown(s2); + LOG.info("Shutting down server 3"); + shutdown(s3); + LOG.info("Shutting down server 4"); + shutdown(s4); + LOG.info("Shutting down server 5"); + shutdown(s5); + + for (String hp : hostPort.split(",")) { + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(hp, + ClientBase.CONNECTION_TIMEOUT)); + LOG.info(hp + " is no longer accepting client connections"); + } + + JMXEnv.tearDown(); + } + + protected void shutdown(QuorumPeer qp) { + QuorumBase.shutdown(qp); + } + + protected TestableZooKeeper createClient() + throws IOException, InterruptedException { + return createClient(hostPort); + } + + protected TestableZooKeeper createClient(String hp) + throws IOException, InterruptedException { + CountdownWatcher watcher = new CountdownWatcher(); + return createClient(watcher, hp); + } + + @Test + public void testHierarchicalQuorum() throws Throwable { + cht.runHammer(5, 10); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java b/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java new file mode 100644 index 00000000000..79bae9786c6 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java @@ -0,0 +1,226 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +/** + * This is a simple test to check the integrity of ZooKeeper servers. The client + * simply cycles through blasting changes to ZooKeeper and the checking what it + * gets back. + * + * The check is very simple. The value of the last successful read or write is + * stored in lastValue. When we issue a request, that value becomes a possible + * value. The difficulty is that when a communication error happens, the client + * doesn't know if the set actually went through. So, our invariant that we + * check for is that we always read a value that is greater than or equal to + * a value that we have previously read or set. (Each time we set a value, the + * value will be one more than the previous set.) + */ + +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Date; +import java.util.HashMap; + +public class IntegrityCheck implements Watcher, StatCallback, DataCallback { + private static final Logger LOG = LoggerFactory.getLogger(IntegrityCheck.class); + + ZooKeeper zk; + + HashMap lastValue = new HashMap(); + + int count; + + String path; + + int iteration; + + int outstanding; + + int errorCount; + + IntegrityCheck(String hostPort, String path, int count) throws + IOException { + zk = new ZooKeeper(hostPort, 30000, this); + this.path = path; + this.count = count; + } + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length < 3) { + System.err.println("USAGE: IntegrityCheck zookeeperHostPort znode #children"); + return; + } + int childrenCount = 0; + try { + childrenCount = Integer.parseInt(args[2]); + } catch (NumberFormatException e) { + e.printStackTrace(); + System.exit(1); + } + + try { + final IntegrityCheck ctest = new IntegrityCheck(args[0], args[1], childrenCount); + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + System.out.println(new Date().toString() + ": Error count = " + ctest.errorCount); + } + }); + while (true) { + try { + ctest.ensureConnected(); + ctest.run(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + System.exit(2); + } + } + + synchronized void incOutstanding() { + outstanding++; + } + + synchronized void decOutstanding() { + outstanding--; + notifyAll(); + } + + synchronized void waitOutstanding() throws InterruptedException { + while (outstanding > 0) { + wait(); + } + } + + public void run() throws InterruptedException, KeeperException { + try { + LOG.warn("Creating znodes for " + path); + doCreate(); + LOG.warn("Staring the test loop for " + path); + while (true) { + LOG.warn("Staring write cycle for " + path); + doPopulate(); + waitOutstanding(); + LOG.warn("Staring read cycle for " + path); + readAll(); + waitOutstanding(); + } + } finally { + LOG.warn("Test loop terminated for " + path); + } + } + + void readAll() { + for (int i = 0; i < count; i++) { + String cpath = path + "/" + i; + zk.getData(cpath, false, this, null); + incOutstanding(); + } + + } + + void doCreate() throws InterruptedException, KeeperException { + // create top level znode + try { + zk.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException e) { + // ignore duplicate create + } + iteration++; + byte v[] = ("" + iteration).getBytes(); + // create child znodes + for (int i = 0; i < count; i++) { + String cpath = path + "/" + i; + try { + if (i % 10 == 0) + LOG.warn("Creating znode " + cpath); + zk.create(cpath, v, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException e) { + // ignore duplicate create + } + lastValue.put(cpath, v); + } + } + + void doPopulate() { + iteration++; + byte v[] = ("" + iteration).getBytes(); + for (int i = 0; i < count; i++) { + String cpath = path + "/" + i; + zk.setData(cpath, v, -1, this, v); + incOutstanding(); + } + } + + // watcher callback + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.SyncConnected) { + synchronized (this) { + notifyAll(); + } + } + } + + synchronized void ensureConnected() { + while (zk.getState() != ZooKeeper.States.CONNECTED) { + try { + wait(); + } catch (InterruptedException e) { + return; + } + } + } + + public void processResult(int rc, String path, Object ctx, Stat stat) { + if (rc == 0) { + lastValue.put(path, (byte[]) ctx); + } + decOutstanding(); + } + + public void processResult(int rc, String path, Object ctx, byte[] data, + Stat stat) { + if (rc == 0) { + String string = new String(data); + String lastString = null; + byte[] v = lastValue.get(path); + if (v != null) { + lastString = new String(v); + } + if (lastString != null + && Integer.parseInt(string) < Integer.parseInt(lastString)) { + LOG.error("ERROR: Got " + string + " expected >= " + + lastString); + errorCount++; + } + lastValue.put(path, (byte[]) ctx); + } + decOutstanding(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java b/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java new file mode 100644 index 00000000000..c1f3629857a --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/InvalidSnapshotTest.java @@ -0,0 +1,116 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.LogFormatter; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SnapshotFormatter; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.concurrent.CountDownLatch; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class InvalidSnapshotTest extends ZKTestCase implements Watcher { + private final static Logger LOG = LoggerFactory.getLogger(InvalidSnapshotTest.class); + private static final String HOSTPORT = + "127.0.0.1:" + PortAssignment.unique(); + + private static final File testData = new File( + System.getProperty("test.data.dir", "build/test/data")); + private CountDownLatch startSignal; + + /** + * Verify the LogFormatter by running it on a known file. + */ + @Test + public void testLogFormatter() throws Exception { + File snapDir = new File(testData, "invalidsnap"); + File logfile = new File(new File(snapDir, "version-2"), "log.274"); + String[] args = {logfile.getCanonicalFile().toString()}; + LogFormatter.main(args); + } + + /** + * Verify the SnapshotFormatter by running it on a known file. + */ + @Test + public void testSnapshotFormatter() throws Exception { + File snapDir = new File(testData, "invalidsnap"); + File snapfile = new File(new File(snapDir, "version-2"), "snapshot.272"); + String[] args = {snapfile.getCanonicalFile().toString()}; + SnapshotFormatter.main(args); + } + + /** + * Verify the SnapshotFormatter by running it on a known file with one null data. + */ + @Test + public void testSnapshotFormatterWithNull() throws Exception { + File snapDir = new File(testData, "invalidsnap"); + File snapfile = new File(new File(snapDir, "version-2"), "snapshot.273"); + String[] args = {snapfile.getCanonicalFile().toString()}; + SnapshotFormatter.main(args); + } + + /** + * test the snapshot + * @throws Exception an exception could be expected + */ + @Test + public void testSnapshot() throws Exception { + File snapDir = new File(testData, "invalidsnap"); + ZooKeeperServer zks = new ZooKeeperServer(snapDir, snapDir, 3000); + SyncRequestProcessor.setSnapCount(1000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + LOG.info("starting up the zookeeper server .. waiting"); + Assert.assertTrue("waiting for server being up", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this); + try { + // we know this from the data files + // this node is the last node in the snapshot + + Assert.assertTrue(zk.exists("/9/9/8", false) != null); + } finally { + zk.close(); + } + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + ClientBase.CONNECTION_TIMEOUT)); + + } + + public void process(WatchedEvent event) { + LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath()); + if (event.getState() == KeeperState.SyncConnected + && startSignal != null && startSignal.getCount() > 0) { + startSignal.countDown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/JMXEnv.java b/src/java/test/org/apache/zookeeper/test/JMXEnv.java new file mode 100644 index 00000000000..e42798bb41e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/JMXEnv.java @@ -0,0 +1,311 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.jmx.CommonNames; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import javax.management.MBeanServer; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXConnectorServer; +import javax.management.remote.JMXConnectorServerFactory; +import javax.management.remote.JMXServiceURL; + +public class JMXEnv { + protected static final Logger LOG = LoggerFactory.getLogger(JMXEnv.class); + + private static JMXConnectorServer cs; + private static JMXConnector cc; + + public static void setUp() throws IOException { + MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer(); + + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://127.0.0.1"); + cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); + cs.start(); + + JMXServiceURL addr = cs.getAddress(); + + cc = JMXConnectorFactory.connect(addr); + } + + public static void tearDown() { + try { + if (cc != null) { + cc.close(); + } + } catch (IOException e) { + LOG.warn("Unexpected, ignoring", e); + + } + cc = null; + try { + if (cs != null) { + cs.stop(); + } + } catch (IOException e) { + LOG.warn("Unexpected, ignoring", e); + + } + cs = null; + } + + public static MBeanServerConnection conn() throws IOException { + return cc.getMBeanServerConnection(); + } + + /** + * Ensure that all of the specified names are registered. + * Note that these are components of the name, and in particular + * order matters - you want the more specific name (leafs) specified + * before their parent(s) (since names are hierarchical) + * It waits in a loop up to 60 seconds before failing if there is a + * mismatch. + * @param expectedNames + * @return + * @throws IOException + * @throws MalformedObjectNameException + */ + public static Set ensureAll(String... expectedNames) + throws IOException, InterruptedException { + Set beans; + Set found; + int nTry = 0; + do { + if (nTry++ > 0) { + Thread.sleep(100); + } + try { + beans = conn().queryNames( + new ObjectName(CommonNames.DOMAIN + ":*"), null); + } catch (MalformedObjectNameException e) { + throw new RuntimeException(e); + } + + found = new HashSet(); + for (String name : expectedNames) { + LOG.info("expect:" + name); + for (ObjectName bean : beans) { + if (bean.toString().contains(name)) { + LOG.info("found:" + name + " " + bean); + found.add(bean); + break; + } + } + beans.removeAll(found); + } + } while ((expectedNames.length != found.size()) && (nTry < 600)); + Assert.assertEquals("expected " + Arrays.toString(expectedNames), + expectedNames.length, found.size()); + return beans; + } + + /** + * Ensure that only the specified names are registered. + * Note that these are components of the name, and in particular + * order matters - you want the more specific name (leafs) specified + * before their parent(s) (since names are hierarchical) + * @param expectedNames + * @return + * @throws IOException + * @throws MalformedObjectNameException + */ + public static Set ensureOnly(String... expectedNames) + throws IOException, InterruptedException { + LOG.info("ensureOnly:" + Arrays.toString(expectedNames)); + Set beans = ensureAll(expectedNames); + for (ObjectName bean : beans) { + LOG.info("unexpected:" + bean.toString()); + } + Assert.assertEquals(0, beans.size()); + return beans; + } + + public static void ensureNone(String... expectedNames) + throws IOException, InterruptedException { + Set beans; + int nTry = 0; + boolean foundUnexpected = false; + String unexpectedName = ""; + do { + if (nTry++ > 0) { + Thread.sleep(100); + } + try { + beans = conn().queryNames( + new ObjectName(CommonNames.DOMAIN + ":*"), null); + } catch (MalformedObjectNameException e) { + throw new RuntimeException(e); + } + + foundUnexpected = false; + for (String name : expectedNames) { + for (ObjectName bean : beans) { + if (bean.toString().contains(name)) { + LOG.info("didntexpect:" + name); + foundUnexpected = true; + unexpectedName = name + " " + bean.toString(); + break; + } + } + if (foundUnexpected) { + break; + } + } + } while ((foundUnexpected) && (nTry < 600)); + if (foundUnexpected) { + LOG.info("List of all beans follows:"); + for (ObjectName bean : beans) { + LOG.info("bean:" + bean.toString()); + } + Assert.fail(unexpectedName); + } + } + + public static void dump() throws IOException { + LOG.info("JMXEnv.dump() follows"); + Set beans; + try { + beans = conn().queryNames( + new ObjectName(CommonNames.DOMAIN + ":*"), null); + } catch (MalformedObjectNameException e) { + throw new RuntimeException(e); + } + for (ObjectName bean : beans) { + LOG.info("bean:" + bean.toString()); + } + } + + /** + * Ensure that the specified parent names are registered. Note that these + * are components of the name. It waits in a loop up to 60 seconds before + * failing if there is a mismatch. This will return the beans which are not + * matched. + * + * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1858} + * + * @param expectedNames + * - expected beans + * @return the beans which are not matched with the given expected names + * + * @throws IOException + * @throws InterruptedException + */ + public static Set ensureParent(String... expectedNames) + throws IOException, InterruptedException { + LOG.info("ensureParent:" + Arrays.toString(expectedNames)); + + Set beans; + int nTry = 0; + Set found = new HashSet(); + do { + if (nTry++ > 0) { + Thread.sleep(500); + } + try { + beans = conn().queryNames( + new ObjectName(CommonNames.DOMAIN + ":*"), null); + } catch (MalformedObjectNameException e) { + throw new RuntimeException(e); + } + found.clear(); + for (String name : expectedNames) { + LOG.info("expect:" + name); + for (ObjectName bean : beans) { + // check the existence of name in bean + if (compare(bean.toString(), name)) { + LOG.info("found:" + name + " " + bean); + found.add(bean); + break; + } + } + beans.removeAll(found); + } + } while (expectedNames.length != found.size() && nTry < 120); + Assert.assertEquals("expected " + Arrays.toString(expectedNames), + expectedNames.length, found.size()); + return beans; + } + + /** + * Ensure that the specified bean name and its attribute is registered. Note + * that these are components of the name. It waits in a loop up to 60 + * seconds before failing if there is a mismatch. This will return the beans + * which are not matched. + * + * @param expectedName + * - expected bean + * @param expectedAttribute + * - expected attribute + * @return the value of the attribute + * + * @throws Exception + */ + public static Object ensureBeanAttribute(String expectedName, + String expectedAttribute) throws Exception { + String value = ""; + LOG.info("ensure bean:{}, attribute:{}", new Object[]{expectedName, + expectedAttribute}); + + Set beans; + int nTry = 0; + do { + if (nTry++ > 0) { + Thread.sleep(500); + } + try { + beans = conn().queryNames( + new ObjectName(CommonNames.DOMAIN + ":*"), null); + } catch (MalformedObjectNameException e) { + throw new RuntimeException(e); + } + LOG.info("expect:" + expectedName); + for (ObjectName bean : beans) { + // check the existence of name in bean + if (bean.toString().equals(expectedName)) { + LOG.info("found:{} {}", new Object[]{expectedName, bean}); + return conn().getAttribute(bean, expectedAttribute); + } + } + } while (nTry < 120); + Assert.fail("Failed to find bean:" + expectedName + ", attribute:" + + expectedAttribute); + return value; + } + + /** + * Comparing that the given name exists in the bean. For component beans, + * the component name will be present at the end of the bean name + * + * For example 'StandaloneServer' will present in the bean name like + * 'org.apache.ZooKeeperService:name0=StandaloneServer_port-1' + */ + private static boolean compare(String bean, String name) { + String[] names = bean.split("="); + if (names.length > 0 && names[names.length - 1].contains(name)) { + return true; + } + return false; + } +} diff --git a/src/java/test/org/apache/zookeeper/test/KeeperStateTest.java b/src/java/test/org/apache/zookeeper/test/KeeperStateTest.java new file mode 100644 index 00000000000..75544d67428 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/KeeperStateTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.junit.Assert; +import org.junit.Test; + +import java.util.EnumSet; + +public class KeeperStateTest extends ZKTestCase { + + @Test + public void testIntConversion() { + // Ensure that we can convert all valid integers to KeeperStates + EnumSet allStates = EnumSet.allOf(KeeperState.class); + + for (KeeperState as : allStates) { + Assert.assertEquals(as, KeeperState.fromInt(as.getIntValue())); + } + } + + @Test + public void testInvalidIntConversion() { + try { + KeeperState.fromInt(324142); + Assert.fail("Was able to create an invalid KeeperState via an integer"); + } catch (RuntimeException re) { + // we're good. + } + + } + + /** Validate that the deprecated constant still works. There were issues + * found with switch statements - which need compile time constants. + */ + @Test + @SuppressWarnings("deprecation") + public void testDeprecatedCodeOkInSwitch() { + int test = 1; + switch (test) { + case Code.Ok: + Assert.assertTrue(true); + break; + } + } + + /** Verify the enum works (paranoid) */ + @Test + public void testCodeOKInSwitch() { + Code test = Code.OK; + switch (test) { + case OK: + Assert.assertTrue(true); + break; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java b/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java new file mode 100644 index 00000000000..13e9435eaf8 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java @@ -0,0 +1,365 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.quorum.Election; +import org.apache.zookeeper.server.quorum.FLELostMessageTest; +import org.apache.zookeeper.server.quorum.LeaderElection; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.Vote; +import org.apache.zookeeper.server.quorum.flexible.QuorumMaj; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +@SuppressWarnings("deprecation") +public class LENonTerminateTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(FLELostMessageTest.class); + static final CountDownLatch latch = new CountDownLatch(2); + static final CountDownLatch mockLatch = new CountDownLatch(1); + int count; + HashMap peers; + File tmpdir[]; + int port[]; + + @Before + public void setUp() throws Exception { + count = 3; + + peers = new HashMap(count); + tmpdir = new File[count]; + port = new int[count]; + } + + /** + * This tests ZK-569. + * With three peers A, B and C, the following could happen: + * 1. Round 1, A,B and C all vote for themselves + * 2. Round 2, C dies, A and B vote for C + * 3. Because C has died, votes for it are ignored, but A and B never + * reset their votes. Hence LE never terminates. ZK-569 fixes this by + * resetting votes to themselves if the set of votes for live peers is null. + */ + @Test + public void testNonTermination() throws Exception { + LOG.info("TestNonTermination: " + getTestName() + ", " + count); + for (int i = 0; i < count; i++) { + int clientport = PortAssignment.unique(); + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress("127.0.0.1", clientport), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()))); + tmpdir[i] = ClientBase.createTmpDir(); + port[i] = clientport; + } + + /* + * peer1 and peer2 are A and B in the above example. + */ + QuorumPeer peer1 = new MockQuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 0, 0, 2, 2, 2); + peer1.startLeaderElection(); + LEThread thread1 = new LEThread(peer1, 0); + + QuorumPeer peer2 = new MockQuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 0, 1, 2, 2, 2); + peer2.startLeaderElection(); + LEThread thread2 = new LEThread(peer2, 1); + + /* + * Start mock server. + */ + Thread thread3 = new Thread() { + public void run() { + try { + mockServer(); + } catch (Exception e) { + LOG.error("exception", e); + Assert.fail("Exception when running mocked server " + e); + } + } + }; + + thread3.start(); + Assert.assertTrue("mockServer did not start in 5s", + mockLatch.await(5000, TimeUnit.MILLISECONDS)); + thread1.start(); + thread2.start(); + /* + * Occasionally seen false negatives with a 5s timeout. + */ + thread1.join(15000); + thread2.join(15000); + thread3.join(15000); + if (thread1.isAlive() || thread2.isAlive() || thread3.isAlive()) { + Assert.fail("Threads didn't join"); + } + } + + /** + * MockServer plays the role of peer C. Respond to two requests for votes + * with vote for self and then Assert.fail. + */ + void mockServer() throws InterruptedException, IOException { + byte b[] = new byte[36]; + ByteBuffer responseBuffer = ByteBuffer.wrap(b); + DatagramPacket packet = new DatagramPacket(b, b.length); + QuorumServer server = peers.get(Long.valueOf(2)); + DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort()); + LOG.info("In MockServer"); + mockLatch.countDown(); + Vote current = new Vote(2, 1); + for (int i = 0; i < 2; ++i) { + udpSocket.receive(packet); + responseBuffer.rewind(); + LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong()); + LOG.info("From " + packet.getSocketAddress()); + responseBuffer.clear(); + responseBuffer.getInt(); // Skip the xid + responseBuffer.putLong(2); + + responseBuffer.putLong(current.getId()); + responseBuffer.putLong(current.getZxid()); + packet.setData(b); + udpSocket.send(packet); + } + } + + public static class MockLeaderElection extends LeaderElection { + public MockLeaderElection(QuorumPeer self) { + super(self); + } + + /** + * Temporary for 3.3.0 - we want to ensure that a round of voting happens + * before any of the peers update their votes. The easiest way to do that + * is to add a latch that all wait on after counting their votes. + * + * In 3.4.0 we intend to make this class more testable, and therefore + * there should be much less duplicated code. + * + * JMX bean method calls are removed to reduce noise. + */ + public Vote lookForLeader() throws InterruptedException { + self.setCurrentVote(new Vote(self.getId(), + self.getLastLoggedZxid())); + // We are going to look for a leader by casting a vote for ourself + byte requestBytes[] = new byte[4]; + ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); + byte responseBytes[] = new byte[28]; + ByteBuffer responseBuffer = ByteBuffer.wrap(responseBytes); + /* The current vote for the leader. Initially me! */ + DatagramSocket s = null; + try { + s = new DatagramSocket(); + s.setSoTimeout(200); + } catch (SocketException e1) { + LOG.error("Socket exception when creating socket for leader election", e1); + System.exit(4); + } + DatagramPacket requestPacket = new DatagramPacket(requestBytes, + requestBytes.length); + DatagramPacket responsePacket = new DatagramPacket(responseBytes, + responseBytes.length); + int xid = epochGen.nextInt(); + while (self.isRunning()) { + HashMap votes = + new HashMap(self.getVotingView().size()); + + requestBuffer.clear(); + requestBuffer.putInt(xid); + requestPacket.setLength(4); + HashSet heardFrom = new HashSet(); + for (QuorumServer server : + self.getVotingView().values()) { + LOG.info("Server address: " + server.addr); + try { + requestPacket.setSocketAddress(server.addr); + } catch (IllegalArgumentException e) { + // Sun doesn't include the address that causes this + // exception to be thrown, so we wrap the exception + // in order to capture this critical detail. + throw new IllegalArgumentException( + "Unable to set socket address on packet, msg:" + + e.getMessage() + " with addr:" + server.addr, + e); + } + + try { + s.send(requestPacket); + responsePacket.setLength(responseBytes.length); + s.receive(responsePacket); + if (responsePacket.getLength() != responseBytes.length) { + LOG.error("Got a short response: " + + responsePacket.getLength()); + continue; + } + responseBuffer.clear(); + int recvedXid = responseBuffer.getInt(); + if (recvedXid != xid) { + LOG.error("Got bad xid: expected " + xid + + " got " + recvedXid); + continue; + } + long peerId = responseBuffer.getLong(); + heardFrom.add(peerId); + //if(server.id != peerId){ + Vote vote = new Vote(responseBuffer.getLong(), + responseBuffer.getLong()); + InetSocketAddress addr = + (InetSocketAddress) responsePacket + .getSocketAddress(); + votes.put(addr, vote); + //} + } catch (IOException e) { + LOG.warn("Ignoring exception while looking for leader", + e); + // Errors are okay, since hosts may be + // down + } + } + + ElectionResult result = countVotes(votes, heardFrom); + + /** + * This is the only difference from LeaderElection - wait for + * this latch on the first time through this method. This ensures + * that the first round of voting happens before setCurrentVote + * is called below. + */ + LOG.info("Waiting for first round of voting to complete"); + latch.countDown(); + Assert.assertTrue("Thread timed out waiting for latch", + latch.await(10000, TimeUnit.MILLISECONDS)); + + // ZOOKEEPER-569: + // If no votes are received for live peers, reset to voting + // for ourselves as otherwise we may hang on to a vote + // for a dead peer + if (result.numValidVotes == 0) { + self.setCurrentVote(new Vote(self.getId(), + self.getLastLoggedZxid())); + } else { + if (result.winner.getId() >= 0) { + self.setCurrentVote(result.vote); + // To do: this doesn't use a quorum verifier + if (result.winningCount > (self.getVotingView().size() / 2)) { + self.setCurrentVote(result.winner); + s.close(); + Vote current = self.getCurrentVote(); + LOG.info("Found leader: my type is: " + self.getLearnerType()); + /* + * We want to make sure we implement the state machine + * correctly. If we are a PARTICIPANT, once a leader + * is elected we can move either to LEADING or + * FOLLOWING. However if we are an OBSERVER, it is an + * error to be elected as a Leader. + */ + if (self.getLearnerType() == LearnerType.OBSERVER) { + if (current.getId() == self.getId()) { + // This should never happen! + LOG.error("OBSERVER elected as leader!"); + Thread.sleep(100); + } else { + self.setPeerState(ServerState.OBSERVING); + Thread.sleep(100); + return current; + } + } else { + self.setPeerState((current.getId() == self.getId()) + ? ServerState.LEADING : ServerState.FOLLOWING); + if (self.getPeerState() == ServerState.FOLLOWING) { + Thread.sleep(100); + } + return current; + } + } + } + } + Thread.sleep(1000); + } + return null; + } + } + + public static class MockQuorumPeer extends QuorumPeer { + public MockQuorumPeer(Map quorumPeers, File snapDir, + File logDir, int clientPort, int electionAlg, + long myid, int tickTime, int initLimit, int syncLimit) + throws IOException { + super(quorumPeers, snapDir, logDir, electionAlg, + myid, tickTime, initLimit, syncLimit, false, + ServerCnxnFactory.createFactory(clientPort, -1), + new QuorumMaj(quorumPeers)); + } + + protected Election createElectionAlgorithm(int electionAlgorithm) { + LOG.info("Returning mocked leader election"); + return new MockLeaderElection(this); + } + } + + private static class LEThread extends Thread { + private int i; + private QuorumPeer peer; + + LEThread(QuorumPeer peer, int i) { + this.i = i; + this.peer = peer; + LOG.info("Constructor: " + getName()); + + } + + public void run() { + try { + Vote v = null; + peer.setPeerState(ServerState.LOOKING); + LOG.info("Going to call leader election: " + i); + v = peer.getElectionAlg().lookForLeader(); + + if (v == null) { + Assert.fail("Thread " + i + " got a null vote"); + } + + /* + * A real zookeeper would take care of setting the current vote. Here + * we do it manually. + */ + peer.setCurrentVote(v); + + LOG.info("Finished election: " + i + ", " + v.getId()); + } catch (Exception e) { + e.printStackTrace(); + } + LOG.info("Joining"); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/LETest.java b/src/java/test/org/apache/zookeeper/test/LETest.java new file mode 100644 index 00000000000..a0b576d63e6 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/LETest.java @@ -0,0 +1,136 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.LeaderElection; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.Vote; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Random; + +@SuppressWarnings("deprecation") +public class LETest extends ZKTestCase { + private static final Logger LOG = LoggerFactory.getLogger(LETest.class); + volatile Vote votes[]; + volatile boolean leaderDies; + volatile long leader = -1; + Random rand = new Random(); + + @Test + public void testLE() throws Exception { + int count = 30; + HashMap peers = new HashMap(count); + ArrayList threads = new ArrayList(count); + File tmpdir[] = new File[count]; + int port[] = new int[count]; + votes = new Vote[count]; + for (int i = 0; i < count; i++) { + peers.put(Long.valueOf(i), + new QuorumServer(i, + new InetSocketAddress("127.0.0.1", + PortAssignment.unique()))); + tmpdir[i] = ClientBase.createTmpDir(); + port[i] = PortAssignment.unique(); + } + LeaderElection le[] = new LeaderElection[count]; + leaderDies = true; + boolean allowOneBadLeader = leaderDies; + for (int i = 0; i < le.length; i++) { + QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], + port[i], 0, i, 1000, 2, 2); + peer.startLeaderElection(); + le[i] = new LeaderElection(peer); + LEThread thread = new LEThread(le[i], peer, i); + thread.start(); + threads.add(thread); + } + for (int i = 0; i < threads.size(); i++) { + threads.get(i).join(15000); + if (threads.get(i).isAlive()) { + Assert.fail("Threads didn't join"); + } + } + long id = votes[0].getId(); + for (int i = 1; i < votes.length; i++) { + if (votes[i] == null) { + Assert.fail("Thread " + i + " had a null vote"); + } + if (votes[i].getId() != id) { + if (allowOneBadLeader && votes[i].getId() == i) { + allowOneBadLeader = false; + } else { + Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id); + } + } + } + } + + class LEThread extends Thread { + LeaderElection le; + int i; + QuorumPeer peer; + + LEThread(LeaderElection le, QuorumPeer peer, int i) { + this.le = le; + this.i = i; + this.peer = peer; + } + + public void run() { + try { + Vote v = null; + while (true) { + v = le.lookForLeader(); + votes[i] = v; + if (v.getId() == i) { + synchronized (LETest.this) { + if (leaderDies) { + leaderDies = false; + peer.stopLeaderElection(); + LOG.info("Leader " + i + " dying"); + leader = -2; + } else { + leader = i; + } + LETest.this.notifyAll(); + } + break; + } + synchronized (LETest.this) { + if (leader == -1) { + LETest.this.wait(); + } + if (leader == v.getId()) { + break; + } + } + Thread.sleep(rand.nextInt(1000)); + peer.setCurrentVote(new Vote(peer.getId(), 0)); + } + LOG.info("Thread " + i + " votes " + v); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java b/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java new file mode 100644 index 00000000000..dc7a314811f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/LeaderSessionTrackerTest.java @@ -0,0 +1,166 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Id; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +/** + * Due to race condition or bad client code, the leader may get request from + * expired session. We need to make sure that we never allow ephmeral node + * to be created in those case, but we do allow normal node to be created. + */ +public class LeaderSessionTrackerTest extends ZKTestCase implements Watcher { + + protected static final Logger LOG = LoggerFactory + .getLogger(LeaderSessionTrackerTest.class); + + QuorumUtil qu; + + @Before + public void setUp() throws Exception { + qu = new QuorumUtil(1); + } + + @After + public void tearDown() throws Exception { + qu.shutdownAll(); + } + + @Test + public void testExpiredSessionWithLocalSession() throws Exception { + testCreateEphemeral(true); + } + + @Test + public void testExpiredSessionWithoutLocalSession() throws Exception { + testCreateEphemeral(false); + } + + /** + * When we create ephemeral node, we need to check against global + * session, so the leader never accept request from an expired session + * (that we no longer track) + * + * This is not the same as SessionInvalidationTest since session + * is not in closing state + */ + public void testCreateEphemeral(boolean localSessionEnabled) throws Exception { + if (localSessionEnabled) { + qu.enableLocalSession(true); + } + qu.startAll(); + QuorumPeer leader = qu.getLeaderQuorumPeer(); + + ZooKeeper zk = new ZooKeeper(qu.getConnectString(leader), + CONNECTION_TIMEOUT, this); + + CreateRequest createRequest = new CreateRequest("/impossible", + new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + createRequest.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + + // Mimic sessionId generated by follower's local session tracker + long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer() + .getServerId(); + long fakeSessionId = (sid << 56) + 1; + + LOG.info("Fake session Id: " + Long.toHexString(fakeSessionId)); + + Request request = new Request(null, fakeSessionId, 0, OpCode.create, + bb, new ArrayList()); + + // Submit request directly to leader + leader.getActiveServer().submitRequest(request); + + // Make sure that previous request is finished + zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + Stat stat = zk.exists("/impossible", null); + Assert.assertEquals("Node from fake session get created", null, stat); + + } + + /** + * When local session is enabled, leader will allow persistent node + * to be create for unknown session + */ + @Test + public void testCreatePersistent() throws Exception { + qu.enableLocalSession(true); + qu.startAll(); + + QuorumPeer leader = qu.getLeaderQuorumPeer(); + + ZooKeeper zk = new ZooKeeper(qu.getConnectString(leader), + CONNECTION_TIMEOUT, this); + + CreateRequest createRequest = new CreateRequest("/success", + new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT.toFlag()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + createRequest.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + + // Mimic sessionId generated by follower's local session tracker + long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer() + .getServerId(); + long locallSession = (sid << 56) + 1; + + LOG.info("Local session Id: " + Long.toHexString(locallSession)); + + Request request = new Request(null, locallSession, 0, OpCode.create, + bb, new ArrayList()); + + // Submit request directly to leader + leader.getActiveServer().submitRequest(request); + + // Make sure that previous request is finished + zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + Stat stat = zk.exists("/success", null); + Assert.assertTrue("Request from local sesson failed", stat != null); + + } + + @Override + public void process(WatchedEvent event) { + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java b/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java new file mode 100644 index 00000000000..5936f444216 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java @@ -0,0 +1,580 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.DataNode; +import org.apache.zookeeper.server.DataTree; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.persistence.FileHeader; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.server.persistence.FileTxnLog.FileTxnIterator; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; +import org.apache.zookeeper.server.persistence.Util; +import org.apache.zookeeper.txn.CreateTxn; +import org.apache.zookeeper.txn.DeleteTxn; +import org.apache.zookeeper.txn.MultiTxn; +import org.apache.zookeeper.txn.Txn; +import org.apache.zookeeper.txn.TxnHeader; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +public class LoadFromLogTest extends ZKTestCase implements Watcher { + protected static final Logger LOG = LoggerFactory.getLogger(LoadFromLogTest.class); + private static final int CONNECTION_TIMEOUT = 3000; + private static final int NUM_MESSAGES = 300; + // setting up the quorum has a transaction overhead for creating and closing the session + private static final int TRANSACTION_OVERHEAD = 2; + private static final int TOTAL_TRANSACTIONS = NUM_MESSAGES + TRANSACTION_OVERHEAD; + private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique(); + private volatile boolean connected; + + /** + * test that all transactions from the Log are loaded, and only once + * @throws Exception an exception might be thrown here + */ + @Test + public void testLoad() throws Exception { + // setup a single server cluster + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(100); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + + // generate some transactions that will get logged + try { + for (int i = 0; i < NUM_MESSAGES; i++) { + zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + } finally { + zk.close(); + } + f.shutdown(); + Assert.assertTrue("waiting for server to shutdown", + ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + + // now verify that the FileTxnLog reads every transaction only once + File logDir = new File(tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION); + FileTxnLog txnLog = new FileTxnLog(logDir); + + TxnIterator itr = txnLog.read(0); + + // Check that storage space return some value + FileTxnIterator fileItr = (FileTxnIterator) itr; + long storageSize = fileItr.getStorageSize(); + LOG.info("Txnlog size: " + storageSize + " bytes"); + Assert.assertTrue("Storage size is greater than zero ", + (storageSize > 0)); + + long expectedZxid = 0; + long lastZxid = 0; + TxnHeader hdr; + do { + hdr = itr.getHeader(); + expectedZxid++; + Assert.assertTrue("not the same transaction. lastZxid=" + lastZxid + ", zxid=" + hdr.getZxid(), lastZxid != hdr.getZxid()); + Assert.assertTrue("excepting next transaction. expected=" + expectedZxid + ", retreived=" + hdr.getZxid(), (hdr.getZxid() == expectedZxid)); + lastZxid = hdr.getZxid(); + } while (itr.next()); + + Assert.assertTrue("processed all transactions. " + expectedZxid + " == " + TOTAL_TRANSACTIONS, (expectedZxid == TOTAL_TRANSACTIONS)); + zks.shutdown(); + } + + /** + * test that we fail to load txnlog of a request zxid that is older + * than what exist on disk + * @throws Exception an exception might be thrown here + */ + @Test + public void testLoadFailure() throws Exception { + // setup a single server cluster + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + // So we have at least 4 logs + SyncRequestProcessor.setSnapCount(50); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + + // generate some transactions that will get logged + try { + for (int i = 0; i < NUM_MESSAGES; i++) { + zk.create("/data-", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL); + } + } finally { + zk.close(); + } + f.shutdown(); + Assert.assertTrue("waiting for server to shutdown", + ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + + File logDir = new File(tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION); + File[] logFiles = FileTxnLog.getLogFiles(logDir.listFiles(), 0); + // Verify that we have at least 4 txnlog + Assert.assertTrue(logFiles.length > 4); + // Delete the first log file, so we will fail to read it back from disk + Assert.assertTrue("delete the first log file", logFiles[0].delete()); + + // Find zxid for the second log + long secondStartZxid = Util.getZxidFromName(logFiles[1].getName(), "log"); + + FileTxnLog txnLog = new FileTxnLog(logDir); + TxnIterator itr = txnLog.read(1, false); + + // Oldest log is already remove, so this should point to the start of + // of zxid on the second log + Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid()); + + itr = txnLog.read(secondStartZxid, false); + Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid()); + Assert.assertTrue(itr.next()); + + // Trying to get a second txn on second txnlog give us the + // the start of second log, since the first one is removed + long nextZxid = itr.getHeader().getZxid(); + + itr = txnLog.read(nextZxid, false); + Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid()); + + // Trying to get a first txn on the third give us the + // the start of second log, since the first one is removed + long thirdStartZxid = Util.getZxidFromName(logFiles[2].getName(), "log"); + itr = txnLog.read(thirdStartZxid, false); + Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid()); + Assert.assertTrue(itr.next()); + + nextZxid = itr.getHeader().getZxid(); + itr = txnLog.read(nextZxid, false); + Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid()); + + } + + public void process(WatchedEvent event) { + switch (event.getType()) { + case None: + switch (event.getState()) { + case SyncConnected: + connected = true; + break; + case Disconnected: + connected = false; + break; + default: + break; + } + break; + default: + break; + } + } + + /** + * For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented + * after create/delete failure during restore. + */ + @Test + public void testTxnFailure() throws Exception { + long count = 1; + File tmpDir = ClientBase.createTmpDir(); + FileTxnSnapLog logFile = new FileTxnSnapLog(tmpDir, tmpDir); + DataTree dt = new DataTree(); + dt.createNode("/test", new byte[0], null, 0, -1, 1, 1); + for (count = 1; count <= 3; count++) { + dt.createNode("/test/" + count, new byte[0], null, 0, -1, count, + Time.currentElapsedTime()); + } + DataNode zk = dt.getNode("/test"); + + // Make create to fail, then verify cversion. + LOG.info("Attempting to create " + "/test/" + (count - 1)); + doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk, -1); + + LOG.info("Attempting to create " + "/test/" + (count - 1)); + doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk, + zk.stat.getCversion() + 1); + + LOG.info("Attempting to create " + "/test/" + (count - 1)); + doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk, + zk.stat.getCversion() + 1); + + LOG.info("Attempting to create " + "/test/" + (count - 1)); + doOp(logFile, OpCode.multi, "/test/" + (count - 1), dt, zk, + -1); + + // Make delete fo fail, then verify cversion. + // this doesn't happen anymore, we only set the cversion on create + // LOG.info("Attempting to delete " + "/test/" + (count + 1)); + // doOp(logFile, OpCode.delete, "/test/" + (count + 1), dt, zk); + } + + /* + * Does create/delete depending on the type and verifies + * if cversion before the operation is 1 less than cversion afer. + */ + private void doOp(FileTxnSnapLog logFile, int type, String path, + DataTree dt, DataNode parent, int cversion) throws Exception { + int lastSlash = path.lastIndexOf('/'); + String parentName = path.substring(0, lastSlash); + + int prevCversion = parent.stat.getCversion(); + long prevPzxid = parent.stat.getPzxid(); + List child = dt.getChildren(parentName, null, null); + StringBuilder childStr = new StringBuilder(); + for (String s : child) { + childStr.append(s).append(" "); + } + LOG.info("Children: " + childStr + " for " + parentName); + LOG.info("(cverions, pzxid): " + prevCversion + ", " + prevPzxid); + + Record txn = null; + TxnHeader txnHeader = null; + if (type == OpCode.delete) { + txn = new DeleteTxn(path); + txnHeader = new TxnHeader(0xabcd, 0x123, prevPzxid + 1, + Time.currentElapsedTime(), OpCode.delete); + } else if (type == OpCode.create) { + txnHeader = new TxnHeader(0xabcd, 0x123, prevPzxid + 1, + Time.currentElapsedTime(), OpCode.create); + txn = new CreateTxn(path, new byte[0], null, false, cversion); + } else if (type == OpCode.multi) { + txnHeader = new TxnHeader(0xabcd, 0x123, prevPzxid + 1, + Time.currentElapsedTime(), OpCode.create); + txn = new CreateTxn(path, new byte[0], null, false, cversion); + ArrayList txnList = new ArrayList(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + txn.serialize(boa, "request"); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + Txn txact = new Txn(OpCode.create, bb.array()); + txnList.add(txact); + txn = new MultiTxn(txnList); + txnHeader = new TxnHeader(0xabcd, 0x123, prevPzxid + 1, + Time.currentElapsedTime(), OpCode.multi); + } + logFile.processTransaction(txnHeader, dt, null, txn); + + int newCversion = parent.stat.getCversion(); + long newPzxid = parent.stat.getPzxid(); + child = dt.getChildren(parentName, null, null); + childStr = new StringBuilder(); + for (String s : child) { + childStr.append(s).append(" "); + } + LOG.info("Children: " + childStr + " for " + parentName); + LOG.info("(cverions, pzxid): " + newCversion + ", " + newPzxid); + Assert.assertTrue(type + " verification failed. Expected: <" + + (prevCversion + 1) + ", " + (prevPzxid + 1) + ">, found: <" + + newCversion + ", " + newPzxid + ">", + (newCversion == prevCversion + 1 && newPzxid == prevPzxid + 1)); + } + + /** + * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile + * fixes it. + */ + @Test + public void testPad() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + FileTxnLog txnLog = new FileTxnLog(tmpDir); + TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123, + Time.currentElapsedTime(), OpCode.create); + Record txn = new CreateTxn("/Test", new byte[0], null, false, 1); + txnLog.append(txnHeader, txn); + FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." + + Long.toHexString(txnHeader.getZxid())); + BinaryInputArchive ia = BinaryInputArchive.getArchive(in); + FileHeader header = new FileHeader(); + header.deserialize(ia, "fileheader"); + LOG.info("Received magic : " + header.getMagic() + + " Expected : " + FileTxnLog.TXNLOG_MAGIC); + Assert.assertTrue("Missing magic number ", + header.getMagic() == FileTxnLog.TXNLOG_MAGIC); + } + + /** + * Test we can restore the snapshot that has data ahead of the zxid + * of the snapshot file. + */ + @Test + public void testRestore() throws Exception { + // setup a single server cluster + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(10000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", ClientBase + .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = getConnectedZkClient(); + + // generate some transactions + String lastPath = null; + try { + zk.create("/invalidsnap", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + for (int i = 0; i < NUM_MESSAGES; i++) { + lastPath = zk.create("/invalidsnap/test-", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + } + } finally { + zk.close(); + } + String[] tokens = lastPath.split("-"); + String expectedPath = "/invalidsnap/test-" + + String.format("%010d", + (new Integer(tokens[1])).intValue() + 1); + long eZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); + // force the zxid to be behind the content + zks.getZKDatabase().setlastProcessedZxid( + zks.getZKDatabase().getDataTreeLastProcessedZxid() - 10); + LOG.info("Set lastProcessedZxid to " + + zks.getZKDatabase().getDataTreeLastProcessedZxid()); + // Force snapshot and restore + zks.takeSnapshot(); + zks.shutdown(); + f.shutdown(); + + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(10000); + f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", ClientBase + .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + connected = false; + long fZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); + + // Verify lastProcessedZxid is set correctly + Assert.assertTrue("Restore failed expected zxid=" + eZxid + " found=" + + fZxid, fZxid == eZxid); + zk = getConnectedZkClient(); + + // Verify correctness of data and whether sequential znode creation + // proceeds correctly after this point + String[] children; + String path; + try { + children = zk.getChildren("/invalidsnap", false).toArray( + new String[0]); + path = zk.create("/invalidsnap/test-", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + } finally { + zk.close(); + } + LOG.info("Expected " + expectedPath + " found " + path); + Assert.assertTrue("Error in sequential znode creation expected " + + expectedPath + " found " + path, path.equals(expectedPath)); + Assert.assertTrue("Unexpected number of children " + children.length + + " expected " + NUM_MESSAGES, + (children.length == NUM_MESSAGES)); + f.shutdown(); + zks.shutdown(); + } + + /** + * Test we can restore a snapshot that has errors and data ahead of the zxid + * of the snapshot file. + */ + @Test + public void testRestoreWithTransactionErrors() throws Exception { + // setup a single server cluster + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(10000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", ClientBase + .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = getConnectedZkClient(); + + // generate some transactions + try { + for (int i = 0; i < NUM_MESSAGES; i++) { + try { + zk.create("/invaliddir/test-", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + } catch (NoNodeException e) { + //Expected + } + } + } finally { + zk.close(); + } + + // force the zxid to be behind the content + zks.getZKDatabase().setlastProcessedZxid( + zks.getZKDatabase().getDataTreeLastProcessedZxid() - 10); + LOG.info("Set lastProcessedZxid to " + + zks.getZKDatabase().getDataTreeLastProcessedZxid()); + + // Force snapshot and restore + zks.takeSnapshot(); + zks.shutdown(); + f.shutdown(); + + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(10000); + f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", ClientBase + .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + + f.shutdown(); + zks.shutdown(); + } + + /** + * Verify snap/log dir create with/without autocreate enabled. + */ + @Test + public void testDatadirAutocreate() throws Exception { + ClientBase.setupTestEnv(); + + // first verify the default (autocreate on) works + File tmpDir = ClientBase.createTmpDir(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", ClientBase + .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + zks.shutdown(); + f.shutdown(); + Assert.assertTrue("waiting for server being down ", ClientBase + .waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + + try { + // now verify autocreate off works + System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, "false"); + + tmpDir = ClientBase.createTmpDir(); + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", ClientBase + .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + + Assert.fail("Server should not have started without datadir"); + } catch (IOException e) { + LOG.info("Server failed to start - correct behavior " + e); + } finally { + System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, + FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE_DEFAULT); + } + } + + /** + * ZOOKEEPER-1573: test restoring a snapshot with deleted txns ahead of the + * snapshot file's zxid. + */ + @Test + public void testReloadSnapshotWithMissingParent() throws Exception { + // setup a single server cluster + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(10000); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = getConnectedZkClient(); + + // create transactions to create the snapshot with create/delete pattern + zk.create("/a", "".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Stat stat = zk.exists("/a", false); + long createZxId = stat.getMzxid(); + zk.create("/a/b", "".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.delete("/a/b", -1); + zk.delete("/a", -1); + // force the zxid to be behind the content + zks.getZKDatabase().setlastProcessedZxid(createZxId); + LOG.info("Set lastProcessedZxid to {}", zks.getZKDatabase() + .getDataTreeLastProcessedZxid()); + // Force snapshot and restore + zks.takeSnapshot(); + zks.shutdown(); + f.shutdown(); + + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(10000); + f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + f.shutdown(); + } + + private ZooKeeper getConnectedZkClient() throws IOException { + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + + long start = Time.currentElapsedTime(); + while (!connected) { + long end = Time.currentElapsedTime(); + if (end - start > 5000) { + Assert.assertTrue("Could not connect with server in 5 seconds", + false); + } + try { + Thread.sleep(200); + } catch (Exception e) { + LOG.warn("Interrupted"); + } + } + return zk; + } +} diff --git a/src/java/test/org/apache/zookeeper/test/LocalSessionRequestTest.java b/src/java/test/org/apache/zookeeper/test/LocalSessionRequestTest.java new file mode 100644 index 00000000000..049582a877e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/LocalSessionRequestTest.java @@ -0,0 +1,140 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.TraceFormatter; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Validate that open/close session request of a local session to not propagate + * to other machines in the quorum. We verify this by checking that + * these request doesn't show up in committedLog on other machines. + */ +public class LocalSessionRequestTest extends ZKTestCase { + // Need to be short since we need to wait for session to expire + public static final int CONNECTION_TIMEOUT = 4000; + protected static final Logger LOG = LoggerFactory + .getLogger(LocalSessionRequestTest.class); + private final QuorumBase qb = new QuorumBase(); + + @Before + public void setUp() throws Exception { + LOG.info("STARTING quorum " + getClass().getName()); + qb.localSessionsEnabled = true; + qb.localSessionsUpgradingEnabled = true; + qb.setUp(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + } + + @After + public void tearDown() throws Exception { + LOG.info("STOPPING quorum " + getClass().getName()); + qb.tearDown(); + } + + @Test + public void testLocalSessionsOnFollower() throws Exception { + testOpenCloseSession(false); + } + + @Test + public void testLocalSessionsOnLeader() throws Exception { + testOpenCloseSession(true); + } + + /** + * Walk through the target peer commmittedLog. + * @param sessionId + * @param peerId + */ + private void validateRequestLog(long sessionId, int peerId) { + String session = Long.toHexString(sessionId); + LOG.info("Searching for txn of session 0x " + session + + " on peer " + peerId); + String peerType = peerId == qb.getLeaderIndex() ? "leader" : "follower"; + QuorumPeer peer = qb.getPeerList().get(peerId); + ZKDatabase db = peer.getActiveServer().getZKDatabase(); + for (Proposal p : db.getCommittedLog()) { + Assert.assertFalse("Should not see " + + TraceFormatter.op2String(p.request.type) + + " request from local session 0x" + session + + " on the " + peerType, + p.request.sessionId == sessionId); + } + } + + /** + * Test that a CloseSession request generated by both the server (client + * disconnect) or by the client (client explicitly issue close()) doesn't + * get committed by the ensemble + */ + public void testOpenCloseSession(boolean onLeader) throws Exception { + int leaderIdx = qb.getLeaderIndex(); + Assert.assertFalse("No leader in quorum?", leaderIdx == -1); + int followerIdx = (leaderIdx + 1) % 5; + int testPeerIdx = onLeader ? leaderIdx : followerIdx; + int verifyPeerIdx = onLeader ? followerIdx : leaderIdx; + + String hostPorts[] = qb.hostPort.split(","); + + CountdownWatcher watcher = new CountdownWatcher(); + DisconnectableZooKeeper client = new DisconnectableZooKeeper( + hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + long localSessionId1 = client.getSessionId(); + + // Cut the connection, so the server will create closeSession as part + // of expiring the session. + client.dontReconnect(); + client.disconnect(); + watcher.reset(); + + // We don't validate right away, will do another session create first + + ZooKeeper zk = qb.createClient(watcher, hostPorts[testPeerIdx], + CONNECTION_TIMEOUT); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + long localSessionId2 = zk.getSessionId(); + + // Send closeSession request. + zk.close(); + watcher.reset(); + + // This should be enough time for the first session to expire and for + // the closeSession request to propagate to other machines (if there is a bug) + // Since it is time sensitive, we have false negative when test + // machine is under load + Thread.sleep(CONNECTION_TIMEOUT * 2); + + // Validate that we don't see any txn from the first session + validateRequestLog(localSessionId1, verifyPeerIdx); + + // Validate that we don't see any txn from the second session + validateRequestLog(localSessionId2, verifyPeerIdx); + + qb.shutdownServers(); + + } +} diff --git a/src/java/test/org/apache/zookeeper/test/LocalSessionsOnlyTest.java b/src/java/test/org/apache/zookeeper/test/LocalSessionsOnlyTest.java new file mode 100644 index 00000000000..8f4d77ef9cf --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/LocalSessionsOnlyTest.java @@ -0,0 +1,129 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map.Entry; + +/** + * Tests learners configured to use local sessions only. Expected + * behavior is that sessions created on the learner will never be + * made global. Operations requiring a global session (e.g. + * creation of ephemeral nodes) will fail with an error. + */ +public class LocalSessionsOnlyTest extends ZKTestCase { + public static final int CONNECTION_TIMEOUT = ClientBase.CONNECTION_TIMEOUT; + protected static final Logger LOG = LoggerFactory + .getLogger(LocalSessionsOnlyTest.class); + private final QuorumBase qb = new QuorumBase(); + + @Before + public void setUp() throws Exception { + LOG.info("STARTING quorum " + getClass().getName()); + qb.localSessionsEnabled = true; + qb.localSessionsUpgradingEnabled = false; + qb.setUp(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + } + + @After + public void tearDown() throws Exception { + LOG.info("STOPPING quorum " + getClass().getName()); + qb.tearDown(); + } + + @Test + public void testLocalSessionsOnFollower() throws Exception { + testLocalSessions(false); + } + + @Test + public void testLocalSessionsOnLeader() throws Exception { + testLocalSessions(true); + } + + private void testLocalSessions(boolean testLeader) throws Exception { + String nodePrefix = "/testLocalSessions-" + + (testLeader ? "leaderTest-" : "followerTest-"); + int leaderIdx = qb.getLeaderIndex(); + Assert.assertFalse("No leader in quorum?", leaderIdx == -1); + int followerIdx = (leaderIdx + 1) % 5; + int testPeerIdx = testLeader ? leaderIdx : followerIdx; + String hostPorts[] = qb.hostPort.split(","); + + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = qb.createClient(watcher, hostPorts[testPeerIdx], + CONNECTION_TIMEOUT); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + long localSessionId = zk.getSessionId(); + + // Try creating some data. + for (int i = 0; i < 5; i++) { + zk.create(nodePrefix + i, new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + + // Now, try an ephemeral node. This should fail since we + // cannot create ephemeral nodes on a local session. + try { + zk.create(nodePrefix + "ephemeral", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + Assert.fail("Ephemeral node creation should fail."); + } catch (KeeperException.EphemeralOnLocalSessionException e) { + } + + // Close the session. + zk.close(); + + // Validate data on both follower and leader + HashMap peers = new HashMap(); + peers.put("leader", leaderIdx); + peers.put("follower", followerIdx); + for (Entry entry : peers.entrySet()) { + watcher.reset(); + // Try reconnecting with a new session. + // The data should be persisted, even though the session was not. + zk = qb.createClient(watcher, hostPorts[entry.getValue()], + CONNECTION_TIMEOUT); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + long newSessionId = zk.getSessionId(); + Assert.assertFalse(newSessionId == localSessionId); + + for (int i = 0; i < 5; i++) { + Assert.assertNotNull("Data not exists in " + entry.getKey(), + zk.exists(nodePrefix + i, null)); + } + + // We may get the correct exception but the txn may go through + Assert.assertNull("Data exists in " + entry.getKey(), + zk.exists(nodePrefix + "ephemeral", null)); + + zk.close(); + } + qb.shutdownServers(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java b/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java new file mode 100644 index 00000000000..ed79677200e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java @@ -0,0 +1,128 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.proto.ConnectRequest; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.util.concurrent.atomic.AtomicInteger; + +public class MaxCnxnsTest extends ClientBase { + final private static int numCnxns = 30; + AtomicInteger numConnected = new AtomicInteger(0); + String host; + int port; + + @Override + public void setUp() throws Exception { + maxCnxns = numCnxns; + super.setUp(); + } + + /** + * Verify the ability to limit the number of concurrent connections. + * @throws IOException + * @throws InterruptedException + */ + @Test + public void testMaxCnxns() throws IOException, InterruptedException { + String split[] = hostPort.split(":"); + host = split[0]; + port = Integer.parseInt(split[1]); + int numThreads = numCnxns + 5; + CnxnThread[] threads = new CnxnThread[numThreads]; + + for (int i = 0; i < numCnxns; ++i) { + threads[i] = new CnxnThread(i); + } + + for (int i = 0; i < numCnxns; ++i) { + threads[i].start(); + } + + for (int i = 0; i < numCnxns; ++i) { + threads[i].join(); + } + Assert.assertSame(numCnxns, numConnected.get()); + } + + class CnxnThread extends Thread { + + public CnxnThread(int i) { + super("CnxnThread-" + i); + } + + public void run() { + SocketChannel sChannel = null; + try { + /* + * For future unwary socket programmers: although connect 'blocks' it + * does not require an accept on the server side to return. Therefore + * you can not assume that all the sockets are connected at the end of + * this for loop. + */ + sChannel = SocketChannel.open(); + sChannel.connect(new InetSocketAddress(host, port)); + // Construct a connection request + ConnectRequest conReq = new ConnectRequest(0, 0, + 10000, 0, "password".getBytes()); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + boa.writeInt(-1, "len"); + conReq.serialize(boa, "connect"); + baos.close(); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + bb.putInt(bb.capacity() - 4); + bb.rewind(); + + /* Send a connect request. Any socket that has been closed (or at least + * not added to the cnxn list on the server) will not have any bytes to + * read and get an eof. + * + * The trick here was finding a call that caused the server to put + * bytes in the input stream without closing the cnxn. None of + * the four letter commands do that, so we actually try to create + * a session which should send us something back, while maintaining + * the connection. + */ + + int eof = sChannel.write(bb); + // If the socket times out, we count that as Assert.failed - + // the server should respond within 10s + sChannel.socket().setSoTimeout(10000); + if (!sChannel.socket().isClosed()) { + eof = sChannel.socket().getInputStream().read(); + if (eof != -1) { + numConnected.incrementAndGet(); + } + } + } catch (IOException io) { + // "Connection reset by peer" + } finally { + if (sChannel != null) { + try { + sChannel.close(); + } catch (Exception e) { + // Do nothing + } + } + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/MultiAsyncTransactionTest.java b/src/java/test/org/apache/zookeeper/test/MultiAsyncTransactionTest.java new file mode 100644 index 00000000000..91271b90ebe --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/MultiAsyncTransactionTest.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.MultiCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.OpResult; +import org.apache.zookeeper.OpResult.CreateResult; +import org.apache.zookeeper.OpResult.ErrorResult; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class MultiAsyncTransactionTest extends ClientBase { + private final AtomicInteger pendingOps = new AtomicInteger(0); + private ZooKeeper zk; + + @Before + public void setUp() throws Exception { + super.setUp(); + zk = createClient(); + pendingOps.set(0); + } + + private void finishPendingOps() { + if (pendingOps.decrementAndGet() == 0) { + synchronized (pendingOps) { + pendingOps.notifyAll(); + } + } + } + + private void waitForPendingOps(int timeout) throws Exception { + synchronized (pendingOps) { + while (pendingOps.get() > 0) { + pendingOps.wait(timeout); + } + } + } + + /** + * ZOOKEEPER-1624: PendingChanges of create sequential node request didn't get rollbacked correctly when multi-op failed. This cause create sequential node request in subsequent multi-op to failed + * because sequential node name generation is incorrect. + * + * The check is to make sure that each request in multi-op failed with the correct reason. + */ + @Test + public void testSequentialNodeCreateInAsyncMulti() throws Exception { + final int iteration = 4; + final List results = new ArrayList(); + + pendingOps.set(iteration); + + List ops = Arrays.asList( + Op.create("/node-", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT_SEQUENTIAL), + Op.create("/dup", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT)); + + + for (int i = 0; i < iteration; ++i) { + zk.multi(ops, new MultiCallback() { + @Override + public void processResult(int rc, String path, Object ctx, + List opResults) { + MultiResult result = new MultiResult(); + result.results = opResults; + result.rc = rc; + results.add(result); + finishPendingOps(); + } + }, null); + } + + waitForPendingOps(CONNECTION_TIMEOUT); + + // Check that return code of all request are correct + assertEquals(KeeperException.Code.OK.intValue(), results.get(0).rc); + assertEquals(KeeperException.Code.NODEEXISTS.intValue(), results.get(1).rc); + assertEquals(KeeperException.Code.NODEEXISTS.intValue(), results.get(2).rc); + assertEquals(KeeperException.Code.NODEEXISTS.intValue(), results.get(3).rc); + + // Check that the first operation is successful in all request + assertTrue(results.get(0).results.get(0) instanceof CreateResult); + assertEquals(KeeperException.Code.OK.intValue(), + ((ErrorResult) results.get(1).results.get(0)).getErr()); + assertEquals(KeeperException.Code.OK.intValue(), + ((ErrorResult) results.get(2).results.get(0)).getErr()); + assertEquals(KeeperException.Code.OK.intValue(), + ((ErrorResult) results.get(3).results.get(0)).getErr()); + + // Check that the second operation failed after the first request + assertEquals(KeeperException.Code.NODEEXISTS.intValue(), + ((ErrorResult) results.get(1).results.get(1)).getErr()); + assertEquals(KeeperException.Code.NODEEXISTS.intValue(), + ((ErrorResult) results.get(2).results.get(1)).getErr()); + assertEquals(KeeperException.Code.NODEEXISTS.intValue(), + ((ErrorResult) results.get(3).results.get(1)).getErr()); + + } + + private static class MultiResult { + int rc; + List results; + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java b/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java new file mode 100644 index 00000000000..a784647843f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java @@ -0,0 +1,798 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.AsyncCallback.MultiCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.OpResult; +import org.apache.zookeeper.OpResult.CheckResult; +import org.apache.zookeeper.OpResult.CreateResult; +import org.apache.zookeeper.OpResult.DeleteResult; +import org.apache.zookeeper.OpResult.ErrorResult; +import org.apache.zookeeper.OpResult.SetDataResult; +import org.apache.zookeeper.Transaction; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKParameterized; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.*; + +@RunWith(Parameterized.class) +@Parameterized.UseParametersRunnerFactory(ZKParameterized.RunnerFactory.class) +public class MultiTransactionTest extends ClientBase { + private static final Logger LOG = LoggerFactory.getLogger(MultiTransactionTest.class); + private final boolean useAsync; + private ZooKeeper zk; + private ZooKeeper zk_chroot; + + public MultiTransactionTest(boolean useAsync) { + this.useAsync = useAsync; + } + + @Parameters + public static Collection configs() { + return Arrays.asList(new Object[][]{ + {false}, {true}, + }); + } + + @Before + public void setUp() throws Exception { + SyncRequestProcessor.setSnapCount(150); + super.setUp(); + zk = createClient(); + } + + private List multi(ZooKeeper zk, Iterable ops) + throws KeeperException, InterruptedException { + if (useAsync) { + final MultiResult res = new MultiResult(); + zk.multi(ops, new MultiCallback() { + @Override + public void processResult(int rc, String path, Object ctx, + List opResults) { + synchronized (res) { + res.rc = rc; + res.results = opResults; + res.finished = true; + res.notifyAll(); + } + } + }, null); + synchronized (res) { + while (!res.finished) { + res.wait(); + } + } + if (KeeperException.Code.OK.intValue() != res.rc) { + KeeperException ke = KeeperException.create(KeeperException.Code.get(res.rc)); + throw ke; + } + return res.results; + } else { + return zk.multi(ops); + } + } + + private void multiHavingErrors(ZooKeeper zk, Iterable ops, + List expectedResultCodes, String expectedErr) + throws KeeperException, InterruptedException { + if (useAsync) { + final MultiResult res = new MultiResult(); + zk.multi(ops, new MultiCallback() { + @Override + public void processResult(int rc, String path, Object ctx, + List opResults) { + synchronized (res) { + res.rc = rc; + res.results = opResults; + res.finished = true; + res.notifyAll(); + } + } + }, null); + synchronized (res) { + while (!res.finished) { + res.wait(); + } + } + for (int i = 0; i < res.results.size(); i++) { + OpResult opResult = res.results.get(i); + Assert.assertTrue("Did't recieve proper error response", + opResult instanceof ErrorResult); + ErrorResult errRes = (ErrorResult) opResult; + Assert.assertEquals("Did't recieve proper error code", + expectedResultCodes.get(i).intValue(), errRes.getErr()); + } + } else { + try { + zk.multi(ops); + Assert.fail("Shouldn't have validated in ZooKeeper client!"); + } catch (KeeperException e) { + Assert.assertEquals("Wrong exception", expectedErr, e.code() + .name()); + } catch (IllegalArgumentException e) { + Assert.assertEquals("Wrong exception", expectedErr, + e.getMessage()); + } + } + } + + private List commit(Transaction txn) + throws KeeperException, InterruptedException { + if (useAsync) { + final MultiResult res = new MultiResult(); + txn.commit(new MultiCallback() { + @Override + public void processResult(int rc, String path, Object ctx, + List opResults) { + synchronized (res) { + res.rc = rc; + res.results = opResults; + res.finished = true; + res.notifyAll(); + } + } + }, null); + synchronized (res) { + while (!res.finished) { + res.wait(); + } + } + if (KeeperException.Code.OK.intValue() != res.rc) { + KeeperException ke = KeeperException.create(KeeperException.Code.get(res.rc)); + throw ke; + } + return res.results; + } else { + return txn.commit(); + } + } + + /** + * Test verifies the multi calls with invalid znode path + */ + @Test(timeout = 90000) + public void testInvalidPath() throws Exception { + List expectedResultCodes = new ArrayList(); + expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY + .intValue()); + expectedResultCodes.add(KeeperException.Code.BADARGUMENTS.intValue()); + expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY + .intValue()); + // create with CreateMode + List opList = Arrays.asList(Op.create("/multi0", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create( + "/multi1/", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT), Op.create("/multi2", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)); + String expectedErr = "Path must not end with / character"; + multiHavingErrors(zk, opList, expectedResultCodes, expectedErr); + + // create with valid sequential flag + opList = Arrays.asList(Op.create("/multi0", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create( + "multi1/", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL_SEQUENTIAL.toFlag()), Op.create("/multi2", + new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)); + expectedErr = "Path must start with / character"; + multiHavingErrors(zk, opList, expectedResultCodes, expectedErr); + + // check + opList = Arrays.asList(Op.check("/multi0", -1), + Op.check("/multi1/", 100), Op.check("/multi2", 5)); + expectedErr = "Path must not end with / character"; + multiHavingErrors(zk, opList, expectedResultCodes, expectedErr); + + // delete + opList = Arrays.asList(Op.delete("/multi0", -1), + Op.delete("/multi1/", 100), Op.delete("/multi2", 5)); + multiHavingErrors(zk, opList, expectedResultCodes, expectedErr); + + // Multiple bad arguments + expectedResultCodes.add(KeeperException.Code.BADARGUMENTS.intValue()); + + // setdata + opList = Arrays.asList(Op.setData("/multi0", new byte[0], -1), + Op.setData("/multi1/", new byte[0], -1), + Op.setData("/multi2", new byte[0], -1), + Op.setData("multi3", new byte[0], -1)); + multiHavingErrors(zk, opList, expectedResultCodes, expectedErr); + } + + /** + * ZOOKEEPER-2052: + * Multi abort shouldn't have any side effect. + * We fix a bug in rollback and the following scenario should work: + * 1. multi delete abort because of not empty directory + * 2. ephemeral nodes under that directory are deleted + * 3. multi delete should succeed. + */ + @Test + public void testMultiRollback() throws Exception { + zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + ZooKeeper epheZk = createClient(); + epheZk.create("/foo/bar", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + + List opList = Arrays.asList(Op.delete("/foo", -1)); + try { + zk.multi(opList); + Assert.fail("multi delete should failed for not empty directory"); + } catch (KeeperException.NotEmptyException e) { + } + + final CountDownLatch latch = new CountDownLatch(1); + + zk.exists("/foo/bar", new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getType() == Event.EventType.NodeDeleted) { + latch.countDown(); + } + } + }); + + epheZk.close(); + + latch.await(); + + try { + zk.getData("/foo/bar", false, null); + Assert.fail("ephemeral node should have been deleted"); + } catch (KeeperException.NoNodeException e) { + } + + zk.multi(opList); + + try { + zk.getData("/foo", false, null); + Assert.fail("persistent node should have been deleted after multi"); + } catch (KeeperException.NoNodeException e) { + } + } + + /** + * Test verifies the multi calls with blank znode path + */ + @Test(timeout = 90000) + public void testBlankPath() throws Exception { + List expectedResultCodes = new ArrayList(); + expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY + .intValue()); + expectedResultCodes.add(KeeperException.Code.BADARGUMENTS.intValue()); + expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY + .intValue()); + expectedResultCodes.add(KeeperException.Code.BADARGUMENTS.intValue()); + + // delete + String expectedErr = "Path cannot be null"; + List opList = Arrays.asList(Op.delete("/multi0", -1), + Op.delete(null, 100), Op.delete("/multi2", 5), + Op.delete("", -1)); + multiHavingErrors(zk, opList, expectedResultCodes, expectedErr); + } + + /** + * Test verifies the multi.create with invalid createModeFlag + */ + @Test(timeout = 90000) + public void testInvalidCreateModeFlag() throws Exception { + List expectedResultCodes = new ArrayList(); + expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY + .intValue()); + expectedResultCodes.add(KeeperException.Code.BADARGUMENTS.intValue()); + expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY + .intValue()); + + int createModeFlag = 6789; + List opList = Arrays.asList(Op.create("/multi0", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create( + "/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, createModeFlag), + Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT)); + String expectedErr = KeeperException.Code.BADARGUMENTS.name(); + multiHavingErrors(zk, opList, expectedResultCodes, expectedErr); + } + + @Test + public void testChRootCreateDelete() throws Exception { + // creating the subtree for chRoot clients. + String chRoot = createNameSpace(); + // Creating child using chRoot client. + zk_chroot = createClient(this.hostPort + chRoot); + Op createChild = Op.create("/myid", new byte[0], + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + multi(zk_chroot, Arrays.asList(createChild)); + + Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk + .exists(chRoot + "/myid", false)); + Assert.assertNotNull("zNode is not created under chroot:" + chRoot, + zk_chroot.exists("/myid", false)); + Assert.assertNull("zNode is created directly under '/', ignored configured chroot", + zk.exists("/myid", false)); + + // Deleting child using chRoot client. + Op deleteChild = Op.delete("/myid", 0); + multi(zk_chroot, Arrays.asList(deleteChild)); + Assert.assertNull("zNode exists under chroot:" + chRoot, zk.exists( + chRoot + "/myid", false)); + Assert.assertNull("zNode exists under chroot:" + chRoot, zk_chroot + .exists("/myid", false)); + } + + @Test + public void testChRootSetData() throws Exception { + // creating the subtree for chRoot clients. + String chRoot = createNameSpace(); + // setData using chRoot client. + zk_chroot = createClient(this.hostPort + chRoot); + String[] names = {"/multi0", "/multi1", "/multi2"}; + List ops = new ArrayList(); + + for (int i = 0; i < names.length; i++) { + ops.add(Op.create(names[i], new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT)); + ops.add(Op.setData(names[i], names[i].getBytes(), 0)); + } + + multi(zk_chroot, ops); + + for (int i = 0; i < names.length; i++) { + Assert.assertArrayEquals("zNode data not matching", names[i] + .getBytes(), zk_chroot.getData(names[i], false, null)); + } + } + + @Test + public void testChRootCheck() throws Exception { + // creating the subtree for chRoot clients. + String chRoot = createNameSpace(); + // checking the child version using chRoot client. + zk_chroot = createClient(this.hostPort + chRoot); + String[] names = {"/multi0", "/multi1", "/multi2"}; + List ops = new ArrayList(); + + for (int i = 0; i < names.length; i++) { + zk.create(chRoot + names[i], new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + for (int i = 0; i < names.length; i++) { + ops.add(Op.check(names[i], 0)); + } + multi(zk_chroot, ops); + } + + @Test + public void testChRootTransaction() throws Exception { + // creating the subtree for chRoot clients. + String chRoot = createNameSpace(); + // checking the child version using chRoot client. + zk_chroot = createClient(this.hostPort + chRoot); + String childPath = "/myid"; + Transaction transaction = zk_chroot.transaction(); + transaction.create(childPath, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + transaction.check(childPath, 0); + transaction.setData(childPath, childPath.getBytes(), 0); + commit(transaction); + + Assert.assertNotNull("zNode is not created under chroot:" + chRoot, zk + .exists(chRoot + childPath, false)); + Assert.assertNotNull("zNode is not created under chroot:" + chRoot, + zk_chroot.exists(childPath, false)); + Assert.assertNull("zNode is created directly under '/', ignored configured chroot", + zk.exists(childPath, false)); + Assert.assertArrayEquals("zNode data not matching", childPath + .getBytes(), zk_chroot.getData(childPath, false, null)); + + transaction = zk_chroot.transaction(); + // Deleting child using chRoot client. + transaction.delete(childPath, 1); + commit(transaction); + + Assert.assertNull("chroot:" + chRoot + " exists after delete", zk + .exists(chRoot + "/myid", false)); + Assert.assertNull("chroot:" + chRoot + " exists after delete", + zk_chroot.exists("/myid", false)); + } + + private String createNameSpace() throws InterruptedException, + KeeperException { + // creating the subtree for chRoot clients. + String chRoot = "/appsX"; + Op createChRoot = Op.create(chRoot, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + multi(zk, Arrays.asList(createChRoot)); + return chRoot; + } + + @Test + public void testCreate() throws Exception { + multi(zk, Arrays.asList( + Op.create("/multi0", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.create("/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT) + )); + zk.getData("/multi0", false, null); + zk.getData("/multi1", false, null); + zk.getData("/multi2", false, null); + } + + @Test + public void testCreateDelete() throws Exception { + + multi(zk, Arrays.asList( + Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/multi", 0) + )); + + // '/multi' should have been deleted + Assert.assertNull(zk.exists("/multi", null)); + } + + @Test + public void testInvalidVersion() throws Exception { + + try { + multi(zk, Arrays.asList( + Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/multi", 1) + )); + Assert.fail("delete /multi should have failed"); + } catch (KeeperException e) { + /* PASS */ + } + } + + @Test + public void testNestedCreate() throws Exception { + + multi(zk, Arrays.asList( + /* Create */ + Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.create("/multi/a", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.create("/multi/a/1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + + /* Delete */ + Op.delete("/multi/a/1", 0), + Op.delete("/multi/a", 0), + Op.delete("/multi", 0) + )); + + //Verify tree deleted + Assert.assertNull(zk.exists("/multi/a/1", null)); + Assert.assertNull(zk.exists("/multi/a", null)); + Assert.assertNull(zk.exists("/multi", null)); + } + + @Test + public void testSetData() throws Exception { + + String[] names = {"/multi0", "/multi1", "/multi2"}; + List ops = new ArrayList(); + + for (int i = 0; i < names.length; i++) { + ops.add(Op.create(names[i], new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)); + ops.add(Op.setData(names[i], names[i].getBytes(), 0)); + } + + multi(zk, ops); + + for (int i = 0; i < names.length; i++) { + Assert.assertArrayEquals(names[i].getBytes(), zk.getData(names[i], false, null)); + } + } + + @Test + public void testUpdateConflict() throws Exception { + + Assert.assertNull(zk.exists("/multi", null)); + + try { + multi(zk, Arrays.asList( + Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.setData("/multi", "X".getBytes(), 0), + Op.setData("/multi", "Y".getBytes(), 0) + )); + Assert.fail("Should have thrown a KeeperException for invalid version"); + } catch (KeeperException e) { + //PASS + LOG.error("STACKTRACE: ", e); + } + + Assert.assertNull(zk.exists("/multi", null)); + + //Updating version solves conflict -- order matters + multi(zk, Arrays.asList( + Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.setData("/multi", "X".getBytes(), 0), + Op.setData("/multi", "Y".getBytes(), 1) + )); + + Assert.assertArrayEquals(zk.getData("/multi", false, null), "Y".getBytes()); + } + + @Test + public void testDeleteUpdateConflict() throws Exception { + + /* Delete of a node folowed by an update of the (now) deleted node */ + try { + multi(zk, Arrays.asList( + Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/multi", 0), + Op.setData("/multi", "Y".getBytes(), 0) + )); + Assert.fail("/multi should have been deleted so setData should have failed"); + } catch (KeeperException e) { + /* PASS */ + } + + // '/multi' should never have been created as entire op should fail + Assert.assertNull(zk.exists("/multi", null)); + } + + @Test + public void testGetResults() throws Exception { + /* Delete of a node folowed by an update of the (now) deleted node */ + Iterable ops = Arrays.asList( + Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/multi", 0), + Op.setData("/multi", "Y".getBytes(), 0), + Op.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT) + ); + List results = null; + if (useAsync) { + final MultiResult res = new MultiResult(); + zk.multi(ops, new MultiCallback() { + @Override + public void processResult(int rc, String path, Object ctx, + List opResults) { + synchronized (res) { + res.rc = rc; + res.results = opResults; + res.finished = true; + res.notifyAll(); + } + } + }, null); + synchronized (res) { + while (!res.finished) { + res.wait(); + } + } + Assert.assertFalse("/multi should have been deleted so setData should have failed", + KeeperException.Code.OK.intValue() == res.rc); + Assert.assertNull(zk.exists("/multi", null)); + results = res.results; + } else { + try { + zk.multi(ops); + Assert.fail("/multi should have been deleted so setData should have failed"); + } catch (KeeperException e) { + // '/multi' should never have been created as entire op should fail + Assert.assertNull(zk.exists("/multi", null)); + results = e.getResults(); + } + } + + Assert.assertNotNull(results); + for (OpResult r : results) { + LOG.info("RESULT==> {}", r); + if (r instanceof ErrorResult) { + ErrorResult er = (ErrorResult) r; + LOG.info("ERROR RESULT: {} ERR=>{}", er, KeeperException.Code.get(er.getErr())); + } + } + } + + /** + * Exercise the equals methods of OpResult classes. + */ + @Test + public void testOpResultEquals() { + opEquals(new CreateResult("/foo"), + new CreateResult("/foo"), + new CreateResult("nope")); + + opEquals(new CreateResult("/foo"), + new CreateResult("/foo"), + new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))); + + opEquals(new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), + new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), + new CreateResult("nope", new Stat(11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111))); + + opEquals(new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), + new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), + new CreateResult("/foo")); + + opEquals(new CheckResult(), + new CheckResult(), + null); + + opEquals(new SetDataResult(new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), + new SetDataResult(new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), + new SetDataResult(new Stat(11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111))); + + opEquals(new ErrorResult(1), + new ErrorResult(1), + new ErrorResult(2)); + + opEquals(new DeleteResult(), + new DeleteResult(), + null); + + opEquals(new ErrorResult(1), + new ErrorResult(1), + new ErrorResult(2)); + } + + private void opEquals(OpResult expected, OpResult value, OpResult near) { + assertEquals(value, value); + assertFalse(value.equals(new Object())); + assertFalse(value.equals(near)); + assertFalse(value.equals(value instanceof CreateResult ? + new ErrorResult(1) : new CreateResult("nope2"))); + assertTrue(value.equals(expected)); + } + + @Test + public void testWatchesTriggered() throws KeeperException, InterruptedException { + HasTriggeredWatcher watcher = new HasTriggeredWatcher(); + zk.getChildren("/", watcher); + multi(zk, Arrays.asList( + Op.create("/t", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/t", -1) + )); + assertTrue(watcher.triggered.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)); + } + + @Test + public void testNoWatchesTriggeredForFailedMultiRequest() throws InterruptedException, KeeperException { + HasTriggeredWatcher watcher = new HasTriggeredWatcher(); + zk.getChildren("/", watcher); + try { + multi(zk, Arrays.asList( + Op.create("/t", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.delete("/nonexisting", -1) + )); + fail("expected previous multi op to fail!"); + } catch (KeeperException.NoNodeException e) { + // expected + } + SyncCallback cb = new SyncCallback(); + zk.sync("/", cb, null); + + // by waiting for the callback we're assured that the event queue is flushed + cb.done.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + assertEquals(1, watcher.triggered.getCount()); + } + + @Test + public void testTransactionBuilder() throws Exception { + List results = commit(zk.transaction() + .create("/t1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT) + .create("/t1/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT) + .create("/t2", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL)); + assertEquals(3, results.size()); + for (OpResult r : results) { + CreateResult c = (CreateResult) r; + assertTrue(c.getPath().startsWith("/t")); + assertNotNull(c.toString()); + } + assertNotNull(zk.exists("/t1", false)); + assertNotNull(zk.exists("/t1/child", false)); + assertNotNull(zk.exists("/t2", false)); + + results = commit(zk.transaction() + .check("/t1", 0) + .check("/t1/child", 0) + .check("/t2", 0)); + assertEquals(3, results.size()); + for (OpResult r : results) { + CheckResult c = (CheckResult) r; + assertNotNull(c.toString()); + } + + try { + results = commit(zk.transaction() + .check("/t1", 0) + .check("/t1/child", 0) + .check("/t2", 1)); + fail(); + } catch (KeeperException.BadVersionException e) { + // expected + } + + results = commit(zk.transaction() + .check("/t1", 0) + .setData("/t1", new byte[0], 0)); + assertEquals(2, results.size()); + for (OpResult r : results) { + assertNotNull(r.toString()); + } + + try { + results = commit(zk.transaction() + .check("/t1", 1) + .setData("/t1", new byte[0], 2)); + fail(); + } catch (KeeperException.BadVersionException e) { + // expected + } + + results = commit(zk.transaction() + .check("/t1", 1) + .check("/t1/child", 0) + .check("/t2", 0)); + assertEquals(3, results.size()); + + results = commit(zk.transaction() + .delete("/t2", -1) + .delete("/t1/child", -1)); + assertEquals(2, results.size()); + for (OpResult r : results) { + DeleteResult d = (DeleteResult) r; + assertNotNull(d.toString()); + } + assertNotNull(zk.exists("/t1", false)); + assertNull(zk.exists("/t1/child", false)); + assertNull(zk.exists("/t2", false)); + } + + static class MultiResult { + int rc; + List results; + boolean finished = false; + } + + private static class HasTriggeredWatcher implements Watcher { + private final CountDownLatch triggered = new CountDownLatch(1); + + @Override + public void process(WatchedEvent event) { + triggered.countDown(); + } + } + + private static class SyncCallback implements AsyncCallback.VoidCallback { + private final CountDownLatch done = new CountDownLatch(1); + + @Override + public void processResult(int rc, String path, Object ctx) { + done.countDown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/NIOConnectionFactoryFdLeakTest.java b/src/java/test/org/apache/zookeeper/test/NIOConnectionFactoryFdLeakTest.java new file mode 100644 index 00000000000..f6a54aafa6f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NIOConnectionFactoryFdLeakTest.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.NIOServerCnxnFactory; +import org.apache.zookeeper.server.util.OSMXBean; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetSocketAddress; + +/** + * ZOOKEEPER-1620 - Acceptor and Selector thread don't call selector.close() + * causing fd leakage + */ +public class NIOConnectionFactoryFdLeakTest extends ZKTestCase { + private static final Logger LOG = LoggerFactory + .getLogger(NIOConnectionFactoryFdLeakTest.class); + + @Test + public void testFileDescriptorLeak() throws Exception { + + OSMXBean osMbean = new OSMXBean(); + if (osMbean.getUnix() != true) { + LOG.info("Unable to run test on non-unix system"); + return; + } + + long startFdCount = osMbean.getOpenFileDescriptorCount(); + LOG.info("Start fdcount is: " + startFdCount); + + for (int i = 0; i < 50; ++i) { + NIOServerCnxnFactory factory = new NIOServerCnxnFactory(); + factory.configure( + new InetSocketAddress( + "127.0.0.1", PortAssignment.unique()), 10); + factory.start(); + Thread.sleep(100); + factory.shutdown(); + } + + long endFdCount = osMbean.getOpenFileDescriptorCount(); + LOG.info("End fdcount is: " + endFdCount); + + // On my box, if selector.close() is not called fd diff is > 700. + Assert.assertTrue("Possible fd leakage", + ((endFdCount - startFdCount) < 50)); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java b/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java new file mode 100644 index 00000000000..cc8e66e9667 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ClientCnxnSocketNetty; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.NettyServerCnxnFactory; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * Run tests with: Netty Client against Netty server + */ +@RunWith(Suite.class) +public class NettyNettySuiteBase { + @BeforeClass + public static void setUp() { + System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, + NettyServerCnxnFactory.class.getName()); + System.setProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET, + ClientCnxnSocketNetty.class.getName()); + System.setProperty("zookeeper.admin.enableServer", "false"); + } + + @AfterClass + public static void tearDown() { + System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); + System.clearProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/NettyNettySuiteHammerTest.java b/src/java/test/org/apache/zookeeper/test/NettyNettySuiteHammerTest.java new file mode 100644 index 00000000000..c3e0361bf3e --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NettyNettySuiteHammerTest.java @@ -0,0 +1,23 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.junit.runners.Suite; + +/** + * Run tests with: Netty Client against Netty server + */ +@Suite.SuiteClasses({ + AsyncHammerTest.class +}) +public class NettyNettySuiteHammerTest extends NettyNettySuiteBase { +} diff --git a/src/java/test/org/apache/zookeeper/test/NettyNettySuiteTest.java b/src/java/test/org/apache/zookeeper/test/NettyNettySuiteTest.java new file mode 100644 index 00000000000..e48ceca1bef --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NettyNettySuiteTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.junit.runners.Suite; + +/** + * Run tests with: Netty Client against Netty server + */ +@Suite.SuiteClasses({ + ACLTest.class, + AsyncOpsTest.class, + ChrootClientTest.class, + ClientTest.class, + FourLetterWordsTest.class, + NullDataTest.class, + SessionTest.class, + WatcherTest.class +}) +public class NettyNettySuiteTest extends NettyNettySuiteBase { +} diff --git a/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java b/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java new file mode 100644 index 00000000000..d958c7d6001 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.server.NettyServerCnxnFactory; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * Run tests with: Nio Client against Netty server + */ +@RunWith(Suite.class) +public class NioNettySuiteBase { + @BeforeClass + public static void setUp() { + System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, + NettyServerCnxnFactory.class.getName()); + System.setProperty("zookeeper.admin.enableServer", "false"); + } + + @AfterClass + public static void tearDown() { + System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/NioNettySuiteHammerTest.java b/src/java/test/org/apache/zookeeper/test/NioNettySuiteHammerTest.java new file mode 100644 index 00000000000..dcfaae9d3ea --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NioNettySuiteHammerTest.java @@ -0,0 +1,23 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.junit.runners.Suite; + +/** + * Run tests with: Nio Client against Netty server + */ +@Suite.SuiteClasses({ + AsyncHammerTest.class +}) +public class NioNettySuiteHammerTest extends NioNettySuiteBase { +} diff --git a/src/java/test/org/apache/zookeeper/test/NioNettySuiteTest.java b/src/java/test/org/apache/zookeeper/test/NioNettySuiteTest.java new file mode 100644 index 00000000000..20764431e9f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NioNettySuiteTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.junit.runners.Suite; + +/** + * Run tests with: Nio Client against Netty server + */ +@Suite.SuiteClasses({ + ACLTest.class, + AsyncOpsTest.class, + ChrootClientTest.class, + ClientTest.class, + FourLetterWordsTest.class, + NullDataTest.class, + SessionTest.class, + WatcherTest.class +}) +public class NioNettySuiteTest extends NioNettySuiteBase { +} diff --git a/src/java/test/org/apache/zookeeper/test/NullDataTest.java b/src/java/test/org/apache/zookeeper/test/NullDataTest.java new file mode 100644 index 00000000000..9df1b5407bc --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/NullDataTest.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class NullDataTest extends ClientBase implements StatCallback { + String snapCount; + CountDownLatch cn = new CountDownLatch(1); + + @Override + public void setUp() throws Exception { + // Change the snapcount to happen more often + snapCount = System.getProperty("zookeeper.snapCount", "1024"); + System.setProperty("zookeeper.snapCount", "10"); + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + System.setProperty("zookeeper.snapCount", snapCount); + super.tearDown(); + } + + @Test + public void testNullData() throws IOException, + InterruptedException, KeeperException { + String path = "/SIZE"; + ZooKeeper zk = null; + zk = createClient(); + try { + zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + // try sync zk exists + zk.exists(path, false); + zk.exists(path, false, this, null); + cn.await(10, TimeUnit.SECONDS); + Assert.assertSame(0L, cn.getCount()); + } finally { + if (zk != null) + zk.close(); + } + + } + + public void processResult(int rc, String path, Object ctx, Stat stat) { + cn.countDown(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/OOMTest.java b/src/java/test/org/apache/zookeeper/test/OOMTest.java new file mode 100644 index 00000000000..ed6e7a5d961 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/OOMTest.java @@ -0,0 +1,150 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class OOMTest extends ZKTestCase implements Watcher { + @Test + public void testOOM() throws IOException, InterruptedException, KeeperException { + // This test takes too long tos run! + if (true) + return; + File tmpDir = ClientBase.createTmpDir(); + // Grab some memory so that it is easier to cause an + // OOM condition; + ArrayList hog = new ArrayList(); + while (true) { + try { + hog.add(new byte[1024 * 1024 * 2]); + } catch (OutOfMemoryError e) { + hog.remove(0); + break; + } + } + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + + final int PORT = PortAssignment.unique(); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp("127.0.0.1:" + PORT, + CONNECTION_TIMEOUT)); + + System.err.println("OOM Stage 0"); + utestPrep(PORT); + System.out.println("Free = " + Runtime.getRuntime().freeMemory() + + " total = " + Runtime.getRuntime().totalMemory() + " max = " + + Runtime.getRuntime().maxMemory()); + System.err.println("OOM Stage 1"); + for (int i = 0; i < 1000; i++) { + System.out.println(i); + utestExists(PORT); + } + System.out.println("Free = " + Runtime.getRuntime().freeMemory() + + " total = " + Runtime.getRuntime().totalMemory() + " max = " + + Runtime.getRuntime().maxMemory()); + System.err.println("OOM Stage 2"); + for (int i = 0; i < 1000; i++) { + System.out.println(i); + utestGet(PORT); + } + System.out.println("Free = " + Runtime.getRuntime().freeMemory() + + " total = " + Runtime.getRuntime().totalMemory() + " max = " + + Runtime.getRuntime().maxMemory()); + System.err.println("OOM Stage 3"); + for (int i = 0; i < 1000; i++) { + System.out.println(i); + utestChildren(PORT); + } + System.out.println("Free = " + Runtime.getRuntime().freeMemory() + + " total = " + Runtime.getRuntime().totalMemory() + " max = " + + Runtime.getRuntime().maxMemory()); + hog.get(0)[0] = (byte) 1; + + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown("127.0.0.1:" + PORT, + CONNECTION_TIMEOUT)); + } + + private void utestExists(int port) + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = + new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); + for (int i = 0; i < 10000; i++) { + zk.exists("/this/path/doesnt_exist!", true); + } + zk.close(); + } + + private void utestPrep(int port) + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = + new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); + for (int i = 0; i < 10000; i++) { + zk.create("/" + i, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + zk.close(); + } + + private void utestGet(int port) + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = + new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); + for (int i = 0; i < 10000; i++) { + Stat stat = new Stat(); + zk.getData("/" + i, true, stat); + } + zk.close(); + } + + private void utestChildren(int port) + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = + new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); + for (int i = 0; i < 10000; i++) { + zk.getChildren("/" + i, true); + } + zk.close(); + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.proto.WatcherEvent) + */ + public void process(WatchedEvent event) { + System.err.println("Got event " + event.getType() + " " + + event.getState() + " " + event.getPath()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/OSMXBeanTest.java b/src/java/test/org/apache/zookeeper/test/OSMXBeanTest.java new file mode 100644 index 00000000000..bd1924a391f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/OSMXBeanTest.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.util.OSMXBean; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OSMXBeanTest extends ZKTestCase { + + protected static final Logger LOG = LoggerFactory.getLogger(OSMXBeanTest.class); + private OSMXBean osMbean; + private Long ofdc = 0L; + private Long mfdc = 0L; + + @Before + public void initialize() { + this.osMbean = new OSMXBean(); + Assert.assertNotNull("Could not initialize OSMXBean object!", osMbean); + } + + @Test + public final void testGetUnix() { + boolean isUnix = osMbean.getUnix(); + if (!isUnix) { + LOG.info("Running in a Windows system! Output won't be printed!"); + } else { + LOG.info("Running in a Unix or Linux system!"); + } + } + + @Test + public final void testGetOpenFileDescriptorCount() { + if (osMbean != null && osMbean.getUnix() == true) { + ofdc = osMbean.getOpenFileDescriptorCount(); + LOG.info("open fdcount is: " + ofdc); + } + Assert.assertFalse("The number of open file descriptor is negative", (ofdc < 0)); + } + + @Test + public final void testGetMaxFileDescriptorCount() { + if (osMbean != null && osMbean.getUnix() == true) { + mfdc = osMbean.getMaxFileDescriptorCount(); + LOG.info("max fdcount is: " + mfdc); + } + Assert.assertFalse("The max file descriptor number is negative", (mfdc < 0)); + } + +} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JDouble.java b/src/java/test/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java old mode 100755 new mode 100644 similarity index 56% rename from zookeeper/java/src/com/yahoo/jute/compiler/JDouble.java rename to src/java/test/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java index 8efdafd1909..07acce27f96 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JDouble.java +++ b/src/java/test/org/apache/zookeeper/test/ObserverHierarchicalQuorumTest.java @@ -1,5 +1,4 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one +/* Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file @@ -16,26 +15,25 @@ * limitations under the License. */ -package com.yahoo.jute.compiler; +package org.apache.zookeeper.test; -/** - * - * @author Milind Bhandarkar - */ -public class JDouble extends JType { - - /** Creates a new instance of JDouble */ - public JDouble() { - super("double", "double", "double", "Double", "Double", "toDouble"); - } - - public String getSignature() { - return "d"; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.junit.Test; + +public class ObserverHierarchicalQuorumTest extends HierarchicalQuorumTest { + /** + * startServers(true) puts two observers into a 5 peer ensemble + */ + void startServers() throws Exception { + startServers(true); } - - public String genJavaHashCode(String fname) { - String tmp = "Double.doubleToLongBits("+fname+")"; - return " ret = (int)("+tmp+"^("+tmp+">>>32));\n"; + + protected void shutdown(QuorumPeer qp) { + QuorumBase.shutdown(qp); } + @Test + public void testHierarchicalQuorum() throws Throwable { + cht.runHammer(5, 10); + } } diff --git a/src/java/test/org/apache/zookeeper/test/ObserverLETest.java b/src/java/test/org/apache/zookeeper/test/ObserverLETest.java new file mode 100644 index 00000000000..b728822d526 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ObserverLETest.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumStats; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.*; + +public class ObserverLETest extends ZKTestCase { + final QuorumBase qb = new QuorumBase(); + final ClientTest ct = new ClientTest(); + + @Before + public void establishThreeParticipantOneObserverEnsemble() throws Exception { + qb.setUp(true); + ct.hostPort = qb.hostPort; + ct.setUpAll(); + qb.s5.shutdown(); + } + + @After + public void shutdownQuorum() throws Exception { + ct.tearDownAll(); + qb.tearDown(); + } + + /** + * See ZOOKEEPER-1294. Confirms that an observer will not support the quorum + * of a leader by forming a 5-node, 2-observer ensemble (so quorum size is 2). + * When all but the leader and one observer are shut down, the leader should + * enter the 'looking' state, not stay in the 'leading' state. + */ + @Test + public void testLEWithObserver() throws Exception { + QuorumPeer leader = null; + for (QuorumPeer server : Arrays.asList(qb.s1, qb.s2, qb.s3)) { + if (server.getServerState().equals( + QuorumStats.Provider.FOLLOWING_STATE)) { + server.shutdown(); + assertTrue("Waiting for server down", ClientBase + .waitForServerDown("127.0.0.1:" + + server.getClientPort(), + ClientBase.CONNECTION_TIMEOUT)); + } else { + assertNull("More than one leader found", leader); + leader = server; + } + } + assertTrue("Leader is not in Looking state", ClientBase + .waitForServerState(leader, ClientBase.CONNECTION_TIMEOUT, + QuorumStats.Provider.LOOKING_STATE)); + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/ObserverQuorumHammerTest.java b/src/java/test/org/apache/zookeeper/test/ObserverQuorumHammerTest.java new file mode 100644 index 00000000000..e8ad39160b3 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ObserverQuorumHammerTest.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.junit.Before; +import org.junit.Test; + +public class ObserverQuorumHammerTest extends QuorumHammerTest { + public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; + + + @Before + @Override + public void setUp() throws Exception { + qb.setUp(true); + cht.hostPort = qb.hostPort; + cht.setUpAll(); + } + + @Test + public void testHammerBasic() throws Throwable { + cht.testHammerBasic(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ObserverTest.java b/src/java/test/org/apache/zookeeper/test/ObserverTest.java new file mode 100644 index 00000000000..224aa7cd8e5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ObserverTest.java @@ -0,0 +1,224 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException.ConnectionLossException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeper.States; +import org.apache.zookeeper.server.quorum.QuorumPeerTestBase; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.CountDownLatch; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class ObserverTest extends QuorumPeerTestBase implements Watcher { + protected static final Logger LOG = + LoggerFactory.getLogger(ObserverTest.class); + + CountDownLatch latch; + ZooKeeper zk; + WatchedEvent lastEvent = null; + + /** + * This test ensures two things: + * 1. That Observers can successfully proxy requests to the ensemble. + * 2. That Observers don't participate in leader elections. + * The second is tested by constructing an ensemble where a leader would + * be elected if and only if an Observer voted. + * @throws Exception + */ + @Test + public void testObserver() throws Exception { + ClientBase.setupTestEnv(); + // We expect two notifications before we want to continue + latch = new CountDownLatch(2); + + final int PORT_QP1 = PortAssignment.unique(); + final int PORT_QP2 = PortAssignment.unique(); + final int PORT_OBS = PortAssignment.unique(); + final int PORT_QP_LE1 = PortAssignment.unique(); + final int PORT_QP_LE2 = PortAssignment.unique(); + final int PORT_OBS_LE = PortAssignment.unique(); + + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + final int CLIENT_PORT_QP2 = PortAssignment.unique(); + final int CLIENT_PORT_OBS = PortAssignment.unique(); + + + String quorumCfgSection = + "server.1=127.0.0.1:" + (PORT_QP1) + + ":" + (PORT_QP_LE1) + ";" + CLIENT_PORT_QP1 + + "\nserver.2=127.0.0.1:" + (PORT_QP2) + + ":" + (PORT_QP_LE2) + ";" + CLIENT_PORT_QP2 + + "\nserver.3=127.0.0.1:" + + (PORT_OBS) + ":" + (PORT_OBS_LE) + ":observer" + ";" + CLIENT_PORT_OBS; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); + MainThread q3 = new MainThread(3, CLIENT_PORT_OBS, quorumCfgSection); + q1.start(); + q2.start(); + q3.start(); + Assert.assertTrue("waiting for server 1 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 2 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + Assert.assertTrue("waiting for server 3 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_OBS, + CONNECTION_TIMEOUT)); + + zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_OBS, + ClientBase.CONNECTION_TIMEOUT, this); + zk.create("/obstest", "test".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + // Assert that commands are getting forwarded correctly + Assert.assertEquals(new String(zk.getData("/obstest", null, null)), "test"); + + // Now check that other commands don't blow everything up + zk.sync("/", null, null); + zk.setData("/obstest", "test2".getBytes(), -1); + zk.getChildren("/", false); + + Assert.assertEquals(zk.getState(), States.CONNECTED); + + LOG.info("Shutting down server 2"); + // Now kill one of the other real servers + q2.shutdown(); + + Assert.assertTrue("Waiting for server 2 to shut down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT)); + + LOG.info("Server 2 down"); + + // Now the resulting ensemble shouldn't be quorate + latch.await(); + Assert.assertNotSame("Client is still connected to non-quorate cluster", + KeeperState.SyncConnected, lastEvent.getState()); + + LOG.info("Latch returned"); + + try { + Assert.assertFalse("Shouldn't get a response when cluster not quorate!", + new String(zk.getData("/obstest", null, null)).equals("test")); + } catch (ConnectionLossException c) { + LOG.info("Connection loss exception caught - ensemble not quorate (this is expected)"); + } + + latch = new CountDownLatch(1); + + LOG.info("Restarting server 2"); + + // Bring it back + q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); + q2.start(); + + LOG.info("Waiting for server 2 to come up"); + Assert.assertTrue("waiting for server 2 being up", + ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, + CONNECTION_TIMEOUT)); + + LOG.info("Server 2 started, waiting for latch"); + + latch.await(); + // It's possible our session expired - but this is ok, shows we + // were able to talk to the ensemble + Assert.assertTrue("Client didn't reconnect to quorate ensemble (state was" + + lastEvent.getState() + ")", + (KeeperState.SyncConnected == lastEvent.getState() || + KeeperState.Expired == lastEvent.getState())); + + LOG.info("Shutting down all servers"); + + q1.shutdown(); + q2.shutdown(); + q3.shutdown(); + + LOG.info("Closing zk client"); + + zk.close(); + Assert.assertTrue("Waiting for server 1 to shut down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("Waiting for server 2 to shut down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, + ClientBase.CONNECTION_TIMEOUT)); + Assert.assertTrue("Waiting for server 3 to shut down", + ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_OBS, + ClientBase.CONNECTION_TIMEOUT)); + + } + + /** + * Implementation of watcher interface. + */ + public void process(WatchedEvent event) { + lastEvent = event; + latch.countDown(); + LOG.info("Latch got event :: " + event); + } + + /** + * This test ensures that an Observer does not elect itself as a leader, or + * indeed come up properly, if it is the lone member of an ensemble. + * @throws Exception + */ + @Test + public void testObserverOnly() throws Exception { + ClientBase.setupTestEnv(); + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + + String quorumCfgSection = + "server.1=127.0.0.1:" + (PortAssignment.unique()) + + ":" + (PortAssignment.unique()) + ":observer;" + CLIENT_PORT_QP1 + "\n"; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + q1.start(); + q1.join(ClientBase.CONNECTION_TIMEOUT); + Assert.assertFalse(q1.isAlive()); + } + + /** + * Ensure that observer only comes up when a proper ensemble is configured. + * (and will not come up with standalone server). + */ + @Test + public void testObserverWithStandlone() throws Exception { + ClientBase.setupTestEnv(); + final int CLIENT_PORT_QP1 = PortAssignment.unique(); + + String quorumCfgSection = + "server.1=127.0.0.1:" + (PortAssignment.unique()) + + ":" + (PortAssignment.unique()) + ":observer\n" + + "server.2=127.0.0.1:" + (PortAssignment.unique()) + + ":" + (PortAssignment.unique()) + "\npeerType=observer\n"; + + MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); + q1.start(); + q1.join(ClientBase.CONNECTION_TIMEOUT); + Assert.assertFalse(q1.isAlive()); + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumBase.java b/src/java/test/org/apache/zookeeper/test/QuorumBase.java new file mode 100644 index 00000000000..344ae921f59 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumBase.java @@ -0,0 +1,422 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.server.quorum.Election; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.util.OSMXBean; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Set; + + +public class QuorumBase extends ClientBase { + private static final Logger LOG = LoggerFactory.getLogger(QuorumBase.class); + + private static final String LOCALADDR = "127.0.0.1"; + protected int port1; + protected int port2; + protected int port3; + protected int port4; + protected int port5; + protected int portLE1; + protected int portLE2; + protected int portLE3; + protected int portLE4; + protected int portLE5; + protected int portClient1; + protected int portClient2; + protected int portClient3; + protected int portClient4; + protected int portClient5; + protected boolean localSessionsEnabled = false; + protected boolean localSessionsUpgradingEnabled = false; + File s1dir, s2dir, s3dir, s4dir, s5dir; + QuorumPeer s1, s2, s3, s4, s5; + HashMap peers = null; + + public static void shutdown(QuorumPeer qp) { + if (qp == null) { + return; + } + try { + LOG.info("Shutting down quorum peer " + qp.getName()); + qp.shutdown(); + Election e = qp.getElectionAlg(); + if (e != null) { + LOG.info("Shutting down leader election " + qp.getName()); + e.shutdown(); + } else { + LOG.info("No election available to shutdown " + qp.getName()); + } + LOG.info("Waiting for " + qp.getName() + " to exit thread"); + long readTimeout = qp.getTickTime() * qp.getInitLimit(); + long connectTimeout = qp.getTickTime() * qp.getSyncLimit(); + long maxTimeout = Math.max(readTimeout, connectTimeout); + maxTimeout = Math.max(maxTimeout, ClientBase.CONNECTION_TIMEOUT); + qp.join(maxTimeout * 2); + if (qp.isAlive()) { + Assert.fail("QP failed to shutdown in " + (maxTimeout * 2) + " seconds: " + qp.getName()); + } + } catch (InterruptedException e) { + LOG.debug("QP interrupted: " + qp.getName(), e); + } + } + + @Test + // This just avoids complaints by junit + public void testNull() { + } + + @Override + public void setUp() throws Exception { + setUp(false); + } + + protected void setUp(boolean withObservers) throws Exception { + LOG.info("QuorumBase.setup " + getTestName()); + setupTestEnv(); + + JMXEnv.setUp(); + + setUpAll(); + + port1 = PortAssignment.unique(); + port2 = PortAssignment.unique(); + port3 = PortAssignment.unique(); + port4 = PortAssignment.unique(); + port5 = PortAssignment.unique(); + + portLE1 = PortAssignment.unique(); + portLE2 = PortAssignment.unique(); + portLE3 = PortAssignment.unique(); + portLE4 = PortAssignment.unique(); + portLE5 = PortAssignment.unique(); + + portClient1 = PortAssignment.unique(); + portClient2 = PortAssignment.unique(); + portClient3 = PortAssignment.unique(); + portClient4 = PortAssignment.unique(); + portClient5 = PortAssignment.unique(); + + hostPort = "127.0.0.1:" + portClient1 + + ",127.0.0.1:" + portClient2 + + ",127.0.0.1:" + portClient3 + + ",127.0.0.1:" + portClient4 + + ",127.0.0.1:" + portClient5; + LOG.info("Ports are: " + hostPort); + + s1dir = ClientBase.createTmpDir(); + s2dir = ClientBase.createTmpDir(); + s3dir = ClientBase.createTmpDir(); + s4dir = ClientBase.createTmpDir(); + s5dir = ClientBase.createTmpDir(); + + startServers(withObservers); + + OSMXBean osMbean = new OSMXBean(); + if (osMbean.getUnix() == true) { + LOG.info("Initial fdcount is: " + + osMbean.getOpenFileDescriptorCount()); + } + + LOG.info("Setup finished"); + } + + void startServers() throws Exception { + startServers(false); + } + + void startServers(boolean withObservers) throws Exception { + int tickTime = 2000; + int initLimit = 3; + int syncLimit = 3; + HashMap peers = new HashMap(); + peers.put(Long.valueOf(1), new QuorumServer(1, + new InetSocketAddress(LOCALADDR, port1), + new InetSocketAddress(LOCALADDR, portLE1), + new InetSocketAddress(LOCALADDR, portClient1), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(2), new QuorumServer(2, + new InetSocketAddress(LOCALADDR, port2), + new InetSocketAddress(LOCALADDR, portLE2), + new InetSocketAddress(LOCALADDR, portClient2), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(3), new QuorumServer(3, + new InetSocketAddress(LOCALADDR, port3), + new InetSocketAddress(LOCALADDR, portLE3), + new InetSocketAddress(LOCALADDR, portClient3), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(4), new QuorumServer(4, + new InetSocketAddress(LOCALADDR, port4), + new InetSocketAddress(LOCALADDR, portLE4), + new InetSocketAddress(LOCALADDR, portClient4), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(5), new QuorumServer(5, + new InetSocketAddress(LOCALADDR, port5), + new InetSocketAddress(LOCALADDR, portLE5), + new InetSocketAddress(LOCALADDR, portClient5), + LearnerType.PARTICIPANT)); + + if (withObservers) { + peers.get(Long.valueOf(4)).type = LearnerType.OBSERVER; + peers.get(Long.valueOf(5)).type = LearnerType.OBSERVER; + } + + LOG.info("creating QuorumPeer 1 port " + portClient1); + s1 = new QuorumPeer(peers, s1dir, s1dir, portClient1, 3, 1, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient1, s1.getClientPort()); + LOG.info("creating QuorumPeer 2 port " + portClient2); + s2 = new QuorumPeer(peers, s2dir, s2dir, portClient2, 3, 2, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient2, s2.getClientPort()); + LOG.info("creating QuorumPeer 3 port " + portClient3); + s3 = new QuorumPeer(peers, s3dir, s3dir, portClient3, 3, 3, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient3, s3.getClientPort()); + LOG.info("creating QuorumPeer 4 port " + portClient4); + s4 = new QuorumPeer(peers, s4dir, s4dir, portClient4, 3, 4, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient4, s4.getClientPort()); + LOG.info("creating QuorumPeer 5 port " + portClient5); + s5 = new QuorumPeer(peers, s5dir, s5dir, portClient5, 3, 5, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient5, s5.getClientPort()); + + if (withObservers) { + s4.setLearnerType(LearnerType.OBSERVER); + s5.setLearnerType(LearnerType.OBSERVER); + } + + LOG.info("QuorumPeer 1 voting view: " + s1.getVotingView()); + LOG.info("QuorumPeer 2 voting view: " + s2.getVotingView()); + LOG.info("QuorumPeer 3 voting view: " + s3.getVotingView()); + LOG.info("QuorumPeer 4 voting view: " + s4.getVotingView()); + LOG.info("QuorumPeer 5 voting view: " + s5.getVotingView()); + + s1.enableLocalSessions(localSessionsEnabled); + s2.enableLocalSessions(localSessionsEnabled); + s3.enableLocalSessions(localSessionsEnabled); + s4.enableLocalSessions(localSessionsEnabled); + s5.enableLocalSessions(localSessionsEnabled); + s1.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled); + s2.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled); + s3.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled); + s4.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled); + s5.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled); + + LOG.info("start QuorumPeer 1"); + s1.start(); + LOG.info("start QuorumPeer 2"); + s2.start(); + LOG.info("start QuorumPeer 3"); + s3.start(); + LOG.info("start QuorumPeer 4"); + s4.start(); + LOG.info("start QuorumPeer 5"); + s5.start(); + LOG.info("started QuorumPeer 5"); + + LOG.info("Checking ports " + hostPort); + for (String hp : hostPort.split(",")) { + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(hp, + CONNECTION_TIMEOUT)); + LOG.info(hp + " is accepting client connections"); + } + + // interesting to see what's there... + JMXEnv.dump(); + // make sure we have these 5 servers listed + Set ensureNames = new LinkedHashSet(); + for (int i = 1; i <= 5; i++) { + ensureNames.add("InMemoryDataTree"); + } + for (int i = 1; i <= 5; i++) { + ensureNames.add("name0=ReplicatedServer_id" + i + + ",name1=replica." + i + ",name2="); + } + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { + ensureNames.add("name0=ReplicatedServer_id" + i + + ",name1=replica." + j); + } + } + for (int i = 1; i <= 5; i++) { + ensureNames.add("name0=ReplicatedServer_id" + i); + } + JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()])); + } + + public int getLeaderIndex() { + if (s1.getPeerState() == ServerState.LEADING) { + return 0; + } else if (s2.getPeerState() == ServerState.LEADING) { + return 1; + } else if (s3.getPeerState() == ServerState.LEADING) { + return 2; + } else if (s4.getPeerState() == ServerState.LEADING) { + return 3; + } else if (s5.getPeerState() == ServerState.LEADING) { + return 4; + } + return -1; + } + + public String getPeersMatching(ServerState state) { + StringBuilder hosts = new StringBuilder(); + for (QuorumPeer p : getPeerList()) { + if (p.getPeerState() == state) { + hosts.append(String.format("%s:%d,", LOCALADDR, p.getClientAddress().getPort())); + } + } + LOG.info("getPeersMatching ports are {}", hosts); + return hosts.toString(); + } + + public ArrayList getPeerList() { + ArrayList peers = new ArrayList(); + peers.add(s1); + peers.add(s2); + peers.add(s3); + peers.add(s4); + peers.add(s5); + return peers; + } + + public void setupServers() throws IOException { + setupServer(1); + setupServer(2); + setupServer(3); + setupServer(4); + setupServer(5); + } + + public void setupServer(int i) throws IOException { + int tickTime = 2000; + int initLimit = 3; + int syncLimit = 3; + + if (peers == null) { + peers = new HashMap(); + + peers.put(Long.valueOf(1), new QuorumServer(1, + new InetSocketAddress(LOCALADDR, port1), + new InetSocketAddress(LOCALADDR, portLE1), + new InetSocketAddress(LOCALADDR, portClient1), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(2), new QuorumServer(2, + new InetSocketAddress(LOCALADDR, port2), + new InetSocketAddress(LOCALADDR, portLE2), + new InetSocketAddress(LOCALADDR, portClient2), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(3), new QuorumServer(3, + new InetSocketAddress(LOCALADDR, port3), + new InetSocketAddress(LOCALADDR, portLE3), + new InetSocketAddress(LOCALADDR, portClient3), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(4), new QuorumServer(4, + new InetSocketAddress(LOCALADDR, port4), + new InetSocketAddress(LOCALADDR, portLE4), + new InetSocketAddress(LOCALADDR, portClient4), + LearnerType.PARTICIPANT)); + peers.put(Long.valueOf(5), new QuorumServer(5, + new InetSocketAddress(LOCALADDR, port5), + new InetSocketAddress(LOCALADDR, portLE5), + new InetSocketAddress(LOCALADDR, portClient5), + LearnerType.PARTICIPANT)); + } + + switch (i) { + case 1: + LOG.info("creating QuorumPeer 1 port " + portClient1); + s1 = new QuorumPeer(peers, s1dir, s1dir, portClient1, 3, 1, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient1, s1.getClientPort()); + break; + case 2: + LOG.info("creating QuorumPeer 2 port " + portClient2); + s2 = new QuorumPeer(peers, s2dir, s2dir, portClient2, 3, 2, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient2, s2.getClientPort()); + break; + case 3: + LOG.info("creating QuorumPeer 3 port " + portClient3); + s3 = new QuorumPeer(peers, s3dir, s3dir, portClient3, 3, 3, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient3, s3.getClientPort()); + break; + case 4: + LOG.info("creating QuorumPeer 4 port " + portClient4); + s4 = new QuorumPeer(peers, s4dir, s4dir, portClient4, 3, 4, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient4, s4.getClientPort()); + break; + case 5: + LOG.info("creating QuorumPeer 5 port " + portClient5); + s5 = new QuorumPeer(peers, s5dir, s5dir, portClient5, 3, 5, tickTime, initLimit, syncLimit); + Assert.assertEquals(portClient5, s5.getClientPort()); + } + } + + @Override + public void tearDown() throws Exception { + LOG.info("TearDown started"); + + OSMXBean osMbean = new OSMXBean(); + if (osMbean.getUnix() == true) { + LOG.info("fdcount after test is: " + + osMbean.getOpenFileDescriptorCount()); + } + + shutdownServers(); + + for (String hp : hostPort.split(",")) { + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(hp, + ClientBase.CONNECTION_TIMEOUT)); + LOG.info(hp + " is no longer accepting client connections"); + } + + JMXEnv.tearDown(); + } + + public void shutdownServers() { + shutdown(s1); + shutdown(s2); + shutdown(s3); + shutdown(s4); + shutdown(s5); + } + + protected TestableZooKeeper createClient() + throws IOException, InterruptedException { + return createClient(hostPort); + } + + protected TestableZooKeeper createClient(String hp) + throws IOException, InterruptedException { + CountdownWatcher watcher = new CountdownWatcher(); + return createClient(watcher, hp); + } + + protected TestableZooKeeper createClient(CountdownWatcher watcher, ServerState state) + throws IOException, InterruptedException { + return createClient(watcher, getPeersMatching(state)); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java b/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java new file mode 100644 index 00000000000..c4ef634fe30 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumHammerTest.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class QuorumHammerTest extends ZKTestCase { + public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; + protected static final Logger LOG = LoggerFactory.getLogger(QuorumHammerTest.class); + protected final QuorumBase qb = new QuorumBase(); + protected final ClientHammerTest cht = new ClientHammerTest(); + + @Before + public void setUp() throws Exception { + qb.setUp(); + cht.hostPort = qb.hostPort; + cht.setUpAll(); + } + + @After + public void tearDown() throws Exception { + cht.tearDownAll(); + qb.tearDown(); + } + + @Test + public void testHammerBasic() throws Throwable { + cht.testHammerBasic(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java b/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java new file mode 100644 index 00000000000..28ba9fc5528 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class QuorumMajorityTest extends QuorumBase { + public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; + protected static final Logger LOG = LoggerFactory.getLogger(QuorumMajorityTest.class); + + /***************************************************************/ + /* Test that the majority quorum verifier only counts votes from */ + /* followers in its view */ + + /***************************************************************/ + @Test + public void testMajQuorums() throws Throwable { + + //setup servers 1-5 to be followers + setUp(false); + + Proposal p = new Proposal(); + + p.addQuorumVerifier(s1.getQuorumVerifier()); + + // 2 followers out of 5 is not a majority + p.addAck(Long.valueOf(1)); + p.addAck(Long.valueOf(2)); + Assert.assertEquals(false, p.hasAllQuorums()); + + // 6 is not in the view - its vote shouldn't count + p.addAck(Long.valueOf(6)); + Assert.assertEquals(false, p.hasAllQuorums()); + + // 3 followers out of 5 are a majority of the voting view + p.addAck(Long.valueOf(3)); + Assert.assertEquals(true, p.hasAllQuorums()); + + //setup servers 1-3 to be followers and 4 and 5 to be observers + setUp(true); + + p = new Proposal(); + p.addQuorumVerifier(s1.getQuorumVerifier()); + + // 1 follower out of 3 is not a majority + p.addAck(Long.valueOf(1)); + Assert.assertEquals(false, p.hasAllQuorums()); + + // 4 and 5 are observers, their vote shouldn't count + p.addAck(Long.valueOf(4)); + p.addAck(Long.valueOf(5)); + Assert.assertEquals(false, p.hasAllQuorums()); + + // 6 is not in the view - its vote shouldn't count + p.addAck(Long.valueOf(6)); + Assert.assertEquals(false, p.hasAllQuorums()); + + // 2 followers out of 3 are a majority of the voting view + p.addAck(Long.valueOf(2)); + Assert.assertEquals(true, p.hasAllQuorums()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumQuotaTest.java b/src/java/test/org/apache/zookeeper/test/QuorumQuotaTest.java new file mode 100644 index 00000000000..59122d79340 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumQuotaTest.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.Quotas; +import org.apache.zookeeper.StatsTrack; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeperMain; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; + +public class QuorumQuotaTest extends QuorumBase { + + @Test + public void testQuotaWithQuorum() throws Exception { + ZooKeeper zk = createClient(); + zk.setData("/", "some".getBytes(), -1); + zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + int i = 0; + for (i = 0; i < 300; i++) { + zk.create("/a/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + ZooKeeperMain.createQuota(zk, "/a", 1000L, 5000); + String statPath = Quotas.quotaZookeeper + "/a" + "/" + Quotas.statNode; + byte[] data = zk.getData(statPath, false, new Stat()); + StatsTrack st = new StatsTrack(new String(data)); + Assert.assertTrue("bytes are set", st.getBytes() == 1204L); + Assert.assertTrue("num count is set", st.getCount() == 301); + for (i = 300; i < 600; i++) { + zk.create("/a/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + data = zk.getData(statPath, false, new Stat()); + st = new StatsTrack(new String(data)); + Assert.assertTrue("bytes are set", st.getBytes() == 2404L); + Assert.assertTrue("num count is set", st.getCount() == 601); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumTest.java b/src/java/test/org/apache/zookeeper/test/QuorumTest.java new file mode 100644 index 00000000000..b4c4fc183e2 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumTest.java @@ -0,0 +1,455 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.quorum.Leader; +import org.apache.zookeeper.server.quorum.LearnerHandler; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class QuorumTest extends ZKTestCase { + public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; + private static final Logger LOG = LoggerFactory.getLogger(QuorumTest.class); + private final QuorumBase qb = new QuorumBase(); + private final ClientTest ct = new ClientTest(); + volatile int counter = 0; + volatile int errors = 0; + private QuorumUtil qu; + + @Before + public void setUp() throws Exception { + qb.setUp(); + ct.hostPort = qb.hostPort; + ct.setUpAll(); + } + + @After + public void tearDown() throws Exception { + ct.tearDownAll(); + qb.tearDown(); + if (qu != null) { + qu.tearDown(); + } + } + + @Test + public void testDeleteWithChildren() throws Exception { + ct.testDeleteWithChildren(); + } + + @Test + public void testPing() throws Exception { + ct.testPing(); + } + + @Test + public void testSequentialNodeNames() + throws IOException, InterruptedException, KeeperException { + ct.testSequentialNodeNames(); + } + + @Test + public void testACLs() throws Exception { + ct.testACLs(); + } + + @Test + public void testClientwithoutWatcherObj() throws IOException, + InterruptedException, KeeperException { + ct.testClientwithoutWatcherObj(); + } + + @Test + public void testClientWithWatcherObj() throws IOException, + InterruptedException, KeeperException { + ct.testClientWithWatcherObj(); + } + + @Test + public void testGetView() { + Assert.assertEquals(5, qb.s1.getView().size()); + Assert.assertEquals(5, qb.s2.getView().size()); + Assert.assertEquals(5, qb.s3.getView().size()); + Assert.assertEquals(5, qb.s4.getView().size()); + Assert.assertEquals(5, qb.s5.getView().size()); + } + + @Test + public void testViewContains() { + // Test view contains self + Assert.assertTrue(qb.s1.viewContains(qb.s1.getId())); + + // Test view contains other servers + Assert.assertTrue(qb.s1.viewContains(qb.s2.getId())); + + // Test view does not contain non-existant servers + Assert.assertFalse(qb.s1.viewContains(-1L)); + } + + @Test + public void testLeaderShutdown() throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = new DisconnectableZooKeeper(qb.hostPort, ClientBase.CONNECTION_TIMEOUT, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.create("/blah/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Leader leader = qb.s1.leader; + if (leader == null) leader = qb.s2.leader; + if (leader == null) leader = qb.s3.leader; + if (leader == null) leader = qb.s4.leader; + if (leader == null) leader = qb.s5.leader; + Assert.assertNotNull(leader); + for (int i = 0; i < 5000; i++) { + zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() { + public void processResult(int rc, String path, Object ctx, + Stat stat) { + counter++; + if (rc != 0) { + errors++; + } + } + }, null); + } + for (LearnerHandler f : leader.getForwardingFollowers()) { + f.getSocket().shutdownInput(); + } + for (int i = 0; i < 5000; i++) { + zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() { + public void processResult(int rc, String path, Object ctx, + Stat stat) { + counter++; + if (rc != 0) { + errors++; + } + } + }, null); + } + // check if all the followers are alive + Assert.assertTrue(qb.s1.isAlive()); + Assert.assertTrue(qb.s2.isAlive()); + Assert.assertTrue(qb.s3.isAlive()); + Assert.assertTrue(qb.s4.isAlive()); + Assert.assertTrue(qb.s5.isAlive()); + zk.close(); + } + + @Test + public void testMultipleWatcherObjs() throws IOException, + InterruptedException, KeeperException { + ct.testMutipleWatcherObjs(); + } + + /** + * Make sure that we can change sessions + * from follower to leader. + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void testSessionMoved() throws Exception { + String hostPorts[] = qb.hostPort.split(","); + DisconnectableZooKeeper zk = new DisconnectableZooKeeper(hostPorts[0], + ClientBase.CONNECTION_TIMEOUT, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/sessionMoveTest", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + // we want to loop through the list twice + for (int i = 0; i < hostPorts.length * 2; i++) { + zk.dontReconnect(); + // This should stomp the zk handle + DisconnectableZooKeeper zknew = + new DisconnectableZooKeeper(hostPorts[(i + 1) % hostPorts.length], + ClientBase.CONNECTION_TIMEOUT, + new Watcher() { + public void process(WatchedEvent event) { + } + }, + zk.getSessionId(), + zk.getSessionPasswd()); + zknew.setData("/", new byte[1], -1); + final int result[] = new int[1]; + result[0] = Integer.MAX_VALUE; + zknew.sync("/", new AsyncCallback.VoidCallback() { + public void processResult(int rc, String path, Object ctx) { + synchronized (result) { + result[0] = rc; + result.notify(); + } + } + }, null); + synchronized (result) { + if (result[0] == Integer.MAX_VALUE) { + result.wait(5000); + } + } + LOG.info(hostPorts[(i + 1) % hostPorts.length] + " Sync returned " + result[0]); + Assert.assertTrue(result[0] == KeeperException.Code.OK.intValue()); + try { + zk.setData("/", new byte[1], -1); + Assert.fail("Should have lost the connection"); + } catch (KeeperException.ConnectionLossException e) { + } + zk = zknew; + } + zk.close(); + } + + /** + * Connect to two different servers with two different handles using the same session and + * make sure we cannot do any changes. + */ + @Test + @Ignore + public void testSessionMove() throws Exception { + String hps[] = qb.hostPort.split(","); + DiscoWatcher oldWatcher = new DiscoWatcher(); + DisconnectableZooKeeper zk = new DisconnectableZooKeeper(hps[0], + ClientBase.CONNECTION_TIMEOUT, oldWatcher); + zk.create("/t1", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + zk.dontReconnect(); + // This should stomp the zk handle + DiscoWatcher watcher = new DiscoWatcher(); + DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(hps[1], + ClientBase.CONNECTION_TIMEOUT, watcher, zk.getSessionId(), + zk.getSessionPasswd()); + zknew.create("/t2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + try { + zk.create("/t3", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + Assert.fail("Should have lost the connection"); + } catch (KeeperException.ConnectionLossException e) { + // wait up to 30 seconds for the disco to be delivered + for (int i = 0; i < 30; i++) { + if (oldWatcher.zkDisco) { + break; + } + Thread.sleep(1000); + } + Assert.assertTrue(oldWatcher.zkDisco); + } + + ArrayList toClose = new ArrayList(); + toClose.add(zknew); + // Let's just make sure it can still move + for (int i = 0; i < 10; i++) { + zknew.dontReconnect(); + zknew = new DisconnectableZooKeeper(hps[1], + ClientBase.CONNECTION_TIMEOUT, new DiscoWatcher(), + zk.getSessionId(), zk.getSessionPasswd()); + toClose.add(zknew); + zknew.create("/t-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + } + for (ZooKeeper z : toClose) { + z.close(); + } + zk.close(); + } + + /** + * See ZOOKEEPER-790 for details + * */ + @Test + public void testFollowersStartAfterLeader() throws Exception { + qu = new QuorumUtil(1); + CountdownWatcher watcher = new CountdownWatcher(); + qu.startQuorum(); + + int index = 1; + while (qu.getPeer(index).peer.leader == null) + index++; + + // break the quorum + qu.shutdown(index); + + // try to reestablish the quorum + qu.start(index); + + // Connect the client after services are restarted (otherwise we would get + // SessionExpiredException as the previous local session was not persisted). + ZooKeeper zk = new ZooKeeper( + "127.0.0.1:" + qu.getPeer((index == 1) ? 2 : 1).peer.getClientPort(), + ClientBase.CONNECTION_TIMEOUT, watcher); + + try { + watcher.waitForConnected(CONNECTION_TIMEOUT); + } catch (TimeoutException e) { + Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds."); + } + + zk.close(); + } + + /** + * Tests if closeSession can be logged before a leader gets established, which + * could lead to a locked-out follower (see ZOOKEEPER-790). + * + * The test works as follows. It has a client connecting to a follower f and + * sending batches of 1,000 updates. The goal is that f has a zxid higher than + * all other servers in the initial leader election. This way we can crash and + * recover the follower so that the follower believes it is the leader once it + * recovers (LE optimization: once a server receives a message from all other + * servers, it picks a leader. + * + * It also makes the session timeout very short so that we force the false + * leader to close the session and write it to the log in the buggy code (before + * ZOOKEEPER-790). Once f drops leadership and finds the current leader, its epoch + * is higher, and it rejects the leader. Now, if we prevent the leader from closing + * the session by only starting up (see Leader.lead()) once it obtains a quorum of + * supporters, then f will find the current leader and support it because it won't + * have a highe epoch. + * + */ + @Test + public void testNoLogBeforeLeaderEstablishment() throws Exception { + final Semaphore sem = new Semaphore(0); + + qu = new QuorumUtil(2, 10); + qu.startQuorum(); + + int index = 1; + while (qu.getPeer(index).peer.leader == null) + index++; + + Leader leader = qu.getPeer(index).peer.leader; + + Assert.assertNotNull(leader); + + /* + * Reusing the index variable to select a follower to connect to + */ + index = (index == 1) ? 2 : 1; + + ZooKeeper zk = new DisconnectableZooKeeper( + "127.0.0.1:" + qu.getPeer(index).peer.getClientPort(), + ClientBase.CONNECTION_TIMEOUT, new Watcher() { + public void process(WatchedEvent event) { + } + }); + + zk.create("/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + for (int i = 0; i < 50000; i++) { + zk.setData("/blah", new byte[0], -1, new AsyncCallback.StatCallback() { + public void processResult(int rc, String path, Object ctx, + Stat stat) { + counter++; + if (rc != 0) { + errors++; + } + if (counter == 20000) { + sem.release(); + } + } + }, null); + + if (i == 5000) { + qu.shutdown(index); + LOG.info("Shutting down s1"); + } + if (i == 12000) { + qu.start(index); + LOG.info("Setting up server: " + index); + } + if ((i % 1000) == 0) { + Thread.sleep(500); + } + } + + // Wait until all updates return + sem.tryAcquire(15, TimeUnit.SECONDS); + + // Verify that server is following and has the same epoch as the leader + Assert.assertTrue("Not following", qu.getPeer(index).peer.follower != null); + long epochF = (qu.getPeer(index).peer.getActiveServer().getZxid() >> 32L); + long epochL = (leader.getEpoch() >> 32L); + Assert.assertTrue("Zxid: " + qu.getPeer(index).peer.getActiveServer().getZxid() + + "Current epoch: " + epochF, epochF == epochL); + + zk.close(); + } + + /** + * Tests if a multiop submitted to a non-leader propagates to the leader properly + * (see ZOOKEEPER-1124). + * + * The test works as follows. It has a client connect to a follower and submit a multiop + * to the follower. It then verifies that the multiop successfully gets committed by the leader. + * + * Without the fix in ZOOKEEPER-1124, this fails with a ConnectionLoss KeeperException. + */ + @Test + public void testMultiToFollower() throws Exception { + qu = new QuorumUtil(1); + CountdownWatcher watcher = new CountdownWatcher(); + qu.startQuorum(); + + int index = 1; + while (qu.getPeer(index).peer.leader == null) + index++; + + ZooKeeper zk = new ZooKeeper( + "127.0.0.1:" + qu.getPeer((index == 1) ? 2 : 1).peer.getClientPort(), + ClientBase.CONNECTION_TIMEOUT, watcher); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + zk.multi(Arrays.asList( + Op.create("/multi0", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.create("/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), + Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT) + )); + zk.getData("/multi0", false, null); + zk.getData("/multi1", false, null); + zk.getData("/multi2", false, null); + + zk.close(); + } + + // skip superhammer and clientcleanup as they are too expensive for quorum + + private static class DiscoWatcher implements Watcher { + volatile boolean zkDisco = false; + + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.Disconnected) { + zkDisco = true; + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumUtil.java b/src/java/test/org/apache/zookeeper/test/QuorumUtil.java new file mode 100644 index 00000000000..9b628bda52f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumUtil.java @@ -0,0 +1,312 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.server.quorum.Election; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.util.OSMXBean; +import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Utility for quorum testing. Setups 2n+1 peers and allows to start/stop all + * peers, particular peer, n peers etc. + */ +public class QuorumUtil { + + // TODO partitioning of peers and clients + + // TODO refactor QuorumBase to be special case of this + + private static final Logger LOG = LoggerFactory.getLogger(QuorumUtil.class); + public final int N; + public final int ALL; + private final Map peersView = new HashMap(); + private final Map peers = new HashMap(); + // This was added to avoid running into the problem of ZOOKEEPER-1539 + public boolean disableJMXTest = false; + private String hostPort; + + private int tickTime; + + private int initLimit; + + private int syncLimit; + + private int electionAlg; + + private boolean localSessionEnabled; + + /** + * Initializes 2n+1 quorum peers which will form a ZooKeeper ensemble. + * + * @param n + * number of peers in the ensemble will be 2n+1 + */ + public QuorumUtil(int n, int syncLimit) throws RuntimeException { + try { + ClientBase.setupTestEnv(); + JMXEnv.setUp(); + + N = n; + ALL = 2 * N + 1; + tickTime = 2000; + initLimit = 3; + this.syncLimit = syncLimit; + electionAlg = 3; + hostPort = ""; + + for (int i = 1; i <= ALL; ++i) { + PeerStruct ps = new PeerStruct(); + ps.id = i; + ps.dataDir = ClientBase.createTmpDir(); + ps.clientPort = PortAssignment.unique(); + peers.put(i, ps); + + peersView.put(Long.valueOf(i), new QuorumServer(i, + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", ps.clientPort), + LearnerType.PARTICIPANT)); + hostPort += "127.0.0.1:" + ps.clientPort + ((i == ALL) ? "" : ","); + } + for (int i = 1; i <= ALL; ++i) { + PeerStruct ps = peers.get(i); + LOG.info("Creating QuorumPeer " + i + "; public port " + ps.clientPort); + ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, + electionAlg, ps.id, tickTime, initLimit, syncLimit); + Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public QuorumUtil(int n) throws RuntimeException { + this(n, 3); + } + + public PeerStruct getPeer(int id) { + return peers.get(id); + } + + public void enableLocalSession(boolean localSessionEnabled) { + this.localSessionEnabled = localSessionEnabled; + } + + public void startAll() throws IOException { + shutdownAll(); + for (int i = 1; i <= ALL; ++i) { + start(i); + LOG.info("Started QuorumPeer " + i); + } + + LOG.info("Checking ports " + hostPort); + for (String hp : hostPort.split(",")) { + Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(hp, + ClientBase.CONNECTION_TIMEOUT)); + LOG.info(hp + " is accepting client connections"); + } + + // This was added to avoid running into the problem of ZOOKEEPER-1539 + if (disableJMXTest) return; + + // interesting to see what's there... + try { + JMXEnv.dump(); + // make sure we have all servers listed + Set ensureNames = new LinkedHashSet(); + for (int i = 1; i <= ALL; ++i) { + ensureNames.add("InMemoryDataTree"); + } + for (int i = 1; i <= ALL; ++i) { + ensureNames + .add("name0=ReplicatedServer_id" + i + ",name1=replica." + i + ",name2="); + } + for (int i = 1; i <= ALL; ++i) { + for (int j = 1; j <= ALL; ++j) { + ensureNames.add("name0=ReplicatedServer_id" + i + ",name1=replica." + j); + } + } + for (int i = 1; i <= ALL; ++i) { + ensureNames.add("name0=ReplicatedServer_id" + i); + } + JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()])); + } catch (IOException e) { + LOG.warn("IOException during JMXEnv operation", e); + } catch (InterruptedException e) { + LOG.warn("InterruptedException during JMXEnv operation", e); + } + } + + /** + * Start first N+1 peers. + */ + public void startQuorum() throws IOException { + shutdownAll(); + for (int i = 1; i <= N + 1; ++i) { + start(i); + } + for (int i = 1; i <= N + 1; ++i) { + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + getPeer(i).clientPort, ClientBase.CONNECTION_TIMEOUT)); + } + } + + public void start(int id) throws IOException { + PeerStruct ps = getPeer(id); + LOG.info("Creating QuorumPeer " + ps.id + "; public port " + ps.clientPort); + ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, electionAlg, + ps.id, tickTime, initLimit, syncLimit); + if (localSessionEnabled) { + ps.peer.enableLocalSessions(true); + } + Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); + + ps.peer.start(); + } + + public void restart(int id) throws IOException { + start(id); + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + getPeer(id).clientPort, ClientBase.CONNECTION_TIMEOUT)); + } + + public void startThenShutdown(int id) throws IOException { + PeerStruct ps = getPeer(id); + LOG.info("Creating QuorumPeer " + ps.id + "; public port " + ps.clientPort); + ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, electionAlg, + ps.id, tickTime, initLimit, syncLimit); + if (localSessionEnabled) { + ps.peer.enableLocalSessions(true); + } + Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); + + ps.peer.start(); + Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + + getPeer(id).clientPort, ClientBase.CONNECTION_TIMEOUT)); + shutdown(id); + } + + public void shutdownAll() { + for (int i = 1; i <= ALL; ++i) { + shutdown(i); + } + for (String hp : hostPort.split(",")) { + Assert.assertTrue("Waiting for server down", ClientBase.waitForServerDown(hp, + ClientBase.CONNECTION_TIMEOUT)); + LOG.info(hp + " is no longer accepting client connections"); + } + } + + public void shutdown(int id) { + QuorumPeer qp = getPeer(id).peer; + try { + LOG.info("Shutting down quorum peer " + qp.getName()); + qp.shutdown(); + Election e = qp.getElectionAlg(); + if (e != null) { + LOG.info("Shutting down leader election " + qp.getName()); + e.shutdown(); + } else { + LOG.info("No election available to shutdown " + qp.getName()); + } + LOG.info("Waiting for " + qp.getName() + " to exit thread"); + qp.join(30000); + if (qp.isAlive()) { + Assert.fail("QP failed to shutdown in 30 seconds: " + qp.getName()); + } + } catch (InterruptedException e) { + LOG.debug("QP interrupted: " + qp.getName(), e); + } + } + + public String getConnString() { + return hostPort; + } + + public String getConnectString(QuorumPeer peer) { + return "127.0.0.1:" + peer.getClientPort(); + } + + public QuorumPeer getLeaderQuorumPeer() { + for (PeerStruct ps : peers.values()) { + if (ps.peer.leader != null) { + return ps.peer; + } + } + throw new RuntimeException("Unable to find a leader peer"); + } + + public List getFollowerQuorumPeers() { + List peerList = new ArrayList(ALL - 1); + + for (PeerStruct ps : peers.values()) { + if (ps.peer.leader == null) { + peerList.add(ps.peer); + } + } + + return Collections.unmodifiableList(peerList); + } + + public void tearDown() throws Exception { + LOG.info("TearDown started"); + + OSMXBean osMbean = new OSMXBean(); + if (osMbean.getUnix() == true) { + LOG.info("fdcount after test is: " + osMbean.getOpenFileDescriptorCount()); + } + + shutdownAll(); + JMXEnv.tearDown(); + } + + public int getLeaderServer() { + int index = 0; + for (int i = 1; i <= ALL; i++) { + if (getPeer(i).peer.leader != null) { + index = i; + break; + } + } + + Assert.assertTrue("Leader server not found.", index > 0); + return index; + } + + public String getConnectionStringForServer(final int index) { + return "127.0.0.1:" + getPeer(index).clientPort; + } + + public static class PeerStruct { + public int id; + public QuorumPeer peer; + public File dataDir; + public int clientPort; + } +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumUtilTest.java b/src/java/test/org/apache/zookeeper/test/QuorumUtilTest.java new file mode 100644 index 00000000000..f66de77f1c6 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumUtilTest.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.jmx.MBeanRegistry; +import org.apache.zookeeper.jmx.ZKMBeanInfo; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Set; + +/** + * This class is intented to ensure the correct functionality of + * {@link QuorumUtil} helper. + */ +public class QuorumUtilTest extends ZKTestCase { + private static final Logger LOG = LoggerFactory + .getLogger(QuorumUtilTest.class); + + /** + *

        + * This test ensures that all JXM beans associated to a {@link QuorumPeer} + * are unregistered when shuted down ({@link QuorumUtil#shutdown(int)}). It + * allows a successfull restarting of several zookeeper servers ( + * {@link QuorumPeer}) running on the same JVM. + *

        + * See ZOOKEEPER-1214 for details. + */ + @Test + public void validateAllMXBeanAreUnregistered() throws IOException { + QuorumUtil qU = new QuorumUtil(1); + LOG.info(">-->> Starting up all servers..."); + qU.startAll(); + LOG.info(">-->> Servers up and running..."); + + int leaderIndex = qU.getLeaderServer(); + int firstFollowerIndex = 0; + int secondFollowerIndex = 0; + + switch (leaderIndex) { + case 1: + firstFollowerIndex = 2; + secondFollowerIndex = 3; + break; + case 2: + firstFollowerIndex = 1; + secondFollowerIndex = 3; + break; + case 3: + firstFollowerIndex = 1; + secondFollowerIndex = 2; + break; + + default: + Assert.fail("Unexpected leaderIndex value: " + leaderIndex); + break; + } + + LOG.info(">-->> Shuting down server [{}]", firstFollowerIndex); + qU.shutdown(firstFollowerIndex); + LOG.info(">-->> Shuting down server [{}]", secondFollowerIndex); + qU.shutdown(secondFollowerIndex); + LOG.info(">-->> Restarting server [{}]", firstFollowerIndex); + qU.restart(firstFollowerIndex); + LOG.info(">-->> Restarting server [{}]", secondFollowerIndex); + qU.restart(secondFollowerIndex); + + qU.shutdownAll(); + Set pending = MBeanRegistry.getInstance() + .getRegisteredBeans(); + Assert.assertTrue("The following beans should have been unregistered: " + + pending, pending.isEmpty()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/QuorumZxidSyncTest.java b/src/java/test/org/apache/zookeeper/test/QuorumZxidSyncTest.java new file mode 100644 index 00000000000..7fb77b9365a --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/QuorumZxidSyncTest.java @@ -0,0 +1,171 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +public class QuorumZxidSyncTest extends ZKTestCase { + QuorumBase qb = new QuorumBase(); + + @Before + public void setUp() throws Exception { + qb.setUp(); + } + + /** + * find out what happens when a follower connects to leader that is behind + */ + @Test + public void testBehindLeader() throws Exception { + // crank up the epoch numbers + ClientBase.waitForServerUp(qb.hostPort, 10000); + ClientBase.waitForServerUp(qb.hostPort, 10000); + ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/0", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.close(); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/1", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.close(); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.close(); + qb.shutdownServers(); + deleteFiles(qb.s1dir); + deleteFiles(qb.s2dir); + deleteFiles(qb.s3dir); + deleteFiles(qb.s4dir); + qb.setupServers(); + qb.s1.start(); + qb.s2.start(); + qb.s3.start(); + qb.s4.start(); + Assert.assertTrue("Servers didn't come up", ClientBase.waitForServerUp(qb.hostPort, 10000)); + qb.s5.start(); + String hostPort = "127.0.0.1:" + qb.s5.getClientPort(); + Assert.assertFalse("Servers came up, but shouldn't have since it's ahead of leader", + ClientBase.waitForServerUp(hostPort, 10000)); + } + + private void deleteFiles(File f) { + File v = new File(f, "version-2"); + for (File c : v.listFiles()) { + c.delete(); + } + } + + /** + * find out what happens when the latest state is in the snapshots not + * the logs. + */ + @Test + public void testLateLogs() throws Exception { + // crank up the epoch numbers + ClientBase.waitForServerUp(qb.hostPort, 10000); + ClientBase.waitForServerUp(qb.hostPort, 10000); + ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/0", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.close(); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/1", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.close(); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + qb.shutdownServers(); + deleteLogs(qb.s1dir); + deleteLogs(qb.s2dir); + deleteLogs(qb.s3dir); + deleteLogs(qb.s4dir); + deleteLogs(qb.s5dir); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + zk.create("/2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.close(); + qb.shutdownServers(); + qb.startServers(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + boolean saw2 = false; + for (String child : zk.getChildren("/", false)) { + if (child.equals("2")) { + saw2 = true; + } + } + zk.close(); + Assert.assertTrue("Didn't see /2 (went back in time)", saw2); + } + + private void deleteLogs(File f) { + File v = new File(f, "version-2"); + for (File c : v.listFiles()) { + if (c.getName().startsWith("log")) { + c.delete(); + } + } + } + + @After + public void tearDown() throws Exception { + qb.tearDown(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java b/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java new file mode 100644 index 00000000000..c0844d1bcd9 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java @@ -0,0 +1,297 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.WriterAppender; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.NotReadOnlyException; +import org.apache.zookeeper.Transaction; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeper.States; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.LineNumberReader; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class ReadOnlyModeTest extends ZKTestCase { + private static int CONNECTION_TIMEOUT = QuorumBase.CONNECTION_TIMEOUT; + private QuorumUtil qu = new QuorumUtil(1); + + @Before + public void setUp() throws Exception { + System.setProperty("readonlymode.enabled", "true"); + qu.startQuorum(); + } + + @After + public void tearDown() throws Exception { + System.setProperty("readonlymode.enabled", "false"); + qu.tearDown(); + } + + /** + * Test write operations using multi request. + */ + @Test(timeout = 90000) + public void testMultiTransaction() throws Exception { + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, + watcher, true); + watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected + + final String data = "Data to be read in RO mode"; + final String node1 = "/tnode1"; + final String node2 = "/tnode2"; + zk.create(node1, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + watcher.reset(); + qu.shutdown(2); + watcher.waitForConnected(CONNECTION_TIMEOUT); + Assert.assertEquals("Should be in r-o mode", States.CONNECTEDREADONLY, + zk.getState()); + + // read operation during r/o mode + String remoteData = new String(zk.getData(node1, false, null)); + Assert.assertEquals("Failed to read data in r-o mode", data, remoteData); + + try { + Transaction transaction = zk.transaction(); + transaction.setData(node1, "no way".getBytes(), -1); + transaction.create(node2, data.getBytes(), + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + transaction.commit(); + Assert.fail("Write operation using multi-transaction" + + " api has succeeded during RO mode"); + } catch (NotReadOnlyException e) { + // ok + } + + Assert.assertNull("Should have created the znode:" + node2, + zk.exists(node2, false)); + } + + /** + * Basic test of read-only client functionality. Tries to read and write + * during read-only mode, then regains a quorum and tries to write again. + */ + @Test(timeout = 90000) + public void testReadOnlyClient() throws Exception { + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, + watcher, true); + watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected + + final String data = "Data to be read in RO mode"; + final String node = "/tnode"; + zk.create(node, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + watcher.reset(); + qu.shutdown(2); + zk.close(); + + // Re-connect the client (in case we were connected to the shut down + // server and the local session was not persisted). + zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, + watcher, true); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + // read operation during r/o mode + String remoteData = new String(zk.getData(node, false, null)); + Assert.assertEquals(data, remoteData); + + try { + zk.setData(node, "no way".getBytes(), -1); + Assert.fail("Write operation has succeeded during RO mode"); + } catch (NotReadOnlyException e) { + // ok + } + + watcher.reset(); + qu.start(2); + Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp( + "127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT)); + zk.close(); + watcher.reset(); + + // Re-connect the client (in case we were connected to the shut down + // server and the local session was not persisted). + zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, + watcher, true); + watcher.waitForConnected(CONNECTION_TIMEOUT); + zk.setData(node, "We're in the quorum now".getBytes(), -1); + + zk.close(); + } + + /** + * Ensures that upon connection to a read-only server client receives + * ConnectedReadOnly state notification. + */ + @Test(timeout = 90000) + public void testConnectionEvents() throws Exception { + final List states = new ArrayList(); + ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, + new Watcher() { + public void process(WatchedEvent event) { + states.add(event.getState()); + } + }, true); + boolean success = false; + for (int i = 0; i < 30; i++) { + try { + zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + success = true; + break; + } catch (KeeperException.ConnectionLossException e) { + Thread.sleep(1000); + } + } + Assert.assertTrue("Did not succeed in connecting in 30s", success); + + // kill peer and wait no more than 5 seconds for read-only server + // to be started (which should take one tickTime (2 seconds)) + qu.shutdown(2); + + // Re-connect the client (in case we were connected to the shut down + // server and the local session was not persisted). + zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, + new Watcher() { + public void process(WatchedEvent event) { + states.add(event.getState()); + } + }, true); + long start = Time.currentElapsedTime(); + while (!(zk.getState() == States.CONNECTEDREADONLY)) { + Thread.sleep(200); + // FIXME this was originally 5 seconds, but realistically, on random/slow/virt hosts, there is no way to guarantee this + Assert.assertTrue("Can't connect to the server", + Time.currentElapsedTime() - start < 30000); + } + + // At this point states list should contain, in the given order, + // SyncConnected, Disconnected, and ConnectedReadOnly states + Assert.assertTrue("ConnectedReadOnly event wasn't received", states + .get(2) == KeeperState.ConnectedReadOnly); + zk.close(); + } + + /** + * Tests a situation when client firstly connects to a read-only server and + * then connects to a majority server. Transition should be transparent for + * the user. + */ + @Test(timeout = 90000) + public void testSessionEstablishment() throws Exception { + qu.shutdown(2); + + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, + watcher, true); + watcher.waitForConnected(CONNECTION_TIMEOUT); + Assert.assertSame("should be in r/o mode", States.CONNECTEDREADONLY, zk + .getState()); + long fakeId = zk.getSessionId(); + + watcher.reset(); + qu.start(2); + Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp( + "127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT)); + watcher.waitForConnected(CONNECTION_TIMEOUT); + zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.assertFalse("fake session and real session have same id", zk + .getSessionId() == fakeId); + + zk.close(); + } + + /** + * Ensures that client seeks for r/w servers while it's connected to r/o + * server. + */ + @SuppressWarnings("deprecation") + @Test(timeout = 90000) + public void testSeekForRwServer() throws Exception { + // setup the logger to capture all logs + Layout layout = Logger.getRootLogger().getAppender("CONSOLE") + .getLayout(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + WriterAppender appender = new WriterAppender(layout, os); + appender.setImmediateFlush(true); + appender.setThreshold(Level.INFO); + Logger zlogger = Logger.getLogger("org.apache.zookeeper"); + zlogger.addAppender(appender); + + try { + qu.shutdown(2); + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper(qu.getConnString(), + CONNECTION_TIMEOUT, watcher, true); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + // if we don't suspend a peer it will rejoin a quorum + qu.getPeer(1).peer.suspend(); + + // start two servers to form a quorum; client should detect this and + // connect to one of them + watcher.reset(); + qu.start(2); + qu.start(3); + ClientBase.waitForServerUp(qu.getConnString(), 2000); + watcher.waitForConnected(CONNECTION_TIMEOUT); + zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + // resume poor fellow + qu.getPeer(1).peer.resume(); + } finally { + zlogger.removeAppender(appender); + } + + os.close(); + LineNumberReader r = new LineNumberReader(new StringReader(os + .toString())); + String line; + Pattern p = Pattern.compile(".*Majority server found.*"); + boolean found = false; + while ((line = r.readLine()) != null) { + if (p.matcher(line).matches()) { + found = true; + break; + } + } + Assert.assertTrue( + "Majority server wasn't found while connected to r/o server", + found); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ReconfigTest.java b/src/java/test/org/apache/zookeeper/test/ReconfigTest.java new file mode 100644 index 00000000000..c89e61a467f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ReconfigTest.java @@ -0,0 +1,935 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.DataCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.jmx.CommonNames; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical; +import org.apache.zookeeper.server.quorum.flexible.QuorumMaj; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class ReconfigTest extends ZKTestCase implements DataCallback { + private static final Logger LOG = LoggerFactory + .getLogger(ReconfigTest.class); + + private QuorumUtil qu; + + public static String reconfig(ZooKeeper zk, List joiningServers, + List leavingServers, List newMembers, long fromConfig) + throws KeeperException, InterruptedException { + byte[] config = null; + for (int j = 0; j < 30; j++) { + try { + config = zk.reconfig(joiningServers, leavingServers, + newMembers, fromConfig, new Stat()); + break; + } catch (KeeperException.ConnectionLossException e) { + if (j < 29) { + Thread.sleep(1000); + } else { + // test fails if we still can't connect to the quorum after + // 30 seconds. + Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds."); + } + } + } + + String configStr = new String(config); + if (joiningServers != null) { + for (String joiner : joiningServers) + Assert.assertTrue(configStr.contains(joiner)); + } + if (leavingServers != null) { + for (String leaving : leavingServers) + Assert.assertFalse(configStr.contains("server.".concat(leaving))); + } + + return configStr; + } + + public static String testServerHasConfig(ZooKeeper zk, + List joiningServers, List leavingServers) + throws KeeperException, InterruptedException { + byte[] config = null; + for (int j = 0; j < 30; j++) { + try { + zk.sync("/", null, null); + config = zk.getConfig(false, new Stat()); + break; + } catch (KeeperException.ConnectionLossException e) { + if (j < 29) { + Thread.sleep(1000); + } else { + // test fails if we still can't connect to the quorum after + // 30 seconds. + Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds."); + } + } + + } + String configStr = new String(config); + if (joiningServers != null) { + for (String joiner : joiningServers) { + Assert.assertTrue(configStr.contains(joiner)); + } + } + if (leavingServers != null) { + for (String leaving : leavingServers) + Assert.assertFalse(configStr.contains("server.".concat(leaving))); + } + + return configStr; + } + + public static void testNormalOperation(ZooKeeper writer, ZooKeeper reader) + throws KeeperException, InterruptedException { + boolean testNodeExists = false; + + for (int j = 0; j < 30; j++) { + try { + if (!testNodeExists) { + try { + writer.create("/test", "test".getBytes(), + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException e) { + } + testNodeExists = true; + } + String data = "test" + j; + writer.setData("/test", data.getBytes(), -1); + reader.sync("/", null, null); + byte[] res = reader.getData("/test", null, new Stat()); + Assert.assertEquals(data, new String(res)); + break; + } catch (KeeperException.ConnectionLossException e) { + if (j < 29) { + Thread.sleep(1000); + } else { + // test fails if we still can't connect to the quorum after + // 30 seconds. + Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds."); + } + } + + } + + } + + public static ZooKeeper[] createHandles(QuorumUtil qu) throws IOException { + // create an extra handle, so we can index the handles from 1 to qu.ALL + // using the server id. + ZooKeeper[] zkArr = new ZooKeeper[qu.ALL + 1]; + zkArr[0] = null; // not used. + for (int i = 1; i <= qu.ALL; i++) { + // server ids are 1, 2 and 3 + zkArr[i] = new ZooKeeper("127.0.0.1:" + + qu.getPeer(i).peer.getClientPort(), + ClientBase.CONNECTION_TIMEOUT, new Watcher() { + public void process(WatchedEvent event) { + } + }); + } + return zkArr; + } + + public static void closeAllHandles(ZooKeeper[] zkArr) throws InterruptedException { + for (ZooKeeper zk : zkArr) + if (zk != null) + zk.close(); + } + + @After + public void tearDown() throws Exception { + if (qu != null) { + qu.tearDown(); + } + } + + private int getLeaderId(QuorumUtil qu) { + int leaderId = 1; + while (qu.getPeer(leaderId).peer.leader == null) + leaderId++; + return leaderId; + } + + @Test + public void testRemoveAddOne() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + List leavingServers = new ArrayList(); + List joiningServers = new ArrayList(); + + int leaderIndex = getLeaderId(qu); + + // during first iteration, leavingIndex will correspond to a follower + // during second iteration leavingIndex will be the index of the leader + int leavingIndex = (leaderIndex == 1) ? 2 : 1; + + for (int i = 0; i < 2; i++) { + // some of the operations will be executed by a client connected to + // the removed server + // while others are invoked by a client connected to some other + // server. + // when we're removing the leader, zk1 will be the client connected + // to removed server + ZooKeeper zk1 = (leavingIndex == leaderIndex) ? zkArr[leaderIndex] + : zkArr[(leaderIndex % qu.ALL) + 1]; + ZooKeeper zk2 = (leavingIndex == leaderIndex) ? zkArr[(leaderIndex % qu.ALL) + 1] + : zkArr[leaderIndex]; + + leavingServers.add(Integer.toString(leavingIndex)); + + // remember this server so we can add it back later + joiningServers.add("server." + + leavingIndex + + "=localhost:" + + qu.getPeer(leavingIndex).peer.getQuorumAddress() + .getPort() + + ":" + + qu.getPeer(leavingIndex).peer.getElectionAddress() + .getPort() + ":participant;localhost:" + + qu.getPeer(leavingIndex).peer.getClientPort()); + + String configStr = reconfig(zk1, null, leavingServers, null, -1); + testServerHasConfig(zk2, null, leavingServers); + testNormalOperation(zk2, zk1); + + QuorumVerifier qv = qu.getPeer(1).peer.configFromString(configStr); + long version = qv.getVersion(); + + // checks that conditioning on version works properly + try { + reconfig(zk2, joiningServers, null, null, version + 1); + Assert.fail("reconfig succeeded even though version condition was incorrect!"); + } catch (KeeperException.BadVersionException e) { + + } + + reconfig(zk2, joiningServers, null, null, version); + + testNormalOperation(zk1, zk2); + testServerHasConfig(zk1, joiningServers, null); + + // second iteration of the loop will remove the leader + // and add it back (as follower) + leavingIndex = leaderIndex = getLeaderId(qu); + leavingServers.clear(); + joiningServers.clear(); + } + + closeAllHandles(zkArr); + } + + /** + * 1. removes and adds back two servers (incl leader). One of the servers is added back as observer + * 2. tests that reconfig fails if quorum of new config is not up + * 3. tests that a server that's not up during reconfig learns the new config when it comes up + * @throws Exception + */ + @Test + public void testRemoveAddTwo() throws Exception { + qu = new QuorumUtil(2); // create 5 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + List leavingServers = new ArrayList(); + List joiningServers = new ArrayList(); + + int leaderIndex = getLeaderId(qu); + + // lets remove the leader and some other server + int leavingIndex1 = leaderIndex; + int leavingIndex2 = (leaderIndex == 1) ? 2 : 1; + + // find some server that's staying + int stayingIndex1 = 1, stayingIndex2 = 1, stayingIndex3 = 1; + while (stayingIndex1 == leavingIndex1 || stayingIndex1 == leavingIndex2) + stayingIndex1++; + + while (stayingIndex2 == leavingIndex1 || stayingIndex2 == leavingIndex2 + || stayingIndex2 == stayingIndex1) + stayingIndex2++; + + while (stayingIndex3 == leavingIndex1 || stayingIndex3 == leavingIndex2 + || stayingIndex3 == stayingIndex1 + || stayingIndex3 == stayingIndex2) + stayingIndex3++; + + leavingServers.add(Integer.toString(leavingIndex1)); + leavingServers.add(Integer.toString(leavingIndex2)); + + // remember these servers so we can add them back later + joiningServers.add("server." + leavingIndex1 + "=localhost:" + + qu.getPeer(leavingIndex1).peer.getQuorumAddress().getPort() + + ":" + + qu.getPeer(leavingIndex1).peer.getElectionAddress().getPort() + + ":participant;localhost:" + + qu.getPeer(leavingIndex1).peer.getClientPort()); + + // this server will be added back as an observer + joiningServers.add("server." + leavingIndex2 + "=localhost:" + + qu.getPeer(leavingIndex2).peer.getQuorumAddress().getPort() + + ":" + + qu.getPeer(leavingIndex2).peer.getElectionAddress().getPort() + + ":observer;localhost:" + + qu.getPeer(leavingIndex2).peer.getClientPort()); + + qu.shutdown(leavingIndex1); + qu.shutdown(leavingIndex2); + + // 3 servers still up so this should work + reconfig(zkArr[stayingIndex2], null, leavingServers, null, -1); + + qu.shutdown(stayingIndex2); + + // the following commands would not work in the original + // cluster of 5, but now that we've removed 2 servers + // we have a cluster of 3 servers and one of them is allowed to fail + + testServerHasConfig(zkArr[stayingIndex1], null, leavingServers); + testServerHasConfig(zkArr[stayingIndex3], null, leavingServers); + testNormalOperation(zkArr[stayingIndex1], zkArr[stayingIndex3]); + + // this is a test that a reconfig will only succeed + // if there is a quorum up in new config. Below there is no + // quorum so it should fail + + // the sleep is necessary so that the leader figures out + // that the switched off servers are down + Thread.sleep(10000); + + try { + reconfig(zkArr[stayingIndex1], joiningServers, null, null, -1); + Assert.fail("reconfig completed successfully even though there is no quorum up in new config!"); + } catch (KeeperException.NewConfigNoQuorum e) { + + } + + // now start the third server so that new config has quorum + qu.restart(stayingIndex2); + + reconfig(zkArr[stayingIndex1], joiningServers, null, null, -1); + testNormalOperation(zkArr[stayingIndex2], zkArr[stayingIndex3]); + testServerHasConfig(zkArr[stayingIndex2], joiningServers, null); + + // this server wasn't around during the configuration change + // we should check that it is able to connect, finds out + // about the change and becomes an observer. + + qu.restart(leavingIndex2); + Assert.assertTrue(qu.getPeer(leavingIndex2).peer.getPeerState() == ServerState.OBSERVING); + testNormalOperation(zkArr[stayingIndex2], zkArr[leavingIndex2]); + testServerHasConfig(zkArr[leavingIndex2], joiningServers, null); + + closeAllHandles(zkArr); + } + + @Test + public void testBulkReconfig() throws Exception { + qu = new QuorumUtil(3); // create 7 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + // new config will have three of the servers as followers + // two of the servers as observers, and all ports different + ArrayList newServers = new ArrayList(); + for (int i = 1; i <= 5; i++) { + String server = "server." + i + "=localhost:" + PortAssignment.unique() + + ":" + PortAssignment.unique() + ":" + + ((i == 4 || i == 5) ? "observer" : "participant") + + ";localhost:" + qu.getPeer(i).peer.getClientPort(); + newServers.add(server); + } + + qu.shutdown(3); + qu.shutdown(6); + qu.shutdown(7); + + reconfig(zkArr[1], null, null, newServers, -1); + testNormalOperation(zkArr[1], zkArr[2]); + + testServerHasConfig(zkArr[1], newServers, null); + testServerHasConfig(zkArr[2], newServers, null); + testServerHasConfig(zkArr[4], newServers, null); + testServerHasConfig(zkArr[5], newServers, null); + + qu.shutdown(5); + qu.shutdown(4); + + testNormalOperation(zkArr[1], zkArr[2]); + + closeAllHandles(zkArr); + } + + @Test + public void testRemoveOneAsynchronous() throws Exception { + qu = new QuorumUtil(2); + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + List leavingServers = new ArrayList(); + + // lets remove someone who's not the leader + leavingServers.add(getLeaderId(qu) == 5 ? "4" : "5"); + + LinkedList results = new LinkedList(); + + zkArr[1].reconfig(null, leavingServers, null, -1, this, results); + + synchronized (results) { + while (results.size() < 1) { + results.wait(); + } + } + Assert.assertEquals(0, (int) results.get(0)); + + testNormalOperation(zkArr[1], zkArr[2]); + for (int i = 1; i <= 5; i++) + testServerHasConfig(zkArr[i], null, leavingServers); + + closeAllHandles(zkArr); + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, byte[] data, + Stat stat) { + synchronized (ctx) { + ((LinkedList) ctx).add(rc); + ctx.notifyAll(); + } + } + + + @Test + public void testRoleChange() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + // changing a server's role / port is done by "adding" it with the same + // id but different role / port + List joiningServers = new ArrayList(); + + int leaderIndex = getLeaderId(qu); + + // during first and second iteration, leavingIndex will correspond to a + // follower + // during third and fouth iteration leavingIndex will be the index of + // the leader + int changingIndex = (leaderIndex == 1) ? 2 : 1; + + // first convert participant to observer, then observer to participant, + // and so on + String newRole = "observer"; + + for (int i = 0; i < 4; i++) { + // some of the operations will be executed by a client connected to + // the removed server + // while others are invoked by a client connected to some other + // server. + // when we're removing the leader, zk1 will be the client connected + // to removed server + ZooKeeper zk1 = (changingIndex == leaderIndex) ? zkArr[leaderIndex] + : zkArr[(leaderIndex % qu.ALL) + 1]; + + // exactly as it is now, except for role change + joiningServers.add("server." + + changingIndex + + "=localhost:" + + qu.getPeer(changingIndex).peer.getQuorumAddress() + .getPort() + + ":" + + qu.getPeer(changingIndex).peer.getElectionAddress() + .getPort() + ":" + newRole + ";localhost:" + + qu.getPeer(changingIndex).peer.getClientPort()); + + reconfig(zk1, joiningServers, null, null, -1); + testNormalOperation(zkArr[changingIndex], zk1); + + if (newRole.equals("observer")) { + Assert.assertTrue(qu.getPeer(changingIndex).peer.observer != null + && qu.getPeer(changingIndex).peer.follower == null + && qu.getPeer(changingIndex).peer.leader == null); + Assert.assertTrue(qu.getPeer(changingIndex).peer.getPeerState() == ServerState.OBSERVING); + } else { + Assert.assertTrue(qu.getPeer(changingIndex).peer.observer == null + && (qu.getPeer(changingIndex).peer.follower != null || qu + .getPeer(changingIndex).peer.leader != null)); + Assert.assertTrue(qu.getPeer(changingIndex).peer.getPeerState() == ServerState.FOLLOWING + || qu.getPeer(changingIndex).peer.getPeerState() == ServerState.LEADING); + } + + joiningServers.clear(); + + if (newRole.equals("observer")) { + newRole = "participant"; + } else { + // lets change leader to observer + newRole = "observer"; + leaderIndex = getLeaderId(qu); + changingIndex = leaderIndex; + } + } + closeAllHandles(zkArr); + } + + @Test + public void testPortChange() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + List joiningServers = new ArrayList(); + + int leaderIndex = getLeaderId(qu); + int followerIndex = leaderIndex == 1 ? 2 : 1; + + // modify follower's client port + + int quorumPort = qu.getPeer(followerIndex).peer.getQuorumAddress().getPort(); + int electionPort = qu.getPeer(followerIndex).peer.getElectionAddress().getPort(); + int oldClientPort = qu.getPeer(followerIndex).peer.getClientPort(); + int newClientPort = PortAssignment.unique(); + joiningServers.add("server." + followerIndex + "=localhost:" + quorumPort + + ":" + electionPort + ":participant;localhost:" + newClientPort); + + // create a /test znode and check that read/write works before + // any reconfig is invoked + testNormalOperation(zkArr[followerIndex], zkArr[leaderIndex]); + + reconfig(zkArr[followerIndex], joiningServers, null, null, -1); + + try { + for (int i = 0; i < 20; i++) { + Thread.sleep(1000); + zkArr[followerIndex].setData("/test", "teststr".getBytes(), -1); + } + } catch (KeeperException.ConnectionLossException e) { + Assert.fail("Existing client disconnected when client port changed!"); + } + + zkArr[followerIndex].close(); + zkArr[followerIndex] = new ZooKeeper("127.0.0.1:" + + oldClientPort, + ClientBase.CONNECTION_TIMEOUT, new Watcher() { + public void process(WatchedEvent event) { + } + }); + for (int i = 0; i < 10; i++) { + try { + Thread.sleep(1000); + zkArr[followerIndex].setData("/test", "teststr".getBytes(), -1); + Assert.fail("New client connected to old client port!"); + } catch (KeeperException.ConnectionLossException e) { + } + } + + zkArr[followerIndex].close(); + zkArr[followerIndex] = new ZooKeeper("127.0.0.1:" + + newClientPort, + ClientBase.CONNECTION_TIMEOUT, new Watcher() { + public void process(WatchedEvent event) { + } + }); + + testNormalOperation(zkArr[followerIndex], zkArr[leaderIndex]); + testServerHasConfig(zkArr[followerIndex], joiningServers, null); + Assert.assertEquals(newClientPort, qu.getPeer(followerIndex).peer.getClientPort()); + + joiningServers.clear(); + + // change leader's leading port - should renounce leadership + + int newQuorumPort = PortAssignment.unique(); + joiningServers.add("server." + leaderIndex + "=localhost:" + + newQuorumPort + + ":" + + qu.getPeer(leaderIndex).peer.getElectionAddress().getPort() + + ":participant;localhost:" + + qu.getPeer(leaderIndex).peer.getClientPort()); + + reconfig(zkArr[leaderIndex], joiningServers, null, null, -1); + + testNormalOperation(zkArr[followerIndex], zkArr[leaderIndex]); + + Assert.assertTrue(qu.getPeer(leaderIndex).peer.getQuorumAddress() + .getPort() == newQuorumPort); + Assert.assertTrue(getLeaderId(qu) != leaderIndex); // the leader changed + + joiningServers.clear(); + + // change everyone's leader election port + + for (int i = 1; i <= 3; i++) { + joiningServers.add("server." + i + "=localhost:" + + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":" + + PortAssignment.unique() + ":participant;localhost:" + + qu.getPeer(i).peer.getClientPort()); + } + + reconfig(zkArr[1], joiningServers, null, null, -1); + + leaderIndex = getLeaderId(qu); + int follower1 = leaderIndex == 1 ? 2 : 1; + int follower2 = 1; + while (follower2 == leaderIndex || follower2 == follower1) + follower2++; + + // lets kill the leader and see if a new one is elected + + qu.shutdown(getLeaderId(qu)); + + testNormalOperation(zkArr[follower2], zkArr[follower1]); + testServerHasConfig(zkArr[follower1], joiningServers, null); + testServerHasConfig(zkArr[follower2], joiningServers, null); + + closeAllHandles(zkArr); + } + + @Test + public void testUnspecifiedClientAddress() throws Exception { + int[] ports = new int[3]; + for (int port : ports) { + port = PortAssignment.unique(); + } + String server = "server.0=localhost:" + ports[0] + ":" + ports[1] + ";" + ports[2]; + QuorumServer qs = new QuorumServer(0, server); + Assert.assertEquals(qs.clientAddr.getHostString(), "0.0.0.0"); + Assert.assertEquals(qs.clientAddr.getPort(), ports[2]); + } + + @Test + public void testQuorumSystemChange() throws Exception { + qu = new QuorumUtil(3); // create 7 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + ArrayList members = new ArrayList(); + members.add("group.1=3:4:5"); + members.add("group.2=1:2"); + members.add("weight.1=0"); + members.add("weight.2=0"); + members.add("weight.3=1"); + members.add("weight.4=1"); + members.add("weight.5=1"); + + for (int i = 1; i <= 5; i++) { + members.add("server." + i + "=127.0.0.1:" + + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":" + + qu.getPeer(i).peer.getElectionAddress().getPort() + ";" + + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort()); + } + + reconfig(zkArr[1], null, null, members, -1); + + // this should flush the config to servers 2, 3, 4 and 5 + testNormalOperation(zkArr[2], zkArr[3]); + testNormalOperation(zkArr[4], zkArr[5]); + + for (int i = 1; i <= 5; i++) { + if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumHierarchical)) + Assert.fail("peer " + i + + " doesn't think the quorum system is Hieararchical!"); + } + + qu.shutdown(1); + qu.shutdown(2); + qu.shutdown(3); + qu.shutdown(7); + qu.shutdown(6); + + // servers 4 and 5 should be able to work independently + testNormalOperation(zkArr[4], zkArr[5]); + + qu.restart(1); + qu.restart(2); + + members.clear(); + for (int i = 1; i <= 3; i++) { + members.add("server." + i + "=127.0.0.1:" + + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":" + + qu.getPeer(i).peer.getElectionAddress().getPort() + ";" + + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort()); + } + + reconfig(zkArr[1], null, null, members, -1); + + // flush the config to server 2 + testNormalOperation(zkArr[1], zkArr[2]); + + qu.shutdown(4); + qu.shutdown(5); + + // servers 1 and 2 should be able to work independently + testNormalOperation(zkArr[1], zkArr[2]); + + for (int i = 1; i <= 2; i++) { + if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumMaj)) + Assert.fail("peer " + + i + + " doesn't think the quorum system is a majority quorum system!"); + } + + closeAllHandles(zkArr); + } + + @Test + public void testInitialConfigHasPositiveVersion() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + testNormalOperation(zkArr[1], zkArr[2]); + for (int i = 1; i < 4; i++) { + String configStr = testServerHasConfig(zkArr[i], null, null); + QuorumVerifier qv = qu.getPeer(i).peer.configFromString(configStr); + long version = qv.getVersion(); + Assert.assertTrue(version == 0x100000000L); + } + } + + /** + * Tests verifies the jmx attributes of local and remote peer bean - remove + * one quorum peer and again adding it back + */ + @Test + public void testJMXBeanAfterRemoveAddOne() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + List leavingServers = new ArrayList(); + List joiningServers = new ArrayList(); + + // assert remotePeerBean.1 of ReplicatedServer_2 + int leavingIndex = 1; + int replica2 = 2; + QuorumPeer peer2 = qu.getPeer(replica2).peer; + QuorumServer leavingQS2 = peer2.getView().get(new Long(leavingIndex)); + String remotePeerBean2 = CommonNames.DOMAIN + + ":name0=ReplicatedServer_id" + replica2 + ",name1=replica." + + leavingIndex; + assertRemotePeerMXBeanAttributes(leavingQS2, remotePeerBean2); + + // assert remotePeerBean.1 of ReplicatedServer_3 + int replica3 = 3; + QuorumPeer peer3 = qu.getPeer(replica3).peer; + QuorumServer leavingQS3 = peer3.getView().get(new Long(leavingIndex)); + String remotePeerBean3 = CommonNames.DOMAIN + + ":name0=ReplicatedServer_id" + replica3 + ",name1=replica." + + leavingIndex; + assertRemotePeerMXBeanAttributes(leavingQS3, remotePeerBean3); + + ZooKeeper zk = zkArr[leavingIndex]; + + leavingServers.add(Integer.toString(leavingIndex)); + + // remember this server so we can add it back later + joiningServers.add("server." + leavingIndex + "=127.0.0.1:" + + qu.getPeer(leavingIndex).peer.getQuorumAddress().getPort() + + ":" + + qu.getPeer(leavingIndex).peer.getElectionAddress().getPort() + + ":participant;127.0.0.1:" + + qu.getPeer(leavingIndex).peer.getClientPort()); + + // Remove ReplicatedServer_1 from the ensemble + reconfig(zk, null, leavingServers, null, -1); + + // localPeerBean.1 of ReplicatedServer_1 + QuorumPeer removedPeer = qu.getPeer(leavingIndex).peer; + String localPeerBean = CommonNames.DOMAIN + + ":name0=ReplicatedServer_id" + leavingIndex + + ",name1=replica." + leavingIndex; + assertLocalPeerMXBeanAttributes(removedPeer, localPeerBean, false); + + // remotePeerBean.1 shouldn't exists in ReplicatedServer_2 + JMXEnv.ensureNone(remotePeerBean2); + // remotePeerBean.1 shouldn't exists in ReplicatedServer_3 + JMXEnv.ensureNone(remotePeerBean3); + + // Add ReplicatedServer_1 back to the ensemble + reconfig(zk, joiningServers, null, null, -1); + + // localPeerBean.1 of ReplicatedServer_1 + assertLocalPeerMXBeanAttributes(removedPeer, localPeerBean, true); + + // assert remotePeerBean.1 of ReplicatedServer_2 + leavingQS2 = peer2.getView().get(new Long(leavingIndex)); + assertRemotePeerMXBeanAttributes(leavingQS2, remotePeerBean2); + + // assert remotePeerBean.1 of ReplicatedServer_3 + leavingQS3 = peer3.getView().get(new Long(leavingIndex)); + assertRemotePeerMXBeanAttributes(leavingQS3, remotePeerBean3); + + closeAllHandles(zkArr); + } + + /** + * Tests verifies the jmx attributes of local and remote peer bean - change + * participant to observer role + */ + @Test + public void testJMXBeanAfterRoleChange() throws Exception { + qu = new QuorumUtil(1); // create 3 servers + qu.disableJMXTest = true; + qu.startAll(); + ZooKeeper[] zkArr = createHandles(qu); + + // changing a server's role / port is done by "adding" it with the same + // id but different role / port + List joiningServers = new ArrayList(); + + // assert remotePeerBean.1 of ReplicatedServer_2 + int changingIndex = 1; + int replica2 = 2; + QuorumPeer peer2 = qu.getPeer(replica2).peer; + QuorumServer changingQS2 = peer2.getView().get(new Long(changingIndex)); + String remotePeerBean2 = CommonNames.DOMAIN + + ":name0=ReplicatedServer_id" + replica2 + ",name1=replica." + + changingIndex; + assertRemotePeerMXBeanAttributes(changingQS2, remotePeerBean2); + + // assert remotePeerBean.1 of ReplicatedServer_3 + int replica3 = 3; + QuorumPeer peer3 = qu.getPeer(replica3).peer; + QuorumServer changingQS3 = peer3.getView().get(new Long(changingIndex)); + String remotePeerBean3 = CommonNames.DOMAIN + + ":name0=ReplicatedServer_id" + replica3 + ",name1=replica." + + changingIndex; + assertRemotePeerMXBeanAttributes(changingQS3, remotePeerBean3); + + String newRole = "observer"; + + ZooKeeper zk = zkArr[changingIndex]; + + // exactly as it is now, except for role change + joiningServers.add("server." + changingIndex + "=127.0.0.1:" + + qu.getPeer(changingIndex).peer.getQuorumAddress().getPort() + + ":" + + qu.getPeer(changingIndex).peer.getElectionAddress().getPort() + + ":" + newRole + ";127.0.0.1:" + + qu.getPeer(changingIndex).peer.getClientPort()); + + reconfig(zk, joiningServers, null, null, -1); + testNormalOperation(zkArr[changingIndex], zk); + + Assert.assertTrue(qu.getPeer(changingIndex).peer.observer != null + && qu.getPeer(changingIndex).peer.follower == null + && qu.getPeer(changingIndex).peer.leader == null); + Assert.assertTrue(qu.getPeer(changingIndex).peer.getPeerState() == ServerState.OBSERVING); + + QuorumPeer qp = qu.getPeer(changingIndex).peer; + String localPeerBeanName = CommonNames.DOMAIN + + ":name0=ReplicatedServer_id" + changingIndex + + ",name1=replica." + changingIndex; + + // localPeerBean.1 of ReplicatedServer_1 + assertLocalPeerMXBeanAttributes(qp, localPeerBeanName, true); + + // assert remotePeerBean.1 of ReplicatedServer_2 + changingQS2 = peer2.getView().get(new Long(changingIndex)); + assertRemotePeerMXBeanAttributes(changingQS2, remotePeerBean2); + + // assert remotePeerBean.1 of ReplicatedServer_3 + changingQS3 = peer3.getView().get(new Long(changingIndex)); + assertRemotePeerMXBeanAttributes(changingQS3, remotePeerBean3); + + closeAllHandles(zkArr); + } + + private void assertLocalPeerMXBeanAttributes(QuorumPeer qp, + String beanName, Boolean isPartOfEnsemble) throws Exception { + Assert.assertEquals("Mismatches LearnerType!", qp.getLearnerType() + .name(), JMXEnv.ensureBeanAttribute(beanName, "LearnerType")); + Assert.assertEquals("Mismatches ClientAddress!", + qp.getClientAddress().getHostString() + ":" + qp.getClientAddress().getPort(), + JMXEnv.ensureBeanAttribute(beanName, "ClientAddress")); + Assert.assertEquals("Mismatches LearnerType!", + qp.getElectionAddress().getHostString() + ":" + qp.getElectionAddress().getPort(), + JMXEnv.ensureBeanAttribute(beanName, "ElectionAddress")); + Assert.assertEquals("Mismatches PartOfEnsemble!", isPartOfEnsemble, + JMXEnv.ensureBeanAttribute(beanName, "PartOfEnsemble")); + Assert.assertEquals("Mismatches ConfigVersion!", qp.getQuorumVerifier() + .getVersion(), JMXEnv.ensureBeanAttribute(beanName, + "ConfigVersion")); + Assert.assertEquals("Mismatches QuorumSystemInfo!", qp + .getQuorumVerifier().toString(), JMXEnv.ensureBeanAttribute( + beanName, "QuorumSystemInfo")); + } + + String getAddrPortFromBean(String beanName, String attribute) throws Exception { + String name = (String) JMXEnv.ensureBeanAttribute( + beanName, attribute); + + if (!name.contains(":")) { + return name; + } + + return getNumericalAddrPort(name); + } + + String getNumericalAddrPort(String name) throws UnknownHostException { + String port = name.split(":")[1]; + String addr = name.split(":")[0]; + addr = InetAddress.getByName(addr).getHostAddress(); + return addr + ":" + port; + } + + private void assertRemotePeerMXBeanAttributes(QuorumServer qs, + String beanName) throws Exception { + Assert.assertEquals("Mismatches LearnerType!", qs.type.name(), + JMXEnv.ensureBeanAttribute(beanName, "LearnerType")); + Assert.assertEquals("Mismatches ClientAddress!", + getNumericalAddrPort(qs.clientAddr.getHostString() + ":" + qs.clientAddr.getPort()), + getAddrPortFromBean(beanName, "ClientAddress")); + Assert.assertEquals("Mismatches ElectionAddress!", + getNumericalAddrPort(qs.electionAddr.getHostString() + ":" + qs.electionAddr.getPort()), + getAddrPortFromBean(beanName, "ElectionAddress")); + Assert.assertEquals("Mismatches QuorumAddress!", + getNumericalAddrPort(qs.addr.getHostString() + ":" + qs.addr.getPort()), + getAddrPortFromBean(beanName, "QuorumAddress")); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/RecoveryTest.java b/src/java/test/org/apache/zookeeper/test/RecoveryTest.java new file mode 100644 index 00000000000..e8c811f3738 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/RecoveryTest.java @@ -0,0 +1,201 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class RecoveryTest extends ZKTestCase implements Watcher { + protected static final Logger LOG = LoggerFactory.getLogger(RecoveryTest.class); + + private static final String HOSTPORT = + "127.0.0.1:" + PortAssignment.unique(); + + private volatile CountDownLatch startSignal; + + /** + * Verify that if a server goes down that clients will reconnect + * automatically after the server is restarted. Note that this requires the + * server to restart within the connection timeout period. + * + * Also note that the client latches are used to eliminate any chance + * of spurrious connectionloss exceptions on the read ops. Specifically + * a sync operation will throw this exception if the server goes down + * (as recognized by the client) during the operation. If the operation + * occurs after the server is down, but before the client recognizes + * that the server is down (ping) then the op will throw connectionloss. + */ + @Test + public void testRecovery() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + + int oldSnapCount = SyncRequestProcessor.getSnapCount(); + SyncRequestProcessor.setSnapCount(1000); + try { + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + LOG.info("starting up the the server, waiting"); + + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(HOSTPORT, + CONNECTION_TIMEOUT)); + + startSignal = new CountDownLatch(1); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + startSignal.await(CONNECTION_TIMEOUT, + TimeUnit.MILLISECONDS); + Assert.assertTrue("count == 0", startSignal.getCount() == 0); + String path; + LOG.info("starting creating nodes"); + for (int i = 0; i < 10; i++) { + path = "/" + i; + zk.create(path, + (path + "!").getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + for (int j = 0; j < 10; j++) { + String subpath = path + "/" + j; + zk.create(subpath, (subpath + "!").getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + for (int k = 0; k < 20; k++) { + String subsubpath = subpath + "/" + k; + zk.create(subsubpath, (subsubpath + "!").getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + } + } + + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + CONNECTION_TIMEOUT)); + + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + f = ServerCnxnFactory.createFactory(PORT, -1); + + startSignal = new CountDownLatch(1); + + f.startup(zks); + + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(HOSTPORT, + CONNECTION_TIMEOUT)); + + startSignal.await(CONNECTION_TIMEOUT, + TimeUnit.MILLISECONDS); + Assert.assertTrue("count == 0", startSignal.getCount() == 0); + + Stat stat = new Stat(); + for (int i = 0; i < 10; i++) { + path = "/" + i; + LOG.info("Checking " + path); + Assert.assertEquals(new String(zk.getData(path, false, stat)), path + + "!"); + for (int j = 0; j < 10; j++) { + String subpath = path + "/" + j; + Assert.assertEquals(new String(zk.getData(subpath, false, stat)), + subpath + "!"); + for (int k = 0; k < 20; k++) { + String subsubpath = subpath + "/" + k; + Assert.assertEquals(new String(zk.getData(subsubpath, false, + stat)), subsubpath + "!"); + } + } + } + f.shutdown(); + zks.shutdown(); + + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + ClientBase.CONNECTION_TIMEOUT)); + + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + f = ServerCnxnFactory.createFactory(PORT, -1); + + startSignal = new CountDownLatch(1); + + f.startup(zks); + + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(HOSTPORT, + CONNECTION_TIMEOUT)); + + startSignal.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertTrue("count == 0", startSignal.getCount() == 0); + + stat = new Stat(); + LOG.info("Check 2"); + for (int i = 0; i < 10; i++) { + path = "/" + i; + Assert.assertEquals(new String(zk.getData(path, false, stat)), + path + "!"); + for (int j = 0; j < 10; j++) { + String subpath = path + "/" + j; + Assert.assertEquals(new String(zk.getData(subpath, false, stat)), + subpath + "!"); + for (int k = 0; k < 20; k++) { + String subsubpath = subpath + "/" + k; + Assert.assertEquals(new String(zk.getData(subsubpath, false, + stat)), subsubpath + "!"); + } + } + } + zk.close(); + + f.shutdown(); + zks.shutdown(); + + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + CONNECTION_TIMEOUT)); + } finally { + SyncRequestProcessor.setSnapCount(oldSnapCount); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatcherEvent) + */ + public void process(WatchedEvent event) { + LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath()); + if (event.getState() == KeeperState.SyncConnected + && startSignal != null && startSignal.getCount() > 0) { + startSignal.countDown(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java b/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java new file mode 100644 index 00000000000..2994339e96f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.Assert; +import org.junit.Test; + +public class RepeatStartupTest extends ZKTestCase { + + /** bring up 5 quorum peers and then shut them down + * and then bring one of the nodes as server + * + * @throws Exception might be thrown here + */ + @Test + public void testFail() throws Exception { + QuorumBase qb = new QuorumBase(); + qb.setUp(); + + System.out.println("Comment: the servers are at " + qb.hostPort); + ZooKeeper zk = qb.createClient(); + zk.create("/test", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.close(); + QuorumBase.shutdown(qb.s1); + QuorumBase.shutdown(qb.s2); + QuorumBase.shutdown(qb.s3); + QuorumBase.shutdown(qb.s4); + QuorumBase.shutdown(qb.s5); + String hp = qb.hostPort.split(",")[0]; + ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(), + qb.s1.getTxnFactory().getDataDir(), 3000); + final int PORT = Integer.parseInt(hp.split(":")[1]); + ServerCnxnFactory factory = ServerCnxnFactory.createFactory(PORT, -1); + + factory.startup(zks); + System.out.println("Comment: starting factory"); + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp("127.0.0.1:" + PORT, + QuorumTest.CONNECTION_TIMEOUT)); + factory.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown("127.0.0.1:" + PORT, + QuorumTest.CONNECTION_TIMEOUT)); + System.out.println("Comment: shutting down standalone"); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java b/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java new file mode 100644 index 00000000000..e75b8ddbbac --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/RestoreCommittedLogTest.java @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.List; + +/** After a replica starts, it should load commits in its committedLog list. + * This test checks if committedLog != 0 after replica restarted. + */ +public class RestoreCommittedLogTest extends ZKTestCase implements Watcher { + private static final Logger LOG = LoggerFactory.getLogger(RestoreCommittedLogTest.class); + private static final String HOSTPORT = "127.0.0.1:" + PortAssignment.unique(); + private static final int CONNECTION_TIMEOUT = 3000; + + /** + * test the purge + * @throws Exception an exception might be thrown here + */ + @Test + public void testRestoreCommittedLog() throws Exception { + File tmpDir = ClientBase.createTmpDir(); + ClientBase.setupTestEnv(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + SyncRequestProcessor.setSnapCount(100); + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", + ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this); + try { + for (int i = 0; i < 2000; i++) { + zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + } finally { + zk.close(); + } + f.shutdown(); + zks.shutdown(); + Assert.assertTrue("waiting for server to shutdown", + ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + + // start server again + zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + zks.startdata(); + List committedLog = zks.getZKDatabase().getCommittedLog(); + int logsize = committedLog.size(); + LOG.info("committedLog size = {}", logsize); + Assert.assertTrue("log size != 0", (logsize != 0)); + zks.shutdown(); + } + + public void process(WatchedEvent event) { + // do nothing + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/SSLAuthTest.java b/src/java/test/org/apache/zookeeper/test/SSLAuthTest.java new file mode 100644 index 00000000000..918efc2a334 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SSLAuthTest.java @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.X509Util; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; + +public class SSLAuthTest extends ClientBase { + @Before + public void setUp() throws Exception { + String testDataPath = System.getProperty("test.data.dir", "build/test/data"); + System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory"); + System.setProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty"); + System.setProperty(ZooKeeper.SECURE_CLIENT, "true"); + System.setProperty(X509Util.SSL_AUTHPROVIDER, "x509"); + System.setProperty(X509Util.SSL_KEYSTORE_LOCATION, testDataPath + "/ssl/testKeyStore.jks"); + System.setProperty(X509Util.SSL_KEYSTORE_PASSWD, "testpass"); + System.setProperty(X509Util.SSL_TRUSTSTORE_LOCATION, testDataPath + "/ssl/testTrustStore.jks"); + System.setProperty(X509Util.SSL_TRUSTSTORE_PASSWD, "testpass"); + System.setProperty("javax.net.debug", "ssl"); + + String host = "localhost"; + int port = PortAssignment.unique(); + hostPort = host + ":" + port; + + serverFactory = ServerCnxnFactory.createFactory(); + serverFactory.configure(new InetSocketAddress(host, port), maxCnxns, true); + + super.setUp(); + } + + @After + public void teardown() throws Exception { + System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); + System.clearProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET); + System.clearProperty(ZooKeeper.SECURE_CLIENT); + System.clearProperty(X509Util.SSL_AUTHPROVIDER); + System.clearProperty(X509Util.SSL_KEYSTORE_LOCATION); + System.clearProperty(X509Util.SSL_KEYSTORE_PASSWD); + System.clearProperty(X509Util.SSL_TRUSTSTORE_LOCATION); + System.clearProperty(X509Util.SSL_TRUSTSTORE_PASSWD); + System.clearProperty("javax.net.debug"); + } + + @Test + public void testRejection() throws Exception { + String testDataPath = System.getProperty("test.data.dir", "build/test/data"); + + // Replace trusted keys with a valid key that is not trusted by the server + System.setProperty(X509Util.SSL_KEYSTORE_LOCATION, testDataPath + "/ssl/testUntrustedKeyStore.jks"); + System.setProperty(X509Util.SSL_KEYSTORE_PASSWD, "testpass"); + + CountdownWatcher watcher = new CountdownWatcher(); + + // Handshake will take place, and then X509AuthenticationProvider should reject the untrusted cert + new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher); + Assert.assertFalse("Untrusted certificate should not result in successful connection", + watcher.clientConnected.await(1000, TimeUnit.MILLISECONDS)); + } + + @Test + public void testMisconfiguration() throws Exception { + System.clearProperty(X509Util.SSL_AUTHPROVIDER); + System.clearProperty(X509Util.SSL_KEYSTORE_LOCATION); + System.clearProperty(X509Util.SSL_KEYSTORE_PASSWD); + System.clearProperty(X509Util.SSL_TRUSTSTORE_LOCATION); + System.clearProperty(X509Util.SSL_TRUSTSTORE_PASSWD); + + CountdownWatcher watcher = new CountdownWatcher(); + new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher); + Assert.assertFalse("Missing SSL configuration should not result in successful connection", + watcher.clientConnected.await(1000, TimeUnit.MILLISECONDS)); + } +} \ No newline at end of file diff --git a/src/java/test/org/apache/zookeeper/test/SSLTest.java b/src/java/test/org/apache/zookeeper/test/SSLTest.java new file mode 100644 index 00000000000..4042a4b3dd8 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SSLTest.java @@ -0,0 +1,152 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +/** + * + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.X509Util; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.quorum.QuorumPeerTestBase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class SSLTest extends QuorumPeerTestBase { + + @Before + public void setup() { + String testDataPath = System.getProperty("test.data.dir", "build/test/data"); + System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory"); + System.setProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty"); + System.setProperty(ZooKeeper.SECURE_CLIENT, "true"); + System.setProperty(X509Util.SSL_KEYSTORE_LOCATION, testDataPath + "/ssl/testKeyStore.jks"); + System.setProperty(X509Util.SSL_KEYSTORE_PASSWD, "testpass"); + System.setProperty(X509Util.SSL_TRUSTSTORE_LOCATION, testDataPath + "/ssl/testTrustStore.jks"); + System.setProperty(X509Util.SSL_TRUSTSTORE_PASSWD, "testpass"); + } + + @After + public void teardown() throws Exception { + System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY); + System.clearProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET); + System.clearProperty(ZooKeeper.SECURE_CLIENT); + System.clearProperty(X509Util.SSL_KEYSTORE_LOCATION); + System.clearProperty(X509Util.SSL_KEYSTORE_PASSWD); + System.clearProperty(X509Util.SSL_TRUSTSTORE_LOCATION); + System.clearProperty(X509Util.SSL_TRUSTSTORE_PASSWD); + } + + /** + * This test checks that SSL works in cluster setup of ZK servers, which includes: + * 1. setting "secureClientPort" in "zoo.cfg" file. + * 2. setting jvm flags for serverCnxn, keystore, truststore. + * Finally, a zookeeper client should be able to connect to the secure port and + * communicate with server via secure connection. + *

        + * Note that in this test a ZK server has two ports -- clientPort and secureClientPort. + */ + @Test + public void testSecureQuorumServer() throws Exception { + final int SERVER_COUNT = 3; + final int clientPorts[] = new int[SERVER_COUNT]; + final Integer secureClientPorts[] = new Integer[SERVER_COUNT]; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < SERVER_COUNT; i++) { + clientPorts[i] = PortAssignment.unique(); + secureClientPorts[i] = PortAssignment.unique(); + String server = String.format("server.%d=localhost:%d:%d:participant;localhost:%d", + i, PortAssignment.unique(), PortAssignment.unique(), clientPorts[i]); + sb.append(server + "\n"); + } + String quorumCfg = sb.toString(); + + + MainThread[] mt = new MainThread[SERVER_COUNT]; + for (int i = 0; i < SERVER_COUNT; i++) { + mt[i] = new MainThread(i, quorumCfg, secureClientPorts[i], true); + mt[i].start(); + } + + // Servers have been set up. Now go test if secure connection is successful. + for (int i = 0; i < SERVER_COUNT; i++) { + Assert.assertTrue("waiting for server " + i + " being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], TIMEOUT)); + + final CountDownLatch latch = new CountDownLatch(1); + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + secureClientPorts[i], TIMEOUT, + new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getState() != Event.KeeperState.SyncConnected) { + Assert.fail("failed to connect to ZK server secure client port"); + } + latch.countDown(); + } + }); + if (!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) { + Assert.fail("Timeout connecting to ZK server secure port"); + } + // Do a simple operation to make sure the connection is fine. + zk.create("/test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.delete("/test", -1); + zk.close(); + } + + for (int i = 0; i < mt.length; i++) { + mt[i].shutdown(); + } + } + + + /** + * Developers might use standalone mode (which is the default for one server). + * This test checks SSL works in standalone mode of ZK server. + *

        + * Note that in this test the Zk server has only secureClientPort + */ + @Test + public void testSecureStandaloneServer() throws Exception { + Integer secureClientPort = PortAssignment.unique(); + MainThread mt = new MainThread(MainThread.UNSET_MYID, "", secureClientPort, false); + mt.start(); + + final CountDownLatch latch = new CountDownLatch(1); + ZooKeeper zk = new ZooKeeper("127.0.0.1:" + secureClientPort, TIMEOUT, + new Watcher() { + @Override + public void process(WatchedEvent event) { + if (event.getState() != Event.KeeperState.SyncConnected) { + Assert.fail("failed to connect to ZK server secure client port"); + } + latch.countDown(); + } + }); + if (!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) { + Assert.fail("Timeout connecting to ZK server secure port"); + } + zk.create("/test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + zk.delete("/test", -1); + zk.close(); + mt.shutdown(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java b/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java new file mode 100644 index 00000000000..cb15a5af174 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedClientTest.java @@ -0,0 +1,154 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.Perms; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.client.ZooKeeperSaslClient; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class SaslAuthDesignatedClientTest extends ClientBase { + static { + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); + System.setProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "MyZookeeperClient"); + + try { + File tmpDir = createTmpDir(); + File saslConfFile = new File(tmpDir, "jaas.conf"); + FileWriter fwriter = new FileWriter(saslConfFile); + + fwriter.write("" + + "Server {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " user_myuser=\"mypassword\";\n" + + "};\n" + + "Client {\n" + /* this 'Client' section has an incorrect password, but we're not configured + to use it (we're configured by the above System.setProperty(...LOGIN_CONTEXT_NAME_KEY...) to + use the 'MyZookeeperClient' section below, which has the correct password).*/ + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"myuser\"\n" + + " password=\"wrongpassword\";\n" + + "};" + + "MyZookeeperClient {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"myuser\"\n" + + " password=\"mypassword\";\n" + + "};" + "\n"); + fwriter.close(); + System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath()); + } catch (IOException e) { + // could not create tmp directory to hold JAAS conf file : test will fail now. + } + } + + @Test + public void testAuth() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + Thread.sleep(1000); + } catch (KeeperException e) { + Assert.fail("test failed :" + e); + } finally { + zk.close(); + } + } + + @Test + public void testSaslConfig() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.getChildren("/", false); + Assert.assertFalse(zk.getSaslClient(). + clientTunneledAuthenticationInProgress()); + Assert.assertEquals(zk.getSaslClient().getSaslState(), + ZooKeeperSaslClient.SaslState.COMPLETE); + Assert.assertNotNull( + javax.security.auth.login.Configuration.getConfiguration(). + getAppConfigurationEntry("MyZookeeperClient")); + Assert.assertSame(zk.getSaslClient().getLoginContext(), + "MyZookeeperClient"); + } catch (KeeperException e) { + Assert.fail("test failed :" + e); + } finally { + zk.close(); + } + } + + @Test + public void testReadAccessUser() throws Exception { + System.setProperty("zookeeper.letAnySaslUserDoX", "anyone"); + ZooKeeper zk = createClient(); + List aclList = new ArrayList(); + ACL acl = new ACL(Perms.ADMIN | Perms.CREATE | Perms.WRITE | Perms.DELETE, new Id("sasl", "fakeuser")); + ACL acl1 = new ACL(Perms.READ, new Id("sasl", "anyone")); + aclList.add(acl); + aclList.add(acl1); + try { + zk.create("/abc", "testData".getBytes(), aclList, CreateMode.PERSISTENT); + } catch (KeeperException e) { + Assert.fail("Unable to create znode"); + } + zk.close(); + Thread.sleep(100); + + // try to access it with different user (myuser) + zk = createClient(); + + try { + zk.setData("/abc", "testData1".getBytes(), -1); + Assert.fail("Should not be able to set data"); + } catch (KeeperException.NoAuthException e) { + // success + } + + try { + byte[] bytedata = zk.getData("/abc", null, null); + String data = new String(bytedata); + Assert.assertTrue("testData".equals(data)); + } catch (KeeperException e) { + Assert.fail("failed to get data"); + } + + zk.close(); + Thread.sleep(100); + + // disable Client Sasl + System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, "false"); + + try { + zk = createClient(); + try { + zk.getData("/abc", null, null); + Assert.fail("Should not be able to read data when not authenticated"); + } catch (KeeperException.NoAuthException e) { + // success + } + zk.close(); + } finally { + // enable Client Sasl + System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, "true"); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedServerTest.java b/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedServerTest.java new file mode 100644 index 00000000000..14facbc81be --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslAuthDesignatedServerTest.java @@ -0,0 +1,93 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.JaasConfiguration; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.ZooKeeperSaslServer; +import org.junit.Assert; +import org.junit.Test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +public class SaslAuthDesignatedServerTest extends ClientBase { + public static int AUTHENTICATION_TIMEOUT = 30000; + + static { + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); + System.setProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY, "MyZookeeperServer"); + + JaasConfiguration conf = new JaasConfiguration(); + + /* this 'Server' section has an incorrect password, but we're not configured + * to use it (we're configured by the above System.setProperty(...LOGIN_CONTEXT_NAME_KEY...) + * to use the 'MyZookeeperServer' section below, which has the correct password). + */ + conf.addSection("Server", "org.apache.zookeeper.server.auth.DigestLoginModule", + "user_myuser", "wrongpassword"); + + conf.addSection("MyZookeeperServer", "org.apache.zookeeper.server.auth.DigestLoginModule", + "user_myuser", "mypassword"); + + conf.addSection("Client", "org.apache.zookeeper.server.auth.DigestLoginModule", + "username", "myuser", "password", "mypassword"); + + javax.security.auth.login.Configuration.setConfiguration(conf); + } + + private AtomicInteger authFailed = new AtomicInteger(0); + + @Test + public void testAuth() throws Exception { + MyWatcher watcher = new MyWatcher(); + ZooKeeper zk = createClient(watcher); + watcher.authCompleted.await(AUTHENTICATION_TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertEquals(authFailed.get(), 0); + + try { + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + } catch (KeeperException e) { + Assert.fail("test failed :" + e); + } finally { + zk.close(); + } + } + + private class MyWatcher extends CountdownWatcher { + volatile CountDownLatch authCompleted; + + @Override + synchronized public void reset() { + authCompleted = new CountDownLatch(1); + super.reset(); + } + + @Override + public synchronized void process(WatchedEvent event) { + if (event.getState() == KeeperState.AuthFailed) { + authFailed.incrementAndGet(); + authCompleted.countDown(); + } else if (event.getState() == KeeperState.SaslAuthenticated) { + authCompleted.countDown(); + } else { + super.process(event); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslAuthFailDesignatedClientTest.java b/src/java/test/org/apache/zookeeper/test/SaslAuthFailDesignatedClientTest.java new file mode 100644 index 00000000000..3c10808bc9f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslAuthFailDesignatedClientTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.client.ZooKeeperSaslClient; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +public class SaslAuthFailDesignatedClientTest extends ClientBase { + static { + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); + System.setProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "MyZookeeperClient"); + + try { + File tmpDir = createTmpDir(); + File saslConfFile = new File(tmpDir, "jaas.conf"); + FileWriter fwriter = new FileWriter(saslConfFile); + + fwriter.write("" + + "Server {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " user_myuser=\"mypassword\";\n" + + "};\n" + + "Client {\n" + /* this 'Client' section has the correct password, but we're not configured + to use it (we're configured by the above System.setProperty(...LOGIN_CONTEXT_NAME_KEY...) to + use the 'MyZookeeperClient' section, which has an incorrect password).*/ + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"myuser\"\n" + + " password=\"mypassword\";\n" + + "};" + + "MyZookeeperClient {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"myuser\"\n" + + " password=\"wrongpassword\";\n" + + "};" + "\n"); + fwriter.close(); + System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath()); + } catch (IOException e) { + // could not create tmp directory to hold JAAS conf file : test will fail now. + } + } + + private AtomicInteger authFailed = new AtomicInteger(0); + + @Test + public void testAuth() throws Exception { + // Cannot use createClient here because server may close session before + // JMXEnv.ensureAll is called which will fail the test case + CountdownWatcher watcher = new CountdownWatcher(); + TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher); + if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)) { + Assert.fail("Unable to connect to server"); + } + try { + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + Assert.fail("Should have gotten exception."); + } catch (KeeperException e) { + // ok, exception as expected. + LOG.info("Got exception as expected: " + e); + } finally { + zk.close(); + } + } + + private class MyWatcher extends CountdownWatcher { + @Override + public synchronized void process(WatchedEvent event) { + if (event.getState() == KeeperState.AuthFailed) { + authFailed.incrementAndGet(); + } else { + super.process(event); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslAuthFailNotifyTest.java b/src/java/test/org/apache/zookeeper/test/SaslAuthFailNotifyTest.java new file mode 100644 index 00000000000..2083e94b379 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslAuthFailNotifyTest.java @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; + +public class SaslAuthFailNotifyTest extends ClientBase { + static { + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); + System.setProperty("zookeeper.allowSaslFailedClients", "true"); + + try { + File tmpDir = createTmpDir(); + File saslConfFile = new File(tmpDir, "jaas.conf"); + FileWriter fwriter = new FileWriter(saslConfFile); + + fwriter.write("" + + "Server {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " user_super=\"test\";\n" + + "};\n" + + "Client {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"super\"\n" + + " password=\"test1\";\n" + // NOTE: wrong password ('test' != 'test1') : this is to test SASL authentication failure. + "};" + "\n"); + fwriter.close(); + System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath()); + } catch (IOException e) { + // could not create tmp directory to hold JAAS conf file. + } + } + + private AtomicInteger authFailed = new AtomicInteger(0); + + @Override + protected TestableZooKeeper createClient(String hp) + throws IOException, InterruptedException { + MyWatcher watcher = new MyWatcher(); + return createClient(watcher, hp); + } + + @Test + public void testBadSaslAuthNotifiesWatch() throws Exception { + ZooKeeper zk = createClient(); + // wait for authFailed event from client's EventThread. + synchronized (authFailed) { + authFailed.wait(); + } + Assert.assertEquals(authFailed.get(), 1); + zk.close(); + } + + private class MyWatcher extends CountdownWatcher { + @Override + public synchronized void process(WatchedEvent event) { + if (event.getState() == KeeperState.AuthFailed) { + synchronized (authFailed) { + authFailed.incrementAndGet(); + authFailed.notify(); + } + } else { + super.process(event); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslAuthFailTest.java b/src/java/test/org/apache/zookeeper/test/SaslAuthFailTest.java new file mode 100644 index 00000000000..9447fd9c97f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslAuthFailTest.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +public class SaslAuthFailTest extends ClientBase { + static { + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); + System.setProperty("zookeeper.allowSaslFailedClients", "true"); + + try { + File tmpDir = createTmpDir(); + File saslConfFile = new File(tmpDir, "jaas.conf"); + FileWriter fwriter = new FileWriter(saslConfFile); + + fwriter.write("" + + "Server {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " user_super=\"test\";\n" + + "};\n" + + "Client {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"super\"\n" + + " password=\"test1\";\n" + // NOTE: wrong password ('test' != 'test1') : this is to test SASL authentication failure. + "};" + "\n"); + fwriter.close(); + System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath()); + } catch (IOException e) { + // could not create tmp directory to hold JAAS conf file. + } + } + + @Test + public void testAuthFail() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + Assert.fail("Should have gotten exception."); + } catch (Exception e) { + // ok, exception as expected. + LOG.info("Got exception as expected: " + e); + } finally { + zk.close(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslAuthMissingClientConfigTest.java b/src/java/test/org/apache/zookeeper/test/SaslAuthMissingClientConfigTest.java new file mode 100644 index 00000000000..c84d4e4579f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslAuthMissingClientConfigTest.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.client.ZooKeeperSaslClient; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; + +public class SaslAuthMissingClientConfigTest extends ClientBase { + static { + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); + // This configuration section 'MyZookeeperClient', is missing from the JAAS configuration. + // As a result, SASL authentication should fail, which is tested by this test (testAuth()). + System.setProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "MyZookeeperClient"); + + try { + File tmpDir = createTmpDir(); + File saslConfFile = new File(tmpDir, "jaas.conf"); + FileWriter fwriter = new FileWriter(saslConfFile); + + fwriter.write("" + + "Server {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " user_myuser=\"mypassword\";\n" + + "};\n" + + "Client {\n" + /* this 'Client' section has the correct password, but we're not configured + to use it - we're configured instead by the above + System.setProperty(...LOGIN_CONTEXT_NAME_KEY...) to + use the (nonexistent) 'MyZookeeperClient' section. */ + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"myuser\"\n" + + " password=\"mypassword\";\n" + + "};\n"); + fwriter.close(); + System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath()); + } catch (IOException e) { + // could not create tmp directory to hold JAAS conf file : test will fail now. + } + } + + private AtomicInteger authFailed = new AtomicInteger(0); + + @Test + public void testAuth() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + Assert.fail("Should have gotten exception."); + } catch (KeeperException e) { + // ok, exception as expected. + LOG.info("Got exception as expected: " + e); + } finally { + zk.close(); + } + } + + private class MyWatcher extends CountdownWatcher { + @Override + public synchronized void process(WatchedEvent event) { + if (event.getState() == KeeperState.AuthFailed) { + authFailed.incrementAndGet(); + } else { + super.process(event); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslAuthTest.java b/src/java/test/org/apache/zookeeper/test/SaslAuthTest.java new file mode 100644 index 00000000000..7b28225be30 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslAuthTest.java @@ -0,0 +1,134 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Id; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +public class SaslAuthTest extends ClientBase { + static { + System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); + + try { + File tmpDir = createTmpDir(); + File saslConfFile = new File(tmpDir, "jaas.conf"); + FileWriter fwriter = new FileWriter(saslConfFile); + + fwriter.write("" + + "Server {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " user_super=\"test\";\n" + + "};\n" + + "Client {\n" + + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + + " username=\"super\"\n" + + " password=\"test\";\n" + + "};" + "\n"); + fwriter.close(); + System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath()); + } catch (IOException e) { + // could not create tmp directory to hold JAAS conf file : test will fail now. + } + } + + private AtomicInteger authFailed = new AtomicInteger(0); + + @Override + protected TestableZooKeeper createClient(String hp) + throws IOException, InterruptedException { + MyWatcher watcher = new MyWatcher(); + return createClient(watcher, hp); + } + + @Test + public void testAuth() throws Exception { + ZooKeeper zk = createClient(); + try { + zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); + Thread.sleep(1000); + } finally { + zk.close(); + } + } + + @Test + public void testValidSaslIds() throws Exception { + ZooKeeper zk = createClient(); + + List validIds = new ArrayList(); + validIds.add("user"); + validIds.add("service/host.name.com"); + validIds.add("user@KERB.REALM"); + validIds.add("service/host.name.com@KERB.REALM"); + + int i = 0; + for (String validId : validIds) { + List aclList = new ArrayList(); + ACL acl = new ACL(0, new Id("sasl", validId)); + aclList.add(acl); + zk.create("/valid" + i, null, aclList, CreateMode.PERSISTENT); + i++; + } + } + + @Test + public void testInvalidSaslIds() throws Exception { + ZooKeeper zk = createClient(); + + List invalidIds = new ArrayList(); + invalidIds.add("user@KERB.REALM/server.com"); + invalidIds.add("user@KERB.REALM1@KERB.REALM2"); + + int i = 0; + for (String invalidId : invalidIds) { + List aclList = new ArrayList(); + try { + ACL acl = new ACL(0, new Id("sasl", invalidId)); + aclList.add(acl); + zk.create("/invalid" + i, null, aclList, CreateMode.PERSISTENT); + Assert.fail("SASLAuthenticationProvider.isValid() failed to catch invalid Id."); + } catch (KeeperException.InvalidACLException e) { + // ok. + } finally { + i++; + } + } + } + + private class MyWatcher extends CountdownWatcher { + @Override + public synchronized void process(WatchedEvent event) { + if (event.getState() == KeeperState.AuthFailed) { + authFailed.incrementAndGet(); + } else { + super.process(event); + } + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/SaslClientTest.java b/src/java/test/org/apache/zookeeper/test/SaslClientTest.java new file mode 100644 index 00000000000..25140c1140d --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SaslClientTest.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.client.ZooKeeperSaslClient; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +public class SaslClientTest extends ZKTestCase { + + private String existingPropertyValue = null; + + @Before + public void setUp() { + existingPropertyValue = System.getProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY); + } + + @After + public void tearDown() { + // Restore the System property if it was set previously + if (existingPropertyValue != null) { + System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, existingPropertyValue); + } + } + + @Test + public void testSaslClientDisabled() { + System.clearProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY); + Assert.assertTrue("SASL client disabled", ZooKeeperSaslClient.isEnabled()); + + for (String value : Arrays.asList("true", "TRUE")) { + System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, value); + Assert.assertTrue("SASL client disabled", ZooKeeperSaslClient.isEnabled()); + } + + for (String value : Arrays.asList("false", "FALSE")) { + System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, value); + Assert.assertFalse("SASL client disabled", ZooKeeperSaslClient.isEnabled()); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ServerCnxnTest.java b/src/java/test/org/apache/zookeeper/test/ServerCnxnTest.java new file mode 100644 index 00000000000..c60287948c7 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ServerCnxnTest.java @@ -0,0 +1,120 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.server.NIOServerCnxnFactory; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.Socket; + + +public class ServerCnxnTest extends ClientBase { + protected static final Logger LOG = + LoggerFactory.getLogger(ServerCnxnTest.class); + + private static int cnxnTimeout = 1000; + + private static String send4LetterWord( + String host, int port, String cmd, int delay) throws IOException { + LOG.info("connecting to " + host + " " + port); + Socket sock = new Socket(host, port); + BufferedReader reader = null; + try { + try { + LOG.info("Sleeping for " + delay + "ms"); + Thread.sleep(delay); + } catch (InterruptedException e) { + // ignore + } + + OutputStream outstream = sock.getOutputStream(); + outstream.write(cmd.getBytes()); + outstream.flush(); + // this replicates NC - close the output stream before reading + sock.shutdownOutput(); + + reader = + new BufferedReader( + new InputStreamReader(sock.getInputStream())); + StringBuilder sb = readLine(reader); + return sb.toString(); + } finally { + sock.close(); + if (reader != null) { + reader.close(); + } + } + } + + private static StringBuilder readLine(BufferedReader reader) { + StringBuilder sb = new StringBuilder(); + String line; + try { + while ((line = reader.readLine()) != null) { + sb.append(line + "\n"); + } + } catch (IOException ioe) { + // During connection expiry the server will close the connection. + // After the socket is closed, when the client tries to read a + // line of text it will throw java.net.SocketException. + // @see jira issue ZOOKEEPER-1862 + LOG.info("Connnection is expired", ioe); + } + return sb; + } + + @Before + public void setUp() throws Exception { + System.setProperty( + NIOServerCnxnFactory.ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT, + Integer.toString(cnxnTimeout)); + super.setUp(); + } + + @After + public void tearDown() throws Exception { + super.tearDown(); + System.clearProperty( + NIOServerCnxnFactory.ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT); + } + + @Test + public void testServerCnxnExpiry() throws Exception { + verify("ruok", "imok"); + + // Expiry time is (now/cnxnTimeout + 1)*cnxnTimeout + // Range is (now + cnxnTimeout) to (now + 2*cnxnTimeout) + // Add 1s buffer to be safe. + String resp = sendRequest("ruok", 2 * cnxnTimeout + 1000); + Assert.assertEquals("Connection should have closed", "", resp); + } + + private void verify(String cmd, String expected) throws IOException { + String resp = sendRequest(cmd, 0); + LOG.info("cmd " + cmd + " expected " + expected + " got " + resp); + Assert.assertTrue(resp.contains(expected)); + } + + private String sendRequest(String cmd, int delay) throws IOException { + HostPort hpobj = ClientBase.parseHostPortList(hostPort).get(0); + return send4LetterWord(hpobj.host, hpobj.port, cmd, delay); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java b/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java new file mode 100644 index 00000000000..1b01615f758 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooDefs.OpCode; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.proto.ConnectRequest; +import org.apache.zookeeper.proto.CreateRequest; +import org.apache.zookeeper.proto.RequestHeader; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; + +public class SessionInvalidationTest extends ClientBase { + /** + * Test solution for ZOOKEEPER-1208. Verify that operations are not + * accepted after a close session. + * + * We're using our own marshalling here in order to force an operation + * after the session is closed (ZooKeeper.class will not allow this). Also + * by filling the pipe with operations it increases the likelyhood that + * the server will process the create before FinalRequestProcessor + * removes the session from the tracker. + */ + @Test + public void testCreateAfterCloseShouldFail() throws Exception { + for (int i = 0; i < 10; i++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); + + // open a connection + boa.writeInt(44, "len"); + ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16]); + conReq.serialize(boa, "connect"); + + // close connection + boa.writeInt(8, "len"); + RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.closeSession); + h.serialize(boa, "header"); + + // create ephemeral znode + boa.writeInt(52, "len"); // We'll fill this in later + RequestHeader header = new RequestHeader(2, OpCode.create); + header.serialize(boa, "header"); + CreateRequest createReq = new CreateRequest("/foo" + i, new byte[0], + Ids.OPEN_ACL_UNSAFE, 1); + createReq.serialize(boa, "request"); + baos.close(); + + System.out.println("Length:" + baos.toByteArray().length); + + String hp[] = hostPort.split(":"); + Socket sock = new Socket(hp[0], Integer.parseInt(hp[1])); + InputStream resultStream = null; + try { + OutputStream outstream = sock.getOutputStream(); + byte[] data = baos.toByteArray(); + outstream.write(data); + outstream.flush(); + + resultStream = sock.getInputStream(); + byte[] b = new byte[10000]; + int len; + while ((len = resultStream.read(b)) >= 0) { + // got results + System.out.println("gotlen:" + len); + } + } finally { + if (resultStream != null) { + resultStream.close(); + } + sock.close(); + } + } + + ZooKeeper zk = createClient(); + Assert.assertEquals(1, zk.getChildren("/", false).size()); + + zk.close(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SessionTest.java b/src/java/test/org/apache/zookeeper/test/SessionTest.java new file mode 100644 index 00000000000..b7982bf87aa --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SessionTest.java @@ -0,0 +1,458 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +public class SessionTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory.getLogger(SessionTest.class); + + private static final String HOSTPORT = "127.0.0.1:" + + PortAssignment.unique(); + private final int TICK_TIME = 3000; + File tmpDir; + private ServerCnxnFactory serverFactory; + private ZooKeeperServer zs; + private CountDownLatch startSignal; + + @Before + public void setUp() throws Exception { + if (tmpDir == null) { + tmpDir = ClientBase.createTmpDir(); + } + + ClientBase.setupTestEnv(); + zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME); + + final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); + serverFactory = ServerCnxnFactory.createFactory(PORT, -1); + serverFactory.startup(zs); + + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(HOSTPORT, + CONNECTION_TIMEOUT)); + } + + @After + public void tearDown() throws Exception { + serverFactory.shutdown(); + zs.shutdown(); + Assert.assertTrue("waiting for server down", + ClientBase.waitForServerDown(HOSTPORT, + CONNECTION_TIMEOUT)); + } + + private DisconnectableZooKeeper createClient() + throws IOException, InterruptedException { + CountdownWatcher watcher = new CountdownWatcher(); + return createClient(CONNECTION_TIMEOUT, watcher); + } + + private DisconnectableZooKeeper createClient(int timeout) + throws IOException, InterruptedException { + CountdownWatcher watcher = new CountdownWatcher(); + return createClient(timeout, watcher); + } + + private DisconnectableZooKeeper createClient(int timeout, + CountdownWatcher watcher) + throws IOException, InterruptedException { + DisconnectableZooKeeper zk = + new DisconnectableZooKeeper(HOSTPORT, timeout, watcher); + if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS)) { + Assert.fail("Unable to connect to server"); + } + + return zk; + } + + /** + * This test verifies that when the session id is reused, and the original + * client is disconnected, but not session closed, that the server + * will remove ephemeral nodes created by the original session. + */ + @Test + public void testSession() + throws IOException, InterruptedException, KeeperException { + DisconnectableZooKeeper zk = createClient(); + zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId()) + + " was destroyed!"); + + // disconnect the client by killing the socket, not sending the + // session disconnect to the server as usual. This allows the test + // to verify disconnect handling + zk.disconnect(); + + Stat stat = new Stat(); + startSignal = new CountDownLatch(1); + zk = new DisconnectableZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, + new MyWatcher("testSession"), zk.getSessionId(), + zk.getSessionPasswd()); + startSignal.await(); + + LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId()) + + " was created!"); + zk.getData("/e", false, stat); + LOG.info("After get data /e"); + zk.close(); + + zk = createClient(); + Assert.assertEquals(null, zk.exists("/e", false)); + LOG.info("before close zk with session id 0x" + + Long.toHexString(zk.getSessionId()) + "!"); + zk.close(); + try { + zk.getData("/e", false, stat); + Assert.fail("Should have received a SessionExpiredException"); + } catch (KeeperException.SessionExpiredException e) { + } + + AsyncCallback.DataCallback cb = new AsyncCallback.DataCallback() { + String status = "not done"; + + public void processResult(int rc, String p, Object c, byte[] b, Stat s) { + synchronized (this) { + status = KeeperException.Code.get(rc).toString(); + this.notify(); + } + } + + public String toString() { + return status; + } + }; + zk.getData("/e", false, cb, null); + synchronized (cb) { + if (cb.toString().equals("not done")) { + cb.wait(1000); + } + } + Assert.assertEquals(KeeperException.Code.SESSIONEXPIRED.toString(), cb.toString()); + } + +// FIXME this test is Assert.failing due to client close race condition fixing in separate patch for ZOOKEEPER-63 +// /** +// * this test checks to see if the sessionid that was created for the +// * first zookeeper client can be reused for the second one immidiately +// * after the first client closes and the new client resues them. +// * @throws IOException +// * @throws InterruptedException +// * @throws KeeperException +// */ +// public void testSessionReuse() throws IOException, InterruptedException { +// ZooKeeper zk = createClient(); +// +// long sessionId = zk.getSessionId(); +// byte[] passwd = zk.getSessionPasswd(); +// zk.close(); +// +// zk.close(); +// +// LOG.info("Closed first session"); +// +// startSignal = new CountDownLatch(1); +// zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this, +// sessionId, passwd); +// startSignal.await(); +// +// LOG.info("Opened reuse"); +// +// Assert.assertEquals(sessionId, zk.getSessionId()); +// +// zk.close(); +// } + + private List findThreads(String name) { + int threadCount = Thread.activeCount(); + Thread threads[] = new Thread[threadCount * 2]; + threadCount = Thread.enumerate(threads); + ArrayList list = new ArrayList(); + for (int i = 0; i < threadCount; i++) { + if (threads[i].getName().indexOf(name) != -1) { + list.add(threads[i]); + } + } + return list; + } + + /** + * Make sure ephemerals get cleaned up when a session times out. + */ + @SuppressWarnings("deprecation") + @Test + public void testSessionTimeout() throws Exception { + final int TIMEOUT = 5000; + List etBefore = findThreads("EventThread"); + List stBefore = findThreads("SendThread"); + DisconnectableZooKeeper zk = createClient(TIMEOUT); + zk.create("/stest", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + + // Find the new event and send threads + List etAfter = findThreads("EventThread"); + List stAfter = findThreads("SendThread"); + Thread eventThread = null; + Thread sendThread = null; + for (Thread t : etAfter) { + if (!etBefore.contains(t)) { + eventThread = t; + break; + } + } + for (Thread t : stAfter) { + if (!stBefore.contains(t)) { + sendThread = t; + break; + } + } + sendThread.suspend(); + //zk.disconnect(); + + Thread.sleep(TIMEOUT * 2); + sendThread.resume(); + eventThread.join(TIMEOUT); + Assert.assertFalse("EventThread is still running", eventThread.isAlive()); + + zk = createClient(TIMEOUT); + zk.create("/stest", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + tearDown(); + zk.close(); + zk.disconnect(); + setUp(); + + zk = createClient(TIMEOUT); + Assert.assertTrue(zk.exists("/stest", false) != null); + Thread.sleep(TIMEOUT * 2); + Assert.assertTrue(zk.exists("/stest", false) == null); + zk.close(); + } + + /** + * Make sure that we cannot have two connections with the same + * session id. + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void testSessionMove() throws Exception { + String hostPorts[] = HOSTPORT.split(","); + DisconnectableZooKeeper zk = new DisconnectableZooKeeper(hostPorts[0], + CONNECTION_TIMEOUT, new MyWatcher("0")); + zk.create("/sessionMoveTest", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + // we want to loop through the list twice + for (int i = 0; i < hostPorts.length * 2; i++) { + zk.dontReconnect(); + // This should stomp the zk handle + DisconnectableZooKeeper zknew = new DisconnectableZooKeeper( + hostPorts[(i + 1) % hostPorts.length], + CONNECTION_TIMEOUT, + new MyWatcher(Integer.toString(i + 1)), + zk.getSessionId(), + zk.getSessionPasswd()); + final int result[] = new int[1]; + result[0] = Integer.MAX_VALUE; + zknew.sync("/", new AsyncCallback.VoidCallback() { + public void processResult(int rc, String path, Object ctx) { + synchronized (result) { + result[0] = rc; + result.notify(); + } + } + }, null); + synchronized (result) { + if (result[0] == Integer.MAX_VALUE) { + result.wait(5000); + } + } + LOG.info(hostPorts[(i + 1) % hostPorts.length] + " Sync returned " + result[0]); + Assert.assertTrue(result[0] == KeeperException.Code.OK.intValue()); + zknew.setData("/", new byte[1], -1); + try { + zk.setData("/", new byte[1], -1); + Assert.fail("Should have lost the connection"); + } catch (KeeperException.ConnectionLossException e) { + LOG.info("Got connection loss exception as expected"); + } + //zk.close(); + zk = zknew; + } + zk.close(); + } + + /** + * This test makes sure that duplicate state changes are not communicated + * to the client watcher. For example we should not notify state as + * "disconnected" if the watch has already been disconnected. In general + * we don't consider a dup state notification if the event type is + * not "None" (ie non-None communicates an event). + */ + @Test + public void testSessionStateNoDupStateReporting() + throws IOException, InterruptedException, KeeperException { + final int TIMEOUT = 3000; + DupWatcher watcher = new DupWatcher(); + ZooKeeper zk = createClient(TIMEOUT, watcher); + + // shutdown the server + serverFactory.shutdown(); + + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + // ignore + } + + // verify that the size is just 2 - ie connect then disconnect + // if the client attempts reconnect and we are not handling current + // state correctly (ie eventing on duplicate disconnects) then we'll + // see a disconnect for each Assert.failed connection attempt + Assert.assertEquals(2, watcher.states.size()); + + zk.close(); + } + + /** + * Verify access to the negotiated session timeout. + */ + @Test + public void testSessionTimeoutAccess() throws Exception { + // validate typical case - requested == negotiated + DisconnectableZooKeeper zk = createClient(TICK_TIME * 4); + Assert.assertEquals(TICK_TIME * 4, zk.getSessionTimeout()); + // make sure tostring works in both cases + LOG.info(zk.toString()); + zk.close(); + LOG.info(zk.toString()); + + // validate lower limit + zk = createClient(TICK_TIME); + Assert.assertEquals(TICK_TIME * 2, zk.getSessionTimeout()); + LOG.info(zk.toString()); + zk.close(); + LOG.info(zk.toString()); + + // validate upper limit + zk = createClient(TICK_TIME * 30); + Assert.assertEquals(TICK_TIME * 20, zk.getSessionTimeout()); + LOG.info(zk.toString()); + zk.close(); + LOG.info(zk.toString()); + } + + @Test + public void testMinMaxSessionTimeout() throws Exception { + // override the defaults + final int MINSESS = 20000; + final int MAXSESS = 240000; + { + ZooKeeperServer zs = ClientBase.getServer(serverFactory); + zs.setMinSessionTimeout(MINSESS); + zs.setMaxSessionTimeout(MAXSESS); + } + + // validate typical case - requested == negotiated + int timeout = 120000; + DisconnectableZooKeeper zk = createClient(timeout); + Assert.assertEquals(timeout, zk.getSessionTimeout()); + // make sure tostring works in both cases + LOG.info(zk.toString()); + zk.close(); + LOG.info(zk.toString()); + + // validate lower limit + zk = createClient(MINSESS / 2); + Assert.assertEquals(MINSESS, zk.getSessionTimeout()); + LOG.info(zk.toString()); + zk.close(); + LOG.info(zk.toString()); + + // validate upper limit + zk = createClient(MAXSESS * 2); + Assert.assertEquals(MAXSESS, zk.getSessionTimeout()); + LOG.info(zk.toString()); + zk.close(); + LOG.info(zk.toString()); + } + + private static class CountdownWatcher implements Watcher { + volatile CountDownLatch clientConnected = new CountDownLatch(1); + + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.SyncConnected) { + clientConnected.countDown(); + } + } + } + + private class MyWatcher implements Watcher { + private String name; + + public MyWatcher(String name) { + this.name = name; + } + + public void process(WatchedEvent event) { + LOG.info(name + " event:" + event.getState() + " " + + event.getType() + " " + event.getPath()); + if (event.getState() == KeeperState.SyncConnected + && startSignal != null && startSignal.getCount() > 0) { + startSignal.countDown(); + } + } + } + + private class DupWatcher extends CountdownWatcher { + public LinkedList states = new LinkedList(); + + public void process(WatchedEvent event) { + super.process(event); + if (event.getType() == EventType.None) { + states.add(event); + } + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SessionTrackerCheckTest.java b/src/java/test/org/apache/zookeeper/test/SessionTrackerCheckTest.java new file mode 100644 index 00000000000..d8018cd3b1d --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SessionTrackerCheckTest.java @@ -0,0 +1,222 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.SessionTracker.Session; +import org.apache.zookeeper.server.SessionTracker.SessionExpirer; +import org.apache.zookeeper.server.ZooKeeperServerListener; +import org.apache.zookeeper.server.quorum.LeaderSessionTracker; +import org.apache.zookeeper.server.quorum.LearnerSessionTracker; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.ConcurrentHashMap; + +/** + * Validate various type of sessions against leader session tracker and learner + * session tracker + */ +public class SessionTrackerCheckTest extends ZKTestCase { + + public static final int TICK_TIME = 1000; + public static final int CONNECTION_TIMEOUT = TICK_TIME * 10; + protected static final Logger LOG = LoggerFactory + .getLogger(SessionTrackerCheckTest.class); + private ConcurrentHashMap sessionsWithTimeouts = + new ConcurrentHashMap(); + + @Before + public void setUp() throws Exception { + sessionsWithTimeouts.clear(); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testLearnerSessionTracker() throws Exception { + Expirer expirer = new Expirer(1); + // With local session on + LearnerSessionTracker tracker = new LearnerSessionTracker(expirer, + sessionsWithTimeouts, TICK_TIME, expirer.sid, true, + testZKSListener()); + + // Unknown session + long sessionId = 0xb100ded; + try { + tracker.checkSession(sessionId, null); + Assert.fail("Unknown session should have failed"); + } catch (SessionExpiredException e) { + // Get expected exception + } + + // Global session + sessionsWithTimeouts.put(sessionId, CONNECTION_TIMEOUT); + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Global session should not fail"); + } + + // Local session + sessionId = 0xf005ba11; + tracker.addSession(sessionId, CONNECTION_TIMEOUT); + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Local session should not fail"); + } + + // During session upgrade + sessionsWithTimeouts.put(sessionId, CONNECTION_TIMEOUT); + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Session during upgrade should not fail"); + } + + // With local session off + tracker = new LearnerSessionTracker(expirer, sessionsWithTimeouts, + TICK_TIME, expirer.sid, false, testZKSListener()); + + // Should be noop + sessionId = 0xdeadbeef; + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Should not get any exception"); + } + + } + + @Test + public void testLeaderSessionTracker() throws Exception { + Expirer expirer = new Expirer(2); + // With local session on + LeaderSessionTracker tracker = new LeaderSessionTracker(expirer, + sessionsWithTimeouts, TICK_TIME, expirer.sid, true, + testZKSListener()); + + // Local session from other server + long sessionId = ((expirer.sid + 1) << 56) + 1; + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("local session from other server should not fail"); + } + + // Global session + tracker.addGlobalSession(sessionId, CONNECTION_TIMEOUT); + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Global session should not fail"); + } + try { + tracker.checkGlobalSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Global session should not fail " + e); + } + + // Local session from the leader + sessionId = (expirer.sid << 56) + 1; + ; + tracker.addSession(sessionId, CONNECTION_TIMEOUT); + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Local session on the leader should not fail"); + } + + // During session upgrade + tracker.addGlobalSession(sessionId, CONNECTION_TIMEOUT); + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Session during upgrade should not fail"); + } + try { + tracker.checkGlobalSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Global session should not fail " + e); + } + + // With local session off + tracker = new LeaderSessionTracker(expirer, sessionsWithTimeouts, + TICK_TIME, expirer.sid, false, testZKSListener()); + + // Global session + sessionId = 0xdeadbeef; + tracker.addSession(sessionId, CONNECTION_TIMEOUT); + try { + tracker.checkSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Global session should not fail"); + } + try { + tracker.checkGlobalSession(sessionId, null); + } catch (Exception e) { + Assert.fail("Global session should not fail"); + } + + // Local session from other server + sessionId = ((expirer.sid + 1) << 56) + 2; + try { + tracker.checkSession(sessionId, null); + Assert.fail("local session from other server should fail"); + } catch (SessionExpiredException e) { + // Got expected exception + } + + // Local session from the leader + sessionId = ((expirer.sid) << 56) + 2; + try { + tracker.checkSession(sessionId, null); + Assert.fail("local session from the leader should fail"); + } catch (SessionExpiredException e) { + // Got expected exception + } + + } + + ZooKeeperServerListener testZKSListener() { + return new ZooKeeperServerListener() { + + @Override + public void notifyStopping(String errMsg, int exitCode) { + + } + }; + } + + private class Expirer implements SessionExpirer { + long sid; + + public Expirer(long sid) { + this.sid = sid; + } + + public void expire(Session session) { + } + + public long getServerId() { + return sid; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SessionUpgradeTest.java b/src/java/test/org/apache/zookeeper/test/SessionUpgradeTest.java new file mode 100644 index 00000000000..d9eef3f8330 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SessionUpgradeTest.java @@ -0,0 +1,224 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Tests that session upgrade works from local to global sessions. + * Expected behavior is that if global-only sessions are unset, + * and no upgrade interval is specified, then sessions will be + * created locally to the host. They will be upgraded to global + * sessions iff an operation is done on that session which requires + * persistence, i.e. creating an ephemeral node. + */ +public class SessionUpgradeTest extends ZKTestCase { + public static final int CONNECTION_TIMEOUT = ClientBase.CONNECTION_TIMEOUT; + protected static final Logger LOG = LoggerFactory.getLogger(SessionUpgradeTest.class); + private final QuorumBase qb = new QuorumBase(); + + @Before + public void setUp() throws Exception { + LOG.info("STARTING quorum " + getClass().getName()); + qb.localSessionsEnabled = true; + qb.localSessionsUpgradingEnabled = true; + qb.setUp(); + ClientBase.waitForServerUp(qb.hostPort, 10000); + } + + @After + public void tearDown() throws Exception { + LOG.info("STOPPING quorum " + getClass().getName()); + qb.tearDown(); + } + + @Test + public void testLocalSessionsWithoutEphemeralOnFollower() throws Exception { + testLocalSessionsWithoutEphemeral(false); + } + + @Test + public void testLocalSessionsWithoutEphemeralOnLeader() throws Exception { + testLocalSessionsWithoutEphemeral(true); + } + + private void testLocalSessionsWithoutEphemeral(boolean testLeader) + throws Exception { + String nodePrefix = "/testLocalSessions-" + + (testLeader ? "leaderTest-" : "followerTest-"); + int leaderIdx = qb.getLeaderIndex(); + Assert.assertFalse("No leader in quorum?", leaderIdx == -1); + int followerIdx = (leaderIdx + 1) % 5; + int otherFollowerIdx = (leaderIdx + 2) % 5; + int testPeerIdx = testLeader ? leaderIdx : followerIdx; + String hostPorts[] = qb.hostPort.split(","); + CountdownWatcher watcher = new CountdownWatcher(); + DisconnectableZooKeeper zk = new DisconnectableZooKeeper( + hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + // Try creating some data. + for (int i = 0; i < 5; i++) { + zk.create(nodePrefix + i, new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + + long localSessionId = zk.getSessionId(); + byte[] localSessionPwd = zk.getSessionPasswd().clone(); + + // Try connecting with the same session id on a different + // server. This should fail since it is a local sesion. + try { + watcher.reset(); + DisconnectableZooKeeper zknew = new DisconnectableZooKeeper( + hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher, + localSessionId, localSessionPwd); + + zknew.create(nodePrefix + "5", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.fail("Connection on the same session ID should fail."); + } catch (KeeperException.SessionExpiredException e) { + } catch (KeeperException.ConnectionLossException e) { + } + + // If we're testing a follower, also check the session id on the + // leader. This should also fail + if (!testLeader) { + try { + watcher.reset(); + DisconnectableZooKeeper zknew = new DisconnectableZooKeeper( + hostPorts[leaderIdx], CONNECTION_TIMEOUT, + watcher, localSessionId, localSessionPwd); + + zknew.create(nodePrefix + "5", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + Assert.fail("Connection on the same session ID should fail."); + } catch (KeeperException.SessionExpiredException e) { + } catch (KeeperException.ConnectionLossException e) { + } + } + + // However, we should be able to disconnect and reconnect to the same + // server with the same session id (as long as we do it quickly + // before expiration). + zk.disconnect(); + + watcher.reset(); + zk = new DisconnectableZooKeeper( + hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher, + localSessionId, localSessionPwd); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + zk.create(nodePrefix + "6", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + + // If we explicitly close the session, then the session id should no + // longer be valid. + zk.close(); + try { + watcher.reset(); + zk = new DisconnectableZooKeeper( + hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher, + localSessionId, localSessionPwd); + + zk.create(nodePrefix + "7", new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.fail("Reconnecting to a closed session ID should fail."); + } catch (KeeperException.SessionExpiredException e) { + } + } + + @Test + public void testUpgradeWithEphemeralOnFollower() throws Exception { + testUpgradeWithEphemeral(false); + } + + @Test + public void testUpgradeWithEphemeralOnLeader() throws Exception { + testUpgradeWithEphemeral(true); + } + + private void testUpgradeWithEphemeral(boolean testLeader) + throws Exception { + String nodePrefix = "/testUpgrade-" + + (testLeader ? "leaderTest-" : "followerTest-"); + int leaderIdx = qb.getLeaderIndex(); + Assert.assertFalse("No leader in quorum?", leaderIdx == -1); + int followerIdx = (leaderIdx + 1) % 5; + int otherFollowerIdx = (leaderIdx + 2) % 5; + int testPeerIdx = testLeader ? leaderIdx : followerIdx; + String hostPorts[] = qb.hostPort.split(","); + + CountdownWatcher watcher = new CountdownWatcher(); + DisconnectableZooKeeper zk = new DisconnectableZooKeeper( + hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + // Create some ephemeral nodes. This should force the session to + // be propagated to the other servers in the ensemble. + for (int i = 0; i < 5; i++) { + zk.create(nodePrefix + i, new byte[0], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + } + + // We should be able to reconnect with the same session id on a + // different server, since it has been propagated. + long localSessionId = zk.getSessionId(); + byte[] localSessionPwd = zk.getSessionPasswd().clone(); + + zk.disconnect(); + watcher.reset(); + zk = new DisconnectableZooKeeper( + hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher, + localSessionId, localSessionPwd); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + // The created ephemeral nodes are still around. + for (int i = 0; i < 5; i++) { + Assert.assertNotNull(zk.exists(nodePrefix + i, null)); + } + + // When we explicitly close the session, we should not be able to + // reconnect with the same session id + zk.close(); + + try { + watcher.reset(); + zk = new DisconnectableZooKeeper( + hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher, + localSessionId, localSessionPwd); + zk.exists(nodePrefix + "0", null); + Assert.fail("Reconnecting to a closed session ID should fail."); + } catch (KeeperException.SessionExpiredException e) { + } + + watcher.reset(); + // And the ephemeral nodes will be gone since the session died. + zk = new DisconnectableZooKeeper( + hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher); + watcher.waitForConnected(CONNECTION_TIMEOUT); + for (int i = 0; i < 5; i++) { + Assert.assertNull(zk.exists(nodePrefix + i, null)); + } + } +} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/SledgeHammer.java b/src/java/test/org/apache/zookeeper/test/SledgeHammer.java similarity index 56% rename from zookeeper/test/com/yahoo/zookeeper/test/SledgeHammer.java rename to src/java/test/org/apache/zookeeper/test/SledgeHammer.java index db71b9c808e..c3b8e86a2d4 100644 --- a/zookeeper/test/com/yahoo/zookeeper/test/SledgeHammer.java +++ b/src/java/test/org/apache/zookeeper/test/SledgeHammer.java @@ -1,16 +1,27 @@ -package com.yahoo.zookeeper.test; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; +import java.util.List; public class SledgeHammer extends Thread implements Watcher { ZooKeeper zk; @@ -20,17 +31,36 @@ public class SledgeHammer extends Thread implements Watcher { int readsPerWrite; public SledgeHammer(String hosts, int count, int readsPerWrite) - throws KeeperException, IOException { + throws IOException { zk = new ZooKeeper(hosts, 10000, this); this.count = count; this.readsPerWrite = readsPerWrite; } + /** + * @param args + * @throws IOException + * @throws KeeperException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, + IOException { + if (args.length != 3) { + System.err + .println("USAGE: SledgeHammer zookeeper_server reps reads_per_rep"); + System.exit(3); + } + SledgeHammer h = new SledgeHammer(args[0], Integer.parseInt(args[1]), + Integer.parseInt(args[2])); + h.start(); + System.exit(0); + } + public void run() { try { Stat stat = new Stat(); String path = zk.create("/hammers/hammer-", new byte[0], - Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE); + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); byte tag[] = (path + " was here!").getBytes(); synchronized (this) { String startPath = "/hammers/start"; @@ -43,8 +73,8 @@ public void run() { for (int i = 0; i < count; i++) { try { System.out.print(i + "\r"); - ArrayList childs = zk - .getChildren("/hammers", false); + List childs = + zk.getChildren("/hammers", false); Collections.shuffle(childs); for (String s : childs) { if (s.startsWith("hammer-")) { @@ -56,39 +86,24 @@ public void run() { break; } } + } catch (KeeperException.ConnectionLossException e) { + // ignore connection loss } catch (KeeperException e) { - if (e.getCode() != KeeperException.Code.ConnectionLoss) { - e.printStackTrace(); - } + e.printStackTrace(); } } System.out.println(); zk.close(); - } catch (Exception e) { + } catch (RuntimeException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (KeeperException e) { e.printStackTrace(); } } - /** - * @param args - * @throws IOException - * @throws KeeperException - * @throws NumberFormatException - */ - public static void main(String[] args) throws NumberFormatException, - KeeperException, IOException { - if (args.length != 3) { - System.err - .println("USAGE: SledgeHammer zookeeper_server reps reads_per_rep"); - System.exit(3); - } - SledgeHammer h = new SledgeHammer(args[0], Integer.parseInt(args[1]), - Integer.parseInt(args[2])); - h.run(); - System.exit(0); - } - - public void process(WatcherEvent event) { + public void process(WatchedEvent event) { synchronized (this) { notifyAll(); } diff --git a/src/java/test/org/apache/zookeeper/test/StandaloneTest.java b/src/java/test/org/apache/zookeeper/test/StandaloneTest.java new file mode 100644 index 00000000000..4822536879c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/StandaloneTest.java @@ -0,0 +1,148 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.quorum.QuorumPeerTestBase; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT; + +/** + * Standalone server tests. + */ +public class StandaloneTest extends QuorumPeerTestBase implements Watcher { + protected static final Logger LOG = + LoggerFactory.getLogger(StandaloneTest.class); + + /** + * This test wouldn't create any dynamic config. + * However, it adds a "clientPort=XXX" in static config file. + * It checks the standard way of standalone mode. + */ + @Test + public void testNoDynamicConfig() throws Exception { + ClientBase.setupTestEnv(); + final int CLIENT_PORT = PortAssignment.unique(); + + MainThread mt = new MainThread( + MainThread.UNSET_MYID, CLIENT_PORT, "", false); + verifyStandalone(mt, CLIENT_PORT); + } + + /** + * This test creates a dynamic config of new format. + * The dynamic config is written in dynamic config file. + * It checks that the client port will be read from the dynamic config. + * + * This handles the case of HBase, which adds a single server line to the config. + * Maintain b/w compatibility. + */ + @Test + public void testClientPortInDynamicFile() throws Exception { + ClientBase.setupTestEnv(); + final int CLIENT_PORT = PortAssignment.unique(); + + String quorumCfgSection = "server.1=127.0.0.1:" + + (PortAssignment.unique()) + ":" + (PortAssignment.unique()) + + ":participant;" + CLIENT_PORT + "\n"; + + MainThread mt = new MainThread(1, quorumCfgSection); + verifyStandalone(mt, CLIENT_PORT); + } + + /** + * This test creates a dynamic config of new format. + * The dynamic config is written in static config file. + * It checks that the client port will be read from the dynamic config. + */ + @Test + public void testClientPortInStaticFile() throws Exception { + ClientBase.setupTestEnv(); + final int CLIENT_PORT = PortAssignment.unique(); + + String quorumCfgSection = "server.1=127.0.0.1:" + + (PortAssignment.unique()) + ":" + (PortAssignment.unique()) + + ":participant;" + CLIENT_PORT + "\n"; + + MainThread mt = new MainThread(1, quorumCfgSection, false); + verifyStandalone(mt, CLIENT_PORT); + } + + void verifyStandalone(MainThread mt, int clientPort) throws InterruptedException { + mt.start(); + try { + Assert.assertTrue("waiting for server 1 being up", + ClientBase.waitForServerUp("127.0.0.1:" + clientPort, + CONNECTION_TIMEOUT)); + } finally { + Assert.assertFalse("Error- MainThread started in Quorum Mode!", + mt.isQuorumPeerRunning()); + mt.shutdown(); + } + } + + /** + * Verify that reconfiguration in standalone mode fails with + * KeeperException.UnimplementedException. + */ + @Test + public void testStandaloneReconfigFails() throws Exception { + ClientBase.setupTestEnv(); + + final int CLIENT_PORT = PortAssignment.unique(); + final String HOSTPORT = "127.0.0.1:" + CLIENT_PORT; + + File tmpDir = ClientBase.createTmpDir(); + ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); + + ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1); + f.startup(zks); + Assert.assertTrue("waiting for server being up ", ClientBase + .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); + + CountdownWatcher watcher = new CountdownWatcher(); + ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, watcher); + watcher.waitForConnected(CONNECTION_TIMEOUT); + + List joiners = new ArrayList(); + joiners.add("server.2=localhost:1234:1235;1236"); + // generate some transactions that will get logged + try { + zk.reconfig(joiners, null, null, -1, new Stat()); + Assert.fail("Reconfiguration in standalone should trigger " + + "UnimplementedException"); + } catch (KeeperException.UnimplementedException ex) { + // expected + } + zk.close(); + + zks.shutdown(); + f.shutdown(); + Assert.assertTrue("waiting for server being down ", ClientBase + .waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/StatTest.java b/src/java/test/org/apache/zookeeper/test/StatTest.java new file mode 100644 index 00000000000..c1815f0f48c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/StatTest.java @@ -0,0 +1,194 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +public class StatTest extends ClientBase { + private ZooKeeper zk; + + @Override + public void setUp() throws Exception { + super.setUp(); + + zk = createClient(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + + zk.close(); + } + + /** + * Create a new Stat, fill in dummy values trying to catch Assert.failure + * to copy in client or server code. + * + * @return a new stat with dummy values + */ + private Stat newStat() { + Stat stat = new Stat(); + + stat.setAversion(100); + stat.setCtime(100); + stat.setCversion(100); + stat.setCzxid(100); + stat.setDataLength(100); + stat.setEphemeralOwner(100); + stat.setMtime(100); + stat.setMzxid(100); + stat.setNumChildren(100); + stat.setPzxid(100); + stat.setVersion(100); + + return stat; + } + + @Test + public void testBasic() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + Stat stat; + + stat = newStat(); + zk.getData(name, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(0, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(0, stat.getNumChildren()); + } + + @Test + public void testChild() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + String childname = name + "/bar"; + zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + + Stat stat; + + stat = newStat(); + zk.getData(name, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid() + 1, stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(1, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(1, stat.getNumChildren()); + + stat = newStat(); + zk.getData(childname, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(0, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(zk.getSessionId(), stat.getEphemeralOwner()); + Assert.assertEquals(childname.length(), stat.getDataLength()); + Assert.assertEquals(0, stat.getNumChildren()); + } + + @Test + public void testChildren() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + for (int i = 0; i < 10; i++) { + String childname = name + "/bar" + i; + zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + + Stat stat; + + stat = newStat(); + zk.getData(name, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid() + i + 1, stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(i + 1, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(i + 1, stat.getNumChildren()); + } + } + + @Test + public void testDataSizeChange() + throws IOException, KeeperException, InterruptedException { + String name = "/foo"; + zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + Stat stat; + + stat = newStat(); + zk.getData(name, false, stat); + + Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); + Assert.assertEquals(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(0, stat.getCversion()); + Assert.assertEquals(0, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length(), stat.getDataLength()); + Assert.assertEquals(0, stat.getNumChildren()); + + zk.setData(name, (name + name).getBytes(), -1); + + stat = newStat(); + zk.getData(name, false, stat); + + Assert.assertNotSame(stat.getCzxid(), stat.getMzxid()); + Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); + Assert.assertNotSame(stat.getCtime(), stat.getMtime()); + Assert.assertEquals(0, stat.getCversion()); + Assert.assertEquals(1, stat.getVersion()); + Assert.assertEquals(0, stat.getAversion()); + Assert.assertEquals(0, stat.getEphemeralOwner()); + Assert.assertEquals(name.length() * 2, stat.getDataLength()); + Assert.assertEquals(0, stat.getNumChildren()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java b/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java new file mode 100644 index 00000000000..4138b2e63aa --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java @@ -0,0 +1,511 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.client.HostProvider; +import org.apache.zookeeper.client.StaticHostProvider; +import org.apache.zookeeper.common.Time; +import org.junit.Test; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Random; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +public class StaticHostProviderTest extends ZKTestCase { + private final double slackPercent = 10; + private final int numClients = 10000; + private Random r = new Random(1); + private HashMap> precomputedLists = new + HashMap>(); + + @Test + public void testNextGoesRound() { + HostProvider hostProvider = getHostProvider((byte) 2); + InetSocketAddress first = hostProvider.next(0); + assertTrue(first != null); + hostProvider.next(0); + assertEquals(first, hostProvider.next(0)); + } + + @Test + public void testNextGoesRoundAndSleeps() { + byte size = 2; + HostProvider hostProvider = getHostProvider(size); + while (size > 0) { + hostProvider.next(0); + --size; + } + long start = Time.currentElapsedTime(); + hostProvider.next(1000); + long stop = Time.currentElapsedTime(); + assertTrue(900 <= stop - start); + } + + @Test + public void testNextDoesNotSleepForZero() { + byte size = 2; + HostProvider hostProvider = getHostProvider(size); + while (size > 0) { + hostProvider.next(0); + --size; + } + long start = Time.currentElapsedTime(); + hostProvider.next(0); + long stop = Time.currentElapsedTime(); + assertTrue(5 > stop - start); + } + + @Test(expected = IllegalArgumentException.class) + public void testTwoInvalidHostAddresses() { + ArrayList list = new ArrayList(); + list.add(new InetSocketAddress("a...", 2181)); + list.add(new InetSocketAddress("b...", 2181)); + new StaticHostProvider(list); + } + + @Test + public void testOneInvalidHostAddresses() { + Collection addr = getServerAddresses((byte) 1); + addr.add(new InetSocketAddress("a...", 2181)); + + StaticHostProvider sp = new StaticHostProvider(addr); + InetSocketAddress n1 = sp.next(0); + InetSocketAddress n2 = sp.next(0); + + assertEquals(n2, n1); + } + + @Test + public void testTwoConsequitiveCallsToNextReturnDifferentElement() { + HostProvider hostProvider = getHostProvider((byte) 2); + assertNotSame(hostProvider.next(0), hostProvider.next(0)); + } + + @Test + public void testOnConnectDoesNotReset() { + HostProvider hostProvider = getHostProvider((byte) 2); + InetSocketAddress first = hostProvider.next(0); + hostProvider.onConnected(); + InetSocketAddress second = hostProvider.next(0); + assertNotSame(first, second); + } + + @Test + public void testUpdateClientMigrateOrNot() throws UnknownHostException { + HostProvider hostProvider = getHostProvider((byte) 4); // 10.10.10.4:1238, 10.10.10.3:1237, 10.10.10.2:1236, 10.10.10.1:1235 + Collection newList = getServerAddresses((byte) 3); // 10.10.10.3:1237, 10.10.10.2:1236, 10.10.10.1:1235 + + InetSocketAddress myServer = new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 3}), 1237); + + // Number of machines becomes smaller, my server is in the new cluster + boolean disconnectRequired = hostProvider.updateServerList(newList, myServer); + assertTrue(!disconnectRequired); + hostProvider.onConnected(); + + // Number of machines stayed the same, my server is in the new cluster + disconnectRequired = hostProvider.updateServerList(newList, myServer); + assertTrue(!disconnectRequired); + hostProvider.onConnected(); + + // Number of machines became smaller, my server is not in the new + // cluster + newList = getServerAddresses((byte) 2); // 10.10.10.2:1236, 10.10.10.1:1235 + disconnectRequired = hostProvider.updateServerList(newList, myServer); + assertTrue(disconnectRequired); + hostProvider.onConnected(); + + // Number of machines stayed the same, my server is not in the new + // cluster + disconnectRequired = hostProvider.updateServerList(newList, myServer); + assertTrue(disconnectRequired); + hostProvider.onConnected(); + + // Number of machines increased, my server is not in the new cluster + newList = new ArrayList(3); + for (byte i = 4; i > 1; i--) { // 10.10.10.4:1238, 10.10.10.3:1237, 10.10.10.2:1236 + newList.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i)); + } + myServer = new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 1}), 1235); + disconnectRequired = hostProvider.updateServerList(newList, myServer); + assertTrue(disconnectRequired); + hostProvider.onConnected(); + + // Number of machines increased, my server is in the new cluster + // Here whether to move or not depends on the difference of cluster + // sizes + // With probability 1 - |old|/|new} the client disconnects + // In the test below 1-9/10 = 1/10 chance of disconnecting + HostProvider[] hostProviderArray = new HostProvider[numClients]; + newList = getServerAddresses((byte) 10); + int numDisconnects = 0; + for (int i = 0; i < numClients; i++) { + hostProviderArray[i] = getHostProvider((byte) 9); + disconnectRequired = hostProviderArray[i].updateServerList(newList, myServer); + if (disconnectRequired) + numDisconnects++; + } + hostProvider.onConnected(); + + // should be numClients/10 in expectation, we test that its numClients/10 +- slackPercent + assertTrue(numDisconnects < upperboundCPS(numClients, 10)); + } + + @Test + public void testUpdateMigrationGoesRound() throws UnknownHostException { + HostProvider hostProvider = getHostProvider((byte) 4); + // old list (just the ports): 1238, 1237, 1236, 1235 + Collection newList = new ArrayList( + 10); + for (byte i = 12; i > 2; i--) { // 1246, 1245, 1244, 1243, 1242, 1241, + // 1240, 1239, 1238, 1237 + newList.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i)); + } + + // servers from the old list that appear in the new list + Collection oldStaying = new ArrayList(2); + for (byte i = 4; i > 2; i--) { // 1238, 1237 + oldStaying.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i)); + } + + // servers in the new list that are not in the old list + Collection newComing = new ArrayList(10); + for (byte i = 12; i > 4; i--) {// 1246, 1245, 1244, 1243, 1242, 1241, 1240, 1139 + newComing.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i)); + } + + // Number of machines increases, my server is not in the new cluster + // load on old servers must be decreased, so must connect to one of the + // new servers + // i.e., pNew = 1. + + boolean disconnectRequired = hostProvider.updateServerList(newList, new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 1}), 1235)); + assertTrue(disconnectRequired); + + // This means reconfigMode = true, and nextHostInReconfigMode will be + // called from next + // Since pNew = 1 we should first try the new servers + ArrayList seen = new ArrayList(); + for (int i = 0; i < newComing.size(); i++) { + InetSocketAddress addr = hostProvider.next(0); + assertTrue(newComing.contains(addr)); + assertTrue(!seen.contains(addr)); + seen.add(addr); + } + + // Next the old servers + seen.clear(); + for (int i = 0; i < oldStaying.size(); i++) { + InetSocketAddress addr = hostProvider.next(0); + assertTrue(oldStaying.contains(addr)); + assertTrue(!seen.contains(addr)); + seen.add(addr); + } + + // And now it goes back to normal next() so it should be everything + // together like in testNextGoesRound() + InetSocketAddress first = hostProvider.next(0); + assertTrue(first != null); + for (int i = 0; i < newList.size() - 1; i++) { + hostProvider.next(0); + } + + assertEquals(first, hostProvider.next(0)); + hostProvider.onConnected(); + } + + @Test + public void testUpdateLoadBalancing() throws UnknownHostException { + // Start with 9 servers and 10000 clients + boolean disconnectRequired; + HostProvider[] hostProviderArray = new HostProvider[numClients]; + InetSocketAddress[] curHostForEachClient = new InetSocketAddress[numClients]; + int[] numClientsPerHost = new int[9]; + + // initialization + for (int i = 0; i < numClients; i++) { + hostProviderArray[i] = getHostProvider((byte) 9); + curHostForEachClient[i] = hostProviderArray[i].next(0); + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + hostProviderArray[i].onConnected(); + } + + for (int i = 0; i < 9; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 9)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 9)); + numClientsPerHost[i] = 0; // prepare for next test + } + + // remove host number 8 (the last one in a list of 9 hosts) + Collection newList = getServerAddresses((byte) 8); + + for (int i = 0; i < numClients; i++) { + disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]); + if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0); + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + hostProviderArray[i].onConnected(); + } + + for (int i = 0; i < 8; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 8)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 8)); + numClientsPerHost[i] = 0; // prepare for next test + } + assertTrue(numClientsPerHost[8] == 0); + + // remove hosts number 6 and 7 (the currently last two in the list) + newList = getServerAddresses((byte) 6); + + for (int i = 0; i < numClients; i++) { + disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]); + if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0); + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + hostProviderArray[i].onConnected(); + } + + for (int i = 0; i < 6; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 6)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 6)); + numClientsPerHost[i] = 0; // prepare for next test + } + assertTrue(numClientsPerHost[6] == 0); + assertTrue(numClientsPerHost[7] == 0); + assertTrue(numClientsPerHost[8] == 0); + + // remove host number 0 (the first one in the current list) + // and add back hosts 6, 7 and 8 + newList = new ArrayList(8); + for (byte i = 9; i > 1; i--) { + newList.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i)); + } + + for (int i = 0; i < numClients; i++) { + disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]); + if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0); + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + hostProviderArray[i].onConnected(); + } + + assertTrue(numClientsPerHost[0] == 0); + + for (int i = 1; i < 9; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 8)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 8)); + numClientsPerHost[i] = 0; // prepare for next test + } + + // add back host number 0 + newList = getServerAddresses((byte) 9); + + for (int i = 0; i < numClients; i++) { + disconnectRequired = hostProviderArray[i].updateServerList(newList, curHostForEachClient[i]); + if (disconnectRequired) curHostForEachClient[i] = hostProviderArray[i].next(0); + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + hostProviderArray[i].onConnected(); + } + + for (int i = 0; i < 9; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 9)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 9)); + } + } + + @Test + public void testNoCurrentHostDuringNormalMode() throws UnknownHostException { + // Start with 9 servers and 10000 clients + boolean disconnectRequired; + StaticHostProvider[] hostProviderArray = new StaticHostProvider[numClients]; + InetSocketAddress[] curHostForEachClient = new InetSocketAddress[numClients]; + int[] numClientsPerHost = new int[9]; + + // initialization + for (int i = 0; i < numClients; i++) { + hostProviderArray[i] = getHostProvider((byte) 9); + if (i >= (numClients / 2)) { + curHostForEachClient[i] = hostProviderArray[i].next(0); + } else { + // its supposed to be the first server on serverList. + // we'll set it later, see below (*) + curHostForEachClient[i] = null; + } + } + + // remove hosts 7 and 8 (the last two in a list of 9 hosts) + Collection newList = getServerAddresses((byte) 7); + + for (int i = 0; i < numClients; i++) { + // tests the case currentHost == null && lastIndex == -1 + // calls next for clients with index < numClients/2 + disconnectRequired = hostProviderArray[i].updateServerList(newList, + curHostForEachClient[i]); + if (disconnectRequired) + curHostForEachClient[i] = hostProviderArray[i].next(0); + else if (curHostForEachClient[i] == null) { + // (*) setting it to what it should be + curHostForEachClient[i] = hostProviderArray[i] + .getServerAtIndex(0); + } + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + // sets lastIndex, resets reconfigMode + hostProviderArray[i].onConnected(); + } + + for (int i = 0; i < 7; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 7)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 7)); + numClientsPerHost[i] = 0; // prepare for next test + } + assertTrue(numClientsPerHost[7] == 0); + assertTrue(numClientsPerHost[8] == 0); + + // add back server 7 + newList = getServerAddresses((byte) 8); + + for (int i = 0; i < numClients; i++) { + InetSocketAddress myServer = (i < (numClients / 2)) ? null + : curHostForEachClient[i]; + // tests the case currentHost == null && lastIndex >= 0 + disconnectRequired = hostProviderArray[i].updateServerList(newList, + myServer); + if (disconnectRequired) + curHostForEachClient[i] = hostProviderArray[i].next(0); + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + hostProviderArray[i].onConnected(); + } + + for (int i = 0; i < 8; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 8)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 8)); + } + } + + @Test + public void testReconfigDuringReconfigMode() throws UnknownHostException { + // Start with 9 servers and 10000 clients + boolean disconnectRequired; + StaticHostProvider[] hostProviderArray = new StaticHostProvider[numClients]; + InetSocketAddress[] curHostForEachClient = new InetSocketAddress[numClients]; + int[] numClientsPerHost = new int[9]; + + // initialization + for (int i = 0; i < numClients; i++) { + hostProviderArray[i] = getHostProvider((byte) 9); + curHostForEachClient[i] = hostProviderArray[i].next(0); + } + + // remove hosts 7 and 8 (the last two in a list of 9 hosts) + Collection newList = getServerAddresses((byte) 7); + + for (int i = 0; i < numClients; i++) { + // sets reconfigMode + hostProviderArray[i].updateServerList(newList, + curHostForEachClient[i]); + } + + // add back servers 7 and 8 while still in reconfigMode (we didn't call + // next) + newList = getServerAddresses((byte) 9); + + for (int i = 0; i < numClients; i++) { + InetSocketAddress myServer = (i < (numClients / 2)) ? null + : curHostForEachClient[i]; + // for i < (numClients/2) this tests the case currentHost == null && + // reconfigMode = true + // for i >= (numClients/2) this tests the case currentHost!=null && + // reconfigMode = true + disconnectRequired = hostProviderArray[i].updateServerList(newList, + myServer); + if (disconnectRequired) + curHostForEachClient[i] = hostProviderArray[i].next(0); + else { + // currentIndex was set by the call to updateServerList, which + // called next + curHostForEachClient[i] = hostProviderArray[i] + .getServerAtCurrentIndex(); + } + numClientsPerHost[curHostForEachClient[i].getPort() - 1235]++; + hostProviderArray[i].onConnected(); + } + + for (int i = 0; i < 9; i++) { + assertTrue(numClientsPerHost[i] <= upperboundCPS(numClients, 9)); + assertTrue(numClientsPerHost[i] >= lowerboundCPS(numClients, 9)); + } + } + + private StaticHostProvider getHostProvider(byte size) { + return new StaticHostProvider(getServerAddresses(size), r.nextLong()); + } + + private Collection getServerAddresses(byte size) { + if (precomputedLists.containsKey(size)) return precomputedLists.get(size); + ArrayList list = new ArrayList( + size); + while (size > 0) { + try { + list.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, size}), 1234 + size)); + } catch (UnknownHostException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + --size; + } + precomputedLists.put(size, list); + return list; + } + + private double lowerboundCPS(int numClients, int numServers) { + return (1 - slackPercent / 100.0) * numClients / numServers; + } + + private double upperboundCPS(int numClients, int numServers) { + return (1 + slackPercent / 100.0) * numClients / numServers; + } + + @Test + public void testLiteralIPNoReverseNS() throws Exception { + byte size = 30; + HostProvider hostProvider = getHostProviderUnresolved(size); + for (int i = 0; i < size; i++) { + InetSocketAddress next = hostProvider.next(0); + assertTrue(next instanceof InetSocketAddress); + assertTrue(!next.isUnresolved()); + assertTrue(!next.toString().startsWith("/")); + // Do NOT trigger the reverse name service lookup. + String hostname = next.getHostString(); + // In this case, the hostname equals literal IP address. + hostname.equals(next.getAddress().getHostAddress()); + } + } + + private StaticHostProvider getHostProviderUnresolved(byte size) + throws UnknownHostException { + return new StaticHostProvider(getUnresolvedServerAddresses(size), r.nextLong()); + } + + private Collection getUnresolvedServerAddresses(byte size) { + ArrayList list = new ArrayList(size); + while (size > 0) { + list.add(InetSocketAddress.createUnresolved("10.10.10." + size, 1234 + size)); + --size; + } + return list; + } +} diff --git a/src/java/test/org/apache/zookeeper/test/StringUtilTest.java b/src/java/test/org/apache/zookeeper/test/StringUtilTest.java new file mode 100644 index 00000000000..4531eb0c8db --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/StringUtilTest.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + + +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.common.StringUtils; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class StringUtilTest extends ZKTestCase { + + @Test + public void testStrings() { + + String s1 = " a , b , "; + assertEquals("[a, b]", StringUtils.split(s1, ",").toString()); + + String s2 = ""; + assertEquals(0, StringUtils.split(s2, ",").size()); + + String s3 = "1, , 2"; + assertEquals("[1, 2]", StringUtils.split(s3, ",").toString()); + + } +} diff --git a/src/java/test/org/apache/zookeeper/test/SyncCallTest.java b/src/java/test/org/apache/zookeeper/test/SyncCallTest.java new file mode 100644 index 00000000000..0bd260392a5 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/SyncCallTest.java @@ -0,0 +1,113 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.Children2Callback; +import org.apache.zookeeper.AsyncCallback.ChildrenCallback; +import org.apache.zookeeper.AsyncCallback.Create2Callback; +import org.apache.zookeeper.AsyncCallback.StringCallback; +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class SyncCallTest extends ClientBase + implements ChildrenCallback, Children2Callback, + StringCallback, VoidCallback, Create2Callback { + List results = new LinkedList(); + Integer limit = 100 + 1 + 100 + 100; + private CountDownLatch opsCount; + + @Test + public void testSync() throws Exception { + try { + LOG.info("Starting ZK:" + (new Date()).toString()); + opsCount = new CountDownLatch(limit); + ZooKeeper zk = createClient(); + + LOG.info("Beginning test:" + (new Date()).toString()); + for (int i = 0; i < 50; i++) + zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT, (StringCallback) this, results); + + for (int i = 50; i < 100; i++) { + zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT, (Create2Callback) this, results); + } + zk.sync("/test", this, results); + for (int i = 0; i < 100; i++) + zk.delete("/test" + i, 0, this, results); + for (int i = 0; i < 100; i++) + zk.getChildren("/", new NullWatcher(), (ChildrenCallback) this, + results); + for (int i = 0; i < 100; i++) + zk.getChildren("/", new NullWatcher(), (Children2Callback) this, + results); + LOG.info("Submitted all operations:" + (new Date()).toString()); + + if (!opsCount.await(10000, TimeUnit.MILLISECONDS)) + Assert.fail("Haven't received all confirmations" + opsCount.getCount()); + + for (int i = 0; i < limit; i++) { + Assert.assertEquals(0, (int) results.get(i)); + } + + } catch (IOException e) { + System.out.println(e.toString()); + } + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, + List children) { + ((List) ctx).add(rc); + opsCount.countDown(); + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, + List children, Stat stat) { + ((List) ctx).add(rc); + opsCount.countDown(); + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx, String name) { + ((List) ctx).add(rc); + opsCount.countDown(); + + } + + @SuppressWarnings("unchecked") + public void processResult(int rc, String path, Object ctx) { + ((List) ctx).add(rc); + opsCount.countDown(); + + } + + @Override + public void processResult(int rc, String path, Object ctx, String name, + Stat stat) { + ((List) ctx).add(rc); + opsCount.countDown(); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/TestHammer.java b/src/java/test/org/apache/zookeeper/test/TestHammer.java new file mode 100644 index 00000000000..17f6df4802c --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/TestHammer.java @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.Time; + +import java.io.IOException; + +public class TestHammer implements VoidCallback { + + /** + * @param args + */ + static int REPS = 50000; + + public static void main(String[] args) { + long startTime = Time.currentElapsedTime(); + ZooKeeper zk = null; + try { + zk = new ZooKeeper(args[0], 10000, null); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + throw new RuntimeException(e1); + } + for (int i = 0; i < REPS; i++) { + try { + String name = zk.create("/testFile-", new byte[16], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL_SEQUENTIAL); + zk.delete(name, -1, new TestHammer(), null); + } catch (Exception e) { + i--; + e.printStackTrace(); + } + } + System.out.println("creates/sec=" + (REPS * 1000 / (Time.currentElapsedTime() - startTime))); + } + + public void processResult(int rc, String path, Object ctx) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/TestUtils.java b/src/java/test/org/apache/zookeeper/test/TestUtils.java new file mode 100644 index 00000000000..5ec3049e78f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/TestUtils.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.junit.Assert; + +import java.io.File; + +/** + * This class contains test utility methods + */ +public class TestUtils { + + /** + * deletes a folder recursively + * + * @param file + * folder to be deleted + * @param failOnError + * if true file deletion success is ensured + */ + public static boolean deleteFileRecursively(File file, + final boolean failOnError) { + if (file != null) { + if (file.isDirectory()) { + File[] files = file.listFiles(); + int size = files.length; + for (int i = 0; i < size; i++) { + File f = files[i]; + boolean deleted = deleteFileRecursively(files[i], failOnError); + if (!deleted && failOnError) { + Assert.fail("file '" + f.getAbsolutePath() + "' deletion failed"); + } + } + } + return file.delete(); + } + return true; + } + + public static boolean deleteFileRecursively(File file) { + return deleteFileRecursively(file, false); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/TruncateTest.java b/src/java/test/org/apache/zookeeper/test/TruncateTest.java new file mode 100644 index 00000000000..8e613900301 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/TruncateTest.java @@ -0,0 +1,251 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.jute.Record; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.PortAssignment; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.Request; +import org.apache.zookeeper.server.ServerCnxnFactory; +import org.apache.zookeeper.server.ZKDatabase; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; +import org.apache.zookeeper.txn.SetDataTxn; +import org.apache.zookeeper.txn.TxnHeader; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.HashMap; + +public class TruncateTest extends ZKTestCase { + private static final Logger LOG = LoggerFactory.getLogger(TruncateTest.class); + File dataDir1, dataDir2, dataDir3; + volatile boolean connected; + Watcher nullWatcher = new Watcher() { + @Override + public void process(WatchedEvent event) { + connected = event.getState() == Watcher.Event.KeeperState.SyncConnected; + } + }; + + @Before + public void setUp() throws IOException { + dataDir1 = ClientBase.createTmpDir(); + dataDir2 = ClientBase.createTmpDir(); + dataDir3 = ClientBase.createTmpDir(); + } + + @After + public void tearDown() { + ClientBase.recursiveDelete(dataDir1); + ClientBase.recursiveDelete(dataDir2); + ClientBase.recursiveDelete(dataDir3); + } + + @Test + public void testTruncationStreamReset() throws Exception { + File tmpdir = ClientBase.createTmpDir(); + FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir); + ZKDatabase zkdb = new ZKDatabase(snaplog); + + for (int i = 1; i <= 100; i++) { + append(zkdb, i); + } + + zkdb.truncateLog(1); + + append(zkdb, 200); + + zkdb.close(); + + // verify that the truncation and subsequent append were processed + // correctly + FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2")); + TxnIterator iter = txnlog.read(1); + + TxnHeader hdr = iter.getHeader(); + Record txn = iter.getTxn(); + Assert.assertEquals(1, hdr.getZxid()); + Assert.assertTrue(txn instanceof SetDataTxn); + + iter.next(); + + hdr = iter.getHeader(); + txn = iter.getTxn(); + Assert.assertEquals(200, hdr.getZxid()); + Assert.assertTrue(txn instanceof SetDataTxn); + iter.close(); + ClientBase.recursiveDelete(tmpdir); + } + + @Test + public void testTruncationNullLog() throws Exception { + File tmpdir = ClientBase.createTmpDir(); + FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir); + ZKDatabase zkdb = new ZKDatabase(snaplog); + + for (int i = 1; i <= 100; i++) { + append(zkdb, i); + } + zkdb.close(); + File[] logs = snaplog.getDataDir().listFiles(); + for (int i = 0; i < logs.length; i++) { + LOG.debug("Deleting: {}", logs[i].getName()); + Assert.assertTrue("Failed to delete log file: " + logs[i].getName(), logs[i].delete()); + } + try { + zkdb.truncateLog(1); + Assert.assertTrue("Should not get here", false); + } catch (IOException e) { + Assert.assertTrue("Should have received an IOException", true); + } catch (NullPointerException npe) { + Assert.fail("This should not throw NPE!"); + } + + ClientBase.recursiveDelete(tmpdir); + } + + private void append(ZKDatabase zkdb, int i) throws IOException { + TxnHeader hdr = new TxnHeader(1, 1, i, 1, ZooDefs.OpCode.setData); + Record txn = new SetDataTxn("/foo" + i, new byte[0], 1); + Request req = new Request(0, 0, 0, hdr, txn, 0); + + zkdb.append(req); + zkdb.commit(); + } + + @Test + public void testTruncate() throws IOException, InterruptedException, KeeperException { + // Prime the server that is going to come in late with 50 txns + String hostPort = "127.0.0.1:" + PortAssignment.unique(); + int maxCnxns = 100; + ServerCnxnFactory factory = ClientBase.createNewServerInstance(null, + hostPort, maxCnxns); + ClientBase.startServerInstance(dataDir1, factory, hostPort); + ClientBase.shutdownServerInstance(factory, hostPort); + + // standalone starts with 0 epoch while quorum starts with 1 + File origfile = new File(new File(dataDir1, "version-2"), "snapshot.0"); + File newfile = new File(new File(dataDir1, "version-2"), "snapshot.100000000"); + origfile.renameTo(newfile); + + factory = ClientBase.createNewServerInstance(null, hostPort, maxCnxns); + ClientBase.startServerInstance(dataDir1, factory, hostPort); + + ZooKeeper zk = new ZooKeeper(hostPort, 15000, nullWatcher); + for (int i = 0; i < 50; i++) { + zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + zk.close(); + + ZKDatabase zkDb; + { + ZooKeeperServer zs = ClientBase.getServer(factory); + + zkDb = zs.getZKDatabase(); + } + factory.shutdown(); + try { + zkDb.close(); + } catch (IOException ie) { + LOG.warn("Error closing logs ", ie); + } + int tickTime = 2000; + int initLimit = 3; + int syncLimit = 3; + + int port1 = PortAssignment.unique(); + int port2 = PortAssignment.unique(); + int port3 = PortAssignment.unique(); + + // Start up two of the quorum and add 10 txns + HashMap peers = new HashMap(); + peers.put(Long.valueOf(1), new QuorumServer(1, + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", port1))); + peers.put(Long.valueOf(2), new QuorumServer(2, + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", port2))); + peers.put(Long.valueOf(3), new QuorumServer(3, + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", PortAssignment.unique()), + new InetSocketAddress("127.0.0.1", port3))); + + QuorumPeer s2 = new QuorumPeer(peers, dataDir2, dataDir2, port2, 0, 2, tickTime, initLimit, syncLimit); + s2.start(); + QuorumPeer s3 = new QuorumPeer(peers, dataDir3, dataDir3, port3, 0, 3, tickTime, initLimit, syncLimit); + s3.start(); + connected = false; + zk = new ZooKeeper("127.0.0.1:" + port2, 15000, nullWatcher); + while (!connected) { + Thread.sleep(1000); + } + for (int i = 0; i < 10; i++) { + zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } + zk.close(); + + final ZooKeeper zk2 = new ZooKeeper("127.0.0.1:" + port2, 15000, nullWatcher); + zk2.getData("/9", false, new Stat()); + try { + zk2.getData("/10", false, new Stat()); + Assert.fail("Should have gotten an error"); + } catch (KeeperException.NoNodeException e) { + // this is what we want + } + QuorumPeer s1 = new QuorumPeer(peers, dataDir1, dataDir1, port1, 0, 1, tickTime, initLimit, syncLimit); + s1.start(); + + connected = false; + ZooKeeper zk1 = new ZooKeeper("127.0.0.1:" + port1, 15000, nullWatcher); + while (!connected) { + Thread.sleep(1000); + } + zk1.getData("/9", false, new Stat()); + try { + // /10 wont work because the session expiration + // will match the zxid for /10 and so we wont + // actually truncate the zxid for /10 creation + // due to an artifact of switching the xid of the standalone + // /11 is the last entry in the log for the xid + // as a result /12 is the first of the truncated znodes to check for + zk1.getData("/12", false, new Stat()); + Assert.fail("Should have gotten an error"); + } catch (KeeperException.NoNodeException e) { + // this is what we want + } + zk1.close(); + QuorumBase.shutdown(s1); + QuorumBase.shutdown(s2); + QuorumBase.shutdown(s3); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java b/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java new file mode 100644 index 00000000000..4939896fc24 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java @@ -0,0 +1,211 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.test.ClientBase.CountdownWatcher; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + + +public class WatchEventWhenAutoResetTest extends ZKTestCase { + protected static final Logger LOG = LoggerFactory + .getLogger(WatchEventWhenAutoResetTest.class); + + // waiting time for expected condition + private static final int TIMEOUT = 30000; + + private ZooKeeper createClient(QuorumUtil qu, int id, EventsWatcher watcher) + throws IOException { + String hostPort = "127.0.0.1:" + qu.getPeer(id).clientPort; + ZooKeeper zk = new ZooKeeper(hostPort, TIMEOUT, watcher); + try { + watcher.waitForConnected(TIMEOUT); + } catch (InterruptedException e) { + // ignoring the interrupt + } catch (TimeoutException e) { + Assert.fail("can not connect to " + hostPort); + } + return zk; + } + + private ZooKeeper createClient(QuorumUtil qu, int id) throws IOException { + return createClient(qu, id, new EventsWatcher()); + } + + @Before + public void setUp() { + System.setProperty("zookeeper.admin.enableServer", "false"); + } + + @Test + public void testNodeDataChanged() throws Exception { + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + + EventsWatcher watcher = new EventsWatcher(); + ZooKeeper zk1 = createClient(qu, 1, watcher); + ZooKeeper zk2 = createClient(qu, 2); + + String path = "/test-changed"; + + zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.getData(path, watcher, null); + qu.shutdown(1); + zk2.delete(path, -1); + zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + qu.start(1); + watcher.waitForConnected(TIMEOUT); + watcher.assertEvent(TIMEOUT, EventType.NodeDataChanged); + + zk1.exists(path, watcher); + qu.shutdown(1); + zk2.delete(path, -1); + zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + qu.start(1); + watcher.waitForConnected(TIMEOUT * 1000L); + watcher.assertEvent(TIMEOUT, EventType.NodeDataChanged); + + qu.shutdownAll(); + } + + @Test + public void testNodeCreated() throws Exception { + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + + EventsWatcher watcher = new EventsWatcher(); + ZooKeeper zk1 = createClient(qu, 1, watcher); + ZooKeeper zk2 = createClient(qu, 2); + + String path = "/test1-created"; + + zk1.exists(path, watcher); + qu.shutdown(1); + zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + qu.start(1); + watcher.waitForConnected(TIMEOUT * 1000L); + watcher.assertEvent(TIMEOUT, EventType.NodeCreated); + + qu.shutdownAll(); + } + + @Test + public void testNodeDeleted() throws Exception { + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + + EventsWatcher watcher = new EventsWatcher(); + ZooKeeper zk1 = createClient(qu, 1, watcher); + ZooKeeper zk2 = createClient(qu, 2); + + String path = "/test-deleted"; + + zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.getData(path, watcher, null); + qu.shutdown(1); + zk2.delete(path, -1); + qu.start(1); + watcher.waitForConnected(TIMEOUT * 1000L); + watcher.assertEvent(TIMEOUT, EventType.NodeDeleted); + + zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.exists(path, watcher); + qu.shutdown(1); + zk2.delete(path, -1); + qu.start(1); + watcher.waitForConnected(TIMEOUT * 1000L); + watcher.assertEvent(TIMEOUT, EventType.NodeDeleted); + + zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.getChildren(path, watcher); + qu.shutdown(1); + zk2.delete(path, -1); + qu.start(1); + watcher.waitForConnected(TIMEOUT * 1000L); + watcher.assertEvent(TIMEOUT, EventType.NodeDeleted); + + qu.shutdownAll(); + } + + @Test + public void testNodeChildrenChanged() throws Exception { + QuorumUtil qu = new QuorumUtil(1); + qu.startAll(); + + EventsWatcher watcher = new EventsWatcher(); + ZooKeeper zk1 = createClient(qu, 1, watcher); + ZooKeeper zk2 = createClient(qu, 2); + + String path = "/test-children-changed"; + + zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk1.getChildren(path, watcher); + qu.shutdown(1); + zk2.create(path + "/children-1", new byte[2], + ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + qu.start(1); + watcher.waitForConnected(TIMEOUT * 1000L); + watcher.assertEvent(TIMEOUT, EventType.NodeChildrenChanged); + + qu.shutdownAll(); + } + + static public class EventsWatcher extends CountdownWatcher { + private LinkedBlockingQueue dataEvents = new LinkedBlockingQueue(); + + @Override + public void process(WatchedEvent event) { + super.process(event); + try { + if (event.getType() != Event.EventType.None) { + dataEvents.put(event); + } + } catch (InterruptedException e) { + LOG.warn("ignoring interrupt during EventsWatcher process"); + } + } + + public void assertEvent(long timeout, EventType eventType) { + try { + WatchedEvent event = dataEvents.poll(timeout, + TimeUnit.MILLISECONDS); + Assert.assertNotNull("do not receive a " + eventType, event); + Assert.assertEquals(eventType, event.getType()); + } catch (InterruptedException e) { + LOG.warn("ignoring interrupt during EventsWatcher assertEvent"); + } + } + } +} + diff --git a/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java b/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java new file mode 100644 index 00000000000..592dcfc2610 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.proto.WatcherEvent; +import org.junit.Assert; +import org.junit.Test; + +import java.util.EnumSet; + +public class WatchedEventTest extends ZKTestCase { + + @Test + public void testCreatingWatchedEvent() { + // EventWatch is a simple, immutable type, so all we need to do + // is make sure we can create all possible combinations of values. + + EnumSet allTypes = EnumSet.allOf(EventType.class); + EnumSet allStates = EnumSet.allOf(KeeperState.class); + WatchedEvent we; + + for (EventType et : allTypes) { + for (KeeperState ks : allStates) { + we = new WatchedEvent(et, ks, "blah"); + Assert.assertEquals(et, we.getType()); + Assert.assertEquals(ks, we.getState()); + Assert.assertEquals("blah", we.getPath()); + } + } + } + + @Test + public void testCreatingWatchedEventFromWrapper() { + // Make sure we can handle any type of correct wrapper + + EnumSet allTypes = EnumSet.allOf(EventType.class); + EnumSet allStates = EnumSet.allOf(KeeperState.class); + WatchedEvent we; + WatcherEvent wep; + + for (EventType et : allTypes) { + for (KeeperState ks : allStates) { + wep = new WatcherEvent(et.getIntValue(), ks.getIntValue(), "blah"); + we = new WatchedEvent(wep); + Assert.assertEquals(et, we.getType()); + Assert.assertEquals(ks, we.getState()); + Assert.assertEquals("blah", we.getPath()); + } + } + } + + @Test + public void testCreatingWatchedEventFromInvalidWrapper() { + // Make sure we can't convert from an invalid wrapper + + try { + WatcherEvent wep = new WatcherEvent(-2342, -252352, "foo"); + new WatchedEvent(wep); + Assert.fail("Was able to create WatchedEvent from bad wrapper"); + } catch (RuntimeException re) { + // we're good + } + } + + @Test + public void testConvertingToEventWrapper() { + WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah"); + WatcherEvent wew = we.getWrapper(); + + Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType()); + Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState()); + Assert.assertEquals("blah", wew.getPath()); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java b/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java new file mode 100644 index 00000000000..803c0158299 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java @@ -0,0 +1,464 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.Watcher.Event.KeeperState; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +public class WatcherFuncTest extends ClientBase { + private SimpleWatcher client_dwatch; + private volatile CountDownLatch client_latch; + private ZooKeeper client; + private SimpleWatcher lsnr_dwatch; + private volatile CountDownLatch lsnr_latch; + private ZooKeeper lsnr; + private List expected; + + @Override + public void setUp() throws Exception { + super.setUp(); + + client_latch = new CountDownLatch(1); + client_dwatch = new SimpleWatcher(client_latch); + client = createClient(client_dwatch, client_latch); + + lsnr_latch = new CountDownLatch(1); + lsnr_dwatch = new SimpleWatcher(lsnr_latch); + lsnr = createClient(lsnr_dwatch, lsnr_latch); + + expected = new ArrayList(); + } + + @Override + public void tearDown() throws Exception { + client.close(); + lsnr.close(); + super.tearDown(); + } + + protected ZooKeeper createClient(Watcher watcher, CountDownLatch latch) + throws IOException, InterruptedException { + ZooKeeper zk = new ZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher); + if (!latch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)) { + Assert.fail("Unable to connect to server"); + } + return zk; + } + + private void verify() throws InterruptedException { + lsnr_dwatch.verify(expected); + expected.clear(); + } + + @Test + public void testExistsSync() + throws IOException, InterruptedException, KeeperException { + Assert.assertNull(lsnr.exists("/foo", true)); + Assert.assertNull(lsnr.exists("/foo/bar", true)); + + client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + expected.add(EventType.NodeCreated); + client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + expected.add(EventType.NodeCreated); + + verify(); + + Assert.assertNotNull(lsnr.exists("/foo", true)); + Assert.assertNotNull(lsnr.exists("/foo/bar", true)); + + try { + Assert.assertNull(lsnr.exists("/car", true)); + client.setData("/car", "missing".getBytes(), -1); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/car", e.getPath()); + } + + try { + Assert.assertNull(lsnr.exists("/foo/car", true)); + client.setData("/foo/car", "missing".getBytes(), -1); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo/car", e.getPath()); + } + + client.setData("/foo", "parent".getBytes(), -1); + expected.add(EventType.NodeDataChanged); + client.setData("/foo/bar", "child".getBytes(), -1); + expected.add(EventType.NodeDataChanged); + + verify(); + + Assert.assertNotNull(lsnr.exists("/foo", true)); + Assert.assertNotNull(lsnr.exists("/foo/bar", true)); + + client.delete("/foo/bar", -1); + expected.add(EventType.NodeDeleted); + client.delete("/foo", -1); + expected.add(EventType.NodeDeleted); + + verify(); + } + + @Test + public void testGetDataSync() + throws IOException, InterruptedException, KeeperException { + try { + lsnr.getData("/foo", true, null); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo", e.getPath()); + } + try { + lsnr.getData("/foo/bar", true, null); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo/bar", e.getPath()); + } + + client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertNotNull(lsnr.getData("/foo", true, null)); + client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertNotNull(lsnr.getData("/foo/bar", true, null)); + + client.setData("/foo", "parent".getBytes(), -1); + expected.add(EventType.NodeDataChanged); + client.setData("/foo/bar", "child".getBytes(), -1); + expected.add(EventType.NodeDataChanged); + + verify(); + + Assert.assertNotNull(lsnr.getData("/foo", true, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", true, null)); + + client.delete("/foo/bar", -1); + expected.add(EventType.NodeDeleted); + client.delete("/foo", -1); + expected.add(EventType.NodeDeleted); + + verify(); + } + + @Test + public void testGetChildrenSync() + throws IOException, InterruptedException, KeeperException { + try { + lsnr.getChildren("/foo", true); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo", e.getPath()); + } + try { + lsnr.getChildren("/foo/bar", true); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo/bar", e.getPath()); + } + + client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertNotNull(lsnr.getChildren("/foo", true)); + + client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + expected.add(EventType.NodeChildrenChanged); // /foo + Assert.assertNotNull(lsnr.getChildren("/foo/bar", true)); + + + client.setData("/foo", "parent".getBytes(), -1); + client.setData("/foo/bar", "child".getBytes(), -1); + + + Assert.assertNotNull(lsnr.exists("/foo", true)); + + Assert.assertNotNull(lsnr.getChildren("/foo", true)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", true)); + + client.delete("/foo/bar", -1); + expected.add(EventType.NodeDeleted); // /foo/bar childwatch + expected.add(EventType.NodeChildrenChanged); // /foo + client.delete("/foo", -1); + expected.add(EventType.NodeDeleted); + + verify(); + } + + @Test + public void testExistsSyncWObj() + throws IOException, InterruptedException, KeeperException { + SimpleWatcher w1 = new SimpleWatcher(null); + SimpleWatcher w2 = new SimpleWatcher(null); + SimpleWatcher w3 = new SimpleWatcher(null); + SimpleWatcher w4 = new SimpleWatcher(null); + + List e2 = new ArrayList(); + + Assert.assertNull(lsnr.exists("/foo", true)); + Assert.assertNull(lsnr.exists("/foo", w1)); + + Assert.assertNull(lsnr.exists("/foo/bar", w2)); + Assert.assertNull(lsnr.exists("/foo/bar", w3)); + Assert.assertNull(lsnr.exists("/foo/bar", w3)); + Assert.assertNull(lsnr.exists("/foo/bar", w4)); + + client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + expected.add(EventType.NodeCreated); + client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + e2.add(EventType.NodeCreated); + + lsnr_dwatch.verify(expected); + w1.verify(expected); + w2.verify(e2); + w3.verify(e2); + w4.verify(e2); + expected.clear(); + e2.clear(); + + // default not registered + Assert.assertNotNull(lsnr.exists("/foo", w1)); + + Assert.assertNotNull(lsnr.exists("/foo/bar", w2)); + Assert.assertNotNull(lsnr.exists("/foo/bar", w3)); + Assert.assertNotNull(lsnr.exists("/foo/bar", w4)); + Assert.assertNotNull(lsnr.exists("/foo/bar", w4)); + + client.setData("/foo", "parent".getBytes(), -1); + expected.add(EventType.NodeDataChanged); + client.setData("/foo/bar", "child".getBytes(), -1); + e2.add(EventType.NodeDataChanged); + + lsnr_dwatch.verify(new ArrayList()); // not reg so should = 0 + w1.verify(expected); + w2.verify(e2); + w3.verify(e2); + w4.verify(e2); + expected.clear(); + e2.clear(); + + Assert.assertNotNull(lsnr.exists("/foo", true)); + Assert.assertNotNull(lsnr.exists("/foo", w1)); + Assert.assertNotNull(lsnr.exists("/foo", w1)); + + Assert.assertNotNull(lsnr.exists("/foo/bar", w2)); + Assert.assertNotNull(lsnr.exists("/foo/bar", w2)); + Assert.assertNotNull(lsnr.exists("/foo/bar", w3)); + Assert.assertNotNull(lsnr.exists("/foo/bar", w4)); + + client.delete("/foo/bar", -1); + expected.add(EventType.NodeDeleted); + client.delete("/foo", -1); + e2.add(EventType.NodeDeleted); + + lsnr_dwatch.verify(expected); + w1.verify(expected); + w2.verify(e2); + w3.verify(e2); + w4.verify(e2); + expected.clear(); + e2.clear(); + + } + + @Test + public void testGetDataSyncWObj() + throws IOException, InterruptedException, KeeperException { + SimpleWatcher w1 = new SimpleWatcher(null); + SimpleWatcher w2 = new SimpleWatcher(null); + SimpleWatcher w3 = new SimpleWatcher(null); + SimpleWatcher w4 = new SimpleWatcher(null); + + List e2 = new ArrayList(); + + try { + lsnr.getData("/foo", w1, null); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo", e.getPath()); + } + try { + lsnr.getData("/foo/bar", w2, null); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo/bar", e.getPath()); + } + + client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertNotNull(lsnr.getData("/foo", true, null)); + Assert.assertNotNull(lsnr.getData("/foo", w1, null)); + client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null)); + + client.setData("/foo", "parent".getBytes(), -1); + expected.add(EventType.NodeDataChanged); + client.setData("/foo/bar", "child".getBytes(), -1); + e2.add(EventType.NodeDataChanged); + + lsnr_dwatch.verify(expected); + w1.verify(expected); + w2.verify(e2); + w3.verify(e2); + w4.verify(e2); + expected.clear(); + e2.clear(); + + Assert.assertNotNull(lsnr.getData("/foo", true, null)); + Assert.assertNotNull(lsnr.getData("/foo", w1, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null)); + Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null)); + + client.delete("/foo/bar", -1); + expected.add(EventType.NodeDeleted); + client.delete("/foo", -1); + e2.add(EventType.NodeDeleted); + + lsnr_dwatch.verify(expected); + w1.verify(expected); + w2.verify(e2); + w3.verify(e2); + w4.verify(e2); + expected.clear(); + e2.clear(); + } + + @Test + public void testGetChildrenSyncWObj() + throws IOException, InterruptedException, KeeperException { + SimpleWatcher w1 = new SimpleWatcher(null); + SimpleWatcher w2 = new SimpleWatcher(null); + SimpleWatcher w3 = new SimpleWatcher(null); + SimpleWatcher w4 = new SimpleWatcher(null); + + List e2 = new ArrayList(); + + try { + lsnr.getChildren("/foo", true); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo", e.getPath()); + } + try { + lsnr.getChildren("/foo/bar", true); + Assert.fail(); + } catch (KeeperException e) { + Assert.assertEquals(KeeperException.Code.NONODE, e.code()); + Assert.assertEquals("/foo/bar", e.getPath()); + } + + client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + Assert.assertNotNull(lsnr.getChildren("/foo", true)); + Assert.assertNotNull(lsnr.getChildren("/foo", w1)); + + client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + expected.add(EventType.NodeChildrenChanged); // /foo + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4)); + + + client.setData("/foo", "parent".getBytes(), -1); + client.setData("/foo/bar", "child".getBytes(), -1); + + + Assert.assertNotNull(lsnr.exists("/foo", true)); + Assert.assertNotNull(lsnr.exists("/foo", w1)); + Assert.assertNotNull(lsnr.exists("/foo", true)); + Assert.assertNotNull(lsnr.exists("/foo", w1)); + + Assert.assertNotNull(lsnr.getChildren("/foo", true)); + Assert.assertNotNull(lsnr.getChildren("/foo", w1)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4)); + Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4)); + + client.delete("/foo/bar", -1); + e2.add(EventType.NodeDeleted); // /foo/bar childwatch + expected.add(EventType.NodeChildrenChanged); // /foo + client.delete("/foo", -1); + expected.add(EventType.NodeDeleted); + + lsnr_dwatch.verify(expected); + w1.verify(expected); + w2.verify(e2); + w3.verify(e2); + w4.verify(e2); + expected.clear(); + e2.clear(); + } + + private static class SimpleWatcher implements Watcher { + private LinkedBlockingQueue events = + new LinkedBlockingQueue(); + private CountDownLatch latch; + + public SimpleWatcher(CountDownLatch latch) { + this.latch = latch; + } + + public void process(WatchedEvent event) { + if (event.getState() == KeeperState.SyncConnected) { + if (latch != null) { + latch.countDown(); + } + } + + if (event.getType() == EventType.None) { + return; + } + try { + events.put(event); + } catch (InterruptedException e) { + Assert.assertTrue("interruption unexpected", false); + } + } + + public void verify(List expected) throws InterruptedException { + WatchedEvent event; + int count = 0; + while (count < expected.size() + && (event = events.poll(30, TimeUnit.SECONDS)) != null) { + Assert.assertEquals(expected.get(count), event.getType()); + count++; + } + Assert.assertEquals(expected.size(), count); + events.clear(); + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/WatcherTest.java b/src/java/test/org/apache/zookeeper/test/WatcherTest.java new file mode 100644 index 00000000000..a7b7a20c97f --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/WatcherTest.java @@ -0,0 +1,385 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback.StatCallback; +import org.apache.zookeeper.AsyncCallback.VoidCallback; +import org.apache.zookeeper.ClientCnxn; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.TestableZooKeeper; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class WatcherTest extends ClientBase { + protected static final Logger LOG = LoggerFactory.getLogger(WatcherTest.class); + final static int COUNT = 100; + final int TIMEOUT = 5000; + boolean hasSeenDelete = true; + + @Before + public void setUp() throws Exception { + super.setUp(); + // Reset to default value since some test cases set this to true. + // Needed for JDK7 since unit test can run is random order + ClientCnxn.setDisableAutoResetWatch(false); + } + + /** + * Verify that we get all of the events we expect to get. This particular + * case verifies that we see all of the data events on a particular node. + * There was a bug (ZOOKEEPER-137) that resulted in events being dropped + * in some cases (timing). + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void testWatcherCorrectness() + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk = null; + try { + MyWatcher watcher = new MyWatcher(); + zk = createClient(watcher, hostPort); + + StatCallback scb = new StatCallback() { + public void processResult(int rc, String path, Object ctx, + Stat stat) { + // don't do anything + } + }; + VoidCallback vcb = new VoidCallback() { + public void processResult(int rc, String path, Object ctx) { + // don't do anything + } + }; + + String names[] = new String[10]; + for (int i = 0; i < names.length; i++) { + String name = zk.create("/tc-", "initialvalue".getBytes(), + Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); + names[i] = name; + + Stat stat = new Stat(); + zk.getData(name, watcher, stat); + zk.setData(name, "new".getBytes(), stat.getVersion(), scb, null); + stat = zk.exists(name, watcher); + zk.delete(name, stat.getVersion(), vcb, null); + } + + for (int i = 0; i < names.length; i++) { + String name = names[i]; + WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals(name, event.getPath()); + Assert.assertEquals(Event.EventType.NodeDataChanged, event.getType()); + Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState()); + event = watcher.events.poll(10, TimeUnit.SECONDS); + Assert.assertEquals(name, event.getPath()); + Assert.assertEquals(Event.EventType.NodeDeleted, event.getType()); + Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState()); + } + } finally { + if (zk != null) { + zk.close(); + } + } + } + + @Test + public void testWatcherCount() + throws IOException, InterruptedException, KeeperException { + ZooKeeper zk1 = null, zk2 = null; + try { + MyWatcher w1 = new MyWatcher(); + zk1 = createClient(w1, hostPort); + + MyWatcher w2 = new MyWatcher(); + zk2 = createClient(w2, hostPort); + + Stat stat = new Stat(); + zk1.create("/watch-count-test", "value".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + zk1.create("/watch-count-test-2", "value".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + + zk1.getData("/watch-count-test", w1, stat); + zk1.getData("/watch-count-test-2", w1, stat); + zk2.getData("/watch-count-test", w2, stat); + + Assert.assertEquals(ClientBase.getServer(serverFactory) + .getZKDatabase().getDataTree().getWatchCount(), 3); + + } finally { + if (zk1 != null) { + zk1.close(); + } + if (zk2 != null) { + zk2.close(); + } + } + + } + + /** + * This test checks that watches for pending requests do not get triggered, + * but watches set by previous requests do. + * + * @throws Exception + */ + @Test + public void testWatchAutoResetWithPending() throws Exception { + MyWatcher watches[] = new MyWatcher[COUNT]; + MyStatCallback cbs[] = new MyStatCallback[COUNT]; + MyWatcher watcher = new MyWatcher(); + int count[] = new int[1]; + TestableZooKeeper zk = createClient(watcher, hostPort, 6000); + ZooKeeper zk2 = createClient(watcher, hostPort, 5000); + zk2.create("/test", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + for (int i = 0; i < COUNT / 2; i++) { + watches[i] = new MyWatcher(); + cbs[i] = new MyStatCallback(); + zk.exists("/test", watches[i], cbs[i], count); + } + zk.exists("/test", false); + Assert.assertTrue("Failed to pause the connection!", zk.pauseCnxn(3000)); + zk2.close(); + stopServer(); + watches[0].waitForDisconnected(60000); + for (int i = COUNT / 2; i < COUNT; i++) { + watches[i] = new MyWatcher(); + cbs[i] = new MyStatCallback(); + zk.exists("/test", watches[i], cbs[i], count); + } + startServer(); + watches[COUNT / 2 - 1].waitForConnected(60000); + Assert.assertEquals(null, zk.exists("/test", false)); + Thread.sleep(10); + for (int i = 0; i < COUNT / 2; i++) { + Assert.assertEquals("For " + i, 1, watches[i].events.size()); + } + for (int i = COUNT / 2; i < COUNT; i++) { + if (cbs[i].rc == 0) { + Assert.assertEquals("For " + i, 1, watches[i].events.size()); + } else { + Assert.assertEquals("For " + i, 0, watches[i].events.size()); + } + } + Assert.assertEquals(COUNT, count[0]); + zk.close(); + } + + @Test + public void testWatcherAutoResetWithGlobal() throws Exception { + ZooKeeper zk = null; + MyWatcher watcher = new MyWatcher(); + zk = createClient(watcher, hostPort, TIMEOUT); + testWatcherAutoReset(zk, watcher, watcher); + zk.close(); + } + + @Test + public void testWatcherAutoResetWithLocal() throws Exception { + ZooKeeper zk = null; + MyWatcher watcher = new MyWatcher(); + zk = createClient(watcher, hostPort, TIMEOUT); + testWatcherAutoReset(zk, watcher, new MyWatcher()); + zk.close(); + } + + @Test + public void testWatcherAutoResetDisabledWithGlobal() throws Exception { + ClientCnxn.setDisableAutoResetWatch(true); + testWatcherAutoResetWithGlobal(); + } + + @Test + public void testWatcherAutoResetDisabledWithLocal() throws Exception { + ClientCnxn.setDisableAutoResetWatch(true); + testWatcherAutoResetWithLocal(); + } + + private void testWatcherAutoReset(ZooKeeper zk, MyWatcher globalWatcher, + MyWatcher localWatcher) throws Exception { + boolean isGlobal = (localWatcher == globalWatcher); + // First test to see if the watch survives across reconnects + zk.create("/watchtest", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + zk.create("/watchtest/child", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); + if (isGlobal) { + zk.getChildren("/watchtest", true); + zk.getData("/watchtest/child", true, new Stat()); + zk.exists("/watchtest/child2", true); + } else { + zk.getChildren("/watchtest", localWatcher); + zk.getData("/watchtest/child", localWatcher, new Stat()); + zk.exists("/watchtest/child2", localWatcher); + } + + Assert.assertTrue(localWatcher.events.isEmpty()); + + stopServer(); + globalWatcher.waitForDisconnected(3000); + localWatcher.waitForDisconnected(500); + startServer(); + globalWatcher.waitForConnected(3000); + if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) { + localWatcher.waitForConnected(500); + } + + Assert.assertTrue(localWatcher.events.isEmpty()); + zk.setData("/watchtest/child", new byte[1], -1); + zk.create("/watchtest/child2", new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + WatchedEvent e; + if (!ClientCnxn.getDisableAutoResetWatch()) { + e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType()); + Assert.assertEquals("/watchtest/child", e.getPath()); + } else { + // we'll catch this later if it does happen after timeout, so + // why waste the time on poll + } + + if (!ClientCnxn.getDisableAutoResetWatch()) { + e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + // The create will trigger the get children and the exist + // watches + Assert.assertEquals(EventType.NodeCreated, e.getType()); + Assert.assertEquals("/watchtest/child2", e.getPath()); + } else { + // we'll catch this later if it does happen after timeout, so + // why waste the time on poll + } + + if (!ClientCnxn.getDisableAutoResetWatch()) { + e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/watchtest", e.getPath()); + } else { + // we'll catch this later if it does happen after timeout, so + // why waste the time on poll + } + + Assert.assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals + stopServer(); + globalWatcher.waitForDisconnected(TIMEOUT); + try { + try { + localWatcher.waitForDisconnected(500); + if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) { + Assert.fail("Got an event when I shouldn't have"); + } + } catch (TimeoutException toe) { + if (ClientCnxn.getDisableAutoResetWatch()) { + Assert.fail("Didn't get an event when I should have"); + } + // Else what we are expecting since there are no outstanding watches + } + } catch (Exception e1) { + LOG.error("bad", e1); + throw new RuntimeException(e1); + } + startServer(); + globalWatcher.waitForConnected(TIMEOUT); + + if (isGlobal) { + zk.getChildren("/watchtest", true); + zk.getData("/watchtest/child", true, new Stat()); + zk.exists("/watchtest/child2", true); + } else { + zk.getChildren("/watchtest", localWatcher); + zk.getData("/watchtest/child", localWatcher, new Stat()); + zk.exists("/watchtest/child2", localWatcher); + } + + // Do trigger an event to make sure that we do not get + // it later + zk.delete("/watchtest/child2", -1); + + e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertEquals(EventType.NodeDeleted, e.getType()); + Assert.assertEquals("/watchtest/child2", e.getPath()); + + e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertEquals(EventType.NodeChildrenChanged, e.getType()); + Assert.assertEquals("/watchtest", e.getPath()); + + Assert.assertTrue(localWatcher.events.isEmpty()); + + stopServer(); + globalWatcher.waitForDisconnected(TIMEOUT); + localWatcher.waitForDisconnected(500); + startServer(); + globalWatcher.waitForConnected(TIMEOUT); + if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) { + localWatcher.waitForConnected(500); + } + + zk.delete("/watchtest/child", -1); + zk.delete("/watchtest", -1); + + if (!ClientCnxn.getDisableAutoResetWatch()) { + e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS); + Assert.assertEquals(EventType.NodeDeleted, e.getType()); + Assert.assertEquals("/watchtest/child", e.getPath()); + } else { + // we'll catch this later if it does happen after timeout, so + // why waste the time on poll + } + + // Make sure nothing is straggling! + Thread.sleep(1000); + Assert.assertTrue(localWatcher.events.isEmpty()); + + } + + private final static class MyStatCallback implements StatCallback { + int rc; + + public void processResult(int rc, String path, Object ctx, Stat stat) { + ((int[]) ctx)[0]++; + this.rc = rc; + } + } + + private class MyWatcher extends CountdownWatcher { + LinkedBlockingQueue events = + new LinkedBlockingQueue(); + + public void process(WatchedEvent event) { + super.process(event); + if (event.getType() != Event.EventType.None) { + try { + events.put(event); + } catch (InterruptedException e) { + LOG.warn("ignoring interrupt during event.put"); + } + } + } + } + +} diff --git a/src/java/test/org/apache/zookeeper/test/X509AuthTest.java b/src/java/test/org/apache/zookeeper/test/X509AuthTest.java new file mode 100644 index 00000000000..667363d28c6 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/X509AuthTest.java @@ -0,0 +1,325 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + *

        + * http://www.apache.org/licenses/LICENSE-2.0 + *

        + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ +package org.apache.zookeeper.test; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.server.MockServerCnxn; +import org.apache.zookeeper.server.auth.X509AuthenticationProvider; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.math.BigInteger; +import java.net.Socket; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.Date; +import java.util.Set; + +import javax.net.ssl.X509KeyManager; +import javax.net.ssl.X509TrustManager; +import javax.security.auth.x500.X500Principal; + +public class X509AuthTest extends ZKTestCase { + private static TestCertificate clientCert; + private static TestCertificate superCert; + private static TestCertificate unknownCert; + + @Before + public void setUp() { + System.setProperty("zookeeper.X509AuthenticationProvider.superUser", + "CN=SUPER"); + System.setProperty("zookeeper.ssl.keyManager", + "org.apache.zookeeper.test.X509AuthTest.TestKeyManager"); + System.setProperty("zookeeper.ssl.trustManager", + "org.apache.zookeeper.test.X509AuthTest.TestTrustManager"); + + clientCert = new TestCertificate("CLIENT"); + superCert = new TestCertificate("SUPER"); + unknownCert = new TestCertificate("UNKNOWN"); + } + + @Test + public void testTrustedAuth() { + X509AuthenticationProvider provider = createProvider(clientCert); + MockServerCnxn cnxn = new MockServerCnxn(); + cnxn.clientChain = new X509Certificate[]{clientCert}; + Assert.assertEquals(KeeperException.Code.OK, provider.handleAuthentication(cnxn, null)); + } + + @Test + public void testSuperAuth() { + X509AuthenticationProvider provider = createProvider(superCert); + MockServerCnxn cnxn = new MockServerCnxn(); + cnxn.clientChain = new X509Certificate[]{superCert}; + Assert.assertEquals(KeeperException.Code.OK, provider.handleAuthentication(cnxn, null)); + Assert.assertEquals("super", cnxn.getAuthInfo().get(0).getScheme()); + } + + @Test + public void testUntrustedAuth() { + X509AuthenticationProvider provider = createProvider(clientCert); + MockServerCnxn cnxn = new MockServerCnxn(); + cnxn.clientChain = new X509Certificate[]{unknownCert}; + Assert.assertEquals(KeeperException.Code.AUTHFAILED, provider.handleAuthentication(cnxn, null)); + } + + protected X509AuthenticationProvider createProvider(X509Certificate trustedCert) { + return new X509AuthenticationProvider( + new TestTrustManager(trustedCert), + new TestKeyManager()); + } + + private static class TestPublicKey implements PublicKey { + private static final long serialVersionUID = 1L; + + @Override + public String getAlgorithm() { + return null; + } + + @Override + public String getFormat() { + return null; + } + + @Override + public byte[] getEncoded() { + return null; + } + } + + private static class TestCertificate extends X509Certificate { + private byte[] encoded; + private X500Principal principal; + private PublicKey publicKey; + + public TestCertificate(String name) { + encoded = name.getBytes(); + principal = new X500Principal("CN=" + name); + publicKey = new TestPublicKey(); + } + + @Override + public boolean hasUnsupportedCriticalExtension() { + return false; + } + + @Override + public Set getCriticalExtensionOIDs() { + return null; + } + + @Override + public Set getNonCriticalExtensionOIDs() { + return null; + } + + @Override + public byte[] getExtensionValue(String oid) { + return null; + } + + @Override + public void checkValidity() throws CertificateExpiredException, + CertificateNotYetValidException { + } + + @Override + public void checkValidity(Date date) + throws CertificateExpiredException, + CertificateNotYetValidException { + } + + @Override + public int getVersion() { + return 0; + } + + @Override + public BigInteger getSerialNumber() { + return null; + } + + @Override + public Principal getIssuerDN() { + return null; + } + + @Override + public Principal getSubjectDN() { + return null; + } + + @Override + public Date getNotBefore() { + return null; + } + + @Override + public Date getNotAfter() { + return null; + } + + @Override + public byte[] getTBSCertificate() throws CertificateEncodingException { + return null; + } + + @Override + public byte[] getSignature() { + return null; + } + + @Override + public String getSigAlgName() { + return null; + } + + @Override + public String getSigAlgOID() { + return null; + } + + @Override + public byte[] getSigAlgParams() { + return null; + } + + @Override + public boolean[] getIssuerUniqueID() { + return null; + } + + @Override + public boolean[] getSubjectUniqueID() { + return null; + } + + @Override + public boolean[] getKeyUsage() { + return null; + } + + @Override + public int getBasicConstraints() { + return 0; + } + + @Override + public byte[] getEncoded() throws CertificateEncodingException { + return encoded; + } + + @Override + public void verify(PublicKey key) throws CertificateException, + NoSuchAlgorithmException, InvalidKeyException, + NoSuchProviderException, SignatureException { + } + + @Override + public void verify(PublicKey key, String sigProvider) + throws CertificateException, NoSuchAlgorithmException, + InvalidKeyException, NoSuchProviderException, + SignatureException { + } + + @Override + public String toString() { + return null; + } + + @Override + public PublicKey getPublicKey() { + return publicKey; + } + + @Override + public X500Principal getSubjectX500Principal() { + return principal; + } + } + + public static class TestKeyManager implements X509KeyManager { + @Override + public String chooseClientAlias(String[] keyType, Principal[] issuers, + Socket socket) { + return null; + } + + @Override + public String chooseServerAlias(String keyType, Principal[] issuers, + Socket socket) { + return null; + } + + @Override + public X509Certificate[] getCertificateChain(String alias) { + return null; + } + + @Override + public String[] getClientAliases(String keyType, Principal[] issuers) { + return null; + } + + @Override + public PrivateKey getPrivateKey(String alias) { + return null; + } + + @Override + public String[] getServerAliases(String keyType, Principal[] issuers) { + return null; + } + } + + public static class TestTrustManager implements X509TrustManager { + X509Certificate cert; + + public TestTrustManager(X509Certificate testCert) { + cert = testCert; + } + + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) + throws CertificateException { + if (!Arrays.equals(cert.getEncoded(), chain[0].getEncoded())) { + throw new CertificateException("Client cert not trusted"); + } + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) + throws CertificateException { + if (!Arrays.equals(cert.getEncoded(), chain[0].getEncoded())) { + throw new CertificateException("Server cert not trusted"); + } + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java b/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java new file mode 100644 index 00000000000..6eb7fcf06fd --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java @@ -0,0 +1,159 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.AsyncCallback; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.server.SyncRequestProcessor; +import org.apache.zookeeper.server.persistence.FileTxnSnapLog; +import org.apache.zookeeper.server.quorum.QuorumPeer; +import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Arrays; + +public class ZkDatabaseCorruptionTest extends ZKTestCase { + public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT; + protected static final Logger LOG = LoggerFactory.getLogger(ZkDatabaseCorruptionTest.class); + private final QuorumBase qb = new QuorumBase(); + + @Before + public void setUp() throws Exception { + LOG.info("STARTING quorum " + getClass().getName()); + qb.setUp(); + } + + @After + public void tearDown() throws Exception { + LOG.info("STOPPING quorum " + getClass().getName()); + } + + private void corruptFile(File f) throws IOException { + RandomAccessFile outFile = new RandomAccessFile(f, "rw"); + outFile.write("fail servers".getBytes()); + outFile.close(); + } + + private void corruptAllSnapshots(File snapDir) throws IOException { + File[] listFiles = snapDir.listFiles(); + for (File f : listFiles) { + if (f.getName().startsWith("snapshot")) { + corruptFile(f); + } + } + } + + @Test + public void testCorruption() throws Exception { + ClientBase.waitForServerUp(qb.hostPort, 10000); + ClientBase.waitForServerUp(qb.hostPort, 10000); + ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() { + public void process(WatchedEvent event) { + } + }); + SyncRequestProcessor.setSnapCount(100); + for (int i = 0; i < 2000; i++) { + zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT, new NoopStringCallback(), null); + } + zk.close(); + + long leaderSid = 1; + QuorumPeer leader = null; + //find out who is the leader and kill it + for (QuorumPeer quorumPeer : Arrays.asList(qb.s1, qb.s2, qb.s3, qb.s4, qb.s5)) { + if (quorumPeer.getPeerState() == ServerState.LEADING) { + leader = quorumPeer; + break; + } + ++leaderSid; + } + + Assert.assertNotNull("Cannot find the leader.", leader); + leader.shutdown(); + + // now corrupt the leader's database + FileTxnSnapLog snapLog = leader.getTxnFactory(); + File snapDir = snapLog.getSnapDir(); + //corrupt all the snapshot in the snapshot directory + corruptAllSnapshots(snapDir); + qb.shutdownServers(); + qb.setupServers(); + + if (leaderSid != 1) qb.s1.start(); + else leader = qb.s1; + if (leaderSid != 2) qb.s2.start(); + else leader = qb.s2; + if (leaderSid != 3) qb.s3.start(); + else leader = qb.s3; + if (leaderSid != 4) qb.s4.start(); + else leader = qb.s4; + if (leaderSid != 5) qb.s5.start(); + else leader = qb.s5; + + try { + leader.start(); + Assert.assertTrue(false); + } catch (RuntimeException re) { + LOG.info("Got an error: expected", re); + } + //wait for servers to be up + String[] list = qb.hostPort.split(","); + for (int i = 0; i < 5; i++) { + if (leaderSid != (i + 1)) { + String hp = list[i]; + Assert.assertTrue("waiting for server up", + ClientBase.waitForServerUp(hp, + CONNECTION_TIMEOUT)); + LOG.info("{} is accepting client connections", hp); + } else { + LOG.info("Skipping the leader"); + } + } + + zk = qb.createClient(); + SyncRequestProcessor.setSnapCount(100); + for (int i = 2000; i < 4000; i++) { + zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT, new NoopStringCallback(), null); + } + zk.close(); + + if (leaderSid != 1) QuorumBase.shutdown(qb.s1); + if (leaderSid != 2) QuorumBase.shutdown(qb.s2); + if (leaderSid != 3) QuorumBase.shutdown(qb.s3); + if (leaderSid != 4) QuorumBase.shutdown(qb.s4); + if (leaderSid != 5) QuorumBase.shutdown(qb.s5); + } + + private class NoopStringCallback implements AsyncCallback.StringCallback { + @Override + public void processResult(int rc, String path, Object ctx, + String name) { + } + } + + +} diff --git a/src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java b/src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java new file mode 100644 index 00000000000..ef37c89a456 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.Quotas; +import org.apache.zookeeper.StatsTrack; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.ZooKeeperMain; +import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.ZooKeeperServer; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +public class ZooKeeperQuotaTest extends ClientBase { + + @Test + public void testQuota() throws IOException, + InterruptedException, KeeperException, Exception { + final ZooKeeper zk = createClient(); + final String path = "/a/b/v"; + // making sure setdata works on / + zk.setData("/", "some".getBytes(), -1); + zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + zk.create("/a/b/v/d", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + ZooKeeperMain.createQuota(zk, path, 5L, 10); + + // see if its set + String absolutePath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode; + byte[] data = zk.getData(absolutePath, false, new Stat()); + StatsTrack st = new StatsTrack(new String(data)); + Assert.assertTrue("bytes are set", st.getBytes() == 5L); + Assert.assertTrue("num count is set", st.getCount() == 10); + + String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode; + byte[] qdata = zk.getData(statPath, false, new Stat()); + StatsTrack qst = new StatsTrack(new String(qdata)); + Assert.assertTrue("bytes are set", qst.getBytes() == 8L); + Assert.assertTrue("count is set", qst.getCount() == 2); + + //force server to restart and load from snapshot, not txn log + stopServer(); + startServer(); + stopServer(); + startServer(); + ZooKeeperServer server = getServer(serverFactory); + Assert.assertNotNull("Quota is still set", + server.getZKDatabase().getDataTree().getMaxPrefixWithQuota(path) != null); + } +} diff --git a/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java b/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java new file mode 100644 index 00000000000..7da42fdecc3 --- /dev/null +++ b/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java @@ -0,0 +1,455 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.apache.zookeeper.test; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.KeeperException.Code; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.Watcher.Event.EventType; +import org.apache.zookeeper.ZKTestCase; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.common.Time; +import org.apache.zookeeper.data.Stat; +import org.junit.Assert; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +public class ZooKeeperTestClient extends ZKTestCase implements Watcher { + protected static final String dirOnZK = "/test_dir"; + protected String hostPort = "127.0.0.1:22801"; + protected String testDirOnZK = dirOnZK + "/" + Time.currentElapsedTime(); + + LinkedBlockingQueue events = new LinkedBlockingQueue(); + + public static void main(String[] args) { + ZooKeeperTestClient zktc = new ZooKeeperTestClient(); + try { + zktc.my_test_1(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private WatchedEvent getEvent(int numTries) throws InterruptedException { + WatchedEvent event = null; + for (int i = 0; i < numTries; i++) { + System.out.println("i = " + i); + event = events.poll(10, TimeUnit.SECONDS); + if (event != null) { + break; + } + Thread.sleep(5000); + } + return event; + + } + + private void deleteZKDir(ZooKeeper zk, String nodeName) + throws IOException, InterruptedException, KeeperException { + + Stat stat = zk.exists(nodeName, false); + if (stat == null) { + return; + } + + List children1 = zk.getChildren(nodeName, false); + List c2 = zk.getChildren(nodeName, false, stat); + + if (!children1.equals(c2)) { + Assert.fail("children lists from getChildren()/getChildren2() do not match"); + } + + if (!stat.equals(stat)) { + Assert.fail("stats from exists()/getChildren2() do not match"); + } + + if (children1.size() == 0) { + zk.delete(nodeName, -1); + return; + } + for (String n : children1) { + deleteZKDir(zk, n); + } + } + + private void checkRoot() throws IOException, + InterruptedException { + ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); + + try { + zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ke) { + // expected, sort of + } catch (KeeperException ke) { + Assert.fail("Unexpected exception code for create " + dirOnZK + ": " + + ke.getMessage()); + } + + try { + zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ke) { + // expected, sort of + } catch (KeeperException ke) { + Assert.fail("Unexpected exception code for create " + testDirOnZK + ": " + + ke.getMessage()); + } + + zk.close(); + } + + private void enode_test_1() throws IOException, + InterruptedException, KeeperException { + checkRoot(); + String parentName = testDirOnZK; + String nodeName = parentName + "/enode_abc"; + ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); + + Stat stat = zk.exists(parentName, false); + if (stat == null) { + try { + zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException ke) { + Assert.fail("Creating node " + parentName + ke.getMessage()); + } + } + + try { + zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NODEEXISTS; + if (!valid) { + Assert.fail("Unexpected exception code for createin: " + ke.getMessage()); + } + } + + stat = zk.exists(nodeName, false); + if (stat == null) { + Assert.fail("node " + nodeName + " should exist"); + } + System.out.println("Closing client with sessionid: 0x" + + Long.toHexString(zk.getSessionId())); + zk.close(); + zk = new ZooKeeper(hostPort, 10000, this); + + for (int i = 0; i < 10; i++) { + System.out.println("i = " + i); + stat = zk.exists(nodeName, false); + if (stat != null) { + System.out.println("node " + nodeName + + " should not exist after reconnection close"); + } else { + System.out.println("node " + nodeName + + " is gone after reconnection close!"); + break; + } + Thread.sleep(5000); + } + deleteZKDir(zk, nodeName); + zk.close(); + + } + + private void enode_test_2() throws IOException, + InterruptedException, KeeperException { + checkRoot(); + String parentName = testDirOnZK; + String nodeName = parentName + "/enode_abc"; + ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); + ZooKeeper zk_1 = new ZooKeeper(hostPort, 10000, this); + + Stat stat_parent = zk_1.exists(parentName, false); + if (stat_parent == null) { + try { + zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException ke) { + Assert.fail("Creating node " + parentName + ke.getMessage()); + } + } + + Stat stat_node = zk_1.exists(nodeName, false); + if (stat_node != null) { + + try { + zk.delete(nodeName, -1); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NONODE + || code == KeeperException.Code.NOTEMPTY; + if (!valid) { + Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); + } + } + } + + List firstGen1 = zk_1.getChildren(parentName, true); + Stat stat = new Stat(); + List firstGen2 = zk_1.getChildren(parentName, true, stat); + + if (!firstGen1.equals(firstGen2)) { + Assert.fail("children lists from getChildren()/getChildren2() do not match"); + } + + if (!stat_parent.equals(stat)) { + Assert.fail("stat from exists()/getChildren() do not match"); + } + + try { + zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NODEEXISTS; + if (!valid) { + Assert.fail("Unexpected exception code for createin: " + ke.getMessage()); + } + } + + Thread.sleep(5000); + WatchedEvent event = events.poll(10, TimeUnit.SECONDS); + if (event == null) { + throw new IOException("No event was delivered promptly"); + } + if (event.getType() != EventType.NodeChildrenChanged + || !event.getPath().equalsIgnoreCase(parentName)) { + Assert.fail("Unexpected event was delivered: " + event.toString()); + } + + stat_node = zk_1.exists(nodeName, false); + if (stat_node == null) { + Assert.fail("node " + nodeName + " should exist"); + } + + try { + zk.delete(parentName, -1); + Assert.fail("Should be impossible to delete a non-empty node " + parentName); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NOTEMPTY; + if (!valid) { + Assert.fail("Unexpected exception code for delete: " + code); + } + } + + try { + zk.create(nodeName + "/def", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + Assert.fail("Should be impossible to create child off Ephemeral node " + nodeName); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NOCHILDRENFOREPHEMERALS; + if (!valid) { + Assert.fail("Unexpected exception code for createin: " + code); + } + } + + try { + List children1 = zk.getChildren(nodeName, false); + List children2 = zk.getChildren(nodeName, false, null); + + if (!children1.equals(children2)) { + Assert.fail("children lists from getChildren()/getChildren2() does not match"); + } + + if (children1.size() > 0) { + Assert.fail("ephemeral node " + nodeName + " should not have children"); + } + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NONODE; + if (!valid) { + Assert.fail("Unexpected exception code for createin: " + code); + } + } + firstGen1 = zk_1.getChildren(parentName, true); + firstGen2 = zk_1.getChildren(parentName, true, null); + + if (!firstGen1.equals(firstGen2)) { + Assert.fail("children list from getChildren()/getChildren2() does not match"); + } + + stat_node = zk_1.exists(nodeName, true); + if (stat_node == null) { + Assert.fail("node " + nodeName + " should exist"); + } + System.out.println("session id of zk: " + zk.getSessionId()); + System.out.println("session id of zk_1: " + zk_1.getSessionId()); + zk.close(); + + zk_1.exists("nosuchnode", false); + + event = this.getEvent(10); + if (event == null) { + throw new Error("First event was not delivered promptly"); + } + if (!((event.getType() == EventType.NodeChildrenChanged && + event.getPath().equalsIgnoreCase(parentName)) || + (event.getType() == EventType.NodeDeleted && + event.getPath().equalsIgnoreCase(nodeName)))) { + System.out.print(parentName + " " + + EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted); + Assert.fail("Unexpected first event was delivered: " + event.toString()); + } + + event = this.getEvent(10); + + if (event == null) { + throw new Error("Second event was not delivered promptly"); + } + if (!((event.getType() == EventType.NodeChildrenChanged && + event.getPath().equalsIgnoreCase(parentName)) || + (event.getType() == EventType.NodeDeleted && + event.getPath().equalsIgnoreCase(nodeName)))) { + System.out.print(parentName + " " + + EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted); + Assert.fail("Unexpected second event was delivered: " + event.toString()); + } + + firstGen1 = zk_1.getChildren(parentName, false); + stat_node = zk_1.exists(nodeName, false); + if (stat_node != null) { + Assert.fail("node " + nodeName + " should have been deleted"); + } + if (firstGen1.contains(nodeName)) { + Assert.fail("node " + nodeName + " should not be a children"); + } + deleteZKDir(zk_1, nodeName); + zk_1.close(); + } + + private void delete_create_get_set_test_1() throws + IOException, InterruptedException, KeeperException { + checkRoot(); + ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); + String parentName = testDirOnZK; + String nodeName = parentName + "/benwashere"; + try { + zk.delete(nodeName, -1); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NONODE + || code == KeeperException.Code.NOTEMPTY; + if (!valid) { + Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); + } + } + try { + zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NODEEXISTS; + if (!valid) { + Assert.fail("Unexpected exception code for create: " + ke.getMessage()); + } + } + try { + zk.setData(nodeName, "hi".getBytes(), 5700); + Assert.fail("Should have gotten BadVersion exception"); + } catch (KeeperException ke) { + if (ke.code() != Code.BADVERSION) { + Assert.fail("Should have gotten BadVersion exception"); + } + } + zk.setData(nodeName, "hi".getBytes(), -1); + Stat st = new Stat(); + byte[] bytes = zk.getData(nodeName, false, st); + String retrieved = new String(bytes); + if (!"hi".equals(retrieved)) { + Assert.fail("The retrieved data [" + retrieved + + "] is differented than the expected [hi]"); + } + try { + zk.delete(nodeName, 6800); + Assert.fail("Should have gotten BadVersion exception"); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NOTEMPTY + || code == KeeperException.Code.BADVERSION; + if (!valid) { + Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); + } + } + try { + zk.delete(nodeName, -1); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NOTEMPTY; + if (!valid) { + Assert.fail("Unexpected exception code for delete: " + code); + } + } + deleteZKDir(zk, nodeName); + zk.close(); + } + + private void deleteNodeIfExists(ZooKeeper zk, String nodeName) + throws InterruptedException { + try { + zk.delete(nodeName, -1); + } catch (KeeperException ke) { + Code code = ke.code(); + boolean valid = code == KeeperException.Code.NONODE || + code == KeeperException.Code.NOTEMPTY; + if (!valid) { + Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); + } + } + } + + private void create_get_stat_test() + throws IOException, InterruptedException, KeeperException { + checkRoot(); + ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); + String parentName = testDirOnZK; + String nodeName = parentName + "/create_with_stat_tmp"; + deleteNodeIfExists(zk, nodeName); + deleteNodeIfExists(zk, nodeName + "_2"); + Stat stat = new Stat(); + zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, + stat); + Assert.assertNotNull(stat); + Assert.assertTrue(stat.getCzxid() > 0); + Assert.assertTrue(stat.getCtime() > 0); + + Stat stat2 = new Stat(); + zk.create(nodeName + "_2", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, + stat2); + Assert.assertNotNull(stat2); + Assert.assertTrue(stat2.getCzxid() > stat.getCzxid()); + Assert.assertTrue(stat2.getCtime() > stat.getCtime()); + + deleteNodeIfExists(zk, nodeName); + deleteNodeIfExists(zk, nodeName + "_2"); + zk.close(); + } + + public void my_test_1() throws IOException, + InterruptedException, KeeperException { + enode_test_1(); + enode_test_2(); + delete_create_get_set_test_1(); + create_get_stat_test(); + } + + synchronized public void process(WatchedEvent event) { + try { + System.out.println("Got an event " + event.toString()); + events.put(event); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/lastRevision.bat b/src/lastRevision.bat new file mode 100644 index 00000000000..e31a6b96c34 --- /dev/null +++ b/src/lastRevision.bat @@ -0,0 +1,23 @@ +echo off +rem Licensed to the Apache Software Foundation (ASF) under one +rem or more contributor license agreements. See the NOTICE file +rem distributed with this work for additional information +rem regarding copyright ownership. The ASF licenses this file +rem to you under the Apache License, Version 2.0 (the +rem "License"); you may not use this file except in compliance +rem with the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + +rem Find the current revision, store it in a file, for DOS +svn info | findstr Revision > %1 + +For /F "tokens=1,2 delims= " %%a In (%1) Do ( + echo lastRevision=%%b> %1 +) diff --git a/src/lastRevision.sh b/src/lastRevision.sh new file mode 100755 index 00000000000..a462990e742 --- /dev/null +++ b/src/lastRevision.sh @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Find the current revision, store it in a file +FILE=$1 +LASTREV=`svn info | grep '^Revision' | sed -e 's/Revision: *//'` + +echo "lastRevision=${LASTREV}" > $FILE diff --git a/src/packages/deb/init.d/zookeeper b/src/packages/deb/init.d/zookeeper new file mode 100644 index 00000000000..d0f7216deed --- /dev/null +++ b/src/packages/deb/init.d/zookeeper @@ -0,0 +1,140 @@ +#! /usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +### BEGIN INIT INFO +# Provides: zookeeper +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: Apache ZooKeeper server +### END INIT INFO + +set -e + +# /etc/init.d/zookeeper: start and stop the Apache ZooKeeper daemon + +umask 022 + +. /usr/libexec/zkEnv.sh + +. /lib/lsb/init-functions + +ZOOPIDDIR=/var/lib/zookeeper/data +ZOOPIDFILE=${ZOOPIDDIR}/zookeeper_server.pid + +check_privsep_dir() { + # Create the PrivSep empty dir if necessary + if [ ! -d ${ZOOPIDDIR} ]; then + mkdir -p ${ZOOPIDDIR} + chown zookeeper:hadoop ${ZOOPIDDIR} + chmod 0775 ${ZOOPIDDIR} + fi +} + +# Are we running from init? +run_by_init() { + ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] +} + +check_for_no_start() { + # forget it if we're trying to start, and /etc/zookeeper/zookeeper_not_to_be_run exists + if [ -e /etc/zookeeper/zookeeper_not_to_be_run ]; then + if [ "$1" = log_end_msg ]; then + log_end_msg 0 + fi + if ! run_by_init; then + log_action_msg "Apache ZooKeeper server not in use (/etc/zookeeper/zookeeper_not_to_be_run)" + fi + exit 0 + fi +} + +export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin" + +case "$1" in + start) + check_for_no_start + check_privsep_dir + log_daemon_msg "Starting Apache ZooKeeper server" "zookeeper" + if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c zookeeper -x ${ZOOKEEPER_PREFIX}/sbin/zkServer.sh start; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + stop) + log_daemon_msg "Stopping Apache ZooKeeper server" "zookeeper" + if start-stop-daemon --stop --quiet --oknodo --pidfile ${ZOOPIDFILE}; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + restart) + check_privsep_dir + log_daemon_msg "Restarting Apache ZooKeeper server" "zookeeper" + start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${ZOOPIDFILE} + check_for_no_start log_end_msg + if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c zookeeper -x ${ZOOKEEPER_PREFIX}/sbin/zkServer.sh start; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + try-restart) + check_privsep_dir + log_daemon_msg "Restarting Apache ZooKeeper server" "zookeeper" + set +e + start-stop-daemon --stop --quiet --retry 30 --pidfile ${ZOOPIDFILE} + RET="$?" + set -e + case $RET in + 0) + # old daemon stopped + check_for_no_start log_end_msg + if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c zookeeper -x ${ZOOKEEPER_PREFIX}/sbin/zkServer.sh start; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + 1) + # daemon not running + log_progress_msg "(not running)" + log_end_msg 0 + ;; + *) + # failed to stop + log_progress_msg "(failed to stop)" + log_end_msg 1 + ;; + esac + ;; + + status) + status_of_proc -p ${ZOOPIDFILE} ${JAVA_HOME}/bin/java zookeeper && exit 0 || exit $? + ;; + + *) + log_action_msg "Usage: /etc/init.d/zookeeper {start|stop|restart|try-restart|status}" + exit 1 +esac + +exit 0 diff --git a/src/packages/deb/zookeeper.control/conffile b/src/packages/deb/zookeeper.control/conffile new file mode 100644 index 00000000000..6fdd65be113 --- /dev/null +++ b/src/packages/deb/zookeeper.control/conffile @@ -0,0 +1,15 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +/etc/zookeeper diff --git a/src/packages/deb/zookeeper.control/control b/src/packages/deb/zookeeper.control/control new file mode 100644 index 00000000000..c746906024a --- /dev/null +++ b/src/packages/deb/zookeeper.control/control @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +Package: zookeeper +Version: @version@ +Section: misc +Priority: optional +Architecture: all +Depends: sun-java6-jre +Maintainer: Apache Software Foundation +Description: ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. +Distribution: development diff --git a/src/packages/deb/zookeeper.control/postinst b/src/packages/deb/zookeeper.control/postinst new file mode 100644 index 00000000000..a6cbd22d143 --- /dev/null +++ b/src/packages/deb/zookeeper.control/postinst @@ -0,0 +1,23 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +bash /usr/sbin/update-zookeeper-env.sh \ + --prefix=/usr \ + --conf-dir=/etc/zookeeper \ + --log-dir=/var/log/zookeeper \ + --pid-dir=/var/run/zookeeper \ + --var-dir=/var/lib/zookeeper diff --git a/src/packages/deb/zookeeper.control/postrm b/src/packages/deb/zookeeper.control/postrm new file mode 100644 index 00000000000..27842b7564b --- /dev/null +++ b/src/packages/deb/zookeeper.control/postrm @@ -0,0 +1,19 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +/usr/sbin/userdel zookeeper 2> /dev/null >/dev/null +exit 0 diff --git a/src/packages/deb/zookeeper.control/preinst b/src/packages/deb/zookeeper.control/preinst new file mode 100644 index 00000000000..d4ca7f7130f --- /dev/null +++ b/src/packages/deb/zookeeper.control/preinst @@ -0,0 +1,20 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +getent group hadoop 2>/dev/null >/dev/null || /usr/sbin/groupadd -r hadoop + +/usr/sbin/useradd --comment "ZooKeeper" --shell /bin/bash -M -r --groups hadoop --home /usr/share/zookeeper zookeeper 2> /dev/null || : diff --git a/src/packages/deb/zookeeper.control/prerm b/src/packages/deb/zookeeper.control/prerm new file mode 100644 index 00000000000..c986688a7b3 --- /dev/null +++ b/src/packages/deb/zookeeper.control/prerm @@ -0,0 +1,24 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +/etc/init.d/zookeeper stop 2>/dev/null >/dev/null +bash /usr/sbin/update-zookeeper-env.sh \ + --prefix=/usr \ + --conf-dir=/etc/zookeeper \ + --log-dir=/var/log/zookeeper \ + --pid-dir=/var/run/zookeeper \ + --uninstal diff --git a/src/packages/rpm/init.d/zookeeper b/src/packages/rpm/init.d/zookeeper new file mode 100644 index 00000000000..624e1a58845 --- /dev/null +++ b/src/packages/rpm/init.d/zookeeper @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# ZooKeeper +# +# chkconfig: 2345 89 9 +# description: zookeeper + +source /etc/rc.d/init.d/functions +source /usr/libexec/zkEnv.sh + +RETVAL=0 +PIDFILE="${ZOOPIDFILE}" +desc="ZooKeeper daemon" + +start() { + echo -n $"Starting $desc (zookeeper): " + daemon --user zookeeper zkServer.sh start + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zookeeper + return $RETVAL +} + +stop() { + echo -n $"Stopping $desc (zookeeper): " + daemon --user zookeeper zkServer.sh stop + RETVAL=$? + sleep 5 + echo + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zookeeper $PIDFILE +} + +restart() { + stop + start +} + +checkstatus(){ + status -p $PIDFILE ${JAVA_HOME}/bin/java + RETVAL=$? +} + +condrestart(){ + [ -e /var/lock/subsys/zookeeper ] && restart || : +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + checkstatus + ;; + restart) + restart + ;; + condrestart) + condrestart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + exit 1 +esac + +exit $RETVAL diff --git a/src/packages/rpm/spec/zookeeper.spec b/src/packages/rpm/spec/zookeeper.spec new file mode 100644 index 00000000000..8e195c7165e --- /dev/null +++ b/src/packages/rpm/spec/zookeeper.spec @@ -0,0 +1,166 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# RPM Spec file for ZooKeeper version @version@ +# + +%define name zookeeper +%define version @version@ +%define release @package.release@ + +# Installation Locations +%define _prefix @package.prefix@ +%define _bin_dir %{_prefix}/bin +%define _conf_dir @package.conf.dir@ +%define _include_dir %{_prefix}/include +%define _lib_dir %{_prefix}/lib +%define _lib64_dir %{_prefix}/lib64 +%define _libexec_dir %{_prefix}/libexec +%define _log_dir @package.log.dir@ +%define _man_dir %{_prefix}/man +%define _pid_dir @package.pid.dir@ +%define _sbin_dir %{_prefix}/sbin +%define _share_dir %{_prefix}/share/zookeeper +%define _src_dir %{_prefix}/src +%define _var_dir @package.var.dir@ + +# Build time settings +%define _build_dir @package.build.dir@ +%define _final_name @final.name@ +%define _c_lib @c.lib@ +%define debug_package %{nil} + +# Disable brp-java-repack-jars for aspect J +%define __os_install_post \ + /usr/lib/rpm/redhat/brp-compress \ + %{!?__debug_package:/usr/lib/rpm/redhat/brp-strip %{__strip}} \ + /usr/lib/rpm/redhat/brp-strip-static-archive %{__strip} \ + /usr/lib/rpm/redhat/brp-strip-comment-note %{__strip} %{__objdump} \ + /usr/lib/rpm/brp-python-bytecompile %{nil} + +# RPM searches perl files for dependancies and this breaks for non packaged perl lib +# like thrift so disable this +%define _use_internal_dependency_generator 0 + +Summary: ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. +License: Apache License, Version 2.0 +URL: http://zookeeper.apache.org/ +Vendor: Apache Software Foundation +Group: Development/Libraries +Name: %{name} +Version: %{version} +Release: %{release} +Source0: %{_final_name}.tar.gz +Source1: %{_final_name}-lib.tar.gz +Prefix: %{_prefix} +Prefix: %{_conf_dir} +Prefix: %{_log_dir} +Prefix: %{_pid_dir} +Prefix: %{_var_dir} +Requires: sh-utils, textutils, /usr/sbin/useradd, /usr/sbin/usermod, /sbin/chkconfig, /sbin/service, jdk >= 1.6 +AutoReqProv: no +Provides: zookeeper + +%description +ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed. + +%package lib +Summary: ZooKeeper C binding library +Group: System/Libraries +#Requires: %{name} == %{version} +Provides: zookeeper-lib + +%description lib +ZooKeeper C client library for communicating with ZooKeeper Server. + +%prep +%setup -D -b 1 -n %{_final_name} +%setup -D -a 0 -n %{_final_name} + +%build +mkdir -p ${RPM_BUILD_DIR}%{_prefix} +mkdir -p ${RPM_BUILD_DIR}%{_bin_dir} +mkdir -p ${RPM_BUILD_DIR}%{_include_dir} +mkdir -p ${RPM_BUILD_DIR}%{_lib_dir} +%ifarch amd64 x86_64 +mkdir -p ${RPM_BUILD_DIR}%{_lib64_dir} +%endif +mkdir -p ${RPM_BUILD_DIR}%{_libexec_dir} +mkdir -p ${RPM_BUILD_DIR}%{_log_dir} +mkdir -p ${RPM_BUILD_DIR}%{_conf_dir} +mkdir -p ${RPM_BUILD_DIR}%{_man_dir} +mkdir -p ${RPM_BUILD_DIR}%{_pid_dir} +mkdir -p ${RPM_BUILD_DIR}%{_sbin_dir} +mkdir -p ${RPM_BUILD_DIR}%{_share_dir} +mkdir -p ${RPM_BUILD_DIR}%{_var_dir} +mkdir -p ${RPM_BUILD_DIR}/etc/init.d + +cp ${RPM_BUILD_DIR}/%{_final_name}/src/packages/rpm/init.d/zookeeper ${RPM_BUILD_DIR}/etc/init.d/zookeeper +cp ${RPM_BUILD_DIR}/%{_final_name}/src/packages/update-zookeeper-env.sh ${RPM_BUILD_DIR}/%{_final_name}/sbin/update-zookeeper-env.sh +chmod 0755 ${RPM_BUILD_DIR}/%{_final_name}/sbin/* +chmod 0755 ${RPM_BUILD_DIR}/etc/init.d/zookeeper + +######################### +#### INSTALL SECTION #### +######################### +%install +pushd ${RPM_BUILD_DIR} +mv ${RPM_BUILD_DIR}/%{_final_name}/bin/* ${RPM_BUILD_DIR}%{_bin_dir} +mv ${RPM_BUILD_DIR}/%{_final_name}/libexec/* ${RPM_BUILD_DIR}%{_libexec_dir} +mv ${RPM_BUILD_DIR}/%{_final_name}/share/zookeeper/* ${RPM_BUILD_DIR}%{_share_dir} +mv ${RPM_BUILD_DIR}/%{_final_name}/conf/* ${RPM_BUILD_DIR}%{_conf_dir} +mv ${RPM_BUILD_DIR}/%{_final_name}/sbin/* ${RPM_BUILD_DIR}%{_sbin_dir} +cp -f ${RPM_BUILD_DIR}%{_conf_dir}/zoo_sample.cfg ${RPM_BUILD_DIR}%{_conf_dir}/zoo.cfg +popd ${RPM_BUILD_DIR} +rm -rf ${RPM_BUILD_DIR}/%{_final_name} + +%pre +getent group hadoop 2>/dev/null >/dev/null || /usr/sbin/groupadd -r hadoop + +/usr/sbin/useradd --comment "ZooKeeper" --shell /bin/bash -M -r --groups hadoop --home %{_share_dir} zookeeper 2> /dev/null || : + +%post +bash ${RPM_INSTALL_PREFIX0}/sbin/update-zookeeper-env.sh \ + --prefix=${RPM_INSTALL_PREFIX0} \ + --conf-dir=${RPM_INSTALL_PREFIX1} \ + --log-dir=${RPM_INSTALL_PREFIX2} \ + --pid-dir=${RPM_INSTALL_PREFIX3} \ + --var-dir=${RPM_INSTALL_PREFIX4} + +%preun +bash ${RPM_INSTALL_PREFIX0}/sbin/update-zookeeper-env.sh \ + --prefix=${RPM_INSTALL_PREFIX0} \ + --conf-dir=${RPM_INSTALL_PREFIX1} \ + --log-dir=${RPM_INSTALL_PREFIX2} \ + --pid-dir=${RPM_INSTALL_PREFIX3} \ + --var-dir=${RPM_INSTALL_PREFIX4} \ + --uninstall + +%files +%defattr(-,root,root) +%attr(0755,root,hadoop) %{_log_dir} +%attr(0775,root,hadoop) %{_pid_dir} +%attr(0775,root,hadoop) /etc/init.d/zookeeper +%config(noreplace) %{_conf_dir}/* +%{_prefix} + +%post lib +/sbin/ldconfig + +%files lib +%defattr(-,root,root) +%{_prefix}/lib/* +%{_prefix}/bin diff --git a/src/packages/templates/conf/zookeeper-env.sh b/src/packages/templates/conf/zookeeper-env.sh new file mode 100644 index 00000000000..a9efb63fb0a --- /dev/null +++ b/src/packages/templates/conf/zookeeper-env.sh @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +export JAVA_HOME=${JAVA_HOME} +export ZOO_LOG_DIR=${LOG_DIR} diff --git a/src/packages/update-zookeeper-env.sh b/src/packages/update-zookeeper-env.sh new file mode 100644 index 00000000000..84284874186 --- /dev/null +++ b/src/packages/update-zookeeper-env.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script configures zookeeper-env.sh and zoo.cfg. + +usage() { + echo " +usage: $0 + Required parameters: + --prefix=PREFIX path to install into + + Optional parameters: + --arch=i386 OS Architecture + --conf-dir=/etc/zookeeper Configuration directory + --log-dir=/var/log/zookeeper Log directory + --pid-dir=/var/run PID file location + " + exit 1 +} + +template_generator() { + REGEX='(\$\{[a-zA-Z_][a-zA-Z_0-9]*\})' + cat $1 | + while read line ; do + while [[ "$line" =~ $REGEX ]] ; do + LHS=${BASH_REMATCH[1]} + RHS="$(eval echo "\"$LHS\"")" + line=${line//$LHS/$RHS} + done + echo $line >> $2 + done +} + +OPTS=$(getopt \ + -n $0 \ + -o '' \ + -l 'arch:' \ + -l 'prefix:' \ + -l 'conf-dir:' \ + -l 'log-dir:' \ + -l 'pid-dir:' \ + -l 'var-dir:' \ + -l 'uninstall' \ + -- "$@") + +if [ $? != 0 ] ; then + usage +fi + +eval set -- "${OPTS}" +while true ; do + case "$1" in + --arch) + ARCH=$2 ; shift 2 + ;; + --prefix) + PREFIX=$2 ; shift 2 + ;; + --log-dir) + LOG_DIR=$2 ; shift 2 + ;; + --lib-dir) + LIB_DIR=$2 ; shift 2 + ;; + --conf-dir) + CONF_DIR=$2 ; shift 2 + ;; + --pid-dir) + PID_DIR=$2 ; shift 2 + ;; + --uninstall) + UNINSTALL=1; shift + ;; + --var-dir) + VAR_DIR=$2 ; shift 2 + ;; + --) + shift ; break + ;; + *) + echo "Unknown option: $1" + usage + exit 1 + ;; + esac +done + +for var in PREFIX; do + if [ -z "$(eval "echo \$$var")" ]; then + echo Missing param: $var + usage + fi +done + +ARCH=${ARCH:-i386} +CONF_DIR=${CONF_DIR:-$PREFIX/etc/zookeeper} +LIB_DIR=${LIB_DIR:-$PREFIX/lib} +LOG_DIR=${LOG_DIR:-$PREFIX/var/log} +PID_DIR=${PID_DIR:-$PREFIX/var/run} +VAR_DIR=${VAR_DIR:-$PREFIX/var/lib} +UNINSTALL=${UNINSTALL:-0} + +if [ "${ARCH}" != "i386" ]; then + LIB_DIR=${LIB_DIR}64 +fi + +if [ "${UNINSTALL}" -eq "1" ]; then + # Remove symlinks + if [ -e ${PREFIX}/etc/zookeeper ]; then + rm -f ${PREFIX}/etc/zookeeper + fi +else + # Create symlinks + if [ ${CONF_DIR} != ${PREFIX}/etc/zookeeper ]; then + mkdir -p ${PREFIX}/etc + ln -sf ${CONF_DIR} ${PREFIX}/etc/zookeeper + fi + + mkdir -p ${LOG_DIR} + chown zookeeper:hadoop ${LOG_DIR} + chmod 755 ${LOG_DIR} + + if [ ! -d ${PID_DIR} ]; then + mkdir -p ${PID_DIR} + chown zookeeper:hadoop ${PID_DIR} + chmod 755 ${PID_DIR} + fi + + if [ ! -d ${VAR_DIR} ]; then + mkdir -p ${VAR_DIR}/data + chown -R zookeeper:hadoop ${VAR_DIR} + chmod -R 755 ${VAR_DIR} + fi + + TFILE="/tmp/$(basename $0).$$.tmp" + if [ -z "${JAVA_HOME}" ]; then + if [ -e /etc/debian_version ]; then + JAVA_HOME=/usr/lib/jvm/java-6-sun/jre + else + JAVA_HOME=/usr/java/default + fi + fi + template_generator ${PREFIX}/share/zookeeper/templates/conf/zookeeper-env.sh $TFILE + cp ${TFILE} ${CONF_DIR}/zookeeper-env.sh + rm -f ${TFILE} + template_generator ${PREFIX}/share/zookeeper/templates/conf/zoo.cfg $TFILE + cp ${TFILE} ${CONF_DIR}/zoo.cfg + rm -f ${TFILE} +fi diff --git a/src/zookeeper.jute b/src/zookeeper.jute new file mode 100644 index 00000000000..3858081dc7e --- /dev/null +++ b/src/zookeeper.jute @@ -0,0 +1,303 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module org.apache.zookeeper.data { + class Id { + ustring scheme; + ustring id; + } + class ACL { + int perms; + Id id; + } + // information shared with the client + class Stat { + long czxid; // created zxid + long mzxid; // last modified zxid + long ctime; // created + long mtime; // last modified + int version; // version + int cversion; // child version + int aversion; // acl version + long ephemeralOwner; // owner id if ephemeral, 0 otw + int dataLength; //length of the data in the node + int numChildren; //number of children of this node + long pzxid; // last modified children + } + // information explicitly stored by the server persistently + class StatPersisted { + long czxid; // created zxid + long mzxid; // last modified zxid + long ctime; // created + long mtime; // last modified + int version; // version + int cversion; // child version + int aversion; // acl version + long ephemeralOwner; // owner id if ephemeral, 0 otw + long pzxid; // last modified children + } +} + +module org.apache.zookeeper.proto { + class ConnectRequest { + int protocolVersion; + long lastZxidSeen; + int timeOut; + long sessionId; + buffer passwd; + } + class ConnectResponse { + int protocolVersion; + int timeOut; + long sessionId; + buffer passwd; + } + class SetWatches { + long relativeZxid; + vectordataWatches; + vectorexistWatches; + vectorchildWatches; + } + class RequestHeader { + int xid; + int type; + } + class MultiHeader { + int type; + boolean done; + int err; + } + class AuthPacket { + int type; + ustring scheme; + buffer auth; + } + class ReplyHeader { + int xid; + long zxid; + int err; + } + + class GetDataRequest { + ustring path; + boolean watch; + } + + class SetDataRequest { + ustring path; + buffer data; + int version; + } + class ReconfigRequest { + ustring joiningServers; + ustring leavingServers; + ustring newMembers; + long curConfigId; + } + class SetDataResponse { + org.apache.zookeeper.data.Stat stat; + } + class GetSASLRequest { + buffer token; + } + class SetSASLRequest { + buffer token; + } + class SetSASLResponse { + buffer token; + } + class CreateRequest { + ustring path; + buffer data; + vector acl; + int flags; + } + class DeleteRequest { + ustring path; + int version; + } + class GetChildrenRequest { + ustring path; + boolean watch; + } + class GetChildren2Request { + ustring path; + boolean watch; + } + class CheckVersionRequest { + ustring path; + int version; + } + class GetMaxChildrenRequest { + ustring path; + } + class GetMaxChildrenResponse { + int max; + } + class SetMaxChildrenRequest { + ustring path; + int max; + } + class SyncRequest { + ustring path; + } + class SyncResponse { + ustring path; + } + class GetACLRequest { + ustring path; + } + class SetACLRequest { + ustring path; + vector acl; + int version; + } + class SetACLResponse { + org.apache.zookeeper.data.Stat stat; + } + class WatcherEvent { + int type; // event type + int state; // state of the Keeper client runtime + ustring path; + } + class ErrorResponse { + int err; + } + class CreateResponse { + ustring path; + } + class Create2Response { + ustring path; + org.apache.zookeeper.data.Stat stat; + } + class ExistsRequest { + ustring path; + boolean watch; + } + class ExistsResponse { + org.apache.zookeeper.data.Stat stat; + } + class GetDataResponse { + buffer data; + org.apache.zookeeper.data.Stat stat; + } + class GetChildrenResponse { + vector children; + } + class GetChildren2Response { + vector children; + org.apache.zookeeper.data.Stat stat; + } + class GetACLResponse { + vector acl; + org.apache.zookeeper.data.Stat stat; + } + class CheckWatchesRequest { + ustring path; + int type; + } + class RemoveWatchesRequest { + ustring path; + int type; + } +} + +module org.apache.zookeeper.server.quorum { + class LearnerInfo { + long serverid; + int protocolVersion; + long configVersion; + } + class QuorumPacket { + int type; // Request, Ack, Commit, Ping + long zxid; + buffer data; // Only significant when type is request + vector authinfo; + } +} + +module org.apache.zookeeper.server.persistence { + class FileHeader { + int magic; + int version; + long dbid; + } +} + +module org.apache.zookeeper.txn { + class TxnHeader { + long clientId; + int cxid; + long zxid; + long time; + int type; + } + class CreateTxnV0 { + ustring path; + buffer data; + vector acl; + boolean ephemeral; + } + class CreateTxn { + ustring path; + buffer data; + vector acl; + boolean ephemeral; + int parentCVersion; + } + class CreateContainerTxn { + ustring path; + buffer data; + vector acl; + int parentCVersion; + } + class DeleteTxn { + ustring path; + } + class SetDataTxn { + ustring path; + buffer data; + int version; + } + class CheckVersionTxn { + ustring path; + int version; + } + class SetACLTxn { + ustring path; + vector acl; + int version; + } + class SetMaxChildrenTxn { + ustring path; + int max; + } + class CreateSessionTxn { + int timeOut; + } + class ErrorTxn { + int err; + } + class Txn { + int type; + buffer data; + } + class MultiTxn { + vector txns; + } +} diff --git a/zookeeper/build.xml b/zookeeper/build.xml deleted file mode 100644 index 8fc5d7e886f..00000000000 --- a/zookeeper/build.xml +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Tests failed! - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/zookeeper/java/src/com/yahoo/jute/BinaryOutputArchive.java b/zookeeper/java/src/com/yahoo/jute/BinaryOutputArchive.java deleted file mode 100755 index 1e7e5ace37b..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/BinaryOutputArchive.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute; - -import java.io.IOException; -import java.io.ByteArrayOutputStream; -import java.util.TreeMap; -import java.util.ArrayList; -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.OutputStream; - -/** - * - * @author Milind Bhandarkar - */ -public class BinaryOutputArchive implements OutputArchive { - - private DataOutput out; - - public static BinaryOutputArchive getArchive(OutputStream strm) { - return new BinaryOutputArchive(new DataOutputStream(strm)); - } - - /** Creates a new instance of BinaryOutputArchive */ - public BinaryOutputArchive(DataOutput out) { - this.out = out; - } - - public void writeByte(byte b, String tag) throws IOException { - out.writeByte(b); - } - - public void writeBool(boolean b, String tag) throws IOException { - out.writeBoolean(b); - } - - public void writeInt(int i, String tag) throws IOException { - out.writeInt(i); - } - - public void writeLong(long l, String tag) throws IOException { - out.writeLong(l); - } - - public void writeFloat(float f, String tag) throws IOException { - out.writeFloat(f); - } - - public void writeDouble(double d, String tag) throws IOException { - out.writeDouble(d); - } - - public void writeString(String s, String tag) throws IOException { - if (s == null) { - out.writeInt(-1); - return; - } - byte b[] = s.getBytes("UTF8"); - out.writeInt(b.length); - out.write(b); - } - - public void writeBuffer(byte barr[], String tag) - throws IOException { - if (barr == null) { - out.writeInt(-1); - return; - } - out.writeInt(barr.length); - out.write(barr); - } - - public void writeRecord(Record r, String tag) throws IOException { - r.serialize(this, tag); - } - - public void startRecord(Record r, String tag) throws IOException {} - - public void endRecord(Record r, String tag) throws IOException {} - - public void startVector(ArrayList v, String tag) throws IOException { - if (v == null) { - writeInt(-1, tag); - return; - } - writeInt(v.size(), tag); - } - - public void endVector(ArrayList v, String tag) throws IOException {} - - public void startMap(TreeMap v, String tag) throws IOException { - writeInt(v.size(), tag); - } - - public void endMap(TreeMap v, String tag) throws IOException {} - -} diff --git a/zookeeper/java/src/com/yahoo/jute/Index.java b/zookeeper/java/src/com/yahoo/jute/Index.java deleted file mode 100755 index 70a7b0125c6..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/Index.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute; - -/** - * Interface that acts as an iterator for deserializing maps. - * The deserializer returns an instance that the record uses to - * read vectors and maps. An example of usage is as follows: - * - * - * Index idx = startVector(...); - * while (!idx.done()) { - * .... // read element of a vector - * idx.incr(); - * } - * - * - * @author Milind Bhandarkar - */ -public interface Index { - public boolean done(); - public void incr(); -} diff --git a/zookeeper/java/src/com/yahoo/jute/OutputArchive.java b/zookeeper/java/src/com/yahoo/jute/OutputArchive.java deleted file mode 100755 index 6079152fcb4..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/OutputArchive.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute; - -import java.io.IOException; -import java.io.ByteArrayOutputStream; -import java.util.TreeMap; -import java.util.ArrayList; - -/** - * Interface that alll the serializers have to implement. - * - * @author Milind Bhandarkar - */ -public interface OutputArchive { - public void writeByte(byte b, String tag) throws IOException; - public void writeBool(boolean b, String tag) throws IOException; - public void writeInt(int i, String tag) throws IOException; - public void writeLong(long l, String tag) throws IOException; - public void writeFloat(float f, String tag) throws IOException; - public void writeDouble(double d, String tag) throws IOException; - public void writeString(String s, String tag) throws IOException; - public void writeBuffer(byte buf[], String tag) - throws IOException; - public void writeRecord(Record r, String tag) throws IOException; - public void startRecord(Record r, String tag) throws IOException; - public void endRecord(Record r, String tag) throws IOException; - public void startVector(ArrayList v, String tag) throws IOException; - public void endVector(ArrayList v, String tag) throws IOException; - public void startMap(TreeMap v, String tag) throws IOException; - public void endMap(TreeMap v, String tag) throws IOException; - -} diff --git a/zookeeper/java/src/com/yahoo/jute/RecordWriter.java b/zookeeper/java/src/com/yahoo/jute/RecordWriter.java deleted file mode 100755 index ffd1c50125f..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/RecordWriter.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.DataOutputStream; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import javax.xml.parsers.ParserConfigurationException; -import org.xml.sax.SAXException; - -/** - * Front-end for serializers. Also serves as a factory for serializers. - * - * @author Milind Bhandarkar - */ -public class RecordWriter { - - private OutputArchive archive; - - static private OutputArchive getBinaryArchive(OutputStream out) { - return new BinaryOutputArchive(new DataOutputStream(out)); - } - - static private OutputArchive getCsvArchive(OutputStream out) - throws IOException { - try { - return new CsvOutputArchive(out); - } catch (UnsupportedEncodingException ex) { - throw new IOException("Unsupported encoding UTF-8"); - } - } - - static private OutputArchive getXmlArchive(OutputStream out) - throws IOException { - return new XmlOutputArchive(out); - } - - static HashMap constructFactory() { - HashMap factory = new HashMap(); - Class[] params = { OutputStream.class }; - try { - factory.put("binary", - BinaryOutputArchive.class.getDeclaredMethod( - "getArchive", params)); - factory.put("csv", - CsvOutputArchive.class.getDeclaredMethod( - "getArchive", params)); - factory.put("xml", - XmlOutputArchive.class.getDeclaredMethod( - "getArchive", params)); - } catch (SecurityException ex) { - ex.printStackTrace(); - } catch (NoSuchMethodException ex) { - ex.printStackTrace(); - } - return factory; - } - - static private HashMap archiveFactory = constructFactory(); - - static private OutputArchive createArchive(OutputStream out, - String format) - throws IOException { - Method factory = (Method) archiveFactory.get(format); - if (factory != null) { - Object[] params = { out }; - try { - return (OutputArchive) factory.invoke(null, params); - } catch (IllegalArgumentException ex) { - ex.printStackTrace(); - } catch (InvocationTargetException ex) { - ex.printStackTrace(); - } catch (IllegalAccessException ex) { - ex.printStackTrace(); - } - } - return null; - } - /** - * Creates a new instance of RecordWriter - * @param out Output stream where the records will be serialized - * @param format Serialization format ("binary", "xml", or "csv") - */ - public RecordWriter(OutputStream out, String format) - throws IOException { - archive = createArchive(out, format); - } - - /** - * Serialize a record - * @param r record to be serialized - */ - public void write(Record r) throws IOException { - r.serialize(archive, ""); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/Utils.java b/zookeeper/java/src/com/yahoo/jute/Utils.java deleted file mode 100755 index e7a60e82ff6..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/Utils.java +++ /dev/null @@ -1,276 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute; - -import java.io.ByteArrayOutputStream; -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.charset.CharacterCodingException; - -/** - * Various utility functions for Hadooop record I/O runtime. - * @author Milind Bhandarkar - */ -public class Utils { - - /** Cannot create a new instance of Utils */ - private Utils() { - } - - /** - * equals function that actually compares two buffers. - * - * @param onearray First buffer - * @param twoarray Second buffer - * @return true if one and two contain exactly the same content, else false. - */ - public static boolean bufEquals(byte onearray[], byte twoarray[] ) { - if (onearray == twoarray) return true; - boolean ret = (onearray.length == twoarray.length); - if (!ret) { - return ret; - } - for (int idx = 0; idx < onearray.length; idx++) { - if (onearray[idx] != twoarray[idx]) { - return false; - } - } - return true; - } - - public static final char[] hexchars = { '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F' }; - /** - * - * @param s - * @return - */ - static String toXMLString(String t) { - String s = t.toString(); - StringBuffer sb = new StringBuffer(); - for (int idx = 0; idx < s.length(); idx++) { - char ch = s.charAt(idx); - if (ch == '<') { - sb.append("<"); - } else if (ch == '&') { - sb.append("&"); - } else if (ch == '%') { - sb.append("%25"); - } else if (ch < 0x20) { - sb.append("%"); - sb.append(hexchars[ch/16]); - sb.append(hexchars[ch%16]); - } else { - sb.append(ch); - } - } - return sb.toString(); - } - - static private int h2c(char ch) { - if (ch >= '0' && ch <= '9') { - return ch - '0'; - } else if (ch >= 'A' && ch <= 'F') { - return ch - 'A'; - } else if (ch >= 'a' && ch <= 'f') { - return ch - 'a'; - } - return 0; - } - - /** - * - * @param s - * @return - */ - static String fromXMLString(String s) { - StringBuffer sb = new StringBuffer(); - for (int idx = 0; idx < s.length();) { - char ch = s.charAt(idx++); - if (ch == '%') { - char ch1 = s.charAt(idx++); - char ch2 = s.charAt(idx++); - char res = (char)(h2c(ch1)*16 + h2c(ch2)); - sb.append(res); - } else { - sb.append(ch); - } - } - - return sb.toString(); - } - - /** - * - * @param s - * @return - */ - static String toCSVString(String t) { - String s = t.toString(); - StringBuffer sb = new StringBuffer(s.length()+1); - sb.append('\''); - int len = s.length(); - for (int i = 0; i < len; i++) { - char c = s.charAt(i); - switch(c) { - case '\0': - sb.append("%00"); - break; - case '\n': - sb.append("%0A"); - break; - case '\r': - sb.append("%0D"); - break; - case ',': - sb.append("%2C"); - break; - case '}': - sb.append("%7D"); - break; - case '%': - sb.append("%25"); - break; - default: - sb.append(c); - } - } - return sb.toString(); - } - - /** - * - * @param s - * @throws java.io.IOException - * @return - */ - static String fromCSVString(String s) throws IOException { - if (s.charAt(0) != '\'') { - throw new IOException("Error deserializing string."); - } - int len = s.length(); - StringBuffer sb = new StringBuffer(len-1); - for (int i = 1; i < len; i++) { - char c = s.charAt(i); - if (c == '%') { - char ch1 = s.charAt(i+1); - char ch2 = s.charAt(i+2); - i += 2; - if (ch1 == '0' && ch2 == '0') { sb.append('\0'); } - else if (ch1 == '0' && ch2 == 'A') { sb.append('\n'); } - else if (ch1 == '0' && ch2 == 'D') { sb.append('\r'); } - else if (ch1 == '2' && ch2 == 'C') { sb.append(','); } - else if (ch1 == '7' && ch2 == 'D') { sb.append('}'); } - else if (ch1 == '2' && ch2 == '5') { sb.append('%'); } - else {throw new IOException("Error deserializing string.");} - } else { - sb.append(c); - } - } - return sb.toString(); - } - - /** - * - * @param s - * @return - */ - static String toXMLBuffer(byte barr[]) { - StringBuffer sb = new StringBuffer(2*barr.length); - for (int idx = 0; idx < barr.length; idx++) { - sb.append(Integer.toHexString((int)barr[idx])); - } - return sb.toString(); - } - - /** - * - * @param s - * @throws java.io.IOException - * @return - */ - static byte[] fromXMLBuffer(String s) - throws IOException { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - if (s.length() == 0) { return stream.toByteArray(); } - int blen = s.length()/2; - byte[] barr = new byte[blen]; - for (int idx = 0; idx < blen; idx++) { - char c1 = s.charAt(2*idx); - char c2 = s.charAt(2*idx+1); - barr[idx] = Byte.parseByte(""+c1+c2, 16); - } - stream.write(barr); - return stream.toByteArray(); - } - - /** - * - * @param buf - * @return - */ - static String toCSVBuffer(byte barr[]) { - StringBuffer sb = new StringBuffer(barr.length+1); - sb.append('#'); - for(int idx = 0; idx < barr.length; idx++) { - sb.append(Integer.toHexString((int)barr[idx])); - } - return sb.toString(); - } - - /** - * Converts a CSV-serialized representation of buffer to a new - * ByteArrayOutputStream. - * @param s CSV-serialized representation of buffer - * @throws java.io.IOException - * @return Deserialized ByteArrayOutputStream - */ - static byte[] fromCSVBuffer(String s) - throws IOException { - if (s.charAt(0) != '#') { - throw new IOException("Error deserializing buffer."); - } - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - if (s.length() == 1) { return stream.toByteArray(); } - int blen = (s.length()-1)/2; - byte[] barr = new byte[blen]; - for (int idx = 0; idx < blen; idx++) { - char c1 = s.charAt(2*idx+1); - char c2 = s.charAt(2*idx+2); - barr[idx] = Byte.parseByte(""+c1+c2, 16); - } - stream.write(barr); - return stream.toByteArray(); - } - public static int compareBytes(byte b1[], int off1, int len1, byte b2[], int off2, int len2) { - int i; - for(i=0; i < len1 && i < len2; i++) { - if (b1[off1+i] != b2[off2+i]) { - return b1[off1+i] < b2[off2+1] ? -1 : 1; - } - } - if (len1 != len2) { - return len1 < len2 ? -1 : 1; - } - return 0; - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/CGenerator.java b/zookeeper/java/src/com/yahoo/jute/compiler/CGenerator.java deleted file mode 100644 index c9d39096918..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/CGenerator.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -import java.util.ArrayList; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; - -/** - * C++ Code generator front-end for Hadoop record I/O. - * - * @author Milind Bhandarkar - */ -class CGenerator { - private String mFullName; - private String mName; - private ArrayList mInclFiles; - private ArrayList mRecList; - - /** Creates a new instance of CppGenerator - * - * @param name possibly full pathname to the file - * @param ilist included files (as JFile) - * @param rlist List of records defined within this file - */ - CGenerator(String name, ArrayList ilist, ArrayList rlist) { - mFullName = name; - mName = (new File(name)).getName(); - mInclFiles = ilist; - mRecList = rlist; - } - - /** - * Generate C++ code. This method only creates the requested file(s) - * and spits-out file-level elements (such as include statements etc.) - * record-level code is generated by JRecord. - */ - void genCode() throws IOException { - FileWriter c = new FileWriter(mName+".c"); - FileWriter h = new FileWriter(mName+".h"); - h.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n"); - h.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n"); - - h.write("#include \"recordio.h\"\n"); - for (Iterator i = mInclFiles.iterator(); i.hasNext();) { - JFile f = (JFile) i.next(); - h.write("#include \""+f.getName()+".hh\"\n"); - } - c.write("#include \""+mName+".h\"\n"); - - for (Iterator i = mRecList.iterator(); i.hasNext();) { - JRecord jr = (JRecord) i.next(); - jr.genCCode(h, c); - } - - h.write("#endif //"+mName.toUpperCase().replace('.','_')+"__\n"); - - h.close(); - c.close(); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/CppGenerator.java b/zookeeper/java/src/com/yahoo/jute/compiler/CppGenerator.java deleted file mode 100755 index 165502ac227..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/CppGenerator.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -import java.util.ArrayList; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; - -/** - * C++ Code generator front-end for Hadoop record I/O. - * - * @author Milind Bhandarkar - */ -class CppGenerator { - private String mFullName; - private String mName; - private ArrayList mInclFiles; - private ArrayList mRecList; - - /** Creates a new instance of CppGenerator - * - * @param name possibly full pathname to the file - * @param ilist included files (as JFile) - * @param rlist List of records defined within this file - */ - CppGenerator(String name, ArrayList ilist, ArrayList rlist) { - mFullName = name; - mName = (new File(name)).getName(); - mInclFiles = ilist; - mRecList = rlist; - } - - /** - * Generate C++ code. This method only creates the requested file(s) - * and spits-out file-level elements (such as include statements etc.) - * record-level code is generated by JRecord. - */ - void genCode() throws IOException { - FileWriter cc = new FileWriter(mName+".cc"); - FileWriter hh = new FileWriter(mName+".hh"); - hh.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n"); - hh.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n"); - - hh.write("#include \"recordio.hh\"\n"); - for (Iterator i = mInclFiles.iterator(); i.hasNext();) { - JFile f = (JFile) i.next(); - hh.write("#include \""+f.getName()+".hh\"\n"); - } - cc.write("#include \""+mName+".hh\"\n"); - - for (Iterator i = mRecList.iterator(); i.hasNext();) { - JRecord jr = (JRecord) i.next(); - jr.genCppCode(hh, cc); - } - - hh.write("#endif //"+mName.toUpperCase().replace('.','_')+"__\n"); - - hh.close(); - cc.close(); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JBuffer.java b/zookeeper/java/src/com/yahoo/jute/compiler/JBuffer.java deleted file mode 100755 index 7f6f2f0c291..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JBuffer.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -/** - * - * @author Milind Bhandarkar - */ -public class JBuffer extends JCompType { - - /** Creates a new instance of JBuffer */ - public JBuffer() { - super("struct buffer", " ::std::string", "byte[]", "Buffer", "byte[]"); - } - - public String genCppGetSet(String fname, int fIdx) { - String cgetFunc = " virtual const "+getCppType()+"& get"+fname+"() const {\n"; - cgetFunc += " return m"+fname+";\n"; - cgetFunc += " }\n"; - String getFunc = " virtual "+getCppType()+"& get"+fname+"() {\n"; - getFunc += " bs_.set("+fIdx+");return m"+fname+";\n"; - getFunc += " }\n"; - return cgetFunc + getFunc; - } - - public String getSignature() { - return "B"; - } - - public String genJavaReadWrapper(String fname, String tag, boolean decl) { - String ret = ""; - if (decl) { - ret = " byte[] "+fname+";\n"; - } - return ret + " "+fname+"=a_.readBuffer(\""+tag+"\");\n"; - } - - public String genJavaWriteWrapper(String fname, String tag) { - return " a_.writeBuffer("+fname+",\""+tag+"\");\n"; - } - - public String genJavaCompareTo(String fname, String other) { - StringBuffer sb = new StringBuffer(); - sb.append(" {\n"); - sb.append(" byte[] my = "+fname+";\n"); - sb.append(" byte[] ur = "+other+";\n"); - sb.append(" ret = com.yahoo.jute.Utils.compareBytes(my,0,my.length,ur,0,ur.length);\n"); - sb.append(" }\n"); - return sb.toString(); - } - - public String genJavaCompareTo(String fname) { - return genJavaCompareTo(fname, "peer."+fname); - } - public String genJavaCompareToWrapper(String fname, String other) { - return " "+genJavaCompareTo(fname, other); - } - - public String genJavaEquals(String fname, String peer) { - return " ret = com.yahoo.jute.Utils.bufEquals("+fname+","+peer+");\n"; - } - - public String genJavaHashCode(String fname) { - return " ret = "+fname+".toString().hashCode();\n"; - } - - public String genJavaSlurpBytes(String b, String s, String l) { - StringBuffer sb = new StringBuffer(); - sb.append(" {\n"); - sb.append(" int i = com.yahoo.jute.Utils.readVInt("+b+", "+s+");\n"); - sb.append(" int z = WritableUtils.getVIntSize(i);\n"); - sb.append(" "+s+" += z+i; "+l+" -= (z+i);\n"); - sb.append(" }\n"); - return sb.toString(); - } - - public String genJavaCompareBytes() { - StringBuffer sb = new StringBuffer(); - sb.append(" {\n"); - sb.append(" int i1 = com.yahoo.jute.Utils.readVInt(b1, s1);\n"); - sb.append(" int i2 = com.yahoo.jute.Utils.readVInt(b2, s2);\n"); - sb.append(" int z1 = WritableUtils.getVIntSize(i1);\n"); - sb.append(" int z2 = WritableUtils.getVIntSize(i2);\n"); - sb.append(" s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n"); - sb.append(" int r1 = com.yahoo.jute.Utils.compareBytes(b1,s1,l1,b2,s2,l2);\n"); - sb.append(" if (r1 != 0) { return (r1<0)?-1:0; }\n"); - sb.append(" s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n"); - sb.append(" }\n"); - return sb.toString(); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JCompType.java b/zookeeper/java/src/com/yahoo/jute/compiler/JCompType.java deleted file mode 100755 index c15c71dd428..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JCompType.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -/** - * Abstract base class for all the "compound" types such as ustring, - * buffer, vector, map, and record. - * - * @author Milind Bhandarkar - */ -abstract class JCompType extends JType { - - /** Creates a new instance of JCompType */ - JCompType(String cType, String cppType, String javaType, String suffix, String wrapper) { - super(cType, cppType, javaType, suffix, wrapper, null); - } - - String genCppGetSet(String fname, int fIdx) { - String cgetFunc = " virtual const "+getCppType()+"& get"+fname+"() const {\n"; - cgetFunc += " return m"+fname+";\n"; - cgetFunc += " }\n"; - String getFunc = " virtual "+getCppType()+"& get"+fname+"() {\n"; - getFunc += " bs_.set("+fIdx+");return m"+fname+";\n"; - getFunc += " }\n"; - return cgetFunc + getFunc; - } - - String genJavaCompareTo(String fname) { - return " ret = "+fname+".compareTo(peer."+fname+");\n"; - } - - String genJavaEquals(String fname, String peer) { - return " ret = "+fname+".equals("+peer+");\n"; - } - - String genJavaHashCode(String fname) { - return " ret = "+fname+".hashCode();\n"; - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JField.java b/zookeeper/java/src/com/yahoo/jute/compiler/JField.java deleted file mode 100755 index dd569350b5f..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JField.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -/** - * - * @author Milind Bhandarkar - */ -public class JField { - private JType mType; - private String mName; - /** - * Creates a new instance of JField - */ - public JField(JType type, String name) { - mType = type; - mName = name; - } - - public String getSignature() { - return mType.getSignature(); - } - - public String genCppDecl() { - return mType.genCppDecl(mName); - } - - public String genCDecl() { - return mType.genCDecl(mName); - } - - public String genJavaDecl() { - return mType.genJavaDecl(mName); - } - - public String genJavaConstructorParam(String fname) { - return mType.genJavaConstructorParam(fname); - } - - public String getName() { - return mName; - } - - public String getTag() { - return mName; - } - - public JType getType() { - return mType; - } - - public String genCppGetSet(int fIdx) { - return mType.genCppGetSet(mName, fIdx); - } - - public String genJavaGetSet(int fIdx) { - return mType.genJavaGetSet(mName, fIdx); - } - - public String genJavaWriteMethodName() { - return mType.genJavaWriteMethod(getName(), getTag()); - } - - public String genJavaReadMethodName() { - return mType.genJavaReadMethod(getName(), getTag()); - } - - public String genJavaCompareTo() { - return mType.genJavaCompareTo(getName()); - } - - public String genJavaEquals() { - return mType.genJavaEquals(getName(), "peer."+getName()); - } - - public String genJavaHashCode() { - return mType.genJavaHashCode(getName()); - } - - public String genJavaConstructorSet(String fname) { - return mType.genJavaConstructorSet(mName, fname); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JFile.java b/zookeeper/java/src/com/yahoo/jute/compiler/JFile.java deleted file mode 100755 index cfbb9632424..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JFile.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -import java.io.IOException; -import java.util.ArrayList; - -/** - * Container for the Hadoop Record DDL. - * The main components of the file are filename, list of included files, - * and records defined in that file. - * - * @author Milind Bhandarkar - */ -public class JFile { - - private String mName; - private ArrayList mInclFiles; - private ArrayList mRecords; - - /** Creates a new instance of JFile - * - * @param name possibly full pathname to the file - * @param inclFiles included files (as JFile) - * @param recList List of records defined within this file - */ - public JFile(String name, ArrayList inclFiles, ArrayList recList) { - mName = name; - mInclFiles = inclFiles; - mRecords = recList; - } - - /** Strip the other pathname components and return the basename */ - String getName() { - int idx = mName.lastIndexOf('/'); - return (idx > 0) ? mName.substring(idx) : mName; - } - - /** Generate record code in given language. Language should be all - * lowercase. - */ - public void genCode(String language) throws IOException { - if ("c++".equals(language)) { - CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords); - gen.genCode(); - } else if ("java".equals(language)) { - JavaGenerator gen = new JavaGenerator(mName, mInclFiles, mRecords); - gen.genCode(); - } else if ("c".equals(language)) { - CGenerator gen = new CGenerator(mName, mInclFiles, mRecords); - gen.genCode(); - } else { - System.out.println("Cannnot recognize language:"+language); - System.exit(1); - } - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JMap.java b/zookeeper/java/src/com/yahoo/jute/compiler/JMap.java deleted file mode 100755 index 4abb8114cd3..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JMap.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -/** - * - * @author Milind Bhandarkar - */ -public class JMap extends JCompType { - - static private int level = 0; - - static private String getLevel() { return Integer.toString(level); } - - static private void incrLevel() { level++; } - - static private void decrLevel() { level--; } - - static private String getId(String id) { return id+getLevel(); } - - private JType mKey; - private JType mValue; - - /** Creates a new instance of JMap */ - public JMap(JType t1, JType t2) { - super("#error", " ::std::map<"+t1.getCppType()+","+t2.getCppType()+">", - "java.util.TreeMap", "Map", "java.util.TreeMap"); - mKey = t1; - mValue = t2; - } - - public String getSignature() { - return "{" + mKey.getSignature() + mValue.getSignature() +"}"; - } - - public String genJavaCompareTo(String fname) { - return ""; - } - - public String genJavaReadWrapper(String fname, String tag, boolean decl) { - StringBuffer ret = new StringBuffer(""); - if (decl) { - ret.append(" java.util.TreeMap "+fname+";\n"); - } - ret.append(" {\n"); - incrLevel(); - ret.append(" com.yahoo.jute.Index "+getId("midx")+" = a_.startMap(\""+tag+"\");\n"); - ret.append(" "+fname+"=new java.util.TreeMap();\n"); - ret.append(" for (; !"+getId("midx")+".done(); "+getId("midx")+".incr()) {\n"); - ret.append(mKey.genJavaReadWrapper(getId("k"),getId("k"),true)); - ret.append(mValue.genJavaReadWrapper(getId("v"),getId("v"),true)); - ret.append(" "+fname+".put("+getId("k")+","+getId("v")+");\n"); - ret.append(" }\n"); - ret.append(" a_.endMap(\""+tag+"\");\n"); - decrLevel(); - ret.append(" }\n"); - return ret.toString(); - } - - public String genJavaReadMethod(String fname, String tag) { - return genJavaReadWrapper(fname, tag, false); - } - - public String genJavaWriteWrapper(String fname, String tag) { - StringBuffer ret = new StringBuffer(" {\n"); - incrLevel(); - ret.append(" a_.startMap("+fname+",\""+tag+"\");\n"); - ret.append(" java.util.Set "+getId("es")+" = "+fname+".entrySet();\n"); - ret.append(" for(java.util.Iterator "+getId("midx")+" = "+getId("es")+".iterator(); "+getId("midx")+".hasNext(); ) {\n"); - ret.append(" java.util.Map.Entry "+getId("me")+" = (java.util.Map.Entry) "+getId("midx")+".next();\n"); - ret.append(" "+mKey.getJavaWrapperType()+" "+getId("k")+" = ("+mKey.getJavaWrapperType()+") "+getId("me")+".getKey();\n"); - ret.append(" "+mValue.getJavaWrapperType()+" "+getId("v")+" = ("+mValue.getJavaWrapperType()+") "+getId("me")+".getValue();\n"); - ret.append(mKey.genJavaWriteWrapper(getId("k"),getId("k"))); - ret.append(mValue.genJavaWriteWrapper(getId("v"),getId("v"))); - ret.append(" }\n"); - ret.append(" a_.endMap("+fname+",\""+tag+"\");\n"); - ret.append(" }\n"); - decrLevel(); - return ret.toString(); - } - - public String genJavaWriteMethod(String fname, String tag) { - return genJavaWriteWrapper(fname, tag); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JRecord.java b/zookeeper/java/src/com/yahoo/jute/compiler/JRecord.java deleted file mode 100755 index c1ff1d5b748..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JRecord.java +++ /dev/null @@ -1,506 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -/** - * - * @author Milind Bhandarkar - */ -public class JRecord extends JCompType { - - private String mFQName; - private String mName; - private String mModule; - private ArrayList mFields; - - /** - * Creates a new instance of JRecord - */ - public JRecord(String name, ArrayList flist) { - super("struct " + name.substring(name.lastIndexOf('.')+1), name.replaceAll("\\.","::"), name, "Record", name); - mFQName = name; - int idx = name.lastIndexOf('.'); - mName = name.substring(idx+1); - mModule = name.substring(0, idx); - mFields = flist; - } - - public String getName() { - return mName; - } - - public String getJavaFQName() { - return mFQName; - } - - public String getCppFQName() { - return mFQName.replaceAll("\\.", "::"); - } - - public String getJavaPackage() { - return mModule; - } - - public String getCppNameSpace() { - return mModule.replaceAll("\\.", "::"); - } - - public ArrayList getFields() { - return mFields; - } - - public String getSignature() { - StringBuffer sb = new StringBuffer(); - sb.append("L").append(mName).append("("); - for (Iterator i = mFields.iterator(); i.hasNext();) { - String s = ((JField) i.next()).getSignature(); - sb.append(s); - } - sb.append(")"); - return sb.toString(); - } - - public String genCppDecl(String fname) { - return " "+mName+" "+fname+";\n"; - } - - public String genJavaReadMethod(String fname, String tag) { - return genJavaReadWrapper(fname, tag, false); - } - - public String genJavaReadWrapper(String fname, String tag, boolean decl) { - StringBuffer ret = new StringBuffer(""); - if (decl) { - ret.append(" "+getJavaFQName()+" "+fname+";\n"); - } - ret.append(" "+fname+"= new "+getJavaFQName()+"();\n"); - ret.append(" a_.readRecord("+fname+",\""+tag+"\");\n"); - return ret.toString(); - } - - public String genJavaWriteWrapper(String fname, String tag) { - return " a_.writeRecord("+fname+",\""+tag+"\");\n"; - } - - static HashMap vectorStructs = new HashMap(); - public void genCCode(FileWriter h, FileWriter c) throws IOException { - for (JField f : mFields) { - if (f.getType() instanceof JVector) { - JVector jv = (JVector)f.getType(); - JType jvType = jv.getElementType(); - String struct_name = JVector.extractVectorName(jvType); - if (vectorStructs.get(struct_name) == null) { - vectorStructs.put(struct_name, struct_name); - h.write("struct " + struct_name + " {\n int count;\n" + jv.getElementType().genCDecl("*data") + ";\n};\n"); - h.write("int serialize_" + struct_name + "(struct oarchive *out, const char *tag, struct " + struct_name + " *v);\n"); - h.write("int deserialize_" + struct_name + "(struct iarchive *in, const char *tag, struct " + struct_name + " *v);\n"); - h.write("int allocate_" + struct_name + "(struct " + struct_name + " *v, int len);\n"); - h.write("int deallocate_" + struct_name + "(struct " + struct_name + " *v);\n"); - c.write("int allocate_" + struct_name + "(struct " + struct_name + " *v, int len) {\n"); - c.write(" if (!len) {\n"); - c.write(" v->count = 0;\n"); - c.write(" v->data = 0;\n"); - c.write(" } else {\n"); - c.write(" v->count = len;\n"); - c.write(" v->data = calloc(sizeof(*v->data), len);\n"); - c.write(" }\n"); - c.write(" return 0;\n"); - c.write("}\n"); - c.write("int deallocate_" + struct_name + "(struct " + struct_name + " *v) {\n"); - c.write(" if (v->data) {\n"); - c.write(" int i;\n"); - c.write(" for(i=0;icount; i++) {\n"); - c.write(" deallocate_"+JRecord.extractMethodSuffix(jvType)+"(&v->data[i]);\n"); - c.write(" }\n"); - c.write(" }\n"); - c.write(" return 0;\n"); - c.write("}\n"); - c.write("int serialize_" + struct_name + "(struct oarchive *out, const char *tag, struct " + struct_name + " *v)\n"); - c.write("{\n"); - c.write(" int count = v->count;\n"); - c.write(" int rc = 0;\n"); - c.write(" int i;\n"); - c.write(" rc = out->start_vector(out, tag, &count);\n"); - c.write(" for(i=0;icount;i++) {\n"); - genSerialize(c, jvType, "data", "data[i]"); - c.write(" }\n"); - c.write(" rc = rc ? : out->end_vector(out, tag);\n"); - c.write(" return rc;\n"); - c.write("}\n"); - c.write("int deserialize_" + struct_name + "(struct iarchive *in, const char *tag, struct " + struct_name + " *v)\n"); - c.write("{\n"); - c.write(" int rc = 0;\n"); - c.write(" int i;\n"); - c.write(" rc = in->start_vector(in, tag, &v->count);\n"); - c.write(" v->data = calloc(v->count, sizeof(*v->data));\n"); - c.write(" for(i=0;icount;i++) {\n"); - genDeserialize(c, jvType, "value", "data[i]"); - c.write(" }\n"); - c.write(" rc = in->end_vector(in, tag);\n"); - c.write(" return rc;\n"); - c.write("}\n"); - - } - } - } - String rec_name = getName(); - h.write("struct " + rec_name + " {\n"); - for (JField f : mFields) { - h.write(f.genCDecl()); - } - h.write("};\n"); - h.write("int serialize_" + rec_name + "(struct oarchive *out, const char *tag, struct " + rec_name + " *v);\n"); - h.write("int deserialize_" + rec_name + "(struct iarchive *in, const char *tag, struct " + rec_name + "*v);\n"); - h.write("void deallocate_" + rec_name + "(struct " + rec_name + "*);\n"); - c.write("int serialize_" + rec_name + "(struct oarchive *out, const char *tag, struct " + rec_name + " *v)"); - c.write("{\n"); - c.write(" int rc;\n"); - c.write(" rc = out->start_record(out, tag);\n"); - for(JField f : mFields) { - genSerialize(c, f.getType(), f.getTag(), f.getName()); - } - c.write(" rc = rc ? : out->end_record(out, tag);\n"); - c.write(" return rc;\n"); - c.write("}\n"); - c.write("int deserialize_" + rec_name + "(struct iarchive *in, const char *tag, struct " + rec_name + "*v)"); - c.write("{\n"); - c.write(" int rc;\n"); - c.write(" rc = in->start_record(in, tag);\n"); - for(JField f : mFields) { - genDeserialize(c, f.getType(), f.getTag(), f.getName()); - } - c.write(" rc = rc ? : in->end_record(in, tag);\n"); - c.write(" return rc;\n"); - c.write("}\n"); - c.write("void deallocate_" + rec_name + "(struct " + rec_name + "*v)"); - c.write("{\n"); - for(JField f : mFields) { - if (f.getType() instanceof JRecord) { - c.write(" deallocate_" + extractStructName(f.getType()) + "(&v->" + f.getName() + ");\n"); - } else if (f.getType() instanceof JVector) { - JVector vt = (JVector)f.getType(); - c.write(" deallocate_" + JVector.extractVectorName(vt.getElementType())+ "(&v->"+f.getName()+");\n"); - } else if (f.getType() instanceof JCompType) { - c.write(" deallocate_" + extractMethodSuffix(f.getType()) + "(&v->"+f.getName()+");\n"); - } - } - c.write("}\n"); - } - - private void genSerialize(FileWriter c, JType type, String tag, String name) throws IOException { - if (type instanceof JRecord) { - c.write(" rc = rc ? : serialize_" + extractStructName(type) + "(out, \"" + tag + "\", &v->" + name + ");\n"); - } else if (type instanceof JVector) { - c.write(" rc = rc ? : serialize_" + JVector.extractVectorName(((JVector)type).getElementType()) + "(out, \"" + tag + "\", &v->" + name + ");\n"); - } else { - c.write(" rc = rc ? : out->serialize_" + extractMethodSuffix(type) + "(out, \"" + tag + "\", &v->" + name + ");\n"); - } - } - - private void genDeserialize(FileWriter c, JType type, String tag, String name) throws IOException { - if (type instanceof JRecord) { - c.write(" rc = rc ? : deserialize_" + extractStructName(type) + "(in, \"" + tag + "\", &v->" + name + ");\n"); - } else if (type instanceof JVector) { - c.write(" rc = rc ? : deserialize_" + JVector.extractVectorName(((JVector)type).getElementType()) + "(in, \"" + tag + "\", &v->" + name + ");\n"); - } else { - c.write(" rc = rc ? : in->deserialize_" + extractMethodSuffix(type) + "(in, \"" + tag + "\", &v->" + name + ");\n"); - } - } - - static String extractMethodSuffix(JType t) { - if (t instanceof JRecord) { - return extractStructName(t); - } - return t.getMethodSuffix(); - } - - static private String extractStructName(JType t) { - String type = t.getCType(); - if (!type.startsWith("struct ")) return type; - return type.substring("struct ".length()); - } - - public void genCppCode(FileWriter hh, FileWriter cc) - throws IOException { - String[] ns = getCppNameSpace().split("::"); - for (int i = 0; i < ns.length; i++) { - hh.write("namespace "+ns[i]+" {\n"); - } - - hh.write("class "+getName()+" : public ::hadoop::Record {\n"); - hh.write("private:\n"); - - for (Iterator i = mFields.iterator(); i.hasNext();) { - JField jf = (JField) i.next(); - hh.write(jf.genCppDecl()); - } - hh.write(" mutable std::bitset<"+mFields.size()+"> bs_;\n"); - hh.write("public:\n"); - hh.write(" virtual void serialize(::hadoop::OArchive& a_, const char* tag) const;\n"); - hh.write(" virtual void deserialize(::hadoop::IArchive& a_, const char* tag);\n"); - hh.write(" virtual const ::std::string& type() const;\n"); - hh.write(" virtual const ::std::string& signature() const;\n"); - hh.write(" virtual bool validate() const;\n"); - hh.write(" virtual bool operator<(const "+getName()+"& peer_) const;\n"); - hh.write(" virtual bool operator==(const "+getName()+"& peer_) const;\n"); - hh.write(" virtual ~"+getName()+"() {};\n"); - int fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - hh.write(jf.genCppGetSet(fIdx)); - } - hh.write("}; // end record "+getName()+"\n"); - for (int i=ns.length-1; i>=0; i--) { - hh.write("} // end namespace "+ns[i]+"\n"); - } - cc.write("void "+getCppFQName()+"::serialize(::hadoop::OArchive& a_, const char* tag) const {\n"); - cc.write(" if (!validate()) throw new ::hadoop::IOException(\"All fields not set.\");\n"); - cc.write(" a_.startRecord(*this,tag);\n"); - fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - String name = jf.getName(); - if (jf.getType() instanceof JBuffer) { - cc.write(" a_.serialize("+name+","+name+".length(),\""+jf.getTag()+"\");\n"); - } else { - cc.write(" a_.serialize("+name+",\""+jf.getTag()+"\");\n"); - } - cc.write(" bs_.reset("+fIdx+");\n"); - } - cc.write(" a_.endRecord(*this,tag);\n"); - cc.write(" return;\n"); - cc.write("}\n"); - - cc.write("void "+getCppFQName()+"::deserialize(::hadoop::IArchive& a_, const char* tag) {\n"); - cc.write(" a_.startRecord(*this,tag);\n"); - fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - String name = jf.getName(); - if (jf.getType() instanceof JBuffer) { - cc.write(" { size_t len=0; a_.deserialize("+name+",len,\""+jf.getTag()+"\");}\n"); - } else { - cc.write(" a_.deserialize("+name+",\""+jf.getTag()+"\");\n"); - } - cc.write(" bs_.set("+fIdx+");\n"); - } - cc.write(" a_.endRecord(*this,tag);\n"); - cc.write(" return;\n"); - cc.write("}\n"); - - cc.write("bool "+getCppFQName()+"::validate() const {\n"); - cc.write(" if (bs_.size() != bs_.count()) return false;\n"); - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - JType type = jf.getType(); - if (type instanceof JRecord) { - cc.write(" if (!"+jf.getName()+".validate()) return false;\n"); - } - } - cc.write(" return true;\n"); - cc.write("}\n"); - - cc.write("bool "+getCppFQName()+"::operator< (const "+getCppFQName()+"& peer_) const {\n"); - cc.write(" return (1\n"); - for (Iterator i = mFields.iterator(); i.hasNext();) { - JField jf = (JField) i.next(); - String name = jf.getName(); - cc.write(" && ("+name+" < peer_."+name+")\n"); - } - cc.write(" );\n"); - cc.write("}\n"); - - cc.write("bool "+getCppFQName()+"::operator== (const "+getCppFQName()+"& peer_) const {\n"); - cc.write(" return (1\n"); - for (Iterator i = mFields.iterator(); i.hasNext();) { - JField jf = (JField) i.next(); - String name = jf.getName(); - cc.write(" && ("+name+" == peer_."+name+")\n"); - } - cc.write(" );\n"); - cc.write("}\n"); - - cc.write("const ::std::string&"+getCppFQName()+"::type() const {\n"); - cc.write(" static const ::std::string type_(\""+mName+"\");\n"); - cc.write(" return type_;\n"); - cc.write("}\n"); - - cc.write("const ::std::string&"+getCppFQName()+"::signature() const {\n"); - cc.write(" static const ::std::string sig_(\""+getSignature()+"\");\n"); - cc.write(" return sig_;\n"); - cc.write("}\n"); - - } - - public void genJavaCode() throws IOException { - String pkg = getJavaPackage(); - String pkgpath = pkg.replaceAll("\\.", "/"); - File pkgdir = new File(pkgpath); - if (!pkgdir.exists()) { - // create the pkg directory - boolean ret = pkgdir.mkdirs(); - if (!ret) { - System.out.println("Cannnot create directory: "+pkgpath); - System.exit(1); - } - } else if (!pkgdir.isDirectory()) { - // not a directory - System.out.println(pkgpath+" is not a directory."); - System.exit(1); - } - File jfile = new File(pkgdir, getName()+".java"); - FileWriter jj = new FileWriter(jfile); - jj.write("// File generated by hadoop record compiler. Do not edit.\n"); - jj.write("package "+getJavaPackage()+";\n\n"); - jj.write("import com.yahoo.jute.*;\n"); - jj.write("public class "+getName()+" implements Record {\n"); - for (Iterator i = mFields.iterator(); i.hasNext();) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaDecl()); - } - jj.write(" public "+getName()+"() {\n"); - jj.write(" }\n"); - - jj.write(" public "+getName()+"(\n"); - int fIdx = 0; - int fLen = mFields.size(); - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaConstructorParam(jf.getName())); - jj.write((fLen-1 == fIdx)?"":",\n"); - } - jj.write(") {\n"); - fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaConstructorSet(jf.getName())); - } - jj.write(" }\n"); - fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaGetSet(fIdx)); - } - jj.write(" public void serialize(OutputArchive a_, String tag) throws java.io.IOException {\n"); - jj.write(" a_.startRecord(this,tag);\n"); - fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaWriteMethodName()); - } - jj.write(" a_.endRecord(this,tag);\n"); - jj.write(" }\n"); - - jj.write(" public void deserialize(InputArchive a_, String tag) throws java.io.IOException {\n"); - jj.write(" a_.startRecord(tag);\n"); - fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaReadMethodName()); - } - jj.write(" a_.endRecord(tag);\n"); - jj.write("}\n"); - - jj.write(" public String toString() {\n"); - jj.write(" try {\n"); - jj.write(" java.io.ByteArrayOutputStream s =\n"); - jj.write(" new java.io.ByteArrayOutputStream();\n"); - jj.write(" CsvOutputArchive a_ = \n"); - jj.write(" new CsvOutputArchive(s);\n"); - jj.write(" a_.startRecord(this,\"\");\n"); - fIdx = 0; - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaWriteMethodName()); - } - jj.write(" a_.endRecord(this,\"\");\n"); - jj.write(" return new String(s.toByteArray(), \"UTF-8\");\n"); - jj.write(" } catch (Throwable ex) {\n"); - jj.write(" ex.printStackTrace();\n"); - jj.write(" }\n"); - jj.write(" return \"ERROR\";\n"); - jj.write(" }\n"); - - jj.write(" public void write(java.io.DataOutput out) throws java.io.IOException {\n"); - jj.write(" BinaryOutputArchive archive = new BinaryOutputArchive(out);\n"); - jj.write(" serialize(archive, \"\");\n"); - jj.write(" }\n"); - - jj.write(" public void readFields(java.io.DataInput in) throws java.io.IOException {\n"); - jj.write(" BinaryInputArchive archive = new BinaryInputArchive(in);\n"); - jj.write(" deserialize(archive, \"\");\n"); - jj.write(" }\n"); - - jj.write(" public int compareTo (Object peer_) throws ClassCastException {\n"); - jj.write(" if (!(peer_ instanceof "+getName()+")) {\n"); - jj.write(" throw new ClassCastException(\"Comparing different types of records.\");\n"); - jj.write(" }\n"); - jj.write(" "+getName()+" peer = ("+getName()+") peer_;\n"); - jj.write(" int ret = 0;\n"); - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaCompareTo()); - jj.write(" if (ret != 0) return ret;\n"); - } - jj.write(" return ret;\n"); - jj.write(" }\n"); - - jj.write(" public boolean equals(Object peer_) {\n"); - jj.write(" if (!(peer_ instanceof "+getName()+")) {\n"); - jj.write(" return false;\n"); - jj.write(" }\n"); - jj.write(" if (peer_ == this) {\n"); - jj.write(" return true;\n"); - jj.write(" }\n"); - jj.write(" "+getName()+" peer = ("+getName()+") peer_;\n"); - jj.write(" boolean ret = false;\n"); - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaEquals()); - jj.write(" if (!ret) return ret;\n"); - } - jj.write(" return ret;\n"); - jj.write(" }\n"); - - jj.write(" public int hashCode() {\n"); - jj.write(" int result = 17;\n"); - jj.write(" int ret;\n"); - for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { - JField jf = (JField) i.next(); - jj.write(jf.genJavaHashCode()); - jj.write(" result = 37*result + ret;\n"); - } - jj.write(" return result;\n"); - jj.write(" }\n"); - jj.write(" public static String signature() {\n"); - jj.write(" return \""+getSignature()+"\";\n"); - jj.write(" }\n"); - - jj.write("}\n"); - - jj.close(); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JString.java b/zookeeper/java/src/com/yahoo/jute/compiler/JString.java deleted file mode 100755 index a4c07e817a4..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JString.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -/** - * - * @author Milind Bhandarkar - */ -public class JString extends JCompType { - - /** Creates a new instance of JString */ - public JString() { - super("char *", " ::std::string", "String", "String", "String"); - } - - public String getSignature() { - return "s"; - } - - public String genJavaReadWrapper(String fname, String tag, boolean decl) { - String ret = ""; - if (decl) { - ret = " String "+fname+";\n"; - } - return ret + " "+fname+"=a_.readString(\""+tag+"\");\n"; - } - - public String genJavaWriteWrapper(String fname, String tag) { - return " a_.writeString("+fname+",\""+tag+"\");\n"; - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JType.java b/zookeeper/java/src/com/yahoo/jute/compiler/JType.java deleted file mode 100755 index a8c115fadbd..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JType.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -/** - * Abstract Base class for all types supported by Hadoop Record I/O. - * - * @author Milind Bhandarkar - */ -abstract public class JType { - - private String mCName; - private String mCppName; - private String mJavaName; - private String mMethodSuffix; - private String mWrapper; - private String mUnwrapMethod; - - /** - * Creates a new instance of JType - */ - JType(String cname, String cppname, String javaname, String suffix, String wrapper, String unwrap) { - mCName = cname; - mCppName = cppname; - mJavaName = javaname; - mMethodSuffix = suffix; - mWrapper = wrapper; - mUnwrapMethod = unwrap; - } - - abstract String getSignature(); - - String genCppDecl(String fname) { - return " "+mCppName+" m"+fname+";\n"; - } - - String genCDecl(String name) { - return " " + mCName + " "+name+";\n"; - } - String genJavaDecl (String fname) { - return " private "+mJavaName+" " +fname+";\n"; - } - - String genJavaConstructorParam (String fname) { - return " "+mJavaName+" "+fname; - } - - String genCppGetSet(String fname, int fIdx) { - String getFunc = " virtual "+mCppName+" get"+fname+"() const {\n"; - getFunc += " return m"+fname+";\n"; - getFunc += " }\n"; - String setFunc = " virtual void set"+fname+"("+mCppName+" m_) {\n"; - setFunc += " m"+fname+"=m_; bs_.set("+fIdx+");\n"; - setFunc += " }\n"; - return getFunc+setFunc; - } - - static String capitalize(String s) { - return s.substring(0,1).toUpperCase()+s.substring(1); - } - String genJavaGetSet(String fname, int fIdx) { - String getFunc = " public "+mJavaName+" get"+capitalize(fname)+"() {\n"; - getFunc += " return "+fname+";\n"; - getFunc += " }\n"; - String setFunc = " public void set"+capitalize(fname)+"("+mJavaName+" m_) {\n"; - setFunc += " " + fname+"=m_;\n"; - setFunc += " }\n"; - return getFunc+setFunc; - } - - String getCType() { - return mCName; - } - String getCppType() { - return mCppName; - } - - String getJavaType() { - return mJavaName; - } - - String getJavaWrapperType() { - return mWrapper; - } - - String getMethodSuffix() { - return mMethodSuffix; - } - - String genJavaWriteMethod(String fname, String tag) { - return " a_.write"+mMethodSuffix+"("+fname+",\""+tag+"\");\n"; - } - - String genJavaReadMethod(String fname, String tag) { - return " "+fname+"=a_.read"+mMethodSuffix+"(\""+tag+"\");\n"; - } - - String genJavaReadWrapper(String fname, String tag, boolean decl) { - String ret = ""; - if (decl) { - ret = " "+mWrapper+" "+fname+";\n"; - } - return ret + " "+fname+"=new "+mWrapper+"(a_.read"+mMethodSuffix+"(\""+tag+"\"));\n"; - } - - String genJavaWriteWrapper(String fname, String tag) { - return " a_.write"+mMethodSuffix+"("+fname+"."+mUnwrapMethod+"(),\""+tag+"\");\n"; - } - - String genJavaCompareTo(String fname) { - return " ret = ("+fname+" == peer."+fname+")? 0 :(("+fname+"", "java.util.ArrayList", "Vector", "java.util.ArrayList"); - mElement = t; - } - - public String getSignature() { - return "[" + mElement.getSignature() + "]"; - } - - public String genJavaCompareTo(String fname) { - return ""; - } - - public String genJavaReadWrapper(String fname, String tag, boolean decl) { - StringBuffer ret = new StringBuffer(""); - if (decl) { - ret.append(" java.util.ArrayList "+fname+";\n"); - } - ret.append(" {\n"); - incrLevel(); - ret.append(" Index "+getId("vidx")+" = a_.startVector(\""+tag+"\");\n"); - ret.append(" if ("+getId("vidx")+"!= null) {"); - ret.append(" "+fname+"=new java.util.ArrayList();\n"); - ret.append(" for (; !"+getId("vidx")+".done(); "+getId("vidx")+".incr()) {\n"); - ret.append(mElement.genJavaReadWrapper(getId("e"), getId("e"), true)); - ret.append(" "+fname+".add("+getId("e")+");\n"); - ret.append(" }\n"); - ret.append(" }\n"); - ret.append(" a_.endVector(\""+tag+"\");\n"); - decrLevel(); - ret.append(" }\n"); - return ret.toString(); - } - - public String genJavaReadMethod(String fname, String tag) { - return genJavaReadWrapper(fname, tag, false); - } - - public String genJavaWriteWrapper(String fname, String tag) { - StringBuffer ret = new StringBuffer(" {\n"); - incrLevel(); - ret.append(" a_.startVector("+fname+",\""+tag+"\");\n"); - ret.append(" if ("+fname+"!= null) {"); - ret.append(" int "+getId("len")+" = "+fname+".size();\n"); - ret.append(" for(int "+getId("vidx")+" = 0; "+getId("vidx")+"<"+getId("len")+"; "+getId("vidx")+"++) {\n"); - ret.append(" "+mElement.getJavaWrapperType()+" "+getId("e")+" = ("+mElement.getJavaWrapperType()+") "+fname+".get("+getId("vidx")+");\n"); - ret.append(mElement.genJavaWriteWrapper(getId("e"), getId("e"))); - ret.append(" }\n"); - ret.append(" }\n"); - ret.append(" a_.endVector("+fname+",\""+tag+"\");\n"); - ret.append(" }\n"); - decrLevel(); - return ret.toString(); - } - - public String genJavaWriteMethod(String fname, String tag) { - return genJavaWriteWrapper(fname, tag); - } - - public JType getElementType() { - return mElement; - } - - static public String extractVectorName(JType jvType) { - return JRecord.extractMethodSuffix(jvType)+"_vector"; - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/JavaGenerator.java b/zookeeper/java/src/com/yahoo/jute/compiler/JavaGenerator.java deleted file mode 100755 index 7dbcb6e5418..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/JavaGenerator.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler; - -import java.util.ArrayList; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; - -/** - * Java Code generator front-end for Hadoop record I/O. - * - * @author Milind Bhandarkar - */ -class JavaGenerator { - private String mName; - private ArrayList mInclFiles; - private ArrayList mRecList; - - /** Creates a new instance of JavaGenerator - * - * @param name possibly full pathname to the file - * @param incl included files (as JFile) - * @param records List of records defined within this file - */ - JavaGenerator(String name, ArrayList incl, ArrayList records) { - mName = name; - mInclFiles = incl; - mRecList = records; - } - - /** - * Generate Java code for records. This method is only a front-end to - * JRecord, since one file is generated for each record. - */ - void genCode() throws IOException { - for (Iterator i = mRecList.iterator(); i.hasNext(); ) { - JRecord rec = (JRecord) i.next(); - rec.genJavaCode(); - } - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/ParseException.java b/zookeeper/java/src/com/yahoo/jute/compiler/generated/ParseException.java deleted file mode 100755 index c7bfa6894e3..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/ParseException.java +++ /dev/null @@ -1,210 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler.generated; - -/** - * This exception is thrown when parse errors are encountered. - * You can explicitly create objects of this exception type by - * calling the method generateParseException in the generated - * parser. - * - * You can modify this class to customize your error reporting - * mechanisms so long as you retain the public fields. - */ -public class ParseException extends Exception { - - /** - * This constructor is used by the method "generateParseException" - * in the generated parser. Calling this constructor generates - * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. The boolean - * flag "specialConstructor" is also set to true to indicate that - * this constructor was used to create this object. - * This constructor calls its super class with the empty string - * to force the "toString" method of parent class "Throwable" to - * print the error message in the form: - * ParseException: - */ - public ParseException(Token currentTokenVal, - int[][] expectedTokenSequencesVal, - String[] tokenImageVal - ) - { - super(""); - specialConstructor = true; - currentToken = currentTokenVal; - expectedTokenSequences = expectedTokenSequencesVal; - tokenImage = tokenImageVal; - } - - /** - * The following constructors are for use by you for whatever - * purpose you can think of. Constructing the exception in this - * manner makes the exception behave in the normal way - i.e., as - * documented in the class "Throwable". The fields "errorToken", - * "expectedTokenSequences", and "tokenImage" do not contain - * relevant information. The JavaCC generated code does not use - * these constructors. - */ - - public ParseException() { - super(); - specialConstructor = false; - } - - public ParseException(String message) { - super(message); - specialConstructor = false; - } - - /** - * This variable determines which constructor was used to create - * this object and thereby affects the semantics of the - * "getMessage" method (see below). - */ - protected boolean specialConstructor; - - /** - * This is the last token that has been consumed successfully. If - * this object has been created due to a parse error, the token - * followng this token will (therefore) be the first error token. - */ - public Token currentToken; - - /** - * Each entry in this array is an array of integers. Each array - * of integers represents a sequence of tokens (by their ordinal - * values) that is expected at this point of the parse. - */ - public int[][] expectedTokenSequences; - - /** - * This is a reference to the "tokenImage" array of the generated - * parser within which the parse error occurred. This array is - * defined in the generated ...Constants interface. - */ - public String[] tokenImage; - - /** - * This method has the standard behavior when this object has been - * created using the standard constructors. Otherwise, it uses - * "currentToken" and "expectedTokenSequences" to generate a parse - * error message and returns it. If this object has been created - * due to a parse error, and you do not catch it (it gets thrown - * from the parser), then this method is called during the printing - * of the final stack trace, and hence the correct error message - * gets displayed. - */ - public String getMessage() { - if (!specialConstructor) { - return super.getMessage(); - } - StringBuffer expected = new StringBuffer(); - int maxSize = 0; - for (int i = 0; i < expectedTokenSequences.length; i++) { - if (maxSize < expectedTokenSequences[i].length) { - maxSize = expectedTokenSequences[i].length; - } - for (int j = 0; j < expectedTokenSequences[i].length; j++) { - expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" "); - } - if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { - expected.append("..."); - } - expected.append(eol).append(" "); - } - String retval = "Encountered \""; - Token tok = currentToken.next; - for (int i = 0; i < maxSize; i++) { - if (i != 0) retval += " "; - if (tok.kind == 0) { - retval += tokenImage[0]; - break; - } - retval += add_escapes(tok.image); - tok = tok.next; - } - retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; - retval += "." + eol; - if (expectedTokenSequences.length == 1) { - retval += "Was expecting:" + eol + " "; - } else { - retval += "Was expecting one of:" + eol + " "; - } - retval += expected.toString(); - return retval; - } - - /** - * The end of line string for this machine. - */ - protected String eol = System.getProperty("line.separator", "\n"); - - /** - * Used to convert raw characters to their escaped version - * when these raw version cannot be used as part of an ASCII - * string literal. - */ - protected String add_escapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); - } - -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/Rcc.java b/zookeeper/java/src/com/yahoo/jute/compiler/generated/Rcc.java deleted file mode 100755 index e7846324efd..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/Rcc.java +++ /dev/null @@ -1,519 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. Rcc.java */ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler.generated; - -import com.yahoo.jute.compiler.*; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.io.File; -import java.io.FileReader; -import java.io.FileNotFoundException; -import java.io.IOException; - -public class Rcc implements RccConstants { - private static String language = "java"; - private static ArrayList recFiles = new ArrayList(); - private static JFile curFile; - private static Hashtable recTab; - private static String curDir = System.getProperty("user.dir"); - private static String curFileName; - private static String curModuleName; - - public static void main(String args[]) { - for (int i=0; i= 0) { - la1tokens[jj_kind] = true; - jj_kind = -1; - } - for (int i = 0; i < 6; i++) { - if (jj_la1[i] == jj_gen) { - for (int j = 0; j < 32; j++) { - if ((jj_la1_0[i] & (1<", - "\" \"", - "\"\\t\"", - "\"\\n\"", - "\"\\r\"", - "\"//\"", - "", - "", - "\"/*\"", - "\"*/\"", - "", - "\"module\"", - "\"class\"", - "\"include\"", - "\"byte\"", - "\"boolean\"", - "\"int\"", - "\"long\"", - "\"float\"", - "\"double\"", - "\"ustring\"", - "\"buffer\"", - "\"vector\"", - "\"map\"", - "\"{\"", - "\"}\"", - "\"<\"", - "\">\"", - "\";\"", - "\",\"", - "\".\"", - "", - "", - }; - -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/RccTokenManager.java b/zookeeper/java/src/com/yahoo/jute/compiler/generated/RccTokenManager.java deleted file mode 100755 index a0fc1853c95..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/RccTokenManager.java +++ /dev/null @@ -1,833 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. RccTokenManager.java */ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler.generated; -import com.yahoo.jute.compiler.*; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.io.File; -import java.io.FileReader; -import java.io.FileNotFoundException; -import java.io.IOException; - -public class RccTokenManager implements RccConstants -{ - public java.io.PrintStream debugStream = System.out; - public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } -private final int jjMoveStringLiteralDfa0_1() -{ - return jjMoveNfa_1(0, 0); -} -private final void jjCheckNAdd(int state) -{ - if (jjrounds[state] != jjround) - { - jjstateSet[jjnewStateCnt++] = state; - jjrounds[state] = jjround; - } -} -private final void jjAddStates(int start, int end) -{ - do { - jjstateSet[jjnewStateCnt++] = jjnextStates[start]; - } while (start++ != end); -} -private final void jjCheckNAddTwoStates(int state1, int state2) -{ - jjCheckNAdd(state1); - jjCheckNAdd(state2); -} -private final void jjCheckNAddStates(int start, int end) -{ - do { - jjCheckNAdd(jjnextStates[start]); - } while (start++ != end); -} -private final void jjCheckNAddStates(int start) -{ - jjCheckNAdd(jjnextStates[start]); - jjCheckNAdd(jjnextStates[start + 1]); -} -private final int jjMoveNfa_1(int startState, int curPos) -{ - int[] nextStates; - int startsAt = 0; - jjnewStateCnt = 3; - int i = 1; - jjstateSet[0] = startState; - int j, kind = 0x7fffffff; - for (;;) - { - if (++jjround == 0x7fffffff) - ReInitRounds(); - if (curChar < 64) - { - long l = 1L << curChar; - MatchLoop: do - { - switch(jjstateSet[--i]) - { - case 0: - if ((0x2400L & l) != 0L) - { - if (kind > 6) - kind = 6; - } - if (curChar == 13) - jjstateSet[jjnewStateCnt++] = 1; - break; - case 1: - if (curChar == 10 && kind > 6) - kind = 6; - break; - case 2: - if (curChar == 13) - jjstateSet[jjnewStateCnt++] = 1; - break; - default : break; - } - } while(i != startsAt); - } - else if (curChar < 128) - { - long l = 1L << (curChar & 077); - MatchLoop: do - { - switch(jjstateSet[--i]) - { - default : break; - } - } while(i != startsAt); - } - else - { - int i2 = (curChar & 0xff) >> 6; - long l2 = 1L << (curChar & 077); - MatchLoop: do - { - switch(jjstateSet[--i]) - { - default : break; - } - } while(i != startsAt); - } - if (kind != 0x7fffffff) - { - jjmatchedKind = kind; - jjmatchedPos = curPos; - kind = 0x7fffffff; - } - ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt))) - return curPos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return curPos; } - } -} -private final int jjStopStringLiteralDfa_0(int pos, long active0) -{ - switch (pos) - { - case 0: - if ((active0 & 0xfff800L) != 0L) - { - jjmatchedKind = 32; - return 4; - } - return -1; - case 1: - if ((active0 & 0xfff800L) != 0L) - { - jjmatchedKind = 32; - jjmatchedPos = 1; - return 4; - } - return -1; - case 2: - if ((active0 & 0x7ef800L) != 0L) - { - jjmatchedKind = 32; - jjmatchedPos = 2; - return 4; - } - if ((active0 & 0x810000L) != 0L) - return 4; - return -1; - case 3: - if ((active0 & 0x24000L) != 0L) - return 4; - if ((active0 & 0x7cb800L) != 0L) - { - jjmatchedKind = 32; - jjmatchedPos = 3; - return 4; - } - return -1; - case 4: - if ((active0 & 0x41000L) != 0L) - return 4; - if ((active0 & 0x78a800L) != 0L) - { - jjmatchedKind = 32; - jjmatchedPos = 4; - return 4; - } - return -1; - case 5: - if ((active0 & 0x680800L) != 0L) - return 4; - if ((active0 & 0x10a000L) != 0L) - { - jjmatchedKind = 32; - jjmatchedPos = 5; - return 4; - } - return -1; - default : - return -1; - } -} -private final int jjStartNfa_0(int pos, long active0) -{ - return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); -} -private final int jjStopAtPos(int pos, int kind) -{ - jjmatchedKind = kind; - jjmatchedPos = pos; - return pos + 1; -} -private final int jjStartNfaWithStates_0(int pos, int kind, int state) -{ - jjmatchedKind = kind; - jjmatchedPos = pos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return pos + 1; } - return jjMoveNfa_0(state, pos + 1); -} -private final int jjMoveStringLiteralDfa0_0() -{ - switch(curChar) - { - case 44: - return jjStopAtPos(0, 29); - case 46: - return jjStopAtPos(0, 30); - case 47: - return jjMoveStringLiteralDfa1_0(0x120L); - case 59: - return jjStopAtPos(0, 28); - case 60: - return jjStopAtPos(0, 26); - case 62: - return jjStopAtPos(0, 27); - case 98: - return jjMoveStringLiteralDfa1_0(0x20c000L); - case 99: - return jjMoveStringLiteralDfa1_0(0x1000L); - case 100: - return jjMoveStringLiteralDfa1_0(0x80000L); - case 102: - return jjMoveStringLiteralDfa1_0(0x40000L); - case 105: - return jjMoveStringLiteralDfa1_0(0x12000L); - case 108: - return jjMoveStringLiteralDfa1_0(0x20000L); - case 109: - return jjMoveStringLiteralDfa1_0(0x800800L); - case 117: - return jjMoveStringLiteralDfa1_0(0x100000L); - case 118: - return jjMoveStringLiteralDfa1_0(0x400000L); - case 123: - return jjStopAtPos(0, 24); - case 125: - return jjStopAtPos(0, 25); - default : - return jjMoveNfa_0(0, 0); - } -} -private final int jjMoveStringLiteralDfa1_0(long active0) -{ - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(0, active0); - return 1; - } - switch(curChar) - { - case 42: - if ((active0 & 0x100L) != 0L) - return jjStopAtPos(1, 8); - break; - case 47: - if ((active0 & 0x20L) != 0L) - return jjStopAtPos(1, 5); - break; - case 97: - return jjMoveStringLiteralDfa2_0(active0, 0x800000L); - case 101: - return jjMoveStringLiteralDfa2_0(active0, 0x400000L); - case 108: - return jjMoveStringLiteralDfa2_0(active0, 0x41000L); - case 110: - return jjMoveStringLiteralDfa2_0(active0, 0x12000L); - case 111: - return jjMoveStringLiteralDfa2_0(active0, 0xa8800L); - case 115: - return jjMoveStringLiteralDfa2_0(active0, 0x100000L); - case 117: - return jjMoveStringLiteralDfa2_0(active0, 0x200000L); - case 121: - return jjMoveStringLiteralDfa2_0(active0, 0x4000L); - default : - break; - } - return jjStartNfa_0(0, active0); -} -private final int jjMoveStringLiteralDfa2_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(0, old0); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(1, active0); - return 2; - } - switch(curChar) - { - case 97: - return jjMoveStringLiteralDfa3_0(active0, 0x1000L); - case 99: - return jjMoveStringLiteralDfa3_0(active0, 0x402000L); - case 100: - return jjMoveStringLiteralDfa3_0(active0, 0x800L); - case 102: - return jjMoveStringLiteralDfa3_0(active0, 0x200000L); - case 110: - return jjMoveStringLiteralDfa3_0(active0, 0x20000L); - case 111: - return jjMoveStringLiteralDfa3_0(active0, 0x48000L); - case 112: - if ((active0 & 0x800000L) != 0L) - return jjStartNfaWithStates_0(2, 23, 4); - break; - case 116: - if ((active0 & 0x10000L) != 0L) - return jjStartNfaWithStates_0(2, 16, 4); - return jjMoveStringLiteralDfa3_0(active0, 0x104000L); - case 117: - return jjMoveStringLiteralDfa3_0(active0, 0x80000L); - default : - break; - } - return jjStartNfa_0(1, active0); -} -private final int jjMoveStringLiteralDfa3_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(1, old0); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(2, active0); - return 3; - } - switch(curChar) - { - case 97: - return jjMoveStringLiteralDfa4_0(active0, 0x40000L); - case 98: - return jjMoveStringLiteralDfa4_0(active0, 0x80000L); - case 101: - if ((active0 & 0x4000L) != 0L) - return jjStartNfaWithStates_0(3, 14, 4); - break; - case 102: - return jjMoveStringLiteralDfa4_0(active0, 0x200000L); - case 103: - if ((active0 & 0x20000L) != 0L) - return jjStartNfaWithStates_0(3, 17, 4); - break; - case 108: - return jjMoveStringLiteralDfa4_0(active0, 0xa000L); - case 114: - return jjMoveStringLiteralDfa4_0(active0, 0x100000L); - case 115: - return jjMoveStringLiteralDfa4_0(active0, 0x1000L); - case 116: - return jjMoveStringLiteralDfa4_0(active0, 0x400000L); - case 117: - return jjMoveStringLiteralDfa4_0(active0, 0x800L); - default : - break; - } - return jjStartNfa_0(2, active0); -} -private final int jjMoveStringLiteralDfa4_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(2, old0); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(3, active0); - return 4; - } - switch(curChar) - { - case 101: - return jjMoveStringLiteralDfa5_0(active0, 0x208000L); - case 105: - return jjMoveStringLiteralDfa5_0(active0, 0x100000L); - case 108: - return jjMoveStringLiteralDfa5_0(active0, 0x80800L); - case 111: - return jjMoveStringLiteralDfa5_0(active0, 0x400000L); - case 115: - if ((active0 & 0x1000L) != 0L) - return jjStartNfaWithStates_0(4, 12, 4); - break; - case 116: - if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(4, 18, 4); - break; - case 117: - return jjMoveStringLiteralDfa5_0(active0, 0x2000L); - default : - break; - } - return jjStartNfa_0(3, active0); -} -private final int jjMoveStringLiteralDfa5_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(3, old0); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(4, active0); - return 5; - } - switch(curChar) - { - case 97: - return jjMoveStringLiteralDfa6_0(active0, 0x8000L); - case 100: - return jjMoveStringLiteralDfa6_0(active0, 0x2000L); - case 101: - if ((active0 & 0x800L) != 0L) - return jjStartNfaWithStates_0(5, 11, 4); - else if ((active0 & 0x80000L) != 0L) - return jjStartNfaWithStates_0(5, 19, 4); - break; - case 110: - return jjMoveStringLiteralDfa6_0(active0, 0x100000L); - case 114: - if ((active0 & 0x200000L) != 0L) - return jjStartNfaWithStates_0(5, 21, 4); - else if ((active0 & 0x400000L) != 0L) - return jjStartNfaWithStates_0(5, 22, 4); - break; - default : - break; - } - return jjStartNfa_0(4, active0); -} -private final int jjMoveStringLiteralDfa6_0(long old0, long active0) -{ - if (((active0 &= old0)) == 0L) - return jjStartNfa_0(4, old0); - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - jjStopStringLiteralDfa_0(5, active0); - return 6; - } - switch(curChar) - { - case 101: - if ((active0 & 0x2000L) != 0L) - return jjStartNfaWithStates_0(6, 13, 4); - break; - case 103: - if ((active0 & 0x100000L) != 0L) - return jjStartNfaWithStates_0(6, 20, 4); - break; - case 110: - if ((active0 & 0x8000L) != 0L) - return jjStartNfaWithStates_0(6, 15, 4); - break; - default : - break; - } - return jjStartNfa_0(5, active0); -} -static final long[] jjbitVec0 = { - 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL -}; -private final int jjMoveNfa_0(int startState, int curPos) -{ - int[] nextStates; - int startsAt = 0; - jjnewStateCnt = 5; - int i = 1; - jjstateSet[0] = startState; - int j, kind = 0x7fffffff; - for (;;) - { - if (++jjround == 0x7fffffff) - ReInitRounds(); - if (curChar < 64) - { - long l = 1L << curChar; - MatchLoop: do - { - switch(jjstateSet[--i]) - { - case 0: - if (curChar == 34) - jjCheckNAdd(1); - break; - case 1: - if ((0xfffffffbffffffffL & l) != 0L) - jjCheckNAddTwoStates(1, 2); - break; - case 2: - if (curChar == 34 && kind > 31) - kind = 31; - break; - case 4: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 32) - kind = 32; - jjstateSet[jjnewStateCnt++] = 4; - break; - default : break; - } - } while(i != startsAt); - } - else if (curChar < 128) - { - long l = 1L << (curChar & 077); - MatchLoop: do - { - switch(jjstateSet[--i]) - { - case 0: - if ((0x7fffffe07fffffeL & l) == 0L) - break; - if (kind > 32) - kind = 32; - jjCheckNAdd(4); - break; - case 1: - jjAddStates(0, 1); - break; - case 4: - if ((0x7fffffe87fffffeL & l) == 0L) - break; - if (kind > 32) - kind = 32; - jjCheckNAdd(4); - break; - default : break; - } - } while(i != startsAt); - } - else - { - int i2 = (curChar & 0xff) >> 6; - long l2 = 1L << (curChar & 077); - MatchLoop: do - { - switch(jjstateSet[--i]) - { - case 1: - if ((jjbitVec0[i2] & l2) != 0L) - jjAddStates(0, 1); - break; - default : break; - } - } while(i != startsAt); - } - if (kind != 0x7fffffff) - { - jjmatchedKind = kind; - jjmatchedPos = curPos; - kind = 0x7fffffff; - } - ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 5 - (jjnewStateCnt = startsAt))) - return curPos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return curPos; } - } -} -private final int jjMoveStringLiteralDfa0_2() -{ - switch(curChar) - { - case 42: - return jjMoveStringLiteralDfa1_2(0x200L); - default : - return 1; - } -} -private final int jjMoveStringLiteralDfa1_2(long active0) -{ - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { - return 1; - } - switch(curChar) - { - case 47: - if ((active0 & 0x200L) != 0L) - return jjStopAtPos(1, 9); - break; - default : - return 2; - } - return 2; -} -static final int[] jjnextStates = { - 1, 2, -}; -public static final String[] jjstrLiteralImages = { -"", null, null, null, null, null, null, null, null, null, null, -"\155\157\144\165\154\145", "\143\154\141\163\163", "\151\156\143\154\165\144\145", "\142\171\164\145", -"\142\157\157\154\145\141\156", "\151\156\164", "\154\157\156\147", "\146\154\157\141\164", -"\144\157\165\142\154\145", "\165\163\164\162\151\156\147", "\142\165\146\146\145\162", -"\166\145\143\164\157\162", "\155\141\160", "\173", "\175", "\74", "\76", "\73", "\54", "\56", null, null, }; -public static final String[] lexStateNames = { - "DEFAULT", - "WithinOneLineComment", - "WithinMultiLineComment", -}; -public static final int[] jjnewLexState = { - -1, -1, -1, -1, -1, 1, 0, -1, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -}; -static final long[] jjtoToken = { - 0x1fffff801L, -}; -static final long[] jjtoSkip = { - 0x37eL, -}; -static final long[] jjtoSpecial = { - 0x360L, -}; -static final long[] jjtoMore = { - 0x480L, -}; -protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[5]; -private final int[] jjstateSet = new int[10]; -StringBuffer image; -int jjimageLen; -int lengthOfMatch; -protected char curChar; -public RccTokenManager(SimpleCharStream stream){ - if (SimpleCharStream.staticFlag) - throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); - input_stream = stream; -} -public RccTokenManager(SimpleCharStream stream, int lexState){ - this(stream); - SwitchTo(lexState); -} -public void ReInit(SimpleCharStream stream) -{ - jjmatchedPos = jjnewStateCnt = 0; - curLexState = defaultLexState; - input_stream = stream; - ReInitRounds(); -} -private final void ReInitRounds() -{ - int i; - jjround = 0x80000001; - for (i = 5; i-- > 0;) - jjrounds[i] = 0x80000000; -} -public void ReInit(SimpleCharStream stream, int lexState) -{ - ReInit(stream); - SwitchTo(lexState); -} -public void SwitchTo(int lexState) -{ - if (lexState >= 3 || lexState < 0) - throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); - else - curLexState = lexState; -} - -protected Token jjFillToken() -{ - Token t = Token.newToken(jjmatchedKind); - t.kind = jjmatchedKind; - String im = jjstrLiteralImages[jjmatchedKind]; - t.image = (im == null) ? input_stream.GetImage() : im; - t.beginLine = input_stream.getBeginLine(); - t.beginColumn = input_stream.getBeginColumn(); - t.endLine = input_stream.getEndLine(); - t.endColumn = input_stream.getEndColumn(); - return t; -} - -int curLexState = 0; -int defaultLexState = 0; -int jjnewStateCnt; -int jjround; -int jjmatchedPos; -int jjmatchedKind; - -public Token getNextToken() -{ - int kind; - Token specialToken = null; - Token matchedToken; - int curPos = 0; - - EOFLoop : - for (;;) - { - try - { - curChar = input_stream.BeginToken(); - } - catch(java.io.IOException e) - { - jjmatchedKind = 0; - matchedToken = jjFillToken(); - matchedToken.specialToken = specialToken; - return matchedToken; - } - image = null; - jjimageLen = 0; - - for (;;) - { - switch(curLexState) - { - case 0: - try { input_stream.backup(0); - while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) - curChar = input_stream.BeginToken(); - } - catch (java.io.IOException e1) { continue EOFLoop; } - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_0(); - break; - case 1: - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_1(); - if (jjmatchedPos == 0 && jjmatchedKind > 7) - { - jjmatchedKind = 7; - } - break; - case 2: - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_2(); - if (jjmatchedPos == 0 && jjmatchedKind > 10) - { - jjmatchedKind = 10; - } - break; - } - if (jjmatchedKind != 0x7fffffff) - { - if (jjmatchedPos + 1 < curPos) - input_stream.backup(curPos - jjmatchedPos - 1); - if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) - { - matchedToken = jjFillToken(); - matchedToken.specialToken = specialToken; - if (jjnewLexState[jjmatchedKind] != -1) - curLexState = jjnewLexState[jjmatchedKind]; - return matchedToken; - } - else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) - { - if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) - { - matchedToken = jjFillToken(); - if (specialToken == null) - specialToken = matchedToken; - else - { - matchedToken.specialToken = specialToken; - specialToken = (specialToken.next = matchedToken); - } - SkipLexicalActions(matchedToken); - } - else - SkipLexicalActions(null); - if (jjnewLexState[jjmatchedKind] != -1) - curLexState = jjnewLexState[jjmatchedKind]; - continue EOFLoop; - } - jjimageLen += jjmatchedPos + 1; - if (jjnewLexState[jjmatchedKind] != -1) - curLexState = jjnewLexState[jjmatchedKind]; - curPos = 0; - jjmatchedKind = 0x7fffffff; - try { - curChar = input_stream.readChar(); - continue; - } - catch (java.io.IOException e1) { } - } - int error_line = input_stream.getEndLine(); - int error_column = input_stream.getEndColumn(); - String error_after = null; - boolean EOFSeen = false; - try { input_stream.readChar(); input_stream.backup(1); } - catch (java.io.IOException e1) { - EOFSeen = true; - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - if (curChar == '\n' || curChar == '\r') { - error_line++; - error_column = 0; - } - else - error_column++; - } - if (!EOFSeen) { - input_stream.backup(1); - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - } - throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); - } - } -} - -void SkipLexicalActions(Token matchedToken) -{ - switch(jjmatchedKind) - { - default : - break; - } -} -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/SimpleCharStream.java b/zookeeper/java/src/com/yahoo/jute/compiler/generated/SimpleCharStream.java deleted file mode 100755 index 0f09093037a..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/SimpleCharStream.java +++ /dev/null @@ -1,457 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler.generated; - -/** - * An implementation of interface CharStream, where the stream is assumed to - * contain only ASCII characters (without unicode processing). - */ - -public class SimpleCharStream -{ - public static final boolean staticFlag = false; - int bufsize; - int available; - int tokenBegin; - public int bufpos = -1; - protected int bufline[]; - protected int bufcolumn[]; - - protected int column = 0; - protected int line = 1; - - protected boolean prevCharIsCR = false; - protected boolean prevCharIsLF = false; - - protected java.io.Reader inputStream; - - protected char[] buffer; - protected int maxNextCharInd = 0; - protected int inBuf = 0; - protected int tabSize = 8; - - protected void setTabSize(int i) { tabSize = i; } - protected int getTabSize(int i) { return tabSize; } - - - protected void ExpandBuff(boolean wrapAround) - { - char[] newbuffer = new char[bufsize + 2048]; - int newbufline[] = new int[bufsize + 2048]; - int newbufcolumn[] = new int[bufsize + 2048]; - - try - { - if (wrapAround) - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - System.arraycopy(buffer, 0, newbuffer, - bufsize - tokenBegin, bufpos); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos += (bufsize - tokenBegin)); - } - else - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos -= tokenBegin); - } - } - catch (Throwable t) - { - throw new Error(t.getMessage()); - } - - - bufsize += 2048; - available = bufsize; - tokenBegin = 0; - } - - protected void FillBuff() throws java.io.IOException - { - if (maxNextCharInd == available) - { - if (available == bufsize) - { - if (tokenBegin > 2048) - { - bufpos = maxNextCharInd = 0; - available = tokenBegin; - } - else if (tokenBegin < 0) - bufpos = maxNextCharInd = 0; - else - ExpandBuff(false); - } - else if (available > tokenBegin) - available = bufsize; - else if ((tokenBegin - available) < 2048) - ExpandBuff(true); - else - available = tokenBegin; - } - - int i; - try { - if ((i = inputStream.read(buffer, maxNextCharInd, - available - maxNextCharInd)) == -1) - { - inputStream.close(); - throw new java.io.IOException(); - } - else - maxNextCharInd += i; - return; - } - catch(java.io.IOException e) { - --bufpos; - backup(0); - if (tokenBegin == -1) - tokenBegin = bufpos; - throw e; - } - } - - public char BeginToken() throws java.io.IOException - { - tokenBegin = -1; - char c = readChar(); - tokenBegin = bufpos; - - return c; - } - - protected void UpdateLineColumn(char c) - { - column++; - - if (prevCharIsLF) - { - prevCharIsLF = false; - line += (column = 1); - } - else if (prevCharIsCR) - { - prevCharIsCR = false; - if (c == '\n') - { - prevCharIsLF = true; - } - else - line += (column = 1); - } - - switch (c) - { - case '\r' : - prevCharIsCR = true; - break; - case '\n' : - prevCharIsLF = true; - break; - case '\t' : - column--; - column += (tabSize - (column % tabSize)); - break; - default : - break; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; - } - - public char readChar() throws java.io.IOException - { - if (inBuf > 0) - { - --inBuf; - - if (++bufpos == bufsize) - bufpos = 0; - - return buffer[bufpos]; - } - - if (++bufpos >= maxNextCharInd) - FillBuff(); - - char c = buffer[bufpos]; - - UpdateLineColumn(c); - return (c); - } - - /** - * @deprecated - * @see #getEndColumn - */ - - public int getColumn() { - return bufcolumn[bufpos]; - } - - /** - * @deprecated - * @see #getEndLine - */ - - public int getLine() { - return bufline[bufpos]; - } - - public int getEndColumn() { - return bufcolumn[bufpos]; - } - - public int getEndLine() { - return bufline[bufpos]; - } - - public int getBeginColumn() { - return bufcolumn[tokenBegin]; - } - - public int getBeginLine() { - return bufline[tokenBegin]; - } - - public void backup(int amount) { - - inBuf += amount; - if ((bufpos -= amount) < 0) - bufpos += bufsize; - } - - public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) - { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - } - - public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn) - { - this(dstream, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.Reader dstream) - { - this(dstream, 1, 1, 4096); - } - public void ReInit(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) - { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - if (buffer == null || buffersize != buffer.length) - { - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - } - prevCharIsLF = prevCharIsCR = false; - tokenBegin = inBuf = maxNextCharInd = 0; - bufpos = -1; - } - - public void ReInit(java.io.Reader dstream, int startline, - int startcolumn) - { - ReInit(dstream, startline, startcolumn, 4096); - } - - public void ReInit(java.io.Reader dstream) - { - ReInit(dstream, 1, 1, 4096); - } - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException - { - this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) - { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException - { - this(dstream, encoding, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn) - { - this(dstream, startline, startcolumn, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException - { - this(dstream, encoding, 1, 1, 4096); - } - - public SimpleCharStream(java.io.InputStream dstream) - { - this(dstream, 1, 1, 4096); - } - - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException - { - ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) - { - ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException - { - ReInit(dstream, encoding, 1, 1, 4096); - } - - public void ReInit(java.io.InputStream dstream) - { - ReInit(dstream, 1, 1, 4096); - } - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException - { - ReInit(dstream, encoding, startline, startcolumn, 4096); - } - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn) - { - ReInit(dstream, startline, startcolumn, 4096); - } - public String GetImage() - { - if (bufpos >= tokenBegin) - return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); - else - return new String(buffer, tokenBegin, bufsize - tokenBegin) + - new String(buffer, 0, bufpos + 1); - } - - public char[] GetSuffix(int len) - { - char[] ret = new char[len]; - - if ((bufpos + 1) >= len) - System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); - else - { - System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, - len - bufpos - 1); - System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); - } - - return ret; - } - - public void Done() - { - buffer = null; - bufline = null; - bufcolumn = null; - } - - /** - * Method to adjust line and column numbers for the start of a token. - */ - public void adjustBeginLineColumn(int newLine, int newCol) - { - int start = tokenBegin; - int len; - - if (bufpos >= tokenBegin) - { - len = bufpos - tokenBegin + inBuf + 1; - } - else - { - len = bufsize - tokenBegin + bufpos + 1 + inBuf; - } - - int i = 0, j = 0, k = 0; - int nextColDiff = 0, columnDiff = 0; - - while (i < len && - bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) - { - bufline[j] = newLine; - nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; - bufcolumn[j] = newCol + columnDiff; - columnDiff = nextColDiff; - i++; - } - - if (i < len) - { - bufline[j] = newLine++; - bufcolumn[j] = newCol + columnDiff; - - while (i++ < len) - { - if (bufline[j = start % bufsize] != bufline[++start % bufsize]) - bufline[j] = newLine++; - else - bufline[j] = newLine; - } - } - - line = bufline[j]; - column = bufcolumn[j]; - } - -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/Token.java b/zookeeper/java/src/com/yahoo/jute/compiler/generated/Token.java deleted file mode 100755 index afb4ee70cff..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/Token.java +++ /dev/null @@ -1,99 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler.generated; - -/** - * Describes the input token stream. - */ - -public class Token { - - /** - * An integer that describes the kind of this token. This numbering - * system is determined by JavaCCParser, and a table of these numbers is - * stored in the file ...Constants.java. - */ - public int kind; - - /** - * beginLine and beginColumn describe the position of the first character - * of this token; endLine and endColumn describe the position of the - * last character of this token. - */ - public int beginLine, beginColumn, endLine, endColumn; - - /** - * The string image of the token. - */ - public String image; - - /** - * A reference to the next regular (non-special) token from the input - * stream. If this is the last token from the input stream, or if the - * token manager has not read tokens beyond this one, this field is - * set to null. This is true only if this token is also a regular - * token. Otherwise, see below for a description of the contents of - * this field. - */ - public Token next; - - /** - * This field is used to access special tokens that occur prior to this - * token, but after the immediately preceding regular (non-special) token. - * If there are no such special tokens, this field is set to null. - * When there are more than one such special token, this field refers - * to the last of these special tokens, which in turn refers to the next - * previous special token through its specialToken field, and so on - * until the first special token (whose specialToken field is null). - * The next fields of special tokens refer to other special tokens that - * immediately follow it (without an intervening regular token). If there - * is no such token, this field is null. - */ - public Token specialToken; - - /** - * Returns the image. - */ - public String toString() - { - return image; - } - - /** - * Returns a new Token object, by default. However, if you want, you - * can create and return subclass objects based on the value of ofKind. - * Simply add the cases to the switch for all those special cases. - * For example, if you have a subclass of Token called IDToken that - * you want to create if ofKind is ID, simlpy add something like : - * - * case MyParserConstants.ID : return new IDToken(); - * - * to the following switch statement. Then you can cast matchedToken - * variable to the appropriate type and use it in your lexical actions. - */ - public static final Token newToken(int ofKind) - { - switch(ofKind) - { - default : return new Token(); - } - } - -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/TokenMgrError.java b/zookeeper/java/src/com/yahoo/jute/compiler/generated/TokenMgrError.java deleted file mode 100755 index 4cde5d30dd9..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/TokenMgrError.java +++ /dev/null @@ -1,151 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.jute.compiler.generated; - -public class TokenMgrError extends Error -{ - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - - /** - * Lexical error occured. - */ - static final int LEXICAL_ERROR = 0; - - /** - * An attempt wass made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; - - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; - - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; - - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; - - /** - * Replaces unprintable characters by their espaced (or unicode escaped) - * equivalents in the given string - */ - protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); - } - - /** - * Returns a detailed message for the Error when it is thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexicl error - * curLexState : lexical state in which this error occured - * errorLine : line number when the error occured - * errorColumn : column number when the error occured - * errorAfter : prefix that was seen before this error occured - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); - } - - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - public String getMessage() { - return super.getMessage(); - } - - /* - * Constructors of various flavors follow. - */ - - public TokenMgrError() { - } - - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } - - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } -} diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/generated/package.html b/zookeeper/java/src/com/yahoo/jute/compiler/generated/package.html deleted file mode 100755 index c5865081e17..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/generated/package.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - Hadoop Record Compiler: Parser - - - This package contains code generated by JavaCC from the - Hadoop record syntax file rcc.jj. For details about the - record file syntax please @see org.apache.hadoop.record. - - diff --git a/zookeeper/java/src/com/yahoo/jute/compiler/package.html b/zookeeper/java/src/com/yahoo/jute/compiler/package.html deleted file mode 100755 index 537fb719136..00000000000 --- a/zookeeper/java/src/com/yahoo/jute/compiler/package.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - Hadoop Record Compiler - - - This package contains classes needed for code generation - from the hadoop record compiler. CppGenerator and JavaGenerator - are the main entry points from the parser. There are classes - corrsponding to every primitive type and compound type - included in Hadoop record I/O syntax. - - diff --git a/zookeeper/java/src/com/yahoo/zookeeper/AsyncCallback.java b/zookeeper/java/src/com/yahoo/zookeeper/AsyncCallback.java deleted file mode 100644 index 0a0f48bbf79..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/AsyncCallback.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.yahoo.zookeeper; - -import java.util.ArrayList; - -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Stat; - -public interface AsyncCallback { - interface StatCallback extends AsyncCallback { - public void processResult(int rc, String path, Object ctx, Stat stat); - } - - interface DataCallback extends AsyncCallback { - public void processResult(int rc, String path, Object ctx, byte data[], - Stat stat); - } - - interface ACLCallback extends AsyncCallback { - public void processResult(int rc, String path, Object ctx, - ArrayList acl, Stat stat); - } - - interface ChildrenCallback extends AsyncCallback { - public void processResult(int rc, String path, Object ctx, - ArrayList children); - } - - interface StringCallback extends AsyncCallback { - public void processResult(int rc, String path, Object ctx, String name); - } - - interface VoidCallback extends AsyncCallback { - public void processResult(int rc, String path, Object ctx); - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/ClientCnxn.java b/zookeeper/java/src/com/yahoo/zookeeper/ClientCnxn.java deleted file mode 100755 index c7ce90e515f..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/ClientCnxn.java +++ /dev/null @@ -1,804 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.SocketChannel; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.jute.BinaryInputArchive; -import com.yahoo.jute.BinaryOutputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.AsyncCallback.ACLCallback; -import com.yahoo.zookeeper.AsyncCallback.ChildrenCallback; -import com.yahoo.zookeeper.AsyncCallback.DataCallback; -import com.yahoo.zookeeper.AsyncCallback.StatCallback; -import com.yahoo.zookeeper.AsyncCallback.StringCallback; -import com.yahoo.zookeeper.AsyncCallback.VoidCallback; -import com.yahoo.zookeeper.Watcher.Event; -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.ZooKeeper.States; -import com.yahoo.zookeeper.proto.AuthPacket; -import com.yahoo.zookeeper.proto.ConnectRequest; -import com.yahoo.zookeeper.proto.ConnectResponse; -import com.yahoo.zookeeper.proto.CreateResponse; -import com.yahoo.zookeeper.proto.ExistsResponse; -import com.yahoo.zookeeper.proto.GetACLResponse; -import com.yahoo.zookeeper.proto.GetChildrenResponse; -import com.yahoo.zookeeper.proto.GetDataResponse; -import com.yahoo.zookeeper.proto.ReplyHeader; -import com.yahoo.zookeeper.proto.RequestHeader; -import com.yahoo.zookeeper.proto.SetACLResponse; -import com.yahoo.zookeeper.proto.SetDataResponse; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.ByteBufferInputStream; -import com.yahoo.zookeeper.server.ZooLog; - -/** - * This class manages the socket i/o for the client. ClientCnxn maintains a list - * of available servers to connect to and "transparently" switches servers it is - * connected to as needed. - * - */ -public class ClientCnxn { - private ArrayList serverAddrs = new ArrayList(); - - static class AuthData { - AuthData(String scheme, byte data[]) { - this.scheme = scheme; - this.data = data; - } - - String scheme; - - byte data[]; - } - - private ArrayList authInfo = new ArrayList(); - - /** - * These are the packets that have been sent and are waiting for a response. - */ - private LinkedList pendingQueue = new LinkedList(); - - private LinkedBlockingQueue waitingEvents = new LinkedBlockingQueue(); - - /** - * These are the packets that need to be sent. - */ - private LinkedList outgoingQueue = new LinkedList(); - - private int nextAddrToTry = 0; - - private int connectTimeout; - - private int readTimeout; - - private int sessionTimeout; - - private int timeout; - - private ZooKeeper zooKeeper; - - private long sessionId; - - private byte sessionPasswd[] = new byte[16]; - - SendThread sendThread; - - EventThread eventThread; - - Selector selector = Selector.open(); - - public long getSessionId() { - return sessionId; - } - - public byte[] getSessionPasswd() { - return sessionPasswd; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("sessionId: ").append(sessionId).append("\n"); - sb.append("lastZxid: ").append(lastZxid).append("\n"); - sb.append("xid: ").append(xid).append("\n"); - sb.append("nextAddrToTry: ").append(nextAddrToTry).append("\n"); - sb.append("serverAddrs: ").append(serverAddrs.get(nextAddrToTry)) - .append("\n"); - return sb.toString(); - } - - /** - * This class allows us to pass the headers and the relevant records around. - */ - static class Packet { - RequestHeader header; - - ByteBuffer bb; - - String path; - - ReplyHeader replyHeader; - - Record request; - - Record response; - - boolean finished; - - AsyncCallback cb; - - Object ctx; - - Packet(RequestHeader header, ReplyHeader replyHeader, Record record, - Record response, ByteBuffer bb) { - this.header = header; - this.replyHeader = replyHeader; - this.request = record; - this.response = response; - if (bb != null) { - this.bb = bb; - } else { - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - BinaryOutputArchive boa = BinaryOutputArchive - .getArchive(baos); - boa.writeInt(-1, "len"); // We'll fill this in later - header.serialize(boa, "header"); - if (record != null) { - record.serialize(boa, "request"); - } - baos.close(); - this.bb = ByteBuffer.wrap(baos.toByteArray()); - this.bb.putInt(this.bb.capacity() - 4); - this.bb.rewind(); - } catch (IOException e) { - ZooLog.logException(e, "this should be impossible!"); - } - } - } - } - - public ClientCnxn(String hosts, int sessionTimeout, ZooKeeper zooKeeper) - throws KeeperException, IOException { - this(hosts, sessionTimeout, zooKeeper, 0, new byte[16]); - } - - /** - * Creates a connection object. The actual network connect doesn't get - * established until needed. - * - * @param hosts - * a comma separated list of hosts that can be connected to. - * @param connectTimeout - * the timeout for connections. - * @param readTimeout - * the read timeout. - * @param zooKeeper - * the zookeeper object that this connection is related to. - * @throws KeeperException - * @throws IOException - */ - public ClientCnxn(String hosts, int sessionTimeout, ZooKeeper zooKeeper, - long sessionId, byte[] sessionPasswd) throws KeeperException, - IOException { - this.zooKeeper = zooKeeper; - this.sessionId = sessionId; - this.sessionPasswd = sessionPasswd; - String hostsList[] = hosts.split(","); - for (String host : hostsList) { - int port = 2181; - String parts[] = host.split(":"); - if (parts.length > 1) { - port = Integer.parseInt(parts[1]); - host = parts[0]; - } - InetAddress addrs[] = InetAddress.getAllByName(host); - for (InetAddress addr : addrs) { - serverAddrs.add(new InetSocketAddress(addr, port)); - } - } - this.sessionTimeout = sessionTimeout; - connectTimeout = sessionTimeout / hostsList.length; - readTimeout = sessionTimeout * 2 / 3; - Collections.shuffle(serverAddrs); - sendThread = new SendThread(); - sendThread.start(); - eventThread = new EventThread(); - eventThread.start(); - } - - WatcherEvent eventOfDeath = new WatcherEvent(); - - class EventThread extends Thread { - EventThread() { - super("EventThread"); - setDaemon(true); - } - - public void run() { - try { - while (true) { - Object event = waitingEvents.take(); - if (event == eventOfDeath) { - break; - } - if (event instanceof WatcherEvent) { - zooKeeper.watcher.process((WatcherEvent) event); - } else { - Packet p = (Packet) event; - int rc = 0; - String path = p.path; - if (p.replyHeader.getErr() != 0) { - rc = p.replyHeader.getErr(); - } - if (p.cb == null) { - ZooLog - .logError("Somehow a null cb got to EventThread!"); - } else if (p.response instanceof ExistsResponse - || p.response instanceof SetDataResponse - || p.response instanceof SetACLResponse) { - StatCallback cb = (StatCallback) p.cb; - if (rc == 0) { - if (p.response instanceof ExistsResponse) { - cb.processResult(rc, path, p.ctx, - ((ExistsResponse) p.response) - .getStat()); - } else if (p.response instanceof SetDataResponse) { - cb.processResult(rc, path, p.ctx, - ((SetDataResponse) p.response) - .getStat()); - } else if (p.response instanceof SetACLResponse) { - cb.processResult(rc, path, p.ctx, - ((SetACLResponse) p.response) - .getStat()); - } - } else { - cb.processResult(rc, path, p.ctx, null); - } - } else if (p.response instanceof GetDataResponse) { - DataCallback cb = (DataCallback) p.cb; - GetDataResponse rsp = (GetDataResponse) p.response; - if (rc == 0) { - cb.processResult(rc, path, p.ctx, - rsp.getData(), rsp.getStat()); - } else { - cb.processResult(rc, path, p.ctx, null, null); - } - } else if (p.response instanceof GetACLResponse) { - ACLCallback cb = (ACLCallback) p.cb; - GetACLResponse rsp = (GetACLResponse) p.response; - if (rc == 0) { - cb.processResult(rc, path, p.ctx, rsp.getAcl(), - rsp.getStat()); - } else { - cb.processResult(rc, path, p.ctx, null, null); - } - } else if (p.response instanceof GetChildrenResponse) { - ChildrenCallback cb = (ChildrenCallback) p.cb; - GetChildrenResponse rsp = (GetChildrenResponse) p.response; - if (rc == 0) { - cb.processResult(rc, path, p.ctx, rsp - .getChildren()); - } else { - cb.processResult(rc, path, p.ctx, null); - } - } else if (p.response instanceof CreateResponse) { - StringCallback cb = (StringCallback) p.cb; - CreateResponse rsp = (CreateResponse) p.response; - if (rc == 0) { - cb - .processResult(rc, path, p.ctx, rsp - .getPath()); - } else { - cb.processResult(rc, path, p.ctx, null); - } - } else if (p.cb instanceof VoidCallback) { - VoidCallback cb = (VoidCallback) p.cb; - cb.processResult(rc, path, p.ctx); - } - } - } - } catch (InterruptedException e) { - } - } - } - - long lastZxid; - - /** - * This class services the outgoing request queue and generates the heart - * beats. It also spawns the ReadThread. - */ - class SendThread extends Thread { - SelectionKey sockKey; - - ByteBuffer lenBuffer = ByteBuffer.allocateDirect(4); - - ByteBuffer incomingBuffer = lenBuffer; - - boolean initialized; - - void readLength() throws IOException { - int len = incomingBuffer.getInt(); - if (len < 0 || len >= 4096 * 1024) { - throw new IOException("Packet len" + len + " is out of range!"); - } - incomingBuffer = ByteBuffer.allocate(len); - } - - void readConnectResult() throws IOException { - ByteBufferInputStream bbis = new ByteBufferInputStream( - incomingBuffer); - BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis); - ConnectResponse conRsp = new ConnectResponse(); - conRsp.deserialize(bbia, "connect"); - int sessionTimeout = conRsp.getTimeOut(); - if (sessionTimeout <= 0) { - running = false; - waitingEvents.add(new WatcherEvent(Watcher.Event.EventNone, - Watcher.Event.KeeperStateExpired, null)); - throw new IOException("Connect failed"); - } - readTimeout = sessionTimeout * 2 / 3; - connectTimeout = sessionTimeout / serverAddrs.size(); - timeout = readTimeout / 2; - sessionId = conRsp.getSessionId(); - sessionPasswd = conRsp.getPasswd(); - waitingEvents.add(new WatcherEvent(Watcher.Event.EventNone, - Watcher.Event.KeeperStateSyncConnected, null)); - } - - @SuppressWarnings("unchecked") - void readResponse() throws IOException { - timeout = readTimeout / 2; - ByteBufferInputStream bbis = new ByteBufferInputStream( - incomingBuffer); - BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis); - ReplyHeader r = new ReplyHeader(); - - r.deserialize(bbia, "header"); - if (r.getXid() == -2) { - // -2 is the xid for pings - return; - } - if (r.getXid() == -4) { - // -2 is the xid for AuthPacket - // TODO: process AuthPacket here - return; - } - if (r.getXid() == -1) { - // -1 means notification - WatcherEvent event = new WatcherEvent(); - event.deserialize(bbia, "response"); - // System.out.println("Got an event: " + event + " for " + - // sessionId + " through" + _cnxn); - waitingEvents.add(event); - return; - } - if (pendingQueue.size() == 0) { - throw new IOException("Nothing in the queue, but got " - + r.getXid()); - } - Packet p = pendingQueue.remove(); - /* - * Since requests are processed in order, we better get a response - * to the first request! - */ - if (p.header.getXid() != r.getXid()) { - throw new IOException("Xid out of order. Got " + r.getXid() - + " expected " + p.header.getXid()); - } - p.replyHeader.setXid(r.getXid()); - p.replyHeader.setErr(r.getErr()); - p.replyHeader.setZxid(r.getZxid()); - lastZxid = r.getZxid(); - if (p.response != null && r.getErr() == 0) { - p.response.deserialize(bbia, "response"); - } - p.finished = true; - finishPacket(p); - } - - @SuppressWarnings("unchecked") - private void finishPacket(Packet p) { - p.finished = true; - if (p.cb == null) { - synchronized (p) { - p.notifyAll(); - } - } else { - waitingEvents.add(p); - } - } - - /** - * @return true if a packet was received - * @param k - * @throws InterruptedException - * @throws IOException - */ - boolean doIO() throws InterruptedException, IOException { - boolean packetReceived = false; - SocketChannel sock = (SocketChannel) sockKey.channel(); - if (sock == null) { - throw new IOException("Socket is null!"); - } - if (sockKey.isReadable()) { - int rc = sock.read(incomingBuffer); - if (rc < 0) { - throw new IOException("Read error rc = " + rc + " " - + incomingBuffer); - } - if (incomingBuffer.remaining() == 0) { - incomingBuffer.flip(); - if (incomingBuffer == lenBuffer) { - readLength(); - } else if (!initialized) { - readConnectResult(); - enableRead(); - if (outgoingQueue.size() > 0) { - enableWrite(); - } - lenBuffer.clear(); - incomingBuffer = lenBuffer; - packetReceived = true; - initialized = true; - } else { - readResponse(); - lenBuffer.clear(); - incomingBuffer = lenBuffer; - packetReceived = true; - } - } - } - if (sockKey.isWritable()) { - synchronized (outgoingQueue) { - if (outgoingQueue.size() > 0) { - int rc = sock.write(outgoingQueue.getFirst().bb); - if (outgoingQueue.getFirst().bb.remaining() == 0) { - Packet p = outgoingQueue.removeFirst(); - if (p.header != null - && p.header.getType() != OpCode.ping - && p.header.getType() != OpCode.auth) { - pendingQueue.add(p); - } - } - } - } - } - if (outgoingQueue.size() == 0) { - disableWrite(); - } else { - enableWrite(); - } - return packetReceived; - } - - synchronized private void enableWrite() { - int i = sockKey.interestOps(); - if ((i & SelectionKey.OP_WRITE) == 0) { - sockKey.interestOps(i | SelectionKey.OP_WRITE); - } - } - - synchronized private void disableWrite() { - int i = sockKey.interestOps(); - if ((i & SelectionKey.OP_WRITE) != 0) { - sockKey.interestOps(i & (~SelectionKey.OP_WRITE)); - } - } - - synchronized private void enableRead() { - int i = sockKey.interestOps(); - if ((i & SelectionKey.OP_READ) == 0) { - sockKey.interestOps(i | SelectionKey.OP_READ); - } - } - - synchronized private void disableRead() { - int i = sockKey.interestOps(); - if ((i & SelectionKey.OP_READ) != 0) { - sockKey.interestOps(i & (~SelectionKey.OP_READ)); - } - } - - boolean running = true; - - SendThread() { - super("SendThread"); - zooKeeper.state = States.CONNECTING; - setDaemon(true); - } - - private void primeConnection(SelectionKey k) throws IOException { - ZooLog.logWarn("Priming connection to " - + ((SocketChannel) sockKey.channel())); - lastConnectIndex = currentConnectIndex; - ConnectRequest conReq = new ConnectRequest(0, lastZxid, - sessionTimeout, sessionId, sessionPasswd); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); - boa.writeInt(-1, "len"); - conReq.serialize(boa, "connect"); - baos.close(); - ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); - bb.putInt(bb.capacity() - 4); - bb.rewind(); - synchronized (outgoingQueue) { - for (AuthData id : authInfo) { - outgoingQueue.addFirst(new Packet(new RequestHeader(-4, - OpCode.auth), null, new AuthPacket(0, id.scheme, - id.data), null, null)); - } - outgoingQueue - .addFirst((new Packet(null, null, null, null, bb))); - } - synchronized (this) { - k.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE); - } - } - - private void conLossPacket(Packet p) { - if (p.replyHeader == null) { - return; - } - p.replyHeader.setErr(KeeperException.Code.ConnectionLoss); - finishPacket(p); - } - - private void sendPing() { - RequestHeader h = new RequestHeader(-2, OpCode.ping); - queuePacket(h, null, null, null, null, null, null); - } - - int lastConnectIndex = -1; - - int currentConnectIndex; - - Random r = new Random(System.nanoTime()); - - private void startConnect() throws IOException { - if (lastConnectIndex == -1) { - // We don't want to delay the first try at a connect, so we - // start with -1 the first time around - lastConnectIndex = 0; - } else { - try { - Thread.sleep(r.nextInt(1000)); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - if (nextAddrToTry == lastConnectIndex) { - try { - // Try not to spin too fast! - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - zooKeeper.state = States.CONNECTING; - currentConnectIndex = nextAddrToTry; - InetSocketAddress addr = serverAddrs.get(nextAddrToTry); - nextAddrToTry++; - if (nextAddrToTry == serverAddrs.size()) { - nextAddrToTry = 0; - } - SocketChannel sock; - sock = SocketChannel.open(); - sock.configureBlocking(false); - sock.socket().setSoLinger(false, -1); - sock.socket().setTcpNoDelay(true); - ZooLog.logWarn("Trying to connect to " + addr); - sockKey = sock.register(selector, SelectionKey.OP_CONNECT); - if (sock.connect(addr)) { - primeConnection(sockKey); - } - initialized = false; - } - - @Override - public void run() { - timeout = connectTimeout; - long now = System.currentTimeMillis(); - long lastHeard = now; - int idle = 0; - while (running && zooKeeper.state.isAlive()) { - try { - if (sockKey == null) { - startConnect(); - lastHeard = now; - } - int to = (int) (timeout - idle); - if (to <= 0) { - throw new IOException("TIMED OUT"); - } - selector.select(to); - Set selected; - synchronized (this) { - selected = selector.selectedKeys(); - } - now = System.currentTimeMillis(); - idle = (int) (now - lastHeard); - for (SelectionKey k : selected) { - SocketChannel sc = ((SocketChannel) k.channel()); - if ((k.readyOps() & SelectionKey.OP_CONNECT) != 0) { - if (sc.finishConnect()) { - zooKeeper.state = States.CONNECTED; - timeout = readTimeout / 2; - lastHeard = now; - primeConnection(k); - } - } else if ((k.readyOps() & (SelectionKey.OP_READ | SelectionKey.OP_WRITE)) != 0) { - if (doIO()) { - lastHeard = now; - } - } - } - // ZooLog.logWarn("interest = " + - // Integer.toHexString(sockKey.interestOps()) + " ready = " - // + Integer.toHexString(sockKey.readyOps()) + " PQq = " + - // pendingQueue.size() + " timout = " + timeout + " - // outgoingQueue = " + outgoingQueue.size()); - if (zooKeeper.state == States.CONNECTED) { - if (pendingQueue.size() == 0) { - if (idle >= timeout && timeout == readTimeout / 2) { - sendPing(); - timeout = readTimeout; - } - } else { - timeout = readTimeout; - } - if (outgoingQueue.size() > 0) { - enableWrite(); - } else { - disableWrite(); - } - } else { - timeout = connectTimeout; - } - selected.clear(); - } catch (Exception e) { - ZooLog.logWarn("Closing: " + e.getMessage()); - cleanup(); - if (running) { - waitingEvents.add(new WatcherEvent(Event.EventNone, - Event.KeeperStateDisconnected, null)); - } - - timeout = connectTimeout; - now = System.currentTimeMillis(); - lastHeard = now; - idle = 0; - } - } - cleanup(); - ZooLog.logTextTraceMessage("SendThread exitedloop.", - ZooLog.textTraceMask); - } - - private void cleanup() { - if (sockKey != null) { - SocketChannel sock = (SocketChannel) sockKey.channel(); - sockKey.cancel(); - try { - sock.socket().shutdownInput(); - } catch (IOException e2) { - } - try { - sock.socket().shutdownOutput(); - } catch (IOException e2) { - } - try { - sock.socket().close(); - } catch (IOException e1) { - } - try { - sock.close(); - } catch (IOException e1) { - } - } - try { - Thread.sleep(100); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } - sockKey = null; - synchronized (pendingQueue) { - for (Packet p : pendingQueue) { - conLossPacket(p); - } - pendingQueue.clear(); - } - } - - public void close() { - running = false; - synchronized (this) { - selector.wakeup(); - } - } - } - - @SuppressWarnings("unchecked") - public void close() throws IOException { - ZooLog.logTextTraceMessage("Close ClientCnxn for session: " + sessionId - + "!", ZooLog.SESSION_TRACE_MASK); - sendThread.running = false; - sendThread.close(); - waitingEvents.add(eventOfDeath); - } - - private int xid = 1; - - synchronized private int getXid() { - return xid++; - } - - public ReplyHeader submitRequest(RequestHeader h, Record request, - Record response) throws InterruptedException { - ReplyHeader r = new ReplyHeader(); - Packet packet = queuePacket(h, r, request, response, null, null, null); - synchronized (packet) { - while (!packet.finished) { - packet.wait(); - } - } - return r; - } - - Packet queuePacket(RequestHeader h, ReplyHeader r, Record request, - Record response, AsyncCallback cb, String path, Object ctx) { - Packet packet = null; - synchronized (outgoingQueue) { - if (h.getType() != OpCode.ping && h.getType() != OpCode.auth) { - h.setXid(getXid()); - } - packet = new Packet(h, r, request, response, null); - packet.cb = cb; - packet.ctx = ctx; - packet.path = path; - outgoingQueue.add(packet); - } - synchronized (sendThread) { - selector.wakeup(); - } - return packet; - } - - public void addAuthInfo(String scheme, byte auth[]) { - authInfo.add(new AuthData(scheme, auth)); - if (zooKeeper.state == States.CONNECTED) { - queuePacket(new RequestHeader(-4, OpCode.auth), null, - new AuthPacket(0, scheme, auth), null, null, null, null); - } - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/KeeperException.java b/zookeeper/java/src/com/yahoo/zookeeper/KeeperException.java deleted file mode 100755 index e6594cfe819..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/KeeperException.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper; - -@SuppressWarnings("serial") -public class KeeperException extends Exception { - public interface Code { - int Ok = 0; - - // System and server-side errors - int SystemError = -1; - - int RuntimeInconsistency = SystemError - 1; - - int DataInconsistency = SystemError - 2; - - int ConnectionLoss = SystemError - 3; - - int MarshallingError = SystemError - 4; - - int Unimplemented = SystemError - 5; - - int OperationTimeout = SystemError - 6; - - int BadArguments = SystemError - 7; - - // API errors - int APIError = -100; // Catch all, shouldn't be used other - // than range start - - int NoNode = APIError - 1; // Node does not exist - - int NoAuth = APIError - 2; // Current operation not permitted - - int BadVersion = APIError - 3; // Version conflict - - int NoChildrenForEphemerals = APIError - 8; - - int NodeExists = APIError - 10; - - int NotEmpty = APIError - 11; - - int SessionExpired = APIError - 12; - - int InvalidCallback = APIError - 13; - - int InvalidACL = APIError - 14; - - int AuthFailed = APIError - 15; // client authentication failed - - } - - static String getCodeMessage(int code) { - switch (code) { - case 0: - return "ok"; - case Code.SystemError: - return "SystemError"; - case Code.RuntimeInconsistency: - return "RuntimeInconsistency"; - case Code.DataInconsistency: - return "DataInconsistency"; - case Code.ConnectionLoss: - return "ConnectionLoss"; - case Code.MarshallingError: - return "MarshallingError"; - case Code.Unimplemented: - return "Unimplemented"; - case Code.OperationTimeout: - return "OperationTimeout"; - case Code.BadArguments: - return "BadArguments"; - case Code.APIError: - return "APIError"; - case Code.NoNode: - return "NoNode"; - case Code.NoAuth: - return "NoAuth"; - case Code.BadVersion: - return "BadVersion"; - case Code.NoChildrenForEphemerals: - return "NoChildrenForEphemerals"; - case Code.NodeExists: - return "NodeExists"; - case Code.InvalidACL: - return "InvalidACL"; - case Code.AuthFailed: - return "AuthFailed"; - default: - return "Unknown error " + code; - } - } - - private int _code; - - private String path; - - public KeeperException(int code) { - _code = code; - } - - public KeeperException(int code, String path) { - _code = code; - this.path = path; - } - - public int getCode() { - return _code; - } - - public String getPath() { - return path; - } - - @Override - public String getMessage() { - if (path == null) { - return "KeeperErrorCode = " + getCodeMessage(_code); - } - return "KeeperErrorCode = " + getCodeMessage(_code) + " for " + path; - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/Watcher.java b/zookeeper/java/src/com/yahoo/zookeeper/Watcher.java deleted file mode 100755 index 6cbad6b55d4..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/Watcher.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper; - -import com.yahoo.zookeeper.proto.WatcherEvent; - -/** - * This interface specifies the public interface an event handler class must - * implement. A ZooKeeper client will get various events from the ZooKeepr - * server it connects to. An application using such a client handles these - * events by registering a callback object with the client. The callback object - * is expected to be an instance of a class that implements Watcher interface. - * - */ -public interface Watcher { - - /** - * - * This interface defines the list of possible event codes - * - */ - public interface Event { - - // constants for connection states - final public static int KeeperStateChanged = 0; - - final public static int KeeperStateUnknown = -1; - - final public static int KeeperStateDisconnected = 0; - - final public static int KeeperStateNoSyncConnected = 1; - - final public static int KeeperStateSyncConnected = 3; - - public static final int KeeperStateExpired = -112; - - // constants for event types - final public static int EventNone = -1; - - final public static int EventNodeCreated = 1; - - final public static int EventNodeDeleted = 2; - - final public static int EventNodeDataChanged = 3; - - final public static int EventNodeChildrenChanged = 4; - } - - abstract public void process(WatcherEvent event); -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/ZooKeeper.java b/zookeeper/java/src/com/yahoo/zookeeper/ZooKeeper.java deleted file mode 100755 index efac82dca2b..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/ZooKeeper.java +++ /dev/null @@ -1,852 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Date; - -import com.yahoo.zookeeper.AsyncCallback.ACLCallback; -import com.yahoo.zookeeper.AsyncCallback.ChildrenCallback; -import com.yahoo.zookeeper.AsyncCallback.DataCallback; -import com.yahoo.zookeeper.AsyncCallback.StatCallback; -import com.yahoo.zookeeper.AsyncCallback.StringCallback; -import com.yahoo.zookeeper.AsyncCallback.VoidCallback; -import com.yahoo.zookeeper.KeeperException.Code; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.CreateRequest; -import com.yahoo.zookeeper.proto.CreateResponse; -import com.yahoo.zookeeper.proto.DeleteRequest; -import com.yahoo.zookeeper.proto.ExistsRequest; -import com.yahoo.zookeeper.proto.GetACLRequest; -import com.yahoo.zookeeper.proto.GetACLResponse; -import com.yahoo.zookeeper.proto.GetChildrenRequest; -import com.yahoo.zookeeper.proto.GetChildrenResponse; -import com.yahoo.zookeeper.proto.GetDataRequest; -import com.yahoo.zookeeper.proto.GetDataResponse; -import com.yahoo.zookeeper.proto.ReplyHeader; -import com.yahoo.zookeeper.proto.RequestHeader; -import com.yahoo.zookeeper.proto.SetACLRequest; -import com.yahoo.zookeeper.proto.SetACLResponse; -import com.yahoo.zookeeper.proto.SetDataRequest; -import com.yahoo.zookeeper.proto.SetDataResponse; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.DataTree; - -/** - * This is the main class of ZooKeeper client library. To use a ZooKeeper - * service, an application must first instantiate an object of ZooKeeper class. - * All the iterations will be done by calling the methods of ZooKeeper class. - *

        - * To create a client(ZooKeeper) object, the application needs to pass a string - * containing a list of host:port pairs, each corresponding to a ZooKeeper - * server; a sessionTimeout; and an object of Watcher type. - *

        - * The client object will pick an arbitrary server and try to connect to it. If - * failed, it will try the next one in the list, until a connection is - * established, or all the servers have been tried. - *

        - * Once a connection to a server is established, a session ID is assigned to the - * client. The client will send heart beats to the server periodically to keep - * the session valid. - *

        - * The application can call ZooKeeper APIs through a client as long as the - * session ID of the client remains valid. - *

        - * If for some reason, the client fails to send heart beats to the server for a - * prolonged period of time (exceeding the sessionTimeout value, for instance), - * the server will expire the session, and the session ID will become invalid. - * The client object will no longer be usable. To make ZooKeeper API calls, the - * application must create a new client object. - *

        - * If the ZooKeeper server the client currently connects to fails or otherwise - * does not respond, the client will automatically try to connect to another - * server before its session ID expires. If successful, the application can - * continue to use the client. - *

        - * Some successful ZooKeeper API calls can leave watches on the "data nodes" in - * the ZooKeeper server. Other successful ZooKeeper API calls can trigger those - * watches. Once a watch is triggered, an event will be delivered to the client - * which left the watch at the first place. Each watch can be triggered only - * once. Thus, up to one event will be delivered to a client for every watch it - * leaves. - *

        - * A client needs an object of a class implementing Watcher interface for - * processing the events delivered to the client. - * - * When a client drops current connection and re-connects to a server, all the - * existing watches are considered as being triggered but the undelivered events - * are lost. To emulate this, the client will generate a special event to tell - * the event handler a connection has been dropped. This special event has type - * EventNone and state sKeeperStateDisconnected. - * - */ -public class ZooKeeper { - Watcher watcher; - - enum States { - CONNECTING, ASSOCIATING, CONNECTED, CLOSED, AUTH_FAILED; - - public boolean isAlive() { - return this != CLOSED && this != AUTH_FAILED; - } - } - - States state; - - ClientCnxn cnxn; - - public ZooKeeper(String host, int sessionTimeout, Watcher watcher) - throws KeeperException, IOException { - cnxn = new ClientCnxn(host, sessionTimeout, this); - this.watcher = watcher; - } - - public ZooKeeper(String host, int sessionTimeout, Watcher watcher, - long sessionId, byte[] sessionPasswd) throws KeeperException, - IOException { - cnxn = new ClientCnxn(host, sessionTimeout, this, sessionId, - sessionPasswd); - this.watcher = watcher; - } - - public long getSessionId() { - return cnxn.getSessionId(); - } - - public byte[] getSessionPasswd() { - return cnxn.getSessionPasswd(); - } - - public void addAuthInfo(String scheme, byte auth[]) { - cnxn.addAuthInfo(scheme, auth); - } - - public String describeCNXN() { - return cnxn.toString(); - } - - public synchronized void register(Watcher watcher) { - this.watcher = watcher; - } - - /** - * Close this client object. Once the client is closed, its session becomes - * invalid. All the ephemeral nodes in the ZooKeeper server associated with - * the session will be removed. The watches left on those nodes (and on - * their parents) will be triggered. - * - * @throws InterruptedException - * - * @throws IOException - * @throws InterruptedException - * @throws KeeperException - */ - public synchronized void close() throws InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.closeSession); - cnxn.submitRequest(h, null, null); - try { - cnxn.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Create a node with the given path. The node data will be the given data, - * and node acl will be the given acl. - *

        - * The flags argument specifies whether the created node will be ephemeral - * or not. - *

        - * An ephemeral node will be removed by the ZooKeeper automatically when the - * session associated with the creation of the node expires. - *

        - * The flags argument can also specify to create a sequential node. The - * actual path name of a sequential node will be the given path plus a - * suffix "_i" where i is the current sequential number of the node. Once - * such a node is created, the sequential number will be incremented by one. - *

        - * If a node with the same actual path already exists in the ZooKeeper, a - * KeeperException with error code KeeperException.NodeExists will be - * thrown. Note that since a different actual path is used for each - * invocation of creating sequential node with the same path argument, the - * call will never throw "file exists" KeeperException. - *

        - * If the parent node does not exist in the ZooKeeper, a KeeperException - * with error code KeeperException.NoNode will be thrown. - *

        - * An ephemeral node cannot have children. If the parent node of the given - * path is ephemeral, a KeeperException with error code - * KeeperException.NoChildrenForEphemerals will be thrown. - *

        - * This operation, if successful, will trigger all the watches left on the - * node of the given path by exists and getData API calls, and the watches - * left on the parent node by getChildren API calls. - *

        - * If a node is created successfully, the ZooKeeper server will trigger the - * watches on the path left by exists calls, and the watches on the parent - * of the node by getChildren calls. - * - * @param path - * the path for the node - * @param data - * the initial data for the node - * @param acl - * the acl for the node - * @param flags - * specifying whether the node to be created is ephemeral - * and/or sequential - * @return the actual path of the created node - * @throws KeeperException - * an exception with appropriate error code defined in - * KeeperException class.. - * @throws IOException - * @throws InterruptedException - */ - public String create(String path, byte data[], ArrayList acl, int flags) - throws KeeperException, InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.create); - CreateRequest request = new CreateRequest(); - CreateResponse response = new CreateResponse(); - request.setData(data); - request.setFlags(flags); - request.setPath(path); - if (acl != null && acl.size() == 0) { - throw new KeeperException(Code.InvalidACL); - } - request.setAcl(acl); - ReplyHeader r = cnxn.submitRequest(h, request, response); - if (r.getErr() != 0) { - throw new KeeperException(r.getErr(), path); - } - return response.getPath(); - } - - /** - * The Asynchronous version of create. The request doesn't actually until - * the asynchronous callback is called. - * - * @see #create(String, byte[], ArrayList, int) - */ - - public void create(String path, byte data[], ArrayList acl, int flags, - StringCallback cb, Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.create); - CreateRequest request = new CreateRequest(); - CreateResponse response = new CreateResponse(); - ReplyHeader r = new ReplyHeader(); - request.setData(data); - request.setFlags(flags); - request.setPath(path); - request.setAcl(acl); - cnxn.queuePacket(h, r, request, response, cb, path, ctx); - } - - /** - * Delete the node with the given path. The call will succeed if such a node - * exists, and the given version matches the node's version (if the given - * version is -1, it matches any node's versions). - *

        - * A KeeperException with error code KeeperException.NoNode will be thrown - * if the nodes does not exist. - *

        - * A KeeperException with error code KeeperException.BadVersion will be - * thrown if the given version does not match the node's version. - *

        - * A KeeperException with error code KeeperException.NotEmpty will be thrown - * if the node has children. - *

        - * This operation, if successful, will trigger all the watches on the node - * of the given path left by exists API calls, and the watches on the parent - * node left by getChildren API calls. - * - * @param path - * the path of the node to be deleted. - * @param version - * the expected node version. - * @throws KeeperException - * an KeeperException with appropriate error code. - * @throws IOException - * @throws InterruptedException - */ - public void delete(String path, int version) throws KeeperException, - InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.delete); - DeleteRequest request = new DeleteRequest(); - request.setPath(path); - request.setVersion(version); - ReplyHeader r = cnxn.submitRequest(h, request, null); - if (r.getErr() != 0) { - throw new KeeperException(r.getErr()); - } - } - - /** - * The Asynchronous version of delete. The request doesn't actually until - * the asynchronous callback is called. - * - * @see #delete(String, int) - */ - public void delete(String path, int version, VoidCallback cb, Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.delete); - DeleteRequest request = new DeleteRequest(); - request.setPath(path); - request.setVersion(version); - cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, path, ctx); - } - - /** - * Return the stat of the node of the given path. Return null if no such a - * node exists. - *

        - * If the watch is true and the call is successful (no exception is thrown), - * a watch will be left on the node with the given path. The watch will be - * triggered by a successful operation that creates/delete the node or sets - * the data on the node. - * - * @param path - * the node path - * @param watch - * whether need to watch this node - * @return the stat of the node of the given path; return null if no such a - * node exists. - * @throws KeeperException - * @throws IOException - * @throws InterruptedException - */ - public Stat exists(String path, boolean watch) throws KeeperException, - InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.exists); - ExistsRequest request = new ExistsRequest(); - request.setPath(path); - request.setWatch(watch); - SetDataResponse response = new SetDataResponse(); - ReplyHeader r = cnxn.submitRequest(h, request, response); - if (r.getErr() != 0) { - if (r.getErr() == KeeperException.Code.NoNode) { - return null; - } - throw new KeeperException(r.getErr()); - } - return response.getStat().getCzxid() == -1 ? null : response.getStat(); - } - - /** - * The Asynchronous version of exists. The request doesn't actually until - * the asynchronous callback is called. - * - * @see #exists(String, boolean) - */ - public void exists(String path, boolean watch, StatCallback cb, Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.exists); - ExistsRequest request = new ExistsRequest(); - request.setPath(path); - request.setWatch(watch); - SetDataResponse response = new SetDataResponse(); - cnxn - .queuePacket(h, new ReplyHeader(), request, response, cb, path, - ctx); - } - - /** - * Return the data and the stat of the node of the given path. - *

        - * If the watch is true and the call is successfull (no exception is - * thrown), a watch will be left on the node with the given path. The watch - * will be triggered by a sucessful operation that sets data on the node, or - * deletes the node. - *

        - * A KeeperException with error code KeeperException.NoNode will be thrown - * if no node with the given path exists. - * - * @param path - * the given path - * @param watch - * whether need to watch this node - * @param stat - * teh stat of the node - * @return the data of the node - * @throws IOException - * @throws KeeperException - * @throws InterruptedException - */ - public byte[] getData(String path, boolean watch, Stat stat) - throws KeeperException, InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.getData); - GetDataRequest request = new GetDataRequest(); - request.setPath(path); - request.setWatch(watch); - GetDataResponse response = new GetDataResponse(); - ReplyHeader r = cnxn.submitRequest(h, request, response); - if (r.getErr() != 0) { - throw new KeeperException(r.getErr()); - } - if (stat != null) { - DataTree.copyStat(response.getStat(), stat); - } - return response.getData(); - } - - /** - * The Asynchronous version of getData. The request doesn't actually until - * the asynchronous callback is called. - * - * @see #getData(String, boolean, Stat) - */ - - public void getData(String path, boolean watch, DataCallback cb, Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.getData); - GetDataRequest request = new GetDataRequest(); - request.setPath(path); - request.setWatch(watch); - GetDataResponse response = new GetDataResponse(); - cnxn - .queuePacket(h, new ReplyHeader(), request, response, cb, path, - ctx); - } - - /** - * Set the data for the node of the given path if such a node exists and the - * given version matches the version of the node (if the given version is - * -1, it matches any node's versions). Return the stat of the node. - *

        - * This operation, if successful, will trigger all the watches on the node - * of the given path left by getData calls. - *

        - * A KeeperException with error code KeeperException.NoNode will be thrown - * if no node with the given path exists. - * - * A KeeperException with error code KeeperException.BadVersion will be - * thrown if the given version does not match the node's version. - * - * @param path - * the path of the node - * @param data - * the data to set - * @param version - * the expected matching version - * @return the state of the node - * @throws KeeperException - * @throws IOException - * @throws InterruptedException - */ - public Stat setData(String path, byte data[], int version) - throws KeeperException, InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.setData); - SetDataRequest request = new SetDataRequest(); - request.setPath(path); - request.setData(data); - request.setVersion(version); - SetDataResponse response = new SetDataResponse(); - ReplyHeader r = cnxn.submitRequest(h, request, response); - if (r.getErr() != 0) { - throw new KeeperException(r.getErr()); - } - return response.getStat(); - } - - /** - * The Asynchronous version of setData. The request doesn't actually until - * the asynchronous callback is called. - * - * @see #setData(String, byte[], int) - */ - public void setData(String path, byte data[], int version, StatCallback cb, - Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.setData); - SetDataRequest request = new SetDataRequest(); - request.setPath(path); - request.setData(data); - request.setVersion(version); - SetDataResponse response = new SetDataResponse(); - cnxn - .queuePacket(h, new ReplyHeader(), request, response, cb, path, - ctx); - } - - /** - * - * Return the ACL and stat of the node of the given path. - *

        - * A KeeperException with error code KeeperException.NoNode will be thrown - * if no node with the given path exists. - * - * @param path - * the given path for the node - * @param stat - * the stat of the node will be copied to this parameter. - * @return the ACL array of the given node. - * @throws KeeperException - * @throws IOException - * @throws InterruptedException - */ - public ArrayList getACL(String path, Stat stat) - throws KeeperException, InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.getACL); - GetACLRequest request = new GetACLRequest(); - request.setPath(path); - GetACLResponse response = new GetACLResponse(); - ReplyHeader r = cnxn.submitRequest(h, request, response); - if (r.getErr() != 0) { - throw new KeeperException(r.getErr()); - } - DataTree.copyStat(response.getStat(), stat); - return response.getAcl(); - } - - /** - * The Asynchronous version of getACL. The request doesn't actually until - * the asynchronous callback is called. - * - * @see #getACL(String, Stat) - */ - public void getACL(String path, Stat stat, ACLCallback cb, Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.getACL); - GetACLRequest request = new GetACLRequest(); - request.setPath(path); - GetACLResponse response = new GetACLResponse(); - cnxn - .queuePacket(h, new ReplyHeader(), request, response, cb, path, - ctx); - } - - /** - * Set the ACL for the node of the given path if such a node exists and the - * given version matches the version of the node. Return the stat of the - * node. - *

        - * A KeeperException with error code KeeperException.NoNode will be thrown - * if no node with the given path exists. - *

        - * A KeeperException with error code KeeperException.BadVersion will be - * thrown if the given version does not match the node's version. - * - * @param path - * @param acl - * @param version - * @return the stat of the node. - * @throws KeeperException - * @throws IOException - * @throws InterruptedException - */ - public Stat setACL(String path, ArrayList acl, int version) - throws KeeperException, InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.setACL); - SetACLRequest request = new SetACLRequest(); - request.setPath(path); - if (acl != null && acl.size() == 0) { - throw new KeeperException(Code.InvalidACL); - } - request.setAcl(acl); - request.setVersion(version); - SetACLResponse response = new SetACLResponse(); - ReplyHeader r = cnxn.submitRequest(h, request, response); - if (r.getErr() != 0) { - throw new KeeperException(r.getErr()); - } - return response.getStat(); - } - - /** - * The Asynchronous version of setACL. The request doesn't actually until - * the asynchronous callback is called. - * - * @see #setACL(String, ArrayList, int) - */ - public void setACL(String path, ArrayList acl, int version, - StatCallback cb, Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.setACL); - SetACLRequest request = new SetACLRequest(); - request.setPath(path); - request.setAcl(acl); - request.setVersion(version); - SetACLResponse response = new SetACLResponse(); - cnxn - .queuePacket(h, new ReplyHeader(), request, response, cb, path, - ctx); - } - - /** - * Return the list of the children of the node of the given path. - *

        - * If the watch is true and the call is successful (no exception is thrown), - * a watch will be left on the node with the given path. The watch willbe - * triggered by a sucessful operation that deletes the node of the given - * path or creates/delete a child under the node. - *

        - * A KeeperException with error code KeeperException.NoNode will be thrown - * if no node with the given path exists. - * - * @param path - * @param watch - * @return an array of children of the node with the given path - * @throws IOException - * @throws KeeperException - * @throws InterruptedException - */ - public ArrayList getChildren(String path, boolean watch) - throws KeeperException, InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.getChildren); - GetChildrenRequest request = new GetChildrenRequest(); - request.setPath(path); - request.setWatch(watch); - GetChildrenResponse response = new GetChildrenResponse(); - ReplyHeader r = cnxn.submitRequest(h, request, response); - if (r.getErr() != 0) { - throw new KeeperException(r.getErr()); - } - return response.getChildren(); - } - - /** - * The Asynchronous version of getChildren. The request doesn't actually - * until the asynchronous callback is called. - * - * @see #getChildren(String, boolean) - */ - public void getChildren(String path, boolean watch, ChildrenCallback cb, - Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.getChildren); - GetChildrenRequest request = new GetChildrenRequest(); - request.setPath(path); - request.setWatch(watch); - GetChildrenResponse response = new GetChildrenResponse(); - cnxn - .queuePacket(h, new ReplyHeader(), request, response, cb, path, - ctx); - } - - public States getState() { - return state; - } - - // Everything below this line is for testing! - - static void usage() { - System.err.println("ZooKeeper host:port cmd args"); - System.err.println("\tcreate path data acl"); - System.err.println("\tdelete path [version]"); - System.err.println("\tset path data [version]"); - System.err.println("\tget path [watch]"); - System.err.println("\tls path [watch]"); - System.err.println("\tgetAcl path"); - System.err.println("\tsetAcl path acl"); - System.err.println("\tstat path [watch]"); - } - - static private class MyWatcher implements Watcher { - public void process(WatcherEvent event) { - System.err.println(event.getPath() + ": " + event.getState() + "-" - + event.getType()); - } - } - - static private int getPermFromString(String permString) { - int perm = 0; - for (int i = 0; i < permString.length(); i++) { - switch (permString.charAt(i)) { - case 'r': - perm |= ZooDefs.Perms.READ; - break; - case 'w': - perm |= ZooDefs.Perms.WRITE; - break; - case 'c': - perm |= ZooDefs.Perms.CREATE; - break; - case 'd': - perm |= ZooDefs.Perms.DELETE; - break; - case 'a': - perm |= ZooDefs.Perms.ADMIN; - break; - default: - System.err - .println("Unknown perm type: " + permString.charAt(i)); - } - } - return perm; - } - - private static void printStat(Stat stat) { - System.err.println("ctime = " + new Date(stat.getCtime()).toString()); - System.err.println("ctime = " + new Date(stat.getMtime()).toString()); - System.err.println("cversion = " + stat.getCversion()); - System.err.println("cZxid = " + stat.getCzxid()); - System.err.println("mZxid = " + stat.getMzxid()); - System.err.println("dataVersion = " + stat.getVersion()); - System.err.println("aclVersion = " + stat.getAversion()); - } - - public static void main(String args[]) throws NumberFormatException, - KeeperException, IOException, InterruptedException { - if (args.length == 1) { - ZooKeeper zooKeeper = new ZooKeeper(args[0], 5000, new MyWatcher()); - BufferedReader br = new BufferedReader(new InputStreamReader( - System.in)); - String line; - while ((line = br.readLine()) != null) { - line = "ignore " + line; - args = line.split(" "); - processCmd(args, zooKeeper); - } - } else if (args.length < 3) { - usage(); - } - ZooKeeper zooKeeper = new ZooKeeper(args[0], 5000, new MyWatcher()); - boolean watch = processCmd(args, zooKeeper); - if (!watch) { - System.exit(0); - } - } - - private static DataCallback dataCallback = new DataCallback() { - - @Override - public void processResult(int rc, String path, Object ctx, byte[] data, - Stat stat) { - System.out.println("rc = " + rc + " path = " + path + " data = " - + (data == null ? "null" : new String(data)) + " stat = "); - printStat(stat); - } - - }; - - private static boolean processCmd(String[] args, ZooKeeper zooKeeper) - throws KeeperException, IOException, InterruptedException { - Stat stat = new Stat(); - if (args.length < 2) { - return false; - } - if (args.length < 3) { - usage(); - return false; - } - String cmd = args[1]; - boolean watch = args.length > 3; - String path = args[2]; - ArrayList acl = Ids.OPEN_ACL_UNSAFE; - System.out.println("Processing " + cmd); - if (cmd.equals("create") && args.length >= 4) { - if (args.length == 5) { - acl = parseACLs(args[4]); - } - String newPath = zooKeeper.create(path, args[3].getBytes(), acl, 0); - System.err.println("Created " + newPath); - } else if (cmd.equals("delete") && args.length >= 3) { - zooKeeper.delete(path, watch ? Integer.parseInt(args[3]) : -1); - } else if (cmd.equals("set") && args.length >= 4) { - stat = zooKeeper.setData(path, args[3].getBytes(), - args.length > 4 ? Integer.parseInt(args[4]) : -1); - printStat(stat); - } else if (cmd.equals("aget") && args.length >= 3) { - zooKeeper.getData(path, watch, dataCallback, path); - } else if (cmd.equals("get") && args.length >= 3) { - byte data[] = zooKeeper.getData(path, watch, stat); - System.out.println(new String(data)); - printStat(stat); - } else if (cmd.equals("ls") && args.length >= 3) { - ArrayList children = zooKeeper.getChildren(path, watch); - System.out.println(children); - } else if (cmd.equals("getAcl") && args.length >= 2) { - acl = zooKeeper.getACL(path, stat); - for (ACL a : acl) { - System.out.println(a.getId() + ": " - + getPermString(a.getPerms())); - } - } else if (cmd.equals("setAcl") && args.length >= 4) { - - stat = zooKeeper.setACL(path, parseACLs(args[3]), - args.length > 4 ? Integer.parseInt(args[4]) : -1); - printStat(stat); - } else if (cmd.equals("stat") && args.length >= 3) { - stat = zooKeeper.exists(path, watch); - printStat(stat); - } else { - usage(); - } - return watch; - } - - private static String getPermString(int perms) { - StringBuffer p = new StringBuffer(); - if ((perms & ZooDefs.Perms.CREATE) != 0) { - p.append('c'); - } - if ((perms & ZooDefs.Perms.DELETE) != 0) { - p.append('d'); - } - if ((perms & ZooDefs.Perms.READ) != 0) { - p.append('r'); - } - if ((perms & ZooDefs.Perms.WRITE) != 0) { - p.append('w'); - } - if ((perms & ZooDefs.Perms.ADMIN) != 0) { - p.append('a'); - } - return p.toString(); - } - - private static ArrayList parseACLs(String aclString) { - ArrayList acl; - String acls[] = aclString.split(","); - acl = new ArrayList(); - for (String a : acls) { - int firstColon = a.indexOf(':'); - int lastColon = a.indexOf(':'); - if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) { - System.err - .println(a + " does not have the form scheme:id:perm"); - continue; - } - ACL newAcl = new ACL(); - newAcl.setId(new Id(a.substring(0, firstColon), a.substring( - firstColon + 1, lastColon))); - newAcl.setPerms(getPermFromString(a.substring(lastColon + 1))); - acl.add(newAcl); - } - return acl; - } - - public void disconnect() throws IOException { - cnxn.close(); - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/ByteBufferInputStream.java b/zookeeper/java/src/com/yahoo/zookeeper/server/ByteBufferInputStream.java deleted file mode 100644 index 9f7e5c914b1..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/ByteBufferInputStream.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; - -public class ByteBufferInputStream extends InputStream { - ByteBuffer bb; - - public ByteBufferInputStream(ByteBuffer bb) { - this.bb = bb; - } - - @Override - public int read() throws IOException { - if (bb.remaining() == 0) { - return -1; - } - return bb.get() & 0xff; - } - - @Override - public int available() throws IOException { - return bb.remaining(); - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - if (bb.remaining() == 0) { - return -1; - } - if (len > bb.remaining()) { - len = bb.remaining(); - } - bb.get(b, off, len); - return len; - } - - @Override - public int read(byte[] b) throws IOException { - return read(b, 0, b.length); - } - - @Override - public long skip(long n) throws IOException { - long newPos = bb.position() + n; - if (newPos > bb.remaining()) { - n = bb.remaining(); - } - bb.position(bb.position() + (int) n); - return n; - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/DataNode.java b/zookeeper/java/src/com/yahoo/zookeeper/server/DataNode.java deleted file mode 100755 index 934d2739e4d..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/DataNode.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import com.yahoo.jute.Index; -import com.yahoo.jute.InputArchive; -import com.yahoo.jute.OutputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Stat; - -/** - * This class contains the data for a node in the data tree. - *

        - * A data node contains a reference to its parent, a byte array as its data, an - * array of ACLs, a stat object, and a set of its children's paths. - * - */ -public class DataNode implements Record { - DataNode() { - } - - DataNode(DataNode parent, byte data[], ArrayList acl, Stat stat) { - this.parent = parent; - this.data = data; - this.acl = acl; - this.stat = stat; - this.children = new HashSet(); - } - - DataNode parent; - - byte data[]; - - ArrayList acl; - - public Stat stat; - - HashSet children = new HashSet(); - - public void deserialize(InputArchive archive, String tag) - throws IOException { - archive.startRecord("node"); - data = archive.readBuffer("data"); - Index i = archive.startVector("acl"); - if (i != null) { - acl = new ArrayList(); - while (!i.done()) { - ACL a = new ACL(); - a.deserialize(archive, "aclEntry"); - acl.add(a); - i.incr(); - } - } - archive.endVector("acl"); - stat = new Stat(); - stat.deserialize(archive, "stat"); - archive.endRecord("node"); - } - - synchronized public void serialize(OutputArchive archive, String tag) - throws IOException { - archive.startRecord(this, "node"); - archive.writeBuffer(data, "data"); - archive.startVector(acl, "acl"); - if (acl != null) { - for (ACL a : acl) { - a.serialize(archive, "aclEntry"); - } - } - archive.endVector(acl, "acl"); - stat.serialize(archive, "stat"); - archive.endRecord(this, "node"); - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/DataTree.java b/zookeeper/java/src/com/yahoo/zookeeper/server/DataTree.java deleted file mode 100755 index 0f1f1fc9e25..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/DataTree.java +++ /dev/null @@ -1,516 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import com.yahoo.jute.InputArchive; -import com.yahoo.jute.OutputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.KeeperException.Code; -import com.yahoo.zookeeper.Watcher.Event; -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.txn.CreateTxn; -import com.yahoo.zookeeper.txn.DeleteTxn; -import com.yahoo.zookeeper.txn.ErrorTxn; -import com.yahoo.zookeeper.txn.SetACLTxn; -import com.yahoo.zookeeper.txn.SetDataTxn; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * This class maintains the tree data structure. It doesn't have any networking - * or client connection code in it so that it can be tested in a stand alone - * way. - *

        - * The tree maintains two parallel data structures: a hashtable that maps from - * full paths to DataNodes and a tree of DataNodes. All accesses to a path is - * through the hashtable. The tree is traversed only when serializing to disk. - */ -public class DataTree { - /** - * This hashtable provides a fast lookup to the datanodes. The tree is the - * source of truth and is where all the locking occurs - */ - private ConcurrentHashMap nodes = new ConcurrentHashMap(); - - private WatchManager dataWatches = new WatchManager(); - - private WatchManager childWatches = new WatchManager(); - - /** - * This hashtable lists the paths of the ephemeral nodes of a session. - */ - private ConcurrentHashMap> ephemerals = new ConcurrentHashMap>(); - - /** A debug string * */ - private String debug = "debug"; - - public HashSet getEphemerals(long sessionId) { - HashSet retv = ephemerals.get(sessionId); - if (retv == null) { - return new HashSet(); - } - return (HashSet) retv.clone(); - } - - public Collection getSessions() { - return ephemerals.keySet(); - } - - public DataNode getNode(String path) { - return nodes.get(path); - } - - /** - * This is a pointer to the root of the DataTree. It is the source of truth, - * but we usually use the nodes hashmap to find nodes in the tree. - */ - private DataNode root = new DataNode(null, new byte[0], null, new Stat()); - - public DataTree() { - /* Rather than fight it, let root have an alias */ - nodes.put("", root); - nodes.put("/", root); - } - - static public void copyStat(Stat from, Stat to) { - to.setAversion(from.getAversion()); - to.setCtime(from.getCtime()); - to.setCversion(from.getCversion()); - to.setCzxid(from.getCzxid()); - to.setMtime(from.getMtime()); - to.setMzxid(from.getMzxid()); - to.setVersion(from.getVersion()); - to.setEphemeralOwner(from.getEphemeralOwner()); - } - - // public void remooveInterest(String path, Watcher nw) { - // DataNode n = nodes.get(path); - // if (n == null) { - // synchronized (nonExistentWatches) { - // HashSet list = nonExistentWatches.get(path); - // if (list != null) { - // list.remove(nw); - // } - // } - // } - // synchronized (n) { - // n.dataWatchers.remove(nw); - // n.childWatchers.remove(nw); - // } - // } - - /** - * @param path - * @param data - * @param acl - * @param ephemeralOwner - * the session id that owns this node. -1 indicates this is - * not an ephemeral node. - * @param zxid - * @param time - * @return - * @throws KeeperException - */ - private String createNode(String path, byte data[], ArrayList acl, - long ephemeralOwner, long zxid, long time) throws KeeperException { - int lastSlash = path.lastIndexOf('/'); - String parentName = path.substring(0, lastSlash); - String childName = path.substring(lastSlash + 1); - Stat stat = new Stat(); - stat.setCtime(time); - stat.setMtime(time); - stat.setCzxid(zxid); - stat.setMzxid(zxid); - stat.setVersion(0); - stat.setAversion(0); - stat.setEphemeralOwner(ephemeralOwner); - DataNode parent = nodes.get(parentName); - if (parent == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (parent) { - if (parent.children.contains(childName)) { - throw new KeeperException(KeeperException.Code.NodeExists); - } - int cver = parent.stat.getCversion(); - cver++; - parent.stat.setCversion(cver); - DataNode child = new DataNode(parent, data, acl, stat); - parent.children.add(childName); - nodes.put(path, child); - if (ephemeralOwner != 0) { - HashSet list = ephemerals.get(ephemeralOwner); - if (list == null) { - list = new HashSet(); - ephemerals.put(ephemeralOwner, list); - } - list.add(path); - } - } - dataWatches.triggerWatch(path, Event.EventNodeCreated); - childWatches.triggerWatch(parentName, Event.EventNodeChildrenChanged); - return path; - } - - private void deleteNode(String path) throws KeeperException { - int lastSlash = path.lastIndexOf('/'); - String parentName = path.substring(0, lastSlash); - String childName = path.substring(lastSlash + 1); - DataNode node = nodes.get(path); - if (node == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - nodes.remove(path); - DataNode parent = nodes.get(parentName); - if (parent == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (parent) { - parent.children.remove(childName); - parent.stat.setCversion(parent.stat.getCversion() + 1); - long eowner = node.stat.getEphemeralOwner(); - if (eowner != 0) { - HashSet nodes = ephemerals.get(eowner); - if (nodes != null) { - nodes.remove(path); - } - } - node.parent = null; - } - ZooLog.logTextTraceMessage("dataWatches.triggerWatch " + path, - ZooLog.EVENT_DELIVERY_TRACE_MASK); - ZooLog.logTextTraceMessage("childWatches.triggerWatch " + parentName, - ZooLog.EVENT_DELIVERY_TRACE_MASK); - dataWatches.triggerWatch(path, Event.EventNodeDeleted); - childWatches.triggerWatch(parentName, Event.EventNodeChildrenChanged); - } - - private Stat setData(String path, byte data[], int version, long zxid, - long time) throws KeeperException { - Stat s = new Stat(); - DataNode n = nodes.get(path); - if (n == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (n) { - n.data = data; - n.stat.setMtime(time); - n.stat.setMzxid(zxid); - n.stat.setVersion(version); - copyStat(n.stat, s); - } - dataWatches.triggerWatch(path, Event.EventNodeDataChanged); - return s; - } - - public byte[] getData(String path, Stat stat, Watcher watcher) - throws KeeperException { - DataNode n = nodes.get(path); - if (n == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (n) { - copyStat(n.stat, stat); - if (watcher != null) { - dataWatches.addWatch(path, watcher); - } - return n.data; - } - } - - public Stat statNode(String path, Watcher watcher) throws KeeperException { - Stat stat = new Stat(); - DataNode n = nodes.get(path); - if (watcher != null) { - dataWatches.addWatch(path, watcher); - } - if (n == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (n) { - copyStat(n.stat, stat); - return stat; - } - } - - public ArrayList getChildren(String path, Stat stat, Watcher watcher) - throws KeeperException { - DataNode n = nodes.get(path); - if (n == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (n) { - ArrayList children = new ArrayList(); - children.addAll(n.children); - Collections.sort(children); - if (watcher != null) { - childWatches.addWatch(path, watcher); - } - return children; - } - } - - private Stat setACL(String path, ArrayList acl, int version) - throws KeeperException { - Stat stat = new Stat(); - DataNode n = nodes.get(path); - if (n == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (n) { - n.stat.setAversion(version); - n.acl = acl; - copyStat(n.stat, stat); - return stat; - } - } - - @SuppressWarnings("unchecked") - public ArrayList getACL(String path, Stat stat) throws KeeperException { - DataNode n = nodes.get(path); - if (n == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - synchronized (n) { - copyStat(n.stat, stat); - return (ArrayList) n.acl.clone(); - } - } - - static public class ProcessTxnResult { - public long clientId; - - public int cxid; - - public long zxid; - - public int err; - - public int type; - - public String path; - - public Stat stat; - - /** - * Equality is defined as the clientId and the cxid being the same. This - * allows us to use hash tables to track completion of transactions. - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object o) { - if (o instanceof ProcessTxnResult) { - ProcessTxnResult other = (ProcessTxnResult) o; - return other.clientId == clientId && other.cxid == cxid; - } - return false; - } - - /** - * See equals() to find the rational for how this hashcode is generated. - * - * @see ProcessTxnResult#equals(Object) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return (int) ((clientId ^ cxid) % Integer.MAX_VALUE); - } - - } - - public volatile long lastProcessedZxid = 0; - - @SuppressWarnings("unchecked") - public ProcessTxnResult processTxn(TxnHeader header, Record txn) { - ProcessTxnResult rc = new ProcessTxnResult(); - - try { - rc.clientId = header.getClientId(); - rc.cxid = header.getCxid(); - rc.zxid = header.getZxid(); - rc.type = header.getType(); - rc.err = 0; - if (rc.zxid > lastProcessedZxid) { - lastProcessedZxid = rc.zxid; - } - switch (header.getType()) { - case OpCode.create: - CreateTxn createTxn = (CreateTxn) txn; - debug = "Create transaction for " + createTxn.getPath(); - createNode(createTxn.getPath(), createTxn.getData(), createTxn - .getAcl(), createTxn.getEphemeral() ? header - .getClientId() : 0, header.getZxid(), header.getTime()); - rc.path = createTxn.getPath(); - break; - case OpCode.delete: - DeleteTxn deleteTxn = (DeleteTxn) txn; - debug = "Delete transaction for " + deleteTxn.getPath(); - deleteNode(deleteTxn.getPath()); - break; - case OpCode.setData: - SetDataTxn setDataTxn = (SetDataTxn) txn; - debug = "Set data for transaction for " + setDataTxn.getPath(); - rc.stat = setData(setDataTxn.getPath(), setDataTxn.getData(), - setDataTxn.getVersion(), header.getZxid(), header - .getTime()); - break; - case OpCode.setACL: - SetACLTxn setACLTxn = (SetACLTxn) txn; - rc.stat = setACL(setACLTxn.getPath(), setACLTxn.getAcl(), - setACLTxn.getVersion()); - break; - case OpCode.closeSession: - killSession(header.getClientId()); - break; - case OpCode.error: - ErrorTxn errTxn = (ErrorTxn) txn; - rc.err = errTxn.getErr(); - break; - } - } catch (KeeperException e) { - // These are expected errors since we take a lazy snapshot - if (initialized - || (e.getCode() != Code.NoNode && e.getCode() != Code.NodeExists)) { - ZooLog.logWarn(debug); - ZooLog.logException(e); - } - } - return rc; - } - - void killSession(long session) { - HashSet list = ephemerals.remove(session); - if (list != null) { - for (String path : list) { - try { - deleteNode(path); - ZooLog.logTextTraceMessage("Deleting ephemeral node " - + path + " for session " + session, - ZooLog.SESSION_TRACE_MASK); - } catch (KeeperException e) { - ZooLog.logException(e); - } - } - } - } - - void serializeNode(OutputArchive oa, String path) throws IOException, - InterruptedException { - DataNode node = getNode(path); - if (node == null) { - return; - } - ArrayList children = null; - synchronized (node) { - scount++; - oa.writeString(path, "path"); - oa.writeRecord(node, "node"); - children = new ArrayList(node.children); - } - if (children != null) { - Collections.sort(children); - for (String childName : children) { - String childPath = path + '/' + childName; - serializeNode(oa, childPath); - } - } - } - - int scount; - - public boolean initialized = false; - - public void serialize(OutputArchive oa, String tag) throws IOException, - InterruptedException { - scount = 0; - serializeNode(oa, ""); - // / marks end of stream - // we need to check if clear had been called in between the snapshot. - if (root != null) { - oa.writeString("/", "path"); - } - } - - public void deserialize(InputArchive ia, String tag) throws IOException { - nodes.clear(); - String path = ia.readString("path"); - while (!path.equals("/")) { - DataNode node = new DataNode(); - ia.readRecord(node, "node"); - nodes.put(path, node); - int lastSlash = path.lastIndexOf('/'); - if (lastSlash == -1) { - root = node; - } else { - String parentPath = path.substring(0, lastSlash); - node.parent = nodes.get(parentPath); - node.parent.children.add(path.substring(lastSlash + 1)); - long eowner = node.stat.getEphemeralOwner(); - if (eowner != 0) { - HashSet list = ephemerals.get(eowner); - if (list == null) { - list = new HashSet(); - ephemerals.put(eowner, list); - } - list.add(path); - } - } - path = ia.readString("path"); - } - nodes.put("/", root); - } - - public String dumpEphemerals() { - Set keys = ephemerals.keySet(); - StringBuffer sb = new StringBuffer("Sessions with Ephemerals (" - + keys.size() + "):\n"); - for (long k : keys) { - sb.append(Long.toHexString(k)); - sb.append(":\n"); - for (String path : ephemerals.get(k)) { - sb.append("\t" + path + "\n"); - } - } - return sb.toString(); - } - - public void removeCnxn(Watcher watcher) { - dataWatches.removeWatcher(watcher); - childWatches.removeWatcher(watcher); - } - - public void clear() { - root = null; - nodes.clear(); - ephemerals.clear(); - // dataWatches = null; - // childWatches = null; - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/FinalRequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/FinalRequestProcessor.java deleted file mode 100644 index e8b3300799a..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/FinalRequestProcessor.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; - -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.ZooDefs; -import com.yahoo.zookeeper.KeeperException.Code; -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.CreateResponse; -import com.yahoo.zookeeper.proto.ExistsRequest; -import com.yahoo.zookeeper.proto.ExistsResponse; -import com.yahoo.zookeeper.proto.GetACLRequest; -import com.yahoo.zookeeper.proto.GetACLResponse; -import com.yahoo.zookeeper.proto.GetChildrenRequest; -import com.yahoo.zookeeper.proto.GetChildrenResponse; -import com.yahoo.zookeeper.proto.GetDataRequest; -import com.yahoo.zookeeper.proto.GetDataResponse; -import com.yahoo.zookeeper.proto.ReplyHeader; -import com.yahoo.zookeeper.proto.SetACLResponse; -import com.yahoo.zookeeper.proto.SetDataResponse; -import com.yahoo.zookeeper.server.DataTree.ProcessTxnResult; -import com.yahoo.zookeeper.txn.CreateSessionTxn; -import com.yahoo.zookeeper.txn.ErrorTxn; - -/** - * This Request processor actually applies any transaction associated with a - * request and services any queries. It is always at the end of a - * RequestProcessor chain (hence the name), so it does not have a nextProcessor - * member. - * - * This RequestProcessor counts on ZooKeeperServer to populate the - * outstandingRequests member of ZooKeeperServer. - */ -public class FinalRequestProcessor implements RequestProcessor { - ZooKeeperServer zks; - - long avg; - - long count; - - public FinalRequestProcessor(ZooKeeperServer zks) { - this.zks = zks; - } - - public void processRequest(Request request) { - // ZooLog.logWarn("Zoo>>> cxid = " + request.cxid + " type = " + - // request.type + " id = " + request.sessionId + " cnxn " + - // request.cnxn); - // request.addRQRec(">final"); - long traceMask = ZooLog.CLIENT_REQUEST_TRACE_MASK; - if (request.type == OpCode.ping) { - traceMask = ZooLog.SERVER_PING_TRACE_MASK; - } - ZooLog.logRequest('E', request, "", traceMask); - ProcessTxnResult rc = null; - synchronized (zks.outstandingChanges) { - while (!zks.outstandingChanges.isEmpty() - && zks.outstandingChanges.get(0).zxid <= request.zxid) { - if (zks.outstandingChanges.get(0).zxid < request.zxid) { - ZooLog.logError("Zxid outstanding " - + zks.outstandingChanges.get(0).zxid - + " is less than current " + request.zxid); - } - zks.outstandingChanges.remove(0); - } - if (request.hdr != null) { - rc = zks.dataTree.processTxn(request.hdr, request.txn); - if (request.type == OpCode.createSession) { - if (request.txn instanceof CreateSessionTxn) { - CreateSessionTxn cst = (CreateSessionTxn) request.txn; - zks.sessionTracker.addSession(request.sessionId, cst - .getTimeOut()); - } else { - ZooLog.logWarn("*****>>>>> Got " - + request.txn.getClass() + " " - + request.txn.toString()); - } - } else if (request.type == OpCode.closeSession) { - zks.sessionTracker.removeSession(request.sessionId); - } - } - } - - if (request.hdr != null && request.hdr.getType() == OpCode.closeSession) { - zks.getServerCnxnFactory().closeSession(request.sessionId); - } - if (request.cnxn == null) { - return; - } - zks.decInProcess(); - int err = 0; - Record rsp = null; - try { - if (request.hdr != null && request.hdr.getType() == OpCode.error) { - throw new KeeperException(((ErrorTxn) request.txn).getErr()); - } - switch (request.type) { - case OpCode.ping: - request.cnxn.sendResponse(new ReplyHeader(-2, - zks.dataTree.lastProcessedZxid, 0), null, "response"); - return; - case OpCode.createSession: - request.cnxn.finishSessionInit(true); - return; - case OpCode.create: - rsp = new CreateResponse(rc.path); - err = rc.err; - break; - case OpCode.delete: - err = rc.err; - break; - case OpCode.setData: - rsp = new SetDataResponse(rc.stat); - err = rc.err; - break; - case OpCode.setACL: - rsp = new SetACLResponse(rc.stat); - err = rc.err; - break; - case OpCode.closeSession: - err = rc.err; - break; - case OpCode.exists: - // TODO we need to figure out the security requirement for this! - ExistsRequest existsRequest = new ExistsRequest(); - ZooKeeperServer.byteBuffer2Record(request.request, - existsRequest); - String path = existsRequest.getPath(); - if (path.indexOf('\0') != -1) { - throw new KeeperException(Code.BadArguments); - } - Stat stat = zks.dataTree.statNode(path, existsRequest - .getWatch() ? request.cnxn : null); - rsp = new ExistsResponse(stat); - break; - case OpCode.getData: - GetDataRequest getDataRequest = new GetDataRequest(); - ZooKeeperServer.byteBuffer2Record(request.request, - getDataRequest); - DataNode n = zks.dataTree.getNode(getDataRequest.getPath()); - if (n == null) { - throw new KeeperException(Code.NoNode); - } - PrepRequestProcessor.checkACL(zks, n.acl, ZooDefs.Perms.READ, - request.authInfo); - stat = new Stat(); - byte b[] = zks.dataTree.getData(getDataRequest.getPath(), stat, - getDataRequest.getWatch() ? request.cnxn : null); - rsp = new GetDataResponse(b, stat); - break; - case OpCode.getACL: - GetACLRequest getACLRequest = new GetACLRequest(); - ZooKeeperServer.byteBuffer2Record(request.request, - getACLRequest); - stat = new Stat(); - ArrayList acl = zks.dataTree.getACL(getACLRequest - .getPath(), stat); - rsp = new GetACLResponse(acl, stat); - break; - case OpCode.getChildren: - GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); - ZooKeeperServer.byteBuffer2Record(request.request, - getChildrenRequest); - stat = new Stat(); - n = zks.dataTree.getNode(getChildrenRequest.getPath()); - if (n == null) { - throw new KeeperException(Code.NoNode); - } - PrepRequestProcessor.checkACL(zks, n.acl, ZooDefs.Perms.READ, - request.authInfo); - ArrayList children = zks.dataTree.getChildren( - getChildrenRequest.getPath(), stat, getChildrenRequest - .getWatch() ? request.cnxn : null); - rsp = new GetChildrenResponse(children); - break; - } - } catch (KeeperException e) { - err = e.getCode(); - } catch (Exception e) { - ZooLog.logWarn("****************************** " + request); - StringBuffer sb = new StringBuffer(); - ByteBuffer bb = request.request; - bb.rewind(); - while (bb.hasRemaining()) { - sb.append(Integer.toHexString(bb.get() & 0xff)); - } - ZooLog.logWarn(sb.toString()); - ZooLog.logException(e); - err = Code.MarshallingError; - } - ReplyHeader hdr = new ReplyHeader(request.cxid, request.zxid, err); - long latency = System.currentTimeMillis() - request.createTime; - count++; - avg += latency; - request.cnxn.setStats(latency, (avg / count)); - try { - request.cnxn.sendResponse(hdr, rsp, "response"); - } catch (IOException e) { - ZooLog.logException(e); - } - } - - public void shutdown() { - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/LogFormatter.java b/zookeeper/java/src/com/yahoo/zookeeper/server/LogFormatter.java deleted file mode 100644 index ed665f7c5e1..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/LogFormatter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.ByteArrayInputStream; -import java.io.EOFException; -import java.io.FileInputStream; -import java.text.DateFormat; -import java.util.Date; - -import com.yahoo.jute.BinaryInputArchive; -import com.yahoo.jute.InputArchive; -import com.yahoo.zookeeper.txn.TxnHeader; - -public class LogFormatter { - - /** - * @param args - */ - public static void main(String[] args) throws Exception { - if (args.length != 1) { - System.err.println("USAGE: LogFormatter log_file"); - System.exit(2); - } - FileInputStream fis = new FileInputStream(args[0]); - BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis); - while (true) { - byte[] bytes = logStream.readBuffer("txnEntry"); - if (bytes.length == 0) { - // Since we preallocate, we define EOF to be an - // empty transaction - throw new EOFException(); - } - InputArchive ia = BinaryInputArchive - .getArchive(new ByteArrayInputStream(bytes)); - TxnHeader hdr = new TxnHeader(); - hdr.deserialize(ia, "hdr"); - System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.LONG).format(new Date(hdr.getTime())) - + " " - + Long.toHexString(hdr.getClientId()) - + ":" - + hdr.getCxid() - + " " - + Long.toHexString(hdr.getZxid()) - + " " + TraceFormatter.op2String(hdr.getType())); - if (logStream.readByte("EOR") != 'B') { - ZooLog.logError("Last transaction was partial."); - throw new EOFException(); - } - } - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/NIOServerCnxn.java b/zookeeper/java/src/com/yahoo/zookeeper/server/NIOServerCnxn.java deleted file mode 100644 index 457508ccf03..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/NIOServerCnxn.java +++ /dev/null @@ -1,815 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.nio.ByteBuffer; -import java.nio.channels.CancelledKeyException; -import java.nio.channels.Channel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.jute.BinaryInputArchive; -import com.yahoo.jute.BinaryOutputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.proto.AuthPacket; -import com.yahoo.zookeeper.proto.ConnectRequest; -import com.yahoo.zookeeper.proto.ConnectResponse; -import com.yahoo.zookeeper.proto.ReplyHeader; -import com.yahoo.zookeeper.proto.RequestHeader; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.auth.AuthenticationProvider; -import com.yahoo.zookeeper.server.quorum.FollowerHandler; -import com.yahoo.zookeeper.server.quorum.QuorumPeer; - -/** - * This class handles communication with clients using NIO. There is one per - * client, but only one thread doing the communication. - */ -public class NIOServerCnxn implements Watcher, ServerCnxn { - static public class Factory extends Thread { - ZooKeeperServer zks; - - ServerSocketChannel ss; - - Selector selector = Selector.open(); - - int packetsSent; - - int packetsReceived; - - HashSet cnxns = new HashSet(); - - QuorumPeer self; - - long avgLatency; - - long maxLatency; - - long minLatency = 99999999; - - int outstandingLimit = 1; - - void setStats(long latency, long avg) { - this.avgLatency = avg; - if (latency < minLatency) { - minLatency = latency; - } - if (latency > maxLatency) { - maxLatency = latency; - } - } - - public Factory(int port) throws IOException { - super("NIOServerCxn.Factory"); - setDaemon(true); - this.ss = ServerSocketChannel.open(); - ss.socket().bind(new InetSocketAddress(port)); - ss.configureBlocking(false); - ss.register(selector, SelectionKey.OP_ACCEPT); - start(); - } - - public Factory(int port, QuorumPeer self) throws IOException { - this(port); - this.self = self; - } - - public void startup(ZooKeeperServer zks) throws IOException, - InterruptedException { - zks.startup(); - setZooKeeperServer(zks); - } - - public void setZooKeeperServer(ZooKeeperServer zks) { - this.zks = zks; - if (zks != null) { - this.outstandingLimit = zks.getGlobalOutstandingLimit(); - zks.setServerCnxnFactory(this); - } else { - this.outstandingLimit = 1; - } - } - - private void addCnxn(NIOServerCnxn cnxn) { - synchronized (cnxns) { - cnxns.add(cnxn); - } - } - - public void run() { - while (!ss.socket().isClosed()) { - try { - selector.select(1000); - Set selected; - synchronized (this) { - selected = selector.selectedKeys(); - } - for (SelectionKey k : selected) { - if ((k.readyOps() & SelectionKey.OP_ACCEPT) != 0) { - SocketChannel sc = ((ServerSocketChannel) k - .channel()).accept(); - sc.configureBlocking(false); - SelectionKey sk = sc.register(selector, - SelectionKey.OP_READ); - NIOServerCnxn cnxn = new NIOServerCnxn(zks, sc, sk, - this); - sk.attach(cnxn); - addCnxn(cnxn); - } else if ((k.readyOps() & (SelectionKey.OP_READ | SelectionKey.OP_WRITE)) != 0) { - NIOServerCnxn c = (NIOServerCnxn) k.attachment(); - c.doIO(k); - } - } - selected.clear(); - } catch (Exception e) { - ZooLog.logException(e); - } - } - ZooLog.logTextTraceMessage("NIOServerCnxn factory exitedloop.", - ZooLog.textTraceMask); - clear(); - ZooLog.logError("=====> Goodbye cruel world <======"); - // System.exit(0); - } - - /** - * clear all the connections in the selector - * - */ - synchronized public void clear() { - selector.wakeup(); - synchronized (cnxns) { - // got to clear all the connections that we have in the selector - for (Iterator it = cnxns.iterator(); it - .hasNext();) { - NIOServerCnxn cnxn = it.next(); - it.remove(); - try { - cnxn.close(); - } catch (Exception e) { - // Do nothing. - } - } - } - - } - - public void shutdown() { - try { - ss.close(); - clear(); - this.interrupt(); - this.join(); - } catch (Exception e) { - ZooLog.logException(e); - } - if (zks != null) { - zks.shutdown(); - } - } - - synchronized void closeSession(long sessionId) { - selector.wakeup(); - synchronized (cnxns) { - for (Iterator it = cnxns.iterator(); it - .hasNext();) { - NIOServerCnxn cnxn = it.next(); - if (cnxn.sessionId == sessionId) { - it.remove(); - try { - cnxn.close(); - } catch (Exception e) { - } - break; - } - } - } - } - } - - /** - * The buffer will cause the connection to be close when we do a send. - */ - static final ByteBuffer closeConn = ByteBuffer.allocate(0); - - Factory factory; - - ZooKeeperServer zk; - - private SocketChannel sock; - - private SelectionKey sk; - - boolean initialized; - - ByteBuffer lenBuffer = ByteBuffer.allocate(4); - - ByteBuffer incomingBuffer = lenBuffer; - - LinkedBlockingQueue outgoingBuffers = new LinkedBlockingQueue(); - - int sessionTimeout; - - int packetsSent; - - int packetsReceived; - - ArrayList authInfo = new ArrayList(); - - LinkedList outstanding = new LinkedList(); - - void sendBuffer(ByteBuffer bb) { - synchronized (factory) { - try { - sk.selector().wakeup(); - // ZooLog.logTextTraceMessage("Add a buffer to outgoingBuffers", - // ZooLog.CLIENT_DATA_PACKET_TRACE_MASK); - // ZooLog.logTextTraceMessage("sk " + sk + " is valid: " + - // sk.isValid(), ZooLog.CLIENT_DATA_PACKET_TRACE_MASK); - outgoingBuffers.add(bb); - if (sk.isValid()) { - sk.interestOps(sk.interestOps() | SelectionKey.OP_WRITE); - } - } catch (RuntimeException e) { - ZooLog.logException(e); - throw e; - } - } - } - - void doIO(SelectionKey k) throws InterruptedException { - try { - if (sock == null) { - return; - } - if (k.isReadable()) { - int rc = sock.read(incomingBuffer); - if (rc < 0) { - throw new IOException("Read error"); - } - if (incomingBuffer.remaining() == 0) { - incomingBuffer.flip(); - if (incomingBuffer == lenBuffer) { - readLength(k); - } else if (!initialized) { - packetsReceived++; - factory.packetsReceived++; - readConnectRequest(); - lenBuffer.clear(); - incomingBuffer = lenBuffer; - } else { - packetsReceived++; - factory.packetsReceived++; - readRequest(); - lenBuffer.clear(); - incomingBuffer = lenBuffer; - } - } - } - if (k.isWritable()) { - // ZooLog.logTextTraceMessage("outgoingBuffers.size() = " + - // outgoingBuffers.size(), - // ZooLog.CLIENT_DATA_PACKET_TRACE_MASK); - if (outgoingBuffers.size() > 0) { - // ZooLog.logTextTraceMessage("sk " + k + " is valid: " + - // k.isValid(), ZooLog.CLIENT_DATA_PACKET_TRACE_MASK); - ByteBuffer bbs[] = outgoingBuffers - .toArray(new ByteBuffer[0]); - // Write as much as we can - long i = sock.write(bbs); - ByteBuffer bb; - // Remove the buffers that we have sent - while (outgoingBuffers.size() > 0 - && (bb = outgoingBuffers.peek()).remaining() == 0) { - if (bb == closeConn) { - throw new IOException("closing"); - } - if (bb.remaining() > 0) { - break; - } - packetsSent++; - factory.packetsSent++; - outgoingBuffers.remove(); - } - // ZooLog.logTextTraceMessage("after send, - // outgoingBuffers.size() = " + outgoingBuffers.size(), - // ZooLog.CLIENT_DATA_PACKET_TRACE_MASK); - } - synchronized (this) { - if (outgoingBuffers.size() == 0) { - if (!initialized - && (sk.interestOps() & SelectionKey.OP_READ) == 0) { - throw new IOException("Responded to info probe"); - } - sk.interestOps(sk.interestOps() - & (~SelectionKey.OP_WRITE)); - } else { - sk - .interestOps(sk.interestOps() - | SelectionKey.OP_WRITE); - } - } - } - } catch (CancelledKeyException e) { - close(); - } catch (IOException e) { - // ZooLog.logException(e); - close(); - } - } - - private void readRequest() throws IOException { - // We have the request, now process and setup for next - InputStream bais = new ByteBufferInputStream(incomingBuffer); - BinaryInputArchive bia = BinaryInputArchive.getArchive(bais); - RequestHeader h = new RequestHeader(); - h.deserialize(bia, "header"); - // Through the magic of byte buffers, txn will not be - // pointing - // to the start of the txn - incomingBuffer = incomingBuffer.slice(); - if (h.getType() == OpCode.auth) { - AuthPacket authPacket = new AuthPacket(); - ZooKeeperServer.byteBuffer2Record(incomingBuffer, authPacket); - String scheme = authPacket.getScheme(); - AuthenticationProvider ap = zk.authenticationProviders.get(scheme); - if (ap == null - || ap.handleAuthentication(this, authPacket.getAuth()) != KeeperException.Code.Ok) { - if (ap == null) - ZooLog.logError("No authentication provider for scheme: " - + scheme); - else - ZooLog.logError("Authentication failed for scheme: " - + scheme); - // send a response... - ReplyHeader rh = new ReplyHeader(h.getXid(), 0, - KeeperException.Code.AuthFailed); - sendResponse(rh, null, null); - // ... and close connection - sendBuffer(NIOServerCnxn.closeConn); - disableRecv(); - } else { - ZooLog.logError("Authentication succeeded for scheme: " - + scheme); - ReplyHeader rh = new ReplyHeader(h.getXid(), 0, - KeeperException.Code.Ok); - sendResponse(rh, null, null); - } - return; - } else { - zk.submitRequest(this, sessionId, h.getType(), h.getXid(), - incomingBuffer, authInfo); - } - if (h.getXid() >= 0) { - synchronized (this) { - outstandingRequests++; - // check throttling - if (zk.getInProcess() > factory.outstandingLimit) { - disableRecv(); - // following lines should not be needed since we are already - // reading - // } else { - // enableRecv(); - } - } - } - } - - public void disableRecv() { - sk.interestOps(sk.interestOps() & (~SelectionKey.OP_READ)); - } - - public void enableRecv() { - if (sk.isValid()) { - int interest = sk.interestOps(); - if ((interest & SelectionKey.OP_READ) == 0) { - sk.interestOps(interest | SelectionKey.OP_READ); - } - } - } - - private void readConnectRequest() throws IOException, InterruptedException { - BinaryInputArchive bia = BinaryInputArchive - .getArchive(new ByteBufferInputStream(incomingBuffer)); - ConnectRequest connReq = new ConnectRequest(); - connReq.deserialize(bia, "connect"); - ZooLog.logWarn("Connected to " + sock.socket().getRemoteSocketAddress() - + " lastZxid " + connReq.getLastZxidSeen()); - if (zk == null) { - throw new IOException("ZooKeeperServer not running"); - } - if (connReq.getLastZxidSeen() > zk.dataTree.lastProcessedZxid) { - ZooLog.logError("Client has seen " - + Long.toHexString(connReq.getLastZxidSeen()) - + " our last zxid is " - + Long.toHexString(zk.dataTree.lastProcessedZxid)); - throw new IOException("We are out of date"); - } - sessionTimeout = connReq.getTimeOut(); - sessionId = connReq.getSessionId(); - byte passwd[] = connReq.getPasswd(); - if (sessionTimeout < zk.tickTime * 2) { - sessionTimeout = zk.tickTime * 2; - } - if (sessionTimeout > zk.tickTime * 20) { - sessionTimeout = zk.tickTime * 20; - } - // We don't want to receive any packets until we are sure that the - // session is setup - disableRecv(); - if (sessionId != 0) { - zk.reopenSession(this, sessionId, passwd, sessionTimeout); - ZooLog.logWarn("Renewing session " + Long.toHexString(sessionId)); - } else { - zk.createSession(this, passwd, sessionTimeout); - ZooLog.logWarn("Creating new session " - + Long.toHexString(sessionId)); - } - initialized = true; - } - - private void readLength(SelectionKey k) throws IOException { - // Read the length, now get the buffer - int len = lenBuffer.getInt(); - if (!initialized) { - // We take advantage of the limited size of the length to look - // for cmds. They are all 4-bytes which fits inside of an int - if (len == ruokCmd) { - sendBuffer(imok.duplicate()); - sendBuffer(NIOServerCnxn.closeConn); - k.interestOps(SelectionKey.OP_WRITE); - return; - } else if (len == killCmd) { - System.exit(0); - } else if (len == getTraceMaskCmd) { - long traceMask = ZooLog.getTextTraceLevel(); - ByteBuffer resp = ByteBuffer.allocate(8); - resp.putLong(traceMask); - resp.flip(); - sendBuffer(resp); - sendBuffer(NIOServerCnxn.closeConn); - k.interestOps(SelectionKey.OP_WRITE); - return; - } else if (len == setTraceMaskCmd) { - incomingBuffer = ByteBuffer.allocate(8); - - int rc = sock.read(incomingBuffer); - if (rc < 0) { - throw new IOException("Read error"); - } - System.out.println("rc=" + rc); - incomingBuffer.flip(); - long traceMask = incomingBuffer.getLong(); - ZooLog.setTextTraceLevel(traceMask); - ByteBuffer resp = ByteBuffer.allocate(8); - resp.putLong(traceMask); - resp.flip(); - sendBuffer(resp); - sendBuffer(NIOServerCnxn.closeConn); - k.interestOps(SelectionKey.OP_WRITE); - return; - } else if (len == dumpCmd) { - if (zk == null) { - sendBuffer(ByteBuffer.wrap("ZooKeeper not active \n" - .getBytes())); - } else { - StringBuffer sb = new StringBuffer(); - sb.append("SessionTracker dump: \n"); - sb.append(zk.sessionTracker.toString()).append("\n"); - sb.append("ephemeral nodes dump:\n"); - sb.append(zk.dataTree.dumpEphemerals()).append("\n"); - sendBuffer(ByteBuffer.wrap(sb.toString().getBytes())); - } - k.interestOps(SelectionKey.OP_WRITE); - return; - } else if (len == reqsCmd) { - StringBuffer sb = new StringBuffer(); - sb.append("Requests:\n"); - synchronized (outstanding) { - for (Request r : outstanding) { - sb.append(r.toString()); - sb.append('\n'); - } - } - sendBuffer(ByteBuffer.wrap(sb.toString().getBytes())); - k.interestOps(SelectionKey.OP_WRITE); - return; - } else if (len == statCmd) { - StringBuffer sb = new StringBuffer(); - sb.append("Clients:\n"); - for (SelectionKey sk : factory.selector.keys()) { - Channel channel = sk.channel(); - if (channel instanceof SocketChannel) { - NIOServerCnxn cnxn = (NIOServerCnxn) sk.attachment(); - sb.append(" " - + ((SocketChannel) channel).socket() - .getRemoteSocketAddress() + "[" - + Integer.toHexString(sk.interestOps()) - + "](queued=" + cnxn.outstandingRequests - + ",recved=" + cnxn.packetsReceived + ",sent=" - + cnxn.packetsSent + ")\n"); - } - } - sb.append("\n"); - sb.append("Latency min/avg/max: " + factory.minLatency + "/" - + factory.avgLatency + "/" + factory.maxLatency + "\n"); - sb.append("Received: " + factory.packetsReceived + "\n"); - sb.append("Sent: " + factory.packetsSent + "\n"); - if (zk != null) { - sb.append("Outstanding: " + zk.getInProcess() + "\n"); - sb.append("Zxid: " - + Long.toHexString(zk.dataTree.lastProcessedZxid) - + "\n"); - } - // sb.append("Done: " + ZooKeeperServer.getRequests() + "\n"); - if (factory.self == null) { - sb.append("Mode: standalone\n"); - } else { - switch (factory.self.state) { - case LOOKING: - sb.append("Mode: leaderelection\n"); - break; - case LEADING: - sb.append("Mode: leading\n"); - sb.append("Followers:"); - for (FollowerHandler fh : factory.self.leader.followers) { - if (fh.s == null) { - continue; - } - sb.append(" "); - sb.append(fh.s.getRemoteSocketAddress()); - if (factory.self.leader.forwardingFollowers - .contains(fh)) { - sb.append("*"); - } - } - sb.append("\n"); - break; - case FOLLOWING: - sb.append("Mode: following\n"); - sb.append("Leader: "); - Socket s = factory.self.follower.sock; - if (s == null) { - sb.append("not connected\n"); - } else { - sb.append(s.getRemoteSocketAddress() + "\n"); - } - } - } - sendBuffer(ByteBuffer.wrap(sb.toString().getBytes())); - k.interestOps(SelectionKey.OP_WRITE); - return; - } - } - if (len < 0 || len > 0xfffff) { - throw new IOException("Len error " + len); - } - if (zk == null) { - throw new IOException("ZooKeeperServer not running"); - } - incomingBuffer = ByteBuffer.allocate(len); - } - - /** - * The number of requests that have been submitted but not yet responded to. - */ - int outstandingRequests; - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.server.ServerCnxnIface#getSessionTimeout() - */ - public int getSessionTimeout() { - return sessionTimeout; - } - - /** - * This is the id that uniquely identifies the session of a client. Once - * this session is no longer active, the ephemeral nodes will go away. - */ - long sessionId; - - static long nextSessionId = 1; - - public NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock, - SelectionKey sk, Factory factory) throws IOException { - this.zk = zk; - this.sock = sock; - this.sk = sk; - this.factory = factory; - sock.socket().setTcpNoDelay(true); - sock.socket().setSoLinger(true, 2); - InetAddress addr = ((InetSocketAddress) sock.socket() - .getRemoteSocketAddress()).getAddress(); - authInfo.add(new Id("ip", addr.getHostAddress())); - authInfo.add(new Id("host", addr.getCanonicalHostName())); - sk.interestOps(SelectionKey.OP_READ); - } - - public String toString() { - return "NIOServerCnxn object with sock = " + sock + " and sk = " + sk; - } - - boolean closed; - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.server.ServerCnxnIface#close() - */ - public void close() { - if (closed) { - return; - } - closed = true; - synchronized (factory.cnxns) { - factory.cnxns.remove(this); - } - if (zk != null) { - zk.removeCnxn(this); - } - - ZooLog.logTextTraceMessage("close NIOServerCnxn: " + sock, - ZooLog.SESSION_TRACE_MASK); - try { - /* - * The following sequence of code is stupid! You would think that - * only sock.close() is needed, but alas, it doesn't work that way. - * If you just do sock.close() there are cases where the socket - * doesn't actually close... - */ - sock.socket().shutdownOutput(); - } catch (IOException e) { - // This is a relatively common exception that we can't avoid - } - try { - sock.socket().shutdownInput(); - } catch (IOException e) { - } - try { - sock.socket().close(); - } catch (IOException e) { - ZooLog.logException(e); - } - try { - sock.close(); - // XXX The next line doesn't seem to be needed, but some posts - // to forums suggest that it is needed. Keep in mind if errors in - // this section arise. - // factory.selector.wakeup(); - } catch (IOException e) { - ZooLog.logException(e); - } - sock = null; - if (sk != null) { - try { - // need to cancel this selection key from the selector - sk.cancel(); - } catch (Exception e) { - } - } - } - - private final static byte fourBytes[] = new byte[4]; - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.server.ServerCnxnIface#sendResponse(com.yahoo.zookeeper.proto.ReplyHeader, - * com.yahoo.jute.Record, java.lang.String) - */ - synchronized public void sendResponse(ReplyHeader h, Record r, String tag) { - if (closed) { - return; - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - // Make space for length - BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos); - try { - baos.write(fourBytes); - bos.writeRecord(h, "header"); - if (r != null) { - bos.writeRecord(r, tag); - } - baos.close(); - } catch (IOException e) { - ZooLog.logError("Error serializing response"); - } - byte b[] = baos.toByteArray(); - ByteBuffer bb = ByteBuffer.wrap(b); - bb.putInt(b.length - 4).rewind(); - sendBuffer(bb); - if (h.getXid() > 0) { - synchronized (this.factory) { - outstandingRequests--; - // check throttling - if (zk.getInProcess() < factory.outstandingLimit - || outstandingRequests < 1) { - sk.selector().wakeup(); - enableRecv(); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.server.ServerCnxnIface#process(com.yahoo.zookeeper.proto.WatcherEvent) - */ - synchronized public void process(WatcherEvent event) { - ReplyHeader h = new ReplyHeader(-1, -1L, 0); - ZooLog.logTextTraceMessage("Deliver event " + event + " to " - + this.sessionId + " through " + this, - ZooLog.EVENT_DELIVERY_TRACE_MASK); - sendResponse(h, event, "notification"); - } - - public void finishSessionInit(boolean valid) { - try { - ConnectResponse rsp = new ConnectResponse(0, valid ? sessionTimeout - : 0, valid ? sessionId : 0, // send 0 if session is no - // longer valid - valid ? zk.generatePasswd(sessionId) : new byte[16]); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos); - bos.writeInt(-1, "len"); - rsp.serialize(bos, "connect"); - baos.close(); - ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); - bb.putInt(bb.remaining() - 4).rewind(); - sendBuffer(bb); - ZooLog.logWarn("Finished init of " + Long.toHexString(sessionId) - + ": " + valid); - if (!valid) { - sendBuffer(closeConn); - } - // Now that the session is ready we can start receiving packets - synchronized (this.factory) { - sk.selector().wakeup(); - enableRecv(); - } - } catch (Exception e) { - ZooLog.logException(e); - close(); - } - } - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.server.ServerCnxnIface#getSessionId() - */ - public long getSessionId() { - return sessionId; - } - - public void setSessionId(long sessionId) { - this.sessionId = sessionId; - } - - public ArrayList getAuthInfo() { - return authInfo; - } - - public InetSocketAddress getRemoteAddress() { - return (InetSocketAddress) sock.socket().getRemoteSocketAddress(); - } - - public void setStats(long latency, long avg) { - factory.setStats(latency, avg); - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/PrepRequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/PrepRequestProcessor.java deleted file mode 100644 index f17d4a30385..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/PrepRequestProcessor.java +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.ZooDefs; -import com.yahoo.zookeeper.KeeperException.Code; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.CreateRequest; -import com.yahoo.zookeeper.proto.DeleteRequest; -import com.yahoo.zookeeper.proto.SetACLRequest; -import com.yahoo.zookeeper.proto.SetDataRequest; -import com.yahoo.zookeeper.server.ZooKeeperServer.ChangeRecord; -import com.yahoo.zookeeper.server.auth.AuthenticationProvider; -import com.yahoo.zookeeper.txn.CreateSessionTxn; -import com.yahoo.zookeeper.txn.CreateTxn; -import com.yahoo.zookeeper.txn.DeleteTxn; -import com.yahoo.zookeeper.txn.ErrorTxn; -import com.yahoo.zookeeper.txn.SetACLTxn; -import com.yahoo.zookeeper.txn.SetDataTxn; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * This request processor is generally at the start of a RequestProcessor - * change. It sets up any transactions associated with requests that change the - * state of the system. It counts on ZooKeeperServer to update - * outstandingRequests, so that it can take into account transactions that are - * in the queue to be applied when generating a transaction. - */ -public class PrepRequestProcessor extends Thread implements RequestProcessor { - static boolean skipACL; - static { - skipACL = System.getProperty("zookeeper.skipACL", "no").equals("yes"); - } - - LinkedBlockingQueue submittedRequests = new LinkedBlockingQueue(); - - RequestProcessor nextProcessor; - - ZooKeeperServer zks; - - public PrepRequestProcessor(ZooKeeperServer zks, - RequestProcessor nextProcessor) { - super("ProcessThread"); - this.nextProcessor = nextProcessor; - this.zks = zks; - - start(); - } - - public void run() { - try { - while (true) { - Request request = submittedRequests.take(); - long traceMask = ZooLog.CLIENT_REQUEST_TRACE_MASK; - if (request.type == OpCode.ping) { - traceMask = ZooLog.CLIENT_PING_TRACE_MASK; - } - ZooLog.logRequest('P', request, "", traceMask); - if (Request.requestOfDeath == request) { - break; - } - pRequest(request); - } - } catch (InterruptedException e) { - ZooLog.logException(e); - } - ZooLog.logTextTraceMessage("PrepRequestProcessor exited loop!", - ZooLog.textTraceMask); - } - - ChangeRecord getRecordForPath(String path) throws KeeperException { - ChangeRecord lastChange = null; - synchronized (zks.outstandingChanges) { - for (int i = 0; i < zks.outstandingChanges.size(); i++) { - ChangeRecord c = zks.outstandingChanges.get(i); - if (c.path.equals(path)) { - lastChange = c; - } - } - if (lastChange == null) { - DataNode n = zks.dataTree.getNode(path); - if (n != null) { - lastChange = new ChangeRecord(-1, path, n.stat, n.children - .size(), n.acl); - } - } - } - if (lastChange == null || lastChange.stat == null) { - throw new KeeperException(KeeperException.Code.NoNode); - } - return lastChange; - } - - void addChangeRecord(ChangeRecord c) { - synchronized (zks.outstandingChanges) { - zks.outstandingChanges.add(c); - } - } - - static void checkACL(ZooKeeperServer zks, ArrayList acl, int perm, - ArrayList ids) throws KeeperException { - if (skipACL) { - return; - } - if (acl == null || acl.size() == 0) { - return; - } - for (ACL a : acl) { - Id id = a.getId(); - if ((a.getPerms() & perm) != 0) { - if (id.getScheme().equals("world") - && id.getId().equals("anyone")) { - return; - } - AuthenticationProvider ap = zks.authenticationProviders.get(id - .getScheme()); - if (ap != null) { - for (Id authId : ids) { - if (authId.getScheme().equals("super")) { - return; - } - if (authId.getScheme().equals(id.getScheme()) - && ap.matches(authId.getId(), id.getId())) { - return; - } - } - } - } - } - throw new KeeperException(KeeperException.Code.NoAuth); - } - - /** - * This method will be called inside the ProcessRequestThread, which is a - * singleton, so there will be a single thread calling this code. - * - * @param request - */ - @SuppressWarnings("unchecked") - protected void pRequest(Request request) { - // ZooLog.logWarn("Prep>>> cxid = " + request.cxid + " type = " + - // request.type + " id = " + request.sessionId); - TxnHeader txnHeader = null; - Record txn = null; - try { - switch (request.type) { - case OpCode.create: - txnHeader = new TxnHeader(request.sessionId, request.cxid, zks - .getNextZxid(), zks.getTime(), OpCode.create); - zks.sessionTracker.checkSession(request.sessionId); - CreateRequest createRequest = new CreateRequest(); - ZooKeeperServer.byteBuffer2Record(request.request, - createRequest); - String path = createRequest.getPath(); - int lastSlash = path.lastIndexOf('/'); - if (lastSlash == -1 || path.indexOf('\0') != -1) { - throw new KeeperException(Code.BadArguments); - } - if (!fixupACL(request.authInfo, createRequest.getAcl())) { - throw new KeeperException(Code.InvalidACL); - } - String parentPath = path.substring(0, lastSlash); - ChangeRecord parentRecord = getRecordForPath(parentPath); - - checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE, - request.authInfo); - int parentCVersion = parentRecord.stat.getCversion(); - if ((createRequest.getFlags() & CreateFlags.SEQUENCE) != 0) { - path = path + parentCVersion; - } - try { - if (getRecordForPath(path) != null) { - throw new KeeperException(Code.NodeExists); - } - } catch (KeeperException e) { - if (e.getCode() != Code.NoNode) { - throw e; - } - } - boolean ephemeralParent = parentRecord.stat.getEphemeralOwner() != 0; - if (ephemeralParent) { - throw new KeeperException(Code.NoChildrenForEphemerals); - } - txn = new CreateTxn(path, createRequest.getData(), - createRequest.getAcl(), - (createRequest.getFlags() & CreateFlags.EPHEMERAL) != 0); - Stat s = new Stat(); - if ((createRequest.getFlags() & CreateFlags.EPHEMERAL) != 0) { - s.setEphemeralOwner(request.sessionId); - } - parentRecord = parentRecord.duplicate(txnHeader.getZxid()); - parentRecord.childCount++; - parentRecord.stat - .setCversion(parentRecord.stat.getCversion() + 1); - addChangeRecord(parentRecord); - addChangeRecord(new ChangeRecord(txnHeader.getZxid(), path, s, - 0, createRequest.getAcl())); - - break; - case OpCode.delete: - txnHeader = new TxnHeader(request.sessionId, request.cxid, zks - .getNextZxid(), zks.getTime(), OpCode.delete); - zks.sessionTracker.checkSession(request.sessionId); - DeleteRequest deleteRequest = new DeleteRequest(); - ZooKeeperServer.byteBuffer2Record(request.request, - deleteRequest); - path = deleteRequest.getPath(); - lastSlash = path.lastIndexOf('/'); - if (lastSlash == -1 || path.indexOf('\0') != -1 - || path.equals("/")) { - throw new KeeperException(Code.BadArguments); - } - parentPath = path.substring(0, lastSlash); - parentRecord = getRecordForPath(parentPath); - ChangeRecord nodeRecord = getRecordForPath(path); - checkACL(zks, parentRecord.acl, ZooDefs.Perms.DELETE, - request.authInfo); - int version = deleteRequest.getVersion(); - if (version != -1 && nodeRecord.stat.getVersion() != version) { - throw new KeeperException(Code.BadVersion); - } - if (nodeRecord.childCount > 0) { - throw new KeeperException(Code.NotEmpty); - } - txn = new DeleteTxn(path); - parentRecord = parentRecord.duplicate(txnHeader.getZxid()); - parentRecord.childCount--; - parentRecord.stat - .setCversion(parentRecord.stat.getCversion() + 1); - addChangeRecord(parentRecord); - addChangeRecord(new ChangeRecord(txnHeader.getZxid(), path, - null, -1, null)); - break; - case OpCode.setData: - txnHeader = new TxnHeader(request.sessionId, request.cxid, zks - .getNextZxid(), zks.getTime(), OpCode.setData); - zks.sessionTracker.checkSession(request.sessionId); - SetDataRequest setDataRequest = new SetDataRequest(); - ZooKeeperServer.byteBuffer2Record(request.request, - setDataRequest); - path = setDataRequest.getPath(); - nodeRecord = getRecordForPath(path); - checkACL(zks, nodeRecord.acl, ZooDefs.Perms.WRITE, - request.authInfo); - version = setDataRequest.getVersion(); - int currentVersion = nodeRecord.stat.getVersion(); - if (version != -1 && version != currentVersion) { - throw new KeeperException(Code.BadVersion); - } - version = currentVersion + 1; - txn = new SetDataTxn(path, setDataRequest.getData(), version); - nodeRecord = nodeRecord.duplicate(txnHeader.getZxid()); - nodeRecord.stat.setVersion(version); - addChangeRecord(nodeRecord); - break; - case OpCode.setACL: - txnHeader = new TxnHeader(request.sessionId, request.cxid, zks - .getNextZxid(), zks.getTime(), OpCode.setACL); - zks.sessionTracker.checkSession(request.sessionId); - SetACLRequest setAclRequest = new SetACLRequest(); - if (!fixupACL(request.authInfo, setAclRequest.getAcl())) { - throw new KeeperException(Code.InvalidACL); - } - ZooKeeperServer.byteBuffer2Record(request.request, - setAclRequest); - path = setAclRequest.getPath(); - nodeRecord = getRecordForPath(path); - checkACL(zks, nodeRecord.acl, ZooDefs.Perms.ADMIN, - request.authInfo); - version = setAclRequest.getVersion(); - currentVersion = nodeRecord.stat.getAversion(); - if (version != -1 && version != currentVersion) { - throw new KeeperException(Code.BadVersion); - } - version = currentVersion + 1; - txn = new SetACLTxn(path, setAclRequest.getAcl(), version); - nodeRecord = nodeRecord.duplicate(txnHeader.getZxid()); - nodeRecord.stat.setAversion(version); - addChangeRecord(nodeRecord); - break; - case OpCode.createSession: - txnHeader = new TxnHeader(request.sessionId, request.cxid, zks - .getNextZxid(), zks.getTime(), OpCode.createSession); - request.request.rewind(); - int to = request.request.getInt(); - txn = new CreateSessionTxn(to); - request.request.rewind(); - break; - case OpCode.closeSession: - txnHeader = new TxnHeader(request.sessionId, request.cxid, zks - .getNextZxid(), zks.getTime(), OpCode.closeSession); - HashSet es = zks.dataTree - .getEphemerals(request.sessionId); - synchronized (zks.outstandingChanges) { - for (ChangeRecord c : zks.outstandingChanges) { - if (c.stat == null) { - // Doing a delete - es.remove(c.path); - } else if (c.stat.getEphemeralOwner() == request.sessionId) { - es.add(c.path); - } - } - for (String path2Delete : es) { - addChangeRecord(new ChangeRecord(txnHeader.getZxid(), - path2Delete, null, 0, null)); - } - } - ZooLog.logWarn("Processed session termination request for id: " - + Long.toHexString(request.sessionId)); - break; - case OpCode.exists: - case OpCode.getData: - case OpCode.getACL: - case OpCode.getChildren: - case OpCode.ping: - break; - } - } catch (KeeperException e) { - if (txnHeader != null) { - txnHeader.setType(OpCode.error); - txn = new ErrorTxn(e.getCode()); - } - } catch (Exception e) { - ZooLog.logWarn("*********************************" + request); - StringBuffer sb = new StringBuffer(); - ByteBuffer bb = request.request; - bb.rewind(); - while (bb.hasRemaining()) { - sb.append(Integer.toHexString(bb.get() & 0xff)); - } - ZooLog.logWarn(sb.toString()); - ZooLog.logException(e); - if (txnHeader != null) { - txnHeader.setType(OpCode.error); - txn = new ErrorTxn(Code.MarshallingError); - } - } - request.hdr = txnHeader; - request.txn = txn; - if (request.hdr != null) { - request.zxid = request.hdr.getZxid(); - } - nextProcessor.processRequest(request); - } - - private boolean fixupACL(ArrayList authInfo, ArrayList acl) { - if (skipACL) { - return true; - } - if (acl == null || acl.size() == 0) { - return false; - } - Iterator it = acl.iterator(); - LinkedList toAdd = null; - while (it.hasNext()) { - ACL a = it.next(); - Id id = a.getId(); - if (id.getScheme().equals("world") && id.getId().equals("anyone")) { - } else if (id.getScheme().equals("auth")) { - it.remove(); - if (toAdd == null) { - toAdd = new LinkedList(); - } - for (Id cid : authInfo) { - AuthenticationProvider ap = zks.authenticationProviders - .get(cid.getScheme()); - if (ap == null) { - ZooLog.logError("Missing AuthenticationProvider for " - + cid.getScheme()); - } else if (ap.isAuthenticated()) { - toAdd.add(new ACL(a.getPerms(), cid)); - } - } - } else { - AuthenticationProvider ap = zks.authenticationProviders.get(id - .getScheme()); - if (ap == null) { - return false; - } - if (!ap.isValid(id.getId())) { - return false; - } - } - } - if (toAdd != null) { - for (ACL a : toAdd) { - acl.add(a); - } - } - return true; - } - - public void processRequest(Request request) { - // request.addRQRec(">prep="+zks.outstandingChanges.size()); - submittedRequests.add(request); - } - - public void shutdown() { - submittedRequests.clear(); - submittedRequests.add(Request.requestOfDeath); - nextProcessor.shutdown(); - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/PurgeTxnLog.java b/zookeeper/java/src/com/yahoo/zookeeper/server/PurgeTxnLog.java deleted file mode 100644 index c28952e2291..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/PurgeTxnLog.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.text.DateFormat; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class PurgeTxnLog { - - static void printUsage(){ - System.out.println("PurgeTxnLog dataLogDir "); - System.out.println("\tdataLogDir -- path to the txn log directory"); - System.exit(1); - } - /** - * @param args PurgeTxnLog dataLogDir - * dataLogDir -- txn log directory - */ - public static void main(String[] args) throws IOException { - if(args.length!=1) - printUsage(); - - File dataDir=new File(args[0]); - - // find the most recent valid snapshot - long highestZxid = -1; - for (File f : dataDir.listFiles()) { - long zxid = ZooKeeperServer.isValidSnapshot(f); - if (zxid > highestZxid) { - highestZxid = zxid; - } - } - // found any valid snapshots? - if(highestZxid==-1) - return; // no snapshots - - // files to exclude from deletion - Set exc=new HashSet(); - exc.add(new File(dataDir, "snapshot."+Long.toHexString(highestZxid))); - exc.addAll(Arrays.asList(ZooKeeperServer.getLogFiles(dataDir,highestZxid))); - - final Set exclude=exc; - List files=Arrays.asList(dataDir.listFiles(new FileFilter(){ - public boolean accept(File f){ - if(!f.getName().startsWith("log.") && - !f.getName().startsWith("snapshot.")) - return false; - if(exclude.contains(f)) - return false; - return true; - }})); - // remove the old files - for(File f: files) - { - System.out.println("Removing file: "+ - DateFormat.getDateTimeInstance().format(f.lastModified())+ - "\t"+f.getPath()); - if(!f.delete()){ - System.err.println("Failed to remove "+f.getPath()); - } - } - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/Request.java b/zookeeper/java/src/com/yahoo/zookeeper/server/Request.java deleted file mode 100644 index f8792d6b2d3..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/Request.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.nio.ByteBuffer; -import java.util.ArrayList; - -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * This is the structure that represents a request moving through a chain of - * RequestProcessors. There are various pieces of information that is tacked - * onto the request as it is processed. - */ -public class Request { - public final static Request requestOfDeath = new Request(null, 0, 0, 0, - null, null); - - /** - * @param cnxn - * @param sessionId - * @param xid - * @param type - * @param bb - */ - public Request(ServerCnxn cnxn, long sessionId, int xid, int type, - ByteBuffer bb, ArrayList authInfo) { - this.cnxn = cnxn; - this.sessionId = sessionId; - this.cxid = xid; - this.type = type; - this.request = bb; - this.authInfo = authInfo; - } - - public long sessionId; - - public int cxid; - - public int type; - - public ByteBuffer request; - - public ServerCnxn cnxn; - - public TxnHeader hdr; - - public Record txn; - - public long zxid = -1; - - public ArrayList authInfo; - - public long createTime = System.currentTimeMillis(); - - /** - * is the packet type a valid packet in zookeeper - * - * @param type - * the type of the packet - * @return true if a valid packet, false if not - */ - static boolean isValid(int type) { - // make sure this is always synchronized with Zoodefs!! - switch (type) { - case OpCode.notification: - return false; - case OpCode.create: - case OpCode.delete: - case OpCode.createSession: - case OpCode.exists: - case OpCode.getData: - case OpCode.setData: - case OpCode.getACL: - case OpCode.setACL: - case OpCode.getChildren: - case OpCode.ping: - case OpCode.closeSession: - return true; - default: - return false; - } - } - - static String op2String(int op) { - switch (op) { - case OpCode.notification: - return "notification"; - case OpCode.create: - return "create"; - case OpCode.delete: - return "delete"; - case OpCode.exists: - return "exists"; - case OpCode.getData: - return "getDate"; - case OpCode.setData: - return "setData"; - case OpCode.getACL: - return "getACL"; - case OpCode.setACL: - return "setACL"; - case OpCode.getChildren: - return "getChildren"; - case OpCode.ping: - return "ping"; - case OpCode.createSession: - return "createSession"; - case OpCode.closeSession: - return "closeSession"; - case OpCode.error: - return "error"; - default: - return "unknown " + op; - } - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(Long.toHexString(sessionId)).append(" "); - sb.append(Long.toHexString(cxid)).append(" "); - sb.append(Long.toHexString((hdr == null ? -2 : hdr.getZxid()))).append( - " "); - sb - .append( - " txn type = " - + (hdr == null ? "unknown" : "" + hdr.getType())) - .append(" "); - sb.append(op2String(type)).append(" "); - - String path = "n/a"; - if (type != OpCode.createSession) { - try { - request.clear(); - int pathLen = request.getInt(); - byte b[] = new byte[pathLen]; - request.get(b); - path = new String(b); - request.clear(); - } catch (Exception e) { - - } - } - sb.append(path).append(" "); - return sb.toString(); - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/RequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/RequestProcessor.java deleted file mode 100644 index 9ffb17468ad..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/RequestProcessor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -/** - * RequestProcessors are chained together to process transactions. Requests are - * always processed in order. The standalone server, follower, and leader all - * have slightly different RequestProcessors changed together. - * - * Requests always move forward through the chain of RequestProcessors. Requests - * are passed to a RequestProcessor through processRequest(). Generally method - * will always be invoked by a single thread. - * - * When shutdown is called, the request RequestProcessor should also shutdown - * any RequestProcessors that it is connected to. - */ -public interface RequestProcessor { - void processRequest(Request request); - - void shutdown(); -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/ServerCnxn.java b/zookeeper/java/src/com/yahoo/zookeeper/server/ServerCnxn.java deleted file mode 100755 index aa06cbcd172..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/ServerCnxn.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.ByteBuffer; -import java.util.ArrayList; - -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.proto.ReplyHeader; -import com.yahoo.zookeeper.proto.WatcherEvent; - -public interface ServerCnxn extends Watcher { - final static int killCmd = ByteBuffer.wrap("kill".getBytes()).getInt(); - - final static int ruokCmd = ByteBuffer.wrap("ruok".getBytes()).getInt(); - - final static int dumpCmd = ByteBuffer.wrap("dump".getBytes()).getInt(); - - final static int statCmd = ByteBuffer.wrap("stat".getBytes()).getInt(); - - final static int reqsCmd = ByteBuffer.wrap("reqs".getBytes()).getInt(); - - final static int setTraceMaskCmd = ByteBuffer.wrap("stmk".getBytes()) - .getInt(); - - final static int getTraceMaskCmd = ByteBuffer.wrap("gtmk".getBytes()) - .getInt(); - - final static ByteBuffer imok = ByteBuffer.wrap("imok".getBytes()); - - public abstract int getSessionTimeout(); - - public abstract void close(); - - public abstract void sendResponse(ReplyHeader h, Record r, String tag) - throws IOException; - - public void finishSessionInit(boolean valid); - - public abstract void process(WatcherEvent event); - - public abstract long getSessionId(); - - public abstract void setSessionId(long sessionId); - - public abstract ArrayList getAuthInfo(); - - public InetSocketAddress getRemoteAddress(); - - public void setStats(long latency, long avgLatency); -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/SessionTracker.java b/zookeeper/java/src/com/yahoo/zookeeper/server/SessionTracker.java deleted file mode 100644 index 792e5d63224..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/SessionTracker.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import com.yahoo.zookeeper.KeeperException; - -/** - * This is the basic interface that ZooKeeperServer uses to track sessions. The - * standalone and leader ZooKeeperServer use the same SessionTracker. The - * FollowerZooKeeperServer uses a SessionTracker which is basically a simple - * shell to track information to be forwarded to the leader. - */ -public interface SessionTracker { - public static interface SessionExpirer { - public void expire(long sessionId); - - public long getServerId(); - } - - long createSession(int sessionTimeout); - - void addSession(long id, int to); - - /** - * @param sessionId - * @param sessionTimeout - * @return false if session is no longer active - */ - boolean touchSession(long sessionId, int sessionTimeout); - - /** - * - */ - void shutdown(); - - /** - * @param sessionId - */ - void removeSession(long sessionId); - - void checkSession(long sessionId) throws KeeperException; -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/SessionTrackerImpl.java b/zookeeper/java/src/com/yahoo/zookeeper/server/SessionTrackerImpl.java deleted file mode 100644 index 01ae1e22fbe..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/SessionTrackerImpl.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.concurrent.ConcurrentHashMap; - -import com.yahoo.zookeeper.KeeperException; - -/** - * This is a full featured SessionTracker. It tracks session in grouped by tick - * interval. It always rounds up the tick interval to provide a sort of grace - * period. Sessions are thus expired in batches made up of sessions that expire - * in a given interval. - */ -public class SessionTrackerImpl extends Thread implements SessionTracker { - HashMap sessionsById = new HashMap(); - - HashMap sessionSets = new HashMap(); - - ConcurrentHashMap sessionsWithTimeout; - - long nextExpirationTime; - - int expirationInterval; - - public static class Session { - Session(long sessionId, long expireTime) { - this.sessionId = sessionId; - this.tickTime = expireTime; - } - - long tickTime; - - long sessionId; - } - - static class SessionSet { - long expireTime; - - HashSet sessions = new HashSet(); - } - - SessionExpirer expirer; - - private long roundToInterval(long time) { - // We give a one interval grace period - return (time / expirationInterval + 1) * expirationInterval; - } - - public SessionTrackerImpl(SessionExpirer expirer, - ConcurrentHashMap sessionsWithTimeout, int tickTime) { - super("SessionTracker"); - this.expirer = expirer; - this.expirationInterval = tickTime; - this.sessionsWithTimeout = sessionsWithTimeout; - nextExpirationTime = roundToInterval(System.currentTimeMillis()); - for (long id : sessionsWithTimeout.keySet()) { - addSession(id, sessionsWithTimeout.get(id)); - } - start(); - } - - boolean running = true; - - synchronized public void finish() { - running = false; - this.notifyAll(); - } - - volatile long currentTime; - - synchronized public String toString() { - StringBuffer sb = new StringBuffer("Session Sets (" - + sessionSets.size() + "):\n"); - ArrayList keys = new ArrayList(sessionSets.keySet()); - Collections.sort(keys); - for (long time : keys) { - sb.append(sessionSets.get(time).sessions.size() + " expire at " - + new Date(time) + ":\n"); - for (Session s : sessionSets.get(time).sessions) { - sb.append("\t" + s.sessionId + "\n"); - } - } - return sb.toString(); - } - - synchronized public void run() { - try { - while (running) { - currentTime = System.currentTimeMillis(); - if (nextExpirationTime > currentTime) { - this.wait(nextExpirationTime - currentTime); - continue; - } - SessionSet set; - set = sessionSets.remove(nextExpirationTime); - if (set != null) { - for (Session s : set.sessions) { - sessionsById.remove(s.sessionId); - ZooLog.logWarn("Expiring " - + Long.toHexString(s.sessionId)); - expirer.expire(s.sessionId); - } - } - nextExpirationTime += expirationInterval; - } - } catch (InterruptedException e) { - ZooLog.logException(e); - } - ZooLog.logTextTraceMessage("SessionTrackerImpl exited loop!", - ZooLog.textTraceMask); - } - - synchronized public boolean touchSession(long sessionId, int timeout) { - ZooLog.logTextTraceMessage("SessionTrackerImpl --- Touch session: " - + sessionId + " with timeout " + timeout, - ZooLog.CLIENT_PING_TRACE_MASK); - Session s = sessionsById.get(sessionId); - if (s == null) { - return false; - } - long expireTime = roundToInterval(System.currentTimeMillis() + timeout); - if (s.tickTime >= expireTime) { - // Nothing needs to be done - return true; - } - SessionSet set = sessionSets.get(s.tickTime); - if (set != null) { - set.sessions.remove(s); - } - s.tickTime = expireTime; - set = sessionSets.get(s.tickTime); - if (set == null) { - set = new SessionSet(); - set.expireTime = expireTime; - sessionSets.put(expireTime, set); - } - set.sessions.add(s); - return true; - } - - synchronized public void removeSession(long sessionId) { - Session s = sessionsById.remove(sessionId); - sessionsWithTimeout.remove(sessionId); - ZooLog.logTextTraceMessage("SessionTrackerImpl --- Removing " - + sessionId, ZooLog.SESSION_TRACE_MASK); - if (s != null) { - sessionSets.get(s.tickTime).sessions.remove(s); - } - } - - public void shutdown() { - running = false; - ZooLog.logTextTraceMessage("Shutdown SessionTrackerImpl!", - ZooLog.textTraceMask); - } - - long nextSessionId = System.currentTimeMillis() << 24; - - synchronized public long createSession(int sessionTimeout) { - addSession(nextSessionId, sessionTimeout); - return nextSessionId++; - } - - synchronized public void addSession(long id, int sessionTimeout) { - sessionsWithTimeout.put(id, sessionTimeout); - if (sessionsById.get(id) == null) { - Session s = new Session(id, 0); - sessionsById.put(id, s); - ZooLog.logTextTraceMessage("SessionTrackerImpl --- Adding " + id - + " " + sessionTimeout, ZooLog.SESSION_TRACE_MASK); - } else { - ZooLog.logTextTraceMessage( - "SessionTrackerImpl --- Existing session " + id + " " - + sessionTimeout, ZooLog.SESSION_TRACE_MASK); - } - touchSession(id, sessionTimeout); - } - - public void checkSession(long sessionId) throws KeeperException { - if (sessionsById.get(sessionId) == null) { - throw new KeeperException(KeeperException.Code.SessionExpired); - } - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/SyncRequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/SyncRequestProcessor.java deleted file mode 100644 index ff8b0cebb8f..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/SyncRequestProcessor.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.util.LinkedList; -import java.util.Random; -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.jute.BinaryOutputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * This RequestProcessor logs requests to disk. It batches the requests to do - * the io efficiently. The request is not passed to the next RequestProcessor - * until its log has been synced to disk. - */ -public class SyncRequestProcessor extends Thread implements RequestProcessor { - ZooKeeperServer zks; - - LinkedBlockingQueue queuedRequests = new LinkedBlockingQueue(); - - static boolean forceSync; - static { - forceSync = !System.getProperty("zookeeper.forceSync", "yes").equals( - "no"); - } - - static long preAllocSize = 65536 * 1024; - static { - String size = System.getProperty("zookeeper.preAllocSize"); - if (size != null) { - try { - preAllocSize = Long.parseLong(size) * 1024; - } catch (NumberFormatException e) { - ZooLog.logWarn(size + " is not a valid value for preAllocSize"); - } - } - } - - /** - * The number of log entries to log before starting a snapshot - */ - static public int snapCount = ZooKeeperServer.getSnapCount(); - - Thread snapInProcess; - - RequestProcessor nextProcessor; - - boolean timeToDie = false; - - public SyncRequestProcessor(ZooKeeperServer zks, - RequestProcessor nextProcessor) { - super("SyncThread"); - this.zks = zks; - this.nextProcessor = nextProcessor; - start(); - } - - /** - * Transactions that have been written and are waiting to be flushed to - * disk. Basically this is the list of SyncItems whose callbacks will be - * invoked after flush returns successfully. - */ - LinkedList toFlush = new LinkedList(); - - FileOutputStream logStream; - - BinaryOutputArchive logArchive; - - Random r = new Random(System.nanoTime()); - - int logCount = 0; - - Request requestOfDeath = Request.requestOfDeath; - - private static ByteBuffer fill = ByteBuffer.allocateDirect(1024); - - LinkedList streamsToFlush = new LinkedList(); - - public void run() { - try { - long fileSize = 0; - long lastZxidSeen = -1; - FileChannel fc = null; - while (true) { - Request si = null; - if (toFlush.isEmpty()) { - si = queuedRequests.take(); - } else { - si = queuedRequests.poll(); - if (si == null) { - flush(toFlush); - continue; - } - } - if (si == requestOfDeath) { - break; - } - if (si != null) { - // ZooLog.logWarn("Sync>>> cxid = " + si.cxid + " type = " + - // si.type + " id = " + si.sessionId + " zxid = " + - // Long.toHexString(si.zxid)); - ZooLog.logRequest('S', si, "", - ZooLog.CLIENT_REQUEST_TRACE_MASK); - TxnHeader hdr = si.hdr; - if (hdr != null) { - if (hdr.getZxid() <= lastZxidSeen) { - ZooLog.logError("Current zxid " + hdr.getZxid() - + " is <= " + lastZxidSeen + " for " - + hdr.getType()); - } - Record txn = si.txn; - if (logStream == null) { - fileSize = 0; - logStream = new FileOutputStream(new File( - zks.dataLogDir, ZooKeeperServer - .getLogName(hdr.getZxid()))); - synchronized (streamsToFlush) { - streamsToFlush.add(logStream); - } - fc = logStream.getChannel(); - logArchive = BinaryOutputArchive - .getArchive(logStream); - } - long position = fc.position(); - // We pad the file in 1M chunks to avoid syncing to - // write the new filesize. - if (position + 4096 >= fileSize) { - fileSize = fileSize + preAllocSize; - fill.position(0); - fc.write(fill, fileSize); - } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - BinaryOutputArchive boa = BinaryOutputArchive - .getArchive(baos); - hdr.serialize(boa, "hdr"); - if (txn != null) { - txn.serialize(boa, "txn"); - } - logArchive.writeBuffer(baos.toByteArray(), "txnEntry"); - logArchive.writeByte((byte) 0x42, "EOR"); - logCount++; - if (logCount > snapCount / 2 - && r.nextInt(snapCount / 2) == 0) { - // We just want one snapshot going at a time - if (snapInProcess != null - && snapInProcess.isAlive()) { - ZooLog.logWarn("Too busy to snap, skipping"); - } else { - logStream = null; - logArchive = null; - snapInProcess = new Thread() { - public void run() { - try { - zks.snapshot(); - } catch (Exception e) { - ZooLog.logException(e); - } - } - }; - snapInProcess.start(); - } - logCount = 0; - } - } - toFlush.add(si); - if (toFlush.size() > 1000) { - flush(toFlush); - } - } - } - } catch (Exception e) { - ZooLog.logException(e, "Severe error, exiting"); - System.exit(11); - } - ZooLog.logTextTraceMessage("SyncRequestProcessor exiyed!", - ZooLog.textTraceMask); - } - - private void flush(LinkedList toFlush) throws IOException { - if (toFlush.size() == 0) { - return; - } - - LinkedList streamsToFlushNow; - synchronized (streamsToFlush) { - streamsToFlushNow = (LinkedList) streamsToFlush - .clone(); - } - for (FileOutputStream fos : streamsToFlushNow) { - fos.flush(); - if (forceSync) { - ((FileChannel) fos.getChannel()).force(false); - } - } - while (streamsToFlushNow.size() > 1) { - FileOutputStream fos = streamsToFlushNow.removeFirst(); - fos.close(); - synchronized (streamsToFlush) { - streamsToFlush.remove(fos); - } - } - while (toFlush.size() > 0) { - Request i = toFlush.remove(); - nextProcessor.processRequest(i); - } - } - - public void shutdown() { - timeToDie = true; - queuedRequests.add(requestOfDeath); - nextProcessor.shutdown(); - } - - public void processRequest(Request request) { - // request.addRQRec(">sync"); - queuedRequests.add(request); - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/TraceFormatter.java b/zookeeper/java/src/com/yahoo/zookeeper/server/TraceFormatter.java deleted file mode 100644 index 50c7861c7cb..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/TraceFormatter.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.text.DateFormat; -import java.util.Date; - -import com.yahoo.zookeeper.ZooDefs.OpCode; - -public class TraceFormatter { - - static String op2String(int op) { - switch (op) { - case OpCode.notification: - return "notification"; - case OpCode.create: - return "create"; - case OpCode.delete: - return "delete"; - case OpCode.exists: - return "exists"; - case OpCode.getData: - return "getDate"; - case OpCode.setData: - return "setData"; - case OpCode.getACL: - return "getACL"; - case OpCode.setACL: - return "setACL"; - case OpCode.getChildren: - return "getChildren"; - case OpCode.ping: - return "ping"; - case OpCode.createSession: - return "createSession"; - case OpCode.closeSession: - return "closeSession"; - case OpCode.error: - return "error"; - default: - return "unknown " + op; - } - } - - /** - * @param args - * @throws IOException - */ - public static void main(String[] args) throws IOException { - if (args.length != 1) { - System.err.println("USAGE: TraceFormatter trace_file"); - System.exit(2); - } - FileChannel fc = new FileInputStream(args[0]).getChannel(); - while (true) { - ByteBuffer bb = ByteBuffer.allocate(41); - fc.read(bb); - bb.flip(); - - byte app = bb.get(); - long time = bb.getLong(); - long id = bb.getLong(); - int cxid = bb.getInt(); - long zxid = bb.getLong(); - int txnType = bb.getInt(); - int type = bb.getInt(); - int len = bb.getInt(); - bb = ByteBuffer.allocate(len); - fc.read(bb); - bb.flip(); - String path = "n/a"; - if (bb.remaining() > 0) { - if (type != OpCode.createSession) { - int pathLen = bb.getInt(); - byte b[] = new byte[pathLen]; - bb.get(b); - path = new String(b); - } - } - System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.LONG).format(new Date(time)) - + ": " - + (char) app - + " id=" - + Long.toHexString(id) - + " cxid=" - + cxid - + " op=" - + op2String(type) - + " zxid=" - + Long.toHexString(zxid) - + " txnType=" - + txnType - + " len=" - + len + " path=" + path); - } - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/WatchManager.java b/zookeeper/java/src/com/yahoo/zookeeper/server/WatchManager.java deleted file mode 100644 index 1c281e0ac85..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/WatchManager.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.util.HashMap; -import java.util.HashSet; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.proto.WatcherEvent; - -/** - * This class manages watches. It allows watches to be associated with a string - * and removes watchers and their watches in addition to managing triggers. - */ -public class WatchManager { - HashMap> watchTable = new HashMap>(); - - HashMap> watch2Paths = new HashMap>(); - - synchronized void addWatch(String path, Watcher watcher) { - HashSet list = watchTable.get(path); - if (list == null) { - list = new HashSet(); - watchTable.put(path, list); - } - list.add(watcher); - - HashSet paths = watch2Paths.get(watcher); - if (paths == null) { - paths = new HashSet(); - watch2Paths.put(watcher, paths); - } - paths.add(path); - } - - synchronized void removeWatcher(Watcher watcher) { - HashSet paths = watch2Paths.remove(watcher); - if (paths == null) { - return; - } - for (String p : paths) { - HashSet list = watchTable.get(p); - if (list != null) { - list.remove(watcher); - if (list.size() == 0) { - watchTable.remove(p); - } - } - } - } - - void triggerWatch(String path, int type) { - WatcherEvent e = new WatcherEvent(type, - Watcher.Event.KeeperStateSyncConnected, path); - HashSet watchers; - synchronized (this) { - watchers = watchTable.remove(path); - if (watchers == null || watchers.isEmpty()) { - ZooLog.logTextTraceMessage("No watchers for " + path, - ZooLog.EVENT_DELIVERY_TRACE_MASK); - return; - } - for (Watcher w : watchers) { - HashSet paths = watch2Paths.get(w); - if (paths != null) { - paths.remove(path); - } - } - } - for (Watcher w : watchers) { - w.process(e); - } - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/ZooKeeperServer.java b/zookeeper/java/src/com/yahoo/zookeeper/server/ZooKeeperServer.java deleted file mode 100755 index 5f7b2c94eb8..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/ZooKeeperServer.java +++ /dev/null @@ -1,728 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.ByteArrayInputStream; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.io.SyncFailedException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.jute.BinaryInputArchive; -import com.yahoo.jute.BinaryOutputArchive; -import com.yahoo.jute.InputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.data.ACL; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.RequestHeader; -import com.yahoo.zookeeper.server.NIOServerCnxn.Factory; -import com.yahoo.zookeeper.server.SessionTracker.SessionExpirer; -import com.yahoo.zookeeper.server.auth.AuthenticationProvider; -import com.yahoo.zookeeper.server.auth.DigestAuthenticationProvider; -import com.yahoo.zookeeper.server.auth.HostAuthenticationProvider; -import com.yahoo.zookeeper.server.auth.IPAuthenticationProvider; -import com.yahoo.zookeeper.txn.CreateSessionTxn; -import com.yahoo.zookeeper.txn.CreateTxn; -import com.yahoo.zookeeper.txn.DeleteTxn; -import com.yahoo.zookeeper.txn.ErrorTxn; -import com.yahoo.zookeeper.txn.SetACLTxn; -import com.yahoo.zookeeper.txn.SetDataTxn; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * This class implements a simple standalone ZooKeeperServer. It sets up the - * following chain of RequestProcessors to process requests: - * PrepRequestProcessor -> SyncRequestProcessor -> FinalRequestProcessor - */ -public class ZooKeeperServer implements SessionExpirer { - int tickTime = 3000; - - HashMap authenticationProviders = new HashMap(); - - /* - * Start up the ZooKeeper server. - * - * @param args the port and data directory - */ - public static void main(String[] args) { - if (args.length != 2) { - System.err.println("USAGE: ZooKeeperServer port datadir\n"); - System.exit(2); - } - int port = -1; - try { - port = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - System.err.println(args[0] + " is not a valid port number"); - System.exit(2); - } - try { - // Note that this thread isn't going to be doing anything else, - // so rather than spawning another thread, we will just call - // run() in this thread. - ZooKeeperServer zk = new ZooKeeperServer(new File(args[1]), - new File(args[1]), 3000); - zk.startup(); - NIOServerCnxn.Factory t = new NIOServerCnxn.Factory(port); - t.setZooKeeperServer(zk); - t.join(); - zk.shutdown(); - } catch (IOException e) { - ZooLog.logException(e); - } catch (InterruptedException e) { - ZooLog.logException(e); - } - System.exit(0); - } - - public DataTree dataTree; - - protected SessionTracker sessionTracker; - - /** - * directory for storing the snapshot - */ - File dataDir; - - /** - * directoy for storing the log tnxns - */ - File dataLogDir; - - protected ConcurrentHashMap sessionsWithTimeouts; - - void removeCnxn(ServerCnxn cnxn) { - dataTree.removeCnxn(cnxn); - } - - /** - * Creates a ZooKeeperServer instance. It sets everything up, but doesn't - * actually start listening for clients until run() is invoked. - * - * @param dataDir - * the directory to put the data - * @throws IOException - */ - public ZooKeeperServer(File dataDir, File dataLogDir, int tickTime) throws IOException { - this.dataDir = dataDir; - this.dataLogDir = dataLogDir; - this.tickTime = tickTime; - if (!dataDir.isDirectory()) { - throw new IOException("data directory does not exist"); - } - IPAuthenticationProvider ipp = new IPAuthenticationProvider(); - HostAuthenticationProvider hostp = new HostAuthenticationProvider(); - DigestAuthenticationProvider digp = new DigestAuthenticationProvider(); - authenticationProviders.put(ipp.getScheme(), ipp); - authenticationProviders.put(hostp.getScheme(), hostp); - authenticationProviders.put(digp.getScheme(), digp); - Enumeration en = System.getProperties().keys(); - while (en.hasMoreElements()) { - String k = (String) en.nextElement(); - if (k.startsWith("zookeeper.authProvider.")) { - String className = System.getProperty(k); - try { - Class c = ZooKeeperServer.class.getClassLoader().loadClass( - className); - AuthenticationProvider ap = (AuthenticationProvider) c - .newInstance(); - authenticationProviders.put(ap.getScheme(), ap); - } catch (Exception e) { - ZooLog.logException(e, "Problems loading " + className); - } - } - } - } - - public static long getZxidFromName(String name, String prefix) { - long zxid = -1; - String nameParts[] = name.split("\\."); - if (nameParts.length == 2 && nameParts[0].equals(prefix)) { - try { - zxid = Long.parseLong(nameParts[1], 16); - } catch (NumberFormatException e) { - } - } - return zxid; - } - - static public long isValidSnapshot(File f) throws IOException { - long zxid = getZxidFromName(f.getName(), "snapshot"); - if (zxid == -1) - return -1; - - // Check for a valid snapshot - RandomAccessFile raf = new RandomAccessFile(f, "r"); - try { - raf.seek(raf.length() - 5); - byte bytes[] = new byte[5]; - raf.read(bytes); - ByteBuffer bb = ByteBuffer.wrap(bytes); - int len = bb.getInt(); - byte b = bb.get(); - if (len != 1 || b != '/') { - ZooLog.logWarn("Invalid snapshot " + f + " len = " + len - + " byte = " + (b & 0xff)); - return -1; - } - } finally { - raf.close(); - } - - return zxid; - } - - static File[] getLogFiles(File logDir,long snapshotZxid){ - List files = Arrays.asList(logDir.listFiles()); - Collections.sort(files, new Comparator() { - public int compare(File o1, File o2) { - long z1 = getZxidFromName(o1.getName(), "log"); - long z2 = getZxidFromName(o2.getName(), "log"); - return z1 < z2 ? -1 : (z1 > z2 ? 1 : 0); - } - }); - // Find the log file that starts before or at the same time as the - // zxid of the snapshot - long logZxid = 0; - for (File f : files) { - long fzxid = getZxidFromName(f.getName(), "log"); - if (fzxid > snapshotZxid) { - continue; - } - if (fzxid > logZxid) { - logZxid = fzxid; - } - } - List v=new ArrayList(5); - // Apply the logs - for (File f : files) { - long fzxid = getZxidFromName(f.getName(), "log"); - if (fzxid < logZxid) { - continue; - } - v.add(f); - } - return v.toArray(new File[0]); - } - - public void loadData() throws IOException, FileNotFoundException, - SyncFailedException, InterruptedException { - long highestZxid = 0; - for (File f : dataDir.listFiles()) { - long zxid = isValidSnapshot(f); - if (zxid == -1) { - ZooLog.logWarn("Skipping " + f); - continue; - } - if (zxid > highestZxid) { - highestZxid = zxid; - } - } - // Restore sessions and data - // Find the latest snapshot - File snapshot = new File(dataDir, "snapshot." - + Long.toHexString(highestZxid)); - if (snapshot.exists()) { - long snapShotZxid = highestZxid; - ZooLog.logWarn("Processing snapshot: " + snapshot); - FileInputStream fis = new FileInputStream(snapshot); - loadData(BinaryInputArchive.getArchive(fis)); - fis.close(); - dataTree.lastProcessedZxid = highestZxid; - File[] files=getLogFiles(dataLogDir,snapShotZxid); - // Apply the logs - for (File f : files) { - ZooLog.logWarn("Processing log file: " + f); - FileInputStream logStream = new FileInputStream(f); - highestZxid = playLog(BinaryInputArchive.getArchive(logStream)); - logStream.close(); - } - hzxid = highestZxid; - } else { - sessionsWithTimeouts = new ConcurrentHashMap(); - dataTree = new DataTree(); - } - // Clean up dead sessions - LinkedList deadSessions = new LinkedList(); - for (long session : dataTree.getSessions()) { - if (sessionsWithTimeouts.get(session) == null) { - deadSessions.add(session); - } - } - dataTree.initialized = true; - for (long session : deadSessions) { - killSession(session); - } - // Make a clean snapshot - snapshot(); - } - - public void loadData(InputArchive ia) throws IOException { - sessionsWithTimeouts = new ConcurrentHashMap(); - dataTree = new DataTree(); - int count = ia.readInt("count"); - while (count > 0) { - long id = ia.readLong("id"); - int to = ia.readInt("timeout"); - sessionsWithTimeouts.put(id, to); - ZooLog.logTextTraceMessage("loadData --- session in archive: " + id - + " with timeout: " + to, ZooLog.SESSION_TRACE_MASK); - count--; - } - dataTree.deserialize(ia, "tree"); - } - - public long playLog(InputArchive logStream) throws IOException { - long highestZxid = 0; - try { - while (true) { - byte[] bytes = logStream.readBuffer("txnEntry"); - if (bytes.length == 0) { - // Since we preallocate, we define EOF to be an - // empty transaction - throw new EOFException(); - } - InputArchive ia = BinaryInputArchive - .getArchive(new ByteArrayInputStream(bytes)); - TxnHeader hdr = new TxnHeader(); - Record txn = deserializeTxn(ia, hdr); - if (logStream.readByte("EOR") != 'B') { - ZooLog.logError("Last transaction was partial."); - throw new EOFException(); - } - if (hdr.getZxid() <= highestZxid && highestZxid != 0) { - ZooLog.logError(highestZxid + "(higestZxid) >= " - + hdr.getZxid() + "(next log) for type " - + hdr.getType()); - } else { - highestZxid = hdr.getZxid(); - } - switch (hdr.getType()) { - case OpCode.createSession: - sessionsWithTimeouts.put(hdr.getClientId(), - ((CreateSessionTxn) txn).getTimeOut()); - ZooLog.logTextTraceMessage( - "playLog --- create session in log: " - + hdr.getClientId() + " with timeout: " - + ((CreateSessionTxn) txn).getTimeOut(), - ZooLog.SESSION_TRACE_MASK); - // give dataTree a chance to sync its lastProcessedZxid - dataTree.processTxn(hdr, txn); - break; - case OpCode.closeSession: - sessionsWithTimeouts.remove(hdr.getClientId()); - ZooLog.logTextTraceMessage( - "playLog --- close session in log: " - + hdr.getClientId(), - ZooLog.SESSION_TRACE_MASK); - dataTree.processTxn(hdr, txn); - break; - default: - dataTree.processTxn(hdr, txn); - } - } - } catch (EOFException e) { - } - return highestZxid; - } - - static public Record deserializeTxn(InputArchive ia, TxnHeader hdr) - throws IOException { - hdr.deserialize(ia, "hdr"); - Record txn = null; - switch (hdr.getType()) { - case OpCode.createSession: - // This isn't really an error txn; it just has the same - // format. The error represents the timeout - txn = new CreateSessionTxn(); - break; - case OpCode.closeSession: - return null; - case OpCode.create: - txn = new CreateTxn(); - break; - case OpCode.delete: - txn = new DeleteTxn(); - break; - case OpCode.setData: - txn = new SetDataTxn(); - break; - case OpCode.setACL: - txn = new SetACLTxn(); - break; - case OpCode.error: - txn = new ErrorTxn(); - break; - } - if (txn != null) { - txn.deserialize(ia, "txn"); - } - return txn; - } - - public void snapshot(BinaryOutputArchive oa) throws IOException, - InterruptedException { - HashMap sessSnap = new HashMap( - sessionsWithTimeouts); - oa.writeInt(sessSnap.size(), "count"); - for (Entry entry : sessSnap.entrySet()) { - oa.writeLong(entry.getKey().longValue(), "id"); - oa.writeInt(entry.getValue().intValue(), "timeout"); - } - dataTree.serialize(oa, "tree"); - } - - public void snapshot() throws InterruptedException { - - long lastZxid = dataTree.lastProcessedZxid; - ZooLog.logTextTraceMessage( - "Snapshoting: " + Long.toHexString(lastZxid), - ZooLog.textTraceMask); - try { - FileOutputStream sessStream = new FileOutputStream(new File( - dataDir, "snapshot." + Long.toHexString(lastZxid))); - BinaryOutputArchive oa = BinaryOutputArchive.getArchive(sessStream); - snapshot(oa); - sessStream.flush(); - // sessStream.getChannel().force(false); - sessStream.close(); - } catch (IOException e) { - ZooLog.logException(e, "Severe error, exiting"); - // This is a severe error that we cannot recover from, - // so we need to exit - System.exit(10); - } - } - - protected long hzxid = 0; - - /** - * This should be called from a synchronized block on this! - */ - public long getZxid() { - return hzxid; - } - - synchronized long getNextZxid() { - return ++hzxid; - } - - long getTime() { - return System.currentTimeMillis(); - } - - static String getLogName(long zxid) { - return "log." + Long.toHexString(zxid); - } - - final public static Exception ok = new Exception("No prob"); - - protected RequestProcessor firstProcessor; - - LinkedBlockingQueue sessionsToDie = new LinkedBlockingQueue(); - - public void closeSession(long sessionId) throws KeeperException, - InterruptedException { - ZooLog.logTextTraceMessage("ZooKeeperServer --- Session to be closed: " - + sessionId, ZooLog.SESSION_TRACE_MASK); - // we do not want to wait for a session close. send it as soon as we - // detect it! - submitRequest(null, sessionId, OpCode.closeSession, 0, null, null); - } - - protected void killSession(long sessionId) { - dataTree.killSession(sessionId); - ZooLog.logTextTraceMessage("ZooKeeperServer --- killSession: " - + sessionId, ZooLog.SESSION_TRACE_MASK); - if (sessionTracker != null) { - sessionTracker.removeSession(sessionId); - } - } - - public void expire(long sessionId) { - try { - ZooLog.logTextTraceMessage( - "ZooKeeperServer --- Session to expire: " + sessionId, - ZooLog.SESSION_TRACE_MASK); - closeSession(sessionId); - } catch (Exception e) { - ZooLog.logException(e); - } - } - - void touch(ServerCnxn cnxn) throws IOException { - if (cnxn == null) { - return; - } - long id = cnxn.getSessionId(); - int to = cnxn.getSessionTimeout(); - if (!sessionTracker.touchSession(id, to)) { - throw new IOException("Missing session " + Long.toHexString(id)); - } - } - - public void startup() throws IOException, InterruptedException { - if (dataTree == null) { - loadData(); - } - createSessionTracker(); - setupRequestProcessors(); - running = true; - synchronized (this) { - notifyAll(); - } - } - - protected void setupRequestProcessors() { - RequestProcessor finalProcessor = new FinalRequestProcessor(this); - RequestProcessor syncProcessor = new SyncRequestProcessor(this, - finalProcessor); - firstProcessor = new PrepRequestProcessor(this, syncProcessor); - } - - protected void createSessionTracker() { - sessionTracker = new SessionTrackerImpl(this, sessionsWithTimeouts, - tickTime); - } - - protected boolean running; - - public boolean isRunning() { - return running; - } - - public void shutdown() { - // new RuntimeException("Calling shutdown").printStackTrace(); - this.running = false; - // Since sessionTracker and syncThreads poll we just have to - // set running to false and they will detect it during the poll - // interval. - if (sessionTracker != null) { - sessionTracker.shutdown(); - } - if (firstProcessor != null) { - firstProcessor.shutdown(); - } - dataTree.clear(); - } - - /** - * This is the secret that we use to generate passwords, for the moment it - * is more of a sanity check. - */ - final private long superSecret = 0XB3415C00L; - - int requestsInProcess; - - synchronized public void incInProcess() { - requestsInProcess++; - } - - synchronized public void decInProcess() { - requestsInProcess--; - } - - public int getInProcess() { - return requestsInProcess; - } - - /** - * This structure is used to facilitate information sharing between PrepRP - * and FinalRP. - */ - static class ChangeRecord { - ChangeRecord(long zxid, String path, Stat stat, int childCount, - ArrayList acl) { - this.zxid = zxid; - this.path = path; - this.stat = stat; - this.childCount = childCount; - this.acl = acl; - } - - long zxid; - - String path; - - Stat stat; /* Make sure to create a new object when changing */ - - int childCount; - - ArrayList acl; /* Make sure to create a new object when changing */ - - @SuppressWarnings("unchecked") - ChangeRecord duplicate(long zxid) { - Stat stat = new Stat(); - if (this.stat != null) { - DataTree.copyStat(this.stat, stat); - } - return new ChangeRecord(zxid, path, stat, childCount, - acl == null ? new ArrayList() : (ArrayList) acl - .clone()); - } - } - - ArrayList outstandingChanges = new ArrayList(); - - private Factory serverCnxnFactory; - - byte[] generatePasswd(long id) { - Random r = new Random(id ^ superSecret); - byte p[] = new byte[16]; - r.nextBytes(p); - return p; - } - - protected boolean checkPasswd(long sessionId, byte[] passwd) { - return sessionId != 0 - && Arrays.equals(passwd, generatePasswd(sessionId)); - } - - long createSession(ServerCnxn cnxn, byte passwd[], int timeout) - throws InterruptedException { - long sessionId = sessionTracker.createSession(timeout); - Random r = new Random(sessionId ^ superSecret); - r.nextBytes(passwd); - ByteBuffer to = ByteBuffer.allocate(4); - to.putInt(timeout); - cnxn.setSessionId(sessionId); - submitRequest(cnxn, sessionId, OpCode.createSession, 0, to, null); - return sessionId; - } - - protected void revalidateSession(ServerCnxn cnxn, long sessionId, - int sessionTimeout) throws IOException, InterruptedException { - boolean rc = sessionTracker.touchSession(sessionId, sessionTimeout); - ZooLog.logTextTraceMessage("Session " + sessionId + " is valid: " + rc, - ZooLog.SESSION_TRACE_MASK); - cnxn.finishSessionInit(rc); - } - - public void reopenSession(ServerCnxn cnxn, long sessionId, byte[] passwd, - int sessionTimeout) throws IOException, InterruptedException { - if (!checkPasswd(sessionId, passwd)) { - cnxn.finishSessionInit(false); - } else { - revalidateSession(cnxn, sessionId, sessionTimeout); - } - } - - public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader) - throws KeeperException, InterruptedException { - closeSession(cnxn.getSessionId()); - } - - public long getServerId() { - return 0; - } - - /** - * @param cnxn - * @param sessionId - * @param xid - * @param bb - */ - public void submitRequest(ServerCnxn cnxn, long sessionId, int type, - int xid, ByteBuffer bb, ArrayList authInfo) { - if (firstProcessor == null) { - synchronized (this) { - try { - while (!running) { - wait(1000); - } - } catch (InterruptedException e) { - ZooLog.logException(e); - } - if (firstProcessor == null) { - throw new RuntimeException("Not started"); - } - } - } - try { - touch(cnxn); - Request si = new Request(cnxn, sessionId, xid, type, bb, authInfo); - boolean validpacket = Request.isValid(type); - if (validpacket) { - firstProcessor.processRequest(si); - if (cnxn != null) { - incInProcess(); - } - } else { - ZooLog.logWarn("Dropping packet at server of type " + type); - // if unvalid packet drop the packet. - } - } catch (IOException e) { - ZooLog.logException(e); - } - } - - static public void byteBuffer2Record(ByteBuffer bb, Record record) - throws IOException { - BinaryInputArchive ia; - ia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); - record.deserialize(ia, "request"); - } - - public static int getSnapCount() { - String sc = System.getProperty("zookeeper.snapCount"); - try { - return Integer.parseInt(sc); - } catch (Exception e) { - return 10000; - } - } - - public int getGlobalOutstandingLimit() { - String sc = System.getProperty("zookeeper.globalOutstandingLimit"); - int limit; - try { - limit = Integer.parseInt(sc); - } catch (Exception e) { - limit = 1000; - } - return limit; - } - - public void setServerCnxnFactory(Factory factory) { - this.serverCnxnFactory = factory; - } - - public Factory getServerCnxnFactory() { - return this.serverCnxnFactory; - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/ZooLog.java b/zookeeper/java/src/com/yahoo/zookeeper/server/ZooLog.java deleted file mode 100644 index 618aa64bc3a..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/ZooLog.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.text.DateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -import com.yahoo.zookeeper.server.quorum.FollowerHandler; -import com.yahoo.zookeeper.server.quorum.QuorumPacket; - -/** - * This class encapsulates and centralizes the logging for the zookeeper server. - * Log messages go to System.out or System.err depending on the severity of the - * message. - *

        - * If the methods that do not take an explicit location are used, the location - * will be derived by creating a stack trace and then looking one frame up the - * stack trace. (It's a hack, but it works rather well.) - */ -public class ZooLog { - private static String requestTraceFile = System - .getProperty("requestTraceFile"); - - static private void formatLine(PrintStream ps, String mess, String location) { - DateFormat dateFormat = DateFormat.getDateTimeInstance( - DateFormat.SHORT, DateFormat.LONG); - StringBuffer entry = new StringBuffer(dateFormat.format(new Date()) - + " [" + location + "][" - + Long.toHexString(Thread.currentThread().getId()) + "]: "); - while (entry.length() < 45) { - entry.append(' '); - } - entry.append(mess); - ps.println(entry); - } - - public static void logError(String mess) { - RuntimeException re = new RuntimeException(); - StackTraceElement ste = re.getStackTrace()[1]; - String location = ZooLog.stackTrace2Location(ste); - ZooLog.logError(mess, location); - ZooLog.logTextTraceMessage(mess + "location: \n" + location, - textTraceMask); - } - - public static void logError(String mess, String location) { - formatLine(System.err, mess, location); - System.err.flush(); - } - - public static void logWarn(String mess) { - RuntimeException re = new RuntimeException(); - StackTraceElement ste = re.getStackTrace()[1]; - String location = ZooLog.stackTrace2Location(ste); - ZooLog.logWarn(mess, location); - ZooLog.logTextTraceMessage(mess + " location: " + location, - WARNING_TRACE_MASK); - } - - static private String stackTrace2Location(StackTraceElement ste) { - String location = ste.getFileName() + "@" + ste.getLineNumber(); - return location; - } - - public static void logWarn(String mess, String location) { - formatLine(System.out, mess, location); - System.out.flush(); - } - - private static void logException(Exception e, String mess, String location) { - StringWriter sw = new StringWriter(); - sw.append(mess); - sw.append(": "); - e.printStackTrace(new PrintWriter(sw)); - if (location == null) { - RuntimeException re = new RuntimeException(); - StackTraceElement ste = re.getStackTrace()[1]; - location = stackTrace2Location(ste); - } - logError(sw.toString(), location); - } - - public static void logException(Exception e, String mess) { - RuntimeException re = new RuntimeException(); - StackTraceElement ste = re.getStackTrace()[1]; - logException(e, mess, stackTrace2Location(ste)); - } - - public static void logException(Exception e) { - RuntimeException re = new RuntimeException(); - StackTraceElement ste = re.getStackTrace()[1]; - logException(e, "", stackTrace2Location(ste)); - } - - static FileChannel tos = null; - - static boolean loggedTraceError = false; - - static boolean traceInitialiazed = false; - - final static public long CLIENT_REQUEST_TRACE_MASK = 1 << 1; - - final static public long CLIENT_DATA_PACKET_TRACE_MASK = 1 << 2; - - final static public long CLIENT_PING_TRACE_MASK = 1 << 3; - - final static public long SERVER_PACKET_TRACE_MASK = 1 << 4; - - final static public long SESSION_TRACE_MASK = 1 << 5; - - final static public long EVENT_DELIVERY_TRACE_MASK = 1 << 6; - - final static public long SERVER_PING_TRACE_MASK = 1 << 7; - - final static public long WARNING_TRACE_MASK = 1 << 8; - - static long binaryTraceMask = CLIENT_REQUEST_TRACE_MASK - | SERVER_PACKET_TRACE_MASK | SESSION_TRACE_MASK - | WARNING_TRACE_MASK; - - static FileChannel textTos = null; - - static long textTosCreationTime = 0; - - static boolean loggedTextTraceError = false; - - static boolean textTraceInitialiazed = false; - - public static long textTraceMask = CLIENT_REQUEST_TRACE_MASK - | SERVER_PACKET_TRACE_MASK | SESSION_TRACE_MASK - | WARNING_TRACE_MASK; - - public static void setTextTraceLevel(long mask) { - textTraceMask = mask; - logTextTraceMessage("Set text trace mask to " - + Long.toBinaryString(mask), textTraceMask); - } - - public static long getTextTraceLevel() { - return textTraceMask; - } - - final static private boolean doLog(long traceMask) { - return requestTraceFile != null && (textTraceMask & traceMask) != 0; - } - - static public void logRequest(char rp, Request request, String header, - long traceMask) { - if (!doLog(traceMask)) { - return; - } - RuntimeException re = new RuntimeException(); - StackTraceElement ste = re.getStackTrace()[1]; - String location = ZooLog.stackTrace2Location(ste); - logRequestText(rp, request, header, traceMask, location); - } - - static private void write(FileChannel os, String msg) throws IOException { - os.write(ByteBuffer.wrap(msg.getBytes())); - } - - static private void writeText(FileChannel os, char rp, Request request, - String header, String location) throws IOException { - StringBuffer sb = new StringBuffer(); - long time = System.currentTimeMillis(); - sb.append( - DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.LONG).format(new Date(time))).append(" ") - .append(location).append(" "); - sb.append(header).append(":").append(rp); - sb.append(request.toString()); - write(os, sb.toString()); - write(textTos, "\n\n"); - } - - static private void writeText(FileChannel os, String message, - String location) throws IOException { - StringBuffer sb = new StringBuffer(); - long time = System.currentTimeMillis(); - sb.append( - DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.LONG).format(new Date(time))).append(" ") - .append(location).append(" "); - sb.append(message); - write(os, sb.toString()); - write(textTos, "\n\n"); - } - - static private long ROLLOVER_TIME = 24 * 3600 * 1000; - - synchronized private static void checkTextTraceFile() { - long time = System.currentTimeMillis(); - - if ((time - textTosCreationTime) > ROLLOVER_TIME) { - textTraceInitialiazed = false; - if (textTos != null) { - try { - textTos.close(); - } catch (IOException e) { - - } - textTos = null; - } - } - if (!textTraceInitialiazed) { - textTraceInitialiazed = true; - Calendar d = new GregorianCalendar(); - long year = d.get(Calendar.YEAR); - long month = d.get(Calendar.MONTH) + 1; - long day = d.get(Calendar.DAY_OF_MONTH); - - if (requestTraceFile == null) { - return; - } - requestTraceFile += "." + year + "." + month + "." + day; - - try { - textTos = new FileOutputStream(requestTraceFile + ".txt", true) - .getChannel(); - textTosCreationTime = time; - write(textTos, "\n\n"); - } catch (IOException e) { - ZooLog.logException(e); - return; - } - ZooLog.logWarn("*********** Traced requests text saved to " - + requestTraceFile + ".txt"); - } - } - - private static void checkTraceFile() { - if (!traceInitialiazed) { - traceInitialiazed = true; - String requestTraceFile = System.getProperty("requestTraceFile"); - if (requestTraceFile == null) { - return; - } - try { - tos = new FileOutputStream(requestTraceFile, true).getChannel(); - } catch (IOException e) { - ZooLog.logException(e); - return; - } - ZooLog.logWarn("*********** Traced requests saved to " - + requestTraceFile); - } - } - - static public void logQuorumPacket(char direction, QuorumPacket qp, - long traceMask) { - if (!doLog(traceMask)) { - return; - } - logTextTraceMessage(direction + " " - + FollowerHandler.packetToString(qp), traceMask); - } - - public static void logTextTraceMessage(String text, long traceMask) { - if (!doLog(traceMask)) { - return; - } - synchronized (ZooLog.class) { - checkTextTraceFile(); - if (textTos != null && !loggedTextTraceError - && ((textTraceMask & traceMask) != 0)) { - try { - RuntimeException re = new RuntimeException(); - StackTraceElement ste = re.getStackTrace()[1]; - String location = ZooLog.stackTrace2Location(ste); - writeText(textTos, text, location); - } catch (IOException e1) { - logException(e1); - loggedTextTraceError = true; - } - } - } - } - - static synchronized private void logRequestText(char rp, Request request, - String header, long traceMask, String location) { - if (!doLog(traceMask)) { - return; - } - checkTextTraceFile(); - if (textTos != null && !loggedTextTraceError - && ((traceMask & textTraceMask) != 0)) { - try { - writeText(textTos, rp, request, header, location); - } catch (IOException e1) { - logException(e1); - loggedTextTraceError = true; - } - } - } - - public void logRequestBinary(char rp, Request request, long traceMask) { - if (!doLog(traceMask)) { - return; - } - synchronized (ZooLog.class) { - checkTraceFile(); - if (tos != null && !loggedTraceError - && ((traceMask & binaryTraceMask) != 0)) { - ByteBuffer bb = ByteBuffer.allocate(41); - bb.put((byte) rp); - bb.putLong(System.currentTimeMillis()); - bb.putLong(request.sessionId); - bb.putInt(request.cxid); - bb.putLong(request.hdr == null ? -2 : request.hdr.getZxid()); - bb.putInt(request.hdr == null ? -2 : request.hdr.getType()); - bb.putInt(request.type); - if (request.request != null) { - bb.putInt(request.request.remaining()); - } else { - bb.putInt(0); - } - bb.flip(); - try { - if (request.request == null) { - tos.write(bb); - } else { - tos.write(new ByteBuffer[] { bb, - request.request.duplicate() }); - } - } catch (IOException e) { - logException(e); - loggedTraceError = true; - } - } - } - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/HostAuthenticationProvider.java b/zookeeper/java/src/com/yahoo/zookeeper/server/auth/HostAuthenticationProvider.java deleted file mode 100644 index d9559b5d8d1..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/auth/HostAuthenticationProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.auth; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.data.Id; -import com.yahoo.zookeeper.server.ServerCnxn; - -public class HostAuthenticationProvider implements AuthenticationProvider { - - public String getScheme() { - return "host"; - } - - public int handleAuthentication(ServerCnxn cnxn, byte[] authData) { - String id = cnxn.getRemoteAddress().getAddress().getCanonicalHostName(); - cnxn.getAuthInfo().add(new Id(getScheme(), id)); - return KeeperException.Code.Ok; - } - - public boolean matches(String id, String aclExpr) { - // We just do suffix matching - String idParts[] = id.split("\\."); - String expParts[] = aclExpr.split("\\."); - int diff = idParts.length - expParts.length; - if (diff < 0) { - return false; - } - for (int i = 0; i < expParts.length; i++) { - if (idParts[i + diff].equals(expParts[i])) { - return false; - } - } - return true; - } - - public boolean isAuthenticated() { - return false; - } - - public boolean isValid(String id) { - String parts[] = id.split("\\."); - for (String part : parts) { - if (part.length() == 0) { - return false; - } - } - return true; - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/package.html b/zookeeper/java/src/com/yahoo/zookeeper/server/package.html deleted file mode 100644 index 99e98e4c8a6..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/package.html +++ /dev/null @@ -1,84 +0,0 @@ - - -

        ZooKeeper server theory of operation

        -ZooKeeperServer is designed to work in standalone mode and also -be extensible so that it can be used to implement the quorum based -version of ZooKeeper. -

        -ZooKeeper maintains a order when processing requests: -

          -
        • All requests will be processed in order. -
        • All responses will return in order. -
        • All watches will be sent in the order that the update takes place. -
        -

        -We will explain the three aspects of ZooKeeperServer: request processing, data -structure maintence, and session tracking. - -

        Request processing

        - -Requests are received by the ServerCnxn. Demarshalling of a request is -done by ClientRequestHandler. After a request has be Demarshalled, -ClientRequestHandler invokes the relevant method in ZooKeeper and marshals -the result. -

        -If the request is just a query, it will be processed by ZooKeeper and returned. -Otherwise, the request will be validated and a transaction will be generated -and logged. This the request will then wait until the request has been logged -before continuing processing. -

        -Requests are logged as a group. Transactions are queued up and the SyncThread -will process them at predefined intervals. (Currently 20ms) The SyncThread -interacts with ZooKeeperServer the txnQueue. Transactions are added to the -txnQueue of SyncThread via queueItem. When the transaction has been synced to -disk, its callback will be invoked which will cause the request processing to -be completed. - -

        Data structure maintence

        - -ZooKeeper data is stored in-memory. Each znode is stored in a DataNode object. -This object is accessed through a hashtable that maps paths to DataNodes. -DataNodes also organize themselves into a tree. This tree is only used for -serializing nodes. -

        -We guarantee that changes to nodes are stored to non-volatile media before -responding to a client. We do this quickly by writing changes as a sequence -of transactions in a log file. Even though we flush transactions as a group, -we need to avoid seeks as much as possible. Also, since the server can fail -at any point, we need to be careful of partial records. -

        -We address the above problems by -

          -
        • Preallocating 1M chunks of file space. This allows us to append to the -file without causing seeks to update file size. It also means that we need -to check for the end of the log by looking for a zero length transaction -rather than simply end of file. -
        • Writing a signature at the end of each transaction. When processing -transactions, we only use transactions that have a valid signature at the end. -
        -

        -As the server runs, the log file will grow quite large. To avoid long startup -times we periodically take a snapshot of the tree of DataNodes. We cannot -take the snapshot synchronously as the data takes a while to write out, so -instead we asynchronously write out the tree. This means that we end up -with a "corrupt" snapshot of the data tree. More formally if we define T -to be the real snapshot of the tree at the time we begin taking the snapshot -and l as the sequence of transactions that are applied to the tree between -the time the snapshot begins and the time the snapshot completes, we write -to disk T+l' where l' is a subset of the transactions in l. While we do not -have a way of figuring out which transactions make up l', it doesn't really -matter. T+l'+l = T+l since the transactions we log are idepotent (applying -the transaction multiple times has the same result as applying the transaction -once). So when we restore the snapshot we also play all transactions in the log -that occur after the snapshot was begun. We can easily figure out where to -start the replay because we start a new logfile when we start a snapshot. Both -the snapshot file and log file have a numeric suffix that represent the -transaction id that created the respective files. - -

        Session tracking

        -Rather than tracking sessions exactly, we track them in batches. That are -processed at fixed intervals. This is easier to implement than exact -session tracking and it is more efficient in terms of performance. It also -provides a small grace period for session renewal. - - \ No newline at end of file diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/AckRequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/AckRequestProcessor.java deleted file mode 100644 index c2a46a0f98e..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/AckRequestProcessor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.RequestProcessor; - -/** - * This is a very simple RequestProcessor that simply forwards a request from a - * previous stage to the leader as an ACK. - */ -class AckRequestProcessor implements RequestProcessor { - Leader leader; - - AckRequestProcessor(Leader leader) { - this.leader = leader; - } - - /** - * Forward the request as an ACK to the leader - */ - public void processRequest(Request request) { - leader.processAck(request.zxid, null); - } - - public void shutdown() { - // XXX No need to do anything - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/CommitProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/CommitProcessor.java deleted file mode 100644 index e6450417d38..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/CommitProcessor.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.util.ArrayList; -import java.util.LinkedList; - -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.RequestProcessor; -import com.yahoo.zookeeper.server.ZooLog; - -/** - * This RequestProcessor matches the incoming committed requests with the - * locally submitted requests. The trick is that locally submitted requests that - * change the state of the system will come back as incoming committed requests, - * so we need to match them up. - */ -public class CommitProcessor extends Thread implements RequestProcessor { - /** - * Requests that we are holding until the commit comes in. - */ - LinkedList queuedRequests = new LinkedList(); - - /** - * Requests that have been committed. - */ - LinkedList committedRequests = new LinkedList(); - - RequestProcessor nextProcessor; - - public CommitProcessor(RequestProcessor nextProcessor) { - this.nextProcessor = nextProcessor; - start(); - } - - boolean finished = false; - - public void run() { - try { - Request nextPending = null; - ArrayList toProcess = new ArrayList(); - while (!finished) { - int len = toProcess.size(); - for (int i = 0; i < len; i++) { - nextProcessor.processRequest(toProcess.get(i)); - } - toProcess.clear(); - synchronized (this) { - if ((queuedRequests.size() == 0 || nextPending != null) - && committedRequests.size() == 0) { - wait(); - continue; - } - // First check and see if the commit came in for the pending - // request - if ((queuedRequests.size() == 0 || nextPending != null) - && committedRequests.size() > 0) { - Request r = committedRequests.remove(); - /* - * We match with nextPending so that we can move to the - * next request when it is committed. We also want to - * use nextPending because it has the cnxn member set - * properly. - */ - if (nextPending != null - && nextPending.sessionId == r.sessionId - && nextPending.cxid == r.cxid) { - // we want to send our version of the request. - // the pointer to the connection in the request - nextPending.hdr = r.hdr; - nextPending.txn = r.txn; - nextPending.zxid = r.zxid; - toProcess.add(nextPending); - nextPending = null; - } else { - // this request came from someone else so just - // send the commit packet - toProcess.add(r); - } - } - } - - // We haven't matched the pending requests, so go back to - // waiting - if (nextPending != null) { - continue; - } - - synchronized (this) { - // Process the next requests in the queuedRequests - while (nextPending == null && queuedRequests.size() > 0) { - Request request = queuedRequests.remove(); - switch (request.type) { - case OpCode.create: - case OpCode.delete: - case OpCode.setData: - case OpCode.setACL: - case OpCode.createSession: - case OpCode.closeSession: - nextPending = request; - break; - default: - toProcess.add(request); - } - } - } - } - } catch (Exception e) { - ZooLog.logException(e); - } - ZooLog.logTextTraceMessage("CommitProcessor exited loop!", - ZooLog.textTraceMask); - } - - synchronized public void commit(Request request) { - if (!finished) { - if (request == null) { - ZooLog.logException(new Exception("committing a null! ")); - return; - } - committedRequests.add(request); - notifyAll(); - } - } - - synchronized public void processRequest(Request request) { - // request.addRQRec(">commit"); - // ZooLog.logWarn("Zoo processReq>>> cxid = " + request.cxid + " type = - // " + request.type + " id = " + request.sessionId + " cnxn " + - // request.cnxn); - if (!finished) { - queuedRequests.add(request); - notifyAll(); - } - } - - public void shutdown() { - finished = true; - queuedRequests.clear(); - synchronized (this) { - notifyAll(); - } - nextProcessor.shutdown(); - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/Follower.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/Follower.java deleted file mode 100644 index 2d111131f87..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/Follower.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * This class has the control logic for the Follower. - */ -package com.yahoo.zookeeper.server.quorum; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.ConnectException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - -import com.yahoo.jute.BinaryInputArchive; -import com.yahoo.jute.BinaryOutputArchive; -import com.yahoo.jute.InputArchive; -import com.yahoo.jute.OutputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.ServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.server.quorum.QuorumPeer.QuorumServer; -import com.yahoo.zookeeper.server.quorum.QuorumPeer.ServerState; -import com.yahoo.zookeeper.txn.TxnHeader; - -public class Follower { - QuorumPeer self; - - FollowerZooKeeperServer zk; - - Follower(QuorumPeer self) { - this.self = self; - } - - private InputArchive leaderIs; - - private OutputArchive leaderOs; - - private BufferedOutputStream bufferedOutput; - - public Socket sock; - - /** - * write a packet to the leader - * - * @param pp - * the proposal packet to be sent to the leader - * @throws IOException - */ - void writePacket(QuorumPacket pp) throws IOException { - long traceMask = ZooLog.SERVER_PACKET_TRACE_MASK; - if (pp.getType() == Leader.PING) { - traceMask = ZooLog.SERVER_PING_TRACE_MASK; - } - ZooLog.logQuorumPacket('o', pp, traceMask); - synchronized (leaderOs) { - leaderOs.writeRecord(pp, "packet"); - bufferedOutput.flush(); - } - } - - /** - * read a packet from the leader - * - * @param pp - * the packet to be instantiated - * @throws IOException - */ - void readPacket(QuorumPacket pp) throws IOException { - synchronized (leaderIs) { - leaderIs.readRecord(pp, "packet"); - } - long traceMask = ZooLog.SERVER_PACKET_TRACE_MASK; - if (pp.getType() == Leader.PING) { - traceMask = ZooLog.SERVER_PING_TRACE_MASK; - } - ZooLog.logQuorumPacket('i', pp, traceMask); - } - - /** - * the main method called by the follower to follow the leader - * - * @throws InterruptedException - */ - void followLeader() throws InterruptedException { - InetSocketAddress addr = null; - // Find the leader by id - for (QuorumServer s : self.quorumPeers) { - if (s.id == self.currentVote.id) { - addr = s.addr; - break; - } - } - if (addr == null) { - ZooLog.logError("Couldn't find the leader with id = " - + self.currentVote.id); - } - ZooLog.logWarn("Following " + addr); - sock = new Socket(); - try { - QuorumPacket ack = new QuorumPacket(Leader.ACK, 0, null, null); - sock.setSoTimeout(self.tickTime * self.initLimit); - for (int tries = 0; tries < 3; tries++) { - try { - sock.connect(addr, self.tickTime * self.syncLimit); - sock.setTcpNoDelay(true); - break; - } catch (ConnectException e) { - ZooLog.logException(e); - if (tries == 2) { - throw e; - } - } - Thread.sleep(1000); - } - leaderIs = BinaryInputArchive.getArchive(new BufferedInputStream( - sock.getInputStream())); - bufferedOutput = new BufferedOutputStream(sock.getOutputStream()); - leaderOs = BinaryOutputArchive.getArchive(bufferedOutput); - QuorumPacket qp = new QuorumPacket(); - qp.setType(Leader.LASTZXID); - long sentLastZxid = self.getLastLoggedZxid(); - qp.setZxid(sentLastZxid); - writePacket(qp); - readPacket(qp); - if (qp.getType() != Leader.NEWLEADER) { - ZooLog.logError("First packet should have been NEWLEADER"); - throw new IOException("First packet should have been NEWLEADER"); - } - zk = new FollowerZooKeeperServer(self.getId(), self.dataDir, - self.dataLogDir, this); - synchronized (zk) { - if (qp.getZxid() != sentLastZxid) { - // The leader is going to dump the database - zk.loadData(leaderIs); - String signature = leaderIs.readString("signature"); - if (!signature.equals("BenWasHere")) { - ZooLog.logError("Missing signature. Got " + signature); - throw new IOException("Missing signature"); - } - } else { - zk.loadData(); - } - zk.dataTree.lastProcessedZxid = qp.getZxid(); - } - ack.setZxid(qp.getZxid() & ~0xffffffffL); - writePacket(ack); - sock.setSoTimeout(self.tickTime * self.syncLimit); - zk.startup(); - while (self.running) { - readPacket(qp); - switch (qp.getType()) { - case Leader.PING: - // Send back the ping with our session data - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(bos); - HashMap touchTable = ((FollowerZooKeeperServer) zk) - .getTouchSnapshot(); - for (Entry entry : touchTable.entrySet()) { - dos.writeLong(entry.getKey()); - dos.writeInt(entry.getValue()); - } - qp.setData(bos.toByteArray()); - writePacket(qp); - break; - case Leader.PROPOSAL: - TxnHeader hdr = new TxnHeader(); - BinaryInputArchive ia = BinaryInputArchive - .getArchive(new ByteArrayInputStream(qp.getData())); - Record txn = ZooKeeperServer.deserializeTxn(ia, hdr); - if (hdr.getZxid() != lastQueued + 1) { - ZooLog.logWarn("Got zxid " - + Long.toHexString(hdr.getZxid()) - + " expected " - + Long.toHexString(lastQueued + 1)); - } - lastQueued = hdr.getZxid(); - zk.logRequest(hdr, txn); - break; - case Leader.COMMIT: - zk.commit(qp.getZxid()); - break; - case Leader.UPTODATE: - zk.snapshot(); - self.cnxnFactory.setZooKeeperServer(zk); - break; - case Leader.REVALIDATE: - ByteArrayInputStream bis = new ByteArrayInputStream(qp - .getData()); - DataInputStream dis = new DataInputStream(bis); - long sessionId = dis.readLong(); - boolean valid = dis.readBoolean(); - synchronized (pendingRevalidations) { - ServerCnxn cnxn = pendingRevalidations - .remove(sessionId); - if (cnxn == null) { - ZooLog.logWarn("Missing " - + Long.toHexString(sessionId) - + " for validation"); - } else { - cnxn.finishSessionInit(valid); - } - } - ZooLog.logTextTraceMessage("Session " + sessionId - + " is valid: " + valid, ZooLog.SESSION_TRACE_MASK); - } - } - } catch (IOException e) { - try { - sock.close(); - } catch (IOException e1) { - e1.printStackTrace(); - } - - synchronized (pendingRevalidations) { - // clear pending revalitions - pendingRevalidations.clear(); - pendingRevalidations.notifyAll(); - } - } finally { - self.state = ServerState.LOOKING; - } - } - - private long lastQueued; - - ConcurrentHashMap pendingRevalidations = new ConcurrentHashMap(); - - /** - * validate a seesion for a client - * - * @param clientId - * the client to be revailidated - * @param timeout - * the timeout for which the session is valid - * @return - * @throws IOException - * @throws InterruptedException - */ - void validateSession(ServerCnxn cnxn, long clientId, int timeout) - throws IOException, InterruptedException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - dos.writeLong(clientId); - dos.writeInt(timeout); - dos.close(); - QuorumPacket qp = new QuorumPacket(Leader.REVALIDATE, -1, baos - .toByteArray(), null); - pendingRevalidations.put(clientId, cnxn); - ZooLog.logTextTraceMessage("To validate session " + clientId, - ZooLog.SESSION_TRACE_MASK); - writePacket(qp); - } - - /** - * send a request packet to the leader - * - * @param request - * the request from the client - * @throws IOException - */ - void request(Request request) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream oa = new DataOutputStream(baos); - oa.writeLong(request.sessionId); - oa.writeInt(request.cxid); - oa.writeInt(request.type); - if (request.request != null) { - request.request.rewind(); - int len = request.request.remaining(); - byte b[] = new byte[len]; - request.request.get(b); - request.request.rewind(); - oa.write(b); - } - oa.close(); - QuorumPacket qp = new QuorumPacket(Leader.REQUEST, -1, baos - .toByteArray(), request.authInfo); - writePacket(qp); - } - - public long getZxid() { - try { - synchronized (zk) { - return zk.getZxid(); - } - } catch (NullPointerException e) { - } - return -1; - } - - public void shutdown() { - - // set the zookeeper server to null - self.cnxnFactory.setZooKeeperServer(null); - // clear all the connections - self.cnxnFactory.clear(); - // shutdown previous zookeeper - if (zk != null) { - zk.shutdown(); - - } - ZooLog.logException(new Exception("shutdown Follower")); - self.state = ServerState.LOOKING; - - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerHandler.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerHandler.java deleted file mode 100644 index 3cadd76caa5..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerHandler.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.Socket; -import java.nio.ByteBuffer; -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.jute.BinaryInputArchive; -import com.yahoo.jute.BinaryOutputArchive; -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * There will be an instance of this class created by the Leader for each - * follower.All communication for a given Follower will be handled by this - * class. - */ -public class FollowerHandler extends Thread { - public Socket s; - - Leader leader; - - long tickOfLastAck; - - /** - * The packets to be sent to the follower - */ - LinkedBlockingQueue queuedPackets = new LinkedBlockingQueue(); - - private BinaryInputArchive ia; - - private BinaryOutputArchive oa; - - private BufferedOutputStream bufferedOutput; - - FollowerHandler(Socket s, Leader leader) throws IOException { - super("FollowerHandler-" + s.getRemoteSocketAddress()); - this.s = s; - this.leader = leader; - leader.addFollowerHandler(this); - start(); - } - - /** - * If this packet is queued, the sender thread will exit - */ - QuorumPacket proposalOfDeath = new QuorumPacket(); - - /** - * This method will use the thread to send packets added to the - * queuedPackets list - * - * @throws InterruptedException - */ - private void sendPackets() throws InterruptedException { - long traceMask = ZooLog.SERVER_PACKET_TRACE_MASK; - while (true) { - QuorumPacket p; - p = queuedPackets.take(); - - if (p == proposalOfDeath) { - // Packet of death! - break; - } - if (p.getType() == Leader.PING) { - traceMask = ZooLog.SERVER_PING_TRACE_MASK; - } - ZooLog.logQuorumPacket('o', p, traceMask); - try { - oa.writeRecord(p, "packet"); - bufferedOutput.flush(); - } catch (IOException e) { - if (!s.isClosed()) { - ZooLog.logException(e); - } - break; - } - } - } - - static public String packetToString(QuorumPacket p) { - if (true) - return null; - String type = null; - String mess = null; - Record txn = null; - switch (p.getType()) { - case Leader.ACK: - type = "ACK"; - break; - case Leader.COMMIT: - type = "COMMIT"; - break; - case Leader.LASTZXID: - type = "LASTZXID"; - break; - case Leader.NEWLEADER: - type = "NEWLEADER"; - break; - case Leader.PING: - type = "PING"; - break; - case Leader.PROPOSAL: - type = "PROPOSAL"; - BinaryInputArchive ia = BinaryInputArchive - .getArchive(new ByteArrayInputStream(p.getData())); - TxnHeader hdr = new TxnHeader(); - try { - txn = ZooKeeperServer.deserializeTxn(ia, hdr); - // mess = "transaction: " + txn.toString(); - } catch (IOException e) { - ZooLog.logException(e); - } - break; - case Leader.REQUEST: - type = "REQUEST"; - break; - case Leader.REVALIDATE: - type = "REVALIDATE"; - ByteArrayInputStream bis = new ByteArrayInputStream(p.getData()); - DataInputStream dis = new DataInputStream(bis); - try { - long id = dis.readLong(); - mess = " sessionid = " + id; - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - break; - case Leader.UPTODATE: - type = "UPTODATE"; - break; - default: - type = "UNKNOWN" + p.getType(); - } - String entry = null; - if (type != null) { - entry = type + " " + Long.toHexString(p.getZxid()) + " " + mess; - } - return entry; - } - - /** - * This thread will receive packets from the follower and process them and - * also listen to new connections from new followers. - */ - public void run() { - try { - - ia = BinaryInputArchive.getArchive(new BufferedInputStream(s - .getInputStream())); - bufferedOutput = new BufferedOutputStream(s.getOutputStream()); - oa = BinaryOutputArchive.getArchive(bufferedOutput); - - QuorumPacket qp = new QuorumPacket(); - ia.readRecord(qp, "packet"); - if (qp.getType() != Leader.LASTZXID) { - ZooLog.logError("First packet " + qp.toString() - + " is not LASTZXID!"); - return; - } - long peerLastZxid = qp.getZxid(); - long leaderLastZxid = leader.startForwarding(this, peerLastZxid); - QuorumPacket newLeaderQP = new QuorumPacket(Leader.NEWLEADER, - leaderLastZxid, null, null); - oa.writeRecord(newLeaderQP, "packet"); - if (leaderLastZxid != peerLastZxid) { - ZooLog.logWarn("sending Snapshot"); - // Dump data to follower - leader.zk.snapshot(oa); - oa.writeString("BenWasHere", "signature"); - } - bufferedOutput.flush(); - // - // Mutation packets will be queued during the serialize, - // so we need to mark when the follower can actually start - // using the data - // - queuedPackets - .add(new QuorumPacket(Leader.UPTODATE, -1, null, null)); - - // Start sending packets - new Thread() { - public void run() { - Thread.currentThread().setName( - "Sender-" + s.getRemoteSocketAddress()); - try { - sendPackets(); - } catch (InterruptedException e) { - ZooLog.logException(e); - } - } - }.start(); - - while (true) { - qp = new QuorumPacket(); - ia.readRecord(qp, "packet"); - - long traceMask = ZooLog.SERVER_PACKET_TRACE_MASK; - if (qp.getType() == Leader.PING) { - traceMask = ZooLog.SERVER_PING_TRACE_MASK; - } - ZooLog.logQuorumPacket('i', qp, traceMask); - tickOfLastAck = leader.self.tick; - switch (qp.getType()) { - case Leader.ACK: - leader.processAck(qp.getZxid(), s.getLocalSocketAddress()); - break; - case Leader.PING: - // Process the touches - ByteArrayInputStream bis = new ByteArrayInputStream(qp - .getData()); - DataInputStream dis = new DataInputStream(bis); - while (dis.available() > 0) { - long sess = dis.readLong(); - int to = dis.readInt(); - leader.zk.touch(sess, to); - } - break; - case Leader.REVALIDATE: - bis = new ByteArrayInputStream(qp.getData()); - dis = new DataInputStream(bis); - long id = dis.readLong(); - int to = dis.readInt(); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(bos); - dos.writeLong(id); - boolean valid = leader.zk.touch(id, to); - ZooLog.logTextTraceMessage("Session " + id + " is valid: " - + valid, ZooLog.SESSION_TRACE_MASK); - dos.writeBoolean(valid); - qp.setData(bos.toByteArray()); - queuedPackets.add(qp); - break; - case Leader.REQUEST: - ByteBuffer bb = ByteBuffer.wrap(qp.getData()); - long sessionId = bb.getLong(); - int cxid = bb.getInt(); - int type = bb.getInt(); - bb = bb.slice(); - leader.zk.submitRequest(null, sessionId, type, cxid, bb, - null); - break; - default: - } - } - } catch (IOException e) { - if (s != null && !s.isClosed()) { - ZooLog.logException(e); - } - } catch (InterruptedException e) { - ZooLog.logException(e); - } finally { - ZooLog.logWarn("******* GOODBYE " + s.getRemoteSocketAddress() - + " ********"); - // Send the packet of death - try { - queuedPackets.put(proposalOfDeath); - } catch (InterruptedException e) { - ZooLog.logException(e); - } - shutdown(); - } - } - - public void shutdown() { - try { - if (s != null && !s.isClosed()) { - s.close(); - } - } catch (IOException e) { - ZooLog.logException(e); - } - leader.removeFollowerHandler(this); - } - - public long tickOfLastAck() { - return tickOfLastAck; - } - - /** - * ping calls from the leader to the followers - */ - public void ping() { - QuorumPacket ping = new QuorumPacket(Leader.PING, leader.lastProposed, - null, null); - queuePacket(ping); - } - - void queuePacket(QuorumPacket p) { - queuedPackets.add(p); - } - - public boolean synced() { - return isAlive() - && tickOfLastAck >= leader.self.tick - leader.self.syncLimit; - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerRequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerRequestProcessor.java deleted file mode 100644 index 154bbc77a8a..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerRequestProcessor.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.zookeeper.ZooDefs.OpCode; -import com.yahoo.zookeeper.server.RequestProcessor; -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.ZooLog; - -/** - * This RequestProcessor forwards any requests that modify the state of the - * system to the Leader. - */ -public class FollowerRequestProcessor extends Thread implements - RequestProcessor { - FollowerZooKeeperServer zks; - - RequestProcessor nextProcessor; - - LinkedBlockingQueue queuedRequests = new LinkedBlockingQueue(); - - boolean finished = false; - - public FollowerRequestProcessor(FollowerZooKeeperServer zks, - RequestProcessor nextProcessor) { - this.zks = zks; - this.nextProcessor = nextProcessor; - start(); - } - - public void run() { - try { - while (!finished) { - Request request = queuedRequests.take(); - ZooLog.logRequest('F', request, "", - ZooLog.CLIENT_REQUEST_TRACE_MASK); - if (request == Request.requestOfDeath) { - break; - } - // We want to queue the request to be processed before we submit - // the request to the leader so that we are ready to receive - // the response - nextProcessor.processRequest(request); - switch (request.type) { - case OpCode.create: - case OpCode.delete: - case OpCode.setData: - case OpCode.setACL: - case OpCode.createSession: - case OpCode.closeSession: - zks.follower.request(request); - break; - } - } - } catch (Exception e) { - ZooLog.logException(e); - } - ZooLog.logTextTraceMessage("FollowerRequestProcessor exited loop!", - ZooLog.textTraceMask); - } - - public void processRequest(Request request) { - if (!finished) { - queuedRequests.add(request); - } - } - - public void shutdown() { - finished = true; - queuedRequests.clear(); - queuedRequests.add(Request.requestOfDeath); - nextProcessor.shutdown(); - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerSessionTracker.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerSessionTracker.java deleted file mode 100644 index bad4f3b85a4..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerSessionTracker.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.util.HashMap; -import java.util.concurrent.ConcurrentHashMap; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.server.SessionTracker; - -/** - * This is really just a shell of a SessionTracker that tracks session activity - * to be forwarded to the Leader using a PING. - */ -public class FollowerSessionTracker implements SessionTracker { - SessionExpirer expirer; - - HashMap touchTable = new HashMap(); - - private ConcurrentHashMap sessionsWithTimeouts; - - /** - * - */ - public FollowerSessionTracker(SessionExpirer expirer, - ConcurrentHashMap sessionsWithTimeouts) { - this.expirer = expirer; - this.sessionsWithTimeouts = sessionsWithTimeouts; - nextSessionId ^= expirer.getServerId() << 24; - } - - synchronized public void removeSession(long sessionId) { - sessionsWithTimeouts.remove(sessionId); - touchTable.remove(sessionId); - } - - public void shutdown() { - } - - synchronized public void addSession(long sessionId, int sessionTimeout) { - sessionsWithTimeouts.put(sessionId, sessionTimeout); - touchTable.put(sessionId, sessionTimeout); - } - - synchronized public boolean touchSession(long sessionId, int sessionTimeout) { - touchTable.put(sessionId, sessionTimeout); - return true; - } - - synchronized HashMap snapshot() { - HashMap oldTouchTable = touchTable; - touchTable = new HashMap(); - return oldTouchTable; - } - - long nextSessionId = System.currentTimeMillis() << 24; - - synchronized public long createSession(int sessionTimeout) { - return (nextSessionId++); - } - - public void checkSession(long sessionId) throws KeeperException { - // Nothing to do here. Sessions are checked at the Leader - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerZooKeeperServer.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerZooKeeperServer.java deleted file mode 100644 index da95337c9dd..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/FollowerZooKeeperServer.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.concurrent.LinkedBlockingQueue; - -import com.yahoo.jute.Record; -import com.yahoo.zookeeper.server.FinalRequestProcessor; -import com.yahoo.zookeeper.server.RequestProcessor; -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.ServerCnxn; -import com.yahoo.zookeeper.server.SyncRequestProcessor; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * Just like the standard ZooKeeperServer. We just replace the request - * processors: FollowerRequestProcessor -> CommitProcessor -> - * FinalRequestProcessor - * - * A SyncRequestProcessor is also spawn off to log proposals from the leader. - */ -class FollowerZooKeeperServer extends ZooKeeperServer { - Follower follower; - - CommitProcessor commitProcessor; - - SyncRequestProcessor syncProcessor; - - long serverId; - - /** - * @param port - * @param dataDir - * @throws IOException - */ - FollowerZooKeeperServer(long serverId, File dataDir, File dataLogDir, - Follower follower) throws IOException { - super(dataDir, dataLogDir, follower.self.tickTime); - this.serverId = serverId; - this.follower = follower; - } - - protected void createSessionTracker() { - sessionTracker = new FollowerSessionTracker(this, sessionsWithTimeouts); - } - - protected void setupRequestProcessors() { - RequestProcessor finalProcessor = new FinalRequestProcessor(this); - commitProcessor = new CommitProcessor(finalProcessor); - firstProcessor = new FollowerRequestProcessor(this, commitProcessor); - syncProcessor = new SyncRequestProcessor(this, - new SendAckRequestProcessor(follower)); - } - - @Override - protected void revalidateSession(ServerCnxn cnxn, long sessionId, - int sessionTimeout) throws IOException, InterruptedException { - follower.validateSession(cnxn, sessionId, sessionTimeout); - } - - /** - * @return - */ - public HashMap getTouchSnapshot() { - if (sessionTracker != null) { - return ((FollowerSessionTracker) sessionTracker).snapshot(); - } - return new HashMap(); - } - - @Override - public long getServerId() { - return serverId; - } - - LinkedBlockingQueue pendingTxns = new LinkedBlockingQueue(); - - public void logRequest(TxnHeader hdr, Record txn) { - Request request = new Request(null, hdr.getClientId(), hdr.getCxid(), - hdr.getType(), null, null); - request.hdr = hdr; - request.txn = txn; - request.zxid = hdr.getZxid(); - if ((request.zxid & 0xffffffffL) != 0) { - pendingTxns.add(request); - } - syncProcessor.processRequest(request); - } - - public void commit(long zxid) { - if (pendingTxns.size() == 0) { - ZooLog.logWarn("Committing " + Long.toHexString(zxid) - + " without seeing txn"); - return; - } - long firstElementZxid = pendingTxns.element().zxid; - if (firstElementZxid != zxid) { - ZooLog.logError("Committing " + Long.toHexString(zxid) - + " but next pending txn " - + Long.toHexString(firstElementZxid)); - System.exit(12); - } - Request request = pendingTxns.remove(); - commitProcessor.commit(request); - } - - @Override - public int getGlobalOutstandingLimit() { - return super.getGlobalOutstandingLimit() - / (follower.self.quorumPeers.size() - 1); - } - - public void shutdown() { - try { - super.shutdown(); - } catch (Exception e) { - ZooLog.logException(e); - } - try { - if (syncProcessor != null) { - syncProcessor.shutdown(); - } - } catch (Exception e) { - ZooLog.logException(e); - } - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/Leader.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/Leader.java deleted file mode 100644 index 468cd857eb6..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/Leader.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.BindException; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketAddress; -import java.util.HashSet; -import java.util.Iterator; -import java.util.concurrent.ConcurrentLinkedQueue; - -import com.yahoo.jute.BinaryOutputArchive; -import com.yahoo.zookeeper.server.FinalRequestProcessor; -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.RequestProcessor; -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.server.quorum.QuorumPeer.ServerState; - -/** - * This class has the control logic for the Leader. - */ -public class Leader { - static public class Proposal { - public QuorumPacket packet; - - public int ackCount; - - public Request request; - - public String toString() { - return packet.getType() + ", " + packet.getZxid() + ", " + request; - } - } - - LeaderZooKeeperServer zk; - - QuorumPeer self; - - // list of all the followers - public HashSet followers = new HashSet(); - - // list of followers that are ready to follow (i.e synced with the leader) - public HashSet forwardingFollowers = new HashSet(); - - /** - * Adds follower to the leader. - * - * @param follower - * instance of follower handle - */ - void addFollowerHandler(FollowerHandler follower) { - synchronized (followers) { - followers.add(follower); - } - } - - /** - * Remove the follower from the followers list - * - * @param follower - */ - void removeFollowerHandler(FollowerHandler follower) { - synchronized (forwardingFollowers) { - forwardingFollowers.remove(follower); - } - synchronized (followers) { - followers.remove(follower); - } - } - - ServerSocket ss; - - Leader(QuorumPeer self) throws IOException { - this.self = self; - try { - ss = new ServerSocket(self.myQuorumAddr.getPort()); - } catch (BindException e) { - ZooLog.logError("Couldn't bind to port " - + self.myQuorumAddr.getPort()); - throw e; - } - } - - /** - * This message type is sent by the leader to indicate it's zxid and if - * needed, its database. - */ - final static int NEWLEADER = 10; - - /** - * This message type is sent by a follower to indicate the last zxid in its - * log. - */ - final static int LASTZXID = 11; - - /** - * This message type is sent by the leader to indicate that the follower is - * now uptodate andt can start responding to clients. - */ - final static int UPTODATE = 12; - - /** - * This message type is sent to a leader to request and mutation operation. - * The payload will consist of a request header followed by a request. - */ - final static int REQUEST = 1; - - /** - * This message type is sent by a leader to propose a mutation. - */ - final static int PROPOSAL = 2; - - /** - * This message type is sent by a follower after it has synced a proposal. - */ - final static int ACK = 3; - - /** - * This message type is sent by a leader to commit a proposal and cause - * followers to start serving the corresponding data. - */ - final static int COMMIT = 4; - - /** - * This message type is enchanged between follower and leader (initiated by - * follower) to determine liveliness. - */ - final static int PING = 5; - - /** - * This message type is to validate a session that should be active. - */ - final static int REVALIDATE = 6; - - private ConcurrentLinkedQueue outstandingProposals = new ConcurrentLinkedQueue(); - - ConcurrentLinkedQueue toBeApplied = new ConcurrentLinkedQueue(); - - Proposal newLeaderProposal = new Proposal(); - - /** - * This method is main function that is called to lead - * - * @throws IOException - * @throws InterruptedException - */ - void lead() throws IOException, InterruptedException { - self.tick = 0; - zk = new LeaderZooKeeperServer(self.getId(), self.dataDir, - self.dataLogDir, this); - zk.loadData(); - zk.startup(); - long epoch = self.getLastLoggedZxid() >> 32L; - epoch++; - zk.setZxid(epoch << 32L); - zk.dataTree.lastProcessedZxid = zk.getZxid(); - lastProposed = zk.getZxid(); - newLeaderProposal.packet = new QuorumPacket(NEWLEADER, zk.getZxid(), - null, null); - if ((newLeaderProposal.packet.getZxid() & 0xffffffffL) != 0) { - ZooLog.logError("NEWLEADER proposal has Zxid of " - + newLeaderProposal.packet.getZxid()); - } - outstandingProposals.add(newLeaderProposal); - new Thread() { - public void run() { - try { - while (true) { - Socket s = ss.accept(); - s.setSoTimeout(self.tickTime * self.syncLimit); - s.setTcpNoDelay(true); - new FollowerHandler(s, Leader.this); - } - } catch (Exception e) { - // - } - } - }.start(); - // We have to get at least a majority of servers in sync with - // us. We do this by waiting for the NEWLEADER packet to get - // acknowledged - newLeaderProposal.ackCount++; - while (newLeaderProposal.ackCount <= self.quorumPeers.size() / 2) { - if (self.tick > self.initLimit) { - // Followers aren't syncing fast enough, - // renounce leadership! - shutdown("Waiting for " + (self.quorumPeers.size() / 2) - + " followers, only synced with " - + newLeaderProposal.ackCount); - if (followers.size() >= self.quorumPeers.size() / 2) { - ZooLog - .logWarn("Enough followers present. Perhaps the initTicks need to be increased."); - } - self.state = ServerState.LOOKING; - return; - } - Thread.sleep(self.tickTime); - self.tick++; - } - if (!System.getProperty("zookeeper.leaderServes", "yes").equals("no")) { - self.cnxnFactory.setZooKeeperServer(zk); - } - // Everything is a go, simply start counting the ticks - synchronized (this) { - notifyAll(); - } - // We ping twice a tick, so we only update the tick every other - // iteration - boolean tickSkip = true; - - while (true) { - Thread.sleep(self.tickTime / 2); - if (!tickSkip) { - self.tick++; - } - int syncedCount = 0; - // lock on the followers when we use it. - synchronized (followers) { - for (FollowerHandler f : followers) { - if (f.synced()) { - syncedCount++; - } - f.ping(); - } - } - if (!tickSkip && syncedCount < self.quorumPeers.size() / 2) { - // Lost quorum, shutdown - shutdown("Only " + syncedCount + " followers, need " - + (self.quorumPeers.size() / 2)); - // make sure the order is the same! - // the leader goes to looking - self.state = ServerState.LOOKING; - - return; - } - tickSkip = !tickSkip; - } - } - - boolean isShutdown; - - /** - * Close down all the FollowerHandlers - */ - void shutdown(String reason) { - if (isShutdown) { - return; - } - - ZooLog - .logException(new Exception("shutdown Leader! reason: " - + reason)); - // NIO should not accept conenctions - self.cnxnFactory.setZooKeeperServer(null); - // clear all the connections - self.cnxnFactory.clear(); - // shutdown the previous zk - if (zk != null) { - zk.shutdown(); - } - try { - ss.close(); - } catch (IOException e) { - ZooLog.logException(e); - } - synchronized (followers) { - for (Iterator it = followers.iterator(); it - .hasNext();) { - FollowerHandler f = it.next(); - it.remove(); - f.shutdown(); - } - } - isShutdown = true; - } - - /** - * Keep a count of acks that are received by the leader for a particular - * proposal - * - * @param zxid - * the zxid of the proposal sent out - * @param followerAddr - */ - synchronized public void processAck(long zxid, SocketAddress followerAddr) { - boolean first = true; - /* - * ZooLog.logError("Ack zxid: " + Long.toHexString(zxid)); for (Proposal - * p : outstandingProposals) { long packetZxid = p.packet.getZxid(); - * ZooLog.logError("outstanding proposal: " + - * Long.toHexString(packetZxid)); } ZooLog.logError("outstanding - * proposals all"); - */ - if (outstandingProposals.size() == 0) { - return; - } - if (outstandingProposals.peek().packet.getZxid() > zxid) { - // The proposal has already been committed - return; - } - for (Proposal p : outstandingProposals) { - long packetZxid = p.packet.getZxid(); - if (packetZxid == zxid) { - p.ackCount++; - // ZooLog.logException(new RuntimeException(), "Count for " + - // Long.toHexString(zxid) + " is " + p.ackCount); - if (p.ackCount > self.quorumPeers.size() / 2) { - if (!first) { - ZooLog.logError("Commiting " + Long.toHexString(zxid) - + " from " + followerAddr + " not first!"); - ZooLog.logError("First is " - + outstandingProposals.element().packet); - System.exit(13); - } - outstandingProposals.remove(); - if (p.request != null) { - toBeApplied.add(p); - } - // We don't commit the new leader proposal - if ((zxid & 0xffffffffL) != 0) { - if (p.request == null) { - ZooLog.logError("Going to commmit null: " + p); - } - commit(zxid); - zk.commitProcessor.commit(p.request); - } - } - return; - } else { - first = false; - } - } - ZooLog.logError("Trying to commit future proposal: " - + Long.toHexString(zxid) + " from " + followerAddr); - } - - static class ToBeAppliedRequestProcessor implements RequestProcessor { - private RequestProcessor next; - - private ConcurrentLinkedQueue toBeApplied; - - /** - * This request processor simply maintains the toBeApplied list. For - * this to work next must be a FinalRequestProcessor and - * FinalRequestProcessor.processRequest MUST process the request - * synchronously! - * - * @param next - * a reference to the FinalRequestProcessor - */ - ToBeAppliedRequestProcessor(RequestProcessor next, - ConcurrentLinkedQueue toBeApplied) { - if (!(next instanceof FinalRequestProcessor)) { - throw new RuntimeException(ToBeAppliedRequestProcessor.class - .getName() - + " must be connected to " - + FinalRequestProcessor.class.getName() - + " not " - + next.getClass().getName()); - } - this.toBeApplied = toBeApplied; - this.next = next; - } - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.server.RequestProcessor#processRequest(com.yahoo.zookeeper.server.Request) - */ - public void processRequest(Request request) { - // request.addRQRec(">tobe"); - next.processRequest(request); - Proposal p = toBeApplied.peek(); - if (p != null && p.request != null - && p.request.zxid == request.zxid) { - toBeApplied.remove(); - } - } - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.server.RequestProcessor#shutdown() - */ - public void shutdown() { - next.shutdown(); - } - } - - /** - * send a packet to all the followers ready to follow - * - * @param qp - * the packet to be sent - */ - void sendPacket(QuorumPacket qp) { - synchronized (forwardingFollowers) { - for (FollowerHandler f : forwardingFollowers) { - f.queuePacket(qp); - } - } - } - - long lastCommitted; - - /** - * Create a commit packet and send it to all the members of the quorum - * - * @param zxid - */ - public void commit(long zxid) { - lastCommitted = zxid; - QuorumPacket qp = new QuorumPacket(Leader.COMMIT, zxid, null, null); - sendPacket(qp); - } - - long lastProposed; - - /** - * create a proposal and send it out to all the members - * - * @param request - * @return the proposal that is queued to send to all the members - */ - public Proposal propose(Request request) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); - try { - request.hdr.serialize(boa, "hdr"); - if (request.txn != null) { - request.txn.serialize(boa, "txn"); - } - baos.close(); - } catch (IOException e) { - // This really should be impossible - ZooLog.logException(e); - } - QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid, baos - .toByteArray(), null); - Proposal p = new Proposal(); - p.packet = pp; - p.request = request; - synchronized (this) { - outstandingProposals.add(p); - lastProposed = p.packet.getZxid(); - sendPacket(pp); - } - return p; - } - - /** - * lets the leader know that a follower is capable of following and is done - * syncing - * - * @param handler - * handler of the follower - * @return last proposed zxid - */ - synchronized public long startForwarding(FollowerHandler handler, - long lastSeenZxid) { - // Queue up any outstanding requests enabling the receipt of - // new requests - if (lastProposed > lastSeenZxid) { - for (Proposal p : toBeApplied) { - if (p.packet.getZxid() <= lastSeenZxid) { - continue; - } - handler.queuePacket(p.packet); - // Since the proposal has been committed we need to send the - // commit message - // also - QuorumPacket qp = new QuorumPacket(Leader.COMMIT, p.packet - .getZxid(), null, null); - handler.queuePacket(qp); - } - for (Proposal p : outstandingProposals) { - if (p.packet.getZxid() <= lastSeenZxid) { - continue; - } - handler.queuePacket(p.packet); - } - } - synchronized (forwardingFollowers) { - forwardingFollowers.add(handler); - return lastProposed; - } - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/LeaderElection.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/LeaderElection.java deleted file mode 100644 index d964a531b24..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/LeaderElection.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetSocketAddress; -import java.net.SocketException; -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.HashMap; -import java.util.Random; -import java.util.Map.Entry; - -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.server.quorum.QuorumPeer.QuorumServer; -import com.yahoo.zookeeper.server.quorum.QuorumPeer.ServerState; - -public class LeaderElection { - static public class Vote { - public Vote(long id, long zxid) { - this.id = id; - this.zxid = zxid; - } - - public long id; - - public long zxid; - - @Override - public boolean equals(Object o) { - if (!(o instanceof Vote)) { - return false; - } - Vote other = (Vote) o; - return id == other.id && zxid == other.zxid; - } - - @Override - public int hashCode() { - return (int) (id & zxid); - } - - } - - QuorumPeer self; - - public LeaderElection(QuorumPeer self) { - this.self = self; - } - - public static class ElectionResult { - public Vote vote; - - public int count; - - public Vote winner; - - public int winningCount; - } - - private ElectionResult countVotes(HashMap votes) { - ElectionResult result = new ElectionResult(); - // Initialize with null vote - result.vote = new Vote(Long.MIN_VALUE, Long.MIN_VALUE); - result.winner = new Vote(Long.MIN_VALUE, Long.MIN_VALUE); - Collection votesCast = votes.values(); - // First make the views consistent. Sometimes peers will have - // different zxids for a server depending on timing. - for (Vote v : votesCast) { - for (Vote w : votesCast) { - if (v.id == w.id) { - if (v.zxid < w.zxid) { - v.zxid = w.zxid; - } - } - } - } - HashMap countTable = new HashMap(); - // Now do the tally - for (Vote v : votesCast) { - Integer count = countTable.get(v); - if (count == null) { - count = new Integer(0); - } - countTable.put(v, count + 1); - if (v.id == result.vote.id) { - result.count++; - } else if (v.zxid > result.vote.zxid - || (v.zxid == result.vote.zxid && v.id > result.vote.id)) { - result.vote = v; - result.count = 1; - } - } - result.winningCount = 0; - ZooLog.logWarn("Election tally: "); - for (Entry entry : countTable.entrySet()) { - if (entry.getValue() > result.winningCount) { - result.winningCount = entry.getValue(); - result.winner = entry.getKey(); - } - ZooLog.logWarn(entry.getKey().id + "\t-> " + entry.getValue()); - } - return result; - } - - public Vote lookForLeader() throws InterruptedException { - self.currentVote = new Vote(self.myid, self.getLastLoggedZxid()); - // We are going to look for a leader by casting a vote for ourself - byte requestBytes[] = new byte[4]; - ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); - byte responseBytes[] = new byte[28]; - ByteBuffer responseBuffer = ByteBuffer.wrap(responseBytes); - /* The current vote for the leader. Initially me! */ - DatagramSocket s = null; - try { - s = new DatagramSocket(); - s.setSoTimeout(200); - } catch (SocketException e1) { - e1.printStackTrace(); - System.exit(4); - } - DatagramPacket requestPacket = new DatagramPacket(requestBytes, - requestBytes.length); - DatagramPacket responsePacket = new DatagramPacket(responseBytes, - responseBytes.length); - HashMap votes = new HashMap( - self.quorumPeers.size()); - int xid = new Random().nextInt(); - while (self.running) { - votes.clear(); - requestBuffer.clear(); - requestBuffer.putInt(xid); - requestPacket.setLength(4); - for (QuorumServer server : self.quorumPeers) { - requestPacket.setSocketAddress(server.addr); - try { - s.send(requestPacket); - responsePacket.setLength(responseBytes.length); - s.receive(responsePacket); - if (responsePacket.getLength() != responseBytes.length) { - ZooLog.logError("Got a short response: " - + responsePacket.getLength()); - continue; - } - responseBuffer.clear(); - int recvedXid = responseBuffer.getInt(); - if (recvedXid != xid) { - ZooLog.logError("Got bad xid: expected " + xid - + " got " + recvedXid); - continue; - } - long peerId = responseBuffer.getLong(); - server.id = peerId; - Vote vote = new Vote(responseBuffer.getLong(), - responseBuffer.getLong()); - InetSocketAddress addr = (InetSocketAddress) responsePacket - .getSocketAddress(); - votes.put(addr, vote); - } catch (IOException e) { - // Errors are okay, since hosts may be - // down - // ZooKeeperServer.logException(e); - } - } - ElectionResult result = countVotes(votes); - if (result.winner.id >= 0) { - self.currentVote = result.vote; - if (result.winningCount > (self.quorumPeers.size() / 2)) { - self.currentVote = result.winner; - s.close(); - self.state = (self.currentVote.id == self.myid) ? ServerState.LEADING - : ServerState.FOLLOWING; - if (self.state == ServerState.FOLLOWING) { - Thread.sleep(100); - } - return self.currentVote; - } - } - Thread.sleep(1000); - } - return null; - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/LeaderZooKeeperServer.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/LeaderZooKeeperServer.java deleted file mode 100644 index d2d9b976688..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/LeaderZooKeeperServer.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.io.File; -import java.io.IOException; - -import com.yahoo.zookeeper.server.FinalRequestProcessor; -import com.yahoo.zookeeper.server.PrepRequestProcessor; -import com.yahoo.zookeeper.server.RequestProcessor; -import com.yahoo.zookeeper.server.ZooKeeperServer; - -/** - * - * Just like the standard ZooKeeperServer. We just replace the request - * processors: PrepRequestProcessor -> ProposalRequestProcessor -> - * CommitProcessor -> Leader.ToBeAppliedRequestProcessor -> - * FinalRequestProcessor - */ -public class LeaderZooKeeperServer extends ZooKeeperServer { - Leader leader; - - long serverId; - - CommitProcessor commitProcessor; - - /** - * @param port - * @param dataDir - * @throws IOException - */ - LeaderZooKeeperServer(long serverId, File dataDir, File dataLogDir, - Leader leader) throws IOException { - super(dataDir, dataLogDir, leader.self.tickTime); - this.serverId = serverId; - this.leader = leader; - } - - protected void setupRequestProcessors() { - RequestProcessor finalProcessor = new FinalRequestProcessor(this); - RequestProcessor toBeAppliedProcessor = new Leader.ToBeAppliedRequestProcessor( - finalProcessor, leader.toBeApplied); - commitProcessor = new CommitProcessor(toBeAppliedProcessor); - RequestProcessor proposalProcessor = new ProposalRequestProcessor(this, - commitProcessor); - firstProcessor = new PrepRequestProcessor(this, proposalProcessor); - } - - @Override - public int getGlobalOutstandingLimit() { - return super.getGlobalOutstandingLimit() - / (leader.self.quorumPeers.size() - 1); - } - - public boolean touch(long sess, int to) { - return sessionTracker.touchSession(sess, to); - } - - public void setZxid(long zxid) { - hzxid = zxid; - } -} \ No newline at end of file diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/ProposalRequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/ProposalRequestProcessor.java deleted file mode 100644 index e68188d7c62..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/ProposalRequestProcessor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.RequestProcessor; -import com.yahoo.zookeeper.server.SyncRequestProcessor; - -/** - * This RequestProcessor simply forwards requests to an AckRequestProcessor and - * SyncRequestProcessor. - */ -public class ProposalRequestProcessor implements RequestProcessor { - LeaderZooKeeperServer zks; - - RequestProcessor nextProcessor; - - SyncRequestProcessor syncProcessor; - - public ProposalRequestProcessor(LeaderZooKeeperServer zks, - RequestProcessor nextProcessor) { - this.zks = zks; - this.nextProcessor = nextProcessor; - AckRequestProcessor ackProcessor = new AckRequestProcessor(zks.leader); - syncProcessor = new SyncRequestProcessor(zks, ackProcessor); - } - - public void processRequest(Request request) { - // ZooLog.logWarn("Ack>>> cxid = " + request.cxid + " type = " + - // request.type + " id = " + request.sessionId); - // request.addRQRec(">prop"); - nextProcessor.processRequest(request); - if (request.hdr != null) { - // We need to sync and get consensus on any transactions - zks.leader.propose(request); - syncProcessor.processRequest(request); - } - } - - public void shutdown() { - nextProcessor.shutdown(); - syncProcessor.shutdown(); - } - -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/QuorumPeer.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/QuorumPeer.java deleted file mode 100644 index 2462e33627f..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/QuorumPeer.java +++ /dev/null @@ -1,520 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetSocketAddress; -import java.net.SocketException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Properties; -import java.util.Map.Entry; - -import com.yahoo.jute.BinaryInputArchive; -import com.yahoo.jute.InputArchive; -import com.yahoo.zookeeper.server.NIOServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.server.quorum.LeaderElection.Vote; -import com.yahoo.zookeeper.txn.TxnHeader; - -/** - * This class manages the quorum protocol. There are three states this server - * can be in: - *
          - *
        1. Leader election - each server will elect a leader (proposing itself as a - * leader initially).
        2. - *
        3. Follower - the server will synchronize with the leader and replicate any - * transactions.
        4. - *
        5. Leader - the server will process requests and forward them to followers. - * A majority of followers must log the request before it can be accepted. - *
        - * - * This class will setup a datagram socket that will always respond with its - * view of the current leader. The response will take the form of: - * - *
        - * int xid;
        - * 
        - * long myid;
        - * 
        - * long leader_id;
        - * 
        - * long leader_zxid;
        - * 
        - * - * The request for the current leader will consist solely of an xid: int xid; - * - *

        Configuration file

        - * - * When the main() method of this class is used to start the program, the file - * "zoo.cfg" in the current directory will be used to obtain configuration - * information. zoo.cfg is a Properties file, so keys and values are separated - * by equals (=) and the key/value pairs are separated by new lines. The - * following keys are used in the configuration file: - *
          - *
        1. dataDir - The directory where the zookeeper data is stored.
        2. - *
        3. clientPort - The port used to communicate with clients.
        4. - *
        5. tickTime - The duration of a tick in milliseconds. This is the basic - * unit of time in zookeeper.
        6. - *
        7. initLimit - The maximum number of ticks that a follower will wait to - * initially synchronize with a leader.
        8. - *
        9. syncLimit - The maximum number of ticks that a follower will wait for a - * message (including heartbeats) from the leader.
        10. - *
        11. server.id - This is the host:port that the server with the - * given id will use for the quorum protocol.
        12. - *
        - * In addition to the zoo.cfg file. There is a file in the data directory called - * "myid" that contains the server id as an ASCII decimal value. - */ -public class QuorumPeer extends Thread { - public static class QuorumServer { - public QuorumServer(long id, InetSocketAddress addr) { - this.id = id; - this.addr = addr; - } - - public InetSocketAddress addr; - - public long id; - } - - public enum ServerState { - LOOKING, FOLLOWING, LEADING; - } - - /** - * The servers that make up the cluster - */ - ArrayList quorumPeers; - - /** - * My id - */ - long myid; - - /** - * This is who I think the leader currently is. - */ - volatile Vote currentVote; - - boolean running = true; - - /** - * The number of milliseconds of each tick - */ - int tickTime; - - /** - * The number of ticks that the initial synchronization phase can take - */ - int initLimit; - - /** - * The number of ticks that can pass between sending a request and getting - * an acknowledgement - */ - int syncLimit; - - /** - * The current tick - */ - int tick; - - /** - * This class simply responds to requests for the current leader of this - * node. - *

        - * The request contains just an xid generated by the requestor. - *

        - * The response has the xid, the id of this server, the id of the leader, - * and the zxid of the leader. - * - * @author breed - * - */ - class ResponderThread extends Thread { - ResponderThread() { - super("ResponderThread"); - } - - public void run() { - try { - byte b[] = new byte[36]; - ByteBuffer responseBuffer = ByteBuffer.wrap(b); - DatagramPacket packet = new DatagramPacket(b, b.length); - while (true) { - udpSocket.receive(packet); - if (packet.getLength() != 4) { - ZooLog.logError("Got more than just an xid! Len = " - + packet.getLength()); - } else { - responseBuffer.clear(); - responseBuffer.getInt(); // Skip the xid - responseBuffer.putLong(myid); - switch (state) { - case LOOKING: - responseBuffer.putLong(currentVote.id); - responseBuffer.putLong(currentVote.zxid); - break; - case LEADING: - responseBuffer.putLong(myid); - try { - responseBuffer.putLong(leader.lastProposed); - } catch (NullPointerException npe) { - // This can happen in state transitions, - // just ignore the request - } - break; - case FOLLOWING: - responseBuffer.putLong(currentVote.id); - try { - responseBuffer.putLong(follower.getZxid()); - } catch (NullPointerException npe) { - // This can happen in state transitions, - // just ignore the request - } - } - packet.setData(b); - udpSocket.send(packet); - } - packet.setLength(b.length); - } - } catch (Exception e) { - ZooLog.logException(e); - } finally { - ZooLog.logError("QuorumPeer responder thread exited"); - } - } - } - - public ServerState state = ServerState.LOOKING; - - DatagramSocket udpSocket; - - InetSocketAddress myQuorumAddr; - - /** - * the directory where the snapshot is stored. - */ - File dataDir; - - /** - * the directory where the logs are stored. - */ - File dataLogDir; - - int clientPort; - - int electionAlg; - - NIOServerCnxn.Factory cnxnFactory; - - public QuorumPeer(ArrayList quorumPeers, File dataDir, - File dataLogDir, int clientPort, int electionAlg, long myid, - int tickTime, int initLimit, int syncLimit) throws IOException { - super("QuorumPeer"); - this.clientPort = clientPort; - this.cnxnFactory = new NIOServerCnxn.Factory(clientPort, this); - this.quorumPeers = quorumPeers; - this.dataDir = dataDir; - this.electionAlg = electionAlg; - this.dataLogDir = dataLogDir; - this.myid = myid; - this.tickTime = tickTime; - this.initLimit = initLimit; - this.syncLimit = syncLimit; - currentVote = new Vote(myid, getLastLoggedZxid()); - for (QuorumServer p : quorumPeers) { - if (p.id == myid) { - myQuorumAddr = p.addr; - break; - } - } - if (myQuorumAddr == null) { - throw new SocketException("My id " + myid + " not in the peer list"); - } - if (electionAlg == 0) { - udpSocket = new DatagramSocket(myQuorumAddr.getPort()); - new ResponderThread().start(); - } - } - - public Follower follower; - - public Leader leader; - - public void run() { - - /* - * Main loop - */ - while (running) { - switch (state) { - case LOOKING: - try { - ZooLog.logWarn("LOOKING"); - switch (electionAlg) { - case 0: - currentVote = new LeaderElection(this).lookForLeader(); - break; - } - } catch (Exception e) { - ZooLog.logException(e); - state = ServerState.LOOKING; - } - break; - case FOLLOWING: - try { - ZooLog.logWarn("FOLLOWING"); - follower = new Follower(this); - follower.followLeader(); - } catch (Exception e) { - ZooLog.logException(e); - } finally { - follower.shutdown(); - follower = null; - state = ServerState.LOOKING; - } - break; - case LEADING: - ZooLog.logWarn("LEADING"); - try { - leader = new Leader(this); - leader.lead(); - leader = null; - } catch (Exception e) { - ZooLog.logException(e); - } finally { - if (leader != null) { - leader.shutdown("Forcing shutdown"); - } - state = ServerState.LOOKING; - } - break; - } - } - ZooLog.logError("QuorumPeer main thread exited"); - } - - public void shutdown() { - running = false; - if (leader != null) { - leader.shutdown("quorum Peer shutdown"); - } - if (follower != null) { - follower.shutdown(); - } - cnxnFactory.shutdown(); - udpSocket.close(); - } - - long getLastLoggedZxid() { - File[] list = dataLogDir.listFiles(); - if (list == null) { - return 0; - } - long maxLog = -1; - long maxSnapShot = 0; - for (File f : list) { - String name = f.getName(); - if (name.startsWith("log.")) { - long zxid = ZooKeeperServer.getZxidFromName(f.getName(), "log"); - if (zxid > maxLog) { - maxLog = zxid; - } - } else if (name.startsWith("snapshot.")) { - long zxid = ZooKeeperServer.getZxidFromName(f.getName(), - "snapshot"); - if (zxid > maxLog) { - maxSnapShot = zxid; - } - } - } - if (maxSnapShot > maxLog) { - return maxSnapShot; - } - long zxid = maxLog; - FileInputStream logStream = null; - try { - logStream = new FileInputStream(new File(dataLogDir, "log." - + Long.toHexString(maxLog))); - BinaryInputArchive ia = BinaryInputArchive.getArchive(logStream); - while (true) { - byte[] bytes = ia.readBuffer("txnEntry"); - if (bytes.length == 0) { - // Since we preallocate, we define EOF to be an - // empty transaction - break; - } - int B = ia.readByte("EOR"); - if (B != 'B') { - break; - } - InputArchive bia = BinaryInputArchive - .getArchive(new ByteArrayInputStream(bytes)); - TxnHeader hdr = new TxnHeader(); - hdr.deserialize(bia, "hdr"); - zxid = hdr.getZxid(); - } - } catch (IOException e) { - ZooLog.logWarn(e.toString()); - } finally { - try { - if (logStream != null) { - logStream.close(); - } - } catch (IOException e) { - ZooLog.logException(e); - } - } - return zxid; - } - - public static void main(String args[]) { - try { - if (args.length == 2) { - ZooKeeperServer.main(args); - return; - } - if (args.length != 1) { - System.err.println("USAGE: configFile"); - System.exit(2); - return; - } - File zooCfgFile = new File(args[0]); - if (!zooCfgFile.exists()) { - ZooLog.logError(zooCfgFile.toString() + " file is missing"); - return; - } - Properties cfg = new Properties(); - cfg.load(new FileInputStream(zooCfgFile)); - ArrayList servers = new ArrayList(); - File dataDir = null; - File dataLogDir = null; - int clientPort = 0; - int tickTime = 0; - int initLimit = 0; - int syncLimit = 0; - int electionAlg = 0; - for (Entry entry : cfg.entrySet()) { - String key = entry.getKey().toString(); - String value = entry.getValue().toString(); - if (key.equals("dataDir")) { - dataDir = new File(value); - } else if (key.equals("dataLogDir")) { - dataLogDir = new File(value); - } else if (key.equals("traceFile")) { - System.setProperty("requestTraceFile", value); - } else if (key.equals("clientPort")) { - clientPort = Integer.parseInt(value); - } else if (key.equals("tickTime")) { - tickTime = Integer.parseInt(value); - } else if (key.equals("initLimit")) { - initLimit = Integer.parseInt(value); - } else if (key.equals("syncLimit")) { - syncLimit = Integer.parseInt(value); - } else if (key.equals("electionAlg")) { - electionAlg = Integer.parseInt(value); - } else if (key.startsWith("server.")) { - int dot = key.indexOf('.'); - long sid = Long.parseLong(key.substring(dot + 1)); - String parts[] = value.split(":"); - if (parts.length != 2) { - ZooLog.logError(value - + " does not have the form host:port"); - } - InetSocketAddress addr = new InetSocketAddress(parts[0], - Integer.parseInt(parts[1])); - servers.add(new QuorumServer(sid, addr)); - } else { - System.setProperty("zookeeper." + key, value); - } - } - if (dataDir == null) { - ZooLog.logError("dataDir is not set"); - System.exit(2); - } - if (dataLogDir == null) { - dataLogDir = dataDir; - } else { - if (!dataLogDir.isDirectory()) { - ZooLog - .logError("dataLogDir " + dataLogDir - + " is missing."); - System.exit(2); - } - } - if (clientPort == 0) { - ZooLog.logError("clientPort is not set"); - System.exit(2); - } - if (tickTime == 0) { - ZooLog.logError("tickTime is not set"); - System.exit(2); - } - if (servers.size() > 1 && initLimit == 0) { - ZooLog.logError("initLimit is not set"); - System.exit(2); - } - if (servers.size() > 1 && syncLimit == 0) { - ZooLog.logError("syncLimit is not set"); - System.exit(2); - } - if (servers.size() > 1) { - File myIdFile = new File(dataDir, "myid"); - if (!myIdFile.exists()) { - ZooLog.logError(myIdFile.toString() + " file is missing"); - return; - } - BufferedReader br = new BufferedReader(new FileReader(myIdFile)); - String myIdString = br.readLine(); - long id; - try { - id = Long.parseLong(myIdString); - } catch (NumberFormatException e) { - ZooLog.logError(myIdString + " is not a number"); - System.exit(2); - return; // makes the id not initialized warning go away... - } - QuorumPeer self = new QuorumPeer(servers, dataDir, dataLogDir, - clientPort, electionAlg, id, tickTime, initLimit, - syncLimit); - self.start(); - self.join(); - } else { - int port = clientPort; - ZooKeeperServer zk = new ZooKeeperServer(dataDir, dataLogDir, tickTime); - zk.startup(); - NIOServerCnxn.Factory t = new NIOServerCnxn.Factory(port); - t.setZooKeeperServer(zk); - t.join(); - zk.shutdown(); - } - } catch (Exception e) { - ZooLog.logException(e); - } - System.exit(2); - } -} diff --git a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/SendAckRequestProcessor.java b/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/SendAckRequestProcessor.java deleted file mode 100644 index 61fb7fac7e1..00000000000 --- a/zookeeper/java/src/com/yahoo/zookeeper/server/quorum/SendAckRequestProcessor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2008, Yahoo! Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.yahoo.zookeeper.server.quorum; - -import java.io.IOException; - -import com.yahoo.zookeeper.server.Request; -import com.yahoo.zookeeper.server.RequestProcessor; -import com.yahoo.zookeeper.server.ZooLog; - -public class SendAckRequestProcessor implements RequestProcessor { - Follower follower; - - SendAckRequestProcessor(Follower follower) { - this.follower = follower; - } - - public void processRequest(Request si) { - QuorumPacket qp = new QuorumPacket(Leader.ACK, si.hdr.getZxid(), null, - null); - try { - follower.writePacket(qp); - } catch (IOException e) { - ZooLog.logException(e); - } - } - - public void shutdown() { - // Nothing needed - } - -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/AsyncTest.java b/zookeeper/test/com/yahoo/zookeeper/test/AsyncTest.java deleted file mode 100644 index c6d85eae5f8..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/AsyncTest.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.yahoo.zookeeper.test; - -import java.io.File; -import java.io.IOException; -import java.util.LinkedList; -import java.util.concurrent.LinkedBlockingQueue; - -import junit.framework.TestCase; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.AsyncCallback.DataCallback; -import com.yahoo.zookeeper.AsyncCallback.StringCallback; -import com.yahoo.zookeeper.AsyncCallback.VoidCallback; -import com.yahoo.zookeeper.KeeperException.Code; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.NIOServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import com.yahoo.zookeeper.server.ZooLog; - -public class AsyncTest extends TestCase implements Watcher, StringCallback, VoidCallback, DataCallback { - protected static String hostPort = "127.0.0.1:33221"; - LinkedBlockingQueue events = new LinkedBlockingQueue(); - static File baseTest = new File(System.getProperty("build.test.dir", "build")); - NIOServerCnxn.Factory f = null; - QuorumTest qt = new QuorumTest(); - @Before - protected void setUp() throws Exception { - qt.setUp(); - hostPort = ClientTest.hostPort; - } - - protected void restart() throws Exception { - qt.startServers(); - } - - @After - protected void tearDown() throws Exception { - qt.tearDown(); - ZooLog.logError("Clent test shutdown"); - if (f != null) { - f.shutdown(); - } - ZooLog.logError("Client test shutdown finished"); - } - - boolean bang; - - class HammerThread extends Thread implements Watcher, StringCallback, VoidCallback { - ZooKeeper zk; - public void run() { - try { - zk = new ZooKeeper(hostPort, 30000, this); - while(bang) { - zk.create("/test-", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE, this, null); - incOut(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - int outstanding; - synchronized void incOut() throws InterruptedException { - outstanding++; - while(outstanding > 30) { - wait(); - } - } - synchronized void decOut() { - outstanding--; - notifyAll(); - } - - @Override - public void process(WatcherEvent event) { - } - - @Override - public void processResult(int rc, String path, Object ctx, String name) { - try { - decOut(); - zk.delete(path, -1, this, null); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void processResult(int rc, String path, Object ctx) { - } - } - - @Test - public void testHammer() throws Exception { - Thread.sleep(1000); - bang = true; - for(int i = 0; i < 100; i++) { - new HammerThread().start(); - } - Thread.sleep(5000); - tearDown(); - bang = false; - restart(); - Thread.sleep(5000); - String parts[] = hostPort.split(","); - String prevList[] = null; - for(String hp: parts) { - ZooKeeper zk = new ZooKeeper(hp, 30000, this); - String list[] = zk.getChildren("/", false).toArray(new String[0]); - if (prevList != null) { - assertEquals(prevList.length, list.length); - for(int i = 0; i < list.length; i++) { - assertEquals(prevList[i], list[i]); - } - } - prevList = list; - } - } - - LinkedList results = new LinkedList(); - @Test - public void testAsync() throws KeeperException, IOException, - InterruptedException { - ZooKeeper zk = null; - zk = new ZooKeeper(hostPort, 30000, this); - zk.addAuthInfo("digest", "ben:passwd".getBytes()); - zk.create("/ben", new byte[0], Ids.READ_ACL_UNSAFE, 0, this, results); - zk.create("/ben/2", new byte[0], Ids.CREATOR_ALL_ACL, 0, this, results); - zk.delete("/ben", -1, this, results); - zk.create("/ben2", new byte[0], Ids.CREATOR_ALL_ACL, 0, this, results); - zk.getData("/ben2", false, this, results); - synchronized(results) { - while(results.size() < 5) { - results.wait(); - } - } - assertEquals(0, (int)results.get(0)); - assertEquals(Code.NoAuth, (int)results.get(1)); - assertEquals(0, (int)results.get(2)); - assertEquals(0, (int)results.get(3)); - assertEquals(0, (int)results.get(4)); - zk.close(); - - zk = new ZooKeeper(hostPort, 30000, this); - zk.addAuthInfo("digest", "ben:passwd2".getBytes()); - try { - zk.getData("/ben2", false, new Stat()); - fail("Should have received a permission error"); - } catch(KeeperException e) { - assertEquals(Code.NoAuth, e.getCode()); - } - zk.close(); - - zk = new ZooKeeper(hostPort, 30000, this); - zk.addAuthInfo("digest", "ben:passwd".getBytes()); - zk.getData("/ben2", false, new Stat()); - zk.close(); - - } - - public void process(WatcherEvent event) { - // TODO Auto-generated method stub - - } - - public void processResult(int rc, String path, Object ctx, String name) { - ((LinkedList)ctx).add(rc); - synchronized(ctx) { - ctx.notifyAll(); - } - } - - public void processResult(int rc, String path, Object ctx) { - ((LinkedList)ctx).add(rc); - synchronized(ctx) { - ctx.notifyAll(); - } - } - - public void processResult(int rc, String path, Object ctx, byte[] data, - Stat stat) { - ((LinkedList)ctx).add(rc); - synchronized(ctx) { - ctx.notifyAll(); - } - } -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/ClientTest.java b/zookeeper/test/com/yahoo/zookeeper/test/ClientTest.java deleted file mode 100755 index 64d44e04036..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/ClientTest.java +++ /dev/null @@ -1,295 +0,0 @@ -package com.yahoo.zookeeper.test; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -import junit.framework.TestCase; -import org.junit.Test; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.KeeperException.Code; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.NIOServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import com.yahoo.zookeeper.server.ZooLog; - -public class ClientTest extends TestCase implements Watcher { - protected static String hostPort = "127.0.0.1:33221"; - LinkedBlockingQueue events = new LinkedBlockingQueue(); - static File baseTest = new File(System.getProperty("build.test.dir", "build")); - NIOServerCnxn.Factory f = null; - File tmpDir = null; - - protected void setUp() throws Exception { - ZooLog.logError("Client test setup"); - tmpDir = File.createTempFile("test", ".junit", baseTest); - tmpDir = new File(tmpDir + ".dir"); - tmpDir.mkdirs(); - ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); - hostPort = "127.0.0.1:33221"; - f = new NIOServerCnxn.Factory(33221); - f.startup(zks); - Thread.sleep(5000); - ZooLog.logError("Client test setup finished"); - } - - protected void tearDown() throws Exception { - ZooLog.logError("Clent test shutdown"); - if (tmpDir != null) { - recursiveDelete(tmpDir); - } - if (f != null) { - f.shutdown(); - } - ZooLog.logError("Client test shutdown finished"); - } - - static void recursiveDelete(File d) { - if (d.isDirectory()) { - File children[] = d.listFiles(); - for (File f : children) { - recursiveDelete(f); - } - } - d.delete(); - } - - @Test - public void testClient() throws KeeperException, IOException, - InterruptedException { - ZooKeeper zk = null; - try { - zk = new ZooKeeper(hostPort, 30000, this); - //System.out.println("Created client: " + zk.describeCNXN()); - System.out.println("Before create /benwashere"); - zk.create("/benwashere", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0); - System.out.println("After create /benwashere"); - try { - zk.setData("/benwashere", "hi".getBytes(), 57); - fail("Should have gotten BadVersion exception"); - } catch(KeeperException e) { - if (e.getCode() != Code.BadVersion) { - fail("Should have gotten BadVersion exception"); - } - } - System.out.println("Before delete /benwashere"); - zk.delete("/benwashere", 0); - System.out.println("Before delete /benwashere"); - zk.close(); - //System.out.println("Closed client: " + zk.describeCNXN()); - Thread.sleep(2000); - zk = new ZooKeeper(hostPort, 30000, this); - //System.out.println("Created a new client: " + zk.describeCNXN()); - System.out.println("Before delete /"); - - try { - zk.delete("/", -1); - fail("deleted root!"); - } catch(KeeperException e) { - assertEquals(KeeperException.Code.BadArguments, e.getCode()); - } - Stat stat = new Stat(); - // Test basic create, ls, and getData - System.out.println("Before create /ben"); - zk.create("/ben", "Ben was here".getBytes(), Ids.OPEN_ACL_UNSAFE, 0); - System.out.println("Before getChildren /"); - ArrayList children = zk.getChildren("/", false); - assertEquals(1, children.size()); - assertEquals("ben", children.get(0)); - String value = new String(zk.getData("/ben", false, stat)); - assertEquals("Ben was here", value); - // Test stat and watch of non existent node - try { - assertEquals(null, zk.exists("/frog", true)); - System.out.println("Comment: asseting passed for frog setting /"); - } catch (KeeperException e) { - assertEquals(Code.NoNode, e.getCode()); - } - zk.create("/frog", "hi".getBytes(), Ids.OPEN_ACL_UNSAFE, 0); - // the first poll is just a sesssion delivery - System.out.println("Comment: checking for events length " + events.size()); - WatcherEvent event = events.poll(10, TimeUnit.SECONDS); - assertEquals("/frog", event.getPath()); - assertEquals(Event.EventNodeCreated, event.getType()); - assertEquals(Event.KeeperStateSyncConnected, event.getState()); - // Test child watch and create with sequence - zk.getChildren("/ben", true); - for (int i = 0; i < 10; i++) { - zk.create("/ben/" + i + "-", Integer.toString(i).getBytes(), - Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE); - } - children = zk.getChildren("/ben", false); - Collections.sort(children); - assertEquals(10, children.size()); - for (int i = 0; i < 10; i++) { - final String name = children.get(i); - assertTrue(name.startsWith(i + "-")); - byte b[] = zk.getData("/ben/" + name, true, stat); - assertEquals(Integer.toString(i), new String(b)); - zk.setData("/ben/" + name, "new".getBytes(), stat.getVersion()); - stat = zk.exists("/ben/" + name, true); - zk.delete("/ben/" + name, stat.getVersion()); - } - event = events.poll(10, TimeUnit.SECONDS); - assertEquals("/ben", event.getPath()); - assertEquals(Event.EventNodeChildrenChanged, event.getType()); - assertEquals(Event.KeeperStateSyncConnected, event.getState()); - for (int i = 0; i < 10; i++) { - event = events.poll(10, TimeUnit.SECONDS); - final String name = children.get(i); - assertEquals("/ben/" + name, event.getPath()); - assertEquals(Event.EventNodeDataChanged, event.getType()); - assertEquals(Event.KeeperStateSyncConnected, event.getState()); - event = events.poll(10, TimeUnit.SECONDS); - assertEquals("/ben/" + name, event.getPath()); - assertEquals(Event.EventNodeDeleted, event.getType()); - assertEquals(Event.KeeperStateSyncConnected, event.getState()); - } - zk.create("/good\u0001path", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0); - //try { - // zk.create("/bad\u0000path", "".getBytes(), null, 0); - // fail("created an invalid path"); - //} catch(KeeperException e) { - // assertEquals(KeeperException.Code.BadArguments, e.getCode()); - //} - - zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0); - try { - zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0); - fail("duplicate create allowed"); - } catch(KeeperException e) { - assertEquals(Code.NodeExists, e.getCode()); - } - } finally { - if (zk != null) { - zk.close(); - } - } - } - - private void notestConnections() throws KeeperException, IOException, InterruptedException { - ZooKeeper zk; - for(int i = 0; i < 2000; i++) { - if (i % 100 == 0) { - System.out.println("Testing " + i + " connections"); - } - // We want to make sure socket descriptors are going away - zk = new ZooKeeper(hostPort, 30000, this); - zk.getData("/", false, new Stat()); - zk.close(); - } - } - - static class HammerThread extends Thread { - ZooKeeper zk; - String prefix; - int count; - - HammerThread(ZooKeeper zk, String prefix, int count) { - this.zk = zk; - this.prefix = prefix; - this.count = count; - start(); - } - - public void run() { - byte b[] = new byte[256]; - try { - for (int i = 0; i < count; i++) { - // Simulate a bit of network latency... - Thread.sleep(5); - zk.create(prefix + i, b, Ids.OPEN_ACL_UNSAFE, 0); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void close() throws IOException, InterruptedException, - KeeperException { - zk.close(); - } - } - - @Test - public void testDeleteWithChildren() throws Exception { - File tmpDir = File.createTempFile("test", ".junit", baseTest); - tmpDir = new File(tmpDir + ".dir"); - tmpDir.mkdirs(); - ZooKeeper zk = new ZooKeeper(hostPort, 30000, this); - zk.create("/parent", new byte[0], Ids.OPEN_ACL_UNSAFE, 0); - zk.create("/parent/child", new byte[0], Ids.OPEN_ACL_UNSAFE, 0); - try { - zk.delete("/parent", -1); - fail("Should have received a not equals message"); - } catch (KeeperException e) { - assertEquals(KeeperException.Code.NotEmpty, e.getCode()); - } - zk.delete("/parent/child", -1); - zk.delete("/parent", -1); - zk.close(); - } - - @Test - public void testHammer() throws KeeperException, IOException, - InterruptedException { - File tmpDir = File.createTempFile("test", ".junit", baseTest); - tmpDir = new File(tmpDir + ".dir"); - tmpDir.mkdirs(); - try { - final int threadCount = 10; - final int childCount = 1000; - ArrayList threads = new ArrayList( - threadCount); - long start = System.currentTimeMillis(); - for (int i = 0; i < threadCount; i++) { - Thread.sleep(10); - ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); - String prefix = "/test-" + i; - zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, 0); - prefix += "/"; - threads.add(new HammerThread(zk, prefix, childCount)); - } - for (HammerThread h : threads) { - h.join(); - h.close(); - } - System.err.println(new Date() + " Total time " - + (System.currentTimeMillis() - start)); - ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); - ZooLog.logWarn("******************* Connected to ZooKeeper" + new Date()); - for (int i = 0; i < threadCount; i++) { - System.err.println("Doing thread: " + i + " " + new Date()); - ArrayList children = zk - .getChildren("/test-" + i, false); - assertEquals(childCount, children.size()); - } - for (int i = 0; i < threadCount; i++) { - ArrayList children = zk - .getChildren("/test-" + i, false); - assertEquals(childCount, children.size()); - } - } finally { - // recursiveDelete(tmpDir); - } - } - - public void process(WatcherEvent event) { - if (event.getType() != Event.EventNone){ - try { - events.put(event); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/CreateHammerTest.java b/zookeeper/test/com/yahoo/zookeeper/test/CreateHammerTest.java deleted file mode 100644 index 0ec65e84bd7..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/CreateHammerTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.yahoo.zookeeper.test; - -import java.io.IOException; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.AsyncCallback.VoidCallback; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.Ids; - -public class CreateHammerTest implements VoidCallback { - - /** - * @param args - */ - static int REPS = 50000; - public static void main(String[] args) { - long startTime = System.currentTimeMillis(); - ZooKeeper zk = null; - try { - zk = new ZooKeeper(args[0], 10000, null); - } catch (KeeperException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - for(int i = 0; i < REPS; i++) { - try { - String name = zk.create("/testFile-", new byte[16], Ids.OPEN_ACL_UNSAFE, - CreateFlags.EPHEMERAL|CreateFlags.SEQUENCE); - zk.delete(name, -1, new CreateHammerTest(), null); - } catch(Exception e) { - i--; - e.printStackTrace(); - } - } - System.out.println("creates/sec=" + (REPS*1000/(System.currentTimeMillis()-startTime))); - } - @Override - public void processResult(int rc, String path, Object ctx) { - // TODO Auto-generated method stub - - } - -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/GenerateLoad.java b/zookeeper/test/com/yahoo/zookeeper/test/GenerateLoad.java deleted file mode 100644 index 08de705c0dd..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/GenerateLoad.java +++ /dev/null @@ -1,490 +0,0 @@ -package com.yahoo.zookeeper.test; - -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooDefs; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.AsyncCallback.DataCallback; -import com.yahoo.zookeeper.AsyncCallback.StatCallback; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; - -public class GenerateLoad { - static ServerSocket ss; - - static Set slaves = Collections - .synchronizedSet(new HashSet()); - - static HashMap totalByTime = new HashMap(); - - static long currentInterval; - - static long lastChange; - - static PrintStream sf; - static PrintStream tf; - static { - try { - tf = new PrintStream(new FileOutputStream("trace")); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - static final int INTERVAL = 6000; - - synchronized static void add(long time, int count, Socket s) { - long interval = time / INTERVAL; - if (currentInterval == 0 || currentInterval > interval) { - System.out.println("Dropping " + count + " for " + new Date(time) + " " + currentInterval + ">" + interval); - return; - } - // We track totals by seconds - Long total = totalByTime.get(interval); - if (total == null) { - totalByTime.put(interval, (long) count); - } else { - totalByTime.put(interval, total.longValue() + count); - } - tf.println(interval + " " + count + " " + s); - } - - synchronized static long remove(long interval) { - Long total = totalByTime.remove(interval); - return total == null ? -1 : total; - } - - static class SlaveThread extends Thread { - Socket s; - - SlaveThread(Socket s) { - setDaemon(true); - this.s = s; - start(); - } - - @SuppressWarnings("deprecation") - public void run() { - try { - System.out.println("Connected to " + s); - DataInputStream is = new DataInputStream( - new BufferedInputStream(s.getInputStream())); - String result; - while ((result = is.readLine()) != null) { - String timePercentCount[] = result.split(" "); - if (timePercentCount.length != 5) { - System.err.println("Got " + result + " from " + s + " exitng."); - throw new IOException(result); - } - long time = Long.parseLong(timePercentCount[0]); - int percent = Integer.parseInt(timePercentCount[1]); - int count = Integer.parseInt(timePercentCount[2]); - int errs = Integer.parseInt(timePercentCount[3]); - if (errs > 0) { - System.out.println(s+" Got an error! " + errs); - } - add(time, count, s); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - close(); - } - } - - void send(int percentage) { - try { - s.getOutputStream().write((percentage + "\n").getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - void close() { - try { - System.err.println("Closing " + s); - slaves.remove(this); - s.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - static class AcceptorThread extends Thread { - AcceptorThread() { - setDaemon(true); - start(); - } - - public void run() { - try { - while (true) { - Socket s = ss.accept(); - slaves.add(new SlaveThread(s)); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - for (Iterator it = slaves.iterator(); it.hasNext();) { - SlaveThread st = it.next(); - it.remove(); - st.close(); - } - } - } - } - - static class ReporterThread extends Thread { - ReporterThread() { - setDaemon(true); - start(); - } - - public void run() { - try { - currentInterval = System.currentTimeMillis() / INTERVAL; - // Give things time to report; - Thread.sleep(INTERVAL*2); - long min = 99999; - long max = 0; - long total = 0; - int number = 0; - while (true) { - long now = System.currentTimeMillis(); - long lastInterval = currentInterval; - currentInterval += 1; - long count = remove(lastInterval); - count=count*1000/INTERVAL; // Multiply by 1000 to get reqs/sec - if (lastChange != 0 && (lastChange + INTERVAL*4 + 5000)< now) { - // We only want to print anything if things have had a - // chance to change - - if (count < min) { - min = count; - } - if (count > max) { - max = count; - } - total += count; - number++; - Date date = new Date(lastInterval * INTERVAL); - String report = lastInterval + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() - + " " - + percentage - + "% " - + count - + " " - + min - + " " - + ((double)total / (double)number) + " " + max; - System.err.println(report); - if (sf != null) { - sf.println(report); - } - } else { - max = total = 0; - min = 999999999; - number = 0; - } - Thread.sleep(INTERVAL); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - } - - synchronized static void sendChange(int percentage) { - long now = System.currentTimeMillis(); - long start = now; - GenerateLoad.percentage = percentage; - for (SlaveThread st : slaves.toArray(new SlaveThread[0])) { - st.send(percentage); - } - long delay = now - start; - if (delay > 1000) { - System.out.println("Delay of " + delay + " to send new percentage"); - } - lastChange = now; - } - - static int percentage = -1; - - static String host; - - static Socket s; - - static int errors; - - static Object statSync = new Object(); - - static int finished; - - static int reads; - - static int writes; - - static int rlatency; - - static int wlatency; - - static int outstanding; - - static class ZooKeeperThread extends Thread implements Watcher, DataCallback, - StatCallback { - ZooKeeperThread() { - setDaemon(true); - start(); - alive = true; - } - - static final int outstandingLimit = 100; - - synchronized void incOutstanding() throws InterruptedException { - outstanding++; - while (outstanding > outstandingLimit) { - wait(); - } - } - - synchronized void decOutstanding() { - outstanding--; - notifyAll(); - } - - boolean alive; - - Random r = new Random(); - - String path; - - ZooKeeper zk; - public void run() { - try { - byte bytes[] = new byte[1024]; - zk = new ZooKeeper(host, 60000, this); - for(int i = 0; i < 300; i++) { - try { - Thread.sleep(100); - path = zk.create("/client", new byte[16], Ids.OPEN_ACL_UNSAFE, - CreateFlags.EPHEMERAL|CreateFlags.SEQUENCE); - break; - } catch(KeeperException e) { - } - } - if (path == null) { - System.err.println("Couldn't create a node in /!"); - System.exit(44); - } - System.err.println("Created: " + s); - while (alive) { - if (r.nextInt(100) < percentage) { - zk.setData(path, bytes, -1, this, System.currentTimeMillis()); - } else { - zk.getData(path, false, this, System.currentTimeMillis()); - } - incOutstanding(); - } - } catch (Exception e) { - e.printStackTrace(); - System.exit(3); - } finally { - alive = false; - } - } - - @Override - public void process(WatcherEvent event) { - System.err.println(event); - synchronized(this) { - try { - wait(200); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - if (event.getType() == Watcher.Event.EventNone && event.getState() == Watcher.Event.KeeperStateExpired) { - try { - zk = new ZooKeeper(host, 10000, this); - } catch (KeeperException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - } - } - - @Override - public void processResult(int rc, String path, Object ctx, byte[] data, - Stat stat) { - decOutstanding(); - synchronized(statSync) { - if (rc != 0) { - System.err.println("Got rc = " + rc); - errors++; - } else { - finished++; - rlatency += System.currentTimeMillis() - (Long)ctx; - reads++; - } - } - - } - - @Override - public void processResult(int rc, String path, Object ctx, Stat stat) { - decOutstanding(); - synchronized(statSync) { - if (rc != 0) { - System.err.println("Got rc = " + rc); - errors++; - } else { - finished++; - wlatency += System.currentTimeMillis() - (Long)ctx; - writes++; - } - } - } - } - - static class SenderThread extends Thread { - SenderThread() { - setDaemon(true); - start(); - } - public void run() { - try { - OutputStream os = s.getOutputStream(); - finished = 0; - errors = 0; - while(true) { - Thread.sleep(300); - if (percentage == -1 || (finished == 0 && errors == 0)) { - continue; - } - String report = System.currentTimeMillis() + " " + percentage + " " + finished + " " + errors + " " + outstanding + "\n"; - String subreport = reads + " " + (((double)rlatency)/reads) + " " + writes + " " + (((double)wlatency/writes)); - synchronized(statSync) { - finished = 0; - errors = 0; - reads = 0; - writes = 0; - rlatency = 0; - wlatency = 0; - } - os.write(report.getBytes()); - System.out.println("Reporting " + report + "+" + subreport); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - } - - /** - * @param args - * @throws InterruptedException - */ - public static void main(String[] args) throws InterruptedException { - if (args.length == 1) { - try { - int port = Integer.parseInt(args[0]); - ss = new ServerSocket(port); - new AcceptorThread(); - new ReporterThread(); - DataInputStream is = new DataInputStream(System.in); - String line; - while ((line = is.readLine()) != null) { - try { - String cmdNumber[] = line.split(" "); - if (cmdNumber[0].equals("percentage") && cmdNumber.length > 1) { - int number = Integer.parseInt(cmdNumber[1]); - if (number < 0 || number > 100) { - throw new NumberFormatException("must be between 0 and 100"); - } - sendChange(number); - } else if (cmdNumber[0].equals("sleep") && cmdNumber.length > 1) { - int number = Integer.parseInt(cmdNumber[1]); - Thread.sleep(number*1000); - } else if (cmdNumber[0].equals("save") && cmdNumber.length > 1) { - sf = new PrintStream(cmdNumber[1]); - } else { - System.err.println("Commands must be:"); - System.err.println("\tpercentage new_write_percentage"); - System.err.println("\tsleep seconds_to_sleep"); - System.err.println("\tsave file_to_save_output"); - } - } catch (NumberFormatException e) { - System.out - .println("Not a valid number: " + e.getMessage()); - } - } - } catch (NumberFormatException e) { - doUsage(); - } catch (IOException e) { - e.printStackTrace(); - System.exit(2); - } - } else if (args.length == 2) { - host = args[1]; - String hostPort[] = args[0].split(":"); - try { - s = new Socket(hostPort[0], Integer - .parseInt(hostPort[1])); - new ZooKeeperThread(); - new SenderThread(); - DataInputStream is = new DataInputStream(s.getInputStream()); - String line; - while((line = is.readLine()) != null) { - percentage = Integer.parseInt(line); - } - } catch (Exception e) { - e.printStackTrace(); - } - } else { - doUsage(); - } - - } - - private static void doUsage() { - System.err - .println("USAGE: " - + GenerateLoad.class.getName() - + " controller_host:port zookeeper_host:port-> connects to a controller"); - System.err.println("USAGE: " + GenerateLoad.class.getName() - + " controller_port -> starts a controller"); - System.exit(2); - } -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/OOMTest.java b/zookeeper/test/com/yahoo/zookeeper/test/OOMTest.java deleted file mode 100644 index 03ea27bc9ce..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/OOMTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * - */ -package com.yahoo.zookeeper.test; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - -import junit.framework.TestCase; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.NIOServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; - -/** - * @author breed - * - */ -public class OOMTest extends TestCase implements Watcher { - public void testOOM() throws IOException, InterruptedException, - KeeperException { - // This test takes too long to run! - if (true) - return; - File tmpDir = File.createTempFile("test", ".junit"); - tmpDir = new File(tmpDir + ".dir"); - tmpDir.mkdirs(); - // Grab some memory so that it is easier to cause an - // OOM condition; - ArrayList hog = new ArrayList(); - while (true) { - try { - hog.add(new byte[1024 * 1024 * 2]); - } catch (OutOfMemoryError e) { - hog.remove(0); - break; - } - } - ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); - NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(33221); - f.startup(zks); - Thread.sleep(2000); - System.err.println("OOM Stage 0"); - utestPrep(); - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - System.err.println("OOM Stage 1"); - for (int i = 0; i < 1000; i++) { - System.out.println(i); - utestExists(); - } - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - System.err.println("OOM Stage 2"); - for (int i = 0; i < 1000; i++) { - System.out.println(i); - utestGet(); - } - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - System.err.println("OOM Stage 3"); - for (int i = 0; i < 1000; i++) { - System.out.println(i); - utestChildren(); - } - System.out.println("Free = " + Runtime.getRuntime().freeMemory() - + " total = " + Runtime.getRuntime().totalMemory() + " max = " - + Runtime.getRuntime().maxMemory()); - hog.get(0)[0] = (byte) 1; - f.shutdown(); - } - - private void utestExists() throws IOException, InterruptedException, - KeeperException { - ZooKeeper zk = new ZooKeeper("127.0.0.1:33221", 30000, this); - for (int i = 0; i < 10000; i++) { - zk.exists("/this/path/doesnt_exist!", true); - } - zk.close(); - } - - private void utestPrep() throws KeeperException, IOException, - InterruptedException { - ZooKeeper zk = new ZooKeeper("127.0.0.1:33221", 30000, this); - for (int i = 0; i < 10000; i++) { - zk.create("/" + i, null, Ids.OPEN_ACL_UNSAFE, 0); - } - zk.close(); - } - - private void utestGet() throws IOException, InterruptedException, - KeeperException { - ZooKeeper zk = new ZooKeeper("127.0.0.1:33221", 30000, this); - for (int i = 0; i < 10000; i++) { - Stat stat = new Stat(); - zk.getData("/" + i, true, stat); - } - zk.close(); - } - - private void utestChildren() throws IOException, InterruptedException, - KeeperException { - ZooKeeper zk = new ZooKeeper("127.0.0.1:33221", 30000, this); - for (int i = 0; i < 10000; i++) { - zk.getChildren("/" + i, true); - } - zk.close(); - } - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.Watcher#process(com.yahoo.zookeeper.proto.WatcherEvent) - */ - public void process(WatcherEvent event) { - System.err.println("Got event " + event.getType() + " " - + event.getState() + " " + event.getPath()); - } -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/QuorumTest.java b/zookeeper/test/com/yahoo/zookeeper/test/QuorumTest.java deleted file mode 100644 index 1e0b6b2f280..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/QuorumTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.yahoo.zookeeper.test; - -import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.ArrayList; - -import org.junit.After; -import org.junit.Before; - -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.server.quorum.QuorumPeer; -import com.yahoo.zookeeper.server.quorum.QuorumPeer.QuorumServer; - -import junit.framework.TestCase; - -public class QuorumTest extends ClientTest { - static File baseTest = new File(System.getProperty("build.test.dir", "build")); - File s1dir, s2dir, s3dir, s4dir, s5dir; - QuorumPeer s1, s2, s3, s4, s5; - @Before - protected void setUp() throws Exception { - s1dir = File.createTempFile("test", ".junit", baseTest); - s1dir = new File(s1dir + ".dir"); - s1dir.mkdirs(); - s2dir = File.createTempFile("test", ".junit", baseTest); - s2dir = new File(s2dir + ".dir"); - s2dir.mkdirs(); - s3dir = File.createTempFile("test", ".junit", baseTest); - s3dir = new File(s3dir + ".dir"); - s3dir.mkdirs(); - s4dir = File.createTempFile("test", ".junit", baseTest); - s4dir = new File(s3dir + ".dir"); - s4dir.mkdirs(); - s5dir = File.createTempFile("test", ".junit", baseTest); - s5dir = new File(s3dir + ".dir"); - s5dir.mkdirs(); - startServers(); - ZooLog.logWarn("Setup finished"); - } - void startServers() throws IOException, InterruptedException { - int tickTime = 2000; - int initLimit = 3; - int syncLimit = 3; - ArrayList peers = new ArrayList(); - hostPort = "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184,127.0.0.1:2185"; - peers.add(new QuorumServer(1, new InetSocketAddress("127.0.0.1", 3181))); - peers.add(new QuorumServer(2, new InetSocketAddress("127.0.0.1", 3182))); - peers.add(new QuorumServer(3, new InetSocketAddress("127.0.0.1", 3183))); - peers.add(new QuorumServer(4, new InetSocketAddress("127.0.0.1", 3184))); - peers.add(new QuorumServer(5, new InetSocketAddress("127.0.0.1", 3185))); - ZooLog.logWarn("creating QuorumPeer 1"); - s1 = new QuorumPeer(peers, s1dir, s1dir, 2181, 0, 1, tickTime, initLimit, syncLimit); - ZooLog.logWarn("creating QuorumPeer 2"); - s2 = new QuorumPeer(peers, s2dir, s2dir, 2182, 0, 2, tickTime, initLimit, syncLimit); - ZooLog.logWarn("creating QuorumPeer 3"); - s3 = new QuorumPeer(peers, s3dir, s3dir, 2183, 0, 3, tickTime, initLimit, syncLimit); - ZooLog.logWarn("creating QuorumPeer 4"); - s4 = new QuorumPeer(peers, s4dir, s4dir, 2184, 0, 4, tickTime, initLimit, syncLimit); - ZooLog.logWarn("creating QuorumPeer 5"); - s5 = new QuorumPeer(peers, s5dir, s5dir, 2185, 0, 5, tickTime, initLimit, syncLimit); - ZooLog.logWarn("start QuorumPeer 1"); - s1.start(); - ZooLog.logWarn("start QuorumPeer 2"); - s2.start(); - ZooLog.logWarn("start QuorumPeer 3"); - s3.start(); - ZooLog.logWarn("start QuorumPeer 4"); - s4.start(); - ZooLog.logWarn("start QuorumPeer 5"); - s5.start(); - ZooLog.logWarn("started QuorumPeer 5"); - Thread.sleep(5000); - } - @After - protected void tearDown() throws Exception { - ZooLog.logWarn("TearDown started"); - s1.shutdown(); - s2.shutdown(); - s3.shutdown(); - s4.shutdown(); - s5.shutdown(); - Thread.sleep(5000); - } -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/RecoveryTest.java b/zookeeper/test/com/yahoo/zookeeper/test/RecoveryTest.java deleted file mode 100644 index 891e7d115d7..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/RecoveryTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * - */ -package com.yahoo.zookeeper.test; - -import java.io.File; - -import junit.framework.TestCase; - -import org.junit.Test; - -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.SyncRequestProcessor; -import com.yahoo.zookeeper.server.NIOServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; - -/** - * @author breed - * - */ -public class RecoveryTest extends TestCase implements Watcher { - static File baseTest = new File(System.getProperty("build.test.dir", - "build")); - - @Test - public void testRecovery() throws Exception { - File tmpDir = File.createTempFile("test", ".junit", baseTest); - tmpDir = new File(tmpDir + ".dir"); - tmpDir.mkdirs(); - ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, 3000); - int oldSnapCount = SyncRequestProcessor.snapCount; - SyncRequestProcessor.snapCount = 1000; - try { - NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(2344); - f.startup(zs); - System.out.println("starting up the the server -- sleeping"); - Thread.sleep(1000); - ZooKeeper zk = new ZooKeeper("127.0.0.1:2344", 20000, this); - String path; - System.out.println("starting creating nodes"); - for (int i = 0; i < 10; i++) { - path = "/" + i; - zk - .create(path, (path + "!").getBytes(), - Ids.OPEN_ACL_UNSAFE, 0); - for (int j = 0; j < 10; j++) { - String subpath = path + "/" + j; - zk.create(subpath, (subpath + "!").getBytes(), - Ids.OPEN_ACL_UNSAFE, 0); - for (int k = 0; k < 20; k++) { - String subsubpath = subpath + "/" + k; - zk.create(subsubpath, (subsubpath + "!").getBytes(), - Ids.OPEN_ACL_UNSAFE, 0); - } - } - } - f.shutdown(); - Thread.sleep(1000); - zs = new ZooKeeperServer(tmpDir, tmpDir, 3000); - f = new NIOServerCnxn.Factory(2344); - f.startup(zs); - Thread.sleep(1000); - Stat stat = new Stat(); - for (int i = 0; i < 10; i++) { - path = "/" + i; - System.out.println("Checking " + path); - assertEquals(new String(zk.getData(path, false, stat)), path - + "!"); - for (int j = 0; j < 10; j++) { - String subpath = path + "/" + j; - assertEquals(new String(zk.getData(subpath, false, stat)), - subpath + "!"); - for (int k = 0; k < 20; k++) { - String subsubpath = subpath + "/" + k; - assertEquals(new String(zk.getData(subsubpath, false, - stat)), subsubpath + "!"); - } - } - } - f.shutdown(); - Thread.sleep(2000); - zs = new ZooKeeperServer(tmpDir, tmpDir, 3000); - f = new NIOServerCnxn.Factory(2344); - f.startup(zs); - Thread.sleep(4000); - stat = new Stat(); - System.out.println("Check 2"); - for (int i = 0; i < 10; i++) { - path = "/" + i; - assertEquals(new String(zk.getData(path, false, stat)), path - + "!"); - for (int j = 0; j < 10; j++) { - String subpath = path + "/" + j; - assertEquals(new String(zk.getData(subpath, false, stat)), - subpath + "!"); - for (int k = 0; k < 20; k++) { - String subsubpath = subpath + "/" + k; - assertEquals(new String(zk.getData(subsubpath, false, - stat)), subsubpath + "!"); - } - } - } - f.shutdown(); - } finally { - SyncRequestProcessor.snapCount = oldSnapCount; - } - } - - /* - * (non-Javadoc) - * - * @see com.yahoo.zookeeper.Watcher#process(com.yahoo.zookeeper.proto.WatcherEvent) - */ - public void process(WatcherEvent event) { - // TODO Auto-generated method stub - - } -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/SessionTest.java b/zookeeper/test/com/yahoo/zookeeper/test/SessionTest.java deleted file mode 100644 index bf242aa9d5d..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/SessionTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.yahoo.zookeeper.test; - -import java.io.File; -import java.io.IOException; -import org.junit.Test; -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.NIOServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import junit.framework.TestCase; - -public class SessionTest extends TestCase implements Watcher { - static File baseTest = new File(System.getProperty("build.test.dir", - "build")); - - @Test - public void testSession() throws IOException, InterruptedException, - KeeperException { - File tmpDir = File.createTempFile("test", ".junit", baseTest); - tmpDir = new File(tmpDir + ".dir"); - tmpDir.mkdirs(); - ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, 3000); - NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(33299); - f.startup(zs); - Thread.sleep(2000); - ZooKeeper zk = new ZooKeeper("127.0.0.1:33299", 30000, this); - zk - .create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE, - CreateFlags.EPHEMERAL); - System.out.println("zk with session id " + zk.getSessionId() - + " was destroyed!"); - // zk.close(); - Stat stat = new Stat(); - try { - zk = new ZooKeeper("127.0.0.1:33299", 30000, this, zk - .getSessionId(), zk.getSessionPasswd()); - System.out.println("zk with session id " + zk.getSessionId() - + " was created!"); - zk.getData("/e", false, stat); - System.out.println("After get data /e"); - } catch (KeeperException e) { - // the zk.close() above if uncommented will close the session on the - // server - // in such case we get an exception here because we've tried joining - // a closed session - } - zk.close(); - Thread.sleep(10000); - zk = new ZooKeeper("127.0.0.1:33299", 30000, this); - assertEquals(null, zk.exists("/e", false)); - System.out.println("before close zk with session id " - + zk.getSessionId() + "!"); - zk.close(); - System.out.println("before shutdown zs!"); - zs.shutdown(); - System.out.println("after shutdown zs!"); - } - - public void process(WatcherEvent event) { - } - -} diff --git a/zookeeper/test/com/yahoo/zookeeper/test/ZooKeeperTestClient.java b/zookeeper/test/com/yahoo/zookeeper/test/ZooKeeperTestClient.java deleted file mode 100644 index 2a73805879b..00000000000 --- a/zookeeper/test/com/yahoo/zookeeper/test/ZooKeeperTestClient.java +++ /dev/null @@ -1,388 +0,0 @@ -package com.yahoo.zookeeper.test; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -import junit.framework.TestCase; - -import org.junit.Test; - -import com.yahoo.zookeeper.KeeperException; -import com.yahoo.zookeeper.Watcher; -import com.yahoo.zookeeper.ZooDefs; -import com.yahoo.zookeeper.ZooKeeper; -import com.yahoo.zookeeper.KeeperException.Code; -import com.yahoo.zookeeper.Watcher.Event; -import com.yahoo.zookeeper.ZooDefs.CreateFlags; -import com.yahoo.zookeeper.ZooDefs.Ids; -import com.yahoo.zookeeper.data.Stat; -import com.yahoo.zookeeper.proto.WatcherEvent; -import com.yahoo.zookeeper.server.NIOServerCnxn; -import com.yahoo.zookeeper.server.ZooKeeperServer; -import com.yahoo.zookeeper.server.ZooLog; -import com.yahoo.zookeeper.test.ClientTest.HammerThread; - -public class ZooKeeperTestClient extends TestCase implements Watcher { - protected String hostPort = "127.0.0.1:22801"; - - protected static String dirOnZK = "/test_dir"; - - protected String testDirOnZK = dirOnZK + "/" + System.currentTimeMillis(); - - LinkedBlockingQueue events = new LinkedBlockingQueue(); - - private WatcherEvent getEvent(int numTries) throws InterruptedException { - WatcherEvent event = null; - for (int i = 0; i < numTries; i++) { - System.out.println("i = " + i); - event = events.poll(10, TimeUnit.SECONDS); - if (event != null) { - break; - } - Thread.sleep(5000); - } - return event; - - } - - private void deleteZKDir(ZooKeeper zk, String nodeName) - throws KeeperException, IOException, InterruptedException { - - Stat stat = zk.exists(nodeName, false); - if (stat == null) { - return; - } - - ArrayList children = zk.getChildren(nodeName, false); - if (children.size() == 0) { - zk.delete(nodeName, -1); - return; - } - for (String n : children) { - deleteZKDir(zk, n); - } - } - - private void checkRoot() throws KeeperException, IOException, - InterruptedException { - ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); - - try { - zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, 0); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NodeExists; - if (!valid) { - fail("Unexpected exception code for create " + dirOnZK + ": " - + ke.getMessage()); - } - } - - try { - zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, 0); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NodeExists; - if (!valid) { - fail("Unexpected exception code for create " + testDirOnZK + ": " - + ke.getMessage()); - } - } - - zk.close(); - } - - private void enode_test_1() throws KeeperException, IOException, - InterruptedException { - checkRoot(); - String parentName = testDirOnZK; - String nodeName = parentName + "/enode_abc"; - ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); - - Stat stat = zk.exists(parentName, false); - if (stat == null) { - try { - zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, 0); - } catch (KeeperException ke) { - fail("Creating node " + parentName + ke.getMessage()); - } - } - - try { - zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, ZooDefs.CreateFlags.EPHEMERAL); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NodeExists; - if (!valid) { - fail("Unexpected exception code for createin: " + ke.getMessage()); - } - } - - stat = zk.exists(nodeName, false); - if (stat == null) { - fail("node " + nodeName + " should exist"); - } - long prevSessionId = zk.getSessionId(); - byte[] prevSessionPasswd = zk.getSessionPasswd(); - System.out.println("Closing client with sessioid: " + prevSessionId); - zk.close(); - zk = new ZooKeeper(hostPort, 10000, this); - - for (int i = 0; i < 10; i++) { - System.out.println("i = " + i); - stat = zk.exists(nodeName, false); - if (stat != null) { - System.out.println("node " + nodeName - + " should not exist after reconnection close"); - } else { - System.out.println("node " + nodeName - + " is gone after reconnection close!"); - break; - } - Thread.sleep(5000); - } - deleteZKDir(zk, nodeName); - zk.close(); - - } - - private void enode_test_2() throws KeeperException, IOException, - InterruptedException { - checkRoot(); - String parentName = testDirOnZK; - String nodeName = parentName + "/enode_abc"; - ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); - ZooKeeper zk_1 = new ZooKeeper(hostPort, 10000, this); - - Stat stat = zk_1.exists(parentName, false); - if (stat == null) { - try { - zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, 0); - } catch (KeeperException ke) { - fail("Creating node " + parentName + ke.getMessage()); - } - } - - stat = zk_1.exists(nodeName, false); - if (stat != null) { - - try { - zk.delete(nodeName, -1); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NoNode - || code == KeeperException.Code.NotEmpty; - if (!valid) { - fail("Unexpected exception code for delete: " + ke.getMessage()); - } - } - } - - ArrayList firstGen = zk_1.getChildren(parentName, true); - - try { - zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, ZooDefs.CreateFlags.EPHEMERAL); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NodeExists; - if (!valid) { - fail("Unexpected exception code for createin: " + ke.getMessage()); - } - } - - Thread.sleep(5000); - WatcherEvent event = events.poll(10, TimeUnit.SECONDS); - if (event == null) { - throw new IOException("No event was delivered promptly"); - } - if (event.getType() != Watcher.Event.EventNodeChildrenChanged - || !event.getPath().equalsIgnoreCase(parentName)) { - fail("Unexpected event was delivered: " + event.toString()); - } - - stat = zk_1.exists(nodeName, false); - if (stat == null) { - fail("node " + nodeName + " should exist"); - } - - try { - zk.delete(parentName, -1); - fail("Should be impossible to delete a non-empty node " + parentName); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NotEmpty; - if (!valid) { - fail("Unexpected exception code for delete: " + code); - } - } - - try { - zk.create(nodeName + "/def", null, Ids.OPEN_ACL_UNSAFE, ZooDefs.CreateFlags.EPHEMERAL); - fail("Should be impossible to create child off Ephemeral node " - + nodeName); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NoChildrenForEphemerals; - if (!valid) { - fail("Unexpected exception code for createin: " + code); - } - } - - try { - ArrayList children = zk.getChildren(nodeName, false); - if (children.size() > 0) { - fail("ephemeral node " + nodeName + " should not have children"); - } - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NoNode; - if (!valid) { - fail("Unexpected exception code for createin: " + code); - } - } - firstGen = zk_1.getChildren(parentName, true); - stat = zk_1.exists(nodeName, true); - if (stat == null) { - fail("node " + nodeName + " should exist"); - } - System.out.println("session id of zk: " + zk.getSessionId()); - System.out.println("session id of zk_1: " + zk_1.getSessionId()); - zk.close(); - - stat = zk_1.exists("nosuchnode", false); - - event = this.getEvent(10); - if (event == null) { - fail("First event was not delivered promptly"); - } - if (!((event.getType() == Watcher.Event.EventNodeChildrenChanged && - event.getPath().equalsIgnoreCase(parentName)) || - (event.getType() == Watcher.Event.EventNodeDeleted && - event.getPath().equalsIgnoreCase(nodeName)))) { - System.out.print(parentName + " " - + Watcher.Event.EventNodeChildrenChanged + " " + nodeName + " " + Watcher.Event.EventNodeDeleted); - fail("Unexpected first event was delivered: " + event.toString()); - } - - event = this.getEvent(10); - - if (event == null) { - fail("Second event was not delivered promptly"); - } - if (!((event.getType() == Watcher.Event.EventNodeChildrenChanged && - event.getPath().equalsIgnoreCase(parentName)) || - (event.getType() == Watcher.Event.EventNodeDeleted && - event.getPath().equalsIgnoreCase(nodeName)))) { - System.out.print(parentName + " " - + Watcher.Event.EventNodeChildrenChanged + " " + nodeName + " " + Watcher.Event.EventNodeDeleted); - fail("Unexpected second event was delivered: " + event.toString()); - } - - firstGen = zk_1.getChildren(parentName, false); - stat = zk_1.exists(nodeName, false); - if (stat != null) { - fail("node " + nodeName + " should have been deleted"); - } - if (firstGen.contains(nodeName)) { - fail("node " + nodeName + " should not be a children"); - } - deleteZKDir(zk_1, nodeName); - zk_1.close(); - } - - private void delete_create_get_set_test_1() throws KeeperException, - IOException, InterruptedException { - checkRoot(); - ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); - String parentName = testDirOnZK; - String nodeName = parentName + "/benwashere"; - try { - zk.delete(nodeName, -1); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NoNode - || code == KeeperException.Code.NotEmpty; - if (!valid) { - fail("Unexpected exception code for delete: " + ke.getMessage()); - } - } - try { - zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, 0); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NodeExists; - if (!valid) { - fail("Unexpected exception code for create: " + ke.getMessage()); - } - } - try { - zk.setData(nodeName, "hi".getBytes(), 5700); - fail("Should have gotten BadVersion exception"); - } catch (KeeperException ke) { - if (ke.getCode() != Code.BadVersion) { - fail("Should have gotten BadVersion exception"); - } - } - zk.setData(nodeName, "hi".getBytes(), -1); - Stat st = new Stat(); - byte[] bytes = zk.getData(nodeName, false, st); - String retrieved = new String(bytes); - if (!"hi".equals(retrieved)) { - fail("The retrieved data [" + retrieved - + "] is differented than the expected [hi]"); - } - try { - zk.delete(nodeName, 6800); - fail("Should have gotten BadVersion exception"); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NotEmpty - || code == KeeperException.Code.BadVersion; - if (!valid) { - fail("Unexpected exception code for delete: " + ke.getMessage()); - } - } - try { - zk.delete(nodeName, -1); - } catch (KeeperException ke) { - int code = ke.getCode(); - boolean valid = code == KeeperException.Code.NotEmpty; - if (!valid) { - fail("Unexpected exception code for delete: " + code); - } - } - deleteZKDir(zk, nodeName); - zk.close(); - } - - @Test - public void my_test_1() throws KeeperException, IOException, - InterruptedException { - enode_test_1(); - enode_test_2(); - delete_create_get_set_test_1(); - } - - synchronized public void process(WatcherEvent event) { - try { - System.out.println("Got an event " + event.toString()); - events.put(event); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - public static void main(String[] args) { - ZooKeeperTestClient zktc = new ZooKeeperTestClient(); - try { - zktc.my_test_1(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/zookeeper/zookeeper.jute b/zookeeper/zookeeper.jute deleted file mode 100755 index 441d360b37a..00000000000 --- a/zookeeper/zookeeper.jute +++ /dev/null @@ -1,177 +0,0 @@ -module com.yahoo.zookeeper.data { - class Id { - ustring scheme; - ustring id; - } - class ACL { - int perms; - Id id; - } - class Stat { - long czxid; - long mzxid; - long ctime; - long mtime; - int version; - int cversion; - int aversion; - long ephemeralOwner; - } -} -module com.yahoo.zookeeper.proto { - class op_result_t { - int rc; - int op; - buffer response; - } - - class ConnectRequest { - int protocolVersion; - long lastZxidSeen; - int timeOut; - long sessionId; - buffer passwd; - } - class ConnectResponse { - int protocolVersion; - int timeOut; - long sessionId; - buffer passwd; - } - class RequestHeader { - int xid; - int type; - } - class AuthPacket { - int type; - ustring scheme; - buffer auth; - } - class ReplyHeader { - int xid; - long zxid; - int err; - } - class GetDataRequest { - ustring path; - boolean watch; - } - class SetDataRequest { - ustring path; - buffer data; - int version; - } - class SetDataResponse { - com.yahoo.zookeeper.data.Stat stat; - } - class CreateRequest { - ustring path; - buffer data; - vector acl; - int flags; - } - class DeleteRequest { - ustring path; - int version; - } - class GetChildrenRequest { - ustring path; - boolean watch; - } - class GetMaxChildrenRequest { - ustring path; - } - class GetMaxChildrenResponse { - int max; - } - class SetMaxChildrenRequest { - ustring path; - int max; - } - class GetACLRequest { - ustring path; - } - class SetACLRequest { - ustring path; - vector acl; - int version; - } - class SetACLResponse { - com.yahoo.zookeeper.data.Stat stat; - } - class WatcherEvent { - int type; // event type - int state; // state of the Keeper client runtime - ustring path; - } - - class CreateResponse { - ustring path; - } - class ExistsRequest { - ustring path; - boolean watch; - } - class ExistsResponse { - com.yahoo.zookeeper.data.Stat stat; - } - class GetDataResponse { - buffer data; - com.yahoo.zookeeper.data.Stat stat; - } - class GetChildrenResponse { - vectorchildren; - } - class GetACLResponse { - vector acl; - com.yahoo.zookeeper.data.Stat stat; - } -} - -module com.yahoo.zookeeper.server.quorum { - class QuorumPacket { - int type; // Request, Ack, Commit, Ping - long zxid; - buffer data; // Only significant when type is request - vector authinfo; - } -} - -module com.yahoo.zookeeper.txn { - class TxnHeader { - long clientId; - int cxid; - long zxid; - long time; - int type; - } - class CreateTxn { - ustring path; - buffer data; - vector acl; - boolean ephemeral; - } - class DeleteTxn { - ustring path; - } - class SetDataTxn { - ustring path; - buffer data; - int version; - } - class SetACLTxn { - ustring path; - vector acl; - int version; - } - class SetMaxChildrenTxn { - ustring path; - int max; - } - class CreateSessionTxn { - int timeOut; - } - class ErrorTxn { - int err; - } -}